@rjsf/core 6.0.0-beta.21 → 6.0.0-beta.23

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 (110) hide show
  1. package/dist/core.umd.js +1580 -1771
  2. package/dist/index.cjs +2019 -2206
  3. package/dist/index.cjs.map +4 -4
  4. package/dist/index.esm.js +2011 -2182
  5. package/dist/index.esm.js.map +4 -4
  6. package/lib/components/Form.d.ts +50 -12
  7. package/lib/components/Form.d.ts.map +1 -1
  8. package/lib/components/Form.js +114 -31
  9. package/lib/components/fields/ArrayField.d.ts +2 -197
  10. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  11. package/lib/components/fields/ArrayField.js +518 -536
  12. package/lib/components/fields/BooleanField.js +2 -2
  13. package/lib/components/fields/FallbackField.d.ts +7 -0
  14. package/lib/components/fields/FallbackField.d.ts.map +1 -0
  15. package/lib/components/fields/FallbackField.js +72 -0
  16. package/lib/components/fields/LayoutGridField.d.ts +109 -191
  17. package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
  18. package/lib/components/fields/LayoutGridField.js +417 -444
  19. package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
  20. package/lib/components/fields/LayoutMultiSchemaField.js +2 -3
  21. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
  22. package/lib/components/fields/MultiSchemaField.js +5 -3
  23. package/lib/components/fields/ObjectField.d.ts +2 -68
  24. package/lib/components/fields/ObjectField.d.ts.map +1 -1
  25. package/lib/components/fields/ObjectField.js +166 -168
  26. package/lib/components/fields/SchemaField.d.ts.map +1 -1
  27. package/lib/components/fields/SchemaField.js +35 -22
  28. package/lib/components/fields/StringField.js +2 -2
  29. package/lib/components/fields/index.d.ts.map +1 -1
  30. package/lib/components/fields/index.js +2 -0
  31. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +3 -3
  32. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
  33. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +3 -8
  34. package/lib/components/templates/ArrayFieldItemTemplate.d.ts +3 -3
  35. package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
  36. package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
  37. package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
  38. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
  39. package/lib/components/templates/ArrayFieldTemplate.js +2 -4
  40. package/lib/components/templates/BaseInputTemplate.js +2 -2
  41. package/lib/components/templates/FallbackFieldTemplate.d.ts +7 -0
  42. package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -0
  43. package/lib/components/templates/FallbackFieldTemplate.js +12 -0
  44. package/lib/components/templates/ObjectFieldTemplate.js +2 -2
  45. package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
  46. package/lib/components/templates/index.d.ts.map +1 -1
  47. package/lib/components/templates/index.js +2 -0
  48. package/lib/components/widgets/AltDateWidget.d.ts +1 -1
  49. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
  50. package/lib/components/widgets/AltDateWidget.js +5 -43
  51. package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
  52. package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
  53. package/lib/components/widgets/CheckboxWidget.js +2 -2
  54. package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
  55. package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
  56. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  57. package/lib/components/widgets/FileWidget.d.ts.map +1 -1
  58. package/lib/components/widgets/FileWidget.js +7 -87
  59. package/lib/components/widgets/HiddenWidget.d.ts +1 -1
  60. package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
  61. package/lib/components/widgets/HiddenWidget.js +2 -2
  62. package/lib/components/widgets/RadioWidget.d.ts +1 -1
  63. package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
  64. package/lib/components/widgets/RadioWidget.js +2 -2
  65. package/lib/components/widgets/RatingWidget.d.ts +1 -1
  66. package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
  67. package/lib/components/widgets/RatingWidget.js +2 -2
  68. package/lib/components/widgets/SelectWidget.d.ts +1 -1
  69. package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
  70. package/lib/components/widgets/SelectWidget.js +2 -2
  71. package/lib/components/widgets/TextareaWidget.d.ts +1 -1
  72. package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
  73. package/lib/components/widgets/TextareaWidget.js +2 -2
  74. package/lib/getDefaultRegistry.d.ts.map +1 -1
  75. package/lib/getDefaultRegistry.js +5 -1
  76. package/lib/getTestRegistry.d.ts.map +1 -1
  77. package/lib/getTestRegistry.js +5 -1
  78. package/lib/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +21 -5
  80. package/src/components/Form.tsx +176 -43
  81. package/src/components/fields/ArrayField.tsx +849 -758
  82. package/src/components/fields/BooleanField.tsx +2 -2
  83. package/src/components/fields/FallbackField.tsx +157 -0
  84. package/src/components/fields/LayoutGridField.tsx +613 -600
  85. package/src/components/fields/LayoutMultiSchemaField.tsx +4 -5
  86. package/src/components/fields/MultiSchemaField.tsx +30 -25
  87. package/src/components/fields/ObjectField.tsx +315 -242
  88. package/src/components/fields/OptionalDataControlsField.tsx +1 -1
  89. package/src/components/fields/SchemaField.tsx +46 -70
  90. package/src/components/fields/StringField.tsx +2 -2
  91. package/src/components/fields/index.ts +2 -0
  92. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +11 -16
  93. package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -3
  94. package/src/components/templates/ArrayFieldTemplate.tsx +2 -13
  95. package/src/components/templates/BaseInputTemplate.tsx +2 -2
  96. package/src/components/templates/FallbackFieldTemplate.tsx +28 -0
  97. package/src/components/templates/ObjectFieldTemplate.tsx +2 -2
  98. package/src/components/templates/WrapIfAdditionalTemplate.tsx +4 -4
  99. package/src/components/templates/index.ts +2 -0
  100. package/src/components/widgets/AltDateWidget.tsx +8 -124
  101. package/src/components/widgets/CheckboxWidget.tsx +2 -1
  102. package/src/components/widgets/CheckboxesWidget.tsx +2 -1
  103. package/src/components/widgets/FileWidget.tsx +11 -102
  104. package/src/components/widgets/HiddenWidget.tsx +2 -1
  105. package/src/components/widgets/RadioWidget.tsx +2 -1
  106. package/src/components/widgets/RatingWidget.tsx +2 -1
  107. package/src/components/widgets/SelectWidget.tsx +2 -1
  108. package/src/components/widgets/TextareaWidget.tsx +2 -1
  109. package/src/getDefaultRegistry.ts +5 -1
  110. package/src/getTestRegistry.tsx +5 -1
