@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.
Files changed (72) hide show
  1. package/dist/esm/index.js +54 -106
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/main/components/cart-context.js +7 -17
  4. package/dist/main/components/cart-context.js.map +1 -1
  5. package/dist/main/components/cart-data-array-injection.js +5 -5
  6. package/dist/main/components/cart-data-array-injection.js.map +1 -1
  7. package/dist/main/components/cart-data-array-item.js +3 -3
  8. package/dist/main/components/cart-data-array-item.js.map +1 -1
  9. package/dist/main/components/cart-data-array.js +5 -4
  10. package/dist/main/components/cart-data-array.js.map +1 -1
  11. package/dist/main/components/cart-data-conditions.js +4 -3
  12. package/dist/main/components/cart-data-conditions.js.map +1 -1
  13. package/dist/main/components/cart-data-injection.js +8 -6
  14. package/dist/main/components/cart-data-injection.js.map +1 -1
  15. package/dist/main/components/cart-data-listener.js +15 -14
  16. package/dist/main/components/cart-data-listener.js.map +1 -1
  17. package/dist/main/components/cart-data.js +5 -3
  18. package/dist/main/components/cart-data.js.map +1 -1
  19. package/dist/main/hooks/index.js +9 -3
  20. package/dist/main/hooks/index.js.map +1 -1
  21. package/dist/main/hooks/useAjaxCart.js.map +1 -1
  22. package/dist/main/index.d.ts +631 -9798
  23. package/dist/main/utils/getValueFromPath.js.map +1 -1
  24. package/package.json +4 -4
  25. package/dist/jsdelivr/components/cart-context.js +0 -22
  26. package/dist/jsdelivr/components/cart-context.js.map +0 -1
  27. package/dist/jsdelivr/components/cart-data-array-item.js +0 -19
  28. package/dist/jsdelivr/components/cart-data-array-item.js.map +0 -1
  29. package/dist/jsdelivr/components/cart-data-array.js +0 -58
  30. package/dist/jsdelivr/components/cart-data-array.js.map +0 -1
  31. package/dist/jsdelivr/components/cart-data-conditions.js +0 -97
  32. package/dist/jsdelivr/components/cart-data-conditions.js.map +0 -1
  33. package/dist/jsdelivr/components/cart-data-injection.js +0 -89
  34. package/dist/jsdelivr/components/cart-data-injection.js.map +0 -1
  35. package/dist/jsdelivr/components/cart-data-listener-status.js +0 -35
  36. package/dist/jsdelivr/components/cart-data-listener-status.js.map +0 -1
  37. package/dist/jsdelivr/components/cart-data-listener.js +0 -163
  38. package/dist/jsdelivr/components/cart-data-listener.js.map +0 -1
  39. package/dist/jsdelivr/components/cart-data.js +0 -29
  40. package/dist/jsdelivr/components/cart-data.js.map +0 -1
  41. package/dist/jsdelivr/components/cart-loading-state.js +0 -39
  42. package/dist/jsdelivr/components/cart-loading-state.js.map +0 -1
  43. package/dist/jsdelivr/components/index.js +0 -11
  44. package/dist/jsdelivr/components/index.js.map +0 -1
  45. package/dist/jsdelivr/hooks/index.js +0 -7
  46. package/dist/jsdelivr/hooks/index.js.map +0 -1
  47. package/dist/jsdelivr/hooks/useCartValue.js +0 -23
  48. package/dist/jsdelivr/hooks/useCartValue.js.map +0 -1
  49. package/dist/jsdelivr/hooks/useFormattedValue.js +0 -27
  50. package/dist/jsdelivr/hooks/useFormattedValue.js.map +0 -1
  51. package/dist/jsdelivr/hooks/useFullPropertyPath.js +0 -35
  52. package/dist/jsdelivr/hooks/useFullPropertyPath.js.map +0 -1
  53. package/dist/jsdelivr/hooks/useHybridCart.js +0 -23
  54. package/dist/jsdelivr/hooks/useHybridCart.js.map +0 -1
  55. package/dist/jsdelivr/hooks/useListenerStatus.js +0 -33
  56. package/dist/jsdelivr/hooks/useListenerStatus.js.map +0 -1
  57. package/dist/jsdelivr/index.js +0 -72
  58. package/dist/jsdelivr/index.js.map +0 -1
  59. package/dist/jsdelivr/utils/formatValue.js +0 -22
  60. package/dist/jsdelivr/utils/formatValue.js.map +0 -1
  61. package/dist/jsdelivr/utils/getTargetElement.js +0 -13
  62. package/dist/jsdelivr/utils/getTargetElement.js.map +0 -1
  63. package/dist/jsdelivr/utils/getTemplateContent.js +0 -11
  64. package/dist/jsdelivr/utils/getTemplateContent.js.map +0 -1
  65. package/dist/jsdelivr/utils/getValueFromPath.js +0 -14
  66. package/dist/jsdelivr/utils/getValueFromPath.js.map +0 -1
  67. package/dist/jsdelivr/utils/index.js +0 -7
  68. package/dist/jsdelivr/utils/index.js.map +0 -1
  69. package/dist/jsdelivr/utils/parseNestedObject.js +0 -32
  70. package/dist/jsdelivr/utils/parseNestedObject.js.map +0 -1
  71. package/dist/main/hooks/useCartValue.js +0 -23
  72. 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, on, createMemo, Show, For, mapArray, onCleanup } from 'solid-js';
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
- on(
142
- () => {
143
- const c = cart();
144
- traverseObject(c);
145
- return {
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 fullPath = useFullPropertyPath({
192
+ const data = useAjaxCart(element);
193
+ const fullPath = useCartPath({
253
194
  element,
254
195
  path: () => props.propertyName
255
196
  });
256
- const formattedValue = useFormattedValue({
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 fullPath = useFullPropertyPath({ element });
297
+ const cart = useAjaxCart(element);
298
+ const fullPath = useCartPath({ element });
356
299
  const data = useCartValue({
357
300
  path: fullPath,
358
- element
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 = useFullPropertyPath(mergedProps);
394
- provideFullPropertyPathContext({
337
+ const fullPath = useCartPath(mergedProps);
338
+ provideCartPathContext({
395
339
  element,
396
340
  path: fullPath
397
341
  });
398
342
  const value = useCartValue({
399
- element,
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 = useFullPropertyPath(mergedProps);
450
- provideFullPropertyPathContext({
394
+ const fullPath = useCartPath(mergedProps);
395
+ provideCartPathContext({
451
396
  element,
452
397
  path: fullPath
453
398
  });
454
399
  const value = useCartValue({
455
- element,
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 = useFullPropertyPath(mergedProps);
528
- provideFullPropertyPathContext({
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 path = useFullPropertyPath({
493
+ const cart = useAjaxCart(element);
494
+ const path = useCartPath({
549
495
  element
550
496
  });
551
497
  const data = useCartValue({
552
- element,
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 cart = AjaxCart;
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
- cart.replaceItem({
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
- cart.updateItem({
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(cart.removeItem(formObj.key)).finally(reset2);
576
+ return handleStatus(cart2.removeItem(formObj.key)).finally(reset2);
631
577
  }
632
578
  if (method === "addDiscount") {
633
- return handleStatus(cart.addDiscount(formObj.code)).finally(
579
+ return handleStatus(cart2.addDiscount(formObj.code)).finally(
634
580
  reset2
635
581
  );
636
582
  }
637
583
  if (method === "removeDiscount") {
638
- return handleStatus(cart.removeDiscount(formObj.code)).finally(
584
+ return handleStatus(cart2.removeDiscount(formObj.code)).finally(
639
585
  reset2
640
586
  );
641
587
  }
642
588
  if (method === "updateNote") {
643
- return handleStatus(cart.updateNote(formObj.note)).finally(reset2);
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(cart.removeItem(data2.key));
595
+ return handleStatus(cart2.removeItem(data2.key));
650
596
  }
651
597
  if (method === "updateQuantity") {
652
598
  return handleStatus(
653
- cart.updateItem({
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
- cart.replaceItem({
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(cart.updateNote(input.value));
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 fullPath = useFullPropertyPath(mergedProps);
743
- const value = useFormattedValue({
744
- path: fullPath,
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, provideFullPropertyPathContext, provideListenerStatusContext, useAjaxCart, useAjaxCartContext, useCartValue, useFormattedValue, useFullPropertyPath, useFullPropertyPathContext, useListenerStatus, useListenerStatusContext, withListenerElementStatus };
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