@tapcart/mobile-components 0.7.46 → 0.7.47
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-click-outside.d.ts +3 -0
- package/dist/components/hooks/use-click-outside.d.ts.map +1 -0
- package/dist/components/hooks/use-click-outside.js +16 -0
- package/dist/components/hooks/use-infinite-scroll.d.ts +3 -1
- package/dist/components/hooks/use-infinite-scroll.d.ts.map +1 -1
- package/dist/components/hooks/use-infinite-scroll.js +15 -6
- package/dist/components/hooks/use-outside-click.d.ts +4 -0
- package/dist/components/hooks/use-outside-click.d.ts.map +1 -0
- package/dist/components/hooks/use-outside-click.js +16 -0
- package/package.json +19 -19
- package/dist/components/hooks/use-customer.d.ts +0 -10
- package/dist/components/hooks/use-customer.d.ts.map +0 -1
- package/dist/components/hooks/use-customer.js +0 -24
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
16
|
+
;
|
|
@@ -16,6 +16,8 @@ interface UseInfiniteScrollProps {
|
|
|
16
16
|
queryVariables: Record<string, any>;
|
|
17
17
|
direction: "vertical" | "horizontal";
|
|
18
18
|
productLimit: number;
|
|
19
|
+
threshold?: number;
|
|
20
|
+
interval?: number;
|
|
19
21
|
}
|
|
20
22
|
interface UseInfiniteScrollReturn {
|
|
21
23
|
data: PageData[] | undefined;
|
|
@@ -31,6 +33,6 @@ interface UseInfiniteScrollReturn {
|
|
|
31
33
|
}
|
|
32
34
|
export declare const formatSearchParamsAsNextQueryVariables: (searchParams: ReadonlyURLSearchParams) => {};
|
|
33
35
|
declare const constructURL: (apiURL: string) => string;
|
|
34
|
-
declare const useInfiniteScroll: ({ initialData, queryVariables: queryVariableProps, direction, productLimit, }: UseInfiniteScrollProps) => UseInfiniteScrollReturn;
|
|
36
|
+
declare const useInfiniteScroll: ({ initialData, queryVariables: queryVariableProps, direction, productLimit, threshold, interval, }: UseInfiniteScrollProps) => UseInfiniteScrollReturn;
|
|
35
37
|
export { useInfiniteScroll, constructURL };
|
|
36
38
|
//# sourceMappingURL=use-infinite-scroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAmB,MAAM,iBAAiB,CAAA;AAG1E,UAAU,OAAO;IACf,MAAM,EAAE,MAAM,CAAA;CAEf;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,GAAG,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;CACxC;AAOD,UAAU,sBAAsB;IAC9B,WAAW,EAAE,QAAQ,CAAA;IACrB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,SAAS,EAAE,UAAU,GAAG,YAAY,CAAA;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,uBAAuB;IAC/B,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA;IAC5B,KAAK,EAAE,GAAG,CAAA;IACV,oBAAoB,EAAE,OAAO,CAAA;IAC7B,aAAa,EAAE,OAAO,GAAG,SAAS,CAAA;IAClC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAA;IAChD,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,sCAAsC,iBACnC,uBAAuB,OAsBtC,CAAA;AAED,QAAA,MAAM,YAAY,WAAY,MAAM,WAGnC,CAAA;AAED,QAAA,MAAM,iBAAiB,uGAOpB,sBAAsB,KAAG,uBAmH3B,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -12,6 +12,7 @@ import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
|
12
12
|
import useSWRInfinite from "swr/infinite";
|
|
13
13
|
import { useInView } from "react-intersection-observer";
|
|
14
14
|
import { useSearchParams } from "next/navigation";
|
|
15
|
+
import { throttle } from "lodash";
|
|
15
16
|
export const formatSearchParamsAsNextQueryVariables = (searchParams) => {
|
|
16
17
|
const formattedParams = {};
|
|
17
18
|
if (!searchParams)
|
|
@@ -40,13 +41,13 @@ const constructURL = (apiURL) => {
|
|
|
40
41
|
const url = new URL(apiURL);
|
|
41
42
|
return url.toString();
|
|
42
43
|
};
|
|
43
|
-
const useInfiniteScroll = ({ initialData, queryVariables: queryVariableProps, direction = "vertical", productLimit = Infinity, }) => {
|
|
44
|
+
const useInfiniteScroll = ({ initialData, queryVariables: queryVariableProps, direction = "vertical", productLimit = Infinity, threshold = 0.8, interval = 300, }) => {
|
|
44
45
|
var _a, _b, _c, _d, _e;
|
|
45
46
|
const searchParams = useSearchParams();
|
|
46
47
|
const productCount = useRef(0);
|
|
47
48
|
const { ref, inView } = useInView({
|
|
48
49
|
rootMargin: direction === "vertical" ? "600px" : "0px 420px 0px 0px",
|
|
49
|
-
threshold:
|
|
50
|
+
threshold: threshold,
|
|
50
51
|
});
|
|
51
52
|
const queryVariables = useMemo(() => {
|
|
52
53
|
const formattedParams = formatSearchParamsAsNextQueryVariables(searchParams);
|
|
@@ -85,17 +86,25 @@ const useInfiniteScroll = ({ initialData, queryVariables: queryVariableProps, di
|
|
|
85
86
|
const isReachingEnd = isEmpty || isEndPointer;
|
|
86
87
|
const isRefreshing = isValidating && data && data.length === size;
|
|
87
88
|
const loadMore = useCallback(() => {
|
|
88
|
-
if (isLoadingMore || isReachingEnd || isRefreshing)
|
|
89
|
+
if (isLoading || isLoadingMore || isReachingEnd || isRefreshing)
|
|
89
90
|
return;
|
|
90
91
|
if (productCount.current >= productLimit)
|
|
91
92
|
return;
|
|
92
93
|
setSize(size + 1);
|
|
93
|
-
}, [
|
|
94
|
+
}, [
|
|
95
|
+
isLoading,
|
|
96
|
+
isLoadingMore,
|
|
97
|
+
isReachingEnd,
|
|
98
|
+
isRefreshing,
|
|
99
|
+
productLimit,
|
|
100
|
+
setSize,
|
|
101
|
+
]);
|
|
102
|
+
const throttleLoadMore = useMemo(() => throttle(loadMore, interval), [loadMore, interval]);
|
|
94
103
|
useEffect(() => {
|
|
95
104
|
if (inView) {
|
|
96
|
-
|
|
105
|
+
throttleLoadMore();
|
|
97
106
|
}
|
|
98
|
-
}, [inView,
|
|
107
|
+
}, [inView, throttleLoadMore]);
|
|
99
108
|
return {
|
|
100
109
|
data,
|
|
101
110
|
error,
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapcart/mobile-components",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.47",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/styles.css",
|
|
@@ -11,19 +11,6 @@
|
|
|
11
11
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
12
12
|
"author": "Tapcart Inc.",
|
|
13
13
|
"homepage": "https://tapcart.com",
|
|
14
|
-
"scripts": {
|
|
15
|
-
"lint": "eslint \"**/*.ts*\"",
|
|
16
|
-
"ui:add": "pnpm dlx shadcn-ui@latest add",
|
|
17
|
-
"build:styles": "postcss styles/globals.css -o dist/styles.css",
|
|
18
|
-
"build:ts": "tsc -p tsconfig.json && tsc-alias",
|
|
19
|
-
"build": "pnpm run build:ts && pnpm run build:styles",
|
|
20
|
-
"dev:ts": "tsc -w -p tsconfig.json",
|
|
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\"",
|
|
23
|
-
"test": "jest",
|
|
24
|
-
"test:silent": "jest --silent",
|
|
25
|
-
"test:watch": "jest --watch"
|
|
26
|
-
},
|
|
27
14
|
"peerDependencies": {
|
|
28
15
|
"react": "^17.0.2 || ^18.0.0",
|
|
29
16
|
"react-dom": "^17.0.2 || ^18.0.0"
|
|
@@ -34,21 +21,21 @@
|
|
|
34
21
|
"@types/lodash": "4.17.5",
|
|
35
22
|
"@types/react": "^18.2.0",
|
|
36
23
|
"@types/react-dom": "^18.2.0",
|
|
37
|
-
"app-studio-types": "workspace:*",
|
|
38
24
|
"autoprefixer": "^10.4.14",
|
|
39
25
|
"chokidar-cli": "^3.0.0",
|
|
40
26
|
"concurrently": "^8.2.2",
|
|
41
27
|
"eslint": "^7.32.0",
|
|
42
|
-
"eslint-config-custom": "workspace:*",
|
|
43
28
|
"jest": "^29.7.0",
|
|
44
29
|
"jest-environment-jsdom": "^29.7.0",
|
|
45
30
|
"postcss": "^8.4.24",
|
|
46
31
|
"tailwindcss": "^3.3.2",
|
|
47
32
|
"ts-jest": "^29.2.5",
|
|
48
33
|
"tsc-alias": "^1.8.10",
|
|
49
|
-
"tsconfig": "workspace:*",
|
|
50
34
|
"typescript": "^4.5.2",
|
|
51
|
-
"@testing-library/react-hooks": "^8.0.1"
|
|
35
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
36
|
+
"app-studio-types": "0.0.6",
|
|
37
|
+
"tsconfig": "0.0.0",
|
|
38
|
+
"eslint-config-custom": "0.0.0"
|
|
52
39
|
},
|
|
53
40
|
"dependencies": {
|
|
54
41
|
"@radix-ui/react-accordion": "^1.1.2",
|
|
@@ -87,5 +74,18 @@
|
|
|
87
74
|
"tailwind-merge": "^1.13.2",
|
|
88
75
|
"tailwindcss-animate": "^1.0.6",
|
|
89
76
|
"vaul": "0.9.1"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"lint": "eslint \"**/*.ts*\"",
|
|
80
|
+
"ui:add": "pnpm dlx shadcn-ui@latest add",
|
|
81
|
+
"build:styles": "postcss styles/globals.css -o dist/styles.css",
|
|
82
|
+
"build:ts": "tsc -p tsconfig.json && tsc-alias",
|
|
83
|
+
"build": "pnpm run build:ts && pnpm run build:styles",
|
|
84
|
+
"dev:ts": "tsc -w -p tsconfig.json",
|
|
85
|
+
"dev:styles": "npx tailwindcss -i styles/globals.css -o dist/styles.css --watch",
|
|
86
|
+
"dev": "concurrently \"pnpm run dev:ts\" \"pnpm run dev:styles\"",
|
|
87
|
+
"test": "jest",
|
|
88
|
+
"test:silent": "jest --silent",
|
|
89
|
+
"test:watch": "jest --watch"
|
|
90
90
|
}
|
|
91
|
-
}
|
|
91
|
+
}
|
|
@@ -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
|
-
};
|