PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.0.8
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.0.8
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
patternswp / build / patternswp-editor.js

patternswp-editor.js in PatternsWP – Gutenberg Block Patterns & Page Templates Library 1.0.8, at build/patternswp-editor.js

1 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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"))})})})()})();