@gem-sdk/core 2.0.0-dev.850 → 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 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 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.850",
3
+ "version": "2.0.0-dev.852",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",