@contember/react-utils 1.3.0-alpha.8 → 2.0.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 (276) hide show
  1. package/dist/development/context/createContext.cjs +10 -0
  2. package/dist/development/context/createContext.cjs.map +1 -0
  3. package/dist/development/context/createContext.js +10 -0
  4. package/dist/development/context/createContext.js.map +1 -0
  5. package/dist/development/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
  6. package/dist/development/context/createRequiredContext.cjs.map +1 -0
  7. package/dist/development/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
  8. package/dist/development/context/createRequiredContext.js.map +1 -0
  9. package/dist/development/hooks/useAutoHeightTextArea.cjs +1 -1
  10. package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -1
  11. package/dist/development/hooks/useAutoHeightTextArea.js +1 -1
  12. package/dist/development/hooks/useAutoHeightTextArea.js.map +1 -1
  13. package/dist/development/hooks/useStoredState.cjs +89 -12
  14. package/dist/development/hooks/useStoredState.cjs.map +1 -1
  15. package/dist/development/hooks/useStoredState.js +91 -14
  16. package/dist/development/hooks/useStoredState.js.map +1 -1
  17. package/dist/development/index.cjs +11 -41
  18. package/dist/development/index.cjs.map +1 -1
  19. package/dist/development/index.js +12 -42
  20. package/dist/development/index.js.map +1 -1
  21. package/dist/production/context/createContext.cjs +10 -0
  22. package/dist/production/context/createContext.cjs.map +1 -0
  23. package/dist/production/context/createContext.js +10 -0
  24. package/dist/production/context/createContext.js.map +1 -0
  25. package/dist/production/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
  26. package/dist/production/context/createRequiredContext.cjs.map +1 -0
  27. package/dist/production/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
  28. package/dist/production/context/createRequiredContext.js.map +1 -0
  29. package/dist/production/hooks/useAutoHeightTextArea.cjs +1 -1
  30. package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -1
  31. package/dist/production/hooks/useAutoHeightTextArea.js +1 -1
  32. package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -1
  33. package/dist/production/hooks/useStoredState.cjs +89 -12
  34. package/dist/production/hooks/useStoredState.cjs.map +1 -1
  35. package/dist/production/hooks/useStoredState.js +91 -14
  36. package/dist/production/hooks/useStoredState.js.map +1 -1
  37. package/dist/production/index.cjs +11 -41
  38. package/dist/production/index.cjs.map +1 -1
  39. package/dist/production/index.js +12 -42
  40. package/dist/production/index.js.map +1 -1
  41. package/dist/types/context/createContext.d.ts +3 -0
  42. package/dist/types/context/createContext.d.ts.map +1 -0
  43. package/dist/types/context/createRequiredContext.d.ts +3 -0
  44. package/dist/types/context/createRequiredContext.d.ts.map +1 -0
  45. package/dist/types/context/index.d.ts +2 -2
  46. package/dist/types/context/index.d.ts.map +1 -1
  47. package/dist/types/hooks/index.d.ts +0 -10
  48. package/dist/types/hooks/index.d.ts.map +1 -1
  49. package/dist/types/hooks/useArrayMapMemo.d.ts.map +1 -1
  50. package/dist/types/hooks/useConstantLengthInvariant.d.ts.map +1 -1
  51. package/dist/types/hooks/useConstantValueInvariant.d.ts.map +1 -1
  52. package/dist/types/hooks/useDebounce.d.ts.map +1 -1
  53. package/dist/types/hooks/useObjectMemo.d.ts.map +1 -1
  54. package/dist/types/hooks/usePreviousValue.d.ts.map +1 -1
  55. package/dist/types/hooks/useStoredState.d.ts +14 -1
  56. package/dist/types/hooks/useStoredState.d.ts.map +1 -1
  57. package/dist/types/index.d.ts +0 -1
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/referentiallyStable/identityFunction.d.ts.map +1 -1
  60. package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts.map +1 -1
  61. package/dist/types/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +3 -3
  63. package/src/context/createContext.ts +9 -0
  64. package/src/context/{createNonNullableContextFactory.ts → createRequiredContext.ts} +6 -4
  65. package/src/context/index.ts +2 -2
  66. package/src/hooks/index.ts +0 -10
  67. package/src/hooks/useAutoHeightTextArea.ts +1 -1
  68. package/src/hooks/useStoredState.ts +103 -14
  69. package/src/index.ts +0 -1
  70. package/dist/development/context/createNonNullableContextFactory.cjs.map +0 -1
  71. package/dist/development/context/createNonNullableContextFactory.js.map +0 -1
  72. package/dist/development/context/createOptionalContextFactory.cjs +0 -13
  73. package/dist/development/context/createOptionalContextFactory.cjs.map +0 -1
  74. package/dist/development/context/createOptionalContextFactory.js +0 -13
  75. package/dist/development/context/createOptionalContextFactory.js.map +0 -1
  76. package/dist/development/hooks/useAddClassNameDuringResize.cjs +0 -32
  77. package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +0 -1
  78. package/dist/development/hooks/useAddClassNameDuringResize.js +0 -32
  79. package/dist/development/hooks/useAddClassNameDuringResize.js.map +0 -1
  80. package/dist/development/hooks/useCloseOnClickOutside.cjs +0 -25
  81. package/dist/development/hooks/useCloseOnClickOutside.cjs.map +0 -1
  82. package/dist/development/hooks/useCloseOnClickOutside.js +0 -25
  83. package/dist/development/hooks/useCloseOnClickOutside.js.map +0 -1
  84. package/dist/development/hooks/useCloseOnEscape.cjs +0 -20
  85. package/dist/development/hooks/useCloseOnEscape.cjs.map +0 -1
  86. package/dist/development/hooks/useCloseOnEscape.js +0 -20
  87. package/dist/development/hooks/useCloseOnEscape.js.map +0 -1
  88. package/dist/development/hooks/useContainerWidth.cjs +0 -14
  89. package/dist/development/hooks/useContainerWidth.cjs.map +0 -1
  90. package/dist/development/hooks/useContainerWidth.js +0 -14
  91. package/dist/development/hooks/useContainerWidth.js.map +0 -1
  92. package/dist/development/hooks/useElementSize.cjs +0 -37
  93. package/dist/development/hooks/useElementSize.cjs.map +0 -1
  94. package/dist/development/hooks/useElementSize.js +0 -37
  95. package/dist/development/hooks/useElementSize.js.map +0 -1
  96. package/dist/development/hooks/useElementTopOffset.cjs +0 -29
  97. package/dist/development/hooks/useElementTopOffset.cjs.map +0 -1
  98. package/dist/development/hooks/useElementTopOffset.js +0 -29
  99. package/dist/development/hooks/useElementTopOffset.js.map +0 -1
  100. package/dist/development/hooks/useEventHandler.cjs +0 -19
  101. package/dist/development/hooks/useEventHandler.cjs.map +0 -1
  102. package/dist/development/hooks/useEventHandler.js +0 -19
  103. package/dist/development/hooks/useEventHandler.js.map +0 -1
  104. package/dist/development/hooks/useOnElementMutation.cjs +0 -35
  105. package/dist/development/hooks/useOnElementMutation.cjs.map +0 -1
  106. package/dist/development/hooks/useOnElementMutation.js +0 -35
  107. package/dist/development/hooks/useOnElementMutation.js.map +0 -1
  108. package/dist/development/hooks/useOnScrollWithin.cjs +0 -52
  109. package/dist/development/hooks/useOnScrollWithin.cjs.map +0 -1
  110. package/dist/development/hooks/useOnScrollWithin.js +0 -52
  111. package/dist/development/hooks/useOnScrollWithin.js.map +0 -1
  112. package/dist/development/hooks/useScrollOffsets.cjs +0 -67
  113. package/dist/development/hooks/useScrollOffsets.cjs.map +0 -1
  114. package/dist/development/hooks/useScrollOffsets.js +0 -67
  115. package/dist/development/hooks/useScrollOffsets.js.map +0 -1
  116. package/dist/development/theming/ColorSchemeProvider.cjs +0 -16
  117. package/dist/development/theming/ColorSchemeProvider.cjs.map +0 -1
  118. package/dist/development/theming/ColorSchemeProvider.js +0 -16
  119. package/dist/development/theming/ColorSchemeProvider.js.map +0 -1
  120. package/dist/development/theming/GlobalClassNamePrefixContext.cjs +0 -6
  121. package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
  122. package/dist/development/theming/GlobalClassNamePrefixContext.js +0 -6
  123. package/dist/development/theming/GlobalClassNamePrefixContext.js.map +0 -1
  124. package/dist/development/theming/contexts.cjs +0 -12
  125. package/dist/development/theming/contexts.cjs.map +0 -1
  126. package/dist/development/theming/contexts.js +0 -12
  127. package/dist/development/theming/contexts.js.map +0 -1
  128. package/dist/development/theming/useClassName.cjs +0 -17
  129. package/dist/development/theming/useClassName.cjs.map +0 -1
  130. package/dist/development/theming/useClassName.js +0 -17
  131. package/dist/development/theming/useClassName.js.map +0 -1
  132. package/dist/development/theming/useClassNameFactory.cjs +0 -22
  133. package/dist/development/theming/useClassNameFactory.cjs.map +0 -1
  134. package/dist/development/theming/useClassNameFactory.js +0 -22
  135. package/dist/development/theming/useClassNameFactory.js.map +0 -1
  136. package/dist/development/theming/useThemedClassName.cjs +0 -17
  137. package/dist/development/theming/useThemedClassName.cjs.map +0 -1
  138. package/dist/development/theming/useThemedClassName.js +0 -17
  139. package/dist/development/theming/useThemedClassName.js.map +0 -1
  140. package/dist/development/theming/useThemedClassNameFactory.cjs +0 -29
  141. package/dist/development/theming/useThemedClassNameFactory.cjs.map +0 -1
  142. package/dist/development/theming/useThemedClassNameFactory.js +0 -29
  143. package/dist/development/theming/useThemedClassNameFactory.js.map +0 -1
  144. package/dist/production/context/createNonNullableContextFactory.cjs.map +0 -1
  145. package/dist/production/context/createNonNullableContextFactory.js.map +0 -1
  146. package/dist/production/context/createOptionalContextFactory.cjs +0 -13
  147. package/dist/production/context/createOptionalContextFactory.cjs.map +0 -1
  148. package/dist/production/context/createOptionalContextFactory.js +0 -13
  149. package/dist/production/context/createOptionalContextFactory.js.map +0 -1
  150. package/dist/production/hooks/useAddClassNameDuringResize.cjs +0 -32
  151. package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +0 -1
  152. package/dist/production/hooks/useAddClassNameDuringResize.js +0 -32
  153. package/dist/production/hooks/useAddClassNameDuringResize.js.map +0 -1
  154. package/dist/production/hooks/useCloseOnClickOutside.cjs +0 -25
  155. package/dist/production/hooks/useCloseOnClickOutside.cjs.map +0 -1
  156. package/dist/production/hooks/useCloseOnClickOutside.js +0 -25
  157. package/dist/production/hooks/useCloseOnClickOutside.js.map +0 -1
  158. package/dist/production/hooks/useCloseOnEscape.cjs +0 -20
  159. package/dist/production/hooks/useCloseOnEscape.cjs.map +0 -1
  160. package/dist/production/hooks/useCloseOnEscape.js +0 -20
  161. package/dist/production/hooks/useCloseOnEscape.js.map +0 -1
  162. package/dist/production/hooks/useContainerWidth.cjs +0 -14
  163. package/dist/production/hooks/useContainerWidth.cjs.map +0 -1
  164. package/dist/production/hooks/useContainerWidth.js +0 -14
  165. package/dist/production/hooks/useContainerWidth.js.map +0 -1
  166. package/dist/production/hooks/useElementSize.cjs +0 -37
  167. package/dist/production/hooks/useElementSize.cjs.map +0 -1
  168. package/dist/production/hooks/useElementSize.js +0 -37
  169. package/dist/production/hooks/useElementSize.js.map +0 -1
  170. package/dist/production/hooks/useElementTopOffset.cjs +0 -29
  171. package/dist/production/hooks/useElementTopOffset.cjs.map +0 -1
  172. package/dist/production/hooks/useElementTopOffset.js +0 -29
  173. package/dist/production/hooks/useElementTopOffset.js.map +0 -1
  174. package/dist/production/hooks/useEventHandler.cjs +0 -19
  175. package/dist/production/hooks/useEventHandler.cjs.map +0 -1
  176. package/dist/production/hooks/useEventHandler.js +0 -19
  177. package/dist/production/hooks/useEventHandler.js.map +0 -1
  178. package/dist/production/hooks/useOnElementMutation.cjs +0 -35
  179. package/dist/production/hooks/useOnElementMutation.cjs.map +0 -1
  180. package/dist/production/hooks/useOnElementMutation.js +0 -35
  181. package/dist/production/hooks/useOnElementMutation.js.map +0 -1
  182. package/dist/production/hooks/useOnScrollWithin.cjs +0 -52
  183. package/dist/production/hooks/useOnScrollWithin.cjs.map +0 -1
  184. package/dist/production/hooks/useOnScrollWithin.js +0 -52
  185. package/dist/production/hooks/useOnScrollWithin.js.map +0 -1
  186. package/dist/production/hooks/useScrollOffsets.cjs +0 -67
  187. package/dist/production/hooks/useScrollOffsets.cjs.map +0 -1
  188. package/dist/production/hooks/useScrollOffsets.js +0 -67
  189. package/dist/production/hooks/useScrollOffsets.js.map +0 -1
  190. package/dist/production/theming/ColorSchemeProvider.cjs +0 -12
  191. package/dist/production/theming/ColorSchemeProvider.cjs.map +0 -1
  192. package/dist/production/theming/ColorSchemeProvider.js +0 -12
  193. package/dist/production/theming/ColorSchemeProvider.js.map +0 -1
  194. package/dist/production/theming/GlobalClassNamePrefixContext.cjs +0 -6
  195. package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
  196. package/dist/production/theming/GlobalClassNamePrefixContext.js +0 -6
  197. package/dist/production/theming/GlobalClassNamePrefixContext.js.map +0 -1
  198. package/dist/production/theming/contexts.cjs +0 -12
  199. package/dist/production/theming/contexts.cjs.map +0 -1
  200. package/dist/production/theming/contexts.js +0 -12
  201. package/dist/production/theming/contexts.js.map +0 -1
  202. package/dist/production/theming/useClassName.cjs +0 -17
  203. package/dist/production/theming/useClassName.cjs.map +0 -1
  204. package/dist/production/theming/useClassName.js +0 -17
  205. package/dist/production/theming/useClassName.js.map +0 -1
  206. package/dist/production/theming/useClassNameFactory.cjs +0 -22
  207. package/dist/production/theming/useClassNameFactory.cjs.map +0 -1
  208. package/dist/production/theming/useClassNameFactory.js +0 -22
  209. package/dist/production/theming/useClassNameFactory.js.map +0 -1
  210. package/dist/production/theming/useThemedClassName.cjs +0 -17
  211. package/dist/production/theming/useThemedClassName.cjs.map +0 -1
  212. package/dist/production/theming/useThemedClassName.js +0 -17
  213. package/dist/production/theming/useThemedClassName.js.map +0 -1
  214. package/dist/production/theming/useThemedClassNameFactory.cjs +0 -29
  215. package/dist/production/theming/useThemedClassNameFactory.cjs.map +0 -1
  216. package/dist/production/theming/useThemedClassNameFactory.js +0 -29
  217. package/dist/production/theming/useThemedClassNameFactory.js.map +0 -1
  218. package/dist/types/context/createNonNullableContextFactory.d.ts +0 -3
  219. package/dist/types/context/createNonNullableContextFactory.d.ts.map +0 -1
  220. package/dist/types/context/createOptionalContextFactory.d.ts +0 -3
  221. package/dist/types/context/createOptionalContextFactory.d.ts.map +0 -1
  222. package/dist/types/hooks/useAddClassNameDuringResize.d.ts +0 -13
  223. package/dist/types/hooks/useAddClassNameDuringResize.d.ts.map +0 -1
  224. package/dist/types/hooks/useCloseOnClickOutside.d.ts +0 -7
  225. package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +0 -1
  226. package/dist/types/hooks/useCloseOnEscape.d.ts +0 -5
  227. package/dist/types/hooks/useCloseOnEscape.d.ts.map +0 -1
  228. package/dist/types/hooks/useContainerWidth.d.ts +0 -4
  229. package/dist/types/hooks/useContainerWidth.d.ts.map +0 -1
  230. package/dist/types/hooks/useElementSize.d.ts +0 -16
  231. package/dist/types/hooks/useElementSize.d.ts.map +0 -1
  232. package/dist/types/hooks/useElementTopOffset.d.ts +0 -3
  233. package/dist/types/hooks/useElementTopOffset.d.ts.map +0 -1
  234. package/dist/types/hooks/useEventHandler.d.ts +0 -10
  235. package/dist/types/hooks/useEventHandler.d.ts.map +0 -1
  236. package/dist/types/hooks/useOnElementMutation.d.ts +0 -3
  237. package/dist/types/hooks/useOnElementMutation.d.ts.map +0 -1
  238. package/dist/types/hooks/useOnScrollWithin.d.ts +0 -10
  239. package/dist/types/hooks/useOnScrollWithin.d.ts.map +0 -1
  240. package/dist/types/hooks/useScrollOffsets.d.ts +0 -14
  241. package/dist/types/hooks/useScrollOffsets.d.ts.map +0 -1
  242. package/dist/types/theming/ColorSchemeProvider.d.ts +0 -6
  243. package/dist/types/theming/ColorSchemeProvider.d.ts.map +0 -1
  244. package/dist/types/theming/GlobalClassNamePrefixContext.d.ts +0 -2
  245. package/dist/types/theming/GlobalClassNamePrefixContext.d.ts.map +0 -1
  246. package/dist/types/theming/contexts.d.ts +0 -12
  247. package/dist/types/theming/contexts.d.ts.map +0 -1
  248. package/dist/types/theming/index.d.ts +0 -8
  249. package/dist/types/theming/index.d.ts.map +0 -1
  250. package/dist/types/theming/useClassName.d.ts +0 -11
  251. package/dist/types/theming/useClassName.d.ts.map +0 -1
  252. package/dist/types/theming/useClassNameFactory.d.ts +0 -17
  253. package/dist/types/theming/useClassNameFactory.d.ts.map +0 -1
  254. package/dist/types/theming/useThemedClassName.d.ts +0 -39
  255. package/dist/types/theming/useThemedClassName.d.ts.map +0 -1
  256. package/dist/types/theming/useThemedClassNameFactory.d.ts +0 -3
  257. package/dist/types/theming/useThemedClassNameFactory.d.ts.map +0 -1
  258. package/src/context/createOptionalContextFactory.ts +0 -13
  259. package/src/hooks/useAddClassNameDuringResize.ts +0 -56
  260. package/src/hooks/useCloseOnClickOutside.ts +0 -27
  261. package/src/hooks/useCloseOnEscape.ts +0 -18
  262. package/src/hooks/useContainerWidth.ts +0 -13
  263. package/src/hooks/useElementSize.ts +0 -56
  264. package/src/hooks/useElementTopOffset.ts +0 -35
  265. package/src/hooks/useEventHandler.ts +0 -24
  266. package/src/hooks/useOnElementMutation.ts +0 -42
  267. package/src/hooks/useOnScrollWithin.ts +0 -68
  268. package/src/hooks/useScrollOffsets.ts +0 -87
  269. package/src/theming/ColorSchemeProvider.tsx +0 -16
  270. package/src/theming/GlobalClassNamePrefixContext.ts +0 -3
  271. package/src/theming/contexts.ts +0 -18
  272. package/src/theming/index.ts +0 -7
  273. package/src/theming/useClassName.ts +0 -28
  274. package/src/theming/useClassNameFactory.ts +0 -50
  275. package/src/theming/useThemedClassName.ts +0 -54
  276. package/src/theming/useThemedClassNameFactory.ts +0 -44
