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

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