File: /wordpress/core/beta/wp-includes/js/dist/reusable-blocks.min.js
/*! This file is auto-generated */
var wp;(wp||={}).reusableBlocks=(()=>{var Aa=Object.create;var U=Object.defineProperty;var Ma=Object.getOwnPropertyDescriptor;var Fa=Object.getOwnPropertyNames;var Na=Object.getPrototypeOf,Va=Object.prototype.hasOwnProperty;var d=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports),P=(a,t)=>{for(var o in t)U(a,o,{get:t[o],enumerable:!0})},$=(a,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Fa(t))!Va.call(a,s)&&s!==o&&U(a,s,{get:()=>t[s],enumerable:!(r=Ma(t,s))||r.enumerable});return a};var e=(a,t,o)=>(o=a!=null?Aa(Na(a)):{},$(t||!a||!a.__esModule?U(o,"default",{value:a,enumerable:!0}):o,a)),za=a=>$(U({},"__esModule",{value:!0}),a);var R=d(($a,aa)=>{aa.exports=window.wp.data});var C=d((at,ta)=>{ta.exports=window.wp.blockEditor});var j=d((tt,ea)=>{ea.exports=window.wp.blocks});var I=d((et,oa)=>{oa.exports=window.wp.i18n});var A=d((ot,ra)=>{ra.exports=window.wp.deprecated});var J=d((st,ua)=>{ua.exports=window.wp.element});var K=d((mt,da)=>{da.exports=window.wp.components});var pa=d((ut,ia)=>{ia.exports=window.wp.primitives});var L=d((dt,na)=>{na.exports=window.ReactJSXRuntime});var ba=d((ct,ca)=>{ca.exports=window.wp.notices});var X=d((bt,ha)=>{ha.exports=window.wp.coreData});var ya=d((wt,Ba)=>{Ba.exports=window.wp.url});var Qa={};P(Qa,{ReusableBlocksMenuItems:()=>Ta,store:()=>g});var M=e(R(),1);var q={};P(q,{__experimentalConvertBlockToStatic:()=>Ha,__experimentalConvertBlocksToReusable:()=>Oa,__experimentalDeleteReusableBlock:()=>Pa,__experimentalSetEditingReusableBlock:()=>qa});var k=e(C(),1),b=e(j(),1),fa=e(I(),1),S=e(A(),1),Ha=a=>({registry:t})=>{(0,S.default)("wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlockToStatic",{since:"7.1"});let o=t.select(k.store).getBlock(a),r=t.select("core").getEditedEntityRecord("postType","wp_block",o.attributes.ref),s=(0,b.parse)(typeof r.content=="function"?r.content(r):r.content);t.dispatch(k.store).replaceBlocks(o.clientId,s)},Oa=(a,t,o)=>async({registry:r,dispatch:s})=>{(0,S.default)("wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlocksToReusable",{since:"7.1"});let c=o==="unsynced"?{wp_pattern_sync_status:o}:void 0,u={title:t||(0,fa.__)("Untitled pattern block"),content:(0,b.serialize)(r.select(k.store).getBlocksByClientId(a)),status:"publish",meta:c},w=await r.dispatch("core").saveEntityRecord("postType","wp_block",u);if(o==="unsynced")return;let i=(0,b.createBlock)("core/block",{ref:w.id});r.dispatch(k.store).replaceBlocks(a,i),s.__experimentalSetEditingReusableBlock(i.clientId,!0)},Pa=a=>async({registry:t})=>{if((0,S.default)("wp.data.dispatch( 'core/reusable-blocks' ).__experimentalDeleteReusableBlock",{since:"7.1"}),!t.select("core").getEditedEntityRecord("postType","wp_block",a))return;let c=t.select(k.store).getBlocks().filter(u=>(0,b.isReusableBlock)(u)&&u.attributes.ref===a).map(u=>u.clientId);c.length&&t.dispatch(k.store).removeBlocks(c),await t.dispatch("core").deleteEntityRecord("postType","wp_block",a)};function qa(a,t){return(0,S.default)("wp.data.dispatch( 'core/reusable-blocks' ).__experimentalSetEditingReusableBlock",{since:"7.1"}),{type:"SET_EDITING_REUSABLE_BLOCK",clientId:a,isEditing:t}}var la=e(R(),1);function Ga(a={},t){return t?.type==="SET_EDITING_REUSABLE_BLOCK"?{...a,[t.clientId]:t.isEditing}:a}var sa=(0,la.combineReducers)({isEditingReusableBlock:Ga});var G={};P(G,{__experimentalIsEditingReusableBlock:()=>Ja});var ma=e(A(),1);function Ja(a,t){return(0,ma.default)("wp.data.select( 'core/reusable-blocks' ).__experimentalIsEditingReusableBlock",{since:"7.1"}),a.isEditingReusableBlock[t]}var Ka="core/reusable-blocks",g=(0,M.createReduxStore)(Ka,{actions:q,reducer:sa,selectors:G});(0,M.register)(g);var Sa=e(C(),1),La=e(A(),1);var N=e(j(),1),ka=e(C(),1),y=e(J(),1),l=e(K(),1);var F=e(pa(),1),W=e(L(),1),Q=(0,W.jsx)(F.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",children:(0,W.jsx)(F.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"})});var T=e(R(),1),f=e(I(),1),ga=e(ba(),1),Y=e(X(),1);var m=e(L(),1);function wa({clientIds:a,rootClientId:t,onClose:o}){let[r,s]=(0,y.useState)(void 0),[c,u]=(0,y.useState)(!1),[w,i]=(0,y.useState)(""),z=(0,T.useSelect)(n=>{let{canUser:H}=n(Y.store),{getBlocksByClientId:Ea,canInsertBlockType:Ua,getBlockRootClientId:ja}=n(ka.store),Ia=t||(a.length>0?ja(a[0]):void 0),x=Ea(a)??[];return!(x.length===1&&x[0]&&(0,N.isReusableBlock)(x[0])&&!!n(Y.store).getEntityRecord("postType","wp_block",x[0].attributes.ref))&&Ua("core/block",Ia)&&x.every(O=>!!O&&O.isValid&&(0,N.hasBlockSupport)(O.name,"reusable",!0))&&!!H("create",{kind:"postType",name:"wp_block"})},[a,t]),{__experimentalConvertBlocksToReusable:E}=(0,T.useDispatch)(g),{createSuccessNotice:_,createErrorNotice:B}=(0,T.useDispatch)(ga.store),Da=(0,y.useCallback)(async function(n){try{await E(a,n,r),_(r?(0,f.sprintf)((0,f.__)("Unsynced pattern created: %s"),n):(0,f.sprintf)((0,f.__)("Synced pattern created: %s"),n),{type:"snackbar",id:"convert-to-reusable-block-success"})}catch(H){B(H.message,{type:"snackbar",id:"convert-to-reusable-block-error"})}},[E,a,r,_,B]);return z?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(l.MenuItem,{icon:Q,onClick:()=>u(!0),children:(0,f.__)("Create pattern")}),c&&(0,m.jsx)(l.Modal,{title:(0,f.__)("Create pattern"),onRequestClose:()=>{u(!1),i("")},overlayClassName:"reusable-blocks-menu-items__convert-modal",children:(0,m.jsx)("form",{onSubmit:n=>{n.preventDefault(),Da(w),u(!1),i(""),o()},children:(0,m.jsxs)(l.__experimentalVStack,{spacing:"5",children:[(0,m.jsx)(l.TextControl,{label:(0,f.__)("Name"),value:w,onChange:i,placeholder:(0,f.__)("My pattern")}),(0,m.jsx)(l.ToggleControl,{label:(0,f._x)("Synced","pattern (singular)"),help:(0,f.__)("Sync this pattern across multiple locations."),checked:!r,onChange:()=>{s(r?void 0:"unsynced")}}),(0,m.jsxs)(l.__experimentalHStack,{justify:"right",children:[(0,m.jsx)(l.Button,{__next40pxDefaultSize:!0,variant:"tertiary",onClick:()=>{u(!1),i("")},children:(0,f.__)("Cancel")}),(0,m.jsx)(l.Button,{__next40pxDefaultSize:!0,variant:"primary",type:"submit",children:(0,f.__)("Create")})]})]})})})]}):null}var D=e(K(),1),v=e(I(),1),va=e(j(),1),V=e(R(),1),_a=e(J(),1),xa=e(C(),1),Z=e(ya(),1),Ra=e(X(),1);var p=e(L(),1);function Wa({clientId:a}){let[t,o]=(0,_a.useState)(!1),{canRemove:r,isVisible:s,managePatternsUrl:c}=(0,V.useSelect)(i=>{let{getBlock:z,canRemoveBlock:E}=i(xa.store),{canUser:_}=i(Ra.store),B=z(a);return{canRemove:E(a),isVisible:!!B&&(0,va.isReusableBlock)(B)&&!!_("update",{kind:"postType",name:"wp_block",id:B.attributes.ref}),managePatternsUrl:_("create",{kind:"postType",name:"wp_template"})?(0,Z.addQueryArgs)("site-editor.php",{p:"/pattern"}):(0,Z.addQueryArgs)("edit.php",{post_type:"wp_block"})}},[a]),{__experimentalConvertBlockToStatic:u}=(0,V.useDispatch)(g);if(!s)return null;let w=()=>{u(a),o(!1)};return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(D.MenuItem,{href:c,children:(0,v.__)("Manage patterns")}),r&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(D.MenuItem,{onClick:()=>o(!0),children:(0,v.__)("Disconnect pattern")}),(0,p.jsx)(D.__experimentalConfirmDialog,{isOpen:t,onConfirm:w,onCancel:()=>o(!1),confirmButtonText:(0,v.__)("Disconnect"),size:"medium",title:(0,v.__)("Disconnect pattern?"),__experimentalHideHeader:!1,children:(0,v.__)("Blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here.")})]})]})}var Ca=Wa;var h=e(L(),1);function Ta({rootClientId:a}){return(0,La.default)("wp.reusableBlocks.ReusableBlocksMenuItems",{since:"7.1"}),(0,h.jsx)(Sa.BlockSettingsMenuControls,{children:({onClose:t,selectedClientIds:o})=>(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(wa,{clientIds:o,rootClientId:a,onClose:t}),o.length===1&&(0,h.jsx)(Ca,{clientId:o[0]})]})})}return za(Qa);})();