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

2 lines
16 KiB
JavaScript
Raw Permalink Normal View History

2024-04-10 12:01:06 +00:00
/*! 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:()=>q,store:()=>C});var n={};e.r(n),e.d(n,{convertSyncedPatternToStatic:()=>g,createPattern:()=>m,createPatternFromFile:()=>_,setEditingPattern:()=>y});var a={};e.r(a),e.d(a,{isEditingPattern:()=>f});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,c=window.wp.coreData,i=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=(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(c.store).saveEntityRecord("postType","wp_block",s)},_=(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)},g=e=>({registry:t})=>{const n=t.select(i.store).getBlock(e);t.dispatch(i.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 y(e,t){return{type:"SET_EDITING_PATTERN",clientId:e,isEditing:t}}function f(e,t){return e.isEditingPattern[t]}const w=window.wp.privateApis,{lock:E,unlock:b}=(0,w.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.","@wordpress/patterns"),S={reducer:o},C=(0,r.createReduxStore)("core/patterns",{...S});(0,r.register)(C),b(C).registerPrivateActions(n),b(C).registerPrivateSelectors(a);const k=window.React,v=window.wp.components,h=window.wp.i18n,P=window.wp.element,T=window.wp.notices,B=window.wp.compose,x=window.wp.htmlEntities,R=e=>(0,x.decodeEntities)(e),I="wp_pattern_category";function D({categoryTerms:e,onChange:t,categoryMap:n}){const[a,r]=(0,P.useState)(""),o=(0,B.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,h.__)("Categories"),tokenizeOnBlur:!0,__experimentalExpandOnFocus:!0,__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0})}function N(){const{saveEntityRecord:e,invalidateResolution:t}=(0,r.useDispatch)(c.store),{corePatternCategories:n,userPatternCategories:a}=(0,r.useSelect)((e=>{const{getUserPatternCategories:t,getBlockPatternCategories:n}=e(c.store);return{corePatternCategories:n(),userPatternCategories:t()}}),[]),o=(0,P.useMemo)((()=>{const e=new Map;return a.forEach((t=>{e.set(t.label.toLowerCase(),{label:t.label,name:t.name,id:t.id})})),n.forEach((t=>{e.has(t.label.toLowerCase())||"query"===t.name||e.set(t.label.toLowerCase(),{label:t.label,name:t.name})})),e}),[a,n]);return{categoryMap:o,findOrCreateTerm:async function(n){try{const a=o.get(n.toLowerCase());if(a?.id)return a.id;const r=a?{name:a.label,slug:a.name}:{name:n},s=await e("taxonomy",I,r