@pradip1995/segment-primitives 0.4.14 → 0.4.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/package.json +3 -1
- package/src/Button.tsx +19 -19
- package/src/Card.tsx +10 -10
- package/src/coupon-apply-result.test.ts +73 -73
- package/src/coupon-apply-result.ts +41 -41
- package/src/coupon-apply.tsx +184 -184
- package/src/format-price.ts +12 -12
- package/src/index.ts +2 -0
- package/src/is-next-redirect.ts +86 -86
- package/src/localized-link.tsx +37 -37
- package/src/notify-wishlist.ts +9 -9
- package/src/optimized-image-src.ts +16 -0
- package/src/order-lines.test.ts +246 -246
- package/src/order-lines.ts +151 -151
- package/src/product-selection-context.tsx +56 -56
- package/src/product-variants.ts +381 -381
- package/src/resolve-media-url.ts +146 -146
- package/src/revalidate-wishlist.ts +8 -8
- package/src/section-variants.ts +13 -13
- package/src/skip-image-optimization.test.ts +27 -0
- package/src/skip-image-optimization.ts +11 -0
- package/src/use-wishlist-count.ts +32 -32
- package/src/wishlist-count.test.ts +96 -96
- package/src/wishlist-count.ts +26 -26
package/src/wishlist-count.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export const WISHLIST_UPDATED_EVENT = "wishlist:updated"
|
|
2
|
-
|
|
3
|
-
export type WishlistUpdatedDetail = {
|
|
4
|
-
delta?: number
|
|
5
|
-
count?: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function nextWishlistCount(
|
|
9
|
-
current: number,
|
|
10
|
-
detail?: WishlistUpdatedDetail | null
|
|
11
|
-
): number {
|
|
12
|
-
const base = Number.isFinite(current) ? Math.max(0, Math.trunc(current)) : 0
|
|
13
|
-
if (!detail) return base
|
|
14
|
-
if (typeof detail.count === "number" && Number.isFinite(detail.count)) {
|
|
15
|
-
return Math.max(0, Math.trunc(detail.count))
|
|
16
|
-
}
|
|
17
|
-
if (typeof detail.delta === "number" && Number.isFinite(detail.delta)) {
|
|
18
|
-
return Math.max(0, base + Math.trunc(detail.delta))
|
|
19
|
-
}
|
|
20
|
-
return base
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function dispatchWishlistUpdated(detail: WishlistUpdatedDetail) {
|
|
24
|
-
if (typeof window === "undefined") return
|
|
25
|
-
window.dispatchEvent(new CustomEvent(WISHLIST_UPDATED_EVENT, { detail }))
|
|
26
|
-
}
|
|
1
|
+
export const WISHLIST_UPDATED_EVENT = "wishlist:updated"
|
|
2
|
+
|
|
3
|
+
export type WishlistUpdatedDetail = {
|
|
4
|
+
delta?: number
|
|
5
|
+
count?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function nextWishlistCount(
|
|
9
|
+
current: number,
|
|
10
|
+
detail?: WishlistUpdatedDetail | null
|
|
11
|
+
): number {
|
|
12
|
+
const base = Number.isFinite(current) ? Math.max(0, Math.trunc(current)) : 0
|
|
13
|
+
if (!detail) return base
|
|
14
|
+
if (typeof detail.count === "number" && Number.isFinite(detail.count)) {
|
|
15
|
+
return Math.max(0, Math.trunc(detail.count))
|
|
16
|
+
}
|
|
17
|
+
if (typeof detail.delta === "number" && Number.isFinite(detail.delta)) {
|
|
18
|
+
return Math.max(0, base + Math.trunc(detail.delta))
|
|
19
|
+
}
|
|
20
|
+
return base
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function dispatchWishlistUpdated(detail: WishlistUpdatedDetail) {
|
|
24
|
+
if (typeof window === "undefined") return
|
|
25
|
+
window.dispatchEvent(new CustomEvent(WISHLIST_UPDATED_EVENT, { detail }))
|
|
26
|
+
}
|