@brytdesigns/shopify-product-info-components 1.1.9 → 3.0.0

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,69 +1,48 @@
1
- import { createContext, provide, consume } from 'component-register';
2
- import { splitProps, mergeProps, untrack } from 'solid-js';
3
- import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
4
-
1
+ import { createRemoteContext, getContextFromProvider } from "@brytdesigns/web-component-core/utils";
2
+ import { merge, omit, untrack } from "solid-js";
3
+ import { consume, createContext, provide } from "component-register";
4
+ //#region src/hooks/useProduct.ts
5
5
  function initializeProductContext(props) {
6
- const [privateProps, publicProps] = splitProps(props, ["root"]);
7
- const state = mergeProps(publicProps, {});
8
- function updateSelectedVariant(variantId) {
9
- const product = untrack(() => state?.product);
10
- if (typeof product?.selected_or_first_available_variant === "undefined" || typeof product === "undefined" || typeof product?.variants === "undefined")
11
- return;
12
- const newVariant = product.variants.find(
13
- (variant) => variant?.id?.toString() === variantId.toString()
14
- );
15
- if (newVariant?.id?.toString() === product.selected_or_first_available_variant?.id?.toString())
16
- return;
17
- const newState = {
18
- ...product,
19
- selected_or_first_available_variant: newVariant
20
- };
21
- privateProps.root.setAttribute("product", JSON.stringify(newState));
22
- privateProps.root.dispatchEvent(
23
- new CustomEvent("variant-updated", {
24
- detail: {
25
- variant: newVariant,
26
- product: newState
27
- },
28
- bubbles: true
29
- })
30
- );
31
- }
32
- return [
33
- state,
34
- {
35
- variant: {
36
- update: updateSelectedVariant
37
- }
38
- }
39
- ];
6
+ const publicProps = omit(props, "root");
7
+ const state = merge(publicProps, {});
8
+ function updateSelectedVariant(variantId) {
9
+ const product = untrack(() => state?.product);
10
+ if (typeof product?.selected_or_first_available_variant === "undefined" || typeof product === "undefined" || typeof product?.variants === "undefined") return;
11
+ const newVariant = product.variants.find((variant) => variant?.id?.toString() === variantId.toString());
12
+ if (newVariant?.id?.toString() === product.selected_or_first_available_variant?.id?.toString()) return;
13
+ const newState = {
14
+ ...product,
15
+ selected_or_first_available_variant: newVariant
16
+ };
17
+ props.root.setAttribute("product", JSON.stringify(newState));
18
+ props.root.dispatchEvent(new CustomEvent("variant-updated", {
19
+ detail: {
20
+ variant: newVariant,
21
+ product: newState
22
+ },
23
+ bubbles: true
24
+ }));
25
+ }
26
+ return [state, { variant: { update: updateSelectedVariant } }];
40
27
  }
