@tapcart/mobile-components 0.7.65 → 0.7.67
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/use-order-details.d.ts.map +1 -1
- package/dist/components/hooks/use-order-details.js +79 -67
- package/dist/lib/cart.util.d.ts.map +1 -1
- package/dist/lib/cart.util.js +12 -5
- package/dist/lib/cart.util.test.js +2 -2
- package/package.json +20 -20
- package/dist/components/hooks/use-click-outside.d.ts +0 -6
- package/dist/components/hooks/use-click-outside.d.ts.map +0 -1
- package/dist/components/hooks/use-click-outside.js +0 -15
- package/dist/components/hooks/use-outside-click.d.ts +0 -7
- package/dist/components/hooks/use-outside-click.d.ts.map +0 -1
- package/dist/components/hooks/use-outside-click.js +0 -16
- package/dist/components/hooks/use-tap.d.ts +0 -8
- package/dist/components/hooks/use-tap.d.ts.map +0 -1
- package/dist/components/hooks/use-tap.js +0 -100
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"
|
|
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;AAkKD,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,CA6C1C"}
|
|
@@ -1,53 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { getIdFromGid } from "../../lib/utils";
|
|
3
|
-
import { useProducts } from "./use-products";
|
|
4
2
|
import { useEffect, useMemo, useState } from "react";
|
|
5
|
-
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const productId = getIdFromGid(productGid);
|
|
8
|
-
const item = lineItems.find((item) => { var _a, _b; return ((_b = (_a = item === null || item === void 0 ? void 0 : item.variant) === null || _a === void 0 ? void 0 : _a.product) === null || _b === void 0 ? void 0 : _b.id) === productId; });
|
|
9
|
-
if (!item) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
return (_b = (_a = item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) === null || _a === void 0 ? void 0 : _a.sellingPlan) === null || _b === void 0 ? void 0 : _b.name;
|
|
13
|
-
};
|
|
14
|
-
const getSalesAmount = (lines) => {
|
|
15
|
-
return lines === null || lines === void 0 ? void 0 : lines.reduce((acc, line) => {
|
|
16
|
-
const sale = line.sale ? parseFloat(line.sale) : 0;
|
|
17
|
-
return acc + sale * line.quantity;
|
|
18
|
-
}, 0);
|
|
19
|
-
};
|
|
20
|
-
const getSubtotal = (lines) => {
|
|
21
|
-
return lines === null || lines === void 0 ? void 0 : lines.reduce((acc, line) => {
|
|
22
|
-
const price = parseFloat(line.compareAtPrice ? line.compareAtPrice.amount : line.price.amount);
|
|
23
|
-
return acc + price * line.quantity;
|
|
24
|
-
}, 0);
|
|
25
|
-
};
|
|
26
|
-
const findProductById = (products, productId) => products.find((product) => product.id === productId);
|
|
27
|
-
const findVariantById = (variants, merchandiseId) => variants.find((variant) => variant.id === merchandiseId);
|
|
28
|
-
const calculateSale = (compareAtPrice, price) => parseFloat(compareAtPrice) - parseFloat(price);
|
|
29
|
-
const updateLineWithVariantDetails = (line, variant) => {
|
|
30
|
-
var _a;
|
|
31
|
-
line.compareAtPrice = variant.compareAtPrice;
|
|
32
|
-
line.variantName = variant.title;
|
|
33
|
-
line.sale = ((_a = variant.compareAtPrice) === null || _a === void 0 ? void 0 : _a.amount)
|
|
34
|
-
? calculateSale(variant.compareAtPrice.amount, variant.price.amount)
|
|
35
|
-
: 0;
|
|
36
|
-
};
|
|
37
|
-
const updateLineDetails = (line, products, checkoutData) => {
|
|
38
|
-
const product = findProductById(products, line.productId);
|
|
39
|
-
if (!product)
|
|
40
|
-
return;
|
|
41
|
-
line.title = product.title;
|
|
42
|
-
line.vendor = product.vendor;
|
|
43
|
-
if (checkoutData && checkoutData.lineItems) {
|
|
44
|
-
line.sellingPlan = getSellingPlan(checkoutData.lineItems, line.productId);
|
|
45
|
-
}
|
|
46
|
-
const productVariant = findVariantById(product.variants, line.merchandiseId);
|
|
47
|
-
if (productVariant) {
|
|
48
|
-
updateLineWithVariantDetails(line, productVariant);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
3
|
+
import { useProducts } from "./use-products";
|
|
51
4
|
const getProductIds = (lines) => lines === null || lines === void 0 ? void 0 : lines.map((line) => line.productId);
|
|
52
5
|
const calculateCompareAtPrice = (variant) => {
|
|
53
6
|
var _a, _b, _c, _d;
|
|
@@ -75,34 +28,46 @@ const createCartLines = (product, variant, compareAtPrice) => {
|
|
|
75
28
|
price: variant === null || variant === void 0 ? void 0 : variant.price,
|
|
76
29
|
compareAtPrice,
|
|
77
30
|
variantName: variant.title,
|
|
78
|
-
sale: calculateSale(compareAtPrice.amount, variant.price.amount),
|
|
79
31
|
},
|
|
80
32
|
];
|
|
81
33
|
};
|
|
82
|
-
const calculateCartPrice = (
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
34
|
+
const calculateCartPrice = (lines) => {
|
|
35
|
+
const subtotal = lines[0].price;
|
|
36
|
+
const orderLevelDiscounts = [
|
|
37
|
+
{
|
|
38
|
+
title: "APP15",
|
|
39
|
+
valueType: "percentage",
|
|
40
|
+
value: { currencyCode: "USD", amount: 15.0 },
|
|
41
|
+
applicationType: "code",
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const shippingLevelDiscounts = [
|
|
87
45
|
{
|
|
88
|
-
|
|
89
|
-
title: "WELCOME20",
|
|
46
|
+
title: "FREESHIPPING",
|
|
90
47
|
valueType: "percentage",
|
|
91
|
-
value:
|
|
48
|
+
value: { currencyCode: "USD", amount: 30.0 },
|
|
92
49
|
applicationType: "code",
|
|
93
50
|
},
|
|
94
51
|
];
|
|
95
52
|
const taxes = { amount: 5.0, currencyCode: "USD" };
|
|
53
|
+
const oldShipping = { amount: 30, currencyCode: "USD" };
|
|
96
54
|
const shipping = { amount: 0, currencyCode: "USD" };
|
|
97
55
|
const total = {
|
|
98
|
-
amount: subtotal -
|
|
99
|
-
|
|
100
|
-
discounts[0].amount.amount -
|
|
56
|
+
amount: subtotal.amount -
|
|
57
|
+
orderLevelDiscounts[0].value.amount -
|
|
101
58
|
20 + // Payment method amount
|
|
102
59
|
taxes.amount,
|
|
103
60
|
currencyCode: "USD",
|
|
104
61
|
};
|
|
105
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
subtotal,
|
|
64
|
+
orderLevelDiscounts,
|
|
65
|
+
shippingLevelDiscounts,
|
|
66
|
+
taxes,
|
|
67
|
+
shipping,
|
|
68
|
+
oldShipping,
|
|
69
|
+
total,
|
|
70
|
+
};
|
|
106
71
|
};
|
|
107
72
|
const updateOrderDetails = (orderDetails, products) => {
|
|
108
73
|
const product = products[0];
|
|
@@ -112,7 +77,49 @@ const updateOrderDetails = (orderDetails, products) => {
|
|
|
112
77
|
orderDetails.cart = {
|
|
113
78
|
lines: createCartLines(product, variant, compareAtPrice),
|
|
114
79
|
};
|
|
115
|
-
orderDetails.cart.price = calculateCartPrice(
|
|
80
|
+
orderDetails.cart.price = calculateCartPrice(orderDetails.cart.lines);
|
|
81
|
+
};
|
|
82
|
+
const mapDiscountsByType = (discounts = [], type) => {
|
|
83
|
+
return discounts.filter((discount) => discount.targetType === type && discount.targetSelection === "ALL");
|
|
84
|
+
};
|
|
85
|
+
const mapShippingDiscount = (discounts = [], shipping) => {
|
|
86
|
+
const mappedDiscounts = mapDiscountsByType(discounts, "SHIPPING_LINE");
|
|
87
|
+
return mappedDiscounts.map((discount) => {
|
|
88
|
+
var _a;
|
|
89
|
+
return (Object.assign(Object.assign({}, discount), { value: {
|
|
90
|
+
currencyCode: shipping.currencyCode,
|
|
91
|
+
amount: ((shipping === null || shipping === void 0 ? void 0 : shipping.amount) * ((_a = discount.value) === null || _a === void 0 ? void 0 : _a.percentage)) / 100,
|
|
92
|
+
} }));
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const updateCartPriceDetails = (orderDetails, checkoutData) => {
|
|
96
|
+
var _a;
|
|
97
|
+
const newCartPrice = {
|
|
98
|
+
subtotal: checkoutData.subtotalPrice,
|
|
99
|
+
orderLevelDiscounts: mapDiscountsByType(checkoutData.discountApplications, "LINE_ITEM"),
|
|
100
|
+
shippingLevelDiscounts: mapShippingDiscount(checkoutData.discountApplications, orderDetails.cart.price.shipping),
|
|
101
|
+
total: checkoutData.totalPrice,
|
|
102
|
+
taxes: checkoutData.totalTax,
|
|
103
|
+
shipping: (_a = checkoutData.shippingLine) === null || _a === void 0 ? void 0 : _a.price,
|
|
104
|
+
oldShipping: orderDetails.cart.price.shipping,
|
|
105
|
+
};
|
|
106
|
+
orderDetails.cart.price = newCartPrice;
|
|
107
|
+
};
|
|
108
|
+
const updateLineDetails = (line, product) => {
|
|
109
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
110
|
+
if (!product) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
line.uniqueId = crypto.randomUUID();
|
|
114
|
+
line.title = (_b = (_a = product.variant) === null || _a === void 0 ? void 0 : _a.product) === null || _b === void 0 ? void 0 : _b.title;
|
|
115
|
+
line.vendor = (_d = (_c = product.variant) === null || _c === void 0 ? void 0 : _c.product) === null || _d === void 0 ? void 0 : _d.vendor;
|
|
116
|
+
line.compareAtPrice = {
|
|
117
|
+
amount: ((_f = (_e = product === null || product === void 0 ? void 0 : product.variant) === null || _e === void 0 ? void 0 : _e.price) === null || _f === void 0 ? void 0 : _f.amount) * (product === null || product === void 0 ? void 0 : product.quantity),
|
|
118
|
+
currencyCode: (_h = (_g = product === null || product === void 0 ? void 0 : product.variant) === null || _g === void 0 ? void 0 : _g.price) === null || _h === void 0 ? void 0 : _h.currencyCode,
|
|
119
|
+
};
|
|
120
|
+
line.price = product.finalLinePrice;
|
|
121
|
+
line.sellingPlan = (_k = (_j = product.sellingPlanAllocation) === null || _j === void 0 ? void 0 : _j.sellingPlan) === null || _k === void 0 ? void 0 : _k.name;
|
|
122
|
+
line.variantName = (_l = product.variant) === null || _l === void 0 ? void 0 : _l.title;
|
|
116
123
|
};
|
|
117
124
|
export function useOrderDetails({ variables, apiUrl, appId, language, country, mock = false, }) {
|
|
118
125
|
const [orderDetails, setOrderDetails] = useState({});
|
|
@@ -128,20 +135,25 @@ export function useOrderDetails({ variables, apiUrl, appId, language, country, m
|
|
|
128
135
|
mock,
|
|
129
136
|
});
|
|
130
137
|
useEffect(() => {
|
|
131
|
-
var _a, _b
|
|
138
|
+
var _a, _b;
|
|
132
139
|
if (products.length > 0) {
|
|
133
140
|
const updatedOrderDetails = Object.assign({}, variables === null || variables === void 0 ? void 0 : variables.orderDetails);
|
|
134
141
|
if (mock) {
|
|
135
142
|
updateOrderDetails(updatedOrderDetails, products);
|
|
136
143
|
}
|
|
137
144
|
else {
|
|
138
|
-
(_b = (_a = updatedOrderDetails === null || updatedOrderDetails === void 0 ? void 0 : updatedOrderDetails.cart) === null || _a === void 0 ? void 0 : _a.lines) === null || _b === void 0 ? void 0 : _b.forEach((line) =>
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
(_b = (_a = updatedOrderDetails === null || updatedOrderDetails === void 0 ? void 0 : updatedOrderDetails.cart) === null || _a === void 0 ? void 0 : _a.lines) === null || _b === void 0 ? void 0 : _b.forEach((line, index) => {
|
|
146
|
+
if (variables.checkoutData &&
|
|
147
|
+
variables.checkoutData.lineItems &&
|
|
148
|
+
variables.checkoutData.lineItems.length > 0) {
|
|
149
|
+
updateLineDetails(line, variables.checkoutData.lineItems[index]);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
updateCartPriceDetails(updatedOrderDetails, variables.checkoutData);
|
|
141
153
|
}
|
|
142
154
|
setOrderDetails(updatedOrderDetails);
|
|
143
155
|
}
|
|
144
|
-
}, [products,
|
|
156
|
+
}, [products, mock, variables === null || variables === void 0 ? void 0 : variables.orderDetails]);
|
|
145
157
|
return {
|
|
146
158
|
orderDetails,
|
|
147
159
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,kBAAkB,CAAA;AA2CzB,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAGpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAGlE,CAAA;AAqGD,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,qBAAqB,SAAU,YAAY,KAAG,cA4B1D,CAAA"}
|
package/dist/lib/cart.util.js
CHANGED
|
@@ -2,7 +2,7 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
2
2
|
var _a;
|
|
3
3
|
const discountMap = (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType !== "SHIPPING_LINE").reduce((acc, discount) => {
|
|
4
4
|
var _a;
|
|
5
|
-
const code = (_a = discount.code) !== null && _a !== void 0 ? _a : "unknown";
|
|
5
|
+
const code = ((_a = discount.code) !== null && _a !== void 0 ? _a : "unknown").toUpperCase();
|
|
6
6
|
if (!acc[code]) {
|
|
7
7
|
acc[code] = 0;
|
|
8
8
|
}
|
|
@@ -18,7 +18,9 @@ const getOrderLevelDiscounts = (cart) => {
|
|
|
18
18
|
name: `Discount - ${code}`,
|
|
19
19
|
type: "ORDER_LEVEL",
|
|
20
20
|
}))
|
|
21
|
-
.filter((discount) => cart.discounts
|
|
21
|
+
.filter((discount) => cart.discounts
|
|
22
|
+
.map((d) => d.toUpperCase())
|
|
23
|
+
.includes(discount.id.toUpperCase()));
|
|
22
24
|
};
|
|
23
25
|
const getShippingDiscounts = (cart) => {
|
|
24
26
|
var _a;
|
|
@@ -68,7 +70,11 @@ const getLineItemDiscounts = (cart) => {
|
|
|
68
70
|
if (!code)
|
|
69
71
|
return;
|
|
70
72
|
if (!acc[code]) {
|
|
71
|
-
acc[code] = {
|
|
73
|
+
acc[code] = {
|
|
74
|
+
amount: 0,
|
|
75
|
+
type: discount.type,
|
|
76
|
+
readOnly: discount.readOnly,
|
|
77
|
+
};
|
|
72
78
|
}
|
|
73
79
|
acc[code].amount += discount.amount;
|
|
74
80
|
});
|
|
@@ -76,12 +82,13 @@ const getLineItemDiscounts = (cart) => {
|
|
|
76
82
|
}, {});
|
|
77
83
|
if (!discountMap)
|
|
78
84
|
return [];
|
|
79
|
-
return (_b = Object.entries(discountMap)) === null || _b === void 0 ? void 0 : _b.map(([code, { amount, type }]) => ({
|
|
85
|
+
return (_b = Object.entries(discountMap)) === null || _b === void 0 ? void 0 : _b.map(([code, { amount, type, readOnly }]) => ({
|
|
80
86
|
id: code,
|
|
81
87
|
name: `Discount - ${code}`,
|
|
82
88
|
amount,
|
|
83
89
|
type,
|
|
84
|
-
|
|
90
|
+
readOnly,
|
|
91
|
+
}));
|
|
85
92
|
};
|
|
86
93
|
const getDiscountsTotalAmount = (orderAndLineItemDiscounts) => {
|
|
87
94
|
return orderAndLineItemDiscounts === null || orderAndLineItemDiscounts === void 0 ? void 0 : orderAndLineItemDiscounts.reduce((acc, discount) => acc + +discount.amount, 0);
|
|
@@ -89,7 +89,7 @@ describe("cart-provider.util", () => {
|
|
|
89
89
|
expect(result.isFreeShipping).toBe(true);
|
|
90
90
|
});
|
|
91
91
|
it("should calculate total discounted price correctly", () => {
|
|
92
|
-
const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: ["
|
|
92
|
+
const mockCart = Object.assign(Object.assign({}, baseCartData), { discounts: ["Discount10"], items: [
|
|
93
93
|
{
|
|
94
94
|
id: "line1",
|
|
95
95
|
quantity: 1,
|
|
@@ -132,7 +132,7 @@ describe("cart-provider.util", () => {
|
|
|
132
132
|
{
|
|
133
133
|
targetType: DiscountApplicationTargetType.LineItem,
|
|
134
134
|
discountedAmount: { amount: "10.00", currencyCode: "USD" },
|
|
135
|
-
code: "
|
|
135
|
+
code: "DiScOUnT10",
|
|
136
136
|
},
|
|
137
137
|
], appliedGiftCards: [
|
|
138
138
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapcart/mobile-components",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.67",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/styles.css",
|
|
@@ -11,6 +11,20 @@
|
|
|
11
11
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
12
12
|
"author": "Tapcart Inc.",
|
|
13
13
|
"homepage": "https://tapcart.com",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"clean": "rm -rf dist node_modules",
|
|
16
|
+
"lint": "eslint \"**/*.ts*\"",
|
|
17
|
+
"ui:add": "pnpm dlx shadcn-ui@latest add",
|
|
18
|
+
"build:styles": "postcss styles/globals.css -o dist/styles.css",
|
|
19
|
+
"build:ts": "tsc -p tsconfig.json && tsc-alias",
|
|
20
|
+
"build": "pnpm run build:ts && pnpm run build:styles",
|
|
21
|
+
"dev:ts": "tsc -w -p tsconfig.json",
|
|
22
|
+
"dev:styles": "npx tailwindcss -i styles/globals.css -o dist/styles.css --watch",
|
|
23
|
+
"dev": "concurrently \"pnpm run dev:ts\" \"pnpm run dev:styles\"",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"test:silent": "jest --silent",
|
|
26
|
+
"test:watch": "jest --watch"
|
|
27
|
+
},
|
|
14
28
|
"peerDependencies": {
|
|
15
29
|
"react": "^17.0.2 || ^18.0.0",
|
|
16
30
|
"react-dom": "^17.0.2 || ^18.0.0"
|
|
@@ -23,20 +37,20 @@
|
|
|
23
37
|
"@types/pluralize": "^0.0.33",
|
|
24
38
|
"@types/react": "^18.2.0",
|
|
25
39
|
"@types/react-dom": "^18.2.0",
|
|
40
|
+
"app-studio-types": "workspace:*",
|
|
26
41
|
"autoprefixer": "^10.4.14",
|
|
27
42
|
"chokidar-cli": "^3.0.0",
|
|
28
43
|
"concurrently": "^8.2.2",
|
|
29
44
|
"eslint": "^7.32.0",
|
|
45
|
+
"eslint-config-custom": "workspace:*",
|
|
30
46
|
"jest": "^29.7.0",
|
|
31
47
|
"jest-environment-jsdom": "^29.7.0",
|
|
32
48
|
"postcss": "^8.4.24",
|
|
33
49
|
"tailwindcss": "^3.3.2",
|
|
34
50
|
"ts-jest": "^29.2.5",
|
|
35
51
|
"tsc-alias": "^1.8.10",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"eslint-config-custom": "0.0.0",
|
|
39
|
-
"tsconfig": "0.0.0"
|
|
52
|
+
"tsconfig": "workspace:*",
|
|
53
|
+
"typescript": "^4.5.2"
|
|
40
54
|
},
|
|
41
55
|
"dependencies": {
|
|
42
56
|
"@radix-ui/react-accordion": "^1.1.2",
|
|
@@ -76,19 +90,5 @@
|
|
|
76
90
|
"tailwind-merge": "^1.13.2",
|
|
77
91
|
"tailwindcss-animate": "^1.0.6",
|
|
78
92
|
"vaul": "0.9.1"
|
|
79
|
-
},
|
|
80
|
-
"scripts": {
|
|
81
|
-
"clean": "rm -rf dist node_modules",
|
|
82
|
-
"lint": "eslint \"**/*.ts*\"",
|
|
83
|
-
"ui:add": "pnpm dlx shadcn-ui@latest add",
|
|
84
|
-
"build:styles": "postcss styles/globals.css -o dist/styles.css",
|
|
85
|
-
"build:ts": "tsc -p tsconfig.json && tsc-alias",
|
|
86
|
-
"build": "pnpm run build:ts && pnpm run build:styles",
|
|
87
|
-
"dev:ts": "tsc -w -p tsconfig.json",
|
|
88
|
-
"dev:styles": "npx tailwindcss -i styles/globals.css -o dist/styles.css --watch",
|
|
89
|
-
"dev": "concurrently \"pnpm run dev:ts\" \"pnpm run dev:styles\"",
|
|
90
|
-
"test": "jest",
|
|
91
|
-
"test:silent": "jest --silent",
|
|
92
|
-
"test:watch": "jest --watch"
|
|
93
93
|
}
|
|
94
|
-
}
|
|
94
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-click-outside.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-click-outside.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,wBAAgB,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAE,IAAI,CAa5F"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
import React from "react"
|
|
3
|
-
export function useClickOutside(ref, callback) {
|
|
4
|
-
React.useEffect(() => {
|
|
5
|
-
const handleClickOutside = (event) => {
|
|
6
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
7
|
-
callback()
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
document.addEventListener("mousedown", handleClickOutside)
|
|
11
|
-
return () => {
|
|
12
|
-
document.removeEventListener("mousedown", handleClickOutside)
|
|
13
|
-
}
|
|
14
|
-
}, [ref, callback])
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-outside-click.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-outside-click.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,QAAA,MAAM,eAAe,QAAS,MAAM,SAAS,CAAC,WAAW,CAAC,YAAY,MAAM,IAAI,SAa/E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
import React from "react"
|
|
3
|
-
const useClickOutside = (ref, callback) => {
|
|
4
|
-
React.useEffect(() => {
|
|
5
|
-
const handleClickOutside = (event) => {
|
|
6
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
7
|
-
callback()
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
document.addEventListener("mousedown", handleClickOutside)
|
|
11
|
-
return () => {
|
|
12
|
-
document.removeEventListener("mousedown", handleClickOutside)
|
|
13
|
-
}
|
|
14
|
-
}, [ref, callback])
|
|
15
|
-
}
|
|
16
|
-
export default useClickOutside
|
|
@@ -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) return
|
|
9
|
-
const handleTouchStart = (e) => {
|
|
10
|
-
const touch = e.touches[0]
|
|
11
|
-
elements.forEach((data, el) => {
|
|
12
|
-
if (el.contains(touch.target)) {
|
|
13
|
-
data.touchStarted = true
|
|
14
|
-
data.touchMoved = false
|
|
15
|
-
data.startPosition = { x: touch.clientX, y: touch.clientY }
|
|
16
|
-
// Don't set isPressed here, wait to determine if it's a tap or drag
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
const handleTouchMove = (e) => {
|
|
21
|
-
const touch = e.touches[0]
|
|
22
|
-
elements.forEach((data, el) => {
|
|
23
|
-
if (data.touchStarted) {
|
|
24
|
-
const deltaX = Math.abs(touch.clientX - data.startPosition.x)
|
|
25
|
-
const deltaY = Math.abs(touch.clientY - data.startPosition.y)
|
|
26
|
-
if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
|
|
27
|
-
data.touchMoved = true
|
|
28
|
-
data.setIsPressed(false)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
const handleTouchEnd = () => {
|
|
34
|
-
elements.forEach((data) => {
|
|
35
|
-
if (data.touchStarted) {
|
|
36
|
-
data.touchStarted = false
|
|
37
|
-
if (!data.touchMoved) {
|
|
38
|
-
// It's a tap, set isPressed briefly
|
|
39
|
-
data.setIsPressed(true)
|
|
40
|
-
setTimeout(() => data.setIsPressed(false), 100)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
document.addEventListener("touchstart", (e) => handleTouchStart(e), {
|
|
46
|
-
passive: true,
|
|
47
|
-
})
|
|
48
|
-
document.addEventListener("touchmove", (e) => handleTouchMove(e), {
|
|
49
|
-
passive: true,
|
|
50
|
-
})
|
|
51
|
-
document.addEventListener("touchend", () => handleTouchEnd(), {
|
|
52
|
-
passive: true,
|
|
53
|
-
})
|
|
54
|
-
isListening = true
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
register: (el, data) => {
|
|
58
|
-
elements.set(el, data)
|
|
59
|
-
startListening()
|
|
60
|
-
},
|
|
61
|
-
unregister: (el) => {
|
|
62
|
-
elements.delete(el)
|
|
63
|
-
},
|
|
64
|
-
elements,
|
|
65
|
-
}
|
|
66
|
-
})()
|
|
67
|
-
const useTap = (tapThreshold = 10) => {
|
|
68
|
-
const [isPressed, setIsPressed] = useState(false)
|
|
69
|
-
const elementRef = useRef(null)
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const element = elementRef.current
|
|
72
|
-
if (!element) return
|
|
73
|
-
const data = {
|
|
74
|
-
touchStarted: false,
|
|
75
|
-
touchMoved: false,
|
|
76
|
-
startPosition: { x: 0, y: 0 },
|
|
77
|
-
setIsPressed,
|
|
78
|
-
tapThreshold,
|
|
79
|
-
}
|
|
80
|
-
tapManager.register(element, data)
|
|
81
|
-
return () => {
|
|
82
|
-
tapManager.unregister(element)
|
|
83
|
-
}
|
|
84
|
-
}, [tapThreshold])
|
|
85
|
-
const onTap = useCallback((handler) => {
|
|
86
|
-
return (event) => {
|
|
87
|
-
const data = tapManager.elements.get(elementRef.current)
|
|
88
|
-
if (!data) return
|
|
89
|
-
if (event.type === "touchend" && !data.touchMoved) {
|
|
90
|
-
handler(event)
|
|
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 }
|