@brytdesigns/shopify-ajax-cart-components 1.3.14 → 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.
Files changed (50) hide show
  1. package/dist/main/components/cart-context.js +19 -15
  2. package/dist/main/components/cart-context.js.map +1 -1
  3. package/dist/main/components/cart-data-array-injection.js +70 -81
  4. package/dist/main/components/cart-data-array-injection.js.map +1 -1
  5. package/dist/main/components/cart-data-array-item.js +16 -17
  6. package/dist/main/components/cart-data-array-item.js.map +1 -1
  7. package/dist/main/components/cart-data-array.js +64 -55
  8. package/dist/main/components/cart-data-array.js.map +1 -1
  9. package/dist/main/components/cart-data-conditions.js +61 -100
  10. package/dist/main/components/cart-data-conditions.js.map +1 -1
  11. package/dist/main/components/cart-data-injection.js +78 -84
  12. package/dist/main/components/cart-data-injection.js.map +1 -1
  13. package/dist/main/components/cart-data-listener-status.js +32 -31
  14. package/dist/main/components/cart-data-listener-status.js.map +1 -1
  15. package/dist/main/components/cart-data-listener.js +98 -155
  16. package/dist/main/components/cart-data-listener.js.map +1 -1
  17. package/dist/main/components/cart-data.js +29 -25
  18. package/dist/main/components/cart-data.js.map +1 -1
  19. package/dist/main/components/cart-loading-state.js +51 -37
  20. package/dist/main/components/cart-loading-state.js.map +1 -1
  21. package/dist/main/components/index.js +10 -22
  22. package/dist/main/hooks/index.js +24 -25
  23. package/dist/main/hooks/index.js.map +1 -1
  24. package/dist/main/hooks/useAjaxCart.js +14 -18
  25. package/dist/main/hooks/useAjaxCart.js.map +1 -1
  26. package/dist/main/hooks/useListenerStatus.js +23 -28
  27. package/dist/main/hooks/useListenerStatus.js.map +1 -1
  28. package/dist/main/index.d.ts +5182 -4789
  29. package/dist/main/index.js +56 -82
  30. package/dist/main/index.js.map +1 -1
  31. package/dist/main/utils/formatValue.js +14 -18
  32. package/dist/main/utils/formatValue.js.map +1 -1
  33. package/dist/main/utils/getTargetElement.js +10 -9
  34. package/dist/main/utils/getTargetElement.js.map +1 -1
  35. package/dist/main/utils/getTemplateContent.js +6 -7
  36. package/dist/main/utils/getTemplateContent.js.map +1 -1
  37. package/dist/main/utils/getValueFromPath.js +9 -10
  38. package/dist/main/utils/getValueFromPath.js.map +1 -1
  39. package/dist/main/utils/parseNestedObject.js +48 -28
  40. package/dist/main/utils/parseNestedObject.js.map +1 -1
  41. package/dist/main/utils/safeInjection.js +120 -0
  42. package/dist/main/utils/safeInjection.js.map +1 -0
  43. package/dist/main/utils/traverseObject.js +13 -15
  44. package/dist/main/utils/traverseObject.js.map +1 -1
  45. package/package.json +9 -8
  46. package/dist/esm/index.js +0 -883
  47. package/dist/esm/index.js.map +0 -1
  48. package/dist/main/components/index.js.map +0 -1
  49. package/dist/main/utils/index.js +0 -8
  50. package/dist/main/utils/index.js.map +0 -1
