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

2 lines
19 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:()=>K,store:()=>v});var n={};e.r(n),e.d(n,{convertSyncedPatternToStatic:()=>y,createPattern:()=>_,createPatternFromFile:()=>g,setEditingPattern:()=>f});var a={};e.r(a),e.d(a,{isEditingPattern:()=>b});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={theme:"pattern",user:"wp_block"},u="all-patterns",d={full:"fully",unsynced:"unsynced"},p={"core/paragraph":["content"],"core/heading":["content"],"core/button":["text","url","linkTarget","rel"],"core/image":["id","url","title","alt"]},m="core/pattern-overrides",_=(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),a=n.attributes?.content;const r=t.select(c.store).getBlocks(n.clientId);t.dispatch(c.store).replaceBlocks(n.clientId,function e(t){return t.map((t=>{let n=t.attributes.metadata;if(n&&(n={...n},delete n.id,delete n.bindings,a[n.name]))for(const[e,r]of Object.entries(a[n.name]))(0,s.getBlockType)(t.name)?.attributes[e]&&(t.attributes[e]=r);return(0,s.cloneBlock)(t,{metadata:n&&Object.keys(n).length>0?n:void 0},e(t.innerBlocks))}))}(r))};function f(e,t){return{type:"SET_EDITING_PATTERN",clientId:e,isEditing:t}}function b(e,t){return e.isEditingPattern[t]}const E=window.wp.privateApis,{lock:w,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"),C={reducer:o},v=(0,r.createReduxStore)("core/patterns",{...C});(0,r.register)(v),S(v).registerPrivateActions(n),S(v).registerPrivateSelectors(a);const h=window.React,k=window.wp.components,x=window.wp.element,P=window.wp.i18n;function B(e){return Object.keys(p).includes(e.name)&&!!e.attributes.metadata?.name&&!!e.attributes.metadata?.bindings&&Object.values(e.attributes.metadata.bindings).some((e=>"core/pattern-overrides"===e.source))}const{BlockQuickNavigation:T}=S(c.privateApis);const D=window.wp.notices,I=window.wp.compose,R=window.wp.htmlEntities,N=e=>(0,R.decodeEntities)(e),M="wp_pattern_category";function O({categoryTerms:e,onChange:t,categoryMap:n}){const[a,r]=(0,x.useState)(""),o=(0,I.useDebounce)(r,500),s=(0,x.useMemo)((()=>Array.from(n.values()).map((e=>N(e.label))).filter((e=>""===a||e.toLowerCase().includes(a.toLowerCase()))).sort(((e,t)=>e.localeCompare(t)))),[a,n]);return(0,h.createElement)(k.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,P.__)("Categories"),tokenizeOnBlur:!0,__experimentalExpandOnFocus:!0,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})}function A(){const{saveEntityRecord:e,invalidateResolution:t}=(0,r.useDispatch)(i.store),{corePatternCategories:n,userPatternCategories:a}=(0,r.useSelect)((e=>{const{getUserPatternCategories:t,getBlockPatternCategories:n}=e(i.store);return{corePatternCategories:n(),userPa