WordPress/wp-includes/js/dist/reusable-blocks.min.js
isabel_brison 2405b7fbf7 Editor: update npm packages with bug fixes and blessed tasks.
Includes miscellaneous bug fixes and enhancements to the Library task (#58579) and to the Command Palette task (#58643).

See #58745.

Built from https://develop.svn.wordpress.org/trunk@56159


git-svn-id: http://core.svn.wordpress.org/trunk@55671 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-07-07 07:21:17 +00:00

2 lines
6.0 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 C},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?{wp_pattern_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 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,E=window.wp.coreData;function f({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(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:y,createErrorNotice:f}=(0,c.useDispatch)(g.store),B=(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){f(e.message,{type:"snackbar",id:"convert-to-reusable-block-error"})}}),[_,e,n,y,f]);return p?(0,b.createElement)(o.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(),B(u),i(!1),d(""),e()}},(0,b.createElement)(k.__experimentalVStack,{spacing:"5"},(0,b.createElement)(o.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 B=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,b.createElement)(o.BlockSettingsMenuControls,null,(0,b.createElement)(k.MenuItem,{href:(0,B.addQueryArgs)("edit.php",{post_type:"wp_block"})},(0,a.__)("Manage Patterns")),t&&(0,b.createElement)(k.MenuItem,{onClick:()=>s(e)},r>1?(0,a.__)("Detach patterns"):(0,a.__)("Detach pattern"))):null};var C=(0,c.withSelect)((e=>{const{getSelectedBlockClientIds:t}=e(o.store);return{clientIds:t()}}))((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)(v,{clientId:e[0]}))}));(window.wp=window.wp||{}).reusableBlocks=t}();