@neo4j-ndl/react 4.9.35 → 4.9.37

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRenderDebugger = exports.useResizeObserver = exports.useEventListener = exports.useScrollLock = exports.useCopyToClipboard = exports.useMediaQuery = exports.useInterval = exports.useOnClickOutside = exports.useWindowSize = exports.useDebounceCallback = exports.useDebounceValue = void 0;
3
+ exports.useRenderDebugger = exports.useDebounceCallback = exports.useResizeObserver = exports.useEventListener = exports.useScrollLock = exports.useCopyToClipboard = exports.useMediaQuery = exports.useInterval = exports.useOnClickOutside = exports.useWindowSize = exports.useDebounceValue = void 0;
4
4
  exports.usePrevious = usePrevious;
5
5
  exports.useEffectDebugger = useEffectDebugger;
6
6
  exports.useRenderCount = useRenderCount;
@@ -27,7 +27,6 @@ exports.useRenderCount = useRenderCount;
27
27
  const react_1 = require("react");
28
28
  var usehooks_ts_1 = require("usehooks-ts");
29
29
  Object.defineProperty(exports, "useDebounceValue", { enumerable: true, get: function () { return usehooks_ts_1.useDebounceValue; } });
30
- Object.defineProperty(exports, "useDebounceCallback", { enumerable: true, get: function () { return usehooks_ts_1.useDebounceCallback; } });
31
30
  Object.defineProperty(exports, "useWindowSize", { enumerable: true, get: function () { return usehooks_ts_1.useWindowSize; } });
32
31
  Object.defineProperty(exports, "useOnClickOutside", { enumerable: true, get: function () { return usehooks_ts_1.useOnClickOutside; } });
33
32
  Object.defineProperty(exports, "useInterval", { enumerable: true, get: function () { return usehooks_ts_1.useInterval; } });
