@mantine/hooks 9.5.1 → 9.5.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.
@@ -8,9 +8,12 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
8
8
  const cooldownRef = (0, react.useRef)(false);
9
9
  const latestValueRef = (0, react.useRef)(value);
10
10
  latestValueRef.current = value;
11
- const cancel = (0, react.useCallback)(() => {
11
+ const clearTimer = (0, react.useCallback)(() => {
12
12
  window.clearTimeout(timeoutRef.current);
13
13
  timeoutRef.current = null;
14
+ }, []);
15
+ const cancel = (0, react.useCallback)(() => {
16
+ clearTimer();
14
17
  cooldownRef.current = false;
15
18
  }, []);
16
19
  const flush = (0, react.useCallback)(() => {
@@ -21,15 +24,15 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
21
24
  }
22
25
  }, []);
23
26
  (0, react.useEffect)(() => {
24
- if (mountedRef.current) if (!cooldownRef.current && options.leading) {
25
- cooldownRef.current = true;
26
- setValue(value);
27
- timeoutRef.current = window.setTimeout(() => {
28
- cooldownRef.current = false;
29
- }, wait);
30
- } else {
31
- cancel();
32
- timeoutRef.current = window.setTimeout(() => {
27
+ if (mountedRef.current) {
28
+ clearTimer();
29
+ if (!cooldownRef.current && options.leading) {
30
+ cooldownRef.current = true;
31
+ setValue(value);
32
+ timeoutRef.current = window.setTimeout(() => {
33
+ cooldownRef.current = false;
34
+ }, wait);
35
+ } else timeoutRef.current = window.setTimeout(() => {
33
36
  cooldownRef.current = false;
34
37
  setValue(value);
35
38
  }, wait);
@@ -1 +1 @@
1
- {"version":3,"file":"use-debounced-value.cjs","names":[],"sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface UseDebouncedValueOptions {\n leading?: boolean;\n}\n\nexport interface UseDebouncedValueHandlers {\n cancel: () => void;\n flush: () => void;\n}\n\nexport type UseDebouncedValueReturnValue<T> = [T, () => void, UseDebouncedValueHandlers];\n\nexport function useDebouncedValue<T = any>(\n value: T,\n wait: number,\n options: UseDebouncedValueOptions = { leading: false }\n): UseDebouncedValueReturnValue<T> {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const latestValueRef = useRef(value);\n latestValueRef.current = value;\n\n const cancel = useCallback(() => {\n window.clearTimeout(timeoutRef.current!);\n timeoutRef.current = null;\n cooldownRef.current = false;\n }, []);\n\n const flush = useCallback(() => {\n if (timeoutRef.current) {\n cancel();\n cooldownRef.current = false;\n setValue(latestValueRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n }, wait);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel, { cancel, flush }];\n}\n\nexport namespace useDebouncedValue {\n export type Handlers = UseDebouncedValueHandlers;\n export type Options = UseDebouncedValueOptions;\n export type ReturnValue<T> = UseDebouncedValueReturnValue<T>;\n}\n"],"mappings":";;;AAaA,SAAgB,kBACd,OACA,MACA,UAAoC,EAAE,SAAS,MAAM,GACpB;CACjC,MAAM,CAAC,QAAQ,aAAA,GAAA,MAAA,SAAA,CAAqB,KAAK;CACzC,MAAM,cAAA,GAAA,MAAA,OAAA,CAAoB,KAAK;CAC/B,MAAM,cAAA,GAAA,MAAA,OAAA,CAAmC,IAAI;CAC7C,MAAM,eAAA,GAAA,MAAA,OAAA,CAAqB,KAAK;CAEhC,MAAM,kBAAA,GAAA,MAAA,OAAA,CAAwB,KAAK;CACnC,eAAe,UAAU;CAEzB,MAAM,UAAA,GAAA,MAAA,YAAA,OAA2B;EAC/B,OAAO,aAAa,WAAW,OAAQ;EACvC,WAAW,UAAU;EACrB,YAAY,UAAU;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,SAAA,GAAA,MAAA,YAAA,OAA0B;EAC9B,IAAI,WAAW,SAAS;GACtB,OAAO;GACP,YAAY,UAAU;GACtB,SAAS,eAAe,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CAEL,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,WAAW,SACb,IAAI,CAAC,YAAY,WAAW,QAAQ,SAAS;GAC3C,YAAY,UAAU;GACtB,SAAS,KAAK;GACd,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;GACxB,GAAG,IAAI;EACT,OAAO;GACL,OAAO;GACP,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;GAChB,GAAG,IAAI;EACT;CAEJ,GAAG;EAAC;EAAO,QAAQ;EAAS;CAAI,CAAC;CAEjC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,WAAW,UAAU;EACrB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,OAAO;EAAC;EAAQ;EAAQ;GAAE;GAAQ;EAAM;CAAC;AAC3C"}
1
+ {"version":3,"file":"use-debounced-value.cjs","names":[],"sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface UseDebouncedValueOptions {\n leading?: boolean;\n}\n\nexport interface UseDebouncedValueHandlers {\n cancel: () => void;\n flush: () => void;\n}\n\nexport type UseDebouncedValueReturnValue<T> = [T, () => void, UseDebouncedValueHandlers];\n\nexport function useDebouncedValue<T = any>(\n value: T,\n wait: number,\n options: UseDebouncedValueOptions = { leading: false }\n): UseDebouncedValueReturnValue<T> {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const latestValueRef = useRef(value);\n latestValueRef.current = value;\n\n const clearTimer = useCallback(() => {\n window.clearTimeout(timeoutRef.current!);\n timeoutRef.current = null;\n }, []);\n\n const cancel = useCallback(() => {\n clearTimer();\n cooldownRef.current = false;\n }, []);\n\n const flush = useCallback(() => {\n if (timeoutRef.current) {\n cancel();\n cooldownRef.current = false;\n setValue(latestValueRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (mountedRef.current) {\n clearTimer();\n\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n }, wait);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel, { cancel, flush }];\n}\n\nexport namespace useDebouncedValue {\n export type Handlers = UseDebouncedValueHandlers;\n export type Options = UseDebouncedValueOptions;\n export type ReturnValue<T> = UseDebouncedValueReturnValue<T>;\n}\n"],"mappings":";;;AAaA,SAAgB,kBACd,OACA,MACA,UAAoC,EAAE,SAAS,MAAM,GACpB;CACjC,MAAM,CAAC,QAAQ,aAAA,GAAA,MAAA,SAAA,CAAqB,KAAK;CACzC,MAAM,cAAA,GAAA,MAAA,OAAA,CAAoB,KAAK;CAC/B,MAAM,cAAA,GAAA,MAAA,OAAA,CAAmC,IAAI;CAC7C,MAAM,eAAA,GAAA,MAAA,OAAA,CAAqB,KAAK;CAEhC,MAAM,kBAAA,GAAA,MAAA,OAAA,CAAwB,KAAK;CACnC,eAAe,UAAU;CAEzB,MAAM,cAAA,GAAA,MAAA,YAAA,OAA+B;EACnC,OAAO,aAAa,WAAW,OAAQ;EACvC,WAAW,UAAU;CACvB,GAAG,CAAC,CAAC;CAEL,MAAM,UAAA,GAAA,MAAA,YAAA,OAA2B;EAC/B,WAAW;EACX,YAAY,UAAU;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,SAAA,GAAA,MAAA,YAAA,OAA0B;EAC9B,IAAI,WAAW,SAAS;GACtB,OAAO;GACP,YAAY,UAAU;GACtB,SAAS,eAAe,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CAEL,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,WAAW,SAAS;GACtB,WAAW;GAEX,IAAI,CAAC,YAAY,WAAW,QAAQ,SAAS;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;IACd,WAAW,UAAU,OAAO,iBAAiB;KAC3C,YAAY,UAAU;IACxB,GAAG,IAAI;GACT,OACE,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;GAChB,GAAG,IAAI;EAEX;CACF,GAAG;EAAC;EAAO,QAAQ;EAAS;CAAI,CAAC;CAEjC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,WAAW,UAAU;EACrB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,OAAO;EAAC;EAAQ;EAAQ;GAAE;GAAQ;EAAM;CAAC;AAC3C"}
@@ -8,9 +8,12 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
8
8
  const cooldownRef = useRef(false);
9
9
  const latestValueRef = useRef(value);
10
10
  latestValueRef.current = value;
11
- const cancel = useCallback(() => {
11
+ const clearTimer = useCallback(() => {
12
12
  window.clearTimeout(timeoutRef.current);
13
13
  timeoutRef.current = null;
14
+ }, []);
15
+ const cancel = useCallback(() => {
16
+ clearTimer();
14
17
  cooldownRef.current = false;
15
18
  }, []);
16
19
  const flush = useCallback(() => {
@@ -21,15 +24,15 @@ function useDebouncedValue(value, wait, options = { leading: false }) {
21
24
  }
22
25
  }, []);
23
26
  useEffect(() => {
24
- if (mountedRef.current) if (!cooldownRef.current && options.leading) {
25
- cooldownRef.current = true;
26
- setValue(value);
27
- timeoutRef.current = window.setTimeout(() => {
28
- cooldownRef.current = false;
29
- }, wait);
30
- } else {
31
- cancel();
32
- timeoutRef.current = window.setTimeout(() => {
27
+ if (mountedRef.current) {
28
+ clearTimer();
29
+ if (!cooldownRef.current && options.leading) {
30
+ cooldownRef.current = true;
31
+ setValue(value);
32
+ timeoutRef.current = window.setTimeout(() => {
33
+ cooldownRef.current = false;
34
+ }, wait);
35
+ } else timeoutRef.current = window.setTimeout(() => {
33
36
  cooldownRef.current = false;
34
37
  setValue(value);
35
38
  }, wait);
@@ -1 +1 @@
1
- {"version":3,"file":"use-debounced-value.mjs","names":[],"sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface UseDebouncedValueOptions {\n leading?: boolean;\n}\n\nexport interface UseDebouncedValueHandlers {\n cancel: () => void;\n flush: () => void;\n}\n\nexport type UseDebouncedValueReturnValue<T> = [T, () => void, UseDebouncedValueHandlers];\n\nexport function useDebouncedValue<T = any>(\n value: T,\n wait: number,\n options: UseDebouncedValueOptions = { leading: false }\n): UseDebouncedValueReturnValue<T> {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const latestValueRef = useRef(value);\n latestValueRef.current = value;\n\n const cancel = useCallback(() => {\n window.clearTimeout(timeoutRef.current!);\n timeoutRef.current = null;\n cooldownRef.current = false;\n }, []);\n\n const flush = useCallback(() => {\n if (timeoutRef.current) {\n cancel();\n cooldownRef.current = false;\n setValue(latestValueRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (mountedRef.current) {\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n }, wait);\n } else {\n cancel();\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel, { cancel, flush }];\n}\n\nexport namespace useDebouncedValue {\n export type Handlers = UseDebouncedValueHandlers;\n export type Options = UseDebouncedValueOptions;\n export type ReturnValue<T> = UseDebouncedValueReturnValue<T>;\n}\n"],"mappings":";;;AAaA,SAAgB,kBACd,OACA,MACA,UAAoC,EAAE,SAAS,MAAM,GACpB;CACjC,MAAM,CAAC,QAAQ,YAAY,SAAS,KAAK;CACzC,MAAM,aAAa,OAAO,KAAK;CAC/B,MAAM,aAAa,OAAsB,IAAI;CAC7C,MAAM,cAAc,OAAO,KAAK;CAEhC,MAAM,iBAAiB,OAAO,KAAK;CACnC,eAAe,UAAU;CAEzB,MAAM,SAAS,kBAAkB;EAC/B,OAAO,aAAa,WAAW,OAAQ;EACvC,WAAW,UAAU;EACrB,YAAY,UAAU;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,kBAAkB;EAC9B,IAAI,WAAW,SAAS;GACtB,OAAO;GACP,YAAY,UAAU;GACtB,SAAS,eAAe,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CAEL,gBAAgB;EACd,IAAI,WAAW,SACb,IAAI,CAAC,YAAY,WAAW,QAAQ,SAAS;GAC3C,YAAY,UAAU;GACtB,SAAS,KAAK;GACd,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;GACxB,GAAG,IAAI;EACT,OAAO;GACL,OAAO;GACP,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;GAChB,GAAG,IAAI;EACT;CAEJ,GAAG;EAAC;EAAO,QAAQ;EAAS;CAAI,CAAC;CAEjC,gBAAgB;EACd,WAAW,UAAU;EACrB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,OAAO;EAAC;EAAQ;EAAQ;GAAE;GAAQ;EAAM;CAAC;AAC3C"}
1
+ {"version":3,"file":"use-debounced-value.mjs","names":[],"sources":["../../src/use-debounced-value/use-debounced-value.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nexport interface UseDebouncedValueOptions {\n leading?: boolean;\n}\n\nexport interface UseDebouncedValueHandlers {\n cancel: () => void;\n flush: () => void;\n}\n\nexport type UseDebouncedValueReturnValue<T> = [T, () => void, UseDebouncedValueHandlers];\n\nexport function useDebouncedValue<T = any>(\n value: T,\n wait: number,\n options: UseDebouncedValueOptions = { leading: false }\n): UseDebouncedValueReturnValue<T> {\n const [_value, setValue] = useState(value);\n const mountedRef = useRef(false);\n const timeoutRef = useRef<number | null>(null);\n const cooldownRef = useRef(false);\n\n const latestValueRef = useRef(value);\n latestValueRef.current = value;\n\n const clearTimer = useCallback(() => {\n window.clearTimeout(timeoutRef.current!);\n timeoutRef.current = null;\n }, []);\n\n const cancel = useCallback(() => {\n clearTimer();\n cooldownRef.current = false;\n }, []);\n\n const flush = useCallback(() => {\n if (timeoutRef.current) {\n cancel();\n cooldownRef.current = false;\n setValue(latestValueRef.current);\n }\n }, []);\n\n useEffect(() => {\n if (mountedRef.current) {\n clearTimer();\n\n if (!cooldownRef.current && options.leading) {\n cooldownRef.current = true;\n setValue(value);\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n }, wait);\n } else {\n timeoutRef.current = window.setTimeout(() => {\n cooldownRef.current = false;\n setValue(value);\n }, wait);\n }\n }\n }, [value, options.leading, wait]);\n\n useEffect(() => {\n mountedRef.current = true;\n return cancel;\n }, []);\n\n return [_value, cancel, { cancel, flush }];\n}\n\nexport namespace useDebouncedValue {\n export type Handlers = UseDebouncedValueHandlers;\n export type Options = UseDebouncedValueOptions;\n export type ReturnValue<T> = UseDebouncedValueReturnValue<T>;\n}\n"],"mappings":";;;AAaA,SAAgB,kBACd,OACA,MACA,UAAoC,EAAE,SAAS,MAAM,GACpB;CACjC,MAAM,CAAC,QAAQ,YAAY,SAAS,KAAK;CACzC,MAAM,aAAa,OAAO,KAAK;CAC/B,MAAM,aAAa,OAAsB,IAAI;CAC7C,MAAM,cAAc,OAAO,KAAK;CAEhC,MAAM,iBAAiB,OAAO,KAAK;CACnC,eAAe,UAAU;CAEzB,MAAM,aAAa,kBAAkB;EACnC,OAAO,aAAa,WAAW,OAAQ;EACvC,WAAW,UAAU;CACvB,GAAG,CAAC,CAAC;CAEL,MAAM,SAAS,kBAAkB;EAC/B,WAAW;EACX,YAAY,UAAU;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,kBAAkB;EAC9B,IAAI,WAAW,SAAS;GACtB,OAAO;GACP,YAAY,UAAU;GACtB,SAAS,eAAe,OAAO;EACjC;CACF,GAAG,CAAC,CAAC;CAEL,gBAAgB;EACd,IAAI,WAAW,SAAS;GACtB,WAAW;GAEX,IAAI,CAAC,YAAY,WAAW,QAAQ,SAAS;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;IACd,WAAW,UAAU,OAAO,iBAAiB;KAC3C,YAAY,UAAU;IACxB,GAAG,IAAI;GACT,OACE,WAAW,UAAU,OAAO,iBAAiB;IAC3C,YAAY,UAAU;IACtB,SAAS,KAAK;GAChB,GAAG,IAAI;EAEX;CACF,GAAG;EAAC;EAAO,QAAQ;EAAS;CAAI,CAAC;CAEjC,gBAAgB;EACd,WAAW,UAAU;EACrB,OAAO;CACT,GAAG,CAAC,CAAC;CAEL,OAAO;EAAC;EAAQ;EAAQ;GAAE;GAAQ;EAAM;CAAC;AAC3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/hooks",
3
- "version": "9.5.1",
3
+ "version": "9.5.2",
4
4
  "description": "A collection of 50+ hooks for state and UI management",
5
5
  "homepage": "https://mantine.dev",
6
6
  "license": "MIT",