@gravity-ui/dynamic-forms 5.30.0 → 5.33.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 (124) hide show
  1. package/build/cjs/lib/unstable/core/constants.d.ts +1 -0
  2. package/build/cjs/lib/unstable/core/constants.js +1 -0
  3. package/build/cjs/lib/unstable/core/useSchemaRenderer/types/state.d.ts +1 -0
  4. package/build/cjs/lib/unstable/core/useSchemaRenderer/useSchemaRenderer.js +17 -0
  5. package/build/cjs/lib/unstable/kit/components/ArrayRemoveButton/ArrayRemoveButton.d.ts +2 -0
  6. package/build/cjs/lib/unstable/kit/components/ArrayRemoveButton/ArrayRemoveButton.js +6 -7
  7. package/build/cjs/lib/unstable/kit/components/CopyButton/CopyButton.css +1 -0
  8. package/build/cjs/lib/unstable/kit/components/CopyButton/CopyButton.d.ts +3 -1
  9. package/build/cjs/lib/unstable/kit/components/CopyButton/CopyButton.js +6 -2
  10. package/build/cjs/lib/unstable/kit/components/DropButton/DropButton.css +3 -0
  11. package/build/cjs/lib/unstable/kit/components/DropButton/DropButton.d.ts +10 -0
  12. package/build/cjs/lib/unstable/kit/components/DropButton/DropButton.js +32 -0
  13. package/build/cjs/lib/unstable/kit/components/DropButton/index.d.ts +1 -0
  14. package/build/cjs/lib/unstable/kit/components/DropButton/index.js +5 -0
  15. package/build/cjs/lib/unstable/kit/components/EntityContainer/EntityContainer.css +1 -0
  16. package/build/cjs/lib/unstable/kit/components/EntityContainer/EntityContainer.d.ts +1 -0
  17. package/build/cjs/lib/unstable/kit/components/EntityContainer/EntityContainer.js +2 -2
  18. package/build/cjs/lib/unstable/kit/components/LayoutButtons/LayoutButtons.d.ts +10 -0
  19. package/build/cjs/lib/unstable/kit/components/LayoutButtons/LayoutButtons.js +15 -0
  20. package/build/cjs/lib/unstable/kit/components/LayoutButtons/index.d.ts +1 -0
  21. package/build/cjs/lib/unstable/kit/components/LayoutButtons/index.js +5 -0
  22. package/build/cjs/lib/unstable/kit/components/LayoutContainer/LayoutContainer.css +30 -1
  23. package/build/cjs/lib/unstable/kit/components/index.d.ts +2 -0
  24. package/build/cjs/lib/unstable/kit/components/index.js +5 -1
  25. package/build/cjs/lib/unstable/kit/constants/config.d.ts +4 -2
  26. package/build/cjs/lib/unstable/kit/constants/config.js +4 -4
  27. package/build/cjs/lib/unstable/kit/entities/ArrayEntity/ArrayEntity.css +1 -1
  28. package/build/cjs/lib/unstable/kit/entities/ArrayEntity/ArrayEntity.js +33 -4
  29. package/build/cjs/lib/unstable/kit/entities/ArrayTable/ArrayTable.css +13 -3
  30. package/build/cjs/lib/unstable/kit/entities/ArrayTable/ArrayTable.js +47 -15
  31. package/build/cjs/lib/unstable/kit/entities/ObjectEntity/ObjectEntity.css +3 -0
  32. package/build/cjs/lib/unstable/kit/entities/ObjectEntity/ObjectEntity.js +40 -5
  33. package/build/cjs/lib/unstable/kit/entities/ObjectInline/ObjectInline.js +1 -1
  34. package/build/cjs/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +1 -1
  35. package/build/cjs/lib/unstable/kit/form-entities/NumberWithScaleInput/NumberWithScaleInput.js +1 -1
  36. package/build/cjs/lib/unstable/kit/form-entities/RadioGroupInput/RadioGroupInput.css +3 -5
  37. package/build/cjs/lib/unstable/kit/form-entities/RadioGroupInput/RadioGroupInput.js +1 -1
  38. package/build/cjs/lib/unstable/kit/form-entities/RangeInput/RangeInput.js +2 -2
  39. package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +1 -0
  40. package/build/cjs/lib/unstable/kit/form-entities/StringNumberWithScaleInput/StringNumberWithScaleInput.js +1 -1
  41. package/build/cjs/lib/unstable/kit/form-entities/TextAreaInput/TextAreaInput.js +1 -1
  42. package/build/cjs/lib/unstable/kit/form-layouts/FormColumn/FormColumn.css +3 -3
  43. package/build/cjs/lib/unstable/kit/form-layouts/FormColumn/FormColumn.js +6 -5
  44. package/build/cjs/lib/unstable/kit/form-layouts/FormRow/FormRow.js +2 -2
  45. package/build/cjs/lib/unstable/kit/hooks/index.d.ts +1 -0
  46. package/build/cjs/lib/unstable/kit/hooks/index.js +5 -0
  47. package/build/cjs/lib/unstable/kit/hooks/useExpanded.d.ts +11 -0
  48. package/build/cjs/lib/unstable/kit/hooks/useExpanded.js +25 -0
  49. package/build/cjs/lib/unstable/kit/index.d.ts +1 -0
  50. package/build/cjs/lib/unstable/kit/index.js +1 -0
  51. package/build/cjs/lib/unstable/kit/layouts/Accordeon/Accordeon.css +2 -6
  52. package/build/cjs/lib/unstable/kit/layouts/Accordeon/Accordeon.js +6 -17
  53. package/build/cjs/lib/unstable/kit/layouts/Card/Card.css +0 -6
  54. package/build/cjs/lib/unstable/kit/layouts/Card/Card.js +12 -11
  55. package/build/cjs/lib/unstable/kit/layouts/Section/Section.css +0 -6
  56. package/build/cjs/lib/unstable/kit/layouts/Section/Section.js +2 -3
  57. package/build/cjs/lib/unstable/kit/layouts/Transparent/Transparent.css +0 -6
  58. package/build/cjs/lib/unstable/kit/layouts/Transparent/Transparent.js +2 -3
  59. package/build/cjs/lib/unstable/kit/overview-layouts/OverviewColumn/OverviewColumn.js +3 -3
  60. package/build/cjs/lib/unstable/kit/overview-layouts/OverviewRow/OverviewRow.js +3 -3
  61. package/build/cjs/lib/unstable/kit/utils/transformer.js +18 -3
  62. package/build/esm/lib/unstable/core/constants.d.ts +1 -0
  63. package/build/esm/lib/unstable/core/constants.js +1 -0
  64. package/build/esm/lib/unstable/core/useSchemaRenderer/types/state.d.ts +1 -0
  65. package/build/esm/lib/unstable/core/useSchemaRenderer/useSchemaRenderer.js +17 -0
  66. package/build/esm/lib/unstable/kit/components/ArrayRemoveButton/ArrayRemoveButton.d.ts +2 -0
  67. package/build/esm/lib/unstable/kit/components/ArrayRemoveButton/ArrayRemoveButton.js +7 -8
  68. package/build/esm/lib/unstable/kit/components/CopyButton/CopyButton.css +1 -0
  69. package/build/esm/lib/unstable/kit/components/CopyButton/CopyButton.d.ts +3 -1
  70. package/build/esm/lib/unstable/kit/components/CopyButton/CopyButton.js +6 -2
  71. package/build/esm/lib/unstable/kit/components/DropButton/DropButton.css +3 -0
  72. package/build/esm/lib/unstable/kit/components/DropButton/DropButton.d.ts +11 -0
  73. package/build/esm/lib/unstable/kit/components/DropButton/DropButton.js +28 -0
  74. package/build/esm/lib/unstable/kit/components/DropButton/index.d.ts +1 -0
  75. package/build/esm/lib/unstable/kit/components/DropButton/index.js +1 -0
  76. package/build/esm/lib/unstable/kit/components/EntityContainer/EntityContainer.css +1 -0
  77. package/build/esm/lib/unstable/kit/components/EntityContainer/EntityContainer.d.ts +1 -0
  78. package/build/esm/lib/unstable/kit/components/EntityContainer/EntityContainer.js +2 -2
  79. package/build/esm/lib/unstable/kit/components/LayoutButtons/LayoutButtons.d.ts +10 -0
  80. package/build/esm/lib/unstable/kit/components/LayoutButtons/LayoutButtons.js +10 -0
  81. package/build/esm/lib/unstable/kit/components/LayoutButtons/index.d.ts +1 -0
  82. package/build/esm/lib/unstable/kit/components/LayoutButtons/index.js +1 -0
  83. package/build/esm/lib/unstable/kit/components/LayoutContainer/LayoutContainer.css +30 -1
  84. package/build/esm/lib/unstable/kit/components/index.d.ts +2 -0
  85. package/build/esm/lib/unstable/kit/components/index.js +2 -0
  86. package/build/esm/lib/unstable/kit/constants/config.d.ts +4 -2
  87. package/build/esm/lib/unstable/kit/constants/config.js +4 -4
  88. package/build/esm/lib/unstable/kit/entities/ArrayEntity/ArrayEntity.css +1 -1
  89. package/build/esm/lib/unstable/kit/entities/ArrayEntity/ArrayEntity.js +33 -4
  90. package/build/esm/lib/unstable/kit/entities/ArrayTable/ArrayTable.css +13 -3
  91. package/build/esm/lib/unstable/kit/entities/ArrayTable/ArrayTable.js +48 -16
  92. package/build/esm/lib/unstable/kit/entities/ObjectEntity/ObjectEntity.css +3 -0
  93. package/build/esm/lib/unstable/kit/entities/ObjectEntity/ObjectEntity.d.ts +1 -0
  94. package/build/esm/lib/unstable/kit/entities/ObjectEntity/ObjectEntity.js +42 -6
  95. package/build/esm/lib/unstable/kit/entities/ObjectInline/ObjectInline.js +1 -1
  96. package/build/esm/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +1 -1
  97. package/build/esm/lib/unstable/kit/form-entities/NumberWithScaleInput/NumberWithScaleInput.js +1 -1
  98. package/build/esm/lib/unstable/kit/form-entities/RadioGroupInput/RadioGroupInput.css +3 -5
  99. package/build/esm/lib/unstable/kit/form-entities/RadioGroupInput/RadioGroupInput.js +1 -1
  100. package/build/esm/lib/unstable/kit/form-entities/RangeInput/RangeInput.js +2 -2
  101. package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +1 -0
  102. package/build/esm/lib/unstable/kit/form-entities/StringNumberWithScaleInput/StringNumberWithScaleInput.js +1 -1
  103. package/build/esm/lib/unstable/kit/form-entities/TextAreaInput/TextAreaInput.js +1 -1
  104. package/build/esm/lib/unstable/kit/form-layouts/FormColumn/FormColumn.css +3 -3
  105. package/build/esm/lib/unstable/kit/form-layouts/FormColumn/FormColumn.js +7 -6
  106. package/build/esm/lib/unstable/kit/form-layouts/FormRow/FormRow.js +3 -3
  107. package/build/esm/lib/unstable/kit/hooks/index.d.ts +1 -0
  108. package/build/esm/lib/unstable/kit/hooks/index.js +1 -0
  109. package/build/esm/lib/unstable/kit/hooks/useExpanded.d.ts +11 -0
  110. package/build/esm/lib/unstable/kit/hooks/useExpanded.js +20 -0
  111. package/build/esm/lib/unstable/kit/index.d.ts +1 -0
  112. package/build/esm/lib/unstable/kit/index.js +1 -0
  113. package/build/esm/lib/unstable/kit/layouts/Accordeon/Accordeon.css +2 -6
  114. package/build/esm/lib/unstable/kit/layouts/Accordeon/Accordeon.js +7 -18
  115. package/build/esm/lib/unstable/kit/layouts/Card/Card.css +0 -6
  116. package/build/esm/lib/unstable/kit/layouts/Card/Card.js +13 -12
  117. package/build/esm/lib/unstable/kit/layouts/Section/Section.css +0 -6
  118. package/build/esm/lib/unstable/kit/layouts/Section/Section.js +3 -4
  119. package/build/esm/lib/unstable/kit/layouts/Transparent/Transparent.css +0 -6
  120. package/build/esm/lib/unstable/kit/layouts/Transparent/Transparent.js +3 -4
  121. package/build/esm/lib/unstable/kit/overview-layouts/OverviewColumn/OverviewColumn.js +4 -4
  122. package/build/esm/lib/unstable/kit/overview-layouts/OverviewRow/OverviewRow.js +4 -4
  123. package/build/esm/lib/unstable/kit/utils/transformer.js +18 -3
  124. package/package.json +1 -1
