@tapcart/mobile-components 0.12.13 → 0.12.15
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/components/hooks/swr-retry.d.ts +28 -0
- package/dist/components/hooks/swr-retry.d.ts.map +1 -0
- package/dist/components/hooks/swr-retry.js +78 -0
- package/dist/components/hooks/swr-retry.test.d.ts +2 -0
- package/dist/components/hooks/swr-retry.test.d.ts.map +1 -0
- package/dist/components/hooks/swr-retry.test.js +240 -0
- package/dist/components/hooks/use-infinite-scroll.d.ts.map +1 -1
- package/dist/components/hooks/use-infinite-scroll.js +16 -3
- package/dist/components/hooks/use-order-details.d.ts.map +1 -1
- package/dist/components/hooks/use-order-details.js +4 -2
- package/dist/components/hooks/use-reviews.d.ts.map +1 -1
- package/dist/components/hooks/use-reviews.js +3 -10
- package/dist/components/ui/quantity-picker.d.ts.map +1 -1
- package/dist/components/ui/quantity-picker.js +5 -4
- package/dist/components/ui/quantity-pickerNEW.d.ts.map +1 -1
- package/dist/components/ui/quantity-pickerNEW.js +7 -6
- package/dist/components/ui/video-enhanced.d.ts.map +1 -1
- package/dist/components/ui/video-enhanced.js +30 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +15 -0
- package/dist/styles.css +0 -4
- package/dist/tests/quantity-picker.test.d.ts +2 -0
- package/dist/tests/quantity-picker.test.d.ts.map +1 -0
- package/dist/tests/quantity-picker.test.js +50 -0
- package/dist/tests/quantity-pickerNEW.test.d.ts +2 -0
- package/dist/tests/quantity-pickerNEW.test.d.ts.map +1 -0
- package/dist/tests/quantity-pickerNEW.test.js +70 -0
- package/dist/tests/utils.test.js +60 -1
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SWRConfiguration } from "swr";
|
|
2
|
+
export declare const RETRY_COUNT = 3;
|
|
3
|
+
export declare const BASE_INTERVAL_MS = 250;
|
|
4
|
+
export declare const MAX_RETRY_DELAY_MS = 4000;
|
|
5
|
+
export declare const isAbortError: (err: unknown) => boolean;
|
|
6
|
+
export declare const shouldRetryOnError: (err: unknown) => boolean;
|
|
7
|
+
type OnErrorRetry = NonNullable<SWRConfiguration["onErrorRetry"]>;
|
|
8
|
+
type OnSuccess = NonNullable<SWRConfiguration["onSuccess"]>;
|
|
9
|
+
export type SwrRetryConfig = {
|
|
10
|
+
errorRetryCount: number;
|
|
11
|
+
shouldRetryOnError: SWRConfiguration["shouldRetryOnError"];
|
|
12
|
+
onErrorRetry: OnErrorRetry;
|
|
13
|
+
onSuccess: OnSuccess;
|
|
14
|
+
isRetrying: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Shared retry config for SWR-backed hooks consuming the search-client.
|
|
18
|
+
*
|
|
19
|
+
* Custom `onErrorRetry` replaces SWR's built-in scheduler entirely, so the cap
|
|
20
|
+
* guard at the top is required — without it retries are unbounded.
|
|
21
|
+
*
|
|
22
|
+
* `isRetrying` is exposed so the hook can derive a loading state that covers
|
|
23
|
+
* the inter-attempt sleep window (where SWR's `isValidating` and `isLoading`
|
|
24
|
+
* are both false).
|
|
25
|
+
*/
|
|
26
|
+
export declare const useSwrRetryConfig: () => SwrRetryConfig;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=swr-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swr-retry.d.ts","sourceRoot":"","sources":["../../../components/hooks/swr-retry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAE3C,eAAO,MAAM,WAAW,IAAI,CAAA;AAC5B,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAOtC,eAAO,MAAM,YAAY,QAAS,OAAO,KAAG,OAG3C,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,OAAO,KAAG,OAA6B,CAAA;AAiC/E,KAAK,YAAY,GAAG,WAAW,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAA;AACjE,KAAK,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;IAC1D,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAO,cAkCpC,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
export const RETRY_COUNT = 3;
|
|
4
|
+
export const BASE_INTERVAL_MS = 250;
|
|
5
|
+
export const MAX_RETRY_DELAY_MS = 4000;
|
|
6
|
+
export const isAbortError = (err) => {
|
|
7
|
+
if (!err || typeof err !== "object")
|
|
8
|
+
return false;
|
|
9
|
+
return err.name === "AbortError";
|
|
10
|
+
};
|
|
11
|
+
export const shouldRetryOnError = (err) => !isAbortError(err);
|
|
12
|
+
const parseRetryAfter = (value) => {
|
|
13
|
+
if (value === null || value === undefined)
|
|
14
|
+
return null;
|
|
15
|
+
const seconds = typeof value === "number" ? value : Number(value);
|
|
16
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
17
|
+
return Math.round(seconds * 1000);
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "string") {
|
|
20
|
+
const dateMs = Date.parse(value);
|
|
21
|
+
if (Number.isFinite(dateMs)) {
|
|
22
|
+
return Math.max(0, dateMs - Date.now());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
const getRetryAfterMs = (err) => {
|
|
28
|
+
if (!err || typeof err !== "object")
|
|
29
|
+
return null;
|
|
30
|
+
const e = err;
|
|
31
|
+
if (e.status !== 429)
|
|
32
|
+
return null;
|
|
33
|
+
return parseRetryAfter(e.retryAfter);
|
|
34
|
+
};
|
|
35
|
+
const computeBackoffMs = (retryCount) => {
|
|
36
|
+
const exponent = Math.min(Math.max(retryCount - 1, 0), 3);
|
|
37
|
+
const base = (1 << exponent) * BASE_INTERVAL_MS;
|
|
38
|
+
const jitter = 0.7 + Math.random() * 0.6;
|
|
39
|
+
return Math.min(Math.floor(base * jitter), MAX_RETRY_DELAY_MS);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Shared retry config for SWR-backed hooks consuming the search-client.
|
|
43
|
+
*
|
|
44
|
+
* Custom `onErrorRetry` replaces SWR's built-in scheduler entirely, so the cap
|
|
45
|
+
* guard at the top is required — without it retries are unbounded.
|
|
46
|
+
*
|
|
47
|
+
* `isRetrying` is exposed so the hook can derive a loading state that covers
|
|
48
|
+
* the inter-attempt sleep window (where SWR's `isValidating` and `isLoading`
|
|
49
|
+
* are both false).
|
|
50
|
+
*/
|
|
51
|
+
export const useSwrRetryConfig = () => {
|
|
52
|
+
const [retryCount, setRetryCount] = useState(0);
|
|
53
|
+
const onErrorRetry = useCallback((err, _key, _config, revalidate, opts) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const currentRetryCount = (_a = opts === null || opts === void 0 ? void 0 : opts.retryCount) !== null && _a !== void 0 ? _a : 0;
|
|
56
|
+
if (currentRetryCount > RETRY_COUNT) {
|
|
57
|
+
setRetryCount(0);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setRetryCount(currentRetryCount);
|
|
61
|
+
const retryAfterMs = getRetryAfterMs(err);
|
|
62
|
+
const waitMs = retryAfterMs !== null
|
|
63
|
+
? retryAfterMs
|
|
64
|
+
: computeBackoffMs(currentRetryCount);
|
|
65
|
+
setTimeout(() => revalidate(opts), waitMs);
|
|
66
|
+
}, []);
|
|
67
|
+
const onSuccess = useCallback(() => {
|
|
68
|
+
setRetryCount(0);
|
|
69
|
+
}, []);
|
|
70
|
+
const isRetrying = retryCount > 0 && retryCount <= RETRY_COUNT;
|
|
71
|
+
return {
|
|
72
|
+
errorRetryCount: RETRY_COUNT,
|
|
73
|
+
shouldRetryOnError,
|
|
74
|
+
onErrorRetry,
|
|
75
|
+
onSuccess,
|
|
76
|
+
isRetrying,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swr-retry.test.d.ts","sourceRoot":"","sources":["../../../components/hooks/swr-retry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
|
+
import { isAbortError, shouldRetryOnError, useSwrRetryConfig, RETRY_COUNT, BASE_INTERVAL_MS, MAX_RETRY_DELAY_MS, } from "./swr-retry";
|
|
3
|
+
describe("swr-retry helpers", () => {
|
|
4
|
+
describe("isAbortError", () => {
|
|
5
|
+
it("returns true for a DOMException named AbortError", () => {
|
|
6
|
+
const err = new DOMException("aborted", "AbortError");
|
|
7
|
+
expect(isAbortError(err)).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it("returns true for a plain Error named AbortError", () => {
|
|
10
|
+
const err = Object.assign(new Error("aborted"), { name: "AbortError" });
|
|
11
|
+
expect(isAbortError(err)).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
it("returns true for a plain object with name AbortError", () => {
|
|
14
|
+
expect(isAbortError({ name: "AbortError" })).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it("returns false for a generic Error", () => {
|
|
17
|
+
expect(isAbortError(new Error("boom"))).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it("returns false for null / undefined / primitives", () => {
|
|
20
|
+
expect(isAbortError(null)).toBe(false);
|
|
21
|
+
expect(isAbortError(undefined)).toBe(false);
|
|
22
|
+
expect(isAbortError("AbortError")).toBe(false);
|
|
23
|
+
expect(isAbortError(42)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe("shouldRetryOnError", () => {
|
|
27
|
+
it("returns false for AbortError", () => {
|
|
28
|
+
expect(shouldRetryOnError(new DOMException("x", "AbortError"))).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it("returns true for any other error", () => {
|
|
31
|
+
expect(shouldRetryOnError(new Error("boom"))).toBe(true);
|
|
32
|
+
expect(shouldRetryOnError({ status: 500 })).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("useSwrRetryConfig", () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
jest.useFakeTimers();
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
jest.useRealTimers();
|
|
42
|
+
});
|
|
43
|
+
const invoke = (onErrorRetry, err, retryCount, revalidate = jest.fn()) => {
|
|
44
|
+
onErrorRetry(err, "key", {}, revalidate, {
|
|
45
|
+
retryCount,
|
|
46
|
+
dedupe: true,
|
|
47
|
+
});
|
|
48
|
+
return revalidate;
|
|
49
|
+
};
|
|
50
|
+
it("exposes the retry count constant", () => {
|
|
51
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
52
|
+
expect(result.current.errorRetryCount).toBe(RETRY_COUNT);
|
|
53
|
+
});
|
|
54
|
+
it("starts with isRetrying = false", () => {
|
|
55
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
56
|
+
expect(result.current.isRetrying).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
it("sets isRetrying = true after onErrorRetry schedules a retry", () => {
|
|
59
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
60
|
+
const revalidate = jest.fn();
|
|
61
|
+
act(() => {
|
|
62
|
+
invoke(result.current.onErrorRetry, new Error("boom"), 1, revalidate);
|
|
63
|
+
});
|
|
64
|
+
expect(result.current.isRetrying).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
it("schedules revalidate with the full opts object (preserves dedupe)", () => {
|
|
67
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
68
|
+
const revalidate = jest.fn();
|
|
69
|
+
act(() => {
|
|
70
|
+
invoke(result.current.onErrorRetry, new Error("boom"), 1, revalidate);
|
|
71
|
+
});
|
|
72
|
+
act(() => {
|
|
73
|
+
jest.advanceTimersByTime(MAX_RETRY_DELAY_MS + 100);
|
|
74
|
+
});
|
|
75
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
76
|
+
expect(revalidate).toHaveBeenCalledWith(expect.objectContaining({ retryCount: 1, dedupe: true }));
|
|
77
|
+
});
|
|
78
|
+
it("schedules with a delay within the jittered range for attempt 1", () => {
|
|
79
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
80
|
+
const revalidate = jest.fn();
|
|
81
|
+
act(() => {
|
|
82
|
+
invoke(result.current.onErrorRetry, new Error("boom"), 1, revalidate);
|
|
83
|
+
});
|
|
84
|
+
// attempt 1: base = 1 * BASE_INTERVAL_MS, jitter 0.7-1.3 → 175-325ms
|
|
85
|
+
act(() => {
|
|
86
|
+
jest.advanceTimersByTime(BASE_INTERVAL_MS * 1.3 + 1);
|
|
87
|
+
});
|
|
88
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
89
|
+
});
|
|
90
|
+
it("caps the delay at MAX_RETRY_DELAY_MS for high retry counts", () => {
|
|
91
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
92
|
+
const revalidate = jest.fn();
|
|
93
|
+
act(() => {
|
|
94
|
+
// retryCount 3 → exponent 2 → base = 4 * 250 = 1000ms (worst case 1300ms)
|
|
95
|
+
// Cap is 4000ms; verify revalidate fires before exceeding the cap.
|
|
96
|
+
invoke(result.current.onErrorRetry, new Error("boom"), 3, revalidate);
|
|
97
|
+
});
|
|
98
|
+
act(() => {
|
|
99
|
+
jest.advanceTimersByTime(MAX_RETRY_DELAY_MS + 1);
|
|
100
|
+
});
|
|
101
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
102
|
+
});
|
|
103
|
+
it("enforces the cap guard: opts.retryCount > RETRY_COUNT skips scheduling", () => {
|
|
104
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
105
|
+
const revalidate = jest.fn();
|
|
106
|
+
act(() => {
|
|
107
|
+
invoke(result.current.onErrorRetry, new Error("boom"), RETRY_COUNT + 1, revalidate);
|
|
108
|
+
});
|
|
109
|
+
act(() => {
|
|
110
|
+
jest.advanceTimersByTime(MAX_RETRY_DELAY_MS * 2);
|
|
111
|
+
});
|
|
112
|
+
expect(revalidate).not.toHaveBeenCalled();
|
|
113
|
+
expect(result.current.isRetrying).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
it("resets isRetrying = false when retries exhaust", () => {
|
|
116
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
117
|
+
const revalidate = jest.fn();
|
|
118
|
+
// Schedule attempt 1, 2, 3 — each before the next is scheduled
|
|
119
|
+
for (let i = 1; i <= RETRY_COUNT; i++) {
|
|
120
|
+
act(() => {
|
|
121
|
+
invoke(result.current.onErrorRetry, new Error("boom"), i, revalidate);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
expect(result.current.isRetrying).toBe(true);
|
|
125
|
+
// Cap hit: opts.retryCount === RETRY_COUNT + 1 → callback resets state
|
|
126
|
+
act(() => {
|
|
127
|
+
invoke(result.current.onErrorRetry, new Error("boom"), RETRY_COUNT + 1, revalidate);
|
|
128
|
+
});
|
|
129
|
+
expect(result.current.isRetrying).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
it("resets isRetrying = false when onSuccess fires after retries", () => {
|
|
132
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
133
|
+
const revalidate = jest.fn();
|
|
134
|
+
act(() => {
|
|
135
|
+
invoke(result.current.onErrorRetry, new Error("boom"), 1, revalidate);
|
|
136
|
+
});
|
|
137
|
+
expect(result.current.isRetrying).toBe(true);
|
|
138
|
+
act(() => {
|
|
139
|
+
result.current.onSuccess({}, "key", {});
|
|
140
|
+
});
|
|
141
|
+
expect(result.current.isRetrying).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
describe("Retry-After honoring", () => {
|
|
144
|
+
it("uses Retry-After in seconds for 429 errors", () => {
|
|
145
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
146
|
+
const revalidate = jest.fn();
|
|
147
|
+
const err = Object.assign(new Error("rate limit"), {
|
|
148
|
+
status: 429,
|
|
149
|
+
retryAfter: "2",
|
|
150
|
+
});
|
|
151
|
+
act(() => {
|
|
152
|
+
invoke(result.current.onErrorRetry, err, 1, revalidate);
|
|
153
|
+
});
|
|
154
|
+
// Should NOT fire after backoff window (would have been ~175-325ms)
|
|
155
|
+
act(() => {
|
|
156
|
+
jest.advanceTimersByTime(1000);
|
|
157
|
+
});
|
|
158
|
+
expect(revalidate).not.toHaveBeenCalled();
|
|
159
|
+
// Should fire after the 2s Retry-After window
|
|
160
|
+
act(() => {
|
|
161
|
+
jest.advanceTimersByTime(1100);
|
|
162
|
+
});
|
|
163
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
164
|
+
});
|
|
165
|
+
it("uses Retry-After as numeric seconds for 429 errors", () => {
|
|
166
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
167
|
+
const revalidate = jest.fn();
|
|
168
|
+
const err = Object.assign(new Error("rate limit"), {
|
|
169
|
+
status: 429,
|
|
170
|
+
retryAfter: 3,
|
|
171
|
+
});
|
|
172
|
+
act(() => {
|
|
173
|
+
invoke(result.current.onErrorRetry, err, 1, revalidate);
|
|
174
|
+
});
|
|
175
|
+
act(() => {
|
|
176
|
+
jest.advanceTimersByTime(2999);
|
|
177
|
+
});
|
|
178
|
+
expect(revalidate).not.toHaveBeenCalled();
|
|
179
|
+
act(() => {
|
|
180
|
+
jest.advanceTimersByTime(2);
|
|
181
|
+
});
|
|
182
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
183
|
+
});
|
|
184
|
+
it("uses Retry-After as HTTP-date for 429 errors", () => {
|
|
185
|
+
// Anchor system time so toUTCString rounding + Date.parse precision are
|
|
186
|
+
// deterministic. Otherwise the HTTP-date round-trip can lose ~999ms of
|
|
187
|
+
// precision depending on jest fake-timer mode.
|
|
188
|
+
jest.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
|
|
189
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
190
|
+
const revalidate = jest.fn();
|
|
191
|
+
const futureDate = new Date(Date.now() + 5000).toUTCString();
|
|
192
|
+
const err = Object.assign(new Error("rate limit"), {
|
|
193
|
+
status: 429,
|
|
194
|
+
retryAfter: futureDate,
|
|
195
|
+
});
|
|
196
|
+
act(() => {
|
|
197
|
+
invoke(result.current.onErrorRetry, err, 1, revalidate);
|
|
198
|
+
});
|
|
199
|
+
act(() => {
|
|
200
|
+
jest.advanceTimersByTime(4500);
|
|
201
|
+
});
|
|
202
|
+
expect(revalidate).not.toHaveBeenCalled();
|
|
203
|
+
act(() => {
|
|
204
|
+
jest.advanceTimersByTime(1000);
|
|
205
|
+
});
|
|
206
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
207
|
+
});
|
|
208
|
+
it("ignores Retry-After for non-429 errors", () => {
|
|
209
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
210
|
+
const revalidate = jest.fn();
|
|
211
|
+
const err = Object.assign(new Error("server error"), {
|
|
212
|
+
status: 500,
|
|
213
|
+
retryAfter: "10",
|
|
214
|
+
});
|
|
215
|
+
act(() => {
|
|
216
|
+
invoke(result.current.onErrorRetry, err, 1, revalidate);
|
|
217
|
+
});
|
|
218
|
+
// Should fire via normal backoff (~175-325ms), well before 10s.
|
|
219
|
+
act(() => {
|
|
220
|
+
jest.advanceTimersByTime(500);
|
|
221
|
+
});
|
|
222
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
223
|
+
});
|
|
224
|
+
it("falls back to backoff when Retry-After is unparseable", () => {
|
|
225
|
+
const { result } = renderHook(() => useSwrRetryConfig());
|
|
226
|
+
const revalidate = jest.fn();
|
|
227
|
+
const err = Object.assign(new Error("rate limit"), {
|
|
228
|
+
status: 429,
|
|
229
|
+
retryAfter: "not-a-date",
|
|
230
|
+
});
|
|
231
|
+
act(() => {
|
|
232
|
+
invoke(result.current.onErrorRetry, err, 1, revalidate);
|
|
233
|
+
});
|
|
234
|
+
act(() => {
|
|
235
|
+
jest.advanceTimersByTime(MAX_RETRY_DELAY_MS + 100);
|
|
236
|
+
});
|
|
237
|
+
expect(revalidate).toHaveBeenCalledTimes(1);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAG5D,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,GAAG,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;CACxC;AAED,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CA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}
|
|
@@ -13,6 +13,7 @@ import useSWRInfinite from "swr/infinite";
|
|
|
13
13
|
import { useInView } from "react-intersection-observer";
|
|
14
14
|
import { useSearchParams } from "next/navigation";
|
|
15
15
|
import { throttle } from "lodash";
|
|
16
|
+
import { useSwrRetryConfig } from "./swr-retry";
|
|
16
17
|
export const formatSearchParamsAsNextQueryVariables = (searchParams) => {
|
|
17
18
|
const formattedParams = {};
|
|
18
19
|
if (!searchParams)
|
|
@@ -147,11 +148,21 @@ customFetcher, customGetKey, shouldSkipFetch: shouldSkipFetchProp, }) => {
|
|
|
147
148
|
});
|
|
148
149
|
// Check if caller provided pre-fetched products to display while SWR fetches
|
|
149
150
|
const hasInitialProducts = Boolean((_a = initialData === null || initialData === void 0 ? void 0 : initialData.products) === null || _a === void 0 ? void 0 : _a.length);
|
|
150
|
-
const
|
|
151
|
+
const retryConfig = useSwrRetryConfig();
|
|
152
|
+
const { data, error, size, setSize, isLoading: rawIsLoading, isValidating, mutate, } = useSWRInfinite(getKey, fetcher, {
|
|
151
153
|
revalidateFirstPage: false,
|
|
152
154
|
initialSize: 1,
|
|
153
155
|
keepPreviousData: true,
|
|
156
|
+
errorRetryCount: retryConfig.errorRetryCount,
|
|
157
|
+
shouldRetryOnError: retryConfig.shouldRetryOnError,
|
|
158
|
+
onErrorRetry: retryConfig.onErrorRetry,
|
|
159
|
+
onSuccess: retryConfig.onSuccess,
|
|
154
160
|
});
|
|
161
|
+
// Keep the loader visible across the retry window. SWR commits
|
|
162
|
+
// { isValidating: false, isLoading: false } immediately on each failure, so
|
|
163
|
+
// a naive isValidating-based derivation would flash "not loading" during the
|
|
164
|
+
// inter-attempt sleep. `isRetrying` from useSwrRetryConfig closes that gap.
|
|
165
|
+
const isLoading = rawIsLoading || retryConfig.isRetrying;
|
|
155
166
|
// Detect when params change and force cache invalidation
|
|
156
167
|
useEffect(() => {
|
|
157
168
|
const prevParams = prevParamsRef.current;
|
|
@@ -175,8 +186,10 @@ customFetcher, customGetKey, shouldSkipFetch: shouldSkipFetchProp, }) => {
|
|
|
175
186
|
isFirstRender.current = false;
|
|
176
187
|
}, [currentCollectionId, currentCollectionHandle, currentSearchQuery, mutate]);
|
|
177
188
|
// When we have pre-fetched products, don't report as "loading initial data"
|
|
178
|
-
// so the grid renders immediately with those products
|
|
179
|
-
|
|
189
|
+
// so the grid renders immediately with those products.
|
|
190
|
+
// During the retry window (after a failure, before exhaustion) we still
|
|
191
|
+
// want to show as loading-initial-data so blocks keep the loader visible.
|
|
192
|
+
const isLoadingInitialData = !data && !hasInitialProducts && (retryConfig.isRetrying || !error);
|
|
180
193
|
const isLoadingMore = isLoadingInitialData ||
|
|
181
194
|
(size > 0 && data && typeof data[size - 1] === "undefined");
|
|
182
195
|
const isEmpty = data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;AA0LD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;CA+NxE,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;AA0LD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;CA+NxE,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,CA8D1C"}
|
|
@@ -339,7 +339,7 @@ export function useOrderDetails({ variables, apiUrl, appId, language, country, m
|
|
|
339
339
|
});
|
|
340
340
|
useEffect(() => {
|
|
341
341
|
var _a, _b;
|
|
342
|
-
if (
|
|
342
|
+
if (orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails) {
|
|
343
343
|
const updatedOrderDetails = Object.assign({}, orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails);
|
|
344
344
|
if (mock && products.length > 0) {
|
|
345
345
|
updateOrderDetails(updatedOrderDetails, products);
|
|
@@ -352,7 +352,9 @@ export function useOrderDetails({ variables, apiUrl, appId, language, country, m
|
|
|
352
352
|
updateLineDetails(line, orderVariables.checkoutData.lineItems[index]);
|
|
353
353
|
}
|
|
354
354
|
});
|
|
355
|
-
|
|
355
|
+
if (orderVariables.checkoutData) {
|
|
356
|
+
updateCartPriceDetails(updatedOrderDetails, orderVariables.checkoutData);
|
|
357
|
+
}
|
|
356
358
|
}
|
|
357
359
|
setOrderDetails(updatedOrderDetails);
|
|
358
360
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reviews.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-reviews.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAGzB,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACvC,QAAQ,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAA;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,CAAC,MAAM,CAAC,CAAA;IACjB,MAAM,EAAE,CAAC,MAAM,CAAC,CAAA;IAChB,MAAM,EACF,MAAM,GACN,UAAU,GACV,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,eAAe,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,gBAAgB,GAAG,IAAI,CAAA;IAClE,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,eAAe,CAAC,EAAE,GAAG,CAAA;IACrB,oBAAoB,CAAC,EAAE,GAAG,CAAA;IAC1B,eAAe,CAAC,EAAE;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,gBAAgB,EAAE,MAAM,CAA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AAC,EAAE,GAAG,CAAA;IACrB,oBAAoB,CAAC,EAAE,GAAG,CAAA;IAC1B,eAAe,CAAC,EAAE;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,gBAAgB,EAAE,MAAM,CAAA;KACzB,CAAA;CACF,CAAA;AA2ED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,gBAAgB,CA6E1E;AAED,KAAK,wBAAwB,GAAG,gBAAgB,GAAG;IACjD,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;CACrC,CAAA;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,eAAe,GAAG,IAAI,GAC5B,wBAAwB,CA+J1B"}
|
|
@@ -117,7 +117,6 @@ export function useReviews(props) {
|
|
|
117
117
|
}
|
|
118
118
|
export function useReviewsInfinite(props) {
|
|
119
119
|
var _a;
|
|
120
|
-
let url = null;
|
|
121
120
|
const { ref, inView } = useInView({ rootMargin: "800px" });
|
|
122
121
|
let baseURL = "";
|
|
123
122
|
let queryParams = new URLSearchParams();
|
|
@@ -152,14 +151,6 @@ export function useReviewsInfinite(props) {
|
|
|
152
151
|
if (limit) {
|
|
153
152
|
queryParams.set("limit", String(limit));
|
|
154
153
|
}
|
|
155
|
-
if (dataType === null ||
|
|
156
|
-
!productId ||
|
|
157
|
-
!SUPPORTED_PROVIDERS.includes(provider)) {
|
|
158
|
-
url = null;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
url = `${baseURL}/reviews/by-id?${queryParams.toString()}`;
|
|
162
|
-
}
|
|
163
154
|
}
|
|
164
155
|
const isEndReached = useRef(false);
|
|
165
156
|
const getKey = (pageIndex, previousPageData) => {
|
|
@@ -167,7 +158,9 @@ export function useReviewsInfinite(props) {
|
|
|
167
158
|
const dataType = queryParams.get("dataType") === "null"
|
|
168
159
|
? null
|
|
169
160
|
: queryParams.get("dataType");
|
|
170
|
-
if (dataType == null
|
|
161
|
+
if (dataType == null ||
|
|
162
|
+
!(props === null || props === void 0 ? void 0 : props.productId) ||
|
|
163
|
+
!SUPPORTED_PROVIDERS.includes(props === null || props === void 0 ? void 0 : props.provider)) {
|
|
171
164
|
return null;
|
|
172
165
|
}
|
|
173
166
|
if ((props === null || props === void 0 ? void 0 : props.provider) === "yotpo") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity-picker.d.ts","sourceRoot":"","sources":["../../../components/ui/quantity-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAS9B,MAAM,WAAW,mBACf,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAmCD,QAAA,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"quantity-picker.d.ts","sourceRoot":"","sources":["../../../components/ui/quantity-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAS9B,MAAM,WAAW,mBACf,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAmCD,QAAA,MAAM,cAAc,4FA2GnB,CAAA;AAID,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -20,13 +20,14 @@ const IconButton = ({ iconUrl, iconColor, handler, className, style, disabled })
|
|
|
20
20
|
};
|
|
21
21
|
const QuantityPicker = React.forwardRef((_a, ref) => {
|
|
22
22
|
var { className, decreaseIconUrl, increaseIconUrl, deleteIconUrl, isDeleteOnly = false, iconColor, onDecreaseClick, onIncreaseClick, isDecreaseDisabled, isIncreaseDisabled, value, setValue, inputStyle, buttonStyle, buttonCornerRadius = 4, max = 99, loading = false } = _a, props = __rest(_a, ["className", "decreaseIconUrl", "increaseIconUrl", "deleteIconUrl", "isDeleteOnly", "iconColor", "onDecreaseClick", "onIncreaseClick", "isDecreaseDisabled", "isIncreaseDisabled", "value", "setValue", "inputStyle", "buttonStyle", "buttonCornerRadius", "max", "loading"]);
|
|
23
|
+
const safeValue = typeof value === "number" && Number.isFinite(value) ? value : 1;
|
|
23
24
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
24
|
-
const [localValue, setLocalValue] = React.useState(
|
|
25
|
+
const [localValue, setLocalValue] = React.useState(String(safeValue));
|
|
25
26
|
React.useEffect(() => {
|
|
26
27
|
if (!isFocused) {
|
|
27
|
-
setLocalValue(
|
|
28
|
+
setLocalValue(String(safeValue));
|
|
28
29
|
}
|
|
29
|
-
}, [
|
|
30
|
+
}, [safeValue, isFocused]);
|
|
30
31
|
const numberInputStyle = Object.assign({ display: "flex", width: "28px", height: "28px", border: "1px solid #E3E3E3", borderRadius: "8px", textAlign: "center", alignItems: "center", justifyContent: "center", fontSize: "14px" }, inputStyle);
|
|
31
32
|
const leftButtonStyle = Object.assign({ borderTopLeftRadius: buttonCornerRadius
|
|
32
33
|
? `${buttonCornerRadius}px`
|
|
@@ -39,7 +40,7 @@ const QuantityPicker = React.forwardRef((_a, ref) => {
|
|
|
39
40
|
? `${buttonCornerRadius}px`
|
|
40
41
|
: undefined }, buttonStyle);
|
|
41
42
|
const singleButtonStyle = Object.assign({ borderRadius: buttonCornerRadius ? `${buttonCornerRadius}px` : undefined }, buttonStyle);
|
|
42
|
-
return (_jsx("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: isDeleteOnly ? (_jsx(IconButton, { handler: onDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: onDecreaseClick, iconUrl:
|
|
43
|
+
return (_jsx("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: isDeleteOnly ? (_jsx(IconButton, { handler: onDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: onDecreaseClick, iconUrl: safeValue === 1 ? deleteIconUrl : decreaseIconUrl, iconColor: iconColor, style: leftButtonStyle, disabled: isDecreaseDisabled || loading }), _jsx("div", Object.assign({ style: numberInputStyle }, { children: _jsx("span", { children: localValue }) })), _jsx(IconButton, { handler: onIncreaseClick, iconUrl: increaseIconUrl, iconColor: iconColor, style: rightButtonStyle, disabled: isIncreaseDisabled || loading })] })) })));
|
|
43
44
|
});
|
|
44
45
|
QuantityPicker.displayName = "QuantityPicker";
|
|
45
46
|
export { QuantityPicker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quantity-pickerNEW.d.ts","sourceRoot":"","sources":["../../../components/ui/quantity-pickerNEW.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,MAAM,WAAW,sBACf,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,OAAO,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAA;IACxC,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,gBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAChC,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM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,MAAM,iBAAiB,+FA4KtB,CAAA;AAID,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -38,13 +38,14 @@ const IconButton = ({ iconUrl, iconColor, handler, className, style, disabled })
|
|
|
38
38
|
};
|
|
39
39
|
const QuantityPickerNEW = React.forwardRef((_a, ref) => {
|
|
40
40
|
var { className, decreaseIconUrl, increaseIconUrl, deleteIconUrl, isDeleteOnly = false, iconColor, onDecreaseClick, onIncreaseClick, isDecreaseDisabled, isIncreaseDisabled, value, onValueSet, onAdjustQuantity, inputStyle, buttonStyle, buttonCornerRadius = 4, max = 99, loading = false, debounceTime = 300, parentRef } = _a, props = __rest(_a, ["className", "decreaseIconUrl", "increaseIconUrl", "deleteIconUrl", "isDeleteOnly", "iconColor", "onDecreaseClick", "onIncreaseClick", "isDecreaseDisabled", "isIncreaseDisabled", "value", "onValueSet", "onAdjustQuantity", "inputStyle", "buttonStyle", "buttonCornerRadius", "max", "loading", "debounceTime", "parentRef"]);
|
|
41
|
+
const safeValue = typeof value === "number" && Number.isFinite(value) ? value : 1;
|
|
41
42
|
const inputRef = React.useRef(null);
|
|
42
43
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
43
|
-
const [localInputValue, setLocalInputValue] = React.useState(
|
|
44
|
+
const [localInputValue, setLocalInputValue] = React.useState(safeValue);
|
|
44
45
|
// Update local state when external value changes
|
|
45
46
|
React.useEffect(() => {
|
|
46
|
-
setLocalInputValue(
|
|
47
|
-
}, [
|
|
47
|
+
setLocalInputValue(safeValue);
|
|
48
|
+
}, [safeValue]);
|
|
48
49
|
const leftButtonStyle = Object.assign(Object.assign({}, buttonStyle), { borderTopLeftRadius: buttonCornerRadius
|
|
49
50
|
? `${buttonCornerRadius}px`
|
|
50
51
|
: undefined, borderBottomLeftRadius: buttonCornerRadius
|
|
@@ -68,10 +69,10 @@ const QuantityPickerNEW = React.forwardRef((_a, ref) => {
|
|
|
68
69
|
onAdjustQuantity(1);
|
|
69
70
|
onIncreaseClick(e);
|
|
70
71
|
};
|
|
71
|
-
return (_jsxs("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: [isDeleteOnly ? (_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: handleDecreaseClick, iconUrl:
|
|
72
|
+
return (_jsxs("div", Object.assign({ className: cn("flex relative", className), ref: ref }, props, { children: [isDeleteOnly ? (_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: deleteIconUrl, iconColor: iconColor, style: singleButtonStyle })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { handler: handleDecreaseClick, iconUrl: safeValue <= 1 ? deleteIconUrl : decreaseIconUrl, iconColor: iconColor, style: leftButtonStyle, disabled: isDecreaseDisabled || loading }), _jsx("input", { type: "number", step: 1, enterKeyHint: "done", ref: inputRef, disabled: loading, max: max, value: localInputValue, onBlur: (e) => {
|
|
72
73
|
setIsFocused(false);
|
|
73
74
|
if (e.target.value === "") {
|
|
74
|
-
setLocalInputValue(
|
|
75
|
+
setLocalInputValue(safeValue);
|
|
75
76
|
return;
|
|
76
77
|
}
|
|
77
78
|
const parsedValue = parseInt(e.target.value) || 0;
|
|
@@ -109,7 +110,7 @@ const QuantityPickerNEW = React.forwardRef((_a, ref) => {
|
|
|
109
110
|
}
|
|
110
111
|
}, className: "w-8 h-7 focus-visible:outline-no ne text-center bg-coreColors-inputBackground text-textColors-primaryColor border-t border-b border-coreColors-dividingLines", style: Object.assign(Object.assign({}, inputStyle), { borderRadius: (inputStyle === null || inputStyle === void 0 ? void 0 : inputStyle.borderRadius)
|
|
111
112
|
? `${inputStyle.borderRadius}px`
|
|
112
|
-
: 0 }), inputMode: "numeric" }), _jsx(IconButton, { handler: handleIncreaseClick, iconUrl: increaseIconUrl, iconColor: iconColor, style: rightButtonStyle, disabled: isIncreaseDisabled || loading ||
|
|
113
|
+
: 0 }), inputMode: "numeric" }), _jsx(IconButton, { handler: handleIncreaseClick, iconUrl: increaseIconUrl, iconColor: iconColor, style: rightButtonStyle, disabled: isIncreaseDisabled || loading || safeValue >= max })] })), _jsx(LoadingDots, { show: loading, size: 1, iconColor: iconColor })] })));
|
|
113
114
|
});
|
|
114
115
|
QuantityPickerNEW.displayName = "QuantityPickerNEW";
|
|
115
116
|
export { QuantityPickerNEW };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video-enhanced.d.ts","sourceRoot":"","sources":["../../../components/ui/video-enhanced.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAW9B,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,UAAU,UAAW,SAAQ,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC;IACtE,GAAG,EAAE,MAAM,CAAA;IACX,eAAe,EAAE,eAAe,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"video-enhanced.d.ts","sourceRoot":"","sources":["../../../components/ui/video-enhanced.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAW9B,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,UAAU,UAAW,SAAQ,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC;IACtE,GAAG,EAAE,MAAM,CAAA;IACX,eAAe,EAAE,eAAe,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,KAAK,qFAqOV,CAAA;AAID,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,CAAA"}
|
|
@@ -29,7 +29,7 @@ const videoVariants = {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
const Video = React.forwardRef((_a, ref) => {
|
|
32
|
-
var { src, videoAttributes, naturalAspectRatio = "1/1", className } = _a, props = __rest(_a, ["src", "videoAttributes", "naturalAspectRatio", "className"]);
|
|
32
|
+
var { src, videoAttributes, naturalAspectRatio = "1/1", className, onLoadedData } = _a, props = __rest(_a, ["src", "videoAttributes", "naturalAspectRatio", "className", "onLoadedData"]);
|
|
33
33
|
const autoPlayEnabled = videoAttributes.autoplay && !videoAttributes.videoSound;
|
|
34
34
|
const internalRef = React.useRef(null);
|
|
35
35
|
const videoRef = ref || internalRef;
|
|
@@ -132,7 +132,22 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
132
132
|
video.removeEventListener("timeupdate", handleTimeUpdate);
|
|
133
133
|
};
|
|
134
134
|
}, [videoRef]);
|
|
135
|
-
//
|
|
135
|
+
// kick off resource selection on first mount for environments that
|
|
136
|
+
// ignore `preload="metadata"` (e.g., iOS Safari / WebView, Low Power Mode).
|
|
137
|
+
// gated on readyState so re-runs of this effect (e.g., from an unstable
|
|
138
|
+
// parent ref) don't abort an in-flight fetch and restart playback.
|
|
139
|
+
React.useEffect(() => {
|
|
140
|
+
const video = videoRef.current;
|
|
141
|
+
if (!video)
|
|
142
|
+
return;
|
|
143
|
+
if (video.readyState === 0) {
|
|
144
|
+
video.load();
|
|
145
|
+
}
|
|
146
|
+
}, [videoRef]);
|
|
147
|
+
// metadata setup — uses native addEventListener instead of React's JSX
|
|
148
|
+
// onLoadedData because non-bubbling media events can fire in the gap
|
|
149
|
+
// between DOM element creation and React's event listener attachment,
|
|
150
|
+
// especially for browser-cached videos.
|
|
136
151
|
React.useEffect(() => {
|
|
137
152
|
const video = videoRef.current;
|
|
138
153
|
if (!video)
|
|
@@ -147,17 +162,24 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
147
162
|
});
|
|
148
163
|
}
|
|
149
164
|
};
|
|
165
|
+
const handleLoadedData = () => {
|
|
166
|
+
onLoadedData === null || onLoadedData === void 0 ? void 0 : onLoadedData({
|
|
167
|
+
target: video,
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
if (video.readyState >= 1) {
|
|
171
|
+
handleLoadedMetadata();
|
|
172
|
+
}
|
|
173
|
+
if (video.readyState >= 2) {
|
|
174
|
+
handleLoadedData();
|
|
175
|
+
}
|
|
150
176
|
video.addEventListener("loadedmetadata", handleLoadedMetadata);
|
|
177
|
+
video.addEventListener("loadeddata", handleLoadedData);
|
|
151
178
|
return () => {
|
|
152
179
|
video.removeEventListener("loadedmetadata", handleLoadedMetadata);
|
|
180
|
+
video.removeEventListener("loadeddata", handleLoadedData);
|
|
153
181
|
};
|
|
154
182
|
}, []);
|
|
155
|
-
React.useEffect(() => {
|
|
156
|
-
const video = videoRef.current;
|
|
157
|
-
if (!video)
|
|
158
|
-
return;
|
|
159
|
-
video.load();
|
|
160
|
-
}, [videoRef]);
|
|
161
183
|
const videoStyle = {
|
|
162
184
|
aspectRatio: videoAttributes.enabled && videoAttributes.aspectRatio !== "auto"
|
|
163
185
|
? videoAttributes.aspectRatio.replace(":", "/")
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { addItemToWishlist, cn, createCollectionImageMap, cva, formatRelativeTime, getBackgroundAndPaddingStyle, getBackgroundAndSpacingStyle, getBadgesForProductFn, getBorderSidesStyle, getBorderStyle, getColor, getDestinationHandler, getEnabledWishlistIntegration, getGridSpacing, getIdFromGid, getInputPlaceholderTextProps, getLoyaltyButtonProps, getMarginStyle, getOverlayStyle, getPaddingStyle, getProductGidsFromIds, getSpaceBetween, getTextStyle, getVariantGidsFromIds, getVerticalAlignment, getVerticalAlignmentStyle, getWishlistAddItemNavigation, isFavoriteIntegrationEnabled, isVideo, mapFlexToAlignment, parsePhoneNumber, pluralize, productGidFromId, removeItemFromWishlists, stringRatioToInt, supportedVideoExtensions, supportsMultipleWishlists, throttleFunction, variantGidFromId, formatFrequency, formatPrice, } from "./lib/utils";
|
|
1
|
+
export { addItemToWishlist, cn, createCollectionImageMap, cva, formatRelativeTime, getBackgroundAndPaddingStyle, getBackgroundAndSpacingStyle, getBadgesForProductFn, getBorderSidesStyle, getBorderStyle, getColor, getDestinationHandler, getEnabledWishlistIntegration, getGridSpacing, getIdFromGid, getInputPlaceholderTextProps, getLoyaltyButtonProps, getMarginStyle, getOverlayStyle, getPaddingStyle, getProductGidsFromIds, getSpaceBetween, getTextStyle, getVariantGidsFromIds, getVerticalAlignment, getVerticalAlignmentStyle, getWishlistAddItemNavigation, isFavoriteIntegrationEnabled, isVideo, mapFlexToAlignment, parsePhoneNumber, pluralize, productGidFromId, removeItemFromWishlists, stringRatioToInt, supportedVideoExtensions, supportsMultipleWishlists, throttleFunction, variantGidFromId, formatFrequency, formatPrice, shareContent, } from "./lib/utils";
|
|
2
2
|
export type { WishlistEntryMatch } from "./lib/utils";
|
|
3
3
|
export * from "./lib/cart.util";
|
|
4
4
|
export * from "./lib/variablesCart.util";
|
|
@@ -6,6 +6,7 @@ export * from "./lib/isTapcartVersion20.util";
|
|
|
6
6
|
export * from "./components/contexts/translation-context";
|
|
7
7
|
export * from "./components/hooks/use-collection";
|
|
8
8
|
export * from "./components/hooks/use-infinite-scroll";
|
|
9
|
+
export * from "./components/hooks/swr-retry";
|
|
9
10
|
export * from "./components/hooks/use-infinite-wishlist";
|
|
10
11
|
export * from "./components/hooks/use-recommendations";
|
|
11
12
|
export * from "./components/hooks/use-products";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,EAAE,EACF,wBAAwB,EACxB,GAAG,EACH,kBAAkB,EAClB,4BAA4B,EAC5B,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,6BAA6B,EAC7B,cAAc,EACd,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,4BAA4B,EAC5B,4BAA4B,EAC5B,OAAO,EACP,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,EAAE,EACF,wBAAwB,EACxB,GAAG,EACH,kBAAkB,EAClB,4BAA4B,EAC5B,4BAA4B,EAC5B,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,6BAA6B,EAC7B,cAAc,EACd,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,4BAA4B,EAC5B,4BAA4B,EAC5B,OAAO,EACP,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EA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AAA;AACnD,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,8CAA8C,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// component exports
|
|
2
|
-
export { addItemToWishlist, cn, createCollectionImageMap, cva, formatRelativeTime, getBackgroundAndPaddingStyle, getBackgroundAndSpacingStyle, getBadgesForProductFn, getBorderSidesStyle, getBorderStyle, getColor, getDestinationHandler, getEnabledWishlistIntegration, getGridSpacing, getIdFromGid, getInputPlaceholderTextProps, getLoyaltyButtonProps, getMarginStyle, getOverlayStyle, getPaddingStyle, getProductGidsFromIds, getSpaceBetween, getTextStyle, getVariantGidsFromIds, getVerticalAlignment, getVerticalAlignmentStyle, getWishlistAddItemNavigation, isFavoriteIntegrationEnabled, isVideo, mapFlexToAlignment, parsePhoneNumber, pluralize, productGidFromId, removeItemFromWishlists, stringRatioToInt, supportedVideoExtensions, supportsMultipleWishlists, throttleFunction, variantGidFromId, formatFrequency, formatPrice, } from "./lib/utils";
|
|
2
|
+
export { addItemToWishlist, cn, createCollectionImageMap, cva, formatRelativeTime, getBackgroundAndPaddingStyle, getBackgroundAndSpacingStyle, getBadgesForProductFn, getBorderSidesStyle, getBorderStyle, getColor, getDestinationHandler, getEnabledWishlistIntegration, getGridSpacing, getIdFromGid, getInputPlaceholderTextProps, getLoyaltyButtonProps, getMarginStyle, getOverlayStyle, getPaddingStyle, getProductGidsFromIds, getSpaceBetween, getTextStyle, getVariantGidsFromIds, getVerticalAlignment, getVerticalAlignmentStyle, getWishlistAddItemNavigation, isFavoriteIntegrationEnabled, isVideo, mapFlexToAlignment, parsePhoneNumber, pluralize, productGidFromId, removeItemFromWishlists, stringRatioToInt, supportedVideoExtensions, supportsMultipleWishlists, throttleFunction, variantGidFromId, formatFrequency, formatPrice, shareContent, } from "./lib/utils";
|
|
3
3
|
export * from "./lib/cart.util";
|
|
4
4
|
export * from "./lib/variablesCart.util";
|
|
5
5
|
export * from "./lib/isTapcartVersion20.util";
|
|
6
6
|
export * from "./components/contexts/translation-context";
|
|
7
7
|
export * from "./components/hooks/use-collection";
|
|
8
8
|
export * from "./components/hooks/use-infinite-scroll";
|
|
9
|
+
export * from "./components/hooks/swr-retry";
|
|
9
10
|
export * from "./components/hooks/use-infinite-wishlist";
|
|
10
11
|
export * from "./components/hooks/use-recommendations";
|
|
11
12
|
export * from "./components/hooks/use-products";
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1269,4 +1269,5 @@ export declare const evaluateConditions: (group: LogicGroup, context: any) => bo
|
|
|
1269
1269
|
* Returns [language, country] tuple
|
|
1270
1270
|
*/
|
|
1271
1271
|
export declare const parseBCP47Locale: (locale: string | undefined) => [string, string];
|
|
1272
|
+
export declare function shareContent(text: string, tapcartAction?: ((action: string, params: Record<string, unknown>) => void) | null): Promise<void>;
|
|
1272
1273
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,4BAA4B,EAC5B,yBAAyB,EACzB,UAAU,EACV,eAAe,EACf,OAAO,EACP,QAAQ,EACR,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAA;AAMvC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,eAAO,MAAM,wBAAwB,UAAmB,CAAA;AAExD,eAAO,MAAM,OAAO,QAAS,MAAM,KAAG,OACiC,CAAA;AAEvE,eAAO,MAAM,eAAe,SACpB,MAAM,QACN,MAAM,gBACE,OAAO,MAAM,EAAE,MAAM,CAAC,KACnC,MAYF,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,GAAG,YAAY,MAAM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cACvB,yBAAyB,YAoDtC,CAAA;AAGD,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AAED,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,CAAA;IAC3B,UAAU,EAAE,CAAC,SAAS,GAAG,UAAU,CAAC,EAAE,CAAA;CACvC,CAAA;AAoDD,eAAO,MAAM,kBAAkB,UACtB,UAAU,WACR,GAAG,KACX,OAyBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,GAAG,SAAS,KACzB,CAAC,MAAM,EAAE,MAAM,CAoCjB,CAAA;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EACV,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC,GAC3D,IAAI,GACP,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
package/dist/lib/utils.js
CHANGED
|
@@ -876,4 +876,19 @@ export const parseBCP47Locale = (locale) => {
|
|
|
876
876
|
}
|
|
877
877
|
return [language, country];
|
|
878
878
|
};
|
|
879
|
+
export function shareContent(text, tapcartAction) {
|
|
880
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
881
|
+
if (navigator.share) {
|
|
882
|
+
try {
|
|
883
|
+
yield navigator.share({ text });
|
|
884
|
+
}
|
|
885
|
+
catch (error) {
|
|
886
|
+
console.error("Could not initiate share", error);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
tapcartAction === null || tapcartAction === void 0 ? void 0 : tapcartAction("app/share", { text });
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
}
|
|
879
894
|
// --- End (Block conditional rendering util functions) ----
|
package/dist/styles.css
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantity-picker.test.d.ts","sourceRoot":"","sources":["../../tests/quantity-picker.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { QuantityPicker } from "../components/ui/quantity-picker";
|
|
4
|
+
jest.mock("../components/ui/icon", () => ({
|
|
5
|
+
Icon: ({ url }) => (_jsx("img", { "data-testid": "icon", src: url, alt: "" })),
|
|
6
|
+
}));
|
|
7
|
+
const baseProps = {
|
|
8
|
+
decreaseIconUrl: "decrease.svg",
|
|
9
|
+
increaseIconUrl: "increase.svg",
|
|
10
|
+
deleteIconUrl: "delete.svg",
|
|
11
|
+
isDeleteOnly: false,
|
|
12
|
+
iconColor: "#000",
|
|
13
|
+
onDecreaseClick: jest.fn(),
|
|
14
|
+
onIncreaseClick: jest.fn(),
|
|
15
|
+
setValue: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
describe("QuantityPicker safeValue", () => {
|
|
18
|
+
it("displays a valid finite value", () => {
|
|
19
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 5 })));
|
|
20
|
+
expect(screen.getByText("5")).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
it("falls back to 1 when value is NaN", () => {
|
|
23
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: NaN })));
|
|
24
|
+
expect(screen.getByText("1")).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
it("falls back to 1 when value is Infinity", () => {
|
|
27
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: Infinity })));
|
|
28
|
+
expect(screen.getByText("1")).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
it("falls back to 1 when value is -Infinity", () => {
|
|
31
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: -Infinity })));
|
|
32
|
+
expect(screen.getByText("1")).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
it("shows delete icon when safeValue is 1", () => {
|
|
35
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 1 })));
|
|
36
|
+
const icons = screen.getAllByTestId("icon");
|
|
37
|
+
// decrease button is the first icon; at quantity 1 it should use deleteIconUrl
|
|
38
|
+
expect(icons[0].getAttribute("src")).toBe("delete.svg");
|
|
39
|
+
});
|
|
40
|
+
it("shows decrease icon when safeValue is greater than 1", () => {
|
|
41
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 3 })));
|
|
42
|
+
const icons = screen.getAllByTestId("icon");
|
|
43
|
+
expect(icons[0].getAttribute("src")).toBe("decrease.svg");
|
|
44
|
+
});
|
|
45
|
+
it("shows delete icon (not decrease) when a non-finite value falls back to 1", () => {
|
|
46
|
+
render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: NaN })));
|
|
47
|
+
const icons = screen.getAllByTestId("icon");
|
|
48
|
+
expect(icons[0].getAttribute("src")).toBe("delete.svg");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantity-pickerNEW.test.d.ts","sourceRoot":"","sources":["../../tests/quantity-pickerNEW.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { QuantityPickerNEW } from "../components/ui/quantity-pickerNEW";
|
|
4
|
+
jest.mock("../components/ui/icon", () => ({
|
|
5
|
+
Icon: ({ url }) => (_jsx("img", { "data-testid": "icon", src: url, alt: "" })),
|
|
6
|
+
}));
|
|
7
|
+
jest.mock("../components/ui/loading-dots", () => ({
|
|
8
|
+
LoadingDots: () => null,
|
|
9
|
+
}));
|
|
10
|
+
const baseProps = {
|
|
11
|
+
decreaseIconUrl: "decrease.svg",
|
|
12
|
+
increaseIconUrl: "increase.svg",
|
|
13
|
+
deleteIconUrl: "delete.svg",
|
|
14
|
+
isDeleteOnly: false,
|
|
15
|
+
iconColor: "#000",
|
|
16
|
+
onDecreaseClick: jest.fn(),
|
|
17
|
+
onIncreaseClick: jest.fn(),
|
|
18
|
+
onValueSet: jest.fn(),
|
|
19
|
+
onAdjustQuantity: jest.fn(),
|
|
20
|
+
};
|
|
21
|
+
describe("QuantityPickerNEW safeValue", () => {
|
|
22
|
+
it("displays a valid finite value in the input", () => {
|
|
23
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 5 })));
|
|
24
|
+
const input = screen.getByRole("spinbutton");
|
|
25
|
+
expect(input.value).toBe("5");
|
|
26
|
+
});
|
|
27
|
+
it("falls back to 1 when value is NaN", () => {
|
|
28
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: NaN })));
|
|
29
|
+
const input = screen.getByRole("spinbutton");
|
|
30
|
+
expect(input.value).toBe("1");
|
|
31
|
+
});
|
|
32
|
+
it("falls back to 1 when value is Infinity", () => {
|
|
33
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: Infinity })));
|
|
34
|
+
const input = screen.getByRole("spinbutton");
|
|
35
|
+
expect(input.value).toBe("1");
|
|
36
|
+
});
|
|
37
|
+
it("falls back to 1 when value is -Infinity", () => {
|
|
38
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: -Infinity })));
|
|
39
|
+
const input = screen.getByRole("spinbutton");
|
|
40
|
+
expect(input.value).toBe("1");
|
|
41
|
+
});
|
|
42
|
+
it("shows delete icon when safeValue is 1", () => {
|
|
43
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 1 })));
|
|
44
|
+
const icons = screen.getAllByTestId("icon");
|
|
45
|
+
expect(icons[0].getAttribute("src")).toBe("delete.svg");
|
|
46
|
+
});
|
|
47
|
+
it("shows decrease icon when safeValue is greater than 1", () => {
|
|
48
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 3 })));
|
|
49
|
+
const icons = screen.getAllByTestId("icon");
|
|
50
|
+
expect(icons[0].getAttribute("src")).toBe("decrease.svg");
|
|
51
|
+
});
|
|
52
|
+
it("shows delete icon (not decrease) when a non-finite value falls back to 1", () => {
|
|
53
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: NaN })));
|
|
54
|
+
const icons = screen.getAllByTestId("icon");
|
|
55
|
+
expect(icons[0].getAttribute("src")).toBe("delete.svg");
|
|
56
|
+
});
|
|
57
|
+
it("disables the increase button when safeValue equals max", () => {
|
|
58
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 10, max: 10 })));
|
|
59
|
+
const buttons = screen.getAllByRole("button");
|
|
60
|
+
// increase button is the last button
|
|
61
|
+
const increaseButton = buttons[buttons.length - 1];
|
|
62
|
+
expect(increaseButton.disabled).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it("does not disable the increase button when safeValue is below max", () => {
|
|
65
|
+
render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 5, max: 10 })));
|
|
66
|
+
const buttons = screen.getAllByRole("button");
|
|
67
|
+
const increaseButton = buttons[buttons.length - 1];
|
|
68
|
+
expect(increaseButton.disabled).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/dist/tests/utils.test.js
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getDestinationHandler, getTextStyle, parseBCP47Locale, shareContent, } from "../lib/utils";
|
|
11
|
+
describe("shareContent", () => {
|
|
12
|
+
let mockTapcartAction;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockTapcartAction = jest.fn();
|
|
15
|
+
Object.defineProperty(global.navigator, "share", {
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: undefined,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
it("calls navigator.share with text when available", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const mockShare = jest.fn().mockResolvedValue(undefined);
|
|
26
|
+
Object.defineProperty(global.navigator, "share", {
|
|
27
|
+
configurable: true,
|
|
28
|
+
value: mockShare,
|
|
29
|
+
});
|
|
30
|
+
yield shareContent("Check this out https://shop.com/products/hat", mockTapcartAction);
|
|
31
|
+
expect(mockShare).toHaveBeenCalledWith({
|
|
32
|
+
text: "Check this out https://shop.com/products/hat",
|
|
33
|
+
});
|
|
34
|
+
expect(mockTapcartAction).not.toHaveBeenCalled();
|
|
35
|
+
}));
|
|
36
|
+
it("falls back to tapcartAction when navigator.share is unavailable", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
yield shareContent("Check this out https://shop.com/products/hat", mockTapcartAction);
|
|
38
|
+
expect(mockTapcartAction).toHaveBeenCalledWith("app/share", {
|
|
39
|
+
text: "Check this out https://shop.com/products/hat",
|
|
40
|
+
});
|
|
41
|
+
}));
|
|
42
|
+
it("falls back to tapcartAction when tapcartAction is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
yield expect(shareContent("text", undefined)).resolves.toBeUndefined();
|
|
44
|
+
}));
|
|
45
|
+
it("swallows errors from navigator.share and does not call tapcartAction", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const mockShare = jest.fn().mockRejectedValue(new Error("AbortError"));
|
|
47
|
+
Object.defineProperty(global.navigator, "share", {
|
|
48
|
+
configurable: true,
|
|
49
|
+
value: mockShare,
|
|
50
|
+
});
|
|
51
|
+
const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => { });
|
|
52
|
+
yield shareContent("text", mockTapcartAction);
|
|
53
|
+
expect(consoleSpy).toHaveBeenCalledWith("Could not initiate share", expect.any(Error));
|
|
54
|
+
expect(mockTapcartAction).not.toHaveBeenCalled();
|
|
55
|
+
consoleSpy.mockRestore();
|
|
56
|
+
}));
|
|
57
|
+
it("falls back to tapcartAction when tapcartAction is null", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
yield expect(shareContent("text", null)).resolves.toBeUndefined();
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
2
61
|
describe("DESTINATION_HANDLERS", () => {
|
|
3
62
|
describe("url handler", () => {
|
|
4
63
|
const mockActions = {
|