@siberiacancode/reactuse 0.3.1 → 0.3.3
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/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAudio/useAudio.cjs +1 -1
- package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs +1 -1
- package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
- package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs +2 -0
- package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -0
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +8 -9
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAudio/useAudio.mjs +29 -23
- package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +12 -13
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +8 -9
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +19 -20
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +15 -16
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs +3 -3
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +17 -18
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +17 -18
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs +12 -12
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +11 -12
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +13 -14
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +18 -19
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +11 -12
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +8 -9
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +12 -13
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +11 -12
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -20
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +8 -9
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +11 -12
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +11 -12
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +11 -12
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +12 -13
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +13 -14
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMeasure/useMeasure.mjs +15 -16
- package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +32 -33
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs +12 -13
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +11 -12
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +23 -24
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +31 -32
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +11 -12
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +11 -12
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs +11 -12
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs +12 -13
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +20 -21
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +13 -14
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs +11 -12
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +21 -22
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +58 -0
- package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -0
- package/dist/esm/hooks/useVisibility/useVisibility.mjs +13 -14
- package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs +4 -4
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs +12 -16
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
- package/dist/esm/index.mjs +256 -256
- package/dist/esm/utils/helpers/isTarget.mjs +9 -3
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/types/hooks/elements.d.ts +1 -0
- package/dist/types/hooks/useHash/useHash.d.ts +18 -5
- package/dist/types/hooks/useTextareaAutosize/useTextareaAutosize.d.ts +60 -0
- package/dist/types/utils/helpers/index.d.ts +0 -1
- package/dist/types/utils/helpers/isTarget.d.ts +19 -2
- package/package.json +89 -89
- package/dist/cjs/utils/helpers/getElement.cjs +0 -2
- package/dist/cjs/utils/helpers/getElement.cjs.map +0 -1
- package/dist/esm/utils/helpers/getElement.mjs +0 -10
- package/dist/esm/utils/helpers/getElement.mjs.map +0 -1
- package/dist/types/utils/helpers/getElement.d.ts +0 -12
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const n = Symbol("target"), o = (e) => "current" in e ? e.current : typeof e.value == "function" ? e.value() : typeof e.value == "string" ? document.querySelector(e.value) : (e.value instanceof Document || e.value instanceof Window || e.value instanceof Element, e.value), l = (e) => ({
|
|
2
|
+
value: e,
|
|
3
|
+
type: n
|
|
4
|
+
}), u = (e) => typeof e == "object" && ("current" in e || e && e.type === n);
|
|
5
|
+
u.wrap = l;
|
|
6
|
+
u.getElement = o;
|
|
3
7
|
export {
|
|
4
|
-
|
|
8
|
+
u as isTarget,
|
|
9
|
+
l as target,
|
|
10
|
+
n as targetSymbol
|
|
5
11
|
};
|
|
6
12
|
//# sourceMappingURL=isTarget.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport const targetSymbol = Symbol('target');\n\nexport type Target = (() => Element) | string | Document | Element | Window;\n\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nconst getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const isTarget = (target: HookTarget) =>\n typeof target === 'object' &&\n ('current' in target || (target && (target as any).type === targetSymbol));\n\nisTarget.wrap = target;\nisTarget.getElement = getElement;\n"],"names":["targetSymbol","getElement","target","isTarget"],"mappings":"AAEO,MAAMA,IAAe,OAAO,QAAQ,GAWrCC,IAAa,CAACC,MACd,aAAaA,IACRA,EAAO,UAGZ,OAAOA,EAAO,SAAU,aACnBA,EAAO,MAAA,IAGZ,OAAOA,EAAO,SAAU,WACnB,SAAS,cAAcA,EAAO,KAAK,KAGxCA,EAAO,iBAAiB,YAIxBA,EAAO,iBAAiB,UAIxBA,EAAO,iBAAiB,SACnBA,EAAO,QAMLA,IAAS,CAACA,OAAoB;AAAA,EACzC,OAAOA;AAAAA,EACP,MAAMF;AACR,IAEaG,IAAW,CAACD,MACvB,OAAOA,KAAW,aACjB,aAAaA,KAAWA,KAAWA,EAAe,SAASF;AAE9DG,EAAS,OAAOD;AAChBC,EAAS,aAAaF;"}
|
|
@@ -13,4 +13,5 @@ export * from './usePaint/usePaint';
|
|
|
13
13
|
export * from './useRightClick/useRightClick';
|
|
14
14
|
export * from './useScript/useScript';
|
|
15
15
|
export * from './useSticky/useSticky';
|
|
16
|
+
export * from './useTextareaAutosize/useTextareaAutosize';
|
|
16
17
|
export * from './useTextDirection/useTextDirection';
|
|
@@ -31,11 +31,7 @@ export interface UseHash {
|
|
|
31
31
|
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
|
-
* const [hash, setHash] = useHash("initial"
|
|
35
|
-
* enabled: true,
|
|
36
|
-
* mode: "replace",
|
|
37
|
-
* onChange: (newHash) => console.log('Hash changed:', newHash)
|
|
38
|
-
* });
|
|
34
|
+
* const [hash, setHash] = useHash("initial");
|
|
39
35
|
*
|
|
40
36
|
* @overload
|
|
41
37
|
* @param {string} [initialValue] The initial hash value if no hash exists
|
|
@@ -44,6 +40,23 @@ export interface UseHash {
|
|
|
44
40
|
*
|
|
45
41
|
* @example
|
|
46
42
|
* const [hash, setHash] = useHash("initial", (newHash) => console.log('callback'));
|
|
43
|
+
*
|
|
44
|
+
* @overload
|
|
45
|
+
* @param {UseHashOptions} [options] Configuration options
|
|
46
|
+
* @param {boolean} [options.enabled] The enabled state of the hook
|
|
47
|
+
* @param {'initial' | 'replace'} [options.mode] The mode of hash setting
|
|
48
|
+
* @param {(hash: string) => void} [options.onChange] Callback function called when hash changes
|
|
49
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const [hash, setHash] = useHash();
|
|
53
|
+
*
|
|
54
|
+
* @overload
|
|
55
|
+
* @param {(hash: string) => void} [callback] Callback function called when hash changes
|
|
56
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const [hash, setHash] = useHash((newHash) => console.log('callback'));
|
|
47
60
|
*/
|
|
48
61
|
export declare const useHash: UseHash;
|
|
49
62
|
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { HookTarget } from '../../utils/helpers';
|
|
2
|
+
import { StateRef } from '../useRefState/useRefState';
|
|
3
|
+
/** The use textarea autosize options */
|
|
4
|
+
export interface UseTextareaAutosizeOptions {
|
|
5
|
+
/** The initial value for the textarea */
|
|
6
|
+
initialValue?: string;
|
|
7
|
+
/** Callback function called when the textarea size changes */
|
|
8
|
+
onResize?: () => void;
|
|
9
|
+
}
|
|
10
|
+
/** The use textarea autosize return type */
|
|
11
|
+
export interface UseTextareaAutosizeReturn {
|
|
12
|
+
/** The current value of the textarea */
|
|
13
|
+
value: string;
|
|
14
|
+
/** Function to clear the textarea value */
|
|
15
|
+
clear: () => void;
|
|
16
|
+
/** Function to set the textarea value */
|
|
17
|
+
setValue: (value: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface UseTextareaAutosize {
|
|
20
|
+
(target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;
|
|
21
|
+
<Target extends HTMLTextAreaElement = HTMLTextAreaElement>(initialValue: string, target?: never): UseTextareaAutosizeReturn & {
|
|
22
|
+
ref: StateRef<Target>;
|
|
23
|
+
};
|
|
24
|
+
<Target extends HTMLTextAreaElement = HTMLTextAreaElement>(options?: UseTextareaAutosizeOptions, target?: never): UseTextareaAutosizeReturn & {
|
|
25
|
+
ref: StateRef<Target>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @name useTextareaAutosize
|
|
30
|
+
* @description - Hook that automatically adjusts textarea height based on content
|
|
31
|
+
* @category Elements
|
|
32
|
+
* @usage medium
|
|
33
|
+
*
|
|
34
|
+
* @overload
|
|
35
|
+
* @param {HookTarget} target The target textarea element
|
|
36
|
+
* @param {string} [options.initialValue] The initial value for the textarea
|
|
37
|
+
* @param {Function} [options.onResize] Callback function called when the textarea size changes
|
|
38
|
+
* @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const { value, setValue, clear } = useTextareaAutosize(ref);
|
|
42
|
+
*
|
|
43
|
+
* @overload
|
|
44
|
+
* @template Target The textarea element type
|
|
45
|
+
* @param {string} initialValue The initial value for the textarea
|
|
46
|
+
* @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const { ref, value, setValue, clear } = useTextareaAutosize('initial');
|
|
50
|
+
*
|
|
51
|
+
* @overload
|
|
52
|
+
* @template Target The textarea element type
|
|
53
|
+
* @param {string} [options.initialValue] The initial value for the textarea
|
|
54
|
+
* @param {Function} [options.onResize] Callback function called when the textarea size changes
|
|
55
|
+
* @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const { ref, value, setValue, clear } = useTextareaAutosize();
|
|
59
|
+
*/
|
|
60
|
+
export declare const useTextareaAutosize: UseTextareaAutosize;
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export declare const targetSymbol: unique symbol;
|
|
3
|
+
export type Target = (() => Element) | string | Document | Element | Window;
|
|
4
|
+
export type HookTarget = RefObject<Element | null | undefined> | {
|
|
5
|
+
value: Target;
|
|
6
|
+
type: symbol;
|
|
7
|
+
};
|
|
8
|
+
export declare const target: (target: Target) => {
|
|
9
|
+
value: Target;
|
|
10
|
+
type: symbol;
|
|
11
|
+
};
|
|
12
|
+
export declare const isTarget: {
|
|
13
|
+
(target: HookTarget): boolean;
|
|
14
|
+
wrap: (target: Target) => {
|
|
15
|
+
value: Target;
|
|
16
|
+
type: symbol;
|
|
17
|
+
};
|
|
18
|
+
getElement: (target: HookTarget) => Window | Document | Element | null | undefined;
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "The ultimate collection of react hooks",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "SIBERIA CAN CODE 🧊",
|
|
7
|
-
"url": "https://github.com/siberiacancode"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"homepage": "https://siberiacancode.github.io/reactuse/",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/siberiacancode/reactuse.git",
|
|
14
|
-
"directory": "packages/core"
|
|
15
|
-
},
|
|
16
|
-
"bugs": "https://github.com/siberiacancode/reactuse/issues",
|
|
17
|
-
"keywords": [
|
|
18
|
-
"react",
|
|
19
|
-
"react hooks",
|
|
20
|
-
"react use",
|
|
21
|
-
"use",
|
|
22
|
-
"hooks"
|
|
23
|
-
],
|
|
24
|
-
"sideEffects": false,
|
|
25
|
-
"exports": {
|
|
26
|
-
"types": "./dist/types/index.d.ts",
|
|
27
|
-
"import": "./dist/esm/index.mjs",
|
|
28
|
-
"require": "./dist/cjs/index.cjs"
|
|
29
|
-
},
|
|
30
|
-
"main": "dist/cjs/index.cjs",
|
|
31
|
-
"module": "dist/esm/index.mjs",
|
|
32
|
-
"types": "dist/types/index.d.ts",
|
|
33
|
-
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
],
|
|
36
|
-
"engines": {
|
|
37
|
-
"node": ">=14"
|
|
38
|
-
},
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"prepublishOnly": "pnpm unit-test run && pnpm build",
|
|
44
|
-
"build": "shx rm -rf dist && vite build",
|
|
45
|
-
"build:js": "tsc --project tsconfig.build.json && prettier --write src/bundle",
|
|
46
|
-
"lint": "eslint . --fix",
|
|
47
|
-
"lint-inspector": "npx @eslint/config-inspector@latest",
|
|
48
|
-
"format": "prettier --write .",
|
|
49
|
-
"pretty": "pnpm lint && pnpm format",
|
|
50
|
-
"unit-test": "vitest",
|
|
51
|
-
"lint-staged": "lint-staged"
|
|
52
|
-
},
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"@types/react": "^18 || ^19",
|
|
55
|
-
"react": "^18 || ^19",
|
|
56
|
-
"react-dom": "^18 || ^19"
|
|
57
|
-
},
|
|
58
|
-
"peerDependenciesMeta": {
|
|
59
|
-
"@types/react": {
|
|
60
|
-
"optional": true
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"screenfull": "^6.0.2"
|
|
65
|
-
},
|
|
66
|
-
"devDependencies": {
|
|
67
|
-
"@siberiacancode/vitest": "^2.
|
|
68
|
-
"@testing-library/dom": "^10.4.1",
|
|
69
|
-
"@testing-library/react": "^16.3.0",
|
|
70
|
-
"@types/dom-speech-recognition": "^0.0.
|
|
71
|
-
"@types/react": "^19.
|
|
72
|
-
"@types/react-dom": "^19.
|
|
73
|
-
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
-
"@vitejs/plugin-react": "^5.0
|
|
75
|
-
"core-js": "^3.
|
|
76
|
-
"react": "^19.
|
|
77
|
-
"react-dom": "^19.
|
|
78
|
-
"shx": "^0.4.0",
|
|
79
|
-
"vite": "^7.
|
|
80
|
-
"vite-plugin-dts": "^4.5.4",
|
|
81
|
-
"vitest": "^
|
|
82
|
-
},
|
|
83
|
-
"lint-staged": {
|
|
84
|
-
"*.{js,ts,tsx}": [
|
|
85
|
-
"eslint --fix",
|
|
86
|
-
"prettier --write"
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@siberiacancode/reactuse",
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "The ultimate collection of react hooks",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "SIBERIA CAN CODE 🧊",
|
|
7
|
+
"url": "https://github.com/siberiacancode"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://siberiacancode.github.io/reactuse/",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/siberiacancode/reactuse.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"bugs": "https://github.com/siberiacancode/reactuse/issues",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react",
|
|
19
|
+
"react hooks",
|
|
20
|
+
"react use",
|
|
21
|
+
"use",
|
|
22
|
+
"hooks"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"import": "./dist/esm/index.mjs",
|
|
28
|
+
"require": "./dist/cjs/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.mjs",
|
|
32
|
+
"types": "dist/types/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=14"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"prepublishOnly": "pnpm unit-test run && pnpm build",
|
|
44
|
+
"build": "shx rm -rf dist && vite build",
|
|
45
|
+
"build:js": "tsc --project tsconfig.build.json && prettier --write src/bundle",
|
|
46
|
+
"lint": "eslint . --fix",
|
|
47
|
+
"lint-inspector": "npx @eslint/config-inspector@latest",
|
|
48
|
+
"format": "prettier --write .",
|
|
49
|
+
"pretty": "pnpm lint && pnpm format",
|
|
50
|
+
"unit-test": "vitest",
|
|
51
|
+
"lint-staged": "lint-staged"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@types/react": "^18 || ^19",
|
|
55
|
+
"react": "^18 || ^19",
|
|
56
|
+
"react-dom": "^18 || ^19"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@types/react": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"screenfull": "^6.0.2"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@siberiacancode/vitest": "^2.2.0",
|
|
68
|
+
"@testing-library/dom": "^10.4.1",
|
|
69
|
+
"@testing-library/react": "^16.3.0",
|
|
70
|
+
"@types/dom-speech-recognition": "^0.0.7",
|
|
71
|
+
"@types/react": "^19.2.2",
|
|
72
|
+
"@types/react-dom": "^19.2.2",
|
|
73
|
+
"@types/web-bluetooth": "^0.0.21",
|
|
74
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
75
|
+
"core-js": "^3.46.0",
|
|
76
|
+
"react": "^19.2.0",
|
|
77
|
+
"react-dom": "^19.2.0",
|
|
78
|
+
"shx": "^0.4.0",
|
|
79
|
+
"vite": "^7.2.2",
|
|
80
|
+
"vite-plugin-dts": "^4.5.4",
|
|
81
|
+
"vitest": "^4.0.8"
|
|
82
|
+
},
|
|
83
|
+
"lint-staged": {
|
|
84
|
+
"*.{js,ts,tsx}": [
|
|
85
|
+
"eslint --fix",
|
|
86
|
+
"prettier --write"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=Symbol("target"),u=e=>({value:e,type:n}),l=e=>"current"in e?e.current:typeof e.value=="function"?e.value():typeof e.value=="string"?document.querySelector(e.value):(e.value instanceof Document||e.value instanceof Window||e.value instanceof Element,e.value);exports.getElement=l;exports.target=u;exports.targetSymbol=n;
|
|
2
|
-
//# sourceMappingURL=getElement.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getElement.cjs","sources":["../../../../src/utils/helpers/getElement.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport type Target = (() => Element) | string | Document | Element | Window;\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nexport const targetSymbol = Symbol('target');\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n"],"names":["targetSymbol","target","getElement"],"mappings":"gFAUO,MAAMA,EAAe,OAAO,QAAQ,EAC9BC,EAAUA,IAAoB,CACzC,MAAOA,EACP,KAAMD,CACR,GAEaE,EAAcD,GACrB,YAAaA,EACRA,EAAO,QAGZ,OAAOA,EAAO,OAAU,WACnBA,EAAO,MAAA,EAGZ,OAAOA,EAAO,OAAU,SACnB,SAAS,cAAcA,EAAO,KAAK,GAGxCA,EAAO,iBAAiB,UAIxBA,EAAO,iBAAiB,QAIxBA,EAAO,iBAAiB,QACnBA,EAAO"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const n = Symbol("target"), u = (e) => ({
|
|
2
|
-
value: e,
|
|
3
|
-
type: n
|
|
4
|
-
}), l = (e) => "current" in e ? e.current : typeof e.value == "function" ? e.value() : typeof e.value == "string" ? document.querySelector(e.value) : (e.value instanceof Document || e.value instanceof Window || e.value instanceof Element, e.value);
|
|
5
|
-
export {
|
|
6
|
-
l as getElement,
|
|
7
|
-
u as target,
|
|
8
|
-
n as targetSymbol
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=getElement.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getElement.mjs","sources":["../../../../src/utils/helpers/getElement.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport type Target = (() => Element) | string | Document | Element | Window;\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nexport const targetSymbol = Symbol('target');\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n"],"names":["targetSymbol","target","getElement"],"mappings":"AAUO,MAAMA,IAAe,OAAO,QAAQ,GAC9BC,IAAS,CAACA,OAAoB;AAAA,EACzC,OAAOA;AAAAA,EACP,MAAMD;AACR,IAEaE,IAAa,CAACD,MACrB,aAAaA,IACRA,EAAO,UAGZ,OAAOA,EAAO,SAAU,aACnBA,EAAO,MAAA,IAGZ,OAAOA,EAAO,SAAU,WACnB,SAAS,cAAcA,EAAO,KAAK,KAGxCA,EAAO,iBAAiB,YAIxBA,EAAO,iBAAiB,UAIxBA,EAAO,iBAAiB,SACnBA,EAAO;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
export type Target = (() => Element) | string | Document | Element | Window;
|
|
3
|
-
export type HookTarget = RefObject<Element | null | undefined> | {
|
|
4
|
-
value: Target;
|
|
5
|
-
type: symbol;
|
|
6
|
-
};
|
|
7
|
-
export declare const targetSymbol: unique symbol;
|
|
8
|
-
export declare const target: (target: Target) => {
|
|
9
|
-
value: Target;
|
|
10
|
-
type: symbol;
|
|
11
|
-
};
|
|
12
|
-
export declare const getElement: (target: HookTarget) => Window | Document | Element | null | undefined;
|