WordPress/wp-includes/js/dist/block-directory.min.js

2 lines
20 KiB
JavaScript
Raw Normal View History

/*! This file is auto-generated */
(()=>{"use strict";var e={n:t=>{var l=t&&t.__esModule?()=>t.default:()=>t;return e.d(l,{a:l}),l},d:(t,l)=>{for(var s in l)e.o(l,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:l[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r: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,{store:()=>G});var l={};e.r(l),e.d(l,{getDownloadableBlocks:()=>h,getErrorNoticeForBlock:()=>f,getErrorNotices:()=>y,getInstalledBlockTypes:()=>m,getNewBlockTypes:()=>g,getUnusedBlockTypes:()=>w,isInstalling:()=>_,isRequestingDownloadableBlocks:()=>k});var s={};e.r(s),e.d(s,{addInstalledBlockType:()=>C,clearErrorNotice:()=>P,fetchDownloadableBlocks:()=>T,installBlockType:()=>S,receiveDownloadableBlocks:()=>L,removeInstalledBlockType:()=>A,setErrorNotice:()=>D,setIsInstalling:()=>R,uninstallBlockType:()=>O});var o={};e.r(o),e.d(o,{getDownloadableBlocks:()=>Y});const n=window.wp.plugins,r=window.wp.hooks,i=window.wp.blocks,a=window.wp.data,c=window.wp.element,d=window.wp.editor,u=(0,a.combineReducers)({downloadableBlocks:(e={},t)=>{switch(t.type){case"FETCH_DOWNLOADABLE_BLOCKS":return{...e,[t.filterValue]:{isRequesting:!0}};case"RECEIVE_DOWNLOADABLE_BLOCKS":return{...e,[t.filterValue]:{results:t.downloadableBlocks,isRequesting:!1}}}return e},blockManagement:(e={installedBlockTypes:[],isInstalling:{}},t)=>{switch(t.type){case"ADD_INSTALLED_BLOCK_TYPE":return{...e,installedBlockTypes:[...e.installedBlockTypes,t.item]};case"REMOVE_INSTALLED_BLOCK_TYPE":return{...e,installedBlockTypes:e.installedBlockTypes.filter((e=>e.name!==t.item.name))};case"SET_INSTALLING_BLOCK":return{...e,isInstalling:{...e.isInstalling,[t.blockId]:t.isInstalling}}}return e},errorNotices:(e={},t)=>{switch(t.type){case"SET_ERROR_NOTICE":return{...e,[t.blockId]:{message:t.message,isFatal:t.isFatal}};case"CLEAR_ERROR_NOTICE":const{[t.blockId]:l,...s}=e;return s}return e}}),p=window.wp.blockEditor;function b(e,t=[]){if(!t.length)return!1;if(t.some((({name:t})=>t===e.name)))return!0;for(let l=0;l<t.length;l++)if(b(e,t[l].innerBlocks))return!0;return!1}function k(e,t){var l;return null!==(l=e.downloadableBlocks[t]?.isRequesting)&&void 0!==l&&l}function h(e,t){var l;return null!==(l=e.downloadableBlocks[t]?.results)&&void 0!==l?l:[]}function m(e){return e.blockManagement.installedBlockTypes}const g=(0,a.createRegistrySelector)((e=>t=>{const l=e(p.store).getBlocks();return m(t).filter((e=>b(e,l)))})),w=(0,a.createRegistrySelector)((e=>t=>{const l=e(p.store).getBlocks();return m(t).filter((e=>!b(e,l)))}));function _(e,t){return e.blockManagement.isInstalling[t]||!1}function y(e){return e.errorNotices}function f(e,t){return e.errorNotices[t]}const v=window.wp.i18n,x=window.wp.apiFetch;var j=e.n(x);const B=window.wp.notices,E=window.wp.url,I=e=>new Promise(((t,l)=>{const s=document.createElement(e.nodeName);["id","rel","src","href","type"].forEach((t=>{e[t]&&(s[t]=e[t])})),e.innerHTML&&s.appendChild(document.createTextNode(e.innerHTML)),s.onload=()=>t(!0),s.onerror=()=>l(new Error("Error loading asset.")),document.body.appendChild(s),("link"===s.nodeName.toLowerCase()||"script"===s.nodeName.toLowerCase()&&!s.src)&&t()}));function N(e){if(!e)return!1;const t=e.links["wp:plugin"]||e.links.self;return!(!t||!t.length)&&t[0].href}function T(e){return{type:"FETCH_DOWNLOADABLE_BLOCKS",filterValue:e}}function L(e,t){return{type:"RECEIVE_DOWNLOADABLE_BLOCKS",downloadableBlocks:e,filterValue:t}}const S=e=>async({registry:t,dispatch:l})=>{const{id:s,name:o}=e;let n=!1;l.clearErrorNotice(s);try{l.setIsInstalling(s,!0);const r=N(e);let a={};if(r)await j()({method:"PUT",url:r,data:{status:"active"}});else{a=(await j()({method:"POST",path:"wp/v2/plugins",data:{slug:s,status:"active"}}))._links}l.addInstalledBlockType({...e,links:{...e.links,...a}});const c=["api_version","title","category","parent","icon","description","keywords","attributes","provides_context","uses_context","supports","styles","example","variations"];await j()({path:(0,E.addQueryArgs)(`