WordPress/wp-includes/js/dist/block-directory.min.js
youknowriad 1de40f71be Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress. 
This includes features like:

 - DataViews.
 - Customization tools like box shadow, background size and repeat.
 - UI improvements in the site editor. 
 - Preferences sharing between the post and site editors.
 - Unified panels and editors between post and site editors.
 - Improved template mode in the post editor.
 - Iterations to multiple interactive blocks.
 - Preparing the blocks and UI for pattern overrides.
 - and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377


git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 21:07:12 +00:00

2 lines
21 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! This file is auto-generated */
!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var l in n)e.o(n,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:n[l]})},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,{store:function(){return W}});var n={};e.r(n),e.d(n,{getDownloadableBlocks:function(){return g},getErrorNoticeForBlock:function(){return h},getErrorNotices:function(){return y},getInstalledBlockTypes:function(){return f},getNewBlockTypes:function(){return w},getUnusedBlockTypes:function(){return _},isInstalling:function(){return E},isRequestingDownloadableBlocks:function(){return b}});var l={};e.r(l),e.d(l,{addInstalledBlockType:function(){return D},clearErrorNotice:function(){return F},fetchDownloadableBlocks:function(){return O},installBlockType:function(){return A},receiveDownloadableBlocks:function(){return C},removeInstalledBlockType:function(){return P},setErrorNotice:function(){return x},setIsInstalling:function(){return M},uninstallBlockType:function(){return R}});var r={};e.r(r),e.d(r,{getDownloadableBlocks:function(){return q}});var o=window.React,a=window.wp.plugins,s=window.wp.hooks,i=window.wp.blocks,c=window.wp.data,d=window.wp.element,u=window.wp.editor;var m=(0,c.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]:n,...l}=e;return l}return e}}),p=window.wp.blockEditor;function k(e,t=[]){if(!t.length)return!1;if(t.some((({name:t})=>t===e.name)))return!0;for(let n=0;n<t.length;n++)if(k(e,t[n].innerBlocks))return!0;return!1}function b(e,t){var n;return null!==(n=e.downloadableBlocks[t]?.isRequesting)&&void 0!==n&&n}function g(e,t){var n;return null!==(n=e.downloadableBlocks[t]?.results)&&void 0!==n?n:[]}function f(e){return e.blockManagement.installedBlockTypes}const w=(0,c.createRegistrySelector)((e=>t=>{const n=e(p.store).getBlocks();return f(t).filter((e=>k(e,n)))})),_=(0,c.createRegistrySelector)((e=>t=>{const n=e(p.store).getBlocks();return f(t).filter((e=>!k(e,n)))}));function E(e,t){return e.blockManagement.isInstalling[t]||!1}function y(e){return e.errorNotices}function h(e,t){return e.errorNotices[t]}var v=window.wp.i18n,B=window.wp.apiFetch,N=e.n(B),I=window.wp.notices,T=window.wp.url;const L=e=>new Promise(((t,n)=>{const l=document.createElement(e.nodeName);["id","rel","src","href","type"].forEach((t=>{e[t]&&(l[t]=e[t])})),e.innerHTML&&l.appendChild(document.createTextNode(e.innerHTML)),l.onload=()=>t(!0),l.onerror=()=>n(new Error("Error loading asset.")),document.body.appendChild(l),("link"===l.nodeName.toLowerCase()||"script"===l.nodeName.toLowerCase()&&!l.src)&&t()}));function S(e){if(!e)return!1;const t=e.links["wp:plugin"]||e.links.self;return!(!t||!t.length)&&t[0].href}function O(e){return{type:"FETCH_DOWNLOADABLE_BLOCKS",filterValue:e}}function C(e,t){return{type:"RECEIVE_DOWNLOADABLE_BLOCKS",downloadableBlocks:e,filterValue:t}}const A=e=>async({registry:t,dispatch:n})=>{const{id:l,name:r}=e;let o=!1;n.clearErrorNotice(l);try{n.setIsInstalling(l,!0);const a=S(e);let s={};if(a)await N()({method:"PUT",url:a,data:{status:"active"}});else{s=(await N()({method:"POST",path:"wp/v2/plugins",data:{slug:l,status:"active"}}))._links}n.addInstalledBlockType({...e,links:{...e.links,...s}});const c=["api_version","title","category","parent","icon","description","keywords","attributes","provides_context","uses_context","supports","styles","example","variations"];await N()({path:(0,T.addQueryArgs)(`/wp/v2/block-types/${r}`,{_fields:c})}).catch((()=>{})).then((e=>{e&&(0,i.unstable__bootstrapServerSideBlockDefinitions)({[r]:Object.fromEntries(Object.entries(e).filter((([e])=>c.includes(e))))})})),await async function(){const e=await N()({url:document.location.href,parse:!1}),t=await e.text(),n=(new window.DOMParser).parseFromString(t,"text/html"),l=Array.from(n.querySelectorAll('link[rel="stylesheet"],script')).filter((e=>e.id&&!document.getElementById(e.id)));for(const e of l)await L(e)}();if(!t.select(i.store).getBlockTypes().some((e=>e.name===r)))throw new Error((0,v.__)("Error registering block. Try reloading the page."));t.dispatch(I.store).createInfoNotice((0,v.sprintf)((0,v.__)("Block %s installed and added."),e.title),{speak:!0,type:"snackbar"}),o=!0}catch(e){let r=e.message||(0,v.__)("An error occurred."),o=e instanceof Error;const a={folder_exists:(0,v.__)("This block is already installed. Try reloading the page."),unable_to_connect_to_filesystem:(0,v.__)("Error installing block. You can reload the page and try again.")};a[e.code]&&(o=!0,r=a[e.code]),n.setErrorNotice(l,r,o),t.dispatch(I.store).createErrorNotice(r,{speak:!0,isDismissible:!0})}return n.setIsInstalling(l,!1),o},R=e=>async({registry:t,dispatch:n})=>{try{const t=S(e);await N()({method:"PUT",url:t,data:{status:"inactive"}}),await N()({method:"DELETE",url:t}),n.removeInstalledBlockType(e)}catch(e){t.dispatch(I.store).createErrorNotice(e.message||(0,v.__)("An error occurred."))}};function D(e){return{type:"ADD_INSTALLED_BLOCK_TYPE",item:e}}function P(e){return{type:"REMOVE_INSTALLED_BLOCK_TYPE",item:e}}function M(e,t){return{type:"SET_INSTALLING_BLOCK",blockId:e,isInstalling:t}}function x(e,t,n=!1){return{type:"SET_ERROR_NOTICE",blockId:e,message:t,isFatal:n}}function F(e){return{type:"CLEAR_ERROR_NOTICE",blockId:e}}var V=function(){return V=Object.assign||function(e){for(var t,n=1,l=arguments.length;n<l;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},V.apply(this,arguments)};Object.create;Object.create;"function"==typeof SuppressedError&&SuppressedError;function H(e){return e.toLowerCase()}var $=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],j=/[^A-Z0-9]+/gi;function z(e,t,n){return t instanceof RegExp?e.replace(t,n):t.reduce((function(e,t){return e.replace(t,n)}),e)}function K(e,t){var n=e.charAt(0),l=e.substr(1).toLowerCase();return t>0&&n>="0"&&n<="9"?"_"+n+l:""+n.toUpperCase()+l}function U(e,t){return void 0===t&&(t={}),function(e,t){void 0===t&&(t={});for(var n=t.splitRegexp,l=void 0===n?$:n,r=t.stripRegexp,o=void 0===r?j:r,a=t.transform,s=void 0===a?H:a,i=t.delimiter,c=void 0===i?" ":i,d=z(z(e,l,"$1\0$2"),o,"\0"),u=0,m=d.length;"\0"===d.charAt(u);)u++;for(;"\0"===d.charAt(m-1);)m--;return d.slice(u,m).split("\0").map(s).join(c)}(e,V({delimiter:"",transform:K},t))}function Y(e,t){return 0===t?e.toLowerCase():K(e,t)}const q=e=>async({dispatch:t})=>{if(e)try{t(O(e));const n=await N()({path:`wp/v2/block-directory/search?term=${e}`});t(C(n.map((e=>Object.fromEntries(Object.entries(e).map((([e,t])=>{return[(n=e,void 0===l&&(l={}),U(n,V({transform:Y},l))),t];var n,l}))))),e))}catch{}},G={reducer:m,selectors:n,actions:l,resolvers:r},W=(0,c.createReduxStore)("core/block-directory",G);function Z(){const{uninstallBlockType:e}=(0,c.useDispatch)(W),t=(0,c.useSelect)((e=>{const{isAutosavingPost:t,isSavingPost:n}=e(u.store);return n()&&!t()}),[]),n=(0,c.useSelect)((e=>e(W).getUnusedBlockTypes()),[]);return(0,d.useEffect)((()=>{t&&n.length&&n.forEach((t=>{e(t),(0,i.unregisterBlockType)(t.name)}))}),[t]),null}(0,c.register)(W);var Q=window.wp.compose,J=window.wp.components,X=window.wp.coreData,ee=window.wp.htmlEntities;var te=(0,d.forwardRef)((function({icon:e,size:t=24,...n},l){return(0,d.cloneElement)(e,{width:t,height:t,...n,ref:l})})),ne=window.wp.primitives;var le=(0,o.createElement)(ne.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(ne.Path,{d:"M11.776 4.454a.25.25 0 01.448 0l2.069 4.192a.25.25 0 00.188.137l4.626.672a.25.25 0 01.139.426l-3.348 3.263a.25.25 0 00-.072.222l.79 4.607a.25.25 0 01-.362.263l-4.138-2.175a.25.25 0 00-.232 0l-4.138 2.175a.25.25 0 01-.363-.263l.79-4.607a.25.25 0 00-.071-.222L4.754 9.881a.25.25 0 01.139-.426l4.626-.672a.25.25 0 00.188-.137l2.069-4.192z"}));var re=(0,o.createElement)(ne.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(ne.Path,{d:"M9.518 8.783a.25.25 0 00.188-.137l2.069-4.192a.25.25 0 01.448 0l2.07 4.192a.25.25 0 00.187.137l4.626.672a.25.25 0 01.139.427l-3.347 3.262a.25.25 0 00-.072.222l.79 4.607a.25.25 0 01-.363.264l-4.137-2.176a.25.25 0 00-.233 0l-4.138 2.175a.25.25 0 01-.362-.263l.79-4.607a.25.25 0 00-.072-.222L4.753 9.882a.25.25 0 01.14-.427l4.625-.672zM12 14.533c.28 0 .559.067.814.2l1.895.997-.362-2.11a1.75 1.75 0 01.504-1.55l1.533-1.495-2.12-.308a1.75 1.75 0 01-1.317-.957L12 7.39v7.143z"}));var oe=(0,o.createElement)(ne.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(ne.Path,{fillRule:"evenodd",d:"M9.706 8.646a.25.25 0 01-.188.137l-4.626.672a.25.25 0 00-.139.427l3.348 3.262a.25.25 0 01.072.222l-.79 4.607a.25.25 0 00.362.264l4.138-2.176a.25.25 0 01.233 0l4.137 2.175a.25.25 0 00.363-.263l-.79-4.607a.25.25 0 01.072-.222l3.347-3.262a.25.25 0 00-.139-.427l-4.626-.672a.25.25 0 01-.188-.137l-2.069-4.192a.25.25 0 00-.448 0L9.706 8.646zM12 7.39l-.948 1.921a1.75 1.75 0 01-1.317.957l-2.12.308 1.534 1.495c.412.402.6.982.503 1.55l-.362 2.11 1.896-.997a1.75 1.75 0 011.629 0l1.895.997-.362-2.11a1.75 1.75 0 01.504-1.55l1.533-1.495-2.12-.308a1.75 1.75 0 01-1.317-.957L12 7.39z",clipRule:"evenodd"}));var ae=function({rating:e}){const t=.5*Math.round(e/.5),n=Math.floor(e),l=Math.ceil(e-n),r=5-(n+l);return(0,o.createElement)("span",{"aria-label":(0,v.sprintf)((0,v.__)("%s out of 5 stars"),t)},Array.from({length:n}).map(((e,t)=>(0,o.createElement)(te,{key:`full_stars_${t}`,className:"block-directory-block-ratings__star-full",icon:le,size:16}))),Array.from({length:l}).map(((e,t)=>(0,o.createElement)(te,{key:`half_stars_${t}`,className:"block-directory-block-ratings__star-half-full",icon:re,size:16}))),Array.from({length:r}).map(((e,t)=>(0,o.createElement)(te,{key:`empty_stars_${t}`,className:"block-directory-block-ratings__star-empty",icon:oe,size:16}))))};var se=({rating:e})=>(0,o.createElement)("span",{className:"block-directory-block-ratings"},(0,o.createElement)(ae,{rating:e}));var ie=function({icon:e}){const t="block-directory-downloadable-block-icon";return null!==e.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/)?(0,o.createElement)("img",{className:t,src:e,alt:""}):(0,o.createElement)(p.BlockIcon,{className:t,icon:e,showColors:!0})};var ce=({block:e})=>{const t=(0,c.useSelect)((t=>t(W).getErrorNoticeForBlock(e.id)),[e]);return t?(0,o.createElement)("div",{className:"block-directory-downloadable-block-notice"},(0,o.createElement)("div",{className:"block-directory-downloadable-block-notice__content"},t.message,t.isFatal?" "+(0,v.__)("Try reloading the page."):null)):null},de=window.wp.privateApis;const{lock:ue,unlock:me}=(0,de.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.","@wordpress/block-directory"),{CompositeItemV2:pe}=me(J.privateApis);function ke({title:e,rating:t,ratingCount:n},{hasNotice:l,isInstalled:r,isInstalling:o}){const a=.5*Math.round(t/.5);return!r&&l?(0,v.sprintf)("Retry installing %s.",(0,ee.decodeEntities)(e)):r?(0,v.sprintf)("Add %s.",(0,ee.decodeEntities)(e)):o?(0,v.sprintf)("Installing %s.",(0,ee.decodeEntities)(e)):n<1?(0,v.sprintf)("Install %s.",(0,ee.decodeEntities)(e)):(0,v.sprintf)((0,v._n)("Install %1$s. %2$s stars with %3$s review.","Install %1$s. %2$s stars with %3$s reviews.",n),(0,ee.decodeEntities)(e),a,n)}var be=function({composite:e,item:t,onClick:n}){const{author:l,description:r,icon:a,rating:s,title:u}=t,m=!!(0,i.getBlockType)(t.name),{hasNotice:p,isInstalling:k,isInstallable:b}=(0,c.useSelect)((e=>{const{getErrorNoticeForBlock:n,isInstalling:l}=e(W),r=n(t.id),o=r&&r.isFatal;return{hasNotice:!!r,isInstalling:l(t.id),isInstallable:!o}}),[t]);let g="";return m?g=(0,v.__)("Installed!"):k&&(g=(0,v.__)("Installing…")),(0,o.createElement)(pe,{render:(0,o.createElement)(J.Button,{__experimentalIsFocusable:!0,type:"button",role:"option",className:"block-directory-downloadable-block-list-item",isBusy:k,onClick:e=>{e.preventDefault(),n()},label:ke(t,{hasNotice:p,isInstalled:m,isInstalling:k}),showTooltip:!0,tooltipPosition:"top center"}),store:e,disabled:k||!b},(0,o.createElement)("div",{className:"block-directory-downloadable-block-list-item__icon"},(0,o.createElement)(ie,{icon:a,title:u}),k?(0,o.createElement)("span",{className:"block-directory-downloadable-block-list-item__spinner"},(0,o.createElement)(J.Spinner,null)):(0,o.createElement)(se,{rating:s})),(0,o.createElement)("span",{className:"block-directory-downloadable-block-list-item__details"},(0,o.createElement)("span",{className:"block-directory-downloadable-block-list-item__title"},(0,d.createInterpolateElement)((0,v.sprintf)((0,v.__)("%1$s <span>by %2$s</span>"),(0,ee.decodeEntities)(u),l),{span:(0,o.createElement)("span",{className:"block-directory-downloadable-block-list-item__author"})})),p?(0,o.createElement)(ce,{block:t}):(0,o.createElement)(o.Fragment,null,(0,o.createElement)("span",{className:"block-directory-downloadable-block-list-item__desc"},g||(0,ee.decodeEntities)(r)),b&&!(m||k)&&(0,o.createElement)(J.VisuallyHidden,null,(0,v.__)("Install block")))))};const{CompositeV2:ge,useCompositeStoreV2:fe}=me(J.privateApis),we=()=>{};var _e=function({items:e,onHover:t=we,onSelect:n}){const l=fe(),{installBlockType:r}=(0,c.useDispatch)(W);return e.length?(0,o.createElement)(ge,{store:l,role:"listbox",className:"block-directory-downloadable-blocks-list","aria-label":(0,v.__)("Blocks available for install")},e.map((e=>(0,o.createElement)(be,{key:e.id,composite:l,onClick:()=>{(0,i.getBlockType)(e.name)?n(e):r(e).then((t=>{t&&n(e)})),t(null)},onHover:t,item:e})))):null},Ee=window.wp.a11y;var ye=function({children:e,downloadableItems:t,hasLocalBlocks:n}){const l=t.length;return(0,d.useEffect)((()=>{(0,Ee.speak)((0,v.sprintf)((0,v._n)("%d additional block is available to install.","%d additional blocks are available to install.",l),l))}),[l]),(0,o.createElement)(o.Fragment,null,!n&&(0,o.createElement)("p",{className:"block-directory-downloadable-blocks-panel__no-local"},(0,v.__)("No results available from your installed blocks.")),(0,o.createElement)("div",{className:"block-editor-inserter__quick-inserter-separator"}),(0,o.createElement)("div",{className:"block-directory-downloadable-blocks-panel"},(0,o.createElement)("div",{className:"block-directory-downloadable-blocks-panel__header"},(0,o.createElement)("h2",{className:"block-directory-downloadable-blocks-panel__title"},(0,v.__)("Available to install")),(0,o.createElement)("p",{className:"block-directory-downloadable-blocks-panel__description"},(0,v.__)("Select a block to install and add it to your post."))),e))};var he=(0,o.createElement)(ne.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,o.createElement)(ne.Path,{d:"M19 8h-1V6h-5v2h-2V6H6v2H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2zm.5 10c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5v-8c0-.3.2-.5.5-.5h14c.3 0 .5.2.5.5v8z"}));var ve=function(){return(0,o.createElement)(o.Fragment,null,(0,o.createElement)("div",{className:"block-editor-inserter__no-results"},(0,o.createElement)(te,{className:"block-editor-inserter__no-results-icon",icon:he}),(0,o.createElement)("p",null,(0,v.__)("No results found."))),(0,o.createElement)("div",{className:"block-editor-inserter__tips"},(0,o.createElement)(J.Tip,null,(0,v.__)("Interested in creating your own block?"),(0,o.createElement)("br",null),(0,o.createElement)(J.ExternalLink,{href:"https://developer.wordpress.org/block-editor/"},(0,v.__)("Get started here"),"."))))};const Be=[],Ne=e=>(0,c.useSelect)((t=>{const{getDownloadableBlocks:n,isRequestingDownloadableBlocks:l,getInstalledBlockTypes:r}=t(W),o=t(X.store).canUser("read","block-directory/search");let a=Be;if(o){a=n(e);const t=r(),l=a.filter((({name:e})=>{const n=t.some((t=>t.name===e)),l=(0,i.getBlockType)(e);return n||!l}));l.length!==a.length&&(a=l),0===a.length&&(a=Be)}return{hasPermission:o,downloadableBlocks:a,isLoading:l(e)}}),[e]);function Ie({onSelect:e,onHover:t,hasLocalBlocks:n,isTyping:l,filterValue:r}){const{hasPermission:a,downloadableBlocks:s,isLoading:i}=Ne(r);return void 0===a||i||l?(0,o.createElement)(o.Fragment,null,a&&!n&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)("p",{className:"block-directory-downloadable-blocks-panel__no-local"},(0,v.__)("No results available from your installed blocks.")),(0,o.createElement)("div",{className:"block-editor-inserter__quick-inserter-separator"})),(0,o.createElement)("div",{className:"block-directory-downloadable-blocks-panel has-blocks-loading"},(0,o.createElement)(J.Spinner,null))):!1===a||0===s.length?n?null:(0,o.createElement)(ve,null):(0,o.createElement)(ye,{downloadableItems:s,hasLocalBlocks:n},(0,o.createElement)(_e,{items:s,onSelect:e,onHover:t}))}var Te,Le=function(){const[e,t]=(0,d.useState)(""),n=(0,Q.debounce)(t,400);return(0,o.createElement)(p.__unstableInserterMenuExtension,null,(({onSelect:t,onHover:l,filterValue:r,hasItems:a})=>(e!==r&&n(r),e?(0,o.createElement)(Ie,{onSelect:t,onHover:l,filterValue:e,hasLocalBlocks:a,isTyping:r!==e}):null)))};function Se({items:e}){return e.length?(0,o.createElement)("ul",{className:"block-directory-compact-list"},e.map((({icon:e,id:t,title:n,author:l})=>(0,o.createElement)("li",{key:t,className:"block-directory-compact-list__item"},(0,o.createElement)(ie,{icon:e,title:n}),(0,o.createElement)("div",{className:"block-directory-compact-list__item-details"},(0,o.createElement)("div",{className:"block-directory-compact-list__item-title"},n),(0,o.createElement)("div",{className:"block-directory-compact-list__item-author"},(0,v.sprintf)((0,v.__)("By %s"),l))))))):null}const{PluginPrePublishPanel:Oe}=null!==(Te=window?.wp?.editPost)&&void 0!==Te?Te:{};function Ce(){const e=(0,c.useSelect)((e=>e(W).getNewBlockTypes()),[]);return e.length?(0,o.createElement)(Oe,{icon:he,title:(0,v.sprintf)((0,v._n)("Added: %d block","Added: %d blocks",e.length),e.length),initialOpen:!0},(0,o.createElement)("p",{className:"installed-blocks-pre-publish-panel__copy"},(0,v._n)("The following block has been added to your site.","The following blocks have been added to your site.",e.length)),(0,o.createElement)(Se,{items:e})):null}function Ae({attributes:e,block:t,clientId:n}){const l=(0,c.useSelect)((e=>e(W).isInstalling(t.id)),[t.id]),{installBlockType:r}=(0,c.useDispatch)(W),{replaceBlock:a}=(0,c.useDispatch)(p.store);return(0,o.createElement)(J.Button,{onClick:()=>r(t).then((l=>{if(l){const l=(0,i.getBlockType)(t.name),[r]=(0,i.parse)(e.originalContent);r&&l&&a(n,(0,i.createBlock)(l.name,r.attributes,r.innerBlocks))}})),disabled:l,isBusy:l,variant:"primary"},(0,v.sprintf)((0,v.__)("Install %s"),t.title))}const Re=({originalBlock:e,...t})=>{const{originalName:n,originalUndelimitedContent:l,clientId:r}=t.attributes,{replaceBlock:a}=(0,c.useDispatch)(p.store),s=()=>{a(t.clientId,(0,i.createBlock)("core/html",{content:l}))},u=!!l,m=(0,c.useSelect)((e=>{const{canInsertBlockType:t,getBlockRootClientId:n}=e(p.store);return t("core/html",n(r))}),[r]);let k=(0,v.sprintf)((0,v.__)("Your site doesnt include support for the %s block. You can try installing the block or remove it entirely."),e.title||n);const b=[(0,o.createElement)(Ae,{key:"install",block:e,attributes:t.attributes,clientId:t.clientId})];return u&&m&&(k=(0,v.sprintf)((0,v.__)("Your site doesnt include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely."),e.title||n),b.push((0,o.createElement)(J.Button,{key:"convert",onClick:s,variant:"tertiary"},(0,v.__)("Keep as HTML")))),(0,o.createElement)("div",{...(0,p.useBlockProps)()},(0,o.createElement)(p.Warning,{actions:b},k),(0,o.createElement)(d.RawHTML,null,l))};var De=e=>t=>{const{originalName:n}=t.attributes,{block:l,hasPermission:r}=(0,c.useSelect)((e=>{const{getDownloadableBlocks:t}=e(W),l=t("block:"+n).filter((({name:e})=>n===e));return{hasPermission:e(X.store).canUser("read","block-directory/search"),block:l.length&&l[0]}}),[n]);return r&&l?(0,o.createElement)(Re,{...t,originalBlock:l}):(0,o.createElement)(e,{...t})};(0,a.registerPlugin)("block-directory",{render(){return(0,o.createElement)(o.Fragment,null,(0,o.createElement)(Z,null),(0,o.createElement)(Le,null),(0,o.createElement)(Ce,null))}}),(0,s.addFilter)("blocks.registerBlockType","block-directory/fallback",((e,t)=>("core/missing"!==t||(e.edit=De(e.edit)),e))),(window.wp=window.wp||{}).blockDirectory=t}();