@contember/react-utils 1.3.0-alpha.9 → 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.
- package/dist/development/context/createContext.cjs +10 -0
- package/dist/development/context/createContext.cjs.map +1 -0
- package/dist/development/context/createContext.js +10 -0
- package/dist/development/context/createContext.js.map +1 -0
- package/dist/development/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
- package/dist/development/context/createRequiredContext.cjs.map +1 -0
- package/dist/development/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
- package/dist/development/context/createRequiredContext.js.map +1 -0
- package/dist/development/hooks/useAutoHeightTextArea.cjs +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.js +1 -1
- package/dist/development/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/development/hooks/useStoredState.cjs +89 -12
- package/dist/development/hooks/useStoredState.cjs.map +1 -1
- package/dist/development/hooks/useStoredState.js +91 -14
- package/dist/development/hooks/useStoredState.js.map +1 -1
- package/dist/development/index.cjs +11 -41
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +12 -42
- package/dist/development/index.js.map +1 -1
- package/dist/production/context/createContext.cjs +10 -0
- package/dist/production/context/createContext.cjs.map +1 -0
- package/dist/production/context/createContext.js +10 -0
- package/dist/production/context/createContext.js.map +1 -0
- package/dist/production/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs} +6 -5
- package/dist/production/context/createRequiredContext.cjs.map +1 -0
- package/dist/production/context/{createNonNullableContextFactory.js → createRequiredContext.js} +6 -5
- package/dist/production/context/createRequiredContext.js.map +1 -0
- package/dist/production/hooks/useAutoHeightTextArea.cjs +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.cjs.map +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.js +1 -1
- package/dist/production/hooks/useAutoHeightTextArea.js.map +1 -1
- package/dist/production/hooks/useStoredState.cjs +89 -12
- package/dist/production/hooks/useStoredState.cjs.map +1 -1
- package/dist/production/hooks/useStoredState.js +91 -14
- package/dist/production/hooks/useStoredState.js.map +1 -1
- package/dist/production/index.cjs +11 -41
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +12 -42
- package/dist/production/index.js.map +1 -1
- package/dist/types/context/createContext.d.ts +3 -0
- package/dist/types/context/createContext.d.ts.map +1 -0
- package/dist/types/context/createRequiredContext.d.ts +3 -0
- package/dist/types/context/createRequiredContext.d.ts.map +1 -0
- package/dist/types/context/index.d.ts +2 -2
- package/dist/types/context/index.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +0 -10
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useArrayMapMemo.d.ts.map +1 -1
- package/dist/types/hooks/useConstantLengthInvariant.d.ts.map +1 -1
- package/dist/types/hooks/useConstantValueInvariant.d.ts.map +1 -1
- package/dist/types/hooks/useDebounce.d.ts.map +1 -1
- package/dist/types/hooks/useObjectMemo.d.ts.map +1 -1
- package/dist/types/hooks/usePreviousValue.d.ts.map +1 -1
- package/dist/types/hooks/useStoredState.d.ts +14 -1
- package/dist/types/hooks/useStoredState.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/referentiallyStable/identityFunction.d.ts.map +1 -1
- package/dist/types/referentiallyStable/useReferentiallyStableCallback.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/context/createContext.ts +9 -0
- package/src/context/{createNonNullableContextFactory.ts → createRequiredContext.ts} +6 -4
- package/src/context/index.ts +2 -2
- package/src/hooks/index.ts +0 -10
- package/src/hooks/useAutoHeightTextArea.ts +1 -1
- package/src/hooks/useStoredState.ts +103 -14
- package/src/index.ts +0 -1
- package/dist/development/context/createNonNullableContextFactory.cjs.map +0 -1
- package/dist/development/context/createNonNullableContextFactory.js.map +0 -1
- package/dist/development/context/createOptionalContextFactory.cjs +0 -13
- package/dist/development/context/createOptionalContextFactory.cjs.map +0 -1
- package/dist/development/context/createOptionalContextFactory.js +0 -13
- package/dist/development/context/createOptionalContextFactory.js.map +0 -1
- package/dist/development/hooks/useAddClassNameDuringResize.cjs +0 -32
- package/dist/development/hooks/useAddClassNameDuringResize.cjs.map +0 -1
- package/dist/development/hooks/useAddClassNameDuringResize.js +0 -32
- package/dist/development/hooks/useAddClassNameDuringResize.js.map +0 -1
- package/dist/development/hooks/useCloseOnClickOutside.cjs +0 -25
- package/dist/development/hooks/useCloseOnClickOutside.cjs.map +0 -1
- package/dist/development/hooks/useCloseOnClickOutside.js +0 -25
- package/dist/development/hooks/useCloseOnClickOutside.js.map +0 -1
- package/dist/development/hooks/useCloseOnEscape.cjs +0 -20
- package/dist/development/hooks/useCloseOnEscape.cjs.map +0 -1
- package/dist/development/hooks/useCloseOnEscape.js +0 -20
- package/dist/development/hooks/useCloseOnEscape.js.map +0 -1
- package/dist/development/hooks/useContainerWidth.cjs +0 -14
- package/dist/development/hooks/useContainerWidth.cjs.map +0 -1
- package/dist/development/hooks/useContainerWidth.js +0 -14
- package/dist/development/hooks/useContainerWidth.js.map +0 -1
- package/dist/development/hooks/useElementSize.cjs +0 -37
- package/dist/development/hooks/useElementSize.cjs.map +0 -1
- package/dist/development/hooks/useElementSize.js +0 -37
- package/dist/development/hooks/useElementSize.js.map +0 -1
- package/dist/development/hooks/useElementTopOffset.cjs +0 -29
- package/dist/development/hooks/useElementTopOffset.cjs.map +0 -1
- package/dist/development/hooks/useElementTopOffset.js +0 -29
- package/dist/development/hooks/useElementTopOffset.js.map +0 -1
- package/dist/development/hooks/useEventHandler.cjs +0 -19
- package/dist/development/hooks/useEventHandler.cjs.map +0 -1
- package/dist/development/hooks/useEventHandler.js +0 -19
- package/dist/development/hooks/useEventHandler.js.map +0 -1
- package/dist/development/hooks/useOnElementMutation.cjs +0 -35
- package/dist/development/hooks/useOnElementMutation.cjs.map +0 -1
- package/dist/development/hooks/useOnElementMutation.js +0 -35
- package/dist/development/hooks/useOnElementMutation.js.map +0 -1
- package/dist/development/hooks/useOnScrollWithin.cjs +0 -52
- package/dist/development/hooks/useOnScrollWithin.cjs.map +0 -1
- package/dist/development/hooks/useOnScrollWithin.js +0 -52
- package/dist/development/hooks/useOnScrollWithin.js.map +0 -1
- package/dist/development/hooks/useScrollOffsets.cjs +0 -67
- package/dist/development/hooks/useScrollOffsets.cjs.map +0 -1
- package/dist/development/hooks/useScrollOffsets.js +0 -67
- package/dist/development/hooks/useScrollOffsets.js.map +0 -1
- package/dist/development/theming/ColorSchemeProvider.cjs +0 -16
- package/dist/development/theming/ColorSchemeProvider.cjs.map +0 -1
- package/dist/development/theming/ColorSchemeProvider.js +0 -16
- package/dist/development/theming/ColorSchemeProvider.js.map +0 -1
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs +0 -6
- package/dist/development/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
- package/dist/development/theming/GlobalClassNamePrefixContext.js +0 -6
- package/dist/development/theming/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/development/theming/contexts.cjs +0 -12
- package/dist/development/theming/contexts.cjs.map +0 -1
- package/dist/development/theming/contexts.js +0 -12
- package/dist/development/theming/contexts.js.map +0 -1
- package/dist/development/theming/useClassName.cjs +0 -17
- package/dist/development/theming/useClassName.cjs.map +0 -1
- package/dist/development/theming/useClassName.js +0 -17
- package/dist/development/theming/useClassName.js.map +0 -1
- package/dist/development/theming/useClassNameFactory.cjs +0 -22
- package/dist/development/theming/useClassNameFactory.cjs.map +0 -1
- package/dist/development/theming/useClassNameFactory.js +0 -22
- package/dist/development/theming/useClassNameFactory.js.map +0 -1
- package/dist/development/theming/useThemedClassName.cjs +0 -17
- package/dist/development/theming/useThemedClassName.cjs.map +0 -1
- package/dist/development/theming/useThemedClassName.js +0 -17
- package/dist/development/theming/useThemedClassName.js.map +0 -1
- package/dist/development/theming/useThemedClassNameFactory.cjs +0 -29
- package/dist/development/theming/useThemedClassNameFactory.cjs.map +0 -1
- package/dist/development/theming/useThemedClassNameFactory.js +0 -29
- package/dist/development/theming/useThemedClassNameFactory.js.map +0 -1
- package/dist/production/context/createNonNullableContextFactory.cjs.map +0 -1
- package/dist/production/context/createNonNullableContextFactory.js.map +0 -1
- package/dist/production/context/createOptionalContextFactory.cjs +0 -13
- package/dist/production/context/createOptionalContextFactory.cjs.map +0 -1
- package/dist/production/context/createOptionalContextFactory.js +0 -13
- package/dist/production/context/createOptionalContextFactory.js.map +0 -1
- package/dist/production/hooks/useAddClassNameDuringResize.cjs +0 -32
- package/dist/production/hooks/useAddClassNameDuringResize.cjs.map +0 -1
- package/dist/production/hooks/useAddClassNameDuringResize.js +0 -32
- package/dist/production/hooks/useAddClassNameDuringResize.js.map +0 -1
- package/dist/production/hooks/useCloseOnClickOutside.cjs +0 -25
- package/dist/production/hooks/useCloseOnClickOutside.cjs.map +0 -1
- package/dist/production/hooks/useCloseOnClickOutside.js +0 -25
- package/dist/production/hooks/useCloseOnClickOutside.js.map +0 -1
- package/dist/production/hooks/useCloseOnEscape.cjs +0 -20
- package/dist/production/hooks/useCloseOnEscape.cjs.map +0 -1
- package/dist/production/hooks/useCloseOnEscape.js +0 -20
- package/dist/production/hooks/useCloseOnEscape.js.map +0 -1
- package/dist/production/hooks/useContainerWidth.cjs +0 -14
- package/dist/production/hooks/useContainerWidth.cjs.map +0 -1
- package/dist/production/hooks/useContainerWidth.js +0 -14
- package/dist/production/hooks/useContainerWidth.js.map +0 -1
- package/dist/production/hooks/useElementSize.cjs +0 -37
- package/dist/production/hooks/useElementSize.cjs.map +0 -1
- package/dist/production/hooks/useElementSize.js +0 -37
- package/dist/production/hooks/useElementSize.js.map +0 -1
- package/dist/production/hooks/useElementTopOffset.cjs +0 -29
- package/dist/production/hooks/useElementTopOffset.cjs.map +0 -1
- package/dist/production/hooks/useElementTopOffset.js +0 -29
- package/dist/production/hooks/useElementTopOffset.js.map +0 -1
- package/dist/production/hooks/useEventHandler.cjs +0 -19
- package/dist/production/hooks/useEventHandler.cjs.map +0 -1
- package/dist/production/hooks/useEventHandler.js +0 -19
- package/dist/production/hooks/useEventHandler.js.map +0 -1
- package/dist/production/hooks/useOnElementMutation.cjs +0 -35
- package/dist/production/hooks/useOnElementMutation.cjs.map +0 -1
- package/dist/production/hooks/useOnElementMutation.js +0 -35
- package/dist/production/hooks/useOnElementMutation.js.map +0 -1
- package/dist/production/hooks/useOnScrollWithin.cjs +0 -52
- package/dist/production/hooks/useOnScrollWithin.cjs.map +0 -1
- package/dist/production/hooks/useOnScrollWithin.js +0 -52
- package/dist/production/hooks/useOnScrollWithin.js.map +0 -1
- package/dist/production/hooks/useScrollOffsets.cjs +0 -67
- package/dist/production/hooks/useScrollOffsets.cjs.map +0 -1
- package/dist/production/hooks/useScrollOffsets.js +0 -67
- package/dist/production/hooks/useScrollOffsets.js.map +0 -1
- package/dist/production/theming/ColorSchemeProvider.cjs +0 -12
- package/dist/production/theming/ColorSchemeProvider.cjs.map +0 -1
- package/dist/production/theming/ColorSchemeProvider.js +0 -12
- package/dist/production/theming/ColorSchemeProvider.js.map +0 -1
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs +0 -6
- package/dist/production/theming/GlobalClassNamePrefixContext.cjs.map +0 -1
- package/dist/production/theming/GlobalClassNamePrefixContext.js +0 -6
- package/dist/production/theming/GlobalClassNamePrefixContext.js.map +0 -1
- package/dist/production/theming/contexts.cjs +0 -12
- package/dist/production/theming/contexts.cjs.map +0 -1
- package/dist/production/theming/contexts.js +0 -12
- package/dist/production/theming/contexts.js.map +0 -1
- package/dist/production/theming/useClassName.cjs +0 -17
- package/dist/production/theming/useClassName.cjs.map +0 -1
- package/dist/production/theming/useClassName.js +0 -17
- package/dist/production/theming/useClassName.js.map +0 -1
- package/dist/production/theming/useClassNameFactory.cjs +0 -22
- package/dist/production/theming/useClassNameFactory.cjs.map +0 -1
- package/dist/production/theming/useClassNameFactory.js +0 -22
- package/dist/production/theming/useClassNameFactory.js.map +0 -1
- package/dist/production/theming/useThemedClassName.cjs +0 -17
- package/dist/production/theming/useThemedClassName.cjs.map +0 -1
- package/dist/production/theming/useThemedClassName.js +0 -17
- package/dist/production/theming/useThemedClassName.js.map +0 -1
- package/dist/production/theming/useThemedClassNameFactory.cjs +0 -29
- package/dist/production/theming/useThemedClassNameFactory.cjs.map +0 -1
- package/dist/production/theming/useThemedClassNameFactory.js +0 -29
- package/dist/production/theming/useThemedClassNameFactory.js.map +0 -1
- package/dist/types/context/createNonNullableContextFactory.d.ts +0 -3
- package/dist/types/context/createNonNullableContextFactory.d.ts.map +0 -1
- package/dist/types/context/createOptionalContextFactory.d.ts +0 -3
- package/dist/types/context/createOptionalContextFactory.d.ts.map +0 -1
- package/dist/types/hooks/useAddClassNameDuringResize.d.ts +0 -13
- package/dist/types/hooks/useAddClassNameDuringResize.d.ts.map +0 -1
- package/dist/types/hooks/useCloseOnClickOutside.d.ts +0 -7
- package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +0 -1
- package/dist/types/hooks/useCloseOnEscape.d.ts +0 -5
- package/dist/types/hooks/useCloseOnEscape.d.ts.map +0 -1
- package/dist/types/hooks/useContainerWidth.d.ts +0 -4
- package/dist/types/hooks/useContainerWidth.d.ts.map +0 -1
- package/dist/types/hooks/useElementSize.d.ts +0 -16
- package/dist/types/hooks/useElementSize.d.ts.map +0 -1
- package/dist/types/hooks/useElementTopOffset.d.ts +0 -3
- package/dist/types/hooks/useElementTopOffset.d.ts.map +0 -1
- package/dist/types/hooks/useEventHandler.d.ts +0 -10
- package/dist/types/hooks/useEventHandler.d.ts.map +0 -1
- package/dist/types/hooks/useOnElementMutation.d.ts +0 -3
- package/dist/types/hooks/useOnElementMutation.d.ts.map +0 -1
- package/dist/types/hooks/useOnScrollWithin.d.ts +0 -10
- package/dist/types/hooks/useOnScrollWithin.d.ts.map +0 -1
- package/dist/types/hooks/useScrollOffsets.d.ts +0 -14
- package/dist/types/hooks/useScrollOffsets.d.ts.map +0 -1
- package/dist/types/theming/ColorSchemeProvider.d.ts +0 -6
- package/dist/types/theming/ColorSchemeProvider.d.ts.map +0 -1
- package/dist/types/theming/GlobalClassNamePrefixContext.d.ts +0 -2
- package/dist/types/theming/GlobalClassNamePrefixContext.d.ts.map +0 -1
- package/dist/types/theming/contexts.d.ts +0 -12
- package/dist/types/theming/contexts.d.ts.map +0 -1
- package/dist/types/theming/index.d.ts +0 -8
- package/dist/types/theming/index.d.ts.map +0 -1
- package/dist/types/theming/useClassName.d.ts +0 -11
- package/dist/types/theming/useClassName.d.ts.map +0 -1
- package/dist/types/theming/useClassNameFactory.d.ts +0 -17
- package/dist/types/theming/useClassNameFactory.d.ts.map +0 -1
- package/dist/types/theming/useThemedClassName.d.ts +0 -39
- package/dist/types/theming/useThemedClassName.d.ts.map +0 -1
- package/dist/types/theming/useThemedClassNameFactory.d.ts +0 -3
- package/dist/types/theming/useThemedClassNameFactory.d.ts.map +0 -1
- package/src/context/createOptionalContextFactory.ts +0 -13
- package/src/hooks/useAddClassNameDuringResize.ts +0 -56
- package/src/hooks/useCloseOnClickOutside.ts +0 -27
- package/src/hooks/useCloseOnEscape.ts +0 -18
- package/src/hooks/useContainerWidth.ts +0 -13
- package/src/hooks/useElementSize.ts +0 -56
- package/src/hooks/useElementTopOffset.ts +0 -35
- package/src/hooks/useEventHandler.ts +0 -24
- package/src/hooks/useOnElementMutation.ts +0 -42
- package/src/hooks/useOnScrollWithin.ts +0 -68
- package/src/hooks/useScrollOffsets.ts +0 -87
- package/src/theming/ColorSchemeProvider.tsx +0 -16
- package/src/theming/GlobalClassNamePrefixContext.ts +0 -3
- package/src/theming/contexts.ts +0 -18
- package/src/theming/index.ts +0 -7
- package/src/theming/useClassName.ts +0 -28
- package/src/theming/useClassNameFactory.ts +0 -50
- package/src/theming/useThemedClassName.ts +0 -54
- package/src/theming/useThemedClassNameFactory.ts +0 -44
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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;"}
|
package/dist/production/context/{createNonNullableContextFactory.cjs → createRequiredContext.cjs}
RENAMED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const react = require("react");
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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.
|
|
17
|
-
//# sourceMappingURL=
|
|
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;;"}
|
package/dist/production/context/{createNonNullableContextFactory.js → createRequiredContext.js}
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createContext, useContext } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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
|
-
|
|
16
|
+
createRequiredContext
|
|
16
17
|
};
|
|
17
|
-
//# sourceMappingURL=
|
|
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;
|
|
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;
|
|
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
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
|
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":["useMemo","useState","value","useCallback"],"mappings":"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"}
|
|
@@ -1,23 +1,100 @@
|
|
|
1
|
-
import { useState, useCallback } from "react";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
|
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":"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"}
|