@tapcart/mobile-components 0.7.61 → 0.7.62

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.
@@ -0,0 +1,16 @@
1
+ import { EnrichedCart, CartCalculatedDiscount, CartCalculatedAppliedGiftCard } from "app-studio-types";
2
+ export declare const isOrderLevelDiscount: (code: string, cart: EnrichedCart) => boolean;
3
+ export declare const isLineItemDiscount: (code: string, cart: EnrichedCart) => boolean;
4
+ export type CalculatedData = {
5
+ orderAndLineItemDiscounts: CartCalculatedDiscount[];
6
+ appliedGiftCards: CartCalculatedAppliedGiftCard[];
7
+ isFreeShipping: boolean;
8
+ discountsTotalAmount: number;
9
+ giftCardsTotalAmount: number;
10
+ salesAmount: number;
11
+ totalCompareAtPrice: number;
12
+ totalDiscountedPrice: number;
13
+ };
14
+ export declare const DEFAULT_CALCULATED_DATA: CalculatedData;
15
+ export declare const getData: (cart: EnrichedCart) => CalculatedData;
16
+ //# sourceMappingURL=calculated-cart-values.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculated-cart-values.util.d.ts","sourceRoot":"","sources":["../../../../components/libs/cart/calculated-cart-values.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,kBAAkB,CAAA;AAuCzB,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAGpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAGlE,CAAA;AAgGD,MAAM,MAAM,cAAc,GAAG;IAC3B,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cASrC,CAAA;AAED,eAAO,MAAM,OAAO,SAAU,YAAY,KAAG,cA4B5C,CAAA"}
@@ -0,0 +1,144 @@
1
+ const getOrderLevelDiscounts = (cart) => {
2
+ var _a;
3
+ const discountMap = (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType !== "SHIPPING_LINE").reduce((acc, discount) => {
4
+ var _a;
5
+ const code = (_a = discount.code) !== null && _a !== void 0 ? _a : "unknown";
6
+ if (!acc[code]) {
7
+ acc[code] = 0;
8
+ }
9
+ acc[code] += parseFloat(discount.discountedAmount.amount);
10
+ return acc;
11
+ }, {});
12
+ if (!discountMap)
13
+ return [];
14
+ return Object.entries(discountMap)
15
+ .map(([code, amount]) => ({
16
+ id: code,
17
+ amount,
18
+ name: `Discount - ${code}`,
19
+ type: "ORDER_LEVEL",
20
+ }))
21
+ .filter((discount) => cart.discounts.includes(discount.id));
22
+ };
23
+ const getShippingDiscounts = (cart) => {
24
+ var _a;
25
+ if (!(cart === null || cart === void 0 ? void 0 : cart.discountAllocations))
26
+ return [];
27
+ return (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType === "SHIPPING_LINE").map((discount) => ({
28
+ amount: discount.discountedAmount.amount,
29
+ code: discount.code,
30
+ type: discount.targetType,
31
+ }));
32
+ };
33
+ export const isOrderLevelDiscount = (code, cart) => {
34
+ const orderLevelDiscounts = getOrderLevelDiscounts(cart);
35
+ return orderLevelDiscounts.some((discount) => discount.id === code);
36
+ };
37
+ export const isLineItemDiscount = (code, cart) => {
38
+ const lineItemDiscounts = getLineItemDiscounts(cart);
39
+ return lineItemDiscounts.some((discount) => discount.id === code);
40
+ };
41
+ const getAppliedGiftCards = (cart) => {
42
+ var _a;
43
+ return (_a = cart.appliedGiftCards) === null || _a === void 0 ? void 0 : _a.map((giftCard) => ({
44
+ id: giftCard.id,
45
+ amount: +giftCard.amountUsed.amount,
46
+ name: `Gift Card - ${giftCard.lastCharacters}`,
47
+ }));
48
+ };
49
+ const getSalesAmount = (cart) => {
50
+ var _a;
51
+ return (_a = cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
52
+ var _a, _b, _c, _d;
53
+ const compareAtPrice = +(((_b = (_a = item.variantDetails) === null || _a === void 0 ? void 0 : _a.compareAtPrice) === null || _b === void 0 ? void 0 : _b.amount) || 0);
54
+ const price = +(((_d = (_c = item.variantDetails) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.amount) || 0);
55
+ const quantity = item.quantity || 1;
56
+ if (compareAtPrice && compareAtPrice > price) {
57
+ return acc + (compareAtPrice - price) * quantity;
58
+ }
59
+ return acc;
60
+ }, 0);
61
+ };
62
+ const getLineItemDiscounts = (cart) => {
63
+ var _a, _b;
64
+ const discountMap = (_a = cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
65
+ var _a;
66
+ (_a = item === null || item === void 0 ? void 0 : item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
67
+ const code = discount === null || discount === void 0 ? void 0 : discount.code;
68
+ if (!code)
69
+ return;
70
+ if (!acc[code]) {
71
+ acc[code] = { amount: 0, type: discount.type };
72
+ }
73
+ acc[code].amount += discount.amount;
74
+ });
75
+ return acc;
76
+ }, {});
77
+ if (!discountMap)
78
+ return [];
79
+ return (_b = Object.entries(discountMap)) === null || _b === void 0 ? void 0 : _b.map(([code, { amount, type }]) => ({
80
+ id: code,
81
+ name: `Discount - ${code}`,
82
+ amount,
83
+ type,
84
+ })).filter((discount) => cart.discounts.includes(discount.id));
85
+ };
86
+ const getDiscountsTotalAmount = (orderAndLineItemDiscounts) => {
87
+ return orderAndLineItemDiscounts === null || orderAndLineItemDiscounts === void 0 ? void 0 : orderAndLineItemDiscounts.reduce((acc, discount) => acc + +discount.amount, 0);
88
+ };
89
+ const getGiftCardsTotalAmount = (appliedGiftCards) => {
90
+ return appliedGiftCards === null || appliedGiftCards === void 0 ? void 0 : appliedGiftCards.reduce((acc, giftCard) => acc + +giftCard.amount, 0);
91
+ };
92
+ const getTotalCompareAtPrice = (cart) => {
93
+ var _a;
94
+ return (_a = cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
95
+ var _a, _b, _c, _d;
96
+ const compareAtPrice = ((_b = (_a = item.variantDetails) === null || _a === void 0 ? void 0 : _a.compareAtPrice) === null || _b === void 0 ? void 0 : _b.amount) ||
97
+ ((_d = (_c = item.variantDetails) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.amount);
98
+ const quantity = item.quantity || 1;
99
+ return acc + +(compareAtPrice || 0) * quantity;
100
+ }, 0);
101
+ };
102
+ const getTotalDiscountedPrice = (totalCompareAtPrice, discountsTotalAmount, salesAmount, giftCardsTotalAmount) => {
103
+ const total = (totalCompareAtPrice === undefined || isNaN(totalCompareAtPrice)
104
+ ? 0
105
+ : totalCompareAtPrice) -
106
+ (discountsTotalAmount === undefined || isNaN(discountsTotalAmount)
107
+ ? 0
108
+ : discountsTotalAmount) -
109
+ (salesAmount === undefined || isNaN(salesAmount) ? 0 : salesAmount) -
110
+ (giftCardsTotalAmount === undefined || isNaN(giftCardsTotalAmount)
111
+ ? 0
112
+ : giftCardsTotalAmount);
113
+ return isNaN(total) ? 0 : total;
114
+ };
115
+ export const DEFAULT_CALCULATED_DATA = {
116
+ orderAndLineItemDiscounts: [],
117
+ appliedGiftCards: [],
118
+ isFreeShipping: false,
119
+ discountsTotalAmount: 0,
120
+ salesAmount: 0,
121
+ giftCardsTotalAmount: 0,
122
+ totalCompareAtPrice: 0,
123
+ totalDiscountedPrice: 0,
124
+ };
125
+ export const getData = (cart) => {
126
+ const orderAndLineItemDiscounts = getOrderLevelDiscounts(cart).concat(getLineItemDiscounts(cart));
127
+ const appliedGiftCards = getAppliedGiftCards(cart);
128
+ const isFreeShipping = getShippingDiscounts(cart).length > 0;
129
+ const discountsTotalAmount = getDiscountsTotalAmount(orderAndLineItemDiscounts);
130
+ const giftCardsTotalAmount = getGiftCardsTotalAmount(appliedGiftCards);
131
+ const salesAmount = getSalesAmount(cart);
132
+ const totalCompareAtPrice = getTotalCompareAtPrice(cart);
133
+ const totalDiscountedPrice = getTotalDiscountedPrice(totalCompareAtPrice, discountsTotalAmount, salesAmount, giftCardsTotalAmount);
134
+ return {
135
+ orderAndLineItemDiscounts,
136
+ appliedGiftCards,
137
+ isFreeShipping,
138
+ discountsTotalAmount,
139
+ giftCardsTotalAmount,
140
+ salesAmount,
141
+ totalCompareAtPrice,
142
+ totalDiscountedPrice,
143
+ };
144
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=calculated-cart-values.util.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculated-cart-values.util.test.d.ts","sourceRoot":"","sources":["../../../../components/libs/cart/calculated-cart-values.util.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,150 @@
1
+ import { getData } from "./calculated-cart-values.util";
2
+ import { DiscountApplicationTargetType } from "app-studio-types";
3
+ const baseCartData = {
4
+ id: "cart123",
5
+ subtotal: 100.0,
6
+ currency: "USD",
7
+ discounts: [],
8
+ attributes: [],
9
+ note: "",
10
+ items: [],
11
+ discountAllocations: [],
12
+ appliedGiftCards: [],
13
+ delivery: {
14
+ addresses: [],
15
+ },
16
+ deliveryGroups: [],
17
+ cost: {
18
+ subtotalAmount: { amount: "0", currencyCode: "" },
19
+ totalAmount: { amount: "0", currencyCode: "" },
20
+ totalTaxAmount: { amount: "0", currencyCode: "" },
21
+ },
22
+ };
23
+ describe("cart-provider.util", () => {
24
+ describe("getData", () => {
25
+ it("should calculate order level discounts correctly", () => {
26
+ const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: ["DISCOUNT10"], items: [], discountAllocations: [
27
+ {
28
+ targetType: DiscountApplicationTargetType.LineItem,
29
+ discountedAmount: { amount: "10.00", currencyCode: "USD" },
30
+ code: "DISCOUNT10",
31
+ },
32
+ ], appliedGiftCards: [], deliveryGroups: [] });
33
+ const result = getData(mockCart);
34
+ expect(result.orderAndLineItemDiscounts).toHaveLength(1);
35
+ expect(result.orderAndLineItemDiscounts[0]).toEqual({
36
+ id: "DISCOUNT10",
37
+ amount: 10,
38
+ name: "Discount - DISCOUNT10",
39
+ type: "ORDER_LEVEL",
40
+ });
41
+ });
42
+ it("should calculate gift cards correctly", () => {
43
+ const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: [], items: [], discountAllocations: [], appliedGiftCards: [
44
+ {
45
+ id: "giftcard1",
46
+ amountUsed: { amount: "25.00", currencyCode: "USD" },
47
+ balance: { amount: "75.00", currencyCode: "USD" },
48
+ lastCharacters: "1234",
49
+ presentmentAmountUsed: { amount: "25.00", currencyCode: "USD" },
50
+ },
51
+ ], deliveryGroups: [] });
52
+ const result = getData(mockCart);
53
+ expect(result.appliedGiftCards).toHaveLength(1);
54
+ expect(result.appliedGiftCards[0]).toEqual({
55
+ id: "giftcard1",
56
+ amount: 25,
57
+ name: "Gift Card - 1234",
58
+ });
59
+ });
60
+ it("should calculate sales amount correctly", () => {
61
+ const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: [], items: [
62
+ {
63
+ id: "line1",
64
+ quantity: 2,
65
+ productId: "prod1",
66
+ variantId: "var1",
67
+ productDetails: {},
68
+ variantDetails: {
69
+ compareAtPrice: { amount: "20.00", currencyCode: "USD" },
70
+ price: { amount: "15.00", currencyCode: "USD" },
71
+ },
72
+ discounts: [],
73
+ cost: { totalAmount: { amount: "30.00", currencyCode: "USD" } },
74
+ },
75
+ ], discountAllocations: [], appliedGiftCards: [], deliveryGroups: [] });
76
+ const result = getData(mockCart);
77
+ expect(result.salesAmount).toBe(10); // (20-15) * 2
78
+ });
79
+ it("should detect free shipping", () => {
80
+ const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: [], items: [], discountAllocations: [
81
+ {
82
+ targetType: DiscountApplicationTargetType.ShippingLine,
83
+ discountedAmount: { amount: "5.00", currencyCode: "USD" },
84
+ code: "FREESHIP",
85
+ },
86
+ ], appliedGiftCards: [], deliveryGroups: [] });
87
+ const result = getData(mockCart);
88
+ expect(result.isFreeShipping).toBe(true);
89
+ });
90
+ it("should calculate total discounted price correctly", () => {
91
+ const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: ["DISCOUNT10"], items: [
92
+ {
93
+ id: "line1",
94
+ quantity: 1,
95
+ productId: "prod1",
96
+ variantId: "var1",
97
+ productDetails: {},
98
+ variantDetails: {
99
+ compareAtPrice: { amount: "100.00", currencyCode: "USD" },
100
+ price: { amount: "80.00", currencyCode: "USD" },
101
+ },
102
+ discounts: [
103
+ {
104
+ amount: 10,
105
+ type: "LINE_ITEM",
106
+ code: "DISCOUNT10",
107
+ },
108
+ ],
109
+ cost: { totalAmount: { amount: "80.00", currencyCode: "USD" } },
110
+ },
111
+ {
112
+ id: "line2",
113
+ quantity: 1,
114
+ productId: "prod2",
115
+ variantId: "var2",
116
+ productDetails: {},
117
+ variantDetails: {
118
+ compareAtPrice: { amount: "100.00", currencyCode: "USD" },
119
+ price: { amount: "80.00", currencyCode: "USD" },
120
+ },
121
+ discounts: [
122
+ {
123
+ amount: 10,
124
+ type: "LINE_ITEM",
125
+ code: "DISCOUNT10",
126
+ },
127
+ ],
128
+ cost: { totalAmount: { amount: "80.00", currencyCode: "USD" } },
129
+ },
130
+ ], discountAllocations: [
131
+ {
132
+ targetType: DiscountApplicationTargetType.LineItem,
133
+ discountedAmount: { amount: "10.00", currencyCode: "USD" },
134
+ code: "DISCOUNT10",
135
+ },
136
+ ], appliedGiftCards: [
137
+ {
138
+ id: "giftcard1",
139
+ amountUsed: { amount: "5.00", currencyCode: "USD" },
140
+ balance: { amount: "95.00", currencyCode: "USD" },
141
+ lastCharacters: "1234",
142
+ presentmentAmountUsed: { amount: "5.00", currencyCode: "USD" },
143
+ },
144
+ ], deliveryGroups: [] });
145
+ const result = getData(mockCart);
146
+ // 100 (compare) - 10 (discount) - 20 (sale) - 5 (gift card) = 65
147
+ expect(result.totalDiscountedPrice).toBe(125);
148
+ });
149
+ });
150
+ });
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=calculatedCartValues.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculatedCartValues.util.d.ts","sourceRoot":"","sources":["../../../../components/libs/cart/calculatedCartValues.util.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -23,7 +23,7 @@ export interface ApplePayButtonProps extends React.ButtonHTMLAttributes<HTMLButt
23
23
  borderRadius?: string | undefined;