@@ -1,11 +1,47 @@
1
1
  import React from 'react';
2
+ import { Plus } from '@gravity-ui/icons';
3
+ import { Button, Icon } from '@gravity-ui/uikit';
2
4
  import { SchemaRendererMode, SchemaRendererNode, } from '../../../core';
3
- import { EmptyEntityValue, EntityContainer } from '../../components';
4
- export const ObjectEntity = ({ headName, mode, input, props, schema, schemaPath, }) => {
5
- const { name } = input;
5
+ import { EntityContainer } from '../../components';
6
+ import { block } from '../../utils';
7
+ import './ObjectEntity.css';
8
+ const b = block('object-entity');
9
+ export const ObjectEntity = ({ Layout, headName, input, layoutProps, meta, mode, props, schema, schemaPath, }) => {
10
+ var _a;
11
+ const { onFocus, onChange, onBlur, value } = input;
12
+ const { disabled, required } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
6
13
  const overviewFlag = mode === SchemaRendererMode.Overview;
7
- if (overviewFlag && !Object.keys(schema.properties || {}).length) {
8
- return React.createElement(EmptyEntityValue, null);
14
+ const { name } = input;
15
+ const initButton = React.useMemo(() => {
16
+ if (required || value !== undefined || overviewFlag) {
17
+ return null;
18
+ }
19
+ const onClick = () => {
20
+ onFocus();
21
+ onChange({});
22
+ onBlur();
23
+ };
24
+ return (React.createElement(Button, { className: b('init-button'), onClick: onClick, disabled: disabled || schema.readOnly, qa: `${name}-init-button` },
25
+ React.createElement(Icon, { data: Plus, size: 14 }),
26
+ schema.title || null));
27
+ }, [
28
+ disabled,
29
+ name,
30
+ onBlur,
31
+ onChange,
32
+ onFocus,
33
+ overviewFlag,
34
+ required,
35
+ schema.title,
36
+ schema.readOnly,
37
+ value,
38
+ ]);
39
+ if (!Object.keys(schema.properties || {}).length) {
40
+ return null;
41
+ }
42
+ let content = (React.createElement(EntityContainer, { stretch: "by-child", fill: "by-child", droppable: true }, initButton ? (initButton) : (React.createElement(React.Fragment, null, (props.order || Object.keys(schema.properties || {})).map((property) => (React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${property}`, schemaPath: `${schemaPath}/properties/${property}`, key: property })))))));
43
+ if (Layout) {
44
+ content = (React.createElement(Layout, { headName: headName, input: input, meta: meta, mode: mode, schema: schema, schemaPath: schemaPath, props: layoutProps || {} }, content));
9
45
  }
10
- return (React.createElement(EntityContainer, { stretch: "by-child", fill: "by-child" }, (props.order || Object.keys(schema.properties || {})).map((property) => (React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${property}`, schemaPath: `${schemaPath}/properties/${property}`, key: property })))));
46
+ return content;
11
47
  };
@@ -16,7 +16,7 @@ export const ObjectInline = ({ headName, input, mode, props, schema, schemaPath,
16
16
  }
17
17
  return (React.createElement(EntityContainer, { stretch: overviewFlag ? 'by-child' : 'max', className: b(), fill: "by-child" },
18
18
  React.createElement(Flex, { className: b('items', { overview: overviewFlag }), direction: "row", alignItems: "flex-start", gap: overviewFlag ? 1 : 2 }, (order || Object.keys(schema.properties || {})).map((property, index, array) => (React.createElement(React.Fragment, { key: property },
19
- React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${property}`, schemaPath: `${schemaPath}/properties/${property}` }),
19
+ React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${property}`, schemaPath: `${schemaPath}/properties/${property}`, key: property }),
20
20
  isString(delimiter) && index + 1 !== array.length ? (React.createElement(Text, { className: b('delimiter') }, delimiter)) : null,
21
21
  isObject(delimiter) && delimiter[property] ? (React.createElement(Text, { className: b('delimiter') }, delimiter[property])) : null))))));
22
22
  };
