@gravity-ui/dynamic-forms 1.2.0 → 1.3.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/CHANGELOG.md +14 -0
- package/build/cjs/lib/core/components/Form/Controller.js +9 -3
- package/build/cjs/lib/core/components/Form/DynamicField.js +11 -4
- package/build/cjs/lib/core/components/Form/hooks/index.js +3 -0
- package/build/cjs/lib/core/components/Form/hooks/useControllerMirror.js +19 -0
- package/build/cjs/lib/core/components/Form/hooks/useDynamicFieldMirror.js +22 -0
- package/build/cjs/lib/core/components/Form/hooks/useField.js +1 -1
- package/build/cjs/lib/core/components/Form/hooks/useIntegrationFF.js +46 -0
- package/build/cjs/lib/core/components/Form/hooks/useSearchStore.js +5 -2
- package/build/cjs/lib/core/components/Form/hooks/useStore.js +3 -35
- package/build/cjs/lib/core/components/Form/types/index.js +2 -0
- package/build/cjs/lib/core/components/Form/types/mirror.js +2 -0
- package/build/cjs/lib/core/components/Form/types/store.js +2 -0
- package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -2
- package/build/cjs/lib/kit/components/Inputs/TextLink/TextLink.js +20 -0
- package/build/cjs/lib/kit/components/Inputs/TextLink/index.js +4 -0
- package/build/cjs/lib/kit/components/Inputs/index.js +1 -0
- package/build/cjs/lib/kit/components/Layouts/Row/Row.css +18 -10
- package/build/cjs/lib/kit/components/Layouts/Row/Row.js +4 -5
- package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +17 -0
- package/build/cjs/lib/kit/components/Views/TextLinkView/index.js +4 -0
- package/build/cjs/lib/kit/components/Views/index.js +1 -0
- package/build/cjs/lib/kit/constants/config.js +4 -0
- package/build/cjs/lib/kit/validators/validators.js +1 -2
- package/build/esm/lib/core/components/Form/Controller.js +9 -3
- package/build/esm/lib/core/components/Form/DynamicField.d.ts +2 -1
- package/build/esm/lib/core/components/Form/DynamicField.js +12 -5
- package/build/esm/lib/core/components/Form/hooks/index.d.ts +3 -0
- package/build/esm/lib/core/components/Form/hooks/index.js +3 -0
- package/build/esm/lib/core/components/Form/hooks/useControllerMirror.d.ts +2 -0
- package/build/esm/lib/core/components/Form/hooks/useControllerMirror.js +14 -0
- package/build/esm/lib/core/components/Form/hooks/useDynamicFieldMirror.d.ts +2 -0
- package/build/esm/lib/core/components/Form/hooks/useDynamicFieldMirror.js +17 -0
- package/build/esm/lib/core/components/Form/hooks/useField.d.ts +2 -2
- package/build/esm/lib/core/components/Form/hooks/useField.js +1 -1
- package/build/esm/lib/core/components/Form/hooks/useIntegrationFF.d.ts +2 -0
- package/build/esm/lib/core/components/Form/hooks/useIntegrationFF.js +41 -0
- package/build/esm/lib/core/components/Form/hooks/useSearchStore.d.ts +2 -4
- package/build/esm/lib/core/components/Form/hooks/useSearchStore.js +5 -2
- package/build/esm/lib/core/components/Form/hooks/useStore.d.ts +2 -8
- package/build/esm/lib/core/components/Form/hooks/useStore.js +5 -37
- package/build/esm/lib/core/components/Form/types/context.d.ts +2 -1
- package/build/esm/lib/core/components/Form/types/index.d.ts +2 -0
- package/build/esm/lib/core/components/Form/types/index.js +2 -0
- package/build/esm/lib/core/components/Form/types/mirror.d.ts +17 -0
- package/build/esm/lib/core/components/Form/types/mirror.js +1 -0
- package/build/esm/lib/core/components/Form/types/store.d.ts +7 -0
- package/build/esm/lib/core/components/Form/types/store.js +1 -0
- package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -2
- package/build/esm/lib/kit/components/Inputs/TextLink/TextLink.d.ts +2 -0
- package/build/esm/lib/kit/components/Inputs/TextLink/TextLink.js +15 -0
- package/build/esm/lib/kit/components/Inputs/TextLink/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/TextLink/index.js +1 -0
- package/build/esm/lib/kit/components/Inputs/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/index.js +1 -0
- package/build/esm/lib/kit/components/Layouts/Row/Row.css +18 -10
- package/build/esm/lib/kit/components/Layouts/Row/Row.js +4 -5
- package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.d.ts +2 -0
- package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +12 -0
- package/build/esm/lib/kit/components/Views/TextLinkView/index.d.ts +1 -0
- package/build/esm/lib/kit/components/Views/TextLinkView/index.js +1 -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 +5 -1
- package/build/esm/lib/kit/validators/validators.js +1 -2
- package/package.json +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.2.0...v1.3.0) (2023-03-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* update row note position ([#20](https://github.com/gravity-ui/dynamic-forms/issues/20)) ([4f15395](https://github.com/gravity-ui/dynamic-forms/commit/4f153959596d3325ddeb2c2e9b24382e36d2db75))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add fixes + tests ([#15](https://github.com/gravity-ui/dynamic-forms/issues/15)) ([80113dd](https://github.com/gravity-ui/dynamic-forms/commit/80113dd05737b18158865506ed3ac8479d69e8d0))
|
|
14
|
+
* **search:** fixed bug related to form blinking ([#21](https://github.com/gravity-ui/dynamic-forms/issues/21)) ([20bab2f](https://github.com/gravity-ui/dynamic-forms/commit/20bab2f628d698714bcee35993583f2c7712e843))
|
|
15
|
+
* **textArea:** fixed row for text area ([#22](https://github.com/gravity-ui/dynamic-forms/issues/22)) ([d5469e7](https://github.com/gravity-ui/dynamic-forms/commit/d5469e7dd0eee86b26e8daba94e93d2fa9465b96))
|
|
16
|
+
|
|
3
17
|
## [1.2.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.1...v1.2.0) (2023-03-23)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -5,9 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const helpers_1 = require("../../helpers");
|
|
7
7
|
const hooks_1 = require("./hooks");
|
|
8
|
-
const useSearch_1 = require("./hooks/useSearch");
|
|
9
8
|
const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
|
|
10
|
-
const { tools } = (0, hooks_1.useDynamicFormsCtx)();
|
|
9
|
+
const { tools, __mirror } = (0, hooks_1.useDynamicFormsCtx)();
|
|
11
10
|
const { inputEntity, Layout } = (0, hooks_1.useComponents)(spec);
|
|
12
11
|
const render = (0, hooks_1.useRender)({ name, spec, inputEntity, Layout });
|
|
13
12
|
const validate = (0, hooks_1.useValidate)(spec);
|
|
@@ -20,7 +19,14 @@ const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount,
|
|
|
20
19
|
parentOnChange,
|
|
21
20
|
parentOnUnmount,
|
|
22
21
|
});
|
|
23
|
-
const withSearch = (0,
|
|
22
|
+
const withSearch = (0, hooks_1.useSearch)(spec, renderProps.input.value, name);
|
|
23
|
+
(0, hooks_1.useControllerMirror)(name, {
|
|
24
|
+
useComponents: { inputEntity, Layout },
|
|
25
|
+
useRender: render,
|
|
26
|
+
useValidate: validate,
|
|
27
|
+
useField: renderProps,
|
|
28
|
+
useSearch: withSearch,
|
|
29
|
+
}, __mirror);
|
|
24
30
|
if (lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec)) {
|
|
25
31
|
return withSearch(render(renderProps));
|
|
26
32
|
}
|
|
@@ -9,16 +9,18 @@ const helpers_1 = require("../../helpers");
|
|
|
9
9
|
const Controller_1 = require("./Controller");
|
|
10
10
|
const hooks_1 = require("./hooks");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
-
const DynamicField = ({ name, spec, config, Monaco, search }) => {
|
|
12
|
+
const DynamicField = ({ name, spec, config, Monaco, search, __mirror, }) => {
|
|
13
13
|
const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
|
|
14
14
|
const SearchContext = (0, hooks_1.useCreateSearchContext)();
|
|
15
|
-
const { tools,
|
|
16
|
-
const
|
|
15
|
+
const { tools, store } = (0, hooks_1.useStore)(name);
|
|
16
|
+
const watcher = (0, hooks_1.useIntegrationFF)(store);
|
|
17
|
+
const { store: searchStore, setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)();
|
|
17
18
|
const context = react_1.default.useMemo(() => ({
|
|
18
19
|
config,
|
|
19
20
|
Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
|
|
20
21
|
tools,
|
|
21
|
-
|
|
22
|
+
__mirror,
|
|
23
|
+
}), [tools, config, Monaco, __mirror]);
|
|
22
24
|
const searchContext = react_1.default.useMemo(() => ({
|
|
23
25
|
setField,
|
|
24
26
|
removeField,
|
|
@@ -26,6 +28,11 @@ const DynamicField = ({ name, spec, config, Monaco, search }) => {
|
|
|
26
28
|
searchFunction: lodash_1.default.isFunction(search) ? search : (0, utils_1.getDefaultSearchFunction)(search),
|
|
27
29
|
}), [isHiddenField, removeField, search, setField]);
|
|
28
30
|
const correctParams = react_1.default.useMemo(() => lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec) && (0, utils_1.isCorrectConfig)(config), [name, spec, config]);
|
|
31
|
+
(0, hooks_1.useDynamicFieldMirror)({
|
|
32
|
+
useStore: { tools, store },
|
|
33
|
+
useIntegrationFF: watcher,
|
|
34
|
+
useSearchStore: { store: searchStore, setField, removeField, isHiddenField },
|
|
35
|
+
}, __mirror);
|
|
29
36
|
if (correctParams) {
|
|
30
37
|
return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
31
38
|
react_1.default.createElement(SearchContext.Provider, { value: searchContext },
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./useComponents"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./useControllerMirror"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./useCreateContext"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./useDynamicFieldMirror"), exports);
|
|
6
8
|
tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
|
|
7
9
|
tslib_1.__exportStar(require("./useField"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./useIntegrationFF"), exports);
|
|
8
11
|
tslib_1.__exportStar(require("./useRender"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./useStore"), exports);
|
|
10
13
|
tslib_1.__exportStar(require("./useValidate"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useControllerMirror = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const useControllerMirror = (name, params, __mirror) => {
|
|
7
|
+
if (__mirror === null || __mirror === void 0 ? void 0 : __mirror.controller) {
|
|
8
|
+
__mirror.controller[name] = params;
|
|
9
|
+
}
|
|
10
|
+
react_1.default.useEffect(() => {
|
|
11
|
+
return () => {
|
|
12
|
+
var _a;
|
|
13
|
+
if ((_a = __mirror === null || __mirror === void 0 ? void 0 : __mirror.controller) === null || _a === void 0 ? void 0 : _a[name]) {
|
|
14
|
+
delete __mirror.controller[name];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
};
|
|
19
|
+
exports.useControllerMirror = useControllerMirror;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDynamicFieldMirror = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const useDynamicFieldMirror = (params, __mirror) => {
|
|
7
|
+
if (__mirror === null || __mirror === void 0 ? void 0 : __mirror.field) {
|
|
8
|
+
__mirror.field.useStore = params.useStore;
|
|
9
|
+
__mirror.field.useIntegrationFF = params.useIntegrationFF;
|
|
10
|
+
__mirror.field.useSearchStore = params.useSearchStore;
|
|
11
|
+
}
|
|
12
|
+
react_1.default.useEffect(() => {
|
|
13
|
+
return () => {
|
|
14
|
+
if (__mirror === null || __mirror === void 0 ? void 0 : __mirror.field) {
|
|
15
|
+
delete __mirror.field.useStore;
|
|
16
|
+
delete __mirror.field.useIntegrationFF;
|
|
17
|
+
delete __mirror.field.useSearchStore;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
exports.useDynamicFieldMirror = useDynamicFieldMirror;
|
|
@@ -126,7 +126,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
|
|
|
126
126
|
onDrop,
|
|
127
127
|
]);
|
|
128
128
|
react_1.default.useEffect(() => {
|
|
129
|
-
if (!firstRenderRef.current || !lodash_1.default.isEqual(initialValue, state.value)) {
|
|
129
|
+
if (!firstRenderRef.current || !lodash_1.default.isEqual(initialValue, state.value) || state.error) {
|
|
130
130
|
(parentOnChange ? parentOnChange : tools.onChange)(name, state.value, Object.assign(Object.assign({}, state.childErrors), { [name]: state.error }));
|
|
131
131
|
}
|
|
132
132
|
}, [state.value]);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIntegrationFF = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
+
const debounce_1 = tslib_1.__importDefault(require("lodash/debounce"));
|
|
8
|
+
const react_final_form_1 = require("react-final-form");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const useIntegrationFF = (store) => {
|
|
11
|
+
const form = (0, react_final_form_1.useForm)();
|
|
12
|
+
const watcher = react_1.default.useMemo(() => {
|
|
13
|
+
const props = {
|
|
14
|
+
name: store.name,
|
|
15
|
+
render: () => null,
|
|
16
|
+
subscription: {},
|
|
17
|
+
validate: () => {
|
|
18
|
+
const asyncErrors = [];
|
|
19
|
+
let error;
|
|
20
|
+
lodash_1.default.values(store.errors).forEach((err) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
if (lodash_1.default.isFunction(err === null || err === void 0 ? void 0 : err.then)) {
|
|
23
|
+
asyncErrors.push(err);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
error = err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
if (asyncErrors.length) {
|
|
31
|
+
return Promise.all(asyncErrors).then((r) => r[0]);
|
|
32
|
+
}
|
|
33
|
+
return error;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return react_1.default.createElement(react_final_form_1.Field, Object.assign({}, props));
|
|
37
|
+
}, [store.name, store.errors]);
|
|
38
|
+
const change = react_1.default.useCallback((0, debounce_1.default)((value) => {
|
|
39
|
+
form.change(store.name, lodash_1.default.get((0, utils_1.transformArrOut)(value), store.name));
|
|
40
|
+
}, 100), [form.change, store.name]);
|
|
41
|
+
react_1.default.useEffect(() => {
|
|
42
|
+
change(store.values);
|
|
43
|
+
}, [store.values]);
|
|
44
|
+
return watcher;
|
|
45
|
+
};
|
|
46
|
+
exports.useIntegrationFF = useIntegrationFF;
|
|
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
7
|
const __1 = require("../");
|
|
8
|
-
const useSearchStore = (
|
|
9
|
-
const [store, setStore] = react_1.default.useState({
|
|
8
|
+
const useSearchStore = () => {
|
|
9
|
+
const [store, setStore] = react_1.default.useState({});
|
|
10
10
|
const isHiddenField = react_1.default.useCallback((name) => {
|
|
11
11
|
const selfFlag = store[name];
|
|
12
12
|
if (selfFlag === false) {
|
|
@@ -24,6 +24,9 @@ const useSearchStore = (name) => {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
if (lodash_1.default.isUndefined(selfFlag)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
27
30
|
return true;
|
|
28
31
|
}, [store]);
|
|
29
32
|
return {
|
|
@@ -21,44 +21,12 @@ const useStore = (name) => {
|
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
const submitFailed = form.getState().submitFailed;
|
|
24
|
-
const watcher = react_1.default.useMemo(() => {
|
|
25
|
-
const props = {
|
|
26
|
-
name: store.name,
|
|
27
|
-
render: () => null,
|
|
28
|
-
subscription: {},
|
|
29
|
-
validate: () => {
|
|
30
|
-
const asyncErrors = [];
|
|
31
|
-
let error;
|
|
32
|
-
lodash_1.default.values(store.errors).forEach((err) => {
|
|
33
|
-
if (err) {
|
|
34
|
-
if (lodash_1.default.isFunction(err === null || err === void 0 ? void 0 : err.then)) {
|
|
35
|
-
asyncErrors.push(err);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
error = err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
if (asyncErrors.length) {
|
|
43
|
-
return Promise.all(asyncErrors).then((r) => r[0]);
|
|
44
|
-
}
|
|
45
|
-
return error;
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
return react_1.default.createElement(react_final_form_1.Field, Object.assign({}, props));
|
|
49
|
-
}, [store.name, store.errors]);
|
|
50
24
|
const tools = react_1.default.useMemo(() => ({
|
|
51
25
|
initialValue: store.initialValue,
|
|
52
|
-
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: lodash_1.default.set(Object.assign({}, store.values), name, value), errors: errors || {} }))),
|
|
53
|
-
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { errors: lodash_1.default.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
26
|
+
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: lodash_1.default.set(Object.assign({}, store.values), name, lodash_1.default.clone(value)), errors: errors || {} }))),
|
|
27
|
+
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { values: lodash_1.default.omit(store.values, name), errors: lodash_1.default.omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
54
28
|
submitFailed,
|
|
55
29
|
}), [store.initialValue, setStore, submitFailed]);
|
|
56
|
-
const change = react_1.default.useCallback(lodash_1.default.debounce((value) => {
|
|
57
|
-
form.change(store.name, lodash_1.default.get((0, utils_1.transformArrOut)(value), store.name));
|
|
58
|
-
}, 100), [form.change, store.name]);
|
|
59
|
-
react_1.default.useEffect(() => {
|
|
60
|
-
change(store.values);
|
|
61
|
-
}, [store.values]);
|
|
62
30
|
react_1.default.useEffect(() => {
|
|
63
31
|
if (!firstRenderRef.current) {
|
|
64
32
|
const initialValue = (0, utils_1.transformArrIn)({
|
|
@@ -75,6 +43,6 @@ const useStore = (name) => {
|
|
|
75
43
|
react_1.default.useEffect(() => {
|
|
76
44
|
firstRenderRef.current = false;
|
|
77
45
|
}, []);
|
|
78
|
-
return { tools,
|
|
46
|
+
return { tools, store };
|
|
79
47
|
};
|
|
80
48
|
exports.useStore = useStore;
|
|
@@ -8,8 +8,10 @@ tslib_1.__exportStar(require("./context"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./field"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./input"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./layout"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./mirror"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./number"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./object"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./store"), exports);
|
|
13
15
|
tslib_1.__exportStar(require("./string"), exports);
|
|
14
16
|
tslib_1.__exportStar(require("./validators"), exports);
|
|
15
17
|
tslib_1.__exportStar(require("./value"), exports);
|
|
@@ -68,9 +68,10 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
|
|
|
68
68
|
return [idxColumn, ...columns, removeColumn];
|
|
69
69
|
}, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
|
|
70
70
|
const getRowClassNames = react_1.default.useCallback(({ key }) => {
|
|
71
|
-
|
|
71
|
+
var _a;
|
|
72
|
+
const searchResult = (_a = spec.viewSpec.table) === null || _a === void 0 ? void 0 : _a.every(({ property }) => isHiddenField(`${name}.<${key}>.${property}`));
|
|
72
73
|
return [b('row', { hidden: searchResult })];
|
|
73
|
-
}, [isHiddenField, name]);
|
|
74
|
+
}, [isHiddenField, name, spec.viewSpec.table]);
|
|
74
75
|
if (!columns) {
|
|
75
76
|
return null;
|
|
76
77
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextLink = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
+
const core_1 = require("../../../../core");
|
|
8
|
+
const TEXT_LINK_PROPERTY_NAME = 'text';
|
|
9
|
+
const TextLink = ({ spec, input, name }) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
|
|
12
|
+
const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
|
|
13
|
+
const specProperties = Object.assign({}, spec.properties);
|
|
14
|
+
if (!specProperties[TEXT_LINK_PROPERTY_NAME] ||
|
|
15
|
+
!(0, core_1.isStringSpec)(specProperties[TEXT_LINK_PROPERTY_NAME])) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME], spec: specProperties[TEXT_LINK_PROPERTY_NAME], name: `${name}.${TEXT_LINK_PROPERTY_NAME}`, key: `${name}.${TEXT_LINK_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount }));
|
|
19
|
+
};
|
|
20
|
+
exports.TextLink = TextLink;
|
|
@@ -14,5 +14,6 @@ tslib_1.__exportStar(require("./TableArrayInput"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./Text"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./TextArea"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./TextContent"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./TextLink"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./NumberWithScale"), exports);
|
|
18
19
|
tslib_1.__exportStar(require("./MonacoInput"), exports);
|
|
@@ -13,13 +13,16 @@
|
|
|
13
13
|
}
|
|
14
14
|
.df-row__left {
|
|
15
15
|
width: 180px;
|
|
16
|
+
min-height: 28px;
|
|
16
17
|
display: flex;
|
|
18
|
+
margin-bottom: auto;
|
|
17
19
|
flex-direction: column;
|
|
18
20
|
flex-shrink: 0;
|
|
19
21
|
}
|
|
20
22
|
.df-row__left-inner {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
display: inline;
|
|
24
|
+
margin-top: auto;
|
|
25
|
+
margin-bottom: auto;
|
|
23
26
|
}
|
|
24
27
|
.df-row__left::after {
|
|
25
28
|
content: "";
|
|
@@ -27,18 +30,24 @@
|
|
|
27
30
|
flex-shrink: 1;
|
|
28
31
|
}
|
|
29
32
|
.df-row__title {
|
|
30
|
-
|
|
33
|
+
word-break: break-word;
|
|
34
|
+
margin-right: 3px;
|
|
35
|
+
}
|
|
36
|
+
.df-row__title_required::after {
|
|
37
|
+
content: "*";
|
|
38
|
+
color: var(--yc-color-text-danger);
|
|
31
39
|
}
|
|
32
40
|
.df-row__note {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
padding-right: 16px;
|
|
42
|
+
}
|
|
43
|
+
.df-row__note-inner {
|
|
44
|
+
position: absolute;
|
|
45
|
+
margin-top: 1px;
|
|
37
46
|
}
|
|
38
|
-
.df-row__note .yc-help-popover {
|
|
47
|
+
.df-row__note-inner .yc-help-popover {
|
|
39
48
|
display: flex;
|
|
40
49
|
}
|
|
41
|
-
.df-row__note .yc-help-popover > span {
|
|
50
|
+
.df-row__note-inner .yc-help-popover > span {
|
|
42
51
|
display: flex;
|
|
43
52
|
}
|
|
44
53
|
.df-row__right {
|
|
@@ -59,6 +68,5 @@
|
|
|
59
68
|
margin-left: 5px;
|
|
60
69
|
}
|
|
61
70
|
.df-row__required-mark {
|
|
62
|
-
margin-left: 2px;
|
|
63
71
|
color: var(--yc-color-text-danger);
|
|
64
72
|
}
|
|
@@ -14,11 +14,10 @@ const RowBase = ({ name, spec, input, meta, verboseDescription, children, }) =>
|
|
|
14
14
|
return (react_1.default.createElement("div", { className: b({ 'extra-width': (0, core_1.isArraySpec)(spec) || arrayItem }) },
|
|
15
15
|
react_1.default.createElement("div", { className: b('left') },
|
|
16
16
|
react_1.default.createElement("div", { className: b('left-inner') },
|
|
17
|
-
react_1.default.createElement("
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
react_1.default.createElement(uikit_1.HelpPopover, { htmlContent: spec.viewSpec.layoutDescription, placement: ['bottom', 'top'] }))) : null)),
|
|
17
|
+
react_1.default.createElement("span", { className: b('title', { required: spec.required }) }, spec.viewSpec.layoutTitle),
|
|
18
|
+
!verboseDescription && spec.viewSpec.layoutDescription ? (react_1.default.createElement("span", { className: b('note') },
|
|
19
|
+
react_1.default.createElement("span", { className: b('note-inner') },
|
|
20
|
+
react_1.default.createElement(uikit_1.HelpPopover, { htmlContent: spec.viewSpec.layoutDescription, placement: ['bottom', 'top'] })))) : null)),
|
|
22
21
|
react_1.default.createElement("div", { className: b('right') },
|
|
23
22
|
react_1.default.createElement("div", { className: b('right-inner') },
|
|
24
23
|
react_1.default.createElement(components_1.ErrorWrapper, { name: name, meta: meta, withoutChildErrorStyles: (0, core_1.isArraySpec)(spec) || (0, core_1.isObjectSpec)(spec) }, children),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextLinkView = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const core_1 = require("../../../../core");
|
|
7
|
+
const TEXT_LINK_PROPERTY_NAME = 'text';
|
|
8
|
+
const TextLinkView = ({ value, spec, name }) => {
|
|
9
|
+
const specProperties = spec.properties;
|
|
10
|
+
const preparedSpec = react_1.default.useMemo(() => {
|
|
11
|
+
var _a;
|
|
12
|
+
return specProperties && specProperties[TEXT_LINK_PROPERTY_NAME]
|
|
13
|
+
? Object.assign(Object.assign({}, specProperties[TEXT_LINK_PROPERTY_NAME]), { viewSpec: Object.assign(Object.assign({}, (_a = specProperties[TEXT_LINK_PROPERTY_NAME]) === null || _a === void 0 ? void 0 : _a.viewSpec), { link: value === null || value === void 0 ? void 0 : value.link }) }) : undefined;
|
|
14
|
+
}, [specProperties, value === null || value === void 0 ? void 0 : value.link]);
|
|
15
|
+
return preparedSpec ? (react_1.default.createElement(core_1.ViewController, { spec: preparedSpec, name: `${name}.${TEXT_LINK_PROPERTY_NAME}` })) : null;
|
|
16
|
+
};
|
|
17
|
+
exports.TextLinkView = TextLinkView;
|
|
@@ -12,3 +12,4 @@ tslib_1.__exportStar(require("./OneOfCardView"), exports);
|
|
|
12
12
|
tslib_1.__exportStar(require("./OneOfView"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./TableArrayView"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./TextAreaView"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./TextLinkView"), exports);
|
|
@@ -60,6 +60,7 @@ exports.dynamicConfig = {
|
|
|
60
60
|
card_oneof: { Component: components_1.CardOneOf, independent: true },
|
|
61
61
|
secret: { Component: components_1.Secret, independent: true },
|
|
62
62
|
base: { Component: components_1.ObjectBase, independent: true },
|
|
63
|
+
text_link: { Component: components_1.TextLink, independent: true },
|
|
63
64
|
},
|
|
64
65
|
layouts: {
|
|
65
66
|
row: components_1.Row,
|
|
@@ -155,6 +156,7 @@ exports.dynamicCardConfig = {
|
|
|
155
156
|
oneof: { Component: components_1.OneOfCard, independent: true },
|
|
156
157
|
secret: { Component: components_1.Secret, independent: true },
|
|
157
158
|
base: { Component: components_1.ObjectBase, independent: true },
|
|
159
|
+
text_link: { Component: components_1.TextLink, independent: true },
|
|
158
160
|
},
|
|
159
161
|
layouts: {
|
|
160
162
|
row: components_1.Row2,
|
|
@@ -239,6 +241,7 @@ exports.dynamicViewConfig = {
|
|
|
239
241
|
card_oneof: { Component: components_1.CardOneOfView, independent: true },
|
|
240
242
|
secret: undefined,
|
|
241
243
|
base: { Component: components_1.ObjectBaseView, independent: true },
|
|
244
|
+
text_link: { Component: components_1.TextLinkView, independent: true },
|
|
242
245
|
},
|
|
243
246
|
layouts: {
|
|
244
247
|
row: components_1.ViewRow,
|
|
@@ -316,6 +319,7 @@ exports.dynamicViewCardConfig = {
|
|
|
316
319
|
oneof: { Component: components_1.OneOfCardView, independent: true },
|
|
317
320
|
secret: undefined,
|
|
318
321
|
base: { Component: components_1.ObjectBaseView, independent: true },
|
|
322
|
+
text_link: { Component: components_1.TextLinkView, independent: true },
|
|
319
323
|
},
|
|
320
324
|
layouts: {
|
|
321
325
|
row: components_1.ViewRow2,
|
|
@@ -71,8 +71,7 @@ const getNumberValidator = (params = {}) => {
|
|
|
71
71
|
}
|
|
72
72
|
if (!ignoreMinimumCheck &&
|
|
73
73
|
lodash_1.default.isNumber(spec.minimum) &&
|
|
74
|
-
stringValue.length &&
|
|
75
|
-
spec.minimum > Number(stringValue)) {
|
|
74
|
+
((stringValue.length && spec.minimum > Number(stringValue)) || !stringValue.length)) {
|
|
76
75
|
return validators_1.ErrorMessages.minNumber(spec.minimum);
|
|
77
76
|
}
|
|
78
77
|
if (lodash_1.default.isString(spec.format) && stringValue.length) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { isCorrectSpec } from '../../helpers';
|
|
3
|
-
import { useComponents, useDynamicFormsCtx, useField, useRender, useValidate } from './hooks';
|
|
4
|
-
import { useSearch } from './hooks/useSearch';
|
|
3
|
+
import { useComponents, useControllerMirror, useDynamicFormsCtx, useField, useRender, useSearch, useValidate, } from './hooks';
|
|
5
4
|
export const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
|
|
6
|
-
const { tools } = useDynamicFormsCtx();
|
|
5
|
+
const { tools, __mirror } = useDynamicFormsCtx();
|
|
7
6
|
const { inputEntity, Layout } = useComponents(spec);
|
|
8
7
|
const render = useRender({ name, spec, inputEntity, Layout });
|
|
9
8
|
const validate = useValidate(spec);
|
|
@@ -17,6 +16,13 @@ export const Controller = ({ spec, name, initialValue, parentOnChange, parentOnU
|
|
|
17
16
|
parentOnUnmount,
|
|
18
17
|
});
|
|
19
18
|
const withSearch = useSearch(spec, renderProps.input.value, name);
|
|
19
|
+
useControllerMirror(name, {
|
|
20
|
+
useComponents: { inputEntity, Layout },
|
|
21
|
+
useRender: render,
|
|
22
|
+
useValidate: validate,
|
|
23
|
+
useField: renderProps,
|
|
24
|
+
useSearch: withSearch,
|
|
25
|
+
}, __mirror);
|
|
20
26
|
if (_.isString(name) && isCorrectSpec(spec)) {
|
|
21
27
|
return withSearch(render(renderProps));
|
|
22
28
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { MonacoEditorProps } from 'react-monaco-editor/lib/types';
|
|
3
3
|
import { Spec } from '../../types';
|
|
4
|
-
import { DynamicFormConfig, FieldValue } from './types';
|
|
4
|
+
import { DynamicFormConfig, FieldValue, WonderMirror } from './types';
|
|
5
5
|
export interface DynamicFieldProps {
|
|
6
6
|
name: string;
|
|
7
7
|
spec: Spec;
|
|
8
8
|
config: DynamicFormConfig;
|
|
9
9
|
Monaco?: React.ComponentType<MonacoEditorProps>;
|
|
10
10
|
search?: string | ((spec: Spec, input: FieldValue, name: string) => boolean);
|
|
11
|
+
__mirror?: WonderMirror;
|
|
11
12
|
}
|
|
12
13
|
export declare const DynamicField: React.FC<DynamicFieldProps>;
|
|
@@ -3,18 +3,20 @@ import _ from 'lodash';
|
|
|
3
3
|
import { isValidElementType } from 'react-is';
|
|
4
4
|
import { isCorrectSpec } from '../../helpers';
|
|
5
5
|
import { Controller } from './Controller';
|
|
6
|
-
import { useCreateContext, useCreateSearchContext, useSearchStore, useStore } from './hooks';
|
|
6
|
+
import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useIntegrationFF, useSearchStore, useStore, } from './hooks';
|
|
7
7
|
import { getDefaultSearchFunction, isCorrectConfig } from './utils';
|
|
8
|
-
export const DynamicField = ({ name, spec, config, Monaco, search }) => {
|
|
8
|
+
export const DynamicField = ({ name, spec, config, Monaco, search, __mirror, }) => {
|
|
9
9
|
const DynamicFormsCtx = useCreateContext();
|
|
10
10
|
const SearchContext = useCreateSearchContext();
|
|
11
|
-
const { tools,
|
|
12
|
-
const
|
|
11
|
+
const { tools, store } = useStore(name);
|
|
12
|
+
const watcher = useIntegrationFF(store);
|
|
13
|
+
const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
|
|
13
14
|
const context = React.useMemo(() => ({
|
|
14
15
|
config,
|
|
15
16
|
Monaco: isValidElementType(Monaco) ? Monaco : undefined,
|
|
16
17
|
tools,
|
|
17
|
-
|
|
18
|
+
__mirror,
|
|
19
|
+
}), [tools, config, Monaco, __mirror]);
|
|
18
20
|
const searchContext = React.useMemo(() => ({
|
|
19
21
|
setField,
|
|
20
22
|
removeField,
|
|
@@ -22,6 +24,11 @@ export const DynamicField = ({ name, spec, config, Monaco, search }) => {
|
|
|
22
24
|
searchFunction: _.isFunction(search) ? search : getDefaultSearchFunction(search),
|
|
23
25
|
}), [isHiddenField, removeField, search, setField]);
|
|
24
26
|
const correctParams = React.useMemo(() => _.isString(name) && isCorrectSpec(spec) && isCorrectConfig(config), [name, spec, config]);
|
|
27
|
+
useDynamicFieldMirror({
|
|
28
|
+
useStore: { tools, store },
|
|
29
|
+
useIntegrationFF: watcher,
|
|
30
|
+
useSearchStore: { store: searchStore, setField, removeField, isHiddenField },
|
|
31
|
+
}, __mirror);
|
|
25
32
|
if (correctParams) {
|
|
26
33
|
return (React.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
27
34
|
React.createElement(SearchContext.Provider, { value: searchContext },
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './useComponents';
|
|
2
|
+
export * from './useControllerMirror';
|
|
2
3
|
export * from './useCreateContext';
|
|
4
|
+
export * from './useDynamicFieldMirror';
|
|
3
5
|
export * from './useDynamicFormsCtx';
|
|
4
6
|
export * from './useField';
|
|
7
|
+
export * from './useIntegrationFF';
|
|
5
8
|
export * from './useRender';
|
|
6
9
|
export * from './useStore';
|
|
7
10
|
export * from './useValidate';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './useComponents';
|
|
2
|
+
export * from './useControllerMirror';
|
|
2
3
|
export * from './useCreateContext';
|
|
4
|
+
export * from './useDynamicFieldMirror';
|
|
3
5
|
export * from './useDynamicFormsCtx';
|
|
4
6
|
export * from './useField';
|
|
7
|
+
export * from './useIntegrationFF';
|
|
5
8
|
export * from './useRender';
|
|
6
9
|
export * from './useStore';
|
|
7
10
|
export * from './useValidate';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const useControllerMirror = (name, params, __mirror) => {
|
|
3
|
+
if (__mirror === null || __mirror === void 0 ? void 0 : __mirror.controller) {
|
|
4
|
+
__mirror.controller[name] = params;
|
|
5
|
+
}
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
return () => {
|
|
8
|
+
var _a;
|
|
9
|
+
if ((_a = __mirror === null || __mirror === void 0 ? void 0 : __mirror.controller) === null || _a === void 0 ? void 0 : _a[name]) {
|
|
10
|
+
delete __mirror.controller[name];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}, []);
|
|
14
|
+
};
|