@brytdesigns/shopify-ajax-cart-components 3.3.3 → 3.4.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 DELETED
@@ -1,883 +0,0 @@
1
- import { createWithElementContext, customShadowlessElement, correctElementType } from '@brytdesigns/web-component-core/utils';
2
- import { splitProps, createEffect, Show, createMemo, For, mapArray, on, onCleanup } from 'solid-js';
3
- import AjaxCart from '@brytdesigns/shopify-ajax-cart';
4
- import { createContext, provide, consume } from 'component-register';
5
- import { makeFullPropertyPathContext } from '@brytdesigns/web-component-core';
6
- import html2 from 'solid-js/html';
7
- import debounce from 'lodash.debounce';
8
-
9
- var __defProp = Object.defineProperty;
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
-
15
- // src/components/cart-context.ts
16
- var cart_context_exports = {};
17
- __export(cart_context_exports, {
18
- Component: () => Component,
19
- Name: () => Name
20
- });
21
- var AjaxCartContext = createContext(() => () => AjaxCart.data);
22
- var provideAjaxCartContext = (element) => {
23
- return provide(AjaxCartContext, {}, element);
24
- };
25
- var useAjaxCartContext = (context) => {
26
- return context;
27
- };
28
- var useAjaxCart = (element) => {
29
- const context = consume(AjaxCartContext, element);
30
- if (!context) {
31
- throw console.error(
32
- "CartContext not found! Please ensure to wrap your custom element with cart-context element."
33
- );
34
- }
35
- return useAjaxCartContext(context);
36
- };
37
-
38
- // src/utils/getValueFromPath.ts
39
- function getValueFromPath(obj, path) {
40
- return path.split(".").reduce((acc, key) => {
41
- if (acc === null || acc === void 0) return void 0;
42
- const isArrayIndex = !isNaN(Number(key)) && key.trim() !== "";
43
- if (Array.isArray(acc) && isArrayIndex) {
44
- return acc[Number(key)];
45
- }
46
- return acc[key];
47
- }, obj);
48
- }
49
-
50
- // src/utils/formatValue.ts
51
- function formatValue(format, value) {
52
- switch (format) {
53
- case "currency":
54
- if (typeof value === "number") return window.Shopify.formatMoney(value);
55
- if (typeof value === "string")
56
- return window.Shopify.formatMoney(parseFloat(value));
57
- console.warn("formatValue: Unsupported value type for currency format.");
58
- return window.Shopify.formatMoney(0);
59
- case "number":
60
- return Number(value);
61
- case "boolean":
62
- return Boolean(value);
63
- case "invert_boolean":
64
- return !Boolean(value);
65
- default:
66
- return value;
67
- }
68
- }
69
-
70
- // src/utils/getTemplateContent.ts
71
- function getTemplateContent(element, state) {
72
- const tmpl = element.querySelector(
73
- `template[${state}]`
74
- );
75
- if (!tmpl) return null;
76
- return tmpl.content;
77
- }
78
-
79
- // src/utils/getTargetElement.ts
80
- function getTargetElement(rootElement, target) {
81
- if (!target) return rootElement;
82
- const t = rootElement.querySelector(target);
83
- if (!t) {
84
- console.error(`target element not found: ${target}`);
85
- return null;
86
- }
87
- return t;
88
- }
89
-
90
- // src/utils/parseNestedObject.ts
91
- function parseNestedObject(data) {
92
- const result = {};
93
- for (const key in data) {
94
- const value = data[key];
95
- const parts = key.match(/(\w+|\[\d+\])/g);
96
- if (!parts) continue;
97
- let current = result;
98
- for (let i = 0; i < parts.length; i++) {
99
- let part = parts[i];
100
- let nextPart = parts[i + 1];
101
- if (!part) continue;
102
- if (part.startsWith("[")) {
103
- part = parseInt(part.slice(1, -1), 10);
104
- }
105
- if (i === parts.length - 1) {
106
- current[part] = value;
107
- } else {
108
- if (typeof parts[i + 1] === "number" || nextPart && nextPart.startsWith("[")) {
109
- current[part] = current[part] || [];
110
- } else {
111
- current[part] = current[part] || {};
112
- }
113
- current = current[part];
114
- }
115
- }
116
- }
117
- return result;
118
- }
119
-
120
- // src/utils/traverseObject.ts
121
- function traverseObject(obj, callback, path = []) {
122
- if (typeof obj !== "object" || obj === null) return;
123
- if (Array.isArray(obj)) {
124
- obj.forEach((item, index) => {
125
- traverseObject(item, callback, [...path, index.toString()]);
126
- });
127
- } else {
128
- for (const key of Object.keys(obj)) {
129
- const value = obj[key];
130
- const currentPath = [...path, key];
131
- traverseObject(value, callback, currentPath);
132
- }
133
- }
134
- }
135
-
136
- // src/components/cart-context.ts
137
- var Name = "cart-context";
138
- var Component = (props, { element }) => {
139
- const cart = provideAjaxCartContext(element);
140
- createEffect(() => {
141
- if (!props.debug) return;
142
- const c = cart();
143
- traverseObject(c);
144
- console.log(`${Name}:updated!`, c);
145
- });
146
- };
147
-
148
- // src/components/cart-data.ts
149
- var cart_data_exports = {};
150
- __export(cart_data_exports, {
151
- Component: () => Component2,
152
- Name: () => Name2
153
- });
154
- function createListenerStatusContext(options) {
155
- const [privateProps, publicProps] = splitProps(options, ["element"]);
156
- function setStatus(status) {
157
- const currentStatus = privateProps.element.getAttribute("status");
158
- if (currentStatus === status) return;
159
- privateProps.element.setAttribute("status", status);
160
- return status;
161
- }
162
- return [() => publicProps.status, setStatus];
163
- }
164
- var ListenerStatusContext = createContext(createListenerStatusContext);
165
- var provideListenerStatusContext = (options) => {
166
- return provide(ListenerStatusContext, options, options.element);
167
- };
168
- var useListenerStatusContext = (context) => {
169
- return context;
170
- };
171
- var useListenerStatus = (element) => {
172
- const context = consume(ListenerStatusContext, element);
173
- if (!context) {
174
- throw console.error(
175
- "CartListenerContext not found! Please ensure to wrap your custom element with cart-data-listener element."
176
- );
177
- }
178
- return useListenerStatusContext(context);
179
- };
180
- var withListenerElementStatus = createWithElementContext(ListenerStatusContext);
181
-
182
- // src/hooks/index.ts
183
- var hooks = makeFullPropertyPathContext();
184
- var useCartValue = (options) => {
185
- const data = useAjaxCart(options.element);
186
- return hooks.usePathValue({
187
- ...options,
188
- data
189
- });
190
- };
191
- var useCartPath = hooks.usePath;
192
- var useCartFormattedValue = (options) => {
193
- const data = useAjaxCart(options.element);
194
- return hooks.useFormattedValue({
195
- data,
196
- get format() {
197
- return options.format;
198
- },
199
- path: options.path
200
- });
201
- };
202
- var provideCartPathContext = hooks.provide;
203
- var Name2 = "cart-data";
204
- var Component2 = (props, { element }) => {
205
- if (!props.propertyName)
206
- return console.warn(`${Name2}: No property-name attribute provided.`);
207
- const fullPath = useCartPath({
208
- element,
209
- path: () => props.propertyName
210
- });
211
- const formattedValue = useCartFormattedValue({
212
- get format() {
213
- return props.format;
214
- },
215
- path: fullPath,
216
- element
217
- });
218
- return html2`
219
- <${Show} when=${() => formattedValue() !== null}> ${formattedValue} <//>
220
- `;
221
- };
222
-
223
- // src/components/cart-data-conditions.ts
224
- var cart_data_conditions_exports = {};
225
- __export(cart_data_conditions_exports, {
226
- Component: () => Component3,
227
- Name: () => Name3
228
- });
229
- function getValue(data, value) {
230
- if (typeof value === "undefined" || !data) return void 0;
231
- if (value.type === "primitive") {
232
- return value.value;
233
- }
234
- if (value.type === "property" && value.name) {
235
- return getValueFromPath(data, value.name);
236
- }
237
- return null;
238
- }
239
- function invertResult(result, invert = false) {
240
- if (invert) return !result;
241
- return result;
242
- }
243
- function validateConditions(conditions, data) {
244
- if (!data) return false;
245
- const result = conditions.every((condition) => {
246
- let valueA = getValue(data, condition.valueA), valueB = getValue(data, condition.valueB), result2 = false;
247
- if (typeof valueA === "undefined" && typeof valueB === "undefined")
248
- return false;
249
- if (condition.type === "typeof") {
250
- result2 = typeof valueA === valueB;
251
- }
252
- if (condition.type === "includes") {
253
- result2 = formatValue(condition.format || "", valueA).includes(
254
- formatValue(condition.format || "", valueB)
255
- );
256
- }
257
- if (condition.type === "includes_property") {
258
- result2 = valueA.some(
259
- (v) => v[condition.valueA?.property_name || ""] === valueB
260
- );
261
- }
262
- if (condition.type === "starts_with") {
263
- result2 = formatValue("string", valueA).startsWith(
264
- formatValue(condition.format || "", valueB)
265
- );
266
- }
267
- if (condition.type === "equals") {
268
- result2 = formatValue(condition.format || "", valueA) === formatValue(condition.format || "", valueB);
269
- }
270
- if (condition.type === "not_equals") {
271
- result2 = formatValue(condition.format || "", valueA) !== formatValue(condition.format || "", valueB);
272
- }
273
- if (condition.type === "lt") {
274
- result2 = formatValue(condition.format || "", valueA) < formatValue(condition.format || "", valueB);
275
- }
276
- if (condition.type === "lte") {
277
- result2 = formatValue(condition.format || "", valueA) <= formatValue(condition.format || "", valueB);
278
- }
279
- if (condition.type === "gt") {
280
- result2 = formatValue(condition.format || "", valueA) > formatValue(condition.format || "", valueB);
281
- }
282
- if (condition.type === "gte") {
283
- result2 = formatValue(condition.format || "", valueA) >= formatValue(condition.format || "", valueB);
284
- }
285
- return invertResult(result2, condition.invert);
286
- });
287
- return result;
288
- }
289
- var Name3 = "cart-data-conditions";
290
- var Component3 = (_, { element }) => {
291
- const conditionTemplates = Array.from(element.children).filter(
292
- (child) => child.tagName === "TEMPLATE" && child.hasAttribute("conditions")
293
- );
294
- if (!conditionTemplates.length)
295
- return console.error(
296
- `${Name3}: no templates found with any conditions attribute!`
297
- );
298
- const allConditions = createMemo(
299
- () => conditionTemplates.map((tmpl) => {
300
- const conditions = tmpl.getAttribute("conditions");
301
- if (!conditions)
302
- console.warn(`${Name3}: conditions attribute is required!`);
303
- try {
304
- return JSON.parse(conditions);
305
- } catch (e) {
306
- return [];
307
- }
308
- })
309
- );
310
- const fullPath = useCartPath({ element });
311
- const data = useCartValue({
312
- path: fullPath,
313
- element
314
- });
315
- element.replaceChildren(...[]);
316
- return html2`
317
- <${For} each=${() => conditionTemplates}>
318
- ${(tmpl, idx) => {
319
- const conditions = allConditions()[idx()];
320
- return html2`
321
- <${Show} when=${() => validateConditions(conditions, data())}>
322
- ${() => Array.from(tmpl.content.cloneNode(true).childNodes)}
323
- <//>
324
- `;
325
- }}
326
- <//>
327
- `;
328
- };
329
-
330
- // src/components/cart-data-array.ts
331
- var cart_data_array_exports = {};
332
- __export(cart_data_array_exports, {
333
- Component: () => Component4,
334
- Name: () => Name4
335
- });
336
- var Name4 = "cart-data-array";
337
- var Component4 = (props, { element }) => {
338
- const itemTemplate = getTemplateContent(element, "item");
339
- if (!itemTemplate)
340
- return console.warn(
341
- `${Name4}: No template found with a property of 'item'.`
342
- );
343
- if (!props.arrayPath) return console.warn(`${Name4}: No array path provided.`);
344
- const mergedProps = {
345
- element,
346
- path: () => props.arrayPath
347
- };
348
- const fullPath = useCartPath(mergedProps);
349
- provideCartPathContext({
350
- element,
351
- path: fullPath
352
- });
353
- const value = useCartValue({
354
- element,
355
- path: fullPath
356
- });
357
- const arrayValue = createMemo(() => {
358
- const v = value();
359
- if (!v) {
360
- console.warn(`${Name4}: value is null or undefined at path ${fullPath()}`);
361
- return null;
362
- }
363
- if (!Array.isArray(v)) {
364
- console.warn(`${Name4}: value is not an array at path ${fullPath()}`);
365
- return null;
366
- }
367
- if (props.reverse) {
368
- return v.toReversed();
369
- }
370
- return v;
371
- });
372
- element.replaceChildren(...[]);
373
- return html2`
374
- <${Show} when=${() => arrayValue() && arrayValue().length > 0}>
375
- <${For} each=${arrayValue}>
376
- ${(_, idx) => html2`
377
- <cart-data-array-item item-index=${() => `${idx()}`} class=${() => props.itemClass}>
378
- ${() => Array.from(itemTemplate.cloneNode(true).childNodes)}
379
- </cart-data-array-item>
380
- `}
381
- <//>
382
- <//>
383
- `;
384
- };
385
-
386
- // src/components/cart-data-array-injection.ts
387
- var cart_data_array_injection_exports = {};
388
- __export(cart_data_array_injection_exports, {
389
- Component: () => Component5,
390
- Name: () => Name5
391
- });
392
- var Name5 = "cart-data-array-injection";
393
- var Component5 = (props, { element }) => {
394
- const itemTemplate = getTemplateContent(element, "item");
395
- if (!itemTemplate)
396
- return console.warn(
397
- `${Name5}: No template found with a property of 'item'.`
398
- );
399
- if (!props.arrayPath) return console.warn(`${Name5}: No array path provided.`);
400
- const mergedProps = {
401
- element,
402
- path: () => props.arrayPath
403
- };
404
- const fullPath = useCartPath(mergedProps);
405
- provideCartPathContext({
406
- element,
407
- path: fullPath
408
- });
409
- const value = useCartValue({
410
- path: fullPath,
411
- element
412
- });
413
- const arrayValue = createMemo(() => {
414
- const v = value();
415
- if (!v) {
416
- console.warn(`${Name5}: value is null or undefined at path ${fullPath()}`);
417
- return null;
418
- }
419
- if (!Array.isArray(v)) {
420
- console.warn(`${Name5}: value is not an array at path ${fullPath()}`);
421
- return null;
422
- }
423
- if (props.reverse) {
424
- return v.toReversed();
425
- }
426
- return v;
427
- });
428
- const children = createMemo(
429
- mapArray(arrayValue, (_, idx) => {
430
- const fragment = itemTemplate.cloneNode(true);
431
- const container = fragment instanceof DocumentFragment ? fragment : null;
432
- if (props.wrapInnerChild && container) {
433
- const firstElement = container.firstElementChild;
434
- if (!firstElement) return null;
435
- const children2 = Array.from(firstElement.children);
436
- const wrapper = html2`
437
- <cart-data-array-item item-index=${() => `${idx()}`}>
438
- ${() => Array.from(children2)}
439
- </cart-data-array-item>
440
- `;
441
- firstElement.replaceChildren(
442
- Array.isArray(wrapper) ? wrapper.at(0) : wrapper
443
- );
444
- return firstElement;
445
- }
446
- })
447
- );
448
- createEffect(
449
- on(
450
- () => {
451
- const rootElement = element;
452
- return {
453
- target: getTargetElement(rootElement, props.target),
454
- children: children()
455
- };
456
- },
457
- ({ children: children2, target }) => {
458
- if (!target) return;
459
- const filteredChildren = children2.filter(
460
- (v) => v !== null && v !== void 0
461
- );
462
- target.replaceChildren(...filteredChildren);
463
- }
464
- )
465
- );
466
- };
467
-
468
- // src/components/cart-data-array-item.ts
469
- var cart_data_array_item_exports = {};
470
- __export(cart_data_array_item_exports, {
471
- Component: () => Component6,
472
- Name: () => Name6
473
- });
474
- var Name6 = "cart-data-array-item";
475
- var Component6 = (props, { element }) => {
476
- if (!props.itemIndex)
477
- return console.warn(`${Name6}: No path attribute provided.`);
478
- const mergedProps = {
479
- element,
480
- path: () => props.itemIndex
481
- };
482
- const fullPath = useCartPath(mergedProps);
483
- provideCartPathContext({
484
- element,
485
- path: fullPath
486
- });
487
- };
488
-
489
- // src/components/cart-data-listener.ts
490
- var cart_data_listener_exports = {};
491
- __export(cart_data_listener_exports, {
492
- Component: () => Component7,
493
- Name: () => Name7
494
- });
495
- var Name7 = "cart-data-listener";
496
- var Component7 = (props, { element }) => {
497
- const [_, setStatus] = provideListenerStatusContext({
498
- element,
499
- get status() {
500
- return props.status;
501
- }
502
- });
503
- const path = useCartPath({
504
- element
505
- });
506
- const data = useCartValue({
507
- element,
508
- path
509
- });
510
- createEffect(
511
- on(
512
- () => ({
513
- method: props.method,
514
- on: props.on,
515
- preventDefault: props.preventDefault,
516
- data: data(),
517
- debounceDelay: props.debounceDelay,
518
- resetForm: props.resetForm,
519
- resetStatusDelay: props.resetStatusDelay
520
- }),
521
- ({
522
- method,
523
- on: on5,
524
- preventDefault,
525
- data: data2,
526
- debounceDelay,
527
- resetForm,
528
- resetStatusDelay
529
- }) => {
530
- if (!method)
531
- return console.error(`${Name7}: method property is required!`);
532
- if (!on5) return console.error(`${Name7}: on property is required!`);
533
- let resetStatusId = null;
534
- function onEvent(e) {
535
- const cart = AjaxCart;
536
- if (preventDefault) e.preventDefault();
537
- async function handleStatus(promise) {
538
- setStatus("loading");
539
- return promise.then((data3) => {
540
- setStatus("success");
541
- return data3;
542
- }).catch((error) => {
543
- setStatus("error");
544
- return error;
545
- }).finally(() => {
546
- if (resetStatusDelay > 0) {
547
- resetStatusId = setTimeout(() => {
548
- setStatus("default");
549
- resetStatusId = null;
550
- }, resetStatusDelay);
551
- } else {
552
- setStatus("default");
553
- }
554
- });
555
- }
556
- if (on5 === "submit") {
557
- let reset2 = function() {
558
- if (resetForm) form.reset();
559
- };
560
- const form = e.target;
561
- const formData = new FormData(form);
562
- const formObj = parseNestedObject(
563
- //@ts-ignore
564
- Object.fromEntries(formData.entries())
565
- );
566
- if (method === "replaceItem") {
567
- return handleStatus(
568
- cart.replaceItem({
569
- key: formObj.key,
570
- id: formObj.id
571
- })
572
- ).finally(reset2);
573
- }
574
- if (method === "updateItem") {
575
- return handleStatus(
576
- cart.updateItem({
577
- id: formObj.id,
578
- quantity: formObj?.quantity || void 0,
579
- properties: formObj?.properties || {},
580
- selling_plan: formObj?.selling_plan || void 0
581
- })
582
- ).finally(reset2);
583
- }
584
- if (method === "removeItem") {
585
- return handleStatus(cart.removeItem(formObj.key)).finally(reset2);
586
- }
587
- if (method === "addDiscount") {
588
- return handleStatus(cart.addDiscount(formObj.code)).finally(
589
- reset2
590
- );
591
- }
592
- if (method === "removeDiscount") {
593
- return handleStatus(cart.removeDiscount(formObj.code)).finally(
594
- reset2
595
- );
596
- }
597
- if (method === "updateNote") {
598
- return handleStatus(cart.updateNote(formObj.note)).finally(reset2);
599
- }
600
- return;
601
- }
602
- const input = e.target;
603
- if (method === "removeItem") {
604
- return handleStatus(cart.removeItem(data2.key));
605
- }
606
- if (method === "updateQuantity") {
607
- return handleStatus(
608
- cart.updateItem({
609
- id: data2.key,
610
- quantity: input.valueAsNumber
611
- })
612
- );
613
- }
614
- if (method === "updateItemVariant") {
615
- return handleStatus(
616
- cart.replaceItem({
617
- key: data2.key,
618
- id: input.value
619
- })
620
- );
621
- }
622
- if (method === "updateNote") {
623
- return handleStatus(cart.updateNote(input.value));
624
- }
625
- }
626
- const handleEvent = debounce(onEvent, debounceDelay), controller = new AbortController();
627
- element.addEventListener(
628
- on5,
629
- (e) => {
630
- if (preventDefault) e.preventDefault();
631
- handleEvent(e);
632
- },
633
- { signal: controller.signal }
634
- );
635
- return onCleanup(() => {
636
- controller.abort();
637
- if (resetStatusId) clearTimeout(resetStatusId);
638
- });
639
- }
640
- )
641
- );
642
- };
643
-
644
- // src/components/cart-data-listener-status.ts
645
- var cart_data_listener_status_exports = {};
646
- __export(cart_data_listener_status_exports, {
647
- Component: () => Component8,
648
- Name: () => Name8
649
- });
650
- var Name8 = "cart-data-listener-status";
651
- var Component8 = (_, { element }) => {
652
- const [status] = useListenerStatus(element);
653
- if (!status) return console.error(`${Name8}: no listener context provided!`);
654
- const templates = {
655
- default: getTemplateContent(element, "default"),
656
- loading: getTemplateContent(element, "loading"),
657
- success: getTemplateContent(element, "success"),
658
- error: getTemplateContent(element, "error")
659
- };
660
- let previousState = null;
661
- const currentStatus = () => {
662
- const s = status();
663
- if (!templates[s]) return previousState;
664
- previousState = s;
665
- return s;
666
- };
667
- element.replaceChildren(...[]);
668
- return createMemo(() => {
669
- const state = currentStatus();
670
- if (!state) return null;
671
- const template = templates[state];
672
- if (!template) return null;
673
- return Array.from(template.cloneNode(true).childNodes);
674
- });
675
- };
676
-
677
- // src/components/cart-data-injection.ts
678
- var cart_data_injection_exports = {};
679
- __export(cart_data_injection_exports, {
680
- Component: () => Component9,
681
- Name: () => Name9
682
- });
683
- var VALID_INJECTION_TYPES = ["attribute", "property", "template"];
684
- var Name9 = "cart-data-injection";
685
- var Component9 = (props, { element }) => {
686
- if (!props.propertyName)
687
- return console.warn(`${Name9}: No path attribute provided.`);
688
- if (!props.target) return console.warn(`${Name9}: No target attribute found!`);
689
- if (!props.attributeName)
690
- return console.warn(`${Name9}: No attribute-name attribute found!`);
691
- if (!props.injectionType || props.injectionType && !VALID_INJECTION_TYPES.includes(props.injectionType))
692
- return console.warn(`${Name9}: Invalid injection-type attribute provided.`);
693
- const mergedProps = {
694
- element,
695
- path: () => props.propertyName
696
- };
697
- const fullPath = useCartPath(mergedProps);
698
- const value = useCartFormattedValue({
699
- element,
700
- path: fullPath,
701
- get format() {
702
- return props.format;
703
- }
704
- });
705
- createEffect(
706
- on(
707
- () => {
708
- return {
709
- target: getTargetElement(element, props.target),
710
- value: value(),
711
- attributeName: props.attributeName,
712
- injectionType: props.injectionType,
713
- propertyName: props.propertyName
714
- };
715
- },
716
- ({ target, value: value2, attributeName, injectionType, propertyName }) => {
717
- if (!target)
718
- return console.warn(
719
- `${Name9}: Unable to find element with selector of: ${props.target}`
720
- );
721
- if (injectionType === "attribute" && value2 !== null && value2 !== void 0) {
722
- target.setAttribute(attributeName, `${value2}`);
723
- return;
724
- }
725
- if (injectionType === "property" && value2 !== null && value2 !== void 0) {
726
- target[attributeName] = value2;
727
- return;
728
- }
729
- if (injectionType === "template" && value2 !== null && value2 !== void 0) {
730
- if (attributeName === "style") {
731
- const styleTmpl = target[attributeName].cssText;
732
- setTimeout(() => {
733
- target[attributeName].cssText = styleTmpl.replace(
734
- //@ts-ignore
735
- `{${propertyName}}`,
736
- value2
737
- );
738
- });
739
- return onCleanup(() => {
740
- target[attributeName].cssText = styleTmpl;
741
- });
742
- }
743
- const tmpValue = target.getAttribute(attributeName);
744
- if (!tmpValue || !value2)
745
- return console.warn(
746
- `${Name9}: Unable to inject value into template`
747
- );
748
- setTimeout(() => {
749
- target.setAttribute(
750
- attributeName,
751
- tmpValue.replace(`{${propertyName}}`, `${value2}`)
752
- );
753
- });
754
- return onCleanup(() => {
755
- target.setAttribute(attributeName, tmpValue);
756
- });
757
- }
758
- }
759
- )
760
- );
761
- };
762
-
763
- // src/components/cart-loading-state.ts
764
- var cart_loading_state_exports = {};
765
- __export(cart_loading_state_exports, {
766
- Component: () => Component10,
767
- Name: () => Name10
768
- });
769
- var Name10 = "cart-loading-state";
770
- var Component10 = (props, { element }) => {
771
- const cart = AjaxCart;
772
- const templates = {
773
- pending: getTemplateContent(element, "pending"),
774
- error: getTemplateContent(element, "error"),
775
- success: getTemplateContent(element, "success")
776
- };
777
- let previousState = null;
778
- const cartState = createMemo(() => {
779
- const state = cart?.status;
780
- if (!templates[state] || props.ignoredStates.includes(state))
781
- return previousState;
782
- previousState = state;
783
- return state;
784
- });
785
- element.replaceChildren(...[]);
786
- return html2`
787
- <${Show} when=${() => cart}>
788
- ${() => {
789
- const state = cartState();
790
- if (!state) return null;
791
- if (!templates[state]) return null;
792
- const children = Array.from(
793
- templates[state].cloneNode(true).childNodes
794
- );
795
- return children;
796
- }}
797
- <//>
798
- `;
799
- };
800
-
801
- // src/index.ts
802
- customShadowlessElement(
803
- cart_context_exports.Name,
804
- { debug: false },
805
- correctElementType(cart_context_exports.Component)
806
- );
807
- customShadowlessElement(
808
- cart_data_array_item_exports.Name,
809
- { itemIndex: "0" },
810
- correctElementType(cart_data_array_item_exports.Component)
811
- );
812
- customShadowlessElement(
813
- cart_data_array_exports.Name,
814
- {
815
- format: "",
816
- arrayPath: "items",
817
- reverse: false,
818
- itemClass: ""
819
- },
820
- correctElementType(cart_data_array_exports.Component)
821
- );
822
- customShadowlessElement(
823
- cart_data_array_injection_exports.Name,
824
- {
825
- format: "",
826
- arrayPath: "items",
827
- target: "",
828
- wrapInnerChild: true,
829
- reverse: false
830
- },
831
- correctElementType(cart_data_array_injection_exports.Component)
832
- );
833
- customShadowlessElement(
834
- cart_data_exports.Name,
835
- {
836
- format: "",
837
- propertyName: "item_count"
838
- },
839
- correctElementType(cart_data_exports.Component)
840
- );
841
- customShadowlessElement(
842
- cart_data_conditions_exports.Name,
843
- {},
844
- correctElementType(cart_data_conditions_exports.Component)
845
- );
846
- customShadowlessElement(
847
- cart_data_injection_exports.Name,
848
- {
849
- propertyName: "item_count",
850
- attributeName: "data-item-count",
851
- injectionType: "attribute",
852
- target: "",
853
- format: ""
854
- },
855
- correctElementType(cart_data_injection_exports.Component)
856
- );
857
- customShadowlessElement(
858
- cart_data_listener_exports.Name,
859
- {
860
- status: "default",
861
- on: "submit",
862
- method: "updateItem",
863
- resetForm: true,
864
- debounceDelay: 0,
865
- resetStatusDelay: 0,
866
- preventDefault: true
867
- },
868
- correctElementType(cart_data_listener_exports.Component)
869
- );
870
- customShadowlessElement(
871
- cart_data_listener_status_exports.Name,
872
- {},
873
- correctElementType(cart_data_listener_status_exports.Component)
874
- );
875
- customShadowlessElement(
876
- cart_loading_state_exports.Name,
877
- { ignoredStates: [] },
878
- correctElementType(cart_loading_state_exports.Component)
879
- );
880
-
881
- export { provideAjaxCartContext, provideCartPathContext, provideListenerStatusContext, useAjaxCart, useAjaxCartContext, useCartFormattedValue, useCartPath, useCartValue, useListenerStatus, useListenerStatusContext, withListenerElementStatus };
882
- //# sourceMappingURL=index.js.map
883
- //# sourceMappingURL=index.js.map