diff --git a/packages/gutenberg/src/index.tsx b/packages/gutenberg/src/index.tsx index 8f3cdb3..7c085ad 100644 --- a/packages/gutenberg/src/index.tsx +++ b/packages/gutenberg/src/index.tsx @@ -106,6 +106,9 @@ window.coreframework = { const removeDuplicates = (arr: T[]): T[] => [...new Set(arr)]; +const parseClassNames = (className?: string): string[] => + className ? className.replace(/\s\s+/g, " ").trim().split(" ").filter(Boolean) : []; + const stylesGroupsIconsMap: Record> = { colorStyles: ColorPalette, typographyStyles: Typography, @@ -200,38 +203,27 @@ const withInspectorControls = createHigherOrderComponent((BlockEdit: React.Compo const [searchValue, setSearchValue] = useState(""); + // Seed from the saved className so the first render already matches the block. const [classNames, setClassNames] = useState<{ active: string[]; dynamic: string[]; - }>({ - active: [], + }>(() => ({ + active: parseClassNames(props.attributes.className), dynamic: [], - }); + })); const [selectedSearchResult, setSelectedSearchResult] = useState(-1); useEffect(() => { - if (!props.attributes.className) { + const className = [...classNames.active, ...classNames.dynamic].join(" "); + + // Any differing write, even "" over no className or a whitespace-only change, marks a clean post, template or template part as modified. + if (className === parseClassNames(props.attributes.className).join(" ")) { return; } - const regExpToRemoveMultipleSpaces = /\s\s+/g; - const parsedClassNames = props.attributes.className.replace(regExpToRemoveMultipleSpaces, " ").trim(); - const initialClassNames = parsedClassNames.split(" "); - setClassNames((prev) => ({ - ...prev, - active: initialClassNames, - })); - }, []); - - useEffect( - () => { - props.setAttributes({ - className: [...classNames.active, ...classNames.dynamic].join(" "), - }); - }, - [classNames], - ); + props.setAttributes({ className }); + }, [classNames]); useEffect(() => { setSearchValue(""); diff --git a/packages/wp/gutenberg/index.asset.php b/packages/wp/gutenberg/index.asset.php index b7ca4ef..11f4dcd 100644 --- a/packages/wp/gutenberg/index.asset.php +++ b/packages/wp/gutenberg/index.asset.php @@ -1 +1 @@ - array('react', 'react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-plugins'), 'version' => '22d01165d701dd03054a'); + array('react', 'react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-plugins'), 'version' => '2acb1b0b908a40c3b7a8'); diff --git a/packages/wp/gutenberg/index.js b/packages/wp/gutenberg/index.js index 48ec47c..937d2d4 100644 --- a/packages/wp/gutenberg/index.js +++ b/packages/wp/gutenberg/index.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.React,t=window.wp.blockEditor,o=window.wp.components,s=window.wp.compose,r=window.wp.plugins,n=window.ReactJSXRuntime,a=function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("rect",{width:"8",height:"8",x:"2",y:"2.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",rx:"2",transform:"rotate(90 6 6.5)"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M2 17.5a4 4 0 014-4 4.062 4.062 0 014 4.003 4 4 0 01-8-.003"}),(0,n.jsx)("rect",{width:"19",height:"9",x:"8",y:"7.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",rx:"2",transform:"rotate(90 17.5 12)"}),(0,n.jsx)("path",{fill:"none",d:"M0 0H24V24H0z",transform:"rotate(90 12 12)"})]})},l=window.wp.data,c=window.wp.element,i="cf-theme-toggle-button";var d=function(e){return e.DARK="cf-theme-dark",e.LIGHT="cf-theme-light",e}(d||{});const h=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-light-mode-icon",color:"currentColor",fill:"currentColor",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M12 2.25a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0V3a.75.75 0 0 1 .75-.75ZM7.5 12a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM18.894 6.166a.75.75 0 0 0-1.06-1.06l-1.591 1.59a.75.75 0 1 0 1.06 1.061l1.591-1.59ZM21.75 12a.75.75 0 0 1-.75.75h-2.25a.75.75 0 0 1 0-1.5H21a.75.75 0 0 1 .75.75ZM17.834 18.894a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 1 0-1.061 1.06l1.59 1.591ZM12 18a.75.75 0 0 1 .75.75V21a.75.75 0 0 1-1.5 0v-2.25A.75.75 0 0 1 12 18ZM7.758 17.303a.75.75 0 0 0-1.061-1.06l-1.591 1.59a.75.75 0 0 0 1.06 1.061l1.591-1.59ZM6 12a.75.75 0 0 1-.75.75H3a.75.75 0 0 1 0-1.5h2.25A.75.75 0 0 1 6 12ZM6.697 7.757a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 0 0-1.061 1.06l1.59 1.591Z"})}),u=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-dark-mode-icon",color:"currentColor",fill:"currentColor",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M9.528 1.718a.75.75 0 0 1 .162.819A8.97 8.97 0 0 0 9 6a9 9 0 0 0 9 9 8.97 8.97 0 0 0 3.463-.69.75.75 0 0 1 .981.98 10.503 10.503 0 0 1-9.694 6.46c-5.799 0-10.5-4.7-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 0 1 .818.162Z"})}),w=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-light-mode-icon",color:"currentColor",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"})}),m=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-dark-mode-icon",color:"currentColor",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"})}),g=({icon_size:e,dark_mode_color:t,light_mode_color:o,icon_type:s})=>(0,n.jsxs)(n.Fragment,{children:["filled"===s?(0,n.jsx)(u,{size:e,color:t}):(0,n.jsx)(m,{size:e,color:t}),"filled"===s?(0,n.jsx)(h,{size:e,color:o}):(0,n.jsx)(w,{size:e,color:o})]}),p=()=>(0,n.jsx)(o.ToolbarButton,{title:"Preview Theme (CF)",icon:(0,n.jsx)(g,{icon_size:18,icon_type:"outline",dark_mode_color:"black",light_mode_color:"black"}),className:"cf-theme-toggle-button",label:"Toggle Theme Preview",style:{padding:"6px"},onClick:()=>(()=>{const e=document.querySelector("html");if(!e)return;const t=e.classList.contains(d.DARK)?"light":"dark";window?.localStorage?.setItem("cf-theme",t),e.classList.remove(d.DARK,d.LIGHT),e.classList.add("light"===t?d.LIGHT:d.DARK),[...document.getElementsByClassName(i)].forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===t?d.LIGHT:d.DARK)}),document.querySelectorAll("iframe")?.forEach(e=>{const o=e.contentDocument?.querySelector("html");if(!o)return;o.classList.remove(d.DARK,d.LIGHT),o.classList.add("light"===t?d.LIGHT:d.DARK);const s=e.contentDocument;s&&[...s?.getElementsByClassName(i)]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===t?d.LIGHT:d.DARK)})})})(),"aria-label":"Preview Theme (CF)",onPointerEnterCapture:null,onPointerLeaveCapture:null,placeholder:null});document.addEventListener("DOMContentLoaded",()=>setTimeout(()=>{const e=window?.core_framework_connector?.theme_mode??"light",t=document.querySelector("html");if(!t)return;t.classList.remove(d.DARK,d.LIGHT);let o=window?.localStorage?.getItem("cf-theme");o||(o=e),"auto"===o&&(o=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),t?.classList.add("light"===o?d.LIGHT:d.DARK),document.querySelectorAll("iframe")?.forEach(e=>{const t=e.contentDocument,s=t?.querySelector("html");s&&(s.classList.remove(d.DARK,d.LIGHT),s.classList.add("light"===o?d.LIGHT:d.DARK),[...t?.getElementsByClassName(i)??[]]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===o?d.LIGHT:d.DARK)}))});const s=document.querySelector(".cf-theme-toggle-button");s?.classList.remove(d.DARK,d.LIGHT),s?.classList.add("dark"===o?d.LIGHT:d.DARK),[...document.getElementsByClassName(i)]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===o?d.LIGHT:d.DARK)})},200)),(0,r.registerPlugin)("core-framework-theme-preview",{render:()=>{(window?.core_framework_connector?.gutenberg_enable_dark_mode_preview??1)&&(0,l.subscribe)(()=>{const e=document.querySelector(".edit-post-header-toolbar")||document.querySelector(".edit-site-header-edit-mode__toolbar");e&&(e?.querySelector(".core-framework-theme-preview")||(e=>{const t=document.createElement("div");t.classList.add("core-framework-theme-preview"),e.appendChild(t),(0,c.render)((0,n.jsx)(p,{}),t)})(e))})}});const k={colorStyles:"Colors",typographyStyles:"Typography",spacingStyles:"Spacing",layoutsStyles:"Layouts",designStyles:"Design",componentsStyles:"Components",otherStyles:"Other"};var f=function(e){return e[e.Idle=0]="Idle",e[e.Loading=1]="Loading",e[e.Loaded=2]="Loaded",e[e.Failed=3]="Failed",e}(f||{});window.coreframework={nonce:window.wpApiSettings.nonce,rest_url:window.wpApiSettings.root,core_api_url:`${window.wpApiSettings.root}core-framework/v2/`,get_classes_request_state:f.Idle};const x=e=>[...new Set(e)],v={colorStyles:function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg","data-name":"Layer 3",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("path",{fill:"none",d:"M0 0h24v24H0z"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M3.006 11L17.952 11"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M5 4l4 4M16.732 20.272h0a2.475 2.475 0 010-3.515h0L18.501 15l1.768 1.757a2.477 2.477 0 010 3.515h0a2.512 2.512 0 01-3.537 0zM17.707 11.406l-5.716 5.715a3 3 0 01-4.242 0l-3.87-3.87a3 3 0 010-4.242l5.715-5.716a1 1 0 011.415 0l6.698 6.698a1 1 0 010 1.415z"})]})},typographyStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:[(0,n.jsx)("path",{d:"M6.51 13.82h4.69M7.14 13.82v0M8.86 8.38L6 15.01M11.71 15.01L8.86 8.38M17 21H7a4 4 0 01-4-4V7a4 4 0 014-4h10a4 4 0 014 4v10a4 4 0 01-4 4zM17.75 11v4"}),(0,n.jsx)("path",{d:"M17.161 11.579a2.011 2.011 0 11-2.844 2.844 2.011 2.011 0 012.844-2.844"})]})})},spacingStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsx)("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:(0,n.jsx)("path",{d:"M3 4v16M21 4v16M12 4v16M16 10l2 2-2 2M8 14l-2-2 2-2"})})})},layoutsStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",children:[(0,n.jsx)("path",{d:"M0 0h24v24H0z"}),(0,n.jsxs)("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:[(0,n.jsx)("path",{d:"M21 9H3M10 9v12M21 14.5H10"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]})]})})},designStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",children:[(0,n.jsx)("path",{d:"M0 0H24V24H0z"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M5.636 18.364A8.972 8.972 0 0012 21a9 9 0 009-9v0a9 9 0 00-9-9v0a9 9 0 00-9 9"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M11 10L14 13"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M6.163 14.837l5.751-5.751a2.122 2.122 0 013 0v0a2.122 2.122 0 010 3l-5.751 5.751c-.168.168-.389.27-.625.29l-2.902.238.238-2.902a.999.999 0 01.289-.626z"})]})})},componentsStyles:a,otherStyles:function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg","data-name":"Layer 3",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("path",{fill:"none",d:"M24 24H0V0h24z"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M20.05 14.293a1 1 0 00-1.414 0l-2.843 2.843a1 1 0 00-.293.707V20h2.157a1 1 0 00.707-.293l2.843-2.843a1 1 0 000-1.414zM12 21H8a5 5 0 01-5-5V8a5 5 0 015-5h8a5 5 0 015 5v3"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M11.55 12a.05.05 0 110 0v0M15.05 12a.05.05 0 110 0v0M8.05 12a.05.05 0 110 0v0"})]})}},j=["Border Colors","Backgrounds","Text Colors"],L=["border-","bg-","text-"],_=e=>L.some(t=>e.includes(t))?e.replace("border-","").replace("bg-","").replace("text-",""):"";(async()=>{const{get_classes_request_state:e}=window.coreframework;if(e!==f.Loading&&e!==f.Loaded){window.coreframework.get_classes_request_state=f.Loading;try{const e=await fetch(`${window.coreframework.core_api_url}get-classes`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":window.wpApiSettings.nonce}}),t=await e.json();if(!("classes"in t))return void(window.coreframework.get_classes_request_state=f.Failed);const o=t?.classes;return window.coreframework.classes=o,window.coreframework.get_classes_request_state=f.Loaded,{data:{classes:o},success:!0}}catch(e){console.error(e)}}})();const y=window?.core_framework_connector?.gutenberg_place_controls_at_the_top??!0,M=window?.core_framework_connector?.gutenberg_close_widget_default??!1,b=window?.core_framework_connector?.plugin_name,C=(0,s.createHigherOrderComponent)(s=>r=>{const[l,c]=(0,e.useState)({}),[i,d]=(0,e.useState)(""),[h,u]=(0,e.useState)({active:[],dynamic:[]}),[w,m]=(0,e.useState)(-1);(0,e.useEffect)(()=>{if(!r.attributes.className)return;const e=r.attributes.className.replace(/\s\s+/g," ").trim().split(" ");u(t=>({...t,active:e}))},[]),(0,e.useEffect)(()=>{r.setAttributes({className:[...h.active,...h.dynamic].join(" ")})},[h]),(0,e.useEffect)(()=>{d("")},[r.isSelected]);const g=(0,e.useMemo)(()=>Object.values(l)?.flatMap(e=>Object.values(e))?.flat(),[JSON.stringify(l)]),p=(0,e.useMemo)(()=>{if(!g)return[];const e=r.attributes.className?.replace(/\s\s+/g," "),t=e?.split(" ")||[];if(!t?.length)return[];const o=g?.filter(e=>t?.some(t=>t===e)&&!h.dynamic?.some(t=>t===e)&&""!==e);return[...new Set(o)]},[r.attributes.className,JSON.stringify(h),JSON.stringify(g)]),L=(0,e.useMemo)(()=>i&&g?.length?x(g?.filter(e=>e.toLowerCase().startsWith(i.toLowerCase()))):(m(-1),[]),[i,JSON.stringify(g)]),C=e=>{e&&u(t=>{const o=t.active.includes(e)?t.active.filter(t=>t!==e):[...t.active,e];return r.setAttributes({className:[...o,...h.dynamic].join(" ")}),{...t,active:o,dynamic:[]}})},S=e=>{if(!e)return;const t=r.attributes?.className?.split(" ").some(t=>t===e);t||u(t=>({...t,dynamic:[e]}))},A=()=>u(e=>({...e,dynamic:[]}));return(0,e.useEffect)(()=>{0===Object.keys(g).length&&(async()=>{const e=await(async()=>{const{classes:e,get_classes_request_state:t}=window.coreframework;return t===f.Loaded?{data:{classes:e},success:!0}:{data:null,success:!1}})();window.coreframework.get_classes_request_state===f.Loaded&&e?.data?.classes&&c(e.data?.classes)})()},[window.coreframework?.classes]),(0,n.jsxs)(n.Fragment,{children:[y?null:(0,n.jsx)(s,{...r}),(0,n.jsx)(t.InspectorControls,{children:(0,n.jsxs)(o.PanelBody,{className:"coreframework-panel",title:b,initialOpen:!M,children:[window.coreframework.get_classes_request_state===f.Failed?(0,n.jsx)("p",{className:"components-base-control__error",children:"Failed to fetch classes. Ensure the Gutenberg addon is enabled and changes are saved."}):null,p?.length?(0,n.jsxs)("h3",{children:["Active ",b," classes"]}):null,p?.length?(0,n.jsx)("div",{className:"coreframework-active-classes",children:p?.map(e=>(0,n.jsx)("button",{onClick:()=>C(e),className:"coreframework-class is-destructive",children:e},e))}):null,p.length?null:(0,n.jsxs)("p",{className:"components-base-control__help",children:["There are no active ",b," classes on this block."]}),(0,n.jsx)("hr",{}),(0,n.jsx)(o.SearchControl,{value:i,onChange:d,placeholder:"Search for a class",onKeyDown:e=>{switch(["ArrowUp","ArrowDown","Enter"].includes(e.key)&&e.preventDefault(),u(e=>({...e,dynamic:[]})),e.key){case"ArrowDown":{const e=L.length-1;m(t=>t0===e?0:e-1),S(L[w-1]);break;case"Enter":C(L[w])}},onBlur:()=>{m(-1),A()},__nextHasNoMarginBottom:!0}),(0,n.jsxs)(o.PanelRow,{className:"coreframework-utility-classes",children:[(0,n.jsx)(o.TabPanel,{tabs:Object.entries(l).map(([e])=>({name:e,title:k?.[e]||e,icon:v?.[e]||(0,n.jsx)(a,{})})),className:i?"disable":"",children:e=>i?(0,n.jsx)(n.Fragment,{}):(0,n.jsx)(n.Fragment,{children:Object.entries(l?.[e.name]).map(([e,t])=>(0,n.jsx)(o.PanelBody,{title:e,initialOpen:!1,children:(0,n.jsx)(o.PanelRow,{children:x(t).map(t=>(0,n.jsxs)("button",{className:"coreframework-class "+(r.attributes.className?.split(" ").some(e=>e===t)?"is-active":""),onClick:()=>C(t),onMouseEnter:()=>S(t),onMouseLeave:A,children:[j.includes(e)&&_(t)&&(0,n.jsx)("span",{className:"coreframework-color-preview",style:{backgroundColor:`var(--${_(t)})`}}),t]},t))})}))})}),L.length?(0,n.jsxs)("div",{className:"coreframework-search-results",children:[(0,n.jsx)("h3",{children:"Search Results"}),L.map((e,t)=>(0,n.jsx)("button",{className:`coreframework-class ${r.attributes.className?.split(" ").some(t=>t===e)?"is-active":""} ${w===t?"is-selected":""}`,onClick:()=>C(e),onMouseEnter:()=>S(e),onMouseLeave:A,children:e},e))]}):null,i&&!L.length?(0,n.jsx)("p",{className:"components-base-control__help",children:"No results found."}):null,!g?.length&&!i&&(0,n.jsx)("p",{className:"components-base-control__help",children:"No Classes Found."})]})]})}),y?(0,n.jsx)(s,{...r}):null]})},"withInspectorControl");window.wp.hooks.addFilter("editor.BlockEdit","my-plugin/with-inspector-controls",C)})(); \ No newline at end of file +(()=>{"use strict";const e=window.React,t=window.wp.blockEditor,o=window.wp.components,s=window.wp.compose,r=window.wp.plugins,n=window.ReactJSXRuntime,a=function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("rect",{width:"8",height:"8",x:"2",y:"2.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",rx:"2",transform:"rotate(90 6 6.5)"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M2 17.5a4 4 0 014-4 4.062 4.062 0 014 4.003 4 4 0 01-8-.003"}),(0,n.jsx)("rect",{width:"19",height:"9",x:"8",y:"7.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",rx:"2",transform:"rotate(90 17.5 12)"}),(0,n.jsx)("path",{fill:"none",d:"M0 0H24V24H0z",transform:"rotate(90 12 12)"})]})},l=window.wp.data,c=window.wp.element,i="cf-theme-toggle-button";var d=function(e){return e.DARK="cf-theme-dark",e.LIGHT="cf-theme-light",e}(d||{});const h=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-light-mode-icon",color:"currentColor",fill:"currentColor",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M12 2.25a.75.75 0 0 1 .75.75v2.25a.75.75 0 0 1-1.5 0V3a.75.75 0 0 1 .75-.75ZM7.5 12a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM18.894 6.166a.75.75 0 0 0-1.06-1.06l-1.591 1.59a.75.75 0 1 0 1.06 1.061l1.591-1.59ZM21.75 12a.75.75 0 0 1-.75.75h-2.25a.75.75 0 0 1 0-1.5H21a.75.75 0 0 1 .75.75ZM17.834 18.894a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 1 0-1.061 1.06l1.59 1.591ZM12 18a.75.75 0 0 1 .75.75V21a.75.75 0 0 1-1.5 0v-2.25A.75.75 0 0 1 12 18ZM7.758 17.303a.75.75 0 0 0-1.061-1.06l-1.591 1.59a.75.75 0 0 0 1.06 1.061l1.591-1.59ZM6 12a.75.75 0 0 1-.75.75H3a.75.75 0 0 1 0-1.5h2.25A.75.75 0 0 1 6 12ZM6.697 7.757a.75.75 0 0 0 1.06-1.06l-1.59-1.591a.75.75 0 0 0-1.061 1.06l1.59 1.591Z"})}),w=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-dark-mode-icon",color:"currentColor",fill:"currentColor",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M9.528 1.718a.75.75 0 0 1 .162.819A8.97 8.97 0 0 0 9 6a9 9 0 0 0 9 9 8.97 8.97 0 0 0 3.463-.69.75.75 0 0 1 .981.98 10.503 10.503 0 0 1-9.694 6.46c-5.799 0-10.5-4.7-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 0 1 .818.162Z"})}),u=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-light-mode-icon",color:"currentColor",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"})}),m=({size:e=24,color:t})=>(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"cf-theme-icon cf-dark-mode-icon",color:"currentColor",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",viewBox:"0 0 24 24",style:{width:e,height:e,...t?{color:t}:{}},children:(0,n.jsx)("path",{d:"M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"})}),g=({icon_size:e,dark_mode_color:t,light_mode_color:o,icon_type:s})=>(0,n.jsxs)(n.Fragment,{children:["filled"===s?(0,n.jsx)(w,{size:e,color:t}):(0,n.jsx)(m,{size:e,color:t}),"filled"===s?(0,n.jsx)(h,{size:e,color:o}):(0,n.jsx)(u,{size:e,color:o})]}),p=()=>(0,n.jsx)(o.ToolbarButton,{title:"Preview Theme (CF)",icon:(0,n.jsx)(g,{icon_size:18,icon_type:"outline",dark_mode_color:"black",light_mode_color:"black"}),className:"cf-theme-toggle-button",label:"Toggle Theme Preview",style:{padding:"6px"},onClick:()=>(()=>{const e=document.querySelector("html");if(!e)return;const t=e.classList.contains(d.DARK)?"light":"dark";window?.localStorage?.setItem("cf-theme",t),e.classList.remove(d.DARK,d.LIGHT),e.classList.add("light"===t?d.LIGHT:d.DARK),[...document.getElementsByClassName(i)].forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===t?d.LIGHT:d.DARK)}),document.querySelectorAll("iframe")?.forEach(e=>{const o=e.contentDocument?.querySelector("html");if(!o)return;o.classList.remove(d.DARK,d.LIGHT),o.classList.add("light"===t?d.LIGHT:d.DARK);const s=e.contentDocument;s&&[...s?.getElementsByClassName(i)]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===t?d.LIGHT:d.DARK)})})})(),"aria-label":"Preview Theme (CF)",onPointerEnterCapture:null,onPointerLeaveCapture:null,placeholder:null});document.addEventListener("DOMContentLoaded",()=>setTimeout(()=>{const e=window?.core_framework_connector?.theme_mode??"light",t=document.querySelector("html");if(!t)return;t.classList.remove(d.DARK,d.LIGHT);let o=window?.localStorage?.getItem("cf-theme");o||(o=e),"auto"===o&&(o=window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),t?.classList.add("light"===o?d.LIGHT:d.DARK),document.querySelectorAll("iframe")?.forEach(e=>{const t=e.contentDocument,s=t?.querySelector("html");s&&(s.classList.remove(d.DARK,d.LIGHT),s.classList.add("light"===o?d.LIGHT:d.DARK),[...t?.getElementsByClassName(i)??[]]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===o?d.LIGHT:d.DARK)}))});const s=document.querySelector(".cf-theme-toggle-button");s?.classList.remove(d.DARK,d.LIGHT),s?.classList.add("dark"===o?d.LIGHT:d.DARK),[...document.getElementsByClassName(i)]?.forEach(e=>{e.classList.remove(d.DARK,d.LIGHT),e.classList.add("dark"===o?d.LIGHT:d.DARK)})},200)),(0,r.registerPlugin)("core-framework-theme-preview",{render:()=>{(window?.core_framework_connector?.gutenberg_enable_dark_mode_preview??1)&&(0,l.subscribe)(()=>{const e=document.querySelector(".edit-post-header-toolbar")||document.querySelector(".edit-site-header-edit-mode__toolbar");e&&(e?.querySelector(".core-framework-theme-preview")||(e=>{const t=document.createElement("div");t.classList.add("core-framework-theme-preview"),e.appendChild(t),(0,c.render)((0,n.jsx)(p,{}),t)})(e))})}});const k={colorStyles:"Colors",typographyStyles:"Typography",spacingStyles:"Spacing",layoutsStyles:"Layouts",designStyles:"Design",componentsStyles:"Components",otherStyles:"Other"};var f=function(e){return e[e.Idle=0]="Idle",e[e.Loading=1]="Loading",e[e.Loaded=2]="Loaded",e[e.Failed=3]="Failed",e}(f||{});window.coreframework={nonce:window.wpApiSettings.nonce,rest_url:window.wpApiSettings.root,core_api_url:`${window.wpApiSettings.root}core-framework/v2/`,get_classes_request_state:f.Idle};const x=e=>[...new Set(e)],j=e=>e?e.replace(/\s\s+/g," ").trim().split(" ").filter(Boolean):[],v={colorStyles:function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg","data-name":"Layer 3",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("path",{fill:"none",d:"M0 0h24v24H0z"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M3.006 11L17.952 11"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M5 4l4 4M16.732 20.272h0a2.475 2.475 0 010-3.515h0L18.501 15l1.768 1.757a2.477 2.477 0 010 3.515h0a2.512 2.512 0 01-3.537 0zM17.707 11.406l-5.716 5.715a3 3 0 01-4.242 0l-3.87-3.87a3 3 0 010-4.242l5.715-5.716a1 1 0 011.415 0l6.698 6.698a1 1 0 010 1.415z"})]})},typographyStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:[(0,n.jsx)("path",{d:"M6.51 13.82h4.69M7.14 13.82v0M8.86 8.38L6 15.01M11.71 15.01L8.86 8.38M17 21H7a4 4 0 01-4-4V7a4 4 0 014-4h10a4 4 0 014 4v10a4 4 0 01-4 4zM17.75 11v4"}),(0,n.jsx)("path",{d:"M17.161 11.579a2.011 2.011 0 11-2.844 2.844 2.011 2.011 0 012.844-2.844"})]})})},spacingStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsx)("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:(0,n.jsx)("path",{d:"M3 4v16M21 4v16M12 4v16M16 10l2 2-2 2M8 14l-2-2 2-2"})})})},layoutsStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",children:[(0,n.jsx)("path",{d:"M0 0h24v24H0z"}),(0,n.jsxs)("g",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",children:[(0,n.jsx)("path",{d:"M21 9H3M10 9v12M21 14.5H10"}),(0,n.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})]})]})})},designStyles:function(){return(0,n.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:(0,n.jsxs)("g",{fill:"none",children:[(0,n.jsx)("path",{d:"M0 0H24V24H0z"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M5.636 18.364A8.972 8.972 0 0012 21a9 9 0 009-9v0a9 9 0 00-9-9v0a9 9 0 00-9 9"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M11 10L14 13"}),(0,n.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M6.163 14.837l5.751-5.751a2.122 2.122 0 013 0v0a2.122 2.122 0 010 3l-5.751 5.751c-.168.168-.389.27-.625.29l-2.902.238.238-2.902a.999.999 0 01.289-.626z"})]})})},componentsStyles:a,otherStyles:function(){return(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg","data-name":"Layer 3",viewBox:"0 0 24 24",width:"24",height:"24",children:[(0,n.jsx)("path",{fill:"none",d:"M24 24H0V0h24z"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M20.05 14.293a1 1 0 00-1.414 0l-2.843 2.843a1 1 0 00-.293.707V20h2.157a1 1 0 00.707-.293l2.843-2.843a1 1 0 000-1.414zM12 21H8a5 5 0 01-5-5V8a5 5 0 015-5h8a5 5 0 015 5v3"}),(0,n.jsx)("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",d:"M11.55 12a.05.05 0 110 0v0M15.05 12a.05.05 0 110 0v0M8.05 12a.05.05 0 110 0v0"})]})}},L=["Border Colors","Backgrounds","Text Colors"],_=["border-","bg-","text-"],y=e=>_.some(t=>e.includes(t))?e.replace("border-","").replace("bg-","").replace("text-",""):"";(async()=>{const{get_classes_request_state:e}=window.coreframework;if(e!==f.Loading&&e!==f.Loaded){window.coreframework.get_classes_request_state=f.Loading;try{const e=await fetch(`${window.coreframework.core_api_url}get-classes`,{method:"GET",headers:{"Content-Type":"application/json","X-WP-Nonce":window.wpApiSettings.nonce}}),t=await e.json();if(!("classes"in t))return void(window.coreframework.get_classes_request_state=f.Failed);const o=t?.classes;return window.coreframework.classes=o,window.coreframework.get_classes_request_state=f.Loaded,{data:{classes:o},success:!0}}catch(e){console.error(e)}}})();const M=window?.core_framework_connector?.gutenberg_place_controls_at_the_top??!0,b=window?.core_framework_connector?.gutenberg_close_widget_default??!1,C=window?.core_framework_connector?.plugin_name,S=(0,s.createHigherOrderComponent)(s=>r=>{const[l,c]=(0,e.useState)({}),[i,d]=(0,e.useState)(""),[h,w]=(0,e.useState)(()=>({active:j(r.attributes.className),dynamic:[]})),[u,m]=(0,e.useState)(-1);(0,e.useEffect)(()=>{const e=[...h.active,...h.dynamic].join(" ");e!==j(r.attributes.className).join(" ")&&r.setAttributes({className:e})},[h]),(0,e.useEffect)(()=>{d("")},[r.isSelected]);const g=(0,e.useMemo)(()=>Object.values(l)?.flatMap(e=>Object.values(e))?.flat(),[JSON.stringify(l)]),p=(0,e.useMemo)(()=>{if(!g)return[];const e=r.attributes.className?.replace(/\s\s+/g," "),t=e?.split(" ")||[];if(!t?.length)return[];const o=g?.filter(e=>t?.some(t=>t===e)&&!h.dynamic?.some(t=>t===e)&&""!==e);return[...new Set(o)]},[r.attributes.className,JSON.stringify(h),JSON.stringify(g)]),_=(0,e.useMemo)(()=>i&&g?.length?x(g?.filter(e=>e.toLowerCase().startsWith(i.toLowerCase()))):(m(-1),[]),[i,JSON.stringify(g)]),S=e=>{e&&w(t=>{const o=t.active.includes(e)?t.active.filter(t=>t!==e):[...t.active,e];return r.setAttributes({className:[...o,...h.dynamic].join(" ")}),{...t,active:o,dynamic:[]}})},A=e=>{if(!e)return;const t=r.attributes?.className?.split(" ").some(t=>t===e);t||w(t=>({...t,dynamic:[e]}))},N=()=>w(e=>({...e,dynamic:[]}));return(0,e.useEffect)(()=>{0===Object.keys(g).length&&(async()=>{const e=await(async()=>{const{classes:e,get_classes_request_state:t}=window.coreframework;return t===f.Loaded?{data:{classes:e},success:!0}:{data:null,success:!1}})();window.coreframework.get_classes_request_state===f.Loaded&&e?.data?.classes&&c(e.data?.classes)})()},[window.coreframework?.classes]),(0,n.jsxs)(n.Fragment,{children:[M?null:(0,n.jsx)(s,{...r}),(0,n.jsx)(t.InspectorControls,{children:(0,n.jsxs)(o.PanelBody,{className:"coreframework-panel",title:C,initialOpen:!b,children:[window.coreframework.get_classes_request_state===f.Failed?(0,n.jsx)("p",{className:"components-base-control__error",children:"Failed to fetch classes. Ensure the Gutenberg addon is enabled and changes are saved."}):null,p?.length?(0,n.jsxs)("h3",{children:["Active ",C," classes"]}):null,p?.length?(0,n.jsx)("div",{className:"coreframework-active-classes",children:p?.map(e=>(0,n.jsx)("button",{onClick:()=>S(e),className:"coreframework-class is-destructive",children:e},e))}):null,p.length?null:(0,n.jsxs)("p",{className:"components-base-control__help",children:["There are no active ",C," classes on this block."]}),(0,n.jsx)("hr",{}),(0,n.jsx)(o.SearchControl,{value:i,onChange:d,placeholder:"Search for a class",onKeyDown:e=>{switch(["ArrowUp","ArrowDown","Enter"].includes(e.key)&&e.preventDefault(),w(e=>({...e,dynamic:[]})),e.key){case"ArrowDown":{const e=_.length-1;m(t=>t0===e?0:e-1),A(_[u-1]);break;case"Enter":S(_[u])}},onBlur:()=>{m(-1),N()},__nextHasNoMarginBottom:!0}),(0,n.jsxs)(o.PanelRow,{className:"coreframework-utility-classes",children:[(0,n.jsx)(o.TabPanel,{tabs:Object.entries(l).map(([e])=>({name:e,title:k?.[e]||e,icon:v?.[e]||(0,n.jsx)(a,{})})),className:i?"disable":"",children:e=>i?(0,n.jsx)(n.Fragment,{}):(0,n.jsx)(n.Fragment,{children:Object.entries(l?.[e.name]).map(([e,t])=>(0,n.jsx)(o.PanelBody,{title:e,initialOpen:!1,children:(0,n.jsx)(o.PanelRow,{children:x(t).map(t=>(0,n.jsxs)("button",{className:"coreframework-class "+(r.attributes.className?.split(" ").some(e=>e===t)?"is-active":""),onClick:()=>S(t),onMouseEnter:()=>A(t),onMouseLeave:N,children:[L.includes(e)&&y(t)&&(0,n.jsx)("span",{className:"coreframework-color-preview",style:{backgroundColor:`var(--${y(t)})`}}),t]},t))})}))})}),_.length?(0,n.jsxs)("div",{className:"coreframework-search-results",children:[(0,n.jsx)("h3",{children:"Search Results"}),_.map((e,t)=>(0,n.jsx)("button",{className:`coreframework-class ${r.attributes.className?.split(" ").some(t=>t===e)?"is-active":""} ${u===t?"is-selected":""}`,onClick:()=>S(e),onMouseEnter:()=>A(e),onMouseLeave:N,children:e},e))]}):null,i&&!_.length?(0,n.jsx)("p",{className:"components-base-control__help",children:"No results found."}):null,!g?.length&&!i&&(0,n.jsx)("p",{className:"components-base-control__help",children:"No Classes Found."})]})]})}),M?(0,n.jsx)(s,{...r}):null]})},"withInspectorControl");window.wp.hooks.addFilter("editor.BlockEdit","my-plugin/with-inspector-controls",S)})(); \ No newline at end of file