@@ -36,6 +35,8 @@ Object.defineProperty(exports, "useCopyToClipboard", { enumerable: true, get: fu
36
35
  Object.defineProperty(exports, "useScrollLock", { enumerable: true, get: function () { return usehooks_ts_1.useScrollLock; } });
37
36
  Object.defineProperty(exports, "useEventListener", { enumerable: true, get: function () { return usehooks_ts_1.useEventListener; } });
38
37
  Object.defineProperty(exports, "useResizeObserver", { enumerable: true, get: function () { return usehooks_ts_1.useResizeObserver; } });
38
+ const use_debounce_callback_1 = require("./use-debounce-callback");
39
+ Object.defineProperty(exports, "useDebounceCallback", { enumerable: true, get: function () { return use_debounce_callback_1.useDebounceCallback; } });
39
40
  /**
40
41
  * Below are hooks that cannot be found in `usehooks-ts`
41
42
  * but are used in some projects.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;AA+CA,kCAWC;AAUD,8CAsCC;AAKD,wCAMC;AArHD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iCAA0C;AAE1C,2CAWqB;AAVnB,+GAAA,gBAAgB,OAAA;AAChB,kHAAA,mBAAmB,OAAA;AACnB,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,0GAAA,WAAW,OAAA;AACX,4GAAA,aAAa,OAAA;AACb,iHAAA,kBAAkB,OAAA;AAClB,4GAAA,aAAa,OAAA;AACb,+GAAA,gBAAgB,OAAA;AAChB,gHAAA,iBAAiB,OAAA;AAGnB;;;;;;GAMG;AAEH;;;GAGG;AACH,SAAgB,WAAW,CAAI,KAAQ;IACrC,0EAA0E;IAC1E,qEAAqE;IAErE,MAAM,GAAG,GAAG,IAAA,cAAM,EAAI,IAAI,CAAC,CAAC;IAC5B,6BAA6B;IAC7B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,+BAA+B;IAC5C,mEAAmE;IACnE,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAC/B,UAAgC,EAChC,YAAuB,EACvB,kBAA4B,EAAE;IAE9B,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IAE/C,8DAA8D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mBAAmB,GACvB,EAAE,CAAC;QAEL,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CACpC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAoB,EAAE,EAAE;YACrC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACnC,mBAAmB,CAAC,GAAG,CAAC,GAAG;oBACzB,GAAG,EAAE,QAAQ;oBACb,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CACX,IAAI,aAAa,uBAAuB,EACxC,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA/BW,QAAA,iBAAiB,qBA+B5B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useEffect, useRef } from 'react';\n\nexport {\n useDebounceValue,\n useDebounceCallback,\n useWindowSize,\n useOnClickOutside,\n useInterval,\n useMediaQuery,\n useCopyToClipboard,\n useScrollLock,\n useEventListener,\n useResizeObserver,\n} from 'usehooks-ts';\n\n/**\n * Below are hooks that cannot be found in `usehooks-ts`\n * but are used in some projects.\n * 1. usePrevious\n * 2. useEffectDebugger\n * 3. useRenderCount\n */\n\n/**\n * The `usePrevious` hook tracks a variable's previous value in a functional component,\n * useful for comparing current and past values to trigger actions or render changes.\n */\nexport function usePrevious<T>(value: T): T | null {\n // The ref object is a generic container whose current property is mutable\n // and can hold any value, similar to an instance property on a class\n\n const ref = useRef<T>(null);\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]); // Only re-run if value changes\n // Return previous value (happens before update in useEffect above)\n return ref.current;\n}\n\n/**\n * The `useEffectDebugger` hook is a wrapper around the `useEffect` hook\n * that logs the dependencies of the effect when they change.\n *\n * Uses the `usePrevious` hook.\n *\n * Source: https://stackoverflow.com/a/59843241/3247715\n */\nexport function useEffectDebugger(\n effectHook: React.EffectCallback,\n dependencies: unknown[],\n dependencyNames: string[] = [],\n) {\n const previousDeps = usePrevious(dependencies);\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const changedDeps: any = dependencies.reduce((accum, dependency, index) => {\n if (previousDeps === undefined) {\n return accum;\n }\n if (previousDeps === null) {\n return accum;\n }\n if (dependency !== previousDeps[index]) {\n const keyName = dependencyNames[index] || index;\n return {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...(accum as any),\n [keyName]: {\n after: dependency,\n before: previousDeps[index],\n },\n };\n }\n\n return accum;\n }, {});\n\n if (Object.keys(changedDeps).length) {\n console.info('[use-effect-debugger] ', changedDeps);\n }\n\n useEffect(() => {\n return effectHook();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n\n/**\n * The `useRenderCount` hook returns the number of times a component has rendered.\n */\nexport function useRenderCount() {\n const count = useRef(0);\n\n count.current++;\n\n return count.current;\n}\n\n/**\n * The `useRenderDebugger` outputs to console what props or states are causing a render (or re-render) of a component\n * if all relevant props and states variables are passed to the hook.\n * For debugging purposes only.\n *\n * Howto use:\n * Place the hook at the top of the component you want to debug and call it like this:\n * useRenderDebugger('MyComponent', props);\n *\n * if there are state variables include them as well:\n *\n * useRenderDebugger('MyComponent', { ...props, stateVar1, stateVar2 });\n *\n * @param componentName Name of the component to debug\n * @param propsAndStates an object containing all props and states variables of the component\n */\nexport const useRenderDebugger = (\n componentName: string,\n propsAndStates: Record<string, unknown>,\n) => {\n const prev = useRef(propsAndStates);\n\n useEffect(() => {\n const changedPropsOrState: Record<string, { old: unknown; new: unknown }> =\n {};\n\n Object.entries(propsAndStates).forEach(\n ([key, newValue]: [string, unknown]) => {\n if (prev.current[key] !== newValue) {\n changedPropsOrState[key] = {\n new: newValue,\n old: prev.current[key],\n };\n }\n },\n {},\n );\n\n if (Object.keys(changedPropsOrState).length > 0) {\n console.debug(\n `[${componentName}] Re-rendered due to:`,\n changedPropsOrState,\n );\n }\n\n prev.current = propsAndStates;\n });\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;AAgDA,kCAWC;AAUD,8CAsCC;AAKD,wCAMC;AAtHD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iCAA0C;AAE1C,2CAUqB;AATnB,+GAAA,gBAAgB,OAAA;AAChB,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,0GAAA,WAAW,OAAA;AACX,4GAAA,aAAa,OAAA;AACb,iHAAA,kBAAkB,OAAA;AAClB,4GAAA,aAAa,OAAA;AACb,+GAAA,gBAAgB,OAAA;AAChB,gHAAA,iBAAiB,OAAA;AAEnB,mEAA8D;AACrD,oGADA,2CAAmB,OACA;AAE5B;;;;;;GAMG;AAEH;;;GAGG;AACH,SAAgB,WAAW,CAAI,KAAQ;IACrC,0EAA0E;IAC1E,qEAAqE;IAErE,MAAM,GAAG,GAAG,IAAA,cAAM,EAAI,IAAI,CAAC,CAAC;IAC5B,6BAA6B;IAC7B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,C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;IAExB,KAAK,CAAC,OAAO,EAAE,CAAC;IAEhB,OAAO,KAAK,CAAC,OAAO,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACI,MAAM,iBAAiB,GAAG,CAC/B,aAAqB,EACrB,cAAuC,EACvC,EAAE;IACF,MAAM,IAAI,GAAG,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAEpC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,mBAAmB,GACvB,EAAE,CAAC;QAEL,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CACpC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAoB,EAAE,EAAE;YACrC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACnC,mBAAmB,CAAC,GAAG,CAAC,GAAG;oBACzB,GAAG,EAAE,QAAQ;oBACb,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CACX,IAAI,aAAa,uBAAuB,EACxC,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA/BW,QAAA,iBAAiB,qBA+B5B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useEffect, useRef } from 'react';\n\nexport {\n useDebounceValue,\n useWindowSize,\n useOnClickOutside,\n useInterval,\n useMediaQuery,\n useCopyToClipboard,\n useScrollLock,\n useEventListener,\n useResizeObserver,\n} from 'usehooks-ts';\nimport { useDebounceCallback } from './use-debounce-callback';\nexport { useDebounceCallback };\n\n/**\n * Below are hooks that cannot be found in `usehooks-ts`\n * but are used in some projects.\n * 1. usePrevious\n * 2. useEffectDebugger\n * 3. useRenderCount\n */\n\n/**\n * The `usePrevious` hook tracks a variable's previous value in a functional component,\n * useful for comparing current and past values to trigger actions or render changes.\n */\nexport function usePrevious<T>(value: T): T | null {\n // The ref object is a generic container whose current property is mutable\n // and can hold any value, similar to an instance property on a class\n\n const ref = useRef<T>(null);\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]); // Only re-run if value changes\n // Return previous value (happens before update in useEffect above)\n return ref.current;\n}\n\n/**\n * The `useEffectDebugger` hook is a wrapper around the `useEffect` hook\n * that logs the dependencies of the effect when they change.\n *\n * Uses the `usePrevious` hook.\n *\n * Source: https://stackoverflow.com/a/59843241/3247715\n */\nexport function useEffectDebugger(\n effectHook: React.EffectCallback,\n dependencies: unknown[],\n dependencyNames: string[] = [],\n) {\n const previousDeps = usePrevious(dependencies);\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const changedDeps: any = dependencies.reduce((accum, dependency, index) => {\n if (previousDeps === undefined) {\n return accum;\n }\n if (previousDeps === null) {\n return accum;\n }\n if (dependency !== previousDeps[index]) {\n const keyName = dependencyNames[index] || index;\n return {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...(accum as any),\n [keyName]: {\n after: dependency,\n before: previousDeps[index],\n },\n };\n }\n\n return accum;\n }, {});\n\n if (Object.keys(changedDeps).length) {\n console.info('[use-effect-debugger] ', changedDeps);\n }\n\n useEffect(() => {\n return effectHook();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n\n/**\n * The `useRenderCount` hook returns the number of times a component has rendered.\n */\nexport function useRenderCount() {\n const count = useRef(0);\n\n count.current++;\n\n return count.current;\n}\n\n/**\n * The `useRenderDebugger` outputs to console what props or states are causing a render (or re-render) of a component\n * if all relevant props and states variables are passed to the hook.\n * For debugging purposes only.\n *\n * Howto use:\n * Place the hook at the top of the component you want to debug and call it like this:\n * useRenderDebugger('MyComponent', props);\n *\n * if there are state variables include them as well:\n *\n * useRenderDebugger('MyComponent', { ...props, stateVar1, stateVar2 });\n *\n * @param componentName Name of the component to debug\n * @param propsAndStates an object containing all props and states variables of the component\n */\nexport const useRenderDebugger = (\n componentName: string,\n propsAndStates: Record<string, unknown>,\n) => {\n const prev = useRef(propsAndStates);\n\n useEffect(() => {\n const changedPropsOrState: Record<string, { old: unknown; new: unknown }> =\n {};\n\n Object.entries(propsAndStates).forEach(\n ([key, newValue]: [string, unknown]) => {\n if (prev.current[key] !== newValue) {\n changedPropsOrState[key] = {\n new: newValue,\n old: prev.current[key],\n };\n }\n },\n {},\n );\n\n if (Object.keys(changedPropsOrState).length > 0) {\n console.debug(\n `[${componentName}] Re-rendered due to:`,\n changedPropsOrState,\n );\n }\n\n prev.current = propsAndStates;\n });\n};\n"]}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ /**
3
+ *
4
+ * Copyright (c) "Neo4j"
5
+ * Neo4j Sweden AB [http://neo4j.com]
6
+ *
7
+ * This file is part of Neo4j.
8
+ *
9
+ * Neo4j is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.useDebounceCallback = useDebounceCallback;
24
+ const react_1 = require("react");
25
+ const createDebouncedFunction = (callback, delay, options) => {
26
+ var _a, _b;
27
+ let timeoutId;
28
+ let maxWaitTimeoutId;
29
+ let lastArgs;
30
+ let result;
31
+ const isLeading = (_a = options.leading) !== null && _a !== void 0 ? _a : false;
32
+ const isTrailing = (_b = options.trailing) !== null && _b !== void 0 ? _b : true;
33
+ const maxWait = options.maxWait;
34
+ const clearTimers = () => {
35
+ if (timeoutId !== undefined) {
36
+ clearTimeout(timeoutId);
37
+ timeoutId = undefined;
38
+ }
39
+ if (maxWaitTimeoutId !== undefined) {
40
+ clearTimeout(maxWaitTimeoutId);
41
+ maxWaitTimeoutId = undefined;
42
+ }
43
+ };
44
+ const invoke = () => {
45
+ if (lastArgs === undefined) {
46
+ return result;
47
+ }
48
+ const args = lastArgs;
49
+ lastArgs = undefined;
50
+ result = callback(...args);
51
+ return result;
52
+ };
53
+ const scheduleTrailing = () => {
54
+ if (!isTrailing) {
55
+ if (isLeading) {
56
+ if (timeoutId !== undefined) {
57
+ clearTimeout(timeoutId);
58
+ }
59
+ timeoutId = setTimeout(() => {
60
+ timeoutId = undefined;
61
+ }, delay);
62
+ }
63
+ return;
64
+ }
65
+ if (timeoutId !== undefined) {
66
+ clearTimeout(timeoutId);
67
+ }
68
+ timeoutId = setTimeout(() => {
69
+ timeoutId = undefined;
70
+ if (maxWaitTimeoutId !== undefined) {
71
+ clearTimeout(maxWaitTimeoutId);
72
+ maxWaitTimeoutId = undefined;
73
+ }
74
+ invoke();
75
+ }, delay);
76
+ };
77
+ const scheduleMaxWait = () => {
78
+ if (maxWait === undefined || maxWaitTimeoutId !== undefined) {
79
+ return;
80
+ }
81
+ maxWaitTimeoutId = setTimeout(() => {
82
+ if (timeoutId !== undefined) {
83
+ clearTimeout(timeoutId);
84
+ timeoutId = undefined;
85
+ }
86
+ maxWaitTimeoutId = undefined;
87
+ invoke();
88
+ }, maxWait);
89
+ };
90
+ const debounced = (...args) => {
91
+ const isFirstInvocationInBurst = timeoutId === undefined && maxWaitTimeoutId === undefined;
92
+ lastArgs = args;
93
+ if (isLeading && isFirstInvocationInBurst) {
94
+ result = callback(...args);
95
+ lastArgs = undefined;
96
+ }
97
+ scheduleTrailing();
98
+ scheduleMaxWait();
99
+ return result;
100
+ };
101
+ const cancel = () => {
102
+ clearTimers();
103
+ lastArgs = undefined;
104
+ };
105
+ const flush = () => {
106
+ clearTimers();
107
+ return invoke();
108
+ };
109
+ const isPending = () => timeoutId !== undefined ||
110
+ maxWaitTimeoutId !== undefined ||
111
+ lastArgs !== undefined;
112
+ return { cancel, debounced, flush, isPending };
113
+ };
114
+ /**
115
+ * Local override for usehooks-ts useDebounceCallback.
116
+ *
117
+ * This keeps one debounced function instance across rerenders (unless delay/options change)
118
+ * while always calling the latest callback. It avoids resetting debounce timing when
119
+ * inline callbacks are recreated every render.
120
+ */
121
+ function useDebounceCallback(func, delay = 500, options = {}) {
122
+ var _a, _b;
123
+ const latestCallbackRef = (0, react_1.useRef)(func);
124
+ const debouncedStateRef = (0, react_1.useRef)(undefined);
125
+ const isLeading = (_a = options.leading) !== null && _a !== void 0 ? _a : false;
126
+ const isTrailing = (_b = options.trailing) !== null && _b !== void 0 ? _b : true;
127
+ const maxWait = options.maxWait;
128
+ (0, react_1.useEffect)(() => {
129
+ latestCallbackRef.current = func;
130
+ }, [func]);
131
+ (0, react_1.useEffect)(() => {
132
+ return () => {
133
+ var _a;
134
+ (_a = debouncedStateRef.current) === null || _a === void 0 ? void 0 : _a.cancel();
135
+ };
136
+ }, []);
137
+ const debouncedState = (0, react_1.useMemo)(() => {
138
+ var _a;
139
+ (_a = debouncedStateRef.current) === null || _a === void 0 ? void 0 : _a.cancel();
140
+ const nextDebouncedState = createDebouncedFunction((...args) => latestCallbackRef.current(...args), delay, {
141
+ leading: isLeading,
142
+ maxWait,
143
+ trailing: isTrailing,
144
+ });
145
+ debouncedStateRef.current = nextDebouncedState;
146
+ return nextDebouncedState;
147
+ }, [delay, isLeading, isTrailing, maxWait]);
148
+ return (0, react_1.useMemo)(() => {
149
+ const wrapped = ((...args) => debouncedState.debounced(...args));
150
+ wrapped.cancel = () => {
151
+ debouncedState.cancel();
152
+ };
153
+ wrapped.flush = () => {
154
+ return debouncedState.flush();
155
+ };
156
+ wrapped.isPending = () => {
157
+ return debouncedState.isPending();
158
+ };
159
+ return wrapped;
160
+ }, [debouncedState]);
161
+ }
162
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/hooks/use-debounce-callback/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AA8IH,kDA0DC;AAtMD,iCAAmD;AAkBnD,MAAM,uBAAuB,GAAG,CAC9B,QAAmD,EACnD,KAAa,EACb,OAAwB,EACxB,EAAE;;IACF,IAAI,SAAoD,CAAC;IACzD,IAAI,gBAA2D,CAAC;IAChE,IAAI,QAAmC,CAAC;IACxC,IAAI,MAAiC,CAAC;IAEtC,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,KAAK,CAAC;IAC3C,MAAM,UAAU,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAC;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEhC,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;QACD,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACnC,YAAY,CAAC,gBAAgB,CAAC,CAAC;YAC/B,gBAAgB,GAAG,SAAS,CAA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AC,MAAM,EAAE,CAAC;QAC1B,CAAC,CAAC;QAEF,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;YACnB,OAAO,cAAc,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC,CAAC;QAEF,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE;YACvB,OAAO,cAAc,CAAC,SAAS,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nexport type DebounceOptions = {\n leading?: boolean;\n trailing?: boolean;\n maxWait?: number;\n};\n\ntype GenericFunction = (...args: never[]) => unknown;\n\ntype DebouncedState<T extends GenericFunction> = ((\n ...args: Parameters<T>\n) => ReturnType<T> | undefined) & {\n cancel: () => void;\n flush: () => ReturnType<T> | undefined;\n isPending: () => boolean;\n};\n\nconst createDebouncedFunction = <T extends GenericFunction>(\n callback: (...args: Parameters<T>) => ReturnType<T>,\n delay: number,\n options: DebounceOptions,\n) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let maxWaitTimeoutId: ReturnType<typeof setTimeout> | undefined;\n let lastArgs: Parameters<T> | undefined;\n let result: ReturnType<T> | undefined;\n\n const isLeading = options.leading ?? false;\n const isTrailing = options.trailing ?? true;\n const maxWait = options.maxWait;\n\n const clearTimers = () => {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n if (maxWaitTimeoutId !== undefined) {\n clearTimeout(maxWaitTimeoutId);\n maxWaitTimeoutId = undefined;\n }\n };\n\n const invoke = () => {\n if (lastArgs === undefined) {\n return result;\n }\n const args = lastArgs;\n lastArgs = undefined;\n result = callback(...args);\n return result;\n };\n\n const scheduleTrailing = () => {\n if (!isTrailing) {\n if (isLeading) {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n }\n timeoutId = setTimeout(() => {\n timeoutId = undefined;\n }, delay);\n }\n return;\n }\n\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(() => {\n timeoutId = undefined;\n\n if (maxWaitTimeoutId !== undefined) {\n clearTimeout(maxWaitTimeoutId);\n maxWaitTimeoutId = undefined;\n }\n\n invoke();\n }, delay);\n };\n\n const scheduleMaxWait = () => {\n if (maxWait === undefined || maxWaitTimeoutId !== undefined) {\n return;\n }\n\n maxWaitTimeoutId = setTimeout(() => {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n maxWaitTimeoutId = undefined;\n invoke();\n }, maxWait);\n };\n\n const debounced = (...args: Parameters<T>) => {\n const isFirstInvocationInBurst =\n timeoutId === undefined && maxWaitTimeoutId === undefined;\n\n lastArgs = args;\n\n if (isLeading && isFirstInvocationInBurst) {\n result = callback(...args);\n lastArgs = undefined;\n }\n\n scheduleTrailing();\n scheduleMaxWait();\n\n return result;\n };\n\n const cancel = () => {\n clearTimers();\n lastArgs = undefined;\n };\n\n const flush = () => {\n clearTimers();\n return invoke();\n };\n\n const isPending = () =>\n timeoutId !== undefined ||\n maxWaitTimeoutId !== undefined ||\n lastArgs !== undefined;\n\n return { cancel, debounced, flush, isPending };\n};\n\n/**\n * Local override for usehooks-ts useDebounceCallback.\n *\n * This keeps one debounced function instance across rerenders (unless delay/options change)\n * while always calling the latest callback. It avoids resetting debounce timing when\n * inline callbacks are recreated every render.\n */\nexport function useDebounceCallback<T extends GenericFunction>(\n func: T,\n delay = 500,\n options: DebounceOptions = {},\n): DebouncedState<T> {\n const latestCallbackRef = useRef(func);\n const debouncedStateRef =\n useRef<ReturnType<typeof createDebouncedFunction<T>>>(undefined);\n\n const isLeading = options.leading ?? false;\n const isTrailing = options.trailing ?? true;\n const maxWait = options.maxWait;\n\n useEffect(() => {\n latestCallbackRef.current = func;\n }, [func]);\n\n useEffect(() => {\n return () => {\n debouncedStateRef.current?.cancel();\n };\n }, []);\n\n const debouncedState = useMemo(() => {\n debouncedStateRef.current?.cancel();\n\n const nextDebouncedState = createDebouncedFunction<T>(\n (...args) => latestCallbackRef.current(...args) as ReturnType<T>,\n delay,\n {\n leading: isLeading,\n maxWait,\n trailing: isTrailing,\n },\n );\n\n debouncedStateRef.current = nextDebouncedState;\n return nextDebouncedState;\n }, [delay, isLeading, isTrailing, maxWait]);\n\n return useMemo(() => {\n const wrapped = ((...args: Parameters<T>) =>\n debouncedState.debounced(...args)) as DebouncedState<T>;\n\n wrapped.cancel = () => {\n debouncedState.cancel();\n };\n\n wrapped.flush = () => {\n return debouncedState.flush();\n };\n\n wrapped.isPending = () => {\n return debouncedState.isPending();\n };\n\n return wrapped;\n }, [debouncedState]);\n}\n"]}
@@ -19,7 +19,9 @@
19
19
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  */
21
21
  import { useEffect, useRef } from 'react';
22
- export { useDebounceValue, useDebounceCallback, useWindowSize, useOnClickOutside, useInterval, useMediaQuery, useCopyToClipboard, useScrollLock, useEventListener, useResizeObserver, } from 'usehooks-ts';
22
+ export { useDebounceValue, useWindowSize, useOnClickOutside, useInterval, useMediaQuery, useCopyToClipboard, useScrollLock, useEventListener, useResizeObserver, } from 'usehooks-ts';
23
+ import { useDebounceCallback } from './use-debounce-callback';
24
+ export { useDebounceCallback };
23
25
  /**
24
26
  * Below are hooks that cannot be found in `usehooks-ts`
25
27
  * but are used in some projects.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,0EAA0E;IAC1E,qEAAqE;IAErE,MAAM,GAAG,GAAG,MAAM,CAAI,IAAI,CAAC,CAAC;IAC5B,6BAA6B;IAC7B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,+BAA+B;IAC5C,mEAAmE;IACnE,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAgC,EAChC,YAAuB,EACvB,kBAA4B,EAAE;IAE9B,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IAE/C,8DAA8D;IAC9D,MAAM,WAAW,GAAQ,YAAY,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACxE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,UAAU,KAAK,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YACvC,MAAM,OAAO,GAAG,eAAe,C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;QACH,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CACX,IAAI,aAAa,uBAAuB,EACxC,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useEffect, useRef } from 'react';\n\nexport {\n useDebounceValue,\n useDebounceCallback,\n useWindowSize,\n useOnClickOutside,\n useInterval,\n useMediaQuery,\n useCopyToClipboard,\n useScrollLock,\n useEventListener,\n useResizeObserver,\n} from 'usehooks-ts';\n\n/**\n * Below are hooks that cannot be found in `usehooks-ts`\n * but are used in some projects.\n * 1. usePrevious\n * 2. useEffectDebugger\n * 3. useRenderCount\n */\n\n/**\n * The `usePrevious` hook tracks a variable's previous value in a functional component,\n * useful for comparing current and past values to trigger actions or render changes.\n */\nexport function usePrevious<T>(value: T): T | null {\n // The ref object is a generic container whose current property is mutable\n // and can hold any value, similar to an instance property on a class\n\n const ref = useRef<T>(null);\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]); // Only re-run if value changes\n // Return previous value (happens before update in useEffect above)\n return ref.current;\n}\n\n/**\n * The `useEffectDebugger` hook is a wrapper around the `useEffect` hook\n * that logs the dependencies of the effect when they change.\n *\n * Uses the `usePrevious` hook.\n *\n * Source: https://stackoverflow.com/a/59843241/3247715\n */\nexport function useEffectDebugger(\n effectHook: React.EffectCallback,\n dependencies: unknown[],\n dependencyNames: string[] = [],\n) {\n const previousDeps = usePrevious(dependencies);\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const changedDeps: any = dependencies.reduce((accum, dependency, index) => {\n if (previousDeps === undefined) {\n return accum;\n }\n if (previousDeps === null) {\n return accum;\n }\n if (dependency !== previousDeps[index]) {\n const keyName = dependencyNames[index] || index;\n return {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...(accum as any),\n [keyName]: {\n after: dependency,\n before: previousDeps[index],\n },\n };\n }\n\n return accum;\n }, {});\n\n if (Object.keys(changedDeps).length) {\n console.info('[use-effect-debugger] ', changedDeps);\n }\n\n useEffect(() => {\n return effectHook();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n\n/**\n * The `useRenderCount` hook returns the number of times a component has rendered.\n */\nexport function useRenderCount() {\n const count = useRef(0);\n\n count.current++;\n\n return count.current;\n}\n\n/**\n * The `useRenderDebugger` outputs to console what props or states are causing a render (or re-render) of a component\n * if all relevant props and states variables are passed to the hook.\n * For debugging purposes only.\n *\n * Howto use:\n * Place the hook at the top of the component you want to debug and call it like this:\n * useRenderDebugger('MyComponent', props);\n *\n * if there are state variables include them as well:\n *\n * useRenderDebugger('MyComponent', { ...props, stateVar1, stateVar2 });\n *\n * @param componentName Name of the component to debug\n * @param propsAndStates an object containing all props and states variables of the component\n */\nexport const useRenderDebugger = (\n componentName: string,\n propsAndStates: Record<string, unknown>,\n) => {\n const prev = useRef(propsAndStates);\n\n useEffect(() => {\n const changedPropsOrState: Record<string, { old: unknown; new: unknown }> =\n {};\n\n Object.entries(propsAndStates).forEach(\n ([key, newValue]: [string, unknown]) => {\n if (prev.current[key] !== newValue) {\n changedPropsOrState[key] = {\n new: newValue,\n old: prev.current[key],\n };\n }\n },\n {},\n );\n\n if (Object.keys(changedPropsOrState).length > 0) {\n console.debug(\n `[${componentName}] Re-rendered due to:`,\n changedPropsOrState,\n );\n }\n\n prev.current = propsAndStates;\n });\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,0EAA0E;IAC1E,qEAAqE;IAErE,MAAM,GAAG,GAAG,MAAM,CAAI,IAAI,CAAC,CAAC;IAC5B,6BAA6B;IAC7B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,+BAA+B;IAC5C,mEAAmE;IACnE,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAgC,EAChC,YAAuB,EACvB,kBAA4B,EAAE;IAE9B,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IAE/C,8DAA8D;IAC9D,MAAM,WAAW,GAAQ,YAAY,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACxE,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,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C,OAAO,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBACnC,mBAAmB,CAAC,GAAG,CAAC,GAAG;oBACzB,GAAG,EAAE,QAAQ;oBACb,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;iBACvB,CAAC;YACJ,CAAC;QACH,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CACX,IAAI,aAAa,uBAAuB,EACxC,mBAAmB,CACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport { useEffect, useRef } from 'react';\n\nexport {\n useDebounceValue,\n useWindowSize,\n useOnClickOutside,\n useInterval,\n useMediaQuery,\n useCopyToClipboard,\n useScrollLock,\n useEventListener,\n useResizeObserver,\n} from 'usehooks-ts';\nimport { useDebounceCallback } from './use-debounce-callback';\nexport { useDebounceCallback };\n\n/**\n * Below are hooks that cannot be found in `usehooks-ts`\n * but are used in some projects.\n * 1. usePrevious\n * 2. useEffectDebugger\n * 3. useRenderCount\n */\n\n/**\n * The `usePrevious` hook tracks a variable's previous value in a functional component,\n * useful for comparing current and past values to trigger actions or render changes.\n */\nexport function usePrevious<T>(value: T): T | null {\n // The ref object is a generic container whose current property is mutable\n // and can hold any value, similar to an instance property on a class\n\n const ref = useRef<T>(null);\n // Store current value in ref\n useEffect(() => {\n ref.current = value;\n }, [value]); // Only re-run if value changes\n // Return previous value (happens before update in useEffect above)\n return ref.current;\n}\n\n/**\n * The `useEffectDebugger` hook is a wrapper around the `useEffect` hook\n * that logs the dependencies of the effect when they change.\n *\n * Uses the `usePrevious` hook.\n *\n * Source: https://stackoverflow.com/a/59843241/3247715\n */\nexport function useEffectDebugger(\n effectHook: React.EffectCallback,\n dependencies: unknown[],\n dependencyNames: string[] = [],\n) {\n const previousDeps = usePrevious(dependencies);\n\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n const changedDeps: any = dependencies.reduce((accum, dependency, index) => {\n if (previousDeps === undefined) {\n return accum;\n }\n if (previousDeps === null) {\n return accum;\n }\n if (dependency !== previousDeps[index]) {\n const keyName = dependencyNames[index] || index;\n return {\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n ...(accum as any),\n [keyName]: {\n after: dependency,\n before: previousDeps[index],\n },\n };\n }\n\n return accum;\n }, {});\n\n if (Object.keys(changedDeps).length) {\n console.info('[use-effect-debugger] ', changedDeps);\n }\n\n useEffect(() => {\n return effectHook();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n\n/**\n * The `useRenderCount` hook returns the number of times a component has rendered.\n */\nexport function useRenderCount() {\n const count = useRef(0);\n\n count.current++;\n\n return count.current;\n}\n\n/**\n * The `useRenderDebugger` outputs to console what props or states are causing a render (or re-render) of a component\n * if all relevant props and states variables are passed to the hook.\n * For debugging purposes only.\n *\n * Howto use:\n * Place the hook at the top of the component you want to debug and call it like this:\n * useRenderDebugger('MyComponent', props);\n *\n * if there are state variables include them as well:\n *\n * useRenderDebugger('MyComponent', { ...props, stateVar1, stateVar2 });\n *\n * @param componentName Name of the component to debug\n * @param propsAndStates an object containing all props and states variables of the component\n */\nexport const useRenderDebugger = (\n componentName: string,\n propsAndStates: Record<string, unknown>,\n) => {\n const prev = useRef(propsAndStates);\n\n useEffect(() => {\n const changedPropsOrState: Record<string, { old: unknown; new: unknown }> =\n {};\n\n Object.entries(propsAndStates).forEach(\n ([key, newValue]: [string, unknown]) => {\n if (prev.current[key] !== newValue) {\n changedPropsOrState[key] = {\n new: newValue,\n old: prev.current[key],\n };\n }\n },\n {},\n );\n\n if (Object.keys(changedPropsOrState).length > 0) {\n console.debug(\n `[${componentName}] Re-rendered due to:`,\n changedPropsOrState,\n );\n }\n\n prev.current = propsAndStates;\n });\n};\n"]}
@@ -0,0 +1,159 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ import { useEffect, useMemo, useRef } from 'react';
22
+ const createDebouncedFunction = (callback, delay, options) => {
23
+ var _a, _b;
24
+ let timeoutId;
25
+ let maxWaitTimeoutId;
26
+ let lastArgs;
27
+ let result;
28
+ const isLeading = (_a = options.leading) !== null && _a !== void 0 ? _a : false;
29
+ const isTrailing = (_b = options.trailing) !== null && _b !== void 0 ? _b : true;
30
+ const maxWait = options.maxWait;
31
+ const clearTimers = () => {
32
+ if (timeoutId !== undefined) {
33
+ clearTimeout(timeoutId);
34
+ timeoutId = undefined;
35
+ }
36
+ if (maxWaitTimeoutId !== undefined) {
37
+ clearTimeout(maxWaitTimeoutId);
38
+ maxWaitTimeoutId = undefined;
39
+ }
40
+ };
41
+ const invoke = () => {
42
+ if (lastArgs === undefined) {
43
+ return result;
44
+ }
45
+ const args = lastArgs;
46
+ lastArgs = undefined;
47
+ result = callback(...args);
48
+ return result;
49
+ };
50
+ const scheduleTrailing = () => {
51
+ if (!isTrailing) {
52
+ if (isLeading) {
53
+ if (timeoutId !== undefined) {
54
+ clearTimeout(timeoutId);
55
+ }
56
+ timeoutId = setTimeout(() => {
57
+ timeoutId = undefined;
58
+ }, delay);
59
+ }
60
+ return;
61
+ }
62
+ if (timeoutId !== undefined) {
63
+ clearTimeout(timeoutId);
64
+ }
65
+ timeoutId = setTimeout(() => {
66
+ timeoutId = undefined;
67
+ if (maxWaitTimeoutId !== undefined) {
68
+ clearTimeout(maxWaitTimeoutId);
69
+ maxWaitTimeoutId = undefined;
70
+ }
71
+ invoke();
72
+ }, delay);
73
+ };
74
+ const scheduleMaxWait = () => {
75
+ if (maxWait === undefined || maxWaitTimeoutId !== undefined) {
76
+ return;
77
+ }
78
+ maxWaitTimeoutId = setTimeout(() => {
79
+ if (timeoutId !== undefined) {
80
+ clearTimeout(timeoutId);
81
+ timeoutId = undefined;
82
+ }
83
+ maxWaitTimeoutId = undefined;
84
+ invoke();
85
+ }, maxWait);
86
+ };
87
+ const debounced = (...args) => {
88
+ const isFirstInvocationInBurst = timeoutId === undefined && maxWaitTimeoutId === undefined;
89
+ lastArgs = args;
90
+ if (isLeading && isFirstInvocationInBurst) {
91
+ result = callback(...args);
92
+ lastArgs = undefined;
93
+ }
94
+ scheduleTrailing();
95
+ scheduleMaxWait();
96
+ return result;
97
+ };
98
+ const cancel = () => {
99
+ clearTimers();
100
+ lastArgs = undefined;
101
+ };
102
+ const flush = () => {
103
+ clearTimers();
104
+ return invoke();
105
+ };
106
+ const isPending = () => timeoutId !== undefined ||
107
+ maxWaitTimeoutId !== undefined ||
108
+ lastArgs !== undefined;
109
+ return { cancel, debounced, flush, isPending };
110
+ };
111
+ /**
112
+ * Local override for usehooks-ts useDebounceCallback.
113
+ *
114
+ * This keeps one debounced function instance across rerenders (unless delay/options change)
115
+ * while always calling the latest callback. It avoids resetting debounce timing when
116
+ * inline callbacks are recreated every render.
117
+ */
118
+ export function useDebounceCallback(func, delay = 500, options = {}) {
119
+ var _a, _b;
120
+ const latestCallbackRef = useRef(func);
121
+ const debouncedStateRef = useRef(undefined);
122
+ const isLeading = (_a = options.leading) !== null && _a !== void 0 ? _a : false;
123
+ const isTrailing = (_b = options.trailing) !== null && _b !== void 0 ? _b : true;
124
+ const maxWait = options.maxWait;
125
+ useEffect(() => {
126
+ latestCallbackRef.current = func;
127
+ }, [func]);
128
+ useEffect(() => {
129
+ return () => {
130
+ var _a;
131
+ (_a = debouncedStateRef.current) === null || _a === void 0 ? void 0 : _a.cancel();
132
+ };
133
+ }, []);
134
+ const debouncedState = useMemo(() => {
135
+ var _a;
136
+ (_a = debouncedStateRef.current) === null || _a === void 0 ? void 0 : _a.cancel();
137
+ const nextDebouncedState = createDebouncedFunction((...args) => latestCallbackRef.current(...args), delay, {
138
+ leading: isLeading,
139
+ maxWait,
140
+ trailing: isTrailing,
141
+ });
142
+ debouncedStateRef.current = nextDebouncedState;
143
+ return nextDebouncedState;
144
+ }, [delay, isLeading, isTrailing, maxWait]);
145
+ return useMemo(() => {
146
+ const wrapped = ((...args) => debouncedState.debounced(...args));
147
+ wrapped.cancel = () => {
148
+ debouncedState.cancel();
149
+ };
150
+ wrapped.flush = () => {
151
+ return debouncedState.flush();
152
+ };
153
+ wrapped.isPending = () => {
154
+ return debouncedState.isPending();
155
+ };
156
+ return wrapped;
157
+ }, [debouncedState]);
158
+ }
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/hooks/use-debounce-callback/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAA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BAAiB,CAAC,OAAO,0CAAE,MAAM,EAAE,CAAC;QAEpC,MAAM,kBAAkB,GAAG,uBAAuB,CAChD,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAkB,EAChE,KAAK,EACL;YACE,OAAO,EAAE,SAAS;YAClB,OAAO;YACP,QAAQ,EAAE,UAAU;SACrB,CACF,CAAC;QAEF,iBAAiB,CAAC,OAAO,GAAG,kBAAkB,CAAC;QAC/C,OAAO,kBAAkB,CAAC;IAC5B,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,IAAmB,EAAE,EAAE,CAC1C,cAAc,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAsB,CAAC;QAE1D,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE;YACpB,cAAc,CAAC,MAAM,EAAE,CAAC;QAC1B,CAAC,CAAC;QAEF,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE;YACnB,OAAO,cAAc,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC,CAAC;QAEF,OAAO,CAAC,SAAS,GAAG,GAAG,EAAE;YACvB,OAAO,cAAc,CAAC,SAAS,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { useEffect, useMemo, useRef } from 'react';\n\nexport type DebounceOptions = {\n leading?: boolean;\n trailing?: boolean;\n maxWait?: number;\n};\n\ntype GenericFunction = (...args: never[]) => unknown;\n\ntype DebouncedState<T extends GenericFunction> = ((\n ...args: Parameters<T>\n) => ReturnType<T> | undefined) & {\n cancel: () => void;\n flush: () => ReturnType<T> | undefined;\n isPending: () => boolean;\n};\n\nconst createDebouncedFunction = <T extends GenericFunction>(\n callback: (...args: Parameters<T>) => ReturnType<T>,\n delay: number,\n options: DebounceOptions,\n) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let maxWaitTimeoutId: ReturnType<typeof setTimeout> | undefined;\n let lastArgs: Parameters<T> | undefined;\n let result: ReturnType<T> | undefined;\n\n const isLeading = options.leading ?? false;\n const isTrailing = options.trailing ?? true;\n const maxWait = options.maxWait;\n\n const clearTimers = () => {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n if (maxWaitTimeoutId !== undefined) {\n clearTimeout(maxWaitTimeoutId);\n maxWaitTimeoutId = undefined;\n }\n };\n\n const invoke = () => {\n if (lastArgs === undefined) {\n return result;\n }\n const args = lastArgs;\n lastArgs = undefined;\n result = callback(...args);\n return result;\n };\n\n const scheduleTrailing = () => {\n if (!isTrailing) {\n if (isLeading) {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n }\n timeoutId = setTimeout(() => {\n timeoutId = undefined;\n }, delay);\n }\n return;\n }\n\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n }\n\n timeoutId = setTimeout(() => {\n timeoutId = undefined;\n\n if (maxWaitTimeoutId !== undefined) {\n clearTimeout(maxWaitTimeoutId);\n maxWaitTimeoutId = undefined;\n }\n\n invoke();\n }, delay);\n };\n\n const scheduleMaxWait = () => {\n if (maxWait === undefined || maxWaitTimeoutId !== undefined) {\n return;\n }\n\n maxWaitTimeoutId = setTimeout(() => {\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n maxWaitTimeoutId = undefined;\n invoke();\n }, maxWait);\n };\n\n const debounced = (...args: Parameters<T>) => {\n const isFirstInvocationInBurst =\n timeoutId === undefined && maxWaitTimeoutId === undefined;\n\n lastArgs = args;\n\n if (isLeading && isFirstInvocationInBurst) {\n result = callback(...args);\n lastArgs = undefined;\n }\n\n scheduleTrailing();\n scheduleMaxWait();\n\n return result;\n };\n\n const cancel = () => {\n clearTimers();\n lastArgs = undefined;\n };\n\n const flush = () => {\n clearTimers();\n return invoke();\n };\n\n const isPending = () =>\n timeoutId !== undefined ||\n maxWaitTimeoutId !== undefined ||\n lastArgs !== undefined;\n\n return { cancel, debounced, flush, isPending };\n};\n\n/**\n * Local override for usehooks-ts useDebounceCallback.\n *\n * This keeps one debounced function instance across rerenders (unless delay/options change)\n * while always calling the latest callback. It avoids resetting debounce timing when\n * inline callbacks are recreated every render.\n */\nexport function useDebounceCallback<T extends GenericFunction>(\n func: T,\n delay = 500,\n options: DebounceOptions = {},\n): DebouncedState<T> {\n const latestCallbackRef = useRef(func);\n const debouncedStateRef =\n useRef<ReturnType<typeof createDebouncedFunction<T>>>(undefined);\n\n const isLeading = options.leading ?? false;\n const isTrailing = options.trailing ?? true;\n const maxWait = options.maxWait;\n\n useEffect(() => {\n latestCallbackRef.current = func;\n }, [func]);\n\n useEffect(() => {\n return () => {\n debouncedStateRef.current?.cancel();\n };\n }, []);\n\n const debouncedState = useMemo(() => {\n debouncedStateRef.current?.cancel();\n\n const nextDebouncedState = createDebouncedFunction<T>(\n (...args) => latestCallbackRef.current(...args) as ReturnType<T>,\n delay,\n {\n leading: isLeading,\n maxWait,\n trailing: isTrailing,\n },\n );\n\n debouncedStateRef.current = nextDebouncedState;\n return nextDebouncedState;\n }, [delay, isLeading, isTrailing, maxWait]);\n\n return useMemo(() => {\n const wrapped = ((...args: Parameters<T>) =>\n debouncedState.debounced(...args)) as DebouncedState<T>;\n\n wrapped.cancel = () => {\n debouncedState.cancel();\n };\n\n wrapped.flush = () => {\n return debouncedState.flush();\n };\n\n wrapped.isPending = () => {\n return debouncedState.isPending();\n };\n\n return wrapped;\n }, [debouncedState]);\n}\n"]}
@@ -19,7 +19,9 @@
19
19
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
  */
