2 lines
5.9 KiB
JavaScript
2 lines
5.9 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,{ReusableBlocksMenuItems:function(){return h},store:function(){return m}});var n={};e.r(n),e.d(n,{__experimentalConvertBlockToStatic:function(){return s},__experimentalConvertBlocksToReusable:function(){return i},__experimentalDeleteReusableBlock:function(){return u},__experimentalSetEditingReusableBlock:function(){return d}});var r={};e.r(r),e.d(r,{__experimentalIsEditingReusableBlock:function(){return _}});var c=window.wp.data,o=window.wp.blockEditor,l=window.wp.blocks,a=window.wp.i18n;const s=e=>({registry:t})=>{const n=t.select(o.store).getBlock(e),r=t.select("core").getEditedEntityRecord("postType","wp_block",n.attributes.ref),c=(0,l.parse)("function"==typeof r.content?r.content(r):r.content);t.dispatch(o.store).replaceBlocks(n.clientId,c)},i=(e,t,n)=>async({registry:r,dispatch:c})=>{const s="unsynced"===n?{sync_status:n}:void 0,i={title:t||(0,a.__)("Untitled Pattern block"),content:(0,l.serialize)(r.select(o.store).getBlocksByClientId(e)),status:"publish",meta:s},u=await r.dispatch("core").saveEntityRecord("postType","wp_block",i);if("unsynced"===n)return;const d=(0,l.createBlock)("core/block",{ref:u.id});r.dispatch(o.store).replaceBlocks(e,d),c.__experimentalSetEditingReusableBlock(d.clientId,!0)},u=e=>async({registry:t})=>{if(!t.select("core").getEditedEntityRecord("postType","wp_block",e))return;const n=t.select(o.store).getBlocks().filter((t=>(0,l.isReusableBlock)(t)&&t.attributes.ref===e)).map((e=>e.clientId));n.length&&t.dispatch(o.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}}var p=(0,c.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,c.createReduxStore)("core/reusable-blocks",{actions:n,reducer:p,selectors:r});(0,c.register)(m);var k=window.wp.element,y=window.wp.components,b=window.wp.primitives;var w=(0,k.createElement)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,k.createElement)(b.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"})),g=window.wp.notices,E=window.wp.coreData;function B({clientIds:e,rootClientId:t}){const[n,r]=(0,k.useState)("unsynced"),[s,i]=(0,k.useState)(!1),[u,d]=(0,k.useState)(""),p=(0,c.useSelect)((n=>{var r;const{canUser:c}=n(E.store),{getBlocksByClientId:a,canInsertBlockType:s}=n(o.store),i=null!==(r=a(e))&&void 0!==r?r:[];return!(1===i.length&&i[0]&&(0,l.isReusableBlock)(i[0])&&!!n(E.store).getEntityRecord("postType","wp_block",i[0].attributes.ref))&&s("core/block",t)&&i.every((e=>!!e&&e.isValid&&(0,l.hasBlockSupport)(e.name,"reusable",!0)))&&!!c("create","blocks")}),[e,t]),{__experimentalConvertBlocksToReusable:_}=(0,c.useDispatch)(m),{createSuccessNotice:b,createErrorNotice:B}=(0,c.useDispatch)(g.store),f=(0,k.useCallback)((async function(t){try{await _(e,t,n),b("fully"===n?(0,a.__)("Synced Pattern created."):(0,a.__)("Unsynced Pattern created."),{type:"snackbar"})}catch(e){B(e.message,{type:"snackbar"})}}),[_,e,n,b,B]);return p?(0,k.createElement)(o.BlockSettingsMenuControls,null,(({onClose:e})=>(0,k.createElement)(k.Fragment,null,(0,k.createElement)(y.MenuItem,{icon:w,onClick:()=>i(!0)},(0,a.__)("Create pattern")),s&&(0,k.createElement)(y.Modal,{title:(0,a.__)("Create pattern"),onRequestClose:()=>{i(!1),d("")},overlayClassName:"reusable-blocks-menu-items__convert-modal"},(0,k.createElement)("form",{onSubmit:t=>{t.preventDefault(),f(u),i(!1),d(""),e()}},(0,k.createElement)(y.__experimentalVStack,{spacing:"5"},(0,k.createElement)(y.TextControl,{__nextHasNoMarginBottom:!0,label:(0,a.__)("Name"),value:u,onChange:d,placeholder:(0,a.__)("My pattern")}),(0,k.createElement)(y.ToggleControl,{label:(0,a.__)("Keep all pattern instances in sync"),help:(0,a.__)("Editing the original pattern will also update anywhere the pattern is used."),checked:"fully"===n,onChange:()=>{r("fully"===n?"unsynced":"fully")}}),(0,k.createElement)(y.__experimentalHStack,{justify:"right"},(0,k.createElement)(y.Button,{variant:"tertiary",onClick:()=>{i(!1),d("")}},(0,a.__)("Cancel")),(0,k.createElement)(y.Button,{variant:"primary",type:"submit"},(0,a.__)("Create"))))))))):null}var f=window.wp.url;var v=function({clientId:e}){const{canRemove:t,isVisible:n,innerBlockCount:r}=(0,c.useSelect)((t=>{const{getBlock:n,canRemoveBlock:r,getBlockCount:c}=t(o.store),{canUser:a}=t(E.store),s=n(e);return{canRemove:r(e),isVisible:!!s&&(0,l.isReusableBlock)(s)&&!!a("update","blocks",s.attributes.ref),innerBlockCount:c(e)}}),[e]),{__experimentalConvertBlockToStatic:s}=(0,c.useDispatch)(m);return n?(0,k.createElement)(o.BlockSettingsMenuControls,null,(0,k.createElement)(y.MenuItem,{href:(0,f.addQueryArgs)("edit.php",{post_type:"wp_block"})},(0,a.__)("Manage Patterns")),t&&(0,k.createElement)(y.MenuItem,{onClick:()=>s(e)},r>1?(0,a.__)("Detach patterns"):(0,a.__)("Detach pattern"))):null};var h=(0,c.withSelect)((e=>{const{getSelectedBlockClientIds:t}=e(o.store);return{clientIds:t()}}))((function({clientIds:e,rootClientId:t}){return(0,k.createElement)(k.Fragment,null,(0,k.createElement)(B,{clientIds:e,rootClientId:t}),1===e.length&&(0,k.createElement)(v,{clientId:e[0]}))}));(window.wp=window.wp||{}).reusableBlocks=t}(); |