@gravity-ui/dynamic-forms 1.1.0 → 1.2.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/cjs/lib/core/components/Form/Controller.js +13 -3
  3. package/build/cjs/lib/core/components/Form/DynamicField.js +14 -5
  4. package/build/cjs/lib/core/components/Form/hooks/index.js +4 -0
  5. package/build/cjs/lib/core/components/Form/hooks/useComponents.js +2 -2
  6. package/build/cjs/lib/core/components/Form/hooks/useCreateSearchContext.js +9 -0
  7. package/build/cjs/lib/core/components/Form/hooks/useField.js +8 -8
  8. package/build/cjs/lib/core/components/Form/hooks/useSearch/index.js +4 -0
  9. package/build/cjs/lib/core/components/Form/hooks/useSearch/useSearch.css +9 -0
  10. package/build/cjs/lib/core/components/Form/hooks/useSearch/useSearch.js +22 -0
  11. package/build/cjs/lib/core/components/Form/hooks/useSearchContext.js +12 -0
  12. package/build/cjs/lib/core/components/Form/hooks/useSearchStore.js +38 -0
  13. package/build/cjs/lib/core/components/Form/hooks/useStore.js +5 -4
  14. package/build/cjs/lib/core/components/Form/hooks/useValidate.js +2 -2
  15. package/build/cjs/lib/core/components/Form/index.js +1 -1
  16. package/build/cjs/lib/core/components/Form/types/index.js +1 -0
  17. package/build/cjs/lib/core/components/Form/types/search.js +2 -0
  18. package/build/cjs/lib/core/components/Form/{helpers.js → utils/common.js} +2 -2
  19. package/build/cjs/lib/core/components/Form/utils/index.js +5 -0
  20. package/build/cjs/lib/core/components/Form/utils/search.js +19 -0
  21. package/build/cjs/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +4 -3
  22. package/build/cjs/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -1
  23. package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -2
  24. package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.js +2 -1
  25. package/build/cjs/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +2 -1
  26. package/build/cjs/lib/kit/components/Inputs/Secret/Secret.js +2 -1
  27. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +10 -0
  28. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +21 -10
  29. package/build/esm/lib/core/components/Form/Controller.d.ts +2 -1
  30. package/build/esm/lib/core/components/Form/Controller.js +13 -3
  31. package/build/esm/lib/core/components/Form/DynamicField.d.ts +2 -1
  32. package/build/esm/lib/core/components/Form/DynamicField.js +14 -5
  33. package/build/esm/lib/core/components/Form/hooks/index.d.ts +4 -0
  34. package/build/esm/lib/core/components/Form/hooks/index.js +4 -0
  35. package/build/esm/lib/core/components/Form/hooks/useComponents.js +1 -1
  36. package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.d.ts +3 -0
  37. package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.js +4 -0
  38. package/build/esm/lib/core/components/Form/hooks/useField.d.ts +2 -1
  39. package/build/esm/lib/core/components/Form/hooks/useField.js +3 -3
  40. package/build/esm/lib/core/components/Form/hooks/useSearch/index.d.ts +1 -0
  41. package/build/esm/lib/core/components/Form/hooks/useSearch/index.js +1 -0
  42. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.css +9 -0
  43. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.d.ts +4 -0
  44. package/build/esm/lib/core/components/Form/hooks/useSearch/useSearch.js +18 -0
  45. package/build/esm/lib/core/components/Form/hooks/useSearchContext.d.ts +1 -0
  46. package/build/esm/lib/core/components/Form/hooks/useSearchContext.js +7 -0
  47. package/build/esm/lib/core/components/Form/hooks/useSearchStore.d.ts +8 -0
  48. package/build/esm/lib/core/components/Form/hooks/useSearchStore.js +33 -0
  49. package/build/esm/lib/core/components/Form/hooks/useStore.d.ts +1 -0
  50. package/build/esm/lib/core/components/Form/hooks/useStore.js +2 -1
  51. package/build/esm/lib/core/components/Form/hooks/useValidate.js +1 -1
  52. package/build/esm/lib/core/components/Form/index.d.ts +1 -1
  53. package/build/esm/lib/core/components/Form/index.js +1 -1
  54. package/build/esm/lib/core/components/Form/types/context.d.ts +1 -0
  55. package/build/esm/lib/core/components/Form/types/index.d.ts +1 -0
  56. package/build/esm/lib/core/components/Form/types/index.js +1 -0
  57. package/build/esm/lib/core/components/Form/types/search.d.ts +8 -0
  58. package/build/esm/lib/core/components/Form/types/search.js +1 -0
  59. package/build/esm/lib/core/components/Form/{helpers.d.ts → utils/common.d.ts} +1 -1
  60. package/build/esm/lib/core/components/Form/{helpers.js → utils/common.js} +2 -2
  61. package/build/esm/lib/core/components/Form/utils/index.d.ts +2 -0
  62. package/build/esm/lib/core/components/Form/utils/index.js +2 -0
  63. package/build/esm/lib/core/components/Form/utils/search.d.ts +3 -0
  64. package/build/esm/lib/core/components/Form/utils/search.js +14 -0
  65. package/build/esm/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +4 -3
  66. package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -1
  67. package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -2
  68. package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.js +2 -1
  69. package/build/esm/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +2 -1
  70. package/build/esm/lib/kit/components/Inputs/Secret/Secret.js +2 -1
  71. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +10 -0
  72. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +21 -10
  73. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.1...v1.2.0) (2023-03-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * search ([#10](https://github.com/gravity-ui/dynamic-forms/issues/10)) ([4ed7d5c](https://github.com/gravity-ui/dynamic-forms/commit/4ed7d5c85dbb890f4c8148d4de43a626917cec0f))
9
+
10
+ ## [1.1.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.1.0...v1.1.1) (2023-03-21)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * fix incorrect unmount ([#12](https://github.com/gravity-ui/dynamic-forms/issues/12)) ([592652b](https://github.com/gravity-ui/dynamic-forms/commit/592652b2814567b2188ec43779eb591b7dec6ade))
16
+
3
17
  ## [1.1.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.0.2...v1.1.0) (2023-03-19)
4
18
 
5
19
 
@@ -5,14 +5,24 @@ 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 Controller = ({ spec, name, initialValue, parentOnChange, }) => {
8
+ const useSearch_1 = require("./hooks/useSearch");
9
+ const Controller = ({ spec, name, initialValue, parentOnChange, parentOnUnmount, }) => {
9
10
  const { tools } = (0, hooks_1.useDynamicFormsCtx)();
10
11
  const { inputEntity, Layout } = (0, hooks_1.useComponents)(spec);
11
12
  const render = (0, hooks_1.useRender)({ name, spec, inputEntity, Layout });
12
13
  const validate = (0, hooks_1.useValidate)(spec);
13
- const renderProps = (0, hooks_1.useField)({ name, initialValue, spec, validate, tools, parentOnChange });
14
+ const renderProps = (0, hooks_1.useField)({
15
+ name,
16
+ initialValue,
17
+ spec,
18
+ validate,
19
+ tools,
20
+ parentOnChange,
21
+ parentOnUnmount,
22
+ });
23
+ const withSearch = (0, useSearch_1.useSearch)(spec, renderProps.input.value, name);
14
24
  if (lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec)) {
15
- return render(renderProps);
25
+ return withSearch(render(renderProps));
16
26
  }
17
27
  return null;
18
28
  };
@@ -7,21 +7,30 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const react_is_1 = require("react-is");
8
8
  const helpers_1 = require("../../helpers");
9
9
  const Controller_1 = require("./Controller");
10
- const helpers_2 = require("./helpers");
11
10
  const hooks_1 = require("./hooks");
12
- const DynamicField = ({ name, spec, config, Monaco }) => {
11
+ const utils_1 = require("./utils");
12
+ const DynamicField = ({ name, spec, config, Monaco, search }) => {
13
13
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
14
+ const SearchContext = (0, hooks_1.useCreateSearchContext)();
14
15
  const { tools, watcher } = (0, hooks_1.useStore)(name);
16
+ const { setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)(name);
15
17
  const context = react_1.default.useMemo(() => ({
16
18
  config,
17
19
  Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
18
20
  tools,
19
21
  }), [tools, config, Monaco]);
20
- const correctParams = react_1.default.useMemo(() => lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec) && (0, helpers_2.isCorrectConfig)(config), [name, spec, config]);
22
+ const searchContext = react_1.default.useMemo(() => ({
23
+ setField,
24
+ removeField,
25
+ isHiddenField,
26
+ searchFunction: lodash_1.default.isFunction(search) ? search : (0, utils_1.getDefaultSearchFunction)(search),
27
+ }), [isHiddenField, removeField, search, setField]);
28
+ const correctParams = react_1.default.useMemo(() => lodash_1.default.isString(name) && (0, helpers_1.isCorrectSpec)(spec) && (0, utils_1.isCorrectConfig)(config), [name, spec, config]);
21
29
  if (correctParams) {
22
30
  return (react_1.default.createElement(DynamicFormsCtx.Provider, { value: context },
23
- react_1.default.createElement(Controller_1.Controller, { spec: spec, name: name, parentOnChange: null, initialValue: lodash_1.default.get(tools.initialValue, name) }),
24
- watcher));
31
+ react_1.default.createElement(SearchContext.Provider, { value: searchContext },
32
+ react_1.default.createElement(Controller_1.Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, initialValue: lodash_1.default.get(tools.initialValue, name) }),
33
+ watcher)));
25
34
  }
26
35
  return null;
27
36
  };
