@brytdesigns/shopify-product-info-components 1.0.13 → 1.1.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/esm/index.js +69 -28
- package/dist/esm/index.js.map +1 -1
- package/dist/main/components/index.js +10 -5
- package/dist/main/components/product-info.js +6 -5
- package/dist/main/components/product-info.js.map +1 -1
- package/dist/main/components/product-option-group.js +3 -2
- package/dist/main/components/product-option-group.js.map +1 -1
- package/dist/main/components/product-options.js +4 -5
- package/dist/main/components/product-options.js.map +1 -1
- package/dist/main/components/product-variant-input.js +4 -4
- package/dist/main/components/product-variant-input.js.map +1 -1
- package/dist/main/components/product-variant-render.js +4 -3
- package/dist/main/components/product-variant-render.js.map +1 -1
- package/dist/main/hooks/useProduct.js +3 -2
- package/dist/main/hooks/useProduct.js.map +1 -1
- package/dist/main/hooks/useProductOptions.js +3 -2
- package/dist/main/hooks/useProductOptions.js.map +1 -1
- package/dist/main/index.d.ts +21 -0
- package/dist/main/index.js +12 -12
- package/dist/main/index.js.map +1 -1
- package/package.json +2 -2
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { customShadowlessElement, correctElementType, getContextFromProvider } from '@brytdesigns/web-component-utils';
|
|
2
|
-
import { splitProps, mergeProps, createEffect,
|
|
1
|
+
import { createWithElementContext, customShadowlessElement, correctElementType, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
|
|
2
|
+
import { splitProps, mergeProps, createEffect, untrack, createMemo, Show, on, onCleanup, observable } from 'solid-js';
|
|
3
3
|
import { createContext, consume, provide } from 'component-register';
|
|
4
4
|
import html from 'solid-js/html';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/components/product-info.ts
|
|
13
|
+
var product_info_exports = {};
|
|
14
|
+
__export(product_info_exports, {
|
|
15
|
+
Component: () => Component,
|
|
16
|
+
Name: () => Name
|
|
17
|
+
});
|
|
7
18
|
function initializeProductContext(props) {
|
|
8
19
|
const [privateProps, publicProps] = splitProps(props, ["root"]);
|
|
9
20
|
const state = mergeProps(publicProps, {});
|
|
@@ -64,6 +75,7 @@ var getProductContext = (element) => {
|
|
|
64
75
|
);
|
|
65
76
|
return useProductContext(context);
|
|
66
77
|
};
|
|
78
|
+
var withProductElementContext = createWithElementContext(ProductContextState);
|
|
67
79
|
function initializeProductOptionsContext(props) {
|
|
68
80
|
const [privateProps, publicProps] = splitProps(props, ["root"]);
|
|
69
81
|
const [context, methods] = useProduct(privateProps.root);
|
|
@@ -126,16 +138,18 @@ var getProductOptionsContext = (element) => {
|
|
|
126
138
|
);
|
|
127
139
|
return useProductOptionsContext(context);
|
|
128
140
|
};
|
|
141
|
+
var withProductOptionsElementContext = createWithElementContext(ProductOptionsContextState);
|
|
129
142
|
|
|
130
143
|
// src/components/product-info.ts
|
|
131
|
-
var
|
|
144
|
+
var Name = `product-info`;
|
|
145
|
+
var Component = (props, { element }) => {
|
|
132
146
|
if (!props.product)
|
|
133
|
-
return console.warn(
|
|
147
|
+
return console.warn(`${Name}: product attribute is required`);
|
|
134
148
|
if (!props.product.variants)
|
|
135
|
-
return console.warn(
|
|
149
|
+
return console.warn(`${Name}: product attribute needs variants array`);
|
|
136
150
|
if (!props.product.selected_or_first_available_variant)
|
|
137
151
|
return console.warn(
|
|
138
|
-
|
|
152
|
+
`${Name}: product attribute needs selected or first available variant object`
|
|
139
153
|
);
|
|
140
154
|
provideProductContext(props, element);
|
|
141
155
|
const url = createMemo(() => {
|
|
@@ -159,12 +173,20 @@ var ProductInfo = (props, { element }) => {
|
|
|
159
173
|
window.history.replaceState(null, "", url());
|
|
160
174
|
});
|
|
161
175
|
};
|
|
162
|
-
|
|
176
|
+
|
|
177
|
+
// src/components/product-variant-render.ts
|
|
178
|
+
var product_variant_render_exports = {};
|
|
179
|
+
__export(product_variant_render_exports, {
|
|
180
|
+
Component: () => Component2,
|
|
181
|
+
Name: () => Name2
|
|
182
|
+
});
|
|
183
|
+
var Name2 = `product-variant-render`;
|
|
184
|
+
var Component2 = (_, { element }) => {
|
|
163
185
|
const templates = Array.from(
|
|
164
186
|
element.querySelectorAll("template[variant-id]")
|
|
165
187
|
);
|
|
166
188
|
if (!templates.length)
|
|
167
|
-
return console.warn(
|
|
189
|
+
return console.warn(`${Name2}: No variant templates found`);
|
|
168
190
|
const [state] = useProduct(element);
|
|
169
191
|
const fallbackChildren = Array.from(element.children);
|
|
170
192
|
const activeVariantTemplate = createMemo(() => {
|
|
@@ -189,14 +211,26 @@ var ProductVariantRender = (_, { element }) => {
|
|
|
189
211
|
};
|
|
190
212
|
|
|
191
213
|
// src/components/product-options.ts
|
|
192
|
-
var
|
|
214
|
+
var product_options_exports = {};
|
|
215
|
+
__export(product_options_exports, {
|
|
216
|
+
Component: () => Component3,
|
|
217
|
+
Name: () => Name3
|
|
218
|
+
});
|
|
219
|
+
var Name3 = `product-options`;
|
|
220
|
+
var Component3 = (props, { element }) => {
|
|
193
221
|
if (!props.selectedOptions)
|
|
194
|
-
return console.warn(
|
|
195
|
-
"product-options: selected-options attribute is required"
|
|
196
|
-
);
|
|
222
|
+
return console.warn(`${Name3}: selected-options attribute is required`);
|
|
197
223
|
provideProductOptionsContext(props, element);
|
|
198
224
|
};
|
|
199
|
-
|
|
225
|
+
|
|
226
|
+
// src/components/product-option-group.ts
|
|
227
|
+
var product_option_group_exports = {};
|
|
228
|
+
__export(product_option_group_exports, {
|
|
229
|
+
Component: () => Component4,
|
|
230
|
+
Name: () => Name4
|
|
231
|
+
});
|
|
232
|
+
var Name4 = `product-option-group`;
|
|
233
|
+
var Component4 = (props, { element }) => {
|
|
200
234
|
const [context, methods] = useProductOptions(element);
|
|
201
235
|
createEffect(
|
|
202
236
|
on(
|
|
@@ -257,7 +291,15 @@ var ProductOptionGroup = (props, { element }) => {
|
|
|
257
291
|
});
|
|
258
292
|
});
|
|
259
293
|
};
|
|
260
|
-
|
|
294
|
+
|
|
295
|
+
// src/components/product-variant-input.ts
|
|
296
|
+
var product_variant_input_exports = {};
|
|
297
|
+
__export(product_variant_input_exports, {
|
|
298
|
+
Component: () => Component5,
|
|
299
|
+
Name: () => Name5
|
|
300
|
+
});
|
|
301
|
+
var Name5 = `product-variant-input`;
|
|
302
|
+
var Component5 = (props, { element }) => {
|
|
261
303
|
const [productContext, productContextMethods] = useProduct(element);
|
|
262
304
|
const [_, optionsMethods] = useProductOptions(element);
|
|
263
305
|
createEffect(() => {
|
|
@@ -290,8 +332,7 @@ var ProductVariantInput = (props, { element }) => {
|
|
|
290
332
|
target = element.querySelector(props.target);
|
|
291
333
|
if (!target)
|
|
292
334
|
target = element.querySelector("input[name='id']");
|
|
293
|
-
if (!target)
|
|
294
|
-
return console.warn("product-variant-input: target input not found");
|
|
335
|
+
if (!target) return console.warn(`${Name5}: target input not found`);
|
|
295
336
|
const variantId = productContext?.product?.selected_or_first_available_variant?.id;
|
|
296
337
|
if (!variantId) return;
|
|
297
338
|
if (target.value === variantId.toString()) return;
|
|
@@ -302,43 +343,43 @@ var ProductVariantInput = (props, { element }) => {
|
|
|
302
343
|
|
|
303
344
|
// src/index.ts
|
|
304
345
|
customShadowlessElement(
|
|
305
|
-
|
|
346
|
+
product_info_exports.Name,
|
|
306
347
|
{
|
|
307
348
|
product: void 0,
|
|
308
349
|
isProductPage: false
|
|
309
350
|
},
|
|
310
|
-
correctElementType(
|
|
351
|
+
correctElementType(product_info_exports.Component)
|
|
311
352
|
);
|
|
312
353
|
customShadowlessElement(
|
|
313
|
-
|
|
354
|
+
product_options_exports.Name,
|
|
314
355
|
{
|
|
315
356
|
selectedOptions: []
|
|
316
357
|
},
|
|
317
|
-
correctElementType(
|
|
358
|
+
correctElementType(product_options_exports.Component)
|
|
318
359
|
);
|
|
319
360
|
customShadowlessElement(
|
|
320
|
-
|
|
361
|
+
product_option_group_exports.Name,
|
|
321
362
|
{
|
|
322
363
|
position: 0,
|
|
323
364
|
name: "",
|
|
324
365
|
inputType: "radio"
|
|
325
366
|
},
|
|
326
|
-
correctElementType(
|
|
367
|
+
correctElementType(product_option_group_exports.Component)
|
|
327
368
|
);
|
|
328
369
|
customShadowlessElement(
|
|
329
|
-
|
|
370
|
+
product_variant_input_exports.Name,
|
|
330
371
|
{
|
|
331
372
|
target: "",
|
|
332
373
|
preventDefault: true
|
|
333
374
|
},
|
|
334
|
-
correctElementType(
|
|
375
|
+
correctElementType(product_variant_input_exports.Component)
|
|
335
376
|
);
|
|
336
377
|
customShadowlessElement(
|
|
337
|
-
|
|
378
|
+
product_variant_render_exports.Name,
|
|
338
379
|
{},
|
|
339
|
-
correctElementType(
|
|
380
|
+
correctElementType(product_variant_render_exports.Component)
|
|
340
381
|
);
|
|
341
382
|
|
|
342
|
-
export { getProductContext, getProductOptionsContext, useProduct, useProductOptions };
|
|
383
|
+
export { getProductContext, getProductOptionsContext, useProduct, useProductOptions, withProductElementContext, withProductOptionsElementContext };
|
|
343
384
|
//# sourceMappingURL=index.js.map
|
|
344
385
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useProduct.ts","../../src/hooks/useProductOptions.ts","../../src/components/product-info.ts","../../src/components/product-variant-render.ts","../../src/components/product-options.ts","../../src/components/product-option-group.ts","../../src/components/product-variant-input.ts","../../src/index.ts"],"names":["splitProps","untrack","variant","createContext","mergeProps","provide","consume","getContextFromProvider","url","createEffect","createMemo","target","onCleanup"],"mappings":";;;;;;AAoBA,SAAS,yBAAyB,KAA6B,EAAA;AAC7D,EAAM,MAAA,CAAC,cAAc,WAAW,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AAC9D,EAAA,MAAM,KAAQ,GAAA,UAAA,CAAW,WAAa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,EAAA;AAAA,IACN,SAAW,EAAA;AAAA,GACb;AAAA,EACA,mBAAmB,kBAAkB;AACvC,CAAA;AAEA,uBAAA;AAAA,EACE,uBAAA;AAAA,EACA;AAAA,IACE,MAAQ,EAAA,EAAA;AAAA,IACR,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,mBAAmB,mBAAmB;AACxC,CAAA;AAEA,uBAAA;AAAA,EACE,wBAAA;AAAA,EACA,EAAC;AAAA,EACD,mBAAmB,oBAAoB;AACzC,CAAA","file":"index.js","sourcesContent":["import {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport { mergeProps, splitProps, untrack } from \"solid-js\";\nimport { getContextFromProvider } from \"@brytdesigns/web-component-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","import {\n type ICustomElement,\n createContext,\n provide,\n consume,\n} from \"component-register\";\nimport { createEffect, mergeProps, splitProps, untrack } from \"solid-js\";\nimport { getContextFromProvider } from \"@brytdesigns/web-component-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","import type { CorrectComponentType } from \"@brytdesigns/web-component-utils\";\n\nimport { createEffect, createMemo, observable } from \"solid-js\";\n\nimport { provideProductContext } from \"../hooks/index.js\";\n\nimport type { Product } from \"../types.js\";\n\ntype ProductInfoProps = {\n product?: Product;\n isProductPage?: boolean;\n};\n\nexport const ProductInfo: CorrectComponentType<ProductInfoProps> = (\n props,\n { element },\n) => {\n if (!props.product)\n return console.warn(\"product-info: product attribute is required\");\n if (!props.product.variants)\n return console.warn(\"product-info: product attribute needs variants array\");\n if (!props.product.selected_or_first_available_variant)\n return console.warn(\n \"product-info: product attribute needs selected or first available variant object\",\n );\n provideProductContext(props as any, element);\n\n const url = createMemo(() => {\n const url = new URL(window.location.href);\n if (props.product && props.product.selected_or_first_available_variant) {\n url.searchParams.set(\n \"variant\",\n props.product.selected_or_first_available_variant.id.toString(),\n );\n }\n return url;\n });\n\n function subscribe(cb: (product: Product | undefined) => void) {\n return observable(() => props.product).subscribe(cb).unsubscribe;\n }\n\n Object.assign(element, {\n subscribe,\n });\n\n createEffect(() => {\n if (!props.isProductPage) return;\n window.history.replaceState(null, \"\", url());\n });\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-utils\";\n\nimport { createMemo, Show } from \"solid-js\";\nimport html from \"solid-js/html\";\n\nimport { useProduct } from \"../hooks/index.js\";\n\ntype ProductVariantRenderProps = {};\n\nexport const ProductVariantRender: CorrectComponentType<\n ProductVariantRenderProps\n> = (_, { element }) => {\n const templates = Array.from(\n element.querySelectorAll<HTMLTemplateElement>(\"template[variant-id]\"),\n );\n if (!templates.length)\n return console.warn(\"product-variant-render: No variant templates found\");\n const [state] = useProduct(element);\n\n const fallbackChildren = Array.from(element.children);\n\n const activeVariantTemplate = createMemo(() => {\n const variantId = state.product?.selected_or_first_available_variant?.id;\n if (!variantId) return null;\n const template = templates.find(\n (t) => t.getAttribute(\"variant-id\") === `${variantId}`,\n );\n return template || null;\n });\n\n element.replaceChildren(...[]);\n\n return html`\n <${Show}\n when=${() => !!activeVariantTemplate()}\n fallback=${fallbackChildren}\n >\n ${() =>\n Array.from(\n activeVariantTemplate()?.content.cloneNode(true).childNodes || [],\n )}\n <//>\n `;\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-utils\";\nimport { provideProductOptionsContext } from \"../hooks/index.js\";\n\ntype ProductOptionsProps = {\n selectedOptions: string[];\n};\n\nexport const ProductOptions: CorrectComponentType<ProductOptionsProps> = (\n props,\n { element },\n) => {\n if (!props.selectedOptions)\n return console.warn(\n \"product-options: selected-options attribute is required\",\n );\n provideProductOptionsContext(props, element);\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-utils\";\n\nimport { createEffect, on, onCleanup } from \"solid-js\";\n\nimport { useProductOptions } from \"../hooks/index.js\";\n\ntype ProductOptionGroupProps = {\n position: number;\n name: string;\n inputType: \"radio\" | \"select\";\n};\n\nexport const ProductOptionGroup: CorrectComponentType<\n ProductOptionGroupProps\n> = (props, { element }) => {\n const [context, methods] = useProductOptions(element);\n\n createEffect(\n on(\n () => ({\n selectedOption: context.selectedOptions[props.position - 1],\n position: props.position,\n name: props.name,\n inputType: props.inputType,\n }),\n ({ selectedOption, position, name, inputType }) => {\n if (inputType !== \"radio\" && inputType !== \"select\") return;\n\n const optionName = `${name}-${position}`;\n\n if (inputType === \"radio\") {\n const inputs = element.querySelectorAll<HTMLInputElement>(\n `input[name=\"${optionName}\"]`,\n );\n inputs.forEach((input) => {\n const prevValue = input.checked;\n if (input.value === selectedOption) input.checked = true;\n else input.checked = false;\n if (prevValue !== input.checked) {\n input.dispatchEvent(new Event(\"change\", { bubbles: true }));\n }\n });\n return;\n }\n\n const select = element.querySelector<HTMLSelectElement>(\n `select[name=\"${optionName}\"]`,\n );\n if (!select || !selectedOption) return;\n select.value = selectedOption;\n select.dispatchEvent(new Event(\"change\", { bubbles: true }));\n },\n ),\n );\n\n createEffect(() => {\n const position = props.position;\n\n function handleChange(event: Event) {\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const selectedOption = target.value;\n if (context.selectedOptions[position - 1] === selectedOption) return;\n\n element.dispatchEvent(\n new CustomEvent(\"option-updated\", {\n detail: {\n group: props.name,\n position: position,\n selectedOption,\n },\n bubbles: true,\n }),\n );\n\n methods.options.updateOption(selectedOption, position - 1);\n }\n\n element.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n element.removeEventListener(\"change\", handleChange);\n });\n });\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-utils\";\n\nimport { createEffect, onCleanup } from \"solid-js\";\n\nimport { useProduct, useProductOptions } from \"../hooks/index.js\";\n\ntype ProductVariantInputProps = {\n target: string | null;\n preventDefault?: boolean;\n};\n\nexport const ProductVariantInput: CorrectComponentType<\n ProductVariantInputProps\n> = (props, { element }) => {\n const [productContext, productContextMethods] = useProduct(element);\n const [_, optionsMethods] = useProductOptions(element);\n\n createEffect(() => {\n let target = null;\n if (props.target) target = element.querySelector(props.target);\n if (!target) target = element;\n\n const preventDefault = props.preventDefault;\n\n function handleChange(event: Event) {\n if (preventDefault) event.preventDefault();\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const value = target.value;\n if (\n value ===\n productContext?.product?.selected_or_first_available_variant?.id\n )\n return;\n const variant = productContext?.product?.variants.find(\n (variant) => variant.id.toString() === value.toString(),\n );\n if (!variant) return;\n if (optionsMethods) optionsMethods.options.update(variant.options);\n else productContextMethods.variant.update(variant.id);\n }\n\n target.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n target.removeEventListener(\"change\", handleChange);\n });\n });\n\n createEffect(() => {\n let target = null;\n if (props.target)\n target = element.querySelector<HTMLInputElement>(props.target);\n if (!target)\n target = element.querySelector<HTMLInputElement>(\"input[name='id']\");\n if (!target)\n return console.warn(\"product-variant-input: target input not found\");\n\n const variantId =\n productContext?.product?.selected_or_first_available_variant?.id;\n if (!variantId) return;\n if (target.value === variantId.toString()) return;\n target.value = variantId.toString();\n target.dispatchEvent(new Event(\"change\", { bubbles: true }));\n });\n};\n","import {\n customShadowlessElement,\n correctElementType,\n} from \"@brytdesigns/web-component-utils\";\n\nimport {\n ProductInfo,\n ProductOptions,\n ProductOptionGroup,\n ProductVariantInput,\n ProductVariantRender,\n} from \"./components/index.js\";\n\ncustomShadowlessElement(\n \"product-info\",\n {\n product: undefined,\n isProductPage: false,\n },\n correctElementType(ProductInfo),\n);\n\ncustomShadowlessElement(\n \"product-options\",\n {\n selectedOptions: [],\n },\n correctElementType(ProductOptions),\n);\n\ncustomShadowlessElement(\n \"product-option-group\",\n {\n position: 0,\n name: \"\",\n inputType: \"radio\",\n },\n correctElementType(ProductOptionGroup),\n);\n\ncustomShadowlessElement(\n \"product-variant-input\",\n {\n target: \"\",\n preventDefault: true,\n },\n correctElementType(ProductVariantInput),\n);\n\ncustomShadowlessElement(\n \"product-variant-render\",\n {},\n correctElementType(ProductVariantRender),\n);\n\nexport {\n useProduct,\n useProductOptions,\n getProductContext,\n getProductOptionsContext,\n} from \"./hooks/index.js\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/product-info.ts","../../src/hooks/useProduct.ts","../../src/hooks/useProductOptions.ts","../../src/components/product-variant-render.ts","../../src/components/product-options.ts","../../src/components/product-option-group.ts","../../src/components/product-variant-input.ts","../../src/index.ts"],"names":["splitProps","untrack","variant","createContext","mergeProps","provide","consume","getContextFromProvider","createWithElementContext","url","createEffect","Component","Name","createMemo","target","onCleanup"],"mappings":";;;;;;;;;;;;AAAA,IAAA,oBAAA,GAAA,EAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACuBA,SAAS,yBAAyB,KAA6B,EAAA;AAC7D,EAAM,MAAA,CAAC,cAAc,WAAW,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AAC9D,EAAA,MAAM,KAAQ,GAAA,UAAA,CAAW,WAAa,EAAA,EAAE,CAAA;AAExC,EAAA,SAAS,sBAAsB,SAA4B,EAAA;AACzD,IAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,MAAM,KAAA,EAAO,OAAO,CAAA;AAC5C,IACE,IAAA,OAAO,SAAS,mCAAwC,KAAA,WAAA,IACxD,OAAO,OAAY,KAAA,WAAA,IACnB,OAAO,OAAA,EAAS,QAAa,KAAA,WAAA;AAE7B,MAAA;AACF,IAAM,MAAA,UAAA,GAAa,QAAQ,QAAS,CAAA,IAAA;AAAA,MAClC,CAAC,OAAY,KAAA,OAAA,CAAQ,GAAG,QAAS,EAAA,KAAM,UAAU,QAAS;AAAA,KAC5D;AAEA,IAAA,IACE,YAAY,EAAG,CAAA,QAAA,OACf,OAAQ,CAAA,mCAAA,EAAqC,GAAG,QAAS,EAAA;AAEzD,MAAA;AAEF,IAAA,MAAM,QAAW,GAAA;AAAA,MACf,GAAG,OAAA;AAAA,MACH,mCAAqC,EAAA;AAAA,KACvC;AAEA,IAAA,YAAA,CAAa,KAAK,YAAa,CAAA,SAAA,EAAW,IAAK,CAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAElE,IAAA,YAAA,CAAa,IAAK,CAAA,aAAA;AAAA,MAChB,IAAI,YAAY,iBAAmB,EAAA;AA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5D,CAAA;AACH,CAAA;;;ACnDA,uBAAA;AAAA,EACE,oBAAY,CAAA,IAAA;AAAA,EACZ;AAAA,IACE,OAAS,EAAA,MAAA;AAAA,IACT,aAAe,EAAA;AAAA,GACjB;AAAA,EACA,kBAAA,CAAmB,qBAAY,SAAS;AAC1C,CAAA;AAEA,uBAAA;AAAA,EACE,uBAAe,CAAA,IAAA;AAAA,EACf;AAAA,IACE,iBAAiB;AAAC,GACpB;AAAA,EACA,kBAAA,CAAmB,wBAAe,SAAS;AAC7C,CAAA;AAEA,uBAAA;AAAA,EACE,4BAAmB,CAAA,IAAA;AAAA,EACnB;AAAA,IACE,QAAU,EAAA,CAAA;AAAA,IACV,IAAM,EAAA,EAAA;AAAA,IACN,SAAW,EAAA;AAAA,GACb;AAAA,EACA,kBAAA,CAAmB,6BAAmB,SAAS;AACjD,CAAA;AAEA,uBAAA;AAAA,EACE,6BAAoB,CAAA,IAAA;AAAA,EACpB;AAAA,IACE,MAAQ,EAAA,EAAA;AAAA,IACR,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,kBAAA,CAAmB,8BAAoB,SAAS;AAClD,CAAA;AAEA,uBAAA;AAAA,EACE,8BAAqB,CAAA,IAAA;AAAA,EACrB,EAAC;AAAA,EACD,kBAAA,CAAmB,+BAAqB,SAAS;AACnD,CAAA","file":"index.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, createMemo, observable } from \"solid-js\";\n\nimport { provideProductContext } from \"../hooks/index.js\";\n\nimport type { Product } from \"../types.js\";\n\ntype Props = {\n product?: Product;\n isProductPage?: boolean;\n};\n\nexport const Name = `product-info`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n if (!props.product)\n return console.warn(`${Name}: product attribute is required`);\n if (!props.product.variants)\n return console.warn(`${Name}: product attribute needs variants array`);\n if (!props.product.selected_or_first_available_variant)\n return console.warn(\n `${Name}: product attribute needs selected or first available variant object`,\n );\n provideProductContext(props as any, element);\n\n const url = createMemo(() => {\n const url = new URL(window.location.href);\n if (props.product && props.product.selected_or_first_available_variant) {\n url.searchParams.set(\n \"variant\",\n props.product.selected_or_first_available_variant.id.toString(),\n );\n }\n return url;\n });\n\n function subscribe(cb: (product: Product | undefined) => void) {\n return observable(() => props.product).subscribe(cb).unsubscribe;\n }\n\n Object.assign(element, {\n subscribe,\n });\n\n createEffect(() => {\n if (!props.isProductPage) return;\n window.history.replaceState(null, \"\", url());\n });\n};\n","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","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","import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createMemo, Show } from \"solid-js\";\nimport html from \"solid-js/html\";\n\nimport { useProduct } from \"../hooks/index.js\";\n\ntype Props = {};\n\nexport const Name = `product-variant-render`;\n\nexport const Component: CorrectComponentType<Props> = (_, { element }) => {\n const templates = Array.from(\n element.querySelectorAll<HTMLTemplateElement>(\"template[variant-id]\"),\n );\n if (!templates.length)\n return console.warn(`${Name}: No variant templates found`);\n const [state] = useProduct(element);\n\n const fallbackChildren = Array.from(element.children);\n\n const activeVariantTemplate = createMemo(() => {\n const variantId = state.product?.selected_or_first_available_variant?.id;\n if (!variantId) return null;\n const template = templates.find(\n (t) => t.getAttribute(\"variant-id\") === `${variantId}`,\n );\n return template || null;\n });\n\n element.replaceChildren(...[]);\n\n return html`\n <${Show}\n when=${() => !!activeVariantTemplate()}\n fallback=${fallbackChildren}\n >\n ${() =>\n Array.from(\n activeVariantTemplate()?.content.cloneNode(true).childNodes || [],\n )}\n <//>\n `;\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { provideProductOptionsContext } from \"../hooks/index.js\";\n\ntype Props = {\n selectedOptions: string[];\n};\n\nexport const Name = `product-options`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n if (!props.selectedOptions)\n return console.warn(`${Name}: selected-options attribute is required`);\n provideProductOptionsContext(props, element);\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, on, onCleanup } from \"solid-js\";\n\nimport { useProductOptions } from \"../hooks/index.js\";\n\ntype Props = {\n position: number;\n name: string;\n inputType: \"radio\" | \"select\";\n};\n\nexport const Name = `product-option-group`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const [context, methods] = useProductOptions(element);\n\n createEffect(\n on(\n () => ({\n selectedOption: context.selectedOptions[props.position - 1],\n position: props.position,\n name: props.name,\n inputType: props.inputType,\n }),\n ({ selectedOption, position, name, inputType }) => {\n if (inputType !== \"radio\" && inputType !== \"select\") return;\n\n const optionName = `${name}-${position}`;\n\n if (inputType === \"radio\") {\n const inputs = element.querySelectorAll<HTMLInputElement>(\n `input[name=\"${optionName}\"]`,\n );\n inputs.forEach((input) => {\n const prevValue = input.checked;\n if (input.value === selectedOption) input.checked = true;\n else input.checked = false;\n if (prevValue !== input.checked) {\n input.dispatchEvent(new Event(\"change\", { bubbles: true }));\n }\n });\n return;\n }\n\n const select = element.querySelector<HTMLSelectElement>(\n `select[name=\"${optionName}\"]`,\n );\n if (!select || !selectedOption) return;\n select.value = selectedOption;\n select.dispatchEvent(new Event(\"change\", { bubbles: true }));\n },\n ),\n );\n\n createEffect(() => {\n const position = props.position;\n\n function handleChange(event: Event) {\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const selectedOption = target.value;\n if (context.selectedOptions[position - 1] === selectedOption) return;\n\n element.dispatchEvent(\n new CustomEvent(\"option-updated\", {\n detail: {\n group: props.name,\n position: position,\n selectedOption,\n },\n bubbles: true,\n }),\n );\n\n methods.options.updateOption(selectedOption, position - 1);\n }\n\n element.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n element.removeEventListener(\"change\", handleChange);\n });\n });\n};\n","import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, onCleanup } from \"solid-js\";\n\nimport { useProduct, useProductOptions } from \"../hooks/index.js\";\n\ntype Props = {\n target: string | null;\n preventDefault?: boolean;\n};\n\nexport const Name = `product-variant-input`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const [productContext, productContextMethods] = useProduct(element);\n const [_, optionsMethods] = useProductOptions(element);\n\n createEffect(() => {\n let target = null;\n if (props.target) target = element.querySelector(props.target);\n if (!target) target = element;\n\n const preventDefault = props.preventDefault;\n\n function handleChange(event: Event) {\n if (preventDefault) event.preventDefault();\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const value = target.value;\n if (\n value ===\n productContext?.product?.selected_or_first_available_variant?.id\n )\n return;\n const variant = productContext?.product?.variants.find(\n (variant) => variant.id.toString() === value.toString(),\n );\n if (!variant) return;\n if (optionsMethods) optionsMethods.options.update(variant.options);\n else productContextMethods.variant.update(variant.id);\n }\n\n target.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n target.removeEventListener(\"change\", handleChange);\n });\n });\n\n createEffect(() => {\n let target = null;\n if (props.target)\n target = element.querySelector<HTMLInputElement>(props.target);\n if (!target)\n target = element.querySelector<HTMLInputElement>(\"input[name='id']\");\n if (!target) return console.warn(`${Name}: target input not found`);\n\n const variantId =\n productContext?.product?.selected_or_first_available_variant?.id;\n if (!variantId) return;\n if (target.value === variantId.toString()) return;\n target.value = variantId.toString();\n target.dispatchEvent(new Event(\"change\", { bubbles: true }));\n });\n};\n","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\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,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
1
|
+
import * as productInfo_js from './product-info.js';
|
|
2
|
+
export { productInfo_js as ProductInfo };
|
|
3
|
+
import * as productVariantRender_js from './product-variant-render.js';
|
|
4
|
+
export { productVariantRender_js as ProductVariantRender };
|
|
5
|
+
import * as productOptions_js from './product-options.js';
|
|
6
|
+
export { productOptions_js as ProductOptions };
|
|
7
|
+
import * as productOptionGroup_js from './product-option-group.js';
|
|
8
|
+
export { productOptionGroup_js as ProductOptionGroup };
|
|
9
|
+
import * as productVariantInput_js from './product-variant-input.js';
|
|
10
|
+
export { productVariantInput_js as ProductVariantInput };
|
|
6
11
|
//# sourceMappingURL=index.js.map
|
|
7
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createMemo, createEffect, observable } from 'solid-js';
|
|
2
2
|
import { provideProductContext } from '../hooks/index.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const Name = `product-info`;
|
|
5
|
+
const Component = (props, { element }) => {
|
|
5
6
|
if (!props.product)
|
|
6
|
-
return console.warn(
|
|
7
|
+
return console.warn(`${Name}: product attribute is required`);
|
|
7
8
|
if (!props.product.variants)
|
|
8
|
-
return console.warn(
|
|
9
|
+
return console.warn(`${Name}: product attribute needs variants array`);
|
|
9
10
|
if (!props.product.selected_or_first_available_variant)
|
|
10
11
|
return console.warn(
|
|
11
|
-
|
|
12
|
+
`${Name}: product attribute needs selected or first available variant object`
|
|
12
13
|
);
|
|
13
14
|
provideProductContext(props, element);
|
|
14
15
|
const url = createMemo(() => {
|
|
@@ -33,6 +34,6 @@ const ProductInfo = (props, { element }) => {
|
|
|
33
34
|
});
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
export {
|
|
37
|
+
export { Component, Name };
|
|
37
38
|
//# sourceMappingURL=product-info.js.map
|
|
38
39
|
//# sourceMappingURL=product-info.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/product-info.ts"],"names":["url"],"mappings":";;;AAaO,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/product-info.ts"],"names":["url"],"mappings":";;;AAaO,MAAM,IAAO,GAAA,CAAA,YAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAA,IAAI,CAAC,KAAM,CAAA,OAAA;AACT,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,CAAG,EAAA,IAAI,CAAiC,+BAAA,CAAA,CAAA;AAC9D,EAAI,IAAA,CAAC,MAAM,OAAQ,CAAA,QAAA;AACjB,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,CAAG,EAAA,IAAI,CAA0C,wCAAA,CAAA,CAAA;AACvE,EAAI,IAAA,CAAC,MAAM,OAAQ,CAAA,mCAAA;AACjB,IAAA,OAAO,OAAQ,CAAA,IAAA;AAAA,MACb,GAAG,IAAI,CAAA,oEAAA;AAAA,KACT;AACF,EAAA,qBAAA,CAAsB,OAAc,OAAO,CAAA;AAE3C,EAAM,MAAA,GAAA,GAAM,WAAW,MAAM;AAC3B,IAAA,MAAMA,IAAM,GAAA,IAAI,GAAI,CAAA,MAAA,CAAO,SAAS,IAAI,CAAA;AACxC,IAAA,IAAI,KAAM,CAAA,OAAA,IAAW,KAAM,CAAA,OAAA,CAAQ,mCAAqC,EAAA;AACtE,MAAAA,KAAI,YAAa,CAAA,GAAA;AAAA,QACf,SAAA;AAAA,QACA,KAAM,CAAA,OAAA,CAAQ,mCAAoC,CAAA,EAAA,CAAG,QAAS;AAAA,OAChE;AAAA;AAEF,IAAOA,OAAAA,IAAAA;AAAA,GACR,CAAA;AAED,EAAA,SAAS,UAAU,EAA4C,EAAA;AAC7D,IAAA,OAAO,WAAW,MAAM,KAAA,CAAM,OAAO,CAAE,CAAA,SAAA,CAAU,EAAE,CAAE,CAAA,WAAA;AAAA;AAGvD,EAAA,MAAA,CAAO,OAAO,OAAS,EAAA;AAAA,IACrB;AAAA,GACD,CAAA;AAED,EAAA,YAAA,CAAa,MAAM;AACjB,IAAI,IAAA,CAAC,MAAM,aAAe,EAAA;AAC1B,IAAA,MAAA,CAAO,OAAQ,CAAA,YAAA,CAAa,IAAM,EAAA,EAAA,EAAI,KAAK,CAAA;AAAA,GAC5C,CAAA;AACH","file":"product-info.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, createMemo, observable } from \"solid-js\";\n\nimport { provideProductContext } from \"../hooks/index.js\";\n\nimport type { Product } from \"../types.js\";\n\ntype Props = {\n product?: Product;\n isProductPage?: boolean;\n};\n\nexport const Name = `product-info`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n if (!props.product)\n return console.warn(`${Name}: product attribute is required`);\n if (!props.product.variants)\n return console.warn(`${Name}: product attribute needs variants array`);\n if (!props.product.selected_or_first_available_variant)\n return console.warn(\n `${Name}: product attribute needs selected or first available variant object`,\n );\n provideProductContext(props as any, element);\n\n const url = createMemo(() => {\n const url = new URL(window.location.href);\n if (props.product && props.product.selected_or_first_available_variant) {\n url.searchParams.set(\n \"variant\",\n props.product.selected_or_first_available_variant.id.toString(),\n );\n }\n return url;\n });\n\n function subscribe(cb: (product: Product | undefined) => void) {\n return observable(() => props.product).subscribe(cb).unsubscribe;\n }\n\n Object.assign(element, {\n subscribe,\n });\n\n createEffect(() => {\n if (!props.isProductPage) return;\n window.history.replaceState(null, \"\", url());\n });\n};\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createEffect, on, onCleanup } from 'solid-js';
|
|
2
2
|
import { useProductOptions } from '../hooks/index.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const Name = `product-option-group`;
|
|
5
|
+
const Component = (props, { element }) => {
|
|
5
6
|
const [context, methods] = useProductOptions(element);
|
|
6
7
|
createEffect(
|
|
7
8
|
on(
|
|
@@ -63,6 +64,6 @@ const ProductOptionGroup = (props, { element }) => {
|
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
export {
|
|
67
|
+
export { Component, Name };
|
|
67
68
|
//# sourceMappingURL=product-option-group.js.map
|
|
68
69
|
//# sourceMappingURL=product-option-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/product-option-group.ts"],"names":[],"mappings":";;;AAYO,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/product-option-group.ts"],"names":[],"mappings":";;;AAYO,MAAM,IAAO,GAAA,CAAA,oBAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAA,MAAM,CAAC,OAAA,EAAS,OAAO,CAAA,GAAI,kBAAkB,OAAO,CAAA;AAEpD,EAAA,YAAA;AAAA,IACE,EAAA;AAAA,MACE,OAAO;AAAA,QACL,cAAgB,EAAA,OAAA,CAAQ,eAAgB,CAAA,KAAA,CAAM,WAAW,CAAC,C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A,CAAa,MAAM;AACjB,IAAA,MAAM,WAAW,KAAM,CAAA,QAAA;AAEvB,IAAA,SAAS,aAAa,KAAc,EAAA;AAClC,MAAA,MAAM,SAAS,KAAM,CAAA,MAAA;AACrB,MAAA,IAAI,CAAC,MAAQ,EAAA;AACb,MAAA,MAAM,iBAAiB,MAAO,CAAA,KAAA;AAC9B,MAAA,IAAI,OAAQ,CAAA,eAAA,CAAgB,QAAW,GAAA,CAAC,MAAM,cAAgB,EAAA;AAE9D,MAAQ,OAAA,CAAA,aAAA;AAAA,QACN,IAAI,YAAY,gBAAkB,EAAA;AAAA,UAChC,MAAQ,EAAA;AAAA,YACN,OAAO,KAAM,CAAA,IAAA;AAAA,YACb,QAAA;AAAA,YACA;AAAA,WACF;AAAA,UACA,OAAS,EAAA;AAAA,SACV;AAAA,OACH;AAEA,MAAA,OAAA,CAAQ,OAAQ,CAAA,YAAA,CAAa,cAAgB,EAAA,QAAA,GAAW,CAAC,CAAA;AAAA;AAG3D,IAAQ,OAAA,CAAA,gBAAA,CAAiB,UAAU,YAAY,CAAA;AAE/C,IAAA,OAAO,UAAU,MAAM;AACrB,MAAQ,OAAA,CAAA,mBAAA,CAAoB,UAAU,YAAY,CAAA;AAAA,KACnD,CAAA;AAAA,GACF,CAAA;AACH","file":"product-option-group.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, on, onCleanup } from \"solid-js\";\n\nimport { useProductOptions } from \"../hooks/index.js\";\n\ntype Props = {\n position: number;\n name: string;\n inputType: \"radio\" | \"select\";\n};\n\nexport const Name = `product-option-group`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const [context, methods] = useProductOptions(element);\n\n createEffect(\n on(\n () => ({\n selectedOption: context.selectedOptions[props.position - 1],\n position: props.position,\n name: props.name,\n inputType: props.inputType,\n }),\n ({ selectedOption, position, name, inputType }) => {\n if (inputType !== \"radio\" && inputType !== \"select\") return;\n\n const optionName = `${name}-${position}`;\n\n if (inputType === \"radio\") {\n const inputs = element.querySelectorAll<HTMLInputElement>(\n `input[name=\"${optionName}\"]`,\n );\n inputs.forEach((input) => {\n const prevValue = input.checked;\n if (input.value === selectedOption) input.checked = true;\n else input.checked = false;\n if (prevValue !== input.checked) {\n input.dispatchEvent(new Event(\"change\", { bubbles: true }));\n }\n });\n return;\n }\n\n const select = element.querySelector<HTMLSelectElement>(\n `select[name=\"${optionName}\"]`,\n );\n if (!select || !selectedOption) return;\n select.value = selectedOption;\n select.dispatchEvent(new Event(\"change\", { bubbles: true }));\n },\n ),\n );\n\n createEffect(() => {\n const position = props.position;\n\n function handleChange(event: Event) {\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const selectedOption = target.value;\n if (context.selectedOptions[position - 1] === selectedOption) return;\n\n element.dispatchEvent(\n new CustomEvent(\"option-updated\", {\n detail: {\n group: props.name,\n position: position,\n selectedOption,\n },\n bubbles: true,\n }),\n );\n\n methods.options.updateOption(selectedOption, position - 1);\n }\n\n element.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n element.removeEventListener(\"change\", handleChange);\n });\n });\n};\n"]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { provideProductOptionsContext } from '../hooks/index.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Name = `product-options`;
|
|
4
|
+
const Component = (props, { element }) => {
|
|
4
5
|
if (!props.selectedOptions)
|
|
5
|
-
return console.warn(
|
|
6
|
-
"product-options: selected-options attribute is required"
|
|
7
|
-
);
|
|
6
|
+
return console.warn(`${Name}: selected-options attribute is required`);
|
|
8
7
|
provideProductOptionsContext(props, element);
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
export {
|
|
10
|
+
export { Component, Name };
|
|
12
11
|
//# sourceMappingURL=product-options.js.map
|
|
13
12
|
//# sourceMappingURL=product-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/product-options.ts"],"names":[],"mappings":";;AAOO,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/product-options.ts"],"names":[],"mappings":";;AAOO,MAAM,IAAO,GAAA,CAAA,eAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAA,IAAI,CAAC,KAAM,CAAA,eAAA;AACT,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,CAAG,EAAA,IAAI,CAA0C,wCAAA,CAAA,CAAA;AACvE,EAAA,4BAAA,CAA6B,OAAO,OAAO,CAAA;AAC7C","file":"product-options.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { provideProductOptionsContext } from \"../hooks/index.js\";\n\ntype Props = {\n selectedOptions: string[];\n};\n\nexport const Name = `product-options`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n if (!props.selectedOptions)\n return console.warn(`${Name}: selected-options attribute is required`);\n provideProductOptionsContext(props, element);\n};\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createEffect, onCleanup } from 'solid-js';
|
|
2
2
|
import { useProduct, useProductOptions } from '../hooks/index.js';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const Name = `product-variant-input`;
|
|
5
|
+
const Component = (props, { element }) => {
|
|
5
6
|
const [productContext, productContextMethods] = useProduct(element);
|
|
6
7
|
const [_, optionsMethods] = useProductOptions(element);
|
|
7
8
|
createEffect(() => {
|
|
@@ -34,8 +35,7 @@ const ProductVariantInput = (props, { element }) => {
|
|
|
34
35
|
target = element.querySelector(props.target);
|
|
35
36
|
if (!target)
|
|
36
37
|
target = element.querySelector("input[name='id']");
|
|
37
|
-
if (!target)
|
|
38
|
-
return console.warn("product-variant-input: target input not found");
|
|
38
|
+
if (!target) return console.warn(`${Name}: target input not found`);
|
|
39
39
|
const variantId = productContext?.product?.selected_or_first_available_variant?.id;
|
|
40
40
|
if (!variantId) return;
|
|
41
41
|
if (target.value === variantId.toString()) return;
|
|
@@ -44,6 +44,6 @@ const ProductVariantInput = (props, { element }) => {
|
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export {
|
|
47
|
+
export { Component, Name };
|
|
48
48
|
//# sourceMappingURL=product-variant-input.js.map
|
|
49
49
|
//# sourceMappingURL=product-variant-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/product-variant-input.ts"],"names":["target","variant"],"mappings":";;;AAWO,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/product-variant-input.ts"],"names":["target","variant"],"mappings":";;;AAWO,MAAM,IAAO,GAAA,CAAA,qBAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAA,MAAM,CAAC,cAAA,EAAgB,qBAAqB,CAAA,GAAI,WAAW,OAAO,CAAA;AAClE,EAAA,MAAM,CAAC,CAAA,EAAG,cAAc,CAAA,GAAI,kBAAkB,OAAO,CAAA;AAErD,EAAA,YAAA,CAAa,MAAM;AACjB,IAAA,IAAI,MAAS,GAAA,IAAA;AACb,IAAA,IAAI,MAAM,MAAQ,EAAA,MAAA,GAAS,OAAQ,CAAA,aAAA,CAAc,MAAM,MAAM,CAAA;AAC7D,IAAI,IAAA,CAAC,QAAiB,MAAA,GAAA,OAAA;AAEtB,IAAA,MAAM,iBAAiB,KAAM,CAAA,cAAA;AAE7B,IAAA,SAAS,aAAa,KAAc,EAAA;AAClC,MAAI,IAAA,cAAA,QAAsB,cAAe,EAAA;AACzC,MAAA,MAAMA,UAAS,KAAM,CAAA,MAAA;AACrB,MAAA,IAAI,CAACA,OAAQ,EAAA;AACb,MAAA,MAAM,QAAQA,OAAO,CAAA,KAAA;AACrB,MACE,IAAA,KAAA,KACA,cAAgB,EAAA,OAAA,EAAS,mCAAqC,EAAA,EAAA;AAE9D,QAAA;AACF,MAAM,MAAA,OAAA,GAAU,cAAgB,EAAA,OAAA,EAAS,QAAS,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","file":"product-variant-input.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, onCleanup } from \"solid-js\";\n\nimport { useProduct, useProductOptions } from \"../hooks/index.js\";\n\ntype Props = {\n target: string | null;\n preventDefault?: boolean;\n};\n\nexport const Name = `product-variant-input`;\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const [productContext, productContextMethods] = useProduct(element);\n const [_, optionsMethods] = useProductOptions(element);\n\n createEffect(() => {\n let target = null;\n if (props.target) target = element.querySelector(props.target);\n if (!target) target = element;\n\n const preventDefault = props.preventDefault;\n\n function handleChange(event: Event) {\n if (preventDefault) event.preventDefault();\n const target = event.target as HTMLInputElement;\n if (!target) return;\n const value = target.value;\n if (\n value ===\n productContext?.product?.selected_or_first_available_variant?.id\n )\n return;\n const variant = productContext?.product?.variants.find(\n (variant) => variant.id.toString() === value.toString(),\n );\n if (!variant) return;\n if (optionsMethods) optionsMethods.options.update(variant.options);\n else productContextMethods.variant.update(variant.id);\n }\n\n target.addEventListener(\"change\", handleChange);\n\n return onCleanup(() => {\n target.removeEventListener(\"change\", handleChange);\n });\n });\n\n createEffect(() => {\n let target = null;\n if (props.target)\n target = element.querySelector<HTMLInputElement>(props.target);\n if (!target)\n target = element.querySelector<HTMLInputElement>(\"input[name='id']\");\n if (!target) return console.warn(`${Name}: target input not found`);\n\n const variantId =\n productContext?.product?.selected_or_first_available_variant?.id;\n if (!variantId) return;\n if (target.value === variantId.toString()) return;\n target.value = variantId.toString();\n target.dispatchEvent(new Event(\"change\", { bubbles: true }));\n });\n};\n"]}
|
|
@@ -2,12 +2,13 @@ import { createMemo, Show } from 'solid-js';
|
|
|
2
2
|
import html from 'solid-js/html';
|
|
3
3
|
import { useProduct } from '../hooks/index.js';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const Name = `product-variant-render`;
|
|
6
|
+
const Component = (_, { element }) => {
|
|
6
7
|
const templates = Array.from(
|
|
7
8
|
element.querySelectorAll("template[variant-id]")
|
|
8
9
|
);
|
|
9
10
|
if (!templates.length)
|
|
10
|
-
return console.warn(
|
|
11
|
+
return console.warn(`${Name}: No variant templates found`);
|
|
11
12
|
const [state] = useProduct(element);
|
|
12
13
|
const fallbackChildren = Array.from(element.children);
|
|
13
14
|
const activeVariantTemplate = createMemo(() => {
|
|
@@ -31,6 +32,6 @@ const ProductVariantRender = (_, { element }) => {
|
|
|
31
32
|
`;
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
export {
|
|
35
|
+
export { Component, Name };
|
|
35
36
|
//# sourceMappingURL=product-variant-render.js.map
|
|
36
37
|
//# sourceMappingURL=product-variant-render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/product-variant-render.ts"],"names":[],"mappings":";;;;AASO,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/product-variant-render.ts"],"names":[],"mappings":";;;;AASO,MAAM,IAAO,GAAA,CAAA,sBAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,CAAG,EAAA,EAAE,SAAc,KAAA;AACxE,EAAA,MAAM,YAAY,KAAM,CAAA,IAAA;AAAA,IACtB,OAAA,CAAQ,iBAAsC,sBAAsB;AAAA,GACtE;AACA,EAAA,IAAI,CAAC,SAAU,CAAA,MAAA;AACb,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,CAAG,EAAA,IAAI,CAA8B,4BAAA,CAAA,CAAA;AAC3D,EAAA,MAAM,CAAC,KAAK,CAAI,GAAA,UAAA,CAAW,OAAO,CAAA;AAElC,EAAA,MAAM,gBAAmB,GAAA,KAAA,CAAM,IAAK,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAEpD,EAAM,MAAA,qBAAA,GAAwB,WAAW,MAAM;AAC7C,IAAM,MAAA,SAAA,GAAY,KAAM,CAAA,OAAA,EAAS,mCAAqC,EAAA,EAAA;AACtE,IAAI,IAAA,CAAC,WAAkB,OAAA,IAAA;AACvB,IAAA,MAAM,WAAW,SAAU,CAAA,IAAA;AAAA,MACzB,CAAC,CAAM,KAAA,CAAA,CAAE,aAAa,YAAY,CAAA,KAAM,GAAG,SAAS,CAAA;AAAA,KACtD;AACA,IAAA,OAAO,QAAY,IAAA,IAAA;AAAA,GACpB,CAAA;AAED,EAAQ,OAAA,CAAA,eAAA,CAAgB,GAAG,EAAE,CAAA;AAE7B,EAAO,OAAA,IAAA;AAAA,KAAA,EACF,IAAI;AAAA,WAAA,EACE,MAAM,CAAC,CAAC,qBAAA,EAAuB;AAAA,eAAA,EAC3B,gBAAgB;AAAA;AAAA,MAAA,EAEzB,MACA,KAAM,CAAA,IAAA;AAAA,IACJ,uBAAyB,EAAA,OAAA,CAAQ,UAAU,IAAI,CAAA,CAAE,cAAc;AAAC,GACjE;AAAA;AAAA,EAAA,CAAA;AAGT","file":"product-variant-render.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createMemo, Show } from \"solid-js\";\nimport html from \"solid-js/html\";\n\nimport { useProduct } from \"../hooks/index.js\";\n\ntype Props = {};\n\nexport const Name = `product-variant-render`;\n\nexport const Component: CorrectComponentType<Props> = (_, { element }) => {\n const templates = Array.from(\n element.querySelectorAll<HTMLTemplateElement>(\"template[variant-id]\"),\n );\n if (!templates.length)\n return console.warn(`${Name}: No variant templates found`);\n const [state] = useProduct(element);\n\n const fallbackChildren = Array.from(element.children);\n\n const activeVariantTemplate = createMemo(() => {\n const variantId = state.product?.selected_or_first_available_variant?.id;\n if (!variantId) return null;\n const template = templates.find(\n (t) => t.getAttribute(\"variant-id\") === `${variantId}`,\n );\n return template || null;\n });\n\n element.replaceChildren(...[]);\n\n return html`\n <${Show}\n when=${() => !!activeVariantTemplate()}\n fallback=${fallbackChildren}\n >\n ${() =>\n Array.from(\n activeVariantTemplate()?.content.cloneNode(true).childNodes || [],\n )}\n <//>\n `;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, provide, consume } from 'component-register';
|
|
2
2
|
import { splitProps, mergeProps, untrack } from 'solid-js';
|
|
3
|
-
import { getContextFromProvider } from '@brytdesigns/web-component-utils';
|
|
3
|
+
import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
|
|
4
4
|
|
|
5
5
|
function initializeProductContext(props) {
|
|
6
6
|
const [privateProps, publicProps] = splitProps(props, ["root"]);
|
|
@@ -62,7 +62,8 @@ const getProductContext = (element) => {
|
|
|
62
62
|
);
|
|
63
63
|
return useProductContext(context);
|
|
64
64
|
};
|
|
65
|
+
const withProductElementContext = createWithElementContext(ProductContextState);
|
|
65
66
|
|
|
66
|
-
export { getProductContext, provideProductContext, useProduct, useProductContext };
|
|
67
|
+
export { getProductContext, provideProductContext, useProduct, useProductContext, withProductElementContext };
|
|
67
68
|
//# sourceMappingURL=useProduct.js.map
|
|
68
69
|
//# sourceMappingURL=useProduct.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useProduct.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useProduct.ts"],"names":[],"mappings":";;;;AAuBA,SAAS,yBAAyB,KAA6B,EAAA;AAC7D,EAAM,MAAA,CAAC,cAAc,WAAW,CAAA,GAAI,WAAW,KAAO,EAAA,CAAC,MAAM,CAAC,CAAA;AAC9D,EAAA,MAAM,KAAQ,GAAA,UAAA,CAAW,WAAa,EAAA,EAAE,CAAA;AAExC,EAAA,SAAS,sBAAsB,SAA4B,EAAA;AACzD,IAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,MAAM,KAAA,EAAO,OAAO,CAAA;AAC5C,IACE,IAAA,OAAO,SAAS,mCAAwC,KAAA,WAAA,IACxD,OAAO,OAAY,KAAA,WAAA,IACnB,OAAO,OAAA,EAAS,QAAa,KAAA,WAAA;AAE7B,MAAA;AACF,IAAM,MAAA,UAAA,GAAa,QAAQ,QAAS,CAAA,IAAA;AAAA,MAClC,CAAC,OAAY,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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,6 +1,6 @@
|
|
|
1
1
|
import { createContext, provide, consume } from 'component-register';
|
|
2
2
|
import { splitProps, createEffect, untrack, mergeProps } from 'solid-js';
|
|
3
|
-
import { getContextFromProvider } from '@brytdesigns/web-component-utils';
|
|
3
|
+
import { createWithElementContext, getContextFromProvider } from '@brytdesigns/web-component-core/utils';
|
|
4
4
|
import { useProduct } from './useProduct.js';
|
|
5
5
|
|
|
6
6
|
function initializeProductOptionsContext(props) {
|
|
@@ -65,7 +65,8 @@ const getProductOptionsContext = (element) => {
|
|
|
65
65
|
);
|
|
66
66
|
return useProductOptionsContext(context);
|
|
67
67
|
};
|
|
68
|
+
const withProductOptionsElementContext = createWithElementContext(ProductOptionsContextState);
|
|
68
69
|
|
|
69
|
-
export { getProductOptionsContext, provideProductOptionsContext, useProductOptions, useProductOptionsContext };
|
|
70
|
+
export { getProductOptionsContext, provideProductOptionsContext, useProductOptions, useProductOptionsContext, withProductOptionsElementContext };
|
|
70
71
|
//# sourceMappingURL=useProductOptions.js.map
|
|
71
72
|
//# sourceMappingURL=useProductOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useProductOptions.ts"],"names":["variant"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../../../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AAA;AAAA,QACP,MAAQ,EAAA,qBAAA;AAAA,QACR,YAAc,EAAA;AAAA;AAChB;AACF,GACF;AACF;AAEA,MAAM,0BAA6B,GAAA,aAAA;AAAA,EACjC;AACF,CAAA;AAEa,MAAA,4BAAA,GAA+B,CAC1C,YAAA,EACA,OAC0B,KAAA;AAC1B,EAAA,MAAM,QAAQ,UAAW,CAAA,YAAA,EAAc,EAAE,IAAA,EAAM,SAAS,CAAA;AACxD,EAAO,OAAA,OAAA,CAAQ,0BAA4B,EAAA,KAAA,EAAO,OAAO,CAAA;AAC3D;AAEa,MAAA,wBAAA,GAA2B,CAAC,OAAmC,KAAA;AAC1E,EAAO,OAAA,OAAA;AACT;AAEa,MAAA,iBAAA,GAAoB,CAAC,OAA0C,KAAA;AAC1E,EAAA,MAAM,OAAiC,GAAA,OAAA;AAAA,IACrC,0BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAA,MAAM,OAAQ,CAAA,KAAA;AAAA,MACZ;AAAA,KACF;AAAA;AAGF,EAAA,OAAO,yBAAyB,OAAO,CAAA;AACzC;AAEa,MAAA,wBAAA,GAA2B,CAAC,OAAqB,KAAA;AAC5D,EAAA,MAAM,OAAU,GAAA,sBAAA;AAAA,IACd,0BAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,yBAAyB,OAAO,CAAA;AACzC;AAEa,MAAA,gCAAA,GAAmC,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"]}
|
package/dist/main/index.d.ts
CHANGED
|
@@ -31,6 +31,16 @@ export declare const getProductContext: (element: Element) => readonly [
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
];
|
|
34
|
+
export declare const withProductElementContext: <D extends unknown>(selector: string | import("solid-js").Accessor<string>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
|
|
35
|
+
{
|
|
36
|
+
product: Product;
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
readonly variant: {
|
|
40
|
+
readonly update: (variantId: string | number) => void;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
], dependencies: D) => void | (() => void)) => void;
|
|
34
44
|
export declare const useProductOptions: (element: HTMLElement & ICustomElement) => readonly [
|
|
35
45
|
{
|
|
36
46
|
selectedOptions: string[];
|
|
@@ -53,5 +63,16 @@ export declare const getProductOptionsContext: (element: Element) => readonly [
|
|
|
53
63
|
};
|
|
54
64
|
}
|
|
55
65
|
];
|
|
66
|
+
export declare const withProductOptionsElementContext: <D extends unknown>(selector: string | import("solid-js").Accessor<string>, dependencies: import("solid-js").Accessor<D> | undefined, cb: (context: readonly [
|
|
67
|
+
{
|
|
68
|
+
selectedOptions: string[];
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
readonly options: {
|
|
72
|
+
readonly update: (options: string[]) => void;
|
|
73
|
+
readonly updateOption: (option: string, index: number) => void;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
], dependencies: D) => void | (() => void)) => void;
|
|
56
77
|
|
|
57
78
|
export {};
|
package/dist/main/index.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { customShadowlessElement, correctElementType } from '@brytdesigns/web-component-utils';
|
|
1
|
+
import { customShadowlessElement, correctElementType } from '@brytdesigns/web-component-core/utils';
|
|
2
2
|
import { ProductInfo, ProductOptions, ProductOptionGroup, ProductVariantInput, ProductVariantRender } from './components/index.js';
|
|
3
|
-
export { getProductContext, getProductOptionsContext, useProduct, useProductOptions } from './hooks/index.js';
|
|
3
|
+
export { getProductContext, getProductOptionsContext, useProduct, useProductOptions, withProductElementContext, withProductOptionsElementContext } from './hooks/index.js';
|
|
4
4
|
|
|
5
5
|
customShadowlessElement(
|
|
6
|
-
|
|
6
|
+
ProductInfo.Name,
|
|
7
7
|
{
|
|
8
8
|
product: void 0,
|
|
9
9
|
isProductPage: false
|
|
10
10
|
},
|
|
11
|
-
correctElementType(ProductInfo)
|
|
11
|
+
correctElementType(ProductInfo.Component)
|
|
12
12
|
);
|
|
13
13
|
customShadowlessElement(
|
|
14
|
-
|
|
14
|
+
ProductOptions.Name,
|
|
15
15
|
{
|
|
16
16
|
selectedOptions: []
|
|
17
17
|
},
|
|
18
|
-
correctElementType(ProductOptions)
|
|
18
|
+
correctElementType(ProductOptions.Component)
|
|
19
19
|
);
|
|
20
20
|
customShadowlessElement(
|
|
21
|
-
|
|
21
|
+
ProductOptionGroup.Name,
|
|
22
22
|
{
|
|
23
23
|
position: 0,
|
|
24
24
|
name: "",
|
|
25
25
|
inputType: "radio"
|
|
26
26
|
},
|
|
27
|
-
correctElementType(ProductOptionGroup)
|
|
27
|
+
correctElementType(ProductOptionGroup.Component)
|
|
28
28
|
);
|
|
29
29
|
customShadowlessElement(
|
|
30
|
-
|
|
30
|
+
ProductVariantInput.Name,
|
|
31
31
|
{
|
|
32
32
|
target: "",
|
|
33
33
|
preventDefault: true
|
|
34
34
|
},
|
|
35
|
-
correctElementType(ProductVariantInput)
|
|
35
|
+
correctElementType(ProductVariantInput.Component)
|
|
36
36
|
);
|
|
37
37
|
customShadowlessElement(
|
|
38
|
-
|
|
38
|
+
ProductVariantRender.Name,
|
|
39
39
|
{},
|
|
40
|
-
correctElementType(ProductVariantRender)
|
|
40
|
+
correctElementType(ProductVariantRender.Component)
|
|
41
41
|
);
|
|
42
42
|
//# sourceMappingURL=index.js.map
|
|
43
43
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAaA,uBAAA;AAAA,EACE,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAaA,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\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brytdesigns/shopify-product-info-components",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"component-register": "^0.8.7",
|
|
23
23
|
"solid-element": "^1.9.1",
|
|
24
24
|
"solid-js": "^1.9.7",
|
|
25
|
-
"@brytdesigns/web-component-
|
|
25
|
+
"@brytdesigns/web-component-core": "1.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"dts-bundle-generator": "^9.5.1",
|