@gem-sdk/core 2.0.0-dev.878 → 2.0.0-dev.884
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),react=require("react");require("zustand");var BuilderPreviewContext=require("../contexts/BuilderPreviewContext.js"),ShopContext=require("../contexts/ShopContext.js");require("@gem-sdk/adapter-shopify"),require("swr"),require("swr/mutation"),require("vanilla-lazyload"),require("../hooks/useCartUI.js");var CreateThemeSection=require("./theme-section/CreateThemeSection.js"),AIContentGenerator=require("./ai-generator/AIContentGenerator.js"),AIGenContentLoading=require("./ai-generator/AIGenContentLoading.js"),Tooltip=require("./toolbar/Tooltip.js"),ThemeSectionStatus=require("./theme-section/ThemeSectionStatus.js"),useToolbarPostPurchase=require("../hooks/useToolbarPostPurchase.js"),Resize=require("./resize/Resize.js");require("../helpers/convert.js");const SECTION_LIMIT=25,notVisible=e=>{let t=getComputedStyle(e).overflow;return"visible"!==t},isSection=e=>{let t=e.getAttribute("data-component-tag");return"Section"===t},ComponentToolbarPreview=e=>{let t=e.isThemeSection,i=e.isShopifySection,o=ShopContext.useShopStore(e=>e.pageType),n=BuilderPreviewContext.useBuilderPreviewStore(e=>e.getParents),l=BuilderPreviewContext.useBuilderPreviewStore(e=>e.getItem("ROOT")),r=BuilderPreviewContext.useBuilderPreviewStore(e=>e.isThemeSectionEditor),[a,s]=react.useState(null),[d,u]=react.useState(!1),[C,c]=react.useState(!1),[h,x]=react.useState([]),[p,m]=react.useState("top"),[j,v]=react.useState(!1),[b,g]=react.useState({width:"",text:""}),[R,f]=react.useState(!1),w=react.useMemo(()=>"POST_PURCHASE"===o,[o]),{checkDisableDelete:S,getTooltipText:T,checkDisableDuplicate:P}=useToolbarPostPurchase.usePostPurchase(e.uid,e.tag||""),M=(e,t)=>{let i=h.length,o=e.getBoundingClientRect(),n=t.getBoundingClientRect();return o.top-n.top<36*i},V=(e,t)=>{let i=t||e;if(e&&!isSection(e))return notVisible(e)&&M(t,e)?e:e.parentElement?V(e.parentElement,i):void 0},Z=react.useCallback(()=>{if("Section"==e.tag)return"bottom";let t=document.querySelector('[data-toolbar-active="true"]');if(t){let e=t.getBoundingClientRect();e.top<60?m("bottom"):m("top")}},[e.tag]),H=react.useCallback(t=>{let i=t.detail;if(i?.componentUid==e.uid){Z(),w&&(v(S()),g(T()),f(P()));let t=n(e.uid).filter(e=>!("ROOT"===e.uid||"Section"===e.tag&&r||e.editorConfigs?.toolbar?.hide||e.editorConfigs?.component?.noSetting)).slice(0,3);x(t)}else x([]),u(!1)},[e.uid,w,n,S,T,P,r,Z]);if(react.useEffect(()=>(window.addEventListener("editor:active-component",H),()=>{window.removeEventListener("editor:active-component",H)}),[H]),"section"===e.type||e.editorConfigs?.toolbar?.hide)return null;let E=()=>l?.childrens?.length||0,L=()=>"Section"!==e.tag?-1:l?.childrens?.length?l.childrens.findIndex(t=>t==e.uid):-1,y=e=>{if(!h.length)return;let t=e?.target||null,i=t.closest("[data-toolbar-active]");if(!t||!i)return;if(d)c(!1),u(!1);else{let e=V(i,i);if(e)c(!0);else{let e=i.getBoundingClientRect();e.top<36*h.length?c(!0):c(!1)}u(!0)}let o=new CustomEvent("editor:toolbar:show-parents",{bubbles:!0,detail:{value:!d}});window.dispatchEvent(o)},B=o=>{o.preventDefault(),o.stopPropagation();let n=new CustomEvent("editor:toolbar:delete-component",{bubbles:!0,detail:{componentUid:e.uid,isThemeSection:t,isShopifySection:i}});return window.dispatchEvent(n),!1},q=o=>{if(o.preventDefault(),o.stopPropagation(),E()>=25&&"Section"==e.tag)return!1;let n=new CustomEvent("editor:toolbar:duplicate-component",{bubbles:!0,detail:{componentUid:e.uid,isThemeSection:t,isShopifySection:i}});return window.dispatchEvent(n),!1},I=t=>{t.preventDefault(),t.stopPropagation();let o=new CustomEvent("editor:toolbar:visibility-shopify-section",{bubbles:!0,detail:{componentUid:e.uid,isShopifySection:i}});return window.dispatchEvent(o),!1},A=t=>{t.preventDefault(),t.stopPropagation();let i=new CustomEvent("editor:toolbar:zoom-out-component",{bubbles:!0,detail:{componentUid:e.uid}});return window.dispatchEvent(i),!1},k=()=>{s(null),window.removeEventListener("editor:close-add-section-popup",k)},F=(t,i)=>{if(t.preventDefault(),t.stopPropagation(),E()>=25)return!1;let o=t.target;if(o){s(i);let t=o.getBoundingClientRect(),n=new CustomEvent("editor:toolbar:add-section",{bubbles:!0,detail:{componentUid:e.uid,position:i,top:t.top+t.height/2}});window.dispatchEvent(n),window.addEventListener("editor:close-add-section-popup",k)}return!1},U=()=>{if(i)return`Shopify section: ${e.name}`;let t=e.name&&e.name===`Section ${e.uid}`;return E()>=20?`${t?"Section":e?.name} ${L()+1}/25`:t?`Section ${L()+1}`:e?.name};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!("Section"==e.tag&&r)&&jsxRuntime.jsxs("div",{"data-toolbar":!0,"data-toolbar-section":"Section"==e.tag,"data-toolbar-theme-section":"Section"==e.tag&&!!t||r,"data-toolbar-shopify-section":"Section"==e.tag&&!!i,"data-toolbar-limit":L()>=25,children:[jsxRuntime.jsxs("div",{"data-toolbar-show-parent":!0,onClick:e=>y(e),"aria-hidden":"true",children:[jsxRuntime.jsx("div",{"data-toolbar-icon-drag":!0,children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),"Section"==e.tag?jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:U()}):jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:e.customLabel||e.label}),"Section"!==e.tag&&h.length>0&&jsxRuntime.jsx("div",{"data-toolbar-icon-parent":!0,"data-toolbar-icon-parent-open":d,children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M5.65522 10C5.07265 10 4.7809 9.22865 5.19284 8.77753L7.53762 6.20974C7.79298 5.93009 8.20702 5.93009 8.46238 6.20974L10.8072 8.77754C11.2191 9.22866 10.9274 10 10.3448 10H5.65522Z",fill:"currentColor"})})})]}),d&&h.map((e,t)=>{let i=e?.childrens?.length??0,o=e.label;return"Row"===e.label&&(o=i<=1?e.label+" "+i+" col":e.label+" "+i+" cols"),jsxRuntime.jsxs("div",{"data-toolbar-parent":!0,"data-parent-uid":e.uid,"data-toolbar-theme-section":r,"data-toolbar-parent-revert":C,style:{top:C?`${36*(t+1)}px`:`${-36*(t+1)}px`},children:[jsxRuntime.jsx("div",{"data-toolbar-icon-drag":!0,children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:o})]},e.uid)}),"Section"===e.tag&&!e.isThemeSection&&"STATIC"!==o&&"POST_PURCHASE"!==o&&!e.isShopifySection&&25>L()&&jsxRuntime.jsx(CreateThemeSection.CreateThemeSection,{...e}),jsxRuntime.jsx(AIContentGenerator.AIContentGenerator,{...e}),"Sticky"==e.tag&&jsxRuntime.jsx("div",{"data-toolbar-zoom-out":!0,onClick:e=>A(e),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.5 7C14.7761 7 15 6.77614 15 6.5C15 6.22386 14.7761 6 14.5 6L10.7072 6L14.8536 1.85355C15.0489 1.65829 15.0489 1.34171 14.8536 1.14645C14.6584 0.951186 14.3418 0.951185 14.1465 1.14645L10 5.29297L10 1.5C10 1.22386 9.77614 1 9.5 1C9.22386 1 9 1.22386 9 1.5L9 6.5C9 6.77614 9.22386 7 9.5 7L14.5 7ZM6 10.7073L6 14.5C6 14.7761 6.22386 15 6.5 15C6.77614 15 7 14.7761 7 14.5L7 9.5C7 9.22386 6.77614 9 6.5 9H1.5C1.22386 9 1 9.22386 1 9.5C1 9.77614 1.22386 10 1.5 10H5.29306L1.14662 14.1464C0.951353 14.3417 0.951353 14.6583 1.14662 14.8536C1.34188 15.0488 1.65846 15.0488 1.85372 14.8536L6 10.7073Z",fill:"currentColor"})})}),jsxRuntime.jsx(Tooltip.default,{enable:"Section"==e.tag&&E()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"bottom","data-toolbar-duplicate":!0,"data-toolbar-disable":"Section"==e.tag&&E()>=25||R,onClick:R?void 0:e=>q(e),"aria-hidden":"true",className:R?"!gp-cursor-not-allowed":"",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M6.08423 1.21289C5.53194 1.21289 5.08423 1.66061 5.08423 2.21289V3.78711H4.26172C3.43329 3.78711 2.76172 4.45868 2.76172 5.28711V13.2871C2.76172 14.1155 3.43329 14.7871 4.26172 14.7871H10.2617C11.0901 14.7871 11.7617 14.1155 11.7617 13.2871V12.4629H13.0842C13.6365 12.4629 14.0842 12.0152 14.0842 11.4629V2.21289C14.0842 1.66061 13.6365 1.21289 13.0842 1.21289H6.08423ZM10.7617 12.4629H6.08423C5.53194 12.4629 5.08423 12.0152 5.08423 11.4629V4.78711H4.26172C3.98558 4.78711 3.76172 5.01097 3.76172 5.28711V13.2871C3.76172 13.5633 3.98558 13.7871 4.26172 13.7871H10.2617C10.5379 13.7871 10.7617 13.5633 10.7617 13.2871V12.4629Z",fill:"currentColor"})})}),"Section"===e.tag&&e.isShopifySection&&jsxRuntime.jsx(Tooltip.default,{enable:!1,text:"",position:"bottom","data-toolbar-visibility":!0,onClick:e=>I(e),"aria-hidden":"true",children:e.isShopifyVisibility?jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99841C10.499 6.61803 9.37945 5.49961 7.99909 5.50027C6.6187 5.50071 5.49975 6.61987 5.49975 8.00027C5.49975 9.38099 6.61904 10.5003 7.99975 10.5003C9.38021 10.5003 10.4996 9.38184 10.4998 8.00107V7.99841ZM7.99949 6.50027C8.82762 6.49983 9.49931 7.17081 9.49975 7.99894V8.00054C9.49975 8.8288 8.82836 9.50027 7.99975 9.50027C7.17133 9.50027 6.49975 8.8287 6.49975 8.00027C6.49975 7.172 7.17122 6.50049 7.99949 6.50027Z",fill:"white"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50098C4.53098 3.50106 2.24443 6.11641 1.43599 7.20809C1.0847 7.68246 1.08696 8.32021 1.43971 8.79238C2.25325 9.88131 4.55461 12.4995 7.9987 12.4995C11.5041 12.4995 13.7751 9.87636 14.5731 8.78489C14.9175 8.31382 14.915 7.68401 14.5684 7.21544C13.7641 6.12774 11.474 3.50089 7.99869 3.50098ZM2.23962 7.80322C3.016 6.75484 5.04126 4.50105 7.99871 4.50098C10.9629 4.50091 12.9916 6.76501 13.7644 7.81003C13.8513 7.92751 13.8516 8.07739 13.7658 8.19472C13.0028 9.23835 10.9929 11.4995 7.9987 11.4995C5.0648 11.4995 3.025 9.24349 2.24082 8.19386C2.15178 8.07468 2.15162 7.92206 2.23962 7.80322Z",fill:"white"})]}):jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99857C10.499 6.61819 9.37945 5.49977 7.99909 5.50044C6.6187 5.50088 5.49975 6.62003 5.49975 8.00044C5.49975 9.38115 6.61904 10.5004 7.99975 10.5004C9.38021 10.5004 10.4996 9.382 10.4998 8.00124V7.99857ZM7.99949 6.50044C8.82762 6.49999 9.49931 7.17097 9.49975 7.9991V8.0007C9.49975 8.82896 8.82836 9.50044 7.99975 9.50044C7.17133 9.50044 6.49975 8.82886 6.49975 8.00044C6.49975 7.17216 7.17122 6.50066 7.99949 6.50044Z",fill:"#F9F9F9"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50114C4.53098 3.50122 2.24443 6.11658 1.43599 7.20825C1.0847 7.68262 1.08696 8.32038 1.43971 8.79254C2.25325 9.88147 4.55461 12.4997 7.9987 12.4997C11.5041 12.4997 13.7751 9.87652 14.5731 8.78505C14.9175 8.31398 14.915 7.68417 14.5684 7.2156C13.7641 6.1279 11.474 3.50106 7.99869 3.50114ZM2.23962 7.80338C3.016 6.755 5.04126 4.50121 7.99871 4.50114C10.9629 4.50107 12.9916 6.76517 13.7644 7.81019C13.8513 7.92767 13.8516 8.07755 13.7658 8.19488C13.0028 9.23851 10.9929 11.4997 7.9987 11.4997C5.0648 11.4997 3.025 9.24365 2.24082 8.19402C2.15178 8.07484 2.15162 7.92222 2.23962 7.80338Z",fill:"#F9F9F9"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.4607 2.6163C14.6728 2.87086 14.6384 3.2492 14.3839 3.46134L2.38387 13.4613C2.1293 13.6735 1.75096 13.6391 1.53882 13.3845C1.32668 13.13 1.36108 12.7516 1.61565 12.5395L13.6156 2.53947C13.8702 2.32733 14.2486 2.36173 14.4607 2.6163Z",fill:"#F9F9F9"})]})}),jsxRuntime.jsx(Tooltip.default,{"data-toolbar-delete":!0,onClick:e=>j?null:B(e),enable:j,"data-toolbar-disable":j,width:b.width,text:b.text,position:p,"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2.88965V2.38965C11 1.56122 10.3284 0.889648 9.5 0.889648H6.5C5.67157 0.889648 5 1.56122 5 2.38965V2.88965H2C1.72386 2.88965 1.5 3.11351 1.5 3.38965C1.5 3.66579 1.72386 3.88965 2 3.88965H3.21997V13.1099C3.21997 14.2144 4.1154 15.1099 5.21997 15.1099H11.22C12.3245 15.1099 13.22 14.2144 13.22 13.1099V3.88965H14C14.2761 3.88965 14.5 3.66579 14.5 3.38965C14.5 3.11351 14.2761 2.88965 14 2.88965H11ZM6 2.88965H10V2.38965C10 2.11351 9.77614 1.88965 9.5 1.88965H6.5C6.22386 1.88965 6 2.11351 6 2.38965V2.88965ZM6.24976 6.13965C6.66397 6.13965 6.99976 6.47543 6.99976 6.88965V11.3896C6.99976 11.8039 6.66397 12.1396 6.24976 12.1396C5.83554 12.1396 5.49976 11.8039 5.49976 11.3896V6.88965C5.49976 6.47543 5.83554 6.13965 6.24976 6.13965ZM10.4998 6.88965C10.4998 6.47543 10.164 6.13965 9.74976 6.13965C9.33554 6.13965 8.99976 6.47543 8.99976 6.88965V11.3896C8.99976 11.8039 9.33554 12.1396 9.74976 12.1396C10.164 12.1396 10.4998 11.8039 10.4998 11.3896V6.88965Z",fill:"currentColor"})})})]},e.uid),"STATIC"!==o&&"POST_PURCHASE"!==o&&25>L()&&jsxRuntime.jsx(ThemeSectionStatus.ThemeSectionStatusWrapper,{...e}),jsxRuntime.jsx("div",{"data-outline":!0,"data-outline-section":"Section"==e.tag,"data-outline-theme-section":"Section"==e.tag&&!!t||r,"data-outline-shopify-section":"Section"==e.tag&&!!i,"data-outline-limit":L()>=25},"outline-"+e.uid),"Section"==e.tag&&!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Tooltip.default,{enable:E()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-top":!0,"data-toolbar-disable":E()>=25,"data-toolbar-add-open":"above"==a,onClick:e=>F(e,"above"),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})}),jsxRuntime.jsx(Tooltip.default,{enable:E()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-bottom":!0,"data-toolbar-disable":E()>=25,"data-toolbar-add-open":"below"==a,onClick:e=>F(e,"below"),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})})]}),jsxRuntime.jsx(AIGenContentLoading.AIGenContentLoading,{...e}),jsxRuntime.jsx(Resize.default,{...e})]})};var ComponentToolbarPreview$1=react.memo(ComponentToolbarPreview);exports.default=ComponentToolbarPreview$1;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),react=require("react");require("zustand");var BuilderPreviewContext=require("../contexts/BuilderPreviewContext.js"),ShopContext=require("../contexts/ShopContext.js");require("@gem-sdk/adapter-shopify"),require("swr"),require("swr/mutation"),require("vanilla-lazyload"),require("../hooks/useCartUI.js");var CreateThemeSection=require("./theme-section/CreateThemeSection.js"),AIContentGenerator=require("./ai-generator/AIContentGenerator.js"),AIGenContentLoading=require("./ai-generator/AIGenContentLoading.js"),Tooltip=require("./toolbar/Tooltip.js"),ThemeSectionStatus=require("./theme-section/ThemeSectionStatus.js"),useToolbarPostPurchase=require("../hooks/useToolbarPostPurchase.js"),Resize=require("./resize/Resize.js");require("../helpers/convert.js");const SECTION_LIMIT=25,notVisible=e=>{let t=getComputedStyle(e).overflow;return"visible"!==t},isSection=e=>{let t=e.getAttribute("data-component-tag");return"Section"===t},ComponentToolbarPreview=e=>{let t=e.isThemeSection,i=e.isShopifySection,o=ShopContext.useShopStore(e=>e.pageType),n=BuilderPreviewContext.useBuilderPreviewStore(e=>e.getParents),l=BuilderPreviewContext.useBuilderPreviewStore(e=>e.getItem("ROOT")),r=BuilderPreviewContext.useBuilderPreviewStore(e=>e.isThemeSectionEditor),[a,s]=react.useState(null),[d,u]=react.useState(!1),[C,c]=react.useState(!1),[h,x]=react.useState([]),[p,m]=react.useState("top"),[j,v]=react.useState(!1),[b,g]=react.useState({width:"",text:""}),[R,f]=react.useState(!1),w=react.useMemo(()=>"POST_PURCHASE"===o,[o]),{checkDisableDelete:S,getTooltipText:T,checkDisableDuplicate:P}=useToolbarPostPurchase.usePostPurchase(e.uid,e.tag||""),M=(e,t)=>{let i=h.length,o=e.getBoundingClientRect(),n=t.getBoundingClientRect();return o.top-n.top<36*i},V=(e,t)=>{let i=t||e;if(e&&!isSection(e))return notVisible(e)&&M(t,e)?e:e.parentElement?V(e.parentElement,i):void 0},Z=react.useCallback(()=>{if("Section"==e.tag)return"bottom";let t=document.querySelector('[data-toolbar-active="true"]');if(t){let e=t.getBoundingClientRect();e.top<60?m("bottom"):m("top")}},[e.tag]),H=react.useCallback(t=>{let i=t.detail;if(i?.componentUid==e.uid){Z(),w&&(v(S()),g(T()),f(P()));let t=n(e.uid).filter(e=>!("ROOT"===e.uid||"Section"===e.tag&&r||e.editorConfigs?.toolbar?.hide||e.editorConfigs?.component?.noSetting)).slice(0,3);x(t)}else x([]),u(!1)},[e.uid,w,n,S,T,P,r,Z]);if(react.useEffect(()=>(window.addEventListener("editor:active-component",H),()=>{window.removeEventListener("editor:active-component",H)}),[H]),"section"===e.type||e.editorConfigs?.toolbar?.hide)return null;let y=()=>l?.childrens?.length||0,E=()=>"Section"!==e.tag?-1:l?.childrens?.length?l.childrens.findIndex(t=>t==e.uid):-1,L=e=>{if(!h.length)return;let t=e?.target||null,i=t.closest("[data-toolbar-active]");if(!t||!i)return;if(d)c(!1),u(!1);else{let e=V(i,i);if(e)c(!0);else{let e=i.getBoundingClientRect();e.top<36*h.length?c(!0):c(!1)}u(!0)}let o=new CustomEvent("editor:toolbar:show-parents",{bubbles:!0,detail:{value:!d}});window.dispatchEvent(o)},B=o=>{o.preventDefault(),o.stopPropagation();let n=new CustomEvent("editor:toolbar:delete-component",{bubbles:!0,detail:{componentUid:e.uid,isThemeSection:t,isShopifySection:i}});return window.dispatchEvent(n),!1},q=o=>{if(o.preventDefault(),o.stopPropagation(),y()>=25&&"Section"==e.tag)return!1;let n=new CustomEvent("editor:toolbar:duplicate-component",{bubbles:!0,detail:{componentUid:e.uid,isThemeSection:t,isShopifySection:i}});return window.dispatchEvent(n),!1},I=t=>{t.preventDefault(),t.stopPropagation();let o=new CustomEvent("editor:toolbar:visibility-shopify-section",{bubbles:!0,detail:{componentUid:e.uid,isShopifySection:i}});return window.dispatchEvent(o),!1},A=t=>{t.preventDefault(),t.stopPropagation();let i=new CustomEvent("editor:toolbar:zoom-out-component",{bubbles:!0,detail:{componentUid:e.uid}});return window.dispatchEvent(i),!1},k=()=>{s(null),window.removeEventListener("editor:close-add-section-popup",k)},F=(t,i)=>{if(t.preventDefault(),t.stopPropagation(),y()>=25)return!1;let o=t.target;if(o){s(i);let t=o.getBoundingClientRect(),n=new CustomEvent("editor:toolbar:add-section",{bubbles:!0,detail:{componentUid:e.uid,position:i,top:t.top+t.height/2}});window.dispatchEvent(n),window.addEventListener("editor:close-add-section-popup",k)}return!1},U=()=>{if(i)return`Shopify section: ${e.name}`;let t=e.name&&e.name===`Section ${e.uid}`;return y()>=20?`${t?"Section":e?.name} ${E()+1}/25`:t?`Section ${E()+1}`:e?.name};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!("Section"==e.tag&&r)&&jsxRuntime.jsxs("div",{"data-toolbar":!0,"data-toolbar-section":"Section"==e.tag,"data-toolbar-theme-section":"Section"==e.tag&&!!t||r,"data-toolbar-shopify-section":"Section"==e.tag&&!!i,"data-toolbar-limit":E()>=25,children:[jsxRuntime.jsxs("div",{"data-toolbar-show-parent":!0,onClick:e=>L(e),"aria-hidden":"true",children:[jsxRuntime.jsx("div",{"data-toolbar-icon-drag":!0,children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),"Section"==e.tag?jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:U()}):jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:e.customLabel||e.label}),"Section"!==e.tag&&h.length>0&&jsxRuntime.jsx("div",{"data-toolbar-icon-parent":!0,"data-toolbar-icon-parent-open":d,children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M5.65522 10C5.07265 10 4.7809 9.22865 5.19284 8.77753L7.53762 6.20974C7.79298 5.93009 8.20702 5.93009 8.46238 6.20974L10.8072 8.77754C11.2191 9.22866 10.9274 10 10.3448 10H5.65522Z",fill:"currentColor"})})})]}),d&&h.map((e,t)=>{let i=e?.childrens?.length??0,o=e.label;return"Row"===e.label&&(o=i<=1?e.label+" "+i+" col":e.label+" "+i+" cols"),jsxRuntime.jsxs("div",{"data-toolbar-parent":!0,"data-parent-uid":e.uid,"data-toolbar-theme-section":r,"data-toolbar-parent-revert":C,style:{top:C?`${36*(t+1)}px`:`${-36*(t+1)}px`},children:[jsxRuntime.jsx("div",{"data-toolbar-icon-drag":!0,children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[jsxRuntime.jsx("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),jsxRuntime.jsx("div",{"data-toolbar-name":!0,children:o})]},e.uid)}),"Section"===e.tag&&!e.isThemeSection&&"STATIC"!==o&&"POST_PURCHASE"!==o&&!e.isShopifySection&&25>E()&&jsxRuntime.jsx(CreateThemeSection.CreateThemeSection,{...e}),!e.isShopifySection&&jsxRuntime.jsx(AIContentGenerator.AIContentGenerator,{...e}),"Sticky"==e.tag&&jsxRuntime.jsx("div",{"data-toolbar-zoom-out":!0,onClick:e=>A(e),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.5 7C14.7761 7 15 6.77614 15 6.5C15 6.22386 14.7761 6 14.5 6L10.7072 6L14.8536 1.85355C15.0489 1.65829 15.0489 1.34171 14.8536 1.14645C14.6584 0.951186 14.3418 0.951185 14.1465 1.14645L10 5.29297L10 1.5C10 1.22386 9.77614 1 9.5 1C9.22386 1 9 1.22386 9 1.5L9 6.5C9 6.77614 9.22386 7 9.5 7L14.5 7ZM6 10.7073L6 14.5C6 14.7761 6.22386 15 6.5 15C6.77614 15 7 14.7761 7 14.5L7 9.5C7 9.22386 6.77614 9 6.5 9H1.5C1.22386 9 1 9.22386 1 9.5C1 9.77614 1.22386 10 1.5 10H5.29306L1.14662 14.1464C0.951353 14.3417 0.951353 14.6583 1.14662 14.8536C1.34188 15.0488 1.65846 15.0488 1.85372 14.8536L6 10.7073Z",fill:"currentColor"})})}),jsxRuntime.jsx(Tooltip.default,{enable:"Section"==e.tag&&y()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"bottom","data-toolbar-duplicate":!0,"data-toolbar-disable":"Section"==e.tag&&y()>=25||R,onClick:R?void 0:e=>q(e),"aria-hidden":"true",className:R?"!gp-cursor-not-allowed":"",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M6.08423 1.21289C5.53194 1.21289 5.08423 1.66061 5.08423 2.21289V3.78711H4.26172C3.43329 3.78711 2.76172 4.45868 2.76172 5.28711V13.2871C2.76172 14.1155 3.43329 14.7871 4.26172 14.7871H10.2617C11.0901 14.7871 11.7617 14.1155 11.7617 13.2871V12.4629H13.0842C13.6365 12.4629 14.0842 12.0152 14.0842 11.4629V2.21289C14.0842 1.66061 13.6365 1.21289 13.0842 1.21289H6.08423ZM10.7617 12.4629H6.08423C5.53194 12.4629 5.08423 12.0152 5.08423 11.4629V4.78711H4.26172C3.98558 4.78711 3.76172 5.01097 3.76172 5.28711V13.2871C3.76172 13.5633 3.98558 13.7871 4.26172 13.7871H10.2617C10.5379 13.7871 10.7617 13.5633 10.7617 13.2871V12.4629Z",fill:"currentColor"})})}),"Section"===e.tag&&e.isShopifySection&&jsxRuntime.jsx(Tooltip.default,{enable:!1,text:"",position:"bottom","data-toolbar-visibility":!0,onClick:e=>I(e),"aria-hidden":"true",children:e.isShopifyVisibility?jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99841C10.499 6.61803 9.37945 5.49961 7.99909 5.50027C6.6187 5.50071 5.49975 6.61987 5.49975 8.00027C5.49975 9.38099 6.61904 10.5003 7.99975 10.5003C9.38021 10.5003 10.4996 9.38184 10.4998 8.00107V7.99841ZM7.99949 6.50027C8.82762 6.49983 9.49931 7.17081 9.49975 7.99894V8.00054C9.49975 8.8288 8.82836 9.50027 7.99975 9.50027C7.17133 9.50027 6.49975 8.8287 6.49975 8.00027C6.49975 7.172 7.17122 6.50049 7.99949 6.50027Z",fill:"white"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50098C4.53098 3.50106 2.24443 6.11641 1.43599 7.20809C1.0847 7.68246 1.08696 8.32021 1.43971 8.79238C2.25325 9.88131 4.55461 12.4995 7.9987 12.4995C11.5041 12.4995 13.7751 9.87636 14.5731 8.78489C14.9175 8.31382 14.915 7.68401 14.5684 7.21544C13.7641 6.12774 11.474 3.50089 7.99869 3.50098ZM2.23962 7.80322C3.016 6.75484 5.04126 4.50105 7.99871 4.50098C10.9629 4.50091 12.9916 6.76501 13.7644 7.81003C13.8513 7.92751 13.8516 8.07739 13.7658 8.19472C13.0028 9.23835 10.9929 11.4995 7.9987 11.4995C5.0648 11.4995 3.025 9.24349 2.24082 8.19386C2.15178 8.07468 2.15162 7.92206 2.23962 7.80322Z",fill:"white"})]}):jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99857C10.499 6.61819 9.37945 5.49977 7.99909 5.50044C6.6187 5.50088 5.49975 6.62003 5.49975 8.00044C5.49975 9.38115 6.61904 10.5004 7.99975 10.5004C9.38021 10.5004 10.4996 9.382 10.4998 8.00124V7.99857ZM7.99949 6.50044C8.82762 6.49999 9.49931 7.17097 9.49975 7.9991V8.0007C9.49975 8.82896 8.82836 9.50044 7.99975 9.50044C7.17133 9.50044 6.49975 8.82886 6.49975 8.00044C6.49975 7.17216 7.17122 6.50066 7.99949 6.50044Z",fill:"#F9F9F9"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50114C4.53098 3.50122 2.24443 6.11658 1.43599 7.20825C1.0847 7.68262 1.08696 8.32038 1.43971 8.79254C2.25325 9.88147 4.55461 12.4997 7.9987 12.4997C11.5041 12.4997 13.7751 9.87652 14.5731 8.78505C14.9175 8.31398 14.915 7.68417 14.5684 7.2156C13.7641 6.1279 11.474 3.50106 7.99869 3.50114ZM2.23962 7.80338C3.016 6.755 5.04126 4.50121 7.99871 4.50114C10.9629 4.50107 12.9916 6.76517 13.7644 7.81019C13.8513 7.92767 13.8516 8.07755 13.7658 8.19488C13.0028 9.23851 10.9929 11.4997 7.9987 11.4997C5.0648 11.4997 3.025 9.24365 2.24082 8.19402C2.15178 8.07484 2.15162 7.92222 2.23962 7.80338Z",fill:"#F9F9F9"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.4607 2.6163C14.6728 2.87086 14.6384 3.2492 14.3839 3.46134L2.38387 13.4613C2.1293 13.6735 1.75096 13.6391 1.53882 13.3845C1.32668 13.13 1.36108 12.7516 1.61565 12.5395L13.6156 2.53947C13.8702 2.32733 14.2486 2.36173 14.4607 2.6163Z",fill:"#F9F9F9"})]})}),jsxRuntime.jsx(Tooltip.default,{"data-toolbar-delete":!0,onClick:e=>j?null:B(e),enable:j,"data-toolbar-disable":j,width:b.width,text:b.text,position:p,"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2.88965V2.38965C11 1.56122 10.3284 0.889648 9.5 0.889648H6.5C5.67157 0.889648 5 1.56122 5 2.38965V2.88965H2C1.72386 2.88965 1.5 3.11351 1.5 3.38965C1.5 3.66579 1.72386 3.88965 2 3.88965H3.21997V13.1099C3.21997 14.2144 4.1154 15.1099 5.21997 15.1099H11.22C12.3245 15.1099 13.22 14.2144 13.22 13.1099V3.88965H14C14.2761 3.88965 14.5 3.66579 14.5 3.38965C14.5 3.11351 14.2761 2.88965 14 2.88965H11ZM6 2.88965H10V2.38965C10 2.11351 9.77614 1.88965 9.5 1.88965H6.5C6.22386 1.88965 6 2.11351 6 2.38965V2.88965ZM6.24976 6.13965C6.66397 6.13965 6.99976 6.47543 6.99976 6.88965V11.3896C6.99976 11.8039 6.66397 12.1396 6.24976 12.1396C5.83554 12.1396 5.49976 11.8039 5.49976 11.3896V6.88965C5.49976 6.47543 5.83554 6.13965 6.24976 6.13965ZM10.4998 6.88965C10.4998 6.47543 10.164 6.13965 9.74976 6.13965C9.33554 6.13965 8.99976 6.47543 8.99976 6.88965V11.3896C8.99976 11.8039 9.33554 12.1396 9.74976 12.1396C10.164 12.1396 10.4998 11.8039 10.4998 11.3896V6.88965Z",fill:"currentColor"})})})]},e.uid),"STATIC"!==o&&"POST_PURCHASE"!==o&&25>E()&&jsxRuntime.jsx(ThemeSectionStatus.ThemeSectionStatusWrapper,{...e}),jsxRuntime.jsx("div",{"data-outline":!0,"data-outline-section":"Section"==e.tag,"data-outline-theme-section":"Section"==e.tag&&!!t||r,"data-outline-shopify-section":"Section"==e.tag&&!!i,"data-outline-limit":E()>=25},"outline-"+e.uid),"Section"==e.tag&&!r&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Tooltip.default,{enable:y()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-top":!0,"data-toolbar-disable":y()>=25,"data-toolbar-add-open":"above"==a,onClick:e=>F(e,"above"),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})}),jsxRuntime.jsx(Tooltip.default,{enable:y()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-bottom":!0,"data-toolbar-disable":y()>=25,"data-toolbar-add-open":"below"==a,onClick:e=>F(e,"below"),"aria-hidden":"true",children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:jsxRuntime.jsx("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})})]}),jsxRuntime.jsx(AIGenContentLoading.AIGenContentLoading,{...e}),jsxRuntime.jsx(Resize.default,{...e})]})};var ComponentToolbarPreview$1=react.memo(ComponentToolbarPreview);exports.default=ComponentToolbarPreview$1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var jsxRuntime=require("react/jsx-runtime"),react=require("react"),zustand=require("zustand"),cloneDeep=require("../helpers/clone-deep.js"),normalizeBuilderData=require("../helpers/normalize-builder-data.js");function moveByIndex(e,t,i){let r=e.splice(t,1)[0];void 0!==r&&e.splice(i,0,r)}function removeByKey(e,t){let i=t[e];i&&(delete t[e],"section"!==i.type&&i.childrens?.map(e=>removeByKey(e,t)))}const BuilderPreviewContext=react.createContext(null),root={uid:"ROOT",tag:"Root",label:"Root",childrens:[]},createBuilderPreviewProvider=(e,t)=>zustand.createStore((i,r)=>({state:e,loaded:!1,isThemeSectionEditor:!!t,dynamicProduct:null,dynamicCollection:null,addItem:e=>{let{position:t,data:l}=e,s=r().state,n=Date.now();if("section"===e.type){if(!Array.isArray(l)){let e=l.uid,r=s.ROOT;r.childrens?r.childrens.splice(t??0,0,e):r.childrens=[e],r.dateModified=n,i({state:{...s,[e]:{uid:e,type:"section",label:l.label},ROOT:cloneDeep.cloneDeep(r)}})}}else{let{id:r,data:l}=e,d=r?s[r]??s.ROOT:s.ROOT;if("section"===d.type)return;if(Array.isArray(l)){let e=l.map(e=>e.uid),r=l.reduceRight((e,t)=>{let i=normalizeBuilderData.normalizeBuilderData(t);return{...e,...i}},{});d.dateModified=n,d.childrens=d.childrens??[],d.childrens.splice(t??0,0,...e),i({state:{...s,...r,[d.uid]:cloneDeep.cloneDeep(d)}})}else{let e=normalizeBuilderData.normalizeBuilderData(l);d.dateModified=n,d.childrens=d.childrens??[],d.childrens.splice(t??0,0,l.uid),i({state:{...s,...e,[d.uid]:cloneDeep.cloneDeep(d)}})}}},changeItemProp:(e,t,l)=>{if(!l||!["setting","style","advanced"].includes(l))return;let s=r().state,n=s[e];if(n?.type!=="section"&&n){let r=Date.now();switch(n.dateModified=r,l){case"setting":i({state:{...s,[e]:{...n,settings:{...n.settings,...t}}}});break;case"style":i({state:{...s,[e]:{...n,styles:{...n.styles,...t}}}});break;case"advanced":i({state:{...s,[e]:{...n,advanced:{...n.advanced,...t}}}})}}},forceChangeItemProp:(e,t,l)=>{if(!l||!["setting","style","advanced"].includes(l))return;let s=r().state,n=s[e];if(n?.type!=="section"&&n){let r=Date.now();switch(n.dateModified=r,l){case"setting":i({state:{...s,[e]:{...n,settings:t}}});break;case"style":i({state:{...s,[e]:{...n,styles:t}}});break;case"advanced":i({state:{...s,[e]:{...n,advanced:t}}})}}},changeItemPropByKey:({id:e,key:t,data:l,group:s})=>{if(!s||!["setting","style","advanced"].includes(s))return;let n=r().state,d=n[e];if(d?.type!=="section"&&d){let r={style:d.styles??{},advanced:d.advanced??{},setting:d.settings??{}};void 0===l?(console.warn("Data is undefined"),delete r[s][t]):r[s][t]=l,i({state:{...n,[e]:{...d,settings:{...r.setting},styles:{...r.style},advanced:{...r.advanced}}}})}},getItem:e=>r().state[e],removeItem:e=>{if("ROOT"===e)i({state:{ROOT:root}});else{let t=r().state;removeByKey(e,t);let l=Object.entries(t).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(l){let r=Date.now(),[s,n]=l;if("section"===n.type)return;n.childrens=n.childrens?.filter(t=>t!==e),n.dateModified=r,i({state:{...t,[s]:cloneDeep.cloneDeep(n)}})}}},moveItem:(e,t,l)=>{let s=r().state,n=s[e],d=s[t];if(n&&d&&"section"!==d.type){if("section"===n.type){let t=s.ROOT;if(!t.childrens)return;let r=t.childrens.findIndex(t=>t===e);moveByIndex(t.childrens,r,l??0),i({state:{...s,ROOT:cloneDeep.cloneDeep(t)}})}else{let r=Object.entries(s).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(n&&r){let a=Date.now(),[,c]=r;if("section"===c.type)return;if(c.dateModified=a,t===c.uid&&c.childrens){let t=c.childrens.findIndex(t=>t===e);c.childrens&&t!==l&&(moveByIndex(c.childrens,t,l??0),i({state:{...s,[c.uid]:cloneDeep.cloneDeep(c)}}))}else c.childrens=c.childrens?.filter(t=>t!==e),d&&(d.dateModified=a,d.childrens=d.childrens??[],d.childrens.splice(l??0,0,n.uid),i({state:{...s,[d.uid]:cloneDeep.cloneDeep(d),[c.uid]:cloneDeep.cloneDeep(c)}}))}}}},forceChangeState:e=>{i({state:e,loaded:!0})},initState:e=>{if(Array.isArray(e)){let t=e.map(e=>e.uid),r=e.reduceRight((e,t)=>{let i=normalizeBuilderData.normalizeBuilderData(t);return{...e,...i}},{});i({loaded:!0,state:{ROOT:{...root,childrens:t},...r}})}else{let t=normalizeBuilderData.normalizeBuilderData(e);i({loaded:!0,state:{ROOT:{...root,childrens:[e.uid]},...t}})}},addSection:(e,t)=>{let l=r().state,s=l.ROOT;s.childrens||(s.childrens=[]),s.childrens.splice(t??0,0,e.uid),i({state:{...l,ROOT:cloneDeep.cloneDeep(s)}})},getParents:(e,t)=>{let i=r().state,l=[],s=0,n=e;for(;!t||!(s>=t);){let e=Object.entries(i).find(([,e])=>"section"!==e.type&&e.childrens?.includes(n));if(!e)break;let[,t]=e;if(!t)break;l.push(t),n=t.uid,s++}return l},updateItemName:(e,t)=>{let l=r().state,s=l[e];s&&(s.name=t,i({state:{...l,[e]:cloneDeep.cloneDeep(s)}}))},updateItemAttribute:(e,t,l)=>{if(!l||!["label","customLabel","isShopifyVisibility"].includes(l))return;let s=r().state,n=s[e];if(n){if("section"!==n.type){let e=Date.now();n.dateModified=e}let r={...n,[l]:t};i({state:{...s,[e]:r}})}}})),BuilderPreviewProvider=({children:e,state:t,isThemeSectionEditor:i,lazy:r,...l})=>{let s=r?react.Suspense:react.Fragment,n=react.useMemo(()=>createBuilderPreviewProvider(t,i),[t,i]);return jsxRuntime.jsx(s,{children:jsxRuntime.jsx(BuilderPreviewContext.Provider,{...l,value:n,children:e})})},useBuilderPreviewStore=(e,t)=>{let i=react.useContext(BuilderPreviewContext);if(!i)throw Error("useBuilderPreviewStore must be used within a BuilderPreviewProvider");return zustand.useStore(i,e,t)};exports.BuilderPreviewProvider=BuilderPreviewProvider,exports.useBuilderPreviewStore=useBuilderPreviewStore;
|
|
1
|
+
"use strict";var jsxRuntime=require("react/jsx-runtime"),react=require("react"),zustand=require("zustand"),cloneDeep=require("../helpers/clone-deep.js"),normalizeBuilderData=require("../helpers/normalize-builder-data.js");function moveByIndex(e,t,i){let r=e.splice(t,1)[0];void 0!==r&&e.splice(i,0,r)}function removeByKey(e,t){let i=t[e];i&&(delete t[e],"section"!==i.type&&i.childrens?.map(e=>removeByKey(e,t)))}const BuilderPreviewContext=react.createContext(null),root={uid:"ROOT",tag:"Root",label:"Root",childrens:[]},createBuilderPreviewProvider=(e,t)=>zustand.createStore((i,r)=>({state:e,loaded:!1,isThemeSectionEditor:!!t,dynamicProduct:null,dynamicCollection:null,addItem:e=>{let{position:t,data:l}=e,s=r().state,n=Date.now();if("section"===e.type){if(!Array.isArray(l)){let e=l.uid,r=s.ROOT;r.childrens?r.childrens.splice(t??0,0,e):r.childrens=[e],r.dateModified=n,i({state:{...s,[e]:{uid:e,type:"section",label:l.label},ROOT:cloneDeep.cloneDeep(r)}})}}else{let{id:r,data:l}=e,d=r?s[r]??s.ROOT:s.ROOT;if("section"===d.type)return;if(Array.isArray(l)){let e=l.map(e=>e.uid),r=l.reduceRight((e,t)=>{let i=normalizeBuilderData.normalizeBuilderData(t);return{...e,...i}},{});d.dateModified=n,d.childrens=d.childrens??[],d.childrens.splice(t??0,0,...e),i({state:{...s,...r,[d.uid]:cloneDeep.cloneDeep(d)}})}else{let e=normalizeBuilderData.normalizeBuilderData(l);d.dateModified=n,d.childrens=d.childrens??[],d.childrens.splice(t??0,0,l.uid),i({state:{...s,...e,[d.uid]:cloneDeep.cloneDeep(d)}})}}},changeItemProp:(e,t,l)=>{if(!l||!["setting","style","advanced"].includes(l))return;let s=r().state,n=s[e];if(n?.type!=="section"&&n){let r=Date.now();switch(n.dateModified=r,l){case"setting":i({state:{...s,[e]:{...n,settings:{...n.settings,...t}}}});break;case"style":i({state:{...s,[e]:{...n,styles:{...n.styles,...t}}}});break;case"advanced":i({state:{...s,[e]:{...n,advanced:{...n.advanced,...t}}}})}}},forceChangeItemProp:(e,t,l)=>{if(!l||!["setting","style","advanced"].includes(l))return;let s=r().state,n=s[e];if(n?.type!=="section"&&n){let r=Date.now();switch(n.dateModified=r,l){case"setting":i({state:{...s,[e]:{...n,settings:t}}});break;case"style":i({state:{...s,[e]:{...n,styles:t}}});break;case"advanced":i({state:{...s,[e]:{...n,advanced:t}}})}}},changeItemPropByKey:({id:e,key:t,data:l,group:s})=>{if(!s||!["setting","style","advanced"].includes(s))return;let n=r().state,d=n[e];if(d?.type!=="section"&&d){let r={style:d.styles??{},advanced:d.advanced??{},setting:d.settings??{}};void 0===l?(console.warn("Data is undefined"),delete r[s][t]):r[s][t]=l,i({state:{...n,[e]:{...d,settings:{...r.setting},styles:{...r.style},advanced:{...r.advanced}}}})}},getItem:e=>{let t=r().state[e];return{...t,rawChildrens:t?.childrens?.map(e=>r().state[e])}},removeItem:e=>{if("ROOT"===e)i({state:{ROOT:root}});else{let t=r().state;removeByKey(e,t);let l=Object.entries(t).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(l){let r=Date.now(),[s,n]=l;if("section"===n.type)return;n.childrens=n.childrens?.filter(t=>t!==e),n.dateModified=r,i({state:{...t,[s]:cloneDeep.cloneDeep(n)}})}}},moveItem:(e,t,l)=>{let s=r().state,n=s[e],d=s[t];if(n&&d&&"section"!==d.type){if("section"===n.type){let t=s.ROOT;if(!t.childrens)return;let r=t.childrens.findIndex(t=>t===e);moveByIndex(t.childrens,r,l??0),i({state:{...s,ROOT:cloneDeep.cloneDeep(t)}})}else{let r=Object.entries(s).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(n&&r){let a=Date.now(),[,c]=r;if("section"===c.type)return;if(c.dateModified=a,t===c.uid&&c.childrens){let t=c.childrens.findIndex(t=>t===e);c.childrens&&t!==l&&(moveByIndex(c.childrens,t,l??0),i({state:{...s,[c.uid]:cloneDeep.cloneDeep(c)}}))}else c.childrens=c.childrens?.filter(t=>t!==e),d&&(d.dateModified=a,d.childrens=d.childrens??[],d.childrens.splice(l??0,0,n.uid),i({state:{...s,[d.uid]:cloneDeep.cloneDeep(d),[c.uid]:cloneDeep.cloneDeep(c)}}))}}}},forceChangeState:e=>{i({state:e,loaded:!0})},initState:e=>{if(Array.isArray(e)){let t=e.map(e=>e.uid),r=e.reduceRight((e,t)=>{let i=normalizeBuilderData.normalizeBuilderData(t);return{...e,...i}},{});i({loaded:!0,state:{ROOT:{...root,childrens:t},...r}})}else{let t=normalizeBuilderData.normalizeBuilderData(e);i({loaded:!0,state:{ROOT:{...root,childrens:[e.uid]},...t}})}},addSection:(e,t)=>{let l=r().state,s=l.ROOT;s.childrens||(s.childrens=[]),s.childrens.splice(t??0,0,e.uid),i({state:{...l,ROOT:cloneDeep.cloneDeep(s)}})},getParents:(e,t)=>{let i=r().state,l=[],s=0,n=e;for(;!t||!(s>=t);){let e=Object.entries(i).find(([,e])=>"section"!==e.type&&e.childrens?.includes(n));if(!e)break;let[,t]=e;if(!t)break;l.push(t),n=t.uid,s++}return l},updateItemName:(e,t)=>{let l=r().state,s=l[e];s&&(s.name=t,i({state:{...l,[e]:cloneDeep.cloneDeep(s)}}))},updateItemAttribute:(e,t,l)=>{if(!l||!["label","customLabel","isShopifyVisibility"].includes(l))return;let s=r().state,n=s[e];if(n){if("section"!==n.type){let e=Date.now();n.dateModified=e}let r={...n,[l]:t};i({state:{...s,[e]:r}})}}})),BuilderPreviewProvider=({children:e,state:t,isThemeSectionEditor:i,lazy:r,...l})=>{let s=r?react.Suspense:react.Fragment,n=react.useMemo(()=>createBuilderPreviewProvider(t,i),[t,i]);return jsxRuntime.jsx(s,{children:jsxRuntime.jsx(BuilderPreviewContext.Provider,{...l,value:n,children:e})})},useBuilderPreviewStore=(e,t)=>{let i=react.useContext(BuilderPreviewContext);if(!i)throw Error("useBuilderPreviewStore must be used within a BuilderPreviewProvider");return zustand.useStore(i,e,t)};exports.BuilderPreviewProvider=BuilderPreviewProvider,exports.useBuilderPreviewStore=useBuilderPreviewStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as t,Fragment as e,jsx as o}from"react/jsx-runtime";import{memo as i,useState as n,useMemo as l,useCallback as a,useEffect as r}from"react";import"zustand";import{useBuilderPreviewStore as d}from"../contexts/BuilderPreviewContext.js";import{useShopStore as C}from"../contexts/ShopContext.js";import"@gem-sdk/adapter-shopify";import"swr";import"swr/mutation";import"vanilla-lazyload";import"../hooks/useCartUI.js";import{CreateThemeSection as c}from"./theme-section/CreateThemeSection.js";import{AIContentGenerator as p}from"./ai-generator/AIContentGenerator.js";import{AIGenContentLoading as h}from"./ai-generator/AIGenContentLoading.js";import s from"./toolbar/Tooltip.js";import{ThemeSectionStatusWrapper as u}from"./theme-section/ThemeSectionStatus.js";import{usePostPurchase as m}from"../hooks/useToolbarPostPurchase.js";import v from"./resize/Resize.js";import"../helpers/convert.js";let SECTION_LIMIT=25,notVisible=t=>{let e=getComputedStyle(t).overflow;return"visible"!==e},isSection=t=>{let e=t.getAttribute("data-component-tag");return"Section"===e},ComponentToolbarPreview=i=>{let b=i.isThemeSection,g=i.isShopifySection,f=C(t=>t.pageType),w=d(t=>t.getParents),S=d(t=>t.getItem("ROOT")),M=d(t=>t.isThemeSectionEditor),[V,Z]=n(null),[x,H]=n(!1),[R,E]=n(!1),[T,y]=n([]),[P,L]=n("top"),[B,j]=n(!1),[k,I]=n({width:"",text:""}),[U,F]=n(!1),$=l(()=>"POST_PURCHASE"===f,[f]),{checkDisableDelete:A,getTooltipText:O,checkDisableDuplicate:z}=m(i.uid,i.tag||""),D=(t,e)=>{let o=T.length,i=t.getBoundingClientRect(),n=e.getBoundingClientRect();return i.top-n.top<36*o},_=(t,e)=>{let o=e||t;if(t&&!isSection(t))return notVisible(t)&&D(e,t)?t:t.parentElement?_(t.parentElement,o):void 0},G=a(()=>{if("Section"==i.tag)return"bottom";let t=document.querySelector('[data-toolbar-active="true"]');if(t){let e=t.getBoundingClientRect();e.top<60?L("bottom"):L("top")}},[i.tag]),N=a(t=>{let e=t.detail;if(e?.componentUid==i.uid){G(),$&&(j(A()),I(O()),F(z()));let t=w(i.uid).filter(t=>!("ROOT"===t.uid||"Section"===t.tag&&M||t.editorConfigs?.toolbar?.hide||t.editorConfigs?.component?.noSetting)).slice(0,3);y(t)}else y([]),H(!1)},[i.uid,$,w,A,O,z,M,G]);if(r(()=>(window.addEventListener("editor:active-component",N),()=>{window.removeEventListener("editor:active-component",N)}),[N]),"section"===i.type||i.editorConfigs?.toolbar?.hide)return null;let q=()=>S?.childrens?.length||0,J=()=>"Section"!==i.tag?-1:S?.childrens?.length?S.childrens.findIndex(t=>t==i.uid):-1,K=t=>{if(!T.length)return;let e=t?.target||null,o=e.closest("[data-toolbar-active]");if(!e||!o)return;if(x)E(!1),H(!1);else{let t=_(o,o);if(t)E(!0);else{let t=o.getBoundingClientRect();t.top<36*T.length?E(!0):E(!1)}H(!0)}let i=new CustomEvent("editor:toolbar:show-parents",{bubbles:!0,detail:{value:!x}});window.dispatchEvent(i)},Q=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:delete-component",{bubbles:!0,detail:{componentUid:i.uid,isThemeSection:b,isShopifySection:g}});return window.dispatchEvent(e),!1},W=t=>{if(t.preventDefault(),t.stopPropagation(),q()>=25&&"Section"==i.tag)return!1;let e=new CustomEvent("editor:toolbar:duplicate-component",{bubbles:!0,detail:{componentUid:i.uid,isThemeSection:b,isShopifySection:g}});return window.dispatchEvent(e),!1},X=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:visibility-shopify-section",{bubbles:!0,detail:{componentUid:i.uid,isShopifySection:g}});return window.dispatchEvent(e),!1},Y=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:zoom-out-component",{bubbles:!0,detail:{componentUid:i.uid}});return window.dispatchEvent(e),!1},tt=()=>{Z(null),window.removeEventListener("editor:close-add-section-popup",tt)},te=(t,e)=>{if(t.preventDefault(),t.stopPropagation(),q()>=25)return!1;let o=t.target;if(o){Z(e);let t=o.getBoundingClientRect(),n=new CustomEvent("editor:toolbar:add-section",{bubbles:!0,detail:{componentUid:i.uid,position:e,top:t.top+t.height/2}});window.dispatchEvent(n),window.addEventListener("editor:close-add-section-popup",tt)}return!1},to=()=>{if(g)return`Shopify section: ${i.name}`;let t=i.name&&i.name===`Section ${i.uid}`;return q()>=20?`${t?"Section":i?.name} ${J()+1}/25`:t?`Section ${J()+1}`:i?.name};return t(e,{children:[!("Section"==i.tag&&M)&&t("div",{"data-toolbar":!0,"data-toolbar-section":"Section"==i.tag,"data-toolbar-theme-section":"Section"==i.tag&&!!b||M,"data-toolbar-shopify-section":"Section"==i.tag&&!!g,"data-toolbar-limit":J()>=25,children:[t("div",{"data-toolbar-show-parent":!0,onClick:t=>K(t),"aria-hidden":"true",children:[o("div",{"data-toolbar-icon-drag":!0,children:t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[o("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),o("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),o("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),o("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),o("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),o("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),"Section"==i.tag?o("div",{"data-toolbar-name":!0,children:to()}):o("div",{"data-toolbar-name":!0,children:i.customLabel||i.label}),"Section"!==i.tag&&T.length>0&&o("div",{"data-toolbar-icon-parent":!0,"data-toolbar-icon-parent-open":x,children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M5.65522 10C5.07265 10 4.7809 9.22865 5.19284 8.77753L7.53762 6.20974C7.79298 5.93009 8.20702 5.93009 8.46238 6.20974L10.8072 8.77754C11.2191 9.22866 10.9274 10 10.3448 10H5.65522Z",fill:"currentColor"})})})]}),x&&T.map((e,i)=>{let n=e?.childrens?.length??0,l=e.label;return"Row"===e.label&&(l=n<=1?e.label+" "+n+" col":e.label+" "+n+" cols"),t("div",{"data-toolbar-parent":!0,"data-parent-uid":e.uid,"data-toolbar-theme-section":M,"data-toolbar-parent-revert":R,style:{top:R?`${36*(i+1)}px`:`${-36*(i+1)}px`},children:[o("div",{"data-toolbar-icon-drag":!0,children:t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[o("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),o("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),o("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),o("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),o("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),o("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),o("div",{"data-toolbar-name":!0,children:l})]},e.uid)}),"Section"===i.tag&&!i.isThemeSection&&"STATIC"!==f&&"POST_PURCHASE"!==f&&!i.isShopifySection&&25>J()&&o(c,{...i}),o(p,{...i}),"Sticky"==i.tag&&o("div",{"data-toolbar-zoom-out":!0,onClick:t=>Y(t),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.5 7C14.7761 7 15 6.77614 15 6.5C15 6.22386 14.7761 6 14.5 6L10.7072 6L14.8536 1.85355C15.0489 1.65829 15.0489 1.34171 14.8536 1.14645C14.6584 0.951186 14.3418 0.951185 14.1465 1.14645L10 5.29297L10 1.5C10 1.22386 9.77614 1 9.5 1C9.22386 1 9 1.22386 9 1.5L9 6.5C9 6.77614 9.22386 7 9.5 7L14.5 7ZM6 10.7073L6 14.5C6 14.7761 6.22386 15 6.5 15C6.77614 15 7 14.7761 7 14.5L7 9.5C7 9.22386 6.77614 9 6.5 9H1.5C1.22386 9 1 9.22386 1 9.5C1 9.77614 1.22386 10 1.5 10H5.29306L1.14662 14.1464C0.951353 14.3417 0.951353 14.6583 1.14662 14.8536C1.34188 15.0488 1.65846 15.0488 1.85372 14.8536L6 10.7073Z",fill:"currentColor"})})}),o(s,{enable:"Section"==i.tag&&q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"bottom","data-toolbar-duplicate":!0,"data-toolbar-disable":"Section"==i.tag&&q()>=25||U,onClick:U?void 0:t=>W(t),"aria-hidden":"true",className:U?"!gp-cursor-not-allowed":"",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M6.08423 1.21289C5.53194 1.21289 5.08423 1.66061 5.08423 2.21289V3.78711H4.26172C3.43329 3.78711 2.76172 4.45868 2.76172 5.28711V13.2871C2.76172 14.1155 3.43329 14.7871 4.26172 14.7871H10.2617C11.0901 14.7871 11.7617 14.1155 11.7617 13.2871V12.4629H13.0842C13.6365 12.4629 14.0842 12.0152 14.0842 11.4629V2.21289C14.0842 1.66061 13.6365 1.21289 13.0842 1.21289H6.08423ZM10.7617 12.4629H6.08423C5.53194 12.4629 5.08423 12.0152 5.08423 11.4629V4.78711H4.26172C3.98558 4.78711 3.76172 5.01097 3.76172 5.28711V13.2871C3.76172 13.5633 3.98558 13.7871 4.26172 13.7871H10.2617C10.5379 13.7871 10.7617 13.5633 10.7617 13.2871V12.4629Z",fill:"currentColor"})})}),"Section"===i.tag&&i.isShopifySection&&o(s,{enable:!1,text:"",position:"bottom","data-toolbar-visibility":!0,onClick:t=>X(t),"aria-hidden":"true",children:i.isShopifyVisibility?t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99841C10.499 6.61803 9.37945 5.49961 7.99909 5.50027C6.6187 5.50071 5.49975 6.61987 5.49975 8.00027C5.49975 9.38099 6.61904 10.5003 7.99975 10.5003C9.38021 10.5003 10.4996 9.38184 10.4998 8.00107V7.99841ZM7.99949 6.50027C8.82762 6.49983 9.49931 7.17081 9.49975 7.99894V8.00054C9.49975 8.8288 8.82836 9.50027 7.99975 9.50027C7.17133 9.50027 6.49975 8.8287 6.49975 8.00027C6.49975 7.172 7.17122 6.50049 7.99949 6.50027Z",fill:"white"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50098C4.53098 3.50106 2.24443 6.11641 1.43599 7.20809C1.0847 7.68246 1.08696 8.32021 1.43971 8.79238C2.25325 9.88131 4.55461 12.4995 7.9987 12.4995C11.5041 12.4995 13.7751 9.87636 14.5731 8.78489C14.9175 8.31382 14.915 7.68401 14.5684 7.21544C13.7641 6.12774 11.474 3.50089 7.99869 3.50098ZM2.23962 7.80322C3.016 6.75484 5.04126 4.50105 7.99871 4.50098C10.9629 4.50091 12.9916 6.76501 13.7644 7.81003C13.8513 7.92751 13.8516 8.07739 13.7658 8.19472C13.0028 9.23835 10.9929 11.4995 7.9987 11.4995C5.0648 11.4995 3.025 9.24349 2.24082 8.19386C2.15178 8.07468 2.15162 7.92206 2.23962 7.80322Z",fill:"white"})]}):t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99857C10.499 6.61819 9.37945 5.49977 7.99909 5.50044C6.6187 5.50088 5.49975 6.62003 5.49975 8.00044C5.49975 9.38115 6.61904 10.5004 7.99975 10.5004C9.38021 10.5004 10.4996 9.382 10.4998 8.00124V7.99857ZM7.99949 6.50044C8.82762 6.49999 9.49931 7.17097 9.49975 7.9991V8.0007C9.49975 8.82896 8.82836 9.50044 7.99975 9.50044C7.17133 9.50044 6.49975 8.82886 6.49975 8.00044C6.49975 7.17216 7.17122 6.50066 7.99949 6.50044Z",fill:"#F9F9F9"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50114C4.53098 3.50122 2.24443 6.11658 1.43599 7.20825C1.0847 7.68262 1.08696 8.32038 1.43971 8.79254C2.25325 9.88147 4.55461 12.4997 7.9987 12.4997C11.5041 12.4997 13.7751 9.87652 14.5731 8.78505C14.9175 8.31398 14.915 7.68417 14.5684 7.2156C13.7641 6.1279 11.474 3.50106 7.99869 3.50114ZM2.23962 7.80338C3.016 6.755 5.04126 4.50121 7.99871 4.50114C10.9629 4.50107 12.9916 6.76517 13.7644 7.81019C13.8513 7.92767 13.8516 8.07755 13.7658 8.19488C13.0028 9.23851 10.9929 11.4997 7.9987 11.4997C5.0648 11.4997 3.025 9.24365 2.24082 8.19402C2.15178 8.07484 2.15162 7.92222 2.23962 7.80338Z",fill:"#F9F9F9"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.4607 2.6163C14.6728 2.87086 14.6384 3.2492 14.3839 3.46134L2.38387 13.4613C2.1293 13.6735 1.75096 13.6391 1.53882 13.3845C1.32668 13.13 1.36108 12.7516 1.61565 12.5395L13.6156 2.53947C13.8702 2.32733 14.2486 2.36173 14.4607 2.6163Z",fill:"#F9F9F9"})]})}),o(s,{"data-toolbar-delete":!0,onClick:t=>B?null:Q(t),enable:B,"data-toolbar-disable":B,width:k.width,text:k.text,position:P,"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2.88965V2.38965C11 1.56122 10.3284 0.889648 9.5 0.889648H6.5C5.67157 0.889648 5 1.56122 5 2.38965V2.88965H2C1.72386 2.88965 1.5 3.11351 1.5 3.38965C1.5 3.66579 1.72386 3.88965 2 3.88965H3.21997V13.1099C3.21997 14.2144 4.1154 15.1099 5.21997 15.1099H11.22C12.3245 15.1099 13.22 14.2144 13.22 13.1099V3.88965H14C14.2761 3.88965 14.5 3.66579 14.5 3.38965C14.5 3.11351 14.2761 2.88965 14 2.88965H11ZM6 2.88965H10V2.38965C10 2.11351 9.77614 1.88965 9.5 1.88965H6.5C6.22386 1.88965 6 2.11351 6 2.38965V2.88965ZM6.24976 6.13965C6.66397 6.13965 6.99976 6.47543 6.99976 6.88965V11.3896C6.99976 11.8039 6.66397 12.1396 6.24976 12.1396C5.83554 12.1396 5.49976 11.8039 5.49976 11.3896V6.88965C5.49976 6.47543 5.83554 6.13965 6.24976 6.13965ZM10.4998 6.88965C10.4998 6.47543 10.164 6.13965 9.74976 6.13965C9.33554 6.13965 8.99976 6.47543 8.99976 6.88965V11.3896C8.99976 11.8039 9.33554 12.1396 9.74976 12.1396C10.164 12.1396 10.4998 11.8039 10.4998 11.3896V6.88965Z",fill:"currentColor"})})})]},i.uid),"STATIC"!==f&&"POST_PURCHASE"!==f&&25>J()&&o(u,{...i}),o("div",{"data-outline":!0,"data-outline-section":"Section"==i.tag,"data-outline-theme-section":"Section"==i.tag&&!!b||M,"data-outline-shopify-section":"Section"==i.tag&&!!g,"data-outline-limit":J()>=25},"outline-"+i.uid),"Section"==i.tag&&!M&&t(e,{children:[o(s,{enable:q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-top":!0,"data-toolbar-disable":q()>=25,"data-toolbar-add-open":"above"==V,onClick:t=>te(t,"above"),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})}),o(s,{enable:q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-bottom":!0,"data-toolbar-disable":q()>=25,"data-toolbar-add-open":"below"==V,onClick:t=>te(t,"below"),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})})]}),o(h,{...i}),o(v,{...i})]})};var ComponentToolbarPreview$1=i(ComponentToolbarPreview);export{ComponentToolbarPreview$1 as default};
|
|
1
|
+
import{jsxs as t,Fragment as e,jsx as o}from"react/jsx-runtime";import{memo as i,useState as n,useMemo as l,useCallback as a,useEffect as r}from"react";import"zustand";import{useBuilderPreviewStore as d}from"../contexts/BuilderPreviewContext.js";import{useShopStore as C}from"../contexts/ShopContext.js";import"@gem-sdk/adapter-shopify";import"swr";import"swr/mutation";import"vanilla-lazyload";import"../hooks/useCartUI.js";import{CreateThemeSection as c}from"./theme-section/CreateThemeSection.js";import{AIContentGenerator as p}from"./ai-generator/AIContentGenerator.js";import{AIGenContentLoading as h}from"./ai-generator/AIGenContentLoading.js";import s from"./toolbar/Tooltip.js";import{ThemeSectionStatusWrapper as u}from"./theme-section/ThemeSectionStatus.js";import{usePostPurchase as m}from"../hooks/useToolbarPostPurchase.js";import v from"./resize/Resize.js";import"../helpers/convert.js";let SECTION_LIMIT=25,notVisible=t=>{let e=getComputedStyle(t).overflow;return"visible"!==e},isSection=t=>{let e=t.getAttribute("data-component-tag");return"Section"===e},ComponentToolbarPreview=i=>{let b=i.isThemeSection,g=i.isShopifySection,f=C(t=>t.pageType),w=d(t=>t.getParents),S=d(t=>t.getItem("ROOT")),M=d(t=>t.isThemeSectionEditor),[V,Z]=n(null),[x,H]=n(!1),[R,y]=n(!1),[E,T]=n([]),[P,L]=n("top"),[B,j]=n(!1),[k,I]=n({width:"",text:""}),[U,F]=n(!1),$=l(()=>"POST_PURCHASE"===f,[f]),{checkDisableDelete:A,getTooltipText:O,checkDisableDuplicate:z}=m(i.uid,i.tag||""),D=(t,e)=>{let o=E.length,i=t.getBoundingClientRect(),n=e.getBoundingClientRect();return i.top-n.top<36*o},_=(t,e)=>{let o=e||t;if(t&&!isSection(t))return notVisible(t)&&D(e,t)?t:t.parentElement?_(t.parentElement,o):void 0},G=a(()=>{if("Section"==i.tag)return"bottom";let t=document.querySelector('[data-toolbar-active="true"]');if(t){let e=t.getBoundingClientRect();e.top<60?L("bottom"):L("top")}},[i.tag]),N=a(t=>{let e=t.detail;if(e?.componentUid==i.uid){G(),$&&(j(A()),I(O()),F(z()));let t=w(i.uid).filter(t=>!("ROOT"===t.uid||"Section"===t.tag&&M||t.editorConfigs?.toolbar?.hide||t.editorConfigs?.component?.noSetting)).slice(0,3);T(t)}else T([]),H(!1)},[i.uid,$,w,A,O,z,M,G]);if(r(()=>(window.addEventListener("editor:active-component",N),()=>{window.removeEventListener("editor:active-component",N)}),[N]),"section"===i.type||i.editorConfigs?.toolbar?.hide)return null;let q=()=>S?.childrens?.length||0,J=()=>"Section"!==i.tag?-1:S?.childrens?.length?S.childrens.findIndex(t=>t==i.uid):-1,K=t=>{if(!E.length)return;let e=t?.target||null,o=e.closest("[data-toolbar-active]");if(!e||!o)return;if(x)y(!1),H(!1);else{let t=_(o,o);if(t)y(!0);else{let t=o.getBoundingClientRect();t.top<36*E.length?y(!0):y(!1)}H(!0)}let i=new CustomEvent("editor:toolbar:show-parents",{bubbles:!0,detail:{value:!x}});window.dispatchEvent(i)},Q=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:delete-component",{bubbles:!0,detail:{componentUid:i.uid,isThemeSection:b,isShopifySection:g}});return window.dispatchEvent(e),!1},W=t=>{if(t.preventDefault(),t.stopPropagation(),q()>=25&&"Section"==i.tag)return!1;let e=new CustomEvent("editor:toolbar:duplicate-component",{bubbles:!0,detail:{componentUid:i.uid,isThemeSection:b,isShopifySection:g}});return window.dispatchEvent(e),!1},X=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:visibility-shopify-section",{bubbles:!0,detail:{componentUid:i.uid,isShopifySection:g}});return window.dispatchEvent(e),!1},Y=t=>{t.preventDefault(),t.stopPropagation();let e=new CustomEvent("editor:toolbar:zoom-out-component",{bubbles:!0,detail:{componentUid:i.uid}});return window.dispatchEvent(e),!1},tt=()=>{Z(null),window.removeEventListener("editor:close-add-section-popup",tt)},te=(t,e)=>{if(t.preventDefault(),t.stopPropagation(),q()>=25)return!1;let o=t.target;if(o){Z(e);let t=o.getBoundingClientRect(),n=new CustomEvent("editor:toolbar:add-section",{bubbles:!0,detail:{componentUid:i.uid,position:e,top:t.top+t.height/2}});window.dispatchEvent(n),window.addEventListener("editor:close-add-section-popup",tt)}return!1},to=()=>{if(g)return`Shopify section: ${i.name}`;let t=i.name&&i.name===`Section ${i.uid}`;return q()>=20?`${t?"Section":i?.name} ${J()+1}/25`:t?`Section ${J()+1}`:i?.name};return t(e,{children:[!("Section"==i.tag&&M)&&t("div",{"data-toolbar":!0,"data-toolbar-section":"Section"==i.tag,"data-toolbar-theme-section":"Section"==i.tag&&!!b||M,"data-toolbar-shopify-section":"Section"==i.tag&&!!g,"data-toolbar-limit":J()>=25,children:[t("div",{"data-toolbar-show-parent":!0,onClick:t=>K(t),"aria-hidden":"true",children:[o("div",{"data-toolbar-icon-drag":!0,children:t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[o("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),o("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),o("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),o("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),o("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),o("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),"Section"==i.tag?o("div",{"data-toolbar-name":!0,children:to()}):o("div",{"data-toolbar-name":!0,children:i.customLabel||i.label}),"Section"!==i.tag&&E.length>0&&o("div",{"data-toolbar-icon-parent":!0,"data-toolbar-icon-parent-open":x,children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M5.65522 10C5.07265 10 4.7809 9.22865 5.19284 8.77753L7.53762 6.20974C7.79298 5.93009 8.20702 5.93009 8.46238 6.20974L10.8072 8.77754C11.2191 9.22866 10.9274 10 10.3448 10H5.65522Z",fill:"currentColor"})})})]}),x&&E.map((e,i)=>{let n=e?.childrens?.length??0,l=e.label;return"Row"===e.label&&(l=n<=1?e.label+" "+n+" col":e.label+" "+n+" cols"),t("div",{"data-toolbar-parent":!0,"data-parent-uid":e.uid,"data-toolbar-theme-section":M,"data-toolbar-parent-revert":R,style:{top:R?`${36*(i+1)}px`:`${-36*(i+1)}px`},children:[o("div",{"data-toolbar-icon-drag":!0,children:t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[o("path",{d:"M5.5 4.5C6.32843 4.5 7 3.82843 7 3C7 2.17157 6.32843 1.5 5.5 1.5C4.67157 1.5 4 2.17157 4 3C4 3.82843 4.67157 4.5 5.5 4.5Z",fill:"currentColor"}),o("path",{d:"M5.5 9.5C6.32843 9.5 7 8.82843 7 8C7 7.17157 6.32843 6.5 5.5 6.5C4.67157 6.5 4 7.17157 4 8C4 8.82843 4.67157 9.5 5.5 9.5Z",fill:"currentColor"}),o("path",{d:"M7 13C7 13.8284 6.32843 14.5 5.5 14.5C4.67157 14.5 4 13.8284 4 13C4 12.1716 4.67157 11.5 5.5 11.5C6.32843 11.5 7 12.1716 7 13Z",fill:"currentColor"}),o("path",{d:"M10.5 4.5C11.3284 4.5 12 3.82843 12 3C12 2.17157 11.3284 1.5 10.5 1.5C9.67157 1.5 9 2.17157 9 3C9 3.82843 9.67157 4.5 10.5 4.5Z",fill:"currentColor"}),o("path",{d:"M12 8C12 8.82843 11.3284 9.5 10.5 9.5C9.67157 9.5 9 8.82843 9 8C9 7.17157 9.67157 6.5 10.5 6.5C11.3284 6.5 12 7.17157 12 8Z",fill:"currentColor"}),o("path",{d:"M10.5 14.5C11.3284 14.5 12 13.8284 12 13C12 12.1716 11.3284 11.5 10.5 11.5C9.67157 11.5 9 12.1716 9 13C9 13.8284 9.67157 14.5 10.5 14.5Z",fill:"currentColor"})]})}),o("div",{"data-toolbar-name":!0,children:l})]},e.uid)}),"Section"===i.tag&&!i.isThemeSection&&"STATIC"!==f&&"POST_PURCHASE"!==f&&!i.isShopifySection&&25>J()&&o(c,{...i}),!i.isShopifySection&&o(p,{...i}),"Sticky"==i.tag&&o("div",{"data-toolbar-zoom-out":!0,onClick:t=>Y(t),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.5 7C14.7761 7 15 6.77614 15 6.5C15 6.22386 14.7761 6 14.5 6L10.7072 6L14.8536 1.85355C15.0489 1.65829 15.0489 1.34171 14.8536 1.14645C14.6584 0.951186 14.3418 0.951185 14.1465 1.14645L10 5.29297L10 1.5C10 1.22386 9.77614 1 9.5 1C9.22386 1 9 1.22386 9 1.5L9 6.5C9 6.77614 9.22386 7 9.5 7L14.5 7ZM6 10.7073L6 14.5C6 14.7761 6.22386 15 6.5 15C6.77614 15 7 14.7761 7 14.5L7 9.5C7 9.22386 6.77614 9 6.5 9H1.5C1.22386 9 1 9.22386 1 9.5C1 9.77614 1.22386 10 1.5 10H5.29306L1.14662 14.1464C0.951353 14.3417 0.951353 14.6583 1.14662 14.8536C1.34188 15.0488 1.65846 15.0488 1.85372 14.8536L6 10.7073Z",fill:"currentColor"})})}),o(s,{enable:"Section"==i.tag&&q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"bottom","data-toolbar-duplicate":!0,"data-toolbar-disable":"Section"==i.tag&&q()>=25||U,onClick:U?void 0:t=>W(t),"aria-hidden":"true",className:U?"!gp-cursor-not-allowed":"",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M6.08423 1.21289C5.53194 1.21289 5.08423 1.66061 5.08423 2.21289V3.78711H4.26172C3.43329 3.78711 2.76172 4.45868 2.76172 5.28711V13.2871C2.76172 14.1155 3.43329 14.7871 4.26172 14.7871H10.2617C11.0901 14.7871 11.7617 14.1155 11.7617 13.2871V12.4629H13.0842C13.6365 12.4629 14.0842 12.0152 14.0842 11.4629V2.21289C14.0842 1.66061 13.6365 1.21289 13.0842 1.21289H6.08423ZM10.7617 12.4629H6.08423C5.53194 12.4629 5.08423 12.0152 5.08423 11.4629V4.78711H4.26172C3.98558 4.78711 3.76172 5.01097 3.76172 5.28711V13.2871C3.76172 13.5633 3.98558 13.7871 4.26172 13.7871H10.2617C10.5379 13.7871 10.7617 13.5633 10.7617 13.2871V12.4629Z",fill:"currentColor"})})}),"Section"===i.tag&&i.isShopifySection&&o(s,{enable:!1,text:"",position:"bottom","data-toolbar-visibility":!0,onClick:t=>X(t),"aria-hidden":"true",children:i.isShopifyVisibility?t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99841C10.499 6.61803 9.37945 5.49961 7.99909 5.50027C6.6187 5.50071 5.49975 6.61987 5.49975 8.00027C5.49975 9.38099 6.61904 10.5003 7.99975 10.5003C9.38021 10.5003 10.4996 9.38184 10.4998 8.00107V7.99841ZM7.99949 6.50027C8.82762 6.49983 9.49931 7.17081 9.49975 7.99894V8.00054C9.49975 8.8288 8.82836 9.50027 7.99975 9.50027C7.17133 9.50027 6.49975 8.8287 6.49975 8.00027C6.49975 7.172 7.17122 6.50049 7.99949 6.50027Z",fill:"white"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50098C4.53098 3.50106 2.24443 6.11641 1.43599 7.20809C1.0847 7.68246 1.08696 8.32021 1.43971 8.79238C2.25325 9.88131 4.55461 12.4995 7.9987 12.4995C11.5041 12.4995 13.7751 9.87636 14.5731 8.78489C14.9175 8.31382 14.915 7.68401 14.5684 7.21544C13.7641 6.12774 11.474 3.50089 7.99869 3.50098ZM2.23962 7.80322C3.016 6.75484 5.04126 4.50105 7.99871 4.50098C10.9629 4.50091 12.9916 6.76501 13.7644 7.81003C13.8513 7.92751 13.8516 8.07739 13.7658 8.19472C13.0028 9.23835 10.9929 11.4995 7.9987 11.4995C5.0648 11.4995 3.025 9.24349 2.24082 8.19386C2.15178 8.07468 2.15162 7.92206 2.23962 7.80322Z",fill:"white"})]}):t("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M10.4998 7.99857C10.499 6.61819 9.37945 5.49977 7.99909 5.50044C6.6187 5.50088 5.49975 6.62003 5.49975 8.00044C5.49975 9.38115 6.61904 10.5004 7.99975 10.5004C9.38021 10.5004 10.4996 9.382 10.4998 8.00124V7.99857ZM7.99949 6.50044C8.82762 6.49999 9.49931 7.17097 9.49975 7.9991V8.0007C9.49975 8.82896 8.82836 9.50044 7.99975 9.50044C7.17133 9.50044 6.49975 8.82886 6.49975 8.00044C6.49975 7.17216 7.17122 6.50066 7.99949 6.50044Z",fill:"#F9F9F9"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99869 3.50114C4.53098 3.50122 2.24443 6.11658 1.43599 7.20825C1.0847 7.68262 1.08696 8.32038 1.43971 8.79254C2.25325 9.88147 4.55461 12.4997 7.9987 12.4997C11.5041 12.4997 13.7751 9.87652 14.5731 8.78505C14.9175 8.31398 14.915 7.68417 14.5684 7.2156C13.7641 6.1279 11.474 3.50106 7.99869 3.50114ZM2.23962 7.80338C3.016 6.755 5.04126 4.50121 7.99871 4.50114C10.9629 4.50107 12.9916 6.76517 13.7644 7.81019C13.8513 7.92767 13.8516 8.07755 13.7658 8.19488C13.0028 9.23851 10.9929 11.4997 7.9987 11.4997C5.0648 11.4997 3.025 9.24365 2.24082 8.19402C2.15178 8.07484 2.15162 7.92222 2.23962 7.80338Z",fill:"#F9F9F9"}),o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M14.4607 2.6163C14.6728 2.87086 14.6384 3.2492 14.3839 3.46134L2.38387 13.4613C2.1293 13.6735 1.75096 13.6391 1.53882 13.3845C1.32668 13.13 1.36108 12.7516 1.61565 12.5395L13.6156 2.53947C13.8702 2.32733 14.2486 2.36173 14.4607 2.6163Z",fill:"#F9F9F9"})]})}),o(s,{"data-toolbar-delete":!0,onClick:t=>B?null:Q(t),enable:B,"data-toolbar-disable":B,width:k.width,text:k.text,position:P,"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2.88965V2.38965C11 1.56122 10.3284 0.889648 9.5 0.889648H6.5C5.67157 0.889648 5 1.56122 5 2.38965V2.88965H2C1.72386 2.88965 1.5 3.11351 1.5 3.38965C1.5 3.66579 1.72386 3.88965 2 3.88965H3.21997V13.1099C3.21997 14.2144 4.1154 15.1099 5.21997 15.1099H11.22C12.3245 15.1099 13.22 14.2144 13.22 13.1099V3.88965H14C14.2761 3.88965 14.5 3.66579 14.5 3.38965C14.5 3.11351 14.2761 2.88965 14 2.88965H11ZM6 2.88965H10V2.38965C10 2.11351 9.77614 1.88965 9.5 1.88965H6.5C6.22386 1.88965 6 2.11351 6 2.38965V2.88965ZM6.24976 6.13965C6.66397 6.13965 6.99976 6.47543 6.99976 6.88965V11.3896C6.99976 11.8039 6.66397 12.1396 6.24976 12.1396C5.83554 12.1396 5.49976 11.8039 5.49976 11.3896V6.88965C5.49976 6.47543 5.83554 6.13965 6.24976 6.13965ZM10.4998 6.88965C10.4998 6.47543 10.164 6.13965 9.74976 6.13965C9.33554 6.13965 8.99976 6.47543 8.99976 6.88965V11.3896C8.99976 11.8039 9.33554 12.1396 9.74976 12.1396C10.164 12.1396 10.4998 11.8039 10.4998 11.3896V6.88965Z",fill:"currentColor"})})})]},i.uid),"STATIC"!==f&&"POST_PURCHASE"!==f&&25>J()&&o(u,{...i}),o("div",{"data-outline":!0,"data-outline-section":"Section"==i.tag,"data-outline-theme-section":"Section"==i.tag&&!!b||M,"data-outline-shopify-section":"Section"==i.tag&&!!g,"data-outline-limit":J()>=25},"outline-"+i.uid),"Section"==i.tag&&!M&&t(e,{children:[o(s,{enable:q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-top":!0,"data-toolbar-disable":q()>=25,"data-toolbar-add-open":"above"==V,onClick:t=>te(t,"above"),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})}),o(s,{enable:q()>=25,text:"Page has reached Shopify’s 25 section-limit",position:"top","data-toolbar-add-bottom":!0,"data-toolbar-disable":q()>=25,"data-toolbar-add-open":"below"==V,onClick:t=>te(t,"below"),"aria-hidden":"true",children:o("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:o("path",{d:"M8.45 3.95C8.45 3.70147 8.24853 3.5 8 3.5C7.75147 3.5 7.55 3.70147 7.55 3.95V7.55H3.95C3.70147 7.55 3.5 7.75147 3.5 8C3.5 8.24853 3.70147 8.45 3.95 8.45H7.55V12.05C7.55 12.2985 7.75147 12.5 8 12.5C8.24853 12.5 8.45 12.2985 8.45 12.05V8.45H12.05C12.2985 8.45 12.5 8.24853 12.5 8C12.5 7.75147 12.2985 7.55 12.05 7.55H8.45V3.95Z",fill:"#212121"})})})]}),o(h,{...i}),o(v,{...i})]})};var ComponentToolbarPreview$1=i(ComponentToolbarPreview);export{ComponentToolbarPreview$1 as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{useMemo as t,useContext as i,createContext as
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useMemo as t,useContext as i,createContext as r,Suspense as s,Fragment as d}from"react";import{useStore as l,createStore as n}from"zustand";import{cloneDeep as a}from"../helpers/clone-deep.js";import{normalizeBuilderData as c}from"../helpers/normalize-builder-data.js";function moveByIndex(e,t,i){let r=e.splice(t,1)[0];void 0!==r&&e.splice(i,0,r)}function removeByKey(e,t){let i=t[e];i&&(delete t[e],"section"!==i.type&&i.childrens?.map(e=>removeByKey(e,t)))}let BuilderPreviewContext=r(null),root={uid:"ROOT",tag:"Root",label:"Root",childrens:[]},createBuilderPreviewProvider=(e,t)=>n((i,r)=>({state:e,loaded:!1,isThemeSectionEditor:!!t,dynamicProduct:null,dynamicCollection:null,addItem:e=>{let{position:t,data:s}=e,d=r().state,l=Date.now();if("section"===e.type){if(!Array.isArray(s)){let e=s.uid,r=d.ROOT;r.childrens?r.childrens.splice(t??0,0,e):r.childrens=[e],r.dateModified=l,i({state:{...d,[e]:{uid:e,type:"section",label:s.label},ROOT:a(r)}})}}else{let{id:r,data:s}=e,n=r?d[r]??d.ROOT:d.ROOT;if("section"===n.type)return;if(Array.isArray(s)){let e=s.map(e=>e.uid),r=s.reduceRight((e,t)=>{let i=c(t);return{...e,...i}},{});n.dateModified=l,n.childrens=n.childrens??[],n.childrens.splice(t??0,0,...e),i({state:{...d,...r,[n.uid]:a(n)}})}else{let e=c(s);n.dateModified=l,n.childrens=n.childrens??[],n.childrens.splice(t??0,0,s.uid),i({state:{...d,...e,[n.uid]:a(n)}})}}},changeItemProp:(e,t,s)=>{if(!s||!["setting","style","advanced"].includes(s))return;let d=r().state,l=d[e];if(l?.type!=="section"&&l){let r=Date.now();switch(l.dateModified=r,s){case"setting":i({state:{...d,[e]:{...l,settings:{...l.settings,...t}}}});break;case"style":i({state:{...d,[e]:{...l,styles:{...l.styles,...t}}}});break;case"advanced":i({state:{...d,[e]:{...l,advanced:{...l.advanced,...t}}}})}}},forceChangeItemProp:(e,t,s)=>{if(!s||!["setting","style","advanced"].includes(s))return;let d=r().state,l=d[e];if(l?.type!=="section"&&l){let r=Date.now();switch(l.dateModified=r,s){case"setting":i({state:{...d,[e]:{...l,settings:t}}});break;case"style":i({state:{...d,[e]:{...l,styles:t}}});break;case"advanced":i({state:{...d,[e]:{...l,advanced:t}}})}}},changeItemPropByKey:({id:e,key:t,data:s,group:d})=>{if(!d||!["setting","style","advanced"].includes(d))return;let l=r().state,n=l[e];if(n?.type!=="section"&&n){let r={style:n.styles??{},advanced:n.advanced??{},setting:n.settings??{}};void 0===s?(console.warn("Data is undefined"),delete r[d][t]):r[d][t]=s,i({state:{...l,[e]:{...n,settings:{...r.setting},styles:{...r.style},advanced:{...r.advanced}}}})}},getItem:e=>{let t=r().state[e];return{...t,rawChildrens:t?.childrens?.map(e=>r().state[e])}},removeItem:e=>{if("ROOT"===e)i({state:{ROOT:root}});else{let t=r().state;removeByKey(e,t);let s=Object.entries(t).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(s){let r=Date.now(),[d,l]=s;if("section"===l.type)return;l.childrens=l.childrens?.filter(t=>t!==e),l.dateModified=r,i({state:{...t,[d]:a(l)}})}}},moveItem:(e,t,s)=>{let d=r().state,l=d[e],n=d[t];if(l&&n&&"section"!==n.type){if("section"===l.type){let t=d.ROOT;if(!t.childrens)return;let r=t.childrens.findIndex(t=>t===e);moveByIndex(t.childrens,r,s??0),i({state:{...d,ROOT:a(t)}})}else{let r=Object.entries(d).find(([,t])=>"section"!==t.type&&t.childrens?.includes(e));if(l&&r){let c=Date.now(),[,o]=r;if("section"===o.type)return;if(o.dateModified=c,t===o.uid&&o.childrens){let t=o.childrens.findIndex(t=>t===e);o.childrens&&t!==s&&(moveByIndex(o.childrens,t,s??0),i({state:{...d,[o.uid]:a(o)}}))}else o.childrens=o.childrens?.filter(t=>t!==e),n&&(n.dateModified=c,n.childrens=n.childrens??[],n.childrens.splice(s??0,0,l.uid),i({state:{...d,[n.uid]:a(n),[o.uid]:a(o)}}))}}}},forceChangeState:e=>{i({state:e,loaded:!0})},initState:e=>{if(Array.isArray(e)){let t=e.map(e=>e.uid),r=e.reduceRight((e,t)=>{let i=c(t);return{...e,...i}},{});i({loaded:!0,state:{ROOT:{...root,childrens:t},...r}})}else{let t=c(e);i({loaded:!0,state:{ROOT:{...root,childrens:[e.uid]},...t}})}},addSection:(e,t)=>{let s=r().state,d=s.ROOT;d.childrens||(d.childrens=[]),d.childrens.splice(t??0,0,e.uid),i({state:{...s,ROOT:a(d)}})},getParents:(e,t)=>{let i=r().state,s=[],d=0,l=e;for(;!t||!(d>=t);){let e=Object.entries(i).find(([,e])=>"section"!==e.type&&e.childrens?.includes(l));if(!e)break;let[,t]=e;if(!t)break;s.push(t),l=t.uid,d++}return s},updateItemName:(e,t)=>{let s=r().state,d=s[e];d&&(d.name=t,i({state:{...s,[e]:a(d)}}))},updateItemAttribute:(e,t,s)=>{if(!s||!["label","customLabel","isShopifyVisibility"].includes(s))return;let d=r().state,l=d[e];if(l){if("section"!==l.type){let e=Date.now();l.dateModified=e}let r={...l,[s]:t};i({state:{...d,[e]:r}})}}})),BuilderPreviewProvider=({children:i,state:r,isThemeSectionEditor:l,lazy:n,...a})=>{let c=n?s:d,o=t(()=>createBuilderPreviewProvider(r,l),[r,l]);return e(c,{children:e(BuilderPreviewContext.Provider,{...a,value:o,children:i})})},useBuilderPreviewStore=(e,t)=>{let r=i(BuilderPreviewContext);if(!r)throw Error("useBuilderPreviewStore must be used within a BuilderPreviewProvider");return l(r,e,t)};export{BuilderPreviewProvider,useBuilderPreviewStore};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6470,6 +6470,7 @@ type BlockEntity = {
|
|
|
6470
6470
|
name?: string;
|
|
6471
6471
|
dateModified?: string | number;
|
|
6472
6472
|
childrens?: string[];
|
|
6473
|
+
rawChildrens?: BlockEntity[];
|
|
6473
6474
|
settings?: Record<string, any>;
|
|
6474
6475
|
advanced?: Record<string, any>;
|
|
6475
6476
|
styles?: Record<string, any>;
|
|
@@ -7738,7 +7739,12 @@ type SelectProductBundleControlType<T> = SharedControlType<T> & {
|
|
|
7738
7739
|
hide?: boolean;
|
|
7739
7740
|
};
|
|
7740
7741
|
|
|
7741
|
-
type
|
|
7742
|
+
type NotesControlType<T> = SharedControlType<T> & {
|
|
7743
|
+
type: 'notes';
|
|
7744
|
+
value?: string;
|
|
7745
|
+
};
|
|
7746
|
+
|
|
7747
|
+
type ControlProp<T> = ProductBundleChildControlType<T> | SelectProductBundleControlType<T> | AngleControlType<T> | CheckboxControlType<T> | ColorPickerControlType<T> | GroupControlType<T> | IconControlType<T> | InputFixContentControlType<T> | InputNumberControlType<T> | InputUnitControlType<T> | InputUnitSpacingControlType<T> | InputUnitWidthControlType<T> | InputControlType<T> | MarginControlType<T> | PaddingControlType<T> | PositionControlType<T> | RadioGroupControlType | RangeControlType<T> | SegmentControlType<T> | SelectControlType<T> | TextareaControlType<T> | ToggleControlType<T> | ImageControlType<T> | ChildrensControlType | GridControlType<T> | FlexControlType<T> | TextEditorControlType<T> | ProductControlType<T> | TypographyControlType<T> | TypographyV2ControlType<T> | MenuControlType<T> | BehaviorStateControlType<T> | PickLinkControlType<T> | BoxShadowControlType<T> | TextShadowControlType<T> | BorderControlType<T> | BorderRadiusControlType<T> | RadiusPresetControlType<T> | SizeControlType<T> | ChildItemType<T> | PickMultiProductControlType<T> | CollectionControlType<T> | BackgroundControlType<T> | VisibilityControlType<T> | SelectVariantControlType | CountdownEvergreenType | Timezone<T> | CustomContentControlType<T> | DateTimePickerControlType | CountdownDailyType | KlaviyoCodes | YotpoLoyaltyCodes | InputWidthControlType<T> | LayoutSegmentControlType<T> | InputSpacing<T> | UniqueIdControlType<T> | PositionSquareControlType<T> | CustomCodeEditor | LayoutControlType<T> | LayoutBannerControlType<T> | SwatchesLinkControlType<T> | VariantSwatchesPresetControlType<T> | VariantSwatchesOnlyDefaultVariantControlType<T> | ProductListControlType<T> | ArticleListControlType<T> | CollectionBannerControlType<T> | Ratio<T> | StickyDisplayControlType<T> | SyncProductPropertiesControlType<T> | StepsGuide<T> | ImageShape<T> | GridArrange<T> | SizeSetting$1<T> | ChildIconType<T> | DropdownInput<T> | Dropdown<T> | AliPickSectionControlType<T> | ParallaxScrollingType<T> | PlayPauseControlType<T> | LayoutCustomSegmentControlType<T> | SneakPeakRange<T> | SneakPeakTypeControlType<T> | BackgroundColorPickerType<T> | ProductInputCurrencyUnitControlType<T> | TypographyPostPurchaseControlType<T> | ProductOffersControlType<T> | DiscountAndShippingFee<T> | SneakPeakControlType<T> | PostPurchaseTextareaControlType<T> | DealControlType<T> | NotesControlType<T>;
|
|
7742
7748
|
type ControlTriggerAction = {
|
|
7743
7749
|
controlId: string;
|
|
7744
7750
|
newValue?: any;
|