@@ -1,25 +1,18 @@
1
- import { createNonNullableContextFactory } from "./context/createNonNullableContextFactory.js";
2
- import { createOptionalContextFactory } from "./context/createOptionalContextFactory.js";
1
+ import { createRequiredContext } from "./context/createRequiredContext.js";
2
+ import { createContext } from "./context/createContext.js";
3
3
  import { isNoopScopedConsole, noopLog, noopLogged, noopScopedConsole } from "./debug-context/Constants.js";
4
4
  import { DebugChildren, ScopedConsoleContext, useScopedConsoleRef } from "./debug-context/Context.js";
5
5
  import { unwrapRefValue } from "./hooks/unwrapRefValue.js";
6
6
  import { useAbortController } from "./hooks/useAbortController.js";
7
- import { useAddClassNameDuringResize } from "./hooks/useAddClassNameDuringResize.js";
8
7
  import { useArrayMapMemo } from "./hooks/useArrayMapMemo.js";
9
8
  import { useAutoHeightTextArea } from "./hooks/useAutoHeightTextArea.js";
10
9
  import { getChildrenAsLabel, useChildrenAsLabel } from "./hooks/useChildrenAsLabel.js";
11
- import { useCloseOnClickOutside } from "./hooks/useCloseOnClickOutside.js";
12
- import { useCloseOnEscape } from "./hooks/useCloseOnEscape.js";
13
10
  import { useComposeRef } from "./hooks/useComposeRef.js";
