@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.
- package/dist/main/components/cart-context.js +19 -15
- package/dist/main/components/cart-context.js.map +1 -1
- package/dist/main/components/cart-data-array-injection.js +70 -81
- package/dist/main/components/cart-data-array-injection.js.map +1 -1
- package/dist/main/components/cart-data-array-item.js +16 -17
- package/dist/main/components/cart-data-array-item.js.map +1 -1
- package/dist/main/components/cart-data-array.js +64 -55
- package/dist/main/components/cart-data-array.js.map +1 -1
- package/dist/main/components/cart-data-conditions.js +61 -100
- package/dist/main/components/cart-data-conditions.js.map +1 -1
- package/dist/main/components/cart-data-injection.js +78 -84
- package/dist/main/components/cart-data-injection.js.map +1 -1
- package/dist/main/components/cart-data-listener-status.js +32 -31
- package/dist/main/components/cart-data-listener-status.js.map +1 -1
- package/dist/main/components/cart-data-listener.js +98 -155
- package/dist/main/components/cart-data-listener.js.map +1 -1
- package/dist/main/components/cart-data.js +29 -25
- package/dist/main/components/cart-data.js.map +1 -1
- package/dist/main/components/cart-loading-state.js +51 -37
- package/dist/main/components/cart-loading-state.js.map +1 -1
- package/dist/main/components/index.js +10 -22
- package/dist/main/hooks/index.js +24 -25
- package/dist/main/hooks/index.js.map +1 -1
- package/dist/main/hooks/useAjaxCart.js +14 -18
- package/dist/main/hooks/useAjaxCart.js.map +1 -1
- package/dist/main/hooks/useListenerStatus.js +23 -28
- package/dist/main/hooks/useListenerStatus.js.map +1 -1
- package/dist/main/index.d.ts +5182 -4789
- package/dist/main/index.js +56 -82
- package/dist/main/index.js.map +1 -1
- package/dist/main/utils/formatValue.js +14 -18
- package/dist/main/utils/formatValue.js.map +1 -1
- package/dist/main/utils/getTargetElement.js +10 -9
- package/dist/main/utils/getTargetElement.js.map +1 -1
- package/dist/main/utils/getTemplateContent.js +6 -7
- package/dist/main/utils/getTemplateContent.js.map +1 -1
- package/dist/main/utils/getValueFromPath.js +9 -10
- package/dist/main/utils/getValueFromPath.js.map +1 -1
- package/dist/main/utils/parseNestedObject.js +48 -28
- package/dist/main/utils/parseNestedObject.js.map +1 -1
- package/dist/main/utils/safeInjection.js +120 -0
- package/dist/main/utils/safeInjection.js.map +1 -0
- package/dist/main/utils/traverseObject.js +13 -15
- package/dist/main/utils/traverseObject.js.map +1 -1
- package/package.json +9 -8
- package/dist/esm/index.js +0 -883
- package/dist/esm/index.js.map +0 -1
- package/dist/main/components/index.js.map +0 -1
- package/dist/main/utils/index.js +0 -8
- package/dist/main/utils/index.js.map +0 -1
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
21
|
+
|
|
18
22
|
//# sourceMappingURL=cart-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
+
|
|
84
73
|
//# sourceMappingURL=cart-data-array-injection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,KAAK,+CACT;CACD,IAAI,cAAc,CAAC,MAAM,SAAS,GACjC,OAAO,QAAQ,KAAK,GAAG,KAAK,0BAA0B;CAKvD,MAAM,WAAW,YAAY;EAH5B;EACA,YAAY,MAAM;CAEU,CAAW;CACxC,uBAAuB;EACtB;EACA,MAAM;CACP,CAAC;CAED,MAAM,QAAQ,aAAa;EAC1B,MAAM;EACN;CACD,CAAC;CAED,MAAM,aAAa,iBAAiB;EACnC,MAAM,IAAI,MAAM;EAEhB,IAAI,CAAC,GAAG;GACP,QAAQ,KAAK,GAAG,KAAK,uCAAuC,SAAS,GAAG;GACxE,OAAO;EACR;EAEA,IAAI,CAAC,MAAM,QAAQ,CAAC,GAAG;GACtB,QAAQ,KAAK,GAAG,KAAK,kCAAkC,SAAS,GAAG;GACnE,OAAO;EACR;EAEA,IAAI,MAAM,SACT,OAAO,EAAE,WAAW;EAGrB,OAAO;CACR,CAAC;CAED,MAAM,WAAW,WAChB,SAAS,aAAa,GAAG,QAAQ;EAChC,MAAM,WAAW,aAAa,UAAU,IAAI;EAC5C,MAAM,YAAY,oBAAoB,mBAAmB,WAAW;EACpE,IAAI,MAAM,kBAAkB,WAAW;GACtC,MAAM,eAAe,UAAU;GAC/B,IAAI,CAAC,cAAc,OAAO;GAC1B,MAAM,WAAW,MAAM,KAAK,aAAa,QAAQ;GAGhD,IAAA,OAAA,OAEsB;GAFtB,KAAA,UAAA,SAEsB;GAFtB,OAAA,YACC;IAAC,OAAA,MAAM,KAAK,QAAQ;GAAC,CACA;GAFA,aAAY,GAAG,IAAI,MAAnB,QAAA;IAAsB,aAAA,MAAA,cAAA,GAAA;;GAD7C,MAAM,UACLA;GAID,aAAa,gBACX,MAAM,QAAQ,OAAO,IAAI,QAAQ,GAAG,CAAC,IAAI,OAC3C;GAEA,OAAO;EACR;CACD,CAAC,CACF;CAEA,0BACO;EAEL,OAAO;GACN,QAAQ,iBAAiB,SAAa,MAAM,MAAM;GAClD,UAAU,SAAS;EACpB;CACD,IACC,EAAE,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 {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
+
|
|
20
19
|
//# sourceMappingURL=cart-data-array-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
66
|
+
|
|
58
67
|
//# sourceMappingURL=cart-data-array.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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\t\t\t)}\n\t\t\t</For>\n\t\t</Show>\n\t);\n};\n"],"mappings":";;;;;;AAmBA,IAAa,OAAO;AAEpB,IAAa,aAA0C,OAAO,EAAE,cAAc;CAC7E,MAAM,eAAe,mBAAmB,SAAS,MAAM;CACvD,IAAI,CAAC,cACJ,OAAO,QAAQ,KACd,GAAG,KAAK,+CACT;CACD,IAAI,cAAc,CAAC,MAAM,SAAS,GACjC,OAAO,QAAQ,KAAK,GAAG,KAAK,0BAA0B;CAKvD,MAAM,WAAW,YAAY;EAH5B;EACA,YAAY,MAAM;CAEU,CAAW;CACxC,uBAAuB;EACtB;EACA,MAAM;CACP,CAAC;CAED,MAAM,QAAQ,aAAa;EAC1B;EACA,MAAM;CACP,CAAC;CAED,MAAM,aAAa,iBAAiB;EACnC,MAAM,IAAI,MAAM;EAEhB,IAAI,CAAC,GAAG;GACP,QAAQ,KAAK,GAAG,KAAK,uCAAuC,SAAS,GAAG;GACxE,OAAO;EACR;EAEA,IAAI,CAAC,MAAM,QAAQ,CAAC,GAAG;GACtB,QAAQ,KAAK,GAAG,KAAK,kCAAkC,SAAS,GAAG;GACnE,OAAO;EACR;EAEA,IAAI,MAAM,SACT,OAAO,EAAE,WAAW;EAGrB,OAAO;CACR,CAAC;CAED,QAAQ,gBAAgB,GAAG,CAAC,CAAC;CAE7B,OACCA,gBAAAA,MAAAA;EAAM,IAAA,OAAA;GAAO,QAAA,WAAW,CAAC,EAAE,UAAU,KAAK;EAAC;EAA3C,IAAA,WAAA;GAECC,OAAAA,gBAAAA,KAAAA;IAAK,IAAA,OAAA;KAAM,OAAA,WAAW,KAAK,CAAC;IAAC;IAAEC,OAAO;IAAtCD,WACG,GAAG,eACJ;KAEsB,IAAA,OAAA,OAAA;KAFA,aAAA,MAAA,cAAY,GAAG,KAAK;KAA1C,KAAA,UAAA,SAEsB;KAFtB,OAAA,YACC;MAAC,OAAA,MAAM,KAAK,aAAa,UAAU,IAAI,CAAC,CAAC,UAAU;KAAC,CAC/B;KAFsB,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 {
|
|
2
|
-
import
|
|
3
|
-
import { useCartPath, useCartValue } from
|
|
4
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
18
|
-
|
|
14
|
+
if (invert) return !result;
|
|
15
|
+
return result;
|
|
19
16
|
}
|
|
20
17
|
function validateConditions(conditions, data) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
69
|
+
|
|
109
70
|
//# sourceMappingURL=cart-data-conditions.js.map
|