21
21
 
22
- export { useDebounceValue, useDebounceCallback, useWindowSize, useOnClickOutside, useInterval, useMediaQuery, useCopyToClipboard, useScrollLock, useEventListener, useResizeObserver, } from 'usehooks-ts';
22
+ export { useDebounceValue, useWindowSize, useOnClickOutside, useInterval, useMediaQuery, useCopyToClipboard, useScrollLock, useEventListener, useResizeObserver, } from 'usehooks-ts';
23
+ import { useDebounceCallback } from './use-debounce-callback';
24
+ export { useDebounceCallback };
23
25
  /**
24
26
  * Below are hooks that cannot be found in `usehooks-ts`
25
27
  * but are used in some projects.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAWjD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,KAAK,CAAC,cAAc,EAChC,YAAY,EAAE,OAAO,EAAE,EACvB,eAAe,GAAE,MAAM,EAAO,QAmC/B;AAED;;GAEG;AACH,wBAAgB,cAAc,WAM7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAC5B,eAAe,MAAM,EACrB,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SA6BxC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAE/B;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAWjD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,KAAK,CAAC,cAAc,EAChC,YAAY,EAAE,OAAO,EAAE,EACvB,eAAe,GAAE,MAAM,EAAO,QAmC/B;AAED;;GAEG;AACH,wBAAgB,cAAc,WAM7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAC5B,eAAe,MAAM,EACrB,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SA6BxC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ *
3
+ * Copyright (c) "Neo4j"
4
+ * Neo4j Sweden AB [http://neo4j.com]
5
+ *
6
+ * This file is part of Neo4j.
7
+ *
8
+ * Neo4j is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+ export type DebounceOptions = {
22
+ leading?: boolean;
23
+ trailing?: boolean;
24
+ maxWait?: number;
25
+ };
26
+ type GenericFunction = (...args: never[]) => unknown;
27
+ type DebouncedState<T extends GenericFunction> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & {
28
+ cancel: () => void;
29
+ flush: () => ReturnType<T> | undefined;
30
+ isPending: () => boolean;
31
+ };
32
+ /**
33
+ * Local override for usehooks-ts useDebounceCallback.
34
+ *
35
+ * This keeps one debounced function instance across rerenders (unless delay/options change)
36
+ * while always calling the latest callback. It avoids resetting debounce timing when
37
+ * inline callbacks are recreated every render.
38
+ */
39
+ export declare function useDebounceCallback<T extends GenericFunction>(func: T, delay?: number, options?: DebounceOptions): DebouncedState<T>;
40
+ export {};
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-debounce-callback/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAErD,KAAK,cAAc,CAAC,CAAC,SAAS,eAAe,IAAI,CAAC,CAChD,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KACnB,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACvC,SAAS,EAAE,MAAM,OAAO,CAAC;CAC1B,CAAC;AAqHF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,eAAe,EAC3D,IAAI,EAAE,CAAC,EACP,KAAK,SAAM,EACX,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,CAAC,CAAC,CAsDnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-ndl/react",
3
- "version": "4.9.35",
3
+ "version": "4.9.37",
4
4
  "sideEffects": false,
5
5
  "description": "React implementation of Neo4j Design System",
6
6
  "keywords": [
@@ -87,7 +87,7 @@
87
87
  "@tanstack/react-table": "8.21.3",
88
88
  "react": ">=19.0.0",
89
89
  "react-dom": ">=19.0.0",
90
- "@neo4j-ndl/base": "^4.9.17"
90
+ "@neo4j-ndl/base": "^4.9.18"
91
91
  },
92
92
  "dependencies": {
93
93
  "@dnd-kit/core": "6.3.1",