WordPress/wp-includes/js/dist/reusable-blocks.min.js

2 lines
6.3 KiB
JavaScript
Raw Normal View History

/*! This file is auto-generated */
(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},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,{ReusableBlocksMenuItems:()=>f,store:()=>m});var n={};e.r(n),e.d(n,{__experimentalConvertBlockToStatic:()=>a,__experimentalConvertBlocksToReusable:()=>i,__experimentalDeleteReusableBlock:()=>u,__experimentalSetEditingReusableBlock:()=>d});var o={};e.r(o),e.d(o,{__experimentalIsEditingReusableBlock:()=>_});const r=window.wp.data,l=window.wp.blockEditor,c=window.wp.blocks,s=window.wp.i18n,a=e=>({registry:t})=>{const n=t.select(l.store).getBlock(e),o=t.select("core").getEditedEntityRecord("postType","wp_block",n.attributes.ref),r=(0,c.parse)("function"==typeof o.content?o.content(o):o.content);t.dispatch(l.store).replaceBlocks(n.clientId,r)},i=(e,t,n)=>async({registry:o,dispatch:r})=>{const a="unsynced"===n?{wp_pattern_sync_status:n}:void 0,i={title:t||(0,s.__)("Untitled Pattern block"),content:(0,c.serialize)(o.select(l.store).getBlocksByClientId(e)),status:"publish",meta:a},u=await o.dispatch("core").saveEntityRecord("postType","wp_block",i);if("unsynced"===n)return;const d=(0,c.createBlock)("core/block",{ref:u.id});o.dispatch(l.store).replaceBlocks(e,d),r.__experimentalSetEditingReusableBlock(d.clientId,!0)},u=e=>async({registry:t})=>{if(!t.select("core").getEditedEntityRecord("postType","wp_block",e))return;const n=t.select(l.store).getBlocks().filter((t=>(0,c.isReusableBlock)(t)&&t.attributes.ref===e)).map((e=>e.clientId));n.length&&t.dispatch(l.store).removeBlocks(n),await t.dispatch("core").deleteEntityRecord("postType","wp_block",e)};function d(e,t){return{type:"SET_EDITING_REUSABLE_BLOCK",clientId:e,isEditing:t}}const p=(0,r.combineReducers)({isEditingReusableBlock:function(e={},t){return"SET_EDITING_REUSABLE_BLOCK"===t?.type?{...e,[t.clientId]:t.isEditing}:e}});function _(e,t){return e.isEditingReusableBlock[t]}const m=(0,r.createReduxStore)("core/reusable-blocks",{actions:n,reducer:p,selectors:o});(0,r.register)(m);const b=window.wp.element,k=window.wp.components,w=window.wp.primitives,g=(0,b.createElement)(w.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,b.createElement)(w.Path,{d:"M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z"})),y=window.wp.notices,B=window.wp.coreData,E=window.wp.privateApis,{unlock:h}=(0,E.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.","@wordpress/reusable-blocks");function v({clientIds:e,rootClientId:t}){const{useReusableBlocksRenameHint:n,ReusableBlocksRenameHint:o}=h(l.privateApis),a=n(),[i,u]=(0,b.useState)(void 0),[d,p]=(0,b.useState)(!1),[_,w]=(0,b.useState)(""),E=(0,r.useSelect)((n=>{var o;const{canUser:r}=n(B.store),{getBlocksByClientId:s,canInsertBlockType:a,getBlockRootClientId:i}=n(l.store),u=t||(e.length>0?i(e[0]):void 0),d=null!==(o=s(e))&&void 0!==o?o:[];return!(1===d.length&&d[0]&&(0,c.isReusableBlock)(d[0])&&!!n(B.store).getEntityRecord("postType","wp_block",d[0].attributes.ref))&&a("core/block",u)&&d.every((e=>!!e&&e.isValid&&(0,c.hasBlockSupport)(e.name,"reusable",!0)))&&!!r("create","blocks")}),[e,t]),{__experimentalConvertBlocksToReusable:v}=(0,r.useDispatch)(m),{createSuccessNotice:C,createErrorNotice:S}=(0,r.useDispatch)(y.store),f=(0,b.useCallback)((async function(t){try{await v(e,t,i),C(i?(0,s.sprintf)((0,s.__)("Unsynced Pattern created: %s"),t):(0,s.sprintf)((0,s.__)("Synced Pattern created: %s"),t),{type:"snackbar",id:"convert-to-reusable-block-success"})}catch(e){S(e.message,{type:"snackbar",id:"convert