@brytdesigns/shopify-ajax-cart-components 1.2.18 → 1.3.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 +54 -106
- package/dist/esm/index.js.map +1 -1
- package/dist/main/components/cart-context.js +7 -17
- package/dist/main/components/cart-context.js.map +1 -1
- package/dist/main/components/cart-data-array-injection.js +5 -5
- package/dist/main/components/cart-data-array-injection.js.map +1 -1
- package/dist/main/components/cart-data-array-item.js +3 -3
- package/dist/main/components/cart-data-array-item.js.map +1 -1
- package/dist/main/components/cart-data-array.js +5 -4
- package/dist/main/components/cart-data-array.js.map +1 -1
- package/dist/main/components/cart-data-conditions.js +4 -3
- package/dist/main/components/cart-data-conditions.js.map +1 -1
- package/dist/main/components/cart-data-injection.js +8 -6
- package/dist/main/components/cart-data-injection.js.map +1 -1
- package/dist/main/components/cart-data-listener.js +15 -14
- package/dist/main/components/cart-data-listener.js.map +1 -1
- package/dist/main/components/cart-data.js +5 -3
- package/dist/main/components/cart-data.js.map +1 -1
- package/dist/main/hooks/index.js +9 -3
- package/dist/main/hooks/index.js.map +1 -1
- package/dist/main/hooks/useAjaxCart.js.map +1 -1
- package/dist/main/index.d.ts +631 -9798
- package/dist/main/utils/getValueFromPath.js.map +1 -1
- package/package.json +4 -4
- package/dist/jsdelivr/components/cart-context.js +0 -22
- package/dist/jsdelivr/components/cart-context.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-array-item.js +0 -19
- package/dist/jsdelivr/components/cart-data-array-item.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-array.js +0 -58
- package/dist/jsdelivr/components/cart-data-array.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-conditions.js +0 -97
- package/dist/jsdelivr/components/cart-data-conditions.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-injection.js +0 -89
- package/dist/jsdelivr/components/cart-data-injection.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-listener-status.js +0 -35
- package/dist/jsdelivr/components/cart-data-listener-status.js.map +0 -1
- package/dist/jsdelivr/components/cart-data-listener.js +0 -163
- package/dist/jsdelivr/components/cart-data-listener.js.map +0 -1
- package/dist/jsdelivr/components/cart-data.js +0 -29
- package/dist/jsdelivr/components/cart-data.js.map +0 -1
- package/dist/jsdelivr/components/cart-loading-state.js +0 -39
- package/dist/jsdelivr/components/cart-loading-state.js.map +0 -1
- package/dist/jsdelivr/components/index.js +0 -11
- package/dist/jsdelivr/components/index.js.map +0 -1
- package/dist/jsdelivr/hooks/index.js +0 -7
- package/dist/jsdelivr/hooks/index.js.map +0 -1
- package/dist/jsdelivr/hooks/useCartValue.js +0 -23
- package/dist/jsdelivr/hooks/useCartValue.js.map +0 -1
- package/dist/jsdelivr/hooks/useFormattedValue.js +0 -27
- package/dist/jsdelivr/hooks/useFormattedValue.js.map +0 -1
- package/dist/jsdelivr/hooks/useFullPropertyPath.js +0 -35
- package/dist/jsdelivr/hooks/useFullPropertyPath.js.map +0 -1
- package/dist/jsdelivr/hooks/useHybridCart.js +0 -23
- package/dist/jsdelivr/hooks/useHybridCart.js.map +0 -1
- package/dist/jsdelivr/hooks/useListenerStatus.js +0 -33
- package/dist/jsdelivr/hooks/useListenerStatus.js.map +0 -1
- package/dist/jsdelivr/index.js +0 -72
- package/dist/jsdelivr/index.js.map +0 -1
- package/dist/jsdelivr/utils/formatValue.js +0 -22
- package/dist/jsdelivr/utils/formatValue.js.map +0 -1
- package/dist/jsdelivr/utils/getTargetElement.js +0 -13
- package/dist/jsdelivr/utils/getTargetElement.js.map +0 -1
- package/dist/jsdelivr/utils/getTemplateContent.js +0 -11
- package/dist/jsdelivr/utils/getTemplateContent.js.map +0 -1
- package/dist/jsdelivr/utils/getValueFromPath.js +0 -14
- package/dist/jsdelivr/utils/getValueFromPath.js.map +0 -1
- package/dist/jsdelivr/utils/index.js +0 -7
- package/dist/jsdelivr/utils/index.js.map +0 -1
- package/dist/jsdelivr/utils/parseNestedObject.js +0 -32
- package/dist/jsdelivr/utils/parseNestedObject.js.map +0 -1
- package/dist/main/hooks/useCartValue.js +0 -23
- package/dist/main/hooks/useCartValue.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createWithElementContext, customShadowlessElement, correctElementType } from '@brytdesigns/web-component-core/utils';
|
|
2
|
-
import { splitProps, createEffect,
|
|
2
|
+
import { splitProps, createEffect, Show, createMemo, For, mapArray, on, onCleanup } from 'solid-js';
|
|
3
3
|
import AjaxCart from '@brytdesigns/shopify-ajax-cart';
|
|
4
4
|
import { createContext, provide, consume } from 'component-register';
|
|
5
|
+
import { makeFullPropertyPathContext } from '@brytdesigns/web-component-core';
|
|
5
6
|
import html2 from 'solid-js/html';
|
|
6
|
-
import 'solid-js/store';
|
|
7
7
|
import debounce from 'lodash.debounce';
|
|
8
8
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
@@ -137,22 +137,12 @@ function traverseObject(obj, callback, path = []) {
|
|
|
137
137
|
var Name = "cart-context";
|
|
138
138
|
var Component = (props, { element }) => {
|
|
139
139
|
const cart = provideAjaxCartContext(element);
|
|
140
|
-
createEffect(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
cart: c,
|
|
147
|
-
debug: props.debug
|
|
148
|
-
};
|
|
149
|
-
},
|
|
150
|
-
({ cart: cart2, debug }) => {
|
|
151
|
-
if (!debug) return;
|
|
152
|
-
console.log(`${Name}:updated!`, cart2);
|
|
153
|
-
}
|
|
154
|
-
)
|
|
155
|
-
);
|
|
140
|
+
createEffect(() => {
|
|
141
|
+
if (!props.debug) return;
|
|
142
|
+
const c = cart();
|
|
143
|
+
traverseObject(c);
|
|
144
|
+
console.log(`${Name}:updated!`, c);
|
|
145
|
+
});
|
|
156
146
|
};
|
|
157
147
|
|
|
158
148
|
// src/components/cart-data.ts
|
|
@@ -161,63 +151,6 @@ __export(cart_data_exports, {
|
|
|
161
151
|
Component: () => Component2,
|
|
162
152
|
Name: () => Name2
|
|
163
153
|
});
|
|
164
|
-
function createFullPathPropertyContext(options) {
|
|
165
|
-
return options.path;
|
|
166
|
-
}
|
|
167
|
-
var FullPropertyPathContext = createContext(createFullPathPropertyContext);
|
|
168
|
-
function provideFullPropertyPathContext({
|
|
169
|
-
element,
|
|
170
|
-
path
|
|
171
|
-
}) {
|
|
172
|
-
return provide(FullPropertyPathContext, { path }, element);
|
|
173
|
-
}
|
|
174
|
-
function useFullPropertyPathContext(context) {
|
|
175
|
-
return context;
|
|
176
|
-
}
|
|
177
|
-
function useFullPropertyPath(props) {
|
|
178
|
-
const context = consume(FullPropertyPathContext, props.element);
|
|
179
|
-
const basePath = useFullPropertyPathContext(context);
|
|
180
|
-
return createMemo(() => {
|
|
181
|
-
if (typeof basePath !== "function" && typeof props.path === "function") {
|
|
182
|
-
return props.path();
|
|
183
|
-
} else if (typeof basePath === "function" && typeof props.path !== "function") {
|
|
184
|
-
return basePath();
|
|
185
|
-
} else if (typeof basePath === "function" && typeof props.path === "function") {
|
|
186
|
-
return `${basePath()}.${props.path()}`;
|
|
187
|
-
}
|
|
188
|
-
return "";
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
function useCartValue(options) {
|
|
192
|
-
const cart = useAjaxCart(options.element);
|
|
193
|
-
const value = createMemo(() => {
|
|
194
|
-
const c = cart();
|
|
195
|
-
if (typeof options.path !== "function") return c;
|
|
196
|
-
const path = options.path();
|
|
197
|
-
if (!path) return c;
|
|
198
|
-
const v = getValueFromPath(c, path);
|
|
199
|
-
if (v === void 0 || v === null) return null;
|
|
200
|
-
return v;
|
|
201
|
-
});
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
function useFormattedValue(options) {
|
|
205
|
-
const value = useCartValue({ path: options.path, element: options.element });
|
|
206
|
-
const formattedValue = createMemo(() => {
|
|
207
|
-
const v = value();
|
|
208
|
-
if (v === null) return null;
|
|
209
|
-
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
|
|
210
|
-
return formatValue(options.format || "", v);
|
|
211
|
-
}
|
|
212
|
-
console.warn(
|
|
213
|
-
options.element,
|
|
214
|
-
`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,
|
|
215
|
-
v
|
|
216
|
-
);
|
|
217
|
-
return null;
|
|
218
|
-
});
|
|
219
|
-
return formattedValue;
|
|
220
|
-
}
|
|
221
154
|
function createListenerStatusContext(options) {
|
|
222
155
|
const [privateProps, publicProps] = splitProps(options, ["element"]);
|
|
223
156
|
function setStatus(status) {
|
|
@@ -245,15 +178,24 @@ var useListenerStatus = (element) => {
|
|
|
245
178
|
return useListenerStatusContext(context);
|
|
246
179
|
};
|
|
247
180
|
var withListenerElementStatus = createWithElementContext(ListenerStatusContext);
|
|
181
|
+
|
|
182
|
+
// src/hooks/index.ts
|
|
183
|
+
var hooks = makeFullPropertyPathContext();
|
|
184
|
+
var useCartValue = hooks.usePathValue;
|
|
185
|
+
var useCartPath = hooks.usePath;
|
|
186
|
+
var useCartFormattedValue = hooks.useFormattedValue;
|
|
187
|
+
var provideCartPathContext = hooks.provide;
|
|
248
188
|
var Name2 = "cart-data";
|
|
249
189
|
var Component2 = (props, { element }) => {
|
|
250
190
|
if (!props.propertyName)
|
|
251
191
|
return console.warn(`${Name2}: No property-name attribute provided.`);
|
|
252
|
-
const
|
|
192
|
+
const data = useAjaxCart(element);
|
|
193
|
+
const fullPath = useCartPath({
|
|
253
194
|
element,
|
|
254
195
|
path: () => props.propertyName
|
|
255
196
|
});
|
|
256
|
-
const formattedValue =
|
|
197
|
+
const formattedValue = useCartFormattedValue({
|
|
198
|
+
data,
|
|
257
199
|
get format() {
|
|
258
200
|
return props.format;
|
|
259
201
|
},
|
|
@@ -352,10 +294,11 @@ var Component3 = (_, { element }) => {
|
|
|
352
294
|
}
|
|
353
295
|
})
|
|
354
296
|
);
|
|
355
|
-
const
|
|
297
|
+
const cart = useAjaxCart(element);
|
|
298
|
+
const fullPath = useCartPath({ element });
|
|
356
299
|
const data = useCartValue({
|
|
357
300
|
path: fullPath,
|
|
358
|
-
|
|
301
|
+
data: cart
|
|
359
302
|
});
|
|
360
303
|
element.replaceChildren(...[]);
|
|
361
304
|
return html2`
|
|
@@ -386,17 +329,18 @@ var Component4 = (props, { element }) => {
|
|
|
386
329
|
`${Name4}: No template found with a property of 'item'.`
|
|
387
330
|
);
|
|
388
331
|
if (!props.arrayPath) return console.warn(`${Name4}: No array path provided.`);
|
|
332
|
+
const data = useAjaxCart(element);
|
|
389
333
|
const mergedProps = {
|
|
390
334
|
element,
|
|
391
335
|
path: () => props.arrayPath
|
|
392
336
|
};
|
|
393
|
-
const fullPath =
|
|
394
|
-
|
|
337
|
+
const fullPath = useCartPath(mergedProps);
|
|
338
|
+
provideCartPathContext({
|
|
395
339
|
element,
|
|
396
340
|
path: fullPath
|
|
397
341
|
});
|
|
398
342
|
const value = useCartValue({
|
|
399
|
-
|
|
343
|
+
data,
|
|
400
344
|
path: fullPath
|
|
401
345
|
});
|
|
402
346
|
const arrayValue = createMemo(() => {
|
|
@@ -442,17 +386,18 @@ var Component5 = (props, { element }) => {
|
|
|
442
386
|
`${Name5}: No template found with a property of 'item'.`
|
|
443
387
|
);
|
|
444
388
|
if (!props.arrayPath) return console.warn(`${Name5}: No array path provided.`);
|
|
389
|
+
const data = useAjaxCart(element);
|
|
445
390
|
const mergedProps = {
|
|
446
391
|
element,
|
|
447
392
|
path: () => props.arrayPath
|
|
448
393
|
};
|
|
449
|
-
const fullPath =
|
|
450
|
-
|
|
394
|
+
const fullPath = useCartPath(mergedProps);
|
|
395
|
+
provideCartPathContext({
|
|
451
396
|
element,
|
|
452
397
|
path: fullPath
|
|
453
398
|
});
|
|
454
399
|
const value = useCartValue({
|
|
455
|
-
|
|
400
|
+
data,
|
|
456
401
|
path: fullPath
|
|
457
402
|
});
|
|
458
403
|
const arrayValue = createMemo(() => {
|
|
@@ -524,8 +469,8 @@ var Component6 = (props, { element }) => {
|
|
|
524
469
|
element,
|
|
525
470
|
path: () => props.itemIndex
|
|
526
471
|
};
|
|
527
|
-
const fullPath =
|
|
528
|
-
|
|
472
|
+
const fullPath = useCartPath(mergedProps);
|
|
473
|
+
provideCartPathContext({
|
|
529
474
|
element,
|
|
530
475
|
path: fullPath
|
|
531
476
|
});
|
|
@@ -545,11 +490,12 @@ var Component7 = (props, { element }) => {
|
|
|
545
490
|
return props.status;
|
|
546
491
|
}
|
|
547
492
|
});
|
|
548
|
-
const
|
|
493
|
+
const cart = useAjaxCart(element);
|
|
494
|
+
const path = useCartPath({
|
|
549
495
|
element
|
|
550
496
|
});
|
|
551
497
|
const data = useCartValue({
|
|
552
|
-
|
|
498
|
+
data: cart,
|
|
553
499
|
path
|
|
554
500
|
});
|
|
555
501
|
createEffect(
|
|
@@ -577,7 +523,7 @@ var Component7 = (props, { element }) => {
|
|
|
577
523
|
if (!on5) return console.error(`${Name7}: on property is required!`);
|
|
578
524
|
let resetStatusId = null;
|
|
579
525
|
function onEvent(e) {
|
|
580
|
-
const
|
|
526
|
+
const cart2 = AjaxCart;
|
|
581
527
|
if (preventDefault) e.preventDefault();
|
|
582
528
|
async function handleStatus(promise) {
|
|
583
529
|
setStatus("loading");
|
|
@@ -610,7 +556,7 @@ var Component7 = (props, { element }) => {
|
|
|
610
556
|
);
|
|
611
557
|
if (method === "replaceItem") {
|
|
612
558
|
return handleStatus(
|
|
613
|
-
|
|
559
|
+
cart2.replaceItem({
|
|
614
560
|
key: formObj.key,
|
|
615
561
|
id: formObj.id
|
|
616
562
|
})
|
|
@@ -618,7 +564,7 @@ var Component7 = (props, { element }) => {
|
|
|
618
564
|
}
|
|
619
565
|
if (method === "updateItem") {
|
|
620
566
|
return handleStatus(
|
|
621
|
-
|
|
567
|
+
cart2.updateItem({
|
|
622
568
|
id: formObj.id,
|
|
623
569
|
quantity: formObj?.quantity || void 0,
|
|
624
570
|
properties: formObj?.properties || {},
|
|
@@ -627,30 +573,30 @@ var Component7 = (props, { element }) => {
|
|
|
627
573
|
).finally(reset2);
|
|
628
574
|
}
|
|
629
575
|
if (method === "removeItem") {
|
|
630
|
-
return handleStatus(
|
|
576
|
+
return handleStatus(cart2.removeItem(formObj.key)).finally(reset2);
|
|
631
577
|
}
|
|
632
578
|
if (method === "addDiscount") {
|
|
633
|
-
return handleStatus(
|
|
579
|
+
return handleStatus(cart2.addDiscount(formObj.code)).finally(
|
|
634
580
|
reset2
|
|
635
581
|
);
|
|
636
582
|
}
|
|
637
583
|
if (method === "removeDiscount") {
|
|
638
|
-
return handleStatus(
|
|
584
|
+
return handleStatus(cart2.removeDiscount(formObj.code)).finally(
|
|
639
585
|
reset2
|
|
640
586
|
);
|
|
641
587
|
}
|
|
642
588
|
if (method === "updateNote") {
|
|
643
|
-
return handleStatus(
|
|
589
|
+
return handleStatus(cart2.updateNote(formObj.note)).finally(reset2);
|
|
644
590
|
}
|
|
645
591
|
return;
|
|
646
592
|
}
|
|
647
593
|
const input = e.target;
|
|
648
594
|
if (method === "removeItem") {
|
|
649
|
-
return handleStatus(
|
|
595
|
+
return handleStatus(cart2.removeItem(data2.key));
|
|
650
596
|
}
|
|
651
597
|
if (method === "updateQuantity") {
|
|
652
598
|
return handleStatus(
|
|
653
|
-
|
|
599
|
+
cart2.updateItem({
|
|
654
600
|
id: data2.key,
|
|
655
601
|
quantity: input.valueAsNumber
|
|
656
602
|
})
|
|
@@ -658,14 +604,14 @@ var Component7 = (props, { element }) => {
|
|
|
658
604
|
}
|
|
659
605
|
if (method === "updateItemVariant") {
|
|
660
606
|
return handleStatus(
|
|
661
|
-
|
|
607
|
+
cart2.replaceItem({
|
|
662
608
|
key: data2.key,
|
|
663
609
|
id: input.value
|
|
664
610
|
})
|
|
665
611
|
);
|
|
666
612
|
}
|
|
667
613
|
if (method === "updateNote") {
|
|
668
|
-
return handleStatus(
|
|
614
|
+
return handleStatus(cart2.updateNote(input.value));
|
|
669
615
|
}
|
|
670
616
|
}
|
|
671
617
|
const handleEvent = debounce(onEvent, debounceDelay), controller = new AbortController();
|
|
@@ -739,10 +685,12 @@ var Component9 = (props, { element }) => {
|
|
|
739
685
|
element,
|
|
740
686
|
path: () => props.propertyName
|
|
741
687
|
};
|
|
742
|
-
const
|
|
743
|
-
const
|
|
744
|
-
|
|
688
|
+
const data = useAjaxCart(element);
|
|
689
|
+
const fullPath = useCartPath(mergedProps);
|
|
690
|
+
const value = useCartFormattedValue({
|
|
745
691
|
element,
|
|
692
|
+
path: fullPath,
|
|
693
|
+
data,
|
|
746
694
|
get format() {
|
|
747
695
|
return props.format;
|
|
748
696
|
}
|
|
@@ -764,7 +712,7 @@ var Component9 = (props, { element }) => {
|
|
|
764
712
|
`${Name9}: Unable to find element with selector of: ${props.target}`
|
|
765
713
|
);
|
|
766
714
|
if (injectionType === "attribute" && value2 !== null && value2 !== void 0) {
|
|
767
|
-
target.setAttribute(attributeName, value2);
|
|
715
|
+
target.setAttribute(attributeName, `${value2}`);
|
|
768
716
|
return;
|
|
769
717
|
}
|
|
770
718
|
if (injectionType === "property" && value2 !== null && value2 !== void 0) {
|
|
@@ -793,7 +741,7 @@ var Component9 = (props, { element }) => {
|
|
|
793
741
|
setTimeout(() => {
|
|
794
742
|
target.setAttribute(
|
|
795
743
|
attributeName,
|
|
796
|
-
tmpValue.replace(`{${propertyName}}`, value2)
|
|
744
|
+
tmpValue.replace(`{${propertyName}}`, `${value2}`)
|
|
797
745
|
);
|
|
798
746
|
});
|
|
799
747
|
return onCleanup(() => {
|
|
@@ -923,6 +871,6 @@ customShadowlessElement(
|
|
|
923
871
|
correctElementType(cart_loading_state_exports.Component)
|
|
924
872
|
);
|
|
925
873
|
|
|
926
|
-
export { provideAjaxCartContext,
|
|
874
|
+
export { provideAjaxCartContext, provideCartPathContext, provideListenerStatusContext, useAjaxCart, useAjaxCartContext, useCartFormattedValue, useCartPath, useCartValue, useListenerStatus, useListenerStatusContext, withListenerElementStatus };
|
|
927
875
|
//# sourceMappingURL=index.js.map
|
|
928
876
|
//# sourceMappingURL=index.js.map
|