@etsoo/toolpad 1.0.48 → 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.
Files changed (41) hide show
  1. package/package.json +15 -25
  2. package/build/cjs/nextjs/AppProvider.d.ts +0 -6
  3. package/build/cjs/nextjs/AppProvider.js +0 -18
  4. package/build/cjs/nextjs/AppProvider.test.d.ts +0 -1
  5. package/build/cjs/nextjs/AppProvider.test.js +0 -71
  6. package/build/cjs/nextjs/AppProviderNextApp.d.ts +0 -5
  7. package/build/cjs/nextjs/AppProviderNextApp.js +0 -63
  8. package/build/cjs/nextjs/AppProviderNextPages.d.ts +0 -5
  9. package/build/cjs/nextjs/AppProviderNextPages.js +0 -73
  10. package/build/cjs/nextjs/index.d.ts +0 -1
  11. package/build/cjs/nextjs/index.js +0 -17
  12. package/build/cjs/utils/hooks/useDebounced.d.ts +0 -8
  13. package/build/cjs/utils/hooks/useDebounced.js +0 -64
  14. package/build/cjs/utils/hooks/useDebouncedHandler.d.ts +0 -12
  15. package/build/cjs/utils/hooks/useDebouncedHandler.js +0 -77
  16. package/build/cjs/utils/hooks/useLatest.d.ts +0 -6
  17. package/build/cjs/utils/hooks/useLatest.js +0 -44
  18. package/build/mjs/nextjs/AppProvider.d.ts +0 -6
  19. package/build/mjs/nextjs/AppProvider.js +0 -16
  20. package/build/mjs/nextjs/AppProvider.test.d.ts +0 -1
  21. package/build/mjs/nextjs/AppProvider.test.js +0 -36
  22. package/build/mjs/nextjs/AppProviderNextApp.d.ts +0 -5
  23. package/build/mjs/nextjs/AppProviderNextApp.js +0 -27
  24. package/build/mjs/nextjs/AppProviderNextPages.d.ts +0 -5
  25. package/build/mjs/nextjs/AppProviderNextPages.js +0 -37
  26. package/build/mjs/nextjs/index.d.ts +0 -1
  27. package/build/mjs/nextjs/index.js +0 -1
  28. package/build/mjs/utils/hooks/useDebounced.d.ts +0 -8
  29. package/build/mjs/utils/hooks/useDebounced.js +0 -28
  30. package/build/mjs/utils/hooks/useDebouncedHandler.d.ts +0 -12
  31. package/build/mjs/utils/hooks/useDebouncedHandler.js +0 -41
  32. package/build/mjs/utils/hooks/useLatest.d.ts +0 -6
  33. package/build/mjs/utils/hooks/useLatest.js +0 -9
  34. package/src/nextjs/AppProvider.test.tsx +0 -48
  35. package/src/nextjs/AppProvider.tsx +0 -18
  36. package/src/nextjs/AppProviderNextApp.tsx +0 -37
  37. package/src/nextjs/AppProviderNextPages.tsx +0 -52
  38. package/src/nextjs/index.tsx +0 -1
  39. package/src/utils/hooks/useDebounced.ts +0 -39
  40. package/src/utils/hooks/useDebouncedHandler.ts +0 -71
  41. package/src/utils/hooks/useLatest.ts +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/toolpad",
3
- "version": "1.0.48",
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": "9.0.0",
51
- "@mui/material": "9.0.0",
52
- "@mui/utils": "9.0.0",
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.5",
56
- "react-dom": "^19.2.5"
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.2",
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.6.0",
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.1",
71
- "@vitest/browser": "4.1.4",
72
- "@vitest/browser-playwright": "^4.1.4",
73
- "jsdom": "^29.0.2",
74
- "next": "^16.2.3",
75
- "next-router-mock": "^1.0.5",
76
- "playwright": "^1.59.1",
77
- "react-router-dom": "^7.14.0",
78
- "vitest": "4.1.4"
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
  }
@@ -1,6 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- declare function AppProvider(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
6
- export { AppProvider };
@@ -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,5 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- export declare function AppProviderNextApp(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -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,5 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- export declare function AppProviderNextPages(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -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,6 +0,0 @@
1
- /**
2
- * Returns the latest non-null, non-undefined value that has been passed to it.
3
- */
4
- declare function useLatest<T>(value: T): T;
5
- declare function useLatest<T>(value: T | null | undefined): T | null | undefined;
6
- export default useLatest;
@@ -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,6 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- declare function AppProvider(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
6
- export { AppProvider };
@@ -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,5 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- export declare function AppProviderNextApp(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -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,5 +0,0 @@
1
- import type { AppProviderProps } from "../AppProvider";
2
- /**
3
- * @ignore - internal component.
4
- */
5
- export declare function AppProviderNextPages(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -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,6 +0,0 @@
1
- /**
2
- * Returns the latest non-null, non-undefined value that has been passed to it.
3
- */
4
- declare function useLatest<T>(value: T): T;
5
- declare function useLatest<T>(value: T | null | undefined): T | null | undefined;
6
- export default useLatest;
@@ -1,9 +0,0 @@
1
- import * as React from "react";
2
- function useLatest(value) {
3
- const [latest, setLatest] = React.useState(value);
4
- if (latest !== value && value !== null && value !== undefined) {
5
- setLatest(value);
6
- }
7
- return value ?? latest;
8
- }
9
- export default useLatest;
@@ -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
- }
@@ -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;