WordPress/wp-includes/js/dist/patterns.min.js

2 lines
15 KiB
JavaScript
Raw Normal View History

/*! This file is auto-generated */
(()=>{"use strict";var e={d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{privateApis:()=>H,store:()=>h});var n={};e.r(n),e.d(n,{convertSyncedPatternToStatic:()=>y,createPattern:()=>_,createPatternFromFile:()=>g,setEditingPattern:()=>f});var a={};e.r(a),e.d(a,{isEditingPattern:()=>w});const r=window.wp.data;const o=(0,r.combineReducers)({isEditingPattern:function(e={},t){return"SET_EDITING_PATTERN"===t?.type?{...e,[t.clientId]:t.isEditing}:e}}),s=window.wp.blocks,i=window.wp.coreData,c=window.wp.blockEditor,l=window.wp.i18n,u={theme:"pattern",user:"wp_block"},p="all-patterns",d={full:"fully",unsynced:"unsynced"},m={"core/paragraph":{content:(0,l.__)("Content")},"core/heading":{content:(0,l.__)("Content")},"core/button":{text:(0,l.__)("Text"),url:(0,l.__)("URL"),linkTarget:(0,l.__)("Link Target")},"core/image":{url:(0,l.__)("URL"),title:(0,l.__)("Title"),alt:(0,l.__)("Alt Text")}},_=(e,t,n,a)=>async({registry:r})=>{const o=t===d.unsynced?{wp_pattern_sync_status:t}:void 0,s={title:e,content:n,status:"publish",meta:o,wp_pattern_category:a};return await r.dispatch(i.store).saveEntityRecord("postType","wp_block",s)},g=(e,t)=>async({dispatch:n})=>{const a=await e.text();let r;try{r=JSON.parse(a)}catch(e){throw new Error("Invalid JSON file")}if("wp_block"!==r.__file||!r.title||!r.content||"string"!=typeof r.title||"string"!=typeof r.content||r.syncStatus&&"string"!=typeof r.syncStatus)throw new Error("Invalid pattern JSON file");return await n.createPattern(r.title,r.syncStatus,r.content,t)},y=e=>({registry:t})=>{const n=t.select(c.store).getBlock(e);t.dispatch(c.store).replaceBlocks(n.clientId,function e(t){return t.map((t=>{let n=t.attributes.metadata;return n&&(n={...n},delete n.id,delete n.bindings),(0,s.cloneBlock)(t,{metadata:n&&Object.keys(n).length>0?n:void 0},e(t.innerBlocks))}))}(n.innerBlocks))};function f(e,t){return{type:"SET_EDITING_PATTERN",clientId:e,isEditing:t}}function w(e,t){return e.isEditingPattern[t]}const E=window.wp.privateApis,{lock:C,unlock:S}=(0,E.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.","@wordpress/patterns"),b={reducer:o},h=(0,r.createReduxStore)("core/patterns",{...b});(0,r.register)(h),S(h).registerPrivateActions(n),S(h).registerPrivateSelectors(a);const k=window.React,v=window.wp.components,P=window.wp.element,x=window.wp.notices,T=window.wp.compose,B=window.wp.htmlEntities,R=e=>(0,B.decodeEntities)(e),D="wp_pattern_category";function I({categoryTerms:e,onChange:t,categoryMap:n}){const[a,r]=(0,P.useState)(""),o=(0,T.useDebounce)(r,500),s=(0,P.useMemo)((()=>Array.from(n.values()).map((e=>R(e.label))).filter((e=>""===a||e.toLowerCase().includes(a.toLowerCase()))).sort(((e,t)=>e.localeCompare(t)))),[a,n]);return(0,k.createElement)(v.FormTokenField,{className:"patterns-menu-items__convert-modal-categories",value:e,suggestions:s,onChange:function(e){const n=e.reduce(((e,t)=>(e.some((e=>e.toLowerCase()===t.toLowerCase()))||e.push(t),e)),[]);t(n)},onInputChange:o,label:(0,l.__)("Categories"),tokenizeOnBlur:!0,__experimentalExpandOnFocus:!0,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})}function N({className:e="patterns-menu-items__convert-modal",modalTitle:t=(0,l.__)("Create pattern"),...n}){return(0,k.createElement)(v.Modal,{title:t,onRequestClose:n.onClose,overlayClassName:e},(0,k.createElement)(M,{...n}))}function M({confirmLabel:e=(0,l.__)("Create"),defaultCategories:t=[],content:n,onClose:a,onError:o,onSuccess:s,defaultSyncType:c=d.full,defaultTitle:u=""}){const[m,_]=(0,P.useState)(c),[g,y]=(0,P.useState)(t),[f,w]=(0,P.useState)(u),[E,C]=(0,P.useState)(!1),{createPattern:b}=S((0,r.useDispatch)(h)),{saveEntityRecord:T,invalidateResolution:B}=(0,r.useDispatch)(i.store),{createErrorNotice:R