@@ -69,7 +69,7 @@ export const OneOfNested = ({ Layout, headName, input, layoutProps, meta, mode,
69
69
  }, [name, input, togglerArrayRemoveButton]);
70
70
  let content = (React.createElement(EntityContainer, { direction: "column-reverse", stretch: "by-child", fill: "populated" },
71
71
  togglerValue === undefined ? null : (React.createElement(LayoutContainer, { className: b('content', { 'with-indent': withIndent }), hideEmpty: overviewFlag },
72
- React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${togglerValue}`, schemaPath: `${schemaPath}/properties/${togglerValue}` }))),
72
+ React.createElement(SchemaRendererNode, { headName: headName, name: `${name ? name + '.' : ''}${togglerValue}`, schemaPath: `${schemaPath}/properties/${togglerValue}`, key: togglerValue }))),
73
73
  toggler));
74
74
  if (overviewFlag && Object.values(value || {}).length === 0) {
75
75
  content = React.createElement(React.Fragment, null, toggler);
@@ -28,7 +28,7 @@ export const NumberWithScaleInput = ({ input, meta, props, schema, }) => {
28
28
  scale: preparedScale,
29
29
  defaultType,
30
30
  viewType: viewType && preparedScale[viewType] ? [viewType] : [defaultType],
31
- minScaleLength: `${minScaleLength + 42}px`,
31
+ minScaleLength: `${minScaleLength + 60}px`,
32
32
  };
33
33
  }
34
34
  }
@@ -1,9 +1,7 @@
1
- .sr-radio-group-input_direction_horizontal {
1
+ .sr-radio-group-input .g-radio-group .g-control-label.g-radio-group__option {
2
2
  min-height: 28px;
3
- padding-top: 1px;
4
- }
5
- .sr-radio-group-input_direction_vertical {
6
- padding-top: 7px;
3
+ align-items: center;
4
+ margin-bottom: 0;
7
5
  }
8
6
  .sr-radio-group-input_error .g-radio-group .g-radio_checked .g-radio__indicator:hover::before {
9
7
  border: 1px solid var(--g-color-text-danger);
@@ -18,6 +18,6 @@ export const RadioGroupInput = ({ input, meta, props, schema, }) => {
18
18
  disabled: optionsDisabled === null || optionsDisabled === void 0 ? void 0 : optionsDisabled[value],
19
19
  }));
20
20
  }, [enumDescriptions, optionsDisabled, schema.enum]);
21
- return (React.createElement(EntityContainer, { stretch: "fit", className: b({ error: getBooleanValidationState(meta), direction }), justifyContent: "center" },
21
+ return (React.createElement(EntityContainer, { stretch: "fit", className: b({ error: getBooleanValidationState(meta) }), justifyContent: "center" },
22
22
  React.createElement(RadioGroup, Object.assign({ options: options, disabled: disabled || schema.readOnly }, restEntityProps, { value: value, onFocus: onFocus, onBlur: onBlur, onUpdate: onChange, direction: direction, qa: name }))));
23
23
  };
@@ -61,7 +61,7 @@ export const RangeInput = ({ headName, input, props, schemaPath, }) => {
61
61
  }, [inputValue === null || inputValue === void 0 ? void 0 : inputValue[fromKey], inputValue === null || inputValue === void 0 ? void 0 : inputValue[toKey]]);
62
62
  return (React.createElement(EntityContainer, { stretch: "max", className: b() },
63
63
  React.createElement(Flex, { className: b('items'), direction: "row", alignItems: "flex-start", gap: 2 },
64
- React.createElement(SchemaRendererNode, { headName: headName, name: fromName, schemaPath: `${schemaPath}/properties/${fromKey}` }),
64
+ React.createElement(SchemaRendererNode, { headName: headName, name: fromName, schemaPath: `${schemaPath}/properties/${fromKey}`, key: fromKey }),
65
65
  React.createElement(Text, { className: b('delimiter') }, separator),
66
- React.createElement(SchemaRendererNode, { headName: headName, name: toName, schemaPath: `${schemaPath}/properties/${toKey}` }))));
66
+ React.createElement(SchemaRendererNode, { headName: headName, name: toName, schemaPath: `${schemaPath}/properties/${toKey}`, key: toKey }))));
67
67
  };
@@ -1,5 +1,6 @@
1
1
  .sr-segmented-radio-group-input {
2
2
  position: relative;
3
+ overflow: hidden;
3
4
  }
4
5
  .sr-segmented-radio-group-input_error .g-segmented-radio-group .g-segmented-radio-group__option_checked:hover::after {
5
6
  border: 1px solid var(--g-color-text-danger);
@@ -29,7 +29,7 @@ export const StringNumberWithScaleInput = ({ input, meta, props, schema }) => {
29
29
  scale: preparedScale,
30
30
  defaultType,
31
31
  viewType: viewType && preparedScale[viewType] ? [viewType] : [defaultType],
32
- minScaleLength: `${minScaleLength + 42}px`,
32
+ minScaleLength: `${minScaleLength + 60}px`,
33
33
  };
34
34
  }
35
35
  }
@@ -8,5 +8,5 @@ export const TextAreaInput = ({ input, meta, props, schema, }) => {
8
8
  var _a, _b, _c;
9
9
  const { disabled } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
10
10
  return (React.createElement(EntityContainer, { stretch: "max", className: b({ error: getBooleanValidationState(meta) }) },
11
- React.createElement(TextArea, Object.assign({ maxRows: 20, minRows: 0, placeholder: (_b = schema.examples) === null || _b === void 0 ? void 0 : _b[0], disabled: disabled || schema.readOnly, hasClear: true }, props, { value: (_c = input.value) !== null && _c !== void 0 ? _c : '', onFocus: input.onFocus, onBlur: input.onBlur, onUpdate: input.onChange, errorMessage: undefined, validationState: getValidationState(meta), qa: input.name }))));
11
+ React.createElement(TextArea, Object.assign({ maxRows: 20, minRows: 8, placeholder: (_b = schema.examples) === null || _b === void 0 ? void 0 : _b[0], disabled: disabled || schema.readOnly, hasClear: true }, props, { value: (_c = input.value) !== null && _c !== void 0 ? _c : '', onFocus: input.onFocus, onBlur: input.onBlur, onUpdate: input.onChange, errorMessage: undefined, validationState: getValidationState(meta), qa: input.name }))));
12
12
  };
@@ -4,14 +4,14 @@
4
4
  .sr-form-column:last-child {
5
5
  margin-bottom: 0;
6
6
  }
7
- .sr-form-column__top {
7
+ .sr-form-column__title {
8
8
  display: inline;
9
9
  }
10
- .sr-form-column__title {
10
+ .sr-form-column__title-text {
11
11
  min-height: 18px;
12
12
  margin-right: calc(var(--g-spacing-base) * 1);
13
13
  }
14
- .sr-form-column__title_required::after {
14
+ .sr-form-column__title-text_required::after {
15
15
  content: "*";
16
16
  margin-left: calc(var(--g-spacing-base) * 1);
17
17
  color: var(--g-color-text-danger);
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { Flex, HelpMark, Text } from '@gravity-ui/uikit';
3
- import { ArrayRemoveButton, EntityError, HTMLContent, LayoutContainer } from '../../components';
3
+ import { EntityError, HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
4
4
  import { block, getValidationState } from '../../utils';
5
5
  import './FormColumn.css';
6
6
  const b = block('form-column');
7
- export const FormColumn = ({ children, headName, input, meta, schema, props, }) => {
7
+ export const FormColumn = ({ children, headName, input, meta, mode, schema, props, }) => {
8
8
  var _a;
9
9
  const { hidden, required } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
10
10
  const tooltip = React.useMemo(() => {
@@ -22,10 +22,11 @@ export const FormColumn = ({ children, headName, input, meta, schema, props, })
22
22
  }, [headName, schema.description, props.descriptionType]);
23
23
  return (React.createElement(LayoutContainer, { className: b(), gap: 2, hidden: hidden },
24
24
  React.createElement(Flex, { direction: "column", gap: 0.5 },
25
- React.createElement("div", { className: b('top') },
26
- React.createElement(Text, { className: b('title', { required }), variant: "subheader-1", color: "complementary", wordBreak: "break-word" }, schema.title),
27
- tooltip,
28
- React.createElement(ArrayRemoveButton, { name: input.name, headName: headName })),
25
+ React.createElement(Flex, { alignItems: "center", gap: 2 },
26
+ React.createElement("div", { className: b('title') },
27
+ React.createElement(Text, { className: b('title-text', { required }), variant: "subheader-1", color: "complementary", wordBreak: "break-word" }, schema.title),
28
+ tooltip),
29
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })),
29
30
  bottomDescription),
30
31
  React.createElement(Flex, { className: b('bottom'), direction: "column", gap: 0.5 },
31
32
  children,
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
2
  import { Flex, HelpMark, Text } from '@gravity-ui/uikit';
3
- import { ArrayRemoveButton, EntityError, HTMLContent, LayoutContainer } from '../../components';
3
+ import { EntityError, HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
4
4
  import { block, getValidationState } from '../../utils';
5
5
  import './FormRow.css';
6
6
  const b = block('form-row');
7
- export const FormRow = ({ children, headName, input, meta, schema, props, }) => {
7
+ export const FormRow = ({ children, headName, input, meta, mode, schema, props, }) => {
8
8
  var _a;
9
9
  const { hidden, required } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
10
10
  const tooltip = React.useMemo(() => {
@@ -27,7 +27,7 @@ export const FormRow = ({ children, headName, input, meta, schema, props, }) =>
27
27
  React.createElement(Flex, { className: b('right'), direction: "column", gap: 0.5, grow: 1 },
28
28
  React.createElement(Flex, { grow: 1, gap: 2 },
29
29
  children,
30
- React.createElement(ArrayRemoveButton, { name: input.name, headName: headName })),
30
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })),
31
31
  bottomDescription,
32
32
  React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) }))));
33
33
  };
@@ -0,0 +1 @@
1
+ export { type UseExpandedParams, useExpanded } from './useExpanded';
@@ -0,0 +1 @@
1
+ export { useExpanded } from './useExpanded';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export interface UseExpandedParams {
3
+ headName: string;
4
+ name: string;
5
+ open?: boolean;
6
+ }
7
+ export declare const useExpanded: ({ headName, name, open }: UseExpandedParams) => {
8
+ expanded: boolean;
9
+ setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
10
+ toggleExpanded: () => void;
11
+ };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { SchemaRendererEventType, useSchemaRendererState } from '../../core';
3
+ export const useExpanded = ({ headName, name, open = true }) => {
4
+ const srState = useSchemaRendererState({
5
+ headName,
6
+ subscriptions: [SchemaRendererEventType.Submit],
7
+ });
8
+ const [expanded, setExpanded] = React.useState(open);
9
+ const toggleExpanded = React.useCallback(() => {
10
+ setExpanded((f) => !f);
11
+ }, []);
12
+ React.useEffect(() => {
13
+ if (srState &&
14
+ srState.submitCount > 0 &&
15
+ Object.keys(srState.errors).some((key) => key.startsWith(name))) {
16
+ setExpanded(true);
17
+ }
18
+ }, [srState]);
19
+ return { expanded, setExpanded, toggleExpanded };
20
+ };
@@ -1,6 +1,7 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
3
  export * from './entities';
4
+ export * from './hooks';
4
5
  export * from './form-entities';
5
6
  export * from './form-layouts';
6
7
  export * from './layouts';
@@ -1,6 +1,7 @@
1
1
  export * from './components';
2
2
  export * from './constants';
3
3
  export * from './entities';
4
+ export * from './hooks';
4
5
  export * from './form-entities';
5
6
  export * from './form-layouts';
6
7
  export * from './layouts';
@@ -4,9 +4,6 @@
4
4
  .sr-accordeon:last-child {
5
5
  margin-bottom: 0;
6
6
  }
7
- .sr-accordeon:hover .sr-accordeon__copy-button {
8
- display: block;
9
- }
10
7
  .sr-accordeon .g-disclosure__trigger {
11
8
  padding-left: 6.5px;
12
9
  }
@@ -17,6 +14,8 @@
17
14
  display: none;
18
15
  }
19
16
  .sr-accordeon__toggler {
17
+ height: auto;
18
+ min-height: 28px;
20
19
  padding-left: 6px;
21
20
  }
22
21
  .sr-accordeon__title_required::after {
@@ -40,7 +39,4 @@
40
39
  position: absolute;
41
40
  left: calc(var(--g-spacing-base) * 3 + 1.5px);
42
41
  bottom: 0;
43
- }
44
- .sr-accordeon__copy-button {
45
- display: none;
46
42
  }
@@ -3,16 +3,18 @@ import React from 'react';
3
3
  import { ChevronDown, ChevronUp } from '@gravity-ui/icons';
4
4
  import { Button, Disclosure, Flex, HelpMark, Icon, Text, } from '@gravity-ui/uikit';
5
5
  import { SchemaRendererMode } from '../../../core';
6
- import { ArrayRemoveButton, CopyButton, EntityError, HTMLContent, LayoutContainer, } from '../../components';
6
+ import { EntityError, HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
7
+ import { useExpanded } from '../../hooks';
7
8
  import { block, getValidationState } from '../../utils';
8
9
  import './Accordeon.css';
9
10
  const b = block('accordeon');
10
11
  export const Accordeon = ({ children, headName, input, meta, mode, schema, props, }) => {
11
12
  var _a;
12
13
  const { titleProps, togglerProps, withIndent = false, withDefaultSummary = false } = props, restLayoutProps = __rest(props, ["titleProps", "togglerProps", "withIndent", "withDefaultSummary"]);
13
- const { copy, required, hidden, open } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
14
+ const { required, hidden, open } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
15
+ const { expanded, setExpanded } = useExpanded({ headName, name: input.name, open });
14
16
  const overviewFlag = mode === SchemaRendererMode.Overview;
15
- const summary = React.useMemo(() => (React.createElement(Text, Object.assign({ variant: "subheader-1", color: "complementary" }, titleProps, { className: b('title', { required: required && !overviewFlag }, titleProps === null || titleProps === void 0 ? void 0 : titleProps.className) }), schema.title)), [overviewFlag, required, schema.title, titleProps]);
17
+ const summary = React.useMemo(() => (React.createElement(Text, Object.assign({ variant: "subheader-1", color: "complementary" }, titleProps, { className: b('title', { required: required && !overviewFlag }, titleProps === null || titleProps === void 0 ? void 0 : titleProps.className), whiteSpace: "break-spaces", wordBreak: "break-word" }), schema.title)), [overviewFlag, required, schema.title, titleProps]);
16
18
  const helpMark = React.useMemo(() => {
17
19
  if (schema.description) {
18
20
  return (React.createElement(HelpMark, null,
@@ -20,28 +22,15 @@ export const Accordeon = ({ children, headName, input, meta, mode, schema, props
20
22
  }
21
23
  return null;
22
24
  }, [schema.description, headName]);
23
- const copyButton = React.useMemo(() => {
24
- if (overviewFlag) {
25
- return React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value });
26
- }
27
- return null;
28
- }, [overviewFlag, copy, input.value]);
29
- const removeButton = React.useMemo(() => {
30
- if (overviewFlag) {
31
- return null;
32
- }
33
- return React.createElement(ArrayRemoveButton, { name: input.name, headName: headName });
34
- }, [overviewFlag, input.name, headName]);
35
25
  return (React.createElement(LayoutContainer, { className: b({ 'without-default-summary': !withDefaultSummary }), hideEmpty: overviewFlag, hidden: hidden },
36
- React.createElement(Disclosure, Object.assign({ defaultExpanded: open, summary: summary }, restLayoutProps),
26
+ React.createElement(Disclosure, Object.assign({ summary: summary, expanded: expanded, onUpdate: setExpanded }, restLayoutProps),
37
27
  React.createElement(Disclosure.Summary, null, ({ expanded, onClick }, defaultSummary) => (React.createElement(Flex, { minHeight: "28px", alignItems: "center", gap: 2 },
38
28
  withDefaultSummary ? (defaultSummary) : (React.createElement(Button, Object.assign({}, togglerProps, { onClick: onClick, className: b('toggler', togglerProps === null || togglerProps === void 0 ? void 0 : togglerProps.className) }),
39
29
  React.createElement(Flex, { alignItems: "center", gap: 2, height: "100%" },
40
30
  React.createElement(Icon, { data: expanded ? ChevronUp : ChevronDown }),
41
31
  summary))),
42
32
  helpMark,
43
- copyButton,
44
- removeButton))),
33
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })))),
45
34
  React.createElement(Flex, { direction: "column", gap: 0.5, grow: 1 },
46
35
  React.createElement("div", { className: b('content', { 'with-indent': withIndent }) }, children),
47
36
  overviewFlag ? null : (React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) }))))));
@@ -4,9 +4,6 @@
4
4
  .sr-card:last-child {
5
5
  margin-bottom: 0;
6
6
  }
7
- .sr-card:hover .sr-card__copy-button {
8
- display: block;
9
- }
10
7
  .sr-card__inner {
11
8
  display: flex;
12
9
  flex-direction: column;
@@ -35,7 +32,4 @@
35
32
  content: "*";
36
33
  margin-left: calc(var(--g-spacing-base) * 1);
37
34
  color: var(--g-color-text-danger);
38
- }
39
- .sr-card__copy-button {
40
- display: none;
41
35
  }
@@ -3,19 +3,21 @@ import React from 'react';
3
3
  import { ChevronDown, ChevronUp } from '@gravity-ui/icons';
4
4
  import { Button, Flex, HelpMark, Icon, Text, Card as UIKitCard, } from '@gravity-ui/uikit';
5
5
  import { SchemaRendererMode } from '../../../core';
6
- import { ArrayRemoveButton, CopyButton, EntityError, HTMLContent, LayoutContainer, } from '../../components';
6
+ import { EntityError, HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
7
+ import { useExpanded } from '../../hooks';
7
8
  import { block, getValidationState } from '../../utils';
8
9
  import './Card.css';
9
10
  const b = block('card');
10
11
  export const Card = ({ children, headName, input, meta, mode, schema, props, }) => {
11
12
  var _a;
12
13
  const { descriptionType = 'tooltip', likeAccordeon = true } = props, restLayoutProps = __rest(props, ["descriptionType", "likeAccordeon"]);
13
- const { copy, required, hidden, open = true } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
14
+ const { required, hidden, open = true } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
14
15
  const overviewFlag = mode === SchemaRendererMode.Overview;
15
- const [visible, setVisible] = React.useState(likeAccordeon ? open : true);
16
- const toggleVisible = React.useCallback(() => {
17
- setVisible((f) => !f);
18
- }, []);
16
+ const { expanded, toggleExpanded } = useExpanded({
17
+ headName,
18
+ name: input.name,
19
+ open: likeAccordeon ? open : true,
20
+ });
19
21
  const tooltip = React.useMemo(() => {
20
22
  if (!schema.description || descriptionType === 'bottom') {
21
23
  return null;
@@ -31,19 +33,18 @@ export const Card = ({ children, headName, input, meta, mode, schema, props, })
31
33
  }, [headName, schema.description, descriptionType, overviewFlag]);
32
34
  return (React.createElement(LayoutContainer, { className: b(), hideEmpty: overviewFlag, hidden: hidden },
33
35
  React.createElement(UIKitCard, Object.assign({}, restLayoutProps, { className: b('card') }),
34
- React.createElement("div", { className: b('inner', { hidden: !visible }) },
36
+ React.createElement("div", { className: b('inner', { hidden: !expanded }) },
35
37
  React.createElement(Flex, { className: b('header'), direction: "column", justifyContent: "center" },
36
38
  React.createElement(Flex, { justifyContent: "space-between", alignItems: "center" },
37
39
  React.createElement(Flex, { alignItems: "center", gap: 2 },
38
40
  React.createElement(Text, { variant: "subheader-1", color: "complementary", className: b('title', { required: required && !overviewFlag }) }, schema.title),
39
41
  tooltip),
40
42
  React.createElement(Flex, { className: b('header-actions'), alignItems: "center", gap: 2 },
41
- overviewFlag ? (React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })) : null,
42
- overviewFlag ? null : (React.createElement(ArrayRemoveButton, { name: input.name, headName: headName })),
43
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value }),
43
44
  likeAccordeon ? (React.createElement(Flex, { width: "28px", justifyContent: "center" },
44
- React.createElement(Button, { onClick: toggleVisible, size: "s", view: "flat-secondary" },
45
- React.createElement(Icon, { data: visible ? ChevronUp : ChevronDown, size: 16 })))) : null)),
45
+ React.createElement(Button, { onClick: toggleExpanded, size: "s", view: "flat-secondary" },
46
+ React.createElement(Icon, { data: expanded ? ChevronUp : ChevronDown, size: 16 })))) : null)),
46
47
  bottomDescription),
47
- React.createElement("div", { className: b('content', { hidden: !visible }) }, children)),
48
+ React.createElement("div", { className: b('content', { hidden: !expanded }) }, children)),
48
49
  overviewFlag ? null : (React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) })))));
49
50
  };
@@ -4,9 +4,6 @@
4
4
  .sr-section:last-child {
5
5
  margin-bottom: 0;
6
6
  }
7
- .sr-section:hover .sr-section__copy-button {
8
- display: block;
9
- }
10
7
  .sr-section__header {
11
8
  min-height: 28px;
12
9
  }
@@ -28,7 +25,4 @@
28
25
  position: absolute;
29
26
  left: calc(var(--g-spacing-base) * 3 + 1.5px);
30
27
  bottom: 0;
31
- }
32
- .sr-section__copy-button {
33
- display: none;
34
28
  }
@@ -2,14 +2,14 @@ import { __rest } from "tslib";
2
2
  import React from 'react';
3
3
  import { Flex, HelpMark, Text, spacing } from '@gravity-ui/uikit';
4
4
  import { SchemaRendererMode } from '../../../core';
5
- import { ArrayRemoveButton, CopyButton, EntityError, HTMLContent, LayoutContainer, } from '../../components';
5
+ import { EntityError, HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
6
6
  import { block, getValidationState } from '../../utils';
7
7
  import './Section.css';
8
8
  const b = block('section');
9
9
  export const Section = ({ children, headName, input, meta, mode, schema, props, }) => {
10
10
  var _a;
11
11
  const { descriptionType = 'tooltip', withIndent = false } = props, restLayoutProps = __rest(props, ["descriptionType", "withIndent"]);
12
- const { copy, required, hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
12
+ const { required, hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
13
13
  const overviewFlag = mode === SchemaRendererMode.Overview;
14
14
  const tooltip = React.useMemo(() => {
15
15
  if (!schema.description || descriptionType === 'bottom') {
@@ -30,8 +30,7 @@ export const Section = ({ children, headName, input, meta, mode, schema, props,
30
30
  React.createElement(Flex, { className: b('header'), gap: 2, alignItems: "center" },
31
31
  React.createElement(Text, Object.assign({ variant: "subheader-1", color: "complementary" }, restLayoutProps, { className: b('title', { required: required && !overviewFlag }, restLayoutProps === null || restLayoutProps === void 0 ? void 0 : restLayoutProps.className) }), schema.title),
32
32
  tooltip,
33
- overviewFlag ? (React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })) : null,
34
- overviewFlag ? null : (React.createElement(ArrayRemoveButton, { name: input.name, headName: headName }))),
33
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })),
35
34
  bottomDescription),
36
35
  React.createElement("div", { className: b('content', { 'with-indent': withIndent }) }, children)),
37
36
  overviewFlag ? null : (React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) }))));
@@ -3,10 +3,4 @@
3
3
  }
4
4
  .sr-transparent:last-child {
5
5
  margin-bottom: 0;
6
- }
7
- .sr-transparent:hover .sr-transparent__copy-button {
8
- display: block;
9
- }
10
- .sr-transparent__copy-button {
11
- display: none;
12
6
  }
@@ -2,18 +2,17 @@ import React from 'react';
2
2
  import { Flex } from '@gravity-ui/uikit';
3
3
  import isBoolean from 'lodash/isBoolean';
4
4
  import { SchemaRendererMode } from '../../../core';
5
- import { ArrayRemoveButton, CopyButton, EntityError, LayoutContainer } from '../../components';
5
+ import { EntityError, LayoutButtons, LayoutContainer } from '../../components';
6
6
  import { block, getValidationState } from '../../utils';
7
7
  import './Transparent.css';
8
8
  const b = block('transparent');
9
9
  export const Transparent = ({ children, headName, input, meta, mode, props, schema, }) => {
10
10
  var _a;
11
- const { copy, hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
11
+ const { hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
12
12
  const overviewFlag = mode === SchemaRendererMode.Overview;
13
13
  return (React.createElement(LayoutContainer, { className: b(), gap: 0.5, hideEmpty: isBoolean(props.hideEmpty) ? props.hideEmpty : overviewFlag, hidden: hidden },
14
14
  React.createElement(Flex, { gap: 2 },
15
15
  children,
16
- overviewFlag ? null : React.createElement(ArrayRemoveButton, { name: input.name, headName: headName }),
17
- overviewFlag ? (React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })) : null),
16
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })),
18
17
  overviewFlag ? null : (React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) }))));
19
18
  };
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import { Flex, HelpMark, Text } from '@gravity-ui/uikit';
3
- import { CopyButton, HTMLContent, LayoutContainer } from '../../components';
3
+ import { HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
4
4
  import { block } from '../../utils';
5
5
  import './OverviewColumn.css';
6
6
  const b = block('overview-column');
7
- export const OverviewColumn = ({ children, headName, input, schema }) => {
7
+ export const OverviewColumn = ({ children, headName, input, mode, schema, }) => {
8
8
  var _a;
9
- const { copy, hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
9
+ const { hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
10
10
  const tooltip = React.useMemo(() => {
11
11
  if (!schema.description) {
12
12
  return null;
@@ -22,5 +22,5 @@ export const OverviewColumn = ({ children, headName, input, schema }) => {
22
22
  React.createElement(Flex, { className: b('bottom'), direction: "column", gap: 0.5, grow: 1 },
23
23
  React.createElement(Flex, { grow: 1, gap: 2 },
24
24
  children,
25
- React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })))));
25
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })))));
26
26
  };
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import { Flex, HelpMark, Text } from '@gravity-ui/uikit';
3
- import { CopyButton, HTMLContent, LayoutContainer } from '../../components';
3
+ import { HTMLContent, LayoutButtons, LayoutContainer } from '../../components';
4
4
  import { block } from '../../utils';
5
5
  import './OverviewRow.css';
6
6
  const b = block('overview-row');
7
- export const OverviewRow = ({ children, headName, input, schema }) => {
7
+ export const OverviewRow = ({ children, headName, input, mode, schema }) => {
8
8
  var _a;
9
- const { copy, hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
9
+ const { hidden } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
10
10
  const tooltip = React.useMemo(() => {
11
11
  if (!schema.description) {
12
12
  return null;
@@ -22,5 +22,5 @@ export const OverviewRow = ({ children, headName, input, schema }) => {
22
22
  React.createElement(Flex, { className: b('right'), direction: "column", gap: 0.5, grow: 1 },
23
23
  React.createElement(Flex, { grow: 1, gap: 2 },
24
24
  children,
25
- React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })))));
25
+ React.createElement(LayoutButtons, { mode: mode, name: input.name, headName: headName, schema: schema, value: input.value })))));
26
26
  };