@etsoo/toolpad 1.0.47 → 1.0.49
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/build/cjs/Account/AccountPreview.js +1 -1
- package/build/cjs/DashboardLayout/TitleBar.js +1 -1
- package/build/cjs/shared/components.js +1 -1
- package/build/mjs/Account/AccountPreview.js +1 -1
- package/build/mjs/DashboardLayout/TitleBar.js +1 -1
- package/build/mjs/shared/components.js +1 -1
- package/package.json +15 -25
- package/src/Account/AccountPreview.tsx +3 -4
- package/src/DashboardLayout/TitleBar.tsx +1 -1
- package/src/shared/components.tsx +1 -1
- package/build/cjs/nextjs/AppProvider.d.ts +0 -6
- package/build/cjs/nextjs/AppProvider.js +0 -18
- package/build/cjs/nextjs/AppProvider.test.d.ts +0 -1
- package/build/cjs/nextjs/AppProvider.test.js +0 -71
- package/build/cjs/nextjs/AppProviderNextApp.d.ts +0 -5
- package/build/cjs/nextjs/AppProviderNextApp.js +0 -63
- package/build/cjs/nextjs/AppProviderNextPages.d.ts +0 -5
- package/build/cjs/nextjs/AppProviderNextPages.js +0 -73
- package/build/cjs/nextjs/index.d.ts +0 -1
- package/build/cjs/nextjs/index.js +0 -17
- package/build/cjs/utils/hooks/useDebounced.d.ts +0 -8
- package/build/cjs/utils/hooks/useDebounced.js +0 -64
- package/build/cjs/utils/hooks/useDebouncedHandler.d.ts +0 -12
- package/build/cjs/utils/hooks/useDebouncedHandler.js +0 -77
- package/build/cjs/utils/hooks/useLatest.d.ts +0 -6
- package/build/cjs/utils/hooks/useLatest.js +0 -44
- package/build/mjs/nextjs/AppProvider.d.ts +0 -6
- package/build/mjs/nextjs/AppProvider.js +0 -16
- package/build/mjs/nextjs/AppProvider.test.d.ts +0 -1
- package/build/mjs/nextjs/AppProvider.test.js +0 -36
- package/build/mjs/nextjs/AppProviderNextApp.d.ts +0 -5
- package/build/mjs/nextjs/AppProviderNextApp.js +0 -27
- package/build/mjs/nextjs/AppProviderNextPages.d.ts +0 -5
- package/build/mjs/nextjs/AppProviderNextPages.js +0 -37
- package/build/mjs/nextjs/index.d.ts +0 -1
- package/build/mjs/nextjs/index.js +0 -1
- package/build/mjs/utils/hooks/useDebounced.d.ts +0 -8
- package/build/mjs/utils/hooks/useDebounced.js +0 -28
- package/build/mjs/utils/hooks/useDebouncedHandler.d.ts +0 -12
- package/build/mjs/utils/hooks/useDebouncedHandler.js +0 -41
- package/build/mjs/utils/hooks/useLatest.d.ts +0 -6
- package/build/mjs/utils/hooks/useLatest.js +0 -9
- package/src/nextjs/AppProvider.test.tsx +0 -48
- package/src/nextjs/AppProvider.tsx +0 -18
- package/src/nextjs/AppProviderNextApp.tsx +0 -37
- package/src/nextjs/AppProviderNextPages.tsx +0 -52
- package/src/nextjs/index.tsx +0 -1
- package/src/utils/hooks/useDebounced.ts +0 -39
- package/src/utils/hooks/useDebouncedHandler.ts +0 -71
- package/src/utils/hooks/useLatest.ts +0 -16
|
@@ -89,7 +89,7 @@ function AccountPreview(props) {
|
|
|
89
89
|
width: variant === "expanded" ? 48 : 32
|
|
90
90
|
}, ...slotProps?.avatar, children: session.user?.image ? null : formatNameInitials(session.user) }));
|
|
91
91
|
if (variant === "expanded") {
|
|
92
|
-
return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row",
|
|
92
|
+
return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row", spacing: 2, sx: { padding: 2, justifyContent: "flex-start" }, children: [avatarContent, (0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "column", sx: { justifyContent: "space-evenly" }, children: [(0, jsx_runtime_1.jsx)(Typography_1.default, { variant: "body2", noWrap: true, sx: { fontWeight: "bolder" }, children: session.user?.name }), (0, jsx_runtime_1.jsx)(Typography_1.default, { variant: "caption", noWrap: true, children: session.user?.email })] }), handleClick &&
|
|
93
93
|
(slots?.moreIconButton ? ((0, jsx_runtime_1.jsx)(slots.moreIconButton, {})) : ((0, jsx_runtime_1.jsx)(IconButton_1.default, { size: "small", onClick: handleClick, ...slotProps?.moreIconButton, sx: { alignSelf: "flex-start", ...slotProps?.moreIconButton?.sx }, children: (0, jsx_runtime_1.jsx)(MoreVert_1.default, { fontSize: "small" }) })))] }));
|
|
94
94
|
}
|
|
95
95
|
return ((0, jsx_runtime_1.jsx)(Tooltip_1.default, { title: session.user.name ?? "Account", children: slots?.avatarIconButton ? ((0, jsx_runtime_1.jsx)(slots.avatarIconButton, {})) : ((0, jsx_runtime_1.jsx)(IconButton_1.default, { onClick: handleClick, "aria-label": localeText.accountIconButtonAriaLabel, size: "small", "aria-controls": open ? "account-menu" : undefined, "aria-haspopup": "true", "aria-expanded": open ? "true" : undefined, ...slotProps?.avatarIconButton, children: avatarContent })) }));
|
|
@@ -51,7 +51,7 @@ function TitleBar() {
|
|
|
51
51
|
return [title, false];
|
|
52
52
|
}, [title]);
|
|
53
53
|
if (hasLink) {
|
|
54
|
-
return ((0, jsx_runtime_1.jsx)(Link_1.Link, { href: "/", style: { color: "inherit", textDecoration: "none" }, children: (0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row", alignItems: "center", children: [branding?.logo && (0, jsx_runtime_1.jsx)(LogoContainer, { children: branding.logo }), titleUI] }) }));
|
|
54
|
+
return ((0, jsx_runtime_1.jsx)(Link_1.Link, { href: "/", style: { color: "inherit", textDecoration: "none" }, children: (0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row", sx: { alignItems: "center" }, children: [branding?.logo && (0, jsx_runtime_1.jsx)(LogoContainer, { children: branding.logo }), titleUI] }) }));
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
return titleUI;
|
|
@@ -25,7 +25,7 @@ function ErrorOverlay({ error }) {
|
|
|
25
25
|
flexDirection: "row",
|
|
26
26
|
gap: 1,
|
|
27
27
|
alignItems: "center"
|
|
28
|
-
}, children: [(0, jsx_runtime_1.jsx)(Error_1.default, { color: "error" }), " Error"] }), (0, jsx_runtime_1.jsx)(Typography_1.default, {
|
|
28
|
+
}, children: [(0, jsx_runtime_1.jsx)(Error_1.default, { color: "error" }), " Error"] }), (0, jsx_runtime_1.jsx)(Typography_1.default, { align: "center", children: error?.message ?? "Unknown error" })] }));
|
|
29
29
|
}
|
|
30
30
|
function LoadingOverlay() {
|
|
31
31
|
return ((0, jsx_runtime_1.jsx)(OverlayRoot, { children: (0, jsx_runtime_1.jsx)(CircularProgress_1.default, {}) }));
|
|
@@ -50,7 +50,7 @@ function AccountPreview(props) {
|
|
|
50
50
|
width: variant === "expanded" ? 48 : 32
|
|
51
51
|
}, ...slotProps?.avatar, children: session.user?.image ? null : formatNameInitials(session.user) }));
|
|
52
52
|
if (variant === "expanded") {
|
|
53
|
-
return (_jsxs(Stack, { direction: "row",
|
|
53
|
+
return (_jsxs(Stack, { direction: "row", spacing: 2, sx: { padding: 2, justifyContent: "flex-start" }, children: [avatarContent, _jsxs(Stack, { direction: "column", sx: { justifyContent: "space-evenly" }, children: [_jsx(Typography, { variant: "body2", noWrap: true, sx: { fontWeight: "bolder" }, children: session.user?.name }), _jsx(Typography, { variant: "caption", noWrap: true, children: session.user?.email })] }), handleClick &&
|
|
54
54
|
(slots?.moreIconButton ? (_jsx(slots.moreIconButton, {})) : (_jsx(IconButton, { size: "small", onClick: handleClick, ...slotProps?.moreIconButton, sx: { alignSelf: "flex-start", ...slotProps?.moreIconButton?.sx }, children: _jsx(MoreVertIcon, { fontSize: "small" }) })))] }));
|
|
55
55
|
}
|
|
56
56
|
return (_jsx(Tooltip, { title: session.user.name ?? "Account", children: slots?.avatarIconButton ? (_jsx(slots.avatarIconButton, {})) : (_jsx(IconButton, { onClick: handleClick, "aria-label": localeText.accountIconButtonAriaLabel, size: "small", "aria-controls": open ? "account-menu" : undefined, "aria-haspopup": "true", "aria-expanded": open ? "true" : undefined, ...slotProps?.avatarIconButton, children: avatarContent })) }));
|
|
@@ -45,7 +45,7 @@ export function TitleBar() {
|
|
|
45
45
|
return [title, false];
|
|
46
46
|
}, [title]);
|
|
47
47
|
if (hasLink) {
|
|
48
|
-
return (_jsx(Link, { href: "/", style: { color: "inherit", textDecoration: "none" }, children: _jsxs(Stack, { direction: "row", alignItems: "center", children: [branding?.logo && _jsx(LogoContainer, { children: branding.logo }), titleUI] }) }));
|
|
48
|
+
return (_jsx(Link, { href: "/", style: { color: "inherit", textDecoration: "none" }, children: _jsxs(Stack, { direction: "row", sx: { alignItems: "center" }, children: [branding?.logo && _jsx(LogoContainer, { children: branding.logo }), titleUI] }) }));
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
51
|
return titleUI;
|
|
@@ -18,7 +18,7 @@ export function ErrorOverlay({ error }) {
|
|
|
18
18
|
flexDirection: "row",
|
|
19
19
|
gap: 1,
|
|
20
20
|
alignItems: "center"
|
|
21
|
-
}, children: [_jsx(ErrorIcon, { color: "error" }), " Error"] }), _jsx(Typography, {
|
|
21
|
+
}, children: [_jsx(ErrorIcon, { color: "error" }), " Error"] }), _jsx(Typography, { align: "center", children: error?.message ?? "Unknown error" })] }));
|
|
22
22
|
}
|
|
23
23
|
export function LoadingOverlay() {
|
|
24
24
|
return (_jsx(OverlayRoot, { children: _jsx(CircularProgress, {}) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/toolpad",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.49",
|
|
4
4
|
"author": "ETSOO",
|
|
5
5
|
"description": "Dashboard framework extention based on Toolpad Core",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -11,11 +11,6 @@
|
|
|
11
11
|
"import": "./build/mjs/index.js",
|
|
12
12
|
"require": "./build/cjs/index.js"
|
|
13
13
|
},
|
|
14
|
-
"./nextjs": {
|
|
15
|
-
"types": "./build/mjs/nextjs/index.d.ts",
|
|
16
|
-
"import": "./build/mjs/nextjs/index.js",
|
|
17
|
-
"require": "./build/cjs/nextjs/index.js"
|
|
18
|
-
},
|
|
19
14
|
"./react-router-dom": {
|
|
20
15
|
"types": "./build/mjs/react-router-dom/index.d.ts",
|
|
21
16
|
"import": "./build/mjs/react-router-dom/index.js",
|
|
@@ -47,40 +42,35 @@
|
|
|
47
42
|
"dependencies": {
|
|
48
43
|
"@emotion/react": "^11.14.0",
|
|
49
44
|
"@emotion/styled": "^11.14.1",
|
|
50
|
-
"@mui/icons-material": "
|
|
51
|
-
"@mui/material": "
|
|
52
|
-
"@mui/utils": "
|
|
45
|
+
"@mui/icons-material": "9.0.1",
|
|
46
|
+
"@mui/material": "9.0.1",
|
|
47
|
+
"@mui/utils": "9.0.1",
|
|
53
48
|
"invariant": "2.2.4",
|
|
54
49
|
"path-to-regexp": "^6.3.0",
|
|
55
|
-
"react": "^19.2.
|
|
56
|
-
"react-dom": "^19.2.
|
|
50
|
+
"react": "^19.2.6",
|
|
51
|
+
"react-dom": "^19.2.6"
|
|
57
52
|
},
|
|
58
53
|
"devDependencies": {
|
|
59
54
|
"@babel/core": "^7.29.0",
|
|
60
55
|
"@babel/plugin-transform-runtime": "^7.29.0",
|
|
61
|
-
"@babel/preset-env": "^7.29.
|
|
56
|
+
"@babel/preset-env": "^7.29.5",
|
|
62
57
|
"@babel/runtime-corejs3": "^7.29.2",
|
|
63
58
|
"@testing-library/jest-dom": "^6.9.1",
|
|
64
59
|
"@testing-library/react": "^16.3.2",
|
|
65
60
|
"@testing-library/user-event": "^14.6.1",
|
|
66
61
|
"@types/invariant": "2.2.37",
|
|
67
|
-
"@types/node": "^25.
|
|
62
|
+
"@types/node": "^25.8.0",
|
|
68
63
|
"@types/react": "19.2.14",
|
|
69
64
|
"@types/react-dom": "19.2.3",
|
|
70
|
-
"@vitejs/plugin-react": "6.0.
|
|
71
|
-
"@vitest/browser": "4.1.
|
|
72
|
-
"@vitest/browser-playwright": "^4.1.
|
|
73
|
-
"jsdom": "^29.
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"react-router-dom": "^7.14.0",
|
|
78
|
-
"vitest": "4.1.2"
|
|
65
|
+
"@vitejs/plugin-react": "6.0.2",
|
|
66
|
+
"@vitest/browser": "4.1.6",
|
|
67
|
+
"@vitest/browser-playwright": "^4.1.6",
|
|
68
|
+
"jsdom": "^29.1.1",
|
|
69
|
+
"playwright": "^1.60.0",
|
|
70
|
+
"react-router-dom": "^7.15.1",
|
|
71
|
+
"vitest": "4.1.6"
|
|
79
72
|
},
|
|
80
73
|
"peerDependenciesMeta": {
|
|
81
|
-
"next": {
|
|
82
|
-
"optional": true
|
|
83
|
-
},
|
|
84
74
|
"react-router-dom": {
|
|
85
75
|
"optional": true
|
|
86
76
|
}
|
|
@@ -120,13 +120,12 @@ function AccountPreview(props: AccountPreviewProps) {
|
|
|
120
120
|
return (
|
|
121
121
|
<Stack
|
|
122
122
|
direction="row"
|
|
123
|
-
justifyContent="flex-start"
|
|
124
123
|
spacing={2}
|
|
125
|
-
|
|
124
|
+
sx={{ padding: 2, justifyContent: "flex-start" }}
|
|
126
125
|
>
|
|
127
126
|
{avatarContent}
|
|
128
|
-
<Stack direction="column" justifyContent
|
|
129
|
-
<Typography variant="body2" fontWeight
|
|
127
|
+
<Stack direction="column" sx={{ justifyContent: "space-evenly" }}>
|
|
128
|
+
<Typography variant="body2" noWrap sx={{ fontWeight: "bolder" }}>
|
|
130
129
|
{session.user?.name}
|
|
131
130
|
</Typography>
|
|
132
131
|
<Typography variant="caption" noWrap>
|
|
@@ -59,7 +59,7 @@ export function TitleBar() {
|
|
|
59
59
|
if (hasLink) {
|
|
60
60
|
return (
|
|
61
61
|
<Link href="/" style={{ color: "inherit", textDecoration: "none" }}>
|
|
62
|
-
<Stack direction="row" alignItems
|
|
62
|
+
<Stack direction="row" sx={{ alignItems: "center" }}>
|
|
63
63
|
{branding?.logo && <LogoContainer>{branding.logo}</LogoContainer>}
|
|
64
64
|
{titleUI}
|
|
65
65
|
</Stack>
|
|
@@ -31,7 +31,7 @@ export function ErrorOverlay({ error }: ErrorOverlayProps) {
|
|
|
31
31
|
>
|
|
32
32
|
<ErrorIcon color="error" /> Error
|
|
33
33
|
</Typography>
|
|
34
|
-
<Typography
|
|
34
|
+
<Typography align="center">
|
|
35
35
|
{(error as any)?.message ?? "Unknown error"}
|
|
36
36
|
</Typography>
|
|
37
37
|
</OverlayRoot>
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AppProvider = AppProvider;
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const router_1 = require("next/compat/router");
|
|
7
|
-
const AppProviderNextApp_1 = require("./AppProviderNextApp");
|
|
8
|
-
const AppProviderNextPages_1 = require("./AppProviderNextPages");
|
|
9
|
-
/**
|
|
10
|
-
* @ignore - internal component.
|
|
11
|
-
*/
|
|
12
|
-
function AppProvider(props) {
|
|
13
|
-
const router = (0, router_1.useRouter)();
|
|
14
|
-
const AppProviderComponent = router
|
|
15
|
-
? AppProviderNextPages_1.AppProviderNextPages
|
|
16
|
-
: AppProviderNextApp_1.AppProviderNextApp;
|
|
17
|
-
return (0, jsx_runtime_1.jsx)(AppProviderComponent, { ...props });
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
|
-
const React = __importStar(require("react"));
|
|
38
|
-
const vitest_1 = require("vitest");
|
|
39
|
-
const react_1 = require("@testing-library/react");
|
|
40
|
-
const AppProvider_1 = require("./AppProvider");
|
|
41
|
-
vitest_1.vi.mock("next/navigation", () => {
|
|
42
|
-
const searchParams = new URLSearchParams();
|
|
43
|
-
const push = () => { };
|
|
44
|
-
const replace = () => { };
|
|
45
|
-
const router = { push, replace };
|
|
46
|
-
return {
|
|
47
|
-
usePathname: () => "/",
|
|
48
|
-
useSearchParams: () => searchParams,
|
|
49
|
-
useRouter: () => router
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
vitest_1.vi.mock("next/router", () => ({ useRouter: () => null }));
|
|
53
|
-
vitest_1.vi.mock("next/compat/router", () => ({ useRouter: () => null }));
|
|
54
|
-
function RouterTest({ children }) {
|
|
55
|
-
const [pathname, setPathname] = React.useState("/page");
|
|
56
|
-
const router = React.useMemo(() => {
|
|
57
|
-
return {
|
|
58
|
-
pathname,
|
|
59
|
-
searchParams: new URLSearchParams(),
|
|
60
|
-
navigate: (path) => setPathname(String(path))
|
|
61
|
-
};
|
|
62
|
-
}, [pathname]);
|
|
63
|
-
return (0, jsx_runtime_1.jsx)(AppProvider_1.AppProvider, { router: router, children: children });
|
|
64
|
-
}
|
|
65
|
-
(0, vitest_1.describe)("Nextjs AppProvider", () => {
|
|
66
|
-
(0, vitest_1.test)("renders content correctly", async () => {
|
|
67
|
-
// placeholder test
|
|
68
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(RouterTest, { children: "Hello" }));
|
|
69
|
-
(0, vitest_1.expect)(react_1.screen.getByText("Hello")).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AppProviderNextApp = AppProviderNextApp;
|
|
37
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
-
const React = __importStar(require("react"));
|
|
39
|
-
const navigation_1 = require("next/navigation");
|
|
40
|
-
const AppProviderComponent_1 = require("../AppProvider/AppProviderComponent");
|
|
41
|
-
/**
|
|
42
|
-
* @ignore - internal component.
|
|
43
|
-
*/
|
|
44
|
-
function AppProviderNextApp(props) {
|
|
45
|
-
const pathname = (0, navigation_1.usePathname)();
|
|
46
|
-
const searchParams = (0, navigation_1.useSearchParams)();
|
|
47
|
-
const { push, replace } = (0, navigation_1.useRouter)();
|
|
48
|
-
const navigate = React.useCallback((url, { history = "auto" } = {}) => {
|
|
49
|
-
if (history === "auto" || history === "push") {
|
|
50
|
-
return push(String(url));
|
|
51
|
-
}
|
|
52
|
-
if (history === "replace") {
|
|
53
|
-
return replace(String(url));
|
|
54
|
-
}
|
|
55
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
56
|
-
}, [push, replace]);
|
|
57
|
-
const routerImpl = React.useMemo(() => ({
|
|
58
|
-
pathname,
|
|
59
|
-
searchParams,
|
|
60
|
-
navigate
|
|
61
|
-
}), [pathname, navigate, searchParams]);
|
|
62
|
-
return (0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { router: routerImpl, ...props });
|
|
63
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AppProviderNextPages = AppProviderNextPages;
|
|
37
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
-
const React = __importStar(require("react"));
|
|
39
|
-
const router_1 = require("next/router");
|
|
40
|
-
const collections_1 = require("../utils/collections");
|
|
41
|
-
const AppProviderComponent_1 = require("../AppProvider/AppProviderComponent");
|
|
42
|
-
/**
|
|
43
|
-
* @ignore - internal component.
|
|
44
|
-
*/
|
|
45
|
-
function AppProviderNextPages(props) {
|
|
46
|
-
const { push, replace, asPath, query } = (0, router_1.useRouter)();
|
|
47
|
-
const search = React.useMemo(() => {
|
|
48
|
-
const params = new URLSearchParams();
|
|
49
|
-
Object.entries(query ?? {}).forEach(([key, value]) => {
|
|
50
|
-
(0, collections_1.asArray)(value ?? []).forEach((v) => {
|
|
51
|
-
params.append(key, v.toString());
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
return params.toString();
|
|
55
|
-
}, [query]);
|
|
56
|
-
// Stable search params object
|
|
57
|
-
const searchParams = React.useMemo(() => new URLSearchParams(search), [search]);
|
|
58
|
-
const navigate = React.useCallback((url, { history = "auto" } = {}) => {
|
|
59
|
-
if (history === "auto" || history === "push") {
|
|
60
|
-
return push(String(url));
|
|
61
|
-
}
|
|
62
|
-
if (history === "replace") {
|
|
63
|
-
return replace(String(url));
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
66
|
-
}, [push, replace]);
|
|
67
|
-
const routerImpl = React.useMemo(() => ({
|
|
68
|
-
pathname: asPath,
|
|
69
|
-
searchParams,
|
|
70
|
-
navigate
|
|
71
|
-
}), [asPath, navigate, searchParams]);
|
|
72
|
-
return (0, jsx_runtime_1.jsx)(AppProviderComponent_1.AppProvider, { router: routerImpl, ...props });
|
|
73
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./AppProvider";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./AppProvider"), exports);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This hook allows you to debounce any fast changing value. The debounced value will only
|
|
3
|
-
* reflect the latest value when the useDebounce hook has not been called for the specified
|
|
4
|
-
* time period.
|
|
5
|
-
*
|
|
6
|
-
* Inspired by https://usehooks.com/useDebounce/
|
|
7
|
-
*/
|
|
8
|
-
export default function useDebounced<T>(value: T, delay: number): T;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = useDebounced;
|
|
37
|
-
const React = __importStar(require("react"));
|
|
38
|
-
/**
|
|
39
|
-
* This hook allows you to debounce any fast changing value. The debounced value will only
|
|
40
|
-
* reflect the latest value when the useDebounce hook has not been called for the specified
|
|
41
|
-
* time period.
|
|
42
|
-
*
|
|
43
|
-
* Inspired by https://usehooks.com/useDebounce/
|
|
44
|
-
*/
|
|
45
|
-
function useDebounced(value, delay) {
|
|
46
|
-
const [debouncedValue, setDebouncedValue] = React.useState(() => value);
|
|
47
|
-
const timeoutIdRef = React.useRef(null);
|
|
48
|
-
React.useEffect(() => () => {
|
|
49
|
-
if (timeoutIdRef.current) {
|
|
50
|
-
clearTimeout(timeoutIdRef.current);
|
|
51
|
-
timeoutIdRef.current = null;
|
|
52
|
-
}
|
|
53
|
-
}, []);
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
timeoutIdRef.current = setTimeout(() => setDebouncedValue(() => value), delay);
|
|
56
|
-
return () => {
|
|
57
|
-
if (timeoutIdRef.current) {
|
|
58
|
-
clearTimeout(timeoutIdRef.current);
|
|
59
|
-
timeoutIdRef.current = null;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}, [value, delay]);
|
|
63
|
-
return debouncedValue;
|
|
64
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
interface Handler<P extends unknown[]> {
|
|
2
|
-
(...params: P): void;
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Creates a debounced version of the handler that is passed. The invocation of [fn] is
|
|
6
|
-
* delayed for [delay] milliseconds from the last invocation of the debounced function.
|
|
7
|
-
*
|
|
8
|
-
* This implementation adds on the lodash implementation in that it handles updates to the
|
|
9
|
-
* delay value.
|
|
10
|
-
*/
|
|
11
|
-
export default function useDebouncedHandler<P extends unknown[]>(fn: Handler<P>, delay: number): Handler<P>;
|
|
12
|
-
export {};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = useDebouncedHandler;
|
|
37
|
-
const React = __importStar(require("react"));
|
|
38
|
-
function defer(fn, params, delay) {
|
|
39
|
-
const timeout = setTimeout(() => {
|
|
40
|
-
fn.current(...params);
|
|
41
|
-
}, delay);
|
|
42
|
-
return { startTime: Date.now(), timeout, params };
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a debounced version of the handler that is passed. The invocation of [fn] is
|
|
46
|
-
* delayed for [delay] milliseconds from the last invocation of the debounced function.
|
|
47
|
-
*
|
|
48
|
-
* This implementation adds on the lodash implementation in that it handles updates to the
|
|
49
|
-
* delay value.
|
|
50
|
-
*/
|
|
51
|
-
function useDebouncedHandler(fn, delay) {
|
|
52
|
-
const fnRef = React.useRef(fn);
|
|
53
|
-
React.useEffect(() => {
|
|
54
|
-
fnRef.current = fn;
|
|
55
|
-
}, [fn]);
|
|
56
|
-
const delayedInvocation = React.useRef(null);
|
|
57
|
-
const clearCurrent = React.useCallback(() => {
|
|
58
|
-
if (delayedInvocation.current) {
|
|
59
|
-
clearTimeout(delayedInvocation.current.timeout);
|
|
60
|
-
delayedInvocation.current = null;
|
|
61
|
-
}
|
|
62
|
-
}, []);
|
|
63
|
-
React.useEffect(() => {
|
|
64
|
-
if (!delayedInvocation.current) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const { startTime, params } = delayedInvocation.current;
|
|
68
|
-
const elapsed = Date.now() - startTime;
|
|
69
|
-
const newDelay = Math.max(delay - elapsed, 0);
|
|
70
|
-
clearCurrent();
|
|
71
|
-
delayedInvocation.current = defer(fnRef, params, newDelay);
|
|
72
|
-
}, [delay, clearCurrent]);
|
|
73
|
-
return React.useCallback((...params) => {
|
|
74
|
-
clearCurrent();
|
|
75
|
-
delayedInvocation.current = defer(fnRef, params, delay);
|
|
76
|
-
}, [delay, clearCurrent]);
|
|
77
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const React = __importStar(require("react"));
|
|
37
|
-
function useLatest(value) {
|
|
38
|
-
const [latest, setLatest] = React.useState(value);
|
|
39
|
-
if (latest !== value && value !== null && value !== undefined) {
|
|
40
|
-
setLatest(value);
|
|
41
|
-
}
|
|
42
|
-
return value ?? latest;
|
|
43
|
-
}
|
|
44
|
-
exports.default = useLatest;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useRouter } from "next/compat/router";
|
|
4
|
-
import { AppProviderNextApp } from "./AppProviderNextApp";
|
|
5
|
-
import { AppProviderNextPages } from "./AppProviderNextPages";
|
|
6
|
-
/**
|
|
7
|
-
* @ignore - internal component.
|
|
8
|
-
*/
|
|
9
|
-
function AppProvider(props) {
|
|
10
|
-
const router = useRouter();
|
|
11
|
-
const AppProviderComponent = router
|
|
12
|
-
? AppProviderNextPages
|
|
13
|
-
: AppProviderNextApp;
|
|
14
|
-
return _jsx(AppProviderComponent, { ...props });
|
|
15
|
-
}
|
|
16
|
-
export { AppProvider };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { describe, test, expect, vi } from "vitest";
|
|
4
|
-
import { render, screen } from "@testing-library/react";
|
|
5
|
-
import { AppProvider } from "./AppProvider";
|
|
6
|
-
vi.mock("next/navigation", () => {
|
|
7
|
-
const searchParams = new URLSearchParams();
|
|
8
|
-
const push = () => { };
|
|
9
|
-
const replace = () => { };
|
|
10
|
-
const router = { push, replace };
|
|
11
|
-
return {
|
|
12
|
-
usePathname: () => "/",
|
|
13
|
-
useSearchParams: () => searchParams,
|
|
14
|
-
useRouter: () => router
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
vi.mock("next/router", () => ({ useRouter: () => null }));
|
|
18
|
-
vi.mock("next/compat/router", () => ({ useRouter: () => null }));
|
|
19
|
-
function RouterTest({ children }) {
|
|
20
|
-
const [pathname, setPathname] = React.useState("/page");
|
|
21
|
-
const router = React.useMemo(() => {
|
|
22
|
-
return {
|
|
23
|
-
pathname,
|
|
24
|
-
searchParams: new URLSearchParams(),
|
|
25
|
-
navigate: (path) => setPathname(String(path))
|
|
26
|
-
};
|
|
27
|
-
}, [pathname]);
|
|
28
|
-
return _jsx(AppProvider, { router: router, children: children });
|
|
29
|
-
}
|
|
30
|
-
describe("Nextjs AppProvider", () => {
|
|
31
|
-
test("renders content correctly", async () => {
|
|
32
|
-
// placeholder test
|
|
33
|
-
render(_jsx(RouterTest, { children: "Hello" }));
|
|
34
|
-
expect(screen.getByText("Hello")).toBeTruthy();
|
|
35
|
-
});
|
|
36
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { usePathname, useSearchParams, useRouter } from "next/navigation";
|
|
4
|
-
import { AppProvider } from "../AppProvider/AppProviderComponent";
|
|
5
|
-
/**
|
|
6
|
-
* @ignore - internal component.
|
|
7
|
-
*/
|
|
8
|
-
export function AppProviderNextApp(props) {
|
|
9
|
-
const pathname = usePathname();
|
|
10
|
-
const searchParams = useSearchParams();
|
|
11
|
-
const { push, replace } = useRouter();
|
|
12
|
-
const navigate = React.useCallback((url, { history = "auto" } = {}) => {
|
|
13
|
-
if (history === "auto" || history === "push") {
|
|
14
|
-
return push(String(url));
|
|
15
|
-
}
|
|
16
|
-
if (history === "replace") {
|
|
17
|
-
return replace(String(url));
|
|
18
|
-
}
|
|
19
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
20
|
-
}, [push, replace]);
|
|
21
|
-
const routerImpl = React.useMemo(() => ({
|
|
22
|
-
pathname,
|
|
23
|
-
searchParams,
|
|
24
|
-
navigate
|
|
25
|
-
}), [pathname, navigate, searchParams]);
|
|
26
|
-
return _jsx(AppProvider, { router: routerImpl, ...props });
|
|
27
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useRouter } from "next/router";
|
|
4
|
-
import { asArray } from "../utils/collections";
|
|
5
|
-
import { AppProvider } from "../AppProvider/AppProviderComponent";
|
|
6
|
-
/**
|
|
7
|
-
* @ignore - internal component.
|
|
8
|
-
*/
|
|
9
|
-
export function AppProviderNextPages(props) {
|
|
10
|
-
const { push, replace, asPath, query } = useRouter();
|
|
11
|
-
const search = React.useMemo(() => {
|
|
12
|
-
const params = new URLSearchParams();
|
|
13
|
-
Object.entries(query ?? {}).forEach(([key, value]) => {
|
|
14
|
-
asArray(value ?? []).forEach((v) => {
|
|
15
|
-
params.append(key, v.toString());
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
return params.toString();
|
|
19
|
-
}, [query]);
|
|
20
|
-
// Stable search params object
|
|
21
|
-
const searchParams = React.useMemo(() => new URLSearchParams(search), [search]);
|
|
22
|
-
const navigate = React.useCallback((url, { history = "auto" } = {}) => {
|
|
23
|
-
if (history === "auto" || history === "push") {
|
|
24
|
-
return push(String(url));
|
|
25
|
-
}
|
|
26
|
-
if (history === "replace") {
|
|
27
|
-
return replace(String(url));
|
|
28
|
-
}
|
|
29
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
30
|
-
}, [push, replace]);
|
|
31
|
-
const routerImpl = React.useMemo(() => ({
|
|
32
|
-
pathname: asPath,
|
|
33
|
-
searchParams,
|
|
34
|
-
navigate
|
|
35
|
-
}), [asPath, navigate, searchParams]);
|
|
36
|
-
return _jsx(AppProvider, { router: routerImpl, ...props });
|
|
37
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./AppProvider";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./AppProvider";
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This hook allows you to debounce any fast changing value. The debounced value will only
|
|
3
|
-
* reflect the latest value when the useDebounce hook has not been called for the specified
|
|
4
|
-
* time period.
|
|
5
|
-
*
|
|
6
|
-
* Inspired by https://usehooks.com/useDebounce/
|
|
7
|
-
*/
|
|
8
|
-
export default function useDebounced<T>(value: T, delay: number): T;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* This hook allows you to debounce any fast changing value. The debounced value will only
|
|
4
|
-
* reflect the latest value when the useDebounce hook has not been called for the specified
|
|
5
|
-
* time period.
|
|
6
|
-
*
|
|
7
|
-
* Inspired by https://usehooks.com/useDebounce/
|
|
8
|
-
*/
|
|
9
|
-
export default function useDebounced(value, delay) {
|
|
10
|
-
const [debouncedValue, setDebouncedValue] = React.useState(() => value);
|
|
11
|
-
const timeoutIdRef = React.useRef(null);
|
|
12
|
-
React.useEffect(() => () => {
|
|
13
|
-
if (timeoutIdRef.current) {
|
|
14
|
-
clearTimeout(timeoutIdRef.current);
|
|
15
|
-
timeoutIdRef.current = null;
|
|
16
|
-
}
|
|
17
|
-
}, []);
|
|
18
|
-
React.useEffect(() => {
|
|
19
|
-
timeoutIdRef.current = setTimeout(() => setDebouncedValue(() => value), delay);
|
|
20
|
-
return () => {
|
|
21
|
-
if (timeoutIdRef.current) {
|
|
22
|
-
clearTimeout(timeoutIdRef.current);
|
|
23
|
-
timeoutIdRef.current = null;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}, [value, delay]);
|
|
27
|
-
return debouncedValue;
|
|
28
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
interface Handler<P extends unknown[]> {
|
|
2
|
-
(...params: P): void;
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Creates a debounced version of the handler that is passed. The invocation of [fn] is
|
|
6
|
-
* delayed for [delay] milliseconds from the last invocation of the debounced function.
|
|
7
|
-
*
|
|
8
|
-
* This implementation adds on the lodash implementation in that it handles updates to the
|
|
9
|
-
* delay value.
|
|
10
|
-
*/
|
|
11
|
-
export default function useDebouncedHandler<P extends unknown[]>(fn: Handler<P>, delay: number): Handler<P>;
|
|
12
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
function defer(fn, params, delay) {
|
|
3
|
-
const timeout = setTimeout(() => {
|
|
4
|
-
fn.current(...params);
|
|
5
|
-
}, delay);
|
|
6
|
-
return { startTime: Date.now(), timeout, params };
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Creates a debounced version of the handler that is passed. The invocation of [fn] is
|
|
10
|
-
* delayed for [delay] milliseconds from the last invocation of the debounced function.
|
|
11
|
-
*
|
|
12
|
-
* This implementation adds on the lodash implementation in that it handles updates to the
|
|
13
|
-
* delay value.
|
|
14
|
-
*/
|
|
15
|
-
export default function useDebouncedHandler(fn, delay) {
|
|
16
|
-
const fnRef = React.useRef(fn);
|
|
17
|
-
React.useEffect(() => {
|
|
18
|
-
fnRef.current = fn;
|
|
19
|
-
}, [fn]);
|
|
20
|
-
const delayedInvocation = React.useRef(null);
|
|
21
|
-
const clearCurrent = React.useCallback(() => {
|
|
22
|
-
if (delayedInvocation.current) {
|
|
23
|
-
clearTimeout(delayedInvocation.current.timeout);
|
|
24
|
-
delayedInvocation.current = null;
|
|
25
|
-
}
|
|
26
|
-
}, []);
|
|
27
|
-
React.useEffect(() => {
|
|
28
|
-
if (!delayedInvocation.current) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const { startTime, params } = delayedInvocation.current;
|
|
32
|
-
const elapsed = Date.now() - startTime;
|
|
33
|
-
const newDelay = Math.max(delay - elapsed, 0);
|
|
34
|
-
clearCurrent();
|
|
35
|
-
delayedInvocation.current = defer(fnRef, params, newDelay);
|
|
36
|
-
}, [delay, clearCurrent]);
|
|
37
|
-
return React.useCallback((...params) => {
|
|
38
|
-
clearCurrent();
|
|
39
|
-
delayedInvocation.current = defer(fnRef, params, delay);
|
|
40
|
-
}, [delay, clearCurrent]);
|
|
41
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { describe, test, expect, vi } from "vitest";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import { AppProvider } from "./AppProvider";
|
|
5
|
-
import { Router } from "../AppProvider";
|
|
6
|
-
|
|
7
|
-
vi.mock("next/navigation", () => {
|
|
8
|
-
const searchParams = new URLSearchParams();
|
|
9
|
-
const push = () => {};
|
|
10
|
-
const replace = () => {};
|
|
11
|
-
const router = { push, replace };
|
|
12
|
-
return {
|
|
13
|
-
usePathname: () => "/",
|
|
14
|
-
useSearchParams: () => searchParams,
|
|
15
|
-
useRouter: () => router
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
vi.mock("next/router", () => ({ useRouter: () => null }));
|
|
20
|
-
|
|
21
|
-
vi.mock("next/compat/router", () => ({ useRouter: () => null }));
|
|
22
|
-
|
|
23
|
-
interface RouterTestProps {
|
|
24
|
-
children: React.ReactNode;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function RouterTest({ children }: RouterTestProps) {
|
|
28
|
-
const [pathname, setPathname] = React.useState("/page");
|
|
29
|
-
|
|
30
|
-
const router = React.useMemo<Router>(() => {
|
|
31
|
-
return {
|
|
32
|
-
pathname,
|
|
33
|
-
searchParams: new URLSearchParams(),
|
|
34
|
-
navigate: (path) => setPathname(String(path))
|
|
35
|
-
};
|
|
36
|
-
}, [pathname]);
|
|
37
|
-
|
|
38
|
-
return <AppProvider router={router}>{children}</AppProvider>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
describe("Nextjs AppProvider", () => {
|
|
42
|
-
test("renders content correctly", async () => {
|
|
43
|
-
// placeholder test
|
|
44
|
-
render(<RouterTest>Hello</RouterTest>);
|
|
45
|
-
|
|
46
|
-
expect(screen.getByText("Hello")).toBeTruthy();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useRouter } from "next/compat/router";
|
|
3
|
-
import { AppProviderNextApp } from "./AppProviderNextApp";
|
|
4
|
-
import { AppProviderNextPages } from "./AppProviderNextPages";
|
|
5
|
-
import type { AppProviderProps } from "../AppProvider";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @ignore - internal component.
|
|
9
|
-
*/
|
|
10
|
-
function AppProvider(props: AppProviderProps) {
|
|
11
|
-
const router = useRouter();
|
|
12
|
-
const AppProviderComponent = router
|
|
13
|
-
? AppProviderNextPages
|
|
14
|
-
: AppProviderNextApp;
|
|
15
|
-
return <AppProviderComponent {...props} />;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { AppProvider };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { usePathname, useSearchParams, useRouter } from "next/navigation";
|
|
3
|
-
import type { AppProviderProps, Navigate, Router } from "../AppProvider";
|
|
4
|
-
import { AppProvider } from "../AppProvider/AppProviderComponent";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @ignore - internal component.
|
|
8
|
-
*/
|
|
9
|
-
export function AppProviderNextApp(props: AppProviderProps) {
|
|
10
|
-
const pathname = usePathname();
|
|
11
|
-
const searchParams = useSearchParams();
|
|
12
|
-
const { push, replace } = useRouter();
|
|
13
|
-
|
|
14
|
-
const navigate = React.useCallback<Navigate>(
|
|
15
|
-
(url, { history = "auto" } = {}) => {
|
|
16
|
-
if (history === "auto" || history === "push") {
|
|
17
|
-
return push(String(url));
|
|
18
|
-
}
|
|
19
|
-
if (history === "replace") {
|
|
20
|
-
return replace(String(url));
|
|
21
|
-
}
|
|
22
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
23
|
-
},
|
|
24
|
-
[push, replace]
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const routerImpl = React.useMemo<Router>(
|
|
28
|
-
() => ({
|
|
29
|
-
pathname,
|
|
30
|
-
searchParams,
|
|
31
|
-
navigate
|
|
32
|
-
}),
|
|
33
|
-
[pathname, navigate, searchParams]
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return <AppProvider router={routerImpl} {...props} />;
|
|
37
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useRouter } from "next/router";
|
|
3
|
-
import type { AppProviderProps, Navigate, Router } from "../AppProvider";
|
|
4
|
-
import { asArray } from "../utils/collections";
|
|
5
|
-
import { AppProvider } from "../AppProvider/AppProviderComponent";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @ignore - internal component.
|
|
9
|
-
*/
|
|
10
|
-
export function AppProviderNextPages(props: AppProviderProps) {
|
|
11
|
-
const { push, replace, asPath, query } = useRouter();
|
|
12
|
-
|
|
13
|
-
const search = React.useMemo(() => {
|
|
14
|
-
const params = new URLSearchParams();
|
|
15
|
-
Object.entries(query ?? {}).forEach(([key, value]) => {
|
|
16
|
-
asArray(value ?? []).forEach((v) => {
|
|
17
|
-
params.append(key, v.toString());
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
return params.toString();
|
|
21
|
-
}, [query]);
|
|
22
|
-
|
|
23
|
-
// Stable search params object
|
|
24
|
-
const searchParams = React.useMemo(
|
|
25
|
-
() => new URLSearchParams(search),
|
|
26
|
-
[search]
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const navigate = React.useCallback<Navigate>(
|
|
30
|
-
(url, { history = "auto" } = {}) => {
|
|
31
|
-
if (history === "auto" || history === "push") {
|
|
32
|
-
return push(String(url));
|
|
33
|
-
}
|
|
34
|
-
if (history === "replace") {
|
|
35
|
-
return replace(String(url));
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Invalid history option: ${history}`);
|
|
38
|
-
},
|
|
39
|
-
[push, replace]
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const routerImpl = React.useMemo<Router>(
|
|
43
|
-
() => ({
|
|
44
|
-
pathname: asPath,
|
|
45
|
-
searchParams,
|
|
46
|
-
navigate
|
|
47
|
-
}),
|
|
48
|
-
[asPath, navigate, searchParams]
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return <AppProvider router={routerImpl} {...props} />;
|
|
52
|
-
}
|
package/src/nextjs/index.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./AppProvider";
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This hook allows you to debounce any fast changing value. The debounced value will only
|
|
5
|
-
* reflect the latest value when the useDebounce hook has not been called for the specified
|
|
6
|
-
* time period.
|
|
7
|
-
*
|
|
8
|
-
* Inspired by https://usehooks.com/useDebounce/
|
|
9
|
-
*/
|
|
10
|
-
export default function useDebounced<T>(value: T, delay: number): T {
|
|
11
|
-
const [debouncedValue, setDebouncedValue] = React.useState(() => value);
|
|
12
|
-
const timeoutIdRef = React.useRef<NodeJS.Timeout | null>(null);
|
|
13
|
-
|
|
14
|
-
React.useEffect(
|
|
15
|
-
() => () => {
|
|
16
|
-
if (timeoutIdRef.current) {
|
|
17
|
-
clearTimeout(timeoutIdRef.current);
|
|
18
|
-
timeoutIdRef.current = null;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
[]
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
timeoutIdRef.current = setTimeout(
|
|
26
|
-
() => setDebouncedValue(() => value),
|
|
27
|
-
delay
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return () => {
|
|
31
|
-
if (timeoutIdRef.current) {
|
|
32
|
-
clearTimeout(timeoutIdRef.current);
|
|
33
|
-
timeoutIdRef.current = null;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}, [value, delay]);
|
|
37
|
-
|
|
38
|
-
return debouncedValue;
|
|
39
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
interface Handler<P extends unknown[]> {
|
|
4
|
-
(...params: P): void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface DelayedInvocation<P extends unknown[]> {
|
|
8
|
-
startTime: number;
|
|
9
|
-
timeout: NodeJS.Timeout;
|
|
10
|
-
params: P;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function defer<P extends unknown[]>(
|
|
14
|
-
fn: React.MutableRefObject<Handler<P>>,
|
|
15
|
-
params: P,
|
|
16
|
-
delay: number
|
|
17
|
-
) {
|
|
18
|
-
const timeout = setTimeout(() => {
|
|
19
|
-
fn.current(...params);
|
|
20
|
-
}, delay);
|
|
21
|
-
|
|
22
|
-
return { startTime: Date.now(), timeout, params };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates a debounced version of the handler that is passed. The invocation of [fn] is
|
|
27
|
-
* delayed for [delay] milliseconds from the last invocation of the debounced function.
|
|
28
|
-
*
|
|
29
|
-
* This implementation adds on the lodash implementation in that it handles updates to the
|
|
30
|
-
* delay value.
|
|
31
|
-
*/
|
|
32
|
-
export default function useDebouncedHandler<P extends unknown[]>(
|
|
33
|
-
fn: Handler<P>,
|
|
34
|
-
delay: number
|
|
35
|
-
): Handler<P> {
|
|
36
|
-
const fnRef = React.useRef(fn);
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
fnRef.current = fn;
|
|
39
|
-
}, [fn]);
|
|
40
|
-
|
|
41
|
-
const delayedInvocation = React.useRef<DelayedInvocation<P> | null>(null);
|
|
42
|
-
|
|
43
|
-
const clearCurrent = React.useCallback(() => {
|
|
44
|
-
if (delayedInvocation.current) {
|
|
45
|
-
clearTimeout(delayedInvocation.current.timeout);
|
|
46
|
-
delayedInvocation.current = null;
|
|
47
|
-
}
|
|
48
|
-
}, []);
|
|
49
|
-
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
if (!delayedInvocation.current) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const { startTime, params } = delayedInvocation.current;
|
|
56
|
-
|
|
57
|
-
const elapsed = Date.now() - startTime;
|
|
58
|
-
const newDelay = Math.max(delay - elapsed, 0);
|
|
59
|
-
|
|
60
|
-
clearCurrent();
|
|
61
|
-
delayedInvocation.current = defer(fnRef, params, newDelay);
|
|
62
|
-
}, [delay, clearCurrent]);
|
|
63
|
-
|
|
64
|
-
return React.useCallback(
|
|
65
|
-
(...params: P) => {
|
|
66
|
-
clearCurrent();
|
|
67
|
-
delayedInvocation.current = defer(fnRef, params, delay);
|
|
68
|
-
},
|
|
69
|
-
[delay, clearCurrent]
|
|
70
|
-
);
|
|
71
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the latest non-null, non-undefined value that has been passed to it.
|
|
5
|
-
*/
|
|
6
|
-
function useLatest<T>(value: T): T;
|
|
7
|
-
function useLatest<T>(value: T | null | undefined): T | null | undefined;
|
|
8
|
-
function useLatest<T>(value: T | null | undefined): T | null | undefined {
|
|
9
|
-
const [latest, setLatest] = React.useState<T | null | undefined>(value);
|
|
10
|
-
if (latest !== value && value !== null && value !== undefined) {
|
|
11
|
-
setLatest(value);
|
|
12
|
-
}
|
|
13
|
-
return value ?? latest;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default useLatest;
|