@kubed/hooks 0.0.1
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 +31 -0
- package/cjs/index.js.map +1 -0
- package/cjs/useClipboard/index.js +32 -0
- package/cjs/useClipboard/index.js.map +1 -0
- package/cjs/useForceUpdate/index.js +14 -0
- package/cjs/useForceUpdate/index.js.map +1 -0
- package/cjs/useId/index.js +14 -0
- package/cjs/useId/index.js.map +1 -0
- package/cjs/useLocalStorage/index.js +39 -0
- package/cjs/useLocalStorage/index.js.map +1 -0
- package/cjs/useMediaQuery/index.js +36 -0
- package/cjs/useMediaQuery/index.js.map +1 -0
- package/cjs/useQueue/index.js +37 -0
- package/cjs/useQueue/index.js.map +1 -0
- package/cjs/useReducedMotion/index.js +12 -0
- package/cjs/useReducedMotion/index.js.map +1 -0
- package/cjs/useToggle/index.js +29 -0
- package/cjs/useToggle/index.js.map +1 -0
- package/cjs/useUncontrolled/index.js +41 -0
- package/cjs/useUncontrolled/index.js.map +1 -0
- package/cjs/useWindowEvent/index.js +15 -0
- package/cjs/useWindowEvent/index.js.map +1 -0
- package/cjs/utils/index.js +10 -0
- package/cjs/utils/index.js.map +1 -0
- package/esm/index.js +12 -0
- package/esm/index.js.map +1 -0
- package/esm/useClipboard/index.js +28 -0
- package/esm/useClipboard/index.js.map +1 -0
- package/esm/useForceUpdate/index.js +10 -0
- package/esm/useForceUpdate/index.js.map +1 -0
- package/esm/useId/index.js +10 -0
- package/esm/useId/index.js.map +1 -0
- package/esm/useLocalStorage/index.js +35 -0
- package/esm/useLocalStorage/index.js.map +1 -0
- package/esm/useMediaQuery/index.js +32 -0
- package/esm/useMediaQuery/index.js.map +1 -0
- package/esm/useQueue/index.js +33 -0
- package/esm/useQueue/index.js.map +1 -0
- package/esm/useReducedMotion/index.js +8 -0
- package/esm/useReducedMotion/index.js.map +1 -0
- package/esm/useToggle/index.js +24 -0
- package/esm/useToggle/index.js.map +1 -0
- package/esm/useUncontrolled/index.js +37 -0
- package/esm/useUncontrolled/index.js.map +1 -0
- package/esm/useWindowEvent/index.js +11 -0
- package/esm/useWindowEvent/index.js.map +1 -0
- package/esm/utils/index.js +6 -0
- package/esm/utils/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.umd.js +2 -0
- package/lib/index.umd.js.map +1 -0
- package/lib/useClipboard/index.d.ts +9 -0
- package/lib/useClipboard/index.d.ts.map +1 -0
- package/lib/useDidMount/index.d.ts +2 -0
- package/lib/useDidMount/index.d.ts.map +1 -0
- package/lib/useForceUpdate/index.d.ts +2 -0
- package/lib/useForceUpdate/index.d.ts.map +1 -0
- package/lib/useId/index.d.ts +2 -0
- package/lib/useId/index.d.ts.map +1 -0
- package/lib/useLocalStorage/index.d.ts +5 -0
- package/lib/useLocalStorage/index.d.ts.map +1 -0
- package/lib/useMediaQuery/index.d.ts +2 -0
- package/lib/useMediaQuery/index.d.ts.map +1 -0
- package/lib/useQueue/index.d.ts +11 -0
- package/lib/useQueue/index.d.ts.map +1 -0
- package/lib/useReducedMotion/index.d.ts +2 -0
- package/lib/useReducedMotion/index.d.ts.map +1 -0
- package/lib/useToggle/index.d.ts +4 -0
- package/lib/useToggle/index.d.ts.map +1 -0
- package/lib/useUncontrolled/index.d.ts +11 -0
- package/lib/useUncontrolled/index.d.ts.map +1 -0
- package/lib/useWindowEvent/index.d.ts +2 -0
- package/lib/useWindowEvent/index.d.ts.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/package.json +26 -0
package/cjs/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index$a = require('./utils/index.js');
|
|
6
|
+
var index = require('./useId/index.js');
|
|
7
|
+
var index$1 = require('./useToggle/index.js');
|
|
8
|
+
var index$2 = require('./useUncontrolled/index.js');
|
|
9
|
+
var index$3 = require('./useMediaQuery/index.js');
|
|
10
|
+
var index$4 = require('./useReducedMotion/index.js');
|
|
11
|
+
var index$5 = require('./useWindowEvent/index.js');
|
|
12
|
+
var index$6 = require('./useLocalStorage/index.js');
|
|
13
|
+
var index$7 = require('./useForceUpdate/index.js');
|
|
14
|
+
var index$8 = require('./useClipboard/index.js');
|
|
15
|
+
var index$9 = require('./useQueue/index.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.randomId = index$a.randomId;
|
|
20
|
+
exports.useId = index.useId;
|
|
21
|
+
exports.useBooleanToggle = index$1.useBooleanToggle;
|
|
22
|
+
exports.useToggle = index$1.useToggle;
|
|
23
|
+
exports.useUncontrolled = index$2.useUncontrolled;
|
|
24
|
+
exports.useMediaQuery = index$3.useMediaQuery;
|
|
25
|
+
exports.useReducedMotion = index$4.useReducedMotion;
|
|
26
|
+
exports.useWindowEvent = index$5.useWindowEvent;
|
|
27
|
+
exports.useLocalStorage = index$6.useLocalStorage;
|
|
28
|
+
exports.useForceUpdate = index$7.useForceUpdate;
|
|
29
|
+
exports.useClipboard = index$8.useClipboard;
|
|
30
|
+
exports.useQueue = index$9.useQueue;
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function useClipboard({ timeout = 2e3 } = {}) {
|
|
8
|
+
const [error, setError] = react.useState(null);
|
|
9
|
+
const [copied, setCopied] = react.useState(false);
|
|
10
|
+
const [copyTimeout, setCopyTimeout] = react.useState(null);
|
|
11
|
+
const handleCopyResult = (value) => {
|
|
12
|
+
clearTimeout(copyTimeout);
|
|
13
|
+
setCopyTimeout(setTimeout(() => setCopied(false), timeout));
|
|
14
|
+
setCopied(value);
|
|
15
|
+
};
|
|
16
|
+
const copy = (valueToCopy) => {
|
|
17
|
+
if ("clipboard" in navigator) {
|
|
18
|
+
navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
|
|
19
|
+
} else {
|
|
20
|
+
setError(new Error("useClipboard: navigator.clipboard is not supported"));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const reset = () => {
|
|
24
|
+
setCopied(false);
|
|
25
|
+
setError(null);
|
|
26
|
+
clearTimeout(copyTimeout);
|
|
27
|
+
};
|
|
28
|
+
return { copy, reset, error, copied };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.useClipboard = useClipboard;
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useClipboard/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useClipboard({ timeout = 2000 } = {}) {\n const [error, setError] = useState<Error>(null);\n const [copied, setCopied] = useState(false);\n const [copyTimeout, setCopyTimeout] = useState(null);\n\n const handleCopyResult = (value: boolean) => {\n clearTimeout(copyTimeout);\n setCopyTimeout(setTimeout(() => setCopied(false), timeout));\n setCopied(value);\n };\n\n const copy = (valueToCopy: any) => {\n if ('clipboard' in navigator) {\n navigator.clipboard\n .writeText(valueToCopy)\n .then(() => handleCopyResult(true))\n .catch((err) => setError(err));\n } else {\n setError(new Error('useClipboard: navigator.clipboard is not supported'));\n }\n };\n\n const reset = () => {\n setCopied(false);\n setError(null);\n clearTimeout(copyTimeout);\n };\n\n return { copy, reset, error, copied };\n}\n"],"names":["useState"],"mappings":";;;;;;AACO,SAAS,YAAY,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,E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
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const reducer = (value) => (value + 1) % 1e6;
|
|
8
|
+
function useForceUpdate() {
|
|
9
|
+
const [, update] = react.useReducer(reducer, 0);
|
|
10
|
+
return update;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useForceUpdate = useForceUpdate;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useForceUpdate/index.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nconst reducer = (value: number) => (value + 1) % 1000000;\n\nexport function useForceUpdate(): () => void {\n const [, update] = useReducer(reducer, 0);\n return update;\n}\n"],"names":["useReducer"],"mappings":";;;;;;AACA,MAAM,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AACtC,SAAS,cAAc,GAAG;AACjC,EAAE,MAAM,GAAG,MAAM,CAAC,GAAGA,gBAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5C,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var index = require('../utils/index.js');
|
|
7
|
+
|
|
8
|
+
function useId(id, generateId = index.randomId) {
|
|
9
|
+
const generatedId = react.useRef(generateId());
|
|
10
|
+
return id || generatedId.current;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useId = useId;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useId/index.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { randomId } from '../utils';\n\nexport function useId(id?: string, generateId: () => string = randomId) {\n const generatedId = useRef(generateId());\n return id || generatedId.current;\n}\n"],"names":["randomId","useRef"],"mappings":";;;;;;;AAEO,SAAS,KAAK,CAAC,EAAE,EAAE,UAAU,GAAGA,cAAQ,EAAE;AACjD,EAAE,MAAM,WAAW,GAAGC,YAAM,CAAC,UAAU,EAAE,CAAC,CAAC;AAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC;AACnC;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var index = require('../useWindowEvent/index.js');
|
|
7
|
+
|
|
8
|
+
function useLocalStorage({
|
|
9
|
+
key,
|
|
10
|
+
defaultValue = void 0
|
|
11
|
+
}) {
|
|
12
|
+
const [value, setValue] = react.useState(typeof window !== "undefined" && "localStorage" in window ? window.localStorage.getItem(key) : defaultValue != null ? defaultValue : "");
|
|
13
|
+
const setLocalStorageValue = react.useCallback((val) => {
|
|
14
|
+
if (typeof val === "function") {
|
|
15
|
+
setValue((current) => {
|
|
16
|
+
const result = val(current);
|
|
17
|
+
window.localStorage.setItem(key, result);
|
|
18
|
+
return result;
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
window.localStorage.setItem(key, val);
|
|
22
|
+
setValue(val);
|
|
23
|
+
}
|
|
24
|
+
}, [key]);
|
|
25
|
+
index.useWindowEvent("storage", (event) => {
|
|
26
|
+
if (event.storageArea === window.localStorage && event.key === key) {
|
|
27
|
+
setValue(event.newValue);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
react.useEffect(() => {
|
|
31
|
+
if (defaultValue && !value) {
|
|
32
|
+
setLocalStorageValue(defaultValue);
|
|
33
|
+
}
|
|
34
|
+
}, [defaultValue, value, setLocalStorageValue]);
|
|
35
|
+
return [value, setLocalStorageValue];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.useLocalStorage = useLocalStorage;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useLocalStorage/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-local-storage-value/use-local-storage-value.ts\nimport { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../useWindowEvent';\n\nexport function useLocalStorage<T extends string>({\n key,\n defaultValue = undefined,\n}: {\n key: string;\n defaultValue?: T;\n}) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? (window.localStorage.getItem(key) as T)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (typeof val === 'function') {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, result);\n return result;\n });\n } else {\n window.localStorage.setItem(key, 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(event.newValue as T);\n }\n });\n\n useEffect(() => {\n if (defaultValue && !value) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value, setLocalStorageValue] as const;\n}\n"],"names":["useState","useCallback","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEO,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC,EAAE;AACH,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,IAAI,IAAI,GAAG,YAAY,GAAG,EAAE,C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|
+
|
|
7
|
+
function attachMediaListener(query, callback) {
|
|
8
|
+
try {
|
|
9
|
+
query.addEventListener("change", callback);
|
|
10
|
+
return () => query.removeEventListener("change", callback);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
query.addListener(callback);
|
|
13
|
+
return () => query.removeListener(callback);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function getInitialValue(query) {
|
|
17
|
+
if (typeof window !== "undefined" && "matchMedia" in window) {
|
|
18
|
+
return window.matchMedia(query).matches;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function useMediaQuery(query) {
|
|
23
|
+
const [matches, setMatches] = react.useState(getInitialValue(query));
|
|
24
|
+
const queryRef = react.useRef();
|
|
25
|
+
react.useEffect(() => {
|
|
26
|
+
if ("matchMedia" in window) {
|
|
27
|
+
queryRef.current = window.matchMedia(query);
|
|
28
|
+
setMatches(queryRef.current.matches);
|
|
29
|
+
return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
|
|
30
|
+
}
|
|
31
|
+
}, [query]);
|
|
32
|
+
return matches;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.useMediaQuery = useMediaQuery;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useMediaQuery/index.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 // eslint-disable-next-line consistent-return\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 }, [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,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;AAChC,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;AACrC,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,EAAE,MAAM,QAAQ,GAAGC,YAAM,EAAE,CAAC;AAC5B,EAAEC,eAAS,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,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function useQueue({ initialValues = [], limit }) {
|
|
8
|
+
const [{ state, queue }, setState] = react.useState({
|
|
9
|
+
state: initialValues.slice(0, limit),
|
|
10
|
+
queue: initialValues.slice(limit)
|
|
11
|
+
});
|
|
12
|
+
const add = (...items) => setState((current) => {
|
|
13
|
+
const results = [...current.state, ...current.queue, ...items];
|
|
14
|
+
return {
|
|
15
|
+
state: results.slice(0, limit),
|
|
16
|
+
queue: results.slice(limit)
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
const update = (fn) => setState((current) => {
|
|
20
|
+
const results = fn([...current.state, ...current.queue]);
|
|
21
|
+
return {
|
|
22
|
+
state: results.slice(0, limit),
|
|
23
|
+
queue: results.slice(limit)
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));
|
|
27
|
+
return {
|
|
28
|
+
state,
|
|
29
|
+
queue,
|
|
30
|
+
add,
|
|
31
|
+
update,
|
|
32
|
+
cleanQueue
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.useQueue = useQueue;
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useQueue/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useQueue<T>({ initialValues = [], limit }: { initialValues?: T[]; limit: number }) {\n const [{ state, queue }, setState] = useState({\n state: initialValues.slice(0, limit),\n queue: initialValues.slice(limit),\n });\n\n const add = (...items: T[]) =>\n setState((current) => {\n const results = [...current.state, ...current.queue, ...items];\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const update = (fn: (state: T[]) => T[]) =>\n setState((current) => {\n const results = fn([...current.state, ...current.queue]);\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));\n\n return {\n state,\n queue,\n add,\n update,\n cleanQueue,\n };\n}\n"],"names":["useState"],"mappings":";;;;;;AACO,SAAS,QAAQ,CAAC,EAAE,aAAa,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE;AACxD,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC;AAChD,IAAI,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACxC,IAAI,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;AACrC,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK;AAClD,IAAI,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC;AACnE,IAAI,OAAO;AACX,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACpC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACjC,KAAK,CAAC;AACN,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,MAAM,GAAG,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,OAAO,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,IAAI,OAAO;AACX,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACpC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACjC,KAAK,CAAC;AACN,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,CAAC,OAAO,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACxF,EAAE,OAAO;AACT,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,GAAG;AACP,IAAI,MAAM;AACV,IAAI,UAAU;AACd,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('../useMediaQuery/index.js');
|
|
6
|
+
|
|
7
|
+
function useReducedMotion() {
|
|
8
|
+
return index.useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.useReducedMotion = useReducedMotion;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useReducedMotion/index.ts"],"sourcesContent":["import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":["useMediaQuery"],"mappings":";;;;;;AACO,SAAS,gBAAgB,GAAG;AACnC,EAAE,OAAOA,mBAAa,CAAC,kCAAkC,CAAC,CAAC;AAC3D;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function useToggle(initialValue, options) {
|
|
8
|
+
const [state, setState] = react.useState(initialValue);
|
|
9
|
+
const toggle = (value) => {
|
|
10
|
+
if (typeof value !== "undefined") {
|
|
11
|
+
setState(value);
|
|
12
|
+
} else {
|
|
13
|
+
setState((current) => {
|
|
14
|
+
if (current === options[0]) {
|
|
15
|
+
return options[1];
|
|
16
|
+
}
|
|
17
|
+
return options[0];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return [state, toggle];
|
|
22
|
+
}
|
|
23
|
+
function useBooleanToggle(initialValue = false) {
|
|
24
|
+
return useToggle(initialValue, [true, false]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.useBooleanToggle = useBooleanToggle;
|
|
28
|
+
exports.useToggle = useToggle;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useToggle/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-toggle/use-toggle.ts\nimport React, { useState } from 'react';\n\nexport function useToggle<T>(initialValue: T, options: [T, T]) {\n const [state, setState] = useState(initialValue);\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\nexport function useBooleanToggle(initialValue = false) {\n return useToggle(initialValue, [true, false]);\n}\n"],"names":["useState"],"mappings":";;;;;;AACO,SAAS,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE;AACjD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,cAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,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,CAAC;AACM,SAAS,gBAAgB,CAAC,YAAY,GAAG,KAAK,EAAE;AACvD,EAAE,OAAO,SAAS,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD;;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function useUncontrolled({
|
|
8
|
+
value,
|
|
9
|
+
defaultValue,
|
|
10
|
+
finalValue,
|
|
11
|
+
rule,
|
|
12
|
+
onChange,
|
|
13
|
+
onValueUpdate
|
|
14
|
+
}) {
|
|
15
|
+
const shouldBeControlled = rule(value);
|
|
16
|
+
const modeRef = react.useRef("initial");
|
|
17
|
+
const initialValue = rule(defaultValue) ? defaultValue : finalValue;
|
|
18
|
+
const [uncontrolledValue, setUncontrolledValue] = react.useState(initialValue);
|
|
19
|
+
let effectiveValue = shouldBeControlled ? value : uncontrolledValue;
|
|
20
|
+
if (!shouldBeControlled && modeRef.current === "controlled") {
|
|
21
|
+
effectiveValue = finalValue;
|
|
22
|
+
}
|
|
23
|
+
modeRef.current = shouldBeControlled ? "controlled" : "uncontrolled";
|
|
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];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.useUncontrolled = useUncontrolled;
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useUncontrolled/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n"],"names":["useRef","useState","useEffect"],"mappings":";;;;;;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,KAAK;AACP,EAAE,YAAY;AACd,EAAE,UAAU;AACZ,EAAE,IAAI;AACN,EAAE,QAAQ;AACV,EAAE,aAAa;AACf,CAAC,EAAE;AACH,EAAE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,EAAE,MAAM,OAAO,GAAGA,YAAM,CAAC,SAAS,CAAC,CAAC;AACpC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACtE,EAAE,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAGC,cAAQ,CAAC,YAAY,CAAC,CAAC;AAC3E,EAAE,IAAI,cAAc,GAAG,kBAAkB,GAAG,KAAK,GAAG,iBAAiB,CAAC;AACtE,EAAE,IAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,OAAO,KAAK,YAAY,EAAE;AAC/D,IAAI,cAAc,GAAG,UAAU,CAAC;AAChC,GAAG;AACH,EAAE,OAAO,CAAC,OAAO,GAAG,kBAAkB,GAAG,YAAY,GAAG,cAAc,CAAC;AACvE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;AAC/B,EAAE,MAAM,YAAY,GAAG,CAAC,SAAS,KAAK;AACtC,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC1D,IAAI,IAAI,IAAI,KAAK,cAAc,EAAE;AACjC,MAAM,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACtC,KAAK;AACL,GAAG,CAAC;AACJ,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,IAAI,IAAI,KAAK,cAAc,EAAE;AACjC,MAAM,oBAAoB,CAAC,cAAc,CAAC,CAAC;AAC3C,KAAK;AACL,IAAI,OAAO,aAAa,KAAK,UAAU,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;AACzE,GAAG,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;AAC7B,EAAE,OAAO,CAAC,cAAc,EAAE,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AACzD;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function useWindowEvent(type, listener, options) {
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
window.addEventListener(type, listener, options);
|
|
10
|
+
return () => window.removeEventListener(type, listener, options);
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.useWindowEvent = useWindowEvent;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useWindowEvent/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useWindowEvent<K extends keyof WindowEventMap>(\n type: K,\n listener: (this: Window, ev: WindowEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n useEffect(() => {\n window.addEventListener(type, listener, options);\n return () => window.removeEventListener(type, listener, options);\n }, []);\n}\n"],"names":["useEffect"],"mappings":";;;;;;AACO,SAAS,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE;AACxD,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrD,IAAI,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrE,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n"],"names":[],"mappings":";;;;AAAO,SAAS,QAAQ,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D;;;;"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { randomId } from './utils/index.js';
|
|
2
|
+
export { useId } from './useId/index.js';
|
|
3
|
+
export { useBooleanToggle, useToggle } from './useToggle/index.js';
|
|
4
|
+
export { useUncontrolled } from './useUncontrolled/index.js';
|
|
5
|
+
export { useMediaQuery } from './useMediaQuery/index.js';
|
|
6
|
+
export { useReducedMotion } from './useReducedMotion/index.js';
|
|
7
|
+
export { useWindowEvent } from './useWindowEvent/index.js';
|
|
8
|
+
export { useLocalStorage } from './useLocalStorage/index.js';
|
|
9
|
+
export { useForceUpdate } from './useForceUpdate/index.js';
|
|
10
|
+
export { useClipboard } from './useClipboard/index.js';
|
|
11
|
+
export { useQueue } from './useQueue/index.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
function useClipboard({ timeout = 2e3 } = {}) {
|
|
4
|
+
const [error, setError] = useState(null);
|
|
5
|
+
const [copied, setCopied] = useState(false);
|
|
6
|
+
const [copyTimeout, setCopyTimeout] = useState(null);
|
|
7
|
+
const handleCopyResult = (value) => {
|
|
8
|
+
clearTimeout(copyTimeout);
|
|
9
|
+
setCopyTimeout(setTimeout(() => setCopied(false), timeout));
|
|
10
|
+
setCopied(value);
|
|
11
|
+
};
|
|
12
|
+
const copy = (valueToCopy) => {
|
|
13
|
+
if ("clipboard" in navigator) {
|
|
14
|
+
navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
|
|
15
|
+
} else {
|
|
16
|
+
setError(new Error("useClipboard: navigator.clipboard is not supported"));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const reset = () => {
|
|
20
|
+
setCopied(false);
|
|
21
|
+
setError(null);
|
|
22
|
+
clearTimeout(copyTimeout);
|
|
23
|
+
};
|
|
24
|
+
return { copy, reset, error, copied };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { useClipboard };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useClipboard/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useClipboard({ timeout = 2000 } = {}) {\n const [error, setError] = useState<Error>(null);\n const [copied, setCopied] = useState(false);\n const [copyTimeout, setCopyTimeout] = useState(null);\n\n const handleCopyResult = (value: boolean) => {\n clearTimeout(copyTimeout);\n setCopyTimeout(setTimeout(() => setCopied(false), timeout));\n setCopied(value);\n };\n\n const copy = (valueToCopy: any) => {\n if ('clipboard' in navigator) {\n navigator.clipboard\n .writeText(valueToCopy)\n .then(() => handleCopyResult(true))\n .catch((err) => setError(err));\n } else {\n setError(new Error('useClipboard: navigator.clipboard is not supported'));\n }\n };\n\n const reset = () => {\n setCopied(false);\n setError(null);\n clearTimeout(copyTimeout);\n };\n\n return { copy, reset, error, copied };\n}\n"],"names":[],"mappings":";;AACO,SAAS,YAAY,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE;AACrD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3C,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9C,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvD,EAAE,MAAM,gBAAgB,GAAG,CAAC,KAAK,KAAK;AACtC,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC;AAC9B,IAAI,cAAc,CAAC,UAAU,CAAC,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAChE,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AACrB,GAAG,CAAC;AACJ,EAAE,MAAM,IAAI,GAAG,CAAC,WAAW,KAAK;AAChC,IAAI,IAAI,WAAW,IAAI,SAAS,EAAE;AAClC,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AAClH,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC,CAAC;AAChF,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,MAAM,KAAK,GAAG,MAAM;AACtB,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AACrB,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnB,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC;AAC9B,GAAG,CAAC;AACJ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACxC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useForceUpdate/index.ts"],"sourcesContent":["import { useReducer } from 'react';\n\nconst reducer = (value: number) => (value + 1) % 1000000;\n\nexport function useForceUpdate(): () => void {\n const [, update] = useReducer(reducer, 0);\n return update;\n}\n"],"names":[],"mappings":";;AACA,MAAM,OAAO,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AACtC,SAAS,cAAc,GAAG;AACjC,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5C,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { randomId } from '../utils/index.js';
|
|
3
|
+
|
|
4
|
+
function useId(id, generateId = randomId) {
|
|
5
|
+
const generatedId = useRef(generateId());
|
|
6
|
+
return id || generatedId.current;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useId };
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useId/index.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { randomId } from '../utils';\n\nexport function useId(id?: string, generateId: () => string = randomId) {\n const generatedId = useRef(generateId());\n return id || generatedId.current;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,KAAK,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,EAAE;AACjD,EAAE,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;AAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC;AACnC;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { useWindowEvent } from '../useWindowEvent/index.js';
|
|
3
|
+
|
|
4
|
+
function useLocalStorage({
|
|
5
|
+
key,
|
|
6
|
+
defaultValue = void 0
|
|
7
|
+
}) {
|
|
8
|
+
const [value, setValue] = useState(typeof window !== "undefined" && "localStorage" in window ? window.localStorage.getItem(key) : defaultValue != null ? defaultValue : "");
|
|
9
|
+
const setLocalStorageValue = useCallback((val) => {
|
|
10
|
+
if (typeof val === "function") {
|
|
11
|
+
setValue((current) => {
|
|
12
|
+
const result = val(current);
|
|
13
|
+
window.localStorage.setItem(key, result);
|
|
14
|
+
return result;
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
window.localStorage.setItem(key, val);
|
|
18
|
+
setValue(val);
|
|
19
|
+
}
|
|
20
|
+
}, [key]);
|
|
21
|
+
useWindowEvent("storage", (event) => {
|
|
22
|
+
if (event.storageArea === window.localStorage && event.key === key) {
|
|
23
|
+
setValue(event.newValue);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (defaultValue && !value) {
|
|
28
|
+
setLocalStorageValue(defaultValue);
|
|
29
|
+
}
|
|
30
|
+
}, [defaultValue, value, setLocalStorageValue]);
|
|
31
|
+
return [value, setLocalStorageValue];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { useLocalStorage };
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useLocalStorage/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-local-storage-value/use-local-storage-value.ts\nimport { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../useWindowEvent';\n\nexport function useLocalStorage<T extends string>({\n key,\n defaultValue = undefined,\n}: {\n key: string;\n defaultValue?: T;\n}) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? (window.localStorage.getItem(key) as T)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (typeof val === 'function') {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, result);\n return result;\n });\n } else {\n window.localStorage.setItem(key, 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(event.newValue as T);\n }\n });\n\n useEffect(() => {\n if (defaultValue && !value) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value, setLocalStorageValue] as const;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,eAAe,CAAC;AAChC,EAAE,GAAG;AACL,EAAE,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC,EAAE;AACH,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,OA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|
|
3
|
+
function attachMediaListener(query, callback) {
|
|
4
|
+
try {
|
|
5
|
+
query.addEventListener("change", callback);
|
|
6
|
+
return () => query.removeEventListener("change", callback);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
query.addListener(callback);
|
|
9
|
+
return () => query.removeListener(callback);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getInitialValue(query) {
|
|
13
|
+
if (typeof window !== "undefined" && "matchMedia" in window) {
|
|
14
|
+
return window.matchMedia(query).matches;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function useMediaQuery(query) {
|
|
19
|
+
const [matches, setMatches] = useState(getInitialValue(query));
|
|
20
|
+
const queryRef = useRef();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if ("matchMedia" in window) {
|
|
23
|
+
queryRef.current = window.matchMedia(query);
|
|
24
|
+
setMatches(queryRef.current.matches);
|
|
25
|
+
return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
|
|
26
|
+
}
|
|
27
|
+
}, [query]);
|
|
28
|
+
return matches;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { useMediaQuery };
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useMediaQuery/index.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 // eslint-disable-next-line consistent-return\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 }, [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;AAChC,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;AACrC,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,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,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
function useQueue({ initialValues = [], limit }) {
|
|
4
|
+
const [{ state, queue }, setState] = useState({
|
|
5
|
+
state: initialValues.slice(0, limit),
|
|
6
|
+
queue: initialValues.slice(limit)
|
|
7
|
+
});
|
|
8
|
+
const add = (...items) => setState((current) => {
|
|
9
|
+
const results = [...current.state, ...current.queue, ...items];
|
|
10
|
+
return {
|
|
11
|
+
state: results.slice(0, limit),
|
|
12
|
+
queue: results.slice(limit)
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
const update = (fn) => setState((current) => {
|
|
16
|
+
const results = fn([...current.state, ...current.queue]);
|
|
17
|
+
return {
|
|
18
|
+
state: results.slice(0, limit),
|
|
19
|
+
queue: results.slice(limit)
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));
|
|
23
|
+
return {
|
|
24
|
+
state,
|
|
25
|
+
queue,
|
|
26
|
+
add,
|
|
27
|
+
update,
|
|
28
|
+
cleanQueue
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { useQueue };
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useQueue/index.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport function useQueue<T>({ initialValues = [], limit }: { initialValues?: T[]; limit: number }) {\n const [{ state, queue }, setState] = useState({\n state: initialValues.slice(0, limit),\n queue: initialValues.slice(limit),\n });\n\n const add = (...items: T[]) =>\n setState((current) => {\n const results = [...current.state, ...current.queue, ...items];\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const update = (fn: (state: T[]) => T[]) =>\n setState((current) => {\n const results = fn([...current.state, ...current.queue]);\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));\n\n return {\n state,\n queue,\n add,\n update,\n cleanQueue,\n };\n}\n"],"names":[],"mappings":";;AACO,SAAS,QAAQ,CAAC,EAAE,aAAa,GAAG,EAAE,EAAE,KAAK,EAAE,EAAE;AACxD,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAChD,IAAI,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACxC,IAAI,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;AACrC,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK;AAClD,IAAI,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC;AACnE,IAAI,OAAO;AACX,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACpC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACjC,KAAK,CAAC;AACN,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,MAAM,GAAG,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,OAAO,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,IAAI,OAAO;AACX,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AACpC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACjC,KAAK,CAAC;AACN,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,CAAC,OAAO,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACxF,EAAE,OAAO;AACT,IAAI,KAAK;AACT,IAAI,KAAK;AACT,IAAI,GAAG;AACP,IAAI,MAAM;AACV,IAAI,UAAU;AACd,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useReducedMotion/index.ts"],"sourcesContent":["import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n"],"names":[],"mappings":";;AACO,SAAS,gBAAgB,GAAG;AACnC,EAAE,OAAO,aAAa,CAAC,kCAAkC,CAAC,CAAC;AAC3D;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
function useToggle(initialValue, options) {
|
|
4
|
+
const [state, setState] = useState(initialValue);
|
|
5
|
+
const toggle = (value) => {
|
|
6
|
+
if (typeof value !== "undefined") {
|
|
7
|
+
setState(value);
|
|
8
|
+
} else {
|
|
9
|
+
setState((current) => {
|
|
10
|
+
if (current === options[0]) {
|
|
11
|
+
return options[1];
|
|
12
|
+
}
|
|
13
|
+
return options[0];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return [state, toggle];
|
|
18
|
+
}
|
|
19
|
+
function useBooleanToggle(initialValue = false) {
|
|
20
|
+
return useToggle(initialValue, [true, false]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { useBooleanToggle, useToggle };
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useToggle/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-toggle/use-toggle.ts\nimport React, { useState } from 'react';\n\nexport function useToggle<T>(initialValue: T, options: [T, T]) {\n const [state, setState] = useState(initialValue);\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\nexport function useBooleanToggle(initialValue = false) {\n return useToggle(initialValue, [true, false]);\n}\n"],"names":[],"mappings":";;AACO,SAAS,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE;AACjD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACnD,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,CAAC;AACM,SAAS,gBAAgB,CAAC,YAAY,GAAG,KAAK,EAAE;AACvD,EAAE,OAAO,SAAS,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function useUncontrolled({
|
|
4
|
+
value,
|
|
5
|
+
defaultValue,
|
|
6
|
+
finalValue,
|
|
7
|
+
rule,
|
|
8
|
+
onChange,
|
|
9
|
+
onValueUpdate
|
|
10
|
+
}) {
|
|
11
|
+
const shouldBeControlled = rule(value);
|
|
12
|
+
const modeRef = useRef("initial");
|
|
13
|
+
const initialValue = rule(defaultValue) ? defaultValue : finalValue;
|
|
14
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);
|
|
15
|
+
let effectiveValue = shouldBeControlled ? value : uncontrolledValue;
|
|
16
|
+
if (!shouldBeControlled && modeRef.current === "controlled") {
|
|
17
|
+
effectiveValue = finalValue;
|
|
18
|
+
}
|
|
19
|
+
modeRef.current = shouldBeControlled ? "controlled" : "uncontrolled";
|
|
20
|
+
const mode = modeRef.current;
|
|
21
|
+
const handleChange = (nextValue) => {
|
|
22
|
+
typeof onChange === "function" && onChange(nextValue);
|
|
23
|
+
if (mode === "uncontrolled") {
|
|
24
|
+
setUncontrolledValue(nextValue);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (mode === "uncontrolled") {
|
|
29
|
+
setUncontrolledValue(effectiveValue);
|
|
30
|
+
}
|
|
31
|
+
typeof onValueUpdate === "function" && onValueUpdate(effectiveValue);
|
|
32
|
+
}, [mode, effectiveValue]);
|
|
33
|
+
return [effectiveValue, handleChange, modeRef.current];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { useUncontrolled };
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useUncontrolled/index.ts"],"sourcesContent":["// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n"],"names":[],"mappings":";;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,KAAK;AACP,EAAE,YAAY;AACd,EAAE,UAAU;AACZ,EAAE,IAAI;AACN,EAAE,QAAQ;AACV,EAAE,aAAa;AACf,CAAC,EAAE;AACH,EAAE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AACpC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AACtE,EAAE,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC3E,EAAE,IAAI,cAAc,GAAG,kBAAkB,GAAG,KAAK,GAAG,iBAAiB,CAAC;AACtE,EAAE,IAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,OAAO,KAAK,YAAY,EAAE;AAC/D,IAAI,cAAc,GAAG,UAAU,CAAC;AAChC,GAAG;AACH,EAAE,OAAO,CAAC,OAAO,GAAG,kBAAkB,GAAG,YAAY,GAAG,cAAc,CAAC;AACvE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;AAC/B,EAAE,MAAM,YAAY,GAAG,CAAC,SAAS,KAAK;AACtC,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC1D,IAAI,IAAI,IAAI,KAAK,cAAc,EAAE;AACjC,MAAM,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACtC,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,IAAI,KAAK,cAAc,EAAE;AACjC,MAAM,oBAAoB,CAAC,cAAc,CAAC,CAAC;AAC3C,KAAK;AACL,IAAI,OAAO,aAAa,KAAK,UAAU,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;AACzE,GAAG,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;AAC7B,EAAE,OAAO,CAAC,cAAc,EAAE,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AACzD;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function useWindowEvent(type, listener, options) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
window.addEventListener(type, listener, options);
|
|
6
|
+
return () => window.removeEventListener(type, listener, options);
|
|
7
|
+
}, []);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { useWindowEvent };
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useWindowEvent/index.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nexport function useWindowEvent<K extends keyof WindowEventMap>(\n type: K,\n listener: (this: Window, ev: WindowEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n useEffect(() => {\n window.addEventListener(type, listener, options);\n return () => window.removeEventListener(type, listener, options);\n }, []);\n}\n"],"names":[],"mappings":";;AACO,SAAS,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE;AACxD,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrD,IAAI,OAAO,MAAM,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACrE,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n"],"names":[],"mappings":"AAAO,SAAS,QAAQ,GAAG;AAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D;;;;"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './utils';
|
|
2
|
+
export { useId } from './useId';
|
|
3
|
+
export { useToggle, useBooleanToggle } from './useToggle';
|
|
4
|
+
export { useUncontrolled } from './useUncontrolled';
|
|
5
|
+
export { useMediaQuery } from './useMediaQuery';
|
|
6
|
+
export { useReducedMotion } from './useReducedMotion';
|
|
7
|
+
export { useWindowEvent } from './useWindowEvent';
|
|
8
|
+
export { useLocalStorage } from './useLocalStorage';
|
|
9
|
+
export { useForceUpdate } from './useForceUpdate';
|
|
10
|
+
export { useClipboard } from './useClipboard';
|
|
11
|
+
export { useQueue } from './useQueue';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/lib/index.umd.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(u,o){typeof exports=="object"&&typeof module!="undefined"?o(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],o):(u=typeof globalThis!="undefined"?globalThis:u||self,o(u["@kubed/hooks"]={},u.React))})(this,function(u,o){"use strict";function h(){return`kubed-${Math.random().toString(36).substr(2,9)}`}function M(e,t=h){const n=o.useRef(t());return e||n.current}function m(e,t){const[n,r]=o.useState(e);return[n,s=>{typeof s!="undefined"?r(s):r(d=>d===t[0]?t[1]:t[0])}]}function T(e=!1){return m(e,[!0,!1])}function L({value:e,defaultValue:t,finalValue:n,rule:r,onChange:c,onValueUpdate:s}){const d=r(e),a=o.useRef("initial"),f=r(t)?t:n,[l,i]=o.useState(f);let w=d?e:l;!d&&a.current==="controlled"&&(w=n),a.current=d?"controlled":"uncontrolled";const g=a.current,U=E=>{typeof c=="function"&&c(E),g==="uncontrolled"&&i(E)};return o.useEffect(()=>{g==="uncontrolled"&&i(w),typeof s=="function"&&s(w)},[g,w]),[w,U,a.current]}function R(e,t){try{return e.addEventListener("change",t),()=>e.removeEventListener("change",t)}catch(n){return e.addListener(t),()=>e.removeListener(t)}}function v(e){return typeof window!="undefined"&&"matchMedia"in window?window.matchMedia(e).matches:!1}function S(e){const[t,n]=o.useState(v(e)),r=o.useRef();return o.useEffect(()=>{if("matchMedia"in window)return r.current=window.matchMedia(e),n(r.current.matches),R(r.current,c=>n(c.matches))},[e]),t}function y(){return S("(prefers-reduced-motion: reduce)")}function p(e,t,n){o.useEffect(()=>(window.addEventListener(e,t,n),()=>window.removeEventListener(e,t,n)),[])}function I({key:e,defaultValue:t=void 0}){const[n,r]=o.useState(typeof window!="undefined"&&"localStorage"in window?window.localStorage.getItem(e):t!=null?t:""),c=o.useCallback(s=>{typeof s=="function"?r(d=>{const a=s(d);return window.localStorage.setItem(e,a),a}):(window.localStorage.setItem(e,s),r(s))},[e]);return p("storage",s=>{s.storageArea===window.localStorage&&s.key===e&&r(s.newValue)}),o.useEffect(()=>{t&&!n&&c(t)},[t,n,c]),[n,c]}const b=e=>(e+1)%1e6;function C(){const[,e]=o.useReducer(b,0);return e}function Q({timeout:e=2e3}={}){const[t,n]=o.useState(null),[r,c]=o.useState(!1),[s,d]=o.useState(null),a=i=>{clearTimeout(s),d(setTimeout(()=>c(!1),e)),c(i)};return{copy:i=>{"clipboard"in navigator?navigator.clipboard.writeText(i).then(()=>a(!0)).catch(w=>n(w)):n(new Error("useClipboard: navigator.clipboard is not supported"))},reset:()=>{c(!1),n(null),clearTimeout(s)},error:t,copied:r}}function q({initialValues:e=[],limit:t}){const[{state:n,queue:r},c]=o.useState({state:e.slice(0,t),queue:e.slice(t)});return{state:n,queue:r,add:(...f)=>c(l=>{const i=[...l.state,...l.queue,...f];return{state:i.slice(0,t),queue:i.slice(t)}}),update:f=>c(l=>{const i=f([...l.state,...l.queue]);return{state:i.slice(0,t),queue:i.slice(t)}}),cleanQueue:()=>c(f=>({state:f.state,queue:[]}))}}u.randomId=h,u.useBooleanToggle=T,u.useClipboard=Q,u.useForceUpdate=C,u.useId=M,u.useLocalStorage=I,u.useMediaQuery=S,u.useQueue=q,u.useReducedMotion=y,u.useToggle=m,u.useUncontrolled=L,u.useWindowEvent=p,Object.defineProperty(u,"__esModule",{value:!0})});
|
|
2
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/utils/index.ts","../src/useId/index.ts","../src/useToggle/index.ts","../src/useUncontrolled/index.ts","../src/useMediaQuery/index.ts","../src/useReducedMotion/index.ts","../src/useWindowEvent/index.ts","../src/useLocalStorage/index.ts","../src/useForceUpdate/index.ts","../src/useClipboard/index.ts","../src/useQueue/index.ts"],"sourcesContent":["export function randomId() {\n return `kubed-${Math.random().toString(36).substr(2, 9)}`;\n}\n","import { useRef } from 'react';\nimport { randomId } from '../utils';\n\nexport function useId(id?: string, generateId: () => string = randomId) {\n const generatedId = useRef(generateId());\n return id || generatedId.current;\n}\n","// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-toggle/use-toggle.ts\nimport React, { useState } from 'react';\n\nexport function useToggle<T>(initialValue: T, options: [T, T]) {\n const [state, setState] = useState(initialValue);\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\nexport function useBooleanToggle(initialValue = false) {\n return useToggle(initialValue, [true, false]);\n}\n","// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-uncontrolled/use-uncontrolled.ts\nimport { useEffect, useRef, useState } from 'react';\n\nexport type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';\n\nexport interface UncontrolledOptions<T> {\n value: T | null | undefined;\n defaultValue: T | null | undefined;\n finalValue: T | null;\n onChange(value: T | null): void;\n onValueUpdate?(value: T | null): void;\n rule: (value: T | null | undefined) => boolean;\n}\n\nexport function useUncontrolled<T>({\n value,\n defaultValue,\n finalValue,\n rule,\n onChange,\n onValueUpdate,\n}: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode] {\n // determine, whether new props indicate controlled state\n const shouldBeControlled = rule(value);\n\n // initialize state\n const modeRef = useRef<UncontrolledMode>('initial');\n const initialValue = rule(defaultValue) ? defaultValue : finalValue;\n const [uncontrolledValue, setUncontrolledValue] = useState(initialValue);\n\n // compute effective value\n let effectiveValue = shouldBeControlled ? value : uncontrolledValue;\n\n if (!shouldBeControlled && modeRef.current === 'controlled') {\n // We are transitioning from controlled to uncontrolled\n // this transition is special as it happens when clearing out\n // the input using \"invalid\" value (typically null or undefined).\n //\n // Since the value is invalid, doing nothing would mean just\n // transitioning to uncontrolled state and using whatever value\n // it currently holds which is likely not the bavior\n // user expects, so lets change the state to finalValue.\n //\n // The value will be propagated to internal state by useEffect below.\n\n effectiveValue = finalValue;\n }\n modeRef.current = shouldBeControlled ? 'controlled' : 'uncontrolled';\n const mode = modeRef.current;\n\n const handleChange = (nextValue: T | null) => {\n typeof onChange === 'function' && onChange(nextValue);\n\n // Controlled input only triggers onChange event and expects\n // the controller to propagate new value back.\n if (mode === 'uncontrolled') {\n setUncontrolledValue(nextValue);\n }\n };\n\n useEffect(() => {\n if (mode === 'uncontrolled') {\n setUncontrolledValue(effectiveValue);\n }\n typeof onValueUpdate === 'function' && onValueUpdate(effectiveValue);\n }, [mode, effectiveValue]);\n\n return [effectiveValue, handleChange, modeRef.current] as const;\n}\n","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 // eslint-disable-next-line consistent-return\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 }, [query]);\n\n return matches;\n}\n","import { useMediaQuery } from '../useMediaQuery';\n\nexport function useReducedMotion() {\n return useMediaQuery('(prefers-reduced-motion: reduce)');\n}\n","import { useEffect } from 'react';\n\nexport function useWindowEvent<K extends keyof WindowEventMap>(\n type: K,\n listener: (this: Window, ev: WindowEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n useEffect(() => {\n window.addEventListener(type, listener, options);\n return () => window.removeEventListener(type, listener, options);\n }, []);\n}\n","// https://github.com/mantinedev/mantine/blob/master/src/mantine-hooks/src/use-local-storage-value/use-local-storage-value.ts\nimport { useState, useCallback, useEffect } from 'react';\nimport { useWindowEvent } from '../useWindowEvent';\n\nexport function useLocalStorage<T extends string>({\n key,\n defaultValue = undefined,\n}: {\n key: string;\n defaultValue?: T;\n}) {\n const [value, setValue] = useState<T>(\n typeof window !== 'undefined' && 'localStorage' in window\n ? (window.localStorage.getItem(key) as T)\n : ((defaultValue ?? '') as T)\n );\n\n const setLocalStorageValue = useCallback(\n (val: T | ((prevState: T) => T)) => {\n if (typeof val === 'function') {\n setValue((current) => {\n const result = val(current);\n window.localStorage.setItem(key, result);\n return result;\n });\n } else {\n window.localStorage.setItem(key, 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(event.newValue as T);\n }\n });\n\n useEffect(() => {\n if (defaultValue && !value) {\n setLocalStorageValue(defaultValue);\n }\n }, [defaultValue, value, setLocalStorageValue]);\n\n return [value, setLocalStorageValue] as const;\n}\n","import { useReducer } from 'react';\n\nconst reducer = (value: number) => (value + 1) % 1000000;\n\nexport function useForceUpdate(): () => void {\n const [, update] = useReducer(reducer, 0);\n return update;\n}\n","import { useState } from 'react';\n\nexport function useClipboard({ timeout = 2000 } = {}) {\n const [error, setError] = useState<Error>(null);\n const [copied, setCopied] = useState(false);\n const [copyTimeout, setCopyTimeout] = useState(null);\n\n const handleCopyResult = (value: boolean) => {\n clearTimeout(copyTimeout);\n setCopyTimeout(setTimeout(() => setCopied(false), timeout));\n setCopied(value);\n };\n\n const copy = (valueToCopy: any) => {\n if ('clipboard' in navigator) {\n navigator.clipboard\n .writeText(valueToCopy)\n .then(() => handleCopyResult(true))\n .catch((err) => setError(err));\n } else {\n setError(new Error('useClipboard: navigator.clipboard is not supported'));\n }\n };\n\n const reset = () => {\n setCopied(false);\n setError(null);\n clearTimeout(copyTimeout);\n };\n\n return { copy, reset, error, copied };\n}\n","import { useState } from 'react';\n\nexport function useQueue<T>({ initialValues = [], limit }: { initialValues?: T[]; limit: number }) {\n const [{ state, queue }, setState] = useState({\n state: initialValues.slice(0, limit),\n queue: initialValues.slice(limit),\n });\n\n const add = (...items: T[]) =>\n setState((current) => {\n const results = [...current.state, ...current.queue, ...items];\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const update = (fn: (state: T[]) => T[]) =>\n setState((current) => {\n const results = fn([...current.state, ...current.queue]);\n\n return {\n state: results.slice(0, limit),\n queue: results.slice(limit),\n };\n });\n\n const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));\n\n return {\n state,\n queue,\n add,\n update,\n cleanQueue,\n };\n}\n"],"names":["useRef","useState","useEffect","useCallback","useReducer"],"mappings":";;;;;;EAAO,SAAS,QAAQ,GAAG;EAC3B,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;EAC5D;;ECAO,SAAS,KAAK,CAAC,EAAE,EAAE,UAAU,GAAG,QAAQ,EAAE;EACjD,EAAE,MAAM,WAAW,GAAGA,YAAM,CAAC,UAAU,EAAE,CAAC,CAAC;EAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC;EACnC;;ECJO,SAAS,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE;EACjD,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGC,cAAQ,CAAC,YAAY,CAAC,CAAC;EACnD,EAA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CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;EAC7D,IAAI,OAAO;EACX,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;EACpC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;EACjC,KAAK,CAAC;EACN,GAAG,CAAC,CAAC;EACL,EAAE,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,CAAC,OAAO,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;EACxF,EAAE,OAAO;EACT,IAAI,KAAK;EACT,IAAI,KAAK;EACT,IAAI,GAAG;EACP,IAAI,MAAM;EACV,IAAI,UAAU;EACd,GAAG,CAAC;EACJ;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useClipboard/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,EAAE,OAAc,EAAE;;CAAK;wBAWvB,GAAG;;;;EAkB/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useDidMount/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,IAAI,CAMrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useForceUpdate/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,cAAc,IAAI,MAAM,IAAI,CAG3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useId/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,MAAiB,UAGrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useLocalStorage/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,EAChD,GAAG,EACH,YAAwB,GACzB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,CAAC,CAAC;CAClB,uCAQ0B,CAAC,KAAK,CAAC,YA4BjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useMediaQuery/index.ts"],"names":[],"mappings":"AAyBA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,WAc1C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function useQueue<T>({ initialValues, limit }: {
|
|
2
|
+
initialValues?: T[];
|
|
3
|
+
limit: number;
|
|
4
|
+
}): {
|
|
5
|
+
state: T[];
|
|
6
|
+
queue: T[];
|
|
7
|
+
add: (...items: T[]) => void;
|
|
8
|
+
update: (fn: (state: T[]) => T[]) => void;
|
|
9
|
+
cleanQueue: () => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useQueue/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,aAAkB,EAAE,KAAK,EAAE,EAAE;IAAE,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;;;oBAMxE,CAAC,EAAE;yBAUE,CAAC,EAAE,KAAK,CAAC,EAAE;;EAmBxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useReducedMotion/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,YAE/B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function useToggle<T>(initialValue: T, options: [T, T]): readonly [T, (value?: React.SetStateAction<T>) => void];
|
|
3
|
+
export declare function useBooleanToggle(initialValue?: boolean): readonly [boolean, (value?: React.SetStateAction<boolean>) => void];
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useToggle/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,yBAGnC,MAAM,cAAc,CAAC,CAAC,CAAC,WAehD;AAED,wBAAgB,gBAAgB,CAAC,YAAY,UAAQ,uEAEpD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';
|
|
2
|
+
export interface UncontrolledOptions<T> {
|
|
3
|
+
value: T | null | undefined;
|
|
4
|
+
defaultValue: T | null | undefined;
|
|
5
|
+
finalValue: T | null;
|
|
6
|
+
onChange(value: T | null): void;
|
|
7
|
+
onValueUpdate?(value: T | null): void;
|
|
8
|
+
rule: (value: T | null | undefined) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function useUncontrolled<T>({ value, defaultValue, finalValue, rule, onChange, onValueUpdate, }: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode];
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useUncontrolled/index.ts"],"names":[],"mappings":"AAGA,oBAAY,gBAAgB,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC;AAEzE,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5B,YAAY,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IACtC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,OAAO,CAAC;CAChD;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,KAAK,EACL,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,aAAa,GACd,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,EAAE,gBAAgB,CAAC,CA+C/F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useWindowEvent/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,cAAc,EAC3D,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,GAAG,EACtD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,QAM5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,WAEvB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubed/hooks",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "cjs/index.js",
|
|
5
|
+
"module": "esm/index.js",
|
|
6
|
+
"browser": "lib/index.umd.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"homepage": "https://github.com/kubesphere/kube-design",
|
|
11
|
+
"files": [
|
|
12
|
+
"cjs",
|
|
13
|
+
"esm",
|
|
14
|
+
"lib"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"url": "https://github.com/kubesphere/kube-design.git",
|
|
18
|
+
"type": "git",
|
|
19
|
+
"directory": "packages/hooks"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=16.8.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {},
|
|
25
|
+
"devDependencies": {}
|
|
26
|
+
}
|