mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-04 01:39:37 +01:00
2 lines
8.2 KiB
JavaScript
2 lines
8.2 KiB
JavaScript
|
/*! This file is auto-generated */
|
||
|
!function(){"use strict";var e={d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(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:function(){return j},store:function(){return h}});var n={};e.r(n),e.d(n,{convertSyncedPatternToStatic:function(){return m},createPattern:function(){return p},createPatternFromFile:function(){return d},setEditingPattern:function(){return w}});var r={};e.r(r),e.d(r,{isEditingPattern:function(){return _}});var a=window.wp.data;var o=(0,a.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;const l="all-patterns",u={full:"fully",unsynced:"unsynced"},p=(e,t,n,r)=>async({registry:a})=>{const o=t===u.unsynced?{wp_pattern_sync_status:t}:void 0,s={title:e,content:n,status:"publish",meta:o,wp_pattern_category:r};return await a.dispatch(c.store).saveEntityRecord("postType","wp_block",s)},d=(e,t)=>async({dispatch:n})=>{const r=await e.text();let a;try{a=JSON.parse(r)}catch(e){throw new Error("Invalid JSON file")}if("wp_block"!==a.__file||!a.title||!a.content||"string"!=typeof a.title||"string"!=typeof a.content||a.syncStatus&&"string"!=typeof a.syncStatus)throw new Error("Invalid Pattern JSON file");return await n.createPattern(a.title,a.syncStatus,a.content,t)},m=e=>({registry:t})=>{const n=t.select(i.store).getBlock(e),r=t.select("core").getEditedEntityRecord("postType","wp_block",n.attributes.ref),a=(0,s.parse)("function"==typeof r.content?r.content(r):r.content);t.dispatch(i.store).replaceBlocks(n.clientId,a)};function w(e,t){return{type:"SET_EDITING_PATTERN",clientId:e,isEditing:t}}function _(e,t){return e.isEditingPattern[t]}var y=window.wp.privateApis;const{lock:g,unlock:E}=(0,y.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.","@wordpress/patterns"),f={reducer:o},h=(0,a.createReduxStore)("core/patterns",{...f});(0,a.register)(h),E(h).registerPrivateActions(n),E(h).registerPrivateSelectors(r);var v=window.wp.element,S=window.wp.components,b=window.wp.i18n,k=window.wp.notices,C=window.wp.compose,P=window.wp.htmlEntities;const T=e=>(0,P.decodeEntities)(e),I=[],R=20,B={per_page:R,_fields:"id,name",context:"view"},N="wp_pattern_category";function A({values:e,onChange:t}){const[n,r]=(0,v.useState)(""),o=(0,C.useDebounce)(r,500),{searchResults:s}=(0,a.useSelect)((e=>{const{getEntityRecords:t}=e(c.store);return{searchResults:n?t("taxonomy",N,{...B,search:n}):I}}),[n]),i=(0,v.useMemo)((()=>(null!=s?s:[]).map((e=>T(e.name)))),[s]);return(0,v.createElement)(v.Fragment,null,(0,v.createElement)(S.FormTokenField,{className:"patterns-menu-items__convert-modal-categories",value:e,suggestions:i,onChange:function(e){const n=e.reduce(((e,t)=>(e.some((e=>e.toLowerCase()===t.toLowerCase()))||e.push(t),e)),[]);t(n)},onInputChange:o,maxSuggestions:R,label:(0,b.__)("Categories"),tokenizeOnBlur:!0}))}function O({onSuccess:e,onError:t,content:n,onClose:r,className:o="patterns-menu-items__convert-modal"}){const[s,i]=(0,v.useState)(u.full),[p,d]=(0,v.useState)([]),[m,w]=(0,v.useState)(""),[_,y]=(0,v.useState)(!1),{createPattern:g}=E((0,a.useDispatch)(h)),{saveEntityRecord:f,invalidateResolution:C}=(0,a.useDispatch)(c.store),{createErrorNotice:P}=(0,a.useDispatch)(k.store);async function T(r,a){if(m&&!_)try{y(!0);const t=await Promise.all(p.map((e=>async function(e){try{const t=await f("taxonomy",N,{name:e},{throwOnError:!0});return C("getUserPatternCategories"),t.id}catch(e){if("term_exists"!==e.code)throw e;return e.data.term_id}}(e)))),o=await g(r,a,"function"==typeof n?n():n,t);e({pattern:o,categoryId:l})}catch(e){P(e.message,{type:"snackbar",id:"convert-to-pattern-error"}),t()}finally{y(!1),d([]),w("")}
|