@@ -1,10 +1,8 @@
1
- import { ComponentType, PureComponent, ReactNode } from 'react';
1
+ import { ComponentType, ReactNode } from 'react';
2
2
  import {
3
3
  ANY_OF_KEY,
4
- ErrorSchema,
5
4
  FieldProps,
6
5
  FieldPathId,
7
- FieldPathList,
8
6
  FormContextType,
9
7
  GenericObjectType,
10
8
  getDiscriminatorFieldFromSchema,
@@ -25,6 +23,7 @@ import {
25
23
  UI_GLOBAL_OPTIONS_KEY,
26
24
  UiSchema,
27
25
  ITEMS_KEY,
26
+ useDeepCompareMemo,
28
27
  } from '@rjsf/utils';
29
28
  import each from 'lodash/each';
30
29
  import flatten from 'lodash/flatten';
@@ -140,6 +139,594 @@ function isNumericIndex(str: string) {
140
139
  return /^\d+?$/.test(str); // Matches positive integers
141
140
  }
142
141
 
142
+ const LAYOUT_GRID_FIELD_TEST_IDS = getTestIds();
143
+
144
+ /** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
145
+ * will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
146
+ * copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
147
+ * updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
148
+ * the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
149
+ * field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
150
+ *
151
+ * @param field - The name of the field to pull the existing UI Schema for
152
+ * @param uiProps - Any props that should be put into the field's uiSchema
153
+ * @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
154
+ * @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
155
+ * @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
156
+ */
157
+ export function computeFieldUiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
158
+ field: string,
159
+ uiProps: ConfigObject,
160
+ uiSchema?: UiSchema<T, S, F>,
161
+ schemaReadonly?: boolean,
162
+ forceReadonly?: boolean,
163
+ ) {
164
+ const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS_KEY], {});
165
+ const localUiSchema = get(uiSchema, field);
166
+ const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
167
+ const fieldUiSchema = { ...localUiSchema };
168
+ if (!isEmpty(localUiOptions)) {
169
+ set(fieldUiSchema, [UI_OPTIONS_KEY], localUiOptions);
170
+ }
171
+ if (!isEmpty(globalUiOptions)) {
172
+ // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields
173
+ set(fieldUiSchema, [UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
174
+ }
175
+ let { readonly: uiReadonly } = getUiOptions<T, S, F>(fieldUiSchema);
176
+ if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) {
177
+ // If we are forcing all widgets to be readonly, OR the schema indicates it is readonly AND the uiSchema does not
178
+ // have an overriding value, then update the uiSchema to set readonly to true. Doing this will
179
+ uiReadonly = true;
180
+ if (has(localUiOptions, READONLY_KEY)) {
181
+ // If the local options has the key value provided in it, then set that one to true
182
+ set(fieldUiSchema, [UI_OPTIONS_KEY, READONLY_KEY], true);
183
+ } else {
184
+ // otherwise set the `ui:` version
185
+ set(fieldUiSchema, `ui:${READONLY_KEY}`, true);
186
+ }
187
+ }
188
+ return { fieldUiSchema, uiReadonly };
189
+ }
190
+
191
+ /** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
192
+ * depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
193
+ * contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
194
+ * equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
195
+ * common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
196
+ * to match.
197
+ *
198
+ * @param [operator] - The optional operator for the condition
199
+ * @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
200
+ * @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
201
+ * to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
202
+ * This can be an item or a list of items of type unknown
203
+ * @returns - True if the condition matches, false otherwise
204
+ */
205
+ export function conditionMatches(
206
+ operator?: Operators,
207
+ datum?: unknown,
208
+ value: unknown = '$0m3tH1nG Un3xP3cT3d',
209
+ ): boolean {
210
+ const data = flatten([datum]).sort();
211
+ const values = flatten([value]).sort();
212
+ switch (operator) {
213
+ case Operators.ALL:
214
+ return isEqual(data, values);
215
+ case Operators.SOME:
216
+ return intersection(data, values).length > 0;
217
+ case Operators.NONE:
218
+ return intersection(data, values).length === 0;
219
+ default:
220
+ return false;
221
+ }
222
+ }
223
+
224
+ /** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
225
+ * `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
226
+ * lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
227
+ * When the `className` value contains multiple classNames separated by a space, the lookup will look for a
228
+ * replacement value for each `className` and combine them into one.
229
+ *
230
+ * @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
231
+ * @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
232
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
233
+ * @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
234
+ * @throws - A `TypeError` when the `children` is not an array
235
+ */
236
+ export function findChildrenAndProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
237
+ layoutGridSchema: GridSchemaType,
238
+ schemaKey: GridType,
239
+ registry: Registry<T, S, F>,
240
+ ) {
241
+ let gridProps: GridProps = {};
242
+ let children = layoutGridSchema[schemaKey];
243
+ if (isPlainObject(children)) {
244
+ const { children: elements, className: toMapClassNames, ...otherProps } = children as ConfigObject;
245
+ children = elements;
246
+ if (toMapClassNames) {
247
+ const classes = toMapClassNames.split(' ');
248
+ const className = classes.map((ele: string) => lookupFromFormContext<T, S, F>(registry, ele, ele)).join(' ');
249
+ gridProps = { ...otherProps, className };
250
+ } else {
251
+ gridProps = otherProps;
252
+ }
253
+ }
254
+ if (!Array.isArray(children)) {
255
+ throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
256
+ }
257
+ return { children: children as LayoutGridSchemaType[], gridProps };
258
+ }
259
+
260
+ /** Computes the `rawSchema` and `fieldPathId` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
261
+ * has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
262
+ * to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
263
+ * otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
264
+ * either case, an `fieldPathId` is computed for the array index. If the `schema` does not represent an array or the
265
+ * `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `fieldPathId` is returned
266
+ * as is.
267
+ *
268
+ * @param schema - The schema to generate the fieldPathId for
269
+ * @param fieldPathId - The FieldPathId for the schema
270
+ * @param potentialIndex - A string containing a potential index
271
+ * @returns - An object containing the `rawSchema` and `fieldPathId` of an array item, otherwise an undefined `rawSchema`
272
+ */
273
+ export function computeArraySchemasIfPresent<S extends StrictRJSFSchema = RJSFSchema>(
274
+ schema: S | undefined,
275
+ fieldPathId: FieldPathId,
276
+ potentialIndex: string,
277
+ ): {
278
+ rawSchema?: S;
279
+ fieldPathId: FieldPathId;
280
+ } {
281
+ let rawSchema: S | undefined;
282
+ if (isNumericIndex(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
283
+ const index = Number(potentialIndex);
284
+ const items = schema[ITEMS_KEY];
285
+ if (Array.isArray(items)) {
286
+ if (index > items.length) {
287
+ rawSchema = last(items) as S;
288
+ } else {
289
+ rawSchema = items[index] as S;
290
+ }
291
+ } else {
292
+ rawSchema = items as S;
293
+ }
294
+ fieldPathId = {
295
+ [ID_KEY]: fieldPathId[ID_KEY],
296
+ path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index],
297
+ };
298
+ }
299
+ return { rawSchema, fieldPathId };
300
+ }
301
+
302
+ /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
303
+ * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
304
+ * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
305
+ * `options`.
306
+ *
307
+ * @param registry - The registry
308
+ * @param dottedPath - The dotted-path to the field for which to get the schema
309
+ * @param initialSchema - The initial schema to start the search from
310
+ * @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
311
+ * @param initialFieldIdPath - The initial fieldPathId to start the search from
312
+ * @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
313
+ * info if a oneOf/anyOf
314
+ */
315
+ export function getSchemaDetailsForField<
316
+ T = any,
317
+ S extends StrictRJSFSchema = RJSFSchema,
318
+ F extends FormContextType = any,
319
+ >(
320
+ registry: Registry<T, S, F>,
321
+ dottedPath: string,
322
+ initialSchema: S,
323
+ formData: FieldProps<T, S, F>['formData'],
324
+ initialFieldIdPath: FieldPathId,
325
+ ): {
326
+ schema?: S;
327
+ isRequired: boolean;
328
+ isReadonly?: boolean;
329
+ optionsInfo?: OneOfOptionsInfoType<S>;
330
+ fieldPathId: FieldPathId;
331
+ } {
332
+ const { schemaUtils, globalFormOptions } = registry;
333
+ let rawSchema: S = initialSchema;
334
+ let fieldPathId = initialFieldIdPath;
335
+ const parts: string[] = dottedPath.split('.');
336
+ const leafPath: string | undefined = parts.pop(); // pop off the last element in the list as the leaf
337
+ let schema: S | undefined = schemaUtils.retrieveSchema(rawSchema, formData); // always returns an object
338
+ let innerData = formData;
339
+ let isReadonly: boolean | undefined = schema.readOnly;
340
+
341
+ // For all the remaining path parts
342
+ parts.forEach((part) => {
343
+ // dive into the properties of the current schema (when it exists) and get the schema for the next part
344
+ fieldPathId = toFieldPathId(part, globalFormOptions, fieldPathId);
345
+ if (has(schema, PROPERTIES_KEY)) {
346
+ rawSchema = get(schema, [PROPERTIES_KEY, part], {}) as S;
347
+ } else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
348
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
349
+ // When the schema represents a oneOf/anyOf, find the selected schema for it and grab the inner part
350
+ const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
351
+ rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {}) as S;
352
+ } else {
353
+ const result = computeArraySchemasIfPresent<S>(schema, fieldPathId, part);
354
+ rawSchema = result.rawSchema ?? ({} as S);
355
+ fieldPathId = result.fieldPathId;
356
+ }
357
+ // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
358
+ innerData = get(innerData, part, {}) as T;
359
+ // Resolve any `$ref`s for the current rawSchema
360
+ schema = schemaUtils.retrieveSchema(rawSchema, innerData);
361
+ isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
362
+ });
363
+
364
+ let optionsInfo: OneOfOptionsInfoType<S> | undefined;
365
+ let isRequired = false;
366
+ // retrieveSchema will return an empty schema in the worst case scenario, convert it to undefined
367
+ if (isEmpty(schema)) {
368
+ schema = undefined;
369
+ }
370
+ if (schema && leafPath) {
371
+ // When we have both a schema and a leafPath...
372
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
373
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
374
+ // Grab the selected schema for the oneOf/anyOf value for the leafPath using the innerData
375
+ schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
376
+ }
377
+ fieldPathId = toFieldPathId(leafPath, globalFormOptions, fieldPathId);
378
+ isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
379
+ const result = computeArraySchemasIfPresent<S>(schema, fieldPathId, leafPath);
380
+ if (result.rawSchema) {
381
+ schema = result.rawSchema;
382
+ fieldPathId = result.fieldPathId;
383
+ } else {
384
+ // Now grab the schema from the leafPath of the current schema properties
385
+ schema = get(schema, [PROPERTIES_KEY, leafPath]) as S | undefined;
386
+ // Resolve any `$ref`s for the current schema
387
+ schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
388
+ }
389
+ isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
390
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
391
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
392
+ // Set the options if we have a schema with a oneOf/anyOf
393
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
394
+ optionsInfo = { options: schema[xxx] as S[], hasDiscriminator: !!discriminator };
395
+ }
396
+ }
397
+
398
+ return { schema, isRequired, isReadonly, optionsInfo, fieldPathId };
399
+ }
400
+
401
+ /** Gets the custom render component from the `render`, by either determining that it is either already a function or
402
+ * it is a non-function value that can be used to look up the function in the registry. If no function can be found,
403
+ * null is returned.
404
+ *
405
+ * @param render - The potential render function or lookup name to one
406
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
407
+ * @returns - Either a render function if available, or null if not
408
+ */
409
+ export function getCustomRenderComponent<
410
+ T = any,
411
+ S extends StrictRJSFSchema = RJSFSchema,
412
+ F extends FormContextType = any,
413
+ >(render: string | RenderComponent, registry: Registry<T, S, F>): RenderComponent | null {
414
+ let customRenderer = render;
415
+ if (isString(customRenderer)) {
416
+ customRenderer = lookupFromFormContext<T, S, F>(registry, customRenderer);
417
+ }
418
+ if (isFunction(customRenderer)) {
419
+ return customRenderer;
420
+ }
421
+ return null;
422
+ }
423
+
424
+ /** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
425
+ * see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
426
+ * set the `rendered` component with only specified props for that component in the object.
427
+ *
428
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
429
+ * @param gridSchema - The string or object that represents the configuration for the grid field
430
+ * @returns - The UIComponentPropsType computed from the gridSchema
431
+ */
432
+ export function computeUIComponentPropsFromGridSchema<
433
+ T = any,
434
+ S extends StrictRJSFSchema = RJSFSchema,
435
+ F extends FormContextType = any,
436
+ >(registry: Registry<T, S, F>, gridSchema?: string | ConfigObject): UIComponentPropsType {
437
+ let name: string;
438
+ let UIComponent: RenderComponent | null = null;
439
+ let uiProps: ConfigObject = {};
440
+ let rendered: ReactNode | undefined;
441
+ if (isString(gridSchema) || isUndefined(gridSchema)) {
442
+ name = gridSchema ?? '';
443
+ } else {
444
+ const { name: innerName = '', render, ...innerProps } = gridSchema;
445
+ name = innerName;
446
+ uiProps = innerProps;
447
+ if (!isEmpty(uiProps)) {
448
+ // Transform any `$lookup=` in the uiProps props with the appropriate value
449
+ each(uiProps, (prop: ConfigObject, key: string) => {
450
+ if (isString(prop)) {
451
+ const match: string[] | null = LOOKUP_REGEX.exec(prop);
452
+ if (Array.isArray(match) && match.length > 1) {
453
+ const name = match[1];
454
+ uiProps[key] = lookupFromFormContext(registry, name, name);
455
+ }
456
+ }
457
+ });
458
+ }
459
+ UIComponent = getCustomRenderComponent<T, S, F>(render, registry);
460
+ if (!innerName && UIComponent) {
461
+ rendered = <UIComponent {...innerProps} data-testid={LAYOUT_GRID_FIELD_TEST_IDS.uiComponent} />;
462
+ }
463
+ }
464
+ return { name, UIComponent, uiProps, rendered };
465
+ }
466
+
467
+ /**
468
+ * The props for the LayoutGridFieldChildren component.
469
+ */
470
+ type LayoutGridFieldChildrenProps<
471
+ T = any,
472
+ S extends StrictRJSFSchema = RJSFSchema,
473
+ F extends FormContextType = any,
474
+ > = LayoutGridFieldProps<T, S, F> & {
475
+ /** The list of strings or objects that represents the configurations for the children fields */
476
+ childrenLayoutGridSchemaId: LayoutGridSchemaType[];
477
+ };
478
+
479
+ /** Iterates through all the `childrenLayoutGridSchemaId`, rendering a nested `LayoutGridField` for each item in the
480
+ * list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
481
+ * `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
482
+ * `childrenLayoutGridSchemaId` is passed as `layoutGridSchema`.
483
+ *
484
+ * @returns - The nested `LayoutGridField`s
485
+ */
486
+ function LayoutGridFieldChildren<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
487
+ props: LayoutGridFieldChildrenProps<T, S, F>,
488
+ ) {
489
+ const { childrenLayoutGridSchemaId, ...layoutGridFieldProps } = props;
490
+ const { registry, schema: rawSchema, formData } = layoutGridFieldProps;
491
+ const { schemaUtils } = registry;
492
+ const schema = schemaUtils.retrieveSchema(rawSchema, formData);
493
+ return childrenLayoutGridSchemaId.map((layoutGridSchema) => (
494
+ <LayoutGridField<T, S, F>
495
+ {...layoutGridFieldProps}
496
+ key={`layoutGrid-${hashObject(layoutGridSchema)}`}
497
+ schema={schema}
498
+ layoutGridSchema={layoutGridSchema}
499
+ />
500
+ ));
501
+ }
502
+
503
+ /**
504
+ * Describes the props for LayoutGridCondition, LayoutGridCol, LayoutGridColumns, and LayoutGridRow. This is typically
505
+ * the original props passed through from the nearest ancestor LayoutGridField, plus the layoutGridSchema for the
506
+ * current node.
507
+ */
508
+ type LayoutFieldProps<
509
+ T = any,
510
+ S extends StrictRJSFSchema = RJSFSchema,
511
+ F extends FormContextType = any,
512
+ > = LayoutGridFieldProps<T, S, F> & {
513
+ /** The string or object that represents the configuration for the grid field */
514
+ layoutGridSchema: GridSchemaType;
515
+ };
516
+
517
+ /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
518
+ * `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
519
+ * the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
520
+ * rendered, otherwise null is returned.
521
+ *
522
+ * @returns - The rendered the children for the `GridType.CONDITION` or null
523
+ */
524
+ function LayoutGridCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
525
+ props: LayoutFieldProps<T, S, F>,
526
+ ) {
527
+ const { layoutGridSchema, ...layoutGridFieldProps } = props;
528
+ const { formData, registry } = layoutGridFieldProps;
529
+ const { children, gridProps } = findChildrenAndProps<T, S, F>(layoutGridSchema, GridType.CONDITION, registry);
530
+ const { operator, field = '', value } = gridProps;
531
+ const fieldData = get(formData, field, null);
532
+ if (conditionMatches(operator, fieldData, value)) {
533
+ return <LayoutGridFieldChildren {...layoutGridFieldProps} childrenLayoutGridSchemaId={children} />;
534
+ }
535
+ return null;
536
+ }
537
+
538
+ /** Renders a `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated into the
539
+ * `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside the
540
+ * `GridTemplate` all the `children` are rendered.
541
+ *
542
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
543
+ */
544
+ function LayoutGridCol<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
545
+ props: LayoutFieldProps<T, S, F>,
546
+ ) {
547
+ const { layoutGridSchema, ...layoutGridFieldProps } = props;
548
+ const { registry, uiSchema } = layoutGridFieldProps;
549
+ const { children, gridProps } = findChildrenAndProps<T, S, F>(layoutGridSchema, GridType.COLUMN, registry);
550
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
551
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
552
+
553
+ return (
554
+ <GridTemplate column data-testid={LAYOUT_GRID_FIELD_TEST_IDS.col} {...gridProps}>
555
+ <LayoutGridFieldChildren {...layoutGridFieldProps} childrenLayoutGridSchemaId={children} />
556
+ </GridTemplate>
557
+ );
558
+ }
559
+
560
+ /** Renders a `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated into the
561
+ * `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the outer
562
+ * `GridTemplate`. Each child will have their own rendered `GridTemplate`.
563
+ *
564
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
565
+ */
566
+ function LayoutGridColumns<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
567
+ props: LayoutFieldProps<T, S, F>,
568
+ ) {
569
+ const { layoutGridSchema, ...layoutGridFieldProps } = props;
570
+
571
+ const { registry, uiSchema } = layoutGridFieldProps;
572
+ const { children, gridProps } = findChildrenAndProps<T, S, F>(layoutGridSchema, GridType.COLUMNS, registry);
573
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
574
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
575
+
576
+ return children.map((child) => (
577
+ <GridTemplate
578
+ column
579
+ key={`column-${hashObject(child)}`}
580
+ data-testid={LAYOUT_GRID_FIELD_TEST_IDS.col}
581
+ {...gridProps}
582
+ >
583
+ <LayoutGridFieldChildren {...layoutGridFieldProps} childrenLayoutGridSchemaId={[child]} />
584
+ </GridTemplate>
585
+ ));
586
+ }
587
+
588
+ /** Renders a `GridTemplate` as a container. The `layoutGridSchema` for the `GridType.ROW` is separated into the
589
+ * `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside of the
590
+ * `GridTemplate` all of the `children` are rendered.
591
+ *
592
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
593
+ */
594
+ function LayoutGridRow<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
595
+ props: LayoutFieldProps<T, S, F>,
596
+ ) {
597
+ const { layoutGridSchema, ...layoutGridFieldProps } = props;
598
+
599
+ const { registry, uiSchema } = layoutGridFieldProps;
600
+ const { children, gridProps } = findChildrenAndProps<T, S, F>(layoutGridSchema, GridType.ROW, registry);
601
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
602
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
603
+
604
+ return (
605
+ <GridTemplate {...gridProps} data-testid={LAYOUT_GRID_FIELD_TEST_IDS.row}>
606
+ <LayoutGridFieldChildren {...layoutGridFieldProps} childrenLayoutGridSchemaId={children} />
607
+ </GridTemplate>
608
+ );
609
+ }
610
+
611
+ /**
612
+ * The props for the LayoutGridFieldComponent.
613
+ */
614
+ type LayoutGridFieldComponentProps<
615
+ T = any,
616
+ S extends StrictRJSFSchema = RJSFSchema,
617
+ F extends FormContextType = any,
618
+ > = LayoutGridFieldProps<T, S, F> & {
619
+ /** The string or object that represents the configuration for the grid field */
620
+ gridSchema?: ConfigObject | string;
621
+ };
622
+
623
+ /** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
624
+ * to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
625
+ * other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
626
+ * specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
627
+ * and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
628
+ * schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
629
+ * `uiSchema`, `errorSchema`, `fieldPathId` and `formData` drilled down to the dotted-path field, spreading any other
630
+ * props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
631
+ * then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
632
+ * schema was located, but a custom render component was found, then it will be rendered with many of the non-event
633
+ * handling props. If none of the previous render paths are valid, then a null is returned.
634
+ *
635
+ * @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
636
+ */
637
+ function LayoutGridFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
638
+ props: LayoutGridFieldComponentProps<T, S, F>,
639
+ ) {
640
+ const {
641
+ gridSchema,
642
+ schema: initialSchema,
643
+ uiSchema,
644
+ errorSchema,
645
+ fieldPathId,
646
+ onBlur,
647
+ onFocus,
648
+ formData,
649
+ readonly,
650
+ registry,
651
+ layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
652
+ ...otherProps
653
+ } = props;
654
+ const { onChange } = otherProps;
655
+ const { fields } = registry;
656
+ const { SchemaField, LayoutMultiSchemaField } = fields;
657
+
658
+ const uiComponentProps = computeUIComponentPropsFromGridSchema(registry, gridSchema);
659
+ const { name, UIComponent, uiProps } = uiComponentProps;
660
+ const {
661
+ schema,
662
+ isRequired,
663
+ isReadonly,
664
+ optionsInfo,
665
+ fieldPathId: fieldIdSchema,
666
+ } = getSchemaDetailsForField<T, S, F>(registry, name, initialSchema, formData, fieldPathId);
667
+ const memoFieldPathId = useDeepCompareMemo<FieldPathId>(fieldIdSchema);
668
+
669
+ if (uiComponentProps.rendered) {
670
+ return uiComponentProps.rendered;
671
+ }
672
+
673
+ if (schema) {
674
+ const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField : SchemaField;
675
+ // Call this function to get the appropriate UISchema, which will always have its `readonly` state matching the
676
+ // `uiReadonly` flag that it returns. This is done since the `SchemaField` will always defer to the `readonly`
677
+ // state in the uiSchema over anything in the props or schema. Because we are implementing the "readonly" state of
678
+ // the `Form` via the prop passed to `LayoutGridField` we need to make sure the uiSchema always has a true value
679
+ // when it is needed
680
+ const { fieldUiSchema, uiReadonly } = computeFieldUiSchema<T, S, F>(name, uiProps, uiSchema, isReadonly, readonly);
681
+
682
+ return (
683
+ <Field
684
+ data-testid={
685
+ optionsInfo?.hasDiscriminator
686
+ ? LAYOUT_GRID_FIELD_TEST_IDS.layoutMultiSchemaField
687
+ : LAYOUT_GRID_FIELD_TEST_IDS.field
688
+ }
689
+ {...otherProps}
690
+ name={name}
691
+ required={isRequired}
692
+ readonly={uiReadonly}
693
+ schema={schema}
694
+ uiSchema={fieldUiSchema}
695
+ errorSchema={get(errorSchema, name)}
696
+ fieldPathId={memoFieldPathId}
697
+ formData={get(formData, name)}
698
+ onChange={onChange}
699
+ onBlur={onBlur}
700
+ onFocus={onFocus}
701
+ options={optionsInfo?.options}
702
+ registry={registry}
703
+ />
704
+ );
705
+ }
706
+
707
+ if (UIComponent) {
708
+ return (
709
+ <UIComponent
710
+ data-testid={LAYOUT_GRID_FIELD_TEST_IDS.uiComponent}
711
+ {...otherProps}
712
+ name={name}
713
+ required={isRequired}
714
+ formData={formData}
715
+ readOnly={!!isReadonly || readonly}
716
+ errorSchema={errorSchema}
717
+ uiSchema={uiSchema}
718
+ schema={initialSchema}
719
+ fieldPathId={fieldPathId}
720
+ onBlur={onBlur}
721
+ onFocus={onFocus}
722
+ registry={registry}
723
+ {...uiProps}
724
+ />
725
+ );
726
+ }
727
+ return null;
728
+ }
729
+
143
730
  /** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
144
731
  * described in the uiSchema. To define the grid to use to render the elements within a field in the schema, provide in
145
732
  * the uiSchema for that field the object contained under a `ui:layoutGrid` element. E.g. (as a JSON object):
@@ -363,612 +950,38 @@ function isNumericIndex(str: string) {
363
950
  * ]
364
951
  * ```
365
952
  */
