@vibe/hooks 4.0.0-alpha.1 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as useClickOutside } from "./useClickOutside";
|
|
2
|
-
export { default as useIsOverflowing } from "./useIsOverflowing";
|
|
3
|
-
export { default as useResizeObserver } from "./useResizeObserver";
|
|
1
|
+
export { default as useClickOutside } from "./useClickOutside";
|
|
2
|
+
export { default as useIsOverflowing } from "./useIsOverflowing";
|
|
3
|
+
export { default as useResizeObserver } from "./useResizeObserver";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type RefObject } from "react";
|
|
2
|
-
import { type GenericEventCallback } from "@vibe/shared";
|
|
3
|
-
export default function useClickOutside({ ref, callback, ignoreClasses, eventName }: {
|
|
4
|
-
ref: RefObject<HTMLElement>;
|
|
5
|
-
callback: GenericEventCallback;
|
|
6
|
-
ignoreClasses?: string[];
|
|
7
|
-
eventName?: keyof HTMLElementEventMap | string;
|
|
8
|
-
}): void;
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type GenericEventCallback } from "@vibe/shared";
|
|
3
|
+
export default function useClickOutside({ ref, callback, ignoreClasses, eventName }: {
|
|
4
|
+
ref: RefObject<HTMLElement>;
|
|
5
|
+
callback: GenericEventCallback;
|
|
6
|
+
ignoreClasses?: string[];
|
|
7
|
+
eventName?: keyof HTMLElementEventMap | string;
|
|
8
|
+
}): void;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { type RefObject } from "react";
|
|
2
|
-
export default function useIsOverflowing({ ref, ignoreHeightOverflow, tolerance: heightTolerance, widthTolerance }: {
|
|
3
|
-
/**
|
|
4
|
-
* The ref of the element to check for overflow.
|
|
5
|
-
*/
|
|
6
|
-
ref: RefObject<HTMLElement>;
|
|
7
|
-
/**
|
|
8
|
-
* Whether to ignore height overflow.
|
|
9
|
-
*/
|
|
10
|
-
ignoreHeightOverflow?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* The tolerance value to consider the element as overflowing (height overflow).
|
|
13
|
-
*/
|
|
14
|
-
tolerance?: number;
|
|
15
|
-
/**
|
|
16
|
-
* The tolerance value to consider the element as overflowing (width overflow).
|
|
17
|
-
*/
|
|
18
|
-
widthTolerance?: number;
|
|
19
|
-
}): boolean;
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export default function useIsOverflowing({ ref, ignoreHeightOverflow, tolerance: heightTolerance, widthTolerance }: {
|
|
3
|
+
/**
|
|
4
|
+
* The ref of the element to check for overflow.
|
|
5
|
+
*/
|
|
6
|
+
ref: RefObject<HTMLElement>;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to ignore height overflow.
|
|
9
|
+
*/
|
|
10
|
+
ignoreHeightOverflow?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The tolerance value to consider the element as overflowing (height overflow).
|
|
13
|
+
*/
|
|
14
|
+
tolerance?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The tolerance value to consider the element as overflowing (width overflow).
|
|
17
|
+
*/
|
|
18
|
+
widthTolerance?: number;
|
|
19
|
+
}): boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type RefObject } from "react";
|
|
2
|
-
type ResizeCallback = ({ borderBoxSize }: {
|
|
3
|
-
borderBoxSize: ResizeObserverSize;
|
|
4
|
-
}) => void;
|
|
5
|
-
export default function useResizeObserver({ ref, callback, debounceTime }: {
|
|
6
|
-
ref: RefObject<HTMLElement>;
|
|
7
|
-
callback: ResizeCallback;
|
|
8
|
-
debounceTime?: number;
|
|
9
|
-
}): void;
|
|
10
|
-
export {};
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
type ResizeCallback = ({ borderBoxSize }: {
|
|
3
|
+
borderBoxSize: ResizeObserverSize;
|
|
4
|
+
}) => void;
|
|
5
|
+
export default function useResizeObserver({ ref, callback, debounceTime }: {
|
|
6
|
+
ref: RefObject<HTMLElement>;
|
|
7
|
+
callback: ResizeCallback;
|
|
8
|
+
debounceTime?: number;
|
|
9
|
+
}): void;
|
|
10
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useResizeObserver/index.ts"],"sourcesContent":["import { type RefObject, useCallback, useEffect } from \"react\";\nimport { debounce } from \"es-toolkit\";\n\ntype ResizeCallback = ({ borderBoxSize }: { borderBoxSize: ResizeObserverSize }) => void;\n\nexport default function useResizeObserver({\n ref,\n callback,\n debounceTime = 200\n}: {\n ref: RefObject<HTMLElement>;\n callback: ResizeCallback;\n debounceTime?: number;\n}) {\n const debouncedCallback = useCallback(debounce<ResizeCallback>(callback, debounceTime), [callback, debounceTime]);\n\n useEffect(() => {\n if (!window.ResizeObserver) {\n return;\n }\n if (!ref?.current) return;\n\n function borderBoxSizeCallback(borderBoxSize: ResizeObserverSize | ReadonlyArray<ResizeObserverSize>): number {\n const value = Array.isArray(borderBoxSize) ? borderBoxSize[0] : borderBoxSize;\n return window.requestAnimationFrame(() => {\n debouncedCallback({ borderBoxSize: value });\n });\n }\n\n let animationFrameId: number | null = null;\n\n const resizeObserver = new ResizeObserver(entries => {\n const entry = entries[0];\n if (entry && entry.borderBoxSize) {\n // handle chrome (entry.borderBoxSize[0])\n // handle ff (entry.borderBoxSize)\n if (!Array.isArray(entry.borderBoxSize)) {\n animationFrameId = borderBoxSizeCallback(entry.borderBoxSize);\n } else {\n const borderBoxEntry = entry.borderBoxSize[0];\n animationFrameId = borderBoxSizeCallback(borderBoxEntry);\n }\n } else if (entry.contentRect) {\n // handle safari (entry.contentRect)\n const borderBoxSize = { blockSize: entry.contentRect.height, inlineSize: entry?.contentRect?.width || 0 };\n animationFrameId = borderBoxSizeCallback(borderBoxSize);\n } else {\n return;\n }\n });\n\n resizeObserver.observe(ref?.current);\n\n return () => {\n if (debounceTime !== 0) {\n debouncedCallback.cancel();\n }\n\n if (animationFrameId) {\n window.cancelAnimationFrame(animationFrameId);\n }\n\n resizeObserver.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref?.current, callback, debounceTime, debouncedCallback]);\n}\n"],"names":["useResizeObserver","ref","callback","debounceTime","debouncedCallback","useCallback","debounce","useEffect","window","ResizeObserver","current","borderBoxSizeCallback","borderBoxSize","value","Array","isArray","requestAnimationFrame","animationFrameId","resizeObserver","entries","entry","contentRect","blockSize","height","inlineSize","_a","width","observe","cancel","cancelAnimationFrame","disconnect"],"mappings":"yFAKwB,SAAAA,GAAkBC,IACxCA,EAAGC,SACHA,EAAQC,aACRA,EAAe,MAMf,MAAMC,EAAoBC,EAAYC,EAAyBJ,EAAUC,GAAe,CAACD,EAAUC,IAEnGI,GAAU,KACR,IAAKC,OAAOC,eACV,OAEF,KAAKR,aAAA,EAAAA,EAAKS,SAAS,OAEnB,SAASC,EAAsBC,GAC7B,MAAMC,EAAQC,MAAMC,QAAQH,GAAiBA,EAAc,GAAKA,EAChE,OAAOJ,OAAOQ,uBAAsB,KAClCZ,EAAkB,CAAEQ,cAAeC,GAAQ,GAE/C,CAEA,IAAII,EAAkC,KAEtC,MAAMC,EAAiB,IAAIT,gBAAeU,UACxC,MAAMC,EAAQD,EAAQ,GACtB,GAAIC,GAASA,EAAMR,cAGjB,GAAKE,MAAMC,QAAQK,EAAMR,eAElB,CAELK,EAAmBN,EADIS,EAAMR,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useResizeObserver/index.ts"],"sourcesContent":["import { type RefObject, useCallback, useEffect } from \"react\";\nimport { debounce } from \"es-toolkit\";\n\ntype ResizeCallback = ({ borderBoxSize }: { borderBoxSize: ResizeObserverSize }) => void;\n\nexport default function useResizeObserver({\n ref,\n callback,\n debounceTime = 200\n}: {\n ref: RefObject<HTMLElement>;\n callback: ResizeCallback;\n debounceTime?: number;\n}) {\n const debouncedCallback = useCallback(debounce<ResizeCallback>(callback, debounceTime), [callback, debounceTime]);\n\n useEffect(() => {\n if (!window.ResizeObserver) {\n return;\n }\n if (!ref?.current) return;\n\n function borderBoxSizeCallback(borderBoxSize: ResizeObserverSize | ReadonlyArray<ResizeObserverSize>): number {\n const value = Array.isArray(borderBoxSize) ? borderBoxSize[0] : borderBoxSize;\n return window.requestAnimationFrame(() => {\n debouncedCallback({ borderBoxSize: value });\n });\n }\n\n let animationFrameId: number | null = null;\n\n const resizeObserver = new ResizeObserver(entries => {\n const entry = entries[0];\n if (entry && entry.borderBoxSize) {\n // handle chrome (entry.borderBoxSize[0])\n // handle ff (entry.borderBoxSize)\n if (!Array.isArray(entry.borderBoxSize)) {\n animationFrameId = borderBoxSizeCallback(entry.borderBoxSize);\n } else {\n const borderBoxEntry = entry.borderBoxSize[0];\n animationFrameId = borderBoxSizeCallback(borderBoxEntry);\n }\n } else if (entry.contentRect) {\n // handle safari (entry.contentRect)\n const borderBoxSize = { blockSize: entry.contentRect.height, inlineSize: entry?.contentRect?.width || 0 };\n animationFrameId = borderBoxSizeCallback(borderBoxSize);\n } else {\n return;\n }\n });\n\n resizeObserver.observe(ref?.current);\n\n return () => {\n if (debounceTime !== 0) {\n debouncedCallback.cancel();\n }\n\n if (animationFrameId) {\n window.cancelAnimationFrame(animationFrameId);\n }\n\n resizeObserver.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref?.current, callback, debounceTime, debouncedCallback]);\n}\n"],"names":["useResizeObserver","ref","callback","debounceTime","debouncedCallback","useCallback","debounce","useEffect","window","ResizeObserver","current","borderBoxSizeCallback","borderBoxSize","value","Array","isArray","requestAnimationFrame","animationFrameId","resizeObserver","entries","entry","contentRect","blockSize","height","inlineSize","_a","width","observe","cancel","cancelAnimationFrame","disconnect"],"mappings":"yFAKwB,SAAAA,GAAkBC,IACxCA,EAAGC,SACHA,EAAQC,aACRA,EAAe,MAMf,MAAMC,EAAoBC,EAAYC,EAAyBJ,EAAUC,GAAe,CAACD,EAAUC,IAEnGI,GAAU,KACR,IAAKC,OAAOC,eACV,OAEF,KAAKR,aAAA,EAAAA,EAAKS,SAAS,OAEnB,SAASC,EAAsBC,GAC7B,MAAMC,EAAQC,MAAMC,QAAQH,GAAiBA,EAAc,GAAKA,EAChE,OAAOJ,OAAOQ,uBAAsB,KAClCZ,EAAkB,CAAEQ,cAAeC,GAAQ,GAE/C,CAEA,IAAII,EAAkC,KAEtC,MAAMC,EAAiB,IAAIT,gBAAeU,UACxC,MAAMC,EAAQD,EAAQ,GACtB,GAAIC,GAASA,EAAMR,cAGjB,GAAKE,MAAMC,QAAQK,EAAMR,eAElB,CAELK,EAAmBN,EADIS,EAAMR,cAAc,GAE7C,MAJEK,EAAmBN,EAAsBS,EAAMR,mBAK5C,KAAIQ,EAAMC,YAKf,OAL4B,CAE5B,MAAMT,EAAgB,CAAEU,UAAWF,EAAMC,YAAYE,OAAQC,YAA8B,QAAlBC,EAAAL,aAAK,EAALA,EAAOC,mBAAW,IAAAI,OAAA,EAAAA,EAAEC,QAAS,GACtGT,EAAmBN,EAAsBC,EAC3C,CAEA,KAKF,OAFAM,EAAeS,QAAQ1B,aAAG,EAAHA,EAAKS,SAErB,KACgB,IAAjBP,GACFC,EAAkBwB,SAGhBX,GACFT,OAAOqB,qBAAqBZ,GAG9BC,EAAeY,YAAY,CAC5B,GAEA,CAAC7B,eAAAA,EAAKS,QAASR,EAAUC,EAAcC,GAC5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe/hooks",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "Vibe sub-package for React hooks",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vibe/shared": "^4.0.0-alpha.
|
|
36
|
+
"@vibe/shared": "^4.0.0-alpha.2",
|
|
37
37
|
"classnames": "^2.5.1",
|
|
38
38
|
"es-toolkit": "^1.39.10"
|
|
39
39
|
},
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@testing-library/react": "^12.1.2",
|
|
42
42
|
"@testing-library/react-hooks": "^7.0.2",
|
|
43
43
|
"@testing-library/user-event": "^13.5.0",
|
|
44
|
-
"@vibe/config": "^4.0.0-alpha.
|
|
44
|
+
"@vibe/config": "^4.0.0-alpha.2",
|
|
45
45
|
"react": "^16.13.0",
|
|
46
46
|
"react-dom": "^16.13.0",
|
|
47
47
|
"react-test-renderer": "16",
|
|
48
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^1.6.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"../../node_modules/@vibe/config/.eslintrc.cjs"
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "8c8df239f258a1ae3f81c1dff9304693fe466ab0"
|
|
67
67
|
}
|