@contember/react-utils 1.2.0-rc.15 → 1.2.0-rc.17

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.
Files changed (54) hide show
  1. package/dist/development/hooks/useAutoHeightTextArea.js +41 -0
  2. package/dist/development/hooks/useAutoHeightTextArea.js.map +1 -0
  3. package/dist/development/hooks/useOnElementClickOutsideCallback.js +20 -0
  4. package/dist/development/hooks/useOnElementClickOutsideCallback.js.map +1 -0
  5. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
  6. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
  7. package/dist/development/hooks/useOnElementResize.js +28 -26
  8. package/dist/development/hooks/useOnElementResize.js.map +1 -1
  9. package/dist/development/hooks/useOnScrollWithin.js +33 -31
  10. package/dist/development/hooks/useOnScrollWithin.js.map +1 -1
  11. package/dist/development/index.js +6 -0
  12. package/dist/development/index.js.map +1 -1
  13. package/dist/development/theming/useClassNameFactory.js +4 -2
  14. package/dist/development/theming/useClassNameFactory.js.map +1 -1
  15. package/dist/development/theming/useThemedClassNameFactory.js +4 -2
  16. package/dist/development/theming/useThemedClassNameFactory.js.map +1 -1
  17. package/dist/production/hooks/useAutoHeightTextArea.js +41 -0
  18. package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -0
  19. package/dist/production/hooks/useOnElementClickOutsideCallback.js +20 -0
  20. package/dist/production/hooks/useOnElementClickOutsideCallback.js.map +1 -0
  21. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
  22. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
  23. package/dist/production/hooks/useOnElementResize.js +28 -26
  24. package/dist/production/hooks/useOnElementResize.js.map +1 -1
  25. package/dist/production/hooks/useOnScrollWithin.js +33 -31
  26. package/dist/production/hooks/useOnScrollWithin.js.map +1 -1
  27. package/dist/production/index.js +6 -0
  28. package/dist/production/index.js.map +1 -1
  29. package/dist/production/theming/useClassNameFactory.js +4 -2
  30. package/dist/production/theming/useClassNameFactory.js.map +1 -1
  31. package/dist/production/theming/useThemedClassNameFactory.js +4 -2
  32. package/dist/production/theming/useThemedClassNameFactory.js.map +1 -1
  33. package/dist/types/hooks/index.d.ts +3 -0
  34. package/dist/types/hooks/index.d.ts.map +1 -1
  35. package/dist/types/hooks/useAutoHeightTextArea.d.ts +3 -0
  36. package/dist/types/hooks/useAutoHeightTextArea.d.ts.map +1 -0
  37. package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts +3 -0
  38. package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts.map +1 -0
  39. package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts +14 -0
  40. package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts.map +1 -0
  41. package/dist/types/hooks/useOnElementResize.d.ts.map +1 -1
  42. package/dist/types/hooks/useOnScrollWithin.d.ts.map +1 -1
  43. package/dist/types/theming/useClassNameFactory.d.ts.map +1 -1
  44. package/dist/types/theming/useThemedClassNameFactory.d.ts.map +1 -1
  45. package/dist/types/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +2 -2
  47. package/src/hooks/index.ts +3 -0
  48. package/src/hooks/useAutoHeightTextArea.ts +51 -0
  49. package/src/hooks/useOnElementClickOutsideCallback.ts +23 -0
  50. package/src/hooks/useOnElementMouseEnterDelayedCallback.ts +54 -0
  51. package/src/hooks/useOnElementResize.ts +34 -31
  52. package/src/hooks/useOnScrollWithin.ts +32 -31
  53. package/src/theming/useClassNameFactory.ts +4 -1
  54. package/src/theming/useThemedClassNameFactory.ts +4 -1
