@gem-sdk/core 2.0.0-dev.849 → 2.0.0-dev.852

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";var react=require("react"),useAnimationConfig=require("./useAnimationConfig.js");const SPACING_ACTIVE_ATTRIBUTE="data-spacing-margin-bottom-active",TOOLBAR_ACTIVE_ATTRIBUTE="data-toolbar-active",OUTLINE_ACTIVE_ATTRIBUTE="data-outline-active",TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE="data-toolbar-add-active",useAnimationTarget=t=>{let{isEnabledAnimation:e}=useAnimationConfig.useAnimationConfig(t),r=t.tag,a=t.uid,o=react.useRef(null),u=react.useRef([]),T=t=>{if(u.current)for(let e of u.current)t?(e.toolbar?.setAttribute(TOOLBAR_ACTIVE_ATTRIBUTE,"true"),e.outline?.setAttribute(OUTLINE_ACTIVE_ATTRIBUTE,"true"),e.spacing?.setAttribute(SPACING_ACTIVE_ATTRIBUTE,"true"),e.addSectionTop?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true"),e.addSectionBottom?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true")):(e.toolbar?.removeAttribute(TOOLBAR_ACTIVE_ATTRIBUTE),e.outline?.removeAttribute(OUTLINE_ACTIVE_ATTRIBUTE),e.spacing?.removeAttribute(SPACING_ACTIVE_ATTRIBUTE),e.addSectionTop?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE),e.addSectionBottom?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE))},i=t=>{let e=t.querySelector("[data-toolbar-add-top]"),r=t.querySelector("[data-toolbar-add-bottom]"),a=Array.from(t.children),o=a.find(t=>null!==t.getAttribute("data-toolbar")),u=a.find(t=>null!==t.getAttribute("data-outline"));return{sectionToolbar:o,sectionOutline:u,sectionAddTop:e,sectionAddBottom:r}},n=react.useCallback(t=>t.reduce((t,e)=>{let a=null,o=null,u=e,T=e.querySelector("[data-toolbar][data-toolbar-active]"),n=e.querySelector("[data-outline][data-outline-active]"),A=Array.from(u.children),c=A.find(t=>{let e=t.getAttribute("data-spacing");return null!==e&&t.querySelector("[data-spacing-margin-bottom")});switch(r){case"Button":case"SubmitButton":case"ProductButton":case"DynamicCheckout":u=e.querySelector(".gp-button-base");break;case"ProductProperties":u=e.querySelector("input");break;case"Icon":u=e.firstElementChild;break;case"ProductTag":u=e?.children[0]?.children[0];break;case"Section":{u=e;let{sectionOutline:t,sectionToolbar:r,sectionAddTop:A,sectionAddBottom:c}=i(u);n=t,T=r,a=A,o=c;break}default:u=e}let l={target:u,toolbar:T,outline:n,spacing:c,addSectionTop:a,addSectionBottom:o};return t.push(l),t},[]),[r]),A=react.useCallback(()=>{if(!e)return;o.current||(o.current=document.querySelectorAll(`[data-uid="${a}"]`));let t=Array.from(o.current);if(!t.length)return;let r=n(t);u.current=r},[a,n,e]);return{targetObjects:u,setToolbarActive:T,initListOfTargets:A}};exports.useAnimationTarget=useAnimationTarget;
1
+ "use strict";var react=require("react"),useAnimationConfig=require("./useAnimationConfig.js");const SPACING_ACTIVE_ATTRIBUTE="data-spacing-margin-bottom-active",TOOLBAR_ACTIVE_ATTRIBUTE="data-toolbar-active",OUTLINE_ACTIVE_ATTRIBUTE="data-outline-active",TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE="data-toolbar-add-active",useAnimationTarget=t=>{let{isEnabledAnimation:e}=useAnimationConfig.useAnimationConfig(t),r=t.tag,a=t.uid,o=react.useRef(null),T=react.useRef([]),u=t=>{if(T.current)for(let e of T.current)t?(e.toolbar?.setAttribute(TOOLBAR_ACTIVE_ATTRIBUTE,"true"),e.outline?.setAttribute(OUTLINE_ACTIVE_ATTRIBUTE,"true"),e.spacing?.setAttribute(SPACING_ACTIVE_ATTRIBUTE,"true"),e.addSectionTop?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true"),e.addSectionBottom?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true")):(e.toolbar?.removeAttribute(TOOLBAR_ACTIVE_ATTRIBUTE),e.outline?.removeAttribute(OUTLINE_ACTIVE_ATTRIBUTE),e.spacing?.removeAttribute(SPACING_ACTIVE_ATTRIBUTE),e.addSectionTop?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE),e.addSectionBottom?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE))},i=t=>{let e=t.querySelector("[data-toolbar-add-top]"),r=t.querySelector("[data-toolbar-add-bottom]"),a=Array.from(t.children),o=a.find(t=>null!==t.getAttribute("data-toolbar")),T=a.find(t=>null!==t.getAttribute("data-outline"));return{sectionToolbar:o,sectionOutline:T,sectionAddTop:e,sectionAddBottom:r}},n=react.useCallback(t=>t.reduce((t,e)=>{let a=null,o=null,T=e,u=e.querySelector("[data-toolbar][data-toolbar-active]"),n=e.querySelector("[data-outline][data-outline-active]"),A=e.querySelector("[data-spacing] [data-spacing-margin-bottom]");switch(r){case"Button":case"SubmitButton":case"ProductButton":case"DynamicCheckout":T=e.querySelector(".gp-button-base");break;case"ProductProperties":T=e.querySelector("input");break;case"Icon":T=e.firstElementChild;break;case"ProductTag":T=e?.children[0]?.children[0];break;case"Section":{T=e;let{sectionOutline:t,sectionToolbar:r,sectionAddTop:A,sectionAddBottom:c}=i(T);n=t,u=r,a=A,o=c;break}default:T=e}let c={target:T,toolbar:u,outline:n,spacing:A,addSectionTop:a,addSectionBottom:o};return t.push(c),t},[]),[r]),A=react.useCallback(()=>{if(!e)return;o.current||(o.current=document.querySelectorAll(`[data-uid="${a}"]`));let t=Array.from(o.current);if(!t.length)return;let r=n(t);T.current=r},[a,n,e]);return{targetObjects:T,setToolbarActive:u,initListOfTargets:A}};exports.useAnimationTarget=useAnimationTarget;
@@ -1 +1 @@
1
- "use strict";var useSWR=require("swr"),getProducts=require("../../helpers/queries/get-products.js"),query=require("../../helpers/query.js"),shop=require("../shop.js"),useFetchHandle=require("../useFetchHandle.js");const useProductsQuery=(e,u,r)=>{let t=useFetchHandle.useFetchHandle(),s=shop.useIsSampleProduct(),c=shop.useIsStorefrontProduct();return useSWR(e?query.generateProductsQueryKey({ids:e,isSample:!r?.fetcher&&s,isStorefront:!r?.fetcher&&c,defaultSelectedProductCount:r?.defaultSelectedProductCount,allStatus:r?.allStatus}):null,async([,e])=>getProducts.getProducts(r?.fetcher||t,e),u)},useProductsQueryAll=(e,u)=>{let r=useFetchHandle.useFetchHandle();return useSWR(e?["query/products",e]:null,async([,e])=>getProducts.getProductQueryAll(r,e),u)};exports.useProductsQuery=useProductsQuery,exports.useProductsQueryAll=useProductsQueryAll;
1
+ "use strict";var useSWR=require("swr"),getProducts=require("../../helpers/queries/get-products.js"),query=require("../../helpers/query.js"),shop=require("../shop.js"),useFetchHandle=require("../useFetchHandle.js");const useProductsQuery=(e,u,r)=>{let s=useFetchHandle.useFetchHandle(),t=shop.useIsSampleProduct(),c=shop.useIsStorefrontProduct();return useSWR(e?query.generateProductsQueryKey({ids:e,isSample:t,isStorefront:c,defaultSelectedProductCount:r?.defaultSelectedProductCount,allStatus:r?.allStatus}):null,async([,e])=>getProducts.getProducts(r?.fetcher||s,e),u)},useProductsQueryAll=(e,u)=>{let r=useFetchHandle.useFetchHandle();return useSWR(e?["query/products",e]:null,async([,e])=>getProducts.getProductQueryAll(r,e),u)};exports.useProductsQuery=useProductsQuery,exports.useProductsQueryAll=useProductsQueryAll;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var useSWR=require("swr"),productValueLabel_generated=require("../graphql/queries/product-value-label.generated.js"),variantPresets=require("../components/src/product/helpers/variant-presets.js"),shop=require("./shop.js"),useFetchHandle=require("./useFetchHandle.js"),ShopContext=require("../contexts/ShopContext.js");let swatchChange=!1,colorChange=!1;const useInitialSwatchesOptions=e=>{let t=useFetchHandle.useFetchHandle(),a=ShopContext.useShopStore(e=>e.changeSwatches),{swatches:o}=shop.useSwatches(),{data:s}=useSWR(["/query/productOptionName",{}],async()=>fetchProductValueLabel(t),{revalidateOnMount:!0}),r=[];if(o?.forEach(e=>{r.push(e.optionTitle)}),s?.productOptionName?.forEach(e=>{r.includes(e)||(swatchChange=!0,o?.push({optionTitle:e,optionType:"rectangle_list",optionValues:[]}))}),!e)return[];setDefaultSwatches(o,e),o?.length&&(swatchChange||colorChange)&&(window?.parent?.postMessage?.(JSON.stringify({type:"update-swatches",swatches:o}),"*"),a(o))},getColorDefault=(e,t)=>{let a=e?variantPresets.colorPreset[e.toLocaleLowerCase()]:void 0,o=a?[a]:[],s=t?.[0];return!s&&o.length&&(colorChange=!0),s?[s]:o},getProductOptionsLabelByName=(e,t)=>{let a=[],o=e.find(e=>e.name===t);return o?.values.forEach(e=>{a.push(e.label??"")}),a},getSwatchesOptionsLabel=e=>{let t=[];return e.forEach(e=>{t.push(e.label??"")}),t},setDefaultSwatches=(e,t)=>(e&&e?.map(e=>{let a=getProductOptionsLabelByName(t,e.optionTitle),o=getSwatchesOptionsLabel(e.optionValues);a.forEach(t=>{o.includes(t)||e.optionValues.push({label:t,colors:getColorDefault(t),imageUrl:""})}),e.optionValues=e.optionValues.map(e=>(void 0===e.imageUrl&&(swatchChange=!0),{label:e.label??"",colors:getColorDefault(e.label,e.colors),imageUrl:e.imageUrl??""}))}),e),fetchProductValueLabel=async e=>{let t={},a=async t=>{let a=await e([productValueLabel_generated.ProductOptionNameDocument,t]);return a};return a(t)};exports.default=useInitialSwatchesOptions;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var useSWR=require("swr"),productValueLabel_generated=require("../graphql/queries/product-value-label.generated.js"),variantPresets=require("../components/src/product/helpers/variant-presets.js"),shop=require("./shop.js"),useFetchHandle=require("./useFetchHandle.js"),ShopContext=require("../contexts/ShopContext.js");require("react"),require("react/jsx-runtime"),require("zustand"),require("@gem-sdk/adapter-shopify"),require("swr/mutation"),require("vanilla-lazyload"),require("./useCartUI.js"),require("react-transition-group"),require("@gem-sdk/core"),require("classnames");var isBrowser=require("../helpers/is-browser.js");require("../helpers/convert.js");let swatchChange=!1,colorChange=!1;const useInitialSwatchesOptions=e=>{let t=useFetchHandle.useFetchHandle(),r=ShopContext.useShopStore(e=>e.changeSwatches),{swatches:a}=shop.useSwatches(),{data:s}=useSWR(["/query/productOptionName",{}],async()=>fetchProductValueLabel(t),{revalidateOnMount:!0}),o=[];if(a?.forEach(e=>{o.push(e.optionTitle)}),s?.productOptionName?.forEach(e=>{o.includes(e)||(swatchChange=!0,a?.push({optionTitle:e,optionType:"rectangle_list",optionValues:[]}))}),!e)return[];setDefaultSwatches(a,e),isBrowser.default()&&a?.length&&(swatchChange||colorChange)&&(window?.parent?.postMessage?.(JSON.stringify({type:"update-swatches",swatches:a}),"*"),r(a))},getColorDefault=(e,t)=>{let r=e?variantPresets.colorPreset[e.toLocaleLowerCase()]:void 0,a=r?[r]:[],s=t?.[0];return!s&&a.length&&(colorChange=!0),s?[s]:a},getProductOptionsLabelByName=(e,t)=>{let r=[],a=e.find(e=>e.name===t);return a?.values.forEach(e=>{r.push(e.label??"")}),r},getSwatchesOptionsLabel=e=>{let t=[];return e.forEach(e=>{t.push(e.label??"")}),t},setDefaultSwatches=(e,t)=>(e&&e?.map(e=>{let r=getProductOptionsLabelByName(t,e.optionTitle),a=getSwatchesOptionsLabel(e.optionValues);r.forEach(t=>{a.includes(t)||e.optionValues.push({label:t,colors:getColorDefault(t),imageUrl:""})}),e.optionValues=e.optionValues.map(e=>(void 0===e.imageUrl&&(swatchChange=!0),{label:e.label??"",colors:getColorDefault(e.label,e.colors),imageUrl:e.imageUrl??""}))}),e),fetchProductValueLabel=async e=>{let t={},r=async t=>{let r=await e([productValueLabel_generated.ProductOptionNameDocument,t]);return r};return r(t)};exports.default=useInitialSwatchesOptions;
@@ -1 +1 @@
1
- import{useRef as t,useCallback as e}from"react";import{useAnimationConfig as r}from"./useAnimationConfig.js";let SPACING_ACTIVE_ATTRIBUTE="data-spacing-margin-bottom-active",TOOLBAR_ACTIVE_ATTRIBUTE="data-toolbar-active",OUTLINE_ACTIVE_ATTRIBUTE="data-outline-active",TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE="data-toolbar-add-active",useAnimationTarget=a=>{let{isEnabledAnimation:o}=r(a),T=a.tag,u=a.uid,i=t(null),A=t([]),n=t=>{if(A.current)for(let e of A.current)t?(e.toolbar?.setAttribute(TOOLBAR_ACTIVE_ATTRIBUTE,"true"),e.outline?.setAttribute(OUTLINE_ACTIVE_ATTRIBUTE,"true"),e.spacing?.setAttribute(SPACING_ACTIVE_ATTRIBUTE,"true"),e.addSectionTop?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true"),e.addSectionBottom?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true")):(e.toolbar?.removeAttribute(TOOLBAR_ACTIVE_ATTRIBUTE),e.outline?.removeAttribute(OUTLINE_ACTIVE_ATTRIBUTE),e.spacing?.removeAttribute(SPACING_ACTIVE_ATTRIBUTE),e.addSectionTop?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE),e.addSectionBottom?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE))},l=t=>{let e=t.querySelector("[data-toolbar-add-top]"),r=t.querySelector("[data-toolbar-add-bottom]"),a=Array.from(t.children),o=a.find(t=>null!==t.getAttribute("data-toolbar")),T=a.find(t=>null!==t.getAttribute("data-outline"));return{sectionToolbar:o,sectionOutline:T,sectionAddTop:e,sectionAddBottom:r}},c=e(t=>t.reduce((t,e)=>{let r=null,a=null,o=e,u=e.querySelector("[data-toolbar][data-toolbar-active]"),i=e.querySelector("[data-outline][data-outline-active]"),A=Array.from(o.children),n=A.find(t=>{let e=t.getAttribute("data-spacing");return null!==e&&t.querySelector("[data-spacing-margin-bottom")});switch(T){case"Button":case"SubmitButton":case"ProductButton":case"DynamicCheckout":o=e.querySelector(".gp-button-base");break;case"ProductProperties":o=e.querySelector("input");break;case"Icon":o=e.firstElementChild;break;case"ProductTag":o=e?.children[0]?.children[0];break;case"Section":{o=e;let{sectionOutline:t,sectionToolbar:T,sectionAddTop:A,sectionAddBottom:n}=l(o);i=t,u=T,r=A,a=n;break}default:o=e}let c={target:o,toolbar:u,outline:i,spacing:n,addSectionTop:r,addSectionBottom:a};return t.push(c),t},[]),[T]),d=e(()=>{if(!o)return;i.current||(i.current=document.querySelectorAll(`[data-uid="${u}"]`));let t=Array.from(i.current);if(!t.length)return;let e=c(t);A.current=e},[u,c,o]);return{targetObjects:A,setToolbarActive:n,initListOfTargets:d}};export{useAnimationTarget};
1
+ import{useRef as t,useCallback as e}from"react";import{useAnimationConfig as r}from"./useAnimationConfig.js";let SPACING_ACTIVE_ATTRIBUTE="data-spacing-margin-bottom-active",TOOLBAR_ACTIVE_ATTRIBUTE="data-toolbar-active",OUTLINE_ACTIVE_ATTRIBUTE="data-outline-active",TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE="data-toolbar-add-active",useAnimationTarget=a=>{let{isEnabledAnimation:o}=r(a),T=a.tag,u=a.uid,i=t(null),A=t([]),n=t=>{if(A.current)for(let e of A.current)t?(e.toolbar?.setAttribute(TOOLBAR_ACTIVE_ATTRIBUTE,"true"),e.outline?.setAttribute(OUTLINE_ACTIVE_ATTRIBUTE,"true"),e.spacing?.setAttribute(SPACING_ACTIVE_ATTRIBUTE,"true"),e.addSectionTop?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true"),e.addSectionBottom?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE,"true")):(e.toolbar?.removeAttribute(TOOLBAR_ACTIVE_ATTRIBUTE),e.outline?.removeAttribute(OUTLINE_ACTIVE_ATTRIBUTE),e.spacing?.removeAttribute(SPACING_ACTIVE_ATTRIBUTE),e.addSectionTop?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE),e.addSectionBottom?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE))},c=t=>{let e=t.querySelector("[data-toolbar-add-top]"),r=t.querySelector("[data-toolbar-add-bottom]"),a=Array.from(t.children),o=a.find(t=>null!==t.getAttribute("data-toolbar")),T=a.find(t=>null!==t.getAttribute("data-outline"));return{sectionToolbar:o,sectionOutline:T,sectionAddTop:e,sectionAddBottom:r}},l=e(t=>t.reduce((t,e)=>{let r=null,a=null,o=e,u=e.querySelector("[data-toolbar][data-toolbar-active]"),i=e.querySelector("[data-outline][data-outline-active]"),A=e.querySelector("[data-spacing] [data-spacing-margin-bottom]");switch(T){case"Button":case"SubmitButton":case"ProductButton":case"DynamicCheckout":o=e.querySelector(".gp-button-base");break;case"ProductProperties":o=e.querySelector("input");break;case"Icon":o=e.firstElementChild;break;case"ProductTag":o=e?.children[0]?.children[0];break;case"Section":{o=e;let{sectionOutline:t,sectionToolbar:T,sectionAddTop:A,sectionAddBottom:n}=c(o);i=t,u=T,r=A,a=n;break}default:o=e}let n={target:o,toolbar:u,outline:i,spacing:A,addSectionTop:r,addSectionBottom:a};return t.push(n),t},[]),[T]),d=e(()=>{if(!o)return;i.current||(i.current=document.querySelectorAll(`[data-uid="${u}"]`));let t=Array.from(i.current);if(!t.length)return;let e=l(t);A.current=e},[u,l,o]);return{targetObjects:A,setToolbarActive:n,initListOfTargets:d}};export{useAnimationTarget};
@@ -1 +1 @@
1
- import e from"swr";import{getProducts as r,getProductQueryAll as t}from"../../helpers/queries/get-products.js";import{generateProductsQueryKey as u}from"../../helpers/query.js";import{useIsSampleProduct as s,useIsStorefrontProduct as o}from"../shop.js";import{useFetchHandle as l}from"../useFetchHandle.js";let useProductsQuery=(t,c,d)=>{let p=l(),f=s(),m=o();return e(t?u({ids:t,isSample:!d?.fetcher&&f,isStorefront:!d?.fetcher&&m,defaultSelectedProductCount:d?.defaultSelectedProductCount,allStatus:d?.allStatus}):null,async([,e])=>r(d?.fetcher||p,e),c)},useProductsQueryAll=(r,u)=>{let s=l();return e(r?["query/products",r]:null,async([,e])=>t(s,e),u)};export{useProductsQuery,useProductsQueryAll};
1
+ import e from"swr";import{getProducts as r,getProductQueryAll as t}from"../../helpers/queries/get-products.js";import{generateProductsQueryKey as u}from"../../helpers/query.js";import{useIsSampleProduct as s,useIsStorefrontProduct as l}from"../shop.js";import{useFetchHandle as o}from"../useFetchHandle.js";let useProductsQuery=(t,c,d)=>{let p=o(),m=s(),a=l();return e(t?u({ids:t,isSample:m,isStorefront:a,defaultSelectedProductCount:d?.defaultSelectedProductCount,allStatus:d?.allStatus}):null,async([,e])=>r(d?.fetcher||p,e),c)},useProductsQueryAll=(r,u)=>{let s=o();return e(r?["query/products",r]:null,async([,e])=>t(s,e),u)};export{useProductsQuery,useProductsQueryAll};
@@ -1 +1 @@
1
- import e from"swr";import{ProductOptionNameDocument as t}from"../graphql/queries/product-value-label.generated.js";import{colorPreset as a}from"../components/src/product/helpers/variant-presets.js";import{useSwatches as o}from"./shop.js";import{useFetchHandle as l}from"./useFetchHandle.js";import{useShopStore as r}from"../contexts/ShopContext.js";let swatchChange=!1,colorChange=!1,useInitialSwatchesOptions=t=>{let a=l(),s=r(e=>e.changeSwatches),{swatches:n}=o(),{data:i}=e(["/query/productOptionName",{}],async()=>fetchProductValueLabel(a),{revalidateOnMount:!0}),p=[];if(n?.forEach(e=>{p.push(e.optionTitle)}),i?.productOptionName?.forEach(e=>{p.includes(e)||(swatchChange=!0,n?.push({optionTitle:e,optionType:"rectangle_list",optionValues:[]}))}),!t)return[];setDefaultSwatches(n,t),n?.length&&(swatchChange||colorChange)&&(window?.parent?.postMessage?.(JSON.stringify({type:"update-swatches",swatches:n}),"*"),s(n))},getColorDefault=(e,t)=>{let o=e?a[e.toLocaleLowerCase()]:void 0,l=o?[o]:[],r=t?.[0];return!r&&l.length&&(colorChange=!0),r?[r]:l},getProductOptionsLabelByName=(e,t)=>{let a=[],o=e.find(e=>e.name===t);return o?.values.forEach(e=>{a.push(e.label??"")}),a},getSwatchesOptionsLabel=e=>{let t=[];return e.forEach(e=>{t.push(e.label??"")}),t},setDefaultSwatches=(e,t)=>(e&&e?.map(e=>{let a=getProductOptionsLabelByName(t,e.optionTitle),o=getSwatchesOptionsLabel(e.optionValues);a.forEach(t=>{o.includes(t)||e.optionValues.push({label:t,colors:getColorDefault(t),imageUrl:""})}),e.optionValues=e.optionValues.map(e=>(void 0===e.imageUrl&&(swatchChange=!0),{label:e.label??"",colors:getColorDefault(e.label,e.colors),imageUrl:e.imageUrl??""}))}),e),fetchProductValueLabel=async e=>{let a={},o=async a=>{let o=await e([t,a]);return o};return o(a)};export{useInitialSwatchesOptions as default};
1
+ import e from"swr";import{ProductOptionNameDocument as t}from"../graphql/queries/product-value-label.generated.js";import{colorPreset as o}from"../components/src/product/helpers/variant-presets.js";import{useSwatches as a}from"./shop.js";import{useFetchHandle as r}from"./useFetchHandle.js";import{useShopStore as s}from"../contexts/ShopContext.js";import"react";import"react/jsx-runtime";import"zustand";import"@gem-sdk/adapter-shopify";import"swr/mutation";import"vanilla-lazyload";import"./useCartUI.js";import"react-transition-group";import"@gem-sdk/core";import"classnames";import l from"../helpers/is-browser.js";import"../helpers/convert.js";let swatchChange=!1,colorChange=!1,useInitialSwatchesOptions=t=>{let o=r(),i=s(e=>e.changeSwatches),{swatches:n}=a(),{data:p}=e(["/query/productOptionName",{}],async()=>fetchProductValueLabel(o),{revalidateOnMount:!0}),c=[];if(n?.forEach(e=>{c.push(e.optionTitle)}),p?.productOptionName?.forEach(e=>{c.includes(e)||(swatchChange=!0,n?.push({optionTitle:e,optionType:"rectangle_list",optionValues:[]}))}),!t)return[];setDefaultSwatches(n,t),l()&&n?.length&&(swatchChange||colorChange)&&(window?.parent?.postMessage?.(JSON.stringify({type:"update-swatches",swatches:n}),"*"),i(n))},getColorDefault=(e,t)=>{let a=e?o[e.toLocaleLowerCase()]:void 0,r=a?[a]:[],s=t?.[0];return!s&&r.length&&(colorChange=!0),s?[s]:r},getProductOptionsLabelByName=(e,t)=>{let o=[],a=e.find(e=>e.name===t);return a?.values.forEach(e=>{o.push(e.label??"")}),o},getSwatchesOptionsLabel=e=>{let t=[];return e.forEach(e=>{t.push(e.label??"")}),t},setDefaultSwatches=(e,t)=>(e&&e?.map(e=>{let o=getProductOptionsLabelByName(t,e.optionTitle),a=getSwatchesOptionsLabel(e.optionValues);o.forEach(t=>{a.includes(t)||e.optionValues.push({label:t,colors:getColorDefault(t),imageUrl:""})}),e.optionValues=e.optionValues.map(e=>(void 0===e.imageUrl&&(swatchChange=!0),{label:e.label??"",colors:getColorDefault(e.label,e.colors),imageUrl:e.imageUrl??""}))}),e),fetchProductValueLabel=async e=>{let o={},a=async o=>{let a=await e([t,o]);return a};return a(o)};export{useInitialSwatchesOptions as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/core",
3
- "version": "2.0.0-dev.849",
3
+ "version": "2.0.0-dev.852",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",