@contember/react-utils 1.3.0-alpha.2 → 1.3.0-alpha.21
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/debug-context/Context.cjs +4 -3
- package/dist/development/debug-context/Context.cjs.map +1 -1
- package/dist/development/debug-context/Context.js +4 -3
- package/dist/development/debug-context/Context.js.map +1 -1
- 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/useCloseOnClickOutside.cjs +25 -0
- package/dist/development/hooks/useCloseOnClickOutside.cjs.map +1 -0
- package/dist/development/hooks/useCloseOnClickOutside.js +25 -0
- package/dist/development/hooks/useCloseOnClickOutside.js.map +1 -0
- package/dist/development/hooks/useCloseOnEscape.cjs +20 -0
- package/dist/development/hooks/useCloseOnEscape.cjs.map +1 -0
- package/dist/development/hooks/useCloseOnEscape.js +20 -0
- package/dist/development/hooks/useCloseOnEscape.js.map +1 -0
- package/dist/development/hooks/useConstantLengthInvariant.cjs.map +1 -1
- package/dist/development/hooks/useConstantLengthInvariant.js.map +1 -1
- package/dist/development/hooks/useConstantValueInvariant.cjs.map +1 -1
- package/dist/development/hooks/useConstantValueInvariant.js.map +1 -1
- package/dist/development/hooks/useId.cjs.map +1 -1
- package/dist/development/hooks/useId.js.map +1 -1
- package/dist/development/hooks/useStoredState.cjs +86 -12
- package/dist/development/hooks/useStoredState.cjs.map +1 -1
- package/dist/development/hooks/useStoredState.js +88 -14
- package/dist/development/hooks/useStoredState.js.map +1 -1
- package/dist/development/index.cjs +14 -4
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +15 -5
- package/dist/development/index.js.map +1 -1
- package/dist/development/theming/ColorSchemeProvider.cjs +8 -10
- package/dist/development/theming/ColorSchemeProvider.cjs.map +1 -1
- package/dist/development/theming/ColorSchemeProvider.js +8 -10
- package/dist/development/theming/ColorSchemeProvider.js.map +1 -1
- package/dist/development/theming/contexts.cjs +2 -2
- package/dist/development/theming/contexts.cjs.map +1 -1
- package/dist/development/theming/contexts.js +2 -2
- package/dist/development/theming/contexts.js.map +1 -1
- package/dist/development/theming/useClassName.cjs.map +1 -1
- package/dist/development/theming/useClassName.js.map +1 -1
- package/dist/development/theming/useClassNameFactory.cjs.map +1 -1
- package/dist/development/theming/useClassNameFactory.js.map +1 -1
- package/dist/development/theming/useThemedClassNameFactory.cjs.map +1 -1
- package/dist/development/theming/useThemedClassNameFactory.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/debug-context/Context.cjs +3 -2
- package/dist/production/debug-context/Context.cjs.map +1 -1
- package/dist/production/debug-context/Context.js +3 -2
- package/dist/production/debug-context/Context.js.map +1 -1
- 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/useChildrenAsLabel.cjs.map +1 -1
- package/dist/production/hooks/useChildrenAsLabel.js.map +1 -1
- package/dist/production/hooks/useCloseOnClickOutside.cjs +25 -0
- package/dist/production/hooks/useCloseOnClickOutside.cjs.map +1 -0
- package/dist/production/hooks/useCloseOnClickOutside.js +25 -0
- package/dist/production/hooks/useCloseOnClickOutside.js.map +1 -0
- package/dist/production/hooks/useCloseOnEscape.cjs +20 -0
- package/dist/production/hooks/useCloseOnEscape.cjs.map +1 -0
- package/dist/production/hooks/useCloseOnEscape.js +20 -0
- package/dist/production/hooks/useCloseOnEscape.js.map +1 -0
- package/dist/production/hooks/useId.cjs.map +1 -1
- package/dist/production/hooks/useId.js.map +1 -1
- package/dist/production/hooks/useStoredState.cjs +86 -12
- package/dist/production/hooks/useStoredState.cjs.map +1 -1
- package/dist/production/hooks/useStoredState.js +88 -14
- package/dist/production/hooks/useStoredState.js.map +1 -1
- package/dist/production/index.cjs +14 -4
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +15 -5
- package/dist/production/index.js.map +1 -1
- package/dist/production/theming/ColorSchemeProvider.cjs +4 -6
- package/dist/production/theming/ColorSchemeProvider.cjs.map +1 -1
- package/dist/production/theming/ColorSchemeProvider.js +4 -6
- package/dist/production/theming/ColorSchemeProvider.js.map +1 -1
- package/dist/production/theming/contexts.cjs +2 -2
- package/dist/production/theming/contexts.cjs.map +1 -1
- package/dist/production/theming/contexts.js +2 -2
- package/dist/production/theming/contexts.js.map +1 -1
- package/dist/production/theming/useClassName.cjs.map +1 -1
- package/dist/production/theming/useClassName.js.map +1 -1
- package/dist/production/theming/useClassNameFactory.cjs.map +1 -1
- package/dist/production/theming/useClassNameFactory.js.map +1 -1
- package/dist/production/theming/useThemedClassNameFactory.cjs.map +1 -1
- package/dist/production/theming/useThemedClassNameFactory.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/debug-context/Context.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useCloseOnClickOutside.d.ts +7 -0
- package/dist/types/hooks/useCloseOnClickOutside.d.ts.map +1 -0
- package/dist/types/hooks/useCloseOnEscape.d.ts +5 -0
- package/dist/types/hooks/useCloseOnEscape.d.ts.map +1 -0
- package/dist/types/hooks/useStoredState.d.ts +13 -1
- package/dist/types/hooks/useStoredState.d.ts.map +1 -1
- package/dist/types/theming/ColorSchemeProvider.d.ts +3 -4
- package/dist/types/theming/ColorSchemeProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- 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/debug-context/Context.tsx +3 -3
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useAutoHeightTextArea.ts +1 -1
- package/src/hooks/useCloseOnClickOutside.ts +27 -0
- package/src/hooks/useCloseOnEscape.ts +18 -0
- package/src/hooks/useStoredState.ts +100 -14
- package/src/theming/ColorSchemeProvider.tsx +8 -11
- package/src/theming/contexts.ts +2 -2
- 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/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/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/src/context/createOptionalContextFactory.ts +0 -13
|
@@ -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/development/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/development/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;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxDevRuntime = require("react/jsx-dev-runtime");
|
|
4
|
-
const utilities = require("@contember/utilities");
|
|
5
4
|
const react = require("react");
|
|
6
5
|
const Constants = require("./Constants.cjs");
|
|
7
6
|
function createPrefixedConsole(message, prefixedConsole) {
|
|
@@ -42,7 +41,9 @@ function parentScopedConsoleOrNone(parentConsole) {
|
|
|
42
41
|
return Constants.isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
|
|
43
42
|
}
|
|
44
43
|
const useScopedConsoleRef = (prefix, override) => {
|
|
45
|
-
|
|
44
|
+
if (prefix.length === 0) {
|
|
45
|
+
throw new Error("Prefix must be non-empty string");
|
|
46
|
+
}
|
|
46
47
|
const parentConsole = parentScopedConsoleOrNone(react.useContext(ScopedConsoleContext));
|
|
47
48
|
const scopedConsole = react.useMemo(() => {
|
|
48
49
|
if (override !== false && (parentConsole || override)) {
|
|
@@ -62,7 +63,7 @@ const DebugChildren = react.memo(({ active = true, children, id }) => {
|
|
|
62
63
|
fileName: "/__w/interface/interface/packages/react-utils/src/debug-context/Context.tsx",
|
|
63
64
|
lineNumber: 77,
|
|
64
65
|
columnNumber: 3
|
|
65
|
-
},
|
|
66
|
+
}, void 0);
|
|
66
67
|
});
|
|
67
68
|
DebugChildren.displayName = "DebugChildren";
|
|
68
69
|
exports.DebugChildren = DebugChildren;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Context.cjs","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","createContext","isNoopScopedConsole","useContext","useMemo","noopScopedConsole","useRef","memo","console","jsxDEV","this"],"mappings":";;;;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuBC,oBAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAAC,UAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0BC,iBAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgBC,MAAAA,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAAC;IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAMC,aAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgBC,WAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0BJ,iBAAW,oBAAoB,CAAC;AAEtF,QAAMK,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7CH;AAGF,SAAAI,qCAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASD,WAAUH,6BACvD,SADF,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAEA,GAAAK,MAAA;AAEF,CAAC;AACD,cAAc,cAAc;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
2
|
-
import { assert, isNonEmptyString } from "@contember/utilities";
|
|
3
2
|
import { createContext, useContext, useMemo, useRef, memo } from "react";
|
|
4
3
|
import { noopScopedConsole, isNoopScopedConsole } from "./Constants.js";
|
|
5
4
|
function createPrefixedConsole(message, prefixedConsole) {
|
|
@@ -40,7 +39,9 @@ function parentScopedConsoleOrNone(parentConsole) {
|
|
|
40
39
|
return isNoopScopedConsole(parentConsole) ? void 0 : parentConsole;
|
|
41
40
|
}
|
|
42
41
|
const useScopedConsoleRef = (prefix, override) => {
|
|
43
|
-
|
|
42
|
+
if (prefix.length === 0) {
|
|
43
|
+
throw new Error("Prefix must be non-empty string");
|
|
44
|
+
}
|
|
44
45
|
const parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext));
|
|
45
46
|
const scopedConsole = useMemo(() => {
|
|
46
47
|
if (override !== false && (parentConsole || override)) {
|
|
@@ -60,7 +61,7 @@ const DebugChildren = memo(({ active = true, children, id }) => {
|
|
|
60
61
|
fileName: "/__w/interface/interface/packages/react-utils/src/debug-context/Context.tsx",
|
|
61
62
|
lineNumber: 77,
|
|
62
63
|
columnNumber: 3
|
|
63
|
-
},
|
|
64
|
+
}, void 0);
|
|
64
65
|
});
|
|
65
66
|
DebugChildren.displayName = "DebugChildren";
|
|
66
67
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Context.js","sources":["../../../src/debug-context/Context.tsx"],"sourcesContent":["import { ReactNode, createContext, memo, useContext, useMemo, useRef } from 'react'\nimport { isNoopScopedConsole, noopScopedConsole } from './Constants'\nimport { ScopedConsoleContextType } from './Types'\n\nfunction createPrefixedConsole(message: string, prefixedConsole?: ScopedConsoleContextType): ScopedConsoleContextType {\n\treturn {\n\t\terror: function error(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).error(message, ...parameters)\n\t\t},\n\t\terrored: function errored<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).error(message, value)\n\t\t\treturn value\n\t\t},\n\t\tlog: function log(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).log(message, ...parameters)\n\t\t},\n\t\tlogged: function logged<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).log(message, value)\n\t\t\treturn value\n\t\t},\n\t\ttrace: function trace(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).trace(message, ...parameters)\n\t\t},\n\t\ttraced: function traced<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).trace(message, value)\n\t\t\treturn value\n\t\t},\n\t\twarn: function warn(...parameters: any[]) {\n\t\t\t(prefixedConsole ?? console).warn(message, ...parameters)\n\t\t},\n\t\twarned: function warned<T>(message: string, value: T): T {\n\t\t\t(prefixedConsole ?? console).warn(message, value)\n\t\t\treturn value\n\t\t},\n\t}\n}\n\nexport const ScopedConsoleContext = createContext<ScopedConsoleContextType>(null!)\nScopedConsoleContext.displayName = 'ScopedConsoleContext'\n\nfunction parentScopedConsoleOrNone(parentConsole: ScopedConsoleContextType): ScopedConsoleContextType | undefined {\n\treturn isNoopScopedConsole(parentConsole) ? undefined : parentConsole\n}\n\nexport const useScopedConsoleRef = (prefix: string, override?: boolean) => {\n\tif (prefix.length === 0) {\n\t\tthrow new Error('Prefix must be non-empty string')\n\t}\n\tconst parentConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst scopedConsole = useMemo(() => {\n\t\tif (override !== false && (parentConsole || override)) {\n\t\t\treturn createPrefixedConsole(prefix, parentConsole)\n\t\t} else {\n\t\t\treturn noopScopedConsole\n\t\t}\n\t}, [override, parentConsole, prefix])\n\n\tconst ref = useRef(scopedConsole)\n\tref.current = scopedConsole\n\n\treturn ref\n}\n\nexport type DebugChildrenProps =\n\t| { active?: true; children: ReactNode; id: string }\n\t| { active?: false; children: ReactNode; id?: string }\n\nexport const DebugChildren = memo<DebugChildrenProps>(({ active = true, children, id }) => {\n\tconst parentScopedConsole = parentScopedConsoleOrNone(useContext(ScopedConsoleContext))\n\n\tconst console = active && id\n\t\t? createPrefixedConsole(id, parentScopedConsole)\n\t\t: noopScopedConsole\n\n\treturn (\n\t\t<ScopedConsoleContext.Provider value={active ? console : noopScopedConsole}>\n\t\t\t{children}\n\t\t</ScopedConsoleContext.Provider>\n\t)\n})\nDebugChildren.displayName = 'DebugChildren'\n"],"names":["message","console","this"],"mappings":";;;AAIA,SAAS,sBAAsB,SAAiB,iBAAsE;AAC9G,SAAA;AAAA,IACN,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,SAAS,SAAS,QAAWA,UAAiB,OAAa;AAC1D,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,KAAK,SAAS,OAAO,YAAmB;AACvC,OAAC,mBAAmB,SAAS,IAAI,SAAS,GAAG,UAAU;AAAA,IACxD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,IAAIA,UAAS,KAAK;AACxC,aAAA;AAAA,IACR;AAAA,IACA,OAAO,SAAS,SAAS,YAAmB;AAC3C,OAAC,mBAAmB,SAAS,MAAM,SAAS,GAAG,UAAU;AAAA,IAC1D;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,MAAMA,UAAS,KAAK;AAC1C,aAAA;AAAA,IACR;AAAA,IACA,MAAM,SAAS,QAAQ,YAAmB;AACzC,OAAC,mBAAmB,SAAS,KAAK,SAAS,GAAG,UAAU;AAAA,IACzD;AAAA,IACA,QAAQ,SAAS,OAAUA,UAAiB,OAAa;AACxD,OAAC,mBAAmB,SAAS,KAAKA,UAAS,KAAK;AACzC,aAAA;AAAA,IACR;AAAA,EAAA;AAEF;AAEa,MAAA,uBAAuB,cAAwC,IAAK;AACjF,qBAAqB,cAAc;AAEnC,SAAS,0BAA0B,eAA+E;AAC1G,SAAA,oBAAoB,aAAa,IAAI,SAAY;AACzD;AAEa,MAAA,sBAAsB,CAAC,QAAgB,aAAuB;AACtE,MAAA,OAAO,WAAW,GAAG;AAClB,UAAA,IAAI,MAAM,iCAAiC;AAAA,EAClD;AACA,QAAM,gBAAgB,0BAA0B,WAAW,oBAAoB,CAAC;AAE1E,QAAA,gBAAgB,QAAQ,MAAM;AAC/B,QAAA,aAAa,UAAU,iBAAiB,WAAW;AAC/C,aAAA,sBAAsB,QAAQ,aAAa;AAAA,IAAA,OAC5C;AACC,aAAA;AAAA,IACR;AAAA,EACE,GAAA,CAAC,UAAU,eAAe,MAAM,CAAC;AAE9B,QAAA,MAAM,OAAO,aAAa;AAChC,MAAI,UAAU;AAEP,SAAA;AACR;AAMa,MAAA,gBAAgB,KAAyB,CAAC,EAAE,SAAS,MAAM,UAAU,SAAS;AAC1F,QAAM,sBAAsB,0BAA0B,WAAW,oBAAoB,CAAC;AAEtF,QAAMC,WAAU,UAAU,KACvB,sBAAsB,IAAI,mBAAmB,IAC7C;AAGF,SAAA,uBAAC,qBAAqB,UAArB,EAA8B,OAAO,SAASA,WAAU,mBACvD,SADF,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAEA,GAAAC,MAAA;AAEF,CAAC;AACD,cAAc,cAAc;"}
|
|
@@ -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;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
|
|
5
|
+
react.useEffect(() => {
|
|
6
|
+
if (isOpen) {
|
|
7
|
+
const closeOnClickOutside = (event) => {
|
|
8
|
+
const target = event.target;
|
|
9
|
+
if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (contents.every((it) => it === null)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
close();
|
|
16
|
+
};
|
|
17
|
+
(outside ?? window).addEventListener("click", closeOnClickOutside);
|
|
18
|
+
return () => {
|
|
19
|
+
(outside ?? window).removeEventListener("click", closeOnClickOutside);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}, [close, isOpen, contents, outside]);
|
|
23
|
+
};
|
|
24
|
+
exports.useCloseOnClickOutside = useCloseOnClickOutside;
|
|
25
|
+
//# sourceMappingURL=useCloseOnClickOutside.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnClickOutside.cjs","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":["useEffect"],"mappings":";;;AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChLA,QAAAA,UAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const useCloseOnClickOutside = ({ isOpen, close, contents, outside }) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
if (isOpen) {
|
|
5
|
+
const closeOnClickOutside = (event) => {
|
|
6
|
+
const target = event.target;
|
|
7
|
+
if (target instanceof Node && (!document.body.contains(target) || target === document.body || contents.some((it) => it && it.contains(target)))) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (contents.every((it) => it === null)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
close();
|
|
14
|
+
};
|
|
15
|
+
(outside ?? window).addEventListener("click", closeOnClickOutside);
|
|
16
|
+
return () => {
|
|
17
|
+
(outside ?? window).removeEventListener("click", closeOnClickOutside);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}, [close, isOpen, contents, outside]);
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
useCloseOnClickOutside
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useCloseOnClickOutside.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnClickOutside.js","sources":["../../../src/hooks/useCloseOnClickOutside.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnClickOutside = ({ isOpen, close, contents, outside }: { isOpen: boolean, close: () => void, contents: (Node | null)[], outside?: HTMLElement | null }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnClickOutside = (event: Event) => {\n\t\t\t\tconst target = event.target\n\t\t\t\tif (\n\t\t\t\t\ttarget instanceof Node &&\n\t\t\t\t\t(!document.body.contains(target) ||\n\t\t\t\t\t\ttarget === document.body ||\n\t\t\t\t\t\tcontents.some(it => it && it.contains(target)))\n\t\t\t\t) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (contents.every(it => it === null)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tclose()\n\t\t\t}\n\t\t\t(outside ?? window).addEventListener('click', closeOnClickOutside)\n\t\t\treturn () => {\n\t\t\t\t(outside ?? window).removeEventListener('click', closeOnClickOutside)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen, contents, outside])\n}\n"],"names":[],"mappings":";AAEO,MAAM,yBAAyB,CAAC,EAAE,QAAQ,OAAO,UAAU,cAA+G;AAChL,YAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,sBAAsB,CAAC,UAAiB;AAC7C,cAAM,SAAS,MAAM;AACrB,YACC,kBAAkB,SACjB,CAAC,SAAS,KAAK,SAAS,MAAM,KAC9B,WAAW,SAAS,QACpB,SAAS,KAAK,CAAM,OAAA,MAAM,GAAG,SAAS,MAAM,CAAC,IAC7C;AACD;AAAA,QACD;AACA,YAAI,SAAS,MAAM,CAAM,OAAA,OAAO,IAAI,GAAG;AACtC;AAAA,QACD;AACM;MAAA;AAEP,OAAC,WAAW,QAAQ,iBAAiB,SAAS,mBAAmB;AACjE,aAAO,MAAM;AACZ,SAAC,WAAW,QAAQ,oBAAoB,SAAS,mBAAmB;AAAA,MAAA;AAAA,IAEtE;AAAA,KACE,CAAC,OAAO,QAAQ,UAAU,OAAO,CAAC;AACtC;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const useCloseOnEscape = ({ isOpen, close }) => {
|
|
5
|
+
react.useEffect(() => {
|
|
6
|
+
if (isOpen) {
|
|
7
|
+
const closeOnEscapeKey = (event) => {
|
|
8
|
+
if (event.key === "Escape") {
|
|
9
|
+
close();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
window.addEventListener("keydown", closeOnEscapeKey);
|
|
13
|
+
return () => {
|
|
14
|
+
window.removeEventListener("keydown", closeOnEscapeKey);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}, [close, isOpen]);
|
|
18
|
+
};
|
|
19
|
+
exports.useCloseOnEscape = useCloseOnEscape;
|
|
20
|
+
//# sourceMappingURL=useCloseOnEscape.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnEscape.cjs","sources":["../../../src/hooks/useCloseOnEscape.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnEscape = ({ isOpen, close }: { isOpen: boolean, close: () => void }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnEscapeKey = (event: KeyboardEvent) => {\n\t\t\t\tif (event.key === 'Escape') {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\t\t\twindow.addEventListener('keydown', closeOnEscapeKey)\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener('keydown', closeOnEscapeKey)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen])\n}\n"],"names":["useEffect"],"mappings":";;;AAEO,MAAM,mBAAmB,CAAC,EAAE,QAAQ,YAAoD;AAC9FA,QAAAA,UAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,mBAAmB,CAAC,UAAyB;AAC9C,YAAA,MAAM,QAAQ,UAAU;AACrB;QACP;AAAA,MAAA;AAEM,aAAA,iBAAiB,WAAW,gBAAgB;AAEnD,aAAO,MAAM;AACL,eAAA,oBAAoB,WAAW,gBAAgB;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA,GACE,CAAC,OAAO,MAAM,CAAC;AACnB;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const useCloseOnEscape = ({ isOpen, close }) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
if (isOpen) {
|
|
5
|
+
const closeOnEscapeKey = (event) => {
|
|
6
|
+
if (event.key === "Escape") {
|
|
7
|
+
close();
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
window.addEventListener("keydown", closeOnEscapeKey);
|
|
11
|
+
return () => {
|
|
12
|
+
window.removeEventListener("keydown", closeOnEscapeKey);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}, [close, isOpen]);
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
useCloseOnEscape
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useCloseOnEscape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloseOnEscape.js","sources":["../../../src/hooks/useCloseOnEscape.ts"],"sourcesContent":["import { useEffect } from 'react'\n\nexport const useCloseOnEscape = ({ isOpen, close }: { isOpen: boolean, close: () => void }) => {\n\tuseEffect(() => {\n\t\tif (isOpen) {\n\t\t\tconst closeOnEscapeKey = (event: KeyboardEvent) => {\n\t\t\t\tif (event.key === 'Escape') {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\t\t\twindow.addEventListener('keydown', closeOnEscapeKey)\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener('keydown', closeOnEscapeKey)\n\t\t\t}\n\t\t}\n\t}, [close, isOpen])\n}\n"],"names":[],"mappings":";AAEO,MAAM,mBAAmB,CAAC,EAAE,QAAQ,YAAoD;AAC9F,YAAU,MAAM;AACf,QAAI,QAAQ;AACL,YAAA,mBAAmB,CAAC,UAAyB;AAC9C,YAAA,MAAM,QAAQ,UAAU;AACrB;QACP;AAAA,MAAA;AAEM,aAAA,iBAAiB,WAAW,gBAAgB;AAEnD,aAAO,MAAM;AACL,eAAA,oBAAoB,WAAW,gBAAgB;AAAA,MAAA;AAAA,IAExD;AAAA,EAAA,GACE,CAAC,OAAO,MAAM,CAAC;AACnB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConstantLengthInvariant.cjs","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAC3D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACnC,QAAA,SAAS,WAAW,MAAM,QAAQ;AACrC,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"useConstantLengthInvariant.cjs","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAC3D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACnC,QAAA,SAAS,WAAW,MAAM,QAAQ;AACrC,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW,oFACnC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConstantLengthInvariant.js","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAC3D;AAElB,UAAA,WAAW,iBAAiB,KAAK;AACnC,QAAA,SAAS,WAAW,MAAM,QAAQ;AACrC,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"useConstantLengthInvariant.js","sources":["../../../src/hooks/useConstantLengthInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantLengthInvariant = <Item>(items: Item[], message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(items)\n\t\tif (previous.length !== items.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing the length of an array whose length must remain constant between renders.'\n\t\t\t\t}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,6BAA6B,CAAO,OAAe,YAAqB;AAC3D;AAElB,UAAA,WAAW,iBAAiB,KAAK;AACnC,QAAA,SAAS,WAAW,MAAM,QAAQ;AACrC,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW,oFACnC;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConstantValueInvariant.cjs","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAC1D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACvC,QAAI,aAAa,OAAO;AACvB,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"useConstantValueInvariant.cjs","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["usePreviousValue"],"mappings":";;;AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAC1D;AAElB,UAAA,WAAWA,kCAAiB,KAAK;AACvC,QAAI,aAAa,OAAO;AACvB,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW,8DAA8D;AAAA,MAAA;AAAA,IAEnG;AAAA,EACD;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConstantValueInvariant.js","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAC1D;AAElB,UAAA,WAAW,iBAAiB,KAAK;AACvC,QAAI,aAAa,OAAO;AACvB,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"useConstantValueInvariant.js","sources":["../../../src/hooks/useConstantValueInvariant.ts"],"sourcesContent":["import { usePreviousValue } from './usePreviousValue'\n\n// This entire hook should get optimized away for prod\nexport const useConstantValueInvariant = <Value>(value: Value, message?: string) => {\n\tif (import.meta.env.DEV) {\n\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\tconst previous = usePreviousValue(value)\n\t\tif (previous !== value) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invariant violation: ${message || 'Changing a value which must remain constant between renders.'}`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,4BAA4B,CAAQ,OAAc,YAAqB;AAC1D;AAElB,UAAA,WAAW,iBAAiB,KAAK;AACvC,QAAI,aAAa,OAAO;AACvB,YAAM,IAAI;AAAA,QACT,wBAAwB,WAAW,8DAA8D;AAAA,MAAA;AAAA,IAEnG;AAAA,EACD;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useId.cjs","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":["useMemo"],"mappings":";;;AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"useId.cjs","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":["useMemo"],"mappings":";;;AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE,CAAC;AACtC;AAUO,SAAS,QAAQ;AACvB,SAAOA,cAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE;
|
|
1
|
+
{"version":3,"file":"useId.js","sources":["../../../src/hooks/useId.ts"],"sourcesContent":["import { useMemo, useRef } from 'react'\n\nconst count = { current: 360 }\n\nfunction nextId() {\n\tcount.current += 1\n\n\treturn `:${count.current.toString(36)}:`\n}\n\n/**\n * Returns a unique ID string\n * @internal\n *\n * NOTE: This hook is a temporary solution until we stop supporting React < 18\n *\n * @returns a unique id\n */\nexport function useId() {\n\treturn useMemo(() => nextId(), [])\n}\n"],"names":[],"mappings":";AAEA,MAAM,QAAQ,EAAE,SAAS;AAEzB,SAAS,SAAS;AACjB,QAAM,WAAW;AAEjB,SAAO,IAAI,MAAM,QAAQ,SAAS,EAAE,CAAC;AACtC;AAUO,SAAS,QAAQ;AACvB,SAAO,QAAQ,MAAM,OAAO,GAAG,CAAE,CAAA;AAClC;"}
|
|
@@ -1,23 +1,97 @@
|
|
|
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 createStateStorage = (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 = createStateStorage(() => sessionStorage);
|
|
29
|
+
const localStateStorage = createStateStorage(() => 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
|
+
if (Array.isArray(storageOrName)) {
|
|
46
|
+
return createFallbackStorage(storageOrName);
|
|
47
|
+
}
|
|
48
|
+
return typeof storageOrName === "string" ? builtInStorages[storageOrName] : storageOrName;
|
|
49
|
+
}, [storageOrName]);
|
|
50
|
+
const [value, setValue] = react.useState(() => {
|
|
51
|
+
const value2 = storage.getItem(key);
|
|
52
|
+
return initializeValue(value2);
|
|
53
|
+
});
|
|
54
|
+
return [
|
|
55
|
+
value,
|
|
56
|
+
react.useCallback((value2) => {
|
|
13
57
|
setValue((current) => {
|
|
14
58
|
const newValue = typeof value2 === "function" ? value2(current) : value2;
|
|
15
|
-
storage.setItem(key,
|
|
59
|
+
storage.setItem(key, newValue);
|
|
16
60
|
return newValue;
|
|
17
61
|
});
|
|
18
|
-
}, [key, storage])
|
|
62
|
+
}, [key, storage])
|
|
63
|
+
];
|
|
64
|
+
};
|
|
65
|
+
const useSessionStorageState = (key, initializeValue) => {
|
|
66
|
+
return useStoredState(sessionStateStorage, key, initializeValue);
|
|
67
|
+
};
|
|
68
|
+
const useLocalStorageState = (key, initializeValue) => {
|
|
69
|
+
return useStoredState(localStateStorage, key, initializeValue);
|
|
70
|
+
};
|
|
71
|
+
const createFallbackStorage = (storageTypes) => {
|
|
72
|
+
const resultStorages = storageTypes.map((it) => typeof it === "string" ? builtInStorages[it] : it);
|
|
73
|
+
return {
|
|
74
|
+
getItem(key) {
|
|
75
|
+
for (const storage of resultStorages) {
|
|
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 resultStorages) {
|
|
85
|
+
storage.setItem(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
19
88
|
};
|
|
20
89
|
};
|
|
21
|
-
|
|
90
|
+
exports.localStateStorage = localStateStorage;
|
|
91
|
+
exports.nullStorage = nullStorage;
|
|
92
|
+
exports.sessionStateStorage = sessionStateStorage;
|
|
93
|
+
exports.urlStateStorage = urlStateStorage;
|
|
94
|
+
exports.useLocalStorageState = useLocalStorageState;
|
|
22
95
|
exports.useSessionStorageState = useSessionStorageState;
|
|
96
|
+
exports.useStoredState = useStoredState;
|
|
23
97
|
//# 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 createStateStorage = (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 = createStateStorage(() => sessionStorage)\nexport const localStateStorage = createStateStorage(() => 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\tif (Array.isArray(storageOrName)) {\n\t\t\treturn createFallbackStorage(storageOrName)\n\t\t}\n\t\treturn typeof storageOrName === 'string' ? builtInStorages[storageOrName] : 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\n\nconst createFallbackStorage = <V extends Serializable>(storageTypes: StateStorageOrName[]): StateStorage => {\n\tconst resultStorages = storageTypes.map(it => typeof it === 'string' ? builtInStorages[it] : it)\n\treturn {\n\t\tgetItem(key) {\n\t\t\tfor (const storage of resultStorages) {\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 resultStorages) {\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":";;;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,IAAI,CAAC,GAAG,KAAK,UAAU,KAAK,CAAC;AACxC,UAAA,SAAS,GAAG,OAAO,SAAS,QAAQ,IAAI,aAAa,SAAU,CAAA;AACrE,WAAO,QAAQ,aAAa,CAAC,GAAG,IAAI,MAAM;AAAA,EAC3C;AACD;AAEA,MAAM,qBAAqB,CAAC,eAA4C;AAChE,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,YAAM,QAAQ,aAAa,QAAQ,IAAI,KAAK,GAAG,CAAC;AAChD,aAAO,UAAU,OAAO,KAAK,MAAM,KAAK,IAAI;AAAA,IAC7C;AAAA,IACA,QAAQ,KAAK,OAAO;AACR,iBAAA,EAAE,QAAQ,IAAI,KAAK,GAAG,GAAG,KAAK,UAAU,KAAK,CAAC;AAAA,IAC1D;AAAA,EAAA;AAEF;AAEa,MAAA,sBAAsB,mBAAmB,MAAM,cAAc;AAC7D,MAAA,oBAAoB,mBAAmB,MAAM,YAAY;AAC/D,MAAM,cAA4B;AAAA,EACxC,UAAU;AACF,WAAA;AAAA,EACR;AAAA,EACA,UAAU;AAAA,EACV;AACD;AAEA,MAAM,kBAAkB;AAAA,EACvB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,MAAM;AACP;AAIO,MAAM,iBAAiB,CAAyB,eAA0D,KAAsB,oBAA2D;AAC3L,QAAA,UAAUA,MAAAA,QAAQ,MAAM;AACzB,QAAA,MAAM,QAAQ,aAAa,GAAG;AACjC,aAAO,sBAAsB,aAAa;AAAA,IAC3C;AACA,WAAO,OAAO,kBAAkB,WAAW,gBAAgB,aAAa,IAAI;AAAA,EAAA,GAC1E,CAAC,aAAa,CAAC;AAElB,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAY,MAAM;AACrCC,UAAAA,SAAQ,QAAQ,QAAQ,GAAG;AACjC,WAAO,gBAAgBA,MAAU;AAAA,EAAA,CACjC;AACM,SAAA;AAAA,IACN;AAAA,IACAC,MAAA,YAAY,CAAAD,WAAS;AACpB,eAAS,CAAW,YAAA;AACnB,cAAM,WAAW,OAAOA,WAAU,aAAcA,OAA4B,OAAO,IAAIA;AAC/E,gBAAA,QAAQ,KAAK,QAAQ;AACtB,eAAA;AAAA,MAAA,CACP;AAAA,IAAA,GACC,CAAC,KAAK,OAAO,CAAC;AAAA,EAAA;AAEnB;AAEa,MAAA,yBAAyB,CAAyB,KAAsB,oBAA2D;AACxI,SAAA,eAAkB,qBAAqB,KAAK,eAAe;AACnE;AAEa,MAAA,uBAAuB,CAAyB,KAAsB,oBAA2D;AACtI,SAAA,eAAkB,mBAAmB,KAAK,eAAe;AACjE;AAGA,MAAM,wBAAwB,CAAyB,iBAAqD;AACrG,QAAA,iBAAiB,aAAa,IAAI,CAAM,OAAA,OAAO,OAAO,WAAW,gBAAgB,EAAE,IAAI,EAAE;AACxF,SAAA;AAAA,IACN,QAAQ,KAAK;AACZ,iBAAW,WAAW,gBAAgB;AAC/B,cAAA,QAAQ,QAAQ,QAAQ,GAAG;AACjC,YAAI,UAAU,MAAM;AACZ,iBAAA;AAAA,QACR;AAAA,MACD;AACO,aAAA;AAAA,IACR;AAAA,IACA,QAAQ,KAAK,OAAO;AACnB,iBAAW,WAAW,gBAAgB;AAC7B,gBAAA,QAAQ,KAAK,KAAK;AAAA,MAC3B;AAAA,IACD;AAAA,EAAA;AAEF;;;;;;;;"}
|