@gravity-ui/dynamic-forms 5.24.0 → 5.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/lib/kit/i18n/en.json +34 -0
- package/build/cjs/lib/kit/i18n/ru.json +34 -0
- package/build/cjs/lib/unstable/core/SchemaRendererNode/SchemaRendererNode.js +23 -19
- package/build/cjs/lib/unstable/core/SchemaRendererNode/utils.d.ts +3 -0
- package/build/cjs/lib/unstable/core/SchemaRendererNode/utils.js +25 -1
- package/build/cjs/lib/unstable/core/types/validation.d.ts +1 -1
- package/build/cjs/lib/unstable/core/useSchemaRenderer/useSchemaRenderer.js +6 -2
- package/build/cjs/lib/unstable/core/useSchemaRenderer/utils/get-validate.js +1 -1
- package/build/cjs/lib/unstable/kit/components/EntityError/EntityError.js +1 -1
- package/build/cjs/lib/unstable/kit/constants/index.d.ts +1 -0
- package/build/cjs/lib/unstable/kit/constants/index.js +3 -1
- package/build/cjs/lib/unstable/kit/constants/messages.d.ts +2 -0
- package/build/cjs/lib/unstable/kit/constants/messages.js +89 -0
- package/build/cjs/lib/unstable/kit/entities/Alert/Alert.js +3 -3
- package/build/cjs/lib/unstable/kit/entities/ArrayTable/ArrayTable.js +2 -2
- package/build/cjs/lib/unstable/kit/entities/FewOfNested/FewOfNested.js +6 -1
- package/build/cjs/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +3 -1
- package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +4 -0
- package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.d.ts +1 -1
- package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.js +30 -5
- package/build/cjs/lib/unstable/kit/form-entities/SelectInput/SelectInput.d.ts +1 -2
- package/build/cjs/lib/unstable/kit/form-layouts/FormRow/FormRow.css +3 -0
- package/build/cjs/lib/unstable/kit/layouts/Accordeon/Accordeon.js +29 -27
- package/build/cjs/lib/unstable/kit/utils/transformer.d.ts +3 -3
- package/build/cjs/lib/unstable/kit/utils/transformer.js +16 -10
- package/build/esm/lib/kit/i18n/en.json +34 -0
- package/build/esm/lib/kit/i18n/ru.json +34 -0
- package/build/esm/lib/unstable/core/SchemaRendererNode/SchemaRendererNode.js +24 -20
- package/build/esm/lib/unstable/core/SchemaRendererNode/utils.d.ts +3 -0
- package/build/esm/lib/unstable/core/SchemaRendererNode/utils.js +22 -0
- package/build/esm/lib/unstable/core/types/validation.d.ts +1 -1
- package/build/esm/lib/unstable/core/useSchemaRenderer/useSchemaRenderer.js +6 -2
- package/build/esm/lib/unstable/core/useSchemaRenderer/utils/get-validate.js +1 -1
- package/build/esm/lib/unstable/kit/components/EntityError/EntityError.js +1 -1
- package/build/esm/lib/unstable/kit/constants/index.d.ts +1 -0
- package/build/esm/lib/unstable/kit/constants/index.js +1 -0
- package/build/esm/lib/unstable/kit/constants/messages.d.ts +2 -0
- package/build/esm/lib/unstable/kit/constants/messages.js +85 -0
- package/build/esm/lib/unstable/kit/entities/Alert/Alert.js +3 -3
- package/build/esm/lib/unstable/kit/entities/ArrayTable/ArrayTable.js +2 -2
- package/build/esm/lib/unstable/kit/entities/FewOfNested/FewOfNested.js +6 -1
- package/build/esm/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +3 -1
- package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +4 -0
- package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.d.ts +1 -1
- package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.js +30 -5
- package/build/esm/lib/unstable/kit/form-entities/SelectInput/SelectInput.d.ts +1 -2
- package/build/esm/lib/unstable/kit/form-layouts/FormRow/FormRow.css +3 -0
- package/build/esm/lib/unstable/kit/layouts/Accordeon/Accordeon.js +29 -27
- package/build/esm/lib/unstable/kit/utils/transformer.d.ts +3 -3
- package/build/esm/lib/unstable/kit/utils/transformer.js +16 -10
- package/package.json +1 -1
|
@@ -12,34 +12,36 @@ export const Accordeon = ({ children, headName, input, meta, mode, schema, props
|
|
|
12
12
|
const { titleProps, togglerProps, withIndent = false, withDefaultSummary = false } = props, restLayoutProps = __rest(props, ["titleProps", "togglerProps", "withIndent", "withDefaultSummary"]);
|
|
13
13
|
const { copy, required, hidden, open } = ((_a = schema.nodeParameters) === null || _a === void 0 ? void 0 : _a.flags) || {};
|
|
14
14
|
const overviewFlag = mode === SchemaRendererMode.Overview;
|
|
15
|
-
const summary = React.useMemo(() => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
schema.title,
|
|
36
|
-
schema.description,
|
|
37
|
-
titleProps,
|
|
38
|
-
togglerProps,
|
|
39
|
-
withDefaultSummary,
|
|
40
|
-
]);
|
|
15
|
+
const summary = React.useMemo(() => (React.createElement(Text, Object.assign({}, titleProps, { className: b('title', { required: required && !overviewFlag }, titleProps === null || titleProps === void 0 ? void 0 : titleProps.className) }), schema.title)), [overviewFlag, required, schema.title, titleProps]);
|
|
16
|
+
const helpMark = React.useMemo(() => {
|
|
17
|
+
if (schema.description) {
|
|
18
|
+
return (React.createElement(HelpMark, null,
|
|
19
|
+
React.createElement(HTMLContent, { content: schema.description, headName: headName })));
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}, [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]);
|
|
41
35
|
return (React.createElement(LayoutContainer, { className: b({ 'without-default-summary': !withDefaultSummary }), hideEmpty: overviewFlag, hidden: hidden },
|
|
42
|
-
React.createElement(Disclosure, Object.assign({
|
|
36
|
+
React.createElement(Disclosure, Object.assign({ defaultExpanded: open, summary: summary }, restLayoutProps),
|
|
37
|
+
React.createElement(Disclosure.Summary, null, ({ expanded, onClick }, defaultSummary) => (React.createElement(Flex, { minHeight: "28px", alignItems: "center", gap: 2 },
|
|
38
|
+
withDefaultSummary ? (defaultSummary) : (React.createElement(Button, Object.assign({}, togglerProps, { onClick: onClick, className: b('toggler', togglerProps === null || togglerProps === void 0 ? void 0 : togglerProps.className) }),
|
|
39
|
+
React.createElement(Flex, { alignItems: "center", gap: 2, height: "100%" },
|
|
40
|
+
React.createElement(Icon, { data: expanded ? ChevronUp : ChevronDown }),
|
|
41
|
+
summary))),
|
|
42
|
+
helpMark,
|
|
43
|
+
copyButton,
|
|
44
|
+
removeButton))),
|
|
43
45
|
React.createElement(Flex, { direction: "column", gap: 0.5, grow: 1 },
|
|
44
46
|
React.createElement("div", { className: b('content', { 'with-indent': withIndent }) }, children),
|
|
45
47
|
overviewFlag ? null : (React.createElement(EntityError, { errorMessage: meta.error, validationState: getValidationState(meta) }))))));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Spec } from '../../../core';
|
|
2
|
-
import { type JsonSchema } from '../../core';
|
|
2
|
+
import { type ErrorMessages, type JsonSchema } from '../../core';
|
|
3
3
|
type Rules = Record<string, (spec: Spec, mutableSchema: JsonSchema, rules: {
|
|
4
4
|
specRules: Rules;
|
|
5
5
|
viewSpecRules: Rules;
|
|
6
|
-
}) => void>;
|
|
6
|
+
}, errorMessages: ErrorMessages) => void>;
|
|
7
7
|
export declare function specToJsonSchema(spec: Spec, mutableSchema?: JsonSchema, rules?: {
|
|
8
8
|
specRules: Rules;
|
|
9
9
|
viewSpecRules: Rules;
|
|
10
|
-
}): JsonSchema;
|
|
10
|
+
}, errorMessages?: ErrorMessages): JsonSchema;
|
|
11
11
|
export {};
|
|
@@ -3,6 +3,7 @@ import isObject from 'lodash/isObject';
|
|
|
3
3
|
import set from 'lodash/set';
|
|
4
4
|
import { SpecTypes } from '../../../core';
|
|
5
5
|
import { JsonSchemaType, NodeType } from '../../core';
|
|
6
|
+
import { errorMessages as defaultErrorMessages } from '../constants';
|
|
6
7
|
const viewSpecRules = {
|
|
7
8
|
disabled: (spec, mutableSchema) => {
|
|
8
9
|
if (spec.viewSpec.disabled) {
|
|
@@ -549,11 +550,16 @@ const specRules = {
|
|
|
549
550
|
set(mutableSchema, 'nodeParameters.type', specTypeToNodeType[spec.type]);
|
|
550
551
|
}
|
|
551
552
|
},
|
|
552
|
-
required: (spec, mutableSchema) => {
|
|
553
|
+
required: (spec, mutableSchema, _rules, errorMessages) => {
|
|
553
554
|
if (spec.required) {
|
|
554
555
|
set(mutableSchema, 'allOf', [
|
|
555
556
|
...(mutableSchema.allOf || []),
|
|
556
|
-
{
|
|
557
|
+
{
|
|
558
|
+
not: {
|
|
559
|
+
enum: [null, undefined, '', false],
|
|
560
|
+
nodeParameters: { errorMessages: { not: errorMessages.required } },
|
|
561
|
+
},
|
|
562
|
+
},
|
|
557
563
|
]);
|
|
558
564
|
set(mutableSchema, 'nodeParameters.flags.required', true);
|
|
559
565
|
}
|
|
@@ -586,12 +592,12 @@ const specRules = {
|
|
|
586
592
|
}
|
|
587
593
|
}
|
|
588
594
|
},
|
|
589
|
-
items: (spec, mutableSchema, rules) => {
|
|
595
|
+
items: (spec, mutableSchema, rules, errorMessages) => {
|
|
590
596
|
if (spec.type === SpecTypes.Array && spec.items) {
|
|
591
597
|
const childSchema = specToJsonSchema(spec.items, 'items' in mutableSchema &&
|
|
592
598
|
mutableSchema.items &&
|
|
593
599
|
!Array.isArray(mutableSchema.items)
|
|
594
|
-
? Object.assign({}, mutableSchema.items) : {}, rules);
|
|
600
|
+
? Object.assign({}, mutableSchema.items) : {}, rules, errorMessages);
|
|
595
601
|
set(mutableSchema, 'items', childSchema);
|
|
596
602
|
}
|
|
597
603
|
},
|
|
@@ -649,10 +655,10 @@ const specRules = {
|
|
|
649
655
|
set(mutableSchema, 'type', JsonSchemaType.Integer);
|
|
650
656
|
}
|
|
651
657
|
},
|
|
652
|
-
properties: (spec, mutableSchema, rules) => {
|
|
658
|
+
properties: (spec, mutableSchema, rules, errorMessages) => {
|
|
653
659
|
if (spec.type === SpecTypes.Object && spec.properties) {
|
|
654
660
|
Object.entries(spec.properties).forEach(([key, childSpec]) => {
|
|
655
|
-
const childSchema = specToJsonSchema(childSpec, Object.assign({}, (get(mutableSchema, ['properties', key]) || {})), rules);
|
|
661
|
+
const childSchema = specToJsonSchema(childSpec, Object.assign({}, (get(mutableSchema, ['properties', key]) || {})), rules, errorMessages);
|
|
656
662
|
set(mutableSchema, ['properties', key], childSchema);
|
|
657
663
|
});
|
|
658
664
|
}
|
|
@@ -667,13 +673,13 @@ const specRules = {
|
|
|
667
673
|
set(mutableSchema, 'nodeParameters.errorMessages.pattern', spec.patternError);
|
|
668
674
|
}
|
|
669
675
|
},
|
|
670
|
-
viewSpec: (spec, mutableSchema, rules) => {
|
|
671
|
-
Object.values(rules.viewSpecRules).forEach((rule) => rule(spec, mutableSchema, rules));
|
|
676
|
+
viewSpec: (spec, mutableSchema, rules, errorMessages) => {
|
|
677
|
+
Object.values(rules.viewSpecRules).forEach((rule) => rule(spec, mutableSchema, rules, errorMessages));
|
|
672
678
|
},
|
|
673
679
|
};
|
|
674
|
-
export function specToJsonSchema(spec, mutableSchema = {}, rules) {
|
|
680
|
+
export function specToJsonSchema(spec, mutableSchema = {}, rules, errorMessages = defaultErrorMessages) {
|
|
675
681
|
const mergedSpecRules = Object.assign(Object.assign({}, specRules), rules === null || rules === void 0 ? void 0 : rules.specRules);
|
|
676
682
|
const mergedViewSpecRules = Object.assign(Object.assign({}, viewSpecRules), rules === null || rules === void 0 ? void 0 : rules.viewSpecRules);
|
|
677
|
-
Object.values(mergedSpecRules).forEach((rule) => rule(spec, mutableSchema, { specRules: mergedSpecRules, viewSpecRules: mergedViewSpecRules }));
|
|
683
|
+
Object.values(mergedSpecRules).forEach((rule) => rule(spec, mutableSchema, { specRules: mergedSpecRules, viewSpecRules: mergedViewSpecRules }, errorMessages));
|
|
678
684
|
return mutableSchema;
|
|
679
685
|
}
|