@tapcart/mobile-components 0.7.8 → 0.7.9
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-reviews.d.ts +1 -1
- package/dist/components/hooks/use-reviews.d.ts.map +1 -1
- package/dist/components/hooks/use-reviews.js +32 -10
- package/dist/components/hooks/use-style-utils.d.ts +69 -0
- package/dist/components/hooks/use-style-utils.d.ts.map +1 -0
- package/dist/components/hooks/use-style-utils.js +77 -0
- package/dist/components/ui/button.d.ts +1 -0
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +6 -2
- package/dist/components/ui/carousel.js +2 -2
- package/dist/components/ui/tap.d.ts.map +1 -1
- package/dist/components/ui/tap.js +7 -1
- package/dist/components/ui/video-enhanced.d.ts.map +1 -1
- package/dist/components/ui/video-enhanced.js +26 -52
- package/dist/lib/block-utils.d.ts +97 -0
- package/dist/lib/block-utils.d.ts.map +1 -0
- package/dist/lib/block-utils.js +77 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -1
- package/dist/tests/utils.test.d.ts +2 -0
- package/dist/tests/utils.test.d.ts.map +1 -0
- package/dist/tests/utils.test.js +34 -0
- package/package.json +9 -3
- 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-reviews.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-reviews.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGtF,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAA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,gBAAgB,GAAG;IACtB,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,gBAAgB,GAAG,IAAI,CAAA;IAClE,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,gBAAgB,CAwD1E;AAED,KAAK,wBAAwB,GAAG,gBAAgB,GAAG;IACjD,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAC;CACtC,CAAA;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,wBAAwB,CA0H1F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect } from "react";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
3
|
import useSWR from "swr";
|
|
4
4
|
import useSWRInfinite from "swr/infinite";
|
|
5
5
|
import { useInView } from 'react-intersection-observer';
|
|
@@ -52,13 +52,13 @@ export function useReviews(props) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
export function useReviewsInfinite(props) {
|
|
55
|
-
var _a
|
|
55
|
+
var _a;
|
|
56
56
|
let url = null;
|
|
57
57
|
const { ref, inView } = useInView({ rootMargin: "800px" });
|
|
58
58
|
let baseURL = "";
|
|
59
59
|
let queryParams = new URLSearchParams();
|
|
60
60
|
if (props) {
|
|
61
|
-
const { productId, provider, dataType, searchText, ratings, topics, sortBy, ascending, perPage } = props;
|
|
61
|
+
const { productId, provider, dataType, searchText, ratings, topics, sortBy, ascending, perPage } = props;
|
|
62
62
|
baseURL = props.baseURL;
|
|
63
63
|
if (productId.length > 0) {
|
|
64
64
|
queryParams.set("id", productId);
|
|
@@ -92,12 +92,29 @@ export function useReviewsInfinite(props) {
|
|
|
92
92
|
url = `${baseURL}/reviews/by-id?${queryParams.toString()}`;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
+
const isEndReached = useRef(false);
|
|
95
96
|
const getKey = (pageIndex, previousPageData) => {
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if ((props === null || props === void 0 ? void 0 : props.provider) === "yotpo") {
|
|
99
|
+
const dataType = queryParams.get("dataType") === "null" ? null : queryParams.get("dataType");
|
|
100
|
+
if (dataType == null) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (previousPageData && previousPageData.pagination) {
|
|
104
|
+
const { perPage, total } = previousPageData.pagination;
|
|
105
|
+
isEndReached.current = (((pageIndex + 1) * perPage) >= total);
|
|
106
|
+
}
|
|
107
|
+
return `${baseURL}/reviews/by-id?${queryParams.toString()}&page=${pageIndex + 1}`;
|
|
108
|
+
}
|
|
109
|
+
if ((props === null || props === void 0 ? void 0 : props.provider) === "okendo") {
|
|
110
|
+
if (pageIndex === 0)
|
|
111
|
+
return `${baseURL}/reviews/by-id?${queryParams.toString()}`;
|
|
112
|
+
if (!((_a = previousPageData === null || previousPageData === void 0 ? void 0 : previousPageData.pagination) === null || _a === void 0 ? void 0 : _a.nextUrl)) {
|
|
113
|
+
isEndReached.current = true;
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return `${baseURL}/reviews/by-id?${queryParams.toString()}&nextUrl=${((_b = previousPageData === null || previousPageData === void 0 ? void 0 : previousPageData.pagination) === null || _b === void 0 ? void 0 : _b.nextUrl) || null}`;
|
|
99
117
|
}
|
|
100
|
-
return `${baseURL}/reviews/by-id?${queryParams.toString()}&page=${pageIndex + 1}`;
|
|
101
118
|
};
|
|
102
119
|
const fetcher = (props === null || props === void 0 ? void 0 : props.fetcher) || ((url) => fetch(url).then((res) => res.json()));
|
|
103
120
|
const { data: dataInfinite, error: errorInfinite, size, setSize, isLoading, isValidating, } = useSWRInfinite(getKey, fetcher);
|
|
@@ -110,17 +127,22 @@ export function useReviewsInfinite(props) {
|
|
|
110
127
|
pagination: (dataInfinite === null || dataInfinite === void 0 ? void 0 : dataInfinite.length) ? dataInfinite[0].pagination : null,
|
|
111
128
|
reviews: mergedReviews
|
|
112
129
|
};
|
|
113
|
-
|
|
130
|
+
if ((props === null || props === void 0 ? void 0 : props.provider) === "yotpo") {
|
|
131
|
+
isEndReached.current = (mergedReviews === null || mergedReviews === void 0 ? void 0 : mergedReviews.length) === ((_a = searchResponse.pagination) === null || _a === void 0 ? void 0 : _a.total);
|
|
132
|
+
}
|
|
114
133
|
const loadMore = useCallback(() => {
|
|
115
|
-
if (!isLoading && !isValidating && !
|
|
134
|
+
if (!isLoading && !isValidating && !isEndReached.current) {
|
|
116
135
|
setSize(size + 1);
|
|
117
136
|
}
|
|
118
|
-
}, [isLoading, isValidating, setSize, size
|
|
137
|
+
}, [isLoading, isValidating, setSize, size]);
|
|
119
138
|
useEffect(() => {
|
|
120
139
|
if (inView) {
|
|
121
140
|
loadMore();
|
|
122
141
|
}
|
|
123
142
|
}, [inView, loadMore]);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
isEndReached.current = false;
|
|
145
|
+
}, [props]);
|
|
124
146
|
return {
|
|
125
147
|
data: searchResponse || {},
|
|
126
148
|
error: errorInfinite,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
type BorderSide = "all" | "top" | "bottom" | "left" | "right";
|
|
2
|
+
type BorderSides = BorderSide[];
|
|
3
|
+
declare const getBorderSidesStyle: (borderSides: BorderSides) => {
|
|
4
|
+
borderWidth: string;
|
|
5
|
+
borderTopWidth?: undefined;
|
|
6
|
+
borderBottomWidth?: undefined;
|
|
7
|
+
borderLeftWidth?: undefined;
|
|
8
|
+
borderRightWidth?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
borderTopWidth: string | number;
|
|
11
|
+
borderBottomWidth: string | number;
|
|
12
|
+
borderLeftWidth: string | number;
|
|
13
|
+
borderRightWidth: string | number;
|
|
14
|
+
borderWidth?: undefined;
|
|
15
|
+
};
|
|
16
|
+
type VerticalAlignment = "top" | "middle" | "bottom";
|
|
17
|
+
type Spacing = {
|
|
18
|
+
top: number;
|
|
19
|
+
bottom: number;
|
|
20
|
+
left: number;
|
|
21
|
+
right: number;
|
|
22
|
+
};
|
|
23
|
+
interface AlignmentAndSpacing {
|
|
24
|
+
alignment: VerticalAlignment;
|
|
25
|
+
spacing: Spacing;
|
|
26
|
+
}
|
|
27
|
+
declare const getVerticalAlignmentStyle: (alignmentAndSpacing: AlignmentAndSpacing) => {
|
|
28
|
+
bottom: string;
|
|
29
|
+
top: string;
|
|
30
|
+
transform?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
top: string;
|
|
33
|
+
transform: string;
|
|
34
|
+
bottom?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
bottom?: undefined;
|
|
37
|
+
top?: undefined;
|
|
38
|
+
transform?: undefined;
|
|
39
|
+
};
|
|
40
|
+
type BackgroundAndPadding = {
|
|
41
|
+
backgroundColor?: ColorOption;
|
|
42
|
+
borderSides?: BorderSides;
|
|
43
|
+
borderColor?: ColorOption;
|
|
44
|
+
cornerRadius?: number;
|
|
45
|
+
padding?: Partial<Spacing>;
|
|
46
|
+
};
|
|
47
|
+
type ColorOption = {
|
|
48
|
+
type: "brand-kit" | "custom";
|
|
49
|
+
value: string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
declare const getColor: (colorOption: ColorOption) => string | undefined;
|
|
52
|
+
type BackgroundAndSpacing = AlignmentAndSpacing & {
|
|
53
|
+
backgroundColor?: ColorOption;
|
|
54
|
+
borderColor?: ColorOption;
|
|
55
|
+
backgroundCorners?: number;
|
|
56
|
+
};
|
|
57
|
+
type TextStyle = {
|
|
58
|
+
font: {
|
|
59
|
+
family: string;
|
|
60
|
+
weight: number | string;
|
|
61
|
+
};
|
|
62
|
+
size: number | string;
|
|
63
|
+
color: ColorOption;
|
|
64
|
+
uppercase: boolean;
|
|
65
|
+
textAlignment: "left" | "center" | "right" | "justify";
|
|
66
|
+
};
|
|
67
|
+
type Headline = TextStyle;
|
|
68
|
+
type Subtext = TextStyle;
|
|
69
|
+
//# sourceMappingURL=use-style-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-style-utils.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-style-utils.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAC7D,KAAK,WAAW,GAAG,UAAU,EAAE,CAAA;AAE/B,QAAA,MAAM,mBAAmB;;;;;;;;;;;;CAUxB,CAAA;AAED,KAAK,iBAAiB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAEpD,KAAK,OAAO,GAAG;IACb,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,UAAU,mBAAmB;IAC3B,SAAS,EAAE,iBAAiB,CAAA;IAC5B,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,QAAA,MAAM,yBAAyB,wBACR,mBAAmB;;;;;;;;;;;;CAczC,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAC3B,CAAA;AAED,KAAK,WAAW,GACZ;IACE,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAA;IAC5B,KAAK,EAAE,MAAM,CAAA;CACd,GACD,SAAS,CAAA;AAEb,QAAA,MAAM,QAAQ,gBAAiB,WAAW,KAAG,MAAM,GAAG,SAMrD,CAAA;AAqCD,KAAK,oBAAoB,GAAG,mBAAmB,GAAG;IAChD,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA;AAeD,KAAK,SAAS,GAAG;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAA;QACd,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KACxB,CAAA;IACD,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;CACvD,CAAA;AAED,KAAK,QAAQ,GAAG,SAAS,CAAA;AACzB,KAAK,OAAO,GAAG,SAAS,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const getBorderSidesStyle = (borderSides) => {
|
|
3
|
+
const style = borderSides.includes("all")
|
|
4
|
+
? { borderWidth: "1px" }
|
|
5
|
+
: {
|
|
6
|
+
borderTopWidth: borderSides.includes("top") ? "1px" : 0,
|
|
7
|
+
borderBottomWidth: borderSides.includes("bottom") ? "1px" : 0,
|
|
8
|
+
borderLeftWidth: borderSides.includes("left") ? "1px" : 0,
|
|
9
|
+
borderRightWidth: borderSides.includes("right") ? "1px" : 0,
|
|
10
|
+
};
|
|
11
|
+
return style;
|
|
12
|
+
};
|
|
13
|
+
const getVerticalAlignmentStyle = (alignmentAndSpacing) => {
|
|
14
|
+
const { alignment, spacing } = alignmentAndSpacing;
|
|
15
|
+
switch (alignment) {
|
|
16
|
+
case "bottom":
|
|
17
|
+
return { bottom: `${spacing.bottom}px`, top: "auto" };
|
|
18
|
+
case "middle":
|
|
19
|
+
return { top: "50%", transform: "translateY(-50%)" };
|
|
20
|
+
case "top":
|
|
21
|
+
return { top: `${spacing.top}px`, bottom: "auto" };
|
|
22
|
+
default:
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getColor = (colorOption) => {
|
|
27
|
+
return colorOption
|
|
28
|
+
? colorOption.type === "brand-kit"
|
|
29
|
+
? `var(--${colorOption.value})`
|
|
30
|
+
: colorOption.value
|
|
31
|
+
: undefined;
|
|
32
|
+
};
|
|
33
|
+
function getBackgroundAndPaddingStyle(backgroundAndPadding) {
|
|
34
|
+
const { backgroundColor, borderSides, borderColor, cornerRadius, padding } = backgroundAndPadding;
|
|
35
|
+
return {
|
|
36
|
+
backgroundColor: getColor(backgroundColor),
|
|
37
|
+
borderColor: getColor(borderColor),
|
|
38
|
+
borderTopWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("top")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
39
|
+
? "1px"
|
|
40
|
+
: undefined,
|
|
41
|
+
borderBottomWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("bottom")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
42
|
+
? "1px"
|
|
43
|
+
: undefined,
|
|
44
|
+
borderLeftWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("left")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
45
|
+
? "1px"
|
|
46
|
+
: undefined,
|
|
47
|
+
borderRightWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("right")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
48
|
+
? "1px"
|
|
49
|
+
: undefined,
|
|
50
|
+
paddingTop: (padding === null || padding === void 0 ? void 0 : padding.top) !== undefined ? `${padding.top}px` : undefined,
|
|
51
|
+
paddingBottom: (padding === null || padding === void 0 ? void 0 : padding.bottom) !== undefined ? `${padding.bottom}px` : undefined,
|
|
52
|
+
paddingLeft: (padding === null || padding === void 0 ? void 0 : padding.left) !== undefined ? `${padding.left}px` : undefined,
|
|
53
|
+
paddingRight: (padding === null || padding === void 0 ? void 0 : padding.right) !== undefined ? `${padding.right}px` : undefined,
|
|
54
|
+
borderStyle: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.length) ? "solid" : undefined,
|
|
55
|
+
borderRadius: cornerRadius !== undefined ? `${cornerRadius}px` : undefined,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getBackgroundAndSpacingStyle(backgroundAndSpacing) {
|
|
59
|
+
const { spacing, borderColor, backgroundColor, backgroundCorners } = backgroundAndSpacing;
|
|
60
|
+
return {
|
|
61
|
+
padding: `${spacing.top}px ${spacing.right}px ${spacing.bottom}px ${spacing.left}px`,
|
|
62
|
+
borderColor: borderColor ? borderColor.value : "transparent",
|
|
63
|
+
backgroundColor: getColor(backgroundColor) || "transparent",
|
|
64
|
+
borderRadius: `${backgroundCorners !== null && backgroundCorners !== void 0 ? backgroundCorners : 0}px`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getTextStyle(textStyle) {
|
|
68
|
+
const { font, size, color, uppercase, textAlignment } = textStyle;
|
|
69
|
+
return {
|
|
70
|
+
fontFamily: font.family,
|
|
71
|
+
fontWeight: font.weight,
|
|
72
|
+
fontSize: size,
|
|
73
|
+
color: getColor(color),
|
|
74
|
+
textTransform: uppercase ? "uppercase" : "none",
|
|
75
|
+
textAlign: textAlignment,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -17,6 +17,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
|
|
|
17
17
|
iconStrokeColor?: string;
|
|
18
18
|
iconClassName?: string;
|
|
19
19
|
iconPosition?: "left" | "right";
|
|
20
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
20
21
|
}
|
|
21
22
|
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
22
23
|
declare const getButtonProps: (buttonConfig: TextStyle & BackgroundAndPadding & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../components/ui/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAGL,KAAK,EAEL,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../components/ui/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAGL,KAAK,EAEL,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAMxB,QAAA,MAAM,cAAc;;;mFAgCnB,CAAA;AAwCD,MAAM,WAAW,WACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,YAAY,CAAC,OAAO,cAAc,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,SAAS,CAAA;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;CAC9D;AAED,QAAA,MAAM,MAAM,uFA0GX,CAAA;AAGD,QAAA,MAAM,cAAc,iBACJ,SAAS,GACrB,oBAAoB,GAAG;IACrB,SAAS,EAAE,KAAK,CAAA;IAChB,WAAW,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5B,gBAAgB,EAAE,OAAO,CAAA;CAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkBJ,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -16,6 +16,8 @@ import { cva } from "class-variance-authority";
|
|
|
16
16
|
import { cn, getColor, getTextStyle, getBackgroundAndPaddingStyle, } from "../../lib/utils";
|
|
17
17
|
import { Icon } from "./icon";
|
|
18
18
|
import { Text } from "./text";
|
|
19
|
+
import { useTap } from "./tap";
|
|
20
|
+
import { useMergeRefs } from "../hooks/use-merge-refs";
|
|
19
21
|
const buttonVariants = cva("w-full flex rounded items-center justify-center transition-colors disabled:bg-stateColors-disabled disabled:border-stateColors-disabled disabled:pointer-events-none ring-offset-background overflow-elipse whitespace-nowrap truncate active:opacity-70 disabled:opacity-70 cursor-pointer", {
|
|
20
22
|
variants: {
|
|
21
23
|
size: {
|
|
@@ -79,7 +81,9 @@ const labelVariants = cva("truncate", {
|
|
|
79
81
|
},
|
|
80
82
|
});
|
|
81
83
|
const Button = React.forwardRef((_a, ref) => {
|
|
82
|
-
var { className, labelClassName, labelStyle, variant, size, asChild = false, loading, icon, iconColor, iconStrokeColor, iconPosition, iconSize, iconUrl, iconClassName } = _a, props = __rest(_a, ["className", "labelClassName", "labelStyle", "variant", "size", "asChild", "loading", "icon", "iconColor", "iconStrokeColor", "iconPosition", "iconSize", "iconUrl", "iconClassName"]);
|
|
84
|
+
var { className, labelClassName, labelStyle, variant, size, asChild = false, loading, icon, iconColor, iconStrokeColor, iconPosition, iconSize, iconUrl, iconClassName, onClick } = _a, props = __rest(_a, ["className", "labelClassName", "labelStyle", "variant", "size", "asChild", "loading", "icon", "iconColor", "iconStrokeColor", "iconPosition", "iconSize", "iconUrl", "iconClassName", "onClick"]);
|
|
85
|
+
const { onTap, isPressed, ref: tapRef } = useTap();
|
|
86
|
+
const mergedRef = useMergeRefs(ref, tapRef);
|
|
83
87
|
const Comp = asChild ? Slot : "button";
|
|
84
88
|
const IconButton = () => icon || iconUrl ? (_jsx(Icon, { name: icon, url: iconUrl, size: "sm", style: { color: iconColor } })) : null;
|
|
85
89
|
const BasicButton = () => (_jsxs(_Fragment, { children: [icon || iconUrl ? (_jsx(Icon, { name: iconUrl ? undefined : icon, url: iconUrl, size: iconSize || variant === "quickadd" ? "xs" : "sm", className: cn(iconVariants({ variant }), {
|
|
@@ -90,7 +94,7 @@ const Button = React.forwardRef((_a, ref) => {
|
|
|
90
94
|
return (_jsx(Comp, Object.assign({ className: cn(buttonVariants({ variant, size }), className, {
|
|
91
95
|
"pointer-events-none": loading,
|
|
92
96
|
"flex-row-reverse": (icon || iconUrl) && iconPosition === "right",
|
|
93
|
-
}), ref:
|
|
97
|
+
}), ref: mergedRef, onClick: onTap(onClick) }, props, { children: loading ? (_jsx(LoadingButton, {})) : typeof props.children === "object" &&
|
|
94
98
|
React.isValidElement(props.children) ? ( // if children are passed as a valid React element
|
|
95
99
|
props.children // render it
|
|
96
100
|
) : // otherwise use props
|
|
@@ -122,7 +122,7 @@ const CarouselPrevious = React.forwardRef((_a, ref) => {
|
|
|
122
122
|
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
123
123
|
return (_jsxs(Button, Object.assign({ ref: ref, variant: variant, size: size, className: cn("absolute h-8 w-8 rounded-full", orientation === "horizontal"
|
|
124
124
|
? "-left-12 top-1/2 -translate-y-1/2"
|
|
125
|
-
: "-top-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollPrev, onClick: scrollPrev },
|
|
125
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollPrev }, props, { onClick: scrollPrev }, { children: [_jsx(ArrowLeft, { className: "h-4 w-4" }), _jsx("span", Object.assign({ className: "sr-only" }, { children: "Previous slide" }))] })));
|
|
126
126
|
});
|
|
127
127
|
CarouselPrevious.displayName = "CarouselPrevious";
|
|
128
128
|
const CarouselNext = React.forwardRef((_a, ref) => {
|
|
@@ -130,7 +130,7 @@ const CarouselNext = React.forwardRef((_a, ref) => {
|
|
|
130
130
|
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
131
131
|
return (_jsxs(Button, Object.assign({ ref: ref, variant: variant, size: size, className: cn("absolute h-8 w-8 rounded-full", orientation === "horizontal"
|
|
132
132
|
? "-right-12 top-1/2 -translate-y-1/2"
|
|
133
|
-
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollNext, onClick: scrollNext },
|
|
133
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollNext }, props, { onClick: scrollNext }, { children: [_jsx(ArrowRight, { className: "h-4 w-4" }), _jsx("span", Object.assign({ className: "sr-only" }, { children: "Next slide" }))] })));
|
|
134
134
|
});
|
|
135
135
|
CarouselNext.displayName = "CarouselNext";
|
|
136
136
|
const CarouselDots = React.forwardRef((_a, ref) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap.d.ts","sourceRoot":"","sources":["../../../components/ui/tap.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAMZ,SAAS,EACV,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"tap.d.ts","sourceRoot":"","sources":["../../../components/ui/tap.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAMZ,SAAS,EACV,MAAM,OAAO,CAAA;AAyFd,QAAA,MAAM,MAAM;6BAyBU,GAAG,KAAK,IAAI,aACb,GAAG;;;CAmBvB,CAAA;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,QAAA,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAuC3B,CAAA;AAED,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React, { useState, useEffect, useCallback, useRef, } from "react";
|
|
4
|
+
// @ts-ignore -- webbridge-react is not typed (yet)
|
|
5
|
+
import { useActions } from "@tapcart/webbridge-react";
|
|
4
6
|
// Shared manager for all instances of the hook
|
|
5
7
|
const tapManager = (() => {
|
|
6
8
|
const elements = new Map();
|
|
@@ -65,6 +67,7 @@ const tapManager = (() => {
|
|
|
65
67
|
const useTap = (tapThreshold = 10) => {
|
|
66
68
|
const [isPressed, setIsPressed] = useState(false);
|
|
67
69
|
const elementRef = useRef(null);
|
|
70
|
+
const webbridgeActions = useActions();
|
|
68
71
|
useEffect(() => {
|
|
69
72
|
const element = elementRef.current;
|
|
70
73
|
if (!element)
|
|
@@ -83,19 +86,22 @@ const useTap = (tapThreshold = 10) => {
|
|
|
83
86
|
}, [tapThreshold]);
|
|
84
87
|
const onTap = useCallback((handler) => {
|
|
85
88
|
return (event) => {
|
|
89
|
+
var _a, _b;
|
|
86
90
|
const data = tapManager.elements.get(elementRef.current);
|
|
87
91
|
if (!data)
|
|
88
92
|
return;
|
|
89
93
|
if (event.type === "touchend" && !data.touchMoved) {
|
|
90
94
|
handler(event);
|
|
95
|
+
(_a = webbridgeActions.action) === null || _a === void 0 ? void 0 : _a.call(webbridgeActions, "trigger/haptic");
|
|
91
96
|
}
|
|
92
97
|
else if (event.type === "click" && !data.touchStarted) {
|
|
93
98
|
handler(event);
|
|
99
|
+
(_b = webbridgeActions.action) === null || _b === void 0 ? void 0 : _b.call(webbridgeActions, "trigger/haptic");
|
|
94
100
|
setIsPressed(true);
|
|
95
101
|
setTimeout(() => setIsPressed(false), 100);
|
|
96
102
|
}
|
|
97
103
|
};
|
|
98
|
-
}, []);
|
|
104
|
+
}, [webbridgeActions]);
|
|
99
105
|
return { onTap, isPressed, ref: elementRef };
|
|
100
106
|
};
|
|
101
107
|
const Tap = ({ children }) => {
|
|
@@ -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,qFAsMV,CAAA;AAID,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,CAAA"}
|
|
@@ -29,45 +29,38 @@ const videoVariants = {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
const Video = React.forwardRef((_a, ref) => {
|
|
32
|
-
var _b;
|
|
33
32
|
var { src, videoAttributes, naturalAspectRatio = "1/1", className } = _a, props = __rest(_a, ["src", "videoAttributes", "naturalAspectRatio", "className"]);
|
|
33
|
+
const autoPlayEnabled = videoAttributes.autoplay && !videoAttributes.videoSound;
|
|
34
34
|
const internalRef = React.useRef(null);
|
|
35
35
|
const videoRef = ref || internalRef;
|
|
36
|
-
const playAttemptRef = React.useRef(false);
|
|
37
36
|
const observerRef = React.useRef(null);
|
|
38
37
|
const lastPositionRef = React.useRef(0);
|
|
39
38
|
const [isLoaded, setIsLoaded] = React.useState(false);
|
|
40
39
|
const [isVisible, setIsVisible] = React.useState(false);
|
|
41
40
|
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
42
|
-
const
|
|
41
|
+
const handlePlay = React.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
42
|
const video = videoRef.current;
|
|
44
43
|
if (!video)
|
|
45
44
|
return;
|
|
46
45
|
try {
|
|
47
46
|
video.currentTime = lastPositionRef.current;
|
|
48
|
-
|
|
49
|
-
video.muted = true;
|
|
50
|
-
}
|
|
47
|
+
video.muted = true;
|
|
51
48
|
yield video.play();
|
|
52
|
-
|
|
53
|
-
playAttemptRef.current = true;
|
|
54
|
-
// If sound is enabled and autoplay was successful, unmute
|
|
55
|
-
if (videoAttributes.videoSound && videoAttributes.autoplay) {
|
|
49
|
+
if (videoAttributes.videoSound) {
|
|
56
50
|
video.muted = false;
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
catch (error) {
|
|
60
54
|
console.error("Error playing video:", error);
|
|
61
|
-
setIsPlaying(false);
|
|
62
55
|
}
|
|
63
|
-
}), [
|
|
56
|
+
}), [videoRef, videoAttributes.videoSound]);
|
|
64
57
|
const handlePlayPause = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
58
|
const video = videoRef.current;
|
|
66
59
|
if (!video)
|
|
67
60
|
return;
|
|
68
61
|
if (video.paused) {
|
|
69
62
|
try {
|
|
70
|
-
yield
|
|
63
|
+
yield handlePlay();
|
|
71
64
|
}
|
|
72
65
|
catch (error) {
|
|
73
66
|
console.error("Error playing video:", error);
|
|
@@ -75,9 +68,9 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
75
68
|
}
|
|
76
69
|
else {
|
|
77
70
|
video.pause();
|
|
78
|
-
setIsPlaying(false);
|
|
79
71
|
}
|
|
80
72
|
});
|
|
73
|
+
// intersection observer setup
|
|
81
74
|
React.useEffect(() => {
|
|
82
75
|
const video = videoRef.current;
|
|
83
76
|
if (!video)
|
|
@@ -88,15 +81,11 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
88
81
|
setIsVisible(entry.isIntersecting);
|
|
89
82
|
// Handle visibility change
|
|
90
83
|
if (!entry.isIntersecting && !video.paused) {
|
|
91
|
-
lastPositionRef.current = video.currentTime;
|
|
92
84
|
video.pause();
|
|
93
|
-
setIsPlaying(false);
|
|
94
85
|
}
|
|
95
|
-
else if (entry.isIntersecting &&
|
|
96
|
-
videoAttributes.autoplay &&
|
|
97
|
-
video.paused) {
|
|
86
|
+
else if (entry.isIntersecting && autoPlayEnabled && video.paused) {
|
|
98
87
|
video.currentTime = lastPositionRef.current;
|
|
99
|
-
|
|
88
|
+
handlePlay();
|
|
100
89
|
}
|
|
101
90
|
}, {
|
|
102
91
|
threshold: 0.1, // 10% of the video needs to be visible
|
|
@@ -109,42 +98,28 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
109
98
|
video.addEventListener("play", handlePlay);
|
|
110
99
|
video.addEventListener("pause", handlePause);
|
|
111
100
|
return () => {
|
|
112
|
-
if (video && !video.paused) {
|
|
113
|
-
lastPositionRef.current = video.currentTime;
|
|
114
|
-
}
|
|
115
101
|
if (observerRef.current) {
|
|
116
102
|
observerRef.current.disconnect();
|
|
117
103
|
}
|
|
118
104
|
video.removeEventListener("play", handlePlay);
|
|
119
105
|
video.removeEventListener("pause", handlePause);
|
|
120
|
-
playAttemptRef.current = false;
|
|
121
106
|
};
|
|
122
|
-
}, [
|
|
123
|
-
//
|
|
107
|
+
}, [handlePlay, autoPlayEnabled, videoRef]);
|
|
108
|
+
// handle visibility change
|
|
109
|
+
// pause video when not visible
|
|
110
|
+
// play video when visible and autoplay is on
|
|
124
111
|
React.useEffect(() => {
|
|
125
112
|
const video = videoRef.current;
|
|
126
113
|
if (!video)
|
|
127
114
|
return;
|
|
128
|
-
if (isVisible &&
|
|
129
|
-
|
|
115
|
+
if (isVisible && autoPlayEnabled) {
|
|
116
|
+
handlePlay();
|
|
130
117
|
}
|
|
131
118
|
else if (!isVisible && !video.paused) {
|
|
132
|
-
lastPositionRef.current = video.currentTime;
|
|
133
119
|
video.pause();
|
|
134
|
-
setIsPlaying(false);
|
|
135
120
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
lastPositionRef.current = video.currentTime;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}, [
|
|
142
|
-
videoAttributes.autoplay,
|
|
143
|
-
videoAttributes.videoSound,
|
|
144
|
-
isVisible,
|
|
145
|
-
videoRef,
|
|
146
|
-
setupVideo,
|
|
147
|
-
]);
|
|
121
|
+
}, [autoPlayEnabled, isVisible, videoRef, handlePlay]);
|
|
122
|
+
// update lastPositionRef on video timeupdate event
|
|
148
123
|
React.useEffect(() => {
|
|
149
124
|
const video = videoRef.current;
|
|
150
125
|
if (!video)
|
|
@@ -157,14 +132,14 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
157
132
|
video.removeEventListener("timeupdate", handleTimeUpdate);
|
|
158
133
|
};
|
|
159
134
|
}, [videoRef]);
|
|
160
|
-
//
|
|
135
|
+
// metadata setup
|
|
161
136
|
React.useEffect(() => {
|
|
162
137
|
const video = videoRef.current;
|
|
163
138
|
if (!video)
|
|
164
139
|
return;
|
|
165
140
|
const handleLoadedMetadata = () => {
|
|
166
141
|
setIsLoaded(true);
|
|
167
|
-
if (
|
|
142
|
+
if (autoPlayEnabled && isVisible) {
|
|
168
143
|
const currentTime = lastPositionRef.current;
|
|
169
144
|
video.currentTime = currentTime;
|
|
170
145
|
video.play().catch((error) => {
|
|
@@ -173,15 +148,16 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
173
148
|
}
|
|
174
149
|
};
|
|
175
150
|
video.addEventListener("loadedmetadata", handleLoadedMetadata);
|
|
176
|
-
video.load();
|
|
177
151
|
return () => {
|
|
178
152
|
video.removeEventListener("loadedmetadata", handleLoadedMetadata);
|
|
179
153
|
};
|
|
180
|
-
}, [
|
|
154
|
+
}, []);
|
|
181
155
|
React.useEffect(() => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
156
|
+
const video = videoRef.current;
|
|
157
|
+
if (!video)
|
|
158
|
+
return;
|
|
159
|
+
video.load();
|
|
160
|
+
}, [videoRef]);
|
|
185
161
|
const videoStyle = {
|
|
186
162
|
aspectRatio: videoAttributes.enabled && videoAttributes.aspectRatio !== "auto"
|
|
187
163
|
? videoAttributes.aspectRatio.replace(":", "/")
|
|
@@ -189,9 +165,7 @@ const Video = React.forwardRef((_a, ref) => {
|
|
|
189
165
|
};
|
|
190
166
|
return (_jsxs("div", Object.assign({ className: "relative w-full" }, { children: [_jsx("video", Object.assign({ ref: videoRef, className: cn(videoVariants.base, videoAttributes.videoFit === "fill"
|
|
191
167
|
? videoVariants.fit.cover
|
|
192
|
-
: videoVariants.fit.contain, className), style: videoStyle, preload: "metadata", playsInline: true, loop: videoAttributes.enabled, controls: false, src: src }, props)),
|
|
193
|
-
(videoAttributes.videoSound && ((_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.muted))) &&
|
|
194
|
-
videoAttributes.enabled && (_jsx("button", Object.assign({ onClick: handlePlayPause, className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-50\n w-16 h-16 rounded-full bg-black/75 hover:bg-black/90 \n flex items-center justify-center transition-all duration-300\n hover:scale-110 focus:outline-none focus:ring-2 focus:ring-white", "aria-label": "Play video" }, { children: _jsx("div", { className: "w-0 h-0 border-y-8 border-y-transparent \n border-l-[16px] border-l-white \n translate-x-[2px]" }) })))] })));
|
|
168
|
+
: videoVariants.fit.contain, className), style: videoStyle, preload: "metadata", playsInline: true, loop: videoAttributes.enabled, controls: false, src: src }, props)), isLoaded && !isPlaying && (_jsx("button", Object.assign({ onClick: handlePlayPause, className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-50\n w-16 h-16 rounded-full bg-black/75 hover:bg-black/90 \n flex items-center justify-center transition-all duration-300\n hover:scale-110 focus:outline-none focus:ring-2 focus:ring-white", "aria-label": "Play video" }, { children: _jsx("div", { className: "w-0 h-0 border-y-8 border-y-transparent \n border-l-[16px] border-l-white \n translate-x-[2px]" }) })))] })));
|
|
195
169
|
});
|
|
196
170
|
Video.displayName = "Video";
|
|
197
171
|
export { Video as VideoEnhanced };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
type BorderSide = "all" | "top" | "bottom" | "left" | "right";
|
|
2
|
+
type BorderSides = BorderSide[];
|
|
3
|
+
declare const getBorderSidesStyle: (borderSides: BorderSides) => {
|
|
4
|
+
borderWidth: string;
|
|
5
|
+
borderTopWidth?: undefined;
|
|
6
|
+
borderBottomWidth?: undefined;
|
|
7
|
+
borderLeftWidth?: undefined;
|
|
8
|
+
borderRightWidth?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
borderTopWidth: string | number;
|
|
11
|
+
borderBottomWidth: string | number;
|
|
12
|
+
borderLeftWidth: string | number;
|
|
13
|
+
borderRightWidth: string | number;
|
|
14
|
+
borderWidth?: undefined;
|
|
15
|
+
};
|
|
16
|
+
type VerticalAlignment = "top" | "middle" | "bottom";
|
|
17
|
+
type Spacing = {
|
|
18
|
+
top: number;
|
|
19
|
+
bottom: number;
|
|
20
|
+
left: number;
|
|
21
|
+
right: number;
|
|
22
|
+
};
|
|
23
|
+
interface AlignmentAndSpacing {
|
|
24
|
+
alignment: VerticalAlignment;
|
|
25
|
+
spacing: Spacing;
|
|
26
|
+
}
|
|
27
|
+
declare const getVerticalAlignmentStyle: (alignmentAndSpacing: AlignmentAndSpacing) => {
|
|
28
|
+
bottom: string;
|
|
29
|
+
top: string;
|
|
30
|
+
transform?: undefined;
|
|
31
|
+
} | {
|
|
32
|
+
top: string;
|
|
33
|
+
transform: string;
|
|
34
|
+
bottom?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
bottom?: undefined;
|
|
37
|
+
top?: undefined;
|
|
38
|
+
transform?: undefined;
|
|
39
|
+
};
|
|
40
|
+
type BackgroundAndPadding = {
|
|
41
|
+
backgroundColor?: ColorOption;
|
|
42
|
+
borderSides?: BorderSides;
|
|
43
|
+
borderColor?: ColorOption;
|
|
44
|
+
cornerRadius?: number;
|
|
45
|
+
padding?: Partial<Spacing>;
|
|
46
|
+
};
|
|
47
|
+
type ColorOption = {
|
|
48
|
+
type: "brand-kit" | "custom";
|
|
49
|
+
value: string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
declare const getColor: (colorOption: ColorOption) => string | undefined;
|
|
52
|
+
declare function getBackgroundAndPaddingStyle(backgroundAndPadding: BackgroundAndPadding): {
|
|
53
|
+
backgroundColor: string | undefined;
|
|
54
|
+
borderColor: string | undefined;
|
|
55
|
+
borderTopWidth: string | undefined;
|
|
56
|
+
borderBottomWidth: string | undefined;
|
|
57
|
+
borderLeftWidth: string | undefined;
|
|
58
|
+
borderRightWidth: string | undefined;
|
|
59
|
+
paddingTop: string | undefined;
|
|
60
|
+
paddingBottom: string | undefined;
|
|
61
|
+
paddingLeft: string | undefined;
|
|
62
|
+
paddingRight: string | undefined;
|
|
63
|
+
borderStyle: string | undefined;
|
|
64
|
+
borderRadius: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
type BackgroundAndSpacing = AlignmentAndSpacing & {
|
|
67
|
+
backgroundColor?: ColorOption;
|
|
68
|
+
borderColor?: ColorOption;
|
|
69
|
+
backgroundCorners?: number;
|
|
70
|
+
};
|
|
71
|
+
declare function getBackgroundAndSpacingStyle(backgroundAndSpacing: BackgroundAndSpacing): {
|
|
72
|
+
padding: string;
|
|
73
|
+
borderColor: string;
|
|
74
|
+
backgroundColor: string;
|
|
75
|
+
borderRadius: string;
|
|
76
|
+
};
|
|
77
|
+
type TextStyle = {
|
|
78
|
+
font: {
|
|
79
|
+
family: string;
|
|
80
|
+
weight: number | string;
|
|
81
|
+
};
|
|
82
|
+
size: number | string;
|
|
83
|
+
color: ColorOption;
|
|
84
|
+
uppercase: boolean;
|
|
85
|
+
textAlignment: "left" | "center" | "right" | "justify";
|
|
86
|
+
};
|
|
87
|
+
type Headline = TextStyle;
|
|
88
|
+
type Subtext = TextStyle;
|
|
89
|
+
declare function getTextStyle(textStyle: Headline | Subtext): {
|
|
90
|
+
fontFamily: string;
|
|
91
|
+
fontWeight: string | number;
|
|
92
|
+
fontSize: string | number;
|
|
93
|
+
color: string | undefined;
|
|
94
|
+
textTransform: string;
|
|
95
|
+
textAlign: "center" | "left" | "right" | "justify";
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=block-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-utils.d.ts","sourceRoot":"","sources":["../../lib/block-utils.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;AAC7D,KAAK,WAAW,GAAG,UAAU,EAAE,CAAA;AAE/B,QAAA,MAAM,mBAAmB;;;;;;;;;;;;CAUxB,CAAA;AAED,KAAK,iBAAiB,GAAG,KAAK,GAAG,QAAQ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EAAE,WAAW,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;CACvD,CAAA;AAED,KAAK,QAAQ,GAAG,SAAS,CAAA;AACzB,KAAK,OAAO,GAAG,SAAS,CAAA;AAExB,iBAAS,YAAY,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO;;;;;;;EAUlD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const getBorderSidesStyle = (borderSides) => {
|
|
3
|
+
const style = borderSides.includes("all")
|
|
4
|
+
? { borderWidth: "1px" }
|
|
5
|
+
: {
|
|
6
|
+
borderTopWidth: borderSides.includes("top") ? "1px" : 0,
|
|
7
|
+
borderBottomWidth: borderSides.includes("bottom") ? "1px" : 0,
|
|
8
|
+
borderLeftWidth: borderSides.includes("left") ? "1px" : 0,
|
|
9
|
+
borderRightWidth: borderSides.includes("right") ? "1px" : 0,
|
|
10
|
+
};
|
|
11
|
+
return style;
|
|
12
|
+
};
|
|
13
|
+
const getVerticalAlignmentStyle = (alignmentAndSpacing) => {
|
|
14
|
+
const { alignment, spacing } = alignmentAndSpacing;
|
|
15
|
+
switch (alignment) {
|
|
16
|
+
case "bottom":
|
|
17
|
+
return { bottom: `${spacing.bottom}px`, top: "auto" };
|
|
18
|
+
case "middle":
|
|
19
|
+
return { top: "50%", transform: "translateY(-50%)" };
|
|
20
|
+
case "top":
|
|
21
|
+
return { top: `${spacing.top}px`, bottom: "auto" };
|
|
22
|
+
default:
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getColor = (colorOption) => {
|
|
27
|
+
return colorOption
|
|
28
|
+
? colorOption.type === "brand-kit"
|
|
29
|
+
? `var(--${colorOption.value})`
|
|
30
|
+
: colorOption.value
|
|
31
|
+
: undefined;
|
|
32
|
+
};
|
|
33
|
+
function getBackgroundAndPaddingStyle(backgroundAndPadding) {
|
|
34
|
+
const { backgroundColor, borderSides, borderColor, cornerRadius, padding } = backgroundAndPadding;
|
|
35
|
+
return {
|
|
36
|
+
backgroundColor: getColor(backgroundColor),
|
|
37
|
+
borderColor: getColor(borderColor),
|
|
38
|
+
borderTopWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("top")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
39
|
+
? "1px"
|
|
40
|
+
: undefined,
|
|
41
|
+
borderBottomWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("bottom")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
42
|
+
? "1px"
|
|
43
|
+
: undefined,
|
|
44
|
+
borderLeftWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("left")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
45
|
+
? "1px"
|
|
46
|
+
: undefined,
|
|
47
|
+
borderRightWidth: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("right")) || (borderSides === null || borderSides === void 0 ? void 0 : borderSides.includes("all"))
|
|
48
|
+
? "1px"
|
|
49
|
+
: undefined,
|
|
50
|
+
paddingTop: (padding === null || padding === void 0 ? void 0 : padding.top) !== undefined ? `${padding.top}px` : undefined,
|
|
51
|
+
paddingBottom: (padding === null || padding === void 0 ? void 0 : padding.bottom) !== undefined ? `${padding.bottom}px` : undefined,
|
|
52
|
+
paddingLeft: (padding === null || padding === void 0 ? void 0 : padding.left) !== undefined ? `${padding.left}px` : undefined,
|
|
53
|
+
paddingRight: (padding === null || padding === void 0 ? void 0 : padding.right) !== undefined ? `${padding.right}px` : undefined,
|
|
54
|
+
borderStyle: (borderSides === null || borderSides === void 0 ? void 0 : borderSides.length) ? "solid" : undefined,
|
|
55
|
+
borderRadius: cornerRadius !== undefined ? `${cornerRadius}px` : undefined,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getBackgroundAndSpacingStyle(backgroundAndSpacing) {
|
|
59
|
+
const { spacing, borderColor, backgroundColor, backgroundCorners } = backgroundAndSpacing;
|
|
60
|
+
return {
|
|
61
|
+
padding: `${spacing.top}px ${spacing.right}px ${spacing.bottom}px ${spacing.left}px`,
|
|
62
|
+
borderColor: borderColor ? borderColor.value : "transparent",
|
|
63
|
+
backgroundColor: getColor(backgroundColor) || "transparent",
|
|
64
|
+
borderRadius: `${backgroundCorners !== null && backgroundCorners !== void 0 ? backgroundCorners : 0}px`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getTextStyle(textStyle) {
|
|
68
|
+
const { font, size, color, uppercase, textAlignment } = textStyle;
|
|
69
|
+
return {
|
|
70
|
+
fontFamily: font.family,
|
|
71
|
+
fontWeight: font.weight,
|
|
72
|
+
fontSize: size,
|
|
73
|
+
color: getColor(color),
|
|
74
|
+
textTransform: uppercase ? "uppercase" : "none",
|
|
75
|
+
textAlign: textAlignment,
|
|
76
|
+
};
|
|
77
|
+
}
|
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,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAA;AAKvC,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnE,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,eAAO,MAAM,eAAe,UAc3B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAA;AAMjE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAI9C,eAAO,MAAM,QAAQ,gBAAiB,KAAK,GAAG,SAAS,uBAUtD,CAAA;AAED,KAAK,UAAU,GAAG,K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AE5C,MAAM,WAAW,kBAAkB,yBAO/B,MAAM,WAAW,kBAAkB,yBAEhC,MAAM,WAAW,kBAAkB,yBAS3D,CAAA;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,YAOlD;AAED,eAAO,MAAM,wBAAwB,gBACtB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,2BAQpE,CAAA"}
|
package/dist/lib/utils.js
CHANGED
|
@@ -193,7 +193,10 @@ export const getOverlayStyle = (opacity) => {
|
|
|
193
193
|
const DESTINATION_HANDLERS = {
|
|
194
194
|
"app-screen": (location, actions) => actions.openScreen({ destination: { type: "internal", url: location } }),
|
|
195
195
|
url: (location, actions) => actions.openScreen({
|
|
196
|
-
destination: {
|
|
196
|
+
destination: {
|
|
197
|
+
type: "web",
|
|
198
|
+
url: location.includes("https://") ? location : `https://${location}`,
|
|
199
|
+
},
|
|
197
200
|
}),
|
|
198
201
|
product: (location, actions) => actions.openProduct({ productId: location }),
|
|
199
202
|
collection: (location, actions) => actions.openCollection({ collectionId: location }),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../tests/utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getDestinationHandler } from "../lib/utils";
|
|
2
|
+
describe("DESTINATION_HANDLERS", () => {
|
|
3
|
+
describe("url handler", () => {
|
|
4
|
+
const mockActions = {
|
|
5
|
+
openScreen: jest.fn(),
|
|
6
|
+
openProduct: jest.fn(),
|
|
7
|
+
openCollection: jest.fn(),
|
|
8
|
+
};
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.clearAllMocks();
|
|
11
|
+
});
|
|
12
|
+
it("should prepend https:// when URL does not include it", () => {
|
|
13
|
+
const urlHandler = getDestinationHandler("url");
|
|
14
|
+
urlHandler("example.com", mockActions);
|
|
15
|
+
expect(mockActions.openScreen).toHaveBeenCalledWith({
|
|
16
|
+
destination: { type: "web", url: "https://example.com" },
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it("should not modify URL when it already includes https://", () => {
|
|
20
|
+
const urlHandler = getDestinationHandler("url");
|
|
21
|
+
urlHandler("https://example.com", mockActions);
|
|
22
|
+
expect(mockActions.openScreen).toHaveBeenCalledWith({
|
|
23
|
+
destination: { type: "web", url: "https://example.com" },
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("should not modify URL when it includes http://", () => {
|
|
27
|
+
const urlHandler = getDestinationHandler("url");
|
|
28
|
+
urlHandler("http://example.com", mockActions);
|
|
29
|
+
expect(mockActions.openScreen).toHaveBeenCalledWith({
|
|
30
|
+
destination: { type: "web", url: "https://http://example.com" },
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapcart/mobile-components",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/styles.css",
|
|
@@ -19,13 +19,16 @@
|
|
|
19
19
|
"build": "pnpm run build:ts && pnpm run build:styles",
|
|
20
20
|
"dev:ts": "tsc -w -p tsconfig.json",
|
|
21
21
|
"dev:styles": "npx tailwindcss -i styles/globals.css -o dist/styles.css --watch",
|
|
22
|
-
"dev": "concurrently \"pnpm run dev:ts\" \"pnpm run dev:styles\""
|
|
22
|
+
"dev": "concurrently \"pnpm run dev:ts\" \"pnpm run dev:styles\"",
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"test:watch": "jest --watch"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|
|
25
27
|
"react": "^17.0.2 || ^18.0.0",
|
|
26
28
|
"react-dom": "^17.0.2 || ^18.0.0"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
31
|
+
"@types/jest": "^29.5.14",
|
|
29
32
|
"@types/lodash": "4.17.5",
|
|
30
33
|
"@types/react": "^18.2.0",
|
|
31
34
|
"@types/react-dom": "^18.2.0",
|
|
@@ -35,8 +38,10 @@
|
|
|
35
38
|
"concurrently": "^8.2.2",
|
|
36
39
|
"eslint": "^7.32.0",
|
|
37
40
|
"eslint-config-custom": "workspace:*",
|
|
41
|
+
"jest": "^29.7.0",
|
|
38
42
|
"postcss": "^8.4.24",
|
|
39
43
|
"tailwindcss": "^3.3.2",
|
|
44
|
+
"ts-jest": "^29.2.5",
|
|
40
45
|
"tsc-alias": "^1.8.10",
|
|
41
46
|
"tsconfig": "workspace:*",
|
|
42
47
|
"typescript": "^4.5.2"
|
|
@@ -60,6 +65,7 @@
|
|
|
60
65
|
"@radix-ui/react-toggle": "^1.0.3",
|
|
61
66
|
"@radix-ui/react-toggle-group": "^1.0.4",
|
|
62
67
|
"@tabler/icons-react": "^3.2.0",
|
|
68
|
+
"@tapcart/webbridge-react": "^1.13.0",
|
|
63
69
|
"class-variance-authority": "^0.6.0",
|
|
64
70
|
"clsx": "^1.2.1",
|
|
65
71
|
"dayjs": "^1.11.13",
|
|
@@ -75,4 +81,4 @@
|
|
|
75
81
|
"tailwindcss-animate": "^1.0.6",
|
|
76
82
|
"vaul": "0.9.1"
|
|
77
83
|
}
|
|
78
|
-
}
|
|
84
|
+
}
|
|
@@ -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 };
|