@mantine/hooks 4.1.1 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/use-color-scheme/use-color-scheme.js +2 -2
- package/cjs/use-color-scheme/use-color-scheme.js.map +1 -1
- package/cjs/use-fullscreen/use-fullscreen.js +6 -0
- package/cjs/use-fullscreen/use-fullscreen.js.map +1 -1
- package/cjs/use-local-storage/use-local-storage.js +8 -1
- package/cjs/use-local-storage/use-local-storage.js.map +1 -1
- package/cjs/use-media-query/use-media-query.js +7 -3
- package/cjs/use-media-query/use-media-query.js.map +1 -1
- package/cjs/use-reduced-motion/use-reduced-motion.js +2 -2
- package/cjs/use-reduced-motion/use-reduced-motion.js.map +1 -1
- package/esm/use-color-scheme/use-color-scheme.js +2 -2
- package/esm/use-color-scheme/use-color-scheme.js.map +1 -1
- package/esm/use-fullscreen/use-fullscreen.js +6 -0
- package/esm/use-fullscreen/use-fullscreen.js.map +1 -1
- package/esm/use-local-storage/use-local-storage.js +8 -1
- package/esm/use-local-storage/use-local-storage.js.map +1 -1
- package/esm/use-media-query/use-media-query.js +7 -3
- package/esm/use-media-query/use-media-query.js.map +1 -1
- package/esm/use-reduced-motion/use-reduced-motion.js +2 -2
- package/esm/use-reduced-motion/use-reduced-motion.js.map +1 -1
- package/lib/use-color-scheme/use-color-scheme.d.ts +1 -1
- package/lib/use-color-scheme/use-color-scheme.d.ts.map +1 -1
- package/lib/use-fullscreen/use-fullscreen.d.ts.map +1 -1
- package/lib/use-local-storage/use-local-storage.d.ts +7 -1
- package/lib/use-local-storage/use-local-storage.d.ts.map +1 -1
- package/lib/use-media-query/use-media-query.d.ts +1 -1
- package/lib/use-media-query/use-media-query.d.ts.map +1 -1
- package/lib/use-reduced-motion/use-reduced-motion.d.ts +1 -1
- package/lib/use-reduced-motion/use-reduced-motion.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var useMediaQuery = require('../use-media-query/use-media-query.js');
|
|
6
6
|
|
|
7
|
-
function useColorScheme() {
|
|
8
|
-
return useMediaQuery.useMediaQuery("(prefers-color-scheme: dark)") ? "dark" : "light";
|
|
7
|
+
function useColorScheme(initialValue) {
|
|
8
|
+
return useMediaQuery.useMediaQuery("(prefers-color-scheme: dark)", initialValue === "dark") ? "dark" : "light";
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
exports.useColorScheme = useColorScheme;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-color-scheme.js","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useColorScheme() {\n return useMediaQuery('(prefers-color-scheme: dark)') ? 'dark' : 'light';\n}\n"],"names":["useMediaQuery"],"mappings":";;;;;;AACO,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"use-color-scheme.js","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useColorScheme(initialValue?: 'dark' | 'light') {\n return useMediaQuery('(prefers-color-scheme: dark)', initialValue === 'dark') ? 'dark' : 'light';\n}\n"],"names":["useMediaQuery"],"mappings":";;;;;;AACO,SAAS,cAAc,CAAC,YAAY,EAAE;AAC7C,EAAE,OAAOA,2BAAa,CAAC,8BAA8B,EAAE,YAAY,KAAK,MAAM,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC;AACnG;;;;"}
|
|
@@ -74,6 +74,12 @@ function useFullscreen() {
|
|
|
74
74
|
onError: handleFullscreenError
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
+
if (_ref.current) {
|
|
78
|
+
return addEvents(_ref.current, {
|
|
79
|
+
onFullScreen: handleFullscreenChange,
|
|
80
|
+
onError: handleFullscreenError
|
|
81
|
+
});
|
|
82
|
+
}
|
|
77
83
|
return void 0;
|
|
78
84
|
}, []);
|
|
79
85
|
return { ref, toggle, fullscreen };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fullscreen.js","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"sourcesContent":["import { useCallback, useRef, useState, useEffect } from 'react';\n\nfunction getFullscreenElement(): HTMLElement | null {\n const _document = window.document as any;\n\n const fullscreenElement =\n _document.fullscreenElement ||\n _document.webkitFullscreenElement ||\n _document.mozFullScreenElement ||\n _document.msFullscreenElement;\n\n return fullscreenElement;\n}\n\nasync function exitFullscreen() {\n const _document = window.document as any;\n\n if (typeof _document.exitFullscreen === 'function') return _document.exitFullscreen();\n if (typeof _document.msExitFullscreen === 'function') return _document.msExitFullscreen();\n if (typeof _document.webkitExitFullscreen === 'function') return _document.webkitExitFullscreen();\n if (typeof _document.mozCancelFullScreen === 'function') return _document.mozCancelFullScreen();\n\n return null;\n}\n\nasync function enterFullScreen(element: HTMLElement) {\n const _element = element as any;\n\n return (\n _element.requestFullscreen?.() ||\n _element.msRequestFullscreen?.() ||\n _element.webkitRequestFullscreen?.() ||\n _element.mozRequestFullscreen?.()\n );\n}\n\nconst prefixes = ['', 'webkit', 'moz', 'ms'];\n\nfunction addEvents(\n element: HTMLElement,\n {\n onFullScreen,\n onError,\n }: { onFullScreen: (event: Event) => void; onError: (event: Event) => void }\n) {\n prefixes.forEach((prefix) => {\n element.addEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.addEventListener(`${prefix}fullscreenerror`, onError);\n });\n\n return () => {\n prefixes.forEach((prefix) => {\n element.removeEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.removeEventListener(`${prefix}fullscreenerror`, onError);\n });\n };\n}\n\nexport function useFullscreen<T extends HTMLElement = any>() {\n const [fullscreen, setFullscreen] = useState<boolean>(false);\n\n const _ref = useRef<T>();\n\n const handleFullscreenChange = useCallback(\n (event: Event) => {\n setFullscreen(event.target === getFullscreenElement());\n },\n [setFullscreen]\n );\n\n const handleFullscreenError = useCallback(\n (event: Event) => {\n setFullscreen(false);\n // eslint-disable-next-line no-console\n console.error(\n `[@mantine/hooks] use-fullscreen: Error attempting full-screen mode method: ${event} (${event.target})`\n );\n },\n [setFullscreen]\n );\n\n const toggle = useCallback(async () => {\n if (!getFullscreenElement()) {\n await enterFullScreen(_ref.current);\n } else {\n await exitFullscreen();\n }\n }, []);\n\n const ref = useCallback((element: T | null) => {\n if (element === null) {\n _ref.current = window.document.documentElement as T;\n } else {\n _ref.current = element;\n }\n }, []);\n\n useEffect(() => {\n if (!_ref.current && window.document) {\n _ref.current = window.document.documentElement as T;\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n return undefined;\n }, []);\n\n return { ref, toggle, fullscreen } as const;\n}\n"],"names":["useState","useRef","useCallback","useEffect"],"mappings":";;;;;;AACA,SAAS,oBAAoB,GAAG;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,IAAI,SAAS,CAAC,uBAAuB,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,CAAC,mBAAmB,CAAC;AAChK,EAAE,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AACD,eAAe,cAAc,GAAG;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AACpC,EAAE,IAAI,OAAO,SAAS,CAAC,cAAc,KAAK,UAAU;AACpD,IAAI,OAAO,SAAS,CAAC,cAAc,EAAE,CAAC;AACtC,EAAE,IAAI,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU;AACtD,IAAI,OAAO,SAAS,CAAC,gBAAgB,EAAE,CAAC;AACxC,EAAE,IAAI,OAAO,SAAS,CAAC,oBAAoB,KAAK,UAAU;AAC1D,IAAI,OAAO,SAAS,CAAC,oBAAoB,EAAE,CAAC;AAC5C,EAAE,IAAI,OAAO,SAAS,CAAC,mB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ACT,EAAE,MAAM,GAAG,GAAGA,iBAAW,CAAC,CAAC,OAAO,KAAK;AACvC,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;AAC1B,MAAM,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;AACrD,KAAK,MAAM;AACX,MAAM,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AAC7B,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE;AAC1C,MAAM,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;AACrD,MAAM,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;AACrC,QAAQ,YAAY,EAAE,sBAAsB;AAC5C,QAAQ,OAAO,EAAE,qBAAqB;AACtC,OAAO,CAAC,CAAC;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACrC;;;;"}
|
|
1
|
+
{"version":3,"file":"use-fullscreen.js","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"sourcesContent":["import { useCallback, useRef, useState, useEffect } from 'react';\n\nfunction getFullscreenElement(): HTMLElement | null {\n const _document = window.document as any;\n\n const fullscreenElement =\n _document.fullscreenElement ||\n _document.webkitFullscreenElement ||\n _document.mozFullScreenElement ||\n _document.msFullscreenElement;\n\n return fullscreenElement;\n}\n\nasync function exitFullscreen() {\n const _document = window.document as any;\n\n if (typeof _document.exitFullscreen === 'function') return _document.exitFullscreen();\n if (typeof _document.msExitFullscreen === 'function') return _document.msExitFullscreen();\n if (typeof _document.webkitExitFullscreen === 'function') return _document.webkitExitFullscreen();\n if (typeof _document.mozCancelFullScreen === 'function') return _document.mozCancelFullScreen();\n\n return null;\n}\n\nasync function enterFullScreen(element: HTMLElement) {\n const _element = element as any;\n\n return (\n _element.requestFullscreen?.() ||\n _element.msRequestFullscreen?.() ||\n _element.webkitRequestFullscreen?.() ||\n _element.mozRequestFullscreen?.()\n );\n}\n\nconst prefixes = ['', 'webkit', 'moz', 'ms'];\n\nfunction addEvents(\n element: HTMLElement,\n {\n onFullScreen,\n onError,\n }: { onFullScreen: (event: Event) => void; onError: (event: Event) => void }\n) {\n prefixes.forEach((prefix) => {\n element.addEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.addEventListener(`${prefix}fullscreenerror`, onError);\n });\n\n return () => {\n prefixes.forEach((prefix) => {\n element.removeEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.removeEventListener(`${prefix}fullscreenerror`, onError);\n });\n };\n}\n\nexport function useFullscreen<T extends HTMLElement = any>() {\n const [fullscreen, setFullscreen] = useState<boolean>(false);\n\n const _ref = useRef<T>();\n\n const handleFullscreenChange = useCallback(\n (event: Event) => {\n setFullscreen(event.target === getFullscreenElement());\n },\n [setFullscreen]\n );\n\n const handleFullscreenError = useCallback(\n (event: Event) => {\n setFullscreen(false);\n // eslint-disable-next-line no-console\n console.error(\n `[@mantine/hooks] use-fullscreen: Error attempting full-screen mode method: ${event} (${event.target})`\n );\n },\n [setFullscreen]\n );\n\n const toggle = useCallback(async () => {\n if (!getFullscreenElement()) {\n await enterFullScreen(_ref.current);\n } else {\n await exitFullscreen();\n }\n }, []);\n\n const ref = useCallback((element: T | null) => {\n if (element === null) {\n _ref.current = window.document.documentElement as T;\n } else {\n _ref.current = element;\n }\n }, []);\n\n useEffect(() => {\n if (!_ref.current && window.document) {\n _ref.current = window.document.documentElement as T;\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n if (_ref.current) {\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n return und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Q,CAAC,eAAe,CAAC;AACrD,MAAM,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;AACrC,QAAQ,YAAY,EAAE,sBAAsB;AAC5C,QAAQ,OAAO,EAAE,qBAAqB;AACtC,OAAO,CAAC,CAAC;AACT,KAAK;AACL,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;AACtB,MAAM,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;AACrC,QAAQ,YAAY,EAAE,sBAAsB;AAC5C,QAAQ,OAAO,EAAE,qBAAqB;AACtC,OAAO,CAAC,CAAC;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACrC;;;;"}
|
|
@@ -22,11 +22,12 @@ function deserializeJSON(value) {
|
|
|
22
22
|
function useLocalStorage({
|
|
23
23
|
key,
|
|
24
24
|
defaultValue = void 0,
|
|
25
|
+
getInitialValueInEffect = false,
|
|
25
26
|
deserialize = deserializeJSON,
|
|
26
27
|
serialize = serializeJSON
|
|
27
28
|
}) {
|
|
28
29
|
var _a;
|
|
29
|
-
const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
30
|
+
const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window && !getInitialValueInEffect ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
30
31
|
const setLocalStorageValue = react.useCallback((val) => {
|
|
31
32
|
if (val instanceof Function) {
|
|
32
33
|
setValue((current) => {
|
|
@@ -50,6 +51,12 @@ function useLocalStorage({
|
|
|
50
51
|
setLocalStorageValue(defaultValue);
|
|
51
52
|
}
|
|
52
53
|
}, [defaultValue, value, setLocalStorageValue]);
|
|
54
|
+
react.useEffect(() => {
|
|
55
|
+
var _a2;
|
|
56
|
+
if (getInitialValueInEffect) {
|
|
57
|
+
setValue(deserialize((_a2 = window.localStorage.getItem(key)) != null ? _a2 : void 0) || (defaultValue != null ? defaultValue : ""));
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
53
60
|
return [value === void 0 ? defaultValue : value, setLocalStorageValue];
|
|
54
61
|
}
|
|
55
62
|
const useLocalStorageValue = useLocalStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n key: string;\n defaultValue?: T;\n serialize?(value: T): string;\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,EAAE,WAAW,GAAG,eAAe;AAC/B,EAAE,SAAS,GAAG,aAAa;AAC3B,CAAC,EAAE;AACH,EAAE,IAAI,EAAE,CAAC;AACT,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n /** Local storage key */\n key: string;\n\n /** Default value that will be set if value is not found in local storage */\n defaultValue?: T;\n\n /** If set to true, value will be update is useEffect after mount */\n getInitialValueInEffect?: boolean;\n\n /** Function to serialize value into string to be save in local storage */\n serialize?(value: T): string;\n\n /** Function to deserialize string value from local storage to value */\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n getInitialValueInEffect = false,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window && !getInitialValueInEffect\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n useEffect(() => {\n if (getInitialValueInEffect) {\n setValue(\n deserialize(window.localStorage.getItem(key) ?? undefined) || ((defaultValue ?? '') as T)\n );\n }\n }, []);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEA,SAAS,aAAa,CAAC,KAAK,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EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,oBAAoB,CAAC,CAAC;AACzE,CAAC;AACW,MAAC,oBAAoB,GAAG;;;;;"}
|
|
@@ -13,14 +13,17 @@ function attachMediaListener(query, callback) {
|
|
|
13
13
|
return () => query.removeListener(callback);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function getInitialValue(query) {
|
|
16
|
+
function getInitialValue(query, initialValue) {
|
|
17
|
+
if (initialValue !== void 0) {
|
|
18
|
+
return initialValue;
|
|
19
|
+
}
|
|
17
20
|
if (typeof window !== "undefined" && "matchMedia" in window) {
|
|
18
21
|
return window.matchMedia(query).matches;
|
|
19
22
|
}
|
|
20
23
|
return false;
|
|
21
24
|
}
|
|
22
|
-
function useMediaQuery(query) {
|
|
23
|
-
const [matches, setMatches] = react.useState(getInitialValue(query));
|
|
25
|
+
function useMediaQuery(query, initialValue) {
|
|
26
|
+
const [matches, setMatches] = react.useState(getInitialValue(query, initialValue));
|
|
24
27
|
const queryRef = react.useRef();
|
|
25
28
|
react.useEffect(() => {
|
|
26
29
|
if ("matchMedia" in window) {
|
|
@@ -28,6 +31,7 @@ function useMediaQuery(query) {
|
|
|
28
31
|
setMatches(queryRef.current.matches);
|
|
29
32
|
return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
|
|
30
33
|
}
|
|
34
|
+
return void 0;
|
|
31
35
|
}, [query]);
|
|
32
36
|
return matches;
|
|
33
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string) {\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n return false;\n}\n\nexport function useMediaQuery(query: string) {\n const [matches, setMatches] = useState(getInitialValue(query));\n const queryRef = useRef<MediaQueryList>();\n\n
|
|
1
|
+
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (initialValue !== undefined) {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(query: string, initialValue?: boolean) {\n const [matches, setMatches] = useState(getInitialValue(query, initialValue));\n const queryRef = useRef<MediaQueryList>();\n\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n\n return undefined;\n }, [query]);\n\n return matches;\n}\n"],"names":["useState","useRef","useEffect"],"mappings":";;;;;;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC9C,EAAE,IAAI;AACN,IAAI,KAAK,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L,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var useMediaQuery = require('../use-media-query/use-media-query.js');
|
|
6
6
|
|
|
7
|
-
function useReducedMotion() {
|
|
8
|
-
return useMediaQuery.useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
7
|
+
function useReducedMotion(initialValue) {
|
|
8
|
+
return useMediaQuery.useMediaQuery("(prefers-reduced-motion: reduce)", initialValue);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
exports.useReducedMotion = useReducedMotion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reduced-motion.js","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":["useMediaQuery"],"mappings":";;;;;;AACO,SAAS,gBAAgB,
|
|
1
|
+
{"version":3,"file":"use-reduced-motion.js","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useReducedMotion(initialValue?: boolean) {\n return useMediaQuery('(prefers-reduced-motion: reduce)', initialValue);\n}\n"],"names":["useMediaQuery"],"mappings":";;;;;;AACO,SAAS,gBAAgB,CAAC,YAAY,EAAE;AAC/C,EAAE,OAAOA,2BAAa,CAAC,kCAAkC,EAAE,YAAY,CAAC,CAAC;AACzE;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMediaQuery } from '../use-media-query/use-media-query.js';
|
|
2
2
|
|
|
3
|
-
function useColorScheme() {
|
|
4
|
-
return useMediaQuery("(prefers-color-scheme: dark)") ? "dark" : "light";
|
|
3
|
+
function useColorScheme(initialValue) {
|
|
4
|
+
return useMediaQuery("(prefers-color-scheme: dark)", initialValue === "dark") ? "dark" : "light";
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export { useColorScheme };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-color-scheme.js","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useColorScheme() {\n return useMediaQuery('(prefers-color-scheme: dark)') ? 'dark' : 'light';\n}\n"],"names":[],"mappings":";;AACO,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"use-color-scheme.js","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useColorScheme(initialValue?: 'dark' | 'light') {\n return useMediaQuery('(prefers-color-scheme: dark)', initialValue === 'dark') ? 'dark' : 'light';\n}\n"],"names":[],"mappings":";;AACO,SAAS,cAAc,CAAC,YAAY,EAAE;AAC7C,EAAE,OAAO,aAAa,CAAC,8BAA8B,EAAE,YAAY,KAAK,MAAM,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC;AACnG;;;;"}
|
|
@@ -70,6 +70,12 @@ function useFullscreen() {
|
|
|
70
70
|
onError: handleFullscreenError
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
+
if (_ref.current) {
|
|
74
|
+
return addEvents(_ref.current, {
|
|
75
|
+
onFullScreen: handleFullscreenChange,
|
|
76
|
+
onError: handleFullscreenError
|
|
77
|
+
});
|
|
78
|
+
}
|
|
73
79
|
return void 0;
|
|
74
80
|
}, []);
|
|
75
81
|
return { ref, toggle, fullscreen };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fullscreen.js","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"sourcesContent":["import { useCallback, useRef, useState, useEffect } from 'react';\n\nfunction getFullscreenElement(): HTMLElement | null {\n const _document = window.document as any;\n\n const fullscreenElement =\n _document.fullscreenElement ||\n _document.webkitFullscreenElement ||\n _document.mozFullScreenElement ||\n _document.msFullscreenElement;\n\n return fullscreenElement;\n}\n\nasync function exitFullscreen() {\n const _document = window.document as any;\n\n if (typeof _document.exitFullscreen === 'function') return _document.exitFullscreen();\n if (typeof _document.msExitFullscreen === 'function') return _document.msExitFullscreen();\n if (typeof _document.webkitExitFullscreen === 'function') return _document.webkitExitFullscreen();\n if (typeof _document.mozCancelFullScreen === 'function') return _document.mozCancelFullScreen();\n\n return null;\n}\n\nasync function enterFullScreen(element: HTMLElement) {\n const _element = element as any;\n\n return (\n _element.requestFullscreen?.() ||\n _element.msRequestFullscreen?.() ||\n _element.webkitRequestFullscreen?.() ||\n _element.mozRequestFullscreen?.()\n );\n}\n\nconst prefixes = ['', 'webkit', 'moz', 'ms'];\n\nfunction addEvents(\n element: HTMLElement,\n {\n onFullScreen,\n onError,\n }: { onFullScreen: (event: Event) => void; onError: (event: Event) => void }\n) {\n prefixes.forEach((prefix) => {\n element.addEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.addEventListener(`${prefix}fullscreenerror`, onError);\n });\n\n return () => {\n prefixes.forEach((prefix) => {\n element.removeEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.removeEventListener(`${prefix}fullscreenerror`, onError);\n });\n };\n}\n\nexport function useFullscreen<T extends HTMLElement = any>() {\n const [fullscreen, setFullscreen] = useState<boolean>(false);\n\n const _ref = useRef<T>();\n\n const handleFullscreenChange = useCallback(\n (event: Event) => {\n setFullscreen(event.target === getFullscreenElement());\n },\n [setFullscreen]\n );\n\n const handleFullscreenError = useCallback(\n (event: Event) => {\n setFullscreen(false);\n // eslint-disable-next-line no-console\n console.error(\n `[@mantine/hooks] use-fullscreen: Error attempting full-screen mode method: ${event} (${event.target})`\n );\n },\n [setFullscreen]\n );\n\n const toggle = useCallback(async () => {\n if (!getFullscreenElement()) {\n await enterFullScreen(_ref.current);\n } else {\n await exitFullscreen();\n }\n }, []);\n\n const ref = useCallback((element: T | null) => {\n if (element === null) {\n _ref.current = window.document.documentElement as T;\n } else {\n _ref.current = element;\n }\n }, []);\n\n useEffect(() => {\n if (!_ref.current && window.document) {\n _ref.current = window.document.documentElement as T;\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n return undefined;\n }, []);\n\n return { ref, toggle, fullscreen } as const;\n}\n"],"names":[],"mappings":";;AACA,SAAS,oBAAoB,GAAG;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,IAAI,SAAS,CAAC,uBAAuB,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,CAAC,mBAAmB,CAAC;AAChK,EAAE,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AACD,eAAe,cAAc,GAAG;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AACpC,EAAE,IAAI,OAAO,SAAS,CAAC,cAAc,KAAK,UAAU;AACpD,IAAI,OAAO,SAAS,CAAC,cAAc,EAAE,CAAC;AACtC,EAAE,IAAI,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU;AACtD,IAAI,OAAO,SAAS,CAAC,gBAAgB,EAAE,CAAC;AACxC,EAAE,IAAI,OAAO,SAAS,CAAC,oBAAoB,KAAK,UAAU;AAC1D,IAAI,OAAO,SAAS,CAAC,oBAAoB,EAAE,CAAC;AAC5C,EAAE,IAAI,OAAO,SAAS,CAAC,mBAAmB,KAAK,UAAU;AACzD,IAAI,OAAO,SAAS,CAAC,mBAAmB,EAAE,CAAC;AAC3C,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACD,eAAe,eAAe,CAAC,OAAO,EAAE;AACxC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACrB,EAAE,MAAM,QAAQ,GAAG,OA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L,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE;AAC1C,MAAM,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;AACrD,MAAM,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE;AACrC,QAAQ,YAAY,EAAE,sBAAsB;AAC5C,QAAQ,OAAO,EAAE,qBAAqB;AACtC,OAAO,CAAC,CAAC;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACrC;;;;"}
|
|
1
|
+
{"version":3,"file":"use-fullscreen.js","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"sourcesContent":["import { useCallback, useRef, useState, useEffect } from 'react';\n\nfunction getFullscreenElement(): HTMLElement | null {\n const _document = window.document as any;\n\n const fullscreenElement =\n _document.fullscreenElement ||\n _document.webkitFullscreenElement ||\n _document.mozFullScreenElement ||\n _document.msFullscreenElement;\n\n return fullscreenElement;\n}\n\nasync function exitFullscreen() {\n const _document = window.document as any;\n\n if (typeof _document.exitFullscreen === 'function') return _document.exitFullscreen();\n if (typeof _document.msExitFullscreen === 'function') return _document.msExitFullscreen();\n if (typeof _document.webkitExitFullscreen === 'function') return _document.webkitExitFullscreen();\n if (typeof _document.mozCancelFullScreen === 'function') return _document.mozCancelFullScreen();\n\n return null;\n}\n\nasync function enterFullScreen(element: HTMLElement) {\n const _element = element as any;\n\n return (\n _element.requestFullscreen?.() ||\n _element.msRequestFullscreen?.() ||\n _element.webkitRequestFullscreen?.() ||\n _element.mozRequestFullscreen?.()\n );\n}\n\nconst prefixes = ['', 'webkit', 'moz', 'ms'];\n\nfunction addEvents(\n element: HTMLElement,\n {\n onFullScreen,\n onError,\n }: { onFullScreen: (event: Event) => void; onError: (event: Event) => void }\n) {\n prefixes.forEach((prefix) => {\n element.addEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.addEventListener(`${prefix}fullscreenerror`, onError);\n });\n\n return () => {\n prefixes.forEach((prefix) => {\n element.removeEventListener(`${prefix}fullscreenchange`, onFullScreen);\n element.removeEventListener(`${prefix}fullscreenerror`, onError);\n });\n };\n}\n\nexport function useFullscreen<T extends HTMLElement = any>() {\n const [fullscreen, setFullscreen] = useState<boolean>(false);\n\n const _ref = useRef<T>();\n\n const handleFullscreenChange = useCallback(\n (event: Event) => {\n setFullscreen(event.target === getFullscreenElement());\n },\n [setFullscreen]\n );\n\n const handleFullscreenError = useCallback(\n (event: Event) => {\n setFullscreen(false);\n // eslint-disable-next-line no-console\n console.error(\n `[@mantine/hooks] use-fullscreen: Error attempting full-screen mode method: ${event} (${event.target})`\n );\n },\n [setFullscreen]\n );\n\n const toggle = useCallback(async () => {\n if (!getFullscreenElement()) {\n await enterFullScreen(_ref.current);\n } else {\n await exitFullscreen();\n }\n }, []);\n\n const ref = useCallback((element: T | null) => {\n if (element === null) {\n _ref.current = window.document.documentElement as T;\n } else {\n _ref.current = element;\n }\n }, []);\n\n useEffect(() => {\n if (!_ref.current && window.document) {\n _ref.current = window.document.documentElement as T;\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n if (_ref.current) {\n return addEvents(_ref.current, {\n onFullScreen: handleFullscreenChange,\n onError: handleFullscreenError,\n });\n }\n\n return undefined;\n }, []);\n\n return { ref, toggle, fullscreen } as const;\n}\n"],"names":[],"mappings":";;AACA,SAAS,oBAAoB,GAAG;AAChC,EAAE,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AACpC,EAAE,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,IAAI,SAAS,CAAC,uBAAuB,IAAI,SAAS,CAAC,oBAAoB,IAAI,SAAS,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E,sBAAsB;AAC5C,QAAQ,OAAO,EAAE,qBAAqB;AACtC,OAAO,CAAC,CAAC;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AACrC;;;;"}
|
|
@@ -18,11 +18,12 @@ function deserializeJSON(value) {
|
|
|
18
18
|
function useLocalStorage({
|
|
19
19
|
key,
|
|
20
20
|
defaultValue = void 0,
|
|
21
|
+
getInitialValueInEffect = false,
|
|
21
22
|
deserialize = deserializeJSON,
|
|
22
23
|
serialize = serializeJSON
|
|
23
24
|
}) {
|
|
24
25
|
var _a;
|
|
25
|
-
const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
26
|
+
const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window && !getInitialValueInEffect ? deserialize((_a = window.localStorage.getItem(key)) != null ? _a : void 0) : defaultValue != null ? defaultValue : "");
|
|
26
27
|
const setLocalStorageValue = useCallback((val) => {
|
|
27
28
|
if (val instanceof Function) {
|
|
28
29
|
setValue((current) => {
|
|
@@ -46,6 +47,12 @@ function useLocalStorage({
|
|
|
46
47
|
setLocalStorageValue(defaultValue);
|
|
47
48
|
}
|
|
48
49
|
}, [defaultValue, value, setLocalStorageValue]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
var _a2;
|
|
52
|
+
if (getInitialValueInEffect) {
|
|
53
|
+
setValue(deserialize((_a2 = window.localStorage.getItem(key)) != null ? _a2 : void 0) || (defaultValue != null ? defaultValue : ""));
|
|
54
|
+
}
|
|
55
|
+
}, []);
|
|
49
56
|
return [value === void 0 ? defaultValue : value, setLocalStorageValue];
|
|
50
57
|
}
|
|
51
58
|
const useLocalStorageValue = useLocalStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n key: string;\n defaultValue?: T;\n serialize?(value: T): string;\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":[],"mappings":";;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,CAAC;AACM,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,EAAE,WAAW,GAAG,eAAe;AAC/B,EAAE,SAAS,GAAG,aAAa;AAC3B,CAAC,EAAE;AACH,EAAE,IAAI,EAAE,CAAC;AACT,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.js","sources":["../../src/use-local-storage/use-local-storage.ts"],"sourcesContent":["import { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\ninterface UseLocalStorage<T> {\n /** Local storage key */\n key: string;\n\n /** Default value that will be set if value is not found in local storage */\n defaultValue?: T;\n\n /** If set to true, value will be update is useEffect after mount */\n getInitialValueInEffect?: boolean;\n\n /** Function to serialize value into string to be save in local storage */\n serialize?(value: T): string;\n\n /** Function to deserialize string value from local storage to value */\n deserialize?(value: string): T;\n}\n\nfunction serializeJSON<T>(value: T) {\n try {\n return JSON.stringify(value);\n } catch (error) {\n throw new Error('@mantine/hooks use-local-storage: Failed to serialize the value');\n }\n}\n\nfunction deserializeJSON(value: string) {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nexport function useLocalStorage<T = string>({\n key,\n defaultValue = undefined,\n getInitialValueInEffect = false,\n deserialize = deserializeJSON,\n serialize = serializeJSON,\n}: UseLocalStorage<T>) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window && !getInitialValueInEffect\n ? deserialize(window.localStorage.getItem(key) ?? undefined)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (val instanceof Function) {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, serialize(result));\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n setValue(val);\n }\n },\n [key]\n );\n\n useWindowEvent('storage', (event) => {\n if (event.storageArea === window.localStorage && event.key === key) {\n setValue(deserialize(event.newValue ?? undefined));\n }\n });\n\n useEffect(() => {\n if (defaultValue !== undefined && value === undefined) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n useEffect(() => {\n if (getInitialValueInEffect) {\n setValue(\n deserialize(window.localStorage.getItem(key) ?? undefined) || ((defaultValue ?? '') as T)\n );\n }\n }, []);\n\n return [value === undefined ? defaultValue : value, setLocalStorageValue] as const;\n}\n\nexport const useLocalStorageValue = useLocalStorage;\n"],"names":[],"mappings":";;;AAEA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,GAAG,CAAC,OAAO,KAAK,EAAE;AAClB,IAAI,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;AACvF,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE;AAChC,EAAE,IAAI;AACN,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7B,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,KA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AAG,CAAC;AACZ,IAAI,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC,YAAY,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;AACxE,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3E,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,YAAY,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,KAAK,CAAC,EAAE;AACrD,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;AACzC,KAAK;AACL,GAAG,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAClD,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,GAAG,CAAC;AACZ,IAAI,IAAI,uBAAuB,EAAE;AACjC,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AAC3I,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,oBAAoB,CAAC,CAAC;AACzE,CAAC;AACW,MAAC,oBAAoB,GAAG;;;;"}
|
|
@@ -9,14 +9,17 @@ function attachMediaListener(query, callback) {
|
|
|
9
9
|
return () => query.removeListener(callback);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function getInitialValue(query) {
|
|
12
|
+
function getInitialValue(query, initialValue) {
|
|
13
|
+
if (initialValue !== void 0) {
|
|
14
|
+
return initialValue;
|
|
15
|
+
}
|
|
13
16
|
if (typeof window !== "undefined" && "matchMedia" in window) {
|
|
14
17
|
return window.matchMedia(query).matches;
|
|
15
18
|
}
|
|
16
19
|
return false;
|
|
17
20
|
}
|
|
18
|
-
function useMediaQuery(query) {
|
|
19
|
-
const [matches, setMatches] = useState(getInitialValue(query));
|
|
21
|
+
function useMediaQuery(query, initialValue) {
|
|
22
|
+
const [matches, setMatches] = useState(getInitialValue(query, initialValue));
|
|
20
23
|
const queryRef = useRef();
|
|
21
24
|
useEffect(() => {
|
|
22
25
|
if ("matchMedia" in window) {
|
|
@@ -24,6 +27,7 @@ function useMediaQuery(query) {
|
|
|
24
27
|
setMatches(queryRef.current.matches);
|
|
25
28
|
return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
|
|
26
29
|
}
|
|
30
|
+
return void 0;
|
|
27
31
|
}, [query]);
|
|
28
32
|
return matches;
|
|
29
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string) {\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n return false;\n}\n\nexport function useMediaQuery(query: string) {\n const [matches, setMatches] = useState(getInitialValue(query));\n const queryRef = useRef<MediaQueryList>();\n\n
|
|
1
|
+
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (initialValue !== undefined) {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(query: string, initialValue?: boolean) {\n const [matches, setMatches] = useState(getInitialValue(query, initialValue));\n const queryRef = useRef<MediaQueryList>();\n\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n\n return undefined;\n }, [query]);\n\n return matches;\n}\n"],"names":[],"mappings":";;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC9C,EAAE,IAAI;AACN,IAAI,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/C,IAAI,OAAO,MAAM,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/D,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAChC,IAAI,OAAO,MAAM,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;AAChD,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE;AAC9C,EAAE,IAAI,YAAY,KAAK,KAAK,CAAC,EAAE;AAC/B,IAAI,OAAO,YAAY,CAAC;AACxB,GAAG;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,EAAE;AAC/D,IAAI,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC5C,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf,CAAC;AACM,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE;AACnD,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;AAC/E,EAAE,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAC5B,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,YAAY,IAAI,MAAM,EAAE;AAChC,MAAM,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAClD,MAAM,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC3C,MAAM,OAAO,mBAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACzF,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMediaQuery } from '../use-media-query/use-media-query.js';
|
|
2
2
|
|
|
3
|
-
function useReducedMotion() {
|
|
4
|
-
return useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
3
|
+
function useReducedMotion(initialValue) {
|
|
4
|
+
return useMediaQuery("(prefers-reduced-motion: reduce)", initialValue);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export { useReducedMotion };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reduced-motion.js","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":[],"mappings":";;AACO,SAAS,gBAAgB,
|
|
1
|
+
{"version":3,"file":"use-reduced-motion.js","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"sourcesContent":["import { useMediaQuery } from '../use-media-query/use-media-query';\n\nexport function useReducedMotion(initialValue?: boolean) {\n return useMediaQuery('(prefers-reduced-motion: reduce)', initialValue);\n}\n"],"names":[],"mappings":";;AACO,SAAS,gBAAgB,CAAC,YAAY,EAAE;AAC/C,EAAE,OAAO,aAAa,CAAC,kCAAkC,EAAE,YAAY,CAAC,CAAC;AACzE;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useColorScheme(): "dark" | "light";
|
|
1
|
+
export declare function useColorScheme(initialValue?: 'dark' | 'light'): "dark" | "light";
|
|
2
2
|
//# sourceMappingURL=use-color-scheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-color-scheme.d.ts","sourceRoot":"","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,
|
|
1
|
+
{"version":3,"file":"use-color-scheme.d.ts","sourceRoot":"","sources":["../../src/use-color-scheme/use-color-scheme.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,oBAE7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fullscreen.d.ts","sourceRoot":"","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"names":[],"mappings":"AA0DA,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,GAAG;4BA+BrB,CAAC,GAAG,IAAI;;;
|
|
1
|
+
{"version":3,"file":"use-fullscreen.d.ts","sourceRoot":"","sources":["../../src/use-fullscreen/use-fullscreen.ts"],"names":[],"mappings":"AA0DA,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,GAAG;4BA+BrB,CAAC,GAAG,IAAI;;;EA4B3C"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
interface UseLocalStorage<T> {
|
|
2
|
+
/** Local storage key */
|
|
2
3
|
key: string;
|
|
4
|
+
/** Default value that will be set if value is not found in local storage */
|
|
3
5
|
defaultValue?: T;
|
|
6
|
+
/** If set to true, value will be update is useEffect after mount */
|
|
7
|
+
getInitialValueInEffect?: boolean;
|
|
8
|
+
/** Function to serialize value into string to be save in local storage */
|
|
4
9
|
serialize?(value: T): string;
|
|
10
|
+
/** Function to deserialize string value from local storage to value */
|
|
5
11
|
deserialize?(value: string): T;
|
|
6
12
|
}
|
|
7
|
-
export declare function useLocalStorage<T = string>({ key, defaultValue, deserialize, serialize, }: UseLocalStorage<T>): readonly [T, (val: T | ((prevState: T) => T)) => void];
|
|
13
|
+
export declare function useLocalStorage<T = string>({ key, defaultValue, getInitialValueInEffect, deserialize, serialize, }: UseLocalStorage<T>): readonly [T, (val: T | ((prevState: T) => T)) => void];
|
|
8
14
|
export declare const useLocalStorageValue: typeof useLocalStorage;
|
|
9
15
|
export {};
|
|
10
16
|
//# sourceMappingURL=use-local-storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.d.ts","sourceRoot":"","sources":["../../src/use-local-storage/use-local-storage.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe,CAAC,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"use-local-storage.d.ts","sourceRoot":"","sources":["../../src/use-local-storage/use-local-storage.ts"],"names":[],"mappings":"AAGA,UAAU,eAAe,CAAC,CAAC;IACzB,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IAEZ,4EAA4E;IAC5E,YAAY,CAAC,EAAE,CAAC,CAAC;IAEjB,oEAAoE;IACpE,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,0EAA0E;IAC1E,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAE7B,uEAAuE;IACvE,WAAW,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;CAChC;AAkBD,wBAAgB,eAAe,CAAC,CAAC,GAAG,MAAM,EAAE,EAC1C,GAAG,EACH,YAAwB,EACxB,uBAA+B,EAC/B,WAA6B,EAC7B,SAAyB,GAC1B,EAAE,eAAe,CAAC,CAAC,CAAC,uCAQM,CAAC,KAAK,CAAC,YAoCjC;AAED,eAAO,MAAM,oBAAoB,wBAAkB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useMediaQuery(query: string): boolean;
|
|
1
|
+
export declare function useMediaQuery(query: string, initialValue?: boolean): boolean;
|
|
2
2
|
//# sourceMappingURL=use-media-query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.d.ts","sourceRoot":"","sources":["../../src/use-media-query/use-media-query.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-media-query.d.ts","sourceRoot":"","sources":["../../src/use-media-query/use-media-query.ts"],"names":[],"mappings":"AA8BA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,WAelE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useReducedMotion(): boolean;
|
|
1
|
+
export declare function useReducedMotion(initialValue?: boolean): boolean;
|
|
2
2
|
//# sourceMappingURL=use-reduced-motion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"use-reduced-motion.d.ts","sourceRoot":"","sources":["../../src/use-reduced-motion/use-reduced-motion.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,YAAY,CAAC,EAAE,OAAO,WAEtD"}
|