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