@dropins/storefront-pdp 1.3.1-alpha101 → 1.3.1-alpha103
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,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as d}from"@dropins/tools/preact-jsx-runtime.js";import{useState as h,useEffect as z,useCallback as j}from"@dropins/tools/preact-compat.js";import{Slot as C}from"@dropins/tools/lib.js";import{events as S}from"@dropins/tools/event-bus.js";import"@dropins/tools/components.js";/* empty css */import{S as A}from"../chunks/Swatches.js";import"@dropins/tools/preact.js";import{c as v,o as G,k as O,j as b,h as H,l as y,p as J}from"../chunks/isProductConfigurationValid.js";import{g as K}from"../chunks/getFetchedProductData.js";import"@dropins/tools/i18n.js";import"../fragments.js";import"@dropins/tools/fetch-graphql.js";const Q=({initialData:
|
|
3
|
+
import{jsx as d}from"@dropins/tools/preact-jsx-runtime.js";import{useState as h,useEffect as z,useCallback as j}from"@dropins/tools/preact-compat.js";import{Slot as C}from"@dropins/tools/lib.js";import{events as S}from"@dropins/tools/event-bus.js";import"@dropins/tools/components.js";/* empty css */import{S as A}from"../chunks/Swatches.js";import"@dropins/tools/preact.js";import{c as v,o as G,k as O,j as b,h as H,l as y,p as J}from"../chunks/isProductConfigurationValid.js";import{g as K}from"../chunks/getFetchedProductData.js";import"@dropins/tools/i18n.js";import"../fragments.js";import"@dropins/tools/fetch-graphql.js";const Q=({initialData:c={data:null,optionsUIDs:[]},scope:i,hideSelectedValue:p=!1,slots:n,onValues:u,onErrors:l,children:V,...B})=>{var I;const[t,T]=h(c.data),[m,F]=h(c.optionsUIDs),[M,L]=h();z(()=>{const a=S.on("pdp/data",T,{scope:i}),s=S.on("pdp/values",({optionsUIDs:f})=>{f&&F(f)},{scope:i});return()=>{a==null||a.off(),s==null||s.off()}},[]);const N=j(async a=>{var U,w,D,k;if(!(t!=null&&t.sku))return;const{persistURLParams:s,anchors:f,acdl:q}=v.getConfig()??{};let o=Object.keys(a).map(r=>a[r].value).filter(r=>r!==void 0);s&&!(t!=null&&t.isBundle)&&G({optionsUIDs:o.join(",")}),((w=(U=O({scope:i}))==null?void 0:U.optionsUIDs)==null?void 0:w.join("|"))!==(o==null?void 0:o.join("|"))&&b(r=>({...r,optionsUIDs:o}),{scope:i}),u==null||u(o);const e=await H(t.sku,{optionsUIDs:o??[],isBundle:t==null?void 0:t.isBundle,anchors:f});S.emit("pdp/data",e,{scope:i});let P=(o==null?void 0:o.length)===((D=e==null?void 0:e.options)==null?void 0:D.length);if(f!=null&&f.length){const r=(e==null?void 0:e.optionUIDs)??[];o.every(g=>r.includes(g))||(L(e==null?void 0:e.options),b(g=>({...g,optionsUIDs:r}),{scope:i}),P=(r==null?void 0:r.length)===((k=e==null?void 0:e.options)==null?void 0:k.length))}y(()=>P,{scope:i}),q&&e&&(e==null?void 0:e.variantSku)!==t.sku&&J(e)},[t==null?void 0:t.isBundle,t==null?void 0:t.sku,u,i]),R=j(a=>{Object.keys(a).length!==0&&(y(()=>!1,{scope:i}),l==null||l(a))},[l,i]);return!t||!t.options?null:d(C,{name:"Swatches",slot:n==null?void 0:n.Swatches,context:{data:t,optionsUIDs:m},children:d(A,{...B,options:t.options,selectedUIDs:m,defaultOptions:m,selectionsToUpdate:M,hideSelectedValue:p,disablePreselections:!((I=v.getConfig())!=null&&I.preselectFirstOption),onValues:N,onErrors:R,imageSwatchNode:n!=null&&n.SwatchImage?({imageSwatchContext:a,...s})=>d(C,{name:"SwatchImage",slot:n==null?void 0:n.SwatchImage,slotTag:"span",contentTag:"span",context:{data:t,optionsUIDs:m,defaultImageProps:s,imageSwatchContext:a}}):void 0})})};Q.getInitialData=async function(c){var n;const i=await K({scope:c==null?void 0:c.scope}),p=((n=O({scope:c==null?void 0:c.scope}))==null?void 0:n.optionsUIDs)??[];return{data:i,optionsUIDs:p}};export{Q as ProductOptions,Q as default};
|
|
4
4
|
//# sourceMappingURL=ProductOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductOptions.js","sources":["/@dropins/storefront-pdp/src/containers/ProductOptions/ProductOptions.tsx"],"sourcesContent":["/**\n * ADOBE CONFIDENTIAL\n * __________________\n * Copyright 2024 Adobe\n * All Rights Reserved.\n * __________________\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n */\n\nimport {\n HTMLAttributes,\n useCallback,\n useEffect,\n useState,\n} from 'preact/compat';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { ProductModel } from '@/pdp/data/models';\nimport { events } from '@adobe-commerce/event-bus';\nimport { Swatches } from '@/pdp/components';\nimport {\n setProductConfigurationValues,\n getProductConfigurationValues,\n setProductConfigurationValid,\n fetchProductData,\n getFetchedProductData,\n config,\n} from '@/pdp/api';\nimport { setUrlParams } from '@/pdp/lib/url-params';\nimport { publishProductPageViewEvent } from '@/pdp/lib/acdl';\nimport {\n ImageNodeRenderProps,\n ImageProps,\n} from '@adobe-commerce/elsie/components';\n\nexport interface ProductOptionsProps extends HTMLAttributes<HTMLDivElement> {\n scope?: string;\n hideSelectedValue?: boolean;\n onValues?: (optionsUIDs: string[]) => void;\n onErrors?: (errors: { [id: string]: string }) => void;\n slots?: {\n Swatches?: SlotProps<{ data: ProductModel | null; optionsUIDs: string[] }>;\n SwatchImage?: SlotProps<{\n data: ProductModel | null;\n optionsUIDs: string[];\n imageSwatchContext: ImageNodeRenderProps['imageSwatchContext'];\n defaultImageProps: ImageProps;\n }>;\n };\n}\n\nexport const ProductOptions: Container<\n ProductOptionsProps,\n { data: ProductModel | null; optionsUIDs: string[] }\n> = ({\n initialData = { data: null, optionsUIDs: [] },\n scope,\n hideSelectedValue = false,\n slots,\n onValues,\n onErrors,\n children,\n ...props\n}) => {\n const [data, setData] = useState<ProductModel | null>(initialData.data);\n\n const [current, setCurrent] = useState<string[]>(initialData.optionsUIDs);\n\n const [selectionsToUpdate, setSelectionsToUpdate] =\n useState<ProductModel['options']>();\n\n useEffect(() => {\n const dataEvent = events.on('pdp/data', setData, { scope });\n\n const valuesEvent = events.on(\n 'pdp/values',\n ({ optionsUIDs }) => {\n if (optionsUIDs) {\n setCurrent(optionsUIDs);\n }\n },\n { scope }\n );\n\n return () => {\n dataEvent?.off();\n valuesEvent?.off();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleOptionSelected = useCallback(\n async (selections: { [id: string]: { label: string; value: string } }) => {\n if (!data?.sku) return;\n\n const { persistURLParams, anchors, acdl } = config.getConfig() ?? {};\n\n // options selected\n let optionsUIDs = Object.keys(selections)\n .map((id) => selections[id].value)\n .filter((element) => element !== undefined);\n\n // set optionUIDs to URL params\n // ?optionsUIDs=1,2,3\n // only set the URL params if the \"persistURLParams\" is set to true and the product is not a bundle type\n if (persistURLParams && !data?.isBundle) {\n setUrlParams({ optionsUIDs: optionsUIDs.join(',') });\n }\n\n // check if the options have changed\n if (\n getProductConfigurationValues({ scope })?.optionsUIDs?.join('|') !==\n optionsUIDs?.join('|')\n ) {\n // update values\n setProductConfigurationValues((prev) => ({ ...prev, optionsUIDs }), {\n scope,\n });\n\n // pass the selected options to callback\n onValues?.(optionsUIDs);\n\n // refetch data\n const next = await fetchProductData(data.sku, {\n optionsUIDs: optionsUIDs ?? [],\n isBundle: data?.isBundle,\n anchors,\n });\n\n // emit the new data\n events.emit('pdp/data', next, { scope });\n\n let valid = optionsUIDs?.length === next?.options?.length;\n\n // special processing for anchor options (options that should not be refined when other options are selected)\n if (anchors?.length) {\n const updatedOptionsUIDs = next?.optionUIDs ?? [];\n\n const isMatching = optionsUIDs.every((item) =>\n updatedOptionsUIDs.includes(item)\n );\n\n if (!isMatching) {\n setSelectionsToUpdate(next?.options);\n setProductConfigurationValues(\n (prev) => ({\n ...prev,\n optionsUIDs: updatedOptionsUIDs,\n }),\n { scope }\n );\n\n valid = updatedOptionsUIDs?.length === next?.options?.length;\n }\n }\n\n // is the product valid\n setProductConfigurationValid(() => valid, { scope });\n\n // ACDL\n if (acdl && next && next?.variantSku !== data.sku) {\n publishProductPageViewEvent(next);\n }\n }\n },\n [data?.isBundle, data?.sku, onValues, scope]\n );\n\n const handleErrors = useCallback(\n (errors: { [id: string]: string }) => {\n const hasErrors = Object.keys(errors).length !== 0;\n\n if (hasErrors) {\n setProductConfigurationValid(() => false, { scope });\n onErrors?.(errors);\n }\n },\n [onErrors, scope]\n );\n\n if (!data) return null;\n\n // Only show if there are options in the data\n if (!data.options) return null;\n\n return (\n <Slot\n name=\"Swatches\"\n slot={slots?.Swatches}\n context={{ data, optionsUIDs: current }}\n >\n <Swatches\n {...props}\n options={data.options}\n selectedUIDs={current}\n defaultOptions={current}\n selectionsToUpdate={selectionsToUpdate}\n hideSelectedValue={hideSelectedValue}\n disablePreselections={!config.getConfig()?.preselectFirstOption}\n onValues={handleOptionSelected}\n onErrors={handleErrors}\n imageSwatchNode={\n slots?.SwatchImage\n ? ({ imageSwatchContext, ...imageProps }) => (\n <Slot\n name=\"SwatchImage\"\n slot={slots?.SwatchImage}\n slotTag=\"span\"\n contentTag=\"span\"\n context={{\n data,\n optionsUIDs: current,\n defaultImageProps: imageProps,\n imageSwatchContext,\n }}\n />\n )\n : undefined\n }\n />\n </Slot>\n );\n};\n\nProductOptions.getInitialData = async function (options) {\n const data = await getFetchedProductData({ scope: options?.scope });\n const optionsUIDs =\n getProductConfigurationValues({ scope: options?.scope })?.optionsUIDs ?? [];\n return { data, optionsUIDs };\n};\n"],"names":["ProductOptions","initialData","scope","hideSelectedValue","slots","onValues","onErrors","children","props","data","setData","useState","current","setCurrent","selectionsToUpdate","setSelectionsToUpdate","useEffect","dataEvent","events","valuesEvent","optionsUIDs","handleOptionSelected","useCallback","selections","persistURLParams","anchors","acdl","config","id","element","setUrlParams","_b","_a","getProductConfigurationValues","setProductConfigurationValues","prev","next","fetchProductData","valid","_c","updatedOptionsUIDs","item","_d","setProductConfigurationValid","publishProductPageViewEvent","handleErrors","errors","jsx","Slot","Swatches","imageSwatchContext","imageProps","options","getFetchedProductData"],"mappings":"goBAyDO,MAAMA,EAGT,CAAC,CACH,YAAAC,EAAc,CAAE,KAAM,KAAM,YAAa,CAAA,CAAG,EAC5C,MAAAC,EACA,kBAAAC,EAAoB,GACpB,MAAAC,EACA,SAAAC,EACA,SAAAC,EACA,SAAAC,EACA,GAAGC,CACL,IAAM,OACJ,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAA8BV,EAAY,IAAI,EAEhE,CAACW,EAASC,CAAU,EAAIF,EAAmBV,EAAY,WAAW,EAElE,CAACa,EAAoBC,CAAqB,EAC9CJ,EAAkC,EAEpCK,EAAU,IAAM,CACd,MAAMC,EAAYC,EAAO,GAAG,WAAYR,EAAS,CAAE,MAAAR,EAAO,EAEpDiB,EAAcD,EAAO,GACzB,aACA,CAAC,CAAE,YAAAE,CAAA,IAAkB,CACfA,GACFP,EAAWO,CAAW,CAE1B,EACA,CAAE,MAAAlB,CAAM,CACV,EAEA,MAAO,IAAM,CACXe,GAAA,MAAAA,EAAW,MACXE,GAAA,MAAAA,EAAa,KACf,CAEF,EAAG,EAAE,EAEL,MAAME,EAAuBC,EAC3B,MAAOC,GAAmE,aACpE,GAAA,EAACd,GAAA,MAAAA,EAAM,KAAK,OAEV,KAAA,CAAE,iBAAAe,EAAkB,QAAAC,EAAS,KAAAC,GAASC,EAAO,UAAA,GAAe,CAAC,EAGnE,IAAIP,EAAc,OAAO,KAAKG,CAAU,EACrC,IAAKK,GAAOL,EAAWK,CAAE,EAAE,KAAK,EAChC,OAAQC,GAAYA,IAAY,MAAS,EAU5C,GALIL,GAAoB,EAACf,GAAA,MAAAA,EAAM,WAC7BqB,EAAa,CAAE,YAAa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,SAAW,IAG/CH,EAA6B,IAAM,GAAO,CAAE,MAAAzC,EAAO,EACnDI,GAAA,MAAAA,EAAWwC,GAEf,EACA,CAACxC,EAAUJ,CAAK,CAClB,EAKI,MAHA,CAACO,GAGD,CAACA,EAAK,QAAgB,KAGxBsC,EAACC,EAAA,CACC,KAAK,WACL,KAAM5C,GAAA,YAAAA,EAAO,SACb,QAAS,CAAE,KAAAK,EAAM,YAAaG,CAAQ,EAEtC,SAAAmC,EAACE,EAAA,CACE,GAAGzC,EACJ,QAASC,EAAK,QACd,aAAcG,EACd,eAAgBA,EAChB,mBAAAE,EACA,kBAAAX,EACA,qBAAsB,GAAC6B,EAAAL,EAAO,UAAA,IAAP,MAAAK,EAAoB,sBAC3C,SAAUX,EACV,SAAUwB,EACV,gBACEzC,GAAA,MAAAA,EAAO,YACH,CAAC,CAAE,mBAAA8C,EAAoB,GAAGC,KACxBJ,EAACC,EAAA,CACC,KAAK,cACL,KAAM5C,GAAA,YAAAA,EAAO,YACb,QAAQ,OACR,WAAW,OACX,QAAS,CACP,KAAAK,EACA,YAAaG,EACb,kBAAmBuC,EACnB,mBAAAD,CAAA,CACF,CAAA,EAGJ,MAAA,CAAA,CAER,CACF,CAEJ,EAEAlD,EAAe,eAAiB,eAAgBoD,EAAS,OACvD,MAAM3C,EAAO,MAAM4C,EAAsB,CAAE,MAAOD,GAAA,YAAAA,EAAS,MAAO,EAC5DhC,IACJY,EAAAC,EAA8B,CAAE,MAAOmB,GAAA,YAAAA,EAAS,KAAO,CAAA,IAAvD,YAAApB,EAA0D,cAAe,CAAC,EACrE,MAAA,CAAE,KAAAvB,EAAM,YAAAW,CAAY,CAC7B"}
|
|
1
|
+
{"version":3,"file":"ProductOptions.js","sources":["/@dropins/storefront-pdp/src/containers/ProductOptions/ProductOptions.tsx"],"sourcesContent":["/**\n * ADOBE CONFIDENTIAL\n * __________________\n * Copyright 2024 Adobe\n * All Rights Reserved.\n * __________________\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n */\n\nimport {\n HTMLAttributes,\n useCallback,\n useEffect,\n useState,\n} from 'preact/compat';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { ProductModel } from '@/pdp/data/models';\nimport { events } from '@adobe-commerce/event-bus';\nimport { Swatches } from '@/pdp/components';\nimport {\n setProductConfigurationValues,\n getProductConfigurationValues,\n setProductConfigurationValid,\n fetchProductData,\n getFetchedProductData,\n config,\n} from '@/pdp/api';\nimport { setUrlParams } from '@/pdp/lib/url-params';\nimport { publishProductPageViewEvent } from '@/pdp/lib/acdl';\nimport {\n ImageNodeRenderProps,\n ImageProps,\n} from '@adobe-commerce/elsie/components';\n\nexport interface ProductOptionsProps extends HTMLAttributes<HTMLDivElement> {\n scope?: string;\n hideSelectedValue?: boolean;\n onValues?: (optionsUIDs: string[]) => void;\n onErrors?: (errors: { [id: string]: string }) => void;\n slots?: {\n Swatches?: SlotProps<{ data: ProductModel | null; optionsUIDs: string[] }>;\n SwatchImage?: SlotProps<{\n data: ProductModel | null;\n optionsUIDs: string[];\n imageSwatchContext: ImageNodeRenderProps['imageSwatchContext'];\n defaultImageProps: ImageProps;\n }>;\n };\n}\n\nexport const ProductOptions: Container<\n ProductOptionsProps,\n { data: ProductModel | null; optionsUIDs: string[] }\n> = ({\n initialData = { data: null, optionsUIDs: [] },\n scope,\n hideSelectedValue = false,\n slots,\n onValues,\n onErrors,\n children,\n ...props\n}) => {\n const [data, setData] = useState<ProductModel | null>(initialData.data);\n\n const [current, setCurrent] = useState<string[]>(initialData.optionsUIDs);\n\n const [selectionsToUpdate, setSelectionsToUpdate] =\n useState<ProductModel['options']>();\n\n useEffect(() => {\n const dataEvent = events.on('pdp/data', setData, { scope });\n\n const valuesEvent = events.on(\n 'pdp/values',\n ({ optionsUIDs }) => {\n if (optionsUIDs) {\n setCurrent(optionsUIDs);\n }\n },\n { scope }\n );\n\n return () => {\n dataEvent?.off();\n valuesEvent?.off();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleOptionSelected = useCallback(\n async (selections: { [id: string]: { label: string; value: string } }) => {\n if (!data?.sku) return;\n\n const { persistURLParams, anchors, acdl } = config.getConfig() ?? {};\n\n // options selected\n let optionsUIDs = Object.keys(selections)\n .map((id) => selections[id].value)\n .filter((element) => element !== undefined);\n\n // set optionUIDs to URL params\n // ?optionsUIDs=1,2,3\n // only set the URL params if the \"persistURLParams\" is set to true and the product is not a bundle type\n if (persistURLParams && !data?.isBundle) {\n setUrlParams({ optionsUIDs: optionsUIDs.join(',') });\n }\n\n // check if the options have changed and update the values only if they have changed\n if (\n getProductConfigurationValues({ scope })?.optionsUIDs?.join('|') !==\n optionsUIDs?.join('|')\n ) {\n // update values\n setProductConfigurationValues((prev) => ({ ...prev, optionsUIDs }), {\n scope,\n });\n }\n\n // pass the selected options to callback\n onValues?.(optionsUIDs);\n\n // refetch data\n const next = await fetchProductData(data.sku, {\n optionsUIDs: optionsUIDs ?? [],\n isBundle: data?.isBundle,\n anchors,\n });\n\n // emit the new data\n events.emit('pdp/data', next, { scope });\n\n let valid = optionsUIDs?.length === next?.options?.length;\n\n // special processing for anchor options (options that should not be refined when other options are selected)\n if (anchors?.length) {\n const updatedOptionsUIDs = next?.optionUIDs ?? [];\n\n const isMatching = optionsUIDs.every((item) =>\n updatedOptionsUIDs.includes(item)\n );\n\n if (!isMatching) {\n setSelectionsToUpdate(next?.options);\n setProductConfigurationValues(\n (prev) => ({\n ...prev,\n optionsUIDs: updatedOptionsUIDs,\n }),\n { scope }\n );\n\n valid = updatedOptionsUIDs?.length === next?.options?.length;\n }\n }\n\n // is the product valid\n setProductConfigurationValid(() => valid, { scope });\n\n // ACDL\n if (acdl && next && next?.variantSku !== data.sku) {\n publishProductPageViewEvent(next);\n }\n },\n [data?.isBundle, data?.sku, onValues, scope]\n );\n\n const handleErrors = useCallback(\n (errors: { [id: string]: string }) => {\n const hasErrors = Object.keys(errors).length !== 0;\n\n if (hasErrors) {\n setProductConfigurationValid(() => false, { scope });\n onErrors?.(errors);\n }\n },\n [onErrors, scope]\n );\n\n if (!data) return null;\n\n // Only show if there are options in the data\n if (!data.options) return null;\n\n return (\n <Slot\n name=\"Swatches\"\n slot={slots?.Swatches}\n context={{ data, optionsUIDs: current }}\n >\n <Swatches\n {...props}\n options={data.options}\n selectedUIDs={current}\n defaultOptions={current}\n selectionsToUpdate={selectionsToUpdate}\n hideSelectedValue={hideSelectedValue}\n disablePreselections={!config.getConfig()?.preselectFirstOption}\n onValues={handleOptionSelected}\n onErrors={handleErrors}\n imageSwatchNode={\n slots?.SwatchImage\n ? ({ imageSwatchContext, ...imageProps }) => (\n <Slot\n name=\"SwatchImage\"\n slot={slots?.SwatchImage}\n slotTag=\"span\"\n contentTag=\"span\"\n context={{\n data,\n optionsUIDs: current,\n defaultImageProps: imageProps,\n imageSwatchContext,\n }}\n />\n )\n : undefined\n }\n />\n </Slot>\n );\n};\n\nProductOptions.getInitialData = async function (options) {\n const data = await getFetchedProductData({ scope: options?.scope });\n const optionsUIDs =\n getProductConfigurationValues({ scope: options?.scope })?.optionsUIDs ?? [];\n return { data, optionsUIDs };\n};\n"],"names":["ProductOptions","initialData","scope","hideSelectedValue","slots","onValues","onErrors","children","props","data","setData","useState","current","setCurrent","selectionsToUpdate","setSelectionsToUpdate","useEffect","dataEvent","events","valuesEvent","optionsUIDs","handleOptionSelected","useCallback","selections","persistURLParams","anchors","acdl","config","id","element","setUrlParams","_b","_a","getProductConfigurationValues","setProductConfigurationValues","prev","next","fetchProductData","valid","_c","updatedOptionsUIDs","item","_d","setProductConfigurationValid","publishProductPageViewEvent","handleErrors","errors","jsx","Slot","Swatches","imageSwatchContext","imageProps","options","getFetchedProductData"],"mappings":"goBAyDO,MAAMA,E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EAAM,YAAaG,CAAQ,EAEtC,SAAAmC,EAACE,EAAA,CACE,GAAGzC,EACJ,QAASC,EAAK,QACd,aAAcG,EACd,eAAgBA,EAChB,mBAAAE,EACA,kBAAAX,EACA,qBAAsB,GAAC6B,EAAAL,EAAO,UAAA,IAAP,MAAAK,EAAoB,sBAC3C,SAAUX,EACV,SAAUwB,EACV,gBACEzC,GAAA,MAAAA,EAAO,YACH,CAAC,CAAE,mBAAA8C,EAAoB,GAAGC,KACxBJ,EAACC,EAAA,CACC,KAAK,cACL,KAAM5C,GAAA,YAAAA,EAAO,YACb,QAAQ,OACR,WAAW,OACX,QAAS,CACP,KAAAK,EACA,YAAaG,EACb,kBAAmBuC,EACnB,mBAAAD,CAAA,CACF,CAAA,EAGJ,MAAA,CAAA,CAER,CACF,CAEJ,EAEAlD,EAAe,eAAiB,eAAgBoD,EAAS,OACvD,MAAM3C,EAAO,MAAM4C,EAAsB,CAAE,MAAOD,GAAA,YAAAA,EAAS,MAAO,EAC5DhC,IACJY,EAAAC,EAA8B,CAAE,MAAOmB,GAAA,YAAAA,EAAS,KAAO,CAAA,IAAvD,YAAApB,EAA0D,cAAe,CAAC,EACrE,MAAA,CAAE,KAAAvB,EAAM,YAAAW,CAAY,CAC7B"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-pdp", "version": "1.3.1-
|
|
1
|
+
{"name": "@dropins/storefront-pdp", "version": "1.3.1-alpha103", "@dropins/tools": "1.4.1-alpha102", "license": "SEE LICENSE IN LICENSE.md"}
|