@vibe/hooks 3.0.3-alpha-ea565.0 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export { default as useClickOutside } from "./useClickOutside";
2
+ export { default as useIsOverflowing } from "./useIsOverflowing";
3
+ export { default as useResizeObserver } from "./useResizeObserver";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export{default as useClickOutside}from"./useClickOutside/index.js";
1
+ export{default as useClickOutside}from"./useClickOutside/index.js";export{default as useIsOverflowing}from"./useIsOverflowing/index.js";export{default as useResizeObserver}from"./useResizeObserver/index.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -0,0 +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;
@@ -0,0 +1,2 @@
1
+ import{useState as e,useCallback as r}from"react";import t from"../useResizeObserver/index.js";function n(e,r,t=0,n=0){if(!e)return!1;return e.scrollWidth>e.clientWidth+n||!r&&e.scrollHeight>e.clientHeight+t}function i({ref:i,ignoreHeightOverflow:o=!1,tolerance:c,widthTolerance:l}){const[u,f]=e((()=>n(null==i?void 0:i.current,o,c,l))),s=r((()=>{const e=null==i?void 0:i.current;if(!e)return;const r=n(e,o,c,l);f((e=>e!==r?r:e))}),[o,i,c,l]);return t({ref:i,callback:s,debounceTime:0}),u}export{i as default};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/useIsOverflowing/index.ts"],"sourcesContent":["import { type RefObject, useCallback, useState } from \"react\";\nimport useResizeObserver from \"../useResizeObserver\";\n\nfunction checkOverflow(element: HTMLElement, ignoreHeightOverflow: boolean, heightTolerance = 0, widthTolerance = 0) {\n if (!element) {\n return false;\n }\n const isOverflowingWidth = element.clientWidth + widthTolerance < element.scrollWidth;\n const isOverflowingHeight = !ignoreHeightOverflow && element.clientHeight + heightTolerance < element.scrollHeight;\n return isOverflowingWidth || isOverflowingHeight;\n}\n\nexport default function useIsOverflowing({\n ref,\n ignoreHeightOverflow = false,\n tolerance: heightTolerance,\n widthTolerance\n}: {\n /**\n * The ref of the element to check for overflow.\n */\n ref: RefObject<HTMLElement>;\n /**\n * Whether to ignore height overflow.\n */\n ignoreHeightOverflow?: boolean;\n /**\n * The tolerance value to consider the element as overflowing (height overflow).\n */\n tolerance?: number;\n /**\n * The tolerance value to consider the element as overflowing (width overflow).\n */\n widthTolerance?: number;\n}) {\n const [isOverflowing, setIsOverflowing] = useState<boolean>(() =>\n checkOverflow(ref?.current, ignoreHeightOverflow, heightTolerance, widthTolerance)\n );\n const callback = useCallback(() => {\n const element = ref?.current;\n if (!element) return;\n\n const newOverflowState = checkOverflow(element, ignoreHeightOverflow, heightTolerance, widthTolerance);\n setIsOverflowing(prevState => (prevState !== newOverflowState ? newOverflowState : prevState));\n }, [ignoreHeightOverflow, ref, heightTolerance, widthTolerance]);\n\n useResizeObserver({\n ref,\n callback,\n debounceTime: 0\n });\n\n return isOverflowing;\n}\n"],"names":["checkOverflow","element","ignoreHeightOverflow","heightTolerance","widthTolerance","scrollWidth","clientWidth","scrollHeight","clientHeight","useIsOverflowing","ref","tolerance","isOverflowing","setIsOverflowing","useState","current","callback","useCallback","newOverflowState","prevState","useResizeObserver","debounceTime"],"mappings":"+FAGA,SAASA,EAAcC,EAAsBC,EAA+BC,EAAkB,EAAGC,EAAiB,GAChH,IAAKH,EACH,OAAO,EAIT,OAFkEA,EAAQI,YAA/CJ,EAAQK,YAAcF,IACpBF,GAAiED,EAAQM,aAAjDN,EAAQO,aAAeL,CAE9E,CAEc,SAAUM,GAAiBC,IACvCA,EAAGR,qBACHA,GAAuB,EACvBS,UAAWR,EAAeC,eAC1BA,IAmBA,MAAOQ,EAAeC,GAAoBC,GAAkB,IAC1Dd,EAAcU,aAAA,EAAAA,EAAKK,QAASb,EAAsBC,EAAiBC,KAE/DY,EAAWC,GAAY,KAC3B,MAAMhB,EAAUS,aAAA,EAAAA,EAAKK,QACrB,IAAKd,EAAS,OAEd,MAAMiB,EAAmBlB,EAAcC,EAASC,EAAsBC,EAAiBC,GACvFS,GAAiBM,GAAcA,IAAcD,EAAmBA,EAAmBC,GAAW,GAC7F,CAACjB,EAAsBQ,EAAKP,EAAiBC,IAQhD,OANAgB,EAAkB,CAChBV,MACAM,WACAK,aAAc,IAGTT,CACT"}
@@ -0,0 +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 {};
@@ -0,0 +1,2 @@
1
+ import{useCallback as e,useEffect as r}from"react";import{debounce as n}from"es-toolkit";function o({ref:o,callback:i,debounceTime:t=200}){const c=e(n(i,t),[i,t]);r((()=>{if(!window.ResizeObserver)return;if(!(null==o?void 0:o.current))return;function e(e){const r=Array.isArray(e)?e[0]:e;return window.requestAnimationFrame((()=>{c({borderBoxSize:r})}))}let r=null;const n=new ResizeObserver((n=>{var o;const i=n[0];if(i&&i.borderBoxSize)if(Array.isArray(i.borderBoxSize)){r=e(i.borderBoxSize[0])}else r=e(i.borderBoxSize);else{if(!i.contentRect)return;{const n={blockSize:i.contentRect.height,inlineSize:(null===(o=null==i?void 0:i.contentRect)||void 0===o?void 0:o.width)||0};r=e(n)}}}));return n.observe(null==o?void 0:o.current),()=>{0!==t&&c.cancel(),r&&window.cancelAnimationFrame(r),n.disconnect()}}),[null==o?void 0:o.current,i,t,c])}export{o as default};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,GAE5C,MAJCK,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,EAC1C,CAEA,KAKH,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": "3.0.3-alpha-ea565.0",
3
+ "version": "3.0.4",
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": "3.0.9-alpha-ea565.0",
36
+ "@vibe/shared": "3.1.0",
37
37
  "classnames": "^2.5.1",
38
38
  "es-toolkit": "^1.39.10"
39
39
  },
@@ -63,5 +63,5 @@
63
63
  "../../node_modules/@vibe/config/.eslintrc.cjs"
64
64
  ]
65
65
  },
66
- "gitHead": "99516622bcc8efdccecfa882e2319a9e8b583f45"
66
+ "gitHead": "1e0ebec593676a7a3e8b4a965d688397a5f44c22"
67
67
  }