41
- const ProductContextState = createContext(initializeProductContext);
42
- const provideProductContext = (initialState, element) => {
43
- const props = mergeProps(initialState, { root: element });
44
- return provide(ProductContextState, props, element);
28
+ var ProductContextState = createContext(initializeProductContext);
29
+ var provideProductContext = (initialState, element) => {
30
+ const props = merge(initialState, { root: element });
31
+ return provide(ProductContextState, props, element);
45
32
  };
46
- const useProductContext = (context) => {
47
- return context;
33
+ var useProductContext = (context) => {
34
+ return context;
48
35
  };
49
- const useProduct = (element) => {
50
- const context = consume(ProductContextState, element);
51
- if (!context) {
52
- throw console.error(
53
- "ProductInfoContext not found! Please ensure to wrap your custom element with product-info element."
54
- );
55
- }
56
- return useProductContext(context);
36
+ var useProduct = (element) => {
37
+ const context = consume(ProductContextState, element);
38
+ if (!context) throw new Error("ProductInfoContext not found! Please ensure to wrap your custom element with product-info element.");
39
+ return useProductContext(context);
57
40
  };
58
- const getProductContext = (element) => {
59
- const context = getContextFromProvider(
60
- ProductContextState,
61
- element
62
- );
63
- return useProductContext(context);
41
+ var getProductContext = (element) => {
42
+ return useProductContext(getContextFromProvider(ProductContextState, element));
64
43
  };
65
- const withProductElementContext = createWithElementContext(ProductContextState);
44
+ var useProductAt = createRemoteContext(ProductContextState);
45
+ //#endregion
46
+ export { getProductContext, provideProductContext, useProduct, useProductAt, useProductContext };
66
47
 
67
- export { getProductContext, provideProductContext, useProduct, useProductContext, withProductElementContext };
68
- //# sourceMappingURL=useProduct.js.map
69
48
  //# sourceMappingURL=useProduct.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useProduct.ts"],"names":[],"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EA,MAAM,mBAAA,GAAsB,cAAc,wBAAwB,CAAA;AAErD,MAAA,qBAAA,GAAwB,CACnC,YAAA,EACA,OACmB,KAAA;AACnB,EAAA,MAAM,QAAQ,UAAW,CAAA,YAAA,EAAc,EAAE,IAAA,EAAM,SAAS,CAAA;AACxD,EAAO,OAAA,OAAA,CAAQ,mBAAqB,EAAA,KAAA,EAAO,OAAO,CAAA;AACpD;AAEa,MAAA,iBAAA,GAAoB,CAAC,OAA4B,KAAA;AAC5D,EAAO,OAAA,OAAA;AACT;AAEa,MAAA,UAAA,GAAa,CAAC,OAA0C,KAAA;AACnE,EAAM,MAAA,OAAA,GAA0B,OAAQ,CAAA,mBAAA,EAAqB,OAAO,CAAA;AAEpE,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAA,MAAM,OAAQ,CAAA,KAAA;AAAA,MACZ;AAAA,KACF;AAAA;AAGF,EAAA,OAAO,kBAAkB,OAAO,CAAA;AAClC;AAEa,MAAA,iBAAA,GAAoB,CAAC,OAAqB,KAAA;AACrD,EAAA,MAAM,OAAU,GAAA,sBAAA;AAAA,IACd,mBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,kBAAkB,OAAO,CAAA;AAClC;AAEa,MAAA,yBAAA,GAA4B,yBAGvC,mBAAmB","file":"useProduct.js","sourcesContent":["import {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport { mergeProps, splitProps, untrack } from \"solid-js\";\nimport {\n getContextFromProvider,\n createWithElementContext,\n} from \"@brytdesigns/web-component-core/utils\";\n\nimport type { Product } from \"../types\";\n\ntype CreateContextOptions = {\n root: HTMLElement & ICustomElement;\n product: Product;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ProductContext = ReturnType<typeof initializeProductContext>;\n\nfunction initializeProductContext(props: CreateContextOptions) {\n const [privateProps, publicProps] = splitProps(props, [\"root\"]);\n const state = mergeProps(publicProps, {});\n\n function updateSelectedVariant(variantId: string | number) {\n const product = untrack(() => state?.product);\n if (\n typeof product?.selected_or_first_available_variant === \"undefined\" ||\n typeof product === \"undefined\" ||\n typeof product?.variants === \"undefined\"\n )\n return;\n const newVariant = product.variants.find(\n (variant) => variant?.id?.toString() === variantId.toString(),\n );\n\n if (\n newVariant?.id?.toString() ===\n product.selected_or_first_available_variant?.id?.toString()\n )\n return;\n\n const newState = {\n ...product,\n selected_or_first_available_variant: newVariant,\n };\n\n privateProps.root.setAttribute(\"product\", JSON.stringify(newState));\n\n privateProps.root.dispatchEvent(\n new CustomEvent(\"variant-updated\", {\n detail: {\n variant: newVariant,\n product: newState,\n },\n bubbles: true,\n }),\n );\n }\n\n return [\n state,\n {\n variant: {\n update: updateSelectedVariant,\n },\n },\n ] as const;\n}\n\nconst ProductContextState = createContext(initializeProductContext);\n\nexport const provideProductContext = (\n initialState: Omit<CreateContextOptions, \"root\">,\n element: WalkableNode,\n): ProductContext => {\n const props = mergeProps(initialState, { root: element });\n return provide(ProductContextState, props, element);\n};\n\nexport const useProductContext = (context: ProductContext) => {\n return context;\n};\n\nexport const useProduct = (element: HTMLElement & ICustomElement) => {\n const context: ProductContext = consume(ProductContextState, element);\n\n if (!context) {\n throw console.error(\n \"ProductInfoContext not found! Please ensure to wrap your custom element with product-info element.\",\n );\n }\n\n return useProductContext(context);\n};\n\nexport const getProductContext = (element: Element) => {\n const context = getContextFromProvider<ProductContext>(\n ProductContextState,\n element,\n );\n return useProductContext(context);\n};\n\nexport const withProductElementContext = createWithElementContext<\n typeof ProductContextState,\n ProductContext\n>(ProductContextState);\n"]}
1
+ {"version":3,"file":"useProduct.js","names":[],"sources":["../../../src/hooks/useProduct.ts"],"sourcesContent":["import {\n\tcreateRemoteContext,\n\tgetContextFromProvider,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n\tconsume,\n\tcreateContext,\n\ttype ICustomElement,\n\tprovide,\n} from \"component-register\";\nimport { merge, omit, untrack } from \"solid-js\";\n\nimport type { Product } from \"../types\";\n\ntype CreateContextOptions = {\n\troot: HTMLElement & ICustomElement;\n\tproduct: Product;\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ProductContext = ReturnType<typeof initializeProductContext>;\n\nfunction initializeProductContext(props: CreateContextOptions) {\n\t// `omit` returns only the rest; `root` is read straight off `props`.\n\tconst publicProps = omit(props, \"root\");\n\tconst state = merge(publicProps, {});\n\n\tfunction updateSelectedVariant(variantId: string | number) {\n\t\tconst product = untrack(() => state?.product);\n\t\tif (\n\t\t\ttypeof product?.selected_or_first_available_variant === \"undefined\" ||\n\t\t\ttypeof product === \"undefined\" ||\n\t\t\ttypeof product?.variants === \"undefined\"\n\t\t)\n\t\t\treturn;\n\t\tconst newVariant = product.variants.find(\n\t\t\t(variant) => variant?.id?.toString() === variantId.toString(),\n\t\t);\n\n\t\tif (\n\t\t\tnewVariant?.id?.toString() ===\n\t\t\tproduct.selected_or_first_available_variant?.id?.toString()\n\t\t)\n\t\t\treturn;\n\n\t\tconst newState = {\n\t\t\t...product,\n\t\t\tselected_or_first_available_variant: newVariant,\n\t\t};\n\n\t\tprops.root.setAttribute(\"product\", JSON.stringify(newState));\n\n\t\tprops.root.dispatchEvent(\n\t\t\tnew CustomEvent(\"variant-updated\", {\n\t\t\t\tdetail: {\n\t\t\t\t\tvariant: newVariant,\n\t\t\t\t\tproduct: newState,\n\t\t\t\t},\n\t\t\t\tbubbles: true,\n\t\t\t}),\n\t\t);\n\t}\n\n\treturn [\n\t\tstate,\n\t\t{\n\t\t\tvariant: {\n\t\t\t\tupdate: updateSelectedVariant,\n\t\t\t},\n\t\t},\n\t] as const;\n}\n\nconst ProductContextState = createContext(initializeProductContext);\n\nexport const provideProductContext = (\n\tinitialState: Omit<CreateContextOptions, \"root\">,\n\telement: WalkableNode,\n): ProductContext => {\n\tconst props = merge(initialState, { root: element });\n\treturn provide(ProductContextState, props, element);\n};\n\nexport const useProductContext = (context: ProductContext) => {\n\treturn context;\n};\n\nexport const useProduct = (element: HTMLElement & ICustomElement) => {\n\tconst context: ProductContext = consume(ProductContextState, element);\n\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"ProductInfoContext not found! Please ensure to wrap your custom element with product-info element.\",\n\t\t);\n\t}\n\n\treturn useProductContext(context);\n};\n\nexport const getProductContext = (element: Element) => {\n\tconst context = getContextFromProvider<ProductContext>(\n\t\tProductContextState,\n\t\telement,\n\t);\n\treturn useProductContext(context);\n};\n\nexport const useProductAt =\n\tcreateRemoteContext<ProductContext>(ProductContextState);\n"],"mappings":";;;;AAuBA,SAAS,yBAAyB,OAA6B;CAE9D,MAAM,cAAc,KAAK,OAAO,MAAM;CACtC,MAAM,QAAQ,MAAM,aAAa,CAAC,CAAC;CAEnC,SAAS,sBAAsB,WAA4B;EAC1D,MAAM,UAAU,cAAc,OAAO,OAAO;EAC5C,IACC,OAAO,SAAS,wCAAwC,eACxD,OAAO,YAAY,eACnB,OAAO,SAAS,aAAa,aAE7B;EACD,MAAM,aAAa,QAAQ,SAAS,MAClC,YAAY,SAAS,IAAI,SAAS,MAAM,UAAU,SAAS,CAC7D;EAEA,IACC,YAAY,IAAI,SAAS,MACzB,QAAQ,qCAAqC,IAAI,SAAS,GAE1D;EAED,MAAM,WAAW;GAChB,GAAG;GACH,qCAAqC;EACtC;EAEA,MAAM,KAAK,aAAa,WAAW,KAAK,UAAU,QAAQ,CAAC;EAE3D,MAAM,KAAK,cACV,IAAI,YAAY,mBAAmB;GAClC,QAAQ;IACP,SAAS;IACT,SAAS;GACV;GACA,SAAS;EACV,CAAC,CACF;CACD;CAEA,OAAO,CACN,OACA,EACC,SAAS,EACR,QAAQ,sBACT,EACD,CACD;AACD;AAEA,IAAM,sBAAsB,cAAc,wBAAwB;AAElE,IAAa,yBACZ,cACA,YACoB;CACpB,MAAM,QAAQ,MAAM,cAAc,EAAE,MAAM,QAAQ,CAAC;CACnD,OAAO,QAAQ,qBAAqB,OAAO,OAAO;AACnD;AAEA,IAAa,qBAAqB,YAA4B;CAC7D,OAAO;AACR;AAEA,IAAa,cAAc,YAA0C;CACpE,MAAM,UAA0B,QAAQ,qBAAqB,OAAO;CAEpE,IAAI,CAAC,SACJ,MAAM,IAAI,MACT,oGACD;CAGD,OAAO,kBAAkB,OAAO;AACjC;AAEA,IAAa,qBAAqB,YAAqB;CAKtD,OAAO,kBAJS,uBACf,qBACA,OAEwB,CAAO;AACjC;AAEA,IAAa,eACZ,oBAAoC,mBAAmB"}
@@ -1,72 +1,51 @@
1
- import { createContext, provide, consume } from 'component-register';
2
- import { splitProps, createEffect, untrack, mergeProps } from 'solid-js';
3
- import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
4
- import { useProduct } from './useProduct.js';
5
-
1
+ import { useProduct } from "./useProduct.js";
2
+ import { createGuardedEffect, createRemoteContext, getContextFromProvider } from "@brytdesigns/web-component-core/utils";
3
+ import { merge, omit, untrack } from "solid-js";
4
+ import { consume, createContext, provide } from "component-register";
5
+ //#region src/hooks/useProductOptions.ts
6
6
  function initializeProductOptionsContext(props) {
7
- const [privateProps, publicProps] = splitProps(props, ["root"]);
8
- const [context, methods] = useProduct(privateProps.root);
9
- function updateSelectedOptions(options) {
10
- privateProps.root.setAttribute("selected-options", JSON.stringify(options));
11
- }
12
- function updateSelectedOption(option, index) {
13
- const current = untrack(() => publicProps.selectedOptions);
14
- const options = [...current];
15
- options[index] = option;
16
- return updateSelectedOptions(options);
17
- }
18
- createEffect(() => {
19
- const variant = context.product.variants.find((variant2) => {
20
- return publicProps.selectedOptions.every(
21
- (option) => variant2.options.includes(option)
22
- );
23
- });
24
- if (!variant) return;
25
- if (variant.id === context.product.selected_or_first_available_variant.id)
26
- return;
27
- methods.variant.update(variant.id);
28
- });
29
- return [
30
- publicProps,
31
- {
32
- options: {
33
- update: updateSelectedOptions,
34
- updateOption: updateSelectedOption
35
- }
36
- }
37
- ];
7
+ const publicProps = omit(props, "root");
8
+ const [context, methods] = useProduct(props.root);
9
+ function updateSelectedOptions(options) {
10
+ props.root.setAttribute("selected-options", JSON.stringify(options));
11
+ }
12
+ function updateSelectedOption(option, index) {
13
+ const options = [...untrack(() => publicProps.selectedOptions)];
14
+ options[index] = option;
15
+ return updateSelectedOptions(options);
16
+ }
17
+ createGuardedEffect(() => {
18
+ const selectedOptions = publicProps.selectedOptions;
19
+ return context.product.variants.find((variant) => selectedOptions.every((option) => variant.options.includes(option)));
20
+ }, (variant) => {
21
+ if (!variant) return;
22
+ const current = untrack(() => context.product.selected_or_first_available_variant.id);
23
+ if (variant.id === current) return;
24
+ methods.variant.update(variant.id);
25
+ });
26
+ return [publicProps, { options: {
27
+ update: updateSelectedOptions,
28
+ updateOption: updateSelectedOption
29
+ } }];
38
30
  }
39
- const ProductOptionsContextState = createContext(
40
- initializeProductOptionsContext
41
- );
42
- const provideProductOptionsContext = (initialState, element) => {
43
- const props = mergeProps(initialState, { root: element });
44
- return provide(ProductOptionsContextState, props, element);
31
+ var ProductOptionsContextState = createContext(initializeProductOptionsContext);
32
+ var provideProductOptionsContext = (initialState, element) => {
33
+ const props = merge(initialState, { root: element });
34
+ return provide(ProductOptionsContextState, props, element);
45
35
  };
46
- const useProductOptionsContext = (context) => {
47
- return context;
36
+ var useProductOptionsContext = (context) => {
37
+ return context;
48
38
  };
49
- const useProductOptions = (element) => {
50
- const context = consume(
51
- ProductOptionsContextState,
52
- element
53
- );
54
- if (!context) {
55
- throw console.error(
56
- "ProductOptionsContext not found! Please ensure to wrap your custom element with product-options element."
57
- );
58
- }
59
- return useProductOptionsContext(context);
39
+ var useProductOptions = (element) => {
40
+ const context = consume(ProductOptionsContextState, element);
41
+ if (!context) throw new Error("ProductOptionsContext not found! Please ensure to wrap your custom element with product-options element.");
42
+ return useProductOptionsContext(context);
60
43
  };
61
- const getProductOptionsContext = (element) => {
62
- const context = getContextFromProvider(
63
- ProductOptionsContextState,
64
- element
65
- );
66
- return useProductOptionsContext(context);
44
+ var getProductOptionsContext = (element) => {
45
+ return useProductOptionsContext(getContextFromProvider(ProductOptionsContextState, element));
67
46
  };
68
- const withProductOptionsElementContext = createWithElementContext(ProductOptionsContextState);
47
+ var useProductOptionsAt = createRemoteContext(ProductOptionsContextState);
48
+ //#endregion
49
+ export { getProductOptionsContext, provideProductOptionsContext, useProductOptions, useProductOptionsAt, useProductOptionsContext };
69
50
 
70
- export { getProductOptionsContext, provideProductOptionsContext, useProductOptions, useProductOptionsContext, withProductOptionsElementContext };
71
- //# sourceMappingURL=useProductOptions.js.map
72
51
  //# sourceMappingURL=useProductOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/useProductOptions.ts"],"names":["variant"],"mappings":";;;;;AAuBA,SAAS,gCAAgC,KAA6B,EAAA;AACpE,EAAM,MAAA,CAAC,cAAc,WAAW,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AAC9D,EAAA,MAAM,CAAC,OAAS,EAAA,OAAO,CAAI,GAAA,UAAA,CAAW,aAAa,IAAI,CAAA;AAEvD,EAAA,SAAS,sBAAsB,OAAmB,EAAA;AAChD,IAAA,YAAA,CAAa,KAAK,YAAa,CAAA,kBAAA,EAAoB,IAAK,CAAA,SAAA,CAAU,OAAO,CAAC,CAAA;AAAA;AAG5E,EAAS,SAAA,oBAAA,CAAqB,QAAgB,KAAe,EAAA;AAC3D,IAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,MAAM,WAAA,CAAY,eAAe,CAAA;AACzD,IAAM,MAAA,OAAA,GAAU,CAAC,GAAG,OAAO,CAAA;AAC3B,IAAA,OAAA,CAAQ,KAAK,CAAI,GAAA,MAAA;AACjB,IAAA,OAAO,sBAAsB,OAAO,CAAA;AAAA;AAGtC,EAAA,YAAA,CAAa,MAAM;AACjB,IAAA,MAAM,UAAU,OAAQ,CAAA,OAAA,CAAQ,QAAS,CAAA,IAAA,CAAK,CAACA,QAAY,KAAA;AACzD,MAAA,OAAO,YAAY,eAAgB,CAAA,KAAA;AAAA,QAAM,CAAC,MAAA,KACxCA,QAAQ,CAAA,OAAA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AAmC,yBAG9C,0BAA0B","file":"useProductOptions.js","sourcesContent":["import {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport { createEffect, mergeProps, splitProps, untrack } from \"solid-js\";\nimport {\n getContextFromProvider,\n createWithElementContext,\n} from \"@brytdesigns/web-component-core/utils\";\n\nimport { useProduct } from \"./useProduct.js\";\n\ntype CreateContextOptions = {\n root: HTMLElement & ICustomElement;\n selectedOptions: string[];\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ProductOptionsContext = ReturnType<typeof initializeProductOptionsContext>;\n\nfunction initializeProductOptionsContext(props: CreateContextOptions) {\n const [privateProps, publicProps] = splitProps(props, [\"root\"]);\n const [context, methods] = useProduct(privateProps.root);\n\n function updateSelectedOptions(options: string[]) {\n privateProps.root.setAttribute(\"selected-options\", JSON.stringify(options));\n }\n\n function updateSelectedOption(option: string, index: number) {\n const current = untrack(() => publicProps.selectedOptions);\n const options = [...current];\n options[index] = option;\n return updateSelectedOptions(options);\n }\n\n createEffect(() => {\n const variant = context.product.variants.find((variant) => {\n return publicProps.selectedOptions.every((option) =>\n variant.options.includes(option),\n );\n });\n if (!variant) return;\n if (variant.id === context.product.selected_or_first_available_variant.id)\n return;\n methods.variant.update(variant.id);\n });\n\n return [\n publicProps,\n {\n options: {\n update: updateSelectedOptions,\n updateOption: updateSelectedOption,\n },\n },\n ] as const;\n}\n\nconst ProductOptionsContextState = createContext(\n initializeProductOptionsContext,\n);\n\nexport const provideProductOptionsContext = (\n initialState: Omit<CreateContextOptions, \"root\">,\n element: WalkableNode,\n): ProductOptionsContext => {\n const props = mergeProps(initialState, { root: element });\n return provide(ProductOptionsContextState, props, element);\n};\n\nexport const useProductOptionsContext = (context: ProductOptionsContext) => {\n return context;\n};\n\nexport const useProductOptions = (element: HTMLElement & ICustomElement) => {\n const context: ProductOptionsContext = consume(\n ProductOptionsContextState,\n element,\n );\n\n if (!context) {\n throw console.error(\n \"ProductOptionsContext not found! Please ensure to wrap your custom element with product-options element.\",\n );\n }\n\n return useProductOptionsContext(context);\n};\n\nexport const getProductOptionsContext = (element: Element) => {\n const context = getContextFromProvider<ProductOptionsContext>(\n ProductOptionsContextState,\n element,\n );\n return useProductOptionsContext(context);\n};\n\nexport const withProductOptionsElementContext = createWithElementContext<\n typeof ProductOptionsContextState,\n ProductOptionsContext\n>(ProductOptionsContextState);\n"]}
1
+ {"version":3,"file":"useProductOptions.js","names":[],"sources":["../../../src/hooks/useProductOptions.ts"],"sourcesContent":["import {\n\tcreateGuardedEffect,\n\tcreateRemoteContext,\n\tgetContextFromProvider,\n} from \"@brytdesigns/web-component-core/utils\";\nimport {\n\tconsume,\n\tcreateContext,\n\ttype ICustomElement,\n\tprovide,\n} from \"component-register\";\nimport { merge, omit, untrack } from \"solid-js\";\n\nimport { useProduct } from \"./useProduct.js\";\n\ntype CreateContextOptions = {\n\troot: HTMLElement & ICustomElement;\n\tselectedOptions: string[];\n};\n\ntype WalkableNode = Parameters<typeof provide>[2];\n\ntype ProductOptionsContext = ReturnType<typeof initializeProductOptionsContext>;\n\nfunction initializeProductOptionsContext(props: CreateContextOptions) {\n\t// `omit` returns only the rest; `root` is read straight off `props`.\n\tconst publicProps = omit(props, \"root\");\n\tconst [context, methods] = useProduct(props.root);\n\n\tfunction updateSelectedOptions(options: string[]) {\n\t\tprops.root.setAttribute(\"selected-options\", JSON.stringify(options));\n\t}\n\n\tfunction updateSelectedOption(option: string, index: number) {\n\t\tconst current = untrack(() => publicProps.selectedOptions);\n\t\tconst options = [...current];\n\t\toptions[index] = option;\n\t\treturn updateSelectedOptions(options);\n\t}\n\n\tcreateGuardedEffect(\n\t\t() => {\n\t\t\tconst selectedOptions = publicProps.selectedOptions;\n\t\t\t// Resolved in the COMPUTE phase. `.find` walks the store's variant\n\t\t\t// array, and walking it here is what subscribes to it — so swapping\n\t\t\t// the product re-resolves the variant. Done from the apply phase, as\n\t\t\t// it was, those reads are untracked: the options were a dependency\n\t\t\t// but the variants were not, and a product replaced underneath this\n\t\t\t// context kept resolving against the previous one's list.\n\t\t\treturn context.product.variants.find((variant) =>\n\t\t\t\tselectedOptions.every((option) => variant.options.includes(option)),\n\t\t\t);\n\t\t},\n\t\t(variant) => {\n\t\t\tif (!variant) return;\n\t\t\t// The currently-selected id is read as a snapshot, deliberately, and\n\t\t\t// must NOT join the dependency list: `methods.variant.update` below\n\t\t\t// is what changes it, so tracking it would re-run this effect on its\n\t\t\t// own result.\n\t\t\tconst current = untrack(\n\t\t\t\t() => context.product.selected_or_first_available_variant.id,\n\t\t\t);\n\t\t\tif (variant.id === current) return;\n\t\t\tmethods.variant.update(variant.id);\n\t\t},\n\t);\n\n\treturn [\n\t\tpublicProps,\n\t\t{\n\t\t\toptions: {\n\t\t\t\tupdate: updateSelectedOptions,\n\t\t\t\tupdateOption: updateSelectedOption,\n\t\t\t},\n\t\t},\n\t] as const;\n}\n\nconst ProductOptionsContextState = createContext(\n\tinitializeProductOptionsContext,\n);\n\nexport const provideProductOptionsContext = (\n\tinitialState: Omit<CreateContextOptions, \"root\">,\n\telement: WalkableNode,\n): ProductOptionsContext => {\n\tconst props = merge(initialState, { root: element });\n\treturn provide(ProductOptionsContextState, props, element);\n};\n\nexport const useProductOptionsContext = (context: ProductOptionsContext) => {\n\treturn context;\n};\n\nexport const useProductOptions = (element: HTMLElement & ICustomElement) => {\n\tconst context: ProductOptionsContext = consume(\n\t\tProductOptionsContextState,\n\t\telement,\n\t);\n\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"ProductOptionsContext not found! Please ensure to wrap your custom element with product-options element.\",\n\t\t);\n\t}\n\n\treturn useProductOptionsContext(context);\n};\n\nexport const getProductOptionsContext = (element: Element) => {\n\tconst context = getContextFromProvider<ProductOptionsContext>(\n\t\tProductOptionsContextState,\n\t\telement,\n\t);\n\treturn useProductOptionsContext(context);\n};\n\nexport const useProductOptionsAt = createRemoteContext<ProductOptionsContext>(\n\tProductOptionsContextState,\n);\n"],"mappings":";;;;;AAwBA,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3
  import { ICustomElement } from 'component-register';
4
4
 
5
+ /**
6
+ * `component-register` types `options.element` as a bare `ICustomElement`, but
7
+ * at runtime it is always also an `HTMLElement`. Every component in this repo
8
+ * needs the DOM half.
9
+ */
5
10
  export type CorrectComponentOptions = {
6
11
  element: HTMLElement & ICustomElement;
7
12
  };
@@ -9,6 +14,13 @@ export type CorrectComponentType<T> = (props: T, options: CorrectComponentOption
9
14
  export type Variant = {
10
15
  id: string | number;
11
16
  options: string[];
17
+ /**
18
+ * Shopify sends both of these; this type has only ever modelled the part
19
+ * the components needed. They are optional because a theme may hand over a
20
+ * trimmed object, and the announcement degrades to the option list.
21
+ */
22
+ title?: string;
23
+ available?: boolean;
12
24
  };
13
25
  export type Product = {
14
26
  id: string | number;
@@ -18,11 +30,19 @@ export type Product = {
18
30
  export type Props = {
19
31
  product?: Product;
20
32
  isProductPage?: boolean;
33
+ /** Appended to the announcement when the chosen variant is in stock. */
34
+ availableLabel: string;
35
+ /** Appended when it is not. */
36
+ unavailableLabel: string;
21
37
  };
22
38
  declare const Name = "product-info";
23
39
  declare const Component: CorrectComponentType<Props>;
24
- type Props$1 = {};
25
- declare const Name$1 = "product-variant-render";
40
+ type Props$1 = {
41
+ position: number;
42
+ name: string;
43
+ inputType: "radio" | "select";
44
+ };
45
+ declare const Name$1 = "product-option-group";
26
46
  declare const Component$1: CorrectComponentType<Props$1>;
27
47
  type Props$2 = {
28
48
  selectedOptions: string[];
@@ -30,17 +50,13 @@ type Props$2 = {
30
50
  declare const Name$2 = "product-options";
31
51
  declare const Component$2: CorrectComponentType<Props$2>;
32
52
  type Props$3 = {
33
- position: number;
34
- name: string;
35
- inputType: "radio" | "select";
36
- };
37
- declare const Name$3 = "product-option-group";
38
- declare const Component$3: CorrectComponentType<Props$3>;
39
- type Props$4 = {
40
53
  target: string | null;
41
54
  preventDefault?: boolean;
42
55
  };
43
- declare const Name$4 = "product-variant-input";
56
+ declare const Name$3 = "product-variant-input";
57
+ declare const Component$3: CorrectComponentType<Props$3>;
58
+ type Props$4 = {};
59
+ declare const Name$4 = "product-variant-render";
44
60
  declare const Component$4: CorrectComponentType<Props$4>;
45
61
  export declare const useProduct: (element: HTMLElement & ICustomElement) => readonly [
46
62
  {
@@ -62,7 +78,7 @@ export declare const getProductContext: (element: Element) => readonly [
62
78
  };
63
79
  }
64
80
  ];
65
- export declare const withProductElementContext: <D extends unknown>(target: string | import("solid-js").Accessor<string> | import("solid-js").Accessor<() => Element>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
81
+ export declare const useProductAt: (target: () => string | undefined, host: HTMLElement) => import("solid-js").SourceAccessor<readonly [
66
82
  {
67
83
  product: Product;
68
84
  },
@@ -71,11 +87,15 @@ export declare const withProductElementContext: <D extends unknown>(target: stri
71
87
  readonly update: (variantId: string | number) => void;
72
88
  };
73
89
  }
74
- ], dependencies: D) => void | (() => void)) => void;
90
+ ]>;
91
+ export type CreateContextOptions = {
92
+ root: HTMLElement & ICustomElement;
93
+ selectedOptions: string[];
94
+ };
75
95
  export declare const useProductOptions: (element: HTMLElement & ICustomElement) => readonly [
76
- {
77
- selectedOptions: string[];
78
- },
96
+ import("solid-js").Omit<CreateContextOptions, [
97
+ "root"
98
+ ]>,
79
99
  {
80
100
  readonly options: {
81
101
  readonly update: (options: string[]) => void;
@@ -84,9 +104,9 @@ export declare const useProductOptions: (element: HTMLElement & ICustomElement)
84
104
  }
85
105
  ];
86
106
  export declare const getProductOptionsContext: (element: Element) => readonly [
87
- {
88
- selectedOptions: string[];
89
- },
107
+ import("solid-js").Omit<CreateContextOptions, [
108
+ "root"
109
+ ]>,
90
110
  {
91
111
  readonly options: {
92
112
  readonly update: (options: string[]) => void;
@@ -94,24 +114,24 @@ export declare const getProductOptionsContext: (element: Element) => readonly [
94
114
  };
95
115
  }
96
116
  ];
97
- export declare const withProductOptionsElementContext: <D extends unknown>(target: string | import("solid-js").Accessor<string> | import("solid-js").Accessor<() => Element>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
98
- {
99
- selectedOptions: string[];
100
- },
117
+ export declare const useProductOptionsAt: (target: () => string | undefined, host: HTMLElement) => import("solid-js").SourceAccessor<readonly [
118
+ import("solid-js").Omit<CreateContextOptions, [
119
+ "root"
120
+ ]>,
101
121
  {
102
122
  readonly options: {
103
123
  readonly update: (options: string[]) => void;
104
124
  readonly updateOption: (option: string, index: number) => void;
105
125
  };
106
126
  }
107
- ], dependencies: D) => void | (() => void)) => void;
127
+ ]>;
108
128
  export type ProductInfoProps = Props;
109
129
  export type ProductOptionsProps = Props$2;
110
- export type ProductOptionGroupProps = Props$3;
111
- export type ProductVariantInputProps = ProductVariantInput.Props;
112
- export type ProductVariantRenderProps = Props$1;
130
+ export type ProductOptionGroupProps = Props$1;
131
+ export type ProductVariantInputProps = Props$3;
132
+ export type ProductVariantRenderProps = ProductVariantRender.Props;
113
133
 
114
- declare namespace ProductVariantInput {
134
+ declare namespace ProductVariantRender {
115
135
  export { Component$4 as Component, Name$4 as Name, Props$4 as Props };
116
136
  }
117
137
 
@@ -1,43 +1,32 @@
1
- import { customShadowlessElement, correctElementType } from '@brytdesigns/web-component-core/utils';
2
- import { ProductInfo, ProductOptions, ProductOptionGroup, ProductVariantInput, ProductVariantRender } from './components/index.js';
3
- export { getProductContext, getProductOptionsContext, useProduct, useProductOptions, withProductElementContext, withProductOptionsElementContext } from './hooks/index.js';
1
+ import { getProductContext, useProduct, useProductAt } from "./hooks/useProduct.js";
2
+ import { getProductOptionsContext, useProductOptions, useProductOptionsAt } from "./hooks/useProductOptions.js";
3
+ import "./hooks/index.js";
4
+ import { Component, Name } from "./components/product-info.js";
5
+ import { Component as Component$1, Name as Name$1 } from "./components/product-option-group.js";
6
+ import { Component as Component$2, Name as Name$2 } from "./components/product-options.js";
7
+ import { Component as Component$3, Name as Name$3 } from "./components/product-variant-input.js";
8
+ import { Component as Component$4, Name as Name$4 } from "./components/product-variant-render.js";
9
+ import "./components/index.js";
10
+ import { customShadowlessElement } from "@brytdesigns/web-component-core/utils";
11
+ //#region src/index.ts
12
+ customShadowlessElement(Name, {
13
+ product: void 0,
14
+ isProductPage: false,
15
+ availableLabel: "In stock",
16
+ unavailableLabel: "Out of stock"
17
+ }, Component);
18
+ customShadowlessElement(Name$2, { selectedOptions: [] }, Component$2);
19
+ customShadowlessElement(Name$1, {
20
+ position: 0,
21
+ name: "",
22
+ inputType: "radio"
23
+ }, Component$1);
24
+ customShadowlessElement(Name$3, {
25
+ target: "",
26
+ preventDefault: true
27
+ }, Component$3);
28
+ customShadowlessElement(Name$4, {}, Component$4);
29
+ //#endregion
30
+ export { getProductContext, getProductOptionsContext, useProduct, useProductAt, useProductOptions, useProductOptionsAt };
4
31
 
5
- customShadowlessElement(
6
- ProductInfo.Name,
7
- {
8
- product: void 0,
9
- isProductPage: false
10
- },
11
- correctElementType(ProductInfo.Component)
12
- );
13
- customShadowlessElement(
14
- ProductOptions.Name,
15
- {
16
- selectedOptions: []
17
- },
18
- correctElementType(ProductOptions.Component)
19
- );
20
- customShadowlessElement(
21
- ProductOptionGroup.Name,
22
- {
23
- position: 0,
24
- name: "",
25
- inputType: "radio"
26
- },
27
- correctElementType(ProductOptionGroup.Component)
28
- );
29
- customShadowlessElement(
30
- ProductVariantInput.Name,
31
- {
32
- target: "",
33
- preventDefault: true
34
- },
35
- correctElementType(ProductVariantInput.Component)
36
- );
37
- customShadowlessElement(
38
- ProductVariantRender.Name,
39
- {},
40
- correctElementType(ProductVariantRender.Component)
41
- );
42
- //# sourceMappingURL=index.js.map
43
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAmBA,uBAAA;AAAA,EACE,WAAY,CAAA,IAAA;AAAA,EACZ;AAAA,IACE,OAAS,EAAA,MAAA;AAAA,IACT,aAAe,EAAA;AAAA,GACjB;AAAA,EACA,kBAAA,CAAmB,YAAY,SAAS;AAC1C,CAAA;AAEA,uBAAA;AAAA,EACE,cAAe,CAAA,IAAA;AAAA,EACf;AAAA,IACE,iBAAiB;AAAC,GACpB;AAAA,EACA,kBAAA,CAAmB,eAAe,SAAS;AAC7C,CAAA;AAEA,uBAAA;AAAA,EACE,kBAAmB,CAAA,IAAA;AAAA,EACnB;AAAA,IACE,QAAU,EAAA,CAAA;AAAA,IACV,IAAM,EAAA,EAAA;AAAA,IACN,SAAW,EAAA;AAAA,GACb;AAAA,EACA,kBAAA,CAAmB,mBAAmB,SAAS;AACjD,CAAA;AAEA,uBAAA;AAAA,EACE,mBAAoB,CAAA,IAAA;AAAA,EACpB;AAAA,IACE,MAAQ,EAAA,EAAA;AAAA,IACR,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,kBAAA,CAAmB,oBAAoB,SAAS;AAClD,CAAA;AAEA,uBAAA;AAAA,EACE,oBAAqB,CAAA,IAAA;AAAA,EACrB,EAAC;AAAA,EACD,kBAAA,CAAmB,qBAAqB,SAAS;AACnD,CAAA","file":"index.js","sourcesContent":["import {\n customShadowlessElement,\n correctElementType,\n} from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n ProductInfo,\n ProductOptions,\n ProductOptionGroup,\n ProductVariantInput,\n ProductVariantRender,\n} from \"./components/index.js\";\n\nexport type ProductInfoProps = ProductInfo.Props;\nexport type ProductOptionsProps = ProductOptions.Props;\nexport type ProductOptionGroupProps = ProductOptionGroup.Props;\nexport type ProductVariantInputProps = ProductVariantInput.Props;\nexport type ProductVariantRenderProps = ProductVariantRender.Props;\n\ncustomShadowlessElement(\n ProductInfo.Name,\n {\n product: undefined,\n isProductPage: false,\n },\n correctElementType(ProductInfo.Component),\n);\n\ncustomShadowlessElement(\n ProductOptions.Name,\n {\n selectedOptions: [],\n },\n correctElementType(ProductOptions.Component),\n);\n\ncustomShadowlessElement(\n ProductOptionGroup.Name,\n {\n position: 0,\n name: \"\",\n inputType: \"radio\",\n },\n correctElementType(ProductOptionGroup.Component),\n);\n\ncustomShadowlessElement(\n ProductVariantInput.Name,\n {\n target: \"\",\n preventDefault: true,\n },\n correctElementType(ProductVariantInput.Component),\n);\n\ncustomShadowlessElement(\n ProductVariantRender.Name,\n {},\n correctElementType(ProductVariantRender.Component),\n);\n\nexport {\n useProduct,\n useProductOptions,\n getProductContext,\n getProductOptionsContext,\n withProductElementContext,\n withProductOptionsElementContext,\n} from \"./hooks/index.js\";\n"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { customShadowlessElement } from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n\tProductInfo,\n\tProductOptionGroup,\n\tProductOptions,\n\tProductVariantInput,\n\tProductVariantRender,\n} from \"./components/index.js\";\n\nexport type ProductInfoProps = ProductInfo.Props;\nexport type ProductOptionsProps = ProductOptions.Props;\nexport type ProductOptionGroupProps = ProductOptionGroup.Props;\nexport type ProductVariantInputProps = ProductVariantInput.Props;\nexport type ProductVariantRenderProps = ProductVariantRender.Props;\n\ncustomShadowlessElement(\n\tProductInfo.Name,\n\t{\n\t\tproduct: undefined,\n\t\tisProductPage: false,\n\t\tavailableLabel: \"In stock\",\n\t\tunavailableLabel: \"Out of stock\",\n\t},\n\tProductInfo.Component,\n);\n\ncustomShadowlessElement(\n\tProductOptions.Name,\n\t{\n\t\tselectedOptions: [],\n\t},\n\tProductOptions.Component,\n);\n\ncustomShadowlessElement(\n\tProductOptionGroup.Name,\n\t{\n\t\tposition: 0,\n\t\tname: \"\",\n\t\tinputType: \"radio\",\n\t},\n\tProductOptionGroup.Component,\n);\n\ncustomShadowlessElement(\n\tProductVariantInput.Name,\n\t{\n\t\ttarget: \"\",\n\t\tpreventDefault: true,\n\t},\n\tProductVariantInput.Component,\n);\n\ncustomShadowlessElement(\n\tProductVariantRender.Name,\n\t{},\n\tProductVariantRender.Component,\n);\n\nexport {\n\tgetProductContext,\n\tgetProductOptionsContext,\n\tuseProduct,\n\tuseProductAt,\n\tuseProductOptions,\n\tuseProductOptionsAt,\n} from \"./hooks/index.js\";\n"],"mappings":";;;;;;;;;;;AAgBA,wBACC,MACA;CACC,SAAS,KAAA;CACT,eAAe;CACf,gBAAgB;CAChB,kBAAkB;AACnB,GACA,SACD;AAEA,wBACC,QACA,EACC,iBAAiB,CAAC,EACnB,GACA,WACD;AAEA,wBACC,QACA;CACC,UAAU;CACV,MAAM;CACN,WAAW;AACZ,GACA,WACD;AAEA,wBACC,QACA;CACC,QAAQ;CACR,gBAAgB;AACjB,GACA,WACD;AAEA,wBACC,QACA,CAAC,GACD,WACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brytdesigns/shopify-product-info-components",
3
- "version": "1.1.9",
3
+ "version": "3.0.0",
4
4
  "description": "Headless web components used to render product information based on active product variants",
5
5
  "main": "./dist/main/index.js",
6
6
  "module": "./dist/main/index.js",
@@ -9,7 +9,7 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/main/index.d.ts",
12
- "module": "./dist/main/index.js"
12
+ "default": "./dist/main/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -19,17 +19,17 @@
19
19
  "author": "Bryt Designs",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
+ "@brytdesigns/web-component-core": "3.0.0",
23
+ "@solidjs/web": "2.0.0-rc.14",
22
24
  "component-register": "0.8.7",
23
- "solid-element": "^1.9.1",
24
- "solid-js": "^1.9.9",
25
- "@brytdesigns/web-component-core": "1.1.6"
25
+ "solid-js": "2.0.0-rc.14"
26
26
  },
27
27
  "devDependencies": {
28
- "dts-bundle-generator": "^9.5.1",
29
- "tsup": "^8.4.0"
28
+ "@repo/vite-config": "0.0.0",
29
+ "vite": "^8.2.2"
30
30
  },
31
31
  "scripts": {
32
- "build": "tsup --clean",
32
+ "build": "vite build",
33
33
  "typecheck": "tsc --noEmit"
34
34
  }
35
35
  }