@contember/react-utils 1.2.6 → 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,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,24 @@
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
+ {
9
+ console.error(
10
+ "Previous and next values do not match in reference although match in value. Try declaring constants outside of the component scope. Otherwise try to memoize callbacks with useCallback, useReferentiallyStableCallback useEvent, useRef or useMemo.",
11
+ {
12
+ previous: previous.current,
13
+ next
14
+ }
15
+ );
16
+ }
17
+ if (shouldThrow) {
18
+ throw new Error("Expecting same reference for same values");
19
+ }
20
+ }
21
+ previous.current = next;
22
+ }
23
+ exports.useExpectSameValueReference = useExpectSameValueReference;
24
+ //# 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;AACwB;AAChB,cAAA;AAAA,QACP;AAAA,QAG+D;AAAA,UAC/D,UAAU,SAAS;AAAA,UACnB;AAAA,QACD;AAAA,MAAA;AAAA,IACD;AAEA,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementMouseEnterDelayedCallback.cjs","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":["useEffect","unwrapRefValue"],"mappings":";;;;AAcO,SAAS,sCACf,cACA,UACA,YAAoB,KACb;AACPA,QAAAA,UAAU,MAAM;AACT,UAAA,WAAWC,8BAAe,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;;"}
@@ -0,0 +1,35 @@
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
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
6
+ const Context = require("../debug-context/Context.cjs");
7
+ function useOnElementMutation(refOrElement, callback, options = { attributes: true, childList: true, subtree: true }) {
8
+ const scopedConsoleRef = Context.useScopedConsoleRef("useOnElementMutation");
9
+ const callbackRef = react.useRef(callback);
10
+ callbackRef.current = callback;
11
+ const optionsRef = react.useRef(options);
12
+ optionsRef.current = options;
13
+ const [optionsState, setOptionsState] = react.useState(options);
14
+ react.useEffect(() => {
15
+ if (!deepEqual(optionsRef.current, options)) {
16
+ setOptionsState(options);
17
+ }
18
+ }, [options]);
19
+ react.useLayoutEffect(() => {
20
+ const element = unwrapRefValue.unwrapRefValue(refOrElement);
21
+ if (element) {
22
+ let handler = function(mutations, observer2) {
23
+ scopedConsoleRef.current.logged("element.mutations", mutations);
24
+ callbackRef.current(mutations, observer2);
25
+ };
26
+ const observer = new MutationObserver(handler);
27
+ observer.observe(element, optionsState);
28
+ return () => {
29
+ observer.disconnect();
30
+ };
31
+ }
32
+ }, [optionsState, refOrElement, scopedConsoleRef]);
33
+ }
34
+ exports.useOnElementMutation = useOnElementMutation;
35
+ //# sourceMappingURL=useOnElementMutation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementMutation.cjs","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":["useScopedConsoleRef","useRef","useState","useEffect","useLayoutEffect","unwrapRefValue","observer"],"mappings":";;;;;;AAKgB,SAAA,qBACf,cACA,UACA,UAAgC,EAAE,YAAY,MAAM,WAAW,MAAM,SAAS,KAAA,GAC7E;AACK,QAAA,mBAAmBA,4BAAoB,sBAAsB;AAE7D,QAAA,cAAcC,aAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,aAAaA,aAA6B,OAAO;AAAG,aAAW,UAAU;AAE/E,QAAM,CAAC,cAAc,eAAe,IAAIC,eAA+B,OAAO;AAE9EC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,UAAU,WAAW,SAAS,OAAO,GAAG;AAC5C,sBAAgB,OAAO;AAAA,IACxB;AAAA,EAAA,GACE,CAAC,OAAO,CAAC;AAEZC,QAAAA,gBAAgB,MAAM;AACf,UAAA,UAAUC,8BAAe,YAAY;AAE3C,QAAI,SAAS;AACH,UAAA,UAAT,SAAiB,WAA6BC,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;;"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
5
+ const Context = require("../debug-context/Context.cjs");
6
+ function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
7
+ const scopedConsoleRef = Context.useScopedConsoleRef("useOnElementResize");
8
+ const { box = "border-box" } = options;
9
+ const callbackRef = react.useRef(callback);
10
+ callbackRef.current = callback;
11
+ const lastTimeStamp = react.useRef(0);
12
+ react.useLayoutEffect(() => {
13
+ const element = unwrapRefValue.unwrapRefValue(refOrElement);
14
+ if (!element) {
15
+ return;
16
+ }
17
+ if (!(element instanceof HTMLElement)) {
18
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
19
+ }
20
+ let timeoutID = void 0;
21
+ function debouncedOnChange([entry]) {
22
+ const timeStamp = Date.now();
23
+ const delta = timeStamp - lastTimeStamp.current;
24
+ clearTimeout(timeoutID);
25
+ const timeoutFinal = delta > timeout ? 0 : timeout;
26
+ timeoutID = setTimeout(() => {
27
+ const message = timeoutFinal > 0 ? "element.resize:debounced" : "element.resize:immediate";
28
+ scopedConsoleRef.current.warned(message, null);
29
+ callbackRef.current(entry);
30
+ lastTimeStamp.current = timeStamp;
31
+ }, timeoutFinal);
32
+ }
33
+ const resizeObserver = new ResizeObserver(debouncedOnChange);
34
+ resizeObserver.observe(element, { box });
35
+ return () => {
36
+ clearTimeout(timeoutID);
37
+ resizeObserver.unobserve(element);
38
+ };
39
+ }, [box, refOrElement, scopedConsoleRef, timeout]);
40
+ }
41
+ exports.useOnElementResize = useOnElementResize;
42
+ //# sourceMappingURL=useOnElementResize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementResize.cjs","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\t\tif (!element) {\n\t\t\treturn\n\t\t}\n\t\tif (!(element instanceof HTMLElement)) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\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\tclearTimeout(timeoutID)\n\t\t\tconst timeoutFinal = delta > timeout ? 0 : timeout\n\n\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\tconst message = timeoutFinal > 0 ? 'element.resize:debounced' : 'element.resize:immediate'\n\t\t\t\tscopedConsoleRef.current.warned(message, null)\n\t\t\t\tcallbackRef.current(entry)\n\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t}, timeoutFinal)\n\t\t}\n\n\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\tresizeObserver.observe(element, { box })\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\tresizeObserver.unobserve(element)\n\t\t}\n\t}, [box, refOrElement, scopedConsoleRef, timeout])\n}\n"],"names":["useScopedConsoleRef","useRef","useLayoutEffect","unwrapRefValue"],"mappings":";;;;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAC,GAClC,UAAkB,KACX;AACD,QAAA,mBAAmBA,4BAAoB,oBAAoB;AAE3D,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,cAAcC,aAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgBA,aAAe,CAAC;AAEtCC,QAAAA,gBAAgB,MAAM;AACf,UAAA,UAAUC,8BAAe,YAAY;AAC3C,QAAI,CAAC,SAAS;AACb;AAAA,IACD;AACI,QAAA,EAAE,mBAAmB,cAAc;AAChC,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAEA,QAAI,YAAgC;AAE3B,aAAA,kBAAkB,CAAC,KAAK,GAA0B;AACpD,YAAA,YAAY,KAAK;AACjB,YAAA,QAAQ,YAAY,cAAc;AAExC,mBAAa,SAAS;AAChB,YAAA,eAAe,QAAQ,UAAU,IAAI;AAE3C,kBAAY,WAAW,MAAM;AACtB,cAAA,UAAU,eAAe,IAAI,6BAA6B;AAC/C,yBAAA,QAAQ,OAAO,SAAS,IAAI;AAC7C,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU;AAAA,SACtB,YAAY;AAAA,IAChB;AAEM,UAAA,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,mBAAe,QAAQ,SAAS,EAAE,IAAK,CAAA;AAEvC,WAAO,MAAM;AACZ,mBAAa,SAAS;AACtB,qBAAe,UAAU,OAAO;AAAA,IAAA;AAAA,KAE/B,CAAC,KAAK,cAAc,kBAAkB,OAAO,CAAC;AAClD;;"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
5
+ const Context = require("../debug-context/Context.cjs");
6
+ function useOnScrollWithin(refOrElement, callback, interval = 1e3 / 60) {
7
+ const scopedConsoleRef = Context.useScopedConsoleRef("useOnScrollWithin");
8
+ const callbackRef = react.useRef(callback);
9
+ callbackRef.current = callback;
10
+ const lastTimeStamp = react.useRef(0);
11
+ react.useLayoutEffect(() => {
12
+ const element = unwrapRefValue.unwrapRefValue(refOrElement);
13
+ let timeoutID = void 0;
14
+ if (element) {
15
+ let debouncedHandler = function(event) {
16
+ clearTimeout(timeoutID);
17
+ const delta = event.timeStamp - lastTimeStamp.current;
18
+ scopedConsoleRef.current.logged("event:element.scroll:delta", delta);
19
+ if (delta > interval) {
20
+ scopedConsoleRef.current.warned("event:element.scroll:immediately", event);
21
+ callbackRef.current(event);
22
+ lastTimeStamp.current = event.timeStamp;
23
+ } else {
24
+ timeoutID = setTimeout(() => {
25
+ scopedConsoleRef.current.warned("event:element.scroll:debounced", event);
26
+ lastTimeStamp.current = event.timeStamp;
27
+ callbackRef.current(event);
28
+ }, interval);
29
+ }
30
+ };
31
+ if (element instanceof HTMLElement) {
32
+ if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
33
+ window.addEventListener("scroll", debouncedHandler, { capture: true, passive: true });
34
+ window.addEventListener("resize", debouncedHandler);
35
+ return () => {
36
+ window.removeEventListener("scroll", debouncedHandler);
37
+ window.removeEventListener("resize", debouncedHandler);
38
+ };
39
+ } else {
40
+ element.addEventListener("scroll", debouncedHandler, { passive: true, capture: true });
41
+ return () => {
42
+ element.removeEventListener("scroll", debouncedHandler);
43
+ };
44
+ }
45
+ } else {
46
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
47
+ }
48
+ }
49
+ }, [interval, refOrElement, scopedConsoleRef]);
50
+ }
51
+ exports.useOnScrollWithin = useOnScrollWithin;
52
+ //# sourceMappingURL=useOnScrollWithin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnScrollWithin.cjs","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":["useScopedConsoleRef","useRef","useLayoutEffect","unwrapRefValue"],"mappings":";;;;;AAWO,SAAS,kBACf,cACA,UACA,WAAmB,MAAO,IACzB;AACK,QAAA,mBAAmBA,4BAAoB,mBAAmB;AAE1D,QAAA,cAAcC,aAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgBA,aAAe,CAAC;AAEtCC,QAAAA,gBAAgB,MAAM;AACf,UAAA,UAAUC,8BAAe,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;;"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const Context = require("../debug-context/Context.cjs");
5
+ function useOnWindowResize(callback, interval = 300) {
6
+ const scopedConsoleRef = Context.useScopedConsoleRef("useOnWindowResize");
7
+ const callbackRef = react.useRef(callback);
8
+ callbackRef.current = callback;
9
+ const lastTimeStamp = react.useRef(0);
10
+ react.useLayoutEffect(() => {
11
+ let timeoutID = void 0;
12
+ function debouncedHandler(event) {
13
+ clearTimeout(timeoutID);
14
+ const delta = event.timeStamp - lastTimeStamp.current;
15
+ scopedConsoleRef.current.logged("window.resize:delta", delta);
16
+ if (delta > interval) {
17
+ scopedConsoleRef.current.warned("event:window.resize:immediately", null);
18
+ callbackRef.current(event);
19
+ lastTimeStamp.current = event.timeStamp;
20
+ } else {
21
+ timeoutID = setTimeout(() => {
22
+ scopedConsoleRef.current.warned("event:window.resize:debounced", null);
23
+ lastTimeStamp.current = event.timeStamp;
24
+ callbackRef.current(event);
25
+ }, interval);
26
+ }
27
+ }
28
+ window.addEventListener("resize", debouncedHandler);
29
+ return () => {
30
+ clearTimeout(timeoutID);
31
+ window.removeEventListener("resize", debouncedHandler);
32
+ };
33
+ }, [callbackRef, interval, scopedConsoleRef]);
34
+ }
35
+ exports.useOnWindowResize = useOnWindowResize;
36
+ //# sourceMappingURL=useOnWindowResize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnWindowResize.cjs","sources":["../../../src/hooks/useOnWindowResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\n\nexport function useOnWindowResize(\n\tcallback: (event: Event) => void,\n\tinterval: number = 300,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnWindowResize')\n\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 debouncedHandler(event: Event) {\n\t\t\tclearTimeout(timeoutID)\n\n\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\tscopedConsoleRef.current.logged('window.resize:delta', delta)\n\n\t\t\tif (delta > interval) {\n\t\t\t\tscopedConsoleRef.current.warned('event:window.resize:immediately', null)\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:window.resize:debounced', null)\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\twindow.addEventListener('resize', debouncedHandler)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID)\n\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t}\n\t}, [callbackRef, interval, scopedConsoleRef])\n}\n"],"names":["useScopedConsoleRef","useRef","useLayoutEffect"],"mappings":";;;;AAGgB,SAAA,kBACf,UACA,WAAmB,KAClB;AACK,QAAA,mBAAmBA,4BAAoB,mBAAmB;AAE1D,QAAA,cAAcC,aAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgBA,aAAe,CAAC;AAEtCC,QAAAA,gBAAgB,MAAM;AACrB,QAAI,YAAgC;AAEpC,aAAS,iBAAiB,OAAc;AACvC,mBAAa,SAAS;AAEhB,YAAA,QAAQ,MAAM,YAAY,cAAc;AAC7B,uBAAA,QAAQ,OAAO,uBAAuB,KAAK;AAE5D,UAAI,QAAQ,UAAU;AACJ,yBAAA,QAAQ,OAAO,mCAAmC,IAAI;AACvE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU,MAAM;AAAA,MAAA,OACxB;AACN,oBAAY,WAAW,MAAM;AACX,2BAAA,QAAQ,OAAO,iCAAiC,IAAI;AACrE,wBAAc,UAAU,MAAM;AAC9B,sBAAY,QAAQ,KAAK;AAAA,WACvB,QAAQ;AAAA,MACZ;AAAA,IACD;AAEO,WAAA,iBAAiB,UAAU,gBAAgB;AAElD,WAAO,MAAM;AACZ,mBAAa,SAAS;AACf,aAAA,oBAAoB,UAAU,gBAAgB;AAAA,IAAA;AAAA,EAEpD,GAAA,CAAC,aAAa,UAAU,gBAAgB,CAAC;AAC7C;;"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const usePreviousValue = (value) => {
5
+ const ref = react.useRef(value);
6
+ react.useEffect(() => {
7
+ ref.current = value;
8
+ });
9
+ return ref.current;
10
+ };
11
+ exports.usePreviousValue = usePreviousValue;
12
+ //# sourceMappingURL=usePreviousValue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePreviousValue.cjs","sources":["../../../src/hooks/usePreviousValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport const usePreviousValue = <Value>(value: Value) => {\n\tconst ref = useRef<Value>(value)\n\tuseEffect(() => {\n\t\tref.current = value\n\t})\n\treturn ref.current\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AAEa,MAAA,mBAAmB,CAAQ,UAAiB;AAClD,QAAA,MAAMA,aAAc,KAAK;AAC/BC,QAAAA,UAAU,MAAM;AACf,QAAI,UAAU;AAAA,EAAA,CACd;AACD,SAAO,IAAI;AACZ;;"}
@@ -0,0 +1,67 @@
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 useOnScrollWithin = require("./useOnScrollWithin.cjs");
7
+ const useOnWindowResize = require("./useOnWindowResize.cjs");
8
+ const Context = require("../debug-context/Context.cjs");
9
+ const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
10
+ function useScrollOffsets(refOrElement, interval = 1e3 / 60) {
11
+ const { logged } = Context.useScopedConsoleRef("useScrollOffsets").current;
12
+ const [top, setTop] = react.useState(0);
13
+ const [bottom, setBottom] = react.useState(0);
14
+ const [left, setLeft] = react.useState(0);
15
+ const [right, setRight] = react.useState(0);
16
+ const updateScrollOffsetsState = useReferentiallyStableCallback.useReferentiallyStableCallback((offsets) => {
17
+ logged("Update the offsets:", {
18
+ previous: { bottom, left, right, top },
19
+ next: offsets
20
+ });
21
+ if (offsets.bottom !== bottom)
22
+ setBottom(offsets.bottom);
23
+ if (offsets.left !== left)
24
+ setLeft(offsets.left);
25
+ if (offsets.right !== right)
26
+ setRight(offsets.right);
27
+ if (offsets.top !== top)
28
+ setTop(offsets.top);
29
+ });
30
+ const handler = useReferentiallyStableCallback.useReferentiallyStableCallback(() => {
31
+ const maybeScrollContent = unwrapRefValue.unwrapRefValue(refOrElement) ?? document;
32
+ if (maybeScrollContent) {
33
+ getElementScrollOffsets(maybeScrollContent).then(updateScrollOffsetsState);
34
+ }
35
+ });
36
+ useOnScrollWithin.useOnScrollWithin(refOrElement, handler, interval);
37
+ useOnWindowResize.useOnWindowResize(handler);
38
+ react.useLayoutEffect(handler, [handler]);
39
+ return react.useMemo(() => ({ bottom, left, right, top }), [bottom, left, right, top]);
40
+ }
41
+ function isIntrinsicScrollElement(element) {
42
+ return element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement || element instanceof DocumentType || element instanceof Document || element instanceof HTMLDocument;
43
+ }
44
+ function getIntrinsicScrollContainer(element) {
45
+ const html = document.body.parentElement;
46
+ utilities.assert("HTML element exists", html, (value) => value instanceof HTMLElement);
47
+ if (isIntrinsicScrollElement(element)) {
48
+ return html;
49
+ } else {
50
+ return element;
51
+ }
52
+ }
53
+ async function getElementScrollOffsets(element) {
54
+ const isIntrinsicScrolling = isIntrinsicScrollElement(element);
55
+ const scrollContainer = getIntrinsicScrollContainer(element);
56
+ const { scrollLeft, scrollTop, scrollHeight, scrollWidth } = scrollContainer;
57
+ const { height: scrollContainerHeight, width: scrollContainerWidth } = await utilities.getElementDimensions(scrollContainer);
58
+ const height = isIntrinsicScrolling ? window.innerHeight : scrollContainerHeight;
59
+ const width = isIntrinsicScrolling ? window.innerWidth : scrollContainerWidth;
60
+ const left = Math.round(scrollLeft);
61
+ const top = Math.round(scrollTop);
62
+ const right = Math.round(scrollWidth - width - left);
63
+ const bottom = Math.round(scrollHeight - height - top);
64
+ return { bottom, left, right, top };
65
+ }
66
+ exports.useScrollOffsets = useScrollOffsets;
67
+ //# sourceMappingURL=useScrollOffsets.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollOffsets.cjs","sources":["../../../src/hooks/useScrollOffsets.ts"],"sourcesContent":["import { assert, getElementDimensions } from '@contember/utilities'\nimport { useLayoutEffect, useMemo, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnScrollWithin } from './useOnScrollWithin'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nexport type Offsets = {\n\tbottom: number;\n\tleft: number;\n\tright: number;\n\ttop: number;\n}\n\nexport function useScrollOffsets(refOrElement: RefObjectOrElement<HTMLElement | null> | null, interval: number = 1000 / 60) {\n\tconst { logged } = useScopedConsoleRef('useScrollOffsets').current\n\n\tconst [top, setTop] = useState(0)\n\tconst [bottom, setBottom] = useState(0)\n\tconst [left, setLeft] = useState(0)\n\tconst [right, setRight] = useState(0)\n\n\tconst updateScrollOffsetsState = useReferentiallyStableCallback((offsets: Offsets) => {\n\t\tlogged('Update the offsets:', {\n\t\t\tprevious: { bottom, left, right, top },\n\t\t\tnext: offsets,\n\t\t})\n\n\t\tif (offsets.bottom !== bottom) setBottom(offsets.bottom)\n\t\tif (offsets.left !== left) setLeft(offsets.left)\n\t\tif (offsets.right !== right) setRight(offsets.right)\n\t\tif (offsets.top !== top) setTop(offsets.top)\n\t})\n\n\tconst handler = useReferentiallyStableCallback(() => {\n\t\tconst maybeScrollContent = unwrapRefValue(refOrElement) ?? document\n\n\t\tif (maybeScrollContent) {\n\t\t\tgetElementScrollOffsets(maybeScrollContent).then(updateScrollOffsetsState)\n\t\t}\n\t})\n\n\tuseOnScrollWithin(refOrElement, handler, interval)\n\tuseOnWindowResize(handler)\n\tuseLayoutEffect(handler, [handler])\n\n\treturn useMemo(() => ({ bottom, left, right, top }), [bottom, left, right, top])\n}\n\nfunction isIntrinsicScrollElement(element: unknown): element is Document {\n\treturn element instanceof HTMLBodyElement\n\t\t|| element instanceof HTMLHtmlElement\n\t\t|| element instanceof DocumentType\n\t\t|| element instanceof Document\n\t\t|| element instanceof HTMLDocument\n}\n\nfunction getIntrinsicScrollContainer(element: HTMLElement | Document): HTMLElement {\n\tconst html = document.body.parentElement\n\tassert('HTML element exists', html, (value): value is HTMLElement => value instanceof HTMLElement)\n\n\tif (isIntrinsicScrollElement(element)) {\n\t\treturn html\n\t} else {\n\t\treturn element\n\t}\n}\n\nasync function getElementScrollOffsets(element: HTMLElement | Document): Promise<Offsets> {\n\tconst isIntrinsicScrolling = isIntrinsicScrollElement(element)\n\tconst scrollContainer = getIntrinsicScrollContainer(element)\n\n\tconst { scrollLeft, scrollTop, scrollHeight, scrollWidth } = scrollContainer\n\tconst { height: scrollContainerHeight, width: scrollContainerWidth } = await getElementDimensions(scrollContainer)\n\n\tconst height = isIntrinsicScrolling ? window.innerHeight : scrollContainerHeight\n\tconst width = isIntrinsicScrolling ? window.innerWidth : scrollContainerWidth\n\n\tconst left = Math.round(scrollLeft)\n\tconst top = Math.round(scrollTop)\n\n\tconst right = Math.round(scrollWidth - width - left)\n\tconst bottom = Math.round(scrollHeight - height - top)\n\n\treturn { bottom, left, right, top }\n}\n"],"names":["useScopedConsoleRef","useState","useReferentiallyStableCallback","unwrapRefValue","useOnScrollWithin","useOnWindowResize","useLayoutEffect","useMemo","assert","getElementDimensions"],"mappings":";;;;;;;;;AAeO,SAAS,iBAAiB,cAA6D,WAAmB,MAAO,IAAI;AAC3H,QAAM,EAAE,OAAW,IAAAA,QAAA,oBAAoB,kBAAkB,EAAE;AAE3D,QAAM,CAAC,KAAK,MAAM,IAAIC,eAAS,CAAC;AAChC,QAAM,CAAC,QAAQ,SAAS,IAAIA,eAAS,CAAC;AACtC,QAAM,CAAC,MAAM,OAAO,IAAIA,eAAS,CAAC;AAClC,QAAM,CAAC,OAAO,QAAQ,IAAIA,eAAS,CAAC;AAE9B,QAAA,2BAA2BC,8DAA+B,CAAC,YAAqB;AACrF,WAAO,uBAAuB;AAAA,MAC7B,UAAU,EAAE,QAAQ,MAAM,OAAO,IAAI;AAAA,MACrC,MAAM;AAAA,IAAA,CACN;AAED,QAAI,QAAQ,WAAW;AAAQ,gBAAU,QAAQ,MAAM;AACvD,QAAI,QAAQ,SAAS;AAAM,cAAQ,QAAQ,IAAI;AAC/C,QAAI,QAAQ,UAAU;AAAO,eAAS,QAAQ,KAAK;AACnD,QAAI,QAAQ,QAAQ;AAAK,aAAO,QAAQ,GAAG;AAAA,EAAA,CAC3C;AAEK,QAAA,UAAUA,+BAAAA,+BAA+B,MAAM;AAC9C,UAAA,qBAAqBC,eAAAA,eAAe,YAAY,KAAK;AAE3D,QAAI,oBAAoB;AACC,8BAAA,kBAAkB,EAAE,KAAK,wBAAwB;AAAA,IAC1E;AAAA,EAAA,CACA;AAEiBC,oBAAAA,kBAAA,cAAc,SAAS,QAAQ;AACjDC,oBAAA,kBAAkB,OAAO;AACTC,QAAAA,gBAAA,SAAS,CAAC,OAAO,CAAC;AAElC,SAAOC,MAAQ,QAAA,OAAO,EAAE,QAAQ,MAAM,OAAO,QAAQ,CAAC,QAAQ,MAAM,OAAO,GAAG,CAAC;AAChF;AAEA,SAAS,yBAAyB,SAAuC;AACjE,SAAA,mBAAmB,mBACtB,mBAAmB,mBACnB,mBAAmB,gBACnB,mBAAmB,YACnB,mBAAmB;AACxB;AAEA,SAAS,4BAA4B,SAA8C;AAC5E,QAAA,OAAO,SAAS,KAAK;AAC3BC,YAAA,OAAO,uBAAuB,MAAM,CAAC,UAAgC,iBAAiB,WAAW;AAE7F,MAAA,yBAAyB,OAAO,GAAG;AAC/B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;AAEA,eAAe,wBAAwB,SAAmD;AACnF,QAAA,uBAAuB,yBAAyB,OAAO;AACvD,QAAA,kBAAkB,4BAA4B,OAAO;AAE3D,QAAM,EAAE,YAAY,WAAW,cAAc,gBAAgB;AACvD,QAAA,EAAE,QAAQ,uBAAuB,OAAO,yBAAyB,MAAMC,UAAAA,qBAAqB,eAAe;AAE3G,QAAA,SAAS,uBAAuB,OAAO,cAAc;AACrD,QAAA,QAAQ,uBAAuB,OAAO,aAAa;AAEnD,QAAA,OAAO,KAAK,MAAM,UAAU;AAC5B,QAAA,MAAM,KAAK,MAAM,SAAS;AAEhC,QAAM,QAAQ,KAAK,MAAM,cAAc,QAAQ,IAAI;AACnD,QAAM,SAAS,KAAK,MAAM,eAAe,SAAS,GAAG;AAErD,SAAO,EAAE,QAAQ,MAAM,OAAO,IAAI;AACnC;;"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const createStoredStateHook = (getStorage) => {
5
+ return (key, initializeValue) => {
6
+ const storage = getStorage();
7
+ const [value, setValue] = react.useState(() => {
8
+ const value2 = storage.getItem(key);
9
+ const parsedValue = value2 !== null ? JSON.parse(value2) : void 0;
10
+ return initializeValue(parsedValue);
11
+ });
12
+ return [value, react.useCallback((value2) => {
13
+ setValue((current) => {
14
+ const newValue = typeof value2 === "function" ? value2(current) : value2;
15
+ storage.setItem(key, JSON.stringify(newValue));
16
+ return newValue;
17
+ });
18
+ }, [key, storage])];
19
+ };
20
+ };
21
+ const useSessionStorageState = createStoredStateHook(() => sessionStorage);
22
+ exports.useSessionStorageState = useSessionStorageState;
23
+ //# sourceMappingURL=useStoredState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStoredState.cjs","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nconst createStoredStateHook = (getStorage: () => Storage) => {\n\treturn <V extends Serializable>(key: string, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\t\tconst storage = getStorage()\n\t\tconst [value, setValue] = useState<V>(() => {\n\t\t\tconst value = storage.getItem(key)\n\t\t\tconst parsedValue: V | undefined = value !== null ? JSON.parse(value) : undefined\n\t\t\treturn initializeValue(parsedValue)\n\t\t})\n\t\treturn [value, useCallback(value => {\n\t\t\tsetValue(current => {\n\t\t\t\tconst newValue = typeof value === 'function' ? (value as (current: V) => V)(current) : value\n\t\t\t\tstorage.setItem(key, JSON.stringify(newValue))\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage])]\n\t}\n\n}\n\nexport const useSessionStorageState = createStoredStateHook(() => sessionStorage)\n"],"names":["useState","value","useCallback"],"mappings":";;;AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAIA,eAAY,MAAM;AACrCC,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAOC,kBAAY,CAAAD,WAAS;AACnC,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AACvF,gBAAQ,QAAQ,KAAK,KAAK,UAAU,QAAQ,CAAC;AACtC,eAAA;AAAA,MAAA,CACP;AAAA,IACC,GAAA,CAAC,KAAK,OAAO,CAAC,CAAC;AAAA,EAAA;AAGpB;AAEa,MAAA,yBAAyB,sBAAsB,MAAM,cAAc;;"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function useUpdatedRef(value) {
5
+ const ref = react.useRef(value);
6
+ ref.current = value;
7
+ return ref;
8
+ }
9
+ exports.useUpdatedRef = useUpdatedRef;
10
+ //# sourceMappingURL=useUpdatedRef.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUpdatedRef.cjs","sources":["../../../src/hooks/useUpdatedRef.ts"],"sourcesContent":["import { useRef } from 'react'\n\n/**\n * Returns a stable mutable object with value that is updated upon each call\n *\n * @param value - Value that could update after initial call\n * @returns Mutable ref object with updated value\n */\nexport function useUpdatedRef<T>(value: T) {\n\tconst ref = useRef(value)\n\tref.current = value\n\n\treturn ref\n}\n"],"names":["useRef"],"mappings":";;;AAQO,SAAS,cAAiB,OAAU;AACpC,QAAA,MAAMA,aAAO,KAAK;AACxB,MAAI,UAAU;AAEP,SAAA;AACR;;"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useOnWindowResize = require("./useOnWindowResize.cjs");
5
+ function useWindowSize() {
6
+ const [width, setWidth] = react.useState(window.innerWidth);
7
+ const [height, setHeight] = react.useState(window.innerHeight);
8
+ useOnWindowResize.useOnWindowResize(() => {
9
+ const { innerHeight, innerWidth } = window;
10
+ if (innerHeight !== height) {
11
+ setHeight(innerHeight);
12
+ }
13
+ if (innerWidth !== width) {
14
+ setWidth(innerWidth);
15
+ }
16
+ });
17
+ return react.useMemo(() => ({ height, width }), [height, width]);
18
+ }
19
+ exports.useWindowSize = useWindowSize;
20
+ //# sourceMappingURL=useWindowSize.cjs.map