@gravity-ui/dynamic-forms 1.4.1 → 1.6.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 (118) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/cjs/lib/core/components/Form/hooks/useField.js +3 -0
  3. package/build/cjs/lib/core/components/Form/hooks/useStore.js +6 -0
  4. package/build/cjs/lib/core/helpers.js +4 -1
  5. package/build/cjs/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
  6. package/build/cjs/lib/kit/components/Card/Card.js +2 -2
  7. package/build/cjs/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
  8. package/build/cjs/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
  9. package/build/cjs/lib/kit/components/Inputs/Checkbox/Checkbox.js +2 -2
  10. package/build/cjs/lib/kit/components/Inputs/FileInput/FileInput.js +3 -3
  11. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.js +5 -5
  12. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.js +2 -2
  13. package/build/cjs/lib/kit/components/Inputs/MultiSelect/MultiSelect.js +2 -2
  14. package/build/cjs/lib/kit/components/Inputs/NumberWithScale/NumberWithScale.js +3 -3
  15. package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +2 -2
  16. package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +32 -0
  17. package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/index.js +4 -0
  18. package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.css +8 -8
  19. package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
  20. package/build/cjs/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +3 -3
  21. package/build/cjs/lib/kit/components/Inputs/Secret/Secret.js +16 -6
  22. package/build/cjs/lib/kit/components/Inputs/Select/Select.js +2 -2
  23. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -3
  24. package/build/cjs/lib/kit/components/Inputs/Text/Text.js +2 -2
  25. package/build/cjs/lib/kit/components/Inputs/TextArea/TextArea.js +2 -2
  26. package/build/cjs/lib/kit/components/Inputs/TextLink/TextLink.js +18 -5
  27. package/build/cjs/lib/kit/components/Inputs/index.js +1 -0
  28. package/build/cjs/lib/kit/components/Layouts/Accordeon/Accordeon.js +3 -3
  29. package/build/cjs/lib/kit/components/Layouts/Accordeon/RemoveButton.js +2 -2
  30. package/build/cjs/lib/kit/components/Layouts/AccordeonCardLayout/AccordeonCardLayout.js +3 -3
  31. package/build/cjs/lib/kit/components/Layouts/CardAccordeon.js +3 -3
  32. package/build/cjs/lib/kit/components/Layouts/CardSection.js +3 -3
  33. package/build/cjs/lib/kit/components/Layouts/Row/Row.js +1 -1
  34. package/build/cjs/lib/kit/components/Layouts/Row2/Row2.js +1 -1
  35. package/build/cjs/lib/kit/components/Layouts/SectionCard/SectionCard.js +1 -1
  36. package/build/cjs/lib/kit/components/Layouts/Transparent/Transparent.js +2 -2
  37. package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +1 -1
  38. package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.js +2 -2
  39. package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
  40. package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
  41. package/build/cjs/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
  42. package/build/cjs/lib/kit/components/ViewLayouts/ViewCardSection.js +2 -2
  43. package/build/cjs/lib/kit/components/Views/CardOneOfView.js +1 -1
  44. package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +29 -0
  45. package/build/cjs/lib/kit/components/Views/ObjectValueInputView/index.js +4 -0
  46. package/build/cjs/lib/kit/components/Views/OneOfCardView.js +1 -1
  47. package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +21 -7
  48. package/build/cjs/lib/kit/components/Views/index.js +1 -0
  49. package/build/cjs/lib/kit/constants/config.js +4 -0
  50. package/build/cjs/lib/kit/hooks/useOneOf.js +4 -4
  51. package/build/esm/lib/core/components/Form/hooks/useField.js +4 -1
  52. package/build/esm/lib/core/components/Form/hooks/useStore.js +6 -0
  53. package/build/esm/lib/core/helpers.d.ts +1 -0
  54. package/build/esm/lib/core/helpers.js +2 -0
  55. package/build/esm/lib/core/types/specs.d.ts +0 -1
  56. package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.d.ts +1 -0
  57. package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
  58. package/build/esm/lib/kit/components/Card/Card.d.ts +1 -0
  59. package/build/esm/lib/kit/components/Card/Card.js +2 -2
  60. package/build/esm/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
  61. package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
  62. package/build/esm/lib/kit/components/Inputs/Checkbox/Checkbox.js +2 -2
  63. package/build/esm/lib/kit/components/Inputs/FileInput/FileInput.js +3 -3
  64. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.js +5 -5
  65. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.d.ts +1 -0
  66. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.js +2 -2
  67. package/build/esm/lib/kit/components/Inputs/MultiSelect/MultiSelect.js +2 -2
  68. package/build/esm/lib/kit/components/Inputs/NumberWithScale/NumberWithScale.js +3 -3
  69. package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +2 -2
  70. package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.d.ts +2 -0
  71. package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +27 -0
  72. package/build/esm/lib/kit/components/Inputs/ObjectValueInput/index.d.ts +1 -0
  73. package/build/esm/lib/kit/components/Inputs/ObjectValueInput/index.js +1 -0
  74. package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.css +8 -8
  75. package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
  76. package/build/esm/lib/kit/components/Inputs/OneOfCard/OneOfCard.js +3 -3
  77. package/build/esm/lib/kit/components/Inputs/Secret/Secret.js +17 -7
  78. package/build/esm/lib/kit/components/Inputs/Select/Select.js +2 -2
  79. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +3 -3
  80. package/build/esm/lib/kit/components/Inputs/Text/Text.d.ts +1 -1
  81. package/build/esm/lib/kit/components/Inputs/Text/Text.js +2 -2
  82. package/build/esm/lib/kit/components/Inputs/TextArea/TextArea.js +2 -2
  83. package/build/esm/lib/kit/components/Inputs/TextLink/TextLink.js +18 -5
  84. package/build/esm/lib/kit/components/Inputs/index.d.ts +1 -0
  85. package/build/esm/lib/kit/components/Inputs/index.js +1 -0
  86. package/build/esm/lib/kit/components/Layouts/Accordeon/Accordeon.js +3 -3
  87. package/build/esm/lib/kit/components/Layouts/Accordeon/RemoveButton.d.ts +1 -0
  88. package/build/esm/lib/kit/components/Layouts/Accordeon/RemoveButton.js +2 -2
  89. package/build/esm/lib/kit/components/Layouts/AccordeonCardLayout/AccordeonCardLayout.js +3 -3
  90. package/build/esm/lib/kit/components/Layouts/CardAccordeon.js +3 -3
  91. package/build/esm/lib/kit/components/Layouts/CardSection.js +3 -3
  92. package/build/esm/lib/kit/components/Layouts/Row/Row.js +1 -1
  93. package/build/esm/lib/kit/components/Layouts/Row2/Row2.js +1 -1
  94. package/build/esm/lib/kit/components/Layouts/SectionCard/SectionCard.js +1 -1
  95. package/build/esm/lib/kit/components/Layouts/Transparent/Transparent.js +2 -2
  96. package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +1 -1
  97. package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.d.ts +1 -0
  98. package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.js +2 -2
  99. package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.d.ts +1 -1
  100. package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
  101. package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.d.ts +1 -1
  102. package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
  103. package/build/esm/lib/kit/components/ViewLayouts/ViewCardAccordeon.d.ts +1 -1
  104. package/build/esm/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
  105. package/build/esm/lib/kit/components/ViewLayouts/ViewCardSection.d.ts +1 -1
  106. package/build/esm/lib/kit/components/ViewLayouts/ViewCardSection.js +2 -2
  107. package/build/esm/lib/kit/components/Views/CardOneOfView.js +1 -1
  108. package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.d.ts +2 -0
  109. package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +25 -0
  110. package/build/esm/lib/kit/components/Views/ObjectValueInputView/index.d.ts +1 -0
  111. package/build/esm/lib/kit/components/Views/ObjectValueInputView/index.js +1 -0
  112. package/build/esm/lib/kit/components/Views/OneOfCardView.js +1 -1
  113. package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +23 -8
  114. package/build/esm/lib/kit/components/Views/index.d.ts +1 -0
  115. package/build/esm/lib/kit/components/Views/index.js +1 -0
  116. package/build/esm/lib/kit/constants/config.js +5 -1
  117. package/build/esm/lib/kit/hooks/useOneOf.js +4 -4
  118. package/package.json +4 -4
