@contember/react-utils 1.1.0 → 1.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/dist/development/context/createNonNullableContextFactory.js +17 -0
  2. package/dist/development/context/createNonNullableContextFactory.js.map +1 -0
  3. package/dist/development/debug-context/Constants.js +25 -0
  4. package/dist/development/debug-context/Constants.js.map +1 -0
  5. package/dist/development/debug-context/Context.js +67 -0
  6. package/dist/development/debug-context/Context.js.map +1 -0
  7. package/dist/development/hooks/unwrapRefValue.js +11 -0
  8. package/dist/development/hooks/unwrapRefValue.js.map +1 -0
  9. package/dist/development/hooks/useAddClassNameDuringResize.js +34 -0
  10. package/dist/development/hooks/useAddClassNameDuringResize.js.map +1 -0
  11. package/dist/development/hooks/useArrayMapMemo.js +0 -2
  12. package/dist/development/hooks/useArrayMapMemo.js.map +1 -1
  13. package/dist/development/hooks/useComposeRef.js +31 -0
  14. package/dist/development/hooks/useComposeRef.js.map +1 -0
  15. package/dist/development/hooks/useConstantLengthInvariant.js +0 -9
  16. package/dist/development/hooks/useConstantLengthInvariant.js.map +1 -1
  17. package/dist/development/hooks/useConstantValueInvariant.js +0 -9
  18. package/dist/development/hooks/useConstantValueInvariant.js.map +1 -1
  19. package/dist/development/hooks/useCountLayoutSlotChildren.js +31 -0
  20. package/dist/development/hooks/useCountLayoutSlotChildren.js.map +1 -0
  21. package/dist/development/hooks/useDebounceCallback.js +1 -1
  22. package/dist/development/hooks/useDebounceCallback.js.map +1 -1
  23. package/dist/development/hooks/useElementSize.js +47 -0
  24. package/dist/development/hooks/useElementSize.js.map +1 -0
  25. package/dist/development/hooks/useEventHandler.js +19 -0
  26. package/dist/development/hooks/useEventHandler.js.map +1 -0
  27. package/dist/development/hooks/useExpectSameValueReference.js +15 -0
  28. package/dist/development/hooks/useExpectSameValueReference.js.map +1 -0
  29. package/dist/development/hooks/useObjectMemo.js.map +1 -1
  30. package/dist/development/hooks/useOnElementMutation.js +35 -0
  31. package/dist/development/hooks/useOnElementMutation.js.map +1 -0
  32. package/dist/development/hooks/useOnElementResize.js +44 -0
  33. package/dist/development/hooks/useOnElementResize.js.map +1 -0
  34. package/dist/development/hooks/useOnScrollWithin.js +50 -0
  35. package/dist/development/hooks/useOnScrollWithin.js.map +1 -0
  36. package/dist/development/hooks/useOnWindowResize.js +36 -0
  37. package/dist/development/hooks/useOnWindowResize.js.map +1 -0
  38. package/dist/development/hooks/useScrollOffsets.js +68 -0
  39. package/dist/development/hooks/useScrollOffsets.js.map +1 -0
  40. package/dist/development/hooks/useStoredState.js.map +1 -1
  41. package/dist/development/hooks/useUpdatedRef.js +10 -0
  42. package/dist/development/hooks/useUpdatedRef.js.map +1 -0
  43. package/dist/development/hooks/useWindowSize.js +20 -0
  44. package/dist/development/hooks/useWindowSize.js.map +1 -0
  45. package/dist/development/index.js +41 -1
  46. package/dist/development/index.js.map +1 -1
  47. package/dist/development/referentiallyStable/useReferentiallyStableCallback.js +12 -0
  48. package/dist/development/referentiallyStable/useReferentiallyStableCallback.js.map +1 -0
  49. package/dist/production/context/createNonNullableContextFactory.js +17 -0
  50. package/dist/production/context/createNonNullableContextFactory.js.map +1 -0
  51. package/dist/production/debug-context/Constants.js +25 -0
  52. package/dist/production/debug-context/Constants.js.map +1 -0
  53. package/dist/production/debug-context/Context.js +67 -0
  54. package/dist/production/debug-context/Context.js.map +1 -0
  55. package/dist/production/hooks/unwrapRefValue.js +11 -0
  56. package/dist/production/hooks/unwrapRefValue.js.map +1 -0
  57. package/dist/production/hooks/useAddClassNameDuringResize.js +34 -0
  58. package/dist/production/hooks/useAddClassNameDuringResize.js.map +1 -0
  59. package/dist/production/hooks/useComposeRef.js +31 -0
  60. package/dist/production/hooks/useComposeRef.js.map +1 -0
  61. package/dist/production/hooks/useCountLayoutSlotChildren.js +31 -0
  62. package/dist/production/hooks/useCountLayoutSlotChildren.js.map +1 -0
  63. package/dist/production/hooks/useDebounceCallback.js +1 -1
  64. package/dist/production/hooks/useDebounceCallback.js.map +1 -1
  65. package/dist/production/hooks/useElementSize.js +47 -0
  66. package/dist/production/hooks/useElementSize.js.map +1 -0
  67. package/dist/production/hooks/useEventHandler.js +19 -0
  68. package/dist/production/hooks/useEventHandler.js.map +1 -0
  69. package/dist/production/hooks/useExpectSameValueReference.js +15 -0
  70. package/dist/production/hooks/useExpectSameValueReference.js.map +1 -0
  71. package/dist/production/hooks/useObjectMemo.js.map +1 -1
  72. package/dist/production/hooks/useOnElementMutation.js +35 -0
  73. package/dist/production/hooks/useOnElementMutation.js.map +1 -0
  74. package/dist/production/hooks/useOnElementResize.js +44 -0
  75. package/dist/production/hooks/useOnElementResize.js.map +1 -0
  76. package/dist/production/hooks/useOnScrollWithin.js +50 -0
  77. package/dist/production/hooks/useOnScrollWithin.js.map +1 -0
  78. package/dist/production/hooks/useOnWindowResize.js +36 -0
  79. package/dist/production/hooks/useOnWindowResize.js.map +1 -0
  80. package/dist/production/hooks/useScrollOffsets.js +68 -0
  81. package/dist/production/hooks/useScrollOffsets.js.map +1 -0
  82. package/dist/production/hooks/useStoredState.js.map +1 -1
  83. package/dist/production/hooks/useUpdatedRef.js +10 -0
  84. package/dist/production/hooks/useUpdatedRef.js.map +1 -0
  85. package/dist/production/hooks/useWindowSize.js +20 -0
  86. package/dist/production/hooks/useWindowSize.js.map +1 -0
  87. package/dist/production/index.js +41 -1
  88. package/dist/production/index.js.map +1 -1
  89. package/dist/production/referentiallyStable/useReferentiallyStableCallback.js +12 -0
  90. package/dist/production/referentiallyStable/useReferentiallyStableCallback.js.map +1 -0
  91. package/dist/types/context/createNonNullableContextFactory.d.ts +3 -0
  92. package/dist/types/context/createNonNullableContextFactory.d.ts.map +1 -0
  93. package/dist/types/context/index.d.ts +2 -0
  94. package/dist/types/context/index.d.ts.map +1 -0
  95. package/dist/types/debug-context/Constants.d.ts +6 -0
  96. package/dist/types/debug-context/Constants.d.ts.map +1 -0
  97. package/dist/types/debug-context/Context.d.ts +15 -0
  98. package/dist/types/debug-context/Context.d.ts.map +1 -0
  99. package/dist/types/debug-context/Types.d.ts +13 -0
  100. package/dist/types/debug-context/Types.d.ts.map +1 -0
  101. package/dist/types/debug-context/index.d.ts +4 -0
  102. package/dist/types/debug-context/index.d.ts.map +1 -0
  103. package/dist/types/hooks/index.d.ts +13 -0
  104. package/dist/types/hooks/index.d.ts.map +1 -1
  105. package/dist/types/hooks/unwrapRefValue.d.ts +9 -0
  106. package/dist/types/hooks/unwrapRefValue.d.ts.map +1 -0
  107. package/dist/types/hooks/useAddClassNameDuringResize.d.ts +13 -0
  108. package/dist/types/hooks/useAddClassNameDuringResize.d.ts.map +1 -0
  109. package/dist/types/hooks/useComposeRef.d.ts +16 -0
  110. package/dist/types/hooks/useComposeRef.d.ts.map +1 -0
  111. package/dist/types/hooks/useCountLayoutSlotChildren.d.ts +5 -0
  112. package/dist/types/hooks/useCountLayoutSlotChildren.d.ts.map +1 -0
  113. package/dist/types/hooks/useElementSize.d.ts +12 -0
  114. package/dist/types/hooks/useElementSize.d.ts.map +1 -0
  115. package/dist/types/hooks/useEventHandler.d.ts +10 -0
  116. package/dist/types/hooks/useEventHandler.d.ts.map +1 -0
  117. package/dist/types/hooks/useExpectSameValueReference.d.ts +2 -0
  118. package/dist/types/hooks/useExpectSameValueReference.d.ts.map +1 -0
  119. package/dist/types/hooks/useForceRender.d.ts +0 -1
  120. package/dist/types/hooks/useForceRender.d.ts.map +1 -1
  121. package/dist/types/hooks/useIsMounted.d.ts +0 -1
  122. package/dist/types/hooks/useIsMounted.d.ts.map +1 -1
  123. package/dist/types/hooks/useOnElementMutation.d.ts +3 -0
  124. package/dist/types/hooks/useOnElementMutation.d.ts.map +1 -0
  125. package/dist/types/hooks/useOnElementResize.d.ts +3 -0
  126. package/dist/types/hooks/useOnElementResize.d.ts.map +1 -0
  127. package/dist/types/hooks/useOnScrollWithin.d.ts +10 -0
  128. package/dist/types/hooks/useOnScrollWithin.d.ts.map +1 -0
  129. package/dist/types/hooks/useOnWindowResize.d.ts +2 -0
  130. package/dist/types/hooks/useOnWindowResize.d.ts.map +1 -0
  131. package/dist/types/hooks/useScrollOffsets.d.ts +14 -0
  132. package/dist/types/hooks/useScrollOffsets.d.ts.map +1 -0
  133. package/dist/types/hooks/useStoredState.d.ts +2 -3
  134. package/dist/types/hooks/useStoredState.d.ts.map +1 -1
  135. package/dist/types/hooks/useUpdatedRef.d.ts +8 -0
  136. package/dist/types/hooks/useUpdatedRef.d.ts.map +1 -0
  137. package/dist/types/hooks/useWindowSize.d.ts +5 -0
  138. package/dist/types/hooks/useWindowSize.d.ts.map +1 -0
  139. package/dist/types/index.d.ts +2 -0
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/dist/types/referentiallyStable/index.d.ts +1 -0
  142. package/dist/types/referentiallyStable/index.d.ts.map +1 -1
  143. package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts +2 -0
  144. package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts.map +1 -0
  145. package/dist/types/tsconfig.tsbuildinfo +1 -1
  146. package/dist/types/types/PropsWithRequiredChildren.d.ts +5 -0
  147. package/dist/types/types/PropsWithRequiredChildren.d.ts.map +1 -0
  148. package/dist/types/{types.d.ts → types/Serializable.d.ts} +1 -1
  149. package/dist/types/types/Serializable.d.ts.map +1 -0
  150. package/dist/types/types/index.d.ts +3 -0
  151. package/dist/types/types/index.d.ts.map +1 -0
  152. package/package.json +7 -2
  153. package/src/context/createNonNullableContextFactory.ts +19 -0
  154. package/src/context/index.ts +1 -0
  155. package/src/debug-context/Constants.ts +22 -0
  156. package/src/debug-context/Context.tsx +82 -0
  157. package/src/debug-context/Types.ts +13 -0
  158. package/src/debug-context/index.ts +3 -0
  159. package/src/hooks/index.ts +13 -0
  160. package/src/hooks/unwrapRefValue.ts +16 -0
  161. package/src/hooks/useAddClassNameDuringResize.ts +58 -0
  162. package/src/hooks/useComposeRef.ts +46 -0
  163. package/src/hooks/useCountLayoutSlotChildren.ts +46 -0
  164. package/src/hooks/useDebounceCallback.ts +1 -1
  165. package/src/hooks/useElementSize.ts +73 -0
  166. package/src/hooks/useEventHandler.ts +24 -0
  167. package/src/hooks/useExpectSameValueReference.ts +26 -0
  168. package/src/hooks/useOnElementMutation.ts +42 -0
  169. package/src/hooks/useOnElementResize.ts +52 -0
  170. package/src/hooks/useOnScrollWithin.ts +67 -0
  171. package/src/hooks/useOnWindowResize.ts +42 -0
  172. package/src/hooks/useScrollOffsets.ts +88 -0
  173. package/src/hooks/useStoredState.ts +2 -2
  174. package/src/hooks/useUpdatedRef.ts +14 -0
  175. package/src/hooks/useWindowSize.ts +20 -0
  176. package/src/index.ts +2 -0
  177. package/src/referentiallyStable/index.ts +1 -0
  178. package/src/referentiallyStable/useReferentiallyStableCallback.ts +11 -0
  179. package/src/tsconfig.json +4 -1
  180. package/src/types/PropsWithRequiredChildren.ts +3 -0
  181. package/src/types/index.ts +2 -0
  182. package/dist/types/types.d.ts.map +0 -1
  183. package/src/ambient.d.ts +0 -1
  184. /package/src/{types.ts → types/Serializable.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementSize.js","sources":["../../../src/hooks/useElementSize.ts"],"sourcesContent":["import { getSizeFromResizeObserverEntryFactory } from '@contember/utilities'\nimport { useLayoutEffect, useMemo, useRef, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nfunction getElementWidth(element: HTMLElement) {\n\treturn element.offsetWidth\n}\n\nfunction getElementHeight(element: HTMLElement) {\n\treturn element.offsetHeight\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 refValue = unwrapRefValue(refOrElement)\n\tconst [width, setWidth] = useState<number | undefined>(refValue?.offsetWidth)\n\tconst [height, setHeight] = useState<number | undefined>(refValue?.offsetHeight)\n\n\tlogged('dimensions', { width, height })\n\n\tuseOnElementResize(refOrElement, entry => {\n\t\tconst dimensions = logged('useOnElementResize => entry:dimensions', getSizeFromResizeObserverEntry(entry))\n\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}, { box }, timeout)\n\n\t// INTENTIONAL AVOID OF ESLint ERROR: We need measure on every Layout side-effect\n\t// otherwise the browser will paint and cause layout shifts.\n\t//\n\t// React Hook useLayoutEffect contains a call to 'setWidth'. Without a list of dependencies,\n\t// this can lead to an infinite chain of updates. To fix this, pass [element] as a second argument\n\t// to the useLayoutEffect Hook.\n\t//\n\t// Seems like only pure function lets us measure before the browser has a chance to paint\n\tconst measure = useRef((element: HTMLElement | null) => {\n\t\tlogged('measure(element)', element)\n\n\t\tif (element instanceof HTMLElement) {\n\t\t\tsetWidth(logged('getElementWidth(element):', getElementWidth(element)))\n\t\t\tsetHeight(logged('getElementHeight(element):', getElementHeight(element)))\n\t\t} else if (element) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement or Window')\n\t\t}\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\t\tlogged('useLayoutEffect => measure', measure.current(element))\n\t})\n\n\treturn { height, width }\n}\n"],"names":[],"mappings":";;;;;AAMA,SAAS,gBAAgB,SAAsB;AAC9C,SAAO,QAAQ;AAChB;AAEA,SAAS,iBAAiB,SAAsB;AAC/C,SAAO,QAAQ;AAChB;AAQO,SAAS,eACf,cACA,UAAiC,CAAA,GACjC,UAAkB,KAC0C;AAC5D,QAAM,EAAE,OAAW,IAAA,oBAAoB,gBAAgB,EAAE;AAEnD,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,iCAAiC,QAAQ,MAAM,sCAAsC,GAAG,GAAG,CAAC,GAAG,CAAC;AAEhG,QAAA,WAAW,eAAe,YAAY;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA6B,UAAU,WAAW;AAC5E,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA6B,UAAU,YAAY;AAE/E,SAAO,cAAc,EAAE,OAAO,OAAQ,CAAA;AAEtC,qBAAmB,cAAc,CAAS,UAAA;AACzC,UAAM,aAAa,OAAO,0CAA0C,+BAA+B,KAAK,CAAC;AAErG,QAAA,UAAU,WAAW,OAAO;AAC/B,eAAS,WAAW,KAAK;AAAA,IAC1B;AACI,QAAA,WAAW,WAAW,QAAQ;AACjC,gBAAU,WAAW,MAAM;AAAA,IAC5B;AAAA,EAAA,GACE,EAAE,OAAO,OAAO;AAUb,QAAA,UAAU,OAAO,CAAC,YAAgC;AACvD,WAAO,oBAAoB,OAAO;AAElC,QAAI,mBAAmB,aAAa;AACnC,eAAS,OAAO,6BAA6B,gBAAgB,OAAO,CAAC,CAAC;AACtE,gBAAU,OAAO,8BAA8B,iBAAiB,OAAO,CAAC,CAAC;AAAA,eAC/D,SAAS;AACb,YAAA,IAAI,MAAM,6EAA6E;AAAA,IAC9F;AAAA,EAAA,CACA;AAED,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAC3C,WAAO,8BAA8B,QAAQ,QAAQ,OAAO,CAAC;AAAA,EAAA,CAC7D;AAEM,SAAA,EAAE,QAAQ;AAClB;"}
@@ -0,0 +1,19 @@
1
+ import { useRef, useEffect } from "react";
2
+ function useEventHandler(type, callback) {
3
+ const callbackRef = useRef(callback);
4
+ callbackRef.current = callback;
5
+ const stableHandler = useRef(function(event) {
6
+ return callbackRef.current(event);
7
+ }).current;
8
+ useEffect(() => {
9
+ return () => {
10
+ callbackRef.current = () => {
11
+ };
12
+ };
13
+ }, []);
14
+ return stableHandler;
15
+ }
16
+ export {
17
+ useEventHandler
18
+ };
19
+ //# sourceMappingURL=useEventHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventHandler.js","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":[],"mappings":";AASgB,SAAA,gBAA+C,MAAiB,UAA4C;AACrH,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AAEtD,QAAA,gBAAgB,OAAO,SAAU,OAAY;AAC3C,WAAA,YAAY,QAAQ,KAAK;AAAA,EAChC,CAAA,EAAE;AAEH,YAAU,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
+ import deepEqual from "deep-equal";
2
+ import { useRef } from "react";
3
+ function useExpectSameValueReference(next, shouldThrow = false) {
4
+ const previous = useRef(next);
5
+ if (next !== previous.current && typeof next === "object" && typeof previous.current === "object" && deepEqual(next, previous.current)) {
6
+ if (shouldThrow) {
7
+ throw new Error("Expecting same reference for same values");
8
+ }
9
+ }
10
+ previous.current = next;
11
+ }
12
+ export {
13
+ useExpectSameValueReference
14
+ };
15
+ //# sourceMappingURL=useExpectSameValueReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExpectSameValueReference.js","sources":["../../../src/hooks/useExpectSameValueReference.ts"],"sourcesContent":["import deepEqual from 'deep-equal'\nimport { useRef } from 'react'\n\n// TODO: Unify error behavior with useConstantValueInvariant() and maybe merge into one hook.\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('Previous and next next do not match in reference although match in value', {\n\t\t\t\tprevious: previous.current,\n\t\t\t\tnext,\n\t\t\t})\n\t\t}\n\n\t\tif (shouldThrow) {\n\t\t\tthrow new Error('Expecting same reference for same values')\n\t\t}\n\t}\n\n\tprevious.current = next\n}\n"],"names":[],"mappings":";;AAIgB,SAAA,4BAA+B,MAAS,cAAuB,OAAO;AAC/E,QAAA,WAAW,OAAO,IAAI;AAE5B,MAAI,SAAS,SAAS,WAClB,OAAO,SAAS,YAChB,OAAO,SAAS,YAAY,YAC5B,UAAU,MAAM,SAAS,OAAO,GAClC;AAQD,QAAI,aAAa;AACV,YAAA,IAAI,MAAM,0CAA0C;AAAA,IAC3D;AAAA,EACD;AAEA,WAAS,UAAU;AACpB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useObjectMemo.js","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":[],"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,SAAS,KAAK;AACpC,aAAA;AAAA,IACR;AAAA,EACD;AACO,SAAA;AACR;AAEa,MAAA,gBAAgB,CAAmB,UAAgB;AACzD,QAAA,WAAW,OAAO,KAAK;AAC7B,MAAI,CAAC,eAAe,SAAS,SAAS,KAAK,GAAG;AAC7C,aAAS,UAAU;AAAA,EACpB;AACA,SAAO,SAAS;AACjB;"}
1
+ {"version":3,"file":"useObjectMemo.js","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":[],"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,WAAW,OAAO,KAAK;AAC7B,MAAI,CAAC,eAAe,SAAS,SAAS,KAAK,GAAG;AAC7C,aAAS,UAAU;AAAA,EACpB;AACA,SAAO,SAAS;AACjB;"}
@@ -0,0 +1,35 @@
1
+ import deepEqual from "deep-equal";
2
+ import { useRef, useState, useEffect, useLayoutEffect } from "react";
3
+ import { unwrapRefValue } from "./unwrapRefValue.js";
4
+ import { useScopedConsoleRef } from "../debug-context/Context.js";
5
+ function useOnElementMutation(refOrElement, callback, options = { attributes: true, childList: true, subtree: true }) {
6
+ const scopedConsoleRef = useScopedConsoleRef("useOnElementMutation");
7
+ const callbackRef = useRef(callback);
8
+ callbackRef.current = callback;
9
+ const optionsRef = useRef(options);
10
+ optionsRef.current = options;
11
+ const [optionsState, setOptionsState] = useState(options);
12
+ useEffect(() => {
13
+ if (!deepEqual(optionsRef.current, options)) {
14
+ setOptionsState(options);
15
+ }
16
+ }, [options]);
17
+ useLayoutEffect(() => {
18
+ const element = unwrapRefValue(refOrElement);
19
+ if (element) {
20
+ let handler = function(mutations, observer2) {
21
+ scopedConsoleRef.current.logged("element.mutations", mutations);
22
+ callbackRef.current(mutations, observer2);
23
+ };
24
+ const observer = new MutationObserver(handler);
25
+ observer.observe(element, optionsState);
26
+ return () => {
27
+ observer.disconnect();
28
+ };
29
+ }
30
+ }, [optionsState, refOrElement, scopedConsoleRef]);
31
+ }
32
+ export {
33
+ useOnElementMutation
34
+ };
35
+ //# sourceMappingURL=useOnElementMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementMutation.js","sources":["../../../src/hooks/useOnElementMutation.ts"],"sourcesContent":["import deepEqual from 'deep-equal'\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementMutation(\n\trefOrElement: RefObjectOrElement<HTMLElement | undefined>,\n\tcallback: MutationCallback,\n\toptions: MutationObserverInit = { attributes: true, childList: true, subtree: true },\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementMutation')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst optionsRef = useRef<MutationObserverInit>(options); optionsRef.current = options\n\n\tconst [optionsState, setOptionsState] = useState<MutationObserverInit>(options)\n\n\tuseEffect(() => {\n\t\tif (!deepEqual(optionsRef.current, options)) {\n\t\t\tsetOptionsState(options)\n\t\t}\n\t}, [options])\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\n\t\tif (element) {\n\t\t\tfunction handler(mutations: MutationRecord[], observer: MutationObserver) {\n\t\t\t\tscopedConsoleRef.current.logged('element.mutations', mutations)\n\t\t\t\tcallbackRef.current(mutations, observer)\n\t\t\t}\n\n\t\t\tconst observer = new MutationObserver(handler)\n\n\t\t\tobserver.observe(element, optionsState)\n\n\t\t\treturn () => {\n\t\t\t\tobserver.disconnect()\n\t\t\t}\n\t\t}\n\t}, [optionsState, refOrElement, scopedConsoleRef])\n}\n"],"names":["observer"],"mappings":";;;;AAKgB,SAAA,qBACf,cACA,UACA,UAAgC,EAAE,YAAY,MAAM,WAAW,MAAM,SAAS,KAAA,GAC7E;AACK,QAAA,mBAAmB,oBAAoB,sBAAsB;AAE7D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,aAAa,OAA6B,OAAO;AAAG,aAAW,UAAU;AAE/E,QAAM,CAAC,cAAc,eAAe,IAAI,SAA+B,OAAO;AAE9E,YAAU,MAAM;AACf,QAAI,CAAC,UAAU,WAAW,SAAS,OAAO,GAAG;AAC5C,sBAAgB,OAAO;AAAA,IACxB;AAAA,EAAA,GACE,CAAC,OAAO,CAAC;AAEZ,kBAAgB,MAAM;AACf,UAAA,UAAU,eAAe,YAAY;AAE3C,QAAI,SAAS;AACH,UAAA,UAAT,SAAiB,WAA6BA,WAA4B;AACxD,yBAAA,QAAQ,OAAO,qBAAqB,SAAS;AAClD,oBAAA,QAAQ,WAAWA,SAAQ;AAAA,MAAA;AAGlC,YAAA,WAAW,IAAI,iBAAiB,OAAO;AAEpC,eAAA,QAAQ,SAAS,YAAY;AAEtC,aAAO,MAAM;AACZ,iBAAS,WAAW;AAAA,MAAA;AAAA,IAEtB;AAAA,EACE,GAAA,CAAC,cAAc,cAAc,gBAAgB,CAAC;AAClD;"}
@@ -0,0 +1,44 @@
1
+ import { useRef, useLayoutEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ import { useScopedConsoleRef } from "../debug-context/Context.js";
4
+ function useOnElementResize(refOrElement, callback, options = {}, timeout = 300) {
5
+ const scopedConsoleRef = useScopedConsoleRef("useOnElementResize");
6
+ const { box = "border-box" } = options;
7
+ const element = unwrapRefValue(refOrElement);
8
+ const callbackRef = useRef(callback);
9
+ callbackRef.current = callback;
10
+ const lastTimeStamp = useRef(0);
11
+ useLayoutEffect(() => {
12
+ let timeoutID = void 0;
13
+ function debouncedOnChange([entry]) {
14
+ const timeStamp = Date.now();
15
+ const delta = timeStamp - lastTimeStamp.current;
16
+ if (delta > timeout) {
17
+ scopedConsoleRef.current.warned("element.resize:immediate", null);
18
+ callbackRef.current(entry);
19
+ lastTimeStamp.current = timeStamp;
20
+ } else {
21
+ clearTimeout(timeoutID);
22
+ timeoutID = setTimeout(() => {
23
+ scopedConsoleRef.current.warned("element.resize:debounced", null);
24
+ callbackRef.current(entry);
25
+ lastTimeStamp.current = timeStamp;
26
+ }, timeout);
27
+ }
28
+ }
29
+ if (element instanceof HTMLElement) {
30
+ const resizeObserver = new ResizeObserver(debouncedOnChange);
31
+ resizeObserver.observe(element, { box });
32
+ return () => {
33
+ clearTimeout(timeoutID);
34
+ resizeObserver.unobserve(element);
35
+ };
36
+ } else if (element) {
37
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
38
+ }
39
+ }, [box, element, scopedConsoleRef, timeout]);
40
+ }
41
+ export {
42
+ useOnElementResize
43
+ };
44
+ //# sourceMappingURL=useOnElementResize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnElementResize.js","sources":["../../../src/hooks/useOnElementResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\nexport function useOnElementResize(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (entries: ResizeObserverEntry) => void,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): void {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnElementResize')\n\n\tconst { box = 'border-box' } = options\n\tconst element = unwrapRefValue(refOrElement)\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: number | undefined = undefined\n\n\t\tfunction debouncedOnChange([entry]: ResizeObserverEntry[]) {\n\t\t\tconst timeStamp = Date.now()\n\t\t\tconst delta = timeStamp - lastTimeStamp.current\n\n\t\t\tif (delta > timeout) {\n\t\t\t\tscopedConsoleRef.current.warned('element.resize:immediate', null)\n\t\t\t\tcallbackRef.current(entry)\n\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t} else {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('element.resize:debounced', null)\n\t\t\t\t\tcallbackRef.current(entry)\n\t\t\t\t\tlastTimeStamp.current = timeStamp\n\t\t\t\t}, timeout)\n\t\t\t}\n\t\t}\n\n\t\tif (element instanceof HTMLElement) {\n\t\t\tconst resizeObserver = new ResizeObserver(debouncedOnChange)\n\n\t\t\tresizeObserver.observe(element, { box })\n\n\t\t\treturn () => {\n\t\t\t\tclearTimeout(timeoutID)\n\t\t\t\tresizeObserver.unobserve(element)\n\t\t\t}\n\t\t} else if (element) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\t}, [box, element, scopedConsoleRef, timeout])\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,mBACf,cACA,UACA,UAAiC,CAAC,GAClC,UAAkB,KACX;AACD,QAAA,mBAAmB,oBAAoB,oBAAoB;AAE3D,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,UAAU,eAAe,YAAY;AACrC,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,MAAM;AACrB,QAAI,YAAgC;AAE3B,aAAA,kBAAkB,CAAC,KAAK,GAA0B;AACpD,YAAA,YAAY,KAAK;AACjB,YAAA,QAAQ,YAAY,cAAc;AAExC,UAAI,QAAQ,SAAS;AACH,yBAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU;AAAA,MAAA,OAClB;AACN,qBAAa,SAAS;AACtB,oBAAY,WAAW,MAAM;AACX,2BAAA,QAAQ,OAAO,4BAA4B,IAAI;AAChE,sBAAY,QAAQ,KAAK;AACzB,wBAAc,UAAU;AAAA,WACtB,OAAO;AAAA,MACX;AAAA,IACD;AAEA,QAAI,mBAAmB,aAAa;AAC7B,YAAA,iBAAiB,IAAI,eAAe,iBAAiB;AAE3D,qBAAe,QAAQ,SAAS,EAAE,IAAK,CAAA;AAEvC,aAAO,MAAM;AACZ,qBAAa,SAAS;AACtB,uBAAe,UAAU,OAAO;AAAA,MAAA;AAAA,eAEvB,SAAS;AACb,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAAA,KACE,CAAC,KAAK,SAAS,kBAAkB,OAAO,CAAC;AAC7C;"}
@@ -0,0 +1,50 @@
1
+ import { useRef, useLayoutEffect } from "react";
2
+ import { unwrapRefValue } from "./unwrapRefValue.js";
3
+ import { useScopedConsoleRef } from "../debug-context/Context.js";
4
+ function useOnScrollWithin(refOrElement, callback, interval = 1e3 / 60) {
5
+ const scopedConsoleRef = useScopedConsoleRef("useOnScrollWithin");
6
+ const callbackRef = useRef(callback);
7
+ callbackRef.current = callback;
8
+ const lastTimeStamp = useRef(0);
9
+ const element = unwrapRefValue(refOrElement);
10
+ useLayoutEffect(() => {
11
+ let timeoutID = void 0;
12
+ function debouncedHandler(event) {
13
+ clearTimeout(timeoutID);
14
+ const delta = event.timeStamp - lastTimeStamp.current;
15
+ scopedConsoleRef.current.logged("event:element.scroll:delta", delta);
16
+ if (delta > interval) {
17
+ scopedConsoleRef.current.warned("event:element.scroll:immediately", event);
18
+ callbackRef.current(event);
19
+ lastTimeStamp.current = event.timeStamp;
20
+ } else {
21
+ timeoutID = setTimeout(() => {
22
+ scopedConsoleRef.current.warned("event:element.scroll:debounced", event);
23
+ lastTimeStamp.current = event.timeStamp;
24
+ callbackRef.current(event);
25
+ }, interval);
26
+ }
27
+ }
28
+ if (element && element instanceof HTMLElement) {
29
+ if (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {
30
+ window.addEventListener("scroll", debouncedHandler, { capture: true, passive: true });
31
+ window.addEventListener("resize", debouncedHandler);
32
+ return () => {
33
+ window.removeEventListener("scroll", debouncedHandler);
34
+ window.removeEventListener("resize", debouncedHandler);
35
+ };
36
+ } else {
37
+ element.addEventListener("scroll", debouncedHandler, { passive: true, capture: true });
38
+ return () => {
39
+ element.removeEventListener("scroll", debouncedHandler);
40
+ };
41
+ }
42
+ } else if (element) {
43
+ throw new Error("Exhaustive error: Expecting element to be instance of HTMLElement");
44
+ }
45
+ }, [element, interval, scopedConsoleRef]);
46
+ }
47
+ export {
48
+ useOnScrollWithin
49
+ };
50
+ //# sourceMappingURL=useOnScrollWithin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnScrollWithin.js","sources":["../../../src/hooks/useOnScrollWithin.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\n\n/**\n * Invokes callback on scroll event within the scroll container\n *\n * @param refOrElement - Scroll container\n * @param callback - Callback that is invoked on scroll event\n * @param interval - Specifies how often should scroll event invoke callback\n */\nexport function useOnScrollWithin(\n\trefOrElement: RefObjectOrElement<HTMLElement | null> | null,\n\tcallback: (event: Event) => void,\n\tinterval: number = 1000 / 60,\n) {\n\tconst scopedConsoleRef = useScopedConsoleRef('useOnScrollWithin')\n\n\tconst callbackRef = useRef(callback); callbackRef.current = callback\n\tconst lastTimeStamp = useRef<number>(0)\n\n\tconst element = unwrapRefValue(refOrElement)\n\n\tuseLayoutEffect(() => {\n\t\tlet timeoutID: number | undefined = undefined\n\n\t\tfunction debouncedHandler(event: Event) {\n\t\t\tclearTimeout(timeoutID)\n\n\t\t\tconst delta = event.timeStamp - lastTimeStamp.current\n\t\t\tscopedConsoleRef.current.logged('event:element.scroll:delta', delta)\n\n\t\t\tif (delta > interval) {\n\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:immediately', event)\n\t\t\t\tcallbackRef.current(event)\n\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t} else {\n\t\t\t\ttimeoutID = setTimeout(() => {\n\t\t\t\t\tscopedConsoleRef.current.warned('event:element.scroll:debounced', event)\n\t\t\t\t\tlastTimeStamp.current = event.timeStamp\n\t\t\t\t\tcallbackRef.current(event)\n\t\t\t\t}, interval)\n\t\t\t}\n\t\t}\n\n\t\tif (element && element instanceof HTMLElement) {\n\t\t\tif (element instanceof HTMLBodyElement || element instanceof HTMLHtmlElement) {\n\t\t\t\twindow.addEventListener('scroll', debouncedHandler, { capture: true, passive: true })\n\t\t\t\twindow.addEventListener('resize', debouncedHandler)\n\n\t\t\t\treturn () => {\n\t\t\t\t\twindow.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t\twindow.removeEventListener('resize', debouncedHandler)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\telement.addEventListener('scroll', debouncedHandler, { passive: true, capture: true })\n\n\t\t\t\treturn () => {\n\t\t\t\t\telement.removeEventListener('scroll', debouncedHandler)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (element) {\n\t\t\tthrow new Error('Exhaustive error: Expecting element to be instance of HTMLElement')\n\t\t}\n\n\t}, [element, interval, scopedConsoleRef])\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,kBACf,cACA,UACA,WAAmB,MAAO,IACzB;AACK,QAAA,mBAAmB,oBAAoB,mBAAmB;AAE1D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEhC,QAAA,UAAU,eAAe,YAAY;AAE3C,kBAAgB,MAAM;AACrB,QAAI,YAAgC;AAEpC,aAAS,iBAAiB,OAAc;AACvC,mBAAa,SAAS;AAEhB,YAAA,QAAQ,MAAM,YAAY,cAAc;AAC7B,uBAAA,QAAQ,OAAO,8BAA8B,KAAK;AAEnE,UAAI,QAAQ,UAAU;AACJ,yBAAA,QAAQ,OAAO,oCAAoC,KAAK;AACzE,oBAAY,QAAQ,KAAK;AACzB,sBAAc,UAAU,MAAM;AAAA,MAAA,OACxB;AACN,oBAAY,WAAW,MAAM;AACX,2BAAA,QAAQ,OAAO,kCAAkC,KAAK;AACvE,wBAAc,UAAU,MAAM;AAC9B,sBAAY,QAAQ,KAAK;AAAA,WACvB,QAAQ;AAAA,MACZ;AAAA,IACD;AAEI,QAAA,WAAW,mBAAmB,aAAa;AAC1C,UAAA,mBAAmB,mBAAmB,mBAAmB,iBAAiB;AACtE,eAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAC7E,eAAA,iBAAiB,UAAU,gBAAgB;AAElD,eAAO,MAAM;AACL,iBAAA,oBAAoB,UAAU,gBAAgB;AAC9C,iBAAA,oBAAoB,UAAU,gBAAgB;AAAA,QAAA;AAAA,MACtD,OACM;AACE,gBAAA,iBAAiB,UAAU,kBAAkB,EAAE,SAAS,MAAM,SAAS,MAAM;AAErF,eAAO,MAAM;AACJ,kBAAA,oBAAoB,UAAU,gBAAgB;AAAA,QAAA;AAAA,MAExD;AAAA,eACU,SAAS;AACb,YAAA,IAAI,MAAM,mEAAmE;AAAA,IACpF;AAAA,EAEE,GAAA,CAAC,SAAS,UAAU,gBAAgB,CAAC;AACzC;"}
@@ -0,0 +1,36 @@
1
+ import { useRef, useLayoutEffect } from "react";
2
+ import { useScopedConsoleRef } from "../debug-context/Context.js";
3
+ function useOnWindowResize(callback, interval = 300) {
4
+ const scopedConsoleRef = useScopedConsoleRef("useOnWindowResize");
5
+ const callbackRef = useRef(callback);
6
+ callbackRef.current = callback;
7
+ const lastTimeStamp = useRef(0);
8
+ useLayoutEffect(() => {
9
+ let timeoutID = void 0;
10
+ function debouncedHandler(event) {
11
+ clearTimeout(timeoutID);
12
+ const delta = event.timeStamp - lastTimeStamp.current;
13
+ scopedConsoleRef.current.logged("window.resize:delta", delta);
14
+ if (delta > interval) {
15
+ scopedConsoleRef.current.warned("event:window.resize:immediately", null);
16
+ callbackRef.current(event);
17
+ lastTimeStamp.current = event.timeStamp;
18
+ } else {
19
+ timeoutID = setTimeout(() => {
20
+ scopedConsoleRef.current.warned("event:window.resize:debounced", null);
21
+ lastTimeStamp.current = event.timeStamp;
22
+ callbackRef.current(event);
23
+ }, interval);
24
+ }
25
+ }
26
+ window.addEventListener("resize", debouncedHandler);
27
+ return () => {
28
+ clearTimeout(timeoutID);
29
+ window.removeEventListener("resize", debouncedHandler);
30
+ };
31
+ }, [callbackRef, interval, scopedConsoleRef]);
32
+ }
33
+ export {
34
+ useOnWindowResize
35
+ };
36
+ //# sourceMappingURL=useOnWindowResize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnWindowResize.js","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":[],"mappings":";;AAGgB,SAAA,kBACf,UACA,WAAmB,KAClB;AACK,QAAA,mBAAmB,oBAAoB,mBAAmB;AAE1D,QAAA,cAAc,OAAO,QAAQ;AAAG,cAAY,UAAU;AACtD,QAAA,gBAAgB,OAAe,CAAC;AAEtC,kBAAgB,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,68 @@
1
+ import { assert } from "@contember/utilities";
2
+ import { useState, useLayoutEffect, useMemo } from "react";
3
+ import { unwrapRefValue } from "./unwrapRefValue.js";
4
+ import { useOnScrollWithin } from "./useOnScrollWithin.js";
5
+ import { useOnWindowResize } from "./useOnWindowResize.js";
6
+ import { useScopedConsoleRef } from "../debug-context/Context.js";
7
+ import { useReferentiallyStableCallback } from "../referentiallyStable/useReferentiallyStableCallback.js";
8
+ function useScrollOffsets(refOrElement, interval = 1e3 / 60) {
9
+ const { logged } = useScopedConsoleRef("useScrollOffsets").current;
10
+ const [top, setTop] = useState(0);
11
+ const [bottom, setBottom] = useState(0);
12
+ const [left, setLeft] = useState(0);
13
+ const [right, setRight] = useState(0);
14
+ const updateScrollOffsetsState = useReferentiallyStableCallback((offsets) => {
15
+ logged("Update the offsets:", {
16
+ previous: { bottom, left, right, top },
17
+ next: offsets
18
+ });
19
+ if (offsets.bottom !== bottom)
20
+ setBottom(offsets.bottom);
21
+ if (offsets.left !== left)
22
+ setLeft(offsets.left);
23
+ if (offsets.right !== right)
24
+ setRight(offsets.right);
25
+ if (offsets.top !== top)
26
+ setTop(offsets.top);
27
+ });
28
+ const handler = useReferentiallyStableCallback(() => {
29
+ const maybeScrollContent = unwrapRefValue(refOrElement) ?? document;
30
+ if (maybeScrollContent) {
31
+ updateScrollOffsetsState(
32
+ getElementScrollOffsets(maybeScrollContent)
33
+ );
34
+ }
35
+ });
36
+ useOnScrollWithin(refOrElement, handler, interval);
37
+ useOnWindowResize(handler);
38
+ useLayoutEffect(handler, [handler]);
39
+ return 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
+ assert("HTML element exists", html, (value) => value instanceof HTMLElement);
47
+ if (isIntrinsicScrollElement(element)) {
48
+ return html;
49
+ } else {
50
+ return element;
51
+ }
52
+ }
53
+ function getElementScrollOffsets(element) {
54
+ const isIntrinsicScrolling = isIntrinsicScrollElement(element);
55
+ const scrollContainer = getIntrinsicScrollContainer(element);
56
+ const { scrollLeft, scrollTop, scrollHeight, scrollWidth } = scrollContainer;
57
+ const height = isIntrinsicScrolling ? window.innerHeight : scrollContainer.offsetHeight;
58
+ const width = isIntrinsicScrolling ? window.innerWidth : scrollContainer.offsetWidth;
59
+ const left = Math.round(scrollLeft);
60
+ const top = Math.round(scrollTop);
61
+ const right = Math.round(scrollWidth - width - left);
62
+ const bottom = Math.round(scrollHeight - height - top);
63
+ return { bottom, left, right, top };
64
+ }
65
+ export {
66
+ useScrollOffsets
67
+ };
68
+ //# sourceMappingURL=useScrollOffsets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollOffsets.js","sources":["../../../src/hooks/useScrollOffsets.ts"],"sourcesContent":["import { assert } 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\tupdateScrollOffsetsState(\n\t\t\t\tgetElementScrollOffsets(maybeScrollContent),\n\t\t\t)\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\nfunction getElementScrollOffsets(element: HTMLElement | Document): Offsets {\n\tconst isIntrinsicScrolling = isIntrinsicScrollElement(element)\n\tconst scrollContainer = getIntrinsicScrollContainer(element)\n\n\tconst { scrollLeft, scrollTop, scrollHeight, scrollWidth } = scrollContainer\n\n\tconst height = isIntrinsicScrolling ? window.innerHeight : scrollContainer.offsetHeight\n\tconst width = isIntrinsicScrolling ? window.innerWidth : scrollContainer.offsetWidth\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":[],"mappings":";;;;;;;AAeO,SAAS,iBAAiB,cAA6D,WAAmB,MAAO,IAAI;AAC3H,QAAM,EAAE,OAAW,IAAA,oBAAoB,kBAAkB,EAAE;AAE3D,QAAM,CAAC,KAAK,MAAM,IAAI,SAAS,CAAC;AAChC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,CAAC;AACtC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,CAAC;AAClC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,CAAC;AAE9B,QAAA,2BAA2B,+BAA+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,UAAU,+BAA+B,MAAM;AAC9C,UAAA,qBAAqB,eAAe,YAAY,KAAK;AAE3D,QAAI,oBAAoB;AACvB;AAAA,QACC,wBAAwB,kBAAkB;AAAA,MAAA;AAAA,IAE5C;AAAA,EAAA,CACA;AAEiB,oBAAA,cAAc,SAAS,QAAQ;AACjD,oBAAkB,OAAO;AACT,kBAAA,SAAS,CAAC,OAAO,CAAC;AAElC,SAAO,QAAQ,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;AAC3B,SAAO,uBAAuB,MAAM,CAAC,UAAgC,iBAAiB,WAAW;AAE7F,MAAA,yBAAyB,OAAO,GAAG;AAC/B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;AAEA,SAAS,wBAAwB,SAA0C;AACpE,QAAA,uBAAuB,yBAAyB,OAAO;AACvD,QAAA,kBAAkB,4BAA4B,OAAO;AAE3D,QAAM,EAAE,YAAY,WAAW,cAAc,gBAAgB;AAE7D,QAAM,SAAS,uBAAuB,OAAO,cAAc,gBAAgB;AAC3E,QAAM,QAAQ,uBAAuB,OAAO,aAAa,gBAAgB;AAEnE,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;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStoredState.js","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\nimport { Serializable } from '../types'\n\ntype SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\ntype 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":["value"],"mappings":";AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACrCA,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAO,YAAY,CAAAA,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;"}
1
+ {"version":3,"file":"useStoredState.js","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":["value"],"mappings":";AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,MAAM;AACrCA,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAO,YAAY,CAAAA,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
+ import { useRef } from "react";
2
+ function useUpdatedRef(value) {
3
+ const ref = useRef(value);
4
+ ref.current = value;
5
+ return ref;
6
+ }
7
+ export {
8
+ useUpdatedRef
9
+ };
10
+ //# sourceMappingURL=useUpdatedRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUpdatedRef.js","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":[],"mappings":";AAQO,SAAS,cAAiB,OAAU;AACpC,QAAA,MAAM,OAAO,KAAK;AACxB,MAAI,UAAU;AAEP,SAAA;AACR;"}
@@ -0,0 +1,20 @@
1
+ import { useState, useMemo } from "react";
2
+ import { useOnWindowResize } from "./useOnWindowResize.js";
3
+ function useWindowSize() {
4
+ const [width, setWidth] = useState(window.innerWidth);
5
+ const [height, setHeight] = useState(window.innerHeight);
6
+ useOnWindowResize(() => {
7
+ const { innerHeight, innerWidth } = window;
8
+ if (innerHeight !== height) {
9
+ setHeight(innerHeight);
10
+ }
11
+ if (innerWidth !== width) {
12
+ setWidth(innerWidth);
13
+ }
14
+ });
15
+ return useMemo(() => ({ height, width }), [height, width]);
16
+ }
17
+ export {
18
+ useWindowSize
19
+ };
20
+ //# sourceMappingURL=useWindowSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowSize.js","sources":["../../../src/hooks/useWindowSize.ts"],"sourcesContent":["import { useMemo, useState } from 'react'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nexport function useWindowSize() {\n const [width, setWidth] = useState(window.innerWidth)\n const [height, setHeight] = useState(window.innerHeight)\n\n useOnWindowResize(() => {\n const { innerHeight, innerWidth } = window\n if (innerHeight !== height) {\n setHeight(innerHeight)\n }\n\n if (innerWidth !== width) {\n setWidth(innerWidth)\n }\n })\n\n return useMemo(() => ({ height, width }), [height, width])\n}\n"],"names":[],"mappings":";;AAGO,SAAS,gBAAgB;AAC9B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,OAAO,UAAU;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,OAAO,WAAW;AAEvD,oBAAkB,MAAM;AAChB,UAAA,EAAE,aAAa,WAAe,IAAA;AACpC,QAAI,gBAAgB,QAAQ;AAC1B,gBAAU,WAAW;AAAA,IACvB;AAEA,QAAI,eAAe,OAAO;AACxB,eAAS,UAAU;AAAA,IACrB;AAAA,EAAA,CACD;AAEM,SAAA,QAAQ,OAAO,EAAE,QAAQ,MAAU,IAAA,CAAC,QAAQ,KAAK,CAAC;AAC3D;"}
@@ -1,37 +1,77 @@
1
+ import { createNonNullableContextFactory } from "./context/createNonNullableContextFactory.js";
2
+ import { isNoopScopedConsole, noopLog, noopLogged, noopScopedConsole } from "./debug-context/Constants.js";
3
+ import { DebugChildren, ScopedConsoleContext, useScopedConsoleRef } from "./debug-context/Context.js";
4
+ import { unwrapRefValue } from "./hooks/unwrapRefValue.js";
1
5
  import { useAbortController } from "./hooks/useAbortController.js";
6
+ import { useAddClassNameDuringResize } from "./hooks/useAddClassNameDuringResize.js";
2
7
  import { useArrayMapMemo } from "./hooks/useArrayMapMemo.js";
8
+ import { useComposeRef } from "./hooks/useComposeRef.js";
3
9
  import { useConstantLengthInvariant } from "./hooks/useConstantLengthInvariant.js";
4
10
  import { useConstantValueInvariant } from "./hooks/useConstantValueInvariant.js";
11
+ import { useCountLayoutSlotChildren, useHasEmptySlotsClassName } from "./hooks/useCountLayoutSlotChildren.js";
5
12
  import { useDebounce } from "./hooks/useDebounce.js";
6
13
  import { useDebounceCallback } from "./hooks/useDebounceCallback.js";
14
+ import { useElementSize } from "./hooks/useElementSize.js";
15
+ import { useEventHandler } from "./hooks/useEventHandler.js";
16
+ import { useExpectSameValueReference } from "./hooks/useExpectSameValueReference.js";
7
17
  import { useForceRender } from "./hooks/useForceRender.js";
8
18
  import { useIsMounted } from "./hooks/useIsMounted.js";
9
19
  import { useObjectMemo } from "./hooks/useObjectMemo.js";
20
+ import { useOnElementMutation } from "./hooks/useOnElementMutation.js";
21
+ import { useOnElementResize } from "./hooks/useOnElementResize.js";
22
+ import { useOnWindowResize } from "./hooks/useOnWindowResize.js";
10
23
  import { usePreviousValue } from "./hooks/usePreviousValue.js";
24
+ import { useScrollOffsets } from "./hooks/useScrollOffsets.js";
11
25
  import { useSessionStorageState } from "./hooks/useStoredState.js";
26
+ import { useUpdatedRef } from "./hooks/useUpdatedRef.js";
27
+ import { useWindowSize } from "./hooks/useWindowSize.js";
12
28
  import { emptyArray } from "./referentiallyStable/emptyArray.js";
13
29
  import { emptyObject } from "./referentiallyStable/emptyObject.js";
14
30
  import { identityFunction } from "./referentiallyStable/identityFunction.js";
15
31
  import { noop } from "./referentiallyStable/noop.js";
16
32
  import { returnFalse } from "./referentiallyStable/returnFalse.js";
17
33
  import { returnTrue } from "./referentiallyStable/returnTrue.js";
34
+ import { useReferentiallyStableCallback } from "./referentiallyStable/useReferentiallyStableCallback.js";
18
35
  export {
36
+ DebugChildren,
37
+ ScopedConsoleContext,
38
+ createNonNullableContextFactory,
19
39
  emptyArray,
20
40
  emptyObject,
21
41
  identityFunction,
42
+ isNoopScopedConsole,
22
43
  noop,
44
+ noopLog,
45
+ noopLogged,
46
+ noopScopedConsole,
23
47
  returnFalse,
24
48
  returnTrue,
49
+ unwrapRefValue,
25
50
  useAbortController,
51
+ useAddClassNameDuringResize,
26
52
  useArrayMapMemo,
53
+ useComposeRef,
27
54
  useConstantLengthInvariant,
28
55
  useConstantValueInvariant,
56
+ useCountLayoutSlotChildren,
29
57
  useDebounce,
30
58
  useDebounceCallback,
59
+ useElementSize,
60
+ useEventHandler,
61
+ useExpectSameValueReference,
31
62
  useForceRender,
63
+ useHasEmptySlotsClassName,
32
64
  useIsMounted,
33
65
  useObjectMemo,
66
+ useOnElementMutation,
67
+ useOnElementResize,
68
+ useOnWindowResize,
34
69
  usePreviousValue,
35
- useSessionStorageState
70
+ useReferentiallyStableCallback,
71
+ useScopedConsoleRef,
72
+ useScrollOffsets,
73
+ useSessionStorageState,
74
+ useUpdatedRef,
75
+ useWindowSize
36
76
  };
37
77
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import { useRef, useCallback } from "react";
2
+ const useReferentiallyStableCallback = (callback) => {
3
+ const ref = useRef(callback);
4
+ ref.current = callback;
5
+ return useCallback((...args) => {
6
+ return ref.current(...args);
7
+ }, []);
8
+ };
9
+ export {
10
+ useReferentiallyStableCallback
11
+ };
12
+ //# sourceMappingURL=useReferentiallyStableCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReferentiallyStableCallback.js","sources":["../../../src/referentiallyStable/useReferentiallyStableCallback.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\n\n// TODO: Should be possible to remove when React.useEvent() lands\nexport const useReferentiallyStableCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n\tconst ref = useRef(callback)\n\tref.current = callback\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\treturn useCallback<T>(((...args: any[]) => {\n\t\treturn ref.current(...args)\n\t}) as T, [])\n}\n"],"names":[],"mappings":";AAGa,MAAA,iCAAiC,CAAoC,aAAmB;AAC9F,QAAA,MAAM,OAAO,QAAQ;AAC3B,MAAI,UAAU;AAEP,SAAA,YAAgB,IAAI,SAAgB;AACnC,WAAA,IAAI,QAAQ,GAAG,IAAI;AAAA,EAC3B,GAAS,CAAE,CAAA;AACZ;"}
@@ -0,0 +1,3 @@
1
+ import type { Context } from 'react';
2
+ export declare function createNonNullableContextFactory<T>(displayName: string, initialValue?: T): [Context<T>, () => NonNullable<T>];
3
+ //# sourceMappingURL=createNonNullableContextFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNonNullableContextFactory.d.ts","sourceRoot":"","sources":["../../../src/context/createNonNullableContextFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAGpC,wBAAgB,+BAA+B,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC,CAe5H"}
@@ -0,0 +1,2 @@
1
+ export * from './createNonNullableContextFactory';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { ScopedConsoleContextType } from './Types';
2
+ export declare function noopLog(...parameters: any[]): void;
3
+ export declare function noopLogged<T>(message: string, value: T): T;
4
+ export declare const noopScopedConsole: ScopedConsoleContextType;
5
+ export declare function isNoopScopedConsole(value: unknown): boolean;
6
+ //# sourceMappingURL=Constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAEvD,wBAAgB,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,QAAK;AAEjD,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAE1D;AAED,eAAO,MAAM,iBAAiB,EAAE,wBAS9B,CAAA;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import { ScopedConsoleContextType } from './Types';
3
+ export declare const ScopedConsoleContext: import("react").Context<ScopedConsoleContextType>;
4
+ export declare const useScopedConsoleRef: (prefix: string) => import("react").MutableRefObject<ScopedConsoleContextType>;
5
+ export type DebugChildrenProps = {
6
+ active: true;
7
+ children: ReactNode;
8
+ id: string;
9
+ } | {
10
+ active?: false;
11
+ children: ReactNode;
12
+ id?: string;
13
+ };
14
+ export declare const DebugChildren: import("react").NamedExoticComponent<DebugChildrenProps>;
15
+ //# sourceMappingURL=Context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Context.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoD,MAAM,OAAO,CAAA;AAEnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAmClD,eAAO,MAAM,oBAAoB,mDAAiD,CAAA;AAOlF,eAAO,MAAM,mBAAmB,WAAY,MAAM,+DAiBjD,CAAA;AAED,MAAM,MAAM,kBAAkB,GAC3B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;CAAE,GAClD;IAAE,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CAAE,CAAA;AAExD,eAAO,MAAM,aAAa,0DAYxB,CAAA"}
@@ -0,0 +1,13 @@
1
+ export type DebugMethod = (...parameters: any[]) => void;
2
+ export type ResultDebuggedMethod = <T>(message: string, value: T) => T;
3
+ export type ScopedConsoleContextType = {
4
+ log: DebugMethod;
5
+ logged: ResultDebuggedMethod;
6
+ warn: DebugMethod;
7
+ warned: ResultDebuggedMethod;
8
+ error: DebugMethod;
9
+ errored: ResultDebuggedMethod;
10
+ trace: DebugMethod;
11
+ traced: ResultDebuggedMethod;
12
+ };
13
+ //# sourceMappingURL=Types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../src/debug-context/Types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AACxD,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAA;AAEtE,MAAM,MAAM,wBAAwB,GAAG;IACtC,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,oBAAoB,CAAC;CAC7B,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './Constants';
2
+ export * from './Context';
3
+ export * from './Types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/debug-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
@@ -1,12 +1,25 @@
1
+ export * from './unwrapRefValue';
1
2
  export * from './useAbortController';
3
+ export * from './useAddClassNameDuringResize';
2
4
  export * from './useArrayMapMemo';
5
+ export * from './useComposeRef';
3
6
  export * from './useConstantLengthInvariant';
4
7
  export * from './useConstantValueInvariant';
8
+ export * from './useCountLayoutSlotChildren';
5
9
  export * from './useDebounce';
6
10
  export * from './useDebounceCallback';
11
+ export * from './useElementSize';
12
+ export * from './useEventHandler';
13
+ export * from './useExpectSameValueReference';
7
14
  export * from './useForceRender';
8
15
  export * from './useIsMounted';
9
16
  export * from './useObjectMemo';
17
+ export * from './useOnElementMutation';
18
+ export * from './useOnElementResize';
19
+ export * from './useOnWindowResize';
10
20
  export * from './usePreviousValue';
21
+ export * from './useScrollOffsets';
11
22
  export * from './useStoredState';
23
+ export * from './useUpdatedRef';
24
+ export * from './useWindowSize';
12
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}