| 1 |
(()=>{"use strict";var e={1295(){const e=window.wp.blockEditor,t=window.wp.blocks,n=window.wp.data,a=window.wp.i18n,s=window.GetwidComponents,r=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"textdomain":"getwid","name":"getwid/template-library","description":"Browses and inserts pre-designed templates.","category":"getwid-blocks","title":"Template Library","icon":"category","supports":{"multiple":true,"customClassName":false},"editorScript":"file:./index.js","editorStyle":"file:./index.css"}'),i=window.wp.components,o=window.wp.element;function l(e){var t,n,a="";if("string"==typeof e||"number"==typeof e)a+=e;else if("object"==typeof e)if(Array.isArray(e)){var s=e.length;for(t=0;t<s;t++)e[t]&&(n=l(e[t]))&&(a&&(a+=" "),a+=n)}else for(n in e)e[n]&&(a&&(a+=" "),a+=n);return a}const c=function(){for(var e,t,n=0,a="",s=arguments.length;n<s;n++)(e=arguments[n])&&(t=l(e))&&(a&&(a+=" "),a+=t);return a},d=new Set;let u;function m(e){return d.has(e)}function p(e){d.delete(e)}const h=window.ReactJSXRuntime,w="wp-block-getwid-template-library",g=window,_=g.wp?.apiFetch,f=g.wp?.url?.addQueryArgs;function b(e){return Object.keys(e).length>0}const v="getwid/template-library";let y;function x(){const a=(0,t.createBlock)(v);var s;s=a.clientId,d.add(s),(0,n.dispatch)(e.store).insertBlocks([a])}function j(){if(document.getElementById("getwid-layout-insert-button"))return;const e=document.querySelector(".edit-post-header-toolbar__left, .editor-document-tools__left");if(!e)return;const t=document.createElement("button");t.id="getwid-layout-insert-button",t.type="button",t.ariaExpanded="false",t.dataset.toolbarItem="true",t.className="components-button",t.textContent=(0,a.__)("Template Library","getwid"),t.addEventListener("click",x),e.append(t)}function N(){j(),(0,n.subscribe)(()=>{y&&clearTimeout(y),y=setTimeout(j,100)})}const k=window.Getwid;k?.disabled_blocks?.includes(v)||("loading"===document.readyState?document.addEventListener("DOMContentLoaded",N,{once:!0}):N()),(0,t.registerBlockType)(r,{title:(0,a.__)("Template Library","getwid"),edit:(0,s.MaybeBlockIsDisabled)(v)||function({clientId:s,className:r}){const[l,d]=(0,o.useState)({}),[v,y]=(0,o.useState)({}),[x,j]=(0,o.useState)(""),[N,k]=(0,o.useState)(""),[C,S]=(0,o.useState)(!0),[B,O]=(0,o.useState)(!1),[T,E]=(0,o.useState)(3),I=(0,o.useRef)(!0),{removeBlock:L,replaceBlocks:G}=(0,n.useDispatch)(e.store),M=(0,e.useBlockProps)({className:r}),$=(0,o.useCallback)(e=>{y(e.categories??{}),d(e.templates??{}),S(!1)},[]),D=(0,o.useCallback)(async(e="cache")=>{if(!_||!f)return y({}),d({}),void S(!1);try{const n=await _({path:f("/getwid/v1/get_remote_templates",{cache:e})});if(!I.current)return;if(200===n.code&&n.data)return t=n.data,u=t,g.Getwid&&(g.Getwid.remote_templates=n.data),void $(n.data);y({}),d({}),S(!1)}catch{I.current&&(y({}),d({}),S(!1))}var t},[$]),A=(0,o.useCallback)(async e=>{if(_&&f)try{const n=await _({path:f("/getwid/v1/get_remote_content",{get_content_url:e})});if(I.current&&"string"==typeof n&&""!==n)return void G(s,(0,t.parse)(n));I.current&&S(!1)}catch{I.current&&S(!1)}else S(!1)},[s,G]);function H(e){const t=function(e){let t=l[e]??{};if(x){const e=t[x];t=e?{[x]:e}:{}}if(!N)return t;const n={};return Object.entries(t).forEach(([e,t])=>{const a=t.filter(e=>{const t=e.keywords.join(", ").toLowerCase();return e.title.toLowerCase().includes(N)||t.includes(N)});a.length&&(n[e]=a)}),n}(e),n=v[e]??{};return 0===Object.keys(t).length?(0,a.__)("No templates found.","getwid"):Object.entries(t).map(([e,t])=>(0,h.jsxs)("div",{className:"template-library-category-wrapper",children:[(0,h.jsx)("div",{className:"template-library-category-title",children:(0,h.jsx)("h2",{children:n[e]})}),(0,h.jsx)("div",{className:"template-library-category-items",children:t.map(e=>(0,h.jsx)("div",{className:"template-library-container",children:(0,h.jsxs)("div",{className:"template-library-item",children:[(0,h.jsx)("div",{className:"template-image-wrapper",children:(0,h.jsx)("div",{className:"template-image",style:{backgroundImage:`url('${e.image}')`}})}),(0,h.jsxs)("div",{className:"template-content-wrapper",children:[(0,h.jsx)("div",{className:"template-title",children:e.title}),""!==e.description&&(0,h.jsx)("div",{className:"template-description",children:e.description}),(0,h.jsx)(i.Button,{className:"template-insert-button",variant:"primary",onClick:()=>function(e){O(!1),S(!0),A(e.get_content_url)}(e),children:(0,a.__)("Insert Template","getwid")})]})]})},e.get_content_url))})]},e))}function R(e){const t=v[e]??{},n=Object.entries(t).map(([e,t])=>({value:e,label:t}));return(0,h.jsx)(i.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,className:"template-category-field",value:x,onChange:j,options:[{value:"",label:(0,a.__)("All Categories","getwid")},...n]})}return(0,o.useEffect)(()=>{I.current=!0;const e=Number.parseInt(window.localStorage.getItem("layoutCount")??"",10);e>=1&&e<=4&&E(e);const t=u??g.Getwid?.remote_templates;return t?$(t):D(),m(s)&&O(!0),()=>{I.current=!1,p(s)}},[$,s,D]),(0,o.useEffect)(()=>{window.localStorage.setItem("layoutCount",String(T))},[T]),(0,h.jsxs)("div",{...M,children:[(0,h.jsxs)("div",{className:"components-placeholder block-editor-inner-blocks__template-picker has-many-options",children:[(0,h.jsxs)("div",{className:"components-placeholder__label",children:[(0,h.jsx)(i.Dashicon,{icon:"category"}),(0,a.__)("Template Library","getwid")]}),(0,h.jsx)("div",{className:"components-placeholder__instructions",children:(0,a.__)("Choose a template from the library.","getwid")}),(0,h.jsx)("div",{className:"components-placeholder__fieldset",children:C?(0,h.jsx)(i.Spinner,{}):b(l)?(0,h.jsx)("div",{className:"insert-template-button",children:(0,h.jsx)(i.Button,{className:"open-modal-button",variant:"secondary",onClick:()=>O(!0),children:(0,a.__)("Insert Template","getwid")})}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("p",{className:"no-templates",children:(0,a.__)("No templates found.","getwid")}),(0,h.jsx)(i.Button,{className:"template-search-button",variant:"secondary",onClick:()=>{S(!0),D("refresh")},children:(0,a.__)("Update","getwid")})]})})]}),B&&(0,h.jsx)(i.Modal,{className:`${w}__modal-templates`,title:(0,a.__)("Template Library","getwid"),shouldCloseOnClickOutside:!0,shouldCloseOnEsc:!0,onRequestClose:function(){if(m(s))return p(s),void L(s);O(!1)},children:(0,h.jsx)(i.TabPanel,{className:"getwid-modal-editor-tabs",activeClass:"is-active",tabs:[{name:"sections",title:(0,a.__)("Section","getwid"),className:"components-button"}],children:()=>function(e){const t=!b(l);return(0,h.jsxs)("div",{className:`${w}__wrapper`,children:[(0,h.jsxs)("div",{className:`${w}__modal-toolbar`,children:[R(e),(0,h.jsx)(i.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,className:"template-search-field",placeholder:(0,a.__)("Search","getwid"),value:N,onChange:e=>k(e.toLowerCase())}),(0,h.jsx)("div",{className:`${w}__layout-view`,children:(0,h.jsx)(i.BaseControl,{__nextHasNoMarginBottom:!0,children:(0,h.jsx)(i.ButtonGroup,{children:[1,2,3,4].map(e=>(0,h.jsx)(i.Button,{className:"template-view-button",variant:T===e?"primary":"secondary",onClick:()=>E(e),children:e},e))})})}),g.Getwid?.settings?.debug&&(0,h.jsx)("div",{className:"template-update-button",children:(0,h.jsx)(i.BaseControl,{__nextHasNoMarginBottom:!0,children:(0,h.jsx)(i.Button,{className:"template-update-button",variant:"primary",onClick:()=>{S(!0),D("refresh")},children:(0,a.__)("Update","getwid")})})})]}),(0,h.jsxs)("div",{className:c("template-library-list",`has-columns-${T}`,{"loading-items":C||t}),children:[t&&!C&&(0,a.__)("No templates found.","getwid"),C?(0,h.jsx)(i.Spinner,{}):H(e)]})]})}("sections")})})]})},save:()=>null})}};const t={};function n(a){const s=t[a];if(void 0!==s)return s.exports;const r=t[a]={exports:{}};return e[a](r,r.exports,n),r.exports}n.m=e,(()=>{const e=[];n.O=(t,a,s,r)=>{if(a){r=r||0;for(var i=e.length;i>0&&e[i-1][2]>r;i--)e[i]=e[i-1];return void(e[i]=[a,s,r])}let o=1/0;for(i=0;i<e.length;i++){let[a,s,r]=e[i],c=!0;for(var l=0;l<a.length;l++)(!1&r||o>=r)&&Object.keys(n.O).every(e=>n.O[e](a[l]))?a.splice(l--,1):(c=!1,r<o&&(o=r));if(c){e.splice(i--,1);const n=s();void 0!==n&&(t=n)}}return t}})(),n.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={2502:0,4538:0};n.O.j=t=>0===e[t];const t=(t,a)=>{let[s,r,i]=a;var o,l,c=0;if(s.some(t=>0!==e[t])){for(o in r)n.o(r,o)&&(n.m[o]=r[o]);if(i)var d=i(n)}for(t&&t(a);c<s.length;c++)l=s[c],n.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return n.O(d)},a=globalThis.webpackChunkgetwid||=[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();let a=n.O(void 0,[4538],()=>n(1295));a=n.O(a)})(); |