@gravity-ui/dynamic-forms 5.29.1 → 5.30.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 (29) hide show
  1. package/build/cjs/lib/unstable/kit/components/EntityContainer/EntityContainer.d.ts +1 -0
  2. package/build/cjs/lib/unstable/kit/entities/FewOfNested/FewOfNested.d.ts +1 -0
  3. package/build/cjs/lib/unstable/kit/entities/FewOfNested/FewOfNested.js +8 -3
  4. package/build/cjs/lib/unstable/kit/entities/OneOfNested/OneOfNested.d.ts +1 -0
  5. package/build/cjs/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +8 -3
  6. package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +9 -4
  7. package/build/cjs/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.js +14 -15
  8. package/build/cjs/lib/unstable/kit/form-layouts/FormColumn/FormColumn.js +1 -1
  9. package/build/cjs/lib/unstable/kit/form-layouts/FormRow/FormRow.js +1 -1
  10. package/build/cjs/lib/unstable/kit/layouts/Accordeon/Accordeon.js +1 -1
  11. package/build/cjs/lib/unstable/kit/layouts/Card/Card.js +1 -1
  12. package/build/cjs/lib/unstable/kit/layouts/Section/Section.js +1 -1
  13. package/build/cjs/lib/unstable/kit/utils/transformer.d.ts +6 -2
  14. package/build/cjs/lib/unstable/kit/utils/transformer.js +103 -72
  15. package/build/esm/lib/unstable/kit/components/EntityContainer/EntityContainer.d.ts +1 -0
  16. package/build/esm/lib/unstable/kit/entities/FewOfNested/FewOfNested.d.ts +1 -0
  17. package/build/esm/lib/unstable/kit/entities/FewOfNested/FewOfNested.js +8 -3
  18. package/build/esm/lib/unstable/kit/entities/OneOfNested/OneOfNested.d.ts +1 -0
  19. package/build/esm/lib/unstable/kit/entities/OneOfNested/OneOfNested.js +8 -3
  20. package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.css +9 -4
  21. package/build/esm/lib/unstable/kit/form-entities/SegmentedRadioGroupInput/SegmentedRadioGroupInput.js +14 -15
  22. package/build/esm/lib/unstable/kit/form-layouts/FormColumn/FormColumn.js +1 -1
  23. package/build/esm/lib/unstable/kit/form-layouts/FormRow/FormRow.js +1 -1
  24. package/build/esm/lib/unstable/kit/layouts/Accordeon/Accordeon.js +1 -1
  25. package/build/esm/lib/unstable/kit/layouts/Card/Card.js +1 -1
  26. package/build/esm/lib/unstable/kit/layouts/Section/Section.js +1 -1
  27. package/build/esm/lib/unstable/kit/utils/transformer.d.ts +6 -2
  28. package/build/esm/lib/unstable/kit/utils/transformer.js +103 -72
  29. package/package.json +1 -1