@@ -0,0 +1,41 @@
1
+ import { px } from "@contember/utilities";
2
+ import { useCallback, useLayoutEffect } from "react";
3
+ import { unwrapRefValue } from "./unwrapRefValue.js";
4
+ import { useOnElementResize } from "./useOnElementResize.js";
5
+ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
6
+ const measure = useCallback((ref, minRows2, maxRows2, value2) => {
7
+ if (ref) {
8
+ const rowsAttribute = ref.rows;
9
+ ref.style.height = "";
10
+ ref.style.minHeight = "";
11
+ ref.style.maxHeight = "";
12
+ if (minRows2 !== maxRows2) {
13
+ const height = ref.scrollHeight;
14
+ let minHeight;
15
+ let maxHeight;
16
+ ref.rows = minRows2;
17
+ minHeight = ref.offsetHeight;
18
+ if (maxRows2 === Infinity) {
19
+ maxHeight = Infinity;
20
+ } else {
21
+ ref.rows = maxRows2;
22
+ maxHeight = ref.offsetHeight;
23
+ }
24
+ ref.style.height = px(height);
25
+ ref.style.minHeight = px(minHeight);
26
+ ref.style.maxHeight = px(maxHeight);
27
+ }
28
+ ref.rows = rowsAttribute;
29
+ }
30
+ }, []);
31
+ useOnElementResize(textAreaRef, () => {
32
+ measure(unwrapRefValue(textAreaRef), minRows, maxRows, value);
33
+ });
34
+ useLayoutEffect(() => {
35
+ measure(unwrapRefValue(textAreaRef), minRows, maxRows, value);
36
+ }, [maxRows, measure, minRows, textAreaRef, value]);
37
+ };
38
+ export {
39
+ useAutoHeightTextArea
40
+ };
41
+ //# sourceMappingURL=useAutoHeightTextArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback((ref: HTMLTextAreaElement | null, minRows: number, maxRows: number, value: string) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = ref.offsetHeight\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = ref.offsetHeight\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows, value)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows, value)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["minRows","maxRows","value"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,CAAC,KAAiCA,UAAiBC,UAAiBC,WAAkB;AACjH,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAIF,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACX,oBAAY,IAAI;AAEhB,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACX,sBAAY,IAAI;AAAA,QACjB;AAEI,YAAA,MAAM,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,SAAS,KAAK;AAAA,EAAA,CAC5D;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,SAAS,KAAK;AAAA,EAAA,GAC1D,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ function useOnElementClickOutsideCallback(refOrElement, callback) {
4
+ useEffect(() => {
5
+ const refValue = unwrapRefValue(refOrElement);
6
+ const handleClickOutside = (event) => {
7
+ if (refValue && !refValue.contains(event.target)) {
8
+ callback(event);
9
+ }
10
+ };
11
+ document.addEventListener("mousedown", handleClickOutside);
12
+ return () => {
13
+ document.removeEventListener("mousedown", handleClickOutside);
14
+ };
15
+ }, [callback, refOrElement]);
16
+ }
17
+ export {
18
+ useOnElementClickOutsideCallback
19
+ };
20
+ //# sourceMappingURL=useOnElementClickOutsideCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementClickOutsideCallback.js","sources":["../../../src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementClickOutsideCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (refValue && !refValue.contains(event.target as Node)) {\n\t\t\t\tcallback(event)\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('mousedown', handleClickOutside)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', handleClickOutside)\n\t\t}\n\t}, [callback, refOrElement])\n}\n"],"names":[],"mappings":";;AAGgB,SAAA,iCACf,cACA,UACO;AACP,YAAU,MAAM;AACT,UAAA,WAAW,eAAe,YAAY;AAEtC,UAAA,qBAAqB,CAAC,UAAsB;AACjD,UAAI,YAAY,CAAC,SAAS,SAAS,MAAM,MAAc,GAAG;AACzD,iBAAS,KAAK;AAAA,MACf;AAAA,IAAA;AAGQ,aAAA,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AACH,eAAA,oBAAoB,aAAa,kBAAkB;AAAA,IAAA;AAAA,EAC7D,GACE,CAAC,UAAU,YAAY,CAAC;AAC5B;"}
@@ -0,0 +1,33 @@
1
+ import { useEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ function useOnElementMouseEnterDelayedCallback(refOrElement, callback, timeoutMs = 300) {
4
+ useEffect(() => {
5
+ const refValue = unwrapRefValue(refOrElement);
6
+ if (refValue) {
7
+ let handleMouseEnter = function(event) {
8
+ clearTimeout(timeoutID);
9
+ timeoutID = setTimeout(() => {
10
+ callback(event);
11
+ }, timeoutMs);
12
+ }, handleMouseLeave = function() {
13
+ clearTimeout(timeoutID);
14
+ }, handleMouseDown = function(event) {
15
+ clearTimeout(timeoutID);
16
+ callback(event);
17
+ };
18
+ let timeoutID = void 0;
19
+ refValue.addEventListener("mouseenter", handleMouseEnter);
20
+ refValue.addEventListener("mouseleave", handleMouseLeave);
21
+ refValue.addEventListener("mousedown", handleMouseDown);
22
+ return () => {
23
+ refValue.removeEventListener("mouseover", handleMouseEnter);
24
+ refValue.removeEventListener("mouseleave", handleMouseLeave);
25
+ refValue.removeEventListener("mousedown", handleMouseDown);
26
+ };
27
+ }
28
+ }, [callback, refOrElement, timeoutMs]);
29
+ }
30
+ export {
31
+ useOnElementMouseEnterDelayedCallback
32
+ };
33
+ //# sourceMappingURL=useOnElementMouseEnterDelayedCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementMouseEnterDelayedCallback.js","sources":["../../../src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Calls the callback when the mouse enters the element, but only after a timeout, e.g. for tooltips or dropdown menus.\n *\n * Calls the callback immediately if the mouse is pressed down with `event.type` of `mousedown`. This is useful for\n * dropdown menus, where the user may click on the menu item before the callback is called resulting in the menu\n * opening and closing immediately.\n *\n * @param refOrElement - The element or ref to the element to attach the event listener to.\n * @param callback - The callback to call when the mouse enters the element.\n * @param timeoutMs - The timeout in milliseconds to wait before calling the callback.\n */\nexport function useOnElementMouseEnterDelayedCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n\ttimeoutMs: number = 300,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tif (refValue) {\n\t\t\tlet timeoutID: ReturnType<typeof setTimeout> | undefined = undefined\n\n\t\t\tfunction handleMouseEnter(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tcallback(event)\n\t\t\t\t}, timeoutMs)\n\t\t\t}\n\n\t\t\tfunction handleMouseLeave() {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t}\n\n\t\t\tfunction handleMouseDown(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tcallback(event)\n\t\t\t}\n\n\t\t\trefValue.addEventListener('mouseenter', handleMouseEnter)\n\t\t\trefValue.addEventListener('mouseleave', handleMouseLeave)\n\t\t\trefValue.addEventListener('mousedown', handleMouseDown)\n\n\t\t\treturn () => {\n\t\t\t\trefValue.removeEventListener('mouseover', handleMouseEnter)\n\t\t\t\trefValue.removeEventListener('mouseleave', handleMouseLeave)\n\t\t\t\trefValue.removeEventListener('mousedown', handleMouseDown)\n\t\t\t}\n\t\t}\n\t}, [callback, refOrElement, timeoutMs])\n}\n"],"names":[],"mappings":";;AAcO,SAAS,sCACf,cACA,UACA,YAAoB,KACb;AACP,YAAU,MAAM;AACT,UAAA,WAAW,eAAe,YAAY;AAE5C,QAAI,UAAU;AAGJ,UAAA,mBAAT,SAA0B,OAAmB;AAC5C,qBAAa,SAAS;AAEtB,oBAAY,WAAW,MAAM;AAC5B,mBAAS,KAAK;AAAA,WACZ,SAAS;AAAA,MACb,GAES,mBAAT,WAA4B;AAC3B,qBAAa,SAAS;AAAA,MAAA,GAGd,kBAAT,SAAyB,OAAmB;AAC3C,qBAAa,SAAS;AACtB,iBAAS,KAAK;AAAA,MAAA;AAhBf,UAAI,YAAuD;AAmBlD,eAAA,iBAAiB,cAAc,gBAAgB;AAC/C,eAAA,iBAAiB,cAAc,gBAAgB;AAC/C,eAAA,iBAAiB,aAAa,eAAe;AAEtD,aAAO,MAAM;AACH,iBAAA,oBAAoB,aAAa,gBAAgB;AACjD,iBAAA,oBAAoB,cAAc,gBAAgB;AAClD,iBAAA,oBAAoB,aAAa,eAAe;AAAA,MAAA;AAAA,IAE3D;AAAA,EACE,GAAA,CAAC,UAAU,cAAc,SAAS,CAAC;AACvC;"}
@@ -4,39 +4,41 @@ import { useScopedConsoleRef } from "../debug-context/Context.js";
4
4
  function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
5
5
  const scopedConsoleRef = useScopedConsoleRef("useOnElementResize");
6
6
  const { box = "border-box" } = options;
7
- const element = unwrapRefValue(refOrElement);
8
7
  const callbackRef = useRef(callback);
9
8
  callbackRef.current = callback;
10
9
  const lastTimeStamp = useRef(0);
11
10
  useLayoutEffect(() => {
12
- let timeoutID = void 0;
13
- function debouncedOnChange([entry]) {
14
- const timeStamp = Date.now();
15
- const delta = timeStamp - lastTimeStamp.current;
16
- if (delta > timeout) {
17
- scopedConsoleRef.current.warned("element.resize:immediate", null);
18
- callbackRef.current(entry);
19
- lastTimeStamp.current = timeStamp;
11
+ const element = unwrapRefValue(refOrElement);
12
+ if (element) {
13
+ if (element instanceof HTMLElement) {
14
+ let debouncedOnChange = function([entry]) {
15
+ const timeStamp = Date.now();
16
+ const delta = timeStamp - lastTimeStamp.current;
17
+ if (delta > timeout) {
18
+ scopedConsoleRef.current.warned("element.resize:immediate", null);
19
+ callbackRef.current(entry);
20
+ lastTimeStamp.current = timeStamp;
21
+ } else {
22
+ clearTimeout(timeoutID);
23
+ timeoutID = setTimeout(() => {
24
+ scopedConsoleRef.current.warned("element.resize:debounced", null);
25
+ callbackRef.current(entry);
26
+ lastTimeStamp.current = timeStamp;
27
+ }, timeout);
28
+ }
29
+ };
30
+ let timeoutID = void 0;
31
+ const resizeObserver = new ResizeObserver(debouncedOnChange);
32
+ resizeObserver.observe(element, { box });
33
+ return () => {
34
+ clearTimeout(timeoutID);
35
+ resizeObserver.unobserve(element);
36
+ };
20
37
  } else {
21
- clearTimeout(timeoutID);
22
- timeoutID = setTimeout(() => {
23
- scopedConsoleRef.current.warned("element.resize:debounced", null);
24
- callbackRef.current(entry);
25
- lastTimeStamp.current = timeStamp;
26
- }, timeout);
38
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
27
39
  }
28
40
  }
29
- if (element instanceof HTMLElement) {
30
- const resizeObserver = new ResizeObserver(debouncedOnChange);
31
- resizeObserver.observe(element, { box });
32
- return () => {
33
- clearTimeout(timeoutID);
34
- resizeObserver.unobserve(element);
35
- };
36
- } else if (element) {
37
- throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
38
- }
39
- }, [box, element, scopedConsoleRef, timeout]);
41
+ }, [box, refOrElement, scopedConsoleRef, timeout]);
40
42
  }
41
43
  export {
42
44
  useOnElementResize
@@ -1 +1 @@
1
- {"version":3,"file":"useOnElementResize.js","sources":["../../../src/hooks/useOnElementResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementResize(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (entries: ResizeObserverEntry) => void,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): void {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementResize')\n\n\tconst { box = 'border-box' } = options\n\tconst element = unwrapRefValue(refOrElement)\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: number | undefined = undefined\n\n\t\tfunction debouncedOnChange([entry]: ResizeObserverEntry[]) {\n\t\t\tconst timeStamp = Date.now()\n\t\t\tconst delta = timeStamp - lastTimeStamp.current\n\n\t\t\tif (delta > timeout) {\n\t\t\t\tscopedConsoleRef.current.warned('element.resize:immediate', null)\n\t\t\t\tcallbackRef.current(entry)\n\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t} else {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('element.resize:debounced', null)\n\t\t\t\t\tcallbackRef.current(entry)\n\t\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t\t}, timeout)\n\t\t\t}\n\t\t}\n\n\t\tif (element instanceof HTMLElement) {\n\t\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\t\tresizeObserver.observe(element, { box })\n\n\t\t\treturn () => {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tresizeObserver.unobserve(element)\n\t\t\t}\n\t\t} else if (element) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\t}, [box, element, scopedConsoleRef, timeout])\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAC,GAClC,UAAkB,KACX;AACD,QAAA,mBAAmB,oBAAoB,oBAAoB;AAE3D,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,UAAU,eAAe,YAAY;AACrC,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,MAAM;AACrB,QAAI,YAAgC;AAE3B,aAAA,kBAAkB,CAAC,KAAK,GAA0B;AACpD,YAAA,YAAY,KAAK;AACjB,YAAA,QAAQ,YAAY,cAAc;AAExC,UAAI,QAAQ,SAAS;AACH,yBAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU;AAAA,MAAA,OAClB;AACN,qBAAa,SAAS;AACtB,oBAAY,WAAW,MAAM;AACX,2BAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,sBAAY,QAAQ,KAAK;AACzB,wBAAc,UAAU;AAAA,WACtB,OAAO;AAAA,MACX;AAAA,IACD;AAEA,QAAI,mBAAmB,aAAa;AAC7B,YAAA,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,qBAAe,QAAQ,SAAS,EAAE,IAAK,CAAA;AAEvC,aAAO,MAAM;AACZ,qBAAa,SAAS;AACtB,uBAAe,UAAU,OAAO;AAAA,MAAA;AAAA,eAEvB,SAAS;AACb,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAAA,KACE,CAAC,KAAK,SAAS,kBAAkB,OAAO,CAAC;AAC7C;"}
1
+ {"version":3,"file":"useOnElementResize.js","sources":["../../../src/hooks/useOnElementResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementResize(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (entries: ResizeObserverEntry) => void,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): void {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementResize')\n\n\tconst { box = 'border-box' } = options\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\n\t\tif (element) {\n\t\t\tif (element instanceof HTMLElement) {\n\t\t\t\tlet timeoutID: number | undefined = undefined\n\n\t\t\t\tfunction debouncedOnChange([entry]: ResizeObserverEntry[]) {\n\t\t\t\t\tconst timeStamp = Date.now()\n\t\t\t\t\tconst delta = timeStamp - lastTimeStamp.current\n\n\t\t\t\t\tif (delta > timeout) {\n\t\t\t\t\t\tscopedConsoleRef.current.warned('element.resize:immediate', null)\n\t\t\t\t\t\tcallbackRef.current(entry)\n\t\t\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t\t\t} else {\n\t\t\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\t\t\tscopedConsoleRef.current.warned('element.resize:debounced', null)\n\t\t\t\t\t\t\tcallbackRef.current(entry)\n\t\t\t\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t\t\t\t}, timeout)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\t\t\tresizeObserver.observe(element, { box })\n\n\t\t\t\treturn () => {\n\t\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\t\tresizeObserver.unobserve(element)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t\t}\n\t\t}\n\t}, [box, refOrElement, scopedConsoleRef, timeout])\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAC,GAClC,UAAkB,KACX;AACD,QAAA,mBAAmB,oBAAoB,oBAAoB;AAE3D,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAE3C,QAAI,SAAS;AACZ,UAAI,mBAAmB,aAAa;AAGnC,YAAS,oBAAT,SAA2B,CAAC,KAAK,GAA0B;AACpD,gBAAA,YAAY,KAAK;AACjB,gBAAA,QAAQ,YAAY,cAAc;AAExC,cAAI,QAAQ,SAAS;AACH,6BAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,wBAAY,QAAQ,KAAK;AACzB,0BAAc,UAAU;AAAA,UAAA,OAClB;AACN,yBAAa,SAAS;AACtB,wBAAY,WAAW,MAAM;AACX,+BAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,0BAAY,QAAQ,KAAK;AACzB,4BAAc,UAAU;AAAA,eACtB,OAAO;AAAA,UACX;AAAA,QAAA;AAjBD,YAAI,YAAgC;AAoB9B,cAAA,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,uBAAe,QAAQ,SAAS,EAAE,IAAK,CAAA;AAEvC,eAAO,MAAM;AACZ,uBAAa,SAAS;AACtB,yBAAe,UAAU,OAAO;AAAA,QAAA;AAAA,MACjC,OACM;AACA,cAAA,IAAI,MAAM,mEAAmE;AAAA,MACpF;AAAA,IACD;AAAA,KACE,CAAC,KAAK,cAAc,kBAAkB,OAAO,CAAC;AAClD;"}
@@ -6,43 +6,45 @@ function useOnScrollWithin(refOrElement, callback, interval = 1e3 / 60) {
6
6
  const callbackRef = useRef(callback);
7
7
  callbackRef.current = callback;
8
8
  const lastTimeStamp = useRef(0);
9
- const element = unwrapRefValue(refOrElement);
10
9
  useLayoutEffect(() => {
10
+ const element = unwrapRefValue(refOrElement);
11
11
  let timeoutID = void 0;
12
- function debouncedHandler(event) {
13
- clearTimeout(timeoutID);
14
- const delta = event.timeStamp - lastTimeStamp.current;
15
- scopedConsoleRef.current.logged("event:element.scroll:delta", delta);
16
- if (delta > interval) {
17
- scopedConsoleRef.current.warned("event:element.scroll:immediately", event);
18
- callbackRef.current(event);
19
- lastTimeStamp.current = event.timeStamp;
20
- } else {
21
- timeoutID = setTimeout(() => {
22
- scopedConsoleRef.current.warned("event:element.scroll:debounced", event);
23
- lastTimeStamp.current = event.timeStamp;
12
+ if (element) {
13
+ let debouncedHandler = function(event) {
14
+ clearTimeout(timeoutID);
15
+ const delta = event.timeStamp - lastTimeStamp.current;
16
+ scopedConsoleRef.current.logged("event:element.scroll:delta", delta);
17
+ if (delta > interval) {
18
+ scopedConsoleRef.current.warned("event:element.scroll:immediately", event);
24
19
  callbackRef.current(event);
25
- }, interval);
26
- }
27
- }
28
- if (element && element instanceof HTMLElement) {
29
- if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
30
- window.addEventListener("scroll", debouncedHandler, { capture: true, passive: true });
31
- window.addEventListener("resize", debouncedHandler);
32
- return () => {
33
- window.removeEventListener("scroll", debouncedHandler);
34
- window.removeEventListener("resize", debouncedHandler);
35
- };
36
- } else {
37
- element.addEventListener("scroll", debouncedHandler, { passive: true, capture: true });
38
- return () => {
39
- element.removeEventListener("scroll", debouncedHandler);
40
- };
20
+ lastTimeStamp.current = event.timeStamp;
21
+ } else {
22
+ timeoutID = setTimeout(() => {
23
+ scopedConsoleRef.current.warned("event:element.scroll:debounced", event);
24
+ lastTimeStamp.current = event.timeStamp;
25
+ callbackRef.current(event);
26
+ }, interval);
27
+ }
28
+ };
29
+ if (element instanceof HTMLElement) {
30
+ if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
31
+ window.addEventListener("scroll", debouncedHandler, { capture: true, passive: true });
32
+ window.addEventListener("resize", debouncedHandler);
33
+ return () => {
34
+ window.removeEventListener("scroll", debouncedHandler);
35
+ window.removeEventListener("resize", debouncedHandler);
36
+ };
37
+ } else {
38
+ element.addEventListener("scroll", debouncedHandler, { passive: true, capture: true });
39
+ return () => {
40
+ element.removeEventListener("scroll", debouncedHandler);
41
+ };
42
+ }
41
43
  }
42
- } else if (element) {
44
+ } else {
43
45
  throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
44
46
  }
45
- }, [element, interval, scopedConsoleRef]);
47
+ }, [interval, refOrElement, scopedConsoleRef]);
46
48
  }
47
49
  export {
48
50
  useOnScrollWithin
@@ -1 +1 @@
1
- {"version":3,"file":"useOnScrollWithin.js","sources":["../../../src/hooks/useOnScrollWithin.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Invokes callback on scroll event within the scroll container\n *\n * @param refOrElement - Scroll container\n * @param callback - Callback that is invoked on scroll event\n * @param interval - Specifies how often should scroll event invoke callback\n */\nexport function useOnScrollWithin(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (event: Event) => void,\n\tinterval: number = 1000 / 60,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnScrollWithin')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tconst element = unwrapRefValue(refOrElement)\n\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: number | undefined = undefined\n\n\t\tfunction debouncedHandler(event: Event) {\n\t\t\tclearTimeout(timeoutID)\n\n\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\tscopedConsoleRef.current.logged('event:element.scroll:delta', delta)\n\n\t\t\tif (delta > interval) {\n\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:immediately', event)\n\t\t\t\tcallbackRef.current(event)\n\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t} else {\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:debounced', event)\n\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t}, interval)\n\t\t\t}\n\t\t}\n\n\t\tif (element && element instanceof HTMLElement) {\n\t\t\tif (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {\n\t\t\t\twindow.addEventListener('scroll', debouncedHandler, { capture: true, passive: true })\n\t\t\t\twindow.addEventListener('resize', debouncedHandler)\n\n\t\t\t\treturn () => {\n\t\t\t\t\twindow.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\telement.addEventListener('scroll', debouncedHandler, { passive: true, capture: true })\n\n\t\t\t\treturn () => {\n\t\t\t\t\telement.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (element) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\n\t}, [element, interval, scopedConsoleRef])\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,kBACf,cACA,UACA,WAAmB,MAAO,IACzB;AACK,QAAA,mBAAmB,oBAAoB,mBAAmB;AAE1D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEhC,QAAA,UAAU,eAAe,YAAY;AAE3C,kBAAgB,MAAM;AACrB,QAAI,YAAgC;AAEpC,aAAS,iBAAiB,OAAc;AACvC,mBAAa,SAAS;AAEhB,YAAA,QAAQ,MAAM,YAAY,cAAc;AAC7B,uBAAA,QAAQ,OAAO,8BAA8B,KAAK;AAEnE,UAAI,QAAQ,UAAU;AACJ,yBAAA,QAAQ,OAAO,oCAAoC,KAAK;AACzE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU,MAAM;AAAA,MAAA,OACxB;AACN,oBAAY,WAAW,MAAM;AACX,2BAAA,QAAQ,OAAO,kCAAkC,KAAK;AACvE,wBAAc,UAAU,MAAM;AAC9B,sBAAY,QAAQ,KAAK;AAAA,WACvB,QAAQ;AAAA,MACZ;AAAA,IACD;AAEI,QAAA,WAAW,mBAAmB,aAAa;AAC1C,UAAA,mBAAmB,mBAAmB,mBAAmB,iBAAiB;AACtE,eAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAC7E,eAAA,iBAAiB,UAAU,gBAAgB;AAElD,eAAO,MAAM;AACL,iBAAA,oBAAoB,UAAU,gBAAgB;AAC9C,iBAAA,oBAAoB,UAAU,gBAAgB;AAAA,QAAA;AAAA,MACtD,OACM;AACE,gBAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAErF,eAAO,MAAM;AACJ,kBAAA,oBAAoB,UAAU,gBAAgB;AAAA,QAAA;AAAA,MAExD;AAAA,eACU,SAAS;AACb,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAAA,EAEE,GAAA,CAAC,SAAS,UAAU,gBAAgB,CAAC;AACzC;"}
1
+ {"version":3,"file":"useOnScrollWithin.js","sources":["../../../src/hooks/useOnScrollWithin.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Invokes callback on scroll event within the scroll container\n *\n * @param refOrElement - Scroll container\n * @param callback - Callback that is invoked on scroll event\n * @param interval - Specifies how often should scroll event invoke callback\n */\nexport function useOnScrollWithin(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (event: Event) => void,\n\tinterval: number = 1000 / 60,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnScrollWithin')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\n\t\tlet timeoutID: number | undefined = undefined\n\n\t\tif (element) {\n\t\t\tfunction debouncedHandler(event: Event) {\n\t\t\t\tclearTimeout(timeoutID)\n\n\t\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\t\tscopedConsoleRef.current.logged('event:element.scroll:delta', delta)\n\n\t\t\t\tif (delta > interval) {\n\t\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:immediately', event)\n\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t} else {\n\t\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:debounced', event)\n\t\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t\t}, interval)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (element instanceof HTMLElement) {\n\t\t\t\tif (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {\n\t\t\t\t\twindow.addEventListener('scroll', debouncedHandler, { capture: true, passive: true })\n\t\t\t\t\twindow.addEventListener('resize', debouncedHandler)\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\twindow.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\telement.addEventListener('scroll', debouncedHandler, { passive: true, capture: true })\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\telement.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\t}, [interval, refOrElement, scopedConsoleRef])\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,kBACf,cACA,UACA,WAAmB,MAAO,IACzB;AACK,QAAA,mBAAmB,oBAAoB,mBAAmB;AAE1D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAE3C,QAAI,YAAgC;AAEpC,QAAI,SAAS;AACH,UAAA,mBAAT,SAA0B,OAAc;AACvC,qBAAa,SAAS;AAEhB,cAAA,QAAQ,MAAM,YAAY,cAAc;AAC7B,yBAAA,QAAQ,OAAO,8BAA8B,KAAK;AAEnE,YAAI,QAAQ,UAAU;AACJ,2BAAA,QAAQ,OAAO,oCAAoC,KAAK;AACzE,sBAAY,QAAQ,KAAK;AACzB,wBAAc,UAAU,MAAM;AAAA,QAAA,OACxB;AACN,sBAAY,WAAW,MAAM;AACX,6BAAA,QAAQ,OAAO,kCAAkC,KAAK;AACvE,0BAAc,UAAU,MAAM;AAC9B,wBAAY,QAAQ,KAAK;AAAA,aACvB,QAAQ;AAAA,QACZ;AAAA,MAAA;AAGD,UAAI,mBAAmB,aAAa;AAC/B,YAAA,mBAAmB,mBAAmB,mBAAmB,iBAAiB;AACtE,iBAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAC7E,iBAAA,iBAAiB,UAAU,gBAAgB;AAElD,iBAAO,MAAM;AACL,mBAAA,oBAAoB,UAAU,gBAAgB;AAC9C,mBAAA,oBAAoB,UAAU,gBAAgB;AAAA,UAAA;AAAA,QACtD,OACM;AACE,kBAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAErF,iBAAO,MAAM;AACJ,oBAAA,oBAAoB,UAAU,gBAAgB;AAAA,UAAA;AAAA,QAExD;AAAA,MACD;AAAA,IAAA,OACM;AACA,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAAA,EACE,GAAA,CAAC,UAAU,cAAc,gBAAgB,CAAC;AAC9C;"}
@@ -6,6 +6,7 @@ import { unwrapRefValue } from "./hooks/unwrapRefValue.js";
6
6
  import { useAbortController } from "./hooks/useAbortController.js";
7
7
  import { useAddClassNameDuringResize } from "./hooks/useAddClassNameDuringResize.js";
8
8
  import { useArrayMapMemo } from "./hooks/useArrayMapMemo.js";
9
+ import { useAutoHeightTextArea } from "./hooks/useAutoHeightTextArea.js";
9
10
  import { useComposeRef } from "./hooks/useComposeRef.js";
10
11
  import { useConstantLengthInvariant } from "./hooks/useConstantLengthInvariant.js";
11
12
  import { useConstantValueInvariant } from "./hooks/useConstantValueInvariant.js";
@@ -21,6 +22,8 @@ import { useForceRender } from "./hooks/useForceRender.js";
21
22
  import { useId } from "./hooks/useId.js";
22
23
  import { useIsMounted } from "./hooks/useIsMounted.js";
23
24
  import { useObjectMemo } from "./hooks/useObjectMemo.js";
25
+ import { useOnElementClickOutsideCallback } from "./hooks/useOnElementClickOutsideCallback.js";
26
+ import { useOnElementMouseEnterDelayedCallback } from "./hooks/useOnElementMouseEnterDelayedCallback.js";
24
27
  import { useOnElementMutation } from "./hooks/useOnElementMutation.js";
25
28
  import { useOnElementResize } from "./hooks/useOnElementResize.js";
26
29
  import { useOnWindowResize } from "./hooks/useOnWindowResize.js";
@@ -67,6 +70,7 @@ export {
67
70
  useAbortController,
68
71
  useAddClassNameDuringResize,
69
72
  useArrayMapMemo,
73
+ useAutoHeightTextArea,
70
74
  useClassName,
71
75
  useClassNameFactory,
72
76
  useColorScheme,
@@ -85,6 +89,8 @@ export {
85
89
  useId,
86
90
  useIsMounted,
87
91
  useObjectMemo,
92
+ useOnElementClickOutsideCallback,
93
+ useOnElementMouseEnterDelayedCallback,
88
94
  useOnElementMutation,
89
95
  useOnElementResize,
90
96
  useOnWindowResize,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,18 +1,20 @@
1
1
  import { flatClassNameList, deduplicateClassName } from "@contember/utilities";
2
2
  import { useContext } from "react";
3
3
  import { GlobalClassNamePrefixContext } from "./GlobalClassNamePrefixContext.js";
4
+ import { useReferentiallyStableCallback } from "../referentiallyStable/useReferentiallyStableCallback.js";
4
5
  function useClassNameFactory(componentClassName, glue = "-", prefixOverride) {
5
6
  const contextPrefix = useContext(GlobalClassNamePrefixContext);
6
7
  const classNamePrefix = prefixOverride === null || prefixOverride === "" ? "" : prefixOverride || contextPrefix;
7
8
  const componentClassNameList = flatClassNameList(componentClassName).map(
8
9
  (componentClassName2) => `${classNamePrefix}${componentClassName2}`
9
10
  );
10
- return function componentClassNameFor(suffix = null, additionalClassName = null) {
11
+ function componentClassNameFor(suffix = null, additionalClassName = null) {
11
12
  const classNameSuffix = suffix ?? "";
12
13
  return deduplicateClassName((classNameSuffix ? classNameSuffix.match(/^[a-zA-Z0-9]/) ? componentClassNameList.map((componentClassName2) => `${componentClassName2}${glue}${classNameSuffix}`) : componentClassNameList.map((componentClassName2) => `${componentClassName2}${classNameSuffix}`) : componentClassNameList).concat(
13
14
  flatClassNameList(additionalClassName)
14
15
  )).join(" ");
15
- };
16
+ }
17
+ return useReferentiallyStableCallback(componentClassNameFor);
16
18
  }
17
19
  export {
18
20
  useClassNameFactory
@@ -1 +1 @@
1
- {"version":3,"file":"useClassNameFactory.js","sources":["../../../src/theming/useClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, deduplicateClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\n\n/**\n * Hook for component class name accepting outer class name\n *\n * Returns a reusable function almost that is handy for components\n * with many sub-component parts that should inherit the root component\n * name.\n *\n * Also, product of the factory is a function that can be used outside of rules of hooks.\n *\n * @param componentClassName - Component class name\n * @param glue - String to use to glue component and sub-component suffix\n * @param prefixOverride - Context component prefix override\n * @returns\n */\nexport function useClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\treturn function componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(additionalClassName),\n\t\t)).join(' ')\n\t}\n}\n"],"names":["componentClassName"],"mappings":";;;AAkBO,SAAS,oBACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,kBAAkBA;AAAAA,EAAA;AAG5C,SAAO,SAAS,sBACf,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAEnC,WAAA,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,OAAO,iBAAiB,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,iBAAiB,IAE3F,wBACD;AAAA,MACD,kBAAkB,mBAAmB;AAAA,IAAA,CACrC,EAAE,KAAK,GAAG;AAAA,EAAA;AAEb;"}
1
+ {"version":3,"file":"useClassNameFactory.js","sources":["../../../src/theming/useClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, deduplicateClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\n\n/**\n * Hook for component class name accepting outer class name\n *\n * Returns a reusable function almost that is handy for components\n * with many sub-component parts that should inherit the root component\n * name.\n *\n * Also, product of the factory is a function that can be used outside of rules of hooks.\n *\n * @param componentClassName - Component class name\n * @param glue - String to use to glue component and sub-component suffix\n * @param prefixOverride - Context component prefix override\n * @returns\n */\nexport function useClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(additionalClassName),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;AAmBO,SAAS,oBACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,kBAAkBA;AAAAA,EAAA;AAG5C,WAAS,sBACR,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAEnC,WAAA,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,OAAO,iBAAiB,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,iBAAiB,IAE3F,wBACD;AAAA,MACD,kBAAkB,mBAAmB;AAAA,IAAA,CACrC,EAAE,KAAK,GAAG;AAAA,EACZ;AAEA,SAAO,+BAA+B,qBAAqB;AAC5D;"}
@@ -2,6 +2,7 @@ import { flatClassNameList, colorSchemeClassName, deduplicateClassName, filterTh
2
2
  import { useContext } from "react";
3
3
  import { GlobalClassNamePrefixContext } from "./GlobalClassNamePrefixContext.js";
4
4
  import { useColorScheme } from "./contexts.js";
5
+ import { useReferentiallyStableCallback } from "../referentiallyStable/useReferentiallyStableCallback.js";
5
6
  function useThemedClassNameFactory(componentClassName, glue = "-", prefixOverride) {
6
7
  const contextPrefix = useContext(GlobalClassNamePrefixContext);
7
8
  const classNamePrefix = prefixOverride === null || prefixOverride === "" ? "" : prefixOverride || contextPrefix;
@@ -9,7 +10,7 @@ function useThemedClassNameFactory(componentClassName, glue = "-", prefixOverrid
9
10
  (componentClassName2) => `${classNamePrefix}${componentClassName2}`
10
11
  );
11
12
  const colorScheme = colorSchemeClassName(useColorScheme());
12
- return function componentClassNameFor(suffix = null, additionalClassName = null) {
13
+ function componentClassNameFor(suffix = null, additionalClassName = null) {
13
14
  const classNameSuffix = suffix ?? "";
14
15
  return deduplicateClassName((classNameSuffix ? classNameSuffix.match(/^[a-zA-Z0-9]/) ? componentClassNameList.map((componentClassName2) => `${componentClassName2}${glue}${classNameSuffix}`) : componentClassNameList.map((componentClassName2) => `${componentClassName2}${classNameSuffix}`) : componentClassNameList).concat(
15
16
  flatClassNameList(
@@ -19,7 +20,8 @@ function useThemedClassNameFactory(componentClassName, glue = "-", prefixOverrid
19
20
  )
20
21
  )
21
22
  )).join(" ");
22
- };
23
+ }
24
+ return useReferentiallyStableCallback(componentClassNameFor);
23
25
  }
24
26
  export {
25
27
  useThemedClassNameFactory
@@ -1 +1 @@
1
- {"version":3,"file":"useThemedClassNameFactory.js","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, deduplicateClassName, filterThemedClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\nimport { useColorScheme } from './contexts'\n\nexport function useThemedClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tconst colorScheme = colorSchemeClassName(useColorScheme())\n\n\treturn function componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(\n\t\t\t\tfilterThemedClassName(\n\t\t\t\t\tadditionalClassName,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t),\n\t\t\t),\n\t\t)).join(' ')\n\t}\n}\n"],"names":["componentClassName"],"mappings":";;;;AAKO,SAAS,0BACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,kBAAkBA;AAAAA,EAAA;AAGtC,QAAA,cAAc,qBAAqB,eAAA,CAAgB;AAEzD,SAAO,SAAS,sBACf,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAEnC,WAAA,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,OAAO,iBAAiB,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,iBAAiB,IAE3F,wBACD;AAAA,MACD;AAAA,QACC;AAAA,UACC;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA,EAAE,KAAK,GAAG;AAAA,EAAA;AAEb;"}
1
+ {"version":3,"file":"useThemedClassNameFactory.js","sources":["../../../src/theming/useThemedClassNameFactory.ts"],"sourcesContent":["import { NestedClassName, colorSchemeClassName, deduplicateClassName, filterThemedClassName, flatClassNameList } from '@contember/utilities'\nimport { useContext } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { GlobalClassNamePrefixContext } from './GlobalClassNamePrefixContext'\nimport { useColorScheme } from './contexts'\n\nexport function useThemedClassNameFactory(\n\tcomponentClassName: NestedClassName,\n\tglue: string | null = '-',\n\tprefixOverride?: string | null | undefined,\n) {\n\tconst contextPrefix = useContext(GlobalClassNamePrefixContext)\n\tconst classNamePrefix: string = prefixOverride === null || prefixOverride === '' ? '' : prefixOverride || contextPrefix\n\n\tconst componentClassNameList: string[] = flatClassNameList(componentClassName).map(\n\t\tcomponentClassName => `${classNamePrefix}${componentClassName}`,\n\t)\n\n\tconst colorScheme = colorSchemeClassName(useColorScheme())\n\n\tfunction componentClassNameFor(\n\t\tsuffix: string | null | undefined = null,\n\t\tadditionalClassName: NestedClassName = null,\n\t): string {\n\t\tconst classNameSuffix: string = suffix ?? ''\n\n\t\treturn deduplicateClassName((classNameSuffix\n\t\t\t? (classNameSuffix.match(/^[a-zA-Z0-9]/)\n\t\t\t\t? componentClassNameList.map(componentClassName => `${componentClassName}${glue}${classNameSuffix}`)\n\t\t\t\t: componentClassNameList.map(componentClassName => `${componentClassName}${classNameSuffix}`)\n\t\t\t)\n\t\t\t: componentClassNameList\n\t\t).concat(\n\t\t\tflatClassNameList(\n\t\t\t\tfilterThemedClassName(\n\t\t\t\t\tadditionalClassName,\n\t\t\t\t\tcolorScheme,\n\t\t\t\t),\n\t\t\t),\n\t\t)).join(' ')\n\t}\n\n\treturn useReferentiallyStableCallback(componentClassNameFor)\n}\n"],"names":["componentClassName"],"mappings":";;;;;AAMO,SAAS,0BACf,oBACA,OAAsB,KACtB,gBACC;AACK,QAAA,gBAAgB,WAAW,4BAA4B;AAC7D,QAAM,kBAA0B,mBAAmB,QAAQ,mBAAmB,KAAK,KAAK,kBAAkB;AAEpG,QAAA,yBAAmC,kBAAkB,kBAAkB,EAAE;AAAA,IAC9E,CAAAA,wBAAsB,GAAG,kBAAkBA;AAAAA,EAAA;AAGtC,QAAA,cAAc,qBAAqB,eAAA,CAAgB;AAEzD,WAAS,sBACR,SAAoC,MACpC,sBAAuC,MAC9B;AACT,UAAM,kBAA0B,UAAU;AAEnC,WAAA,sBAAsB,kBACzB,gBAAgB,MAAM,cAAc,IACpC,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,OAAO,iBAAiB,IACjG,uBAAuB,IAAI,CAAAA,wBAAsB,GAAGA,sBAAqB,iBAAiB,IAE3F,wBACD;AAAA,MACD;AAAA,QACC;AAAA,UACC;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA,EAAE,KAAK,GAAG;AAAA,EACZ;AAEA,SAAO,+BAA+B,qBAAqB;AAC5D;"}
@@ -0,0 +1,41 @@
1
+ import { px } from "@contember/utilities";
2
+ import { useCallback, useLayoutEffect } from "react";
3
+ import { unwrapRefValue } from "./unwrapRefValue.js";
4
+ import { useOnElementResize } from "./useOnElementResize.js";
5
+ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
6
+ const measure = useCallback((ref, minRows2, maxRows2, value2) => {
7
+ if (ref) {
8
+ const rowsAttribute = ref.rows;
9
+ ref.style.height = "";
10
+ ref.style.minHeight = "";
11
+ ref.style.maxHeight = "";
12
+ if (minRows2 !== maxRows2) {
13
+ const height = ref.scrollHeight;
14
+ let minHeight;
15
+ let maxHeight;
16
+ ref.rows = minRows2;
17
+ minHeight = ref.offsetHeight;
18
+ if (maxRows2 === Infinity) {
19
+ maxHeight = Infinity;
20
+ } else {
21
+ ref.rows = maxRows2;
22
+ maxHeight = ref.offsetHeight;
23
+ }
24
+ ref.style.height = px(height);
25
+ ref.style.minHeight = px(minHeight);
26
+ ref.style.maxHeight = px(maxHeight);
27
+ }
28
+ ref.rows = rowsAttribute;
29
+ }
30
+ }, []);
31
+ useOnElementResize(textAreaRef, () => {
32
+ measure(unwrapRefValue(textAreaRef), minRows, maxRows, value);
33
+ });
34
+ useLayoutEffect(() => {
35
+ measure(unwrapRefValue(textAreaRef), minRows, maxRows, value);
36
+ }, [maxRows, measure, minRows, textAreaRef, value]);
37
+ };
38
+ export {
39
+ useAutoHeightTextArea
40
+ };
41
+ //# sourceMappingURL=useAutoHeightTextArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback((ref: HTMLTextAreaElement | null, minRows: number, maxRows: number, value: string) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = ref.offsetHeight\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = ref.offsetHeight\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows, value)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows, value)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["minRows","maxRows","value"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,CAAC,KAAiCA,UAAiBC,UAAiBC,WAAkB;AACjH,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAIF,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACX,oBAAY,IAAI;AAEhB,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACX,sBAAY,IAAI;AAAA,QACjB;AAEI,YAAA,MAAM,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,SAAS,KAAK;AAAA,EAAA,CAC5D;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,SAAS,KAAK;AAAA,EAAA,GAC1D,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ function useOnElementClickOutsideCallback(refOrElement, callback) {
4
+ useEffect(() => {
5
+ const refValue = unwrapRefValue(refOrElement);
6
+ const handleClickOutside = (event) => {
7
+ if (refValue && !refValue.contains(event.target)) {
8
+ callback(event);
9
+ }
10
+ };
11
+ document.addEventListener("mousedown", handleClickOutside);
12
+ return () => {
13
+ document.removeEventListener("mousedown", handleClickOutside);
14
+ };
15
+ }, [callback, refOrElement]);
16
+ }
17
+ export {
18
+ useOnElementClickOutsideCallback
19
+ };
20
+ //# sourceMappingURL=useOnElementClickOutsideCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementClickOutsideCallback.js","sources":["../../../src/hooks/useOnElementClickOutsideCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementClickOutsideCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (refValue && !refValue.contains(event.target as Node)) {\n\t\t\t\tcallback(event)\n\t\t\t}\n\t\t}\n\n\t\tdocument.addEventListener('mousedown', handleClickOutside)\n\n\t\treturn () => {\n\t\t\tdocument.removeEventListener('mousedown', handleClickOutside)\n\t\t}\n\t}, [callback, refOrElement])\n}\n"],"names":[],"mappings":";;AAGgB,SAAA,iCACf,cACA,UACO;AACP,YAAU,MAAM;AACT,UAAA,WAAW,eAAe,YAAY;AAEtC,UAAA,qBAAqB,CAAC,UAAsB;AACjD,UAAI,YAAY,CAAC,SAAS,SAAS,MAAM,MAAc,GAAG;AACzD,iBAAS,KAAK;AAAA,MACf;AAAA,IAAA;AAGQ,aAAA,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AACH,eAAA,oBAAoB,aAAa,kBAAkB;AAAA,IAAA;AAAA,EAC7D,GACE,CAAC,UAAU,YAAY,CAAC;AAC5B;"}
@@ -0,0 +1,33 @@
1
+ import { useEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ function useOnElementMouseEnterDelayedCallback(refOrElement, callback, timeoutMs = 300) {
4
+ useEffect(() => {
5
+ const refValue = unwrapRefValue(refOrElement);
6
+ if (refValue) {
7
+ let handleMouseEnter = function(event) {
8
+ clearTimeout(timeoutID);
9
+ timeoutID = setTimeout(() => {
10
+ callback(event);
11
+ }, timeoutMs);
12
+ }, handleMouseLeave = function() {
13
+ clearTimeout(timeoutID);
14
+ }, handleMouseDown = function(event) {
15
+ clearTimeout(timeoutID);
16
+ callback(event);
17
+ };
18
+ let timeoutID = void 0;
19
+ refValue.addEventListener("mouseenter", handleMouseEnter);
20
+ refValue.addEventListener("mouseleave", handleMouseLeave);
21
+ refValue.addEventListener("mousedown", handleMouseDown);
22
+ return () => {
23
+ refValue.removeEventListener("mouseover", handleMouseEnter);
24
+ refValue.removeEventListener("mouseleave", handleMouseLeave);
25
+ refValue.removeEventListener("mousedown", handleMouseDown);
26
+ };
27
+ }
28
+ }, [callback, refOrElement, timeoutMs]);
29
+ }
30
+ export {
31
+ useOnElementMouseEnterDelayedCallback
32
+ };
33
+ //# sourceMappingURL=useOnElementMouseEnterDelayedCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementMouseEnterDelayedCallback.js","sources":["../../../src/hooks/useOnElementMouseEnterDelayedCallback.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Calls the callback when the mouse enters the element, but only after a timeout, e.g. for tooltips or dropdown menus.\n *\n * Calls the callback immediately if the mouse is pressed down with `event.type` of `mousedown`. This is useful for\n * dropdown menus, where the user may click on the menu item before the callback is called resulting in the menu\n * opening and closing immediately.\n *\n * @param refOrElement - The element or ref to the element to attach the event listener to.\n * @param callback - The callback to call when the mouse enters the element.\n * @param timeoutMs - The timeout in milliseconds to wait before calling the callback.\n */\nexport function useOnElementMouseEnterDelayedCallback(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\tcallback: (event: MouseEvent) => void,\n\ttimeoutMs: number = 300,\n): void {\n\tuseEffect(() => {\n\t\tconst refValue = unwrapRefValue(refOrElement)\n\n\t\tif (refValue) {\n\t\t\tlet timeoutID: ReturnType<typeof setTimeout> | undefined = undefined\n\n\t\t\tfunction handleMouseEnter(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tcallback(event)\n\t\t\t\t}, timeoutMs)\n\t\t\t}\n\n\t\t\tfunction handleMouseLeave() {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t}\n\n\t\t\tfunction handleMouseDown(event: MouseEvent) {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tcallback(event)\n\t\t\t}\n\n\t\t\trefValue.addEventListener('mouseenter', handleMouseEnter)\n\t\t\trefValue.addEventListener('mouseleave', handleMouseLeave)\n\t\t\trefValue.addEventListener('mousedown', handleMouseDown)\n\n\t\t\treturn () => {\n\t\t\t\trefValue.removeEventListener('mouseover', handleMouseEnter)\n\t\t\t\trefValue.removeEventListener('mouseleave', handleMouseLeave)\n\t\t\t\trefValue.removeEventListener('mousedown', handleMouseDown)\n\t\t\t}\n\t\t}\n\t}, [callback, refOrElement, timeoutMs])\n}\n"],"names":[],"mappings":";;AAcO,SAAS,sCACf,cACA,UACA,YAAoB,KACb;AACP,YAAU,MAAM;AACT,UAAA,WAAW,eAAe,YAAY;AAE5C,QAAI,UAAU;AAGJ,UAAA,mBAAT,SAA0B,OAAmB;AAC5C,qBAAa,SAAS;AAEtB,oBAAY,WAAW,MAAM;AAC5B,mBAAS,KAAK;AAAA,WACZ,SAAS;AAAA,MACb,GAES,mBAAT,WAA4B;AAC3B,qBAAa,SAAS;AAAA,MAAA,GAGd,kBAAT,SAAyB,OAAmB;AAC3C,qBAAa,SAAS;AACtB,iBAAS,KAAK;AAAA,MAAA;AAhBf,UAAI,YAAuD;AAmBlD,eAAA,iBAAiB,cAAc,gBAAgB;AAC/C,eAAA,iBAAiB,cAAc,gBAAgB;AAC/C,eAAA,iBAAiB,aAAa,eAAe;AAEtD,aAAO,MAAM;AACH,iBAAA,oBAAoB,aAAa,gBAAgB;AACjD,iBAAA,oBAAoB,cAAc,gBAAgB;AAClD,iBAAA,oBAAoB,aAAa,eAAe;AAAA,MAAA;AAAA,IAE3D;AAAA,EACE,GAAA,CAAC,UAAU,cAAc,SAAS,CAAC;AACvC;"}
@@ -4,39 +4,41 @@ import { useScopedConsoleRef } from "../debug-context/Context.js";
4
4
  function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
5
5
  const scopedConsoleRef = useScopedConsoleRef("useOnElementResize");
6
6
  const { box = "border-box" } = options;
7
- const element = unwrapRefValue(refOrElement);
8
7
  const callbackRef = useRef(callback);
9
8
  callbackRef.current = callback;
10
9
  const lastTimeStamp = useRef(0);
11
10
  useLayoutEffect(() => {
12
- let timeoutID = void 0;
13
- function debouncedOnChange([entry]) {
14
- const timeStamp = Date.now();
15
- const delta = timeStamp - lastTimeStamp.current;
16
- if (delta > timeout) {
17
- scopedConsoleRef.current.warned("element.resize:immediate", null);
18
- callbackRef.current(entry);
19
- lastTimeStamp.current = timeStamp;
11
+ const element = unwrapRefValue(refOrElement);
12
+ if (element) {
13
+ if (element instanceof HTMLElement) {
14
+ let debouncedOnChange = function([entry]) {
15
+ const timeStamp = Date.now();
16
+ const delta = timeStamp - lastTimeStamp.current;
17
+ if (delta > timeout) {
18
+ scopedConsoleRef.current.warned("element.resize:immediate", null);
19
+ callbackRef.current(entry);
20
+ lastTimeStamp.current = timeStamp;
21
+ } else {
22
+ clearTimeout(timeoutID);
23
+ timeoutID = setTimeout(() => {
24
+ scopedConsoleRef.current.warned("element.resize:debounced", null);
25
+ callbackRef.current(entry);
26
+ lastTimeStamp.current = timeStamp;
27
+ }, timeout);
28
+ }
29
+ };
30
+ let timeoutID = void 0;
31
+ const resizeObserver = new ResizeObserver(debouncedOnChange);
32
+ resizeObserver.observe(element, { box });
33
+ return () => {
34
+ clearTimeout(timeoutID);
35
+ resizeObserver.unobserve(element);
36
+ };
20
37
  } else {
21
- clearTimeout(timeoutID);
22
- timeoutID = setTimeout(() => {
23
- scopedConsoleRef.current.warned("element.resize:debounced", null);
24
- callbackRef.current(entry);
25
- lastTimeStamp.current = timeStamp;
26
- }, timeout);
38
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
27
39
  }
28
40
  }
29
- if (element instanceof HTMLElement) {
30
- const resizeObserver = new ResizeObserver(debouncedOnChange);
31
- resizeObserver.observe(element, { box });
32
- return () => {
33
- clearTimeout(timeoutID);
34
- resizeObserver.unobserve(element);
35
- };
36
- } else if (element) {
37
- throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
38
- }
39
- }, [box, element, scopedConsoleRef, timeout]);
41
+ }, [box, refOrElement, scopedConsoleRef, timeout]);
40
42
  }
41
43
  export {
42
44
  useOnElementResize