@mantine/hooks 4.2.9 → 5.0.0-alpha.10
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/index.js +6 -6
- package/cjs/use-click-outside/use-click-outside.js +3 -3
- package/cjs/use-clipboard/use-clipboard.js +4 -4
- package/cjs/use-counter/use-counter.js +39 -0
- package/cjs/use-counter/use-counter.js.map +1 -0
- package/cjs/use-debounced-value/use-debounced-value.js +7 -7
- package/cjs/use-did-update/use-did-update.js +3 -3
- package/cjs/use-disclosure/use-disclosure.js +2 -2
- package/cjs/use-document-visibility/use-document-visibility.js +23 -0
- package/cjs/use-document-visibility/use-document-visibility.js.map +1 -0
- package/cjs/use-event-listener/use-event-listener.js +3 -3
- package/cjs/use-focus-return/use-focus-return.js +3 -3
- package/cjs/use-focus-return/use-focus-return.js.map +1 -1
- package/cjs/use-focus-trap/use-focus-trap.js +5 -5
- package/cjs/use-focus-within/use-focus-within.js +5 -5
- package/cjs/use-force-update/use-force-update.js +2 -2
- package/cjs/use-fullscreen/use-fullscreen.js +8 -8
- package/cjs/use-hash/use-hash.js +2 -2
- package/cjs/use-hotkeys/use-hotkeys.js +2 -2
- package/cjs/use-hover/use-hover.js +6 -6
- package/cjs/use-id/use-id.js +21 -5
- package/cjs/use-id/use-id.js.map +1 -1
- package/cjs/use-idle/use-idle.js +4 -4
- package/cjs/use-input-state/use-input-state.js +2 -2
- package/cjs/use-intersection/use-intersection.js +5 -5
- package/cjs/use-intersection/use-intersection.js.map +1 -1
- package/cjs/use-interval/use-interval.js +3 -3
- package/cjs/use-isomorphic-effect/use-isomorphic-effect.js +2 -2
- package/cjs/use-list-state/use-list-state.js +2 -2
- package/cjs/use-local-storage/use-local-storage.js +5 -7
- package/cjs/use-local-storage/use-local-storage.js.map +1 -1
- package/cjs/use-logger/use-logger.js +2 -2
- package/cjs/use-media-query/use-media-query.js +4 -4
- package/cjs/use-merged-ref/use-merged-ref.js +4 -6
- package/cjs/use-merged-ref/use-merged-ref.js.map +1 -1
- package/cjs/use-mouse/use-mouse.js +4 -4
- package/cjs/use-move/use-move.js +12 -12
- package/cjs/use-move/use-move.js.map +1 -1
- package/cjs/use-network/use-network.js +9 -13
- package/cjs/use-network/use-network.js.map +1 -1
- package/cjs/use-page-leave/use-page-leave.js +2 -2
- package/cjs/use-pagination/use-pagination.js +3 -4
- package/cjs/use-pagination/use-pagination.js.map +1 -1
- package/cjs/use-queue/use-queue.js +2 -2
- package/cjs/use-resize-observer/use-resize-observer.js +6 -6
- package/cjs/use-scroll-into-view/use-scroll-into-view.js +8 -8
- package/cjs/use-scroll-lock/use-scroll-lock.js +7 -7
- package/cjs/use-set-state/use-set-state.js +2 -2
- package/cjs/use-shallow-effect/use-shallow-effect.js +4 -4
- package/cjs/use-timeout/use-timeout.js +33 -0
- package/cjs/use-timeout/use-timeout.js.map +1 -0
- package/cjs/use-toggle/use-toggle.js +3 -7
- package/cjs/use-toggle/use-toggle.js.map +1 -1
- package/cjs/use-uncontrolled/use-uncontrolled.js +8 -26
- package/cjs/use-uncontrolled/use-uncontrolled.js.map +1 -1
- package/cjs/use-validated-state/use-validated-state.js +4 -4
- package/cjs/use-viewport-size/use-viewport-size.js +3 -3
- package/cjs/use-window-event/use-window-event.js +2 -2
- package/cjs/use-window-scroll/use-window-scroll.js +2 -2
- package/cjs/utils/clamp/clamp.js +1 -1
- package/cjs/utils/clamp/clamp.js.map +1 -1
- package/cjs/utils/shallow-equal/shallow-equal.js +7 -5
- package/cjs/utils/shallow-equal/shallow-equal.js.map +1 -1
- package/esm/index.js +5 -4
- package/esm/index.js.map +1 -1
- package/esm/use-counter/use-counter.js +35 -0
- package/esm/use-counter/use-counter.js.map +1 -0
- package/esm/use-document-visibility/use-document-visibility.js +19 -0
- package/esm/use-document-visibility/use-document-visibility.js.map +1 -0
- package/esm/use-focus-return/use-focus-return.js +1 -1
- package/esm/use-focus-return/use-focus-return.js.map +1 -1
- package/esm/use-id/use-id.js +17 -5
- package/esm/use-id/use-id.js.map +1 -1
- package/esm/use-intersection/use-intersection.js +1 -1
- package/esm/use-intersection/use-intersection.js.map +1 -1
- package/esm/use-local-storage/use-local-storage.js +1 -2
- package/esm/use-local-storage/use-local-storage.js.map +1 -1
- package/esm/use-merged-ref/use-merged-ref.js +3 -5
- package/esm/use-merged-ref/use-merged-ref.js.map +1 -1
- package/esm/use-move/use-move.js +4 -4
- package/esm/use-move/use-move.js.map +1 -1
- package/esm/use-network/use-network.js +5 -9
- package/esm/use-network/use-network.js.map +1 -1
- package/esm/use-pagination/use-pagination.js +1 -2
- package/esm/use-pagination/use-pagination.js.map +1 -1
- package/esm/use-timeout/use-timeout.js +29 -0
- package/esm/use-timeout/use-timeout.js.map +1 -0
- package/esm/use-toggle/use-toggle.js +3 -6
- package/esm/use-toggle/use-toggle.js.map +1 -1
- package/esm/use-uncontrolled/use-uncontrolled.js +8 -26
- package/esm/use-uncontrolled/use-uncontrolled.js.map +1 -1
- package/esm/utils/clamp/clamp.js +1 -1
- package/esm/utils/clamp/clamp.js.map +1 -1
- package/esm/utils/shallow-equal/shallow-equal.js +7 -5
- package/esm/utils/shallow-equal/shallow-equal.js.map +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/use-counter/use-counter.d.ts +10 -0
- package/lib/use-counter/use-counter.d.ts.map +1 -0
- package/lib/use-document-visibility/use-document-visibility.d.ts +2 -0
- package/lib/use-document-visibility/use-document-visibility.d.ts.map +1 -0
- package/lib/use-id/use-id.d.ts +1 -1
- package/lib/use-id/use-id.d.ts.map +1 -1
- package/lib/use-intersection/use-intersection.d.ts +4 -1
- package/lib/use-intersection/use-intersection.d.ts.map +1 -1
- package/lib/use-local-storage/use-local-storage.d.ts +0 -1
- package/lib/use-local-storage/use-local-storage.d.ts.map +1 -1
- package/lib/use-merged-ref/use-merged-ref.d.ts +1 -1
- package/lib/use-merged-ref/use-merged-ref.d.ts.map +1 -1
- package/lib/use-network/use-network.d.ts +6 -4
- package/lib/use-network/use-network.d.ts.map +1 -1
- package/lib/use-pagination/use-pagination.d.ts.map +1 -1
- package/lib/use-timeout/use-timeout.d.ts +7 -0
- package/lib/use-timeout/use-timeout.d.ts.map +1 -0
- package/lib/use-toggle/use-toggle.d.ts +1 -2
- package/lib/use-toggle/use-toggle.d.ts.map +1 -1
- package/lib/use-uncontrolled/use-uncontrolled.d.ts +11 -9
- package/lib/use-uncontrolled/use-uncontrolled.d.ts.map +1 -1
- package/lib/utils/clamp/clamp.d.ts +1 -7
- package/lib/utils/clamp/clamp.d.ts.map +1 -1
- package/lib/utils/shallow-equal/shallow-equal.d.ts.map +1 -1
- package/package.json +1 -1
- package/cjs/use-form/use-form.js +0 -91
- package/cjs/use-form/use-form.js.map +0 -1
- package/cjs/use-uuid/use-uuid.js +0 -18
- package/cjs/use-uuid/use-uuid.js.map +0 -1
- package/esm/use-form/use-form.js +0 -87
- package/esm/use-form/use-form.js.map +0 -1
- package/esm/use-uuid/use-uuid.js +0 -14
- package/esm/use-uuid/use-uuid.js.map +0 -1
- package/lib/use-form/use-form.d.ts +0 -37
- package/lib/use-form/use-form.d.ts.map +0 -1
- package/lib/use-uuid/use-uuid.d.ts +0 -2
- package/lib/use-uuid/use-uuid.d.ts.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
function useTimeout(fn, delay, options = { autoInvoke: false }) {
|
|
8
|
+
const timeoutRef = React.useRef(null);
|
|
9
|
+
const start = () => {
|
|
10
|
+
if (!timeoutRef.current) {
|
|
11
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
12
|
+
fn();
|
|
13
|
+
timeoutRef.current = null;
|
|
14
|
+
}, delay);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const clear = () => {
|
|
18
|
+
if (timeoutRef.current) {
|
|
19
|
+
window.clearTimeout(timeoutRef.current);
|
|
20
|
+
timeoutRef.current = null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (options.autoInvoke) {
|
|
25
|
+
start();
|
|
26
|
+
}
|
|
27
|
+
return clear;
|
|
28
|
+
}, [delay]);
|
|
29
|
+
return { start, clear };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.useTimeout = useTimeout;
|
|
33
|
+
//# sourceMappingURL=use-timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-timeout.js","sources":["../../src/use-timeout/use-timeout.ts"],"sourcesContent":["import { useRef, useEffect } from 'react';\n\nexport function useTimeout(\n fn: () => void,\n delay: number,\n options: { autoInvoke: boolean } = { autoInvoke: false }\n) {\n const timeoutRef = useRef<number>(null);\n\n const start = () => {\n if (!timeoutRef.current) {\n timeoutRef.current = window.setTimeout(() => {\n fn();\n timeoutRef.current = null;\n }, delay);\n }\n };\n\n const clear = () => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n\n useEffect(() => {\n if (options.autoInvoke) {\n start();\n }\n\n return clear;\n }, [delay]);\n\n return { start, clear };\n}\n"],"names":["useRef","useEffect"],"mappings":";;;;;;AACO,SAAS,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;AACvE,EAAE,MAAM,UAAU,GAAGA,YAAM,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,KAAK,GAAG,MAAM;AACtB,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;AAC7B,MAAM,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM;AACnD,QAAQ,EAAE,EAAE,CAAC;AACb,QAAQ,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAClC,OAAO,EAAE,KAAK,CAAC,CAAC;AAChB,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,MAAM,KAAK,GAAG,MAAM;AACtB,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE;AAC5B,MAAM,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC9C,MAAM,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;AAChC,KAAK;AACL,GAAG,CAAC;AACJ,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE;AAC5B,MAAM,KAAK,EAAE,CAAC;AACd,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B;;;;"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
|
|
7
|
-
function useToggle(
|
|
8
|
-
const [state, setState] =
|
|
7
|
+
function useToggle(options) {
|
|
8
|
+
const [state, setState] = React.useState(options[0]);
|
|
9
9
|
const toggle = (value) => {
|
|
10
10
|
if (typeof value !== "undefined") {
|
|
11
11
|
setState(value);
|
|
@@ -20,10 +20,6 @@ function useToggle(initialValue, options) {
|
|
|
20
20
|
};
|
|
21
21
|
return [state, toggle];
|
|
22
22
|
}
|
|
23
|
-
function useBooleanToggle(initialValue = false) {
|
|
24
|
-
return useToggle(initialValue, [true, false]);
|
|
25
|
-
}
|
|
26
23
|
|
|
27
|
-
exports.useBooleanToggle = useBooleanToggle;
|
|
28
24
|
exports.useToggle = useToggle;
|
|
29
25
|
//# sourceMappingURL=use-toggle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useToggle<T>(
|
|
1
|
+
{"version":3,"file":"use-toggle.js","sources":["../../src/use-toggle/use-toggle.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useToggle<T>(options: [T, T]) {\n const [state, setState] = useState(options[0]);\n\n const toggle = (value?: React.SetStateAction<T>) => {\n if (typeof value !== 'undefined') {\n setState(value);\n } else {\n setState((current) => {\n if (current === options[0]) {\n return options[1];\n }\n\n return options[0];\n });\n }\n };\n\n return [state, toggle] as const;\n}\n"],"names":["useState"],"mappings":";;;;;;AACO,SAAS,SAAS,CAAC,OAAO,EAAE;AACnC,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,EAAE,MAAM,MAAM,GAAG,CAAC,KAAK,KAAK;AAC5B,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;AACtC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtB,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,CAAC,OAAO,KAAK;AAC5B,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE;AACpC,UAAU,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5B,SAAS;AACT,QAAQ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1B,OAAO,CAAC,CAAC;AACT,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzB;;;;"}
|
|
@@ -2,39 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
|
|
7
7
|
function useUncontrolled({
|
|
8
8
|
value,
|
|
9
9
|
defaultValue,
|
|
10
10
|
finalValue,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
onValueUpdate
|
|
11
|
+
onChange = () => {
|
|
12
|
+
}
|
|
14
13
|
}) {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let effectiveValue = shouldBeControlled ? value : uncontrolledValue;
|
|
20
|
-
if (!shouldBeControlled && modeRef.current === "controlled") {
|
|
21
|
-
effectiveValue = finalValue;
|
|
14
|
+
const controlled = React.useRef(value !== void 0);
|
|
15
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue !== void 0 ? defaultValue : finalValue);
|
|
16
|
+
if (controlled.current) {
|
|
17
|
+
return [value, onChange, true];
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
const mode = modeRef.current;
|
|
25
|
-
const handleChange = (nextValue) => {
|
|
26
|
-
typeof onChange === "function" && onChange(nextValue);
|
|
27
|
-
if (mode === "uncontrolled") {
|
|
28
|
-
setUncontrolledValue(nextValue);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
react.useEffect(() => {
|
|
32
|
-
if (mode === "uncontrolled") {
|
|
33
|
-
setUncontrolledValue(effectiveValue);
|
|
34
|
-
}
|
|
35
|
-
typeof onValueUpdate === "function" && onValueUpdate(effectiveValue);
|
|
36
|
-
}, [mode, effectiveValue]);
|
|
37
|
-
return [effectiveValue, handleChange, modeRef.current];
|
|
19
|
+
return [uncontrolledValue, setUncontrolledValue, false];
|
|
38
20
|
}
|
|
39
21
|
|
|
40
22
|
exports.useUncontrolled = useUncontrolled;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-uncontrolled.js","sources":["../../src/use-uncontrolled/use-uncontrolled.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"use-uncontrolled.js","sources":["../../src/use-uncontrolled/use-uncontrolled.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\ninterface UseUncontrolledInput<T> {\n /** Value for controlled state */\n value?: T;\n\n /** Initial value for uncontrolled state */\n defaultValue?: T;\n\n /** Final value for uncontrolled state when value and defaultValue are not provided */\n finalValue?: T;\n\n /** Controlled state onChange handler */\n onChange?(value: T): void;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n onChange = () => {},\n}: UseUncontrolledInput<T>): [T, (value: T) => void, boolean] {\n const controlled = useRef(value !== undefined);\n const [uncontrolledValue, setUncontrolledValue] = useState(\n defaultValue !== undefined ? defaultValue : finalValue\n );\n\n if (controlled.current) {\n return [value as T, onChange, true];\n }\n\n return [uncontrolledValue as T, setUncontrolledValue, false];\n}\n"],"names":["useRef","useState"],"mappings":";;;;;;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,KAAK;AACP,EAAE,YAAY;AACd,EAAE,UAAU;AACZ,EAAE,QAAQ,GAAG,MAAM;AACnB,GAAG;AACH,CAAC,EAAE;AACH,EAAE,MAAM,UAAU,GAAGA,YAAM,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC;AAC9C,EAAE,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAGC,cAAQ,CAAC,YAAY,KAAK,KAAK,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC,CAAC;AAClH,EAAE,IAAI,UAAU,CAAC,OAAO,EAAE;AAC1B,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AACnC,GAAG;AACH,EAAE,OAAO,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;AAC1D;;;;"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
|
|
7
7
|
function useValidatedState(initialValue, validation) {
|
|
8
|
-
const [value, setValue] =
|
|
9
|
-
const [lastValidValue, setLastValidValue] =
|
|
10
|
-
const [valid, setValid] =
|
|
8
|
+
const [value, setValue] = React.useState(initialValue);
|
|
9
|
+
const [lastValidValue, setLastValidValue] = React.useState(validation(initialValue) ? initialValue : void 0);
|
|
10
|
+
const [valid, setValid] = React.useState(validation(initialValue));
|
|
11
11
|
const onChange = (val) => {
|
|
12
12
|
if (validation(val)) {
|
|
13
13
|
setLastValidValue(val);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
var useWindowEvent = require('../use-window-event/use-window-event.js');
|
|
7
7
|
|
|
8
8
|
const eventListerOptions = {
|
|
@@ -10,11 +10,11 @@ const eventListerOptions = {
|
|
|
10
10
|
};
|
|
11
11
|
const browser = typeof window !== "undefined";
|
|
12
12
|
function useViewportSize() {
|
|
13
|
-
const [windowSize, setWindowSize] =
|
|
13
|
+
const [windowSize, setWindowSize] = React.useState({
|
|
14
14
|
width: browser ? window.innerWidth : 0,
|
|
15
15
|
height: browser ? window.innerHeight : 0
|
|
16
16
|
});
|
|
17
|
-
const setSize =
|
|
17
|
+
const setSize = React.useCallback(() => {
|
|
18
18
|
setWindowSize({
|
|
19
19
|
width: window.innerWidth || 0,
|
|
20
20
|
height: window.innerHeight || 0
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
|
|
7
7
|
function useWindowEvent(type, listener, options) {
|
|
8
|
-
|
|
8
|
+
React.useEffect(() => {
|
|
9
9
|
window.addEventListener(type, listener, options);
|
|
10
10
|
return () => window.removeEventListener(type, listener, options);
|
|
11
11
|
}, []);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var React = require('react');
|
|
6
6
|
var useWindowEvent = require('../use-window-event/use-window-event.js');
|
|
7
7
|
|
|
8
8
|
function getScrollPosition() {
|
|
@@ -21,7 +21,7 @@ function scrollTo({ x, y }) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
function useWindowScroll() {
|
|
24
|
-
const [position, setPosition] =
|
|
24
|
+
const [position, setPosition] = React.useState(getScrollPosition());
|
|
25
25
|
useWindowEvent.useWindowEvent("scroll", () => setPosition(getScrollPosition()));
|
|
26
26
|
useWindowEvent.useWindowEvent("resize", () => setPosition(getScrollPosition()));
|
|
27
27
|
return [position, scrollTo];
|
package/cjs/utils/clamp/clamp.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.js","sources":["../../../src/utils/clamp/clamp.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"clamp.js","sources":["../../../src/utils/clamp/clamp.ts"],"sourcesContent":["export function clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE;AACvC,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C;;;;"}
|
|
@@ -11,17 +11,19 @@ function shallowEqual(a, b) {
|
|
|
11
11
|
}
|
|
12
12
|
const keys = Object.keys(a);
|
|
13
13
|
const { length } = keys;
|
|
14
|
+
if (length !== Object.keys(b).length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
14
17
|
for (let i = 0; i < length; i += 1) {
|
|
15
|
-
|
|
18
|
+
const key = keys[i];
|
|
19
|
+
if (!(key in b)) {
|
|
16
20
|
return false;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
for (let i = 0; i < length; i += 1) {
|
|
20
|
-
if (a[keys[i]] !== b[keys[i]]) {
|
|
22
|
+
if (a[key] !== b[key]) {
|
|
21
23
|
return false;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
return
|
|
26
|
+
return true;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
exports.shallowEqual = shallowEqual;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shallow-equal.js","sources":["../../../src/utils/shallow-equal/shallow-equal.ts"],"sourcesContent":["export function shallowEqual(a: any, b: any) {\n if (a === b) {\n return true;\n }\n\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n\n const keys = Object.keys(a);\n const { length } = keys;\n\n for (let i = 0; i < length; i += 1) {\n
|
|
1
|
+
{"version":3,"file":"shallow-equal.js","sources":["../../../src/utils/shallow-equal/shallow-equal.ts"],"sourcesContent":["export function shallowEqual(a: any, b: any) {\n if (a === b) {\n return true;\n }\n\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n\n const keys = Object.keys(a);\n const { length } = keys;\n\n if (length !== Object.keys(b).length) {\n return false;\n }\n\n for (let i = 0; i < length; i += 1) {\n const key = keys[i];\n\n if (!(key in b)) {\n return false;\n }\n\n if (a[key] !== b[key]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE;AACnC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;AACf,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,IAAI,EAAE,CAAC,YAAY,MAAM,CAAC,IAAI,EAAE,CAAC,YAAY,MAAM,CAAC,EAAE;AACxD,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9B,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;AAC1B,EAAE,IAAI,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;AACxC,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;AACtC,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,IAAI,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE;AACrB,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE;AAC3B,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd;;;;"}
|
package/esm/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
export { useClickOutside } from './use-click-outside/use-click-outside.js';
|
|
2
2
|
export { useClipboard } from './use-clipboard/use-clipboard.js';
|
|
3
3
|
export { useColorScheme } from './use-color-scheme/use-color-scheme.js';
|
|
4
|
+
export { useCounter } from './use-counter/use-counter.js';
|
|
4
5
|
export { useDebouncedValue } from './use-debounced-value/use-debounced-value.js';
|
|
5
6
|
export { useDocumentTitle } from './use-document-title/use-document-title.js';
|
|
7
|
+
export { useDocumentVisibility } from './use-document-visibility/use-document-visibility.js';
|
|
6
8
|
export { useFocusReturn } from './use-focus-return/use-focus-return.js';
|
|
7
9
|
export { useDidUpdate } from './use-did-update/use-did-update.js';
|
|
8
10
|
export { useFocusTrap } from './use-focus-trap/use-focus-trap.js';
|
|
9
11
|
export { useForceUpdate } from './use-force-update/use-force-update.js';
|
|
10
|
-
export { useForm } from './use-form/use-form.js';
|
|
11
12
|
export { useId } from './use-id/use-id.js';
|
|
12
13
|
export { useIdle } from './use-idle/use-idle.js';
|
|
13
14
|
export { useInterval } from './use-interval/use-interval.js';
|
|
14
15
|
export { useIsomorphicEffect } from './use-isomorphic-effect/use-isomorphic-effect.js';
|
|
15
16
|
export { useListState } from './use-list-state/use-list-state.js';
|
|
16
|
-
export { useLocalStorage
|
|
17
|
+
export { useLocalStorage } from './use-local-storage/use-local-storage.js';
|
|
17
18
|
export { useMediaQuery } from './use-media-query/use-media-query.js';
|
|
18
19
|
export { mergeRefs, useMergedRef } from './use-merged-ref/use-merged-ref.js';
|
|
19
20
|
export { useMouse } from './use-mouse/use-mouse.js';
|
|
@@ -26,7 +27,7 @@ export { useScrollIntoView } from './use-scroll-into-view/use-scroll-into-view.j
|
|
|
26
27
|
export { useElementSize, useResizeObserver } from './use-resize-observer/use-resize-observer.js';
|
|
27
28
|
export { useScrollLock } from './use-scroll-lock/use-scroll-lock.js';
|
|
28
29
|
export { useShallowEffect } from './use-shallow-effect/use-shallow-effect.js';
|
|
29
|
-
export {
|
|
30
|
+
export { useToggle } from './use-toggle/use-toggle.js';
|
|
30
31
|
export { useUncontrolled } from './use-uncontrolled/use-uncontrolled.js';
|
|
31
32
|
export { useViewportSize } from './use-viewport-size/use-viewport-size.js';
|
|
32
33
|
export { useWindowEvent } from './use-window-event/use-window-event.js';
|
|
@@ -37,7 +38,6 @@ export { useHotkeys } from './use-hotkeys/use-hotkeys.js';
|
|
|
37
38
|
export { useFullscreen } from './use-fullscreen/use-fullscreen.js';
|
|
38
39
|
export { useLogger } from './use-logger/use-logger.js';
|
|
39
40
|
export { useHover } from './use-hover/use-hover.js';
|
|
40
|
-
export { useUuid } from './use-uuid/use-uuid.js';
|
|
41
41
|
export { useValidatedState } from './use-validated-state/use-validated-state.js';
|
|
42
42
|
export { useOs } from './use-os/use-os.js';
|
|
43
43
|
export { useSetState } from './use-set-state/use-set-state.js';
|
|
@@ -46,6 +46,7 @@ export { useEventListener } from './use-event-listener/use-event-listener.js';
|
|
|
46
46
|
export { useDisclosure } from './use-disclosure/use-disclosure.js';
|
|
47
47
|
export { useFocusWithin } from './use-focus-within/use-focus-within.js';
|
|
48
48
|
export { useNetwork } from './use-network/use-network.js';
|
|
49
|
+
export { useTimeout } from './use-timeout/use-timeout.js';
|
|
49
50
|
export { getHotkeyHandler } from './use-hotkeys/parse-hotkey.js';
|
|
50
51
|
export { assignRef } from './utils/assign-ref/assign-ref.js';
|
|
51
52
|
export { clamp } from './utils/clamp/clamp.js';
|
package/esm/index.js.map
CHANGED
|
@@ -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,35 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { clamp } from '../utils/clamp/clamp.js';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_OPTIONS = {
|
|
21
|
+
min: -Infinity,
|
|
22
|
+
max: Infinity
|
|
23
|
+
};
|
|
24
|
+
function useCounter(initialValue = 0, options) {
|
|
25
|
+
const { min, max } = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
26
|
+
const [count, setCount] = useState(clamp(initialValue, min, max));
|
|
27
|
+
const increment = (delta = 1) => setCount((current) => clamp(current + delta, min, max));
|
|
28
|
+
const decrement = (delta = 1) => setCount((current) => clamp(current - delta, min, max));
|
|
29
|
+
const set = (value) => setCount(clamp(value, min, max));
|
|
30
|
+
const reset = () => setCount(clamp(initialValue, min, max));
|
|
31
|
+
return [count, { increment, decrement, set, reset }];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useCounter };
|
|
35
|
+
//# sourceMappingURL=use-counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-counter.js","sources":["../../src/use-counter/use-counter.ts"],"sourcesContent":["import { useState } from 'react';\nimport { clamp } from '../utils';\n\nconst DEFAULT_OPTIONS = {\n min: -Infinity,\n max: Infinity,\n};\n\nexport function useCounter(initialValue = 0, options?: Partial<{ min: number; max: number }>) {\n const { min, max } = { ...DEFAULT_OPTIONS, ...options };\n const [count, setCount] = useState<number>(clamp(initialValue, min, max));\n\n const increment = (delta = 1) => setCount((current) => clamp(current + delta, min, max));\n const decrement = (delta = 1) => setCount((current) => clamp(current - delta, min, max));\n const set = (value: number) => setCount(clamp(value, min, max));\n const reset = () => setCount(clamp(initialValue, min, max));\n\n return [count, { increment, decrement, set, reset }] as const;\n}\n"],"names":[],"mappings":";;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY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G,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC3F,EAAE,MAAM,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC3F,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1D,EAAE,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9D,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;AACvD;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const getVisibility = () => {
|
|
4
|
+
if (typeof document === "undefined")
|
|
5
|
+
return "visible";
|
|
6
|
+
return document.visibilityState;
|
|
7
|
+
};
|
|
8
|
+
function useDocumentVisibility() {
|
|
9
|
+
const [documentVisibility, setDocumentVisibility] = useState(getVisibility());
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const listener = () => setDocumentVisibility(getVisibility());
|
|
12
|
+
document.addEventListener("visibilitychange", listener);
|
|
13
|
+
return () => document.removeEventListener("visibilitychange", listener);
|
|
14
|
+
}, []);
|
|
15
|
+
return documentVisibility;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useDocumentVisibility };
|
|
19
|
+
//# sourceMappingURL=use-document-visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-document-visibility.js","sources":["../../src/use-document-visibility/use-document-visibility.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getVisibility = () => {\n if (typeof document === 'undefined') return 'visible';\n\n return document.visibilityState;\n};\n\nexport function useDocumentVisibility(): DocumentVisibilityState {\n const [documentVisibility, setDocumentVisibility] = useState<DocumentVisibilityState>(\n getVisibility()\n );\n\n useEffect(() => {\n const listener = () => setDocumentVisibility(getVisibility());\n\n document.addEventListener('visibilitychange', listener);\n\n return () => document.removeEventListener('visibilitychange', listener);\n }, []);\n\n return documentVisibility;\n}\n"],"names":[],"mappings":";;AACA,MAAM,aAAa,GAAG,MAAM;AAC5B,EAAE,IAAI,OAAO,QAAQ,KAAK,WAAW;AACrC,IAAI,OAAO,SAAS,CAAC;AACrB,EAAE,OAAO,QAAQ,CAAC,eAAe,CAAC;AAClC,CAAC,CAAC;AACK,SAAS,qBAAqB,GAAG;AACxC,EAAE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;AAChF,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,aAAa,EAAE,CAAC,CAAC;AAClE,IAAI,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC5D,IAAI,OAAO,MAAM,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC5E,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,kBAAkB,CAAC;AAC5B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-focus-return.js","sources":["../../src/use-focus-return/use-focus-return.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useDidUpdate } from '../use-did-update/use-did-update';\n\ninterface UseFocusReturn {\n opened: boolean;\n transitionDuration: number;\n shouldReturnFocus?: boolean;\n}\n\n/** Returns focus to last active element, used in Modal and Drawer */\nexport function useFocusReturn({\n opened,\n transitionDuration,\n shouldReturnFocus = true,\n}: UseFocusReturn) {\n const lastActiveElement = useRef<HTMLElement>();\n const returnFocus = () => {\n if (\n lastActiveElement.current &&\n 'focus' in lastActiveElement.current &&\n typeof lastActiveElement.current.focus === 'function'\n ) {\n lastActiveElement.current?.focus();\n }\n };\n\n useDidUpdate(() => {\n let timeout = -1;\n\n const clearFocusTimeout = (event: KeyboardEvent) => {\n if (event.
|
|
1
|
+
{"version":3,"file":"use-focus-return.js","sources":["../../src/use-focus-return/use-focus-return.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { useDidUpdate } from '../use-did-update/use-did-update';\n\ninterface UseFocusReturn {\n opened: boolean;\n transitionDuration: number;\n shouldReturnFocus?: boolean;\n}\n\n/** Returns focus to last active element, used in Modal and Drawer */\nexport function useFocusReturn({\n opened,\n transitionDuration,\n shouldReturnFocus = true,\n}: UseFocusReturn) {\n const lastActiveElement = useRef<HTMLElement>();\n const returnFocus = () => {\n if (\n lastActiveElement.current &&\n 'focus' in lastActiveElement.current &&\n typeof lastActiveElement.current.focus === 'function'\n ) {\n lastActiveElement.current?.focus();\n }\n };\n\n useDidUpdate(() => {\n let timeout = -1;\n\n const clearFocusTimeout = (event: KeyboardEvent) => {\n if (event.key === 'Tab') {\n window.clearTimeout(timeout);\n }\n };\n\n document.addEventListener('keydown', clearFocusTimeout);\n\n if (opened) {\n lastActiveElement.current = document.activeElement as HTMLElement;\n } else if (shouldReturnFocus) {\n timeout = window.setTimeout(returnFocus, transitionDuration + 10);\n }\n\n return () => {\n window.clearTimeout(timeout);\n document.removeEventListener('keydown', clearFocusTimeout);\n };\n }, [opened]);\n\n return returnFocus;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,cAAc,CAAC;AAC/B,EAAE,MAAM;AACR,EAAE,kBAAkB;AACpB,EAAE,iBAAiB,GAAG,IAAI;AAC1B,CAAC,EAAE;AACH,EAAE,MAAM,iBAAiB,GAAG,MAAM,EAAE,CAAC;AACrC,EAAE,MAAM,WAAW,GAAG,MAAM;AAC5B,IAAI,IAAI,EAAE,CA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
1
|
+
import React, { useState, useLayoutEffect, useEffect } from 'react';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;
|
|
4
|
+
const useIsomorphicEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
5
|
+
const useReactId = React["useId".toString()] || (() => void 0);
|
|
6
|
+
function useClientId() {
|
|
7
|
+
const [uuid, setUuid] = useState("");
|
|
8
|
+
useIsomorphicEffect(() => {
|
|
9
|
+
setUuid(randomId());
|
|
10
|
+
}, []);
|
|
11
|
+
return uuid;
|
|
12
|
+
}
|
|
13
|
+
function getReactId() {
|
|
14
|
+
const id = useReactId();
|
|
15
|
+
return id ? `mantine-${id.replaceAll(":", "")}` : "";
|
|
16
|
+
}
|
|
17
|
+
function useId(staticId) {
|
|
18
|
+
return typeof staticId === "string" ? staticId : getReactId() || useClientId();
|
|
7
19
|
}
|
|
8
20
|
|
|
9
21
|
export { useId };
|
package/esm/use-id/use-id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"use-id.js","sources":["../../src/use-id/use-id.ts"],"sourcesContent":["import React, { useState, useEffect, useLayoutEffect } from 'react';\n\nconst randomId = () => `mantine-${Math.random().toString(36).slice(2, 11)}`;\n\nconst useIsomorphicEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;\n\nconst useReactId: () => string | undefined =\n (React as any)['useId'.toString()] || (() => undefined);\n\nfunction useClientId() {\n const [uuid, setUuid] = useState('');\n\n useIsomorphicEffect(() => {\n setUuid(randomId());\n }, []);\n\n return uuid;\n}\n\nfunction getReactId() {\n const id = useReactId();\n return id ? `mantine-${id.replaceAll(':', '')}` : '';\n}\n\nexport function useId(staticId?: string) {\n return typeof staticId === 'string' ? staticId : getReactId() || useClientId();\n}\n"],"names":[],"mappings":";;AACA,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,MAAM,mBAAmB,GAAG,OAAO,QAAQ,KAAK,WAAW,GAAG,eAAe,GAAG,SAAS,CAAC;AAC1F,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC;AAC/D,SAAS,WAAW,GAAG;AACvB,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvC,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxB,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACD,SAAS,UAAU,GAAG;AACtB,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;AAC1B,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACvD,CAAC;AACM,SAAS,KAAK,CAAC,QAAQ,EAAE;AAChC,EAAE,OAAO,OAAO,QAAQ,KAAK,QAAQ,GAAG,QAAQ,GAAG,UAAU,EAAE,IAAI,WAAW,EAAE,CAAC;AACjF;;;;"}
|
|
@@ -17,7 +17,7 @@ function useIntersection(options) {
|
|
|
17
17
|
}, options);
|
|
18
18
|
observer.current.observe(element);
|
|
19
19
|
}, [options == null ? void 0 : options.rootMargin, options == null ? void 0 : options.root, options == null ? void 0 : options.threshold]);
|
|
20
|
-
return
|
|
20
|
+
return { ref, entry };
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export { useIntersection };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intersection.js","sources":["../../src/use-intersection/use-intersection.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nexport function useIntersection<T extends HTMLElement = any>(\n options?: ConstructorParameters<typeof IntersectionObserver>[1]\n)
|
|
1
|
+
{"version":3,"file":"use-intersection.js","sources":["../../src/use-intersection/use-intersection.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nexport function useIntersection<T extends HTMLElement = any>(\n options?: ConstructorParameters<typeof IntersectionObserver>[1]\n) {\n const [entry, setEntry] = useState<IntersectionObserverEntry>(null);\n\n const observer = useRef<IntersectionObserver>();\n\n const ref = useCallback(\n (element: T | null) => {\n if (observer.current) {\n observer.current.disconnect();\n observer.current = null;\n }\n\n if (element === null) {\n setEntry(null);\n return;\n }\n\n observer.current = new IntersectionObserver(([_entry]) => {\n setEntry(_entry);\n }, options);\n\n observer.current.observe(element);\n },\n [options?.rootMargin, options?.root, options?.threshold]\n );\n\n return { ref, entry };\n}\n"],"names":[],"mappings":";;AACO,SAAS,eAAe,CAAC,OAAO,EAAE;AACzC,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3C,EAAE,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAC5B,EAAE,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,OAAO,KAAK;AACvC,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE;AAC1B,MAAM,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;AACpC,MAAM,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;AAC9B,KAAK;AACL,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;AAC1B,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;AACrB,MAAM,OAAO;AACb,KAAK;AACL,IAAI,QAAQ,CAAC,OAAO,GAAG,IAAI,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;AAC9D,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvB,KAAK,EAAE,OAAO,CAAC,CAAC;AAChB,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACtC,GAAG,EAAE,CAAC,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,UAAU,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7I,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB;;;;"}
|
|
@@ -62,7 +62,6 @@ function useLocalStorage({
|
|
|
62
62
|
}, []);
|
|
63
63
|
return [value === void 0 ? defaultValue : value, setLocalStorageValue];
|
|
64
64
|
}
|
|
65
|
-
const useLocalStorageValue = useLocalStorage;
|
|
66
65
|
|
|
67
|
-
export { useLocalStorage
|
|
66
|
+
export { useLocalStorage };
|
|
68
67
|
//# sourceMappingURL=use-local-storage.js.map
|
|
@@ -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 /** 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 window.dispatchEvent(\n new CustomEvent('mantine-local-storage', { detail: { key, value: val(current) } })\n );\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n window.dispatchEvent(\n new CustomEvent('mantine-local-storage', { detail: { key, value: val } })\n );\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 useWindowEvent('mantine-local-storage', (event) => {\n if (event.detail.key === key) {\n setValue(event.detail.value);\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
|
|
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 window.dispatchEvent(\n new CustomEvent('mantine-local-storage', { detail: { key, value: val(current) } })\n );\n return result;\n });\n } else {\n window.localStorage.setItem(key, serialize(val));\n window.dispatchEvent(\n new CustomEvent('mantine-local-storage', { detail: { key, value: val } })\n );\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 useWindowEvent('mantine-local-storage', (event) => {\n if (event.detail.key === key) {\n setValue(event.detail.value);\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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L,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;;;;"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { assignRef } from '../utils/assign-ref/assign-ref.js';
|
|
3
3
|
|
|
4
|
-
function useMergedRef(...refs) {
|
|
5
|
-
return useCallback((node) => {
|
|
6
|
-
refs.forEach((ref) => assignRef(ref, node));
|
|
7
|
-
}, refs);
|
|
8
|
-
}
|
|
9
4
|
function mergeRefs(...refs) {
|
|
10
5
|
return (node) => {
|
|
11
6
|
refs.forEach((ref) => assignRef(ref, node));
|
|
12
7
|
};
|
|
13
8
|
}
|
|
9
|
+
function useMergedRef(...refs) {
|
|
10
|
+
return useCallback(mergeRefs(...refs), refs);
|
|
11
|
+
}
|
|
14
12
|
|
|
15
13
|
export { mergeRefs, useMergedRef };
|
|
16
14
|
//# sourceMappingURL=use-merged-ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-merged-ref.js","sources":["../../src/use-merged-ref/use-merged-ref.ts"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { assignRef } from '../utils';\n\ntype Ref<T> = React.Dispatch<React.SetStateAction<T>> | React.ForwardedRef<T>;\n\nexport function
|
|
1
|
+
{"version":3,"file":"use-merged-ref.js","sources":["../../src/use-merged-ref/use-merged-ref.ts"],"sourcesContent":["import React, { useCallback } from 'react';\nimport { assignRef } from '../utils';\n\ntype Ref<T> = React.Dispatch<React.SetStateAction<T>> | React.ForwardedRef<T>;\n\nexport function mergeRefs<T = any>(...refs: Ref<T>[]) {\n return (node: T | null) => {\n refs.forEach((ref) => assignRef(ref, node));\n };\n}\n\nexport function useMergedRef<T = any>(...refs: Ref<T>[]) {\n return useCallback(mergeRefs(...refs), refs);\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE;AACnC,EAAE,OAAO,CAAC,IAAI,KAAK;AACnB,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,YAAY,CAAC,GAAG,IAAI,EAAE;AACtC,EAAE,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;AAC/C;;;;"}
|
package/esm/use-move/use-move.js
CHANGED
|
@@ -2,8 +2,8 @@ import { useRef, useState, useEffect } from 'react';
|
|
|
2
2
|
import { clamp } from '../utils/clamp/clamp.js';
|
|
3
3
|
|
|
4
4
|
const clampUseMovePosition = (position) => ({
|
|
5
|
-
x: clamp(
|
|
6
|
-
y: clamp(
|
|
5
|
+
x: clamp(position.x, 0, 1),
|
|
6
|
+
y: clamp(position.y, 0, 1)
|
|
7
7
|
});
|
|
8
8
|
function useMove(onChange, handlers, dir = "ltr") {
|
|
9
9
|
const ref = useRef();
|
|
@@ -22,10 +22,10 @@ function useMove(onChange, handlers, dir = "ltr") {
|
|
|
22
22
|
ref.current.style.userSelect = "none";
|
|
23
23
|
const rect = ref.current.getBoundingClientRect();
|
|
24
24
|
if (rect.width && rect.height) {
|
|
25
|
-
const _x = clamp(
|
|
25
|
+
const _x = clamp((x - rect.left) / rect.width, 0, 1);
|
|
26
26
|
onChange({
|
|
27
27
|
x: dir === "ltr" ? _x : 1 - _x,
|
|
28
|
-
y: clamp(
|
|
28
|
+
y: clamp((y - rect.top) / rect.height, 0, 1)
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}
|