@@ -12,7 +12,8 @@ export const SegmentedRadioGroupInput = (_a) => {
12
12
  const { name, onBlur, onChange, onFocus, value } = input;
13
13
  const { enumDescriptions, optionsDisabled } = props, restEntityProps = __rest(props, ["enumDescriptions", "optionsDisabled"]);
14
14
  const { disabled } = ((_b = schema.nodeParameters) === null || _b === void 0 ? void 0 : _b.flags) || {};
15
- const ref = React.useRef(null);
15
+ const containerRef = React.useRef(null);
16
+ const controlRef = React.useRef(null);
16
17
  const [overflowed, setOverflowed] = React.useState(false);
17
18
  const options = React.useMemo(() => {
18
19
  var _a;
@@ -28,26 +29,24 @@ export const SegmentedRadioGroupInput = (_a) => {
28
29
  onBlur();
29
30
  }, [onBlur, onChange, onFocus]);
30
31
  React.useLayoutEffect(() => {
31
- const root = ref.current;
32
- if (!root) {
32
+ const container = containerRef.current;
33
+ const control = controlRef.current;
34
+ if (!container || !control) {
33
35
  return;
34
36
  }
35
37
  const measure = () => {
36
- const texts = root.querySelectorAll('.g-segmented-radio-group__option-text');
37
- setOverflowed(Array.from(texts).some((node) => {
38
- if (node.offsetWidth === 0 && node.scrollWidth === 0) {
39
- return false;
40
- }
41
- return node.scrollWidth > node.clientWidth;
42
- }));
38
+ const GAP = 48; // little bit more than potential remove button width + spacing
39
+ const containerWidth = container.offsetWidth - GAP;
40
+ const controlWidth = control.offsetWidth;
41
+ setOverflowed(controlWidth > containerWidth);
43
42
  };
44
43
  measure();
45
44
  const observer = new ResizeObserver(measure);
46
- observer.observe(root);
45
+ observer.observe(container);
47
46
  return () => observer.disconnect();
48
47
  }, [options]);
49
- return (React.createElement(EntityContainer, { stretch: "max" },
50
- overflowed ? (React.createElement(SelectInput, Object.assign({ input: input, meta: meta, props: props, schema: schema }, restProps))) : null,
51
- React.createElement(EntityContainer, { stretch: "max", className: b({ error: getBooleanValidationState(meta), overflowed }) },
52
- React.createElement(SegmentedRadioGroup, Object.assign({ ref: ref, width: "max", disabled: disabled || schema.readOnly, options: options }, restEntityProps, { value: value, onFocus: onFocus, onBlur: onBlur, onUpdate: onUpdate, qa: name })))));
48
+ return (React.createElement(EntityContainer, { ref: containerRef, className: b({ error: getBooleanValidationState(meta) }), stretch: "max" },
49
+ overflowed ? (React.createElement(SelectInput, Object.assign({ input: input, meta: meta, props: props, schema: schema }, restProps))) : (React.createElement(SegmentedRadioGroup, Object.assign({ width: "max", disabled: disabled || schema.readOnly, options: options }, restEntityProps, { value: value, onFocus: onFocus, onBlur: onBlur, onUpdate: onUpdate, qa: name }))),
50
+ React.createElement("div", { className: b('checker') },
51
+ React.createElement(SegmentedRadioGroup, Object.assign({ ref: controlRef, width: "max", disabled: disabled || schema.readOnly, options: options }, restEntityProps)))));
53
52
  };
@@ -23,7 +23,7 @@ export const FormColumn = ({ children, headName, input, meta, schema, props, })
23
23
  return (React.createElement(LayoutContainer, { className: b(), gap: 2, hidden: hidden },
24
24
  React.createElement(Flex, { direction: "column", gap: 0.5 },
25
25
  React.createElement("div", { className: b('top') },
26
- React.createElement(Text, { className: b('title', { required }), wordBreak: "break-word" }, schema.title),
26
+ React.createElement(Text, { className: b('title', { required }), variant: "subheader-1", color: "complementary", wordBreak: "break-word" }, schema.title),
27
27
  tooltip,
28
28
  React.createElement(ArrayRemoveButton, { name: input.name, headName: headName })),
29
29
  bottomDescription),
@@ -22,7 +22,7 @@ export const FormRow = ({ children, headName, input, meta, schema, props, }) =>
22
22
  }, [headName, schema.description, props.descriptionType]);
23
23
  return (React.createElement(LayoutContainer, { className: b(), direction: "row", alignItems: "flex-start", gap: 2, hidden: hidden },
24
24
  React.createElement("div", { className: b('left') },
25
- React.createElement(Text, { className: b('title', { required }), wordBreak: "break-word" }, schema.title),
25
+ React.createElement(Text, { className: b('title', { required }), variant: "subheader-1", color: "complementary", wordBreak: "break-word" }, schema.title),
26
26
  tooltip),
27
27
  React.createElement(Flex, { className: b('right'), direction: "column", gap: 0.5, grow: 1 },
28
28
  React.createElement(Flex, { grow: 1, gap: 2 },
@@ -12,7 +12,7 @@ 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(() => (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]);
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]);
16
16
  const helpMark = React.useMemo(() => {
17
17
  if (schema.description) {
18
18
  return (React.createElement(HelpMark, null,
@@ -35,7 +35,7 @@ export const Card = ({ children, headName, input, meta, mode, schema, props, })
35
35
  React.createElement(Flex, { className: b('header'), direction: "column", justifyContent: "center" },
36
36
  React.createElement(Flex, { justifyContent: "space-between", alignItems: "center" },
37
37
  React.createElement(Flex, { alignItems: "center", gap: 2 },
38
- React.createElement(Text, { variant: "subheader-1", className: b('title', { required: required && !overviewFlag }) }, schema.title),
38
+ React.createElement(Text, { variant: "subheader-1", color: "complementary", className: b('title', { required: required && !overviewFlag }) }, schema.title),
39
39
  tooltip),
40
40
  React.createElement(Flex, { className: b('header-actions'), alignItems: "center", gap: 2 },
41
41
  overviewFlag ? (React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })) : null,
@@ -28,7 +28,7 @@ export const Section = ({ children, headName, input, meta, mode, schema, props,
28
28
  React.createElement(Flex, { direction: "column", gap: 4 },
29
29
  React.createElement(Flex, { direction: "column" },
30
30
  React.createElement(Flex, { className: b('header'), gap: 2, alignItems: "center" },
31
- React.createElement(Text, Object.assign({ variant: "subheader-1" }, restLayoutProps, { className: b('title', { required: required && !overviewFlag }, restLayoutProps === null || restLayoutProps === void 0 ? void 0 : restLayoutProps.className) }), schema.title),
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
33
  overviewFlag ? (React.createElement(CopyButton, { className: b('copy-button'), copy: copy, value: input.value })) : null,
34
34
  overviewFlag ? null : (React.createElement(ArrayRemoveButton, { name: input.name, headName: headName }))),
@@ -1,10 +1,14 @@
1
1
  import { type Spec } from '../../../core';
2
2
  import { type ErrorMessages, type JsonSchema } from '../../core';
3
- type Rules = Record<string, (spec: Spec, mutableSchema: JsonSchema, rules: {
3
+ type Rules = Record<string, (spec: Partial<Spec & {
4
+ viewSpec: Partial<Spec['viewSpec']>;
5
+ }> | null | undefined, mutableSchema: JsonSchema, rules: {
4
6
  specRules: Rules;
5
7
  viewSpecRules: Rules;
6
8
  }, errorMessages: ErrorMessages) => void>;
7
- export declare function specToJsonSchema(spec: Spec, mutableSchema?: JsonSchema, rules?: {
9
+ export declare function specToJsonSchema(spec: Partial<Spec & {
10
+ viewSpec: Partial<Spec['viewSpec']>;
11
+ }> | null | undefined, mutableSchema?: JsonSchema, rules?: {
8
12
  specRules: Rules;
9
13
  viewSpecRules: Rules;
10
14
  }, errorMessages?: ErrorMessages): JsonSchema;
@@ -5,12 +5,14 @@ import { SpecTypes } from '../../../core';
5
5
  import { JsonSchemaType, NodeType } from '../../core';
6
6
  const viewSpecRules = {
7
7
  disabled: (spec, mutableSchema) => {
8
- if (spec.viewSpec.disabled) {
8
+ var _a;
9
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.disabled) {
9
10
  set(mutableSchema, 'nodeParameters.flags.disabled', true);
10
11
  }
11
12
  },
12
13
  layout: (spec, mutableSchema) => {
13
- const layout = spec.viewSpec.layout;
14
+ var _a;
15
+ const layout = (_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layout;
14
16
  if (!layout) {
15
17
  return;
16
18
  }
@@ -55,35 +57,38 @@ const viewSpecRules = {
55
57
  }
56
58
  },
57
59
  layoutTitle: (spec, mutableSchema) => {
58
- if (spec.viewSpec.layoutTitle) {
60
+ var _a;
61
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutTitle) {
59
62
  set(mutableSchema, 'title', spec.viewSpec.layoutTitle);
60
63
  }
61
64
  },
62
65
  layoutDescription: (spec, mutableSchema) => {
63
- if (spec.viewSpec.layoutDescription) {
66
+ var _a;
67
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutDescription) {
64
68
  set(mutableSchema, 'description', spec.viewSpec.layoutDescription);
65
69
  }
66
70
  },
67
71
  layoutOpen: (spec, mutableSchema) => {
68
- if (spec.viewSpec.layoutOpen !== undefined) {
72
+ var _a;
73
+ if (((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutOpen) !== undefined) {
69
74
  set(mutableSchema, 'nodeParameters.flags.open', spec.viewSpec.layoutOpen);
70
75
  }
71
76
  },
72
77
  itemLabel: (spec, mutableSchema) => {
73
- if ('itemLabel' in spec.viewSpec && spec.viewSpec.itemLabel) {
78
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) && 'itemLabel' in spec.viewSpec && spec.viewSpec.itemLabel) {
74
79
  set(mutableSchema, 'nodeParameters.entityProps.addButtonText', spec.viewSpec.itemLabel);
75
80
  }
76
81
  },
77
82
  itemPrefix: (spec, mutableSchema) => {
78
- if ('itemPrefix' in spec.viewSpec && spec.viewSpec.itemPrefix) {
83
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) && 'itemPrefix' in spec.viewSpec && spec.viewSpec.itemPrefix) {
79
84
  set(mutableSchema, 'nodeParameters.entityProps.itemPrefix', spec.viewSpec.itemPrefix);
80
85
  }
81
86
  },
82
87
  table: (spec, mutableSchema) => {
83
- var _a;
84
- if (spec.type === SpecTypes.Array &&
85
- spec.viewSpec.table &&
86
- ((_a = spec.items) === null || _a === void 0 ? void 0 : _a.type) === SpecTypes.Object) {
88
+ var _a, _b;
89
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array &&
90
+ ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.table) &&
91
+ ((_b = spec === null || spec === void 0 ? void 0 : spec.items) === null || _b === void 0 ? void 0 : _b.type) === SpecTypes.Object) {
87
92
  const order = [];
88
93
  spec.viewSpec.table.forEach(({ description, label, property }) => {
89
94
  order.push(property);
@@ -98,32 +103,39 @@ const viewSpecRules = {
98
103
  }
99
104
  },
100
105
  link: (spec, mutableSchema) => {
101
- if (spec.viewSpec.link) {
106
+ var _a;
107
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.link) {
102
108
  set(mutableSchema, 'nodeParameters.entityProps.link', spec.viewSpec.link);
103
109
  }
104
110
  },
105
111
  placeholder: (spec, mutableSchema) => {
106
- if ('placeholder' in spec.viewSpec && spec.viewSpec.placeholder) {
112
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) && 'placeholder' in spec.viewSpec && spec.viewSpec.placeholder) {
107
113
  if (spec.type === SpecTypes.String) {
108
114
  set(mutableSchema, 'examples', [spec.viewSpec.placeholder]);
109
115
  }
110
116
  else if (spec.type === SpecTypes.Array) {
111
117
  set(mutableSchema, 'examples', [[spec.viewSpec.placeholder]]);
112
118
  }
119
+ else {
120
+ set(mutableSchema, 'nodeParameters.entityProps.placeholder', spec.viewSpec.placeholder);
121
+ }
113
122
  }
114
123
  },
115
124
  addButtonPosition: (spec, mutableSchema) => {
116
- if ('addButtonPosition' in spec.viewSpec && spec.viewSpec.addButtonPosition) {
125
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) &&
126
+ 'addButtonPosition' in spec.viewSpec &&
127
+ spec.viewSpec.addButtonPosition) {
117
128
  set(mutableSchema, 'nodeParameters.entityProps.addButtonPosition', spec.viewSpec.addButtonPosition);
118
129
  }
119
130
  },
120
131
  hidden: (spec, mutableSchema) => {
121
- if (spec.viewSpec.hidden) {
132
+ var _a;
133
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.hidden) {
122
134
  set(mutableSchema, 'nodeParameters.flags.hidden', true);
123
135
  }
124
136
  },
125
137
  selectParams: (spec, mutableSchema) => {
126
- if ('selectParams' in spec.viewSpec && spec.viewSpec.selectParams) {
138
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) && 'selectParams' in spec.viewSpec && spec.viewSpec.selectParams) {
127
139
  if (spec.viewSpec.selectParams.filterPlaceholder) {
128
140
  set(mutableSchema, 'nodeParameters.entityProps.filterPlaceholder', spec.viewSpec.selectParams.filterPlaceholder);
129
141
  }
@@ -133,7 +145,8 @@ const viewSpecRules = {
133
145
  }
134
146
  },
135
147
  checkboxGroupParams: (spec, mutableSchema) => {
136
- if (spec.type === SpecTypes.Array && spec.viewSpec.checkboxGroupParams) {
148
+ var _a;
149
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.checkboxGroupParams)) {
137
150
  if (spec.viewSpec.checkboxGroupParams.placement) {
138
151
  set(mutableSchema, 'nodeParameters.entityProps.direction', spec.viewSpec.checkboxGroupParams.placement === 'vertical' ? 'column' : 'row');
139
152
  }
@@ -143,31 +156,35 @@ const viewSpecRules = {
143
156
  }
144
157
  },
145
158
  viewColor: (spec, mutableSchema) => {
146
- if (spec.type === SpecTypes.Boolean && spec.viewSpec.viewColor) {
159
+ var _a;
160
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Boolean && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.viewColor)) {
147
161
  set(mutableSchema, 'nodeParameters.overviewEntityProps.viewColor', spec.viewSpec.viewColor);
148
162
  }
149
163
  },
150
164
  copy: (spec, mutableSchema) => {
151
- if ('copy' in spec.viewSpec && spec.viewSpec.copy) {
165
+ if ((spec === null || spec === void 0 ? void 0 : spec.viewSpec) && 'copy' in spec.viewSpec && spec.viewSpec.copy) {
152
166
  set(mutableSchema, 'nodeParameters.flags.copy', true);
153
167
  }
154
168
  },
155
169
  order: (spec, mutableSchema) => {
156
- if (spec.type === SpecTypes.Object &&
157
- spec.viewSpec.order &&
170
+ var _a;
171
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Object &&
172
+ ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.order) &&
158
173
  Object.keys(spec.viewSpec.order).length) {
159
174
  set(mutableSchema, 'nodeParameters.entityProps.order', spec.viewSpec.order);
160
175
  }
161
176
  },
162
177
  delimiter: (spec, mutableSchema) => {
163
- if (spec.type === SpecTypes.Object &&
164
- spec.viewSpec.delimiter &&
178
+ var _a;
179
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Object &&
180
+ ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.delimiter) &&
165
181
  Object.keys(spec.viewSpec.delimiter).length) {
166
182
  set(mutableSchema, 'nodeParameters.entityProps.delimiter', spec.viewSpec.delimiter);
167
183
  }
168
184
  },
169
185
  sizeParams: (spec, mutableSchema) => {
170
- if (spec.type === SpecTypes.String && spec.viewSpec.sizeParams) {
186
+ var _a;
187
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.sizeParams)) {
171
188
  if (spec.viewSpec.sizeParams.defaultType) {
172
189
  set(mutableSchema, 'nodeParameters.entityProps.defaultType', spec.viewSpec.sizeParams.defaultType);
173
190
  }
@@ -180,7 +197,8 @@ const viewSpecRules = {
180
197
  }
181
198
  },
182
199
  monacoParams: (spec, mutableSchema) => {
183
- if (spec.type === SpecTypes.String && spec.viewSpec.monacoParams) {
200
+ var _a;
201
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.monacoParams)) {
184
202
  if (spec.viewSpec.monacoParams.language) {
185
203
  set(mutableSchema, 'nodeParameters.entityProps.language', spec.viewSpec.monacoParams.language);
186
204
  }
@@ -190,12 +208,14 @@ const viewSpecRules = {
190
208
  }
191
209
  },
192
210
  hideValues: (spec, mutableSchema) => {
193
- if (spec.type === SpecTypes.String && spec.viewSpec.hideValues) {
211
+ var _a;
212
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.hideValues)) {
194
213
  set(mutableSchema, 'nodeParameters.entityProps.hideValues', spec.viewSpec.hideValues);
195
214
  }
196
215
  },
197
216
  textContentParams: (spec, mutableSchema) => {
198
- if (spec.type !== SpecTypes.String || !spec.viewSpec.textContentParams) {
217
+ var _a;
218
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) !== SpecTypes.String || !((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.textContentParams)) {
199
219
  return;
200
220
  }
201
221
  const textContentParams = spec.viewSpec.textContentParams;
@@ -228,7 +248,8 @@ const viewSpecRules = {
228
248
  }
229
249
  },
230
250
  fileInput: (spec, mutableSchema) => {
231
- if (spec.type === SpecTypes.String && spec.viewSpec.fileInput) {
251
+ var _a;
252
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.fileInput)) {
232
253
  if (spec.viewSpec.fileInput.accept) {
233
254
  set(mutableSchema, 'nodeParameters.entityProps.accept', [
234
255
  spec.viewSpec.fileInput.accept,
@@ -240,7 +261,8 @@ const viewSpecRules = {
240
261
  }
241
262
  },
242
263
  dateInput: (spec, mutableSchema) => {
243
- if (spec.type === SpecTypes.String && spec.viewSpec.dateInput) {
264
+ var _a;
265
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.dateInput)) {
244
266
  if (spec.viewSpec.dateInput.outputFormat) {
245
267
  set(mutableSchema, 'nodeParameters.entityProps.outputFormat', spec.viewSpec.dateInput.outputFormat);
246
268
  }
@@ -253,7 +275,8 @@ const viewSpecRules = {
253
275
  }
254
276
  },
255
277
  radioGroupParams: (spec, mutableSchema) => {
256
- if (spec.type === SpecTypes.String && spec.viewSpec.radioGroupParams) {
278
+ var _a;
279
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.radioGroupParams)) {
257
280
  if (spec.viewSpec.radioGroupParams.direction) {
258
281
  set(mutableSchema, 'nodeParameters.entityProps.direction', spec.viewSpec.radioGroupParams.direction);
259
282
  }
@@ -263,19 +286,22 @@ const viewSpecRules = {
263
286
  }
264
287
  },
265
288
  generateRandomValueButton: (spec, mutableSchema) => {
266
- if (spec.type === SpecTypes.String && spec.viewSpec.generateRandomValueButton) {
289
+ var _a;
290
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.generateRandomValueButton)) {
267
291
  set(mutableSchema, 'nodeParameters.entityProps.generateRandomValueButton', true);
268
292
  }
269
293
  },
270
294
  inputProps: (spec, mutableSchema) => {
271
- if (spec.viewSpec.inputProps) {
295
+ var _a;
296
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.inputProps) {
272
297
  Object.entries(spec.viewSpec.inputProps).forEach(([key, value]) => {
273
298
  set(mutableSchema, `nodeParameters.entityProps.${key}`, value);
274
299
  });
275
300
  }
276
301
  },
277
302
  layoutProps: (spec, mutableSchema) => {
278
- if (spec.viewSpec.layoutProps) {
303
+ var _a;
304
+ if ((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutProps) {
279
305
  Object.entries(spec.viewSpec.layoutProps).forEach(([key, value]) => {
280
306
  set(mutableSchema, `nodeParameters.layoutProps.${key}`, value);
281
307
  });
@@ -283,7 +309,8 @@ const viewSpecRules = {
283
309
  },
284
310
  // eslint-disable-next-line complexity -- old viewSpec.type mapping, isolated per viewType
285
311
  type: (spec, mutableSchema) => {
286
- if (spec.viewSpec.type === 'oneof') {
312
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
313
+ if (((_a = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _a === void 0 ? void 0 : _a.type) === 'oneof') {
287
314
  set(mutableSchema, 'nodeParameters.entity', 'one_of_nested');
288
315
  if (spec.type === SpecTypes.Object) {
289
316
  const { toggler, booleanMap } = spec.viewSpec.oneOfParams || {};
@@ -329,7 +356,7 @@ const viewSpecRules = {
329
356
  }
330
357
  }
331
358
  }
332
- else if (spec.viewSpec.type === 'oneof_flat') {
359
+ else if (((_b = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _b === void 0 ? void 0 : _b.type) === 'oneof_flat') {
333
360
  set(mutableSchema, 'nodeParameters.entity', 'one_of_nested');
334
361
  if (spec.type === SpecTypes.Object) {
335
362
  const { toggler, booleanMap } = spec.viewSpec.oneOfParams || {};
@@ -374,7 +401,7 @@ const viewSpecRules = {
374
401
  }
375
402
  }
376
403
  }
377
- else if (spec.viewSpec.type === 'card_oneof') {
404
+ else if (((_c = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _c === void 0 ? void 0 : _c.type) === 'card_oneof') {
378
405
  set(mutableSchema, 'nodeParameters.entity', 'one_of_nested');
379
406
  if (spec.type === SpecTypes.Object) {
380
407
  const { toggler, booleanMap } = spec.viewSpec.oneOfParams || {};
@@ -419,7 +446,7 @@ const viewSpecRules = {
419
446
  }
420
447
  }
421
448
  }
422
- else if (spec.viewSpec.type === 'multi_oneof') {
449
+ else if (((_d = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _d === void 0 ? void 0 : _d.type) === 'multi_oneof') {
423
450
  set(mutableSchema, 'nodeParameters.entity', 'few_of_nested');
424
451
  if (spec.type === SpecTypes.Object) {
425
452
  const { toggler } = spec.viewSpec.oneOfParams || {};
@@ -455,7 +482,7 @@ const viewSpecRules = {
455
482
  set(mutableSchema, 'nodeParameters.entityProps.toggler.items.enum', spec.viewSpec.order || Object.keys(spec.properties || {}));
456
483
  }
457
484
  }
458
- else if (spec.viewSpec.type === 'multi_oneof_flat') {
485
+ else if (((_e = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _e === void 0 ? void 0 : _e.type) === 'multi_oneof_flat') {
459
486
  set(mutableSchema, 'nodeParameters.entity', 'few_of_nested');
460
487
  if (spec.type === SpecTypes.Object) {
461
488
  const { toggler } = spec.viewSpec.oneOfParams || {};
@@ -490,10 +517,10 @@ const viewSpecRules = {
490
517
  set(mutableSchema, 'nodeParameters.entityProps.toggler.items.enum', spec.viewSpec.order || Object.keys(spec.properties || {}));
491
518
  }
492
519
  }
493
- else if (spec.viewSpec.type === 'object_value') {
520
+ else if (((_f = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _f === void 0 ? void 0 : _f.type) === 'object_value') {
494
521
  set(mutableSchema, 'nodeParameters.entity', 'dot_value');
495
522
  }
496
- else if (spec.viewSpec.type === 'text_content') {
523
+ else if (((_g = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _g === void 0 ? void 0 : _g.type) === 'text_content') {
497
524
  const textContentParams = spec.type === SpecTypes.String ? spec.viewSpec.textContentParams : undefined;
498
525
  if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert) {
499
526
  set(mutableSchema, 'nodeParameters.entity', 'alert');
@@ -505,31 +532,31 @@ const viewSpecRules = {
505
532
  set(mutableSchema, 'nodeParameters.entity', 'text_content');
506
533
  }
507
534
  }
508
- else if (spec.viewSpec.type === 'date_input') {
535
+ else if (((_h = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _h === void 0 ? void 0 : _h.type) === 'date_input') {
509
536
  set(mutableSchema, 'type', undefined);
510
537
  set(mutableSchema, 'nodeParameters.entity', 'date');
511
538
  set(mutableSchema, 'nodeParameters.type', NodeType.Any);
512
539
  }
513
- else if (spec.viewSpec.type === 'file_input') {
540
+ else if (((_j = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _j === void 0 ? void 0 : _j.type) === 'file_input') {
514
541
  set(mutableSchema, 'nodeParameters.entity', 'file');
515
542
  }
516
- else if (spec.viewSpec.type === 'monaco_input') {
543
+ else if (((_k = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _k === void 0 ? void 0 : _k.type) === 'monaco_input') {
517
544
  set(mutableSchema, 'nodeParameters.entity', 'monaco_input');
518
545
  }
519
- else if (spec.viewSpec.type === 'number_with_scale') {
546
+ else if (((_l = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _l === void 0 ? void 0 : _l.type) === 'number_with_scale') {
520
547
  set(mutableSchema, 'nodeParameters.entity', 'string_number_with_scale');
521
548
  }
522
- else if (spec.viewSpec.type === 'range_input_picker') {
549
+ else if (((_m = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _m === void 0 ? void 0 : _m.type) === 'range_input_picker') {
523
550
  set(mutableSchema, 'nodeParameters.entity', spec.type === SpecTypes.Number ? 'slider' : 'range_input');
524
551
  }
525
552
  else {
526
- set(mutableSchema, 'nodeParameters.entity', spec.viewSpec.type);
553
+ set(mutableSchema, 'nodeParameters.entity', (_o = spec === null || spec === void 0 ? void 0 : spec.viewSpec) === null || _o === void 0 ? void 0 : _o.type);
527
554
  }
528
555
  },
529
556
  };
530
557
  const specRules = {
531
558
  defaultValue: (spec, mutableSchema) => {
532
- if (spec.defaultValue !== undefined) {
559
+ if ((spec === null || spec === void 0 ? void 0 : spec.defaultValue) !== undefined) {
533
560
  set(mutableSchema, 'default', spec.defaultValue);
534
561
  }
535
562
  },
@@ -548,13 +575,13 @@ const specRules = {
548
575
  [SpecTypes.Object]: NodeType.Object,
549
576
  [SpecTypes.String]: NodeType.String,
550
577
  };
551
- if (spec.type) {
578
+ if (spec === null || spec === void 0 ? void 0 : spec.type) {
552
579
  set(mutableSchema, 'type', specTypeToJsonSchemaType[spec.type]);
553
580
  set(mutableSchema, 'nodeParameters.type', specTypeToNodeType[spec.type]);
554
581
  }
555
582
  },
556
583
  required: (spec, mutableSchema, _rules, errorMessages) => {
557
- if (spec.required) {
584
+ if (spec === null || spec === void 0 ? void 0 : spec.required) {
558
585
  set(mutableSchema, 'allOf', [
559
586
  ...(mutableSchema.allOf || []),
560
587
  {
@@ -568,13 +595,13 @@ const specRules = {
568
595
  }
569
596
  },
570
597
  maxLength: (spec, mutableSchema) => {
571
- if (spec.type === SpecTypes.Array && spec.maxLength !== undefined) {
598
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array && (spec === null || spec === void 0 ? void 0 : spec.maxLength) !== undefined) {
572
599
  const maxItems = Number(spec.maxLength);
573
600
  if (!Number.isNaN(maxItems)) {
574
601
  set(mutableSchema, 'maxItems', maxItems);
575
602
  }
576
603
  }
577
- if (spec.type === SpecTypes.String && spec.maxLength !== undefined) {
604
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && (spec === null || spec === void 0 ? void 0 : spec.maxLength) !== undefined) {
578
605
  const maxLength = Number(spec.maxLength);
579
606
  if (!Number.isNaN(maxLength)) {
580
607
  set(mutableSchema, 'maxLength', maxLength);
@@ -582,13 +609,13 @@ const specRules = {
582
609
  }
583
610
  },
584
611
  minLength: (spec, mutableSchema) => {
585
- if (spec.type === SpecTypes.Array && spec.minLength !== undefined) {
612
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array && (spec === null || spec === void 0 ? void 0 : spec.minLength) !== undefined) {
586
613
  const minItems = Number(spec.minLength);
587
614
  if (!Number.isNaN(minItems)) {
588
615
  set(mutableSchema, 'minItems', minItems);
589
616
  }
590
617
  }
591
- if (spec.type === SpecTypes.String && spec.minLength !== undefined) {
618
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && (spec === null || spec === void 0 ? void 0 : spec.minLength) !== undefined) {
592
619
  const minLength = Number(spec.minLength);
593
620
  if (!Number.isNaN(minLength)) {
594
621
  set(mutableSchema, 'minLength', minLength);
@@ -596,7 +623,7 @@ const specRules = {
596
623
  }
597
624
  },
598
625
  items: (spec, mutableSchema, rules, errorMessages) => {
599
- if (spec.type === SpecTypes.Array && spec.items) {
626
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array && (spec === null || spec === void 0 ? void 0 : spec.items)) {
600
627
  const childSchema = specToJsonSchema(spec.items, 'items' in mutableSchema &&
601
628
  mutableSchema.items &&
602
629
  !Array.isArray(mutableSchema.items)
@@ -606,35 +633,36 @@ const specRules = {
606
633
  },
607
634
  enum: (spec, mutableSchema) => {
608
635
  var _a, _b, _c, _d;
609
- if (spec.type === SpecTypes.Array &&
636
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Array &&
610
637
  ((_a = spec.enum) === null || _a === void 0 ? void 0 : _a.length) &&
611
638
  (((_b = spec.items) === null || _b === void 0 ? void 0 : _b.type) === SpecTypes.String || !((_c = spec.items) === null || _c === void 0 ? void 0 : _c.type))) {
612
639
  set(mutableSchema, 'items.enum', spec.enum);
613
640
  }
614
- if (spec.type === SpecTypes.String && ((_d = spec.enum) === null || _d === void 0 ? void 0 : _d.length)) {
641
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && ((_d = spec === null || spec === void 0 ? void 0 : spec.enum) === null || _d === void 0 ? void 0 : _d.length)) {
615
642
  set(mutableSchema, 'enum', spec.enum);
616
643
  }
617
644
  },
618
645
  description: (spec, mutableSchema) => {
619
- if ('description' in spec &&
646
+ if (spec &&
647
+ 'description' in spec &&
620
648
  isObject(spec.description) &&
621
649
  Object.keys(spec.description).length) {
622
650
  set(mutableSchema, 'nodeParameters.entityProps.enumDescriptions', spec.description);
623
651
  }
624
652
  },
625
653
  validator: (spec, mutableSchema) => {
626
- if (spec.validator && spec.validator !== 'base') {
654
+ if ((spec === null || spec === void 0 ? void 0 : spec.validator) && (spec === null || spec === void 0 ? void 0 : spec.validator) !== 'base') {
627
655
  set(mutableSchema, 'nodeParameters.validator', spec.validator);
628
656
  }
629
657
  },
630
658
  maximum: (spec, mutableSchema) => {
631
- if (spec.type === SpecTypes.Number && spec.maximum !== undefined) {
659
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Number && (spec === null || spec === void 0 ? void 0 : spec.maximum) !== undefined) {
632
660
  const maximum = Number(spec.maximum);
633
661
  if (!Number.isNaN(maximum)) {
634
662
  set(mutableSchema, 'maximum', maximum);
635
663
  }
636
664
  }
637
- if (spec.type === SpecTypes.String && 'maximum' in spec && spec.maximum !== undefined) {
665
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && 'maximum' in spec && (spec === null || spec === void 0 ? void 0 : spec.maximum) !== undefined) {
638
666
  const maximum = Number(spec.maximum);
639
667
  if (!Number.isNaN(maximum)) {
640
668
  set(mutableSchema, 'stringNumber.maximum', `${spec.maximum}`);
@@ -642,13 +670,13 @@ const specRules = {
642
670
  }
643
671
  },
644
672
  minimum: (spec, mutableSchema) => {
645
- if (spec.type === SpecTypes.Number && spec.minimum !== undefined) {
673
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Number && spec.minimum !== undefined) {
646
674
  const minimum = Number(spec.minimum);
647
675
  if (!Number.isNaN(minimum)) {
648
676
  set(mutableSchema, 'minimum', minimum);
649
677
  }
650
678
  }
651
- if (spec.type === SpecTypes.String && 'minimum' in spec && spec.minimum !== undefined) {
679
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && 'minimum' in spec && (spec === null || spec === void 0 ? void 0 : spec.minimum) !== undefined) {
652
680
  const minimum = Number(spec.minimum);
653
681
  if (!Number.isNaN(minimum)) {
654
682
  set(mutableSchema, 'stringNumber.minimum', `${spec.minimum}`);
@@ -656,21 +684,22 @@ const specRules = {
656
684
  }
657
685
  },
658
686
  format: (spec, mutableSchema) => {
659
- if (spec.type === SpecTypes.Number && spec.format === 'int64') {
687
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Number && spec.format === 'int64') {
660
688
  set(mutableSchema, 'type', JsonSchemaType.Integer);
661
689
  }
662
690
  },
663
691
  properties: (spec, mutableSchema, rules, errorMessages) => {
664
- if (spec.type === SpecTypes.Object && spec.properties) {
692
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.Object && spec.properties) {
665
693
  Object.entries(spec.properties).forEach(([key, childSpec]) => {
694
+ var _a, _b, _c, _d, _e;
666
695
  const childSchema = specToJsonSchema(childSpec, Object.assign({}, (get(mutableSchema, ['properties', key]) || {})), rules, errorMessages);
667
696
  set(mutableSchema, ['properties', key], childSchema);
668
697
  if (childSpec.required &&
669
- !(spec.viewSpec.type === 'oneof' ||
670
- spec.viewSpec.type === 'oneof_flat' ||
671
- spec.viewSpec.type === 'card_oneof' ||
672
- spec.viewSpec.type === 'multi_oneof' ||
673
- spec.viewSpec.type === 'multi_oneof_flat')) {
698
+ !(((_a = spec.viewSpec) === null || _a === void 0 ? void 0 : _a.type) === 'oneof' ||
699
+ ((_b = spec.viewSpec) === null || _b === void 0 ? void 0 : _b.type) === 'oneof_flat' ||
700
+ ((_c = spec.viewSpec) === null || _c === void 0 ? void 0 : _c.type) === 'card_oneof' ||
701
+ ((_d = spec.viewSpec) === null || _d === void 0 ? void 0 : _d.type) === 'multi_oneof' ||
702
+ ((_e = spec.viewSpec) === null || _e === void 0 ? void 0 : _e.type) === 'multi_oneof_flat')) {
674
703
  set(mutableSchema, ['required'], [...(get(mutableSchema, 'required') || []), key]);
675
704
  set(mutableSchema, 'nodeParameters.errorMessages.required', errorMessages.required);
676
705
  }
@@ -678,12 +707,12 @@ const specRules = {
678
707
  }
679
708
  },
680
709
  pattern: (spec, mutableSchema) => {
681
- if (spec.type === SpecTypes.String && spec.pattern) {
710
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && spec.pattern) {
682
711
  set(mutableSchema, 'pattern', spec.pattern);
683
712
  }
684
713
  },
685
714
  patternError: (spec, mutableSchema) => {
686
- if (spec.type === SpecTypes.String && spec.patternError) {
715
+ if ((spec === null || spec === void 0 ? void 0 : spec.type) === SpecTypes.String && (spec === null || spec === void 0 ? void 0 : spec.patternError)) {
687
716
  set(mutableSchema, 'nodeParameters.errorMessages.pattern', spec.patternError);
688
717
  }
689
718
  },
@@ -694,6 +723,8 @@ const specRules = {
694
723
  export function specToJsonSchema(spec, mutableSchema = {}, rules, errorMessages = {}) {
695
724
  const mergedSpecRules = Object.assign(Object.assign({}, specRules), rules === null || rules === void 0 ? void 0 : rules.specRules);
696
725
  const mergedViewSpecRules = Object.assign(Object.assign({}, viewSpecRules), rules === null || rules === void 0 ? void 0 : rules.viewSpecRules);
697
- Object.values(mergedSpecRules).forEach((rule) => rule(spec, mutableSchema, { specRules: mergedSpecRules, viewSpecRules: mergedViewSpecRules }, errorMessages));
726
+ if (spec) {
727
+ Object.values(mergedSpecRules).forEach((rule) => rule(spec, mutableSchema, { specRules: mergedSpecRules, viewSpecRules: mergedViewSpecRules }, errorMessages));
728
+ }
698
729
  return mutableSchema;
699
730
  }