@raystack/apsara 0.53.1 → 0.53.2

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.
@@ -3,10 +3,12 @@
3
3
  var useCopyToClipboard = require('./useCopyToClipboard.cjs');
4
4
  var useMouse = require('./useMouse.cjs');
5
5
  var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect.cjs');
6
+ var useDebouncedState = require('./useDebouncedState.cjs');
6
7
 
7
8
 
8
9
 
9
10
  exports.useCopyToClipboard = useCopyToClipboard.useCopyToClipboard;
10
11
  exports.useMouse = useMouse.useMouse;
11
12
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect.useIsomorphicLayoutEffect;
13
+ exports.useDebouncedState = useDebouncedState.useDebouncedState;
12
14
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,4 +1,5 @@
1
1
  export { useCopyToClipboard } from './useCopyToClipboard';
2
2
  export { useMouse } from './useMouse';
3
3
  export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
4
+ export { useDebouncedState } from './useDebouncedState';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../hooks/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../hooks/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export { useCopyToClipboard } from './useCopyToClipboard.js';
2
2
  export { useMouse } from './useMouse.js';
3
3
  export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
4
+ export { useDebouncedState } from './useDebouncedState.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ /**
6
+ * A hook that debounces the state update.
7
+ * @param defaultValue - The default value of the state.
8
+ * @param delay - The delay time in milliseconds.
9
+ * @param options - The options for the hook.
10
+ * @returns A tuple containing the current value and the debounced set value function.
11
+ *
12
+ * @example
13
+ * const [value, setValue] = useDebouncedState('Hello', 1000);
14
+
15
+ * @example
16
+ * const [value, setValue] = useDebouncedState('Hello', 1000, { leading: true });
17
+ */
18
+ function useDebouncedState(defaultValue, delay, options = { leading: false }) {
19
+ const [value, setValue] = react.useState(defaultValue);
20
+ const timeoutRef = react.useRef(null);
21
+ const leadingRef = react.useRef(true);
22
+ const clearTimeout = react.useCallback(() => window.clearTimeout(timeoutRef.current), []);
23
+ react.useEffect(() => clearTimeout, [clearTimeout]);
24
+ const debouncedSetValue = react.useCallback((newValue) => {
25
+ clearTimeout();
26
+ if (leadingRef.current && options.leading) {
27
+ setValue(newValue);
28
+ }
29
+ else {
30
+ timeoutRef.current = window.setTimeout(() => {
31
+ leadingRef.current = true;
32
+ setValue(newValue);
33
+ }, delay);
34
+ }
35
+ leadingRef.current = false;
36
+ }, [options.leading, clearTimeout, delay]);
37
+ return [value, debouncedSetValue];
38
+ }
39
+
40
+ exports.useDebouncedState = useDebouncedState;
41
+ //# sourceMappingURL=useDebouncedState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedState.cjs","sources":["../../hooks/useDebouncedState.tsx"],"sourcesContent":["import {\n SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nexport interface UseDebouncedStateOptions {\n /**\n * If `true`, the state will be updated immediately on the first call (leading edge).\n * Subsequent calls within the delay period will be debounced.\n * @default false\n */\n leading?: boolean;\n}\n\nexport type UseDebouncedStateReturnValue<T> = [\n T,\n (newValue: SetStateAction<T>) => void\n];\n\n/**\n * A hook that debounces the state update.\n * @param defaultValue - The default value of the state.\n * @param delay - The delay time in milliseconds.\n * @param options - The options for the hook.\n * @returns A tuple containing the current value and the debounced set value function.\n *\n * @example\n * const [value, setValue] = useDebouncedState('Hello', 1000);\n\n * @example\n * const [value, setValue] = useDebouncedState('Hello', 1000, { leading: true });\n */\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n delay: number,\n options: UseDebouncedStateOptions = { leading: false }\n): UseDebouncedStateReturnValue<T> {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = useCallback(\n () => window.clearTimeout(timeoutRef.current!),\n []\n );\n useEffect(() => clearTimeout, [clearTimeout]);\n\n const debouncedSetValue = useCallback(\n (newValue: SetStateAction<T>) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, delay);\n }\n leadingRef.current = false;\n },\n [options.leading, clearTimeout, delay]\n );\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":["useState","useRef","useCallback","useEffect"],"mappings":";;;;AAsBA;;;;;;;;;;;;AAYG;AACa,SAAA,iBAAiB,CAC/B,YAAe,EACf,KAAa,EACb,OAAA,GAAoC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAA;IAEtD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,YAAY,CAAC,CAAC;AACjD,IAAA,MAAM,UAAU,GAAGC,YAAM,CAAgB,IAAI,CAAC,CAAC;AAC/C,IAAA,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AAEhC,IAAA,MAAM,YAAY,GAAGC,iBAAW,CAC9B,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAQ,CAAC,EAC9C,EAAE,CACH,CAAC;IACFC,eAAS,CAAC,MAAM,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AAE9C,IAAA,MAAM,iBAAiB,GAAGD,iBAAW,CACnC,CAAC,QAA2B,KAAI;AAC9B,QAAA,YAAY,EAAE,CAAC;QACf,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;YACzC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SACpB;aAAM;YACL,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AAC1C,gBAAA,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;gBAC1B,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACpB,EAAE,KAAK,CAAC,CAAC;SACX;AACD,QAAA,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;KAC5B,EACD,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CACvC,CAAC;AAEF,IAAA,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAU,CAAC;AAC7C;;;;"}
@@ -0,0 +1,28 @@
1
+ import { SetStateAction } from 'react';
2
+ export interface UseDebouncedStateOptions {
3
+ /**
4
+ * If `true`, the state will be updated immediately on the first call (leading edge).
5
+ * Subsequent calls within the delay period will be debounced.
6
+ * @default false
7
+ */
8
+ leading?: boolean;
9
+ }
10
+ export type UseDebouncedStateReturnValue<T> = [
11
+ T,
12
+ (newValue: SetStateAction<T>) => void
13
+ ];
14
+ /**
15
+ * A hook that debounces the state update.
16
+ * @param defaultValue - The default value of the state.
17
+ * @param delay - The delay time in milliseconds.
18
+ * @param options - The options for the hook.
19
+ * @returns A tuple containing the current value and the debounced set value function.
20
+ *
21
+ * @example
22
+ * const [value, setValue] = useDebouncedState('Hello', 1000);
23
+
24
+ * @example
25
+ * const [value, setValue] = useDebouncedState('Hello', 1000, { leading: true });
26
+ */
27
+ export declare function useDebouncedState<T = any>(defaultValue: T, delay: number, options?: UseDebouncedStateOptions): UseDebouncedStateReturnValue<T>;
28
+ //# sourceMappingURL=useDebouncedState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedState.d.ts","sourceRoot":"","sources":["../../hooks/useDebouncedState.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAKf,MAAM,OAAO,CAAC;AAEf,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,4BAA4B,CAAC,CAAC,IAAI;IAC5C,CAAC;IACD,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI;CACtC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,GAAG,EACvC,YAAY,EAAE,CAAC,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,wBAA6C,GACrD,4BAA4B,CAAC,CAAC,CAAC,CA4BjC"}
@@ -0,0 +1,39 @@
1
+ import { useState, useRef, useCallback, useEffect } from 'react';
2
+
3
+ /**
4
+ * A hook that debounces the state update.
5
+ * @param defaultValue - The default value of the state.
6
+ * @param delay - The delay time in milliseconds.
7
+ * @param options - The options for the hook.
8
+ * @returns A tuple containing the current value and the debounced set value function.
9
+ *
10
+ * @example
11
+ * const [value, setValue] = useDebouncedState('Hello', 1000);
12
+
13
+ * @example
14
+ * const [value, setValue] = useDebouncedState('Hello', 1000, { leading: true });
15
+ */
16
+ function useDebouncedState(defaultValue, delay, options = { leading: false }) {
17
+ const [value, setValue] = useState(defaultValue);
18
+ const timeoutRef = useRef(null);
19
+ const leadingRef = useRef(true);
20
+ const clearTimeout = useCallback(() => window.clearTimeout(timeoutRef.current), []);
21
+ useEffect(() => clearTimeout, [clearTimeout]);
22
+ const debouncedSetValue = useCallback((newValue) => {
23
+ clearTimeout();
24
+ if (leadingRef.current && options.leading) {
25
+ setValue(newValue);
26
+ }
27
+ else {
28
+ timeoutRef.current = window.setTimeout(() => {
29
+ leadingRef.current = true;
30
+ setValue(newValue);
31
+ }, delay);
32
+ }
33
+ leadingRef.current = false;
34
+ }, [options.leading, clearTimeout, delay]);
35
+ return [value, debouncedSetValue];
36
+ }
37
+
38
+ export { useDebouncedState };
39
+ //# sourceMappingURL=useDebouncedState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedState.js","sources":["../../hooks/useDebouncedState.tsx"],"sourcesContent":["import {\n SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nexport interface UseDebouncedStateOptions {\n /**\n * If `true`, the state will be updated immediately on the first call (leading edge).\n * Subsequent calls within the delay period will be debounced.\n * @default false\n */\n leading?: boolean;\n}\n\nexport type UseDebouncedStateReturnValue<T> = [\n T,\n (newValue: SetStateAction<T>) => void\n];\n\n/**\n * A hook that debounces the state update.\n * @param defaultValue - The default value of the state.\n * @param delay - The delay time in milliseconds.\n * @param options - The options for the hook.\n * @returns A tuple containing the current value and the debounced set value function.\n *\n * @example\n * const [value, setValue] = useDebouncedState('Hello', 1000);\n\n * @example\n * const [value, setValue] = useDebouncedState('Hello', 1000, { leading: true });\n */\nexport function useDebouncedState<T = any>(\n defaultValue: T,\n delay: number,\n options: UseDebouncedStateOptions = { leading: false }\n): UseDebouncedStateReturnValue<T> {\n const [value, setValue] = useState(defaultValue);\n const timeoutRef = useRef<number | null>(null);\n const leadingRef = useRef(true);\n\n const clearTimeout = useCallback(\n () => window.clearTimeout(timeoutRef.current!),\n []\n );\n useEffect(() => clearTimeout, [clearTimeout]);\n\n const debouncedSetValue = useCallback(\n (newValue: SetStateAction<T>) => {\n clearTimeout();\n if (leadingRef.current && options.leading) {\n setValue(newValue);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n leadingRef.current = true;\n setValue(newValue);\n }, delay);\n }\n leadingRef.current = false;\n },\n [options.leading, clearTimeout, delay]\n );\n\n return [value, debouncedSetValue] as const;\n}\n"],"names":[],"mappings":";;AAsBA;;;;;;;;;;;;AAYG;AACa,SAAA,iBAAiB,CAC/B,YAAe,EACf,KAAa,EACb,OAAA,GAAoC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAA;IAEtD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACjD,IAAA,MAAM,UAAU,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;AAC/C,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAEhC,IAAA,MAAM,YAAY,GAAG,WAAW,CAC9B,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAQ,CAAC,EAC9C,EAAE,CACH,CAAC;IACF,SAAS,CAAC,MAAM,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AAE9C,IAAA,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,QAA2B,KAAI;AAC9B,QAAA,YAAY,EAAE,CAAC;QACf,IAAI,UAAU,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;YACzC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SACpB;aAAM;YACL,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AAC1C,gBAAA,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;gBAC1B,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACpB,EAAE,KAAK,CAAC,CAAC;SACX;AACD,QAAA,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;KAC5B,EACD,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CACvC,CAAC;AAEF,IAAA,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAU,CAAC;AAC7C;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raystack/apsara",
3
- "version": "0.53.1",
3
+ "version": "0.53.2",
4
4
  "types": "dist/index.d.ts",
5
5
  "sideEffects": false,
6
6
  "engines": {