| 1 |
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>x});const r=window.wp.element,n=window.wp.i18n,o=window.wp.components,s=window.wp.data,c=window.wp.compose,l=window.wp.apiFetch;var a=e.n(l);const i=window.wp.url,u=window.wp.blocks;function d(e){var t;const[n,o]=(0,r.useState)({status:"idle"}),s=(0,r.useRef)(!1),{attributes:l,block:d,skipBlockSupportAttributes:p=!1,httpMethod:w="GET",urlQueryArgs:f}=e;let m=l&&(0,u.__experimentalSanitizeBlockAttributes)(d,l);p&&(m=function(e){const{backgroundColor:t,borderColor:r,fontFamily:n,fontSize:o,gradient:s,textColor:c,className:l,...a}=e,{border:i,color:u,elements:d,shadow:p,spacing:w,typography:f,...m}=e?.style||{};return{...a,style:m}}(m));const h="POST"===w,y=function(e,t=null,r={}){return(0,i.addQueryArgs)(`/wp/v2/block-renderer/${e}`,{context:"edit",...null!==t?{attributes:t}:{},...r})}(d,h?null:m,f),b=h?JSON.stringify({attributes:null!==(t=m)&&void 0!==t?t:null}):void 0;return(0,r.useEffect)((()=>{const e=new AbortController,t=(0,c.debounce)((function(){o({status:"loading"}),a()({path:y,method:h?"POST":"GET",body:b,headers:h?{"Content-Type":"application/json"}:{},signal:e.signal}).then((e=>{o({status:"success",content:e?e.rendered:""})})).catch((e=>{"AbortError"!==e.name&&o({status:"error",error:e.message})})).finally((()=>{s.current=!0}))}),s.current?500:0);return t(),()=>{e.abort(),t.cancel()}}),[y,h,b]),n}const p=window.ReactJSXRuntime,w={};function f({className:e}){return(0,p.jsx)(o.Placeholder,{className:e,children:(0,n.__)("Block rendered as empty.")})}function m({message:e,className:t}){const r=(0,n.sprintf)( |
| 4 |
(0,n.__)("Error loading block: %s"),e);return(0,p.jsx)(o.Placeholder,{className:t,children:r})}function h({children:e}){const[t,n]=(0,r.useState)(!1);return(0,r.useEffect)((()=>{const e=setTimeout((()=>{n(!0)}),1e3);return()=>clearTimeout(e)}),[]),(0,p.jsxs)("div",{style:{position:"relative"},children:[t&&(0,p.jsx)("div",{style:{position:"absolute",top:"50%",left:"50%",marginTop:"-9px",marginLeft:"-9px"},children:(0,p.jsx)(o.Spinner,{})}),(0,p.jsx)("div",{style:{opacity:t?"0.3":1},children:e})]})}function y(e){const t=(0,r.useRef)(""),{className:n,EmptyResponsePlaceholder:o=f,ErrorResponsePlaceholder:s=m,LoadingResponsePlaceholder:c=h,...l}=e,{content:a,status:i,error:u}=d(l);return(0,r.useEffect)((()=>{a&&(t.current=a)}),[a]),"loading"===i?(0,p.jsx)(c,{...e,children:!!t.current&&(0,p.jsx)(r.RawHTML,{className:n,children:t.current})}):"success"!==i||a?"error"===i?(0,p.jsx)(s,{message:u,...e}):(0,p.jsx)(r.RawHTML,{className:n,children:a}):(0,p.jsx)(o,{...e})}function b({urlQueryArgs:e=w,...t}){const n=(0,s.useSelect)((e=>{const t=e("core/editor")?.getCurrentPostId();return t&&"number"==typeof t?t:null}),[]),o=(0,r.useMemo)((()=>n?{post_id:n,...e}:e),[n,e]);return(0,p.jsx)(y,{urlQueryArgs:o,...t})}const g=b;g.ServerSideRender=b,g.useServerSideRender=d;const x=g;(window.wp=window.wp||{}).serverSideRender=t.default})(); |