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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/development/context/createNonNullableContextFactory.cjs +17 -0
  2. package/dist/development/context/createNonNullableContextFactory.cjs.map +1 -0
  3. package/dist/development/context/createOptionalContextFactory.cjs +13 -0
  4. package/dist/development/context/createOptionalContextFactory.cjs.map +1 -0
  5. package/dist/development/debug-context/Constants.cjs +25 -0
  6. package/dist/development/debug-context/Constants.cjs.map +1 -0
  7. package/dist/development/debug-context/Context.cjs +71 -0
  8. package/dist/development/debug-context/Context.cjs.map +1 -0
  9. package/dist/development/hooks/unwrapRefValue.cjs +11 -0
  10. package/dist/development/hooks/unwrapRefValue.cjs.map +1 -0
  11. package/dist/development/hooks/useAbortController.cjs +17 -0
  12. package/dist/development/hooks/useAbortController.cjs.map +1 -0
  13. package/dist/development/hooks/useAddClassNameDuringResize.cjs +32 -0
  14. package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +1 -0
  15. package/dist/development/hooks/useArrayMapMemo.cjs +11 -0
  16. package/dist/development/hooks/useArrayMapMemo.cjs.map +1 -0
  17. package/dist/development/hooks/useAutoHeightTextArea.cjs +41 -0
  18. package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -0
  19. package/dist/development/hooks/useChildrenAsLabel.cjs +53 -0
  20. package/dist/development/hooks/useChildrenAsLabel.cjs.map +1 -0
  21. package/dist/development/hooks/useComposeRef.cjs +31 -0
  22. package/dist/development/hooks/useComposeRef.cjs.map +1 -0
  23. package/dist/development/hooks/useConstantLengthInvariant.cjs +15 -0
  24. package/dist/development/hooks/useConstantLengthInvariant.cjs.map +1 -0
  25. package/dist/development/hooks/useConstantValueInvariant.cjs +15 -0
  26. package/dist/development/hooks/useConstantValueInvariant.cjs.map +1 -0
  27. package/dist/development/hooks/useContainerWidth.cjs +14 -0
  28. package/dist/development/hooks/useContainerWidth.cjs.map +1 -0
  29. package/dist/development/hooks/useDebounce.cjs +15 -0
  30. package/dist/development/hooks/useDebounce.cjs.map +1 -0
  31. package/dist/development/hooks/useDebounceCallback.cjs +19 -0
  32. package/dist/development/hooks/useDebounceCallback.cjs.map +1 -0
  33. package/dist/development/hooks/useDocumentTitle.cjs +22 -0
  34. package/dist/development/hooks/useDocumentTitle.cjs.map +1 -0
  35. package/dist/development/hooks/useElementSize.cjs +37 -0
  36. package/dist/development/hooks/useElementSize.cjs.map +1 -0
  37. package/dist/development/hooks/useElementTopOffset.cjs +29 -0
  38. package/dist/development/hooks/useElementTopOffset.cjs.map +1 -0
  39. package/dist/development/hooks/useEventHandler.cjs +19 -0
  40. package/dist/development/hooks/useEventHandler.cjs.map +1 -0
  41. package/dist/development/hooks/useExpectSameValueReference.cjs +24 -0
  42. package/dist/development/hooks/useExpectSameValueReference.cjs.map +1 -0
  43. package/dist/development/hooks/useForceRender.cjs +9 -0
  44. package/dist/development/hooks/useForceRender.cjs.map +1 -0
  45. package/dist/development/hooks/useId.cjs +13 -0
  46. package/dist/development/hooks/useId.cjs.map +1 -0
  47. package/dist/development/hooks/useIsMounted.cjs +18 -0
  48. package/dist/development/hooks/useIsMounted.cjs.map +1 -0
  49. package/dist/development/hooks/useObjectMemo.cjs +27 -0
  50. package/dist/development/hooks/useObjectMemo.cjs.map +1 -0
  51. package/dist/development/hooks/useOnElementClickOutsideCallback.cjs +20 -0
  52. package/dist/development/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
  53. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
  54. package/dist/development/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
  55. package/dist/development/hooks/useOnElementMutation.cjs +35 -0
  56. package/dist/development/hooks/useOnElementMutation.cjs.map +1 -0
  57. package/dist/development/hooks/useOnElementResize.cjs +42 -0
  58. package/dist/development/hooks/useOnElementResize.cjs.map +1 -0
  59. package/dist/development/hooks/useOnScrollWithin.cjs +52 -0
  60. package/dist/development/hooks/useOnScrollWithin.cjs.map +1 -0
  61. package/dist/development/hooks/useOnWindowResize.cjs +36 -0
  62. package/dist/development/hooks/useOnWindowResize.cjs.map +1 -0
  63. package/dist/development/hooks/usePreviousValue.cjs +12 -0
  64. package/dist/development/hooks/usePreviousValue.cjs.map +1 -0
  65. package/dist/development/hooks/useScrollOffsets.cjs +67 -0
  66. package/dist/development/hooks/useScrollOffsets.cjs.map +1 -0
  67. package/dist/development/hooks/useStoredState.cjs +23 -0
  68. package/dist/development/hooks/useStoredState.cjs.map +1 -0
  69. package/dist/development/hooks/useUpdatedRef.cjs +10 -0
  70. package/dist/development/hooks/useUpdatedRef.cjs.map +1 -0
  71. package/dist/development/hooks/useWindowSize.cjs +20 -0
  72. package/dist/development/hooks/useWindowSize.cjs.map +1 -0
  73. package/dist/development/index.cjs +112 -0
  74. package/dist/development/index.cjs.map +1 -0
  75. package/dist/development/referentiallyStable/emptyArray.cjs +5 -0
  76. package/dist/development/referentiallyStable/emptyArray.cjs.map +1 -0
  77. package/dist/development/referentiallyStable/emptyObject.cjs +5 -0
  78. package/dist/development/referentiallyStable/emptyObject.cjs.map +1 -0
  79. package/dist/development/referentiallyStable/identityFunction.cjs +5 -0
  80. package/dist/development/referentiallyStable/identityFunction.cjs.map +1 -0
  81. package/dist/development/referentiallyStable/noop.cjs +5 -0
  82. package/dist/development/referentiallyStable/noop.cjs.map +1 -0
  83. package/dist/development/referentiallyStable/returnFalse.cjs +5 -0
  84. package/dist/development/referentiallyStable/returnFalse.cjs.map +1 -0
  85. package/dist/development/referentiallyStable/returnTrue.cjs +5 -0
  86. package/dist/development/referentiallyStable/returnTrue.cjs.map +1 -0
  87. package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
  88. package/dist/development/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
  89. package/dist/development/theming/ColorSchemeProvider.cjs +18 -0
  90. package/dist/development/theming/ColorSchemeProvider.cjs.map +1 -0
  91. package/dist/development/theming/GlobalClassNamePrefixContext.cjs +6 -0
  92. package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
  93. package/dist/development/theming/contexts.cjs +12 -0
  94. package/dist/development/theming/contexts.cjs.map +1 -0
  95. package/dist/development/theming/useClassName.cjs +17 -0
  96. package/dist/development/theming/useClassName.cjs.map +1 -0
  97. package/dist/development/theming/useClassNameFactory.cjs +22 -0
  98. package/dist/development/theming/useClassNameFactory.cjs.map +1 -0
  99. package/dist/development/theming/useThemedClassName.cjs +17 -0
  100. package/dist/development/theming/useThemedClassName.cjs.map +1 -0
  101. package/dist/development/theming/useThemedClassNameFactory.cjs +29 -0
  102. package/dist/development/theming/useThemedClassNameFactory.cjs.map +1 -0
  103. package/dist/production/context/createNonNullableContextFactory.cjs +17 -0
  104. package/dist/production/context/createNonNullableContextFactory.cjs.map +1 -0
  105. package/dist/production/context/createOptionalContextFactory.cjs +13 -0
  106. package/dist/production/context/createOptionalContextFactory.cjs.map +1 -0
  107. package/dist/production/debug-context/Constants.cjs +25 -0
  108. package/dist/production/debug-context/Constants.cjs.map +1 -0
  109. package/dist/production/debug-context/Context.cjs +67 -0
  110. package/dist/production/debug-context/Context.cjs.map +1 -0
  111. package/dist/production/hooks/unwrapRefValue.cjs +11 -0
  112. package/dist/production/hooks/unwrapRefValue.cjs.map +1 -0
  113. package/dist/production/hooks/useAbortController.cjs +17 -0
  114. package/dist/production/hooks/useAbortController.cjs.map +1 -0
  115. package/dist/production/hooks/useAddClassNameDuringResize.cjs +32 -0
  116. package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +1 -0
  117. package/dist/production/hooks/useArrayMapMemo.cjs +9 -0
  118. package/dist/production/hooks/useArrayMapMemo.cjs.map +1 -0
  119. package/dist/production/hooks/useAutoHeightTextArea.cjs +41 -0
  120. package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -0
  121. package/dist/production/hooks/useChildrenAsLabel.cjs +52 -0
  122. package/dist/production/hooks/useChildrenAsLabel.cjs.map +1 -0
  123. package/dist/production/hooks/useComposeRef.cjs +31 -0
  124. package/dist/production/hooks/useComposeRef.cjs.map +1 -0
  125. package/dist/production/hooks/useConstantLengthInvariant.cjs +6 -0
  126. package/dist/production/hooks/useConstantLengthInvariant.cjs.map +1 -0
  127. package/dist/production/hooks/useConstantValueInvariant.cjs +6 -0
  128. package/dist/production/hooks/useConstantValueInvariant.cjs.map +1 -0
  129. package/dist/production/hooks/useContainerWidth.cjs +14 -0
  130. package/dist/production/hooks/useContainerWidth.cjs.map +1 -0
  131. package/dist/production/hooks/useDebounce.cjs +15 -0
  132. package/dist/production/hooks/useDebounce.cjs.map +1 -0
  133. package/dist/production/hooks/useDebounceCallback.cjs +19 -0
  134. package/dist/production/hooks/useDebounceCallback.cjs.map +1 -0
  135. package/dist/production/hooks/useDocumentTitle.cjs +22 -0
  136. package/dist/production/hooks/useDocumentTitle.cjs.map +1 -0
  137. package/dist/production/hooks/useElementSize.cjs +37 -0
  138. package/dist/production/hooks/useElementSize.cjs.map +1 -0
  139. package/dist/production/hooks/useElementTopOffset.cjs +29 -0
  140. package/dist/production/hooks/useElementTopOffset.cjs.map +1 -0
  141. package/dist/production/hooks/useEventHandler.cjs +19 -0
  142. package/dist/production/hooks/useEventHandler.cjs.map +1 -0
  143. package/dist/production/hooks/useExpectSameValueReference.cjs +15 -0
  144. package/dist/production/hooks/useExpectSameValueReference.cjs.map +1 -0
  145. package/dist/production/hooks/useForceRender.cjs +9 -0
  146. package/dist/production/hooks/useForceRender.cjs.map +1 -0
  147. package/dist/production/hooks/useId.cjs +13 -0
  148. package/dist/production/hooks/useId.cjs.map +1 -0
  149. package/dist/production/hooks/useIsMounted.cjs +18 -0
  150. package/dist/production/hooks/useIsMounted.cjs.map +1 -0
  151. package/dist/production/hooks/useObjectMemo.cjs +27 -0
  152. package/dist/production/hooks/useObjectMemo.cjs.map +1 -0
  153. package/dist/production/hooks/useOnElementClickOutsideCallback.cjs +20 -0
  154. package/dist/production/hooks/useOnElementClickOutsideCallback.cjs.map +1 -0
  155. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs +33 -0
  156. package/dist/production/hooks/useOnElementMouseEnterDelayedCallback.cjs.map +1 -0
  157. package/dist/production/hooks/useOnElementMutation.cjs +35 -0
  158. package/dist/production/hooks/useOnElementMutation.cjs.map +1 -0
  159. package/dist/production/hooks/useOnElementResize.cjs +42 -0
  160. package/dist/production/hooks/useOnElementResize.cjs.map +1 -0
  161. package/dist/production/hooks/useOnScrollWithin.cjs +52 -0
  162. package/dist/production/hooks/useOnScrollWithin.cjs.map +1 -0
  163. package/dist/production/hooks/useOnWindowResize.cjs +36 -0
  164. package/dist/production/hooks/useOnWindowResize.cjs.map +1 -0
  165. package/dist/production/hooks/usePreviousValue.cjs +12 -0
  166. package/dist/production/hooks/usePreviousValue.cjs.map +1 -0
  167. package/dist/production/hooks/useScrollOffsets.cjs +67 -0
  168. package/dist/production/hooks/useScrollOffsets.cjs.map +1 -0
  169. package/dist/production/hooks/useStoredState.cjs +23 -0
  170. package/dist/production/hooks/useStoredState.cjs.map +1 -0
  171. package/dist/production/hooks/useUpdatedRef.cjs +10 -0
  172. package/dist/production/hooks/useUpdatedRef.cjs.map +1 -0
  173. package/dist/production/hooks/useWindowSize.cjs +20 -0
  174. package/dist/production/hooks/useWindowSize.cjs.map +1 -0
  175. package/dist/production/index.cjs +112 -0
  176. package/dist/production/index.cjs.map +1 -0
  177. package/dist/production/referentiallyStable/emptyArray.cjs +5 -0
  178. package/dist/production/referentiallyStable/emptyArray.cjs.map +1 -0
  179. package/dist/production/referentiallyStable/emptyObject.cjs +5 -0
  180. package/dist/production/referentiallyStable/emptyObject.cjs.map +1 -0
  181. package/dist/production/referentiallyStable/identityFunction.cjs +5 -0
  182. package/dist/production/referentiallyStable/identityFunction.cjs.map +1 -0
  183. package/dist/production/referentiallyStable/noop.cjs +5 -0
  184. package/dist/production/referentiallyStable/noop.cjs.map +1 -0
  185. package/dist/production/referentiallyStable/returnFalse.cjs +5 -0
  186. package/dist/production/referentiallyStable/returnFalse.cjs.map +1 -0
  187. package/dist/production/referentiallyStable/returnTrue.cjs +5 -0
  188. package/dist/production/referentiallyStable/returnTrue.cjs.map +1 -0
  189. package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs +12 -0
  190. package/dist/production/referentiallyStable/useReferentiallyStableCallback.cjs.map +1 -0
  191. package/dist/production/theming/ColorSchemeProvider.cjs +14 -0
  192. package/dist/production/theming/ColorSchemeProvider.cjs.map +1 -0
  193. package/dist/production/theming/GlobalClassNamePrefixContext.cjs +6 -0
  194. package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +1 -0
  195. package/dist/production/theming/contexts.cjs +12 -0
  196. package/dist/production/theming/contexts.cjs.map +1 -0
  197. package/dist/production/theming/useClassName.cjs +17 -0
  198. package/dist/production/theming/useClassName.cjs.map +1 -0
  199. package/dist/production/theming/useClassNameFactory.cjs +22 -0
  200. package/dist/production/theming/useClassNameFactory.cjs.map +1 -0
  201. package/dist/production/theming/useThemedClassName.cjs +17 -0
  202. package/dist/production/theming/useThemedClassName.cjs.map +1 -0
  203. package/dist/production/theming/useThemedClassNameFactory.cjs +29 -0
  204. package/dist/production/theming/useThemedClassNameFactory.cjs.map +1 -0
  205. package/dist/types/tsconfig.tsbuildinfo +1 -1
  206. package/package.json +10 -3
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function createNonNullableContextFactory(displayName, initialValue) {
5
+ const RequiredContext = react.createContext(initialValue ?? null);
6
+ RequiredContext.displayName = displayName;
7
+ const useRequiredContext = () => {
8
+ const context = react.useContext(RequiredContext);
9
+ if (context == null) {
10
+ throw new Error(`use${displayName} must be used within a ${displayName} provider`);
11
+ }
12
+ return context;
13
+ };
14
+ return [RequiredContext, useRequiredContext];
15
+ }
16
+ exports.createNonNullableContextFactory = createNonNullableContextFactory;
17
+ //# sourceMappingURL=createNonNullableContextFactory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createNonNullableContextFactory.cjs","sources":["../../../src/context/createNonNullableContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createNonNullableContextFactory<T>(displayName: string, initialValue?: T): [Context<T>, () => NonNullable<T>] {\n const RequiredContext = createContext<T>((initialValue ?? null)!)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = () => {\n const context = useContext(RequiredContext)\n\n if (context == null) {\n throw new Error(`use${displayName} must be used within a ${displayName} provider`)\n }\n\n return context\n }\n\n return [RequiredContext, useRequiredContext]\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAGgB,SAAA,gCAAmC,aAAqB,cAAsD;AACtH,QAAA,kBAAkBA,MAAAA,cAAkB,gBAAgB,IAAM;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACzB,UAAA,UAAUC,iBAAW,eAAe;AAE1C,QAAI,WAAW,MAAM;AACnB,YAAM,IAAI,MAAM,MAAM,qCAAqC,sBAAsB;AAAA,IACnF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;;"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function createOptionalContextFactory(name, initialValue) {
5
+ const OptionalContext = react.createContext(initialValue);
6
+ OptionalContext.displayName = name;
7
+ const useOptionalContext = () => {
8
+ return react.useContext(OptionalContext) ?? initialValue;
9
+ };
10
+ return [OptionalContext, useOptionalContext];
11
+ }
12
+ exports.createOptionalContextFactory = createOptionalContextFactory;
13
+ //# sourceMappingURL=createOptionalContextFactory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createOptionalContextFactory.cjs","sources":["../../../src/context/createOptionalContextFactory.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nexport function createOptionalContextFactory<T>(name: string, initialValue: T): [Context<T>, () => T] {\n const OptionalContext = createContext<T>(initialValue)\n OptionalContext.displayName = name\n\n const useOptionalContext = () => {\n return useContext(OptionalContext) ?? initialValue\n }\n\n return [OptionalContext, useOptionalContext]\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAGgB,SAAA,6BAAgC,MAAc,cAAwC;AAC9F,QAAA,kBAAkBA,oBAAiB,YAAY;AACrD,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAM;AACxB,WAAAC,MAAA,WAAW,eAAe,KAAK;AAAA,EAAA;AAGjC,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;;"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function noopLog(...parameters) {
4
+ }
5
+ function noopLogged(message, value) {
6
+ return value;
7
+ }
8
+ const noopScopedConsole = Object.freeze({
9
+ log: noopLog,
10
+ logged: noopLogged,
11
+ warn: noopLog,
12
+ warned: noopLogged,
13
+ error: noopLog,
14
+ errored: noopLogged,
15
+ trace: noopLog,
16
+ traced: noopLogged
17
+ });
18
+ function isNoopScopedConsole(value) {
19
+ return value === noopScopedConsole;
20
+ }
21
+ exports.isNoopScopedConsole = isNoopScopedConsole;
22
+ exports.noopLog = noopLog;
23
+ exports.noopLogged = noopLogged;
24
+ exports.noopScopedConsole = noopScopedConsole;
25
+ //# sourceMappingURL=Constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Constants.cjs","sources":["../../../src/debug-context/Constants.ts"],"sourcesContent":["import type { ScopedConsoleContextType } from './Types'\n\nexport function noopLog(...parameters: any[]) { }\n\nexport function noopLogged<T>(message: string, value: T): T {\n\treturn value\n}\n\nexport const noopScopedConsole: ScopedConsoleContextType = Object.freeze({\n\tlog: noopLog,\n\tlogged: noopLogged,\n\twarn: noopLog,\n\twarned: noopLogged,\n\terror: noopLog,\n\terrored: noopLogged,\n\ttrace: noopLog,\n\ttraced: noopLogged,\n})\n\nexport function isNoopScopedConsole(value: unknown): boolean {\n\treturn value === noopScopedConsole\n}\n"],"names":[],"mappings":";;AAEO,SAAS,WAAW,YAAmB;AAAE;AAEhC,SAAA,WAAc,SAAiB,OAAa;AACpD,SAAA;AACR;AAEa,MAAA,oBAA8C,OAAO,OAAO;AAAA,EACxE,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AACT,CAAC;AAEM,SAAS,oBAAoB,OAAyB;AAC5D,SAAO,UAAU;AAClB;;;;;"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxDevRuntime = require("react/jsx-dev-runtime");
4
+ const utilities = require("@contember/utilities");
5
+ const react = require("react");
6
+ const Constants = require("./Constants.cjs");
7
+ function createPrefixedConsole(message, prefixedConsole) {
8
+ return {
9
+ error: function error(...parameters) {
10
+ (prefixedConsole ?? console).error(message, ...parameters);
11
+ },
12
+ errored: function errored(message2, value) {
13
+ (prefixedConsole ?? console).error(message2, value);
14
+ return value;
15
+ },
16
+ log: function log(...parameters) {
17
+ (prefixedConsole ?? console).log(message, ...parameters);
18
+ },
19
+ logged: function logged(message2, value) {
20
+ (prefixedConsole ?? console).log(message2, value);
21
+ return value;
22
+ },
23
+ trace: function trace(...parameters) {
24
+ (prefixedConsole ?? console).trace(message, ...parameters);
25
+ },
26
+ traced: function traced(message2, value) {
27
+ (prefixedConsole ?? console).trace(message2, value);
28
+ return value;
29
+ },
30
+ warn: function warn(...parameters) {
31
+ (prefixedConsole ?? console).warn(message, ...parameters);
32
+ },
33
+ warned: function warned(message2, value) {
34
+ (prefixedConsole ?? console).warn(message2, value);
35
+ return value;
36
+ }
37
+ };
38
+ }
39
+ const ScopedConsoleContext = react.createContext(null);
40
+ ScopedConsoleContext.displayName = "ScopedConsoleContext";
41
+ function parentScopedConsoleOrNone(parentConsole) {
42
+ return Constants.isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
43
+ }
44
+ const useScopedConsoleRef = (prefix, override) => {
45
+ utilities.assert("prefix is non-empty string", prefix, utilities.isNonEmptyString);
46
+ const parentConsole = parentScopedConsoleOrNone(react.useContext(ScopedConsoleContext));
47
+ const scopedConsole = react.useMemo(() => {
48
+ if (override !== false && (parentConsole || override)) {
49
+ return createPrefixedConsole(prefix, parentConsole);
50
+ } else {
51
+ return Constants.noopScopedConsole;
52
+ }
53
+ }, [override, parentConsole, prefix]);
54
+ const ref = react.useRef(scopedConsole);
55
+ ref.current = scopedConsole;
56
+ return ref;
57
+ };
58
+ const DebugChildren = react.memo(({ active = true, children, id }) => {
59
+ const parentScopedConsole = parentScopedConsoleOrNone(react.useContext(ScopedConsoleContext));
60
+ const console2 = active && id ? createPrefixedConsole(id, parentScopedConsole) : Constants.noopScopedConsole;
61
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(ScopedConsoleContext.Provider, { value: active ? console2 : Constants.noopScopedConsole, children }, void 0, false, {
62
+ fileName: "/__w/interface/interface/packages/react-utils/src/debug-context/Context.tsx",
63
+ lineNumber: 77,
64
+ columnNumber: 3
65
+ }, globalThis);
66
+ });
67
+ DebugChildren.displayName = "DebugChildren";
68
+ exports.DebugChildren = DebugChildren;
69
+ exports.ScopedConsoleContext = ScopedConsoleContext;
70
+ exports.useScopedConsoleRef = useScopedConsoleRef;
71
+ //# sourceMappingURL=Context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { assert, isNonEmptyString } from '@contember/utilities'\nimport { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tassert('prefix is non-empty string', prefix, isNonEmptyString)\n\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","createContext","isNoopScopedConsole","assert","isNonEmptyString","useContext","useMemo","noopScopedConsole","useRef","memo","console","jsxDEV","this"],"mappings":";;;;;;AAKA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuBC,oBAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAAC,UAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACnEC,YAAAA,OAAA,8BAA8B,QAAQC,UAAAA,gBAAgB;AAE7D,QAAM,gBAAgB,0BAA0BC,iBAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgBC,MAAAA,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAAC;IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAMC,aAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgBC,WAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0BJ,iBAAW,oBAAoB,CAAC;AAEtF,QAAMK,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7CH;AAGF,SAAAI,qCAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASD,WAAUH,6BACvD,SADF,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAEA,GAAAK,UAAA;AAEF,CAAC;AACD,cAAc,cAAc;;;;"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function unwrapRefValue(value) {
4
+ if (value && typeof value === "object" && "current" in value) {
5
+ return value.current;
6
+ } else {
7
+ return value;
8
+ }
9
+ }
10
+ exports.unwrapRefValue = unwrapRefValue;
11
+ //# sourceMappingURL=unwrapRefValue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrapRefValue.cjs","sources":["../../../src/hooks/unwrapRefValue.ts"],"sourcesContent":["import { RefObject } from 'react'\n\nexport type RefObjectOrElement<T> = T | RefObject<T>\n\n/**\n * Unwraps a ref object or returns the value if it is not a ref object.\n * @param value - Value to unwrap\n * @returns Unwrapped value\n */\nexport function unwrapRefValue<T>(value: RefObjectOrElement<T>): T | null {\n\tif (value && typeof value === 'object' && 'current' in value) {\n\t\treturn value.current\n\t} else {\n\t\treturn value\n\t}\n}\n"],"names":[],"mappings":";;AASO,SAAS,eAAkB,OAAwC;AACzE,MAAI,SAAS,OAAO,UAAU,YAAY,aAAa,OAAO;AAC7D,WAAO,MAAM;AAAA,EAAA,OACP;AACC,WAAA;AAAA,EACR;AACD;;"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useAbortController = () => {
5
+ const lastAbortControllerRef = react.useRef(void 0);
6
+ react.useEffect(() => () => {
7
+ lastAbortControllerRef.current?.abort();
8
+ }, []);
9
+ return react.useCallback(() => {
10
+ lastAbortControllerRef.current?.abort();
11
+ const newController = new AbortController();
12
+ lastAbortControllerRef.current = newController;
13
+ return newController.signal;
14
+ }, []);
15
+ };
16
+ exports.useAbortController = useAbortController;
17
+ //# sourceMappingURL=useAbortController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAbortController.cjs","sources":["../../../src/hooks/useAbortController.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react'\n\nexport const useAbortController = () => {\n\tconst lastAbortControllerRef = useRef<AbortController | undefined>(undefined)\n\tuseEffect(() => () => {\n\t\tlastAbortControllerRef.current?.abort()\n\t}, [])\n\treturn useCallback((): AbortSignal => {\n\t\tlastAbortControllerRef.current?.abort()\n\n\t\tconst newController = new AbortController()\n\t\tlastAbortControllerRef.current = newController\n\t\treturn newController.signal\n\t}, [])\n}\n"],"names":["useRef","useEffect","useCallback"],"mappings":";;;AAEO,MAAM,qBAAqB,MAAM;AACjC,QAAA,yBAAyBA,MAAAA,OAAoC,MAAS;AAC5EC,QAAAA,UAAU,MAAM,MAAM;AACrB,2BAAuB,SAAS;EACjC,GAAG,CAAE,CAAA;AACL,SAAOC,kBAAY,MAAmB;AACrC,2BAAuB,SAAS;AAE1B,UAAA,gBAAgB,IAAI;AAC1B,2BAAuB,UAAU;AACjC,WAAO,cAAc;AAAA,EACtB,GAAG,CAAE,CAAA;AACN;;"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useOnWindowResize = require("./useOnWindowResize.cjs");
5
+ const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
6
+ function addClassName(className, element) {
7
+ if (element.classList.contains(className)) {
8
+ element.classList.remove(className);
9
+ }
10
+ }
11
+ function removeClassName(className, element) {
12
+ if (!element.classList.contains(className)) {
13
+ element.classList.add(className);
14
+ }
15
+ }
16
+ function useAddClassNameDuringResize(className, timeoutToRestore = 300, element) {
17
+ const timeoutID = react.useRef();
18
+ const addTemporaryClassName = useReferentiallyStableCallback.useReferentiallyStableCallback(() => {
19
+ clearTimeout(timeoutID.current);
20
+ removeClassName(className, element ?? document.body);
21
+ timeoutID.current = setTimeout(() => {
22
+ addClassName(className, element ?? document.body);
23
+ }, timeoutToRestore);
24
+ return () => {
25
+ clearTimeout(timeoutID.current);
26
+ };
27
+ });
28
+ react.useLayoutEffect(addTemporaryClassName, [addTemporaryClassName]);
29
+ useOnWindowResize.useOnWindowResize(addTemporaryClassName);
30
+ }
31
+ exports.useAddClassNameDuringResize = useAddClassNameDuringResize;
32
+ //# sourceMappingURL=useAddClassNameDuringResize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAddClassNameDuringResize.cjs","sources":["../../../src/hooks/useAddClassNameDuringResize.ts"],"sourcesContent":["import { useLayoutEffect, useRef } from 'react'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { useOnWindowResize } from './useOnWindowResize'\n\nfunction addClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (element.classList.contains(className)) {\n\t\telement.classList.remove(className)\n\t}\n}\n\nfunction removeClassName(\n\tclassName: string,\n\telement: HTMLElement,\n) {\n\tif (!element.classList.contains(className)) {\n\t\telement.classList.add(className)\n\t}\n}\n\n/**\n * Adds CSS class during resize event to element\n *\n * - Falls back to document.body when no element is specified\n * - Adds CSS class to element also on the initial load\n * - Uses element.classList directly\n *\n * @param className - CSS class to apply during the resize event\n * @param timeoutToRestore - Timeout in milliseconds to wait before finally removing the CSS class\n * @param element - Optional HTML element to apply CSS class to\n */\nexport function useAddClassNameDuringResize(\n\tclassName: string,\n\ttimeoutToRestore: number = 300,\n\telement?: HTMLElement,\n) {\n\tconst timeoutID = useRef<number>()\n\n\tconst addTemporaryClassName = useReferentiallyStableCallback(() => {\n\t\tclearTimeout(timeoutID.current)\n\t\tremoveClassName(className, element ?? document.body)\n\n\t\ttimeoutID.current = setTimeout(() => {\n\t\t\taddClassName(className, element ?? document.body)\n\t\t}, timeoutToRestore)\n\n\t\treturn () => {\n\t\t\tclearTimeout(timeoutID.current)\n\t\t}\n\t})\n\n\tuseLayoutEffect(addTemporaryClassName, [addTemporaryClassName])\n\tuseOnWindowResize(addTemporaryClassName)\n}\n"],"names":["useRef","useReferentiallyStableCallback","useLayoutEffect","useOnWindowResize"],"mappings":";;;;;AAIA,SAAS,aACR,WACA,SACC;AACD,MAAI,QAAQ,UAAU,SAAS,SAAS,GAAG;AAClC,YAAA,UAAU,OAAO,SAAS;AAAA,EACnC;AACD;AAEA,SAAS,gBACR,WACA,SACC;AACD,MAAI,CAAC,QAAQ,UAAU,SAAS,SAAS,GAAG;AACnC,YAAA,UAAU,IAAI,SAAS;AAAA,EAChC;AACD;AAaO,SAAS,4BACf,WACA,mBAA2B,KAC3B,SACC;AACD,QAAM,YAAYA,MAAAA;AAEZ,QAAA,wBAAwBC,+BAAAA,+BAA+B,MAAM;AAClE,iBAAa,UAAU,OAAO;AACd,oBAAA,WAAW,WAAW,SAAS,IAAI;AAEzC,cAAA,UAAU,WAAW,MAAM;AACvB,mBAAA,WAAW,WAAW,SAAS,IAAI;AAAA,OAC9C,gBAAgB;AAEnB,WAAO,MAAM;AACZ,mBAAa,UAAU,OAAO;AAAA,IAAA;AAAA,EAC/B,CACA;AAEeC,QAAAA,gBAAA,uBAAuB,CAAC,qBAAqB,CAAC;AAC9DC,oBAAA,kBAAkB,qBAAqB;AACxC;;"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useConstantLengthInvariant = require("./useConstantLengthInvariant.cjs");
5
+ const useArrayMapMemo = (items, map) => {
6
+ useConstantLengthInvariant.useConstantLengthInvariant(items);
7
+ const mapped = react.useMemo(() => items.map(map), [map, ...items]);
8
+ return react.useMemo(() => mapped, mapped);
9
+ };
10
+ exports.useArrayMapMemo = useArrayMapMemo;
11
+ //# sourceMappingURL=useArrayMapMemo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useArrayMapMemo.cjs","sources":["../../../src/hooks/useArrayMapMemo.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { useConstantLengthInvariant } from './useConstantLengthInvariant'\n\n/**\n * ⚠️ ONLY USE THIS IF YOU *REALLY* KNOW WHAT YOU'RE DOING! ⚠️\n * ⚠ HERE BE DRAGONS THAT KNOW WHERE YOU LIVE! ⚠\n *\n * This is a bit of React naughtiness that allows us to memoize outputs of Array.prototype.map() based on the contents\n * of the original array, and not its referential equality. That way, if we create a new array with identical items,\n * we get an array that is referentially equal to the previous one.\n */\nexport const useArrayMapMemo = <Item, OutputItem>(\n\titems: Item[],\n\tmap: (value: Item, index: number, array: Item[]) => OutputItem,\n): OutputItem[] => {\n\tuseConstantLengthInvariant(items)\n\n\t// This is tricky. We don't want to exclude the map function from the dependency list because if it changes but the\n\t// items array remains the same, we still want to re-compute the new array. However, if that yields the same array,\n\t// in the sense that the items are identical, albeit computed via a different map function, we still want to\n\t// preserve the referential equality of the original. Hence the second memo.\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst mapped = useMemo(() => items.map(map), [map, ...items])\n\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\treturn useMemo(() => mapped, mapped) // This is deliberately not `[mapped]`\n}\n"],"names":["useConstantLengthInvariant","useMemo"],"mappings":";;;;AAWa,MAAA,kBAAkB,CAC9B,OACA,QACkB;AAClBA,6BAAA,2BAA2B,KAAK;AAQ1B,QAAA,SAASC,MAAAA,QAAQ,MAAM,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAGrD,SAAAA,cAAQ,MAAM,QAAQ,MAAM;AACpC;;"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utilities = require("@contember/utilities");
4
+ const react = require("react");
5
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
6
+ const useOnElementResize = require("./useOnElementResize.cjs");
7
+ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
8
+ const measure = react.useCallback(async (ref, minRows2, maxRows2) => {
9
+ if (ref) {
10
+ const rowsAttribute = ref.rows;
11
+ ref.style.height = "";
12
+ ref.style.minHeight = "";
13
+ ref.style.maxHeight = "";
14
+ if (minRows2 !== maxRows2) {
15
+ const height = ref.scrollHeight;
16
+ let minHeight;
17
+ let maxHeight;
18
+ ref.rows = minRows2;
19
+ minHeight = await ref.getBoundingClientRect().height;
20
+ if (maxRows2 === Infinity) {
21
+ maxHeight = Infinity;
22
+ } else {
23
+ ref.rows = maxRows2;
24
+ maxHeight = await ref.getBoundingClientRect().height;
25
+ }
26
+ ref.style.height = utilities.px(height);
27
+ ref.style.minHeight = utilities.px(minHeight);
28
+ ref.style.maxHeight = utilities.px(maxHeight);
29
+ }
30
+ ref.rows = rowsAttribute;
31
+ }
32
+ }, []);
33
+ useOnElementResize.useOnElementResize(textAreaRef, () => {
34
+ measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
35
+ });
36
+ react.useLayoutEffect(() => {
37
+ measure(unwrapRefValue.unwrapRefValue(textAreaRef), minRows, maxRows);
38
+ }, [maxRows, measure, minRows, textAreaRef, value]);
39
+ };
40
+ exports.useAutoHeightTextArea = useAutoHeightTextArea;
41
+ //# sourceMappingURL=useAutoHeightTextArea.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoHeightTextArea.cjs","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(async (ref: HTMLTextAreaElement | null, minRows: number, maxRows: number) => {\n\t\tif (ref) {\n\t\t\tconst rowsAttribute = ref.rows\n\n\t\t\tref.style.height = ''\n\t\t\tref.style.minHeight = ''\n\t\t\tref.style.maxHeight = ''\n\n\t\t\tif (minRows !== maxRows) {\n\t\t\t\tconst height = ref.scrollHeight\n\t\t\t\tlet minHeight: number\n\t\t\t\tlet maxHeight: number\n\n\t\t\t\tref.rows = minRows\n\t\t\t\tminHeight = await ref.getBoundingClientRect().height\n\n\t\t\t\tif (maxRows === Infinity) {\n\t\t\t\t\tmaxHeight = Infinity\n\t\t\t\t} else {\n\t\t\t\t\tref.rows = maxRows\n\t\t\t\t\tmaxHeight = await ref.getBoundingClientRect().height\n\t\t\t\t}\n\n\t\t\t\tref.style.height = px(height)\n\t\t\t\tref.style.minHeight = px(minHeight)\n\t\t\t\tref.style.maxHeight = px(maxHeight)\n\t\t\t}\n\n\t\t\tref.rows = rowsAttribute\n\t\t}\n\t}, [])\n\n\tuseOnElementResize(textAreaRef, () => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t})\n\n\tuseLayoutEffect(() => {\n\t\tmeasure(unwrapRefValue(textAreaRef), minRows, maxRows)\n\t}, [maxRows, measure, minRows, textAreaRef, value])\n}\n"],"names":["useCallback","minRows","maxRows","px","useOnElementResize","unwrapRefValue","useLayoutEffect"],"mappings":";;;;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAUA,MAAA,YAAY,OAAO,KAAiCC,UAAiBC,aAAoB;AACxG,QAAI,KAAK;AACR,YAAM,gBAAgB,IAAI;AAE1B,UAAI,MAAM,SAAS;AACnB,UAAI,MAAM,YAAY;AACtB,UAAI,MAAM,YAAY;AAEtB,UAAID,aAAYC,UAAS;AACxB,cAAM,SAAS,IAAI;AACf,YAAA;AACA,YAAA;AAEJ,YAAI,OAAOD;AACC,oBAAA,MAAM,IAAI,sBAAA,EAAwB;AAE9C,YAAIC,aAAY,UAAU;AACb,sBAAA;AAAA,QAAA,OACN;AACN,cAAI,OAAOA;AACC,sBAAA,MAAM,IAAI,sBAAA,EAAwB;AAAA,QAC/C;AAEI,YAAA,MAAM,SAASC,UAAA,GAAG,MAAM;AACxB,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAYA,UAAA,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAELC,qBAAA,mBAAmB,aAAa,MAAM;AACrC,YAAQC,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAEDC,QAAAA,gBAAgB,MAAM;AACrB,YAAQD,eAAAA,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;;"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const MULTIPLE_SPACES_REG_EXP = / +/g;
5
+ function normalize(text) {
6
+ return text.replace(MULTIPLE_SPACES_REG_EXP, " ").trim();
7
+ }
8
+ function getChildrenAsLabel(node) {
9
+ if (typeof node === "string" || typeof node === "number") {
10
+ return String(node);
11
+ } else if (node === null || node === void 0 || typeof node === "boolean") {
12
+ return void 0;
13
+ } else if (Array.isArray(node)) {
14
+ return normalize(node.map(getChildrenAsLabel).join(""));
15
+ } else {
16
+ let label = [];
17
+ react.Children.map(node, (child) => {
18
+ if (child === null || child === void 0 || typeof child === "boolean")
19
+ ;
20
+ else if (typeof child === "string") {
21
+ label.push(child);
22
+ } else if (typeof child === "number") {
23
+ label.push(child);
24
+ } else if (Array.isArray(child)) {
25
+ const childLabel = getChildrenAsLabel(child);
26
+ if (childLabel) {
27
+ label.push(childLabel);
28
+ }
29
+ } else {
30
+ if ("props" in child && "children" in child.props) {
31
+ const childLabel = getChildrenAsLabel(child.props.children);
32
+ if (childLabel) {
33
+ label.push(childLabel);
34
+ }
35
+ } else if ("children" in child) {
36
+ const childLabel = getChildrenAsLabel(child.children);
37
+ if (childLabel) {
38
+ label.push(childLabel);
39
+ }
40
+ } else {
41
+ console.warn("Unsupported child:", child);
42
+ }
43
+ }
44
+ });
45
+ return label.length > 0 ? label.join("") : void 0;
46
+ }
47
+ }
48
+ function useChildrenAsLabel(node) {
49
+ return react.useMemo(() => getChildrenAsLabel(node), [node]);
50
+ }
51
+ exports.getChildrenAsLabel = getChildrenAsLabel;
52
+ exports.useChildrenAsLabel = useChildrenAsLabel;
53
+ //# sourceMappingURL=useChildrenAsLabel.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChildrenAsLabel.cjs","sources":["../../../src/hooks/useChildrenAsLabel.ts"],"sourcesContent":["import { Children, ReactNode, useMemo } from 'react'\n\nconst MULTIPLE_SPACES_REG_EXP = / +/g\n\nfunction normalize(text: string): string {\n\treturn text.replace(MULTIPLE_SPACES_REG_EXP, ' ').trim()\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function getChildrenAsLabel(node: ReactNode): string | undefined {\n\tif (typeof node === 'string' || typeof node === 'number') {\n\t\treturn String(node)\n\t} else if (node === null || node === undefined || typeof node === 'boolean') {\n\t\treturn undefined\n\t} else if (Array.isArray(node)) {\n\t\treturn normalize(node.map(getChildrenAsLabel).join(''))\n\t} else {\n\t\tlet label: (string | number)[] = []\n\n\t\tChildren.map(node, child => {\n\t\t\tif (child === null || child === undefined || typeof child === 'boolean') {\n\t\t\t} else if (typeof child === 'string') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (typeof child === 'number') {\n\t\t\t\tlabel.push(child)\n\t\t\t} else if (Array.isArray(child)) {\n\t\t\t\tconst childLabel = getChildrenAsLabel(child)\n\n\t\t\t\tif (childLabel) {\n\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// ReactElement | JSXElementConstructor | ReactPortal\n\t\t\t\tif ('props' in child && 'children' in child.props) {\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.props.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if ('children' in child) {\n\t\t\t\t\t// ReactPortal\n\t\t\t\t\tconst childLabel = getChildrenAsLabel(child.children)\n\n\t\t\t\t\tif (childLabel) {\n\t\t\t\t\t\tlabel.push(childLabel)\n\t\t\t\t\t}\n\t\t\t\t} else if (import.meta.env.DEV) {\n\t\t\t\t\tconsole.warn('Unsupported child:', child)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\n\t\treturn label.length > 0 ? label.join('') : undefined\n\t}\n}\n\n/**\n * Walks through the children and returns a string representation of the text content.\n *\n * @param node - The children to walk through.\n * @returns String representation of the text content or undefined if there is no text content.\n *\n */\nexport function useChildrenAsLabel(node: ReactNode): string | undefined {\n\treturn useMemo(() => getChildrenAsLabel(node), [node])\n}\n"],"names":["Children","useMemo"],"mappings":";;;AAEA,MAAM,0BAA0B;AAEhC,SAAS,UAAU,MAAsB;AACxC,SAAO,KAAK,QAAQ,yBAAyB,GAAG,EAAE,KAAK;AACxD;AASO,SAAS,mBAAmB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AACzD,WAAO,OAAO,IAAI;AAAA,EAAA,WACR,SAAS,QAAQ,SAAS,UAAa,OAAO,SAAS,WAAW;AACrE,WAAA;AAAA,EACG,WAAA,MAAM,QAAQ,IAAI,GAAG;AAC/B,WAAO,UAAU,KAAK,IAAI,kBAAkB,EAAE,KAAK,EAAE,CAAC;AAAA,EAAA,OAChD;AACN,QAAI,QAA6B,CAAA;AAExBA,UAAAA,SAAA,IAAI,MAAM,CAAS,UAAA;AAC3B,UAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU;AAAW;AAAA,eAC9D,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MAAA,WACN,OAAO,UAAU,UAAU;AACrC,cAAM,KAAK,KAAK;AAAA,MACN,WAAA,MAAM,QAAQ,KAAK,GAAG;AAC1B,cAAA,aAAa,mBAAmB,KAAK;AAE3C,YAAI,YAAY;AACf,gBAAM,KAAK,UAAU;AAAA,QACtB;AAAA,MAAA,OACM;AAEN,YAAI,WAAW,SAAS,cAAc,MAAM,OAAO;AAClD,gBAAM,aAAa,mBAAmB,MAAM,MAAM,QAAQ;AAE1D,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,WACU,cAAc,OAAO;AAEzB,gBAAA,aAAa,mBAAmB,MAAM,QAAQ;AAEpD,cAAI,YAAY;AACf,kBAAM,KAAK,UAAU;AAAA,UACtB;AAAA,QAAA,OAC+B;AACvB,kBAAA,KAAK,sBAAsB,KAAK;AAAA,QACzC;AAAA,MACD;AAAA,IAAA,CACA;AAED,WAAO,MAAM,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI;AAAA,EAC5C;AACD;AASO,SAAS,mBAAmB,MAAqC;AACvE,SAAOC,MAAAA,QAAQ,MAAM,mBAAmB,IAAI,GAAG,CAAC,IAAI,CAAC;AACtD;;;"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function setRef(ref, instance) {
5
+ if (ref) {
6
+ if (typeof ref === "function") {
7
+ ref(instance);
8
+ } else if (instance) {
9
+ ref.current = instance;
10
+ }
11
+ }
12
+ }
13
+ function useComposeRef(...refs) {
14
+ const initialRefs = react.useRef(refs);
15
+ const composeRef = react.useMemo(() => {
16
+ function composedRefCallback(instance) {
17
+ initialRefs.current.forEach((ref) => setRef(ref, instance));
18
+ setCurrent(instance);
19
+ }
20
+ function setCurrent(instance) {
21
+ if (instance) {
22
+ composedRefCallback.current = instance;
23
+ }
24
+ }
25
+ composedRefCallback.current = null;
26
+ return composedRefCallback;
27
+ }, []);
28
+ return composeRef;
29
+ }
30
+ exports.useComposeRef = useComposeRef;
31
+ //# sourceMappingURL=useComposeRef.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComposeRef.cjs","sources":["../../../src/hooks/useComposeRef.ts"],"sourcesContent":["import { MutableRefObject, RefCallback, useMemo, useRef } from 'react'\n\nexport type MaybeRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null | undefined\nexport type ComposedRefCallback<T> = RefCallback<T> & { current: T | null };\n\nfunction setRef<T>(ref: MaybeRef<T>, instance: T | null): void {\n\tif (ref) {\n\t\tif (typeof ref === 'function') {\n\t\t\tref(instance)\n\t\t} else if (instance) {\n\t\t\tref.current = instance\n\t\t}\n\t}\n}\n\n/**\n * Fills any number of refs with an instance\n *\n * Useful when you need to use outer ref and inner in the same time, e.g. passing element\n * back to forwardedRef an also using the same value within the component locally.\n *\n * @param refs - Rest parameter of refs to fill with instance\n * @returns Returns a function similar to a RefCallback\n */\nexport function useComposeRef<T>(...refs: MaybeRef<T>[]): ComposedRefCallback<T> {\n\tconst initialRefs = useRef(refs)\n\n\tconst composeRef: ComposedRefCallback<T> = useMemo(() => {\n\t\tfunction composedRefCallback(instance: T | null) {\n\t\t\tinitialRefs.current.forEach(ref => setRef(ref, instance))\n\t\t\tsetCurrent(instance)\n\t\t}\n\n\t\tfunction setCurrent(instance: T | null) {\n\t\t\tif (instance) {\n\t\t\t\tcomposedRefCallback.current = instance\n\t\t\t}\n\t\t}\n\n\t\tcomposedRefCallback.current = null as T | null\n\n\t\treturn composedRefCallback\n\t}, [])\n\n\treturn composeRef\n}\n"],"names":["useRef","useMemo"],"mappings":";;;AAKA,SAAS,OAAU,KAAkB,UAA0B;AAC9D,MAAI,KAAK;AACJ,QAAA,OAAO,QAAQ,YAAY;AAC9B,UAAI,QAAQ;AAAA,eACF,UAAU;AACpB,UAAI,UAAU;AAAA,IACf;AAAA,EACD;AACD;AAWO,SAAS,iBAAoB,MAA6C;AAC1E,QAAA,cAAcA,aAAO,IAAI;AAEzB,QAAA,aAAqCC,MAAAA,QAAQ,MAAM;AACxD,aAAS,oBAAoB,UAAoB;AAChD,kBAAY,QAAQ,QAAQ,CAAA,QAAO,OAAO,KAAK,QAAQ,CAAC;AACxD,iBAAW,QAAQ;AAAA,IACpB;AAEA,aAAS,WAAW,UAAoB;AACvC,UAAI,UAAU;AACb,4BAAoB,UAAU;AAAA,MAC/B;AAAA,IACD;AAEA,wBAAoB,UAAU;AAEvB,WAAA;AAAA,EACR,GAAG,CAAE,CAAA;AAEE,SAAA;AACR;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const usePreviousValue = require("./usePreviousValue.cjs");
4
+ const useConstantLengthInvariant = (items, message) => {
5
+ {
6
+ const previous = usePreviousValue.usePreviousValue(items);
7
+ if (previous.length !== items.length) {
8
+ throw new Error(
9
+ `Invariant violation: ${message || "Changing the length of an array whose length must remain constant between renders."}`
10
+ );
11
+ }
12
+ }
13
+ };
14
+ exports.useConstantLengthInvariant = useConstantLengthInvariant;
15
+ //# sourceMappingURL=useConstantLengthInvariant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConstantLengthInvariant.cjs","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAC3D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACnC,QAAA,SAAS,WAAW,MAAM,QAAQ;AACrC,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,IAGrC;AAAA,EACD;AACD;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const usePreviousValue = require("./usePreviousValue.cjs");
4
+ const useConstantValueInvariant = (value, message) => {
5
+ {
6
+ const previous = usePreviousValue.usePreviousValue(value);
7
+ if (previous !== value) {
8
+ throw new Error(
9
+ `Invariant violation: ${message || "Changing a value which must remain constant between renders."}`
10
+ );
11
+ }
12
+ }
13
+ };
14
+ exports.useConstantValueInvariant = useConstantValueInvariant;
15
+ //# sourceMappingURL=useConstantValueInvariant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConstantValueInvariant.cjs","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAC1D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACvC,QAAI,aAAa,OAAO;AACvB,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,IAErC;AAAA,EACD;AACD;;"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useWindowSize = require("./useWindowSize.cjs");
5
+ const ContainerWidthContext = react.createContext(void 0);
6
+ ContainerWidthContext.displayName = "ContainerWidthContext";
7
+ function useContainerWidth() {
8
+ const maybeContainerWidth = react.useContext(ContainerWidthContext);
9
+ const { width: windowWidth } = useWindowSize.useWindowSize();
10
+ return maybeContainerWidth ?? windowWidth;
11
+ }
12
+ exports.ContainerWidthContext = ContainerWidthContext;
13
+ exports.useContainerWidth = useContainerWidth;
14
+ //# sourceMappingURL=useContainerWidth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useContainerWidth.cjs","sources":["../../../src/hooks/useContainerWidth.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport { useWindowSize } from './useWindowSize'\n\nexport type ContainerWidthContextType = number\nexport const ContainerWidthContext = createContext<ContainerWidthContextType | null | undefined>(undefined)\nContainerWidthContext.displayName = 'ContainerWidthContext'\n\nexport function useContainerWidth(): number {\n\tconst maybeContainerWidth = useContext(ContainerWidthContext)\n\tconst { width: windowWidth } = useWindowSize()\n\n\treturn maybeContainerWidth ?? windowWidth\n}\n"],"names":["createContext","useContext","useWindowSize"],"mappings":";;;;AAIa,MAAA,wBAAwBA,MAAAA,cAA4D,MAAS;AAC1G,sBAAsB,cAAc;AAE7B,SAAS,oBAA4B;AACrC,QAAA,sBAAsBC,iBAAW,qBAAqB;AAC5D,QAAM,EAAE,OAAO,YAAY,IAAIC,cAAc,cAAA;AAE7C,SAAO,uBAAuB;AAC/B;;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useDebounce = (value, debounceMs) => {
5
+ const [debounced, setDebounced] = react.useState(value);
6
+ react.useEffect(() => {
7
+ const handle = window.setTimeout(() => setDebounced(value), debounceMs);
8
+ return () => {
9
+ window.clearTimeout(handle);
10
+ };
11
+ }, [value, debounceMs]);
12
+ return debounced;
13
+ };
14
+ exports.useDebounce = useDebounce;
15
+ //# sourceMappingURL=useDebounce.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.cjs","sources":["../../../src/hooks/useDebounce.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nexport const useDebounce = <T>(value: T, debounceMs: number): T => {\n\tconst [debounced, setDebounced] = useState(value)\n\tuseEffect(() => {\n\t\tconst handle = window.setTimeout(() => setDebounced(value), debounceMs)\n\t\treturn () => {\n\t\t\twindow.clearTimeout(handle)\n\t\t}\n\t}, [value, debounceMs])\n\treturn debounced\n}\n"],"names":["useState","useEffect"],"mappings":";;;AAEa,MAAA,cAAc,CAAI,OAAU,eAA0B;AAClE,QAAM,CAAC,WAAW,YAAY,IAAIA,eAAS,KAAK;AAChDC,QAAAA,UAAU,MAAM;AACf,UAAM,SAAS,OAAO,WAAW,MAAM,aAAa,KAAK,GAAG,UAAU;AACtE,WAAO,MAAM;AACZ,aAAO,aAAa,MAAM;AAAA,IAAA;AAAA,EAC3B,GACE,CAAC,OAAO,UAAU,CAAC;AACf,SAAA;AACR;;"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useDebounceCallback = (cb, debounceMs) => {
5
+ const timerRef = react.useRef();
6
+ const cbRef = react.useRef(cb);
7
+ cbRef.current = cb;
8
+ react.useEffect(() => {
9
+ return () => clearTimeout(timerRef.current);
10
+ }, []);
11
+ return react.useCallback(() => {
12
+ timerRef.current && clearTimeout(timerRef.current);
13
+ timerRef.current = setTimeout(() => {
14
+ cbRef.current();
15
+ }, debounceMs);
16
+ }, [debounceMs]);
17
+ };
18
+ exports.useDebounceCallback = useDebounceCallback;
19
+ //# sourceMappingURL=useDebounceCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounceCallback.cjs","sources":["../../../src/hooks/useDebounceCallback.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react'\n\nexport const useDebounceCallback = (cb: () => any, debounceMs: number) => {\n\tconst timerRef = useRef<ReturnType<typeof setTimeout>>()\n\tconst cbRef = useRef(cb)\n\tcbRef.current = cb\n\n\tuseEffect(() => {\n\t\treturn () => clearTimeout(timerRef.current)\n\t}, [])\n\n\treturn useCallback(() => {\n\t\ttimerRef.current && clearTimeout(timerRef.current)\n\n\t\ttimerRef.current = setTimeout(() => {\n\t\t\tcbRef.current()\n\t\t}, debounceMs)\n\t}, [debounceMs])\n}\n"],"names":["useRef","useEffect","useCallback"],"mappings":";;;AAEa,MAAA,sBAAsB,CAAC,IAAe,eAAuB;AACzE,QAAM,WAAWA,MAAAA;AACX,QAAA,QAAQA,aAAO,EAAE;AACvB,QAAM,UAAU;AAEhBC,QAAAA,UAAU,MAAM;AACR,WAAA,MAAM,aAAa,SAAS,OAAO;AAAA,EAC3C,GAAG,CAAE,CAAA;AAEL,SAAOC,kBAAY,MAAM;AACf,aAAA,WAAW,aAAa,SAAS,OAAO;AAExC,aAAA,UAAU,WAAW,MAAM;AACnC,YAAM,QAAQ;AAAA,OACZ,UAAU;AAAA,EAAA,GACX,CAAC,UAAU,CAAC;AAChB;;"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function useDocumentTitle(title, formatter) {
5
+ const initialTitle = react.useRef(document.title).current;
6
+ react.useEffect(() => {
7
+ if (title) {
8
+ if (formatter) {
9
+ document.title = formatter(title, initialTitle);
10
+ } else {
11
+ document.title = title;
12
+ }
13
+ } else {
14
+ document.title = initialTitle;
15
+ }
16
+ return () => {
17
+ document.title = initialTitle;
18
+ };
19
+ }, [formatter, initialTitle, title]);
20
+ }
21
+ exports.useDocumentTitle = useDocumentTitle;
22
+ //# sourceMappingURL=useDocumentTitle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDocumentTitle.cjs","sources":["../../../src/hooks/useDocumentTitle.ts"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport function useDocumentTitle(title: string | null | undefined, formatter?: (title: string, initialTitle: string) => string) {\n\tconst initialTitle = useRef(document.title).current\n\n\tuseEffect(() => {\n\t\tif (title) {\n\t\t\tif (formatter) {\n\t\t\t\tdocument.title = formatter(title, initialTitle)\n\t\t\t} else {\n\t\t\t\tdocument.title = title\n\t\t\t}\n\t\t} else {\n\t\t\tdocument.title = initialTitle\n\t\t}\n\n\t\treturn () => {\n\t\t\tdocument.title = initialTitle\n\t\t}\n\t}, [formatter, initialTitle, title])\n}\n"],"names":["useRef","useEffect"],"mappings":";;;AAEgB,SAAA,iBAAiB,OAAkC,WAA6D;AAC/H,QAAM,eAAeA,MAAA,OAAO,SAAS,KAAK,EAAE;AAE5CC,QAAAA,UAAU,MAAM;AACf,QAAI,OAAO;AACV,UAAI,WAAW;AACL,iBAAA,QAAQ,UAAU,OAAO,YAAY;AAAA,MAAA,OACxC;AACN,iBAAS,QAAQ;AAAA,MAClB;AAAA,IAAA,OACM;AACN,eAAS,QAAQ;AAAA,IAClB;AAEA,WAAO,MAAM;AACZ,eAAS,QAAQ;AAAA,IAAA;AAAA,EAEhB,GAAA,CAAC,WAAW,cAAc,KAAK,CAAC;AACpC;;"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utilities = require("@contember/utilities");
4
+ const react = require("react");
5
+ const unwrapRefValue = require("./unwrapRefValue.cjs");
6
+ const useOnElementResize = require("./useOnElementResize.cjs");
7
+ const Context = require("../debug-context/Context.cjs");
8
+ const useReferentiallyStableCallback = require("../referentiallyStable/useReferentiallyStableCallback.cjs");
9
+ function useElementSize(refOrElement, options = {}, timeout = 300) {
10
+ const { logged } = Context.useScopedConsoleRef("useElementSize").current;
11
+ const { box = "border-box" } = options;
12
+ const getSizeFromResizeObserverEntry = react.useMemo(() => utilities.getSizeFromResizeObserverEntryFactory(box), [box]);
13
+ const [width, setWidth] = react.useState();
14
+ const [height, setHeight] = react.useState();
15
+ logged("dimensions", { width, height });
16
+ const maybeSetNewDimensions = useReferentiallyStableCallback.useReferentiallyStableCallback((dimensions) => {
17
+ if (width !== dimensions.width) {
18
+ setWidth(dimensions.width);
19
+ }
20
+ if (height !== dimensions.height) {
21
+ setHeight(dimensions.height);
22
+ }
23
+ });
24
+ useOnElementResize.useOnElementResize(refOrElement, (entry) => {
25
+ const dimensions = logged("useOnElementResize => entry:dimensions", getSizeFromResizeObserverEntry(entry));
26
+ maybeSetNewDimensions(dimensions);
27
+ }, { box }, timeout);
28
+ react.useLayoutEffect(() => {
29
+ const element = unwrapRefValue.unwrapRefValue(refOrElement);
30
+ if (element) {
31
+ utilities.getElementDimensionsCallback(element, (dimensions) => maybeSetNewDimensions(dimensions));
32
+ }
33
+ });
34
+ return { height, width };
35
+ }
36
+ exports.useElementSize = useElementSize;
37
+ //# sourceMappingURL=useElementSize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementSize.cjs","sources":["../../../src/hooks/useElementSize.ts"],"sourcesContent":["import { getElementDimensionsCallback, getSizeFromResizeObserverEntryFactory } from '@contember/utilities'\nimport { useLayoutEffect, useMemo, useState } from 'react'\nimport { useScopedConsoleRef } from '../debug-context'\nimport { useReferentiallyStableCallback } from '../referentiallyStable'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport type ElementSize = {\n\theight: number\n\twidth: number\n}\n\n/**\n * Measure HTMLElement\n *\n * @param refOrElement - HTMLElement passed directly or indirectly as RefObject\n * @returns Size vector consisting of width and height properties\n */\nexport function useElementSize(\n\trefOrElement: RefObjectOrElement<HTMLElement>,\n\toptions: ResizeObserverOptions = {},\n\ttimeout: number = 300,\n): { height: number | undefined, width: number | undefined } {\n\tconst { logged } = useScopedConsoleRef('useElementSize').current\n\n\tconst { box = 'border-box' } = options\n\tconst getSizeFromResizeObserverEntry = useMemo(() => getSizeFromResizeObserverEntryFactory(box), [box])\n\n\tconst [width, setWidth] = useState<number | undefined>()\n\tconst [height, setHeight] = useState<number | undefined>()\n\n\tlogged('dimensions', { width, height })\n\n\tconst maybeSetNewDimensions = useReferentiallyStableCallback((dimensions: ElementSize) => {\n\t\tif (width !== dimensions.width) {\n\t\t\tsetWidth(dimensions.width)\n\t\t}\n\t\tif (height !== dimensions.height) {\n\t\t\tsetHeight(dimensions.height)\n\t\t}\n\t})\n\n\tuseOnElementResize(refOrElement, entry => {\n\t\tconst dimensions = logged('useOnElementResize => entry:dimensions', getSizeFromResizeObserverEntry(entry))\n\t\tmaybeSetNewDimensions(dimensions)\n\t}, { box }, timeout)\n\n\tuseLayoutEffect(() => {\n\t\tconst element = unwrapRefValue(refOrElement)\n\t\tif (element) {\n\t\t\tgetElementDimensionsCallback(element, dimensions => maybeSetNewDimensions(dimensions))\n\t\t}\n\t})\n\n\treturn { height, width }\n}\n"],"names":["useScopedConsoleRef","useMemo","getSizeFromResizeObserverEntryFactory","useState","useReferentiallyStableCallback","useOnElementResize","useLayoutEffect","unwrapRefValue","getElementDimensionsCallback"],"mappings":";;;;;;;;AAkBO,SAAS,eACf,cACA,UAAiC,CAAA,GACjC,UAAkB,KAC0C;AAC5D,QAAM,EAAE,OAAW,IAAAA,QAAA,oBAAoB,gBAAgB,EAAE;AAEnD,QAAA,EAAE,MAAM,aAAiB,IAAA;AACzB,QAAA,iCAAiCC,MAAAA,QAAQ,MAAMC,UAAAA,sCAAsC,GAAG,GAAG,CAAC,GAAG,CAAC;AAEtG,QAAM,CAAC,OAAO,QAAQ,IAAIC,MAA6B,SAAA;AACvD,QAAM,CAAC,QAAQ,SAAS,IAAIA,MAA6B,SAAA;AAEzD,SAAO,cAAc,EAAE,OAAO,OAAQ,CAAA;AAEhC,QAAA,wBAAwBC,8DAA+B,CAAC,eAA4B;AACrF,QAAA,UAAU,WAAW,OAAO;AAC/B,eAAS,WAAW,KAAK;AAAA,IAC1B;AACI,QAAA,WAAW,WAAW,QAAQ;AACjC,gBAAU,WAAW,MAAM;AAAA,IAC5B;AAAA,EAAA,CACA;AAEDC,wCAAmB,cAAc,CAAS,UAAA;AACzC,UAAM,aAAa,OAAO,0CAA0C,+BAA+B,KAAK,CAAC;AACzG,0BAAsB,UAAU;AAAA,EAAA,GAC9B,EAAE,OAAO,OAAO;AAEnBC,QAAAA,gBAAgB,MAAM;AACf,UAAA,UAAUC,8BAAe,YAAY;AAC3C,QAAI,SAAS;AACZC,gBAAA,6BAA6B,SAAS,CAAA,eAAc,sBAAsB,UAAU,CAAC;AAAA,IACtF;AAAA,EAAA,CACA;AAEM,SAAA,EAAE,QAAQ;AAClB;;"}