@gem-sdk/core 1.14.0-dev.312 → 1.14.0-dev.315
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 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.map(e=>({
|
|
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 +1 @@
|
|
|
1
|
-
import e from"swr";import{ProductOptionNameDocument as t}from"../graphql/queries/product-value-label.generated.js";import{colorPreset as
|
|
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};
|