366
- export default class LayoutGridField<
953
+ export default function LayoutGridField<
367
954
  T = any,
368
955
  S extends StrictRJSFSchema = RJSFSchema,
369
956
  F extends FormContextType = any,
370
- > extends PureComponent<LayoutGridFieldProps<T, S, F>> {
371
- static defaultProps = {
372
- layoutGridSchema: undefined,
373
- };
374
-
375
- static TEST_IDS = getTestIds();
376
- /** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
377
- * will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
378
- * copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
379
- * updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
380
- * the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
381
- * field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
382
- *
383
- * @param field - The name of the field to pull the existing UI Schema for
384
- * @param uiProps - Any props that should be put into the field's uiSchema
385
- * @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
386
- * @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
387
- * @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
388
- */
389
- static computeFieldUiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
390
- field: string,
391
- uiProps: ConfigObject,
392
- uiSchema?: UiSchema<T, S, F>,
393
- schemaReadonly?: boolean,
394
- forceReadonly?: boolean,
395
- ) {
396
- const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS_KEY], {});
397
- const localUiSchema = get(uiSchema, field);
398
- const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
399
- const fieldUiSchema = { ...localUiSchema };
400
- if (!isEmpty(localUiOptions)) {
401
- set(fieldUiSchema, [UI_OPTIONS_KEY], localUiOptions);
402
- }
403
- if (!isEmpty(globalUiOptions)) {
404
- // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields
405
- set(fieldUiSchema, [UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
406
- }
407
- let { readonly: uiReadonly } = getUiOptions<T, S, F>(fieldUiSchema);
408
- if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) {
409
- // If we are forcing all widgets to be readonly, OR the schema indicates it is readonly AND the uiSchema does not
410
- // have an overriding value, then update the uiSchema to set readonly to true. Doing this will
411
- uiReadonly = true;
412
- if (has(localUiOptions, READONLY_KEY)) {
413
- // If the local options has the key value provided in it, then set that one to true
414
- set(fieldUiSchema, [UI_OPTIONS_KEY, READONLY_KEY], true);
415
- } else {
416
- // otherwise set the `ui:` version
417
- set(fieldUiSchema, `ui:${READONLY_KEY}`, true);
418
- }
419
- }
420
- return { fieldUiSchema, uiReadonly };
421
- }
422
-
423
- /** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
424
- * depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
425
- * contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
426
- * equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
427
- * common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
428
- * to match.
429
- *
430
- * @param [operator] - The optional operator for the condition
431
- * @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
432
- * @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
433
- * to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
434
- * This can be an item or a list of items of type unknown
435
- * @returns - True if the condition matches, false otherwise
436
- */
437
- static conditionMatches(operator?: Operators, datum?: unknown, value: unknown = '$0m3tH1nG Un3xP3cT3d'): boolean {
438
- const data = flatten([datum]).sort();
439
- const values = flatten([value]).sort();
440
- switch (operator) {
441
- case Operators.ALL:
442
- return isEqual(data, values);
443
- case Operators.SOME:
444
- return intersection(data, values).length > 0;
445
- case Operators.NONE:
446
- return intersection(data, values).length === 0;
447
- default:
448
- return false;
449
- }
450
- }
451
-
452
- /** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
453
- * `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
454
- * lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
455
- * When the `className` value contains multiple classNames separated by a space, the lookup will look for a
456
- * replacement value for each `className` and combine them into one.
457
- *
458
- * @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
459
- * @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
460
- * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
461
- * @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
462
- * @throws - A `TypeError` when the `children` is not an array
463
- */
464
- static findChildrenAndProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
465
- layoutGridSchema: GridSchemaType,
466
- schemaKey: GridType,
467
- registry: Registry<T, S, F>,
468
- ) {
469
- let gridProps: GridProps = {};
470
- let children = layoutGridSchema[schemaKey];
471
- if (isPlainObject(children)) {
472
- const { children: elements, className: toMapClassNames, ...otherProps } = children as ConfigObject;
473
- children = elements;
474
- if (toMapClassNames) {
475
- const classes = toMapClassNames.split(' ');
476
- const className = classes.map((ele: string) => lookupFromFormContext<T, S, F>(registry, ele, ele)).join(' ');
477
- gridProps = { ...otherProps, className };
478
- } else {
479
- gridProps = otherProps;
480
- }
481
- }
482
- if (!Array.isArray(children)) {
483
- throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
484
- }
485
- return { children: children as LayoutGridSchemaType[], gridProps };
486
- }
487
-
488
- /** Computes the `rawSchema` and `fieldPathId` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
489
- * has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
490
- * to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
491
- * otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
492
- * either case, an `fieldPathId` is computed for the array index. If the `schema` does not represent an array or the
493
- * `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `fieldPathId` is returned
494
- * as is.
495
- *
496
- * @param schema - The schema to generate the fieldPathId for
497
- * @param fieldPathId - The FieldPathId for the schema
498
- * @param potentialIndex - A string containing a potential index
499
- * @returns - An object containing the `rawSchema` and `fieldPathId` of an array item, otherwise an undefined `rawSchema`
500
- */
501
- static computeArraySchemasIfPresent<S extends StrictRJSFSchema = RJSFSchema>(
502
- schema: S | undefined,
503
- fieldPathId: FieldPathId,
504
- potentialIndex: string,
505
- ): {
506
- rawSchema?: S;
507
- fieldPathId: FieldPathId;
508
- } {
509
- let rawSchema: S | undefined;
510
- if (isNumericIndex(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
511
- const index = Number(potentialIndex);
512
- const items = schema[ITEMS_KEY];
513
- if (Array.isArray(items)) {
514
- if (index > items.length) {
515
- rawSchema = last(items) as S;
516
- } else {
517
- rawSchema = items[index] as S;
518
- }
519
- } else {
520
- rawSchema = items as S;
521
- }
522
- fieldPathId = {
523
- [ID_KEY]: fieldPathId[ID_KEY],
524
- path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index],
525
- };
526
- }
527
- return { rawSchema, fieldPathId };
528
- }
529
-
530
- /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
531
- * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
532
- * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
533
- * `options`.
534
- *
535
- * @param registry - The registry
536
- * @param dottedPath - The dotted-path to the field for which to get the schema
537
- * @param initialSchema - The initial schema to start the search from
538
- * @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
539
- * @param initialFieldIdPath - The initial fieldPathId to start the search from
540
- * @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
541
- * info if a oneOf/anyOf
542
- */
543
- static getSchemaDetailsForField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
544
- registry: Registry<T, S, F>,
545
- dottedPath: string,
546
- initialSchema: S,
547
- formData: FieldProps<T, S, F>['formData'],
548
- initialFieldIdPath: FieldPathId,
549
- ): {
550
- schema?: S;
551
- isRequired: boolean;
552
- isReadonly?: boolean;
553
- optionsInfo?: OneOfOptionsInfoType<S>;
554
- fieldPathId: FieldPathId;
555
- } {
556
- const { schemaUtils, globalFormOptions } = registry;
557
- let rawSchema: S = initialSchema;
558
- let fieldPathId = initialFieldIdPath;
559
- const parts: string[] = dottedPath.split('.');
560
- const leafPath: string | undefined = parts.pop(); // pop off the last element in the list as the leaf
561
- let schema: S | undefined = schemaUtils.retrieveSchema(rawSchema, formData); // always returns an object
562
- let innerData = formData;
563
- let isReadonly: boolean | undefined = schema.readOnly;
564
-
565
- // For all the remaining path parts
566
- parts.forEach((part) => {
567
- // dive into the properties of the current schema (when it exists) and get the schema for the next part
568
- fieldPathId = toFieldPathId(part, globalFormOptions, fieldPathId);
569
- if (has(schema, PROPERTIES_KEY)) {
570
- rawSchema = get(schema, [PROPERTIES_KEY, part], {}) as S;
571
- } else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
572
- const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
573
- // When the schema represents a oneOf/anyOf, find the selected schema for it and grab the inner part
574
- const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
575
- rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {}) as S;
576
- } else {
577
- const result = LayoutGridField.computeArraySchemasIfPresent<S>(schema, fieldPathId, part);
578
- rawSchema = result.rawSchema ?? ({} as S);
579
- fieldPathId = result.fieldPathId;
580
- }
581
- // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
582
- innerData = get(innerData, part, {}) as T;
583
- // Resolve any `$ref`s for the current rawSchema
584
- schema = schemaUtils.retrieveSchema(rawSchema, innerData);
585
- isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
586
- });
587
-
588
- let optionsInfo: OneOfOptionsInfoType<S> | undefined;
589
- let isRequired = false;
590
- // retrieveSchema will return an empty schema in the worst case scenario, convert it to undefined
591
- if (isEmpty(schema)) {
592
- schema = undefined;
593
- }
594
- if (schema && leafPath) {
595
- // When we have both a schema and a leafPath...
596
- if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
597
- const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
598
- // Grab the selected schema for the oneOf/anyOf value for the leafPath using the innerData
599
- schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
600
- }
601
- fieldPathId = toFieldPathId(leafPath, globalFormOptions, fieldPathId);
602
- isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
603
- const result = LayoutGridField.computeArraySchemasIfPresent<S>(schema, fieldPathId, leafPath);
604
- if (result.rawSchema) {
605
- schema = result.rawSchema;
606
- fieldPathId = result.fieldPathId;
607
- } else {
608
- // Now grab the schema from the leafPath of the current schema properties
609
- schema = get(schema, [PROPERTIES_KEY, leafPath]) as S | undefined;
610
- // Resolve any `$ref`s for the current schema
611
- schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
612
- }
613
- isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
614
- if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
615
- const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
616
- // Set the options if we have a schema with a oneOf/anyOf
617
- const discriminator = getDiscriminatorFieldFromSchema(schema);
618
- optionsInfo = { options: schema[xxx] as S[], hasDiscriminator: !!discriminator };
619
- }
620
- }
621
-
622
- return { schema, isRequired, isReadonly, optionsInfo, fieldPathId };
623
- }
624
-
625
- /** Gets the custom render component from the `render`, by either determining that it is either already a function or
626
- * it is a non-function value that can be used to look up the function in the registry. If no function can be found,
627
- * null is returned.
628
- *
629
- * @param render - The potential render function or lookup name to one
630
- * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
631
- * @returns - Either a render function if available, or null if not
632
- */
633
- static getCustomRenderComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
634
- render: string | RenderComponent,
635
- registry: Registry<T, S, F>,
636
- ): RenderComponent | null {
637
- let customRenderer = render;
638
- if (isString(customRenderer)) {
639
- customRenderer = lookupFromFormContext<T, S, F>(registry, customRenderer);
640
- }
641
- if (isFunction(customRenderer)) {
642
- return customRenderer;
643
- }
644
- return null;
645
- }
646
-
647
- /** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
648
- * see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
649
- * set the `rendered` component with only specified props for that component in the object.
650
- *
651
- * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
652
- * @param gridSchema - The string or object that represents the configuration for the grid field
653
- * @returns - The UIComponentPropsType computed from the gridSchema
654
- */
655
- static computeUIComponentPropsFromGridSchema<
656
- T = any,
657
- S extends StrictRJSFSchema = RJSFSchema,
658
- F extends FormContextType = any,
659
- >(registry: Registry<T, S, F>, gridSchema?: string | ConfigObject): UIComponentPropsType {
660
- let name: string;
661
- let UIComponent: RenderComponent | null = null;
662
- let uiProps: ConfigObject = {};
663
- let rendered: ReactNode | undefined;
664
- if (isString(gridSchema) || isUndefined(gridSchema)) {
665
- name = gridSchema ?? '';
666
- } else {
667
- const { name: innerName = '', render, ...innerProps } = gridSchema;
668
- name = innerName;
669
- uiProps = innerProps;
670
- if (!isEmpty(uiProps)) {
671
- // Transform any `$lookup=` in the uiProps props with the appropriate value
672
- each(uiProps, (prop: ConfigObject, key: string) => {
673
- if (isString(prop)) {
674
- const match: string[] | null = LOOKUP_REGEX.exec(prop);
675
- if (Array.isArray(match) && match.length > 1) {
676
- const name = match[1];
677
- uiProps[key] = lookupFromFormContext(registry, name, name);
678
- }
679
- }
680
- });
681
- }
682
- UIComponent = LayoutGridField.getCustomRenderComponent<T, S, F>(render, registry);
683
- if (!innerName && UIComponent) {
684
- rendered = <UIComponent {...innerProps} data-testid={LayoutGridField.TEST_IDS.uiComponent} />;
685
- }
686
- }
687
- return { name, UIComponent, uiProps, rendered };
688
- }
689
-
690
- /** Constructs an `LayoutGridField` with the given `props`
691
- *
692
- * @param props - The `LayoutGridField` for this template
693
- */
694
- constructor(props: LayoutGridFieldProps<T, S, F>) {
695
- super(props);
696
- }
697
-
698
- /** Generates an `onChange` handler for the field associated with the `dottedPath`. This handler will clone and update
699
- * the `formData` with the new `value` and the `errorSchema` if an `errSchema` is provided. After updating those two
700
- * elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
701
- *
702
- * @param dottedPath - The dotted-path to the field for which to generate the onChange handler
703
- * @returns - The `onChange` handling function for the `dottedPath` field of the `schemaType` type
704
- */
705
- onFieldChange = (dottedPath: string) => {
706
- return (value: T | undefined, path: FieldPathList, errSchema?: ErrorSchema<T>, id?: string) => {
707
- const { onChange } = this.props;
708
- onChange(value, path, errSchema, id);
709
- };
710
- };
711
-
712
- /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
713
- * `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
714
- * the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
715
- * rendered, otherwise null is returned.
716
- *
717
- * @param layoutGridSchema - The string or object that represents the configuration for the grid field
718
- * @returns - The rendered the children for the `GridType.CONDITION` or null
719
- */
720
- renderCondition(layoutGridSchema: GridSchemaType) {
721
- const { formData, registry } = this.props;
722
- const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
723
- layoutGridSchema,
724
- GridType.CONDITION,
725
- registry,
726
- );
727
- const { operator, field = '', value } = gridProps;
728
- const fieldData = get(formData, field, null);
729
- if (LayoutGridField.conditionMatches(operator, fieldData, value)) {
730
- return this.renderChildren(children);
731
- }
732
- return null;
733
- }
734
-
735
- /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated
736
- * into the `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside
737
- * the `GridTemplate` all the `children` are rendered.
738
- *
739
- * @param layoutGridSchema - The string or object that represents the configuration for the grid field
740
- * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
741
- */
742
- renderCol(layoutGridSchema: GridSchemaType) {
743
- const { registry, uiSchema } = this.props;
744
- const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
745
- layoutGridSchema,
746
- GridType.COLUMN,
747
- registry,
748
- );
749
- const uiOptions = getUiOptions<T, S, F>(uiSchema);
750
- const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
751
-
752
- return (
753
- <GridTemplate column data-testid={LayoutGridField.TEST_IDS.col} {...gridProps}>
754
- {this.renderChildren(children)}
755
- </GridTemplate>
756
- );
757
- }
758
-
759
- /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated
760
- * into the `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the
761
- * outer `GridTemplate`. Each child will have their own rendered `GridTemplate`.
762
- *
763
- * @param layoutGridSchema - The string or object that represents the configuration for the grid field
764
- * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
765
- */
766
- renderColumns(layoutGridSchema: GridSchemaType) {
767
- const { registry, uiSchema } = this.props;
768
- const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
769
- layoutGridSchema,
770
- GridType.COLUMNS,
771
- registry,
772
- );
773
- const uiOptions = getUiOptions<T, S, F>(uiSchema);
774
- const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
775
-
776
- return children.map((child) => (
777
- <GridTemplate
778
- column
779
- key={`column-${hashObject(child)}`}
780
- data-testid={LayoutGridField.TEST_IDS.col}
781
- {...gridProps}
782
- >
783
- {this.renderChildren([child])}
784
- </GridTemplate>
785
- ));
786
- }
787
-
788
- /** Renders a material-ui `GridTemplate` as a container. The
789
- * `layoutGridSchema` for the `GridType.ROW` is separated into the `children` and other `gridProps`. The `gridProps`
790
- * will be spread onto the outer `GridTemplate`. Inside of the `GridTemplate` all of the `children` are rendered.
791
- *
792
- * @param layoutGridSchema - The string or object that represents the configuration for the grid field
793
- * @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
794
- */
795
- renderRow(layoutGridSchema: GridSchemaType) {
796
- const { registry, uiSchema } = this.props;
797
- const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
798
- layoutGridSchema,
799
- GridType.ROW,
800
- registry,
801
- );
802
- const uiOptions = getUiOptions<T, S, F>(uiSchema);
803
- const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
804
-
805
- return (
806
- <GridTemplate {...gridProps} data-testid={LayoutGridField.TEST_IDS.row}>
807
- {this.renderChildren(children)}
808
- </GridTemplate>
809
- );
810
- }
811
-
812
- /** Iterates through all the `childrenLayoutGrfieldPathId`, rendering a nested `LayoutGridField` for each item in the
813
- * list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
814
- * `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
815
- * `childrenLayoutGrfieldPathId` is passed as `layoutGridSchema`.
816
- *
817
- * @param childrenLayoutGrfieldPathId - The list of strings or objects that represents the configurations for the
818
- * children fields
819
- * @returns - The nested `LayoutGridField`s
957
+ >(props: LayoutGridFieldProps<T, S, F>) {
958
+ /** Render the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
959
+ * `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
960
+ * match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
961
+ * generic `renderField()` function with the `layoutGridSchema`.
820
962
  */
821
- renderChildren(childrenLayoutGrfieldPathId: LayoutGridSchemaType[]) {
822
- const { registry, schema: rawSchema, formData } = this.props;
823
- const { schemaUtils } = registry;
824
- const schema = schemaUtils.retrieveSchema(rawSchema, formData);
825
-
826
- return childrenLayoutGrfieldPathId.map((layoutGridSchema) => (
827
- <LayoutGridField<T, S, F>
828
- {...this.props}
829
- key={`layoutGrid-${hashObject(layoutGridSchema)}`}
830
- schema={schema}
831
- layoutGridSchema={layoutGridSchema}
832
- />
833
- ));
963
+ const { uiSchema } = props;
964
+ let { layoutGridSchema } = props;
965
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
966
+ if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
967
+ layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
834
968
  }
835
969
 
836
- /** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
837
- * to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
838
- * other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
839
- * specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
840
- * and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
841
- * schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
842
- * `uiSchema`, `errorSchema`, `fieldPathId` and `formData` drilled down to the dotted-path field, spreading any other
843
- * props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
844
- * then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
845
- * schema was located, but a custom render component was found, then it will be rendered with many of the non-event
846
- * handling props. If none of the previous render paths are valid, then a null is returned.
847
- *
848
- * @param gridSchema - The string or object that represents the configuration for the grid field
849
- * @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
850
- */
851
- renderField(gridSchema?: ConfigObject | string) {
852
- const {
853
- schema: initialSchema,
854
- uiSchema,
855
- errorSchema,
856
- fieldPathId,
857
- onBlur,
858
- onFocus,
859
- formData,
860
- readonly,
861
- registry,
862
- layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
863
- ...otherProps
864
- } = this.props;
865
- const { fields } = registry;
866
- const { SchemaField, LayoutMultiSchemaField } = fields;
867
- const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
868
- if (uiComponentProps.rendered) {
869
- return uiComponentProps.rendered;
870
- }
871
- const { name, UIComponent, uiProps } = uiComponentProps;
872
- const {
873
- schema,
874
- isRequired,
875
- isReadonly,
876
- optionsInfo,
877
- fieldPathId: fieldIdSchema,
878
- } = LayoutGridField.getSchemaDetailsForField<T, S, F>(registry, name, initialSchema, formData, fieldPathId);
879
-
880
- if (schema) {
881
- const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField : SchemaField;
882
- // Call this function to get the appropriate UISchema, which will always have its `readonly` state matching the
883
- // `uiReadonly` flag that it returns. This is done since the `SchemaField` will always defer to the `readonly`
884
- // state in the uiSchema over anything in the props or schema. Because we are implementing the "readonly" state of
885
- // the `Form` via the prop passed to `LayoutGridField` we need to make sure the uiSchema always has a true value
886
- // when it is needed
887
- const { fieldUiSchema, uiReadonly } = LayoutGridField.computeFieldUiSchema<T, S, F>(
888
- name,
889
- uiProps,
890
- uiSchema,
891
- isReadonly,
892
- readonly,
893
- );
894
-
895
- return (
896
- <Field
897
- data-testid={
898
- optionsInfo?.hasDiscriminator
899
- ? LayoutGridField.TEST_IDS.layoutMultiSchemaField
900
- : LayoutGridField.TEST_IDS.field
901
- }
902
- {...otherProps}
903
- name={name}
904
- required={isRequired}
905
- readonly={uiReadonly}
906
- schema={schema}
907
- uiSchema={fieldUiSchema}
908
- errorSchema={get(errorSchema, name)}
909
- fieldPathId={fieldIdSchema}
910
- formData={get(formData, name)}
911
- onChange={this.onFieldChange(name)}
912
- onBlur={onBlur}
913
- onFocus={onFocus}
914
- options={optionsInfo?.options}
915
- registry={registry}
916
- />
917
- );
970
+ if (isObject(layoutGridSchema)) {
971
+ if (GridType.ROW in layoutGridSchema) {
972
+ return <LayoutGridRow {...props} layoutGridSchema={layoutGridSchema} />;
918
973
  }
919
-
920
- if (UIComponent) {
921
- return (
922
- <UIComponent
923
- data-testid={LayoutGridField.TEST_IDS.uiComponent}
924
- {...otherProps}
925
- name={name}
926
- required={isRequired}
927
- formData={formData}
928
- readOnly={!!isReadonly || readonly}
929
- errorSchema={errorSchema}
930
- uiSchema={uiSchema}
931
- schema={initialSchema}
932
- fieldPathId={fieldPathId}
933
- onBlur={onBlur}
934
- onFocus={onFocus}
935
- registry={registry}
936
- {...uiProps}
937
- />
938
- );
974
+ if (GridType.COLUMN in layoutGridSchema) {
975
+ return <LayoutGridCol {...props} layoutGridSchema={layoutGridSchema} />;
939
976
  }
940
- return null;
941
- }
942
-
943
- /** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
944
- * `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
945
- * match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
946
- * generic `renderField()` function with the `layoutGridSchema`.
947
- *
948
- * @returns - the rendered `LayoutGridField`
949
- */
950
- render() {
951
- const { uiSchema } = this.props;
952
- let { layoutGridSchema } = this.props;
953
- const uiOptions = getUiOptions<T, S, F>(uiSchema);
954
- if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
955
- layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
977
+ if (GridType.COLUMNS in layoutGridSchema) {
978
+ return <LayoutGridColumns {...props} layoutGridSchema={layoutGridSchema} />;
956
979
  }
957
-
958
- if (isObject(layoutGridSchema)) {
959
- if (GridType.ROW in layoutGridSchema) {
960
- return this.renderRow(layoutGridSchema as GridSchemaType);
961
- }
962
- if (GridType.COLUMN in layoutGridSchema) {
963
- return this.renderCol(layoutGridSchema as GridSchemaType);
964
- }
965
- if (GridType.COLUMNS in layoutGridSchema) {
966
- return this.renderColumns(layoutGridSchema as GridSchemaType);
967
- }
968
- if (GridType.CONDITION in layoutGridSchema) {
969
- return this.renderCondition(layoutGridSchema as GridSchemaType);
970
- }
980
+ if (GridType.CONDITION in layoutGridSchema) {
981
+ return <LayoutGridCondition {...props} layoutGridSchema={layoutGridSchema} />;
971
982
  }
972
- return this.renderField(layoutGridSchema);
973
983
  }
984
+ return <LayoutGridFieldComponent {...props} gridSchema={layoutGridSchema} />;
974
985
  }
986
+
987
+ LayoutGridField.TEST_IDS = LAYOUT_GRID_FIELD_TEST_IDS;