@@ -24,5 +24,5 @@ export const OneOfCardView = (props) => {
24
24
  if (!value || !Object.keys(value).length) {
25
25
  return null;
26
26
  }
27
- return (React.createElement(AccordeonCard, { className: "df-accordeon-card-layout", header: wrappedValue, open: open, onToggle: onToggle, ignoreHeaderToggle: true }, specProperties[valueKey] ? (React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` })) : null));
27
+ return (React.createElement(AccordeonCard, { className: "df-accordeon-card-layout", name: name, header: wrappedValue, open: open, onToggle: onToggle, ignoreHeaderToggle: true }, specProperties[valueKey] ? (React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` })) : null));
28
28
  };
@@ -1,12 +1,27 @@
1
+ import { __rest } from "tslib";
1
2
  import React from 'react';
2
- import { ViewController } from '../../../../core';
3
+ import _ from 'lodash';
4
+ import { ViewController, isStringSpec } from '../../../../core';
3
5
  const TEXT_LINK_PROPERTY_NAME = 'text';
4
- export const TextLinkView = ({ value, spec, name }) => {
5
- const specProperties = spec.properties;
6
- const preparedSpec = React.useMemo(() => {
6
+ export const TextLinkView = (_a) => {
7
+ var { value, spec, name, Layout } = _a, restProps = __rest(_a, ["value", "spec", "name", "Layout"]);
8
+ const childSpec = React.useMemo(() => {
7
9
  var _a;
8
- return specProperties && specProperties[TEXT_LINK_PROPERTY_NAME]
9
- ? 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;
10
- }, [specProperties, value === null || value === void 0 ? void 0 : value.link]);
11
- return preparedSpec ? (React.createElement(ViewController, { spec: preparedSpec, name: `${name}.${TEXT_LINK_PROPERTY_NAME}` })) : null;
10
+ if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME]) &&
11
+ isStringSpec(spec.properties[TEXT_LINK_PROPERTY_NAME])) {
12
+ const childSpec = _.cloneDeep(spec.properties[TEXT_LINK_PROPERTY_NAME]);
13
+ childSpec.viewSpec.layout = '';
14
+ childSpec.viewSpec.link = value === null || value === void 0 ? void 0 : value.link;
15
+ return childSpec;
16
+ }
17
+ return undefined;
18
+ }, [spec.properties, value === null || value === void 0 ? void 0 : value.link]);
19
+ if (!childSpec || !(value === null || value === void 0 ? void 0 : value.text)) {
20
+ return null;
21
+ }
22
+ const content = React.createElement(ViewController, { spec: childSpec, name: `${name}.${TEXT_LINK_PROPERTY_NAME}` });
23
+ if (Layout) {
24
+ return (React.createElement(Layout, Object.assign({ spec: spec, name: name, value: value }, restProps), content));
25
+ }
26
+ return React.createElement(React.Fragment, null, content);
12
27
  };
