@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.
- package/dist/main/components/index.js +5 -12
- package/dist/main/components/product-info.js +55 -36
- package/dist/main/components/product-info.js.map +1 -1
- package/dist/main/components/product-option-group.js +53 -66
- package/dist/main/components/product-option-group.js.map +1 -1
- package/dist/main/components/product-options.js +10 -9
- package/dist/main/components/product-options.js.map +1 -1
- package/dist/main/components/product-variant-input.js +49 -46
- package/dist/main/components/product-variant-input.js.map +1 -1
- package/dist/main/components/product-variant-render.js +28 -34
- package/dist/main/components/product-variant-render.js.map +1 -1
- package/dist/main/hooks/index.js +3 -4
- package/dist/main/hooks/useProduct.js +40 -61
- package/dist/main/hooks/useProduct.js.map +1 -1
- package/dist/main/hooks/useProductOptions.js +43 -64
- package/dist/main/hooks/useProductOptions.js.map +1 -1
- package/dist/main/index.d.ts +47 -27
- package/dist/main/index.js +30 -41
- package/dist/main/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/esm/index.js +0 -385
- package/dist/esm/index.js.map +0 -1
- package/dist/main/components/index.js.map +0 -1
- package/dist/main/hooks/index.js.map +0 -1
- package/dist/main/types.js +0 -3
- package/dist/main/types.js.map +0 -1
|
@@ -1,69 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
33
|
+
var useProductContext = (context) => {
|
|
34
|
+
return context;
|
|
48
35
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
ProductContextState,
|
|
61
|
-
element
|
|
62
|
-
);
|
|
63
|
-
return useProductContext(context);
|
|
41
|
+
var getProductContext = (element) => {
|
|
42
|
+
return useProductContext(getContextFromProvider(ProductContextState, element));
|
|
64
43
|
};
|
|
65
|
-
|
|
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,"
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
|
|
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
|
-
|
|
47
|
-
|
|
36
|
+
var useProductOptionsContext = (context) => {
|
|
37
|
+
return context;
|
|
48
38
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
ProductOptionsContextState,
|
|
64
|
-
element
|
|
65
|
-
);
|
|
66
|
-
return useProductOptionsContext(context);
|
|
44
|
+
var getProductOptionsContext = (element) => {
|
|
45
|
+
return useProductOptionsContext(getContextFromProvider(ProductOptionsContextState, element));
|
|
67
46
|
};
|
|
68
|
-
|
|
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,"
|
|
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,SAAS,gCAAgC,OAA6B;CAErE,MAAM,cAAc,KAAK,OAAO,MAAM;CACtC,MAAM,CAAC,SAAS,WAAW,WAAW,MAAM,IAAI;CAEhD,SAAS,sBAAsB,SAAmB;EACjD,MAAM,KAAK,aAAa,oBAAoB,KAAK,UAAU,OAAO,CAAC;CACpE;CAEA,SAAS,qBAAqB,QAAgB,OAAe;EAE5D,MAAM,UAAU,CAAC,GADD,cAAc,YAAY,eACtB,CAAO;EAC3B,QAAQ,SAAS;EACjB,OAAO,sBAAsB,OAAO;CACrC;CAEA,0BACO;EACL,MAAM,kBAAkB,YAAY;EAOpC,OAAO,QAAQ,QAAQ,SAAS,MAAM,YACrC,gBAAgB,OAAO,WAAW,QAAQ,QAAQ,SAAS,MAAM,CAAC,CACnE;CACD,IACC,YAAY;EACZ,IAAI,CAAC,SAAS;EAKd,MAAM,UAAU,cACT,QAAQ,QAAQ,oCAAoC,EAC3D;EACA,IAAI,QAAQ,OAAO,SAAS;EAC5B,QAAQ,QAAQ,OAAO,QAAQ,EAAE;CAClC,CACD;CAEA,OAAO,CACN,aACA,EACC,SAAS;EACR,QAAQ;EACR,cAAc;CACf,EACD,CACD;AACD;AAEA,IAAM,6BAA6B,cAClC,+BACD;AAEA,IAAa,gCACZ,cACA,YAC2B;CAC3B,MAAM,QAAQ,MAAM,cAAc,EAAE,MAAM,QAAQ,CAAC;CACnD,OAAO,QAAQ,4BAA4B,OAAO,OAAO;AAC1D;AAEA,IAAa,4BAA4B,YAAmC;CAC3E,OAAO;AACR;AAEA,IAAa,qBAAqB,YAA0C;CAC3E,MAAM,UAAiC,QACtC,4BACA,OACD;CAEA,IAAI,CAAC,SACJ,MAAM,IAAI,MACT,0GACD;CAGD,OAAO,yBAAyB,OAAO;AACxC;AAEA,IAAa,4BAA4B,YAAqB;CAK7D,OAAO,yBAJS,uBACf,4BACA,OAE+B,CAAO;AACxC;AAEA,IAAa,sBAAsB,oBAClC,0BACD"}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
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
|
-
|
|
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$
|
|
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
|
|
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
|
-
]
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
]
|
|
127
|
+
]>;
|
|
108
128
|
export type ProductInfoProps = Props;
|
|
109
129
|
export type ProductOptionsProps = Props$2;
|
|
110
|
-
export type ProductOptionGroupProps = Props$
|
|
111
|
-
export type ProductVariantInputProps =
|
|
112
|
-
export type ProductVariantRenderProps = Props
|
|
130
|
+
export type ProductOptionGroupProps = Props$1;
|
|
131
|
+
export type ProductVariantInputProps = Props$3;
|
|
132
|
+
export type ProductVariantRenderProps = ProductVariantRender.Props;
|
|
113
133
|
|
|
114
|
-
declare namespace
|
|
134
|
+
declare namespace ProductVariantRender {
|
|
115
135
|
export { Component$4 as Component, Name$4 as Name, Props$4 as Props };
|
|
116
136
|
}
|
|
117
137
|
|
package/dist/main/index.js
CHANGED
|
@@ -1,43 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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": "
|
|
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
|
-
"
|
|
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-
|
|
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
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"@repo/vite-config": "0.0.0",
|
|
29
|
+
"vite": "^8.2.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "
|
|
32
|
+
"build": "vite build",
|
|
33
33
|
"typecheck": "tsc --noEmit"
|
|
34
34
|
}
|
|
35
35
|
}
|