PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.1.0
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.1.0
1.1.0 trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
← All changes | build/patternswp-editor.js +1 -7 1.0.61.1.0 View file →
@@ -1,7 +1 @@
1 -(()=>{var e={942:(e,t)=>{var n;!function(){"use strict";var a={}.hasOwnProperty;function r(){for(var e="",t=0;t<arguments.length;t++){var n=arguments[t];n&&(e=o(e,s(n)))}return e}function s(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return r.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var n in e)a.call(e,n)&&e[n]&&(t=o(t,n));return t}function o(e,t){return t?e?e+" "+t:e+t:e}e.exports?(r.default=r,e.exports=r):void 0===(n=function(){return r}.apply(t,[]))||(e.exports=n)}()}},t={};function n(a){var r=t[a];if(void 0!==r)return r.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";const e=window.React,t=window.lodash,a=window.wp.i18n,r=window.wp.element,s=window.wp.data,o=window.wp.components;function l(t){const{patternCategories:n,patternCategoryTypes:s,selectedCategory:l,setSelectedCategory:i,searchValue:c,setSearchValue:p,isLicenseActive:d}=t,u=(0,r.useMemo)((()=>s.map((e=>e.name))),[s]),m="patternswp__sidebar";return(0,e.createElement)("div",{className:m},(0,e.createElement)("div",{className:`${m}__search`},(0,e.createElement)(o.SearchControl,{value:c,onChange:p,label:(0,a.__)("Search patterns","patternswp")})),s.map((t=>{const r=n.filter((e=>"uncategorized"===t.name?!e?.categoryTypes||e.categoryTypes.every((e=>!u.includes(e))):e.categoryTypes?.includes(t.name)));return r.length?(0,e.createElement)("div",{key:t.name,className:`${m}__category-type`},t?.hideLabelFromVision?(0,e.createElement)(o.VisuallyHidden,{as:"h2"},t.label):(0,e.createElement)("h2",{className:`${m}__category-type__title`},t.label),(0,e.createElement)("div",{className:`${m}__category-type__categories`},(0,e.createElement)(o.MenuGroup,{className:`${m}__categories-list`},r.map((t=>(0,e.createElement)("div",{key:t.name,className:`${m}__category-item`},(0,e.createElement)(o.MenuItem,{label:t.label,className:`${m}__categories-list__item`,isPressed:!c&&t.name===l,onClick:()=>function(e){i(e),p("")}(t.name)},t.label))))),!d&&(0,e.createElement)("div",{className:`${m}__category-item__button-container`},(0,e.createElement)("a",{href:"https://thepatternswp.com/pricing/",target:"_blank",rel:"noopener noreferrer",onClick:()=>console.log("Link clicked for",category.name),className:`${m}__category-item__a`},(0,e.createElement)(o.Button,{isSecondary:!0,className:`${m}__category-item__button`},(0,a.__)("Upgrade to Pro","patternswp")))))):null})))}const i=window.wp.compose,c=window.wp.a11y;var p=n(942),d=n.n(p);const u=window.wp.primitives,m=(0,r.createElement)(u.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(u.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),f=(0,r.createElement)(u.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(u.Path,{d:"M5 4v11h14V4H5zm3 15.8h8v-1.5H8v1.5z"})),w=(0,r.createElement)(u.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,r.createElement)(u.Path,{d:"M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z",fillRule:"evenodd",clipRule:"evenodd"}));function h(t){const{viewportWidth:n,setViewportWidth:r,isGrid:s,setIsGrid:l,shownPatterns:i,searchValue:c,isLoading:p}=t,u=[{label:(0,a.__)("Desktop","patternswp"),slug:"desktop",value:1300,active:1300===n},{label:(0,a.__)("Tablet","patternswp"),slug:"tablet",value:778,active:778===n},{label:(0,a.__)("Mobile","patternswp"),slug:"mobile",value:358,active:358===n}],h="patternswp__preview-header";return(0,e.createElement)("div",{className:h},(0,e.createElement)("div",{className:`${h}__search-results`},p&&(0,e.createElement)(o.Spinner,null),c&&c.length>1&&(0,a.sprintf)(
2 -// translators: %1$d: Number of patterns. %2$s: The search input.
3 -// translators: %1$d: Number of patterns. %2$s: The search input.
4 -(0,a._n)('%1$d search result for "%2$s"','%1$d search results for "%2$s"',i.length,"patternswp"),i.length,c)),(0,e.createElement)("div",{className:`${h}__controls`},(0,e.createElement)(o.DropdownMenu,{icon:"",text:(0,a.__)("Preview","patternswp"),className:"viewport-toggle",toggleProps:{isTertiary:!0},popoverProps:{focusOnMount:"container",position:"bottom left"}},(()=>(0,e.createElement)(o.MenuGroup,null,u.map((t=>(0,e.createElement)(o.MenuItem,{key:t.slug,className:d()({disabled:!t.active}),icon:t.active?m:"",onClick:()=>function(e){e.active||r(e.value)}(t)},t.label)))))),(0,e.createElement)(o.Button,{label:(0,a.__)("Individual Pattern","patternswp"),icon:f,isPressed:!s,onClick:()=>l(!s)}),(0,e.createElement)(o.Button,{label:(0,a.__)("Grid View","patternswp"),icon:w,isPressed:s,onClick:()=>l(!s)})))}const _=function(e){let{icon:t,size:n=24,...a}=e;return(0,r.cloneElement)(t,{width:n,height:n,...a})},g=(0,r.createElement)(u.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,r.createElement)(u.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"})),v=function({icon:t,label:n}){return(0,e.createElement)("div",{className:"patternswp-inserter__no-results"},(0,e.createElement)("div",null,(0,e.createElement)(_,{className:"patternswp-inserter__no-results-icon",icon:t||g}),(0,e.createElement)("p",null,n||(0,a.__)("No results found.","patternswp"))))},y=(0,r.createContext)(),b=function({children:t}){const n=(0,o.__unstableUseCompositeState)({shift:!0,wrap:"horizontal"});return(0,e.createElement)(y.Provider,{value:n},t)},k=window.wp.blocks,E=window.wp.blockEditor;function C(t){const{pattern:n,onInsertPattern:r,viewportWidth:l,composite:c,isBlock:p,clientId:d}=t;let u=decodeURIComponent(escape(atob(n.content)));const m=(0,k.parse)(u),{createSuccessNotice:f}=(0,s.useDispatch)("core/notices"),w=`preview-pattern-card__info-description-${(0,i.useInstanceId)(C)}`;function h(){r(m.map((e=>(0,k.cloneBlock)(e)))),p&&(0,s.dispatch)("core/block-editor").removeBlock(d),f((0,a.sprintf)((0,a.__)('Block pattern "%s" inserted.',"patternswp"),n.title),{type:"snackbar"}),t.onRequestClose()}const _="patternswp__preview-pattern-list__item";return(0,e.createElement)("div",{className:`${_}${"pro"===n.type?" patternswp_pro_hover":""}`,"aria-label":n.title,"aria-describedby":n?.description?w:void 0},(0,e.createElement)(o.__unstableCompositeItem,{role:"option",as:"div",...c,className:`${_}-preview`,onClick:"pro"===n.type?null:h,disabled:"pro"===n.type},(0,e.createElement)(E.BlockPreview,{blocks:m,viewportWidth:l})),(0,e.createElement)("div",{className:`${_}-actions`},(0,e.createElement)("div",{className:`${_}-title`},n.title),!!n.description&&(0,e.createElement)(o.VisuallyHidden,{id:w},n.description),(0,e.createElement)(o.Button,{isSecondary:!0,onClick:h,disabled:"pro"===n.type},"pro"===n.type?(0,e.createElement)("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M5 9V7C5 5.67392 5.52678 4.40215 6.46447 3.46447C7.40215 2.52678 8.67392 2 10 2C11.3261 2 12.5979 2.52678 13.5355 3.46447C14.4732 4.40215 15 5.67392 15 7V9C15.5304 9 16.0391 9.21071 16.4142 9.58579C16.7893 9.96086 17 10.4696 17 11V16C17 16.5304 16.7893 17.0391 16.4142 17.4142C16.0391 17.7893 15.5304 18 15 18H5C4.46957 18 3.96086 17.7893 3.58579 17.4142C3.21071 17.0391 3 16.5304 3 16V11C3 10.4696 3.21071 9.96086 3.58579 9.58579C3.96086 9.21071 4.46957 9 5 9ZM13 7V9H7V7C7 6.20435 7.31607 5.44129 7.87868 4.87868C8.44129 4.31607 9.20435 4 10 4C10.7957 4 11.5587 4.31607 12.1213 4.87868C12.6839 5.44129 13 6.20435 13 7Z",fill:"#818181"})):(0,a.__)("Add Pattern","patternswp"))))}function S(n){const{isGrid:l,isLoading:i,searchValue:p,shownPatterns:u,viewportWidth:m}=n,[h,_]=function({rootClientId:e="",insertionIndex:n,clientId:o,isAppender:l,onSelect:i,shouldFocusBlock:p=!0}){const{getSelectedBlock:d}=(0,s.useSelect)(E.store),{destinationRootClientId:u,destinationIndex:m}=(0,s.useSelect)((t=>{const{getSelectedBlockClientId:a,getBlockRootClientId:r,getBlockIndex:s,getBlockOrder:i}=t(E.store),c=a();let p,d=e;return void 0!==n?p=n:o?p=s(o,d):!l&&c?(d=r(c),p=s(c,d)+1):p=i(d).length,{destinationRootClientId:d,destinationIndex:p}}),[e,n,o,l]),{replaceBlocks:f,insertBlocks:w,showInsertionPoint:h,hideInsertionPoint:_}=(0,s.useDispatch)(E.store),g=(0,r.useCallback)(((e,n,r=!1)=>{const s=d();!l&&s&&(0,k.isUnmodifiedDefaultBlock)(s)?f(s.clientId,e,null,p||r?0:null,n):w(e,m,u,!0,p||r?0:null,n);const o=(0,a.sprintf)(
5 -// translators: %d: the name of the block that has been added
6 -// translators: %d: the name of the block that has been added
7 -(0,a._n)("%d block added.","%d blocks added.",(0,t.castArray)(e).length),(0,t.castArray)(e).length);(0,c.speak)(o),i&&i()}),[l,d,f,w,u,m,i,p]),v=(0,r.useCallback)((e=>{e?h(u,m):_()}),[h,_,u,m]);return[u,g,v]}({shouldFocusBlock:!0}),g=(0,t.isEmpty)(u)&&!p&&!i,y=(0,t.isEmpty)(u)&&p,S=!g&&!y,V=!S&&y?(0,a.__)("No search results found.","patternswp"):(0,a.__)("No patterns were found for this category.","patternswp"),P=(0,o.__unstableUseCompositeState)();return(0,e.createElement)(b,null,!S&&(0,e.createElement)(v,{icon:l?w:f,label:V}),S&&(0,e.createElement)(o.__unstableComposite,{...P,role:"listbox",className:d()("patternswp__preview-pattern-list",{"is-grid":l,"is-loading":i,"preview-tablet":778===m,"preview-mobile":358===m}),"aria-label":(0,a.__)("Patterns","patternswp")},u.map((t=>(0,e.createElement)(C,{key:t.name,pattern:t,onInsertPattern:_,viewportWidth:m,composite:P,onRequestClose:n.onRequestClose})))))}const V=window.wp.notices,P=(e,t,n)=>{const[o,l]=(0,r.useState)([]);let[i]=(0,r.useState)(0);const c=window.patternsWpData.patternCategories||[],p=window.patternsWpData.patternCategoryTypes||[],d=window.patternsWpData.patternsNonce||[];let[u,m]=(0,r.useState)(2),[]=(0,r.useState)("");const[f,w]=(0,r.useState)(!0),[h,_]=(0,r.useState)(!1),{createSuccessNotice:g,createErrorNotice:v}=(0,s.useDispatch)(V.store),y=(0,r.useRef)(null),b=(0,r.useCallback)((async()=>{if(null!=n&&((t||n)&&0==i&&(u=1,m(2)),console.log(u),""!==t&&(n=""),""!==n&&(t=""),!h||""!=t)){_(!0);try{const e="all"===n?"":n,r=await fetch(window.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"fetch_patterns",page:u,patternsPerPage:15,search:t,category:e,nonce:d})}),s=r.headers.get("Content-Type");if(s&&s.includes("text/html"))return console.error("Received HTML response instead of JSON:",await r.text()),void v((0,a.__)("Failed to load patterns. Please try again later.","patternswp"),{type:"error"});const o=await r.json();o.success&&Array.isArray(o.data)?(l((e=>{if((t||n)&&0===i)return o.data;const a=new Set(e.map((e=>e.content))),r=o.data.filter((e=>!a.has(e.content)));return[...e,...r]})),h||1!=i||m((e=>e+1)),w(15===o.data.length)):console.error("Expected an array of patterns but got:",o)}catch(e){console.error("Error fetching patterns:",e),v((0,a.__)("Failed to load more patterns.","patternswp"),{type:"error"})}finally{_(!1)}}}),[v,f,h,t,n]),E=(0,r.useCallback)(((t,n)=>{e(n.map((e=>(0,k.cloneBlock)(e))),t.name),g((0,a.sprintf)((0,a.__)('Block pattern "%s" inserted.',"patternswp"),t.title),{type:"snackbar"})}),[g,e]);return(0,r.useEffect)((()=>{i=0,b(i)}),[t,n]),(0,r.useEffect)((()=>{const e=()=>{const e=document.querySelector(".components-modal__content");if(!e)return;const{clientHeight:t,scrollTop:n,scrollHeight:a}=e;t+n>=a-800&&f&&!h&&(i=1,b(i))},t=document.querySelector(".components-modal__content");return t&&t.addEventListener("scroll",e),()=>{t&&t.removeEventListener("scroll",e)}}),[b,f,h]),[o,c,p,E,y,f,h]};function x(t){const{selectedCategory:n,searchValue:s,onRequestClose:o}=t,[l,p]=(0,r.useState)(1300),[d,u]=(0,r.useState)(!0),m=(0,i.useDebounce)(c.speak,500),[f=[],,,w,_,,g]=P([],s,n),v=(0,r.useMemo)((()=>f),[f]);return(0,r.useEffect)((()=>{if(g)return;const e=v.length,t=(0,a.sprintf)((0,a._n)("%d pattern found.","%d patterns found.",e,"patternswp"),e);m(t)}),[s,m,v.length,g]),(0,e.createElement)("div",{className:"patternswp__preview",ref:_},(0,e.createElement)(h,{viewportWidth:l,setViewportWidth:p,isGrid:d,setIsGrid:u,shownPatterns:v,searchValue:s,isLoading:g}),(0,e.createElement)(S,{viewportWidth:l,isGrid:d,shownPatterns:v,searchValue:s,isLoading:g,onRequestClose:o,onClickPattern:w}),g&&(0,e.createElement)("div",{className:"patternswp__loader"},"Loading..."))}function L({allPatterns:t,initialCategory:n,patternCategories:a,patternCategoryTypes:s,isLicenseActive:o,onRequestClose:i}){const[c,p]=(0,r.useState)(""),[d,u]=(0,r.useState)("all");return(0,e.createElement)("div",{className:"patternswp"},(0,e.createElement)(l,{patternCategories:a,patternCategoryTypes:s,selectedCategory:d,setSelectedCategory:u,searchValue:c,setSearchValue:p,isLicenseActive:o}),(0,e.createElement)(x,{allPatterns:t,patternCategories:a,selectedCategory:d,searchValue:c,onRequestClose:i}))}function N(){const[t,n]=(0,r.useState)(!1),[s,l,i]=P(),c="fetching"===i?[]:i,p=patternsWpData.isLicenseActive,d=(0,r.useCallback)((e=>!(!e.categoryTypes||!e.categoryTypes.length)&&e.categoryTypes.some((e=>c.some((t=>t.name===e))))),[c]),u=()=>{n(!1)},m=(0,r.useMemo)((()=>[{name:"all",label:"All"},...l.filter((e=>e.name.startsWith("patternswp-"))).map((e=>({...e,label:e.name.replace("patternswp-","").replace(/-/g," ").replace(/\b\w/g,(e=>e.toUpperCase()))})))]),[l]),f=(0,r.useMemo)((()=>{const e=c.filter((e=>m.some((t=>t.categoryTypes?.includes(e.name)))));return m.some((e=>!d(e)))&&!e.find((e=>"uncategorized"===e.name))&&e.unshift({name:"uncategorized",label:(0,a.__)("Uncategorized","patternswp"),hideLabelFromVision:!0}),e}),[m,c]),w=m[0];return(0,r.useEffect)((()=>{const e=new MutationObserver((e=>{for(const n of e)"childList"===n.type&&n.addedNodes.length&&document.querySelectorAll(".components-dropdown.block-editor-inserter").forEach((e=>{t(e)}))}));e.observe(document.body,{subtree:!0,childList:!0});const t=e=>{if(!e.querySelector(".patternswp-appender-button")){const t=document.createElement("button");t.type="button",t.setAttribute("aria-haspopup","true"),t.className="components-button block-editor-inserter__toggle has-icon patternswp-appender-button",t.innerHTML='<svg width="20" height="20" viewBox="0 0 25 37" fill="#ffffff" xmlns="http://www.w3.org/2000/svg">\n <mask id="mask0_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="18" width="9" height="19" fill="#ffffff" ><path d="M0 18.3303H8.23816V36.3607H0V18.3303Z" fill="#ffffff"/></mask>\n <g mask="url(#mask0_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M0.625738 32.0853L8.04102 36.3602V18.5413L-0.000976562 23.1771V31.7244L0.625738 32.0853Z" fill="#ffffff"/></g>\n <mask id="mask1_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="10" y="9" width="15" height="18"><path d="M10.1934 9.198H24.1297V26.5898H10.1934V9.198Z" fill="#ffffff"/></mask>\n <g mask="url(#mask1_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.2178 17.2857V26.5548L16.0824 23.1758L24.1278 18.54V9.26831L16.0824 13.9041L10.2178 17.2857Z" fill="#ffffff"/></g>\n <mask id="mask2_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="16" y="4" width="9" height="10"><path d="M16.0645 4.63403H24.1311V13.9821H16.0645V4.63403Z" fill="#ffffff"/></mask>\n <g mask="url(#mask2_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M16.083 13.9058L24.1284 9.26999L16.083 4.63672V13.9058Z" fill="#ffffff"/></g>\n <mask id="mask3_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="17" height="14">\n <path d="M0 0H16.2819V13.9813H0V0Z" fill="#ffffff"/></mask><g mask="url(#mask3_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M8.04102 9.2691L16.083 4.63582L8.04102 0L-0.000976562 4.63582V13.9049L8.04102 9.2691Z" fill="#ffffff"/></g>\n </svg>',t.style.marginLeft="8px",e.appendChild(t),e.style.display="flex",e.style.gap="5px",t.addEventListener("click",(()=>{n(!0)}))}},a=()=>{document.querySelectorAll('iframe[name="editor-canvas"]').forEach((e=>{const n=e.contentDocument.querySelector(".components-dropdown.block-editor-inserter");n&&t(n)})),setTimeout(a,200)};return a(),()=>{e.disconnect()}}),[]),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(o.Button,{className:"components-button is-button is-primary patternswp-button",onClick:()=>n(!0)},"PatternsWP Library"),t&&(0,e.createElement)(o.Modal,{id:"patternswp__modal",title:(0,a.__)("PatternsWP","patternswp"),closeLabel:(0,a.__)("Close","patternswp"),onRequestClose:u,className:"patternswp__modal",isFullScreen:!0},(0,e.createElement)(L,{allPatterns:s,initialCategory:w,patternCategories:m,patternCategoryTypes:f,onRequestClose:u,isLicenseActive:p})))}(0,s.subscribe)((()=>{document.querySelector("#patternswp")||wp.domReady((()=>{const t=document.querySelector(".edit-post-header-toolbar");if(!t)return;const n=document.createElement("div");n.id="patternswp",t.appendChild(n),(0,r.render)((0,e.createElement)(N,null),document.getElementById("patternswp"))}))}))})()})();
1 +(()=>{var e={942(e,t){var a;!function(){"use strict";var r={}.hasOwnProperty;function n(){for(var e="",t=0;t<arguments.length;t++){var a=arguments[t];a&&(e=s(e,l(a)))}return e}function l(e){if("string"==typeof e||"number"==typeof e)return e;if("object"!=typeof e)return"";if(Array.isArray(e))return n.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var a in e)r.call(e,a)&&e[a]&&(t=s(t,a));return t}function s(e,t){return t?e?e+" "+t:e+t:e}e.exports?(n.default=n,e.exports=n):void 0===(a=(function(){return n}).apply(t,[]))||(e.exports=a)}()}},t={};function a(r){var n=t[r];if(void 0!==n)return n.exports;var l=t[r]={exports:{}};return e[r](l,l.exports,a),l.exports}a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";let e=window.React,t=window.lodash,r=window.wp.i18n,n=window.wp.element,l=window.wp.data,s=window.wp.components;function o(t){let{patternCategories:a,patternCategoryTypes:l,selectedCategory:o,setSelectedCategory:i,searchValue:c,setSearchValue:$,isLicenseActive:p}=t,d=(0,n.useMemo)(()=>l.map(e=>e.name),[l]),u="patternswp__sidebar";return(0,e.createElement)("div",{className:u},(0,e.createElement)("div",{className:`${u}__search`},(0,e.createElement)(s.SearchControl,{value:c,onChange:$,label:(0,r.__)("Search patterns","patternswp")})),l.map(t=>{let n=a.filter(e=>"uncategorized"===t.name?!e?.categoryTypes||e.categoryTypes.every(e=>!d.includes(e)):e.categoryTypes?.includes(t.name));return n.length?(0,e.createElement)("div",{key:t.name,className:`${u}__category-type`},t?.hideLabelFromVision?(0,e.createElement)(s.VisuallyHidden,{as:"h2"},t.label):(0,e.createElement)("h2",{className:`${u}__category-type__title`},t.label),(0,e.createElement)("div",{className:`${u}__category-type__categories`},(0,e.createElement)(s.MenuGroup,{className:`${u}__categories-list`},n.map(t=>(0,e.createElement)("div",{key:t.name,className:`${u}__category-item`},(0,e.createElement)(s.MenuItem,{label:t.label,className:`${u}__categories-list__item`,isPressed:!c&&t.name===o,onClick(){var e;i(e=t.name),$("")}},t.label)))),!p&&(0,e.createElement)("div",{className:`${u}__category-item__button-container`},(0,e.createElement)("a",{href:"https://thepatternswp.com/pricing?utm_source=free_plugin&utm_medium=patterns_library_modal&utm_campaign=sidebar_button",target:"_blank",rel:"noopener noreferrer",onClick:()=>console.log("Link clicked for",category.name),className:`${u}__category-item__a`},(0,e.createElement)(s.Button,{isSecondary:!0,className:`${u}__category-item__button`},(0,r.__)("Upgrade to Pro","patternswp")))))):null}))}let i=window.wp.compose,c=window.wp.a11y;var $=a(942),p=a.n($);let d=window.wp.primitives,u=(0,n.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(d.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),m=(0,n.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(d.Path,{d:"M5 4v11h14V4H5zm3 15.8h8v-1.5H8v1.5z"})),_=(0,n.createElement)(d.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,n.createElement)(d.Path,{d:"M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z",fillRule:"evenodd",clipRule:"evenodd"}));function f(t){let{viewportWidth:a,setViewportWidth:n,isGrid:l,setIsGrid:o,shownPatterns:i,searchValue:c,isLoading:$}=t,d=[{label:(0,r.__)("Desktop","patternswp"),slug:"desktop",value:1300,active:1300===a},{label:(0,r.__)("Tablet","patternswp"),slug:"tablet",value:778,active:778===a},{label:(0,r.__)("Mobile","patternswp"),slug:"mobile",value:358,active:358===a}],f="patternswp__preview-header";return(0,e.createElement)("div",{className:f},(0,e.createElement)("div",{className:`${f}__search-results`},$&&(0,e.createElement)(s.Spinner,null),c&&c.length>1&&(0,r.sprintf)((0,r._n)('%1$d search result for "%2$s"','%1$d search results for "%2$s"',i.length,"patternswp"),i.length,c)),(0,e.createElement)("div",{className:`${f}__controls`},(0,e.createElement)(s.DropdownMenu,{icon:"",text:(0,r.__)("Preview","patternswp"),className:"viewport-toggle",toggleProps:{isTertiary:!0},popoverProps:{focusOnMount:"container",position:"bottom left"}},()=>(0,e.createElement)(s.MenuGroup,null,d.map(t=>(0,e.createElement)(s.MenuItem,{key:t.slug,className:p()({disabled:!t.active}),icon:t.active?u:"",onClick(){var e;(e=t).active||n(e.value)}},t.label)))),(0,e.createElement)(s.Button,{label:(0,r.__)("Individual Pattern","patternswp"),icon:m,isPressed:!l,onClick:()=>o(!l)}),(0,e.createElement)(s.Button,{label:(0,r.__)("Grid View","patternswp"),icon:_,isPressed:l,onClick:()=>o(!l)})))}let h=function(e){let{icon:t,size:a=24,...r}=e;return(0,n.cloneElement)(t,{width:a,height:a,...r})},g=(0,n.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(d.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"})),v=function({icon:t,label:a}){return(0,e.createElement)("div",{className:"patternswp-inserter__no-results"},(0,e.createElement)("div",null,(0,e.createElement)(h,{className:"patternswp-inserter__no-results-icon",icon:t||g}),(0,e.createElement)("p",null,a||(0,r.__)("No results found.","patternswp"))))},w=(0,n.createContext)(),y=function({children:t}){let a=(0,s.__unstableUseCompositeState)({shift:!0,wrap:"horizontal"});return(0,e.createElement)(w.Provider,{value:a},t)},b=window.wp.blocks,k=window.wp.blockEditor;function E(t){let{pattern:a,onInsertPattern:n,viewportWidth:o,composite:c,isBlock:$,clientId:p}=t,d=decodeURIComponent(escape(atob(a.content))),u=(0,b.parse)(d),{createSuccessNotice:m}=(0,l.useDispatch)("core/notices"),_=`preview-pattern-card__info-description-${(0,i.useInstanceId)(E)}`;function f(){n(u.map(e=>(0,b.cloneBlock)(e))),$&&(0,l.dispatch)("core/block-editor").removeBlock(p),m((0,r.sprintf)((0,r.__)('Block pattern "%s" inserted.',"patternswp"),a.title),{type:"snackbar"}),t.onRequestClose()}let h="patternswp__preview-pattern-list__item";return(0,e.createElement)("div",{className:`${h}${"pro"===a.type?" patternswp_pro_hover":""}`,"aria-label":a.title,"aria-describedby":a?.description?_:void 0},(0,e.createElement)(s.__unstableCompositeItem,{role:"option",as:"div",...c,className:`${h}-preview`,onClick:"pro"===a.type?null:f,disabled:"pro"===a.type},(0,e.createElement)(k.BlockPreview,{blocks:u,viewportWidth:o})),(0,e.createElement)("div",{className:`${h}-actions`},(0,e.createElement)("div",{className:`${h}-title`},a.title),!!a.description&&(0,e.createElement)(s.VisuallyHidden,{id:_},a.description),(0,e.createElement)(s.Button,{isSecondary:!0,onClick:f,disabled:"pro"===a.type},"pro"===a.type?(0,e.createElement)("a",{href:"https://thepatternswp.com/pricing?utm_source=free_plugin&utm_medium=patterns_library_modal&utm_campaign=patterns_lock",target:"_blank",rel:"noopener noreferrer",className:"patternswp__pro-pattern-link"},(0,e.createElement)("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M5 9V7C5 5.67392 5.52678 4.40215 6.46447 3.46447C7.40215 2.52678 8.67392 2 10 2C11.3261 2 12.5979 2.52678 13.5355 3.46447C14.4732 4.40215 15 5.67392 15 7V9C15.5304 9 16.0391 9.21071 16.4142 9.58579C16.7893 9.96086 17 10.4696 17 11V16C17 16.5304 16.7893 17.0391 16.4142 17.4142C16.0391 17.7893 15.5304 18 15 18H5C4.46957 18 3.96086 17.7893 3.58579 17.4142C3.21071 17.0391 3 16.5304 3 16V11C3 10.4696 3.21071 9.96086 3.58579 9.58579C3.96086 9.21071 4.46957 9 5 9ZM13 7V9H7V7C7 6.20435 7.31607 5.44129 7.87868 4.87868C8.44129 4.31607 9.20435 4 10 4C10.7957 4 11.5587 4.31607 12.1213 4.87868C12.6839 5.44129 13 6.20435 13 7Z",fill:"#818181"}))):(0,r.__)("Add Pattern","patternswp"))))}function C(a){let{isGrid:o,isLoading:i,searchValue:$,shownPatterns:d,viewportWidth:u}=a,[f,h]=function({rootClientId:e="",insertionIndex:a,clientId:s,isAppender:o,onSelect:i,shouldFocusBlock:$=!0}){let{getSelectedBlock:p}=(0,l.useSelect)(k.store),{destinationRootClientId:d,destinationIndex:u}=(0,l.useSelect)(t=>{let{getSelectedBlockClientId:r,getBlockRootClientId:n,getBlockIndex:l,getBlockOrder:i}=t(k.store),c=r(),$,p=e;return void 0!==a?$=a:s?$=l(s,p):!o&&c?(p=n(c),$=l(c,p)+1):$=i(p).length,{destinationRootClientId:p,destinationIndex:$}},[e,a,s,o]),{replaceBlocks:m,insertBlocks:_,showInsertionPoint:f,hideInsertionPoint:h}=(0,l.useDispatch)(k.store),g=(0,n.useCallback)((e,a,n=!1)=>{let l=p();!o&&l&&(0,b.isUnmodifiedDefaultBlock)(l)?m(l.clientId,e,null,$||n?0:null,a):_(e,u,d,!0,$||n?0:null,a);let s=(0,r.sprintf)((0,r._n)("%d block added.","%d blocks added.",(0,t.castArray)(e).length),(0,t.castArray)(e).length);(0,c.speak)(s),i&&i()},[o,p,m,_,d,u,i,$]),v=(0,n.useCallback)(e=>{e?f(d,u):h()},[f,h,d,u]);return[d,g,v]}({shouldFocusBlock:!0}),g=(0,t.isEmpty)(d)&&!$&&!i,w=(0,t.isEmpty)(d)&&$,C=!g&&!w,S=!C&&w?(0,r.__)("No search results found.","patternswp"):(0,r.__)("No patterns were found for this category.","patternswp"),V=(0,s.__unstableUseCompositeState)();return(0,e.createElement)(y,null,!C&&(0,e.createElement)(v,{icon:o?_:m,label:S}),C&&(0,e.createElement)(s.__unstableComposite,{...V,role:"listbox",className:p()("patternswp__preview-pattern-list",{"is-grid":o,"is-loading":i,"preview-tablet":778===u,"preview-mobile":358===u}),"aria-label":(0,r.__)("Patterns","patternswp")},d.map(t=>(0,e.createElement)(E,{key:t.name,pattern:t,onInsertPattern:h,viewportWidth:u,composite:V,onRequestClose:a.onRequestClose}))))}let S=window.wp.notices,V=(e,t,a)=>{let[s,o]=(0,n.useState)([]),[i]=(0,n.useState)(0),c=window.patternsWpData.patternCategories||[],$=window.patternsWpData.patternCategoryTypes||[],p=window.patternsWpData.patternsNonce||[],[d,u]=(0,n.useState)(2),[]=(0,n.useState)(""),[m,_]=(0,n.useState)(!0),[f,h]=(0,n.useState)(!1),{createSuccessNotice:g,createErrorNotice:v}=(0,l.useDispatch)(S.store),w=(0,n.useRef)(null),y=(0,n.useCallback)(async()=>{if(null!=a&&((t||a)&&0==i&&(d=1,u(2)),console.log(d),""!==t&&(a=""),""!==a&&(t=""),!f||""!=t)){h(!0);try{let e="all"===a?"":a,n=await fetch(window.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"fetch_patterns",page:d,patternsPerPage:15,search:t,category:e,nonce:p})}),l=n.headers.get("Content-Type");if(l&&l.includes("text/html"))return console.error("Received HTML response instead of JSON:",await n.text()),void v((0,r.__)("Failed to load patterns. Please try again later.","patternswp"),{type:"error"});let s=await n.json();s.success&&Array.isArray(s.data)?(o(e=>{if((t||a)&&0===i)return s.data;let r=new Set(e.map(e=>e.content)),n=s.data.filter(e=>!r.has(e.content));return[...e,...n]}),f||1!=i||u(e=>e+1),_(15===s.data.length)):console.error("Expected an array of patterns but got:",s)}catch(c){console.error("Error fetching patterns:",c),v((0,r.__)("Failed to load more patterns.","patternswp"),{type:"error"})}finally{h(!1)}}},[v,m,f,t,a]),k=(0,n.useCallback)((t,a)=>{e(a.map(e=>(0,b.cloneBlock)(e)),t.name),g((0,r.sprintf)((0,r.__)('Block pattern "%s" inserted.',"patternswp"),t.title),{type:"snackbar"})},[g,e]);return(0,n.useEffect)(()=>{y(i=0)},[t,a]),(0,n.useEffect)(()=>{let e=()=>{let e=document.querySelector(".components-modal__content");if(!e)return;let{clientHeight:t,scrollTop:a,scrollHeight:r}=e;t+a>=r-800&&m&&!f&&y(i=1)},t=document.querySelector(".components-modal__content");return t&&t.addEventListener("scroll",e),()=>{t&&t.removeEventListener("scroll",e)}},[y,m,f]),[s,c,$,k,w,m,f]};function N(t){let{selectedCategory:a,searchValue:l,onRequestClose:s}=t,[o,$]=(0,n.useState)(1300),[p,d]=(0,n.useState)(!0),u=(0,i.useDebounce)(c.speak,500),[m=[],,,_,h,,g]=V([],l,a),v=(0,n.useMemo)(()=>m,[m]);return(0,n.useEffect)(()=>{if(g)return;let e=v.length,t=(0,r.sprintf)((0,r._n)("%d pattern found.","%d patterns found.",e,"patternswp"),e);u(t)},[l,u,v.length,g]),(0,e.createElement)("div",{className:"patternswp__preview",ref:h},(0,e.createElement)(f,{viewportWidth:o,setViewportWidth:$,isGrid:p,setIsGrid:d,shownPatterns:v,searchValue:l,isLoading:g}),(0,e.createElement)(C,{viewportWidth:o,isGrid:p,shownPatterns:v,searchValue:l,isLoading:g,onRequestClose:s,onClickPattern:_}),g&&(0,e.createElement)("div",{className:"patternswp__loader"},"Loading..."))}function P({allPatterns:t,initialCategory:a,patternCategories:r,patternCategoryTypes:l,isLicenseActive:s,onRequestClose:i}){let[c,$]=(0,n.useState)(""),[p,d]=(0,n.useState)("all");return(0,e.createElement)("div",{className:"patternswp"},(0,e.createElement)(o,{patternCategories:r,patternCategoryTypes:l,selectedCategory:p,setSelectedCategory:d,searchValue:c,setSearchValue:$,isLicenseActive:s}),(0,e.createElement)(N,{allPatterns:t,patternCategories:r,selectedCategory:p,searchValue:c,onRequestClose:i}))}function x(){let[t,a]=(0,n.useState)(!1),[l,o,i]=V(),c="fetching"===i?[]:i,$=patternsWpData.isLicenseActive,p=(0,n.useCallback)(e=>!(!e.categoryTypes||!e.categoryTypes.length)&&e.categoryTypes.some(e=>c.some(t=>t.name===e)),[c]),d=()=>{a(!1)},u=(0,n.useMemo)(()=>[{name:"all",label:"All"},...o.filter(e=>e.name.startsWith("patternswp-")).map(e=>({...e,label:e.name.replace("patternswp-","").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}))],[o]),m=(0,n.useMemo)(()=>{let e=c.filter(e=>u.some(t=>t.categoryTypes?.includes(e.name)));return u.some(e=>!p(e))&&!e.find(e=>"uncategorized"===e.name)&&e.unshift({name:"uncategorized",label:(0,r.__)("Uncategorized","patternswp"),hideLabelFromVision:!0}),e},[u,c]),_=u[0];return(0,n.useEffect)(()=>{let e=new MutationObserver(e=>{for(let a of e)"childList"===a.type&&a.addedNodes.length&&document.querySelectorAll(".components-dropdown.block-editor-inserter").forEach(e=>{t(e)})});e.observe(document.body,{subtree:!0,childList:!0});let t=e=>{if(!e.querySelector(".patternswp-appender-button")){let t=document.createElement("button");t.type="button",t.setAttribute("aria-haspopup","true"),t.className="components-button block-editor-inserter__toggle has-icon patternswp-appender-button",t.innerHTML='<svg width="20" height="20" viewBox="0 0 25 37" fill="#ffffff" xmlns="http://www.w3.org/2000/svg">\n <mask id="mask0_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="18" width="9" height="19" fill="#ffffff" ><path d="M0 18.3303H8.23816V36.3607H0V18.3303Z" fill="#ffffff"/></mask>\n <g mask="url(#mask0_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M0.625738 32.0853L8.04102 36.3602V18.5413L-0.000976562 23.1771V31.7244L0.625738 32.0853Z" fill="#ffffff"/></g>\n <mask id="mask1_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="10" y="9" width="15" height="18"><path d="M10.1934 9.198H24.1297V26.5898H10.1934V9.198Z" fill="#ffffff"/></mask>\n <g mask="url(#mask1_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.2178 17.2857V26.5548L16.0824 23.1758L24.1278 18.54V9.26831L16.0824 13.9041L10.2178 17.2857Z" fill="#ffffff"/></g>\n <mask id="mask2_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="16" y="4" width="9" height="10"><path d="M16.0645 4.63403H24.1311V13.9821H16.0645V4.63403Z" fill="#ffffff"/></mask>\n <g mask="url(#mask2_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M16.083 13.9058L24.1284 9.26999L16.083 4.63672V13.9058Z" fill="#ffffff"/></g>\n <mask id="mask3_671_1966" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="17" height="14">\n <path d="M0 0H16.2819V13.9813H0V0Z" fill="#ffffff"/></mask><g mask="url(#mask3_671_1966)"><path fill-rule="evenodd" clip-rule="evenodd" d="M8.04102 9.2691L16.083 4.63582L8.04102 0L-0.000976562 4.63582V13.9049L8.04102 9.2691Z" fill="#ffffff"/></g>\n </svg>',t.style.marginLeft="8px",e.appendChild(t),e.style.display="flex",e.style.gap="5px",t.addEventListener("click",()=>{a(!0)})}},r=()=>{document.querySelectorAll('iframe[name="editor-canvas"]').forEach(e=>{let a=e.contentDocument.querySelector(".components-dropdown.block-editor-inserter");a&&t(a)}),setTimeout(r,200)};return r(),()=>{e.disconnect()}},[]),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(s.Button,{className:"components-button is-button is-primary patternswp-button",onClick:()=>a(!0)},"PatternsWP Library"),t&&(0,e.createElement)(s.Modal,{id:"patternswp__modal",title:(0,r.__)("PatternsWP","patternswp"),closeLabel:(0,r.__)("Close","patternswp"),onRequestClose:d,className:"patternswp__modal",isFullScreen:!0},(0,e.createElement)(P,{allPatterns:l,initialCategory:_,patternCategories:u,patternCategoryTypes:m,onRequestClose:d,isLicenseActive:$})))}(0,l.subscribe)(()=>{document.querySelector("#patternswp")||wp.domReady(()=>{let t=document.querySelector(".edit-post-header-toolbar");if(!t)return;let a=document.createElement("div");a.id="patternswp",t.appendChild(a),(0,n.render)((0,e.createElement)(x,null),document.getElementById("patternswp"))})})})()})();