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