@gravity-ui/dynamic-forms 4.11.0 → 4.13.0
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/build/cjs/lib/core/components/Form/DynamicField.js +13 -1
- package/build/cjs/lib/core/components/Form/hooks/index.js +2 -0
- package/build/cjs/lib/core/components/Form/hooks/useFormShared.js +6 -0
- package/build/cjs/lib/core/components/Form/hooks/useFormSharedStore.js +11 -0
- package/build/cjs/lib/core/components/Form/index.js +2 -1
- package/build/cjs/lib/core/components/View/DynamicView.js +3 -1
- package/build/cjs/lib/core/components/View/hooks/index.js +2 -0
- package/build/cjs/lib/core/components/View/hooks/useViewShared.js +6 -0
- package/build/cjs/lib/core/components/View/hooks/useViewSharedStore.js +11 -0
- package/build/cjs/lib/core/components/View/index.js +2 -1
- package/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.js +21 -9
- package/build/cjs/lib/kit/components/Views/TextContentView.js +20 -0
- package/build/cjs/lib/kit/components/Views/index.js +1 -0
- package/build/cjs/lib/kit/constants/config.js +1 -1
- package/build/esm/lib/core/components/Form/DynamicField.js +14 -2
- package/build/esm/lib/core/components/Form/hooks/index.d.ts +2 -0
- package/build/esm/lib/core/components/Form/hooks/index.js +2 -0
- package/build/esm/lib/core/components/Form/hooks/useFormShared.d.ts +4 -0
- package/build/esm/lib/core/components/Form/hooks/useFormShared.js +2 -0
- package/build/esm/lib/core/components/Form/hooks/useFormSharedStore.d.ts +4 -0
- package/build/esm/lib/core/components/Form/hooks/useFormSharedStore.js +6 -0
- package/build/esm/lib/core/components/Form/index.d.ts +1 -1
- package/build/esm/lib/core/components/Form/index.js +1 -1
- package/build/esm/lib/core/components/Form/types/context.d.ts +4 -0
- package/build/esm/lib/core/components/View/DynamicView.js +4 -2
- package/build/esm/lib/core/components/View/hooks/index.d.ts +2 -0
- package/build/esm/lib/core/components/View/hooks/index.js +2 -0
- package/build/esm/lib/core/components/View/hooks/useViewShared.d.ts +4 -0
- package/build/esm/lib/core/components/View/hooks/useViewShared.js +2 -0
- package/build/esm/lib/core/components/View/hooks/useViewSharedStore.d.ts +4 -0
- package/build/esm/lib/core/components/View/hooks/useViewSharedStore.js +6 -0
- package/build/esm/lib/core/components/View/index.d.ts +1 -1
- package/build/esm/lib/core/components/View/index.js +1 -1
- package/build/esm/lib/core/components/View/types/context.d.ts +4 -0
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.d.ts +11 -2
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.js +19 -9
- package/build/esm/lib/kit/components/Views/TextContentView.d.ts +2 -0
- package/build/esm/lib/kit/components/Views/TextContentView.js +15 -0
- package/build/esm/lib/kit/components/Views/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Views/index.js +1 -0
- package/build/esm/lib/kit/constants/config.js +2 -2
- package/package.json +2 -1
|
@@ -18,15 +18,27 @@ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search,
|
|
|
18
18
|
const watcher = (0, hooks_1.useIntegrationFF)(store, withoutInsertFFDebounce, destroyOnUnregister);
|
|
19
19
|
const { mutatorsStore, mutateDFState } = (0, hooks_1.useMutators)(externalMutators);
|
|
20
20
|
const { store: searchStore, setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)();
|
|
21
|
+
const shared = (0, hooks_1.useFormSharedStore)();
|
|
21
22
|
const context = react_1.default.useMemo(() => ({
|
|
22
23
|
config,
|
|
23
24
|
Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
|
|
24
25
|
generateRandomValue,
|
|
25
26
|
tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
|
|
26
27
|
store,
|
|
28
|
+
shared,
|
|
27
29
|
mutatorsStore,
|
|
28
30
|
__mirror,
|
|
29
|
-
}), [
|
|
31
|
+
}), [
|
|
32
|
+
tools,
|
|
33
|
+
shared,
|
|
34
|
+
config,
|
|
35
|
+
Monaco,
|
|
36
|
+
__mirror,
|
|
37
|
+
generateRandomValue,
|
|
38
|
+
mutatorsStore,
|
|
39
|
+
mutateDFState,
|
|
40
|
+
store,
|
|
41
|
+
]);
|
|
30
42
|
const searchContext = react_1.default.useMemo(() => ({
|
|
31
43
|
setField,
|
|
32
44
|
removeField,
|
|
@@ -5,6 +5,8 @@ tslib_1.__exportStar(require("./useControllerMirror"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./useCreateContext"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./useDynamicFieldMirror"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useFormShared"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./useFormSharedStore"), exports);
|
|
8
10
|
tslib_1.__exportStar(require("./useGenerateRandomValue"), exports);
|
|
9
11
|
tslib_1.__exportStar(require("./useIntegrationFF"), exports);
|
|
10
12
|
tslib_1.__exportStar(require("./useMutateDFState"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormShared = void 0;
|
|
4
|
+
const useDynamicFormsCtx_1 = require("./useDynamicFormsCtx");
|
|
5
|
+
const useFormShared = () => (0, useDynamicFormsCtx_1.useDynamicFormsCtx)().shared;
|
|
6
|
+
exports.useFormShared = useFormShared;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormSharedStore = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const useFormSharedStore = () => {
|
|
7
|
+
const [store, setStore] = react_1.default.useState({});
|
|
8
|
+
const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
|
|
9
|
+
return { store, onChangeShared };
|
|
10
|
+
};
|
|
11
|
+
exports.useFormSharedStore = useFormSharedStore;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStoreValue = exports.useMutateDFState = void 0;
|
|
3
|
+
exports.useFormShared = exports.useStoreValue = exports.useMutateDFState = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./constants"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./Controller"), exports);
|
|
@@ -8,5 +8,6 @@ tslib_1.__exportStar(require("./DynamicField"), exports);
|
|
|
8
8
|
var hooks_1 = require("./hooks");
|
|
9
9
|
Object.defineProperty(exports, "useMutateDFState", { enumerable: true, get: function () { return hooks_1.useMutateDFState; } });
|
|
10
10
|
Object.defineProperty(exports, "useStoreValue", { enumerable: true, get: function () { return hooks_1.useStoreValue; } });
|
|
11
|
+
Object.defineProperty(exports, "useFormShared", { enumerable: true, get: function () { return hooks_1.useFormShared; } });
|
|
11
12
|
tslib_1.__exportStar(require("./types"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
@@ -10,13 +10,15 @@ const helpers_2 = require("./helpers");
|
|
|
10
10
|
const hooks_1 = require("./hooks");
|
|
11
11
|
const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
|
|
12
12
|
const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
|
|
13
|
+
const shared = (0, hooks_1.useViewSharedStore)();
|
|
13
14
|
const context = react_1.default.useMemo(() => ({
|
|
14
15
|
config,
|
|
15
16
|
value,
|
|
16
17
|
showLayoutDescription,
|
|
17
18
|
Link,
|
|
18
19
|
Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
|
|
19
|
-
|
|
20
|
+
shared,
|
|
21
|
+
}), [config, value, Link, Monaco, showLayoutDescription, shared]);
|
|
20
22
|
if ((0, helpers_1.isCorrectSpec)(spec) && (0, helpers_2.isCorrectViewConfig)(config)) {
|
|
21
23
|
return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
22
24
|
react_1.default.createElement(ViewController_1.ViewController, { spec: spec, name: "" })));
|
|
@@ -6,3 +6,5 @@ tslib_1.__exportStar(require("./useCreateContext"), exports);
|
|
|
6
6
|
tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./useRender"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./useMonaco"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./useViewShared"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./useViewSharedStore"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useViewShared = void 0;
|
|
4
|
+
const useDynamicFormsCtx_1 = require("./useDynamicFormsCtx");
|
|
5
|
+
const useViewShared = () => (0, useDynamicFormsCtx_1.useDynamicFormsCtx)().shared;
|
|
6
|
+
exports.useViewShared = useViewShared;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useViewSharedStore = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const useViewSharedStore = () => {
|
|
7
|
+
const [store, setStore] = react_1.default.useState({});
|
|
8
|
+
const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
|
|
9
|
+
return { store, onChangeShared };
|
|
10
|
+
};
|
|
11
|
+
exports.useViewSharedStore = useViewSharedStore;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useDynamicFormsCtx = void 0;
|
|
3
|
+
exports.useViewShared = exports.useDynamicFormsCtx = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./DynamicView"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./ViewController"), exports);
|
|
@@ -8,3 +8,4 @@ tslib_1.__exportStar(require("./helpers"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./types"), exports);
|
|
9
9
|
var hooks_1 = require("./hooks");
|
|
10
10
|
Object.defineProperty(exports, "useDynamicFormsCtx", { enumerable: true, get: function () { return hooks_1.useDynamicFormsCtx; } });
|
|
11
|
+
Object.defineProperty(exports, "useViewShared", { enumerable: true, get: function () { return hooks_1.useViewShared; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextContent = void 0;
|
|
3
|
+
exports.TextContent = exports.TextContentComponent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
@@ -9,9 +9,8 @@ const utils_1 = require("../../../utils");
|
|
|
9
9
|
const LazyLoader_1 = require("../../LazyLoader");
|
|
10
10
|
const utils_2 = require("./utils");
|
|
11
11
|
const b = (0, utils_1.block)('text-content');
|
|
12
|
-
const
|
|
13
|
-
var
|
|
14
|
-
var { spec, Layout, input } = _a, restProps = tslib_1.__rest(_a, ["spec", "Layout", "input"]);
|
|
12
|
+
const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
13
|
+
var _a;
|
|
15
14
|
const { textContentParams, layoutDescription } = spec.viewSpec;
|
|
16
15
|
const text = react_1.default.useMemo(() => ((textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text) ? textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text : layoutDescription), [layoutDescription, textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text]);
|
|
17
16
|
if (!text) {
|
|
@@ -20,23 +19,36 @@ const TextContent = (_a) => {
|
|
|
20
19
|
const iconLib = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) ? (react_1.default.createElement(LazyLoader_1.LazyLoader, { component: (0, utils_2.loadIcon)(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) })) : null;
|
|
21
20
|
let content = react_1.default.createElement("span", { dangerouslySetInnerHTML: { __html: text } });
|
|
22
21
|
if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
23
|
-
content = (react_1.default.createElement(uikit_1.Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value:
|
|
22
|
+
content = (react_1.default.createElement(uikit_1.Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
25
|
content = (react_1.default.createElement("div", { className: b('wrapper') },
|
|
27
|
-
iconLib ? (react_1.default.createElement(uikit_1.Text, { color: (
|
|
26
|
+
iconLib ? (react_1.default.createElement(uikit_1.Text, { color: (_a = spec.viewSpec.textContentParams) === null || _a === void 0 ? void 0 : _a.iconColor, className: b('icon') }, iconLib)) : null,
|
|
28
27
|
content,
|
|
29
|
-
|
|
28
|
+
value ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
30
29
|
react_1.default.createElement(uikit_1.Text, { className: b('separator') }, ":"),
|
|
31
|
-
react_1.default.createElement(uikit_1.Text, { color: "secondary" },
|
|
30
|
+
react_1.default.createElement(uikit_1.Text, { color: "secondary" }, value))) : null));
|
|
32
31
|
}
|
|
33
32
|
if (Layout) {
|
|
34
33
|
const _spec = (0, cloneDeep_1.default)(spec);
|
|
35
34
|
if (!(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text)) {
|
|
36
35
|
_spec.viewSpec.layoutDescription = undefined;
|
|
37
36
|
}
|
|
38
|
-
return
|
|
37
|
+
return react_1.default.createElement(Layout, { spec: _spec }, content);
|
|
39
38
|
}
|
|
40
39
|
return content;
|
|
41
40
|
};
|
|
41
|
+
exports.TextContentComponent = TextContentComponent;
|
|
42
|
+
const TextContent = ({ name, spec, Layout, input, arrayInput, meta, layoutProps, }) => {
|
|
43
|
+
const WrappedLayout = react_1.default.useMemo(() => {
|
|
44
|
+
if (Layout) {
|
|
45
|
+
const Component = (props) => {
|
|
46
|
+
return (react_1.default.createElement(Layout, Object.assign({ name: name, input: input, layoutProps: layoutProps, arrayInput: arrayInput, meta: meta }, props)));
|
|
47
|
+
};
|
|
48
|
+
return Component;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}, [Layout, layoutProps, input, arrayInput, meta, name]);
|
|
52
|
+
return react_1.default.createElement(exports.TextContentComponent, { spec: spec, value: input.value, Layout: WrappedLayout });
|
|
53
|
+
};
|
|
42
54
|
exports.TextContent = TextContent;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextContentView = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const Inputs_1 = require("../Inputs");
|
|
7
|
+
const TextContentView = ({ name, spec, Layout, value }) => {
|
|
8
|
+
const WrappedLayout = react_1.default.useMemo(() => {
|
|
9
|
+
if (Layout) {
|
|
10
|
+
const Component = (props) => {
|
|
11
|
+
const VALUE_STUB = 'if u see this, please create issue about it here: https://github.com/gravity-ui/dynamic-forms/issues/new';
|
|
12
|
+
return react_1.default.createElement(Layout, Object.assign({ name: name, value: VALUE_STUB }, props));
|
|
13
|
+
};
|
|
14
|
+
return Component;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}, [Layout, name]);
|
|
18
|
+
return react_1.default.createElement(Inputs_1.TextContentComponent, { spec: spec, value: value, Layout: WrappedLayout });
|
|
19
|
+
};
|
|
20
|
+
exports.TextContentView = TextContentView;
|
|
@@ -15,6 +15,7 @@ tslib_1.__exportStar(require("./ObjectValueInputView"), exports);
|
|
|
15
15
|
tslib_1.__exportStar(require("./OneOfView"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./TableArrayView"), exports);
|
|
17
17
|
tslib_1.__exportStar(require("./TextAreaView"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./TextContentView"), exports);
|
|
18
19
|
tslib_1.__exportStar(require("./TextLinkView"), exports);
|
|
19
20
|
tslib_1.__exportStar(require("./TimeRangeSelectorView"), exports);
|
|
20
21
|
tslib_1.__exportStar(require("./DateView"), exports);
|
|
@@ -202,7 +202,7 @@ exports.dynamicViewConfig = {
|
|
|
202
202
|
file_input: { Component: components_1.FileInputView },
|
|
203
203
|
number_with_scale: { Component: components_1.NumberWithScaleView },
|
|
204
204
|
monaco_input: { Component: components_1.MonacoView },
|
|
205
|
-
text_content:
|
|
205
|
+
text_content: { Component: components_1.TextContentView, independent: true },
|
|
206
206
|
},
|
|
207
207
|
layouts: {
|
|
208
208
|
row: components_1.ViewRow,
|
|
@@ -5,7 +5,7 @@ import isString from 'lodash/isString';
|
|
|
5
5
|
import { isValidElementType } from 'react-is';
|
|
6
6
|
import { isCorrectSpec } from '../../helpers';
|
|
7
7
|
import { Controller } from './Controller';
|
|
8
|
-
import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
|
|
8
|
+
import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useFormSharedStore, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
|
|
9
9
|
import { getDefaultSearchFunction, isCorrectConfig } from './utils';
|
|
10
10
|
export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
|
|
11
11
|
const DynamicFormsCtx = useCreateContext();
|
|
@@ -14,15 +14,27 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
|
|
|
14
14
|
const watcher = useIntegrationFF(store, withoutInsertFFDebounce, destroyOnUnregister);
|
|
15
15
|
const { mutatorsStore, mutateDFState } = useMutators(externalMutators);
|
|
16
16
|
const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
|
|
17
|
+
const shared = useFormSharedStore();
|
|
17
18
|
const context = React.useMemo(() => ({
|
|
18
19
|
config,
|
|
19
20
|
Monaco: isValidElementType(Monaco) ? Monaco : undefined,
|
|
20
21
|
generateRandomValue,
|
|
21
22
|
tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
|
|
22
23
|
store,
|
|
24
|
+
shared,
|
|
23
25
|
mutatorsStore,
|
|
24
26
|
__mirror,
|
|
25
|
-
}), [
|
|
27
|
+
}), [
|
|
28
|
+
tools,
|
|
29
|
+
shared,
|
|
30
|
+
config,
|
|
31
|
+
Monaco,
|
|
32
|
+
__mirror,
|
|
33
|
+
generateRandomValue,
|
|
34
|
+
mutatorsStore,
|
|
35
|
+
mutateDFState,
|
|
36
|
+
store,
|
|
37
|
+
]);
|
|
26
38
|
const searchContext = React.useMemo(() => ({
|
|
27
39
|
setField,
|
|
28
40
|
removeField,
|
|
@@ -2,6 +2,8 @@ export * from './useControllerMirror';
|
|
|
2
2
|
export * from './useCreateContext';
|
|
3
3
|
export * from './useDynamicFieldMirror';
|
|
4
4
|
export * from './useDynamicFormsCtx';
|
|
5
|
+
export * from './useFormShared';
|
|
6
|
+
export * from './useFormSharedStore';
|
|
5
7
|
export * from './useGenerateRandomValue';
|
|
6
8
|
export * from './useIntegrationFF';
|
|
7
9
|
export * from './useMutateDFState';
|
|
@@ -2,6 +2,8 @@ export * from './useControllerMirror';
|
|
|
2
2
|
export * from './useCreateContext';
|
|
3
3
|
export * from './useDynamicFieldMirror';
|
|
4
4
|
export * from './useDynamicFormsCtx';
|
|
5
|
+
export * from './useFormShared';
|
|
6
|
+
export * from './useFormSharedStore';
|
|
5
7
|
export * from './useGenerateRandomValue';
|
|
6
8
|
export * from './useIntegrationFF';
|
|
7
9
|
export * from './useMutateDFState';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const useFormSharedStore = () => {
|
|
3
|
+
const [store, setStore] = React.useState({});
|
|
4
|
+
const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
|
|
5
|
+
return { store, onChangeShared };
|
|
6
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './constants';
|
|
2
2
|
export * from './Controller';
|
|
3
3
|
export * from './DynamicField';
|
|
4
|
-
export { useMutateDFState, useStoreValue } from './hooks';
|
|
4
|
+
export { useMutateDFState, useStoreValue, useFormShared } from './hooks';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './utils';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './constants';
|
|
2
2
|
export * from './Controller';
|
|
3
3
|
export * from './DynamicField';
|
|
4
|
-
export { useMutateDFState, useStoreValue } from './hooks';
|
|
4
|
+
export { useMutateDFState, useStoreValue, useFormShared } from './hooks';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './utils';
|
|
@@ -14,6 +14,10 @@ export interface DynamicFormsContext {
|
|
|
14
14
|
mutateDFState: (mutators: DynamicFormMutators) => void;
|
|
15
15
|
};
|
|
16
16
|
store: DynamicFieldStore;
|
|
17
|
+
shared: {
|
|
18
|
+
store: Record<string, any>;
|
|
19
|
+
onChangeShared: (name: string, value: any) => void;
|
|
20
|
+
};
|
|
17
21
|
mutatorsStore: DynamicFormMutatorsStore;
|
|
18
22
|
__mirror?: WonderMirror;
|
|
19
23
|
}
|
|
@@ -3,16 +3,18 @@ import { isValidElementType } from 'react-is';
|
|
|
3
3
|
import { isCorrectSpec } from '../../helpers';
|
|
4
4
|
import { ViewController } from './ViewController';
|
|
5
5
|
import { isCorrectViewConfig } from './helpers';
|
|
6
|
-
import { useCreateContext } from './hooks';
|
|
6
|
+
import { useCreateContext, useViewSharedStore } from './hooks';
|
|
7
7
|
export const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
|
|
8
8
|
const DynamicFormsCtx = useCreateContext();
|
|
9
|
+
const shared = useViewSharedStore();
|
|
9
10
|
const context = React.useMemo(() => ({
|
|
10
11
|
config,
|
|
11
12
|
value,
|
|
12
13
|
showLayoutDescription,
|
|
13
14
|
Link,
|
|
14
15
|
Monaco: isValidElementType(Monaco) ? Monaco : undefined,
|
|
15
|
-
|
|
16
|
+
shared,
|
|
17
|
+
}), [config, value, Link, Monaco, showLayoutDescription, shared]);
|
|
16
18
|
if (isCorrectSpec(spec) && isCorrectViewConfig(config)) {
|
|
17
19
|
return (React.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
18
20
|
React.createElement(ViewController, { spec: spec, name: "" })));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const useViewSharedStore = () => {
|
|
3
|
+
const [store, setStore] = React.useState({});
|
|
4
|
+
const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
|
|
5
|
+
return { store, onChangeShared };
|
|
6
|
+
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StringIndependentInput, StringSpec } from '../../../../core';
|
|
3
3
|
import './TextContent.css';
|
|
4
|
-
export
|
|
4
|
+
export interface TextContentComponentProps {
|
|
5
|
+
spec: StringSpec;
|
|
6
|
+
value?: string;
|
|
7
|
+
Layout?: React.FC<{
|
|
8
|
+
spec: StringSpec;
|
|
9
|
+
children: React.ReactElement;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare const TextContentComponent: React.FC<TextContentComponentProps>;
|
|
13
|
+
export declare const TextContent: StringIndependentInput;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from "tslib";
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { Label, Text } from '@gravity-ui/uikit';
|
|
4
3
|
import cloneDeep from 'lodash/cloneDeep';
|
|
@@ -7,9 +6,8 @@ import { LazyLoader } from '../../LazyLoader';
|
|
|
7
6
|
import { loadIcon } from './utils';
|
|
8
7
|
import './TextContent.css';
|
|
9
8
|
const b = block('text-content');
|
|
10
|
-
export const
|
|
11
|
-
var
|
|
12
|
-
var { spec, Layout, input } = _a, restProps = __rest(_a, ["spec", "Layout", "input"]);
|
|
9
|
+
export const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
10
|
+
var _a;
|
|
13
11
|
const { textContentParams, layoutDescription } = spec.viewSpec;
|
|
14
12
|
const text = React.useMemo(() => ((textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text) ? textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text : layoutDescription), [layoutDescription, textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text]);
|
|
15
13
|
if (!text) {
|
|
@@ -18,22 +16,34 @@ export const TextContent = (_a) => {
|
|
|
18
16
|
const iconLib = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) ? (React.createElement(LazyLoader, { component: loadIcon(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) })) : null;
|
|
19
17
|
let content = React.createElement("span", { dangerouslySetInnerHTML: { __html: text } });
|
|
20
18
|
if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
21
|
-
content = (React.createElement(Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value:
|
|
19
|
+
content = (React.createElement(Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
22
20
|
}
|
|
23
21
|
else {
|
|
24
22
|
content = (React.createElement("div", { className: b('wrapper') },
|
|
25
|
-
iconLib ? (React.createElement(Text, { color: (
|
|
23
|
+
iconLib ? (React.createElement(Text, { color: (_a = spec.viewSpec.textContentParams) === null || _a === void 0 ? void 0 : _a.iconColor, className: b('icon') }, iconLib)) : null,
|
|
26
24
|
content,
|
|
27
|
-
|
|
25
|
+
value ? (React.createElement(React.Fragment, null,
|
|
28
26
|
React.createElement(Text, { className: b('separator') }, ":"),
|
|
29
|
-
React.createElement(Text, { color: "secondary" },
|
|
27
|
+
React.createElement(Text, { color: "secondary" }, value))) : null));
|
|
30
28
|
}
|
|
31
29
|
if (Layout) {
|
|
32
30
|
const _spec = cloneDeep(spec);
|
|
33
31
|
if (!(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text)) {
|
|
34
32
|
_spec.viewSpec.layoutDescription = undefined;
|
|
35
33
|
}
|
|
36
|
-
return
|
|
34
|
+
return React.createElement(Layout, { spec: _spec }, content);
|
|
37
35
|
}
|
|
38
36
|
return content;
|
|
39
37
|
};
|
|
38
|
+
export const TextContent = ({ name, spec, Layout, input, arrayInput, meta, layoutProps, }) => {
|
|
39
|
+
const WrappedLayout = React.useMemo(() => {
|
|
40
|
+
if (Layout) {
|
|
41
|
+
const Component = (props) => {
|
|
42
|
+
return (React.createElement(Layout, Object.assign({ name: name, input: input, layoutProps: layoutProps, arrayInput: arrayInput, meta: meta }, props)));
|
|
43
|
+
};
|
|
44
|
+
return Component;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}, [Layout, layoutProps, input, arrayInput, meta, name]);
|
|
48
|
+
return React.createElement(TextContentComponent, { spec: spec, value: input.value, Layout: WrappedLayout });
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextContentComponent } from '../Inputs';
|
|
3
|
+
export const TextContentView = ({ name, spec, Layout, value }) => {
|
|
4
|
+
const WrappedLayout = React.useMemo(() => {
|
|
5
|
+
if (Layout) {
|
|
6
|
+
const Component = (props) => {
|
|
7
|
+
const VALUE_STUB = 'if u see this, please create issue about it here: https://github.com/gravity-ui/dynamic-forms/issues/new';
|
|
8
|
+
return React.createElement(Layout, Object.assign({ name: name, value: VALUE_STUB }, props));
|
|
9
|
+
};
|
|
10
|
+
return Component;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}, [Layout, name]);
|
|
14
|
+
return React.createElement(TextContentComponent, { spec: spec, value: value, Layout: WrappedLayout });
|
|
15
|
+
};
|
|
@@ -12,6 +12,7 @@ export * from './ObjectValueInputView';
|
|
|
12
12
|
export * from './OneOfView';
|
|
13
13
|
export * from './TableArrayView';
|
|
14
14
|
export * from './TextAreaView';
|
|
15
|
+
export * from './TextContentView';
|
|
15
16
|
export * from './TextLinkView';
|
|
16
17
|
export * from './TimeRangeSelectorView';
|
|
17
18
|
export * from './DateView';
|
|
@@ -12,6 +12,7 @@ export * from './ObjectValueInputView';
|
|
|
12
12
|
export * from './OneOfView';
|
|
13
13
|
export * from './TableArrayView';
|
|
14
14
|
export * from './TextAreaView';
|
|
15
|
+
export * from './TextContentView';
|
|
15
16
|
export * from './TextLinkView';
|
|
16
17
|
export * from './TimeRangeSelectorView';
|
|
17
18
|
export * from './DateView';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, CheckboxGroup, CheckboxGroupView, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, TimeRangeSelector, TimeRangeSelectorView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
|
|
1
|
+
import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, CheckboxGroup, CheckboxGroupView, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextContentView, TextLink, TextLinkView, TimeRangeSelector, TimeRangeSelectorView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
|
|
2
2
|
import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
|
|
3
3
|
export const dynamicConfig = {
|
|
4
4
|
array: {
|
|
@@ -199,7 +199,7 @@ export const dynamicViewConfig = {
|
|
|
199
199
|
file_input: { Component: FileInputView },
|
|
200
200
|
number_with_scale: { Component: NumberWithScaleView },
|
|
201
201
|
monaco_input: { Component: MonacoView },
|
|
202
|
-
text_content:
|
|
202
|
+
text_content: { Component: TextContentView, independent: true },
|
|
203
203
|
},
|
|
204
204
|
layouts: {
|
|
205
205
|
row: ViewRow,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/dynamic-forms",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"playwright:install": "playwright install --with-deps",
|
|
39
39
|
"playwright": "playwright test --config=playwright/playwright.config.ts",
|
|
40
40
|
"playwright:update": "npm run playwright -- -u",
|
|
41
|
+
"playwright:clear-cache": "rm -rf ./playwright/.cache",
|
|
41
42
|
"playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'",
|
|
42
43
|
"playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'",
|
|
43
44
|
"playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache"
|