@@ -1,18 +1,22 @@
1
- import { createEffect } from 'solid-js';
2
- import { provideAjaxCartContext } from '../hooks/useAjaxCart.js';
3
- import { traverseObject } from '../utils/index.js';
4
-
5
- const Name = "cart-context";
6
- const Component = (props, { element }) => {
7
- const cart = provideAjaxCartContext(element);
8
- createEffect(() => {
9
- if (!props.debug) return;
10
- const c = cart();
11
- traverseObject(c);
12
- console.log(`${Name}:updated!`, c);
13
- });
1
+ import { provideAjaxCartContext } from "../hooks/useAjaxCart.js";
2
+ import { traverseObject } from "../utils/traverseObject.js";
3
+ import { createGuardedEffect } from "@brytdesigns/web-component-core/utils";
4
+ import { untrack } from "solid-js";
5
+ //#region src/components/cart-context.ts
6
+ var Name = "cart-context";
7
+ var Component = (props, { element }) => {
8
+ const debug = untrack(() => props.debug);
9
+ const cart = provideAjaxCartContext(element);
10
+ createGuardedEffect(() => ({
11
+ debug,
12
+ cart: cart()
13
+ }), ({ debug, cart: c }) => {
14
+ if (!debug) return;
15
+ traverseObject(c);
16
+ console.log(`${Name}:updated!`, c);
17
+ });
14
18
  };
15
-
19
+ //#endregion
16
20
  export { Component, Name };
17
- //# sourceMappingURL=cart-context.js.map
21
+
18
22
  //# sourceMappingURL=cart-context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/cart-context.ts"],"names":[],"mappings":";;;;AAUO,MAAM,IAAO,GAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EAAM,MAAA,IAAA,GAAO,uBAAuB,OAAO,CAAA;AAE3C,EAAA,YAAA,CAAa,MAAM;AACjB,IAAI,IAAA,CAAC,MAAM,KAAO,EAAA;AAClB,IAAA,MAAM,IAAI,IAAK,EAAA;AAEf,IAAA,cAAA,CAAe,CAAC,CAAA;AAChB,IAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,EAAG,IAAI,CAAA,SAAA,CAAA,EAAa,CAAC,CAAA;AAAA,GAClC,CAAA;AACH","file":"cart-context.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport { createEffect, on } from \"solid-js\";\nimport { provideAjaxCartContext } from \"../hooks/useAjaxCart.js\";\nimport { traverseObject } from \"../utils/index.js\";\n\nexport type Props = {\n debug?: boolean;\n};\n\nexport const Name = \"cart-context\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const cart = provideAjaxCartContext(element);\n\n createEffect(() => {\n if (!props.debug) return;\n const c = cart();\n // This will listen to every change within the cart object.\n traverseObject(c);\n console.log(`${Name}:updated!`, c);\n });\n};\n"]}
1
+ {"version":3,"file":"cart-context.js","names":[],"sources":["../../../src/components/cart-context.ts"],"sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { createGuardedEffect } from \"@brytdesigns/web-component-core/utils\";\n\nimport { untrack } from \"solid-js\";\nimport { provideAjaxCartContext } from \"../hooks/useAjaxCart.js\";\nimport { traverseObject } from \"../utils/index.js\";\n\nexport type Props = {\n\tdebug?: boolean;\n};\n\nexport const Name = \"cart-context\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\t// `debug` is a mount-time switch; snapshot it rather than tracking.\n\tconst debug = untrack(() => props.debug);\n\tconst cart = provideAjaxCartContext(element);\n\n\tcreateGuardedEffect(\n\t\t() => ({ debug: debug, cart: cart() }),\n\t\t({ debug, cart: c }) => {\n\t\t\tif (!debug) return;\n\t\t\t// This will listen to every change within the cart object.\n\t\t\ttraverseObject(c);\n\t\t\tconsole.log(`${Name}:updated!`, c);\n\t\t},\n\t);\n};\n"],"mappings":";;;;;AAWA,IAAa,OAAO;AAEpB,IAAa,aAA0C,OAAO,EAAE,cAAc;CAE7E,MAAM,QAAQ,cAAc,MAAM,KAAK;CACvC,MAAM,OAAO,uBAAuB,OAAO;CAE3C,2BACQ;EAAS;EAAO,MAAM,KAAK;CAAE,KACnC,EAAE,OAAO,MAAM,QAAQ;EACvB,IAAI,CAAC,OAAO;EAEZ,eAAe,CAAC;EAChB,QAAQ,IAAI,GAAG,KAAK,YAAY,CAAC;CAClC,CACD;AACD"}
@@ -1,84 +1,73 @@
1
- import { getTemplateContent, getTargetElement } from '../utils/index.js';
2
- import { createMemo, mapArray, createEffect, on } from 'solid-js';
3
- import { useCartPath, provideCartPathContext, useCartValue } from '../hooks/index.js';
4
- import html from 'solid-js/html';
5
-
6
- const Name = "cart-data-array-injection";
7
- const Component = (props, { element }) => {
8
- const itemTemplate = getTemplateContent(element, "item");
9
- if (!itemTemplate)
10
- return console.warn(
11
- `${Name}: No template found with a property of 'item'.`
12
- );
13
- if (!props.arrayPath) return console.warn(`${Name}: No array path provided.`);
14
- const mergedProps = {
15
- element,
16
- path: () => props.arrayPath
17
- };
18
- const fullPath = useCartPath(mergedProps);
19
- provideCartPathContext({
20
- element,
21
- path: fullPath
22
- });
23
- const value = useCartValue({
24
- path: fullPath,
25
- element
26
- });
27
- const arrayValue = createMemo(() => {
28
- const v = value();
29
- if (!v) {
30
- console.warn(`${Name}: value is null or undefined at path ${fullPath()}`);
31
- return null;
32
- }
33
- if (!Array.isArray(v)) {
34
- console.warn(`${Name}: value is not an array at path ${fullPath()}`);
35
- return null;
36
- }
37
- if (props.reverse) {
38
- return v.toReversed();
39
- }
40
- return v;
41
- });
42
- const children = createMemo(
43
- mapArray(arrayValue, (_, idx) => {
44
- const fragment = itemTemplate.cloneNode(true);
45
- const container = fragment instanceof DocumentFragment ? fragment : null;
46
- if (props.wrapInnerChild && container) {
47
- const firstElement = container.firstElementChild;
48
- if (!firstElement) return null;
49
- const children2 = Array.from(firstElement.children);
50
- const wrapper = html`
51
- <cart-data-array-item item-index=${() => `${idx()}`}>
52
- ${() => Array.from(children2)}
53
- </cart-data-array-item>
54
- `;
55
- firstElement.replaceChildren(
56
- Array.isArray(wrapper) ? wrapper.at(0) : wrapper
57
- );
58
- return firstElement;
59
- }
60
- })
61
- );
62
- createEffect(
63
- on(
64
- () => {
65
- const rootElement = element;
66
- return {
67
- target: getTargetElement(rootElement, props.target),
68
- children: children()
69
- };
70
- },
71
- ({ children: children2, target }) => {
72
- if (!target) return;
73
- const filteredChildren = children2.filter(
74
- (v) => v !== null && v !== void 0
75
- );
76
- target.replaceChildren(...filteredChildren);
77
- }
78
- )
79
- );
1
+ import { getTargetElement } from "../utils/getTargetElement.js";
2
+ import { getTemplateContent } from "../utils/getTemplateContent.js";
3
+ import { provideCartPathContext, useCartPath, useCartValue } from "../hooks/index.js";
4
+ import { createGuardedEffect } from "@brytdesigns/web-component-core/utils";
5
+ import { createMemo, mapArray, untrack } from "solid-js";
6
+ import { effect, getOwner, insert, setAttribute, template } from "@solidjs/web";
7
+ //#region src/components/cart-data-array-injection.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<cart-data-array-item>`, 1);
9
+ var Name = "cart-data-array-injection";
10
+ var Component = (props, { element }) => {
11
+ const itemTemplate = getTemplateContent(element, "item");
12
+ if (!itemTemplate) return console.warn(`${Name}: No template found with a property of 'item'.`);
13
+ if (untrack(() => !props.arrayPath)) return console.warn(`${Name}: No array path provided.`);
14
+ const fullPath = useCartPath({
15
+ element,
16
+ path: () => props.arrayPath
17
+ });
18
+ provideCartPathContext({
19
+ element,
20
+ path: fullPath
21
+ });
22
+ const value = useCartValue({
23
+ path: fullPath,
24
+ element
25
+ });
26
+ const arrayValue = createMemo(() => {
27
+ const v = value();
28
+ if (!v) {
29
+ console.warn(`${Name}: value is null or undefined at path ${fullPath()}`);
30
+ return null;
31
+ }
32
+ if (!Array.isArray(v)) {
33
+ console.warn(`${Name}: value is not an array at path ${fullPath()}`);
34
+ return null;
35
+ }
36
+ if (props.reverse) return v.toReversed();
37
+ return v;
38
+ });
39
+ const children = createMemo(mapArray(arrayValue, (_, idx) => {
40
+ const fragment = itemTemplate.cloneNode(true);
41
+ const container = fragment instanceof DocumentFragment ? fragment : null;
42
+ if (props.wrapInnerChild && container) {
43
+ const firstElement = container.firstElementChild;
44
+ if (!firstElement) return null;
45
+ const children = Array.from(firstElement.children);
46
+ var _el$ = _tmpl$();
47
+ _el$._$owner = getOwner();
48
+ insert(_el$, () => {
49
+ return Array.from(children);
50
+ });
51
+ effect(() => `${idx()}`, (_v$) => {
52
+ setAttribute(_el$, "item-index", _v$);
53
+ });
54
+ const wrapper = _el$;
55
+ firstElement.replaceChildren(Array.isArray(wrapper) ? wrapper.at(0) : wrapper);
56
+ return firstElement;
57
+ }
58
+ }));
59
+ createGuardedEffect(() => {
60
+ return {
61
+ target: getTargetElement(element, props.target),
62
+ children: children()
63
+ };
64
+ }, ({ children, target }) => {
65
+ if (!target) return;
66
+ const filteredChildren = children.filter((v) => v !== null && v !== void 0);
67
+ target.replaceChildren(...filteredChildren);
68
+ });
80
69
  };
81
-
70
+ //#endregion
82
71
  export { Component, Name };
83
- //# sourceMappingURL=cart-data-array-injection.js.map
72
+
84
73
  //# sourceMappingURL=cart-data-array-injection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/cart-data-array-injection.ts"],"names":["children"],"mappings":";;;;;AAwBO,MAAM,IAAO,GAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC5E,EA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AACA,QAAO,MAAA,CAAA,eAAA,CAAgB,GAAG,gBAAgB,CAAA;AAAA;AAC5C;AACF,GACF;AACF","file":"cart-data-array-injection.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { getTemplateContent, type Format } from \"../utils/index.js\";\n\nimport { createEffect, on, createMemo, mapArray } from \"solid-js\";\n\nimport {\n type CartPath,\n useCartPath,\n useCartValue,\n provideCartPathContext,\n} from \"../hooks/index.js\";\n\nimport { getTargetElement } from \"../utils/index.js\";\n\nimport html from \"solid-js/html\";\n\nexport type Props = {\n arrayPath: CartPath;\n wrapInnerChild: boolean;\n target: string;\n format?: Format;\n reverse?: boolean;\n};\n\nexport const Name = \"cart-data-array-injection\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n const itemTemplate = getTemplateContent(element, \"item\");\n if (!itemTemplate)\n return console.warn(\n `${Name}: No template found with a property of 'item'.`,\n );\n if (!props.arrayPath) return console.warn(`${Name}: No array path provided.`);\n const mergedProps = {\n element,\n path: () => props.arrayPath,\n };\n const fullPath = useCartPath(mergedProps);\n provideCartPathContext({\n element,\n path: fullPath,\n });\n\n const value = useCartValue({\n path: fullPath,\n element,\n });\n\n const arrayValue = createMemo(() => {\n const v = value();\n\n if (!v) {\n console.warn(`${Name}: value is null or undefined at path ${fullPath()}`);\n return null;\n }\n\n if (!Array.isArray(v)) {\n console.warn(`${Name}: value is not an array at path ${fullPath()}`);\n return null;\n }\n\n if (props.reverse) {\n return v.toReversed();\n }\n\n return v;\n });\n\n const children = createMemo(\n mapArray(arrayValue, (_, idx) => {\n const fragment = itemTemplate.cloneNode(true);\n const container = fragment instanceof DocumentFragment ? fragment : null;\n if (props.wrapInnerChild && container) {\n const firstElement = container.firstElementChild;\n if (!firstElement) return null;\n const children = Array.from(firstElement.children);\n\n const wrapper = html`\n <cart-data-array-item item-index=${() => `${idx()}`}>\n ${() => Array.from(children)}\n </cart-data-array-item>\n `;\n firstElement.replaceChildren(\n Array.isArray(wrapper) ? wrapper.at(0)! : wrapper,\n );\n\n return firstElement;\n }\n }),\n );\n\n createEffect(\n on(\n () => {\n const rootElement = element;\n return {\n target: getTargetElement(rootElement, props.target),\n children: children(),\n };\n },\n ({ children, target }) => {\n if (!target) return;\n const filteredChildren = children.filter(\n (v) => v !== null && v !== undefined,\n );\n target.replaceChildren(...filteredChildren);\n },\n ),\n );\n};\n"]}
1
+ {"version":3,"file":"cart-data-array-injection.js","names":["<cart-data-array-item item-index={`${idx()}`}>\n\t\t\t\t\t\t{Array.from(children)}\n\t\t\t\t\t</cart-data-array-item>"],"sources":["../../../src/components/cart-data-array-injection.tsx"],"sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { createGuardedEffect } from \"@brytdesigns/web-component-core/utils\";\nimport { createMemo, mapArray, untrack } from \"solid-js\";\n\nimport {\n\ttype CartPath,\n\tprovideCartPathContext,\n\tuseCartPath,\n\tuseCartValue,\n} from \"../hooks/index.js\";\nimport {\n\ttype Format,\n\tgetTargetElement,\n\tgetTemplateContent,\n} from \"../utils/index.js\";\n\nexport type Props = {\n\tarrayPath: CartPath;\n\twrapInnerChild: boolean;\n\ttarget: string;\n\tformat?: Format;\n\treverse?: boolean;\n};\n\nexport const Name = \"cart-data-array-injection\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\tconst itemTemplate = getTemplateContent(element, \"item\");\n\tif (!itemTemplate)\n\t\treturn console.warn(\n\t\t\t`${Name}: No template found with a property of 'item'.`,\n\t\t);\n\tif (untrack(() => !props.arrayPath))\n\t\treturn console.warn(`${Name}: No array path provided.`);\n\tconst mergedProps = {\n\t\telement,\n\t\tpath: () => props.arrayPath,\n\t};\n\tconst fullPath = useCartPath(mergedProps);\n\tprovideCartPathContext({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n\n\tconst value = useCartValue({\n\t\tpath: fullPath,\n\t\telement,\n\t});\n\n\tconst arrayValue = createMemo(() => {\n\t\tconst v = value();\n\n\t\tif (!v) {\n\t\t\tconsole.warn(`${Name}: value is null or undefined at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (!Array.isArray(v)) {\n\t\t\tconsole.warn(`${Name}: value is not an array at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (props.reverse) {\n\t\t\treturn v.toReversed();\n\t\t}\n\n\t\treturn v;\n\t});\n\n\tconst children = createMemo(\n\t\tmapArray(arrayValue, (_, idx) => {\n\t\t\tconst fragment = itemTemplate.cloneNode(true);\n\t\t\tconst container = fragment instanceof DocumentFragment ? fragment : null;\n\t\t\tif (props.wrapInnerChild && container) {\n\t\t\t\tconst firstElement = container.firstElementChild;\n\t\t\t\tif (!firstElement) return null;\n\t\t\t\tconst children = Array.from(firstElement.children);\n\n\t\t\t\tconst wrapper = (\n\t\t\t\t\t<cart-data-array-item item-index={`${idx()}`}>\n\t\t\t\t\t\t{Array.from(children)}\n\t\t\t\t\t</cart-data-array-item>\n\t\t\t\t);\n\t\t\t\tfirstElement.replaceChildren(\n\t\t\t\t\t(Array.isArray(wrapper) ? wrapper.at(0) : wrapper) as Node,\n\t\t\t\t);\n\n\t\t\t\treturn firstElement;\n\t\t\t}\n\t\t}),\n\t);\n\n\tcreateGuardedEffect(\n\t\t() => {\n\t\t\tconst rootElement = element;\n\t\t\treturn {\n\t\t\t\ttarget: getTargetElement(rootElement, props.target),\n\t\t\t\tchildren: children(),\n\t\t\t};\n\t\t},\n\t\t({ children, target }) => {\n\t\t\tif (!target) return;\n\t\t\tconst filteredChildren = children.filter(\n\t\t\t\t(v) => v !== null && v !== undefined,\n\t\t\t);\n\t\t\ttarget.replaceChildren(...filteredChildren);\n\t\t},\n\t);\n};\n"],"mappings":";;;;;;;;AAwBA,IAAa,OAAO;AAEpB,IAAa,aAA0C,OAAO,EAAE,cAAc;CAC7E,MAAM,eAAe,mBAAmB,SAAS,MAAM;CACvD,IAAI,CAAC,cACJ,OAAO,QAAQ,KACd,GAAG,K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AAE,UAAU,aAAa;EACzB,IAAI,CAAC,QAAQ;EACb,MAAM,mBAAmB,SAAS,QAChC,MAAM,MAAM,QAAQ,MAAM,KAAA,CAC5B;EACA,OAAO,gBAAgB,GAAG,gBAAgB;CAC3C,CACD;AACD"}
@@ -1,20 +1,19 @@
1
- import { useCartPath, provideCartPathContext } from '../hooks/index.js';
2
-
3
- const Name = "cart-data-array-item";
4
- const Component = (props, { element }) => {
5
- if (!props.itemIndex)
6
- return console.warn(`${Name}: No path attribute provided.`);
7
- const mergedProps = {
8
- element,
9
- path: () => props.itemIndex
10
- };
11
- const fullPath = useCartPath(mergedProps);
12
- provideCartPathContext({
13
- element,
14
- path: fullPath
15
- });
1
+ import { provideCartPathContext, useCartPath } from "../hooks/index.js";
2
+ import { untrack } from "solid-js";
3
+ //#region src/components/cart-data-array-item.ts
4
+ var Name = "cart-data-array-item";
5
+ var Component = (props, { element }) => {
6
+ if (untrack(() => !props.itemIndex)) return console.warn(`${Name}: No path attribute provided.`);
7
+ const fullPath = useCartPath({
8
+ element,
9
+ path: () => props.itemIndex
10
+ });
11
+ provideCartPathContext({
12
+ element,
13
+ path: fullPath
14
+ });
16
15
  };
17
-
16
+ //#endregion
18
17
  export { Component, Name };
19
- //# sourceMappingURL=cart-data-array-item.js.map
18
+
20
19
  //# sourceMappingURL=cart-data-array-item.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/cart-data-array-item.ts"],"names":[],"mappings":";;AAYO,MAAM,IAAO,GAAA;AAEb,MAAM,SAAyC,GAAA,CAAC,KAAO,EAAA,EAAE,SAAc,KAAA;AAC7E,EAAA,IAAI,CAAC,KAAM,CAAA,SAAA;AACV,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,CAAG,EAAA,IAAI,CAA+B,6BAAA,CAAA,CAAA;AAE3D,EAAA,MAAM,WAAc,GAAA;AAAA,IACnB,OAAA;AAAA,IACA,IAAA,EAAM,MAAM,KAAM,CAAA;AAAA,GACnB;AAEA,EAAM,MAAA,QAAA,GAAW,YAAY,WAAkB,CAAA;AAC/C,EAAuB,sBAAA,CAAA;AAAA,IACtB,OAAA;AAAA,IACA,IAAM,EAAA;AAAA,GACN,CAAA;AACF","file":"cart-data-array-item.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\n\nimport {\n\tprovideCartPathContext,\n\tuseCartPath,\n\ttype CartPath,\n} from \"../hooks/index.js\";\n\nexport type Props = {\n\titemIndex: string;\n};\n\nexport const Name = \"cart-data-array-item\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\tif (!props.itemIndex)\n\t\treturn console.warn(`${Name}: No path attribute provided.`);\n\n\tconst mergedProps = {\n\t\telement,\n\t\tpath: () => props.itemIndex,\n\t};\n\n\tconst fullPath = useCartPath(mergedProps as any);\n\tprovideCartPathContext({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n};\n"]}
1
+ {"version":3,"file":"cart-data-array-item.js","names":[],"sources":["../../../src/components/cart-data-array-item.ts"],"sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { untrack } from \"solid-js\";\n\nimport {\n\ttype CartPath,\n\tprovideCartPathContext,\n\tuseCartPath,\n} from \"../hooks/index.js\";\n\nexport type Props = {\n\titemIndex: string;\n};\n\nexport const Name = \"cart-data-array-item\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\tif (untrack(() => !props.itemIndex))\n\t\treturn console.warn(`${Name}: No path attribute provided.`);\n\n\tconst mergedProps = {\n\t\telement,\n\t\tpath: () => props.itemIndex,\n\t};\n\n\tconst fullPath = useCartPath(mergedProps as any);\n\tprovideCartPathContext({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n};\n"],"mappings":";;;AAaA,IAAa,OAAO;AAEpB,IAAa,aAA0C,OAAO,EAAE,cAAc;CAC7E,IAAI,cAAc,CAAC,MAAM,SAAS,GACjC,OAAO,QAAQ,KAAK,GAAG,KAAK,8BAA8B;CAO3D,MAAM,WAAW,YAAY;EAJ5B;EACA,YAAY,MAAM;CAGU,CAAkB;CAC/C,uBAAuB;EACtB;EACA,MAAM;CACP,CAAC;AACF"}
@@ -1,58 +1,67 @@
1
- import { getTemplateContent } from '../utils/index.js';
2
- import { createMemo, Show, For } from 'solid-js';
3
- import { useCartPath, provideCartPathContext, useCartValue } from '../hooks/index.js';
4
- import html from 'solid-js/html';
5
-
6
- const Name = "cart-data-array";
7
- const Component = (props, { element }) => {
8
- const itemTemplate = getTemplateContent(element, "item");
9
- if (!itemTemplate)
10
- return console.warn(
11
- `${Name}: No template found with a property of 'item'.`
12
- );
13
- if (!props.arrayPath) return console.warn(`${Name}: No array path provided.`);
14
- const mergedProps = {
15
- element,
16
- path: () => props.arrayPath
17
- };
18
- const fullPath = useCartPath(mergedProps);
19
- provideCartPathContext({
20
- element,
21
- path: fullPath
22
- });
23
- const value = useCartValue({
24
- element,
25
- path: fullPath
26
- });
27
- const arrayValue = createMemo(() => {
28
- const v = value();
29
- if (!v) {
30
- console.warn(`${Name}: value is null or undefined at path ${fullPath()}`);
31
- return null;
32
- }
33
- if (!Array.isArray(v)) {
34
- console.warn(`${Name}: value is not an array at path ${fullPath()}`);
35
- return null;
36
- }
37
- if (props.reverse) {
38
- return v.toReversed();
39
- }
40
- return v;
41
- });
42
- element.replaceChildren(...[]);
43
- return html`
44
- <${Show} when=${() => arrayValue() && arrayValue().length > 0}>
45
- <${For} each=${arrayValue}>
46
- ${(_, idx) => html`
47
- <cart-data-array-item item-index=${() => `${idx()}`} class=${() => props.itemClass}>
48
- ${() => Array.from(itemTemplate.cloneNode(true).childNodes)}
49
- </cart-data-array-item>
50
- `}
51
- <//>
52
- <//>
53
- `;
1
+ import { getTemplateContent } from "../utils/getTemplateContent.js";
2
+ import { provideCartPathContext, useCartPath, useCartValue } from "../hooks/index.js";
3
+ import { createMemo, untrack } from "solid-js";
4
+ import { For, Show, className, createComponent, effect, getOwner, insert, readShallow, setAttribute, template } from "@solidjs/web";
5
+ //#region src/components/cart-data-array.tsx
6
+ var _tmpl$ = /* @__PURE__ */ template(`<cart-data-array-item>`, 1);
7
+ var Name = "cart-data-array";
8
+ var Component = (props, { element }) => {
9
+ const itemTemplate = getTemplateContent(element, "item");
10
+ if (!itemTemplate) return console.warn(`${Name}: No template found with a property of 'item'.`);
11
+ if (untrack(() => !props.arrayPath)) return console.warn(`${Name}: No array path provided.`);
12
+ const fullPath = useCartPath({
13
+ element,
14
+ path: () => props.arrayPath
15
+ });
16
+ provideCartPathContext({
17
+ element,
18
+ path: fullPath
19
+ });
20
+ const value = useCartValue({
21
+ element,
22
+ path: fullPath
23
+ });
24
+ const arrayValue = createMemo(() => {
25
+ const v = value();
26
+ if (!v) {
27
+ console.warn(`${Name}: value is null or undefined at path ${fullPath()}`);
28
+ return null;
29
+ }
30
+ if (!Array.isArray(v)) {
31
+ console.warn(`${Name}: value is not an array at path ${fullPath()}`);
32
+ return null;
33
+ }
34
+ if (props.reverse) return v.toReversed();
35
+ return v;
36
+ });
37
+ element.replaceChildren(...[]);
38
+ return createComponent(Show, {
39
+ get when() {
40
+ return (arrayValue()?.length ?? 0) > 0;
41
+ },
42
+ get children() {
43
+ return createComponent(For, {
44
+ get each() {
45
+ return arrayValue() ?? [];
46
+ },
47
+ keyed: false,
48
+ children: (_, idx) => (() => {
49
+ var _el$ = _tmpl$();
50
+ setAttribute(_el$, "item-index", `${idx}`);
51
+ _el$._$owner = getOwner();
52
+ insert(_el$, () => {
53
+ return Array.from(itemTemplate.cloneNode(true).childNodes);
54
+ });
55
+ effect(() => readShallow(props.itemClass), (_v$, _$p) => {
56
+ className(_el$, _v$, _$p);
57
+ });
58
+ return _el$;
59
+ })()
60
+ });
61
+ }
62
+ });
54
63
  };
55
-
64
+ //#endregion
56
65
  export { Component, Name };
57
- //# sourceMappingURL=cart-data-array.js.map
66
+
58
67
  //# sourceMappingURL=cart-data-array.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/cart-data-array.ts"],"names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EAAA;AAAA;AAGrB,IAAO,OAAA,CAAA;AAAA,GACP,CAAA;AAED,EAAQ,OAAA,CAAA,eAAA,CAAgB,GAAG,EAAE,CAAA;AAE7B,EAAO,OAAA,IAAA;AAAA,KACD,EAAA,IAAI,SAAS,MAAM,UAAA,MAAgB,UAAW,EAAA,CAAG,SAAS,CAAC,CAAA;AAAA,OACzD,EAAA,GAAG,SAAS,UAAU,CAAA;AAAA,QACrB,EAAA,CAAC,GAAQ,GAA0B,KAAA,IAAA;AAAA,2CACA,EAAA,MAAM,GAAG,GAAI,EAAC,EAAE,CAAU,OAAA,EAAA,MAAM,MAAM,SAAS,CAAA;AAAA,YAC9E,EAAA,MAAM,MAAM,IAAK,CAAA,YAAA,CAAa,UAAU,IAAI,CAAA,CAAE,UAAU,CAAC;AAAA;AAAA,QAE9D,CAAA;AAAA;AAAA;AAAA,EAAA,CAAA;AAIT","file":"cart-data-array.js","sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { getTemplateContent, type Format } from \"../utils/index.js\";\n\nimport { Show, For, type Accessor, createMemo } from \"solid-js\";\n\nimport {\n\ttype CartPath,\n\tuseCartPath,\n\tuseCartValue,\n\tprovideCartPathContext,\n} from \"../hooks/index.js\";\nimport html from \"solid-js/html\";\n\nexport type Props = {\n\tarrayPath: CartPath;\n\tformat?: Format;\n\treverse?: boolean;\n\titemClass?: string;\n};\n\nexport const Name = \"cart-data-array\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\tconst itemTemplate = getTemplateContent(element, \"item\");\n\tif (!itemTemplate)\n\t\treturn console.warn(\n\t\t\t`${Name}: No template found with a property of 'item'.`,\n\t\t);\n\tif (!props.arrayPath) return console.warn(`${Name}: No array path provided.`);\n\tconst mergedProps = {\n\t\telement,\n\t\tpath: () => props.arrayPath,\n\t};\n\tconst fullPath = useCartPath(mergedProps);\n\tprovideCartPathContext({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n\n\tconst value = useCartValue({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n\n\tconst arrayValue = createMemo(() => {\n\t\tconst v = value();\n\n\t\tif (!v) {\n\t\t\tconsole.warn(`${Name}: value is null or undefined at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (!Array.isArray(v)) {\n\t\t\tconsole.warn(`${Name}: value is not an array at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (props.reverse) {\n\t\t\treturn v.toReversed();\n\t\t}\n\n\t\treturn v;\n\t});\n\n\telement.replaceChildren(...[]);\n\n\treturn html`\n <${Show} when=${() => arrayValue() && arrayValue()!.length > 0}>\n <${For} each=${arrayValue}>\n ${(_: any, idx: Accessor<number>) => html`\n <cart-data-array-item item-index=${() => `${idx()}`} class=${() => props.itemClass}>\n ${() => Array.from(itemTemplate.cloneNode(true).childNodes)}\n </cart-data-array-item>\n `}\n <//>\n <//>\n `;\n};\n"]}
1
+ {"version":3,"file":"cart-data-array.js","names":["<Show when={(arrayValue()?.length ?? 0) > 0}>\n\t\t\t{/* keyed={false}: the index is what identifies a row here. */}\n\t\t\t<For each={arrayValue() ?? []} keyed={false}>\n\t\t\t\t{(_, idx) => (\n\t\t\t\t\t<cart-data-array-item item-index={`${idx}`} class={props.itemClass}>\n\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t</cart-data-array-item>\n\t\t\t\t)}\n\t\t\t</For>\n\t\t</Show>","<For each={arrayValue() ?? []} keyed={false}>\n\t\t\t\t{(_, idx) => (\n\t\t\t\t\t<cart-data-array-item item-index={`${idx}`} class={props.itemClass}>\n\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t</cart-data-array-item>\n\t\t\t\t)}\n\t\t\t</For>","keyed={false}"],"sources":["../../../src/components/cart-data-array.tsx"],"sourcesContent":["import type { CorrectComponentType } from \"@brytdesigns/web-component-core/utils\";\nimport { For, Show } from \"@solidjs/web\";\nimport { type Accessor, createMemo, untrack } from \"solid-js\";\n\nimport {\n\ttype CartPath,\n\tprovideCartPathContext,\n\tuseCartPath,\n\tuseCartValue,\n} from \"../hooks/index.js\";\nimport { type Format, getTemplateContent } from \"../utils/index.js\";\n\nexport type Props = {\n\tarrayPath: CartPath;\n\tformat?: Format;\n\treverse?: boolean;\n\titemClass?: string;\n};\n\nexport const Name = \"cart-data-array\";\n\nexport const Component: CorrectComponentType<Props> = (props, { element }) => {\n\tconst itemTemplate = getTemplateContent(element, \"item\");\n\tif (!itemTemplate)\n\t\treturn console.warn(\n\t\t\t`${Name}: No template found with a property of 'item'.`,\n\t\t);\n\tif (untrack(() => !props.arrayPath))\n\t\treturn console.warn(`${Name}: No array path provided.`);\n\tconst mergedProps = {\n\t\telement,\n\t\tpath: () => props.arrayPath,\n\t};\n\tconst fullPath = useCartPath(mergedProps);\n\tprovideCartPathContext({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n\n\tconst value = useCartValue({\n\t\telement,\n\t\tpath: fullPath,\n\t});\n\n\tconst arrayValue = createMemo(() => {\n\t\tconst v = value();\n\n\t\tif (!v) {\n\t\t\tconsole.warn(`${Name}: value is null or undefined at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (!Array.isArray(v)) {\n\t\t\tconsole.warn(`${Name}: value is not an array at path ${fullPath()}`);\n\t\t\treturn null;\n\t\t}\n\n\t\tif (props.reverse) {\n\t\t\treturn v.toReversed();\n\t\t}\n\n\t\treturn v;\n\t});\n\n\telement.replaceChildren(...[]);\n\n\treturn (\n\t\t<Show when={(arrayValue()?.length ?? 0) > 0}>\n\t\t\t{/* keyed={false}: the index is what identifies a row here. */}\n\t\t\t<For each={arrayValue() ?? []} keyed={false}>\n\t\t\t\t{(_, idx) => (\n\t\t\t\t\t<cart-data-array-item item-index={`${idx}`} class={props.itemClass}>\n\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t</cart-data-array-item>\n\t\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sB,aAAA,YAAO,MAAM,SAAS,IAAtB,KAAA,QAAA;MAAsB,UAAA,MAAA,KAAA,GAAA;;KAAlE,OAAA;IAEsB,EAAA,CAAA;GAEnB,CAAA;EACA;;AAER"}
@@ -1,109 +1,70 @@
1
- import { createMemo, For, Show } from 'solid-js';
2
- import html from 'solid-js/html';
3
- import { useCartPath, useCartValue } from '../hooks/index.js';
4
- import { formatValue, getValueFromPath } from '../utils/index.js';
5
-
1
+ import { formatValue } from "../utils/formatValue.js";
2
+ import { getValueFromPath } from "../utils/getValueFromPath.js";
3
+ import { useCartPath, useCartValue } from "../hooks/index.js";
4
+ import { createMemo } from "solid-js";
5
+ import { For, Show, createComponent } from "@solidjs/web";
6
+ //#region src/components/cart-data-conditions.tsx
6
7
  function getValue(data, value) {
7
- if (typeof value === "undefined" || !data) return void 0;
8
- if (value.type === "primitive") {
9
- return value.value;
10
- }
11
- if (value.type === "property" && value.name) {
12
- return getValueFromPath(data, value.name);
13
- }
14
- return null;
8
+ if (typeof value === "undefined" || !data) return void 0;
9
+ if (value.type === "primitive") return value.value;
10
+ if (value.type === "property" && value.name) return getValueFromPath(data, value.name);
11
+ return null;
15
12
  }
16
13
  function invertResult(result, invert = false) {
17
- if (invert) return !result;
18
- return result;
14
+ if (invert) return !result;
15
+ return result;
19
16
  }
20
17
  function validateConditions(conditions, data) {
21
- if (!data) return false;
22
- const result = conditions.every((condition) => {
23
- let valueA = getValue(data, condition.valueA), valueB = getValue(data, condition.valueB), result2 = false;
24
- if (typeof valueA === "undefined" && typeof valueB === "undefined")
25
- return false;
26
- if (condition.type === "typeof") {
27
- result2 = typeof valueA === valueB;
28
- }
29
- if (condition.type === "includes") {
30
- result2 = formatValue(condition.format || "", valueA).includes(
31
- formatValue(condition.format || "", valueB)
32
- );
33
- }
34
- if (condition.type === "includes_property") {
35
- result2 = valueA.some(
36
- (v) => v[condition.valueA?.property_name || ""] === valueB
37
- );
38
- }
39
- if (condition.type === "starts_with") {
40
- result2 = formatValue("string", valueA).startsWith(
41
- formatValue(condition.format || "", valueB)
42
- );
43
- }
44
- if (condition.type === "equals") {
45
- result2 = formatValue(condition.format || "", valueA) === formatValue(condition.format || "", valueB);
46
- }
47
- if (condition.type === "not_equals") {
48
- result2 = formatValue(condition.format || "", valueA) !== formatValue(condition.format || "", valueB);
49
- }
50
- if (condition.type === "lt") {
51
- result2 = formatValue(condition.format || "", valueA) < formatValue(condition.format || "", valueB);
52
- }
53
- if (condition.type === "lte") {
54
- result2 = formatValue(condition.format || "", valueA) <= formatValue(condition.format || "", valueB);
55
- }
56
- if (condition.type === "gt") {
57
- result2 = formatValue(condition.format || "", valueA) > formatValue(condition.format || "", valueB);
58
- }
59
- if (condition.type === "gte") {
60
- result2 = formatValue(condition.format || "", valueA) >= formatValue(condition.format || "", valueB);
61
- }
62
- return invertResult(result2, condition.invert);
63
- });
64
- return result;
18
+ if (!data) return false;
19
+ return conditions.every((condition) => {
20
+ let valueA = getValue(data, condition.valueA), valueB = getValue(data, condition.valueB), result = false;
21
+ if (typeof valueA === "undefined" && typeof valueB === "undefined") return false;
22
+ if (condition.type === "typeof") result = typeof valueA === valueB;
23
+ if (condition.type === "includes") result = formatValue(condition.format || "", valueA).includes(formatValue(condition.format || "", valueB));
24
+ if (condition.type === "includes_property") result = valueA.some((v) => v[condition.valueA?.property_name || ""] === valueB);
25
+ if (condition.type === "starts_with") result = formatValue("string", valueA).startsWith(formatValue(condition.format || "", valueB));
26
+ if (condition.type === "equals") result = formatValue(condition.format || "", valueA) === formatValue(condition.format || "", valueB);
27
+ if (condition.type === "not_equals") result = formatValue(condition.format || "", valueA) !== formatValue(condition.format || "", valueB);
28
+ if (condition.type === "lt") result = formatValue(condition.format || "", valueA) < formatValue(condition.format || "", valueB);
29
+ if (condition.type === "lte") result = formatValue(condition.format || "", valueA) <= formatValue(condition.format || "", valueB);
30
+ if (condition.type === "gt") result = formatValue(condition.format || "", valueA) > formatValue(condition.format || "", valueB);
31
+ if (condition.type === "gte") result = formatValue(condition.format || "", valueA) >= formatValue(condition.format || "", valueB);
32
+ return invertResult(result, condition.invert);
33
+ });
65
34
  }
66
- const Name = "cart-data-conditions";
67
- const Component = (_, { element }) => {
68
- const conditionTemplates = Array.from(element.children).filter(
69
- (child) => child.tagName === "TEMPLATE" && child.hasAttribute("conditions")
70
- );
71
- if (!conditionTemplates.length)
72
- return console.error(
73
- `${Name}: no templates found with any conditions attribute!`
74
- );
75
- const allConditions = createMemo(
76
- () => conditionTemplates.map((tmpl) => {
77
- const conditions = tmpl.getAttribute("conditions");
78
- if (!conditions)
79
- console.warn(`${Name}: conditions attribute is required!`);
80
- try {
81
- return JSON.parse(conditions);
82
- } catch (e) {
83
- return [];
84
- }
85
- })
86
- );
87
- const fullPath = useCartPath({ element });
88
- const data = useCartValue({
89
- path: fullPath,
90
- element
91
- });
92
- element.replaceChildren(...[]);
93
- return html`
94
- <${For} each=${() => conditionTemplates}>
95
- ${(tmpl, idx) => {
96
- const conditions = allConditions()[idx()];
97
- return html`
98
- <${Show} when=${() => validateConditions(conditions, data())}>
99
- ${() => Array.from(tmpl.content.cloneNode(true).childNodes)}
100
- <//>
101
- `;
102
- }}
103
- <//>
104
- `;
35
+ var Name = "cart-data-conditions";
36
+ var Component = (_, { element }) => {
37
+ const conditionTemplates = Array.from(element.children).filter((child) => child.tagName === "TEMPLATE" && child.hasAttribute("conditions"));
38
+ if (!conditionTemplates.length) return console.error(`${Name}: no templates found with any conditions attribute!`);
39
+ const allConditions = createMemo(() => conditionTemplates.map((tmpl) => {
40
+ const conditions = tmpl.getAttribute("conditions");
41
+ if (!conditions) console.warn(`${Name}: conditions attribute is required!`);
42
+ try {
43
+ return JSON.parse(conditions);
44
+ } catch (e) {
45
+ return [];
46
+ }
47
+ }));
48
+ const fullPath = useCartPath({ element });
49
+ const data = useCartValue({
50
+ path: fullPath,
51
+ element
52
+ });
53
+ element.replaceChildren(...[]);
54
+ return createComponent(For, {
55
+ each: conditionTemplates,
56
+ keyed: false,
57
+ children: (tmpl, idx) => createComponent(Show, {
58
+ get when() {
59
+ return validateConditions(allConditions()[idx], data());
60
+ },
61
+ get children() {
62
+ return Array.from(tmpl().content.cloneNode(true).childNodes);
63
+ }
64
+ })
65
+ });
105
66
  };
106
-
67
+ //#endregion
107
68
  export { Component, Name };
108
- //# sourceMappingURL=cart-data-conditions.js.map
69
+
109
70
  //# sourceMappingURL=cart-data-conditions.js.map