@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.20
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/dist/core.umd.js +469 -360
- package/dist/{index.js → index.cjs} +640 -519
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +706 -566
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +66 -16
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +138 -59
- package/lib/components/fields/ArrayField.d.ts +17 -7
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +92 -59
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -2
- package/lib/components/fields/LayoutGridField.d.ts +27 -25
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +83 -53
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +13 -9
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +3 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +18 -25
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +17 -17
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +7 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +2 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +19 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -19
- package/src/components/Form.tsx +183 -73
- package/src/components/fields/ArrayField.tsx +99 -67
- package/src/components/fields/BooleanField.tsx +12 -3
- package/src/components/fields/LayoutGridField.tsx +95 -82
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
- package/src/components/fields/MultiSchemaField.tsx +51 -35
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +19 -36
- package/src/components/fields/SchemaField.tsx +24 -30
- package/src/components/fields/StringField.tsx +12 -3
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +3 -3
- package/src/components/templates/BaseInputTemplate.tsx +3 -3
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -5
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +21 -23
- package/src/components/widgets/CheckboxWidget.tsx +2 -2
- package/src/components/widgets/CheckboxesWidget.tsx +3 -3
- package/src/components/widgets/RadioWidget.tsx +1 -1
- package/src/components/widgets/SelectWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +1 -1
- package/src/getDefaultRegistry.ts +10 -1
- package/src/getTestRegistry.tsx +34 -0
- package/src/index.ts +2 -1
- package/dist/index.js.map +0 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, MouseEvent } from 'react';
|
|
2
|
-
import { ErrorSchema, FieldProps, FormContextType,
|
|
2
|
+
import { ErrorSchema, FieldPathId, FieldPathList, FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from '@rjsf/utils';
|
|
3
3
|
/** Type used to represent the keyed form data used in the state */
|
|
4
4
|
type KeyedFormDataType<T> = {
|
|
5
5
|
key: string;
|
|
@@ -106,9 +106,19 @@ declare class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
|
|
|
106
106
|
*
|
|
107
107
|
* @param index - The index of the item being changed
|
|
108
108
|
*/
|
|
109
|
-
onChangeForIndex: (index: number) => (value: any, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
|
|
109
|
+
onChangeForIndex: (index: number) => (value: any, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
|
|
110
110
|
/** Callback handler used to change the value for a checkbox */
|
|
111
111
|
onSelectChange: (value: any) => void;
|
|
112
|
+
/** Helper method to compute item UI schema for both normal and fixed arrays
|
|
113
|
+
* Handles both static object and dynamic function cases
|
|
114
|
+
*
|
|
115
|
+
* @param uiSchema - The parent UI schema containing items definition
|
|
116
|
+
* @param item - The item data
|
|
117
|
+
* @param index - The index of the item
|
|
118
|
+
* @param formContext - The form context
|
|
119
|
+
* @returns The computed UI schema for the item
|
|
120
|
+
*/
|
|
121
|
+
private computeItemUiSchema;
|
|
112
122
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
113
123
|
*/
|
|
114
124
|
render(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -143,8 +153,8 @@ declare class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
|
|
|
143
153
|
canMoveDown: boolean;
|
|
144
154
|
itemSchema: S;
|
|
145
155
|
itemData: T[];
|
|
146
|
-
itemUiSchema: UiSchema<T[], S, F
|
|
147
|
-
|
|
156
|
+
itemUiSchema: UiSchema<T[], S, F> | undefined;
|
|
157
|
+
itemFieldPathId: FieldPathId;
|
|
148
158
|
itemErrorSchema?: ErrorSchema<T[]>;
|
|
149
159
|
autofocus?: boolean;
|
|
150
160
|
onBlur: FieldProps<T[], S, F>['onBlur'];
|
|
@@ -154,7 +164,7 @@ declare class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
|
|
|
154
164
|
}): {
|
|
155
165
|
children: import("react/jsx-runtime").JSX.Element;
|
|
156
166
|
buttonsProps: {
|
|
157
|
-
|
|
167
|
+
fieldPathId: FieldPathId;
|
|
158
168
|
disabled: boolean | undefined;
|
|
159
169
|
readonly: boolean | undefined;
|
|
160
170
|
canAdd: boolean;
|
|
@@ -170,7 +180,7 @@ declare class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
|
|
|
170
180
|
onReorderClick: (index: number, newIndex: number) => (event: MouseEvent<HTMLButtonElement>) => void;
|
|
171
181
|
registry: import("@rjsf/utils").Registry<T[], S, F>;
|
|
172
182
|
schema: S;
|
|
173
|
-
uiSchema: UiSchema<T[], S, F
|
|
183
|
+
uiSchema: UiSchema<T[], S, F> | undefined;
|
|
174
184
|
};
|
|
175
185
|
className: string;
|
|
176
186
|
disabled: boolean | undefined;
|
|
@@ -181,7 +191,7 @@ declare class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ext
|
|
|
181
191
|
readonly: boolean | undefined;
|
|
182
192
|
registry: import("@rjsf/utils").Registry<T[], S, F>;
|
|
183
193
|
schema: S;
|
|
184
|
-
uiSchema: UiSchema<T[], S, F
|
|
194
|
+
uiSchema: UiSchema<T[], S, F> | undefined;
|
|
185
195
|
};
|
|
186
196
|
}
|
|
187
197
|
/** `ArrayField` is `React.ComponentType<FieldProps<T[], S, F>>` (necessarily) but the `registry` requires things to be a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ArrayField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"ArrayField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ArrayField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAUL,WAAW,EACX,WAAW,EACX,aAAa,EACb,UAAU,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EAEhB,QAAQ,EAET,MAAM,aAAa,CAAC;AAOrB,mEAAmE;AACnE,KAAK,iBAAiB,CAAC,CAAC,IAAI;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAErD,4DAA4D;AAC5D,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,mCAAmC;IACnC,aAAa,EAAE,iBAAiB,CAAC,CAA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,CAAC;QACxC,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC1C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB;;;;;;;;;;;;;qCAzlByB,MAAM,MACtB,OAAO,UAAU;sCAWA,MAAM,MACvB,OAAO,UAAU;sCA+CA,MAAM,MACvB,OAAO,UAAU;oCAqCF,MAAM,YAAY,MAAM,MACvC,OAAO,UAAU,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;CAklB/C;AAED;;GAEG;AACH,eAAe,UAAU,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Component } from 'react';
|
|
3
|
-
import { getTemplate, getWidget, getUiOptions, isFixedItems, allowAdditionalItems, isCustomWidget, optionsList, TranslatableString, ITEMS_KEY, } from '@rjsf/utils';
|
|
3
|
+
import { getTemplate, getWidget, getUiOptions, isFixedItems, allowAdditionalItems, isCustomWidget, optionsList, toFieldPathId, TranslatableString, ITEMS_KEY, } from '@rjsf/utils';
|
|
4
4
|
import cloneDeep from 'lodash-es/cloneDeep.js';
|
|
5
5
|
import get from 'lodash-es/get.js';
|
|
6
6
|
import isObject from 'lodash-es/isObject.js';
|
|
7
7
|
import set from 'lodash-es/set.js';
|
|
8
|
-
import
|
|
8
|
+
import uniqueId from 'lodash-es/uniqueId.js';
|
|
9
9
|
/** Used to generate a unique ID for an element in a row */
|
|
10
10
|
function generateRowId() {
|
|
11
|
-
return
|
|
11
|
+
return uniqueId('rjsf-array-item-');
|
|
12
12
|
}
|
|
13
13
|
/** Converts the `formData` into `KeyedFormDataType` data, using the `generateRowId()` function to create the key
|
|
14
14
|
*
|
|
@@ -149,7 +149,7 @@ class ArrayField extends Component {
|
|
|
149
149
|
if (event) {
|
|
150
150
|
event.preventDefault();
|
|
151
151
|
}
|
|
152
|
-
const { onChange, errorSchema } = this.props;
|
|
152
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
153
153
|
const { keyedFormData } = this.state;
|
|
154
154
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
155
155
|
let newErrorSchema;
|
|
@@ -179,7 +179,9 @@ class ArrayField extends Component {
|
|
|
179
179
|
this.setState({
|
|
180
180
|
keyedFormData: newKeyedFormData,
|
|
181
181
|
updatedKeyedFormData: true,
|
|
182
|
-
},
|
|
182
|
+
},
|
|
183
|
+
// add click will pass the empty `path` array to the onChange which adds the appropriate path
|
|
184
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema));
|
|
183
185
|
}
|
|
184
186
|
/** Callback handler for when the user clicks on the add button. Creates a new row of keyed form data at the end of
|
|
185
187
|
* the list, adding it into the state, and then returning `onChange()` with the plain form data converted from the
|
|
@@ -212,7 +214,7 @@ class ArrayField extends Component {
|
|
|
212
214
|
if (event) {
|
|
213
215
|
event.preventDefault();
|
|
214
216
|
}
|
|
215
|
-
const { onChange, errorSchema } = this.props;
|
|
217
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
216
218
|
const { keyedFormData } = this.state;
|
|
217
219
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
218
220
|
let newErrorSchema;
|
|
@@ -242,7 +244,7 @@ class ArrayField extends Component {
|
|
|
242
244
|
this.setState({
|
|
243
245
|
keyedFormData: newKeyedFormData,
|
|
244
246
|
updatedKeyedFormData: true,
|
|
245
|
-
}, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
|
|
247
|
+
}, () => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema));
|
|
246
248
|
};
|
|
247
249
|
};
|
|
248
250
|
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
@@ -256,7 +258,7 @@ class ArrayField extends Component {
|
|
|
256
258
|
if (event) {
|
|
257
259
|
event.preventDefault();
|
|
258
260
|
}
|
|
259
|
-
const { onChange, errorSchema } = this.props;
|
|
261
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
260
262
|
const { keyedFormData } = this.state;
|
|
261
263
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
262
264
|
let newErrorSchema;
|
|
@@ -276,7 +278,7 @@ class ArrayField extends Component {
|
|
|
276
278
|
this.setState({
|
|
277
279
|
keyedFormData: newKeyedFormData,
|
|
278
280
|
updatedKeyedFormData: true,
|
|
279
|
-
}, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
|
|
281
|
+
}, () => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema));
|
|
280
282
|
};
|
|
281
283
|
};
|
|
282
284
|
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
@@ -292,7 +294,7 @@ class ArrayField extends Component {
|
|
|
292
294
|
event.preventDefault();
|
|
293
295
|
event.currentTarget.blur();
|
|
294
296
|
}
|
|
295
|
-
const { onChange, errorSchema } = this.props;
|
|
297
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
296
298
|
let newErrorSchema;
|
|
297
299
|
if (errorSchema) {
|
|
298
300
|
newErrorSchema = {};
|
|
@@ -321,7 +323,7 @@ class ArrayField extends Component {
|
|
|
321
323
|
const newKeyedFormData = reOrderArray();
|
|
322
324
|
this.setState({
|
|
323
325
|
keyedFormData: newKeyedFormData,
|
|
324
|
-
}, () => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema));
|
|
326
|
+
}, () => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema));
|
|
325
327
|
};
|
|
326
328
|
};
|
|
327
329
|
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
@@ -330,36 +332,58 @@ class ArrayField extends Component {
|
|
|
330
332
|
* @param index - The index of the item being changed
|
|
331
333
|
*/
|
|
332
334
|
onChangeForIndex = (index) => {
|
|
333
|
-
return (value, newErrorSchema, id) => {
|
|
334
|
-
const {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const jsonValue = typeof value === 'undefined' ? null : value;
|
|
340
|
-
return index === i ? jsonValue : item;
|
|
341
|
-
});
|
|
342
|
-
onChange(newFormData, errorSchema &&
|
|
343
|
-
errorSchema && {
|
|
344
|
-
...errorSchema,
|
|
345
|
-
[index]: newErrorSchema,
|
|
346
|
-
}, id);
|
|
335
|
+
return (value, path, newErrorSchema, id) => {
|
|
336
|
+
const { onChange } = this.props;
|
|
337
|
+
onChange(
|
|
338
|
+
// We need to treat undefined items as nulls to have validation.
|
|
339
|
+
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
340
|
+
value === undefined ? null : value, path, newErrorSchema, id);
|
|
347
341
|
};
|
|
348
342
|
};
|
|
349
343
|
/** Callback handler used to change the value for a checkbox */
|
|
350
344
|
onSelectChange = (value) => {
|
|
351
|
-
const { onChange,
|
|
352
|
-
|
|
345
|
+
const { onChange, fieldPathId } = this.props;
|
|
346
|
+
// select change will pass an empty `path` array since the `ObjectField` will add the path value automatically
|
|
347
|
+
onChange(value, fieldPathId.path, undefined, fieldPathId && fieldPathId.$id);
|
|
353
348
|
};
|
|
349
|
+
/** Helper method to compute item UI schema for both normal and fixed arrays
|
|
350
|
+
* Handles both static object and dynamic function cases
|
|
351
|
+
*
|
|
352
|
+
* @param uiSchema - The parent UI schema containing items definition
|
|
353
|
+
* @param item - The item data
|
|
354
|
+
* @param index - The index of the item
|
|
355
|
+
* @param formContext - The form context
|
|
356
|
+
* @returns The computed UI schema for the item
|
|
357
|
+
*/
|
|
358
|
+
computeItemUiSchema(uiSchema, item, index, formContext) {
|
|
359
|
+
if (typeof uiSchema.items === 'function') {
|
|
360
|
+
try {
|
|
361
|
+
// Call the function with item data, index, and form context
|
|
362
|
+
// TypeScript now correctly infers the types thanks to the ArrayElement type in UiSchema
|
|
363
|
+
const result = uiSchema.items(item, index, formContext);
|
|
364
|
+
// Only use the result if it's truthy
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
catch (e) {
|
|
368
|
+
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
369
|
+
// Fall back to undefined to allow the field to still render
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
// Static object case - preserve undefined to maintain backward compatibility
|
|
375
|
+
return uiSchema.items;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
354
378
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
355
379
|
*/
|
|
356
380
|
render() {
|
|
357
|
-
const { schema, uiSchema,
|
|
381
|
+
const { schema, uiSchema, fieldPathId, registry } = this.props;
|
|
358
382
|
const { schemaUtils, translateString } = registry;
|
|
359
383
|
if (!(ITEMS_KEY in schema)) {
|
|
360
384
|
const uiOptions = getUiOptions(uiSchema);
|
|
361
385
|
const UnsupportedFieldTemplate = getTemplate('UnsupportedFieldTemplate', registry, uiOptions);
|
|
362
|
-
return (_jsx(UnsupportedFieldTemplate, { schema: schema,
|
|
386
|
+
return (_jsx(UnsupportedFieldTemplate, { schema: schema, fieldPathId: fieldPathId, reason: translateString(TranslatableString.MissingItems), registry: registry }));
|
|
363
387
|
}
|
|
364
388
|
if (schemaUtils.isMultiSelect(schema)) {
|
|
365
389
|
// If array has enum or uniqueItems set to true, call renderMultiSelect() to render the default multiselect widget or a custom widget, if specified.
|
|
@@ -379,10 +403,10 @@ class ArrayField extends Component {
|
|
|
379
403
|
/** Renders a normal array without any limitations of length
|
|
380
404
|
*/
|
|
381
405
|
renderNormalArray() {
|
|
382
|
-
const { schema, uiSchema = {}, errorSchema,
|
|
406
|
+
const { schema, uiSchema = {}, errorSchema, fieldPathId, name, title, disabled = false, readonly = false, autofocus = false, required = false, registry, onBlur, onFocus, rawErrors, } = this.props;
|
|
383
407
|
const { keyedFormData } = this.state;
|
|
384
408
|
const fieldTitle = schema.title || title || name;
|
|
385
|
-
const { schemaUtils, formContext } = registry;
|
|
409
|
+
const { schemaUtils, formContext, globalFormOptions } = registry;
|
|
386
410
|
const uiOptions = getUiOptions(uiSchema);
|
|
387
411
|
const _schemaItems = isObject(schema.items) ? schema.items : {};
|
|
388
412
|
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
|
|
@@ -396,8 +420,9 @@ class ArrayField extends Component {
|
|
|
396
420
|
const itemCast = item;
|
|
397
421
|
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
398
422
|
const itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
|
|
399
|
-
const
|
|
400
|
-
|
|
423
|
+
const itemFieldPathId = toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
424
|
+
// Compute the item UI schema using the helper method
|
|
425
|
+
const itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
401
426
|
return this.renderArrayFieldItem({
|
|
402
427
|
key,
|
|
403
428
|
index,
|
|
@@ -407,10 +432,10 @@ class ArrayField extends Component {
|
|
|
407
432
|
canMoveUp: index > 0,
|
|
408
433
|
canMoveDown: index < formData.length - 1,
|
|
409
434
|
itemSchema,
|
|
410
|
-
|
|
435
|
+
itemFieldPathId,
|
|
411
436
|
itemErrorSchema,
|
|
412
437
|
itemData: itemCast,
|
|
413
|
-
itemUiSchema
|
|
438
|
+
itemUiSchema,
|
|
414
439
|
autofocus: autofocus && index === 0,
|
|
415
440
|
onBlur,
|
|
416
441
|
onFocus,
|
|
@@ -420,14 +445,13 @@ class ArrayField extends Component {
|
|
|
420
445
|
}),
|
|
421
446
|
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}`,
|
|
422
447
|
disabled,
|
|
423
|
-
|
|
448
|
+
fieldPathId,
|
|
424
449
|
uiSchema,
|
|
425
450
|
onAddClick: this.onAddClick,
|
|
426
451
|
readonly,
|
|
427
452
|
required,
|
|
428
453
|
schema,
|
|
429
454
|
title: fieldTitle,
|
|
430
|
-
formContext,
|
|
431
455
|
formData,
|
|
432
456
|
rawErrors,
|
|
433
457
|
registry,
|
|
@@ -438,18 +462,18 @@ class ArrayField extends Component {
|
|
|
438
462
|
/** Renders an array using the custom widget provided by the user in the `uiSchema`
|
|
439
463
|
*/
|
|
440
464
|
renderCustomWidget() {
|
|
441
|
-
const { schema,
|
|
465
|
+
const { schema, fieldPathId, uiSchema, disabled = false, readonly = false, autofocus = false, required = false, hideError, placeholder, onBlur, onFocus, formData: items = [], registry, rawErrors, name, } = this.props;
|
|
442
466
|
const { widgets, formContext, globalUiOptions, schemaUtils } = registry;
|
|
443
467
|
const { widget, title: uiTitle, ...options } = getUiOptions(uiSchema, globalUiOptions);
|
|
444
468
|
const Widget = getWidget(schema, widget, widgets);
|
|
445
469
|
const label = uiTitle ?? schema.title ?? name;
|
|
446
470
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
447
|
-
return (_jsx(Widget, { id:
|
|
471
|
+
return (_jsx(Widget, { id: fieldPathId.$id, name: name, multiple: true, onChange: this.onSelectChange, onBlur: onBlur, onFocus: onFocus, options: options, schema: schema, uiSchema: uiSchema, registry: registry, value: items, disabled: disabled, readonly: readonly, hideError: hideError, required: required, label: label, hideLabel: !displayLabel, placeholder: placeholder, formContext: formContext, autofocus: autofocus, rawErrors: rawErrors }));
|
|
448
472
|
}
|
|
449
473
|
/** Renders an array as a set of checkboxes
|
|
450
474
|
*/
|
|
451
475
|
renderMultiSelect() {
|
|
452
|
-
const { schema,
|
|
476
|
+
const { schema, fieldPathId, uiSchema, formData: items = [], disabled = false, readonly = false, autofocus = false, required = false, placeholder, onBlur, onFocus, registry, rawErrors, name, } = this.props;
|
|
453
477
|
const { widgets, schemaUtils, formContext, globalUiOptions } = registry;
|
|
454
478
|
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
|
|
455
479
|
const enumOptions = optionsList(itemsSchema, uiSchema);
|
|
@@ -457,28 +481,28 @@ class ArrayField extends Component {
|
|
|
457
481
|
const Widget = getWidget(schema, widget, widgets);
|
|
458
482
|
const label = uiTitle ?? schema.title ?? name;
|
|
459
483
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
460
|
-
return (_jsx(Widget, { id:
|
|
484
|
+
return (_jsx(Widget, { id: fieldPathId.$id, name: name, multiple: true, onChange: this.onSelectChange, onBlur: onBlur, onFocus: onFocus, options: { ...options, enumOptions }, schema: schema, uiSchema: uiSchema, registry: registry, value: items, disabled: disabled, readonly: readonly, required: required, label: label, hideLabel: !displayLabel, placeholder: placeholder, formContext: formContext, autofocus: autofocus, rawErrors: rawErrors }));
|
|
461
485
|
}
|
|
462
486
|
/** Renders an array of files using the `FileWidget`
|
|
463
487
|
*/
|
|
464
488
|
renderFiles() {
|
|
465
|
-
const { schema, uiSchema,
|
|
489
|
+
const { schema, uiSchema, fieldPathId, name, disabled = false, readonly = false, autofocus = false, required = false, onBlur, onFocus, registry, formData: items = [], rawErrors, } = this.props;
|
|
466
490
|
const { widgets, formContext, globalUiOptions, schemaUtils } = registry;
|
|
467
491
|
const { widget = 'files', title: uiTitle, ...options } = getUiOptions(uiSchema, globalUiOptions);
|
|
468
492
|
const Widget = getWidget(schema, widget, widgets);
|
|
469
493
|
const label = uiTitle ?? schema.title ?? name;
|
|
470
494
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
471
|
-
return (_jsx(Widget, { options: options, id:
|
|
495
|
+
return (_jsx(Widget, { options: options, id: fieldPathId.$id, name: name, multiple: true, onChange: this.onSelectChange, onBlur: onBlur, onFocus: onFocus, schema: schema, uiSchema: uiSchema, value: items, disabled: disabled, readonly: readonly, required: required, registry: registry, formContext: formContext, autofocus: autofocus, rawErrors: rawErrors, label: label, hideLabel: !displayLabel }));
|
|
472
496
|
}
|
|
473
497
|
/** Renders an array that has a maximum limit of items
|
|
474
498
|
*/
|
|
475
499
|
renderFixedArray() {
|
|
476
|
-
const { schema, uiSchema = {}, formData = [], errorSchema,
|
|
500
|
+
const { schema, uiSchema = {}, formData = [], errorSchema, fieldPathId, name, title, disabled = false, readonly = false, autofocus = false, required = false, registry, onBlur, onFocus, rawErrors, } = this.props;
|
|
477
501
|
const { keyedFormData } = this.state;
|
|
478
502
|
let { formData: items = [] } = this.props;
|
|
479
503
|
const fieldTitle = schema.title || title || name;
|
|
480
504
|
const uiOptions = getUiOptions(uiSchema);
|
|
481
|
-
const { schemaUtils, formContext } = registry;
|
|
505
|
+
const { schemaUtils, formContext, globalFormOptions } = registry;
|
|
482
506
|
const _schemaItems = isObject(schema.items) ? schema.items : [];
|
|
483
507
|
const itemSchemas = _schemaItems.map((item, index) => schemaUtils.retrieveSchema(item, formData[index]));
|
|
484
508
|
const additionalSchema = isObject(schema.additionalItems)
|
|
@@ -495,7 +519,7 @@ class ArrayField extends Component {
|
|
|
495
519
|
canAdd,
|
|
496
520
|
className: 'rjsf-field rjsf-field-array rjsf-field-array-fixed-items',
|
|
497
521
|
disabled,
|
|
498
|
-
|
|
522
|
+
fieldPathId,
|
|
499
523
|
formData,
|
|
500
524
|
items: keyedFormData.map((keyedItem, index) => {
|
|
501
525
|
const { key, item } = keyedItem;
|
|
@@ -505,13 +529,23 @@ class ArrayField extends Component {
|
|
|
505
529
|
const itemSchema = (additional && isObject(schema.additionalItems)
|
|
506
530
|
? schemaUtils.retrieveSchema(schema.additionalItems, itemCast)
|
|
507
531
|
: itemSchemas[index]) || {};
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
532
|
+
const itemFieldPathId = toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
533
|
+
// Compute the item UI schema - handle both static and dynamic cases
|
|
534
|
+
let itemUiSchema;
|
|
535
|
+
if (additional) {
|
|
536
|
+
// For additional items, use additionalItems uiSchema
|
|
537
|
+
itemUiSchema = uiSchema.additionalItems;
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
// For fixed items, uiSchema.items can be an array, a function, or a single object
|
|
541
|
+
if (Array.isArray(uiSchema.items)) {
|
|
542
|
+
itemUiSchema = uiSchema.items[index];
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
// Use the helper method for function or static object cases
|
|
546
|
+
itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
515
549
|
const itemErrorSchema = errorSchema ? errorSchema[index] : undefined;
|
|
516
550
|
return this.renderArrayFieldItem({
|
|
517
551
|
key,
|
|
@@ -525,7 +559,7 @@ class ArrayField extends Component {
|
|
|
525
559
|
itemSchema,
|
|
526
560
|
itemData: itemCast,
|
|
527
561
|
itemUiSchema,
|
|
528
|
-
|
|
562
|
+
itemFieldPathId,
|
|
529
563
|
itemErrorSchema,
|
|
530
564
|
autofocus: autofocus && index === 0,
|
|
531
565
|
onBlur,
|
|
@@ -541,7 +575,6 @@ class ArrayField extends Component {
|
|
|
541
575
|
schema,
|
|
542
576
|
uiSchema,
|
|
543
577
|
title: fieldTitle,
|
|
544
|
-
formContext,
|
|
545
578
|
errorSchema,
|
|
546
579
|
rawErrors,
|
|
547
580
|
};
|
|
@@ -554,8 +587,8 @@ class ArrayField extends Component {
|
|
|
554
587
|
* @param props - The props for the individual array item to be rendered
|
|
555
588
|
*/
|
|
556
589
|
renderArrayFieldItem(props) {
|
|
557
|
-
const { key, index, name, canAdd, canRemove = true, canMoveUp, canMoveDown, itemSchema, itemData, itemUiSchema,
|
|
558
|
-
const { disabled, hideError,
|
|
590
|
+
const { key, index, name, canAdd, canRemove = true, canMoveUp, canMoveDown, itemSchema, itemData, itemUiSchema, itemFieldPathId, itemErrorSchema, autofocus, onBlur, onFocus, rawErrors, totalItems, title, } = props;
|
|
591
|
+
const { disabled, hideError, readonly, uiSchema, registry, formContext } = this.props;
|
|
559
592
|
const { fields: { ArraySchemaField, SchemaField }, globalUiOptions, } = registry;
|
|
560
593
|
const ItemSchemaField = ArraySchemaField || SchemaField;
|
|
561
594
|
const { orderable = true, removable = true, copyable = false } = getUiOptions(uiSchema, globalUiOptions);
|
|
@@ -568,9 +601,9 @@ class ArrayField extends Component {
|
|
|
568
601
|
};
|
|
569
602
|
has.toolbar = Object.keys(has).some((key) => has[key]);
|
|
570
603
|
return {
|
|
571
|
-
children: (_jsx(ItemSchemaField, { name: name, title: title, index: index, schema: itemSchema, uiSchema: itemUiSchema, formData: itemData, formContext: formContext, errorSchema: itemErrorSchema,
|
|
604
|
+
children: (_jsx(ItemSchemaField, { name: name, title: title, index: index, schema: itemSchema, uiSchema: itemUiSchema, formData: itemData, formContext: formContext, errorSchema: itemErrorSchema, fieldPathId: itemFieldPathId, required: this.isItemRequired(itemSchema), onChange: this.onChangeForIndex(index), onBlur: onBlur, onFocus: onFocus, registry: registry, disabled: disabled, readonly: readonly, hideError: hideError, autofocus: autofocus, rawErrors: rawErrors })),
|
|
572
605
|
buttonsProps: {
|
|
573
|
-
|
|
606
|
+
fieldPathId: itemFieldPathId,
|
|
574
607
|
disabled: disabled,
|
|
575
608
|
readonly: readonly,
|
|
576
609
|
canAdd,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/BooleanField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BooleanField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/BooleanField.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,eAAe,EAGf,UAAU,EACV,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAGrB;;;;GAIG;AACH,iBAAS,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACrG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAoG3B;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
2
3
|
import { getWidget, getUiOptions, optionsList, TranslatableString, } from '@rjsf/utils';
|
|
3
4
|
import isObject from 'lodash-es/isObject.js';
|
|
4
5
|
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
@@ -7,7 +8,7 @@ import isObject from 'lodash-es/isObject.js';
|
|
|
7
8
|
* @param props - The `FieldProps` for this template
|
|
8
9
|
*/
|
|
9
10
|
function BooleanField(props) {
|
|
10
|
-
const { schema, name, uiSchema,
|
|
11
|
+
const { schema, name, uiSchema, fieldPathId, formData, registry, required, disabled, readonly, hideError, autofocus, title, onChange, onFocus, onBlur, rawErrors, } = props;
|
|
11
12
|
const { title: schemaTitle } = schema;
|
|
12
13
|
const { widgets, formContext, translateString, globalUiOptions } = registry;
|
|
13
14
|
const { widget = 'checkbox', title: uiTitle,
|
|
@@ -51,6 +52,10 @@ function BooleanField(props) {
|
|
|
51
52
|
enumOptions = optionsList({ enum: enums }, uiSchema);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
const onWidgetChange = useCallback((value, errorSchema, id) => {
|
|
56
|
+
// Boolean field change passes an empty path array to the parent field which adds the appropriate path
|
|
57
|
+
return onChange(value, fieldPathId.path, errorSchema, id);
|
|
58
|
+
}, [onChange, fieldPathId]);
|
|
59
|
+
return (_jsx(Widget, { options: { ...options, enumOptions }, schema: schema, uiSchema: uiSchema, id: fieldPathId.$id, name: name, onChange: onWidgetChange, onFocus: onFocus, onBlur: onBlur, label: label, hideLabel: !displayLabel, value: formData, required: required, disabled: disabled, readonly: readonly, hideError: hideError, registry: registry, formContext: formContext, autofocus: autofocus, rawErrors: rawErrors }));
|
|
55
60
|
}
|
|
56
61
|
export default BooleanField;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType, PureComponent, ReactNode } from 'react';
|
|
2
|
-
import { ErrorSchema, FieldProps, FormContextType, GenericObjectType,
|
|
2
|
+
import { ErrorSchema, FieldProps, FieldPathId, FieldPathList, FormContextType, GenericObjectType, RJSFSchema, Registry, StrictRJSFSchema, UiSchema } from '@rjsf/utils';
|
|
3
3
|
/** The enumeration of the three different Layout GridTemplate type values
|
|
4
4
|
*/
|
|
5
5
|
export declare enum GridType {
|
|
@@ -48,9 +48,6 @@ export declare const LAYOUT_GRID_UI_OPTION = "layoutGrid";
|
|
|
48
48
|
/** The constant representing the main layout grid schema option name in the `uiSchema`
|
|
49
49
|
*/
|
|
50
50
|
export declare const LAYOUT_GRID_OPTION = "ui:layoutGrid";
|
|
51
|
-
/** The constant representing the global UI Options object potentially contained within the `uiSchema`
|
|
52
|
-
*/
|
|
53
|
-
export declare const UI_GLOBAL_OPTIONS = "ui:global_options";
|
|
54
51
|
/** Type used to return options list and whether it has a discriminator */
|
|
55
52
|
type OneOfOptionsInfoType<S extends StrictRJSFSchema = RJSFSchema> = {
|
|
56
53
|
options: S[];
|
|
@@ -345,37 +342,42 @@ export default class LayoutGridField<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
345
342
|
children: LayoutGridSchemaType[];
|
|
346
343
|
gridProps: GridProps;
|
|
347
344
|
};
|
|
348
|
-
/**
|
|
349
|
-
*
|
|
345
|
+
/** Computes the `rawSchema` and `fieldPathId` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
|
|
346
|
+
* has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
|
|
347
|
+
* to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
|
|
348
|
+
* otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
|
|
349
|
+
* either case, an `fieldPathId` is computed for the array index. If the `schema` does not represent an array or the
|
|
350
|
+
* `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `fieldPathId` is returned
|
|
351
|
+
* as is.
|
|
350
352
|
*
|
|
351
|
-
* @param
|
|
352
|
-
* @param
|
|
353
|
-
* @param
|
|
354
|
-
* @
|
|
355
|
-
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
356
|
-
* @returns - The generated `idSchema` for the `schema`
|
|
353
|
+
* @param schema - The schema to generate the fieldPathId for
|
|
354
|
+
* @param fieldPathId - The FieldPathId for the schema
|
|
355
|
+
* @param potentialIndex - A string containing a potential index
|
|
356
|
+
* @returns - An object containing the `rawSchema` and `fieldPathId` of an array item, otherwise an undefined `rawSchema`
|
|
357
357
|
*/
|
|
358
|
-
static
|
|
358
|
+
static computeArraySchemasIfPresent<S extends StrictRJSFSchema = RJSFSchema>(schema: S | undefined, fieldPathId: FieldPathId, potentialIndex: string): {
|
|
359
|
+
rawSchema?: S;
|
|
360
|
+
fieldPathId: FieldPathId;
|
|
361
|
+
};
|
|
359
362
|
/** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
|
|
360
363
|
* the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
|
|
361
364
|
* element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
|
|
362
365
|
* `options`.
|
|
363
366
|
*
|
|
364
|
-
* @param
|
|
367
|
+
* @param registry - The registry
|
|
365
368
|
* @param dottedPath - The dotted-path to the field for which to get the schema
|
|
366
369
|
* @param initialSchema - The initial schema to start the search from
|
|
367
370
|
* @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
|
|
368
|
-
* @param
|
|
369
|
-
* @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
|
|
371
|
+
* @param initialFieldIdPath - The initial fieldPathId to start the search from
|
|
370
372
|
* @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
|
|
371
373
|
* info if a oneOf/anyOf
|
|
372
374
|
*/
|
|
373
|
-
static getSchemaDetailsForField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
375
|
+
static getSchemaDetailsForField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(registry: Registry<T, S, F>, dottedPath: string, initialSchema: S, formData: FieldProps<T, S, F>['formData'], initialFieldIdPath: FieldPathId): {
|
|
374
376
|
schema?: S;
|
|
375
377
|
isRequired: boolean;
|
|
376
378
|
isReadonly?: boolean;
|
|
377
379
|
optionsInfo?: OneOfOptionsInfoType<S>;
|
|
378
|
-
|
|
380
|
+
fieldPathId: FieldPathId;
|
|
379
381
|
};
|
|
380
382
|
/** Gets the custom render component from the `render`, by either determining that it is either already a function or
|
|
381
383
|
* it is a non-function value that can be used to look up the function in the registry. If no function can be found,
|
|
@@ -405,9 +407,9 @@ export default class LayoutGridField<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
405
407
|
* elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
|
|
406
408
|
*
|
|
407
409
|
* @param dottedPath - The dotted-path to the field for which to generate the onChange handler
|
|
408
|
-
* @returns - The `onChange` handling function for the `dottedPath` field
|
|
410
|
+
* @returns - The `onChange` handling function for the `dottedPath` field of the `schemaType` type
|
|
409
411
|
*/
|
|
410
|
-
onFieldChange: (dottedPath: string) => (value:
|
|
412
|
+
onFieldChange: (dottedPath: string) => (value: T | undefined, path: FieldPathList, errSchema?: ErrorSchema<T>, id?: string) => void;
|
|
411
413
|
/** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
|
|
412
414
|
* `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
|
|
413
415
|
* the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
|
|
@@ -441,23 +443,23 @@ export default class LayoutGridField<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
441
443
|
* @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
|
|
442
444
|
*/
|
|
443
445
|
renderRow(layoutGridSchema: GridSchemaType): import("react/jsx-runtime").JSX.Element;
|
|
444
|
-
/** Iterates through all the `
|
|
446
|
+
/** Iterates through all the `childrenLayoutGrfieldPathId`, rendering a nested `LayoutGridField` for each item in the
|
|
445
447
|
* list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
|
|
446
448
|
* `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
|
|
447
|
-
* `
|
|
449
|
+
* `childrenLayoutGrfieldPathId` is passed as `layoutGridSchema`.
|
|
448
450
|
*
|
|
449
|
-
* @param
|
|
451
|
+
* @param childrenLayoutGrfieldPathId - The list of strings or objects that represents the configurations for the
|
|
450
452
|
* children fields
|
|
451
453
|
* @returns - The nested `LayoutGridField`s
|
|
452
454
|
*/
|
|
453
|
-
renderChildren(
|
|
455
|
+
renderChildren(childrenLayoutGrfieldPathId: LayoutGridSchemaType[]): import("react/jsx-runtime").JSX.Element[];
|
|
454
456
|
/** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
|
|
455
457
|
* to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
|
|
456
458
|
* other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
|
|
457
459
|
* specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
|
|
458
460
|
* and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
|
|
459
461
|
* schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
|
|
460
|
-
* `uiSchema`, `errorSchema`, `
|
|
462
|
+
* `uiSchema`, `errorSchema`, `fieldPathId` and `formData` drilled down to the dotted-path field, spreading any other
|
|
461
463
|
* props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
|
|
462
464
|
* then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
|
|
463
465
|
* schema was located, but a custom render component was found, then it will be rendered with many of the non-event
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutGridField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutGridField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAEL,WAAW,EACX,UAAU,EACV,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"LayoutGridField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutGridField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAEL,WAAW,EACX,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,EAWjB,UAAU,EACV,QAAQ,EACR,gBAAgB,EAIhB,QAAQ,EAET,MAAM,aAAa,CAAC;AAkBrB;GACG;AACH,oBAAY,QAAQ;IAClB,GAAG,WAAW;IACd,MAAM,WAAW;IACjB,OAAO,eAAe;IACtB,SAAS,iBAAiB;CAC3B;AAED;GACG;AACH,oBAAY,SAAS;IACnB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,8DAA8D;AAC9D,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExC,MAAM,WAAW,SAAU,SAAQ,iBAAiB;IAClD;OACG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;OACG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;OACG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG;KAG1B,QAAQ,IAAI,QAAQ,CAAC,CAAC,EAAE,MAAM;CAChC,CAAC;AAEF;GACG;AACH,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG,YAAY,GAAG,MAAM,CAAC;AAE1E,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,C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