24
24
  padding?: string | undefined;
25
25
  boxSizing?: string | undefined;
26
- } | undefined;
26
+ };
27
27
  onPaymentAuthorized?: (paymentData: ApplePayJS.ApplePayPayment) => Promise<boolean>;
28
28
  onShippingContactSelected?: (shippingContact: ApplePayJS.ApplePayPaymentContact) => Promise<ApplePayJS.ApplePayShippingMethodUpdate>;
29
29
  onShippingMethodSelected?: (shippingMethod: ApplePayJS.ApplePayShippingMethod) => Promise<ApplePayJS.ApplePayShippingMethodUpdate>;
@@ -1 +1 @@
1
- {"version":3,"file":"apple-pay-button.d.ts","sourceRoot":"","sources":["../../../components/ui/apple-pay-button.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,WAAW,GACX,MAAM,GACN,KAAK,GACL,WAAW,GACX,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,OAAO,GACP,KAAK,GACL,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,WAAW,GACX,SAAS,GACT,KAAK,GACL,QAAQ,CAAA;AAEZ,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,CAAA;AAErE,MAAM,WAAW,mBACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;I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AE,MAAM,GAAG,SAAS,CAAA;QAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QACjC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC/B,CAAA;IACD,mBAAmB,CAAC,EAAE,CACpB,WAAW,EAAE,UAAU,CAAC,eAAe,KACpC,OAAO,CAAC,OAAO,CAAC,CAAA;IACrB,yBAAyB,CAAC,EAAE,CAC1B,eAAe,EAAE,UAAU,CAAC,sBAAsB,KAC/C,OAAO,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAA;IACrD,wBAAwB,CAAC,EAAE,CACzB,cAAc,EAAE,UAAU,CAAC,sBAAsB,KAC9C,OAAO,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAA;IACrD,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,KAAK,IAAI,CAAA;CACxD;AAED,QAAA,MAAM,cAAc;yWAoBjB,mBAAmB;;CAsKrB,CAAA;AAID,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=cart.util%20copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cart.util copy.d.ts","sourceRoot":"","sources":["../../lib/cart.util copy.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.7.61",
3
+ "version": "0.7.62",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",
@@ -1,10 +0,0 @@
1
- type Customer = {
2
- isAuthenticated: boolean;
3
- };
4
- type UseCustomerProps = {};
5
- type UseCustomerReturn = {
6
- customer: Customer;
7
- };
8
- export declare const useCustomer: (props: UseCustomerProps | null) => UseCustomerReturn;
9
- export {};
10
- //# sourceMappingURL=use-customer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-customer.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-customer.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,KAAK,gBAAgB,GAAG,EAAE,CAAA;AAE1B,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,UACf,gBAAgB,GAAG,IAAI,KAC7B,iBAuBF,CAAA"}
@@ -1,24 +0,0 @@
1
- "use client";
2
- import { useState, useEffect } from "react";
3
- // @ts-ignore -- webbridge-react is not typed (yet)
4
- import { useActions } from "@tapcart/webbridge-react";
5
- export const useCustomer = (props) => {
6
- const [isAuthenticated, setIsAuthenticated] = useState(false);
7
- const [customer, setCustomer] = useState({});
8
- const actions = useActions();
9
- // verify customer
10
- useEffect(() => {
11
- try {
12
- // webbridge method to get customerIdentity
13
- actions.getCustomerIdentity(null, {
14
- onSuccess: (user) => setIsAuthenticated(!!(user === null || user === void 0 ? void 0 : user.email)),
15
- });
16
- }
17
- catch (e) {
18
- console.log("unable to get customer identity ", e);
19
- }
20
- }, [actions]);
21
- return {
22
- customer: Object.assign({ isAuthenticated }, customer),
23
- };
24
- };
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- declare const useTap: (tapThreshold?: number) => {
3
- onTap: (handler: (event: any) => void) => (event: any) => void;
4
- isPressed: boolean;
5
- ref: React.MutableRefObject<null>;
6
- };
7
- export { useTap };
8
- //# sourceMappingURL=use-tap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-tap.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-tap.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAuFvE,QAAA,MAAM,MAAM;6BAuBkC,GAAG,KAAK,IAAI,aACvC,GAAG;;;CAerB,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
@@ -1,100 +0,0 @@
1
- "use client";
2
- import { useState, useEffect, useCallback, useRef } from "react";
3
- // Shared manager for all instances of the hook
4
- const tapManager = (() => {
5
- const elements = new Map();
6
- let isListening = false;
7
- const startListening = () => {
8
- if (isListening)
9
- return;
10
- const handleTouchStart = (e) => {
11
- const touch = e.touches[0];
12
- elements.forEach((data, el) => {
13
- if (el.contains(touch.target)) {
14
- data.touchStarted = true;
15
- data.touchMoved = false;
16
- data.startPosition = { x: touch.clientX, y: touch.clientY };
17
- // Don't set isPressed here, wait to determine if it's a tap or drag
18
- }
19
- });
20
- };
21
- const handleTouchMove = (e) => {
22
- const touch = e.touches[0];
23
- elements.forEach((data, el) => {
24
- if (data.touchStarted) {
25
- const deltaX = Math.abs(touch.clientX - data.startPosition.x);
26
- const deltaY = Math.abs(touch.clientY - data.startPosition.y);
27
- if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
28
- data.touchMoved = true;
29
- data.setIsPressed(false);
30
- }
31
- }
32
- });
33
- };
34
- const handleTouchEnd = () => {
35
- elements.forEach((data) => {
36
- if (data.touchStarted) {
37
- data.touchStarted = false;
38
- if (!data.touchMoved) {
39
- // It's a tap, set isPressed briefly
40
- data.setIsPressed(true);
41
- setTimeout(() => data.setIsPressed(false), 100);
42
- }
43
- }
44
- });
45
- };
46
- document.addEventListener("touchstart", (e) => handleTouchStart(e), { passive: true });
47
- document.addEventListener("touchmove", (e) => handleTouchMove(e), { passive: true });
48
- document.addEventListener("touchend", () => handleTouchEnd(), {
49
- passive: true,
50
- });
51
- isListening = true;
52
- };
53
- return {
54
- register: (el, data) => {
55
- elements.set(el, data);
56
- startListening();
57
- },
58
- unregister: (el) => {
59
- elements.delete(el);
60
- },
61
- elements,
62
- };
63
- })();
64
- const useTap = (tapThreshold = 10) => {
65
- const [isPressed, setIsPressed] = useState(false);
66
- const elementRef = useRef(null);
67
- useEffect(() => {
68
- const element = elementRef.current;
69
- if (!element)
70
- return;
71
- const data = {
72
- touchStarted: false,
73
- touchMoved: false,
74
- startPosition: { x: 0, y: 0 },
75
- setIsPressed,
76
- tapThreshold,
77
- };
78
- tapManager.register(element, data);
79
- return () => {
80
- tapManager.unregister(element);
81
- };
82
- }, [tapThreshold]);
83
- const onTap = useCallback((handler) => {
84
- return (event) => {
85
- const data = tapManager.elements.get(elementRef.current);
86
- if (!data)
87
- return;
88
- if (event.type === "touchend" && !data.touchMoved) {
89
- handler(event);
90
- }
91
- else if (event.type === "click" && !data.touchStarted) {
92
- handler(event);
93
- setIsPressed(true);
94
- setTimeout(() => setIsPressed(false), 100);
95
- }
96
- };
97
- }, []);
98
- return { onTap, isPressed, ref: elementRef };
99
- };
100
- export { useTap };