@@ -9,3 +9,7 @@ tslib_1.__exportStar(require("./useRender"), exports);
9
9
  tslib_1.__exportStar(require("./useStore"), exports);
10
10
  tslib_1.__exportStar(require("./useValidate"), exports);
11
11
  tslib_1.__exportStar(require("./useMonaco"), exports);
12
+ tslib_1.__exportStar(require("./useSearchStore"), exports);
13
+ tslib_1.__exportStar(require("./useSearchContext"), exports);
14
+ tslib_1.__exportStar(require("./useSearch"), exports);
15
+ tslib_1.__exportStar(require("./useCreateSearchContext"), exports);
@@ -6,13 +6,13 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const react_is_1 = require("react-is");
8
8
  const helpers_1 = require("../../../helpers");
9
- const helpers_2 = require("../helpers");
9
+ const utils_1 = require("../utils");
10
10
  const _1 = require("./");
11
11
  const useComponents = (spec) => {
12
12
  var _a, _b;
13
13
  const { config } = (0, _1.useDynamicFormsCtx)();
14
14
  const { inputs, layouts } = react_1.default.useMemo(() => {
15
- if ((0, helpers_2.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
15
+ if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
16
16
  return config[spec.type];
17
17
  }
18
18
  return {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCreateSearchContext = 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 createContext = lodash_1.default.once(() => react_1.default.createContext({}));
8
+ const useCreateSearchContext = () => createContext();
9
+ exports.useCreateSearchContext = useCreateSearchContext;
@@ -6,20 +6,20 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const helpers_1 = require("../../../helpers");
8
8
  const constants_1 = require("../constants");
9
- const helpers_2 = require("../helpers");
10
- const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, }) => {
9
+ const utils_1 = require("../utils");
10
+ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }) => {
11
11
  const firstRenderRef = react_1.default.useRef(true);
12
12
  const validate = react_1.default.useCallback((value) => {
13
13
  if (value === constants_1.REMOVED_ITEM) {
14
14
  return;
15
15
  }
16
- return propsValidate === null || propsValidate === void 0 ? void 0 : propsValidate((0, helpers_2.transformArrOut)(value));
16
+ return propsValidate === null || propsValidate === void 0 ? void 0 : propsValidate((0, utils_1.transformArrOut)(value));
17
17
  }, [propsValidate]);
18
18
  const [state, setState] = react_1.default.useState(() => {
19
19
  let value = lodash_1.default.cloneDeep(initialValue);
20
20
  if (lodash_1.default.isNil(value)) {
21
21
  if (spec.defaultValue) {
22
- value = (0, helpers_2.transformArrIn)(spec.defaultValue);
22
+ value = (0, utils_1.transformArrIn)(spec.defaultValue);
23
23
  }
24
24
  // if the spec with type array or object, and this spec has "required === true",
25
25
  // we immediately exclude empty value
@@ -52,7 +52,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
52
52
  setState((state) => {
53
53
  const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
54
54
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
55
- const value = (0, helpers_2.transformArrIn)(_value);
55
+ const value = (0, utils_1.transformArrIn)(_value);
56
56
  let newChildErrors = Object.assign({}, state.childErrors);
57
57
  if (childErrors) {
58
58
  const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -65,7 +65,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
65
65
  });
66
66
  };
67
67
  const onDrop = () => {
68
- if ((0, helpers_2.isArrayItem)(name)) {
68
+ if ((0, utils_1.isArrayItem)(name)) {
69
69
  onChange(constants_1.REMOVED_ITEM);
70
70
  }
71
71
  else {
@@ -86,7 +86,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
86
86
  [constants_1.OBJECT_ARRAY_FLAG]: true,
87
87
  [constants_1.OBJECT_ARRAY_CNT]: 0,
88
88
  });
89
- const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[constants_1.OBJECT_ARRAY_CNT]}>`]: (0, helpers_2.transformArrIn)(_value), [constants_1.OBJECT_ARRAY_CNT]: stateValue[constants_1.OBJECT_ARRAY_CNT] + 1 });
89
+ const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[constants_1.OBJECT_ARRAY_CNT]}>`]: (0, utils_1.transformArrIn)(_value), [constants_1.OBJECT_ARRAY_CNT]: stateValue[constants_1.OBJECT_ARRAY_CNT] + 1 });
90
90
  const error = validate === null || validate === void 0 ? void 0 : validate(value);
91
91
  setState((state) => (Object.assign(Object.assign({}, state), { dirty: !lodash_1.default.isEqual(value, initialValue), error, invalid: Boolean(error), modified: true, pristine: value === initialValue, touched: true, valid: !error, value, visited: true })));
92
92
  };
@@ -133,7 +133,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
133
133
  react_1.default.useEffect(() => {
134
134
  firstRenderRef.current = false;
135
135
  return () => {
136
- (parentOnChange ? parentOnChange : tools.onChange)(name, state.value, { [name]: false });
136
+ (parentOnUnmount ? parentOnUnmount : tools.onUnmount)(name);
137
137
  };
138
138
  }, []);
139
139
  return renderProps;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./useSearch"), exports);
@@ -0,0 +1,9 @@
1
+ .df-use-search {
2
+ margin-bottom: 15px;
3
+ }
4
+ .df-use-search_hidden {
5
+ display: none;
6
+ }
7
+ .df-use-search:last-child {
8
+ margin-bottom: 0;
9
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const utils_1 = require("../../../../../kit/utils");
7
+ const useSearchContext_1 = require("../useSearchContext");
8
+ const b = (0, utils_1.block)('use-search');
9
+ const useSearch = (spec, value, name) => {
10
+ const { setField, removeField, isHiddenField, searchFunction } = (0, useSearchContext_1.useSearchContext)();
11
+ const searchResult = react_1.default.useMemo(() => !searchFunction(spec, value, name), [name, searchFunction, spec, value]);
12
+ const hidden = react_1.default.useMemo(() => isHiddenField(name), [isHiddenField, name]);
13
+ const withSearch = react_1.default.useCallback((children) => react_1.default.createElement("div", { className: b({ hidden: hidden }) }, children), [hidden]);
14
+ react_1.default.useEffect(() => {
15
+ setField(name, searchResult);
16
+ }, [searchResult]);
17
+ react_1.default.useEffect(() => {
18
+ return () => removeField(name);
19
+ }, []);
20
+ return withSearch;
21
+ };
22
+ exports.useSearch = useSearch;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const index_1 = require("./index");
7
+ const useSearchContext = () => {
8
+ const SearchContext = (0, index_1.useCreateSearchContext)();
9
+ const context = react_1.default.useContext(SearchContext);
10
+ return context;
11
+ };
12
+ exports.useSearchContext = useSearchContext;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchStore = 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 __1 = require("../");
8
+ const useSearchStore = (name) => {
9
+ const [store, setStore] = react_1.default.useState({ [name]: false });
10
+ const isHiddenField = react_1.default.useCallback((name) => {
11
+ const selfFlag = store[name];
12
+ if (selfFlag === false) {
13
+ return false;
14
+ }
15
+ let parentName = (0, __1.getParentName)(name);
16
+ while (parentName) {
17
+ if (store[parentName] === false) {
18
+ return false;
19
+ }
20
+ parentName = (0, __1.getParentName)(parentName);
21
+ }
22
+ for (const key of Object.keys(store)) {
23
+ if (key.includes(name + '.') && !store[key]) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }, [store]);
29
+ return {
30
+ store,
31
+ setField: (name, search) => setStore((store) => (Object.assign(Object.assign({}, store), { [name]: search }))),
32
+ removeField: (name) => {
33
+ setStore((store) => lodash_1.default.omit(store, name));
34
+ },
35
+ isHiddenField,
36
+ };
37
+ };
38
+ exports.useSearchStore = useSearchStore;
@@ -5,12 +5,12 @@ 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 react_final_form_1 = require("react-final-form");
8
- const helpers_1 = require("../helpers");
8
+ const utils_1 = require("../utils");
9
9
  const useStore = (name) => {
10
10
  const form = (0, react_final_form_1.useForm)();
11
11
  const firstRenderRef = react_1.default.useRef(true);
12
12
  const [store, setStore] = react_1.default.useState(() => {
13
- const initialValue = (0, helpers_1.transformArrIn)({
13
+ const initialValue = (0, utils_1.transformArrIn)({
14
14
  [name]: lodash_1.default.get(form.getState().values, name),
15
15
  });
16
16
  return {
@@ -50,17 +50,18 @@ const useStore = (name) => {
50
50
  const tools = react_1.default.useMemo(() => ({
51
51
  initialValue: store.initialValue,
52
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))) }))),
53
54
  submitFailed,
54
55
  }), [store.initialValue, setStore, submitFailed]);
55
56
  const change = react_1.default.useCallback(lodash_1.default.debounce((value) => {
56
- form.change(store.name, lodash_1.default.get((0, helpers_1.transformArrOut)(value), store.name));
57
+ form.change(store.name, lodash_1.default.get((0, utils_1.transformArrOut)(value), store.name));
57
58
  }, 100), [form.change, store.name]);
58
59
  react_1.default.useEffect(() => {
59
60
  change(store.values);
60
61
  }, [store.values]);
61
62
  react_1.default.useEffect(() => {
62
63
  if (!firstRenderRef.current) {
63
- const initialValue = (0, helpers_1.transformArrIn)({
64
+ const initialValue = (0, utils_1.transformArrIn)({
64
65
  [name]: lodash_1.default.get(form.getState().values, name),
65
66
  });
66
67
  setStore({
@@ -5,12 +5,12 @@ 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 helpers_1 = require("../../../helpers");
8
- const helpers_2 = require("../helpers");
8
+ const utils_1 = require("../utils");
9
9
  const _1 = require("./");
10
10
  const useValidate = (spec) => {
11
11
  const { config } = (0, _1.useDynamicFormsCtx)();
12
12
  const { validators } = react_1.default.useMemo(() => {
13
- if ((0, helpers_2.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
13
+ if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
14
14
  return config[spec.type];
15
15
  }
16
16
  return {};
@@ -4,5 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants"), exports);
5
5
  tslib_1.__exportStar(require("./Controller"), exports);
6
6
  tslib_1.__exportStar(require("./DynamicField"), exports);
7
- tslib_1.__exportStar(require("./helpers"), exports);
8
7
  tslib_1.__exportStar(require("./types"), exports);
8
+ tslib_1.__exportStar(require("./utils"), exports);
@@ -13,3 +13,4 @@ tslib_1.__exportStar(require("./object"), exports);
13
13
  tslib_1.__exportStar(require("./string"), exports);
14
14
  tslib_1.__exportStar(require("./validators"), exports);
15
15
  tslib_1.__exportStar(require("./value"), exports);
16
+ tslib_1.__exportStar(require("./search"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isArrayItem = exports.transformArrOut = exports.transformArrIn = exports.isCorrectConfig = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
- const constants_1 = require("../../constants");
7
- const constants_2 = require("./constants");
6
+ const constants_1 = require("../../../constants");
7
+ const constants_2 = require("../constants");
8
8
  const isCorrectConfig = (candidate) => Object.values(constants_1.SpecTypes).every((type) => lodash_1.default.isObjectLike(candidate) &&
9
9
  lodash_1.default.isObjectLike(candidate[type]) &&
10
10
  lodash_1.default.isObjectLike(candidate[type].inputs) &&
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./common"), exports);
5
+ tslib_1.__exportStar(require("./search"), exports);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultSearchFunction = exports.getParentName = void 0;
4
+ const getParentName = (name) => {
5
+ const index = name.lastIndexOf('.');
6
+ if (index !== -1) {
7
+ return name.substring(0, index);
8
+ }
9
+ return undefined;
10
+ };
11
+ exports.getParentName = getParentName;
12
+ const getDefaultSearchFunction = (search) => (spec) => {
13
+ var _a;
14
+ if (search) {
15
+ return Boolean((_a = spec.viewSpec.layoutTitle) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(search.trim().toLowerCase()));
16
+ }
17
+ return true;
18
+ };
19
+ exports.getDefaultSearchFunction = getDefaultSearchFunction;
@@ -20,7 +20,7 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
20
20
  let item;
21
21
  if (!((_a = spec.items) === null || _a === void 0 ? void 0 : _a.required)) {
22
22
  if ((0, core_1.isArraySpec)(spec.items)) {
23
- item = { OBJECT_ARRAY_FLAG: true, OBJECT_ARRAY_CNT: 0 };
23
+ item = { [core_1.OBJECT_ARRAY_FLAG]: true, [core_1.OBJECT_ARRAY_CNT]: 0 };
24
24
  }
25
25
  else if ((0, core_1.isObjectSpec)(spec.items)) {
26
26
  item = {};
@@ -39,14 +39,15 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
39
39
  return itemSpec;
40
40
  }, [spec.items, itemSpecCorrect]);
41
41
  const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
42
+ const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
42
43
  const items = react_1.default.useMemo(() => keys.map((key, idx) => {
43
44
  var _a;
44
45
  const itemSpec = getItemSpec(idx);
45
46
  if (!itemSpec) {
46
47
  return null;
47
48
  }
48
- return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
49
- }), [keys.join(''), name, getItemSpec, parentOnChange, input.value]);
49
+ return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[`<${key}>`], parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, spec: itemSpec, name: `${name}.<${key}>`, key: `${name}.<${key}>` }));
50
+ }), [keys.join(''), name, getItemSpec, parentOnChange, parentOnUnmount, input.value]);
50
51
  if (!itemSpecCorrect) {
51
52
  return null;
52
53
  }
@@ -30,7 +30,8 @@ const CardOneOf = (props) => {
30
30
  const value = lodash_1.default.set({}, childName.split(`${input.name}.`).join(''), childValue);
31
31
  input.onChange(value, childErrors);
32
32
  }, [input.onChange, input.name]);
33
+ const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
33
34
  (0, hooks_1.useErrorChecker)({ name, meta, open, setOpen });
34
- return (react_1.default.createElement(__1.Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
35
+ return (react_1.default.createElement(__1.Card, { title: toggler, description: spec.viewSpec.layoutDescription, actions: actions, open: open, onToggle: onToggle, disableHeaderToggle: true }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
35
36
  };
36
37
  exports.CardOneOf = CardOneOf;
@@ -16,6 +16,7 @@ const ObjectBase = (_a) => {
16
16
  spec.viewSpec.layoutTitle || null));
17
17
  }, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
18
18
  const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
19
+ const parentOnUnmount = react_1.default.useCallback((childName) => restProps.input.onChange((currentValue) => currentValue, { [childName]: false }), [restProps.input.onChange]);
19
20
  const content = react_1.default.useMemo(() => {
20
21
  if (!lodash_1.default.isObjectLike(spec.properties) || !Object.keys(spec.properties || {}).length) {
21
22
  return null;
@@ -26,9 +27,17 @@ const ObjectBase = (_a) => {
26
27
  const specProperties = Object.assign({}, spec.properties);
27
28
  return (react_1.default.createElement(react_1.default.Fragment, null, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => {
28
29
  var _a;
29
- return specProperties[property] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, key: `${name ? name + '.' : ''}${property}` })) : null;
30
+ return specProperties[property] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name ? name + '.' : ''}${property}` })) : null;
30
31
  })));
31
- }, [spec.properties, spec.viewSpec.order, name, restProps.input.value, addBtn, parentOnChange]);
32
+ }, [
33
+ spec.properties,
34
+ spec.viewSpec.order,
35
+ name,
36
+ restProps.input.value,
37
+ addBtn,
38
+ parentOnChange,
39
+ parentOnUnmount,
40
+ ]);
32
41
  if (!Layout || !content) {
33
42
  return content;
34
43
  }
@@ -16,9 +16,10 @@ const OneOf = (props) => {
16
16
  const value = lodash_1.default.set({}, childName.split(`${props.input.name}.`).join(''), childValue);
17
17
  props.input.onChange(value, childErrors);
18
18
  }, [props.input.onChange, props.input.name]);
19
+ const parentOnUnmount = react_1.default.useCallback((childName) => props.input.onChange((currentValue) => currentValue, { [childName]: false }), [props.input.onChange]);
19
20
  return (react_1.default.createElement("div", { className: b() },
20
21
  specProperties[oneOfValue] ? (react_1.default.createElement(__1.GroupIndent, null,
21
- react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${props.name}.${oneOfValue}` }))) : null,
22
+ react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${props.name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${props.name}.${oneOfValue}` }))) : null,
22
23
  react_1.default.createElement("div", { className: b('toggler') }, toggler)));
23
24
  };
24
25
  exports.OneOf = OneOf;
@@ -37,7 +37,8 @@ const OneOfCard = (props) => {
37
37
  const value = lodash_1.default.set({}, childName.split(`${input.name}.`).join(''), childValue);
38
38
  input.onChange(value, childErrors);
39
39
  }, [input.onChange, input.name]);
40
+ const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
40
41
  (0, hooks_1.useErrorChecker)({ name, meta, open, setOpen });
41
- return (react_1.default.createElement(__1.AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, key: `${name}.${oneOfValue}` })) : null));
42
+ return (react_1.default.createElement(__1.AccordeonCard, { className: b(), header: toggler, description: spec.viewSpec.layoutDescription || '', open: open, onToggle: onToggle, ignoreHeaderToggle: true, headerActionsTemplate: headerActionsTemplate }, specProperties[oneOfValue] ? (react_1.default.createElement(core_1.Controller, { initialValue: (_a = props.input.value) === null || _a === void 0 ? void 0 : _a[oneOfValue], spec: specProperties[oneOfValue], name: `${name}.${oneOfValue}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${oneOfValue}` })) : null));
42
43
  };
43
44
  exports.OneOfCard = OneOfCard;
@@ -9,6 +9,7 @@ const SECRET_PROPERTY_NAME = 'raw';
9
9
  const Secret = ({ spec, name, input }) => {
10
10
  var _a;
11
11
  const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
12
+ const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
12
13
  if (!lodash_1.default.isObjectLike(spec.properties)) {
13
14
  return null;
14
15
  }
@@ -16,6 +17,6 @@ const Secret = ({ spec, name, input }) => {
16
17
  if (!specProperties[SECRET_PROPERTY_NAME]) {
17
18
  return null;
18
19
  }
19
- return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, key: `${name}.${SECRET_PROPERTY_NAME}` }));
20
+ return (react_1.default.createElement(core_1.Controller, { initialValue: (_a = input.value) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME], spec: specProperties[SECRET_PROPERTY_NAME], name: `${name}.${SECRET_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount, key: `${name}.${SECRET_PROPERTY_NAME}` }));
20
21
  };
21
22
  exports.Secret = Secret;
@@ -1,6 +1,16 @@
1
1
  .df-table-array__table {
2
2
  margin-bottom: 10px;
3
3
  }
4
+ .df-table-array__table .yc-table__cell {
5
+ border-bottom: 0px transparent;
6
+ }
7
+ .df-table-array__row .yc-table__cell {
8
+ border-bottom: 0px transparent;
9
+ border-top: 1px solid var(--yc-color-line-generic);
10
+ }
11
+ .df-table-array__row_hidden {
12
+ display: none;
13
+ }
4
14
  .df-table-array__cell .yc-text-input,
5
15
  .df-table-array__cell .yc-select-control,
6
16
  .df-table-array__cell .yc-select,
@@ -7,15 +7,20 @@ const icons_1 = require("@gravity-ui/icons");
7
7
  const uikit_1 = require("@gravity-ui/uikit");
8
8
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
9
9
  const core_1 = require("../../../../core");
10
+ const hooks_1 = require("../../../../core/components/Form/hooks");
10
11
  const utils_1 = require("../../../utils");
11
12
  const b = (0, utils_1.block)('table-array');
12
13
  const TableArrayInput = ({ spec, name, arrayInput, input }) => {
14
+ const { isHiddenField } = (0, hooks_1.useSearchContext)();
13
15
  const keys = react_1.default.useMemo(() => Object.keys(arrayInput.value || {})
14
16
  .filter((k) => k !== core_1.OBJECT_ARRAY_FLAG &&
15
17
  k !== core_1.OBJECT_ARRAY_CNT &&
16
18
  arrayInput.value[k] !== core_1.REMOVED_ITEM)
17
19
  .map((k) => k.split('<').join('').split('>').join(''))
18
- .sort((a, b) => Number(a) - Number(b)), [arrayInput.value]);
20
+ .sort((a, b) => Number(a) - Number(b))
21
+ .map((key) => ({
22
+ key,
23
+ })), [arrayInput.value]);
19
24
  const onItemAdd = react_1.default.useCallback(() => {
20
25
  arrayInput.onItemAdd({});
21
26
  }, [arrayInput.onItemAdd]);
@@ -23,6 +28,7 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
23
28
  arrayInput.onItemRemove(key);
24
29
  }, [arrayInput.onItemRemove]);
25
30
  const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${input.name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
31
+ const parentOnUnmount = react_1.default.useCallback((childName) => input.onChange((currentValue) => currentValue, { [childName]: false }), [input.onChange]);
26
32
  const columns = react_1.default.useMemo(() => {
27
33
  const { items, viewSpec: { table }, } = spec;
28
34
  if (!(table === null || table === void 0 ? void 0 : table.length) || !(0, core_1.isObjectSpec)(items)) {
@@ -32,39 +38,44 @@ const TableArrayInput = ({ spec, name, arrayInput, input }) => {
32
38
  id: 'idx',
33
39
  name: '',
34
40
  sticky: 'left',
35
- template: (key, idx) => (react_1.default.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
41
+ template: ({ key }, idx) => (react_1.default.createElement("div", { className: b('idx'), key: `idx-${key}` }, idx + 1)),
36
42
  };
37
43
  const removeColumn = {
38
44
  id: 'remove',
39
45
  name: '',
40
46
  sticky: 'right',
41
- template: (key) => (react_1.default.createElement(uikit_1.Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
47
+ template: ({ key }) => (react_1.default.createElement(uikit_1.Button, { view: "flat", onClick: () => onItemRemove(key), key: `remove-${key}` },
42
48
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Xmark, size: 16 }))),
43
49
  };
44
50
  const columns = table.map(({ property, label }) => ({
45
51
  id: property,
46
52
  name: label,
47
- template: (key) => {
53
+ template: ({ key, }, idx) => {
48
54
  var _a, _b, _c;
49
55
  const entitySpec = (_a = items === null || items === void 0 ? void 0 : items.properties) === null || _a === void 0 ? void 0 : _a[property];
50
56
  if (!entitySpec) {
51
57
  return null;
52
58
  }
59
+ const preparedEntitySpec = Object.assign(Object.assign({}, entitySpec), { viewSpec: Object.assign(Object.assign({}, entitySpec.viewSpec), { layoutTitle: table.map(({ label }) => label).join(` ${idx + 1} `) + ` ${idx + 1}` }) });
53
60
  return (react_1.default.createElement("div", { className: b('cell', {
54
- bool: (0, core_1.isBooleanSpec)(entitySpec),
55
- arr: (0, core_1.isArraySpec)(entitySpec),
56
- obj: (0, core_1.isObjectSpec)(entitySpec),
61
+ bool: (0, core_1.isBooleanSpec)(preparedEntitySpec),
62
+ arr: (0, core_1.isArraySpec)(preparedEntitySpec),
63
+ obj: (0, core_1.isObjectSpec)(preparedEntitySpec),
57
64
  }), key: `${name}.<${key}>.${property}` },
58
- react_1.default.createElement(core_1.Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: entitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange })));
65
+ react_1.default.createElement(core_1.Controller, { initialValue: (_c = (_b = input.value) === null || _b === void 0 ? void 0 : _b[`<${key}>`]) === null || _c === void 0 ? void 0 : _c[property], spec: preparedEntitySpec, name: `${name}.<${key}>.${property}`, parentOnChange: parentOnChange, parentOnUnmount: parentOnUnmount })));
59
66
  },
60
67
  }));
61
68
  return [idxColumn, ...columns, removeColumn];
62
- }, [name, spec, onItemRemove, parentOnChange, input.value]);
69
+ }, [name, spec, onItemRemove, parentOnChange, parentOnUnmount, input.value]);
70
+ const getRowClassNames = react_1.default.useCallback(({ key }) => {
71
+ const searchResult = isHiddenField(`${name}.<${key}>`);
72
+ return [b('row', { hidden: searchResult })];
73
+ }, [isHiddenField, name]);
63
74
  if (!columns) {
64
75
  return null;
65
76
  }
66
77
  return (react_1.default.createElement("div", { className: b() },
67
- keys.length ? (react_1.default.createElement(uikit_1.Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top" })) : null,
78
+ keys.length ? (react_1.default.createElement(uikit_1.Table, { className: b('table'), data: keys, columns: columns, getRowId: (_, idx) => `${name}-${idx}`, verticalAlign: "top", getRowClassNames: getRowClassNames })) : null,
68
79
  !arrayInput.value && spec.defaultValue ? (react_1.default.createElement(uikit_1.Button, { onClick: () => input.onChange((0, core_1.transformArrIn)(spec.defaultValue)), disabled: spec.viewSpec.disabled },
69
80
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Plus, size: 14 }),
70
81
  spec.viewSpec.layoutTitle || null)) : (react_1.default.createElement(uikit_1.Button, { onClick: onItemAdd, disabled: spec.viewSpec.disabled },
@@ -5,5 +5,6 @@ export interface ControllerProps<Value extends FieldValue, SpecType extends Spec
5
5
  name: string;
6
6
  initialValue: Value;
7
7
  parentOnChange: ((childName: string, childValue: FieldValue, childErrors: Record<string, ValidateError>) => void) | null;
8
+ parentOnUnmount: ((childName: string) => void) | null;
8
9
  }
9
- export declare const Controller: <Value extends FieldValue, SpecType extends Spec>({ spec, name, initialValue, parentOnChange, }: ControllerProps<Value, SpecType>) => JSX.Element | null;
10
+ export declare const Controller: <Value extends FieldValue, SpecType extends Spec>({ spec, name, initialValue, parentOnChange, parentOnUnmount, }: ControllerProps<Value, SpecType>) => JSX.Element | null;