@gem-sdk/pages 2.0.0-dev.890 → 2.0.0-staging.120
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.
- package/dist/cjs/components/ErrorBoundary.js +41 -1
- package/dist/cjs/components/ErrorFallback.js +27 -1
- package/dist/cjs/components/FacebookPixel.js +34 -3
- package/dist/cjs/components/FooterForPostPurchase.js +35 -1
- package/dist/cjs/components/GoogleAnalytic.js +66 -5
- package/dist/cjs/components/TikTokPixel.js +20 -3
- package/dist/cjs/components/builder/Body.js +37 -0
- package/dist/cjs/components/builder/Footer.js +155 -0
- package/dist/cjs/components/builder/Header.js +188 -0
- package/dist/cjs/components/builder/PopupManager.js +64 -1
- package/dist/cjs/components/builder/SwitchView.js +185 -0
- package/dist/cjs/components/builder/Toolbar.js +701 -1
- package/dist/cjs/components/builder/Toolbox.js +485 -1
- package/dist/cjs/components/builder/const.js +56 -0
- package/dist/cjs/components/builder/toolbar/const.js +7 -0
- package/dist/cjs/components/builder/toolbar/utils/findDOMClosest.js +41 -0
- package/dist/cjs/components/builder/toolbar/utils/findOverflowParent.js +20 -0
- package/dist/cjs/components/builder/toolbar/utils/getChildrenByAttrSelector.js +18 -0
- package/dist/cjs/components/builder/toolbar/utils/getDOMElementParents.js +32 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverParent.js +16 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverToolbarPosition.js +12 -0
- package/dist/cjs/components/builder/toolbar/utils/isSection.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/notVisible.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/waitForElementToExist.js +27 -0
- package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +151 -1
- package/dist/cjs/components/image-to-layout/DropElement.js +167 -1
- package/dist/cjs/components/image-to-layout/ImageToLayout.js +42 -1
- package/dist/cjs/index.js +80 -1
- package/dist/cjs/layouts/main.js +31 -1
- package/dist/cjs/libs/api/get-builder-props.js +46 -1
- package/dist/cjs/libs/api/get-collection-props.js +68 -1
- package/dist/cjs/libs/api/get-home-page-props-v2.js +145 -1
- package/dist/cjs/libs/api/get-home-page-props.js +151 -1
- package/dist/cjs/libs/api/get-post-purchase-props-preview.js +268 -1
- package/dist/cjs/libs/api/get-preview-props.js +18 -1
- package/dist/cjs/libs/api/get-product-props.js +73 -1
- package/dist/cjs/libs/api/get-static-page-props-preview.js +155 -1
- package/dist/cjs/libs/api/get-static-page-props-v2.js +164 -1
- package/dist/cjs/libs/api/get-static-page-props.js +148 -1
- package/dist/cjs/libs/custom-fonts.js +60 -6
- package/dist/cjs/libs/fetcher.js +100 -1
- package/dist/cjs/libs/get-layout.js +13 -1
- package/dist/cjs/libs/get-storefront-api.js +12 -1
- package/dist/cjs/libs/getStaticPaths.js +10 -1
- package/dist/cjs/libs/google-fonts.js +118 -1
- package/dist/cjs/libs/helpers/check-option-font.js +65 -0
- package/dist/cjs/libs/helpers/common.js +27 -1
- package/dist/cjs/libs/helpers/gen-css.js +135 -1
- package/dist/cjs/libs/helpers/gen-fonts.js +90 -1
- package/dist/cjs/libs/helpers/generate-manifres.js +5 -1
- package/dist/cjs/libs/helpers/get-fallback.js +34 -1
- package/dist/cjs/libs/helpers/normalize.js +111 -1
- package/dist/cjs/libs/helpers/parse-json.js +16 -1
- package/dist/cjs/libs/helpers/user-agent.js +7 -1
- package/dist/cjs/libs/hooks/use-tracking-view.js +43 -1
- package/dist/cjs/libs/hooks/usePagePreview.js +92 -1
- package/dist/cjs/libs/parse-html.js +34 -1
- package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1845 -1
- package/dist/cjs/pages/404.js +43 -1
- package/dist/cjs/pages/500.js +74 -1
- package/dist/cjs/pages/CollectionGlobalProvider.js +59 -1
- package/dist/cjs/pages/builder.js +115 -1
- package/dist/cjs/pages/collection-detail.js +64 -1
- package/dist/cjs/pages/preview.js +26 -1
- package/dist/cjs/pages/product-detail.js +69 -1
- package/dist/cjs/pages/static-v2.js +139 -1
- package/dist/cjs/pages/static.js +75 -1
- package/dist/cjs/store/libs-store.js +14 -0
- package/dist/esm/components/ErrorBoundary.js +39 -1
- package/dist/esm/components/ErrorFallback.js +25 -1
- package/dist/esm/components/FacebookPixel.js +32 -3
- package/dist/esm/components/FooterForPostPurchase.js +31 -1
- package/dist/esm/components/GoogleAnalytic.js +64 -5
- package/dist/esm/components/TikTokPixel.js +18 -3
- package/dist/esm/components/builder/Body.js +33 -0
- package/dist/esm/components/builder/Footer.js +151 -0
- package/dist/esm/components/builder/Header.js +184 -0
- package/dist/esm/components/builder/PopupManager.js +60 -1
- package/dist/esm/components/builder/SwitchView.js +181 -0
- package/dist/esm/components/builder/Toolbar.js +697 -1
- package/dist/esm/components/builder/Toolbox.js +481 -1
- package/dist/esm/components/builder/const.js +54 -0
- package/dist/esm/components/builder/toolbar/const.js +4 -0
- package/dist/esm/components/builder/toolbar/utils/findDOMClosest.js +39 -0
- package/dist/esm/components/builder/toolbar/utils/findOverflowParent.js +18 -0
- package/dist/esm/components/builder/toolbar/utils/getChildrenByAttrSelector.js +16 -0
- package/dist/esm/components/builder/toolbar/utils/getDOMElementParents.js +30 -0
- package/dist/esm/components/builder/toolbar/utils/isOverParent.js +14 -0
- package/dist/esm/components/builder/toolbar/utils/isOverToolbarPosition.js +10 -0
- package/dist/esm/components/builder/toolbar/utils/isSection.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/notVisible.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/waitForElementToExist.js +25 -0
- package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +147 -1
- package/dist/esm/components/image-to-layout/DropElement.js +165 -1
- package/dist/esm/components/image-to-layout/ImageToLayout.js +38 -1
- package/dist/esm/index.js +35 -1
- package/dist/esm/layouts/main.js +27 -1
- package/dist/esm/libs/api/get-builder-props.js +44 -1
- package/dist/esm/libs/api/get-collection-props.js +66 -1
- package/dist/esm/libs/api/get-home-page-props-v2.js +143 -1
- package/dist/esm/libs/api/get-home-page-props.js +149 -1
- package/dist/esm/libs/api/get-post-purchase-props-preview.js +260 -1
- package/dist/esm/libs/api/get-preview-props.js +16 -1
- package/dist/esm/libs/api/get-product-props.js +71 -1
- package/dist/esm/libs/api/get-static-page-props-preview.js +153 -1
- package/dist/esm/libs/api/get-static-page-props-v2.js +162 -1
- package/dist/esm/libs/api/get-static-page-props.js +146 -1
- package/dist/esm/libs/custom-fonts.js +55 -6
- package/dist/esm/libs/fetcher.js +96 -1
- package/dist/esm/libs/get-layout.js +11 -1
- package/dist/esm/libs/get-storefront-api.js +10 -1
- package/dist/esm/libs/getStaticPaths.js +8 -1
- package/dist/esm/libs/google-fonts.js +112 -1
- package/dist/esm/libs/helpers/check-option-font.js +63 -0
- package/dist/esm/libs/helpers/common.js +24 -1
- package/dist/esm/libs/helpers/gen-css.js +133 -1
- package/dist/esm/libs/helpers/gen-fonts.js +87 -1
- package/dist/esm/libs/helpers/generate-manifres.js +3 -1
- package/dist/esm/libs/helpers/get-fallback.js +32 -1
- package/dist/esm/libs/helpers/normalize.js +103 -1
- package/dist/esm/libs/helpers/parse-json.js +13 -1
- package/dist/esm/libs/helpers/user-agent.js +5 -1
- package/dist/esm/libs/hooks/use-tracking-view.js +41 -1
- package/dist/esm/libs/hooks/usePagePreview.js +90 -1
- package/dist/esm/libs/parse-html.js +32 -1
- package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1843 -1
- package/dist/esm/pages/404.js +41 -1
- package/dist/esm/pages/500.js +72 -1
- package/dist/esm/pages/CollectionGlobalProvider.js +55 -1
- package/dist/esm/pages/builder.js +113 -1
- package/dist/esm/pages/collection-detail.js +60 -1
- package/dist/esm/pages/preview.js +24 -1
- package/dist/esm/pages/product-detail.js +65 -1
- package/dist/esm/pages/static-v2.js +137 -1
- package/dist/esm/pages/static.js +71 -1
- package/dist/esm/store/libs-store.js +12 -0
- package/dist/types/index.d.ts +50 -34
- package/package.json +8 -5
- package/dist/cjs/components/Footer.js +0 -1
- package/dist/cjs/components/Header.js +0 -1
- package/dist/cjs/components/builder/toolbar/Onboarding.js +0 -1
- package/dist/esm/components/Footer.js +0 -1
- package/dist/esm/components/Header.js +0 -1
- package/dist/esm/components/builder/toolbar/Onboarding.js +0 -1
|
@@ -1 +1,697 @@
|
|
|
1
|
-
import{jsx as t}from"react/jsx-runtime";import{memo as e,useRef as r,useState as o,useCallback as a,useEffect as i}from"react";import n from"./toolbar/Onboarding.js";let TOOLBAR_HOVER_HEIGHT=24,TOOLBAR_ACTIVE_HEIGHT=32,getDOMElementParents=(t,e,r)=>{let o=[];for(;t;)if(t=t.parentElement??void 0){if("BODY"===t.tagName||"ROOT"===t.getAttribute("data-uid"))break;if(e){if(t.matches(e)&&(o.push(t),r&&o.length==r))return o;continue}if(o.push(t),r&&o.length==r)break}return o},getChildrenByAttrSelector=(t,e)=>{let r=t.children.length;if(r)for(let o=0;o<r;o++){let r=t.children[o];if(r){let t=r.getAttribute(e);if(t)return r}}},isOverParent=({current:t,parent:e,index:r,revert:o})=>{for(let a=0;a<r;a++){let r=t.top-23*a>=e.top&&t.top-23*a<=e.top+e.height||t.top-23*a>=e.top+e.height&&t.top-23*a<=e.top;if(o&&(r=t.bottom+23*a>=e.bottom&&t.bottom+23*a<=e.bottom-e.height||t.bottom+23*a>=e.bottom-e.height&&t.bottom+23*a<=e.bottom),r)return!0}return!1},waitForElementToExist=(t,e=200)=>new Promise(r=>{let o=setInterval(()=>{let e=document.querySelector(t);e&&(clearInterval(o),clearTimeout(a),r(e))},50),a=setTimeout(()=>{clearInterval(o),clearTimeout(a),r(null)},e)}),notVisible=t=>{let e=getComputedStyle(t).overflow;return"visible"!==e},isSection=t=>{let e=t.getAttribute("data-component-tag");return"Section"===e},isLayoutElement=t=>{let e=t.getAttribute("data-component-tag");return"Row"===e||"Product"===e},isPopup=t=>{let e=t.getAttribute("data-component-tag");return"Dialog"===e},isSticky=t=>{let e=t.getAttribute("data-component-tag");return"Sticky"===e},isOverToolbarPosition=(t,e)=>{let r=t.getBoundingClientRect(),o=e.getBoundingClientRect();return r.top-o.top<33},findOverflowParent=(t,e)=>{let r=e||t;if(t&&!isSection(t))return notVisible(t)&&isOverToolbarPosition(e,t)?t:t.parentElement?findOverflowParent(t.parentElement,r):void 0},COMPONENTS_TAG_NOT_LOAD_IMAGES=["PostPurchaseProductImages"],Toolbar=()=>{let e=r(null),l=r(!1),d=r(),u=r(!1),c=r(!1),[s,b]=o(!1),[m,v]=o(0),[g,f]=o("bottom"),p=r(null),h=({state:t,$toolbar:e,$component:r})=>{let o=findOverflowParent(r,e),a=e.getBoundingClientRect(),i=r.getBoundingClientRect(),n=window.innerWidth;o?i?.height<=60?e.setAttribute(`data-toolbar-${t}-revert`,"true"):e.setAttribute(`data-toolbar-${t}-inside`,"true"):a.top<33&&(i?.height<=60?e.setAttribute(`data-toolbar-${t}-revert`,"true"):e.setAttribute(`data-toolbar-${t}-inside`,"true")),i.left+a.width>n&&e.setAttribute(`data-toolbar-${t}-overflow`,"true");let l=r?.closest('[aria-label="Dialog body"]');if(l){let r=l.getBoundingClientRect(),o=r.left+r.width-20;i.left+a.width>o&&e.setAttribute(`data-toolbar-${t}-overflow`,"true")}},A=a(({$component:t,componentUid:e,focus:r,isPreventSection:o,isParent:a})=>{if(!t&&!e)return;if(!t){let r=document.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}if(!e){let r=t.getAttribute("data-uid");if(!r)return;e=r}let i=getChildrenByAttrSelector(t,"data-toolbar"),n=getChildrenByAttrSelector(t,"data-outline"),l=getChildrenByAttrSelector(t,"data-toolbar-add-top"),d=getChildrenByAttrSelector(t,"data-toolbar-add-bottom"),u=getChildrenByAttrSelector(t,"data-column"),c=getChildrenByAttrSelector(t,"data-theme-section-status");o&&c&&c.setAttribute("data-theme-section-status-active","true"),i&&(i.removeAttribute("style"),a||i.setAttribute("data-toolbar-hover","true"),r&&i.setAttribute("data-toolbar-hover-focus","true"),h({$toolbar:i,$component:t,state:"hover"})),n&&(n.setAttribute("data-outline-hover","true"),a&&n.setAttribute("data-outline-parent-hover","true"),o&&n.setAttribute("data-outline-overlay-theme-section","true"),r&&n.setAttribute("data-outline-hover-focus","true")),l&&!a&&l.setAttribute("data-toolbar-add-hover","true"),d&&!a&&d.setAttribute("data-toolbar-add-hover","true"),u&&u.setAttribute("data-column-visible","true")},[]),y=a(({$component:t,componentUid:e})=>{if(!t){let r=document.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}let r=getDOMElementParents(t,'[data-uid][data-component-type="component"]:not([data-component-no-setting])',1);if(r.length){for(let t of r)t&&A({$component:t,isParent:!0});w({$component:t,$parents:r})}},[A]),w=({$component:t,$parents:e})=>{if(!t||!e?.length)return;let r=getChildrenByAttrSelector(t,"data-toolbar-hover-focus");if(r){let t=r.getBoundingClientRect(),o=!!r.getAttribute("data-toolbar-hover-revert"),a=!!r.getAttribute("data-toolbar-hover-inside"),i=1;for(let r of e)if(r){let e=r.getAttribute("data-component-tag");if("Section"===e)continue;let n=getChildrenByAttrSelector(r,"data-toolbar-hover");if(n){let e=n.getAttribute("data-toolbar-active");if(e)continue;let r=n.getBoundingClientRect(),l=o||a;if(isOverParent({current:t,parent:r,index:i,revert:l})){let e=getComputedStyle(n),o=t.top-r.top,a=t.left-r.left,d=parseFloat(e.top)+o-23*i;l&&(d=parseFloat(e.top)-o+23*i);let u=parseFloat(e.left)+a;n.setAttribute("style",`top: ${d}px;left: ${u}px;`),i++}}}}},E=a(()=>{let t=["data-outline-overlay","data-outline-overlay-theme-section","data-theme-section-status-active"],e=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))})},[]),S=a(()=>{let t=["data-toolbar-hover-focus","data-toolbar-hover","data-outline-hover-focus","data-toolbar-hover-revert","data-toolbar-hover-inside","data-outline-hover","data-toolbar-add-hover","data-column-visible","data-outline-parent-hover","data-toolbar-hover-overflow"],e=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))}),E()},[E]),$=a(()=>{if(p.current&&clearTimeout(p.current),m>0){let t=new CustomEvent("editor:toolbar:close-onboarding",{bubbles:!0,detail:{close:"close Onboarding"}});window.dispatchEvent(t),b(!1)}},[m]),C=a(()=>{e.current=null;let t=["data-toolbar-active","data-outline-active","data-toolbar-add-active","data-toolbar-active-revert","data-toolbar-active-inside","data-spacing-margin-bottom-active","data-toolbar-force-hover","data-outline-force-hover","data-column-force-visible","data-toolbar-active-overflow"],r=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));r&&t.forEach(t=>{r.forEach(e=>e.removeAttribute(t))}),I(!1),d.current&&d.current(),$()},[$]),B=(t,r)=>{let o=t=>{let o=t.detail;o?.componentUid==e.current?.componentUid&&r()};window.removeEventListener("editor:component:render",o),window.addEventListener("editor:component:render",o);let a=t.getAttribute("data-component-tag");if(a&&!COMPONENTS_TAG_NOT_LOAD_IMAGES.includes(a)){let e=t.querySelectorAll("img");e?.length&&e.forEach(t=>{t.addEventListener("load",()=>{r()})})}d.current=()=>{window.removeEventListener("editor:component:render",o)}},L=a(({$component:t})=>{if(!t)return;let e=getComputedStyle(t),r=getChildrenByAttrSelector(t,"data-spacing"),o=r?.querySelector("[data-spacing-margin-bottom]")||null;if(o){let r=o.querySelector("[data-spacing-margin-bottom-bg]")||null,a=o.querySelector("[data-spacing-margin-bottom-drag]")||null;if(r&&a){let i=e.marginBottom;if(0>parseFloat(i)&&(i="0"),r.style.height=i,a.style.top=i,o.setAttribute("data-spacing-margin-bottom-active","true"),isLayoutElement(t))r.style.left="0";else{let t=e.paddingLeft,o=`-${t}`,i=`translate(${o}, -100%)`;r.style.left=o,a.style.transform=i}}}},[]),T=()=>{let t=document.querySelector("[data-toolbar-active]"),e=document.querySelector("[data-toolbar-onboarding]");t&&e&&(e?.removeAttribute("data-onboarding-active"),setTimeout(()=>{let r=t.getBoundingClientRect(),o=r.top||0,a=e?.getBoundingClientRect(),i=a?.height||0,n=parent.document.querySelector(".iframe"),l=n?.contentWindow,d=l?.scrollY||0,u=n?.clientHeight||0;if(o+i>u){let t=r.top+d-i-8;e?.setAttribute("style",`top: ${t}px;left: ${r.left}px;`),f("top"),l&&t<r.top+d&&setTimeout(()=>{let e=t-20;l.scrollTo({top:e,behavior:"smooth"})},200)}else{let t=r.top+d+r.height+8;e?.setAttribute("style",`top: ${t}px;left: ${r.left}px;`),f("bottom")}v(t=>t+1),e?.setAttribute("data-onboarding-active","true")},100))},O=a(({$component:t})=>{if(!t||isSection(t)||isPopup(t)||isSticky(t))return;let e=document.querySelector("[data-toolbar-onboarding]");0==m?T():($(),e?.removeAttribute("data-onboarding-active"))},[m,$]),q=({componentUid:t,productId:e,marqueeKey:r})=>r?`[marquee-item-key="${r}"] [data-uid="${t}"]`:`${e?`[data-product-id="${e}"][data-uid="${t}"], [data-product-id="${e}"] [data-uid="${t}"]`:`[data-uid="${t}"]`}`,P=a(async({componentUid:t,productId:r,timeAwait:o=600,forceReActive:a,marqueeKey:i})=>{if(!t)return;let n=q({componentUid:t,productId:r,marqueeKey:i}),l=await waitForElementToExist(n,o);if(!l||!a&&t==e.current?.componentUid&&r==e.current?.productId&&i==e.current?.marqueeKey)return;(a||t===e.current?.componentUid)&&r===e.current?.productId&&i===e.current?.marqueeKey||C();let d=getChildrenByAttrSelector(l,"data-toolbar"),u=getChildrenByAttrSelector(l,"data-outline"),c=getChildrenByAttrSelector(l,"data-toolbar-add-top"),s=getChildrenByAttrSelector(l,"data-toolbar-add-bottom"),b=getChildrenByAttrSelector(l,"data-column");d&&(e.current={componentUid:t,productId:r,marqueeKey:i},d.removeAttribute("style"),d.setAttribute("data-toolbar-active","true"),h({$toolbar:d,$component:l,state:"active"})),u&&u.setAttribute("data-outline-active","true"),c&&c.setAttribute("data-toolbar-add-active","true"),s&&s.setAttribute("data-toolbar-add-active","true"),b&&b.setAttribute("data-column-force-visible","true");let m=!!l.closest('[data-component-tag="Marquee"]');if(r||m){let e=document.querySelectorAll(`[data-uid="${t}"]`);e?.length&&e.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&e.setAttribute("data-outline-active","true")})}L({$component:l}),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{O({$component:l})},5e3),S(),B(l,()=>{P({componentUid:t,productId:r,timeAwait:2e3,forceReActive:!0})})},[C,S,L,O]),I=async t=>{if(t){if(e.current?.componentUid){let r=e.current?.componentUid,o=e.current?.productId,a=await waitForElementToExist(`${o?`[data-product-id="${o}"] `:""}[data-uid="${r}"]`,500);if(console.log(" $component",a),a){let e=getChildrenByAttrSelector(a,"data-toolbar"),r=getChildrenByAttrSelector(a,"data-outline"),o=getChildrenByAttrSelector(a,"data-spacing");e&&t&&e.setAttribute("data-toolbar-editor-inline-focus","true"),r&&t&&r.setAttribute("data-outline-editor-inline-focus","true"),o&&t&&o.setAttribute("data-spacing-hidden","true")}}}else{let t=document.querySelectorAll("[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]");t.length&&t.forEach(t=>{t&&(t.removeAttribute("data-toolbar-editor-inline-focus"),t.removeAttribute("data-outline-editor-inline-focus"),t.removeAttribute("data-spacing-hidden"))})}},R=a(t=>{let r=t.closest("[data-theme-section]"),o=r?.getAttribute("data-uid"),a=r&&o===e.current?.componentUid;if(!a)return;let i=getChildrenByAttrSelector(r,"data-theme-section-status");i&&i.setAttribute("data-theme-section-status-active","true")},[]),U=async({value:t})=>{if(!t)return;let r=await waitForElementToExist(`${e.current?.productId?`[data-product-id="${e.current?.productId}"] `:""}[data-uid="${e.current?.componentUid}"]`,500);if(r){let t=r?.querySelectorAll("[data-toolbar-parent]");if(t.length){let r=t=>{let e=t.getAttribute("data-parent-uid");if(!e)return;let r=document.querySelectorAll(`[data-uid="${e}"]`);r.length&&r.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&(e.setAttribute("data-outline-force-hover","true"),e.setAttribute("data-outline-force-overlay","true"))})},o=t=>{let e=t.getAttribute("data-parent-uid");if(!e)return;let r=document.querySelectorAll(`[data-uid="${e}"]`);r.length&&r.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&(e.removeAttribute("data-outline-force-hover"),e.removeAttribute("data-outline-force-overlay"))})},a=async t=>{let r=t.getAttribute("data-parent-uid");if(!r)return;let a=async()=>{let t=await waitForElementToExist(`[data-uid="${r}"]`,500),e=t?.closest("[data-product-id]"),o=e?.getAttribute("data-product-id")||"";return!!o},i="";await a()&&(i=e.current?.productId||"");let n=new CustomEvent("editor:toolbar:force-active-component",{bubbles:!0,detail:{componentUid:r,productId:i}});o(t),window.dispatchEvent(n)};t.forEach(t=>{t.addEventListener("mouseover",()=>r(t)),t.addEventListener("mouseout",()=>o(t)),t.addEventListener("click",()=>a(t))})}}},x=a(t=>{if(l.current||u.current||c.current)return;let r=t.target;if(!r||"function"!=typeof r.closest){E();return}let o=r.closest("[data-toolbar-hover]");if(o)return;let a=r.closest("[data-toolbar-wrap]"),i=a?.getAttribute("data-uid");if(!a||!i||"ROOT"==i){S();return}let n=getChildrenByAttrSelector(a,"data-toolbar"),d=getChildrenByAttrSelector(a,"data-outline");if(d&&d.removeAttribute("data-outline-overlay"),!i||"ROOT"==i||n?.getAttribute("data-toolbar-hover-focus"))return;if(n?.getAttribute("data-toolbar-hover-focus")||S(),R(r),i==e.current?.componentUid){if(e.current.productId){let t=a.closest("[data-product-id]");if(t){let r=t.getAttribute("data-product-id");if(r==e.current.productId)return}}let t=r.closest("[data-theme-section]")||r.closest("[data-shopify-section]");if(!t)return;A({$component:t,focus:!0,isPreventSection:!0})}let s=r.closest("[data-theme-section]")||r.closest("[data-shopify-section]");s?A({$component:s,focus:!0,isPreventSection:!0}):(A({$component:a,componentUid:i,focus:!0}),y({$component:a,componentUid:i}))},[R,S,A,y,E,e]),_=a(t=>{if(l.current)return;let e=t.detail;e?.componentUid?P({componentUid:e.componentUid,productId:e.productId,marqueeKey:e.marqueeKey}):C()},[P,C,l]),F=a(()=>{S()},[S]),N=a(t=>{let e=t.detail;e.value&&(S(),C()),l.current=e.value},[S,C]),k=a(t=>{let e=t.detail;e.value?I(!0):I(!1)},[]),D=a(t=>{if(l.current)return;let e=t.detail;U({value:e?.value||!1})},[]),M=a(t=>{let e=t.detail;e?.value?(S(),u.current=!0):u.current=!1},[S]),z=a(t=>{let e=t.detail;e?.value?(S(),c.current=!0):c.current=!1},[S]),G=(t,e)=>{if(!t)return;let r=document.querySelectorAll(`[data-uid="${t}"]`);r.length&&r.forEach(t=>{let r=getChildrenByAttrSelector(t,"data-outline");r&&("in"===e?(r.setAttribute("data-outline-force-hover","true"),r.setAttribute("data-outline-force-overlay","true")):(r.removeAttribute("data-outline-force-hover"),r.removeAttribute("data-outline-force-overlay")))})},H=a(t=>{if(l.current)return;let e=t.detail;e?.componentUid&&G(e?.componentUid,e?.type)},[l]),j=a(t=>{let e=t.detail;e?.isNewUser&&b(!0)},[]),K=a(()=>{s&&T()},[s]);return i(()=>(document.addEventListener("mousemove",x),window.addEventListener("editor:active-component",_),window.addEventListener("editor:focus-outside-preview",F),window.addEventListener("editor:is-dragging",N),window.addEventListener("editor:is-editing-text-editor",k),window.addEventListener("editor:toolbar:show-parents",D),window.addEventListener("editor:toolbar:resize-spacing",M),window.addEventListener("editor:toolbar:resize-column",z),window.addEventListener("editor:hover-component",H),window.addEventListener("editor:toolbar-onboarding",j),window.addEventListener("resize",K),()=>{document.removeEventListener("mousemove",x),window.removeEventListener("editor:active-component",_),window.removeEventListener("editor:is-dragging",F),window.removeEventListener("editor:is-dragging",N),window.removeEventListener("editor:is-editing-text-editor",k),window.removeEventListener("editor:toolbar:show-parents",D),window.removeEventListener("editor:toolbar:resize-spacing",M),window.removeEventListener("editor:toolbar:resize-column",z),window.removeEventListener("editor:hover-component",H),window.removeEventListener("editor:toolbar-onboarding",j),window.removeEventListener("resize",K)}),[x,_,F,N,k,D,M,z,H,j,K]),s&&t(n,{enable:!0,position:g,onCloseOnboarding:$})};var Toolbar$1=e(Toolbar);export{Toolbar$1 as default};
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { memo, useRef, useCallback, useEffect } from 'react';
|
|
4
|
+
import { getDOMElementParents } from './toolbar/utils/getDOMElementParents.js';
|
|
5
|
+
import { TOOLBAR_ACTIVE_HEIGHT, TOOLBAR_HOVER_HEIGHT } from './toolbar/const.js';
|
|
6
|
+
import { getChildrenByAttrSelector } from './toolbar/utils/getChildrenByAttrSelector.js';
|
|
7
|
+
import { findOverflowParent } from './toolbar/utils/findOverflowParent.js';
|
|
8
|
+
import { waitForElementToExist } from './toolbar/utils/waitForElementToExist.js';
|
|
9
|
+
import { isOverParent } from './toolbar/utils/isOverParent.js';
|
|
10
|
+
import { findDOMClosest } from './toolbar/utils/findDOMClosest.js';
|
|
11
|
+
|
|
12
|
+
const Toolbar = ()=>{
|
|
13
|
+
const currentComponentActive = useRef(null);
|
|
14
|
+
const isDragging = useRef(false);
|
|
15
|
+
const stopWatchReRenderComponent = useRef();
|
|
16
|
+
const isResizeSpacing = useRef(false);
|
|
17
|
+
const cacheHoverComponents = useRef([]);
|
|
18
|
+
const cacheHoverThemeSectionComponents = useRef([]);
|
|
19
|
+
const cacheActiveComponents = useRef([]);
|
|
20
|
+
/* Functions */ const changePositionToolbar = ({ state, $toolbar, $component })=>{
|
|
21
|
+
const $parentOverflow = findOverflowParent($component, $toolbar);
|
|
22
|
+
const rect = $toolbar.getBoundingClientRect();
|
|
23
|
+
const rectComponent = $component.getBoundingClientRect();
|
|
24
|
+
const windowWidth = window.innerWidth;
|
|
25
|
+
if ($parentOverflow) {
|
|
26
|
+
if (rectComponent?.height <= 60) {
|
|
27
|
+
$toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
|
|
28
|
+
} else {
|
|
29
|
+
$toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
|
|
30
|
+
}
|
|
31
|
+
// fix toolbar overflow right side
|
|
32
|
+
if (rectComponent.left + rect.width > windowWidth) {
|
|
33
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
if (rect.top < TOOLBAR_ACTIVE_HEIGHT + 1) {
|
|
37
|
+
if (rectComponent?.height <= 60) {
|
|
38
|
+
$toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
|
|
39
|
+
} else {
|
|
40
|
+
$toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// fix toolbar overflow right side
|
|
44
|
+
if (rectComponent.left + rect.width > windowWidth) {
|
|
45
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// fix Popup overflow right position
|
|
49
|
+
const popupEl = $component?.closest('[aria-label="Dialog body"]');
|
|
50
|
+
if (popupEl) {
|
|
51
|
+
const rectPopupEl = popupEl.getBoundingClientRect();
|
|
52
|
+
const popupElRightPosition = rectPopupEl.left + rectPopupEl.width - 20;
|
|
53
|
+
if (rectComponent.left + rect.width > popupElRightPosition) {
|
|
54
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const setHoverComponent = useCallback(({ $component, componentUid, focus, isPreventSection, isParent })=>{
|
|
59
|
+
if (!$component && !componentUid) return;
|
|
60
|
+
if (!$component) {
|
|
61
|
+
const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
|
|
62
|
+
if (!$c) return;
|
|
63
|
+
$component = $c;
|
|
64
|
+
}
|
|
65
|
+
if (!componentUid) {
|
|
66
|
+
const cUid = $component.getAttribute('data-uid');
|
|
67
|
+
if (!cUid) return;
|
|
68
|
+
componentUid = cUid;
|
|
69
|
+
}
|
|
70
|
+
cacheHoverComponents.current.push($component);
|
|
71
|
+
const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
|
|
72
|
+
const $outline = getChildrenByAttrSelector($component, 'data-outline');
|
|
73
|
+
const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
|
|
74
|
+
const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
|
|
75
|
+
const $themeSectionStatus = getChildrenByAttrSelector($component, 'data-theme-section-status');
|
|
76
|
+
if (isPreventSection && $themeSectionStatus) {
|
|
77
|
+
$themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
|
|
78
|
+
}
|
|
79
|
+
if ($toolbar) {
|
|
80
|
+
$toolbar.removeAttribute('style');
|
|
81
|
+
if (!isParent) {
|
|
82
|
+
$toolbar.setAttribute('data-toolbar-hover', 'true');
|
|
83
|
+
}
|
|
84
|
+
if (focus) {
|
|
85
|
+
$toolbar.setAttribute('data-toolbar-hover-focus', 'true');
|
|
86
|
+
}
|
|
87
|
+
changePositionToolbar({
|
|
88
|
+
$toolbar,
|
|
89
|
+
$component,
|
|
90
|
+
state: 'hover'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if ($outline) {
|
|
94
|
+
$outline.setAttribute('data-outline-hover', 'true');
|
|
95
|
+
if (isParent) {
|
|
96
|
+
$outline.setAttribute('data-outline-parent-hover', 'true');
|
|
97
|
+
}
|
|
98
|
+
if (isPreventSection) {
|
|
99
|
+
cacheHoverThemeSectionComponents.current.push($component);
|
|
100
|
+
$outline.setAttribute('data-outline-overlay-theme-section', 'true');
|
|
101
|
+
}
|
|
102
|
+
if (focus) {
|
|
103
|
+
$outline.setAttribute('data-outline-hover-focus', 'true');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if ($btnAddTop) {
|
|
107
|
+
if (!isParent) {
|
|
108
|
+
$btnAddTop.setAttribute('data-toolbar-add-hover', 'true');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if ($btnAddBottom) {
|
|
112
|
+
if (!isParent) {
|
|
113
|
+
$btnAddBottom.setAttribute('data-toolbar-add-hover', 'true');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, []);
|
|
117
|
+
const setHoverComponentParents = useCallback(({ $component, componentUid })=>{
|
|
118
|
+
if (!$component) {
|
|
119
|
+
const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
|
|
120
|
+
if (!$c) return;
|
|
121
|
+
$component = $c;
|
|
122
|
+
}
|
|
123
|
+
const $parents = getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])', 1);
|
|
124
|
+
if ($parents.length) {
|
|
125
|
+
for (const $parent of $parents){
|
|
126
|
+
if ($parent) {
|
|
127
|
+
setHoverComponent({
|
|
128
|
+
$component: $parent,
|
|
129
|
+
isParent: true
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
changePositionToolbarParents({
|
|
134
|
+
$component,
|
|
135
|
+
$parents
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, [
|
|
139
|
+
setHoverComponent
|
|
140
|
+
]);
|
|
141
|
+
const changePositionToolbarParents = ({ $component, $parents })=>{
|
|
142
|
+
if (!$component) return;
|
|
143
|
+
if (!$parents?.length) return;
|
|
144
|
+
const $currentToolbar = getChildrenByAttrSelector($component, 'data-toolbar-hover-focus');
|
|
145
|
+
if ($currentToolbar) {
|
|
146
|
+
const currentRect = $currentToolbar.getBoundingClientRect();
|
|
147
|
+
const isRevert = $currentToolbar.getAttribute('data-toolbar-hover-revert') ? true : false;
|
|
148
|
+
const isInside = $currentToolbar.getAttribute('data-toolbar-hover-inside') ? true : false;
|
|
149
|
+
let index = 1;
|
|
150
|
+
for (const $parent of $parents){
|
|
151
|
+
if ($parent) {
|
|
152
|
+
const tag = $parent.getAttribute('data-component-tag');
|
|
153
|
+
if (tag === 'Section') continue;
|
|
154
|
+
const $toolbar = getChildrenByAttrSelector($parent, 'data-toolbar-hover');
|
|
155
|
+
if ($toolbar) {
|
|
156
|
+
// Ignore with toolbar active
|
|
157
|
+
const isActive = $toolbar.getAttribute('data-toolbar-active');
|
|
158
|
+
if (isActive) continue;
|
|
159
|
+
// Start calc
|
|
160
|
+
const parentRect = $toolbar.getBoundingClientRect();
|
|
161
|
+
const checkRevert = isRevert || isInside;
|
|
162
|
+
if (isOverParent({
|
|
163
|
+
current: currentRect,
|
|
164
|
+
parent: parentRect,
|
|
165
|
+
index,
|
|
166
|
+
revert: checkRevert
|
|
167
|
+
})) {
|
|
168
|
+
const parentStyle = getComputedStyle($toolbar);
|
|
169
|
+
// parentStyle.top
|
|
170
|
+
const diffTop = currentRect.top - parentRect.top;
|
|
171
|
+
const diffLeft = currentRect.left - parentRect.left;
|
|
172
|
+
let newTop = parseFloat(parentStyle.top) + diffTop - (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
|
|
173
|
+
if (checkRevert) {
|
|
174
|
+
newTop = parseFloat(parentStyle.top) - diffTop + (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
|
|
175
|
+
}
|
|
176
|
+
const newLeft = parseFloat(parentStyle.left) + diffLeft;
|
|
177
|
+
$toolbar.setAttribute('style', `top: ${newTop}px;left: ${newLeft}px;`);
|
|
178
|
+
index++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const removeHoverThemeSectionComponent = useCallback(()=>{
|
|
186
|
+
const clearAttrs = [
|
|
187
|
+
'data-outline-overlay-theme-section',
|
|
188
|
+
'data-theme-section-status-active'
|
|
189
|
+
];
|
|
190
|
+
const $hoverThemeSectionComponents = cacheHoverThemeSectionComponents.current;
|
|
191
|
+
if ($hoverThemeSectionComponents.length) {
|
|
192
|
+
for (const $hoverThemeSectionComponent of $hoverThemeSectionComponents){
|
|
193
|
+
const $elms = $hoverThemeSectionComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
|
|
194
|
+
if ($elms) {
|
|
195
|
+
clearAttrs.forEach((attr)=>{
|
|
196
|
+
$elms.forEach(($el)=>$el.removeAttribute(attr));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
cacheHoverThemeSectionComponents.current = []; // clear
|
|
202
|
+
}, []);
|
|
203
|
+
const removeHoverComponent = useCallback(()=>{
|
|
204
|
+
const clearAttrs = [
|
|
205
|
+
'data-toolbar-hover-focus',
|
|
206
|
+
'data-toolbar-hover',
|
|
207
|
+
'data-outline-hover-focus',
|
|
208
|
+
'data-toolbar-hover-revert',
|
|
209
|
+
'data-toolbar-hover-inside',
|
|
210
|
+
'data-outline-hover',
|
|
211
|
+
'data-toolbar-add-hover',
|
|
212
|
+
'data-outline-parent-hover',
|
|
213
|
+
'data-toolbar-hover-overflow'
|
|
214
|
+
];
|
|
215
|
+
const $hoverComponents = cacheHoverComponents.current;
|
|
216
|
+
if ($hoverComponents.length) {
|
|
217
|
+
for (const $hoverComponent of $hoverComponents){
|
|
218
|
+
const $elms = $hoverComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
|
|
219
|
+
if ($elms) {
|
|
220
|
+
clearAttrs.forEach((attr)=>{
|
|
221
|
+
$elms.forEach(($el)=>$el.removeAttribute(attr));
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
removeHoverThemeSectionComponent();
|
|
227
|
+
cacheHoverComponents.current = []; // clear
|
|
228
|
+
}, [
|
|
229
|
+
removeHoverThemeSectionComponent
|
|
230
|
+
]);
|
|
231
|
+
const removeActiveComponent = useCallback(()=>{
|
|
232
|
+
currentComponentActive.current = null;
|
|
233
|
+
const clearAttrs = [
|
|
234
|
+
'data-toolbar-active',
|
|
235
|
+
'data-outline-active',
|
|
236
|
+
'data-toolbar-add-active',
|
|
237
|
+
'data-toolbar-active-revert',
|
|
238
|
+
'data-toolbar-active-inside',
|
|
239
|
+
'data-spacing-margin-bottom-active',
|
|
240
|
+
'data-toolbar-force-hover',
|
|
241
|
+
'data-outline-force-hover',
|
|
242
|
+
'data-toolbar-active-overflow'
|
|
243
|
+
];
|
|
244
|
+
const $activeComponents = cacheActiveComponents.current;
|
|
245
|
+
if ($activeComponents.length) {
|
|
246
|
+
for (const $activeComponent of $activeComponents){
|
|
247
|
+
const $elms = $activeComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
|
|
248
|
+
if ($elms) {
|
|
249
|
+
clearAttrs.forEach((attr)=>{
|
|
250
|
+
$elms.forEach(($el)=>$el.removeAttribute(attr));
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
cacheActiveComponents.current = []; // clear
|
|
256
|
+
setFocusTextEditor(false);
|
|
257
|
+
if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
|
|
258
|
+
}, []);
|
|
259
|
+
const setActiveComponentSpacing = useCallback(({ $component })=>{
|
|
260
|
+
if (!$component) return;
|
|
261
|
+
const style = getComputedStyle($component);
|
|
262
|
+
const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
|
|
263
|
+
const $marginBottom = ($spacing?.querySelector('[data-spacing-margin-bottom]')) || null;
|
|
264
|
+
if ($marginBottom) {
|
|
265
|
+
const $bg = $marginBottom.querySelector('[data-spacing-margin-bottom-bg]') || null;
|
|
266
|
+
const $drag = $marginBottom.querySelector('[data-spacing-margin-bottom-drag]') || null;
|
|
267
|
+
if ($bg && $drag) {
|
|
268
|
+
const value = style.marginBottom;
|
|
269
|
+
$bg.style.height = value;
|
|
270
|
+
$drag.style.top = value;
|
|
271
|
+
$marginBottom.setAttribute('data-spacing-margin-bottom-active', 'true');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}, []);
|
|
275
|
+
const getSelectorComponent = ({ componentUid, productId, articleId, marqueeKey })=>{
|
|
276
|
+
if (articleId) {
|
|
277
|
+
return `${articleId ? `[data-article-id="${articleId}"][data-uid="${componentUid}"], [data-article-id="${articleId}"] [data-uid="${componentUid}"]` : `[data-uid="${componentUid}"]`}`;
|
|
278
|
+
}
|
|
279
|
+
if (marqueeKey) {
|
|
280
|
+
return `[marquee-item-key="${marqueeKey}"] [data-uid="${componentUid}"]`;
|
|
281
|
+
}
|
|
282
|
+
return `${productId ? `[data-product-id="${productId}"][data-uid="${componentUid}"], [data-product-id="${productId}"] [data-uid="${componentUid}"]` : `[data-uid="${componentUid}"]`}`;
|
|
283
|
+
};
|
|
284
|
+
const setActiveComponent = useCallback(async ({ componentUid, productId, timeAwait = 600, articleId, forceReActive, marqueeKey })=>{
|
|
285
|
+
if (!componentUid) return;
|
|
286
|
+
const selector = getSelectorComponent({
|
|
287
|
+
componentUid,
|
|
288
|
+
productId,
|
|
289
|
+
articleId,
|
|
290
|
+
marqueeKey
|
|
291
|
+
});
|
|
292
|
+
const $component = await waitForElementToExist(selector, timeAwait);
|
|
293
|
+
if (!$component) return;
|
|
294
|
+
if (!forceReActive && componentUid == currentComponentActive.current?.componentUid && productId == currentComponentActive.current?.productId && articleId == currentComponentActive.current?.articleId && marqueeKey == currentComponentActive.current?.marqueeKey) return;
|
|
295
|
+
if (componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || articleId !== currentComponentActive.current?.articleId || forceReActive) removeActiveComponent();
|
|
296
|
+
if (!forceReActive && componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || marqueeKey !== currentComponentActive.current?.marqueeKey) {
|
|
297
|
+
removeActiveComponent();
|
|
298
|
+
}
|
|
299
|
+
cacheActiveComponents.current.push($component);
|
|
300
|
+
const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
|
|
301
|
+
const $outline = getChildrenByAttrSelector($component, 'data-outline');
|
|
302
|
+
const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
|
|
303
|
+
const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
|
|
304
|
+
if ($toolbar) {
|
|
305
|
+
currentComponentActive.current = {
|
|
306
|
+
componentUid,
|
|
307
|
+
productId,
|
|
308
|
+
articleId,
|
|
309
|
+
marqueeKey
|
|
310
|
+
};
|
|
311
|
+
$toolbar.removeAttribute('style');
|
|
312
|
+
$toolbar.setAttribute('data-toolbar-active', 'true');
|
|
313
|
+
changePositionToolbar({
|
|
314
|
+
$toolbar,
|
|
315
|
+
$component,
|
|
316
|
+
state: 'active'
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if ($outline) {
|
|
320
|
+
$outline.setAttribute('data-outline-active', 'true');
|
|
321
|
+
}
|
|
322
|
+
if ($btnAddTop) {
|
|
323
|
+
$btnAddTop.setAttribute('data-toolbar-add-active', 'true');
|
|
324
|
+
}
|
|
325
|
+
if ($btnAddBottom) {
|
|
326
|
+
$btnAddBottom.setAttribute('data-toolbar-add-active', 'true');
|
|
327
|
+
}
|
|
328
|
+
const { $isChildOfMarquee, $section } = findDOMClosest($component, {
|
|
329
|
+
$isChildOfMarquee: '[data-component-tag="Marquee"]',
|
|
330
|
+
$section: '[data-component-tag="Section"]'
|
|
331
|
+
});
|
|
332
|
+
// Active same element in product list
|
|
333
|
+
if ($section && (productId || articleId || $isChildOfMarquee)) {
|
|
334
|
+
const $relatedElements = $section.querySelectorAll(`[data-uid="${componentUid}"]`);
|
|
335
|
+
if ($relatedElements?.length) {
|
|
336
|
+
$relatedElements.forEach(($relatedElement)=>{
|
|
337
|
+
cacheActiveComponents.current.push($relatedElement);
|
|
338
|
+
const $outline = getChildrenByAttrSelector($relatedElement, 'data-outline');
|
|
339
|
+
if ($outline) {
|
|
340
|
+
$outline.setAttribute('data-outline-active', 'true');
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
setActiveComponentSpacing({
|
|
346
|
+
$component
|
|
347
|
+
});
|
|
348
|
+
removeHoverComponent();
|
|
349
|
+
}, [
|
|
350
|
+
removeActiveComponent,
|
|
351
|
+
removeHoverComponent,
|
|
352
|
+
setActiveComponentSpacing
|
|
353
|
+
]);
|
|
354
|
+
const setFocusTextEditor = async (value)=>{
|
|
355
|
+
if (!value) {
|
|
356
|
+
const $components = document.body.querySelector('#storefront')?.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
|
|
357
|
+
if ($components?.length) {
|
|
358
|
+
$components.forEach(($component)=>{
|
|
359
|
+
if ($component) {
|
|
360
|
+
$component.removeAttribute('data-toolbar-editor-inline-focus');
|
|
361
|
+
$component.removeAttribute('data-outline-editor-inline-focus');
|
|
362
|
+
$component.removeAttribute('data-spacing-hidden');
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
if (currentComponentActive.current?.componentUid) {
|
|
368
|
+
const selector = getSelectorComponent({
|
|
369
|
+
...currentComponentActive.current
|
|
370
|
+
});
|
|
371
|
+
const $component = await waitForElementToExist(selector, 500);
|
|
372
|
+
if ($component) {
|
|
373
|
+
const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
|
|
374
|
+
const $outline = getChildrenByAttrSelector($component, 'data-outline');
|
|
375
|
+
const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
|
|
376
|
+
if ($toolbar) {
|
|
377
|
+
if (value) {
|
|
378
|
+
$toolbar.setAttribute('data-toolbar-editor-inline-focus', 'true');
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if ($outline) {
|
|
382
|
+
if (value) {
|
|
383
|
+
$outline.setAttribute('data-outline-editor-inline-focus', 'true');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if ($spacing) {
|
|
387
|
+
if (value) {
|
|
388
|
+
$spacing.setAttribute('data-spacing-hidden', 'true');
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const hoverActiveThemeSection = useCallback(($target)=>{
|
|
396
|
+
const $themeSection = $target.closest('[data-theme-section]');
|
|
397
|
+
const $themeSectionUid = $themeSection?.getAttribute('data-uid');
|
|
398
|
+
const isActiveThemeSection = $themeSection && $themeSectionUid === currentComponentActive.current?.componentUid;
|
|
399
|
+
if (!isActiveThemeSection) return;
|
|
400
|
+
cacheHoverThemeSectionComponents.current.push($themeSection);
|
|
401
|
+
const $themeSectionStatus = getChildrenByAttrSelector($themeSection, 'data-theme-section-status');
|
|
402
|
+
if ($themeSectionStatus) {
|
|
403
|
+
$themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
|
|
404
|
+
}
|
|
405
|
+
}, []);
|
|
406
|
+
const setShowParents = async ({ value })=>{
|
|
407
|
+
if (!value || !currentComponentActive.current) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const selector = getSelectorComponent({
|
|
411
|
+
...currentComponentActive.current
|
|
412
|
+
});
|
|
413
|
+
const $component = await waitForElementToExist(selector, 500);
|
|
414
|
+
if ($component) {
|
|
415
|
+
const $parents = $component?.querySelectorAll('[data-toolbar-parent]');
|
|
416
|
+
if ($parents.length) {
|
|
417
|
+
const onHover = ($parent)=>{
|
|
418
|
+
const uid = $parent.getAttribute('data-parent-uid');
|
|
419
|
+
if (!uid) return;
|
|
420
|
+
const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
|
|
421
|
+
if ($parentComponents?.length) {
|
|
422
|
+
$parentComponents.forEach(($parentComponent)=>{
|
|
423
|
+
const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
|
|
424
|
+
if ($outline) {
|
|
425
|
+
$outline.setAttribute('data-outline-force-hover', 'true');
|
|
426
|
+
$outline.setAttribute('data-outline-force-overlay', 'true');
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
const outHover = ($parent)=>{
|
|
432
|
+
const uid = $parent.getAttribute('data-parent-uid');
|
|
433
|
+
if (!uid) return;
|
|
434
|
+
const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
|
|
435
|
+
if ($parentComponents?.length) {
|
|
436
|
+
$parentComponents.forEach(($parentComponent)=>{
|
|
437
|
+
const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
|
|
438
|
+
if ($outline) {
|
|
439
|
+
$outline.removeAttribute('data-outline-force-hover');
|
|
440
|
+
$outline.removeAttribute('data-outline-force-overlay');
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const onClick = async ($parent)=>{
|
|
446
|
+
const uid = $parent.getAttribute('data-parent-uid');
|
|
447
|
+
if (!uid) return;
|
|
448
|
+
const isElementInsideProduct = async ()=>{
|
|
449
|
+
const $component = await waitForElementToExist(`[data-uid="${uid}"]`, 500);
|
|
450
|
+
const $product = $component?.closest('[data-product-id]');
|
|
451
|
+
return !!($product?.getAttribute('data-product-id') || '');
|
|
452
|
+
};
|
|
453
|
+
const isElementInsideArticle = async ()=>{
|
|
454
|
+
const $component = await waitForElementToExist(`[data-uid="${uid}"]`, 500);
|
|
455
|
+
const $article = $component?.closest('[data-article-id]');
|
|
456
|
+
return !!($article?.getAttribute('data-article-id') || '');
|
|
457
|
+
};
|
|
458
|
+
let productId = '';
|
|
459
|
+
let articleId = '';
|
|
460
|
+
if (await isElementInsideProduct()) {
|
|
461
|
+
productId = currentComponentActive.current?.productId || '';
|
|
462
|
+
}
|
|
463
|
+
if (await isElementInsideArticle()) {
|
|
464
|
+
articleId = currentComponentActive.current?.articleId || '';
|
|
465
|
+
}
|
|
466
|
+
const event = new CustomEvent('editor:toolbar:force-active-component', {
|
|
467
|
+
bubbles: true,
|
|
468
|
+
detail: {
|
|
469
|
+
componentUid: uid,
|
|
470
|
+
productId,
|
|
471
|
+
articleId,
|
|
472
|
+
elementTag: $parent.getAttribute('data-component-tag') || ''
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
outHover($parent);
|
|
476
|
+
window.dispatchEvent(event);
|
|
477
|
+
};
|
|
478
|
+
$parents.forEach(($parent)=>{
|
|
479
|
+
$parent.addEventListener('mouseover', ()=>onHover($parent));
|
|
480
|
+
$parent.addEventListener('mouseout', ()=>outHover($parent));
|
|
481
|
+
$parent.addEventListener('click', ()=>onClick($parent));
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
/* Event listener */ const onMouseMove = useCallback((e)=>{
|
|
487
|
+
if (isDragging.current) return;
|
|
488
|
+
if (isResizeSpacing.current) return;
|
|
489
|
+
const $target = e.target;
|
|
490
|
+
// check target
|
|
491
|
+
if (!$target || typeof $target.closest !== 'function') {
|
|
492
|
+
removeHoverThemeSectionComponent();
|
|
493
|
+
removeHoverComponent();
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const { $toolbarHover, $component, $themeSection, $shopifySection } = findDOMClosest($target, {
|
|
497
|
+
$toolbarHover: '[data-toolbar-hover]',
|
|
498
|
+
$component: '[data-toolbar-wrap]',
|
|
499
|
+
$themeSection: '[data-theme-section]',
|
|
500
|
+
$shopifySection: '[data-shopify-section]'
|
|
501
|
+
});
|
|
502
|
+
if ($toolbarHover) {
|
|
503
|
+
// Disable feature overlay when hover to toolbar parents
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
// Hover to other component
|
|
507
|
+
const componentUid = $component?.getAttribute('data-uid');
|
|
508
|
+
if (!$component || !componentUid || componentUid == 'ROOT') {
|
|
509
|
+
removeHoverComponent();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
|
|
513
|
+
if (!componentUid) return;
|
|
514
|
+
if (componentUid == 'ROOT') return;
|
|
515
|
+
if ($toolbar?.getAttribute('data-toolbar-hover-focus')) return;
|
|
516
|
+
if (!$toolbar?.getAttribute('data-toolbar-hover-focus')) removeHoverComponent();
|
|
517
|
+
hoverActiveThemeSection($target);
|
|
518
|
+
const $preventSection = $themeSection || $shopifySection;
|
|
519
|
+
// Disable event when hover active component
|
|
520
|
+
if (componentUid == currentComponentActive.current?.componentUid) {
|
|
521
|
+
if (currentComponentActive.current.productId) {
|
|
522
|
+
const $product = $component.closest(`[data-product-id]`);
|
|
523
|
+
if ($product) {
|
|
524
|
+
const productId = $product.getAttribute('data-product-id');
|
|
525
|
+
if (productId == currentComponentActive.current.productId) {
|
|
526
|
+
removeHoverComponent();
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if ($preventSection) {
|
|
532
|
+
setHoverComponent({
|
|
533
|
+
$component: $preventSection,
|
|
534
|
+
focus: true,
|
|
535
|
+
isPreventSection: true
|
|
536
|
+
});
|
|
537
|
+
} else {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if ($preventSection) {
|
|
542
|
+
setHoverComponent({
|
|
543
|
+
$component: $preventSection,
|
|
544
|
+
focus: true,
|
|
545
|
+
isPreventSection: true
|
|
546
|
+
});
|
|
547
|
+
} else {
|
|
548
|
+
setHoverComponent({
|
|
549
|
+
$component,
|
|
550
|
+
componentUid,
|
|
551
|
+
focus: true
|
|
552
|
+
});
|
|
553
|
+
setHoverComponentParents({
|
|
554
|
+
$component,
|
|
555
|
+
componentUid
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
}, [
|
|
559
|
+
hoverActiveThemeSection,
|
|
560
|
+
removeHoverComponent,
|
|
561
|
+
setHoverComponent,
|
|
562
|
+
setHoverComponentParents,
|
|
563
|
+
removeHoverThemeSectionComponent,
|
|
564
|
+
currentComponentActive
|
|
565
|
+
]);
|
|
566
|
+
const onActiveComponent = useCallback((e)=>{
|
|
567
|
+
if (isDragging.current) return;
|
|
568
|
+
const detail = e.detail;
|
|
569
|
+
if (detail?.componentUid) {
|
|
570
|
+
setActiveComponent({
|
|
571
|
+
componentUid: detail.componentUid,
|
|
572
|
+
productId: detail.productId,
|
|
573
|
+
articleId: detail.articleId,
|
|
574
|
+
marqueeKey: detail.marqueeKey
|
|
575
|
+
});
|
|
576
|
+
} else {
|
|
577
|
+
removeActiveComponent();
|
|
578
|
+
}
|
|
579
|
+
}, [
|
|
580
|
+
setActiveComponent,
|
|
581
|
+
removeActiveComponent,
|
|
582
|
+
isDragging
|
|
583
|
+
]);
|
|
584
|
+
const onFocusOutsidePreview = useCallback(()=>{
|
|
585
|
+
removeHoverComponent();
|
|
586
|
+
}, [
|
|
587
|
+
removeHoverComponent
|
|
588
|
+
]);
|
|
589
|
+
const onIsDragging = useCallback((e)=>{
|
|
590
|
+
const detail = e.detail;
|
|
591
|
+
if (detail.value) {
|
|
592
|
+
removeHoverComponent();
|
|
593
|
+
removeActiveComponent();
|
|
594
|
+
}
|
|
595
|
+
isDragging.current = detail.value;
|
|
596
|
+
}, [
|
|
597
|
+
removeHoverComponent,
|
|
598
|
+
removeActiveComponent
|
|
599
|
+
]);
|
|
600
|
+
const onIsEditingTextEditor = useCallback((e)=>{
|
|
601
|
+
const detail = e.detail;
|
|
602
|
+
if (detail.value) {
|
|
603
|
+
setFocusTextEditor(true);
|
|
604
|
+
} else {
|
|
605
|
+
setFocusTextEditor(false);
|
|
606
|
+
}
|
|
607
|
+
}, []);
|
|
608
|
+
const onShowParents = useCallback((e)=>{
|
|
609
|
+
if (isDragging.current) return;
|
|
610
|
+
const detail = e.detail;
|
|
611
|
+
setShowParents({
|
|
612
|
+
value: detail?.value || false
|
|
613
|
+
});
|
|
614
|
+
}, []);
|
|
615
|
+
const onResizeSpacing = useCallback((e)=>{
|
|
616
|
+
const detail = e.detail;
|
|
617
|
+
if (detail?.value) {
|
|
618
|
+
removeHoverComponent();
|
|
619
|
+
isResizeSpacing.current = true;
|
|
620
|
+
} else {
|
|
621
|
+
isResizeSpacing.current = false;
|
|
622
|
+
}
|
|
623
|
+
}, [
|
|
624
|
+
removeHoverComponent
|
|
625
|
+
]);
|
|
626
|
+
const setHoverParentComponent = (uid, type)=>{
|
|
627
|
+
if (!uid) return;
|
|
628
|
+
const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
|
|
629
|
+
if ($parentComponents?.length) {
|
|
630
|
+
$parentComponents.forEach(($parentComponent)=>{
|
|
631
|
+
const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
|
|
632
|
+
if ($outline) {
|
|
633
|
+
if (type === 'in') {
|
|
634
|
+
$outline.setAttribute('data-outline-force-hover', 'true');
|
|
635
|
+
$outline.setAttribute('data-outline-force-overlay', 'true');
|
|
636
|
+
} else {
|
|
637
|
+
$outline.removeAttribute('data-outline-force-hover');
|
|
638
|
+
$outline.removeAttribute('data-outline-force-overlay');
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
const onHoverComponent = useCallback((e)=>{
|
|
645
|
+
if (isDragging.current) return;
|
|
646
|
+
const detail = e.detail;
|
|
647
|
+
if (detail?.componentUid) {
|
|
648
|
+
setHoverParentComponent(detail?.componentUid, detail?.type);
|
|
649
|
+
}
|
|
650
|
+
}, [
|
|
651
|
+
isDragging
|
|
652
|
+
]);
|
|
653
|
+
const onComponentReRender = (e)=>{
|
|
654
|
+
const detail = e.detail;
|
|
655
|
+
if (currentComponentActive.current?.componentUid && detail?.componentUid == currentComponentActive.current?.componentUid) {
|
|
656
|
+
setActiveComponent({
|
|
657
|
+
...currentComponentActive.current
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
/* Register event */ useEffect(()=>{
|
|
662
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
663
|
+
window.addEventListener('editor:active-component', onActiveComponent);
|
|
664
|
+
window.addEventListener('editor:focus-outside-preview', onFocusOutsidePreview);
|
|
665
|
+
window.addEventListener('editor:is-dragging', onIsDragging);
|
|
666
|
+
window.addEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
|
|
667
|
+
window.addEventListener('editor:toolbar:show-parents', onShowParents);
|
|
668
|
+
window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
|
|
669
|
+
window.addEventListener('editor:hover-component', onHoverComponent);
|
|
670
|
+
window.addEventListener('editor:component:render', onComponentReRender);
|
|
671
|
+
return ()=>{
|
|
672
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
673
|
+
window.removeEventListener('editor:active-component', onActiveComponent);
|
|
674
|
+
window.removeEventListener('editor:is-dragging', onFocusOutsidePreview);
|
|
675
|
+
window.removeEventListener('editor:is-dragging', onIsDragging);
|
|
676
|
+
window.removeEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
|
|
677
|
+
window.removeEventListener('editor:toolbar:show-parents', onShowParents);
|
|
678
|
+
window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
|
|
679
|
+
window.removeEventListener('editor:hover-component', onHoverComponent);
|
|
680
|
+
window.removeEventListener('editor:component:render', onComponentReRender);
|
|
681
|
+
};
|
|
682
|
+
}, [
|
|
683
|
+
onMouseMove,
|
|
684
|
+
onActiveComponent,
|
|
685
|
+
onFocusOutsidePreview,
|
|
686
|
+
onIsDragging,
|
|
687
|
+
onIsEditingTextEditor,
|
|
688
|
+
onShowParents,
|
|
689
|
+
onResizeSpacing,
|
|
690
|
+
onHoverComponent,
|
|
691
|
+
onComponentReRender
|
|
692
|
+
]);
|
|
693
|
+
return /*#__PURE__*/ jsx(Fragment, {});
|
|
694
|
+
};
|
|
695
|
+
var Toolbar$1 = /*#__PURE__*/ memo(Toolbar);
|
|
696
|
+
|
|
697
|
+
export { Toolbar$1 as default };
|