@@ -6,6 +6,7 @@ export * from './MonacoInputView';
6
6
  export * from './MultiSelectView';
7
7
  export * from './NumberWithScaleView';
8
8
  export * from './ObjectBaseView';
9
+ export * from './ObjectValueInputView';
9
10
  export * from './OneOfCardView';
10
11
  export * from './OneOfView';
11
12
  export * from './TableArrayView';
@@ -6,6 +6,7 @@ export * from './MonacoInputView';
6
6
  export * from './MultiSelectView';
7
7
  export * from './NumberWithScaleView';
8
8
  export * from './ObjectBaseView';
9
+ export * from './ObjectValueInputView';
9
10
  export * from './OneOfCardView';
10
11
  export * from './OneOfView';
11
12
  export * from './TableArrayView';
@@ -1,4 +1,4 @@
1
- import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, OneOf, OneOfCard, OneOfCardView, OneOfView, Row, Row2, RowVerbose, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
1
+ import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfCard, OneOfCardView, OneOfView, Row, Row2, RowVerbose, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
2
2
  import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
3
3
  export const dynamicConfig = {
4
4
  array: {
@@ -58,6 +58,7 @@ export const dynamicConfig = {
58
58
  secret: { Component: Secret, independent: true },
59
59
  base: { Component: ObjectBase, independent: true },
60
60
  text_link: { Component: TextLink, independent: true },
61
+ object_value: { Component: ObjectValueInput, independent: true },
61
62
  },
62
63
  layouts: {
63
64
  row: Row,
@@ -155,6 +156,7 @@ export const dynamicCardConfig = {
155
156
  secret: { Component: Secret, independent: true },
156
157
  base: { Component: ObjectBase, independent: true },
157
158
  text_link: { Component: TextLink, independent: true },
159
+ object_value: { Component: ObjectValueInput, independent: true },
158
160
  },
159
161
  layouts: {
160
162
  row: Row2,
@@ -241,6 +243,7 @@ export const dynamicViewConfig = {
241
243
  secret: undefined,
242
244
  base: { Component: ObjectBaseView, independent: true },
243
245
  text_link: { Component: TextLinkView, independent: true },
246
+ object_value: { Component: ObjectValueInputView, independent: true },
244
247
  },
245
248
  layouts: {
246
249
  row: ViewRow,
@@ -320,6 +323,7 @@ export const dynamicViewCardConfig = {
320
323
  secret: undefined,
321
324
  base: { Component: ObjectBaseView, independent: true },
322
325
  text_link: { Component: TextLinkView, independent: true },
326
+ object_value: { Component: ObjectValueInputView, independent: true },
323
327
  },
324
328
  layouts: {
325
329
  row: ViewRow2,
@@ -3,7 +3,7 @@ import { RadioButton, Select } from '@gravity-ui/uikit';
3
3
  import _ from 'lodash';
4
4
  const MAX_TAB_TITLE_LENGTH = 20;
5
5
  export const useOneOf = ({ props, onTogglerChange }) => {
6
- const { input, spec, Layout } = props;
6
+ const { name, input, spec, Layout } = props;
7
7
  const specProperties = React.useMemo(() => (_.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
8
8
  const [oneOfValue, setOneOfValue] = React.useState(() => {
9
9
  let valueKeys;
@@ -37,10 +37,10 @@ export const useOneOf = ({ props, onTogglerChange }) => {
37
37
  const togglerInput = React.useMemo(() => {
38
38
  if (options.length > 3 ||
39
39
  _.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH)) {
40
- return (React.createElement(Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7 }));
40
+ return (React.createElement(Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7, qa: name }));
41
41
  }
42
- return (React.createElement(RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled }, options.map((option) => (React.createElement(RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
43
- }, [options, oneOfValue, onOneOfChange]);
42
+ return (React.createElement(RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled, qa: name }, options.map((option) => (React.createElement(RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
43
+ }, [options, oneOfValue, onOneOfChange, name]);
44
44
  const toggler = React.useMemo(() => {
45
45
  if (Layout) {
46
46
  return React.createElement(Layout, Object.assign({}, props), togglerInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@gravity-ui/i18n": "^1.0.0",
41
- "@gravity-ui/icons": "^1.1.0",
41
+ "@gravity-ui/icons": "^2.1.0",
42
42
  "bem-cn-lite": "^4.0.0",
43
43
  "lodash": "^4.17.20"
44
44
  },
@@ -51,7 +51,7 @@
51
51
  "@gravity-ui/prettier-config": "^1.0.1",
52
52
  "@gravity-ui/stylelint-config": "^2.0.0",
53
53
  "@gravity-ui/tsconfig": "^1.0.0",
54
- "@gravity-ui/uikit": "^4.1.0",
54
+ "@gravity-ui/uikit": "^4.10.0",
55
55
  "@storybook/addon-essentials": "^6.5.16",
56
56
  "@storybook/preset-scss": "^1.0.3",
57
57
  "@storybook/react": "^6.5.16",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.9.5"
95
95
  },
96
96
  "peerDependencies": {
97
- "@gravity-ui/uikit": "^3.0.0 || ^4.0.0",
97
+ "@gravity-ui/uikit": "^4.0.0",
98
98
  "final-form": "^4.20.2",
99
99
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0",
100
100
  "react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0",