14
11
  import { useConstantLengthInvariant } from "./hooks/useConstantLengthInvariant.js";
15
12
  import { useConstantValueInvariant } from "./hooks/useConstantValueInvariant.js";
16
- import { ContainerWidthContext, useContainerWidth } from "./hooks/useContainerWidth.js";
17
13
  import { useDebounce } from "./hooks/useDebounce.js";
18
14
  import { useDebounceCallback } from "./hooks/useDebounceCallback.js";
19
15
  import { useDocumentTitle } from "./hooks/useDocumentTitle.js";
20
- import { useElementSize } from "./hooks/useElementSize.js";
21
- import { useElementTopOffset } from "./hooks/useElementTopOffset.js";
22
- import { useEventHandler } from "./hooks/useEventHandler.js";
23
16
  import { useExpectSameValueReference } from "./hooks/useExpectSameValueReference.js";
24
17
  import { useForceRender } from "./hooks/useForceRender.js";
25
18
  import { useId } from "./hooks/useId.js";
@@ -27,13 +20,10 @@ import { useIsMounted } from "./hooks/useIsMounted.js";
27
20
  import { useObjectMemo } from "./hooks/useObjectMemo.js";
28
21
  import { useOnElementClickOutsideCallback } from "./hooks/useOnElementClickOutsideCallback.js";
