@contember/react-utils 1.2.3 → 1.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/development/context/createNonNullableContextFactory.cjs +17 -0
  2. package/dist/development/context/createNonNullableContextFactory.cjs.map +1 -0
  3. package/dist/development/context/createOptionalContextFactory.cjs +13 -0
  4. package/dist/development/context/createOptionalContextFactory.cjs.map +1 -0
  5. package/dist/development/debug-context/Constants.cjs +25 -0
  6. package/dist/development/debug-context/Constants.cjs.map +1 -0
  7. package/dist/development/debug-context/Context.cjs +71 -0
  8. package/dist/development/debug-context/Context.cjs.map +1 -0
  9. package/dist/development/hooks/unwrapRefValue.cjs +11 -0
  10. package/dist/development/hooks/unwrapRefValue.cjs.map +1 -0
  11. package/dist/development/hooks/useAbortController.cjs +17 -0
  12. package/dist/development/hooks/useAbortController.cjs.map +1 -0
  13. package/dist/development/hooks/useAddClassNameDuringResize.cjs +32 -0
  14. package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +1 -0
  15. package/dist/development/hooks/useArrayMapMemo.cjs +11 -0
  16. package/dist/development/hooks/useArrayMapMemo.cjs.map +1 -0
  17. package/dist/development/hooks/useAutoHeightTextArea.cjs +41 -0
  18. package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -0
  19. package/dist/development/hooks/useChildrenAsLabel.cjs +53 -0
  20. package/dist/development/hooks/useChildrenAsLabel.cjs.map +1 -0
  21. package/dist/development/hooks/useComposeRef.cjs +31 -0
  22. package/dist/development/hooks/useComposeRef.cjs.map +1 -0
  23. package/dist/development/hooks/useConstantLengthInvariant.cjs +15 -0
  24. package/dist/development/hooks/useConstantLengthInvariant.cjs.map +1 -0
  25. package/dist/development/hooks/useConstantValueInvariant.cjs +15 -0
  26. package/dist/development/hooks/useConstantValueInvariant.cjs.map +1 -0
  27. package/dist/development/hooks/useContainerWidth.cjs +14 -0
  28. package/dist/development/hooks/useContainerWidth.cjs.map +1 -0
  29. package/dist/development/hooks/useDebounce.cjs +15 -0
  30. package/dist/development/hooks/useDebounce.cjs.map +1 -0
  31. package/dist/development/hooks/useDebounceCallback.cjs +19 -0
  32. package/dist/development/hooks/useDebounceCallback.cjs.map +1 -0
  33. package/dist/development/hooks/useDocumentTitle.cjs +22 -0
  34. package/dist/development/hooks/useDocumentTitle.cjs.map +1 -0
  35. package/dist/development/hooks/useElementSize.cjs +37 -0
  36. package/dist/development/hooks/useElementSize.cjs.map +1 -0
  37. package/dist/development/hooks/useElementTopOffset.cjs +29 -0
  38. package/dist/development/hooks/useElementTopOffset.cjs.map +1 -0
  39. package/dist/development/hooks/useEventHandler.cjs +19 -0
  40. package/dist/development/hooks/useEventHandler.cjs.map +1 -0
  41. package/dist/development/hooks/useExpectSameValueReference.cjs +24 -0
  42. package/dist/development/hooks/useExpectSameValueReference.cjs.map +1 -0
  43. package/dist/development/hooks/useForceRender.cjs +9 -0
  44. package/dist/development/hooks/useForceRender.cjs.map +1 -0
  45. package/dist/development/hooks/useId.cjs +13 -0
  46. package/dist/development/hooks/useId.cjs.map +1 -0
  47. package/dist/development/hooks/useIsMounted.cjs +18 -0
  48. package/dist/development/hooks/useIsMounted.cjs.map +1 -0
  49. package/dist/development/hooks/useObjectMemo.cjs +27 -0
  50. package/dist/development/hooks/useObjectMemo.cjs.map +1 -0
  51. package/dist/development/hooks/useOnElementClickOutsideCallback.cjs +20 -0
  52. package/dist/development/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
  53. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
  54. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
  55. package/dist/development/hooks/useOnElementMutation.cjs +35 -0
  56. package/dist/development/hooks/useOnElementMutation.cjs.map +1 -0
  57. package/dist/development/hooks/useOnElementResize.cjs +42 -0
  58. package/dist/development/hooks/useOnElementResize.cjs.map +1 -0
  59. package/dist/development/hooks/useOnScrollWithin.cjs +52 -0
  60. package/dist/development/hooks/useOnScrollWithin.cjs.map +1 -0
  61. package/dist/development/hooks/useOnWindowResize.cjs +36 -0
  62. package/dist/development/hooks/useOnWindowResize.cjs.map +1 -0
  63. package/dist/development/hooks/usePreviousValue.cjs +12 -0
  64. package/dist/development/hooks/usePreviousValue.cjs.map +1 -0
  65. package/dist/development/hooks/useScrollOffsets.cjs +67 -0
  66. package/dist/development/hooks/useScrollOffsets.cjs.map +1 -0
  67. package/dist/development/hooks/useStoredState.cjs +23 -0
  68. package/dist/development/hooks/useStoredState.cjs.map +1 -0
  69. package/dist/development/hooks/useUpdatedRef.cjs +10 -0
  70. package/dist/development/hooks/useUpdatedRef.cjs.map +1 -0
  71. package/dist/development/hooks/useWindowSize.cjs +20 -0
  72. package/dist/development/hooks/useWindowSize.cjs.map +1 -0
  73. package/dist/development/index.cjs +112 -0
  74. package/dist/development/index.cjs.map +1 -0
  75. package/dist/development/referentiallyStable/emptyArray.cjs +5 -0
  76. package/dist/development/referentiallyStable/emptyArray.cjs.map +1 -0
  77. package/dist/development/referentiallyStable/emptyObject.cjs +5 -0
  78. package/dist/development/referentiallyStable/emptyObject.cjs.map +1 -0
  79. package/dist/development/referentiallyStable/identityFunction.cjs +5 -0
  80. package/dist/development/referentiallyStable/identityFunction.cjs.map +1 -0
  81. package/dist/development/referentiallyStable/noop.cjs +5 -0
  82. package/dist/development/referentiallyStable/noop.cjs.map +1 -0
  83. package/dist/development/referentiallyStable/returnFalse.cjs +5 -0
  84. package/dist/development/referentiallyStable/returnFalse.cjs.map +1 -0
  85. package/dist/development/referentiallyStable/returnTrue.cjs +5 -0
  86. package/dist/development/referentiallyStable/returnTrue.cjs.map +1 -0
  87. package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
  88. package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
  89. package/dist/development/theming/ColorSchemeProvider.cjs +18 -0
  90. package/dist/development/theming/ColorSchemeProvider.cjs.map +1 -0
  91. package/dist/development/theming/GlobalClassNamePrefixContext.cjs +6 -0
  92. package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
  93. package/dist/development/theming/contexts.cjs +12 -0
  94. package/dist/development/theming/contexts.cjs.map +1 -0
  95. package/dist/development/theming/useClassName.cjs +17 -0
  96. package/dist/development/theming/useClassName.cjs.map +1 -0
  97. package/dist/development/theming/useClassNameFactory.cjs +22 -0
  98. package/dist/development/theming/useClassNameFactory.cjs.map +1 -0
  99. package/dist/development/theming/useThemedClassName.cjs +17 -0
  100. package/dist/development/theming/useThemedClassName.cjs.map +1 -0
  101. package/dist/development/theming/useThemedClassNameFactory.cjs +29 -0
  102. package/dist/development/theming/useThemedClassNameFactory.cjs.map +1 -0
  103. package/dist/production/context/createNonNullableContextFactory.cjs +17 -0
  104. package/dist/production/context/createNonNullableContextFactory.cjs.map +1 -0
  105. package/dist/production/context/createOptionalContextFactory.cjs +13 -0
  106. package/dist/production/context/createOptionalContextFactory.cjs.map +1 -0
  107. package/dist/production/debug-context/Constants.cjs +25 -0
  108. package/dist/production/debug-context/Constants.cjs.map +1 -0
  109. package/dist/production/debug-context/Context.cjs +67 -0
  110. package/dist/production/debug-context/Context.cjs.map +1 -0
  111. package/dist/production/hooks/unwrapRefValue.cjs +11 -0
  112. package/dist/production/hooks/unwrapRefValue.cjs.map +1 -0
  113. package/dist/production/hooks/useAbortController.cjs +17 -0
  114. package/dist/production/hooks/useAbortController.cjs.map +1 -0
  115. package/dist/production/hooks/useAddClassNameDuringResize.cjs +32 -0
  116. package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +1 -0
  117. package/dist/production/hooks/useArrayMapMemo.cjs +9 -0
  118. package/dist/production/hooks/useArrayMapMemo.cjs.map +1 -0
  119. package/dist/production/hooks/useAutoHeightTextArea.cjs +41 -0
  120. package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -0
  121. package/dist/production/hooks/useChildrenAsLabel.cjs +52 -0
  122. package/dist/production/hooks/useChildrenAsLabel.cjs.map +1 -0
  123. package/dist/production/hooks/useComposeRef.cjs +31 -0
  124. package/dist/production/hooks/useComposeRef.cjs.map +1 -0
  125. package/dist/production/hooks/useConstantLengthInvariant.cjs +6 -0
  126. package/dist/production/hooks/useConstantLengthInvariant.cjs.map +1 -0
  127. package/dist/production/hooks/useConstantValueInvariant.cjs +6 -0
  128. package/dist/production/hooks/useConstantValueInvariant.cjs.map +1 -0
  129. package/dist/production/hooks/useContainerWidth.cjs +14 -0
  130. package/dist/production/hooks/useContainerWidth.cjs.map +1 -0
  131. package/dist/production/hooks/useDebounce.cjs +15 -0
  132. package/dist/production/hooks/useDebounce.cjs.map +1 -0
  133. package/dist/production/hooks/useDebounceCallback.cjs +19 -0
  134. package/dist/production/hooks/useDebounceCallback.cjs.map +1 -0
  135. package/dist/production/hooks/useDocumentTitle.cjs +22 -0
  136. package/dist/production/hooks/useDocumentTitle.cjs.map +1 -0
  137. package/dist/production/hooks/useElementSize.cjs +37 -0
  138. package/dist/production/hooks/useElementSize.cjs.map +1 -0
  139. package/dist/production/hooks/useElementTopOffset.cjs +29 -0
  140. package/dist/production/hooks/useElementTopOffset.cjs.map +1 -0
  141. package/dist/production/hooks/useEventHandler.cjs +19 -0
  142. package/dist/production/hooks/useEventHandler.cjs.map +1 -0
  143. package/dist/production/hooks/useExpectSameValueReference.cjs +15 -0
  144. package/dist/production/hooks/useExpectSameValueReference.cjs.map +1 -0
  145. package/dist/production/hooks/useForceRender.cjs +9 -0
  146. package/dist/production/hooks/useForceRender.cjs.map +1 -0
  147. package/dist/production/hooks/useId.cjs +13 -0
  148. package/dist/production/hooks/useId.cjs.map +1 -0
  149. package/dist/production/hooks/useIsMounted.cjs +18 -0
  150. package/dist/production/hooks/useIsMounted.cjs.map +1 -0
  151. package/dist/production/hooks/useObjectMemo.cjs +27 -0
  152. package/dist/production/hooks/useObjectMemo.cjs.map +1 -0
  153. package/dist/production/hooks/useOnElementClickOutsideCallback.cjs +20 -0
  154. package/dist/production/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
  155. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
  156. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
  157. package/dist/production/hooks/useOnElementMutation.cjs +35 -0
  158. package/dist/production/hooks/useOnElementMutation.cjs.map +1 -0
  159. package/dist/production/hooks/useOnElementResize.cjs +42 -0
  160. package/dist/production/hooks/useOnElementResize.cjs.map +1 -0
  161. package/dist/production/hooks/useOnScrollWithin.cjs +52 -0
  162. package/dist/production/hooks/useOnScrollWithin.cjs.map +1 -0
  163. package/dist/production/hooks/useOnWindowResize.cjs +36 -0
  164. package/dist/production/hooks/useOnWindowResize.cjs.map +1 -0
  165. package/dist/production/hooks/usePreviousValue.cjs +12 -0
  166. package/dist/production/hooks/usePreviousValue.cjs.map +1 -0
  167. package/dist/production/hooks/useScrollOffsets.cjs +67 -0
  168. package/dist/production/hooks/useScrollOffsets.cjs.map +1 -0
  169. package/dist/production/hooks/useStoredState.cjs +23 -0
  170. package/dist/production/hooks/useStoredState.cjs.map +1 -0
  171. package/dist/production/hooks/useUpdatedRef.cjs +10 -0
  172. package/dist/production/hooks/useUpdatedRef.cjs.map +1 -0
  173. package/dist/production/hooks/useWindowSize.cjs +20 -0
  174. package/dist/production/hooks/useWindowSize.cjs.map +1 -0
  175. package/dist/production/index.cjs +112 -0
  176. package/dist/production/index.cjs.map +1 -0
  177. package/dist/production/referentiallyStable/emptyArray.cjs +5 -0
  178. package/dist/production/referentiallyStable/emptyArray.cjs.map +1 -0
  179. package/dist/production/referentiallyStable/emptyObject.cjs +5 -0
  180. package/dist/production/referentiallyStable/emptyObject.cjs.map +1 -0
  181. package/dist/production/referentiallyStable/identityFunction.cjs +5 -0
  182. package/dist/production/referentiallyStable/identityFunction.cjs.map +1 -0
  183. package/dist/production/referentiallyStable/noop.cjs +5 -0
  184. package/dist/production/referentiallyStable/noop.cjs.map +1 -0
  185. package/dist/production/referentiallyStable/returnFalse.cjs +5 -0
  186. package/dist/production/referentiallyStable/returnFalse.cjs.map +1 -0
  187. package/dist/production/referentiallyStable/returnTrue.cjs +5 -0
  188. package/dist/production/referentiallyStable/returnTrue.cjs.map +1 -0
  189. package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
  190. package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
  191. package/dist/production/theming/ColorSchemeProvider.cjs +14 -0
  192. package/dist/production/theming/ColorSchemeProvider.cjs.map +1 -0
  193. package/dist/production/theming/GlobalClassNamePrefixContext.cjs +6 -0
  194. package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
  195. package/dist/production/theming/contexts.cjs +12 -0
  196. package/dist/production/theming/contexts.cjs.map +1 -0
  197. package/dist/production/theming/useClassName.cjs +17 -0
  198. package/dist/production/theming/useClassName.cjs.map +1 -0
  199. package/dist/production/theming/useClassNameFactory.cjs +22 -0
  200. package/dist/production/theming/useClassNameFactory.cjs.map +1 -0
  201. package/dist/production/theming/useThemedClassName.cjs +17 -0
  202. package/dist/production/theming/useThemedClassName.cjs.map +1 -0
  203. package/dist/production/theming/useThemedClassNameFactory.cjs +29 -0
  204. package/dist/production/theming/useThemedClassNameFactory.cjs.map +1 -0
  205. package/dist/types/tsconfig.tsbuildinfo +1 -1
  206. package/package.json +10 -3
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useOnWindowResize = require("./useOnWindowResize.cjs");
5
+ const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
6
+ function addClassName(className, element) {
7
+ if (element.classList.contains(className)) {
8
+ element.classList.remove(className);
9
+ }
10
+ }
11
+ function removeClassName(className, element) {
12
+ if (!element.classList.contains(className)) {
13
+ element.classList.add(className);
14
+ }
15
+ }
16
+ function useAddClassNameDuringResize(className, timeoutToRestore = 300, element) {
17
+ const timeoutID = react.useRef();
18
+ const addTemporaryClassName = useReferentiallyStableCallback.useReferentiallyStableCallback(() => {
19
+ clearTimeout(timeoutID.current);
20
+ removeClassName(className, element ?? document.body);
21
+ timeoutID.current = setTimeout(() => {
22
+ addClassName(className, element ?? document.body);
23
+ }, timeoutToRestore);
24
+ return () => {
25
+ clearTimeout(timeoutID.current);
26
+ };
27
+ });
28
+ react.useLayoutEffect(addTemporaryClassName, [addTemporaryClassName]);
29
+ useOnWindowResize.useOnWindowResize(addTemporaryClassName);
30
+ }
31
+ exports.useAddClassNameDuringResize = useAddClassNameDuringResize;
32
+ //# sourceMappingURL=useAddClassNameDuringResize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAddClassNameDuringResize.cjs","sources":["../../../src/hooks/useAddClassNameDuringResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nfunction addClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (element.classList.contains(className)) {\n\t\telement.classList.remove(className)\n\t}\n}\n\nfunction removeClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (!element.classList.contains(className)) {\n\t\telement.classList.add(className)\n\t}\n}\n\n/**\n * Adds CSS class during resize event to element\n *\n * - Falls back to document.body when no element is specified\n * - Adds CSS class to element also on the initial load\n * - Uses element.classList directly\n *\n * @param className - CSS class to apply during the resize event\n * @param timeoutToRestore - Timeout in milliseconds to wait before finally removing the CSS class\n * @param element - Optional HTML element to apply CSS class to\n */\nexport function useAddClassNameDuringResize(\n\tclassName: string,\n\ttimeoutToRestore: number = 300,\n\telement?: HTMLElement,\n) {\n\tconst timeoutID = useRef<number>()\n\n\tconst addTemporaryClassName = useReferentiallyStableCallback(() => {\n\t\tclearTimeout(timeoutID.current)\n\t\tremoveClassName(className, element ?? document.body)\n\n\t\ttimeoutID.current = setTimeout(() => {\n\t\t\taddClassName(className, element ?? document.body)\n\t\t}, timeoutToRestore)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID.current)\n\t\t}\n\t})\n\n\tuseLayoutEffect(addTemporaryClassName, [addTemporaryClassName])\n\tuseOnWindowResize(addTemporaryClassName)\n}\n"],"names":["useRef","useReferentiallyStableCallback","useLayoutEffect","useOnWindowResize"],"mappings":";;;;;AAIA,SAAS,aACR,WACA,SACC;AACD,MAAI,QAAQ,UAAU,SAAS,SAAS,GAAG;AAClC,YAAA,UAAU,OAAO,SAAS;AAAA,EACnC;AACD;AAEA,SAAS,gBACR,WACA,SACC;AACD,MAAI,CAAC,QAAQ,UAAU,SAAS,SAAS,GAAG;AACnC,YAAA,UAAU,IAAI,SAAS;AAAA,EAChC;AACD;AAaO,SAAS,4BACf,WACA,mBAA2B,KAC3B,SACC;AACD,QAAM,YAAYA,MAAAA;AAEZ,QAAA,wBAAwBC,+BAAAA,+BAA+B,MAAM;AAClE,iBAAa,UAAU,OAAO;AACd,oBAAA,WAAW,WAAW,SAAS,IAAI;AAEzC,cAAA,UAAU,WAAW,MAAM;AACvB,mBAAA,WAAW,WAAW,SAAS,IAAI;AAAA,OAC9C,gBAAgB;AAEnB,WAAO,MAAM;AACZ,mBAAa,UAAU,OAAO;AAAA,IAAA;AAAA,EAC/B,CACA;AAEeC,QAAAA,gBAAA,uBAAuB,CAAC,qBAAqB,CAAC;AAC9DC,oBAAA,kBAAkB,qBAAqB;AACxC;;"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useArrayMapMemo = (items, map) => {
5
+ const mapped = react.useMemo(() => items.map(map), [map, ...items]);
6
+ return react.useMemo(() => mapped, mapped);
7
+ };
8
+ exports.useArrayMapMemo = useArrayMapMemo;
9
+ //# sourceMappingURL=useArrayMapMemo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useArrayMapMemo.cjs","sources":["../../../src/hooks/useArrayMapMemo.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { useConstantLengthInvariant } from './useConstantLengthInvariant'\n\n/**\n * ⚠️ ONLY USE THIS IF YOU *REALLY* KNOW WHAT YOU'RE DOING! ⚠️\n * ⚠ HERE BE DRAGONS THAT KNOW WHERE YOU LIVE! ⚠\n *\n * This is a bit of React naughtiness that allows us to memoize outputs of Array.prototype.map() based on the contents\n * of the original array, and not its referential equality. That way, if we create a new array with identical items,\n * we get an array that is referentially equal to the previous one.\n */\nexport const useArrayMapMemo = <Item, OutputItem>(\n\titems: Item[],\n\tmap: (value: Item, index: number, array: Item[]) => OutputItem,\n): OutputItem[] => {\n\tuseConstantLengthInvariant(items)\n\n\t// This is tricky. We don't want to exclude the map function from the dependency list because if it changes but the\n\t// items array remains the same, we still want to re-compute the new array. However, if that yields the same array,\n\t// in the sense that the items are identical, albeit computed via a different map function, we still want to\n\t// preserve the referential equality of the original. Hence the second memo.\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst mapped = useMemo(() => items.map(map), [map, ...items])\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\treturn useMemo(() => mapped, mapped) // This is deliberately not `[mapped]`\n}\n"],"names":["useMemo"],"mappings":";;;AAWa,MAAA,kBAAkB,CAC9B,OACA,QACkB;AASZ,QAAA,SAASA,MAAAA,QAAQ,MAAM,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAGrD,SAAAA,cAAQ,MAAM,QAAQ,MAAM;AACpC;;"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utilities = require("@contember/utilities");
4
+ const react = require("react");
5
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
6
+ const useOnElementResize = require("./useOnElementResize.cjs");
7
+ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
8
+ const measure = react.useCallback(async (ref, minRows2, maxRows2) => {
9
+ if (ref) {
10
+ const rowsAttribute = ref.rows;
11
+ ref.style.height = "";
12
+ ref.style.minHeight = "";
13
+ ref.style.maxHeight = "";
14
+ if (minRows2 !== maxRows2) {
15
+ const height = ref.scrollHeight;
16
+ let minHeight;
17
+ let maxHeight;
18
+ ref.rows = minRows2;
19
+ minHeight = await ref.getBoundingClientRect().height;
20
+ if (maxRows2 === Infinity) {
21
+ maxHeight = Infinity;
22
+ } else {
23
+ ref.rows = maxRows2;
24
+ maxHeight = await ref.getBoundingClientRect().height;
25
+ }
26
+ ref.style.height = utilities.px(height);
27
+ ref.style.minHeight = utilities.px(minHeight);
28
+ ref.style.maxHeight = utilities.px(maxHeight);
29
+ }
30
+ ref.rows = rowsAttribute;
31
+ }
32
+ }, []);
33
+ useOnElementResize.useOnElementResize(textAreaRef, () => {
34
+ measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
35
+ });
36
+ react.useLayoutEffect(() => {
37
+ measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
38
+ }, [maxRows, measure, minRows, textAreaRef, value]);
39
+ };
40
+ exports.useAutoHeightTextArea = useAutoHeightTextArea;
41
+ //# sourceMappingURL=useAutoHeightTextArea.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoHeightTextArea.cjs","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(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\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 = await ref.getBoundingClientRect().height\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 = await ref.getBoundingClientRect().height\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)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["useCallback","minRows","maxRows","px","useOnElementResize","unwrapRefValue","useLayoutEffect"],"mappings":";;;;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAUA,MAAA,YAAY,OAAO,KAAiCC,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAASC,UAAA,GAAG,MAAM;AACxB,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAELC,qBAAA,mBAAmB,aAAa,MAAM;AACrC,YAAQC,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAEDC,QAAAA,gBAAgB,MAAM;AACrB,YAAQD,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;;"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const MULTIPLE_SPACES_REG_EXP = / +/g;
5
+ function normalize(text) {
6
+ return text.replace(MULTIPLE_SPACES_REG_EXP, " ").trim();
7
+ }
8
+ function getChildrenAsLabel(node) {
9
+ if (typeof node === "string" || typeof node === "number") {
10
+ return String(node);
11
+ } else if (node === null || node === void 0 || typeof node === "boolean") {
12
+ return void 0;
13
+ } else if (Array.isArray(node)) {
14
+ return normalize(node.map(getChildrenAsLabel).join(""));
15
+ } else {
16
+ let label = [];
17
+ react.Children.map(node, (child) => {
18
+ if (child === null || child === void 0 || typeof child === "boolean")
19
+ ;
20
+ else if (typeof child === "string") {
21
+ label.push(child);
22
+ } else if (typeof child === "number") {
23
+ label.push(child);
24
+ } else if (Array.isArray(child)) {
25
+ const childLabel = getChildrenAsLabel(child);
26
+ if (childLabel) {
27
+ label.push(childLabel);
28
+ }
29
+ } else {
30
+ if ("props" in child && "children" in child.props) {
31
+ const childLabel = getChildrenAsLabel(child.props.children);
32
+ if (childLabel) {
33
+ label.push(childLabel);
34
+ }
35
+ } else if ("children" in child) {
36
+ const childLabel = getChildrenAsLabel(child.children);
37
+ if (childLabel) {
38
+ label.push(childLabel);
39
+ }
40
+ } else
41
+ ;
42
+ }
43
+ });
44
+ return label.length > 0 ? label.join("") : void 0;
45
+ }
46
+ }
47
+ function useChildrenAsLabel(node) {
48
+ return react.useMemo(() => getChildrenAsLabel(node), [node]);
49
+ }
50
+ exports.getChildrenAsLabel = getChildrenAsLabel;
51
+ exports.useChildrenAsLabel = useChildrenAsLabel;
52
+ //# sourceMappingURL=useChildrenAsLabel.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChildrenAsLabel.cjs","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":["Children","useMemo"],"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;AAExBA,UAAAA,SAAA,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,SAAOC,MAAAA,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;;;"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function setRef(ref, instance) {
5
+ if (ref) {
6
+ if (typeof ref === "function") {
7
+ ref(instance);
8
+ } else if (instance) {
9
+ ref.current = instance;
10
+ }
11
+ }
12
+ }
13
+ function useComposeRef(...refs) {
14
+ const initialRefs = react.useRef(refs);
15
+ const composeRef = react.useMemo(() => {
16
+ function composedRefCallback(instance) {
17
+ initialRefs.current.forEach((ref) => setRef(ref, instance));
18
+ setCurrent(instance);
19
+ }
20
+ function setCurrent(instance) {
21
+ if (instance) {
22
+ composedRefCallback.current = instance;
23
+ }
24
+ }
25
+ composedRefCallback.current = null;
26
+ return composedRefCallback;
27
+ }, []);
28
+ return composeRef;
29
+ }
30
+ exports.useComposeRef = useComposeRef;
31
+ //# sourceMappingURL=useComposeRef.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComposeRef.cjs","sources":["../../../src/hooks/useComposeRef.ts"],"sourcesContent":["import { MutableRefObject, RefCallback, useMemo, useRef } from 'react'\n\nexport type MaybeRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null | undefined\nexport type ComposedRefCallback<T> = RefCallback<T> & { current: T | null };\n\nfunction setRef<T>(ref: MaybeRef<T>, instance: T | null): void {\n\tif (ref) {\n\t\tif (typeof ref === 'function') {\n\t\t\tref(instance)\n\t\t} else if (instance) {\n\t\t\tref.current = instance\n\t\t}\n\t}\n}\n\n/**\n * Fills any number of refs with an instance\n *\n * Useful when you need to use outer ref and inner in the same time, e.g. passing element\n * back to forwardedRef an also using the same value within the component locally.\n *\n * @param refs - Rest parameter of refs to fill with instance\n * @returns Returns a function similar to a RefCallback\n */\nexport function useComposeRef<T>(...refs: MaybeRef<T>[]): ComposedRefCallback<T> {\n\tconst initialRefs = useRef(refs)\n\n\tconst composeRef: ComposedRefCallback<T> = useMemo(() => {\n\t\tfunction composedRefCallback(instance: T | null) {\n\t\t\tinitialRefs.current.forEach(ref => setRef(ref, instance))\n\t\t\tsetCurrent(instance)\n\t\t}\n\n\t\tfunction setCurrent(instance: T | null) {\n\t\t\tif (instance) {\n\t\t\t\tcomposedRefCallback.current = instance\n\t\t\t}\n\t\t}\n\n\t\tcomposedRefCallback.current = null as T | null\n\n\t\treturn composedRefCallback\n\t}, [])\n\n\treturn composeRef\n}\n"],"names":["useRef","useMemo"],"mappings":";;;AAKA,SAAS,OAAU,KAAkB,UAA0B;AAC9D,MAAI,KAAK;AACJ,QAAA,OAAO,QAAQ,YAAY;AAC9B,UAAI,QAAQ;AAAA,eACF,UAAU;AACpB,UAAI,UAAU;AAAA,IACf;AAAA,EACD;AACD;AAWO,SAAS,iBAAoB,MAA6C;AAC1E,QAAA,cAAcA,aAAO,IAAI;AAEzB,QAAA,aAAqCC,MAAAA,QAAQ,MAAM;AACxD,aAAS,oBAAoB,UAAoB;AAChD,kBAAY,QAAQ,QAAQ,CAAA,QAAO,OAAO,KAAK,QAAQ,CAAC;AACxD,iBAAW,QAAQ;AAAA,IACpB;AAEA,aAAS,WAAW,UAAoB;AACvC,UAAI,UAAU;AACb,4BAAoB,UAAU;AAAA,MAC/B;AAAA,IACD;AAEA,wBAAoB,UAAU;AAEvB,WAAA;AAAA,EACR,GAAG,CAAE,CAAA;AAEE,SAAA;AACR;;"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useConstantLengthInvariant = (items, message) => {
4
+ };
5
+ exports.useConstantLengthInvariant = useConstantLengthInvariant;
6
+ //# sourceMappingURL=useConstantLengthInvariant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConstantLengthInvariant.cjs","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAWrF;;"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useConstantValueInvariant = (value, message) => {
4
+ };
5
+ exports.useConstantValueInvariant = useConstantValueInvariant;
6
+ //# sourceMappingURL=useConstantValueInvariant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConstantValueInvariant.cjs","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAUpF;;"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useWindowSize = require("./useWindowSize.cjs");
5
+ const ContainerWidthContext = react.createContext(void 0);
6
+ ContainerWidthContext.displayName = "ContainerWidthContext";
7
+ function useContainerWidth() {
8
+ const maybeContainerWidth = react.useContext(ContainerWidthContext);
9
+ const { width: windowWidth } = useWindowSize.useWindowSize();
10
+ return maybeContainerWidth ?? windowWidth;
11
+ }
12
+ exports.ContainerWidthContext = ContainerWidthContext;
13
+ exports.useContainerWidth = useContainerWidth;
14
+ //# sourceMappingURL=useContainerWidth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContainerWidth.cjs","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":["createContext","useContext","useWindowSize"],"mappings":";;;;AAIa,MAAA,wBAAwBA,MAAAA,cAA4D,MAAS;AAC1G,sBAAsB,cAAc;AAE7B,SAAS,oBAA4B;AACrC,QAAA,sBAAsBC,iBAAW,qBAAqB;AAC5D,QAAM,EAAE,OAAO,YAAY,IAAIC,cAAc,cAAA;AAE7C,SAAO,uBAAuB;AAC/B;;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useDebounce = (value, debounceMs) => {
5
+ const [debounced, setDebounced] = react.useState(value);
6
+ react.useEffect(() => {
7
+ const handle = window.setTimeout(() => setDebounced(value), debounceMs);
8
+ return () => {
9
+ window.clearTimeout(handle);
10
+ };
11
+ }, [value, debounceMs]);
12
+ return debounced;
13
+ };
14
+ exports.useDebounce = useDebounce;
15
+ //# sourceMappingURL=useDebounce.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.cjs","sources":["../../../src/hooks/useDebounce.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nexport const useDebounce = <T>(value: T, debounceMs: number): T => {\n\tconst [debounced, setDebounced] = useState(value)\n\tuseEffect(() => {\n\t\tconst handle = window.setTimeout(() => setDebounced(value), debounceMs)\n\t\treturn () => {\n\t\t\twindow.clearTimeout(handle)\n\t\t}\n\t}, [value, debounceMs])\n\treturn debounced\n}\n"],"names":["useState","useEffect"],"mappings":";;;AAEa,MAAA,cAAc,CAAI,OAAU,eAA0B;AAClE,QAAM,CAAC,WAAW,YAAY,IAAIA,eAAS,KAAK;AAChDC,QAAAA,UAAU,MAAM;AACf,UAAM,SAAS,OAAO,WAAW,MAAM,aAAa,KAAK,GAAG,UAAU;AACtE,WAAO,MAAM;AACZ,aAAO,aAAa,MAAM;AAAA,IAAA;AAAA,EAC3B,GACE,CAAC,OAAO,UAAU,CAAC;AACf,SAAA;AACR;;"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useDebounceCallback = (cb, debounceMs) => {
5
+ const timerRef = react.useRef();
6
+ const cbRef = react.useRef(cb);
7
+ cbRef.current = cb;
8
+ react.useEffect(() => {
9
+ return () => clearTimeout(timerRef.current);
10
+ }, []);
11
+ return react.useCallback(() => {
12
+ timerRef.current && clearTimeout(timerRef.current);
13
+ timerRef.current = setTimeout(() => {
14
+ cbRef.current();
15
+ }, debounceMs);
16
+ }, [debounceMs]);
17
+ };
18
+ exports.useDebounceCallback = useDebounceCallback;
19
+ //# sourceMappingURL=useDebounceCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounceCallback.cjs","sources":["../../../src/hooks/useDebounceCallback.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react'\n\nexport const useDebounceCallback = (cb: () => any, debounceMs: number) => {\n\tconst timerRef = useRef<ReturnType<typeof setTimeout>>()\n\tconst cbRef = useRef(cb)\n\tcbRef.current = cb\n\n\tuseEffect(() => {\n\t\treturn () => clearTimeout(timerRef.current)\n\t}, [])\n\n\treturn useCallback(() => {\n\t\ttimerRef.current && clearTimeout(timerRef.current)\n\n\t\ttimerRef.current = setTimeout(() => {\n\t\t\tcbRef.current()\n\t\t}, debounceMs)\n\t}, [debounceMs])\n}\n"],"names":["useRef","useEffect","useCallback"],"mappings":";;;AAEa,MAAA,sBAAsB,CAAC,IAAe,eAAuB;AACzE,QAAM,WAAWA,MAAAA;AACX,QAAA,QAAQA,aAAO,EAAE;AACvB,QAAM,UAAU;AAEhBC,QAAAA,UAAU,MAAM;AACR,WAAA,MAAM,aAAa,SAAS,OAAO;AAAA,EAC3C,GAAG,CAAE,CAAA;AAEL,SAAOC,kBAAY,MAAM;AACf,aAAA,WAAW,aAAa,SAAS,OAAO;AAExC,aAAA,UAAU,WAAW,MAAM;AACnC,YAAM,QAAQ;AAAA,OACZ,UAAU;AAAA,EAAA,GACX,CAAC,UAAU,CAAC;AAChB;;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function useDocumentTitle(title, formatter) {
5
+ const initialTitle = react.useRef(document.title).current;
6
+ react.useEffect(() => {
7
+ if (title) {
8
+ if (formatter) {
9
+ document.title = formatter(title, initialTitle);
10
+ } else {
11
+ document.title = title;
12
+ }
13
+ } else {
14
+ document.title = initialTitle;
15
+ }
16
+ return () => {
17
+ document.title = initialTitle;
18
+ };
19
+ }, [formatter, initialTitle, title]);
20
+ }
21
+ exports.useDocumentTitle = useDocumentTitle;
22
+ //# sourceMappingURL=useDocumentTitle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDocumentTitle.cjs","sources":["../../../src/hooks/useDocumentTitle.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport function useDocumentTitle(title: string | null | undefined, formatter?: (title: string, initialTitle: string) => string) {\n\tconst initialTitle = useRef(document.title).current\n\n\tuseEffect(() => {\n\t\tif (title) {\n\t\t\tif (formatter) {\n\t\t\t\tdocument.title = formatter(title, initialTitle)\n\t\t\t} else {\n\t\t\t\tdocument.title = title\n\t\t\t}\n\t\t} else {\n\t\t\tdocument.title = initialTitle\n\t\t}\n\n\t\treturn () => {\n\t\t\tdocument.title = initialTitle\n\t\t}\n\t}, [formatter, initialTitle, title])\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AAEgB,SAAA,iBAAiB,OAAkC,WAA6D;AAC/H,QAAM,eAAeA,MAAA,OAAO,SAAS,KAAK,EAAE;AAE5CC,QAAAA,UAAU,MAAM;AACf,QAAI,OAAO;AACV,UAAI,WAAW;AACL,iBAAA,QAAQ,UAAU,OAAO,YAAY;AAAA,MAAA,OACxC;AACN,iBAAS,QAAQ;AAAA,MAClB;AAAA,IAAA,OACM;AACN,eAAS,QAAQ;AAAA,IAClB;AAEA,WAAO,MAAM;AACZ,eAAS,QAAQ;AAAA,IAAA;AAAA,EAEhB,GAAA,CAAC,WAAW,cAAc,KAAK,CAAC;AACpC;;"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utilities = require("@contember/utilities");
4
+ const react = require("react");
5
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
6
+ const useOnElementResize = require("./useOnElementResize.cjs");
7
+ const Context = require("../debug-context/Context.cjs");
8
+ const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
9
+ function useElementSize(refOrElement, options = {}, timeout = 300) {
10
+ const { logged } = Context.useScopedConsoleRef("useElementSize").current;
11
+ const { box = "border-box" } = options;
12
+ const getSizeFromResizeObserverEntry = react.useMemo(() => utilities.getSizeFromResizeObserverEntryFactory(box), [box]);
13
+ const [width, setWidth] = react.useState();
14
+ const [height, setHeight] = react.useState();
15
+ logged("dimensions", { width, height });
16
+ const maybeSetNewDimensions = useReferentiallyStableCallback.useReferentiallyStableCallback((dimensions) => {
17
+ if (width !== dimensions.width) {
18
+ setWidth(dimensions.width);
19
+ }
20
+ if (height !== dimensions.height) {
21
+ setHeight(dimensions.height);
22
+ }
23
+ });
24
+ useOnElementResize.useOnElementResize(refOrElement, (entry) => {
25
+ const dimensions = logged("useOnElementResize => entry:dimensions", getSizeFromResizeObserverEntry(entry));
26
+ maybeSetNewDimensions(dimensions);
27
+ }, { box }, timeout);
28
+ react.useLayoutEffect(() => {
29
+ const element = unwrapRefValue.unwrapRefValue(refOrElement);
30
+ if (element) {
31
+ utilities.getElementDimensionsCallback(element, (dimensions) => maybeSetNewDimensions(dimensions));
32
+ }
33
+ });
34
+ return { height, width };
35
+ }
36
+ exports.useElementSize = useElementSize;
37
+ //# sourceMappingURL=useElementSize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementSize.cjs","sources":["../../../src/hooks/useElementSize.ts"],"sourcesContent":["import { getElementDimensionsCallback, getSizeFromResizeObserverEntryFactory } from '@contember/utilities'\nimport { useLayoutEffect, useMemo, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport type ElementSize = {\n\theight: number\n\twidth: number\n}\n\n/**\n * Measure HTMLElement\n *\n * @param refOrElement - HTMLElement passed directly or indirectly as RefObject\n * @returns Size vector consisting of width and height properties\n */\nexport function useElementSize(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): { height: number | undefined, width: number | undefined } {\n\tconst { logged } = useScopedConsoleRef('useElementSize').current\n\n\tconst { box = 'border-box' } = options\n\tconst getSizeFromResizeObserverEntry = useMemo(() => getSizeFromResizeObserverEntryFactory(box), [box])\n\n\tconst [width, setWidth] = useState<number | undefined>()\n\tconst [height, setHeight] = useState<number | undefined>()\n\n\tlogged('dimensions', { width, height })\n\n\tconst maybeSetNewDimensions = useReferentiallyStableCallback((dimensions: ElementSize) => {\n\t\tif (width !== dimensions.width) {\n\t\t\tsetWidth(dimensions.width)\n\t\t}\n\t\tif (height !== dimensions.height) {\n\t\t\tsetHeight(dimensions.height)\n\t\t}\n\t})\n\n\tuseOnElementResize(refOrElement, entry => {\n\t\tconst dimensions = logged('useOnElementResize => entry:dimensions', getSizeFromResizeObserverEntry(entry))\n\t\tmaybeSetNewDimensions(dimensions)\n\t}, { box }, timeout)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\t\tif (element) {\n\t\t\tgetElementDimensionsCallback(element, dimensions => maybeSetNewDimensions(dimensions))\n\t\t}\n\t})\n\n\treturn { height, width }\n}\n"],"names":["useScopedConsoleRef","useMemo","getSizeFromResizeObserverEntryFactory","useState","useReferentiallyStableCallback","useOnElementResize","useLayoutEffect","unwrapRefValue","getElementDimensionsCallback"],"mappings":";;;;;;;;AAkBO,SAAS,eACf,cACA,UAAiC,CAAA,GACjC,UAAkB,KAC0C;AAC5D,QAAM,EAAE,OAAW,IAAAA,QAAA,oBAAoB,gBAAgB,EAAE;AAEnD,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,iCAAiCC,MAAAA,QAAQ,MAAMC,UAAAA,sCAAsC,GAAG,GAAG,CAAC,GAAG,CAAC;AAEtG,QAAM,CAAC,OAAO,QAAQ,IAAIC,MAA6B,SAAA;AACvD,QAAM,CAAC,QAAQ,SAAS,IAAIA,MAA6B,SAAA;AAEzD,SAAO,cAAc,EAAE,OAAO,OAAQ,CAAA;AAEhC,QAAA,wBAAwBC,8DAA+B,CAAC,eAA4B;AACrF,QAAA,UAAU,WAAW,OAAO;AAC/B,eAAS,WAAW,KAAK;AAAA,IAC1B;AACI,QAAA,WAAW,WAAW,QAAQ;AACjC,gBAAU,WAAW,MAAM;AAAA,IAC5B;AAAA,EAAA,CACA;AAEDC,wCAAmB,cAAc,CAAS,UAAA;AACzC,UAAM,aAAa,OAAO,0CAA0C,+BAA+B,KAAK,CAAC;AACzG,0BAAsB,UAAU;AAAA,EAAA,GAC9B,EAAE,OAAO,OAAO;AAEnBC,QAAAA,gBAAgB,MAAM;AACf,UAAA,UAAUC,8BAAe,YAAY;AAC3C,QAAI,SAAS;AACZC,gBAAA,6BAA6B,SAAS,CAAA,eAAc,sBAAsB,UAAU,CAAC;AAAA,IACtF;AAAA,EAAA,CACA;AAEM,SAAA,EAAE,QAAQ;AAClB;;"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function useElementTopOffset(ref) {
5
+ const [offsetTop, setOffsetTop] = react.useState(void 0);
6
+ react.useLayoutEffect(() => {
7
+ if (!ref?.current) {
8
+ return;
9
+ }
10
+ const element = ref.current;
11
+ function updateTopOffsetCallback() {
12
+ setOffsetTop(element.offsetTop);
13
+ }
14
+ function updateTopOffsetHandler() {
15
+ requestAnimationFrame(updateTopOffsetCallback);
16
+ }
17
+ updateTopOffsetHandler();
18
+ const observer = new ResizeObserver(() => {
19
+ requestAnimationFrame(updateTopOffsetCallback);
20
+ });
21
+ observer.observe(element);
22
+ return () => {
23
+ observer.unobserve(element);
24
+ };
25
+ }, [ref]);
26
+ return offsetTop;
27
+ }
28
+ exports.useElementTopOffset = useElementTopOffset;
29
+ //# sourceMappingURL=useElementTopOffset.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementTopOffset.cjs","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":["useState","useLayoutEffect"],"mappings":";;;AAEO,SAAS,oBAAoB,KAAkD;AACrF,QAAM,CAAC,WAAW,YAAY,IAAIA,MAAAA,SAA6B,MAAS;AAExEC,QAAAA,gBAAgB,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;;"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function useEventHandler(type, callback) {
5
+ const callbackRef = react.useRef(callback);
6
+ callbackRef.current = callback;
7
+ const stableHandler = react.useRef(function(event) {
8
+ return callbackRef.current(event);
9
+ }).current;
10
+ react.useEffect(() => {
11
+ return () => {
12
+ callbackRef.current = () => {
13
+ };
14
+ };
15
+ }, []);
16
+ return stableHandler;
17
+ }
18
+ exports.useEventHandler = useEventHandler;
19
+ //# sourceMappingURL=useEventHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventHandler.cjs","sources":["../../../src/hooks/useEventHandler.ts"],"sourcesContent":["import { EventHandler, SyntheticEvent, useEffect, useRef } from 'react'\n\n/**\n * Similar to useEvent with inferred type for the event parameter according to event type\n *\n * @param type - String, keyof DocumentEventMap, e.g. 'click', 'keydown',...\n * @param callback - EventHandler\n * @returns Stable reference callback\n */\nexport function useEventHandler<E extends SyntheticEvent<any>>(type: E['type'], callback: EventHandler<E>): EventHandler<E> {\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\n\tconst stableHandler = useRef(function (event: any) {\n\t\treturn callbackRef.current(event)\n\t}).current\n\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tcallbackRef.current = () => { }\n\t\t}\n\t}, [])\n\n\treturn stableHandler\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AASgB,SAAA,gBAA+C,MAAiB,UAA4C;AACrH,QAAA,cAAcA,aAAO,QAAQ;AAAG,cAAY,UAAU;AAEtD,QAAA,gBAAgBA,aAAO,SAAU,OAAY;AAC3C,WAAA,YAAY,QAAQ,KAAK;AAAA,EAChC,CAAA,EAAE;AAEHC,QAAAA,UAAU,MAAM;AACf,WAAO,MAAM;AACZ,kBAAY,UAAU,MAAM;AAAA,MAAA;AAAA,IAAE;AAAA,EAEhC,GAAG,CAAE,CAAA;AAEE,SAAA;AACR;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const deepEqual = require("fast-deep-equal/es6/index.js");
4
+ const react = require("react");
5
+ function useExpectSameValueReference(next, shouldThrow = false) {
6
+ const previous = react.useRef(next);
7
+ if (next !== previous.current && typeof next === "object" && typeof previous.current === "object" && deepEqual(next, previous.current)) {
8
+ if (shouldThrow) {
9
+ throw new Error("Expecting same reference for same values");
10
+ }
11
+ }
12
+ previous.current = next;
13
+ }
14
+ exports.useExpectSameValueReference = useExpectSameValueReference;
15
+ //# sourceMappingURL=useExpectSameValueReference.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExpectSameValueReference.cjs","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":["useRef"],"mappings":";;;;AAyBgB,SAAA,4BAA+B,MAAS,cAAuB,OAAO;AAC/E,QAAA,WAAWA,aAAO,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;;"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useForceRender = () => {
5
+ const [, forceRender] = react.useReducer((s) => s + 1, 0);
6
+ return forceRender;
7
+ };
8
+ exports.useForceRender = useForceRender;
9
+ //# sourceMappingURL=useForceRender.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForceRender.cjs","sources":["../../../src/hooks/useForceRender.ts"],"sourcesContent":["import { useReducer } from 'react'\n\nexport const useForceRender = () => {\n\tconst [, forceRender] = useReducer((s: number) => s + 1, 0)\n\treturn forceRender\n}\n"],"names":["useReducer"],"mappings":";;;AAEO,MAAM,iBAAiB,MAAM;AAC7B,QAAA,CAAG,EAAA,WAAW,IAAIA,iBAAW,CAAC,MAAc,IAAI,GAAG,CAAC;AACnD,SAAA;AACR;;"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const count = { current: 360 };
5
+ function nextId() {
6
+ count.current += 1;
7
+ return `:${count.current.toString(36)}:`;
8
+ }
9
+ function useId() {
10
+ return react.useMemo(() => nextId(), []);
11
+ }
12
+ exports.useId = useId;
13
+ //# sourceMappingURL=useId.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useId.cjs","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":["useMemo"],"mappings":";;;AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;AACrC;AAUO,SAAS,QAAQ;AACvB,SAAOA,cAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useIsMounted = () => {
5
+ const isMountedRef = react.useRef(true);
6
+ react.useEffect(
7
+ () => {
8
+ isMountedRef.current = true;
9
+ return () => {
10
+ isMountedRef.current = false;
11
+ };
12
+ },
13
+ []
14
+ );
15
+ return isMountedRef;
16
+ };
17
+ exports.useIsMounted = useIsMounted;
18
+ //# sourceMappingURL=useIsMounted.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsMounted.cjs","sources":["../../../src/hooks/useIsMounted.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport const useIsMounted = () => {\n\tconst isMountedRef = useRef(true)\n\tuseEffect(\n\t\t() => {\n\t\t\tisMountedRef.current = true\n\t\t\treturn () => {\n\t\t\t\tisMountedRef.current = false\n\t\t\t}\n\t\t},\n\t\t[],\n\t)\n\treturn isMountedRef\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AAEO,MAAM,eAAe,MAAM;AAC3B,QAAA,eAAeA,aAAO,IAAI;AAChCC,QAAA;AAAA,IACC,MAAM;AACL,mBAAa,UAAU;AACvB,aAAO,MAAM;AACZ,qBAAa,UAAU;AAAA,MAAA;AAAA,IAEzB;AAAA,IACA,CAAC;AAAA,EAAA;AAEK,SAAA;AACR;;"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const compareObjects = (a, b) => {
5
+ if (a === b) {
6
+ return true;
7
+ }
8
+ const aEntries = Object.entries(a);
9
+ if (aEntries.length !== Object.keys(b).length) {
10
+ return false;
11
+ }
12
+ for (const [key, val] of aEntries) {
13
+ if (!(key in b) || b[key] !== val) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ };
19
+ const useObjectMemo = (value) => {
20
+ const valueRef = react.useRef(value);
21
+ if (!compareObjects(valueRef.current, value)) {
22
+ valueRef.current = value;
23
+ }
24
+ return valueRef.current;
25
+ };
26
+ exports.useObjectMemo = useObjectMemo;
27
+ //# sourceMappingURL=useObjectMemo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useObjectMemo.cjs","sources":["../../../src/hooks/useObjectMemo.ts"],"sourcesContent":["import { useRef } from 'react'\n\nconst compareObjects = (a: object, b: object): boolean => {\n\tif (a === b) {\n\t\treturn true\n\t}\n\tconst aEntries = Object.entries(a)\n\tif (aEntries.length !== Object.keys(b).length) {\n\t\treturn false\n\t}\n\tfor (const [key, val] of aEntries) {\n\t\tif (!(key in b) || (b as any)[key] !== val) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\nexport const useObjectMemo = <A extends object>(value: A): A => {\n\tconst valueRef = useRef(value)\n\tif (!compareObjects(valueRef.current, value)) {\n\t\tvalueRef.current = value\n\t}\n\treturn valueRef.current\n}\n"],"names":["useRef"],"mappings":";;;AAEA,MAAM,iBAAiB,CAAC,GAAW,MAAuB;AACzD,MAAI,MAAM,GAAG;AACL,WAAA;AAAA,EACR;AACM,QAAA,WAAW,OAAO,QAAQ,CAAC;AACjC,MAAI,SAAS,WAAW,OAAO,KAAK,CAAC,EAAE,QAAQ;AACvC,WAAA;AAAA,EACR;AACA,aAAW,CAAC,KAAK,GAAG,KAAK,UAAU;AAClC,QAAI,EAAE,OAAO,MAAO,EAAU,GAAG,MAAM,KAAK;AACpC,aAAA;AAAA,IACR;AAAA,EACD;AACO,SAAA;AACR;AAEa,MAAA,gBAAgB,CAAmB,UAAgB;AACzD,QAAA,WAAWA,aAAO,KAAK;AAC7B,MAAI,CAAC,eAAe,SAAS,SAAS,KAAK,GAAG;AAC7C,aAAS,UAAU;AAAA,EACpB;AACA,SAAO,SAAS;AACjB;;"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
5
+ function useOnElementClickOutsideCallback(refOrElement, callback) {
6
+ react.useEffect(() => {
7
+ const refValue = unwrapRefValue.unwrapRefValue(refOrElement);
8
+ const handleClickOutside = (event) => {
9
+ if (refValue && !refValue.contains(event.target)) {
10
+ callback(event);
11
+ }
12
+ };
13
+ document.addEventListener("mousedown", handleClickOutside);
14
+ return () => {
15
+ document.removeEventListener("mousedown", handleClickOutside);
16
+ };
17
+ }, [callback, refOrElement]);
18
+ }
19
+ exports.useOnElementClickOutsideCallback = useOnElementClickOutsideCallback;
20
+ //# sourceMappingURL=useOnElementClickOutsideCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementClickOutsideCallback.cjs","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":["useEffect","unwrapRefValue"],"mappings":";;;;AAGgB,SAAA,iCACf,cACA,UACO;AACPA,QAAAA,UAAU,MAAM;AACT,UAAA,WAAWC,8BAAe,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
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
5
+ function useOnElementMouseEnterDelayedCallback(refOrElement, callback, timeoutMs = 300) {
6
+ react.useEffect(() => {
7
+ const refValue = unwrapRefValue.unwrapRefValue(refOrElement);
8
+ if (refValue) {
9
+ let handleMouseEnter = function(event) {
10
+ clearTimeout(timeoutID);
11
+ timeoutID = setTimeout(() => {
12
+ callback(event);
13
+ }, timeoutMs);
14
+ }, handleMouseLeave = function() {
15
+ clearTimeout(timeoutID);
16
+ }, handleMouseDown = function(event) {
17
+ clearTimeout(timeoutID);
18
+ callback(event);
19
+ };
20
+ let timeoutID = void 0;
21
+ refValue.addEventListener("mouseenter", handleMouseEnter);
22
+ refValue.addEventListener("mouseleave", handleMouseLeave);
23
+ refValue.addEventListener("mousedown", handleMouseDown);
24
+ return () => {
25
+ refValue.removeEventListener("mouseover", handleMouseEnter);
26
+ refValue.removeEventListener("mouseleave", handleMouseLeave);
27
+ refValue.removeEventListener("mousedown", handleMouseDown);
28
+ };
29
+ }
30
+ }, [callback, refOrElement, timeoutMs]);
31
+ }
32
+ exports.useOnElementMouseEnterDelayedCallback = useOnElementMouseEnterDelayedCallback;
33
+ //# sourceMappingURL=useOnElementMouseEnterDelayedCallback.cjs.map