@etsoo/toolpad 1.0.48 → 1.0.50
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/Account.d.ts +1 -1
- package/build/cjs/Account/AccountPopoverFooter.d.ts +1 -1
- package/build/cjs/Account/AccountPopoverHeader.d.ts +1 -1
- package/build/cjs/Account/AccountPreview.d.ts +1 -1
- package/build/cjs/Account/SignInButton.d.ts +2 -1
- package/build/cjs/Account/SignOutButton.d.ts +2 -1
- package/build/cjs/AppProvider/AppProviderComponent.d.ts +1 -1
- package/build/cjs/AppProvider/AppThemeProvider.d.ts +1 -1
- package/build/cjs/DashboardLayout/DashboardLayout.d.ts +1 -1
- package/build/cjs/DashboardLayout/DashboardSidebarSubNavigation.d.ts +2 -1
- package/build/cjs/DashboardLayout/ThemeSwitcher.d.ts +2 -1
- package/build/cjs/DashboardLayout/TitleBar.d.ts +1 -1
- package/build/cjs/PageContainer/PageContainer.d.ts +2 -2
- package/build/cjs/PageContainer/PageContainerToolbar.d.ts +1 -1
- package/build/cjs/react-router-dom/AppProvider.d.ts +2 -1
- package/build/cjs/shared/components.d.ts +2 -2
- package/build/cjs/shared/locales/LocaleContext.d.ts +1 -1
- package/build/mjs/Account/Account.d.ts +1 -1
- package/build/mjs/Account/AccountPopoverFooter.d.ts +1 -1
- package/build/mjs/Account/AccountPopoverHeader.d.ts +1 -1
- package/build/mjs/Account/AccountPreview.d.ts +1 -1
- package/build/mjs/Account/SignInButton.d.ts +2 -1
- package/build/mjs/Account/SignOutButton.d.ts +2 -1
- package/build/mjs/AppProvider/AppProviderComponent.d.ts +1 -1
- package/build/mjs/AppProvider/AppThemeProvider.d.ts +1 -1
- package/build/mjs/DashboardLayout/DashboardLayout.d.ts +1 -1
- package/build/mjs/DashboardLayout/DashboardSidebarSubNavigation.d.ts +2 -1
- package/build/mjs/DashboardLayout/ThemeSwitcher.d.ts +2 -1
- package/build/mjs/DashboardLayout/TitleBar.d.ts +1 -1
- package/build/mjs/PageContainer/PageContainer.d.ts +2 -2
- package/build/mjs/PageContainer/PageContainerToolbar.d.ts +1 -1
- package/build/mjs/react-router-dom/AppProvider.d.ts +2 -1
- package/build/mjs/shared/components.d.ts +2 -2
- package/build/mjs/shared/locales/LocaleContext.d.ts +1 -1
- package/package.json +19 -29
- package/vite.config.mts +15 -0
- 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
|
@@ -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 };
|