29
22
  import { useOnElementMouseEnterDelayedCallback } from "./hooks/useOnElementMouseEnterDelayedCallback.js";
30
- import { useOnElementMutation } from "./hooks/useOnElementMutation.js";
31
23
  import { useOnElementResize } from "./hooks/useOnElementResize.js";
32
- import { useOnScrollWithin } from "./hooks/useOnScrollWithin.js";
33
24
  import { useOnWindowResize } from "./hooks/useOnWindowResize.js";
34
25
  import { usePreviousValue } from "./hooks/usePreviousValue.js";
35
- import { useScrollOffsets } from "./hooks/useScrollOffsets.js";
36
- import { useSessionStorageState } from "./hooks/useStoredState.js";
26
+ import { getStateStorage, localStateStorage, nullStorage, sessionStateStorage, urlStateStorage, useLocalStorageState, useSessionStorageState, useStoredState } from "./hooks/useStoredState.js";
37
27
  import { useUpdatedRef } from "./hooks/useUpdatedRef.js";
38
28
  import { useWindowSize } from "./hooks/useWindowSize.js";
39
29
  import { emptyArray } from "./referentiallyStable/emptyArray.js";
@@ -43,73 +33,53 @@ import { noop } from "./referentiallyStable/noop.js";
43
33
  import { returnFalse } from "./referentiallyStable/returnFalse.js";
44
34
  import { returnTrue } from "./referentiallyStable/returnTrue.js";
45
35
  import { useReferentiallyStableCallback } from "./referentiallyStable/useReferentiallyStableCallback.js";
46
- import { ColorSchemeProvider } from "./theming/ColorSchemeProvider.js";
47
- import { GlobalClassNamePrefixContext } from "./theming/GlobalClassNamePrefixContext.js";
48
- import { ColorSchemeContext, DEFAULT_COLOR_SCHEME, useColorScheme } from "./theming/contexts.js";
49
- import { useClassName } from "./theming/useClassName.js";
50
- import { useClassNameFactory } from "./theming/useClassNameFactory.js";
51
- import { useThemedClassName } from "./theming/useThemedClassName.js";
52
- import { useThemedClassNameFactory } from "./theming/useThemedClassNameFactory.js";
53
36
  export {
54
- ColorSchemeContext,
55
- ColorSchemeProvider,
56
- ContainerWidthContext,
57
- DEFAULT_COLOR_SCHEME,
58
37
  DebugChildren,
59
- GlobalClassNamePrefixContext,
60
38
  ScopedConsoleContext,
61
- createNonNullableContextFactory,
62
- createOptionalContextFactory,
39
+ createContext,
40
+ createRequiredContext,
63
41
  emptyArray,
64
42
  emptyObject,
65
43
  getChildrenAsLabel,
44
+ getStateStorage,
66
45
  identityFunction,
67
46
  isNoopScopedConsole,
47
+ localStateStorage,
68
48
  noop,
69
49
  noopLog,
70
50
  noopLogged,
71
51
  noopScopedConsole,
52
+ nullStorage,
72
53
  returnFalse,
73
54
  returnTrue,
55
+ sessionStateStorage,
74
56
  unwrapRefValue,
57
+ urlStateStorage,
75
58
  useAbortController,
76
- useAddClassNameDuringResize,
77
59
  useArrayMapMemo,
78
60
  useAutoHeightTextArea,
79
61
  useChildrenAsLabel,
80
- useClassName,
81
- useClassNameFactory,
82
- useCloseOnClickOutside,
83
- useCloseOnEscape,
84
- useColorScheme,
85
62
  useComposeRef,
86
63
  useConstantLengthInvariant,
87
64
  useConstantValueInvariant,
88
- useContainerWidth,
89
65
  useDebounce,
90
66
  useDebounceCallback,
91
67
  useDocumentTitle,
92
- useElementSize,
93
- useElementTopOffset,
94
- useEventHandler,
95
68
  useExpectSameValueReference,
96
69
  useForceRender,
97
70
  useId,
98
71
  useIsMounted,
72
+ useLocalStorageState,
99
73
  useObjectMemo,
100
74
  useOnElementClickOutsideCallback,
101
75
  useOnElementMouseEnterDelayedCallback,
102
- useOnElementMutation,
103
76
  useOnElementResize,
104
- useOnScrollWithin,
105
77
  useOnWindowResize,
106
78
  usePreviousValue,
107
79
  useReferentiallyStableCallback,
108
80
  useScopedConsoleRef,
109
- useScrollOffsets,
110
81
  useSessionStorageState,
111
- useThemedClassName,
112
- useThemedClassNameFactory,
82
+ useStoredState,
113
83
  useUpdatedRef,
114
84
  useWindowSize
115
85
  };
@@ -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,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ function createContext(name, initialValue) {
5
+ const OptionalContext = react.createContext(initialValue);
6
+ OptionalContext.displayName = name;
7
+ return [OptionalContext, () => react.useContext(OptionalContext)];
8
+ }
9
+ exports.createContext = createContext;
10
+ //# sourceMappingURL=createContext.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContext.cjs","sources":["../../../src/context/createContext.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext as baseCreateContext, useContext } from 'react'\n\nexport function createContext<T>(name: string, initialValue: T): [Context<T>, () => T] {\n const OptionalContext = baseCreateContext<T>(initialValue)\n OptionalContext.displayName = name\n\n return [OptionalContext, () => useContext(OptionalContext)]\n}\n"],"names":["baseCreateContext","useContext"],"mappings":";;;AAGgB,SAAA,cAAiB,MAAc,cAAwC;AAC/E,QAAA,kBAAkBA,oBAAqB,YAAY;AACzD,kBAAgB,cAAc;AAE9B,SAAO,CAAC,iBAAiB,MAAMC,iBAAW,eAAe,CAAC;AAC5D;;"}
@@ -0,0 +1,10 @@
1
+ import { createContext as createContext$1, useContext } from "react";
2
+ function createContext(name, initialValue) {
3
+ const OptionalContext = createContext$1(initialValue);
4
+ OptionalContext.displayName = name;
5
+ return [OptionalContext, () => useContext(OptionalContext)];
6
+ }
7
+ export {
8
+ createContext
9
+ };
10
+ //# sourceMappingURL=createContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContext.js","sources":["../../../src/context/createContext.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext as baseCreateContext, useContext } from 'react'\n\nexport function createContext<T>(name: string, initialValue: T): [Context<T>, () => T] {\n const OptionalContext = baseCreateContext<T>(initialValue)\n OptionalContext.displayName = name\n\n return [OptionalContext, () => useContext(OptionalContext)]\n}\n"],"names":["baseCreateContext"],"mappings":";AAGgB,SAAA,cAAiB,MAAc,cAAwC;AAC/E,QAAA,kBAAkBA,gBAAqB,YAAY;AACzD,kBAAgB,cAAc;AAE9B,SAAO,CAAC,iBAAiB,MAAM,WAAW,eAAe,CAAC;AAC5D;"}
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
- function createNonNullableContextFactory(displayName, initialValue) {
5
- const RequiredContext = react.createContext(initialValue ?? null);
4
+ const EmptyContextSymbol = Symbol("EmptyContextSymbol");
5
+ function createRequiredContext(displayName) {
6
+ const RequiredContext = react.createContext(EmptyContextSymbol);
6
7
  RequiredContext.displayName = displayName;
7
8
  const useRequiredContext = () => {
8
9
  const context = react.useContext(RequiredContext);
9
- if (context == null) {
10
+ if (context === EmptyContextSymbol) {
10
11
  throw new Error(`use${displayName} must be used within a ${displayName} provider`);
11
12
  }
12
13
  return context;
13
14
  };
14
15
  return [RequiredContext, useRequiredContext];
15
16
  }
16
- exports.createNonNullableContextFactory = createNonNullableContextFactory;
17
- //# sourceMappingURL=createNonNullableContextFactory.cjs.map
17
+ exports.createRequiredContext = createRequiredContext;
18
+ //# sourceMappingURL=createRequiredContext.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRequiredContext.cjs","sources":["../../../src/context/createRequiredContext.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nconst EmptyContextSymbol = Symbol('EmptyContextSymbol')\n\nexport function createRequiredContext<T>(displayName: string): [Context<T>, () => T] {\n const RequiredContext = createContext<T>(EmptyContextSymbol as T)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = (): T => {\n const context = useContext(RequiredContext)\n\n if (context === EmptyContextSymbol) {\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":";;;AAGA,MAAM,qBAAqB,OAAO,oBAAoB;AAE/C,SAAS,sBAAyB,aAA4C;AAC7E,QAAA,kBAAkBA,oBAAiB,kBAAuB;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAS;AAC5B,UAAA,UAAUC,iBAAW,eAAe;AAE1C,QAAI,YAAY,oBAAoB;AAClC,YAAM,IAAI,MAAM,MAAM,WAAW,0BAA0B,WAAW,WAAW;AAAA,IACnF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;;"}
@@ -1,10 +1,11 @@
1
1
  import { createContext, useContext } from "react";
2
- function createNonNullableContextFactory(displayName, initialValue) {
3
- const RequiredContext = createContext(initialValue ?? null);
2
+ const EmptyContextSymbol = Symbol("EmptyContextSymbol");
3
+ function createRequiredContext(displayName) {
4
+ const RequiredContext = createContext(EmptyContextSymbol);
4
5
  RequiredContext.displayName = displayName;
5
6
  const useRequiredContext = () => {
6
7
  const context = useContext(RequiredContext);
7
- if (context == null) {
8
+ if (context === EmptyContextSymbol) {
8
9
  throw new Error(`use${displayName} must be used within a ${displayName} provider`);
9
10
  }
10
11
  return context;
@@ -12,6 +13,6 @@ function createNonNullableContextFactory(displayName, initialValue) {
12
13
  return [RequiredContext, useRequiredContext];
13
14
  }
14
15
  export {
15
- createNonNullableContextFactory
16
+ createRequiredContext
16
17
  };
17
- //# sourceMappingURL=createNonNullableContextFactory.js.map
18
+ //# sourceMappingURL=createRequiredContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRequiredContext.js","sources":["../../../src/context/createRequiredContext.ts"],"sourcesContent":["import type { Context } from 'react'\nimport { createContext, useContext } from 'react'\n\nconst EmptyContextSymbol = Symbol('EmptyContextSymbol')\n\nexport function createRequiredContext<T>(displayName: string): [Context<T>, () => T] {\n const RequiredContext = createContext<T>(EmptyContextSymbol as T)\n RequiredContext.displayName = displayName\n\n const useRequiredContext = (): T => {\n const context = useContext(RequiredContext)\n\n if (context === EmptyContextSymbol) {\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":[],"mappings":";AAGA,MAAM,qBAAqB,OAAO,oBAAoB;AAE/C,SAAS,sBAAyB,aAA4C;AAC7E,QAAA,kBAAkB,cAAiB,kBAAuB;AAChE,kBAAgB,cAAc;AAE9B,QAAM,qBAAqB,MAAS;AAC5B,UAAA,UAAU,WAAW,eAAe;AAE1C,QAAI,YAAY,oBAAoB;AAClC,YAAM,IAAI,MAAM,MAAM,WAAW,0BAA0B,WAAW,WAAW;AAAA,IACnF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA,CAAC,iBAAiB,kBAAkB;AAC7C;"}
@@ -12,7 +12,7 @@ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
12
12
  ref.style.minHeight = "";
13
13
  ref.style.maxHeight = "";
14
14
  if (minRows2 !== maxRows2) {
15
- const height = ref.scrollHeight;
15
+ const height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight;
16
16
  let minHeight;
17
17
  let maxHeight;
18
18
  ref.rows = minRows2;
@@ -1 +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;;"}
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 - ref.clientHeight + ref.offsetHeight\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,eAAe,IAAI,eAAe,IAAI;AACrD,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;;"}
@@ -10,7 +10,7 @@ const useAutoHeightTextArea = (textAreaRef, value, minRows, maxRows) => {
10
10
  ref.style.minHeight = "";
11
11
  ref.style.maxHeight = "";
12
12
  if (minRows2 !== maxRows2) {
13
- const height = ref.scrollHeight;
13
+ const height = ref.scrollHeight - ref.clientHeight + ref.offsetHeight;
14
14
  let minHeight;
15
15
  let maxHeight;
16
16
  ref.rows = minRows2;
@@ -1 +1 @@
1
- {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(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":["minRows","maxRows"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,OAAO,KAAiCA,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,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
1
+ {"version":3,"file":"useAutoHeightTextArea.js","sources":["../../../src/hooks/useAutoHeightTextArea.ts"],"sourcesContent":["import { px } from '@contember/utilities'\nimport { useCallback, useLayoutEffect } from 'react'\nimport { RefObjectOrElement, unwrapRefValue } from './unwrapRefValue'\nimport { useOnElementResize } from './useOnElementResize'\n\nexport const useAutoHeightTextArea = (\n\ttextAreaRef: RefObjectOrElement<HTMLTextAreaElement>,\n\tvalue: string,\n\tminRows: number,\n\tmaxRows: number,\n) => {\n\tconst measure = useCallback(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 - ref.clientHeight + ref.offsetHeight\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":["minRows","maxRows"],"mappings":";;;;AAKO,MAAM,wBAAwB,CACpC,aACA,OACA,SACA,YACI;AACJ,QAAM,UAAU,YAAY,OAAO,KAAiCA,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,eAAe,IAAI,eAAe,IAAI;AACrD,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,SAAS,GAAG,MAAM;AACxB,YAAA,MAAM,YAAY,GAAG,SAAS;AAC9B,YAAA,MAAM,YAAY,GAAG,SAAS;AAAA,MACnC;AAEA,UAAI,OAAO;AAAA,IACZ;AAAA,EACD,GAAG,CAAE,CAAA;AAEL,qBAAmB,aAAa,MAAM;AACrC,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,CACrD;AAED,kBAAgB,MAAM;AACrB,YAAQ,eAAe,WAAW,GAAG,SAAS,OAAO;AAAA,EAAA,GACnD,CAAC,SAAS,SAAS,SAAS,aAAa,KAAK,CAAC;AACnD;"}
@@ -1,23 +1,100 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
- const createStoredStateHook = (getStorage) => {
5
- return (key, initializeValue) => {
6
- const storage = getStorage();
7
- const [value, setValue] = react.useState(() => {
8
- const value2 = storage.getItem(key);
9
- const parsedValue = value2 !== null ? JSON.parse(value2) : void 0;
10
- return initializeValue(parsedValue);
11
- });
12
- return [value, react.useCallback((value2) => {
4
+ const urlStateStorage = {
5
+ getItem(key) {
6
+ const searchParams = new URLSearchParams(window.location.search);
7
+ const value = searchParams.get(key[1]);
8
+ return value !== null && value !== void 0 ? JSON.parse(value) : null;
9
+ },
10
+ setItem(key, value) {
11
+ const searchParams = new URLSearchParams(window.location.search);
12
+ searchParams.set(key[1], JSON.stringify(value));
13
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
14
+ window.history.replaceState({}, "", newUrl);
15
+ }
16
+ };
17
+ const createStateStorageFromNativeStorage = (getStorage) => {
18
+ return {
19
+ getItem(key) {
20
+ const value = getStorage().getItem(key.join("-"));
21
+ return value !== null ? JSON.parse(value) : null;
22
+ },
23
+ setItem(key, value) {
24
+ getStorage().setItem(key.join("-"), JSON.stringify(value));
25
+ }
26
+ };
27
+ };
28
+ const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage);
29
+ const localStateStorage = createStateStorageFromNativeStorage(() => localStorage);
30
+ const nullStorage = {
31
+ getItem() {
32
+ return null;
33
+ },
34
+ setItem() {
35
+ }
36
+ };
37
+ const builtInStorages = {
38
+ url: urlStateStorage,
39
+ session: sessionStateStorage,
40
+ local: localStateStorage,
41
+ null: nullStorage
42
+ };
43
+ const useStoredState = (storageOrName, key, initializeValue) => {
44
+ const storage = react.useMemo(() => {
45
+ return getStateStorage(storageOrName);
46
+ }, [storageOrName]);
47
+ const [value, setValue] = react.useState(() => {
48
+ const value2 = storage.getItem(key);
49
+ return initializeValue(value2);
50
+ });
51
+ return [
52
+ value,
53
+ react.useCallback((value2) => {
13
54
  setValue((current) => {
14
55
  const newValue = typeof value2 === "function" ? value2(current) : value2;
15
- storage.setItem(key, JSON.stringify(newValue));
56
+ storage.setItem(key, newValue);
16
57
  return newValue;
17
58
  });
18
- }, [key, storage])];
59
+ }, [key, storage])
60
+ ];
61
+ };
62
+ const useSessionStorageState = (key, initializeValue) => {
63
+ return useStoredState(sessionStateStorage, key, initializeValue);
64
+ };
65
+ const useLocalStorageState = (key, initializeValue) => {
66
+ return useStoredState(localStateStorage, key, initializeValue);
67
+ };
68
+ const getStateStorage = (storageOrName) => {
69
+ if (Array.isArray(storageOrName)) {
70
+ return createFallbackStorage(storageOrName.map((it) => typeof it === "string" ? builtInStorages[it] : it));
71
+ }
72
+ return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
73
+ };
74
+ const createFallbackStorage = (storageTypes) => {
75
+ return {
76
+ getItem(key) {
77
+ for (const storage of storageTypes) {
78
+ const value = storage.getItem(key);
79
+ if (value !== null) {
80
+ return value;
81
+ }
82
+ }
83
+ return null;
84
+ },
85
+ setItem(key, value) {
86
+ for (const storage of storageTypes) {
87
+ storage.setItem(key, value);
88
+ }
89
+ }
19
90
  };
20
91
  };
21
- const useSessionStorageState = createStoredStateHook(() => sessionStorage);
92
+ exports.getStateStorage = getStateStorage;
93
+ exports.localStateStorage = localStateStorage;
94
+ exports.nullStorage = nullStorage;
95
+ exports.sessionStateStorage = sessionStateStorage;
96
+ exports.urlStateStorage = urlStateStorage;
97
+ exports.useLocalStorageState = useLocalStorageState;
22
98
  exports.useSessionStorageState = useSessionStorageState;
99
+ exports.useStoredState = useStoredState;
23
100
  //# sourceMappingURL=useStoredState.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStoredState.cjs","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nconst createStoredStateHook = (getStorage: () => Storage) => {\n\treturn <V extends Serializable>(key: string, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\t\tconst storage = getStorage()\n\t\tconst [value, setValue] = useState<V>(() => {\n\t\t\tconst value = storage.getItem(key)\n\t\t\tconst parsedValue: V | undefined = value !== null ? JSON.parse(value) : undefined\n\t\t\treturn initializeValue(parsedValue)\n\t\t})\n\t\treturn [value, useCallback(value => {\n\t\t\tsetValue(current => {\n\t\t\t\tconst newValue = typeof value === 'function' ? (value as (current: V) => V)(current) : value\n\t\t\t\tstorage.setItem(key, JSON.stringify(newValue))\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage])]\n\t}\n\n}\n\nexport const useSessionStorageState = createStoredStateHook(() => sessionStorage)\n"],"names":["useState","value","useCallback"],"mappings":";;;AAMA,MAAM,wBAAwB,CAAC,eAA8B;AACrD,SAAA,CAAyB,KAAa,oBAA2D;AACvG,UAAM,UAAU;AAChB,UAAM,CAAC,OAAO,QAAQ,IAAIA,eAAY,MAAM;AACrCC,YAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAM,cAA6BA,WAAU,OAAO,KAAK,MAAMA,MAAK,IAAI;AACxE,aAAO,gBAAgB,WAAW;AAAA,IAAA,CAClC;AACD,WAAO,CAAC,OAAOC,kBAAY,CAAAD,WAAS;AACnC,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AACvF,gBAAQ,QAAQ,KAAK,KAAK,UAAU,QAAQ,CAAC;AACtC,eAAA;AAAA,MAAA,CACP;AAAA,IACC,GAAA,CAAC,KAAK,OAAO,CAAC,CAAC;AAAA,EAAA;AAGpB;AAEa,MAAA,yBAAyB,sBAAsB,MAAM,cAAc;;"}
1
+ {"version":3,"file":"useStoredState.cjs","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type StateStorageKey = [uniquePrefix: string, key: string]\n\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nexport interface StateStorage {\n\tgetItem(key: StateStorageKey): Serializable\n\n\tsetItem(key: StateStorageKey, value: Serializable): void\n}\n\n\nexport const urlStateStorage: StateStorage = {\n\tgetItem(key) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tconst value = searchParams.get(key[1])\n\t\treturn value !== null && value !== undefined ? JSON.parse(value) : null\n\t},\n\tsetItem(key, value) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tsearchParams.set(key[1], JSON.stringify(value))\n\t\tconst newUrl = `${window.location.pathname}?${searchParams.toString()}`\n\t\twindow.history.replaceState({}, '', newUrl)\n\t},\n}\n\nconst createStateStorageFromNativeStorage = (getStorage: () => Storage): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tconst value = getStorage().getItem(key.join('-'))\n\t\t\treturn value !== null ? JSON.parse(value) : null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tgetStorage().setItem(key.join('-'), JSON.stringify(value))\n\t\t},\n\t}\n}\n\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorageFromNativeStorage(() => localStorage)\nexport const nullStorage: StateStorage = {\n\tgetItem() {\n\t\treturn null\n\t},\n\tsetItem() {\n\t},\n}\n\nconst builtInStorages = {\n\turl: urlStateStorage,\n\tsession: sessionStateStorage,\n\tlocal: localStateStorage,\n\tnull: nullStorage,\n}\n\nexport type StateStorageOrName = StateStorage | 'url' | 'session' | 'local' | 'null'\n\nexport const useStoredState = <V extends Serializable>(storageOrName: StateStorageOrName | StateStorageOrName[], key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\treturn getStateStorage(storageOrName)\n\t}, [storageOrName])\n\n\tconst [value, setValue] = useState<V>(() => {\n\t\tconst value = storage.getItem(key)\n\t\treturn initializeValue(value as V)\n\t})\n\treturn [\n\t\tvalue,\n\t\tuseCallback(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, newValue)\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage]),\n\t]\n}\n\nexport const useSessionStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(sessionStateStorage, key, initializeValue)\n}\n\nexport const useLocalStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(localStateStorage, key, initializeValue)\n}\n\nexport const getStateStorage = (storageOrName: StateStorageOrName | StateStorageOrName[]) => {\n\tif (Array.isArray(storageOrName)) {\n\t\treturn createFallbackStorage(storageOrName.map(it => typeof it === 'string' ? builtInStorages[it] : it))\n\t}\n\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : storageOrName\n}\n\n\nconst createFallbackStorage = (storageTypes: StateStorage[]): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tconst value = storage.getItem(key)\n\t\t\t\tif (value !== null) {\n\t\t\t\t\treturn value\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tstorage.setItem(key, value)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"names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-1,23 +1,100 @@
1
- import { useState, useCallback } from "react";
2
- const createStoredStateHook = (getStorage) => {
3
- return (key, initializeValue) => {
4
- const storage = getStorage();
5
- const [value, setValue] = useState(() => {
6
- const value2 = storage.getItem(key);
7
- const parsedValue = value2 !== null ? JSON.parse(value2) : void 0;
8
- return initializeValue(parsedValue);
9
- });
10
- return [value, useCallback((value2) => {
1
+ import { useMemo, useState, useCallback } from "react";
2
+ const urlStateStorage = {
3
+ getItem(key) {
4
+ const searchParams = new URLSearchParams(window.location.search);
5
+ const value = searchParams.get(key[1]);
6
+ return value !== null && value !== void 0 ? JSON.parse(value) : null;
7
+ },
8
+ setItem(key, value) {
9
+ const searchParams = new URLSearchParams(window.location.search);
10
+ searchParams.set(key[1], JSON.stringify(value));
11
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
12
+ window.history.replaceState({}, "", newUrl);
13
+ }
14
+ };
15
+ const createStateStorageFromNativeStorage = (getStorage) => {
16
+ return {
17
+ getItem(key) {
18
+ const value = getStorage().getItem(key.join("-"));
19
+ return value !== null ? JSON.parse(value) : null;
20
+ },
21
+ setItem(key, value) {
22
+ getStorage().setItem(key.join("-"), JSON.stringify(value));
23
+ }
24
+ };
25
+ };
26
+ const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage);
27
+ const localStateStorage = createStateStorageFromNativeStorage(() => localStorage);
28
+ const nullStorage = {
29
+ getItem() {
30
+ return null;
31
+ },
32
+ setItem() {
33
+ }
34
+ };
35
+ const builtInStorages = {
36
+ url: urlStateStorage,
37
+ session: sessionStateStorage,
38
+ local: localStateStorage,
39
+ null: nullStorage
40
+ };
41
+ const useStoredState = (storageOrName, key, initializeValue) => {
42
+ const storage = useMemo(() => {
43
+ return getStateStorage(storageOrName);
44
+ }, [storageOrName]);
45
+ const [value, setValue] = useState(() => {
46
+ const value2 = storage.getItem(key);
47
+ return initializeValue(value2);
48
+ });
49
+ return [
50
+ value,
51
+ useCallback((value2) => {
11
52
  setValue((current) => {
12
53
  const newValue = typeof value2 === "function" ? value2(current) : value2;
13
- storage.setItem(key, JSON.stringify(newValue));
54
+ storage.setItem(key, newValue);
14
55
  return newValue;
15
56
  });
16
- }, [key, storage])];
57
+ }, [key, storage])
58
+ ];
59
+ };
60
+ const useSessionStorageState = (key, initializeValue) => {
61
+ return useStoredState(sessionStateStorage, key, initializeValue);
62
+ };
63
+ const useLocalStorageState = (key, initializeValue) => {
64
+ return useStoredState(localStateStorage, key, initializeValue);
65
+ };
66
+ const getStateStorage = (storageOrName) => {
67
+ if (Array.isArray(storageOrName)) {
68
+ return createFallbackStorage(storageOrName.map((it) => typeof it === "string" ? builtInStorages[it] : it));
69
+ }
70
+ return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
71
+ };
72
+ const createFallbackStorage = (storageTypes) => {
73
+ return {
74
+ getItem(key) {
75
+ for (const storage of storageTypes) {
76
+ const value = storage.getItem(key);
77
+ if (value !== null) {
78
+ return value;
79
+ }
80
+ }
81
+ return null;
82
+ },
83
+ setItem(key, value) {
84
+ for (const storage of storageTypes) {
85
+ storage.setItem(key, value);
86
+ }
87
+ }
17
88
  };
18
89
  };
19
- const useSessionStorageState = createStoredStateHook(() => sessionStorage);
20
90
  export {
21
- useSessionStorageState
91
+ getStateStorage,
92
+ localStateStorage,
93
+ nullStorage,
94
+ sessionStateStorage,
95
+ urlStateStorage,
96
+ useLocalStorageState,
97
+ useSessionStorageState,
98
+ useStoredState
22
99
  };
23
100
  //# sourceMappingURL=useStoredState.js.map
@@ -1 +1 @@
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;"}
1
+ {"version":3,"file":"useStoredState.js","sources":["../../../src/hooks/useStoredState.ts"],"sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { Serializable } from '../types'\n\nexport type SetState<V extends Serializable> = (value: V | ((current: V) => V)) => void;\nexport type StateStorageKey = [uniquePrefix: string, key: string]\n\nexport type ValueInitializer<V extends Serializable> = (storedValue: V | undefined) => V;\n\nexport interface StateStorage {\n\tgetItem(key: StateStorageKey): Serializable\n\n\tsetItem(key: StateStorageKey, value: Serializable): void\n}\n\n\nexport const urlStateStorage: StateStorage = {\n\tgetItem(key) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tconst value = searchParams.get(key[1])\n\t\treturn value !== null && value !== undefined ? JSON.parse(value) : null\n\t},\n\tsetItem(key, value) {\n\t\tconst searchParams = new URLSearchParams(window.location.search)\n\t\tsearchParams.set(key[1], JSON.stringify(value))\n\t\tconst newUrl = `${window.location.pathname}?${searchParams.toString()}`\n\t\twindow.history.replaceState({}, '', newUrl)\n\t},\n}\n\nconst createStateStorageFromNativeStorage = (getStorage: () => Storage): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tconst value = getStorage().getItem(key.join('-'))\n\t\t\treturn value !== null ? JSON.parse(value) : null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tgetStorage().setItem(key.join('-'), JSON.stringify(value))\n\t\t},\n\t}\n}\n\nexport const sessionStateStorage = createStateStorageFromNativeStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorageFromNativeStorage(() => localStorage)\nexport const nullStorage: StateStorage = {\n\tgetItem() {\n\t\treturn null\n\t},\n\tsetItem() {\n\t},\n}\n\nconst builtInStorages = {\n\turl: urlStateStorage,\n\tsession: sessionStateStorage,\n\tlocal: localStateStorage,\n\tnull: nullStorage,\n}\n\nexport type StateStorageOrName = StateStorage | 'url' | 'session' | 'local' | 'null'\n\nexport const useStoredState = <V extends Serializable>(storageOrName: StateStorageOrName | StateStorageOrName[], key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\tconst storage = useMemo(() => {\n\t\treturn getStateStorage(storageOrName)\n\t}, [storageOrName])\n\n\tconst [value, setValue] = useState<V>(() => {\n\t\tconst value = storage.getItem(key)\n\t\treturn initializeValue(value as V)\n\t})\n\treturn [\n\t\tvalue,\n\t\tuseCallback(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, newValue)\n\t\t\t\treturn newValue\n\t\t\t})\n\t\t}, [key, storage]),\n\t]\n}\n\nexport const useSessionStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(sessionStateStorage, key, initializeValue)\n}\n\nexport const useLocalStorageState = <V extends Serializable>(key: StateStorageKey, initializeValue: ValueInitializer<V>): [V, SetState<V>] => {\n\treturn useStoredState<V>(localStateStorage, key, initializeValue)\n}\n\nexport const getStateStorage = (storageOrName: StateStorageOrName | StateStorageOrName[]) => {\n\tif (Array.isArray(storageOrName)) {\n\t\treturn createFallbackStorage(storageOrName.map(it => typeof it === 'string' ? builtInStorages[it] : it))\n\t}\n\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : storageOrName\n}\n\n\nconst createFallbackStorage = (storageTypes: StateStorage[]): StateStorage => {\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tconst value = storage.getItem(key)\n\t\t\t\tif (value !== null) {\n\t\t\t\t\treturn value\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null\n\t\t},\n\t\tsetItem(key, value) {\n\t\t\tfor (const storage of storageTypes) {\n\t\t\t\tstorage.setItem(key, value)\n\t\t\t}\n\t\t},\n\t}\n}\n"],"names":["value"],"mappings":";AAeO,MAAM,kBAAgC;AAAA,EAC5C,QAAQ,KAAK;AACZ,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,UAAM,QAAQ,aAAa,IAAI,IAAI,CAAC,CAAC;AACrC,WAAO,UAAU,QAAQ,UAAU,SAAY,KAAK,MAAM,KAAK,IAAI;AAAA,EACpE;AAAA,EACA,QAAQ,KAAK,OAAO;AACnB,UAAM,eAAe,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAC/D,iBAAa,IAAI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