@contember/react-utils 1.2.0-rc.9 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) 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/useChildrenAsLabel.js +53 -0
  4. package/dist/development/hooks/useChildrenAsLabel.js.map +1 -0
  5. package/dist/development/hooks/useContainerWidth.js +1 -1
  6. package/dist/development/hooks/useContainerWidth.js.map +1 -1
  7. package/dist/development/hooks/useElementTopOffset.js +29 -0
  8. package/dist/development/hooks/useElementTopOffset.js.map +1 -0
  9. package/dist/development/hooks/useExpectSameValueReference.js +1 -1
  10. package/dist/development/hooks/useExpectSameValueReference.js.map +1 -1
  11. package/dist/development/hooks/useId.js +2 -2
  12. package/dist/development/hooks/useId.js.map +1 -1
  13. package/dist/development/hooks/useOnElementClickOutsideCallback.js +20 -0
  14. package/dist/development/hooks/useOnElementClickOutsideCallback.js.map +1 -0
  15. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
  16. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
  17. package/dist/development/hooks/useOnElementMutation.js +1 -1
  18. package/dist/development/hooks/useOnElementMutation.js.map +1 -1
  19. package/dist/development/hooks/useOnElementResize.js +28 -26
  20. package/dist/development/hooks/useOnElementResize.js.map +1 -1
  21. package/dist/development/hooks/useOnScrollWithin.js +33 -31
  22. package/dist/development/hooks/useOnScrollWithin.js.map +1 -1
  23. package/dist/development/index.js +13 -0
  24. package/dist/development/index.js.map +1 -1
  25. package/dist/development/theming/useClassNameFactory.js +4 -2
  26. package/dist/development/theming/useClassNameFactory.js.map +1 -1
  27. package/dist/development/theming/useThemedClassNameFactory.js +4 -2
  28. package/dist/development/theming/useThemedClassNameFactory.js.map +1 -1
  29. package/dist/production/hooks/useAutoHeightTextArea.js +41 -0
  30. package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -0
  31. package/dist/production/hooks/useChildrenAsLabel.js +52 -0
  32. package/dist/production/hooks/useChildrenAsLabel.js.map +1 -0
  33. package/dist/production/hooks/useContainerWidth.js +1 -1
  34. package/dist/production/hooks/useContainerWidth.js.map +1 -1
  35. package/dist/production/hooks/useElementTopOffset.js +29 -0
  36. package/dist/production/hooks/useElementTopOffset.js.map +1 -0
  37. package/dist/production/hooks/useExpectSameValueReference.js +1 -1
  38. package/dist/production/hooks/useExpectSameValueReference.js.map +1 -1
  39. package/dist/production/hooks/useId.js +2 -2
  40. package/dist/production/hooks/useId.js.map +1 -1
  41. package/dist/production/hooks/useOnElementClickOutsideCallback.js +20 -0
  42. package/dist/production/hooks/useOnElementClickOutsideCallback.js.map +1 -0
  43. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.js +33 -0
  44. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.js.map +1 -0
  45. package/dist/production/hooks/useOnElementMutation.js +1 -1
  46. package/dist/production/hooks/useOnElementMutation.js.map +1 -1
  47. package/dist/production/hooks/useOnElementResize.js +28 -26
  48. package/dist/production/hooks/useOnElementResize.js.map +1 -1
  49. package/dist/production/hooks/useOnScrollWithin.js +33 -31
  50. package/dist/production/hooks/useOnScrollWithin.js.map +1 -1
  51. package/dist/production/index.js +13 -0
  52. package/dist/production/index.js.map +1 -1
  53. package/dist/production/theming/useClassNameFactory.js +4 -2
  54. package/dist/production/theming/useClassNameFactory.js.map +1 -1
  55. package/dist/production/theming/useThemedClassNameFactory.js +4 -2
  56. package/dist/production/theming/useThemedClassNameFactory.js.map +1 -1
  57. package/dist/types/hooks/index.d.ts +6 -0
  58. package/dist/types/hooks/index.d.ts.map +1 -1
  59. package/dist/types/hooks/useAutoHeightTextArea.d.ts +3 -0
  60. package/dist/types/hooks/useAutoHeightTextArea.d.ts.map +1 -0
  61. package/dist/types/hooks/useChildrenAsLabel.d.ts +18 -0
  62. package/dist/types/hooks/useChildrenAsLabel.d.ts.map +1 -0
  63. package/dist/types/hooks/useContainerWidth.d.ts +1 -1
  64. package/dist/types/hooks/useContainerWidth.d.ts.map +1 -1
  65. package/dist/types/hooks/useElementTopOffset.d.ts +3 -0
  66. package/dist/types/hooks/useElementTopOffset.d.ts.map +1 -0
  67. package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts +3 -0
  68. package/dist/types/hooks/useOnElementClickOutsideCallback.d.ts.map +1 -0
  69. package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts +14 -0
  70. package/dist/types/hooks/useOnElementMouseEnterDelayedCallback.d.ts.map +1 -0
  71. package/dist/types/hooks/useOnElementResize.d.ts.map +1 -1
  72. package/dist/types/hooks/useOnScrollWithin.d.ts.map +1 -1
  73. package/dist/types/theming/useClassNameFactory.d.ts.map +1 -1
  74. package/dist/types/theming/useThemedClassNameFactory.d.ts.map +1 -1
  75. package/dist/types/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +7 -6
  77. package/src/hooks/index.ts +6 -0
  78. package/src/hooks/useAutoHeightTextArea.ts +51 -0
  79. package/src/hooks/useChildrenAsLabel.ts +72 -0
  80. package/src/hooks/useContainerWidth.ts +1 -1
  81. package/src/hooks/useElementTopOffset.ts +35 -0
  82. package/src/hooks/useExpectSameValueReference.ts +1 -1
  83. package/src/hooks/useId.ts +2 -2
  84. package/src/hooks/useOnElementClickOutsideCallback.ts +23 -0
  85. package/src/hooks/useOnElementMouseEnterDelayedCallback.ts +54 -0
  86. package/src/hooks/useOnElementMutation.ts +1 -1
  87. package/src/hooks/useOnElementResize.ts +34 -31
  88. package/src/hooks/useOnScrollWithin.ts +33 -32
  89. package/src/theming/useClassNameFactory.ts +4 -1
  90. package/src/theming/useThemedClassNameFactory.ts +4 -1
@@ -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,52 @@
1
+ import { Children, useMemo } from "react";
2
+ const MULTIPLE_SPACES_REG_EXP = / +/g;
3
+ function normalize(text) {
4
+ return text.replace(MULTIPLE_SPACES_REG_EXP, " ").trim();
5
+ }
6
+ function getChildrenAsLabel(node) {
7
+ if (typeof node === "string" || typeof node === "number") {
8
+ return String(node);
9
+ } else if (node === null || node === void 0 || typeof node === "boolean") {
10
+ return void 0;
11
+ } else if (Array.isArray(node)) {
12
+ return normalize(node.map(getChildrenAsLabel).join(""));
13
+ } else {
14
+ let label = [];
15
+ Children.map(node, (child) => {
16
+ if (child === null || child === void 0 || typeof child === "boolean")
17
+ ;
18
+ else if (typeof child === "string") {
19
+ label.push(child);
20
+ } else if (typeof child === "number") {
21
+ label.push(child);
22
+ } else if (Array.isArray(child)) {
23
+ const childLabel = getChildrenAsLabel(child);
24
+ if (childLabel) {
25
+ label.push(childLabel);
26
+ }
27
+ } else {
28
+ if ("props" in child && "children" in child.props) {
29
+ const childLabel = getChildrenAsLabel(child.props.children);
30
+ if (childLabel) {
31
+ label.push(childLabel);
32
+ }
33
+ } else if ("children" in child) {
34
+ const childLabel = getChildrenAsLabel(child.children);
35
+ if (childLabel) {
36
+ label.push(childLabel);
37
+ }
38
+ } else
39
+ ;
40
+ }
41
+ });
42
+ return label.length > 0 ? label.join("") : void 0;
43
+ }
44
+ }
45
+ function useChildrenAsLabel(node) {
46
+ return useMemo(() => getChildrenAsLabel(node), [node]);
47
+ }
48
+ export {
49
+ getChildrenAsLabel,
50
+ useChildrenAsLabel
51
+ };
52
+ //# sourceMappingURL=useChildrenAsLabel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChildrenAsLabel.js","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":[],"mappings":";AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExB,aAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA;AACD;AAAA,MAGD;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAO,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;"}
@@ -1,6 +1,6 @@
1
1
  import { createContext, useContext } from "react";
2
2
  import { useWindowSize } from "./useWindowSize.js";
3
- const ContainerWidthContext = createContext(null);
3
+ const ContainerWidthContext = createContext(void 0);
4
4
  ContainerWidthContext.displayName = "ContainerWidthContext";
5
5
  function useContainerWidth() {
6
6
  const maybeContainerWidth = useContext(ContainerWidthContext);
@@ -1 +1 @@
1
- {"version":3,"file":"useContainerWidth.js","sources":["../../../src/hooks/useContainerWidth.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport { useWindowSize } from './useWindowSize'\n\nexport type ContainerWidthContextType = number\nexport const ContainerWidthContext = createContext<ContainerWidthContextType | null>(null)\nContainerWidthContext.displayName = 'ContainerWidthContext'\n\nexport function useContainerWidth(): number {\n\tconst maybeContainerWidth = useContext(ContainerWidthContext)\n\tconst { width: windowWidth } = useWindowSize()\n\n\treturn maybeContainerWidth ?? windowWidth\n}\n"],"names":[],"mappings":";;AAIa,MAAA,wBAAwB,cAAgD,IAAI;AACzF,sBAAsB,cAAc;AAE7B,SAAS,oBAA4B;AACrC,QAAA,sBAAsB,WAAW,qBAAqB;AAC5D,QAAM,EAAE,OAAO,YAAY,IAAI,cAAc;AAE7C,SAAO,uBAAuB;AAC/B;"}
1
+ {"version":3,"file":"useContainerWidth.js","sources":["../../../src/hooks/useContainerWidth.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport { useWindowSize } from './useWindowSize'\n\nexport type ContainerWidthContextType = number\nexport const ContainerWidthContext = createContext<ContainerWidthContextType | null | undefined>(undefined)\nContainerWidthContext.displayName = 'ContainerWidthContext'\n\nexport function useContainerWidth(): number {\n\tconst maybeContainerWidth = useContext(ContainerWidthContext)\n\tconst { width: windowWidth } = useWindowSize()\n\n\treturn maybeContainerWidth ?? windowWidth\n}\n"],"names":[],"mappings":";;AAIa,MAAA,wBAAwB,cAA4D,MAAS;AAC1G,sBAAsB,cAAc;AAE7B,SAAS,oBAA4B;AACrC,QAAA,sBAAsB,WAAW,qBAAqB;AAC5D,QAAM,EAAE,OAAO,YAAY,IAAI,cAAc;AAE7C,SAAO,uBAAuB;AAC/B;"}
@@ -0,0 +1,29 @@
1
+ import { useState, useLayoutEffect } from "react";
2
+ function useElementTopOffset(ref) {
3
+ const [offsetTop, setOffsetTop] = useState(void 0);
4
+ useLayoutEffect(() => {
5
+ if (!ref?.current) {
6
+ return;
7
+ }
8
+ const element = ref.current;
9
+ function updateTopOffsetCallback() {
10
+ setOffsetTop(element.offsetTop);
11
+ }
12
+ function updateTopOffsetHandler() {
13
+ requestAnimationFrame(updateTopOffsetCallback);
14
+ }
15
+ updateTopOffsetHandler();
16
+ const observer = new ResizeObserver(() => {
17
+ requestAnimationFrame(updateTopOffsetCallback);
18
+ });
19
+ observer.observe(element);
20
+ return () => {
21
+ observer.unobserve(element);
22
+ };
23
+ }, [ref]);
24
+ return offsetTop;
25
+ }
26
+ export {
27
+ useElementTopOffset
28
+ };
29
+ //# sourceMappingURL=useElementTopOffset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementTopOffset.js","sources":["../../../src/hooks/useElementTopOffset.ts"],"sourcesContent":["import { RefObject, useLayoutEffect, useState } from 'react'\n\nexport function useElementTopOffset(ref?: RefObject<HTMLElement>): number | undefined {\n\tconst [offsetTop, setOffsetTop] = useState<number | undefined>(undefined)\n\n\tuseLayoutEffect(() => {\n\t\tif (!ref?.current) {\n\t\t\treturn\n\t\t}\n\n\t\tconst element = ref.current\n\n\t\tfunction updateTopOffsetCallback() {\n\t\t\tsetOffsetTop(element.offsetTop)\n\t\t}\n\n\t\tfunction updateTopOffsetHandler() {\n\t\t\trequestAnimationFrame(updateTopOffsetCallback)\n\t\t}\n\n\t\tupdateTopOffsetHandler()\n\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\trequestAnimationFrame(updateTopOffsetCallback)\n\t\t})\n\n\t\tobserver.observe(element)\n\n\t\treturn () => {\n\t\t\tobserver.unobserve(element)\n\t\t}\n\t}, [ref])\n\n\treturn offsetTop\n}\n"],"names":[],"mappings":";AAEO,SAAS,oBAAoB,KAAkD;AACrF,QAAM,CAAC,WAAW,YAAY,IAAI,SAA6B,MAAS;AAExE,kBAAgB,MAAM;AACjB,QAAA,CAAC,KAAK,SAAS;AAClB;AAAA,IACD;AAEA,UAAM,UAAU,IAAI;AAEpB,aAAS,0BAA0B;AAClC,mBAAa,QAAQ,SAAS;AAAA,IAC/B;AAEA,aAAS,yBAAyB;AACjC,4BAAsB,uBAAuB;AAAA,IAC9C;AAEuB;AAEjB,UAAA,WAAW,IAAI,eAAe,MAAM;AACzC,4BAAsB,uBAAuB;AAAA,IAAA,CAC7C;AAED,aAAS,QAAQ,OAAO;AAExB,WAAO,MAAM;AACZ,eAAS,UAAU,OAAO;AAAA,IAAA;AAAA,EAC3B,GACE,CAAC,GAAG,CAAC;AAED,SAAA;AACR;"}
@@ -1,4 +1,4 @@
1
- import deepEqual from "deep-equal";
1
+ import deepEqual from "fast-deep-equal/es6/index.js";
2
2
  import { useRef } from "react";
3
3
  function useExpectSameValueReference(next, shouldThrow = false) {
4
4
  const previous = useRef(next);
@@ -1 +1 @@
1
- {"version":3,"file":"useExpectSameValueReference.js","sources":["../../../src/hooks/useExpectSameValueReference.ts"],"sourcesContent":["import deepEqual from 'deep-equal'\nimport { useRef } from 'react'\n\n/**\n * Checks whether the next value is the same reference as the previous one\n *\n * If not, it checks whether the values are deeply equal. If not, it logs an error.\n *\n * @param next - Value to be checked.\n * @param shouldThrow - If true, it throws an error instead of logging it. Defaults to false.\n * @returns void\n * -\n * @example\n * ```ts\n * useExpectSameValueReference(style)\n * ```\n * @example\n * ```ts\n * useExpectSameValueReference(style, true)\n * ```\n * @example\n * ```ts\n * useExpectSameValueReference(style, import.meta.env.DEV)\n * ```\n */\nexport function useExpectSameValueReference<T>(next: T, shouldThrow: boolean = false) {\n\tconst previous = useRef(next)\n\n\tif (next !== previous.current\n\t\t&& typeof next === 'object'\n\t\t&& typeof previous.current === 'object'\n\t\t&& deepEqual(next, previous.current)\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconsole.error(\n\t\t\t\t'Previous and next values do not match in reference although match in value. ' +\n\t\t\t\t'Try declaring constants outside of the component scope. ' +\n\t\t\t\t'Otherwise try to memoize callbacks with useCallback, ' +\n\t\t\t\t'useReferentiallyStableCallback useEvent, useRef or useMemo.', {\n\t\t\t\tprevious: previous.current,\n\t\t\t\tnext,\n\t\t\t})\n\t\t}\n\n\t\tif (shouldThrow) {\n\t\t\tthrow new Error('Expecting same reference for same values')\n\t\t}\n\t}\n\n\tprevious.current = next\n}\n"],"names":[],"mappings":";;AAyBgB,SAAA,4BAA+B,MAAS,cAAuB,OAAO;AAC/E,QAAA,WAAW,OAAO,IAAI;AAE5B,MAAI,SAAS,SAAS,WAClB,OAAO,SAAS,YAChB,OAAO,SAAS,YAAY,YAC5B,UAAU,MAAM,SAAS,OAAO,GAClC;AAYD,QAAI,aAAa;AACV,YAAA,IAAI,MAAM,0CAA0C;AAAA,IAC3D;AAAA,EACD;AAEA,WAAS,UAAU;AACpB;"}
1
+ {"version":3,"file":"useExpectSameValueReference.js","sources":["../../../src/hooks/useExpectSameValueReference.ts"],"sourcesContent":["import deepEqual from 'fast-deep-equal/es6/index.js'\nimport { useRef } from 'react'\n\n/**\n * Checks whether the next value is the same reference as the previous one\n *\n * If not, it checks whether the values are deeply equal. If not, it logs an error.\n *\n * @param next - Value to be checked.\n * @param shouldThrow - If true, it throws an error instead of logging it. Defaults to false.\n * @returns void\n * -\n * @example\n * ```ts\n * useExpectSameValueReference(style)\n * ```\n * @example\n * ```ts\n * useExpectSameValueReference(style, true)\n * ```\n * @example\n * ```ts\n * useExpectSameValueReference(style, import.meta.env.DEV)\n * ```\n */\nexport function useExpectSameValueReference<T>(next: T, shouldThrow: boolean = false) {\n\tconst previous = useRef(next)\n\n\tif (next !== previous.current\n\t\t&& typeof next === 'object'\n\t\t&& typeof previous.current === 'object'\n\t\t&& deepEqual(next, previous.current)\n\t) {\n\t\tif (import.meta.env.DEV) {\n\t\t\tconsole.error(\n\t\t\t\t'Previous and next values do not match in reference although match in value. ' +\n\t\t\t\t'Try declaring constants outside of the component scope. ' +\n\t\t\t\t'Otherwise try to memoize callbacks with useCallback, ' +\n\t\t\t\t'useReferentiallyStableCallback useEvent, useRef or useMemo.', {\n\t\t\t\tprevious: previous.current,\n\t\t\t\tnext,\n\t\t\t})\n\t\t}\n\n\t\tif (shouldThrow) {\n\t\t\tthrow new Error('Expecting same reference for same values')\n\t\t}\n\t}\n\n\tprevious.current = next\n}\n"],"names":[],"mappings":";;AAyBgB,SAAA,4BAA+B,MAAS,cAAuB,OAAO;AAC/E,QAAA,WAAW,OAAO,IAAI;AAE5B,MAAI,SAAS,SAAS,WAClB,OAAO,SAAS,YAChB,OAAO,SAAS,YAAY,YAC5B,UAAU,MAAM,SAAS,OAAO,GAClC;AAYD,QAAI,aAAa;AACV,YAAA,IAAI,MAAM,0CAA0C;AAAA,IAC3D;AAAA,EACD;AAEA,WAAS,UAAU;AACpB;"}
@@ -1,11 +1,11 @@
1
- import { useRef } from "react";
1
+ import { useMemo } from "react";
2
2
  const count = { current: 360 };
3
3
  function nextId() {
4
4
  count.current += 1;
5
5
  return `:${count.current.toString(36)}:`;
6
6
  }
7
7
  function useId() {
8
- return useRef(nextId()).current;
8
+ return useMemo(() => nextId(), []);
9
9
  }
10
10
  export {
11
11
  useId
@@ -1 +1 @@
1
- {"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useRef(nextId()).current\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;AACrC;AAUO,SAAS,QAAQ;AAChB,SAAA,OAAO,QAAQ,EAAE;AACzB;"}
1
+ {"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;AACrC;AAUO,SAAS,QAAQ;AACvB,SAAO,QAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;"}
@@ -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;"}
@@ -1,4 +1,4 @@
1
- import deepEqual from "deep-equal";
1
+ import deepEqual from "fast-deep-equal/es6/index.js";
2
2
  import { useRef, useState, useEffect, useLayoutEffect } from "react";
3
3
  import { unwrapRefValue } from "./unwrapRefValue.js";
4
4
  import { useScopedConsoleRef } from "../debug-context/Context.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useOnElementMutation.js","sources":["../../../src/hooks/useOnElementMutation.ts"],"sourcesContent":["import deepEqual from 'deep-equal'\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementMutation(\n\trefOrElement: RefObjectOrElement<HTMLElement | undefined>,\n\tcallback: MutationCallback,\n\toptions: MutationObserverInit = { attributes: true, childList: true, subtree: true },\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementMutation')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst optionsRef = useRef<MutationObserverInit>(options); optionsRef.current = options\n\n\tconst [optionsState, setOptionsState] = useState<MutationObserverInit>(options)\n\n\tuseEffect(() => {\n\t\tif (!deepEqual(optionsRef.current, options)) {\n\t\t\tsetOptionsState(options)\n\t\t}\n\t}, [options])\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\n\t\tif (element) {\n\t\t\tfunction handler(mutations: MutationRecord[], observer: MutationObserver) {\n\t\t\t\tscopedConsoleRef.current.logged('element.mutations', mutations)\n\t\t\t\tcallbackRef.current(mutations, observer)\n\t\t\t}\n\n\t\t\tconst observer = new MutationObserver(handler)\n\n\t\t\tobserver.observe(element, optionsState)\n\n\t\t\treturn () => {\n\t\t\t\tobserver.disconnect()\n\t\t\t}\n\t\t}\n\t}, [optionsState, refOrElement, scopedConsoleRef])\n}\n"],"names":["observer"],"mappings":";;;;AAKgB,SAAA,qBACf,cACA,UACA,UAAgC,EAAE,YAAY,MAAM,WAAW,MAAM,SAAS,KAAA,GAC7E;AACK,QAAA,mBAAmB,oBAAoB,sBAAsB;AAE7D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,aAAa,OAA6B,OAAO;AAAG,aAAW,UAAU;AAE/E,QAAM,CAAC,cAAc,eAAe,IAAI,SAA+B,OAAO;AAE9E,YAAU,MAAM;AACf,QAAI,CAAC,UAAU,WAAW,SAAS,OAAO,GAAG;AAC5C,sBAAgB,OAAO;AAAA,IACxB;AAAA,EAAA,GACE,CAAC,OAAO,CAAC;AAEZ,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAE3C,QAAI,SAAS;AACH,UAAA,UAAT,SAAiB,WAA6BA,WAA4B;AACxD,yBAAA,QAAQ,OAAO,qBAAqB,SAAS;AAClD,oBAAA,QAAQ,WAAWA,SAAQ;AAAA,MAAA;AAGlC,YAAA,WAAW,IAAI,iBAAiB,OAAO;AAEpC,eAAA,QAAQ,SAAS,YAAY;AAEtC,aAAO,MAAM;AACZ,iBAAS,WAAW;AAAA,MAAA;AAAA,IAEtB;AAAA,EACE,GAAA,CAAC,cAAc,cAAc,gBAAgB,CAAC;AAClD;"}
1
+ {"version":3,"file":"useOnElementMutation.js","sources":["../../../src/hooks/useOnElementMutation.ts"],"sourcesContent":["import deepEqual from 'fast-deep-equal/es6/index.js'\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementMutation(\n\trefOrElement: RefObjectOrElement<HTMLElement | undefined>,\n\tcallback: MutationCallback,\n\toptions: MutationObserverInit = { attributes: true, childList: true, subtree: true },\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementMutation')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst optionsRef = useRef<MutationObserverInit>(options); optionsRef.current = options\n\n\tconst [optionsState, setOptionsState] = useState<MutationObserverInit>(options)\n\n\tuseEffect(() => {\n\t\tif (!deepEqual(optionsRef.current, options)) {\n\t\t\tsetOptionsState(options)\n\t\t}\n\t}, [options])\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\n\t\tif (element) {\n\t\t\tfunction handler(mutations: MutationRecord[], observer: MutationObserver) {\n\t\t\t\tscopedConsoleRef.current.logged('element.mutations', mutations)\n\t\t\t\tcallbackRef.current(mutations, observer)\n\t\t\t}\n\n\t\t\tconst observer = new MutationObserver(handler)\n\n\t\t\tobserver.observe(element, optionsState)\n\n\t\t\treturn () => {\n\t\t\t\tobserver.disconnect()\n\t\t\t}\n\t\t}\n\t}, [optionsState, refOrElement, scopedConsoleRef])\n}\n"],"names":["observer"],"mappings":";;;;AAKgB,SAAA,qBACf,cACA,UACA,UAAgC,EAAE,YAAY,MAAM,WAAW,MAAM,SAAS,KAAA,GAC7E;AACK,QAAA,mBAAmB,oBAAoB,sBAAsB;AAE7D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,aAAa,OAA6B,OAAO;AAAG,aAAW,UAAU;AAE/E,QAAM,CAAC,cAAc,eAAe,IAAI,SAA+B,OAAO;AAE9E,YAAU,MAAM;AACf,QAAI,CAAC,UAAU,WAAW,SAAS,OAAO,GAAG;AAC5C,sBAAgB,OAAO;AAAA,IACxB;AAAA,EAAA,GACE,CAAC,OAAO,CAAC;AAEZ,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAE3C,QAAI,SAAS;AACH,UAAA,UAAT,SAAiB,WAA6BA,WAA4B;AACxD,yBAAA,QAAQ,OAAO,qBAAqB,SAAS;AAClD,oBAAA,QAAQ,WAAWA,SAAQ;AAAA,MAAA;AAGlC,YAAA,WAAW,IAAI,iBAAiB,OAAO;AAEpC,eAAA,QAAQ,SAAS,YAAY;AAEtC,aAAO,MAAM;AACZ,iBAAS,WAAW;AAAA,MAAA;AAAA,IAEtB;AAAA,EACE,GAAA,CAAC,cAAc,cAAc,gBAAgB,CAAC;AAClD;"}
@@ -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
- };
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
+ }
36
43
  } else {
37
- element.addEventListener("scroll", debouncedHandler, { passive: true, capture: true });
38
- return () => {
39
- element.removeEventListener("scroll", debouncedHandler);
40
- };
44
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
41
45
  }
42
- } else if (element) {
43
- 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} 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}, [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,MAAA,OACM;AACA,cAAA,IAAI,MAAM,mEAAmE;AAAA,MACpF;AAAA,IACD;AAAA,EACE,GAAA,CAAC,UAAU,cAAc,gBAAgB,CAAC;AAC9C;"}
@@ -6,6 +6,8 @@ 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";
10
+ import { getChildrenAsLabel, useChildrenAsLabel } from "./hooks/useChildrenAsLabel.js";
9
11
  import { useComposeRef } from "./hooks/useComposeRef.js";
10
12
  import { useConstantLengthInvariant } from "./hooks/useConstantLengthInvariant.js";
11
13
  import { useConstantValueInvariant } from "./hooks/useConstantValueInvariant.js";
@@ -14,14 +16,18 @@ import { useDebounce } from "./hooks/useDebounce.js";
14
16
  import { useDebounceCallback } from "./hooks/useDebounceCallback.js";
15
17
  import { useDocumentTitle } from "./hooks/useDocumentTitle.js";
16
18
  import { useElementSize } from "./hooks/useElementSize.js";
19
+ import { useElementTopOffset } from "./hooks/useElementTopOffset.js";
17
20
  import { useEventHandler } from "./hooks/useEventHandler.js";
18
21
  import { useExpectSameValueReference } from "./hooks/useExpectSameValueReference.js";
19
22
  import { useForceRender } from "./hooks/useForceRender.js";
20
23
  import { useId } from "./hooks/useId.js";
21
24
  import { useIsMounted } from "./hooks/useIsMounted.js";
22
25
  import { useObjectMemo } from "./hooks/useObjectMemo.js";
26
+ import { useOnElementClickOutsideCallback } from "./hooks/useOnElementClickOutsideCallback.js";
27
+ import { useOnElementMouseEnterDelayedCallback } from "./hooks/useOnElementMouseEnterDelayedCallback.js";
23
28
  import { useOnElementMutation } from "./hooks/useOnElementMutation.js";
24
29
  import { useOnElementResize } from "./hooks/useOnElementResize.js";
30
+ import { useOnScrollWithin } from "./hooks/useOnScrollWithin.js";
25
31
  import { useOnWindowResize } from "./hooks/useOnWindowResize.js";
26
32
  import { usePreviousValue } from "./hooks/usePreviousValue.js";
27
33
  import { useScrollOffsets } from "./hooks/useScrollOffsets.js";
@@ -54,6 +60,7 @@ export {
54
60
  createOptionalContextFactory,
55
61
  emptyArray,
56
62
  emptyObject,
63
+ getChildrenAsLabel,
57
64
  identityFunction,
58
65
  isNoopScopedConsole,
59
66
  noop,
@@ -66,6 +73,8 @@ export {
66
73
  useAbortController,
67
74
  useAddClassNameDuringResize,
68
75
  useArrayMapMemo,
76
+ useAutoHeightTextArea,
77
+ useChildrenAsLabel,
69
78
  useClassName,
70
79
  useClassNameFactory,
71
80
  useColorScheme,
@@ -77,14 +86,18 @@ export {
77
86
  useDebounceCallback,
78
87
  useDocumentTitle,
79
88
  useElementSize,
89
+ useElementTopOffset,
80
90
  useEventHandler,
81
91
  useExpectSameValueReference,
82
92
  useForceRender,
83
93
  useId,
84
94
  useIsMounted,
85
95
  useObjectMemo,
96
+ useOnElementClickOutsideCallback,
97
+ useOnElementMouseEnterDelayedCallback,
86
98
  useOnElementMutation,
87
99
  useOnElementResize,
100
+ useOnScrollWithin,
88
101
  useOnWindowResize,
89
102
  usePreviousValue,
90
103
  useReferentiallyStableCallback,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}