@rjsf/core 6.0.0-alpha.0 → 6.0.0-beta.2

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 (301) hide show
  1. package/dist/core.umd.js +1680 -809
  2. package/dist/index.esm.js +2166 -1198
  3. package/dist/index.esm.js.map +4 -4
  4. package/dist/index.js +2221 -1299
  5. package/dist/index.js.map +4 -4
  6. package/lib/components/Form.d.ts +22 -9
  7. package/lib/components/Form.d.ts.map +1 -0
  8. package/lib/components/Form.js +368 -312
  9. package/lib/components/RichDescription.d.ts +20 -0
  10. package/lib/components/RichDescription.d.ts.map +1 -0
  11. package/lib/components/RichDescription.js +17 -0
  12. package/lib/components/fields/ArrayField.d.ts +20 -9
  13. package/lib/components/fields/ArrayField.d.ts.map +1 -0
  14. package/lib/components/fields/ArrayField.js +212 -206
  15. package/lib/components/fields/BooleanField.d.ts +1 -0
  16. package/lib/components/fields/BooleanField.d.ts.map +1 -0
  17. package/lib/components/fields/BooleanField.js +6 -14
  18. package/lib/components/fields/LayoutGridField.d.ts +480 -0
  19. package/lib/components/fields/LayoutGridField.d.ts.map +1 -0
  20. package/lib/components/fields/LayoutGridField.js +711 -0
  21. package/lib/components/fields/LayoutHeaderField.d.ts +12 -0
  22. package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -0
  23. package/lib/components/fields/LayoutHeaderField.js +23 -0
  24. package/lib/components/fields/LayoutMultiSchemaField.d.ts +28 -0
  25. package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -0
  26. package/lib/components/fields/LayoutMultiSchemaField.js +114 -0
  27. package/lib/components/fields/MultiSchemaField.d.ts +1 -0
  28. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -0
  29. package/lib/components/fields/MultiSchemaField.js +31 -31
  30. package/lib/components/fields/NullField.d.ts +1 -0
  31. package/lib/components/fields/NullField.d.ts.map +1 -0
  32. package/lib/components/fields/NullField.js +0 -1
  33. package/lib/components/fields/NumberField.d.ts +1 -0
  34. package/lib/components/fields/NumberField.d.ts.map +1 -0
  35. package/lib/components/fields/NumberField.js +2 -3
  36. package/lib/components/fields/ObjectField.d.ts +1 -0
  37. package/lib/components/fields/ObjectField.d.ts.map +1 -0
  38. package/lib/components/fields/ObjectField.js +146 -141
  39. package/lib/components/fields/SchemaField.d.ts +1 -0
  40. package/lib/components/fields/SchemaField.d.ts.map +1 -0
  41. package/lib/components/fields/SchemaField.js +10 -20
  42. package/lib/components/fields/StringField.d.ts +1 -0
  43. package/lib/components/fields/StringField.d.ts.map +1 -0
  44. package/lib/components/fields/StringField.js +1 -3
  45. package/lib/components/fields/index.d.ts +1 -0
  46. package/lib/components/fields/index.d.ts.map +1 -0
  47. package/lib/components/fields/index.js +14 -9
  48. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -0
  49. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -0
  50. package/lib/components/templates/ArrayFieldDescriptionTemplate.js +0 -1
  51. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +8 -0
  52. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -0
  53. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +17 -0
  54. package/lib/components/templates/ArrayFieldItemTemplate.d.ts +4 -3
  55. package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -0
  56. package/lib/components/templates/ArrayFieldItemTemplate.js +7 -6
  57. package/lib/components/templates/ArrayFieldTemplate.d.ts +2 -1
  58. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -0
  59. package/lib/components/templates/ArrayFieldTemplate.js +3 -4
  60. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -0
  61. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -0
  62. package/lib/components/templates/ArrayFieldTitleTemplate.js +0 -1
  63. package/lib/components/templates/BaseInputTemplate.d.ts +1 -0
  64. package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -0
  65. package/lib/components/templates/BaseInputTemplate.js +0 -1
  66. package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -0
  67. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -0
  68. package/lib/components/templates/ButtonTemplates/AddButton.js +1 -2
  69. package/lib/components/templates/ButtonTemplates/IconButton.d.ts +1 -0
  70. package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -0
  71. package/lib/components/templates/ButtonTemplates/IconButton.js +4 -5
  72. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +1 -0
  73. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -0
  74. package/lib/components/templates/ButtonTemplates/SubmitButton.js +0 -1
  75. package/lib/components/templates/ButtonTemplates/index.d.ts +1 -0
  76. package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -0
  77. package/lib/components/templates/ButtonTemplates/index.js +3 -4
  78. package/lib/components/templates/DescriptionField.d.ts +1 -0
  79. package/lib/components/templates/DescriptionField.d.ts.map +1 -0
  80. package/lib/components/templates/DescriptionField.js +3 -8
  81. package/lib/components/templates/ErrorList.d.ts +1 -0
  82. package/lib/components/templates/ErrorList.d.ts.map +1 -0
  83. package/lib/components/templates/ErrorList.js +0 -1
  84. package/lib/components/templates/FieldErrorTemplate.d.ts +1 -0
  85. package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -0
  86. package/lib/components/templates/FieldErrorTemplate.js +0 -1
  87. package/lib/components/templates/FieldHelpTemplate.d.ts +1 -0
  88. package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -0
  89. package/lib/components/templates/FieldHelpTemplate.js +0 -1
  90. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +1 -0
  91. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -0
  92. package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -2
  93. package/lib/components/templates/FieldTemplate/Label.d.ts +1 -0
  94. package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -0
  95. package/lib/components/templates/FieldTemplate/Label.js +0 -1
  96. package/lib/components/templates/FieldTemplate/index.d.ts +2 -1
  97. package/lib/components/templates/FieldTemplate/index.d.ts.map +1 -0
  98. package/lib/components/templates/FieldTemplate/index.js +1 -2
  99. package/lib/components/templates/GridTemplate.d.ts +8 -0
  100. package/lib/components/templates/GridTemplate.d.ts.map +1 -0
  101. package/lib/components/templates/GridTemplate.js +10 -0
  102. package/lib/components/templates/ObjectFieldTemplate.d.ts +1 -0
  103. package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -0
  104. package/lib/components/templates/ObjectFieldTemplate.js +2 -3
  105. package/lib/components/templates/TitleField.d.ts +1 -0
  106. package/lib/components/templates/TitleField.d.ts.map +1 -0
  107. package/lib/components/templates/TitleField.js +0 -1
  108. package/lib/components/templates/UnsupportedField.d.ts +1 -0
  109. package/lib/components/templates/UnsupportedField.d.ts.map +1 -0
  110. package/lib/components/templates/UnsupportedField.js +0 -1
  111. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +1 -0
  112. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -0
  113. package/lib/components/templates/WrapIfAdditionalTemplate.js +10 -6
  114. package/lib/components/templates/index.d.ts +1 -0
  115. package/lib/components/templates/index.d.ts.map +1 -0
  116. package/lib/components/templates/index.js +19 -16
  117. package/lib/components/widgets/AltDateTimeWidget.d.ts +1 -0
  118. package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -0
  119. package/lib/components/widgets/AltDateTimeWidget.js +0 -1
  120. package/lib/components/widgets/AltDateWidget.d.ts +1 -0
  121. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -0
  122. package/lib/components/widgets/AltDateWidget.js +0 -1
  123. package/lib/components/widgets/CheckboxWidget.d.ts +1 -0
  124. package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -0
  125. package/lib/components/widgets/CheckboxWidget.js +2 -4
  126. package/lib/components/widgets/CheckboxesWidget.d.ts +1 -0
  127. package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -0
  128. package/lib/components/widgets/CheckboxesWidget.js +0 -1
  129. package/lib/components/widgets/ColorWidget.d.ts +1 -0
  130. package/lib/components/widgets/ColorWidget.d.ts.map +1 -0
  131. package/lib/components/widgets/ColorWidget.js +0 -1
  132. package/lib/components/widgets/DateTimeWidget.d.ts +1 -0
  133. package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -0
  134. package/lib/components/widgets/DateTimeWidget.js +0 -1
  135. package/lib/components/widgets/DateWidget.d.ts +1 -0
  136. package/lib/components/widgets/DateWidget.d.ts.map +1 -0
  137. package/lib/components/widgets/DateWidget.js +0 -1
  138. package/lib/components/widgets/EmailWidget.d.ts +1 -0
  139. package/lib/components/widgets/EmailWidget.d.ts.map +1 -0
  140. package/lib/components/widgets/EmailWidget.js +0 -1
  141. package/lib/components/widgets/FileWidget.d.ts +1 -0
  142. package/lib/components/widgets/FileWidget.d.ts.map +1 -0
  143. package/lib/components/widgets/FileWidget.js +3 -5
  144. package/lib/components/widgets/HiddenWidget.d.ts +1 -0
  145. package/lib/components/widgets/HiddenWidget.d.ts.map +1 -0
  146. package/lib/components/widgets/HiddenWidget.js +0 -1
  147. package/lib/components/widgets/PasswordWidget.d.ts +1 -0
  148. package/lib/components/widgets/PasswordWidget.d.ts.map +1 -0
  149. package/lib/components/widgets/PasswordWidget.js +0 -1
  150. package/lib/components/widgets/RadioWidget.d.ts +1 -0
  151. package/lib/components/widgets/RadioWidget.d.ts.map +1 -0
  152. package/lib/components/widgets/RadioWidget.js +3 -4
  153. package/lib/components/widgets/RangeWidget.d.ts +1 -0
  154. package/lib/components/widgets/RangeWidget.d.ts.map +1 -0
  155. package/lib/components/widgets/RangeWidget.js +0 -1
  156. package/lib/components/widgets/RatingWidget.d.ts +15 -0
  157. package/lib/components/widgets/RatingWidget.d.ts.map +1 -0
  158. package/lib/components/widgets/RatingWidget.js +63 -0
  159. package/lib/components/widgets/SelectWidget.d.ts +1 -0
  160. package/lib/components/widgets/SelectWidget.d.ts.map +1 -0
  161. package/lib/components/widgets/SelectWidget.js +4 -5
  162. package/lib/components/widgets/TextWidget.d.ts +1 -0
  163. package/lib/components/widgets/TextWidget.d.ts.map +1 -0
  164. package/lib/components/widgets/TextWidget.js +0 -1
  165. package/lib/components/widgets/TextareaWidget.d.ts +1 -0
  166. package/lib/components/widgets/TextareaWidget.d.ts.map +1 -0
  167. package/lib/components/widgets/TextareaWidget.js +0 -1
  168. package/lib/components/widgets/TimeWidget.d.ts +1 -0
  169. package/lib/components/widgets/TimeWidget.d.ts.map +1 -0
  170. package/lib/components/widgets/TimeWidget.js +0 -1
  171. package/lib/components/widgets/URLWidget.d.ts +1 -0
  172. package/lib/components/widgets/URLWidget.d.ts.map +1 -0
  173. package/lib/components/widgets/URLWidget.js +0 -1
  174. package/lib/components/widgets/UpDownWidget.d.ts +1 -0
  175. package/lib/components/widgets/UpDownWidget.d.ts.map +1 -0
  176. package/lib/components/widgets/UpDownWidget.js +0 -1
  177. package/lib/components/widgets/index.d.ts +1 -0
  178. package/lib/components/widgets/index.d.ts.map +1 -0
  179. package/lib/components/widgets/index.js +21 -20
  180. package/lib/getDefaultRegistry.d.ts +1 -0
  181. package/lib/getDefaultRegistry.d.ts.map +1 -0
  182. package/lib/getDefaultRegistry.js +3 -4
  183. package/lib/index.d.ts +7 -5
  184. package/lib/index.d.ts.map +1 -0
  185. package/lib/index.js +5 -5
  186. package/lib/tsconfig.tsbuildinfo +1 -1
  187. package/lib/withTheme.d.ts +2 -1
  188. package/lib/withTheme.d.ts.map +1 -0
  189. package/lib/withTheme.js +7 -8
  190. package/package.json +46 -37
  191. package/src/components/Form.tsx +127 -41
  192. package/src/components/RichDescription.tsx +50 -0
  193. package/src/components/fields/ArrayField.tsx +34 -24
  194. package/src/components/fields/BooleanField.tsx +6 -14
  195. package/src/components/fields/LayoutGridField.tsx +967 -0
  196. package/src/components/fields/LayoutHeaderField.tsx +49 -0
  197. package/src/components/fields/LayoutMultiSchemaField.tsx +228 -0
  198. package/src/components/fields/MultiSchemaField.tsx +9 -4
  199. package/src/components/fields/NullField.tsx +1 -1
  200. package/src/components/fields/NumberField.tsx +5 -5
  201. package/src/components/fields/ObjectField.tsx +32 -24
  202. package/src/components/fields/SchemaField.tsx +17 -30
  203. package/src/components/fields/StringField.tsx +2 -2
  204. package/src/components/fields/index.ts +7 -1
  205. package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -2
  206. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +85 -0
  207. package/src/components/templates/ArrayFieldItemTemplate.tsx +18 -57
  208. package/src/components/templates/ArrayFieldTemplate.tsx +10 -8
  209. package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -2
  210. package/src/components/templates/BaseInputTemplate.tsx +4 -4
  211. package/src/components/templates/ButtonTemplates/IconButton.tsx +9 -36
  212. package/src/components/templates/ButtonTemplates/SubmitButton.tsx +1 -1
  213. package/src/components/templates/ButtonTemplates/index.ts +1 -1
  214. package/src/components/templates/DescriptionField.tsx +9 -15
  215. package/src/components/templates/FieldErrorTemplate.tsx +1 -1
  216. package/src/components/templates/FieldHelpTemplate.tsx +1 -1
  217. package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -2
  218. package/src/components/templates/GridTemplate.tsx +15 -0
  219. package/src/components/templates/ObjectFieldTemplate.tsx +5 -3
  220. package/src/components/templates/TitleField.tsx +1 -1
  221. package/src/components/templates/UnsupportedField.tsx +1 -1
  222. package/src/components/templates/WrapIfAdditionalTemplate.tsx +14 -4
  223. package/src/components/templates/index.ts +4 -0
  224. package/src/components/widgets/AltDateWidget.tsx +9 -6
  225. package/src/components/widgets/CheckboxWidget.tsx +5 -5
  226. package/src/components/widgets/CheckboxesWidget.tsx +2 -2
  227. package/src/components/widgets/ColorWidget.tsx +1 -1
  228. package/src/components/widgets/DateTimeWidget.tsx +1 -1
  229. package/src/components/widgets/DateWidget.tsx +1 -1
  230. package/src/components/widgets/EmailWidget.tsx +1 -1
  231. package/src/components/widgets/FileWidget.tsx +5 -5
  232. package/src/components/widgets/PasswordWidget.tsx +1 -1
  233. package/src/components/widgets/RadioWidget.tsx +3 -3
  234. package/src/components/widgets/RangeWidget.tsx +1 -1
  235. package/src/components/widgets/RatingWidget.tsx +129 -0
  236. package/src/components/widgets/SelectWidget.tsx +4 -3
  237. package/src/components/widgets/TextWidget.tsx +1 -1
  238. package/src/components/widgets/TextareaWidget.tsx +3 -3
  239. package/src/components/widgets/TimeWidget.tsx +1 -1
  240. package/src/components/widgets/URLWidget.tsx +1 -1
  241. package/src/components/widgets/UpDownWidget.tsx +1 -1
  242. package/src/components/widgets/index.ts +3 -1
  243. package/src/getDefaultRegistry.ts +1 -1
  244. package/src/index.ts +3 -2
  245. package/src/tsconfig.json +14 -6
  246. package/src/withTheme.tsx +4 -3
  247. package/LICENSE.md +0 -201
  248. package/lib/components/Form.js.map +0 -1
  249. package/lib/components/fields/ArrayField.js.map +0 -1
  250. package/lib/components/fields/BooleanField.js.map +0 -1
  251. package/lib/components/fields/MultiSchemaField.js.map +0 -1
  252. package/lib/components/fields/NullField.js.map +0 -1
  253. package/lib/components/fields/NumberField.js.map +0 -1
  254. package/lib/components/fields/ObjectField.js.map +0 -1
  255. package/lib/components/fields/SchemaField.js.map +0 -1
  256. package/lib/components/fields/StringField.js.map +0 -1
  257. package/lib/components/fields/index.js.map +0 -1
  258. package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +0 -1
  259. package/lib/components/templates/ArrayFieldItemTemplate.js.map +0 -1
  260. package/lib/components/templates/ArrayFieldTemplate.js.map +0 -1
  261. package/lib/components/templates/ArrayFieldTitleTemplate.js.map +0 -1
  262. package/lib/components/templates/BaseInputTemplate.js.map +0 -1
  263. package/lib/components/templates/ButtonTemplates/AddButton.js.map +0 -1
  264. package/lib/components/templates/ButtonTemplates/IconButton.js.map +0 -1
  265. package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +0 -1
  266. package/lib/components/templates/ButtonTemplates/index.js.map +0 -1
  267. package/lib/components/templates/DescriptionField.js.map +0 -1
  268. package/lib/components/templates/ErrorList.js.map +0 -1
  269. package/lib/components/templates/FieldErrorTemplate.js.map +0 -1
  270. package/lib/components/templates/FieldHelpTemplate.js.map +0 -1
  271. package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +0 -1
  272. package/lib/components/templates/FieldTemplate/Label.js.map +0 -1
  273. package/lib/components/templates/FieldTemplate/index.js.map +0 -1
  274. package/lib/components/templates/ObjectFieldTemplate.js.map +0 -1
  275. package/lib/components/templates/TitleField.js.map +0 -1
  276. package/lib/components/templates/UnsupportedField.js.map +0 -1
  277. package/lib/components/templates/WrapIfAdditionalTemplate.js.map +0 -1
  278. package/lib/components/templates/index.js.map +0 -1
  279. package/lib/components/widgets/AltDateTimeWidget.js.map +0 -1
  280. package/lib/components/widgets/AltDateWidget.js.map +0 -1
  281. package/lib/components/widgets/CheckboxWidget.js.map +0 -1
  282. package/lib/components/widgets/CheckboxesWidget.js.map +0 -1
  283. package/lib/components/widgets/ColorWidget.js.map +0 -1
  284. package/lib/components/widgets/DateTimeWidget.js.map +0 -1
  285. package/lib/components/widgets/DateWidget.js.map +0 -1
  286. package/lib/components/widgets/EmailWidget.js.map +0 -1
  287. package/lib/components/widgets/FileWidget.js.map +0 -1
  288. package/lib/components/widgets/HiddenWidget.js.map +0 -1
  289. package/lib/components/widgets/PasswordWidget.js.map +0 -1
  290. package/lib/components/widgets/RadioWidget.js.map +0 -1
  291. package/lib/components/widgets/RangeWidget.js.map +0 -1
  292. package/lib/components/widgets/SelectWidget.js.map +0 -1
  293. package/lib/components/widgets/TextWidget.js.map +0 -1
  294. package/lib/components/widgets/TextareaWidget.js.map +0 -1
  295. package/lib/components/widgets/TimeWidget.js.map +0 -1
  296. package/lib/components/widgets/URLWidget.js.map +0 -1
  297. package/lib/components/widgets/UpDownWidget.js.map +0 -1
  298. package/lib/components/widgets/index.js.map +0 -1
  299. package/lib/getDefaultRegistry.js.map +0 -1
  300. package/lib/index.js.map +0 -1
  301. package/lib/withTheme.js.map +0 -1
@@ -0,0 +1,711 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { PureComponent } from 'react';
4
+ import { ANY_OF_KEY, getDiscriminatorFieldFromSchema, getTemplate, getTestIds, getUiOptions, hashObject, ID_KEY, lookupFromFormContext, mergeObjects, ONE_OF_KEY, PROPERTIES_KEY, READONLY_KEY, UI_OPTIONS_KEY, } from '@rjsf/utils';
5
+ import cloneDeep from 'lodash-es/cloneDeep.js';
6
+ import each from 'lodash-es/each.js';
7
+ import flatten from 'lodash-es/flatten.js';
8
+ import get from 'lodash-es/get.js';
9
+ import has from 'lodash-es/has.js';
10
+ import includes from 'lodash-es/includes.js';
11
+ import intersection from 'lodash-es/intersection.js';
12
+ import isEmpty from 'lodash-es/isEmpty.js';
13
+ import isFunction from 'lodash-es/isFunction.js';
14
+ import isEqual from 'lodash-es/isEqual.js';
15
+ import isObject from 'lodash-es/isObject.js';
16
+ import isPlainObject from 'lodash-es/isPlainObject.js';
17
+ import isString from 'lodash-es/isString.js';
18
+ import isUndefined from 'lodash-es/isUndefined.js';
19
+ import set from 'lodash-es/set.js';
20
+ /** The enumeration of the three different Layout GridTemplate type values
21
+ */
22
+ export var GridType;
23
+ (function (GridType) {
24
+ GridType["ROW"] = "ui:row";
25
+ GridType["COLUMN"] = "ui:col";
26
+ GridType["COLUMNS"] = "ui:columns";
27
+ GridType["CONDITION"] = "ui:condition";
28
+ })(GridType || (GridType = {}));
29
+ /** The enumeration of the different operators within a condition
30
+ */
31
+ export var Operators;
32
+ (function (Operators) {
33
+ Operators["ALL"] = "all";
34
+ Operators["SOME"] = "some";
35
+ Operators["NONE"] = "none";
36
+ })(Operators || (Operators = {}));
37
+ /** The regular expression that is used to detect whether a string contains a lookup key
38
+ */
39
+ export const LOOKUP_REGEX = /^\$lookup=(.+)/;
40
+ /** The constant representing the main layout grid schema option name in the `uiSchema`
41
+ */
42
+ export const LAYOUT_GRID_UI_OPTION = 'layoutGrid';
43
+ /** The constant representing the main layout grid schema option name in the `uiSchema`
44
+ */
45
+ export const LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
46
+ /** The constant representing the global UI Options object potentially contained within the `uiSchema`
47
+ */
48
+ export const UI_GLOBAL_OPTIONS = 'ui:global_options';
49
+ /** Returns either the `value` if it is non-nullish or the fallback
50
+ *
51
+ * @param [value] - The potential value to return if it is non-nullish
52
+ * @param [fallback] - The fallback value to return if `value` is nullish
53
+ * @returns - `value` if it is non-nullish otherwise `fallback`
54
+ */
55
+ function getNonNullishValue(value, fallback) {
56
+ return value ?? fallback;
57
+ }
58
+ /** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
59
+ * described in the uiSchema. To define the grid to use to render the elements within a field in the schema, provide in
60
+ * the uiSchema for that field the object contained under a `ui:layoutGrid` element. E.g. (as a JSON object):
61
+ *
62
+ * ```
63
+ * {
64
+ * "field1" : {
65
+ * "ui:field": "LayoutGridField",
66
+ * "ui:layoutGrid": {
67
+ * "ui:row": { ... }
68
+ * }
69
+ * }
70
+ * }
71
+ * ```
72
+ *
73
+ * The outermost level of a `LayoutGridField` is the `ui:row` that defines the nested rows, columns, and/or condition
74
+ * elements (i.e. "grid elements") in the grid. This definition is either a simple "grid elements" OR an object with
75
+ * native `GridTemplate` implementation specific props and a `children` array of "grid elements". E.g. (as JSON objects):
76
+ *
77
+ * Simple `ui:row` definition, without additional `GridTemplate` props:
78
+ * ```
79
+ * "ui:row": [
80
+ * { "ui:row"|"ui:col"|"ui:columns"|"ui:condition": ... },
81
+ * ...
82
+ * ]
83
+ * ```
84
+ *
85
+ * Complex `ui:row` definition, with additional `GridTemplate` (this example uses @mui/material/Grid2 native props):
86
+ * ```
87
+ * "ui:row": {
88
+ * "spacing": 2,
89
+ * "size": { md": 4 },
90
+ * "alignContent": "flex-start",
91
+ * "className": "GridRow",
92
+ * "children": [
93
+ * { "ui:row"|"ui:col"|"ui:columns"|"ui:condition": ... },
94
+ * ...
95
+ * ]
96
+ * }
97
+ * ```
98
+ *
99
+ * NOTE: Special note about the native `className` prop values. All className values will automatically be looked up in
100
+ * the `formContext.lookupMap` in case they have been defined using a CSS-in-JS approach. In other words, from the
101
+ * example above, if the `Form` was constructed with a `lookupMap` set to `{ GridRow: cssInJs.GridRowClass }`
102
+ * then when rendered, the native `GridTemplate` will get the `className` with the value from
103
+ * `cssInJs.GridRowClass`. This automatic lookup will happen for any of the "grid elements" when rendering with
104
+ * `GridTemplate` props. If multiple className values are present, for example:
105
+ * `{ className: 'GridRow GridColumn' }`, the classNames are split apart, looked up individually, and joined
106
+ * together to form one className with the values from `cssInJs.GridRowClass` and `cssInJs.GridColumnClass`.
107
+ *
108
+ * The `ui:col` grid element is used to specify the list of columns within a grid row. A `ui:col` element can take on
109
+ * several forms: 1) a simple list of dotted-path field names within the root field; 2) a list of objects containing the
110
+ * dotted-path field `name` any other props that are gathered into `ui:options` for the field; 3) a list with a one-off
111
+ * `render` functional component with or without a non-field `name` identifier and any other to-be-spread props; and
112
+ * 4) an object with native `GridTemplate` implementation specific props and a `children` array with 1) or 2) or even a
113
+ * nested `ui:row` or a `ui:condition` containing a `ui:row` (although this should be used carefully). E.g.
114
+ * (as JSON objects):
115
+ *
116
+ * Simple `ui:col` definition, without additional `GridTemplate` props and form 1 only children:
117
+ * ```
118
+ * "ui:col": ["innerField", "inner.grandChild", ...]
119
+ * ```
120
+ *
121
+ * Complicated `ui:col` definition, without additional `GridTemplate` props and form 2 only children:
122
+ * ```
123
+ * "ui:col": [
124
+ * { "name": "innerField", "fullWidth": true },
125
+ * { "name": "inner.grandChild", "convertOther": true },
126
+ * ...
127
+ * ]
128
+ * ```
129
+ *
130
+ * More complicated `ui:col` definition, without additional `GridTemplate` props and form 2 children, one being a
131
+ * one-off `render` functional component without a non-field `name` identifier
132
+ * ```
133
+ * "ui:col": [
134
+ * "innerField",
135
+ * {
136
+ * "render": "WizardNavButton",
137
+ * "isNext": true,
138
+ * "size": "large"
139
+ * }
140
+ * ]
141
+ * ```
142
+ *
143
+ * Most complicated `ui:col` definition, additional `GridTemplate` props and form 1, 2 and 3 children (this example
144
+ * uses @mui/material/Grid2 native props):
145
+ * ```
146
+ * "ui:col": {
147
+ * "size": { "md": 4 },
148
+ * "className": "GridColumn",
149
+ * "children": [
150
+ * "innerField",
151
+ * { "name": "inner.grandChild", "convertOther": true },
152
+ * { "name": "customRender", "render": "CustomRender", toSpread: "prop-value" }
153
+ * { "ui:row|ui:condition": ... }
154
+ * ...
155
+ * ]
156
+ * }
157
+ * ```
158
+ *
159
+ * NOTE: If a `name` prop does not exist or its value does not match any field in a schema, then it is assumed to be a
160
+ * custom `render` component. If the `render` prop does not exist, a null render will occur. If `render` is a
161
+ * string, its value will be looked up in the `formContext.lookupMap` first before defaulting to a null render.
162
+ *
163
+ * The `ui:columns` grid element is syntactic sugar to specify a set of `ui:col` columns that all share the same set of
164
+ * native `GridTemplate` props. In other words rather than writing the following configuration that renders a
165
+ * `<GridTemplate>` element with 3 `<GridTemplate column className="GridColumn col-md-4">` nodes and 2
166
+ * `<GridTemplate column className="col-md-6">` nodes within it (one for each of the fields contained in the `children`
167
+ * list):
168
+ *
169
+ * ```
170
+ * "ui:row": {
171
+ * "children": [
172
+ * {
173
+ * "ui:col": {
174
+ * "className": "GridColumn col-md-4",
175
+ * "children": ["innerField"],
176
+ * }
177
+ * },
178
+ * {
179
+ * "ui:col": {
180
+ * "className": "GridColumn col-md-4",
181
+ * "children": ["inner.grandChild"],
182
+ * }
183
+ * },
184
+ * {
185
+ * "ui:col": {
186
+ * "className": "GridColumn col-md-4",
187
+ * "children": [{ "name": "inner.grandChild2" }],
188
+ * }
189
+ * },
190
+ * {
191
+ * "ui:col": {
192
+ * "className": "col-md-6",
193
+ * "children": ["innerField2"],
194
+ * }
195
+ * },
196
+ * {
197
+ * "ui:col": {
198
+ * "className": "col-md-6",
199
+ * "children": ["inner.grandChild3"],
200
+ * }
201
+ * },
202
+
203
+ * ]
204
+ * }
205
+ * ```
206
+ *
207
+ * One can write this instead:
208
+ * ```
209
+ * "ui:row": {
210
+ * "children": [
211
+ * {
212
+ * "ui:columns": {
213
+ * "className": "GridColumn col-md-4",
214
+ * "children": ["innerField", "inner.grandChild", { "name": "inner.grandChild2", "convertOther": true }],
215
+ * }
216
+ * },
217
+ * {
218
+ * "ui:columns": {
219
+ * "className": "col-md-6",
220
+ * "children": ["innerField2", "inner.grandChild3"],
221
+ * }
222
+ * }
223
+ * ]
224
+ * }
225
+ * ```
226
+ *
227
+ * NOTE: This syntax differs from
228
+ * `"ui:col": { "className": "col-md-6", "children": ["innerField2", "inner.grandChild3"] }` in that
229
+ * the `ui:col` will render the two children fields inside a single `<GridTemplate "className": "col-md-6",>`
230
+ * element.
231
+ *
232
+ * The final grid element, `ui:condition`, allows for conditionally displaying "grid elements" within a row based on the
233
+ * current value of a field as it relates to a (list of) hard-coded value(s). There are four elements that make up a
234
+ * `ui:condition`: 1) the dotted-path `field` name within the root field that makes up the left-side of the condition;
235
+ * 2) the hard-coded `value` (single or list) that makes up the right-side of the condition; 3) the `operator` that
236
+ * controls how the left and right sides of the condition are compared; and 4) the `children` array that defines the
237
+ * "grid elements" to display if the condition passes.
238
+ *
239
+ * A `ui:condition` uses one of three `operators` when deciding if a condition passes: 1) The `all` operator will pass
240
+ * when the right-side and left-side contains all the same value(s); 2) the `some` operator will pass when the
241
+ * right-side and left-side contain as least one value in common; 3) the `none` operator will pass when the right-side
242
+ * and left-side do not contain any values in common. E.g. (as JSON objects):
243
+ *
244
+ * Here is how to render an if-then-else for `field2` which is an enum that has 3 known values and supports allowing
245
+ * any other value:
246
+ * ```
247
+ * "ui:row": [
248
+ * {
249
+ * "ui:condition": {
250
+ * "field": "field2",
251
+ * "operator": "all",
252
+ * "value": "value1",
253
+ * "children": [
254
+ * { "ui:row": [...] },
255
+ * ],
256
+ * }
257
+ * },
258
+ * {
259
+ * "ui:condition": {
260
+ * "field": "field2",
261
+ * "operator": "some",
262
+ * "value": ["value2", "value3"],
263
+ * "children": [
264
+ * { "ui:row": [...] },
265
+ * ],
266
+ * }
267
+ * },
268
+ * {
269
+ * "ui:condition": {
270
+ * "field": "field2",
271
+ * "operator": "none",
272
+ * "value": ["value1", "value2", "value3"],
273
+ * "children": [
274
+ * { "ui:row": [...] },
275
+ * ],
276
+ * }
277
+ * }
278
+ * ]
279
+ * ```
280
+ */
281
+ export default class LayoutGridField extends PureComponent {
282
+ static defaultProps = {
283
+ layoutGridSchema: undefined,
284
+ };
285
+ static TEST_IDS = getTestIds();
286
+ /** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
287
+ * will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
288
+ * copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
289
+ * updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
290
+ * the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
291
+ * field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
292
+ *
293
+ * @param field - The name of the field to pull the existing UI Schema for
294
+ * @param uiProps - Any props that should be put into the field's uiSchema
295
+ * @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
296
+ * @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
297
+ * @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
298
+ */
299
+ static computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
300
+ const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS], {});
301
+ const localUiSchema = get(uiSchema, field);
302
+ const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
303
+ const fieldUiSchema = { ...localUiSchema };
304
+ if (!isEmpty(localUiOptions)) {
305
+ set(fieldUiSchema, [UI_OPTIONS_KEY], localUiOptions);
306
+ }
307
+ if (!isEmpty(globalUiOptions)) {
308
+ // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields
309
+ set(fieldUiSchema, [UI_GLOBAL_OPTIONS], globalUiOptions);
310
+ }
311
+ let { readonly: uiReadonly } = getUiOptions(fieldUiSchema);
312
+ if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) {
313
+ // If we are forcing all widgets to be readonly, OR the schema indicates it is readonly AND the uiSchema does not
314
+ // have an overriding value, then update the uiSchema to set readonly to true. Doing this will
315
+ uiReadonly = true;
316
+ if (has(localUiOptions, READONLY_KEY)) {
317
+ // If the local options has the key value provided in it, then set that one to true
318
+ set(fieldUiSchema, [UI_OPTIONS_KEY, READONLY_KEY], true);
319
+ }
320
+ else {
321
+ // otherwise set the `ui:` version
322
+ set(fieldUiSchema, `ui:${READONLY_KEY}`, true);
323
+ }
324
+ }
325
+ return { fieldUiSchema, uiReadonly };
326
+ }
327
+ /** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
328
+ * depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
329
+ * contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
330
+ * equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
331
+ * common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
332
+ * to match.
333
+ *
334
+ * @param [operator] - The optional operator for the condition
335
+ * @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
336
+ * @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
337
+ * to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
338
+ * This can be an item or a list of items of type unknown
339
+ * @returns - True if the condition matches, false otherwise
340
+ */
341
+ static conditionMatches(operator, datum, value = '$0m3tH1nG Un3xP3cT3d') {
342
+ const data = flatten([datum]).sort();
343
+ const values = flatten([value]).sort();
344
+ switch (operator) {
345
+ case Operators.ALL:
346
+ return isEqual(data, values);
347
+ case Operators.SOME:
348
+ return intersection(data, values).length > 0;
349
+ case Operators.NONE:
350
+ return intersection(data, values).length === 0;
351
+ default:
352
+ return false;
353
+ }
354
+ }
355
+ /** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
356
+ * `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
357
+ * lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
358
+ * When the `className` value contains multiple classNames separated by a space, the lookup will look for a
359
+ * replacement value for each `className` and combine them into one.
360
+ *
361
+ * @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
362
+ * @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
363
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
364
+ * @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
365
+ * @throws - A `TypeError` when the `children` is not an array
366
+ */
367
+ static findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
368
+ let gridProps = {};
369
+ let children = layoutGridSchema[schemaKey];
370
+ if (isPlainObject(children)) {
371
+ const { children: elements, className: toMapClassNames, ...otherProps } = children;
372
+ children = elements;
373
+ if (toMapClassNames) {
374
+ const classes = toMapClassNames.split(' ');
375
+ const className = classes.map((ele) => lookupFromFormContext(registry, ele, ele)).join(' ');
376
+ gridProps = { ...otherProps, className };
377
+ }
378
+ else {
379
+ gridProps = otherProps;
380
+ }
381
+ }
382
+ if (!Array.isArray(children)) {
383
+ throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
384
+ }
385
+ return { children: children, gridProps };
386
+ }
387
+ /** Generates an idSchema for the `schema` using `@rjsf`'s `toIdSchema` util, passing the `baseIdSchema`'s `$id` value
388
+ * as the id prefix.
389
+ *
390
+ * @param schemaUtils - The `SchemaUtilsType` used to call `toIdSchema`
391
+ * @param schema - The schema to generate the idSchema for
392
+ * @param baseIdSchema - The IdSchema for the base
393
+ * @param formData - The formData to pass the `toIdSchema`
394
+ * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
395
+ * @returns - The generated `idSchema` for the `schema`
396
+ */
397
+ static getIdSchema(schemaUtils, baseIdSchema, formData, schema = {}, idSeparator) {
398
+ const baseId = get(baseIdSchema, ID_KEY);
399
+ return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
400
+ }
401
+ /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
402
+ * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
403
+ * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
404
+ * `options`.
405
+ *
406
+ * @param schemaUtils - The `SchemaUtilsType` used to call `retrieveSchema`
407
+ * @param dottedPath - The dotted-path to the field for which to get the schema
408
+ * @param initialSchema - The initial schema to start the search from
409
+ * @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
410
+ * @param initialIdSchema - The initial idSchema to start the search from
411
+ * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
412
+ * @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
413
+ * info if a oneOf/anyOf
414
+ */
415
+ static getSchemaDetailsForField(schemaUtils, dottedPath, initialSchema, formData, initialIdSchema, idSeparator) {
416
+ let rawSchema = initialSchema;
417
+ let idSchema = initialIdSchema;
418
+ const parts = dottedPath.split('.');
419
+ const leafPath = parts.pop(); // pop off the last element in the list as the leaf
420
+ let schema = schemaUtils.retrieveSchema(rawSchema, formData); // always returns an object
421
+ let innerData = formData;
422
+ let isReadonly = schema.readOnly;
423
+ // For all the remaining path parts
424
+ parts.forEach((part) => {
425
+ // dive into the properties of the current schema (when it exists) and get the schema for the next part
426
+ if (has(schema, PROPERTIES_KEY)) {
427
+ rawSchema = get(schema, [PROPERTIES_KEY, part], {});
428
+ idSchema = get(idSchema, part, {});
429
+ }
430
+ else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
431
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
432
+ // When the schema represents a oneOf/anyOf, find the selected schema for it and grab the inner part
433
+ const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
434
+ const selectedIdSchema = LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, selectedSchema, idSeparator);
435
+ rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {});
436
+ idSchema = get(selectedIdSchema, part, {});
437
+ }
438
+ else {
439
+ rawSchema = {};
440
+ }
441
+ // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
442
+ innerData = get(innerData, part, {});
443
+ // Resolve any `$ref`s for the current rawSchema
444
+ schema = schemaUtils.retrieveSchema(rawSchema, innerData);
445
+ isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
446
+ });
447
+ let optionsInfo;
448
+ let isRequired = false;
449
+ // retrieveSchema will return an empty schema in the worst case scenario, convert it to undefined
450
+ if (isEmpty(schema)) {
451
+ schema = undefined;
452
+ }
453
+ if (schema && leafPath) {
454
+ // When we have both a schema and a leafPath...
455
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
456
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
457
+ // Grab the selected schema for the oneOf/anyOf value for the leafPath using the innerData
458
+ schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
459
+ // Generate the idSchema for the oneOf/anyOf value then merge with the existing `idSchema`
460
+ const rawIdSchema = LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, schema, idSeparator);
461
+ idSchema = mergeObjects(rawIdSchema, idSchema);
462
+ }
463
+ isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
464
+ // Now grab the schema from the leafPath of the current schema properties
465
+ schema = get(schema, [PROPERTIES_KEY, leafPath]);
466
+ // Resolve any `$ref`s for the current schema
467
+ schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
468
+ idSchema = get(idSchema, leafPath, {});
469
+ isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
470
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
471
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
472
+ // Set the options if we have a schema with a oneOf/anyOf
473
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
474
+ optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
475
+ }
476
+ }
477
+ return { schema, isRequired, isReadonly, optionsInfo, idSchema };
478
+ }
479
+ /** Gets the custom render component from the `render`, by either determining that it is either already a function or
480
+ * it is a non-function value that can be used to look up the function in the registry. If no function can be found,
481
+ * null is returned.
482
+ *
483
+ * @param render - The potential render function or lookup name to one
484
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
485
+ * @returns - Either a render function if available, or null if not
486
+ */
487
+ static getCustomRenderComponent(render, registry) {
488
+ let customRenderer = render;
489
+ if (isString(customRenderer)) {
490
+ customRenderer = lookupFromFormContext(registry, customRenderer);
491
+ }
492
+ if (isFunction(customRenderer)) {
493
+ return customRenderer;
494
+ }
495
+ return null;
496
+ }
497
+ /** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
498
+ * see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
499
+ * set the `rendered` component with only specified props for that component in the object.
500
+ *
501
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
502
+ * @param gridSchema - The string or object that represents the configuration for the grid field
503
+ * @returns - The UIComponentPropsType computed from the gridSchema
504
+ */
505
+ static computeUIComponentPropsFromGridSchema(registry, gridSchema) {
506
+ let name;
507
+ let UIComponent = null;
508
+ let uiProps = {};
509
+ let rendered;
510
+ if (isString(gridSchema) || isUndefined(gridSchema)) {
511
+ name = gridSchema ?? '';
512
+ }
513
+ else {
514
+ const { name: innerName, render, ...innerProps } = gridSchema;
515
+ name = innerName;
516
+ uiProps = innerProps;
517
+ if (!isEmpty(uiProps)) {
518
+ // Transform any `$lookup=` in the uiProps props with the appropriate value
519
+ each(uiProps, (prop, key) => {
520
+ if (isString(prop)) {
521
+ const match = LOOKUP_REGEX.exec(prop);
522
+ if (Array.isArray(match) && match.length > 1) {
523
+ const name = match[1];
524
+ uiProps[key] = lookupFromFormContext(registry, name, name);
525
+ }
526
+ }
527
+ });
528
+ }
529
+ UIComponent = LayoutGridField.getCustomRenderComponent(render, registry);
530
+ if (!innerName && UIComponent) {
531
+ rendered = _jsx(UIComponent, { ...innerProps, "data-testid": LayoutGridField.TEST_IDS.uiComponent });
532
+ }
533
+ }
534
+ return { name, UIComponent, uiProps, rendered };
535
+ }
536
+ /** Constructs an `LayoutGridField` with the given `props`
537
+ *
538
+ * @param props - The `LayoutGridField` for this template
539
+ */
540
+ constructor(props) {
541
+ super(props);
542
+ }
543
+ /** Generates an `onChange` handler for the field associated with the `dottedPath`. This handler will clone and update
544
+ * the `formData` with the new `value` and the `errorSchema` if an `errSchema` is provided. After updating those two
545
+ * elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
546
+ *
547
+ * @param dottedPath - The dotted-path to the field for which to generate the onChange handler
548
+ * @returns - The `onChange` handling function for the `dottedPath` field
549
+ */
550
+ onFieldChange = (dottedPath) => {
551
+ return (value, errSchema, id) => {
552
+ const { onChange, errorSchema, formData } = this.props;
553
+ const newFormData = cloneDeep(formData || {});
554
+ let newErrorSchema = errorSchema;
555
+ if (errSchema && errorSchema) {
556
+ newErrorSchema = cloneDeep(errorSchema);
557
+ set(newErrorSchema, dottedPath, errSchema);
558
+ }
559
+ set(newFormData, dottedPath, value);
560
+ onChange(newFormData, newErrorSchema, id);
561
+ };
562
+ };
563
+ /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
564
+ * `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
565
+ * the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
566
+ * rendered, otherwise null is returned.
567
+ *
568
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
569
+ * @returns - The rendered the children for the `GridType.CONDITION` or null
570
+ */
571
+ renderCondition(layoutGridSchema) {
572
+ const { formData, registry } = this.props;
573
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps(layoutGridSchema, GridType.CONDITION, registry);
574
+ const { operator, field = '', value } = gridProps;
575
+ const fieldData = get(formData, field, null);
576
+ if (LayoutGridField.conditionMatches(operator, fieldData, value)) {
577
+ return this.renderChildren(children);
578
+ }
579
+ return null;
580
+ }
581
+ /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated
582
+ * into the `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside
583
+ * the `GridTemplate` all the `children` are rendered.
584
+ *
585
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
586
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
587
+ */
588
+ renderCol(layoutGridSchema) {
589
+ const { registry, uiSchema } = this.props;
590
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps(layoutGridSchema, GridType.COLUMN, registry);
591
+ const uiOptions = getUiOptions(uiSchema);
592
+ const GridTemplate = getTemplate('GridTemplate', registry, uiOptions);
593
+ return (_jsx(GridTemplate, { column: true, "data-testid": LayoutGridField.TEST_IDS.col, ...gridProps, children: this.renderChildren(children) }));
594
+ }
595
+ /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated
596
+ * into the `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the
597
+ * outer `GridTemplate`. Each child will have their own rendered `GridTemplate`.
598
+ *
599
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
600
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
601
+ */
602
+ renderColumns(layoutGridSchema) {
603
+ const { registry, uiSchema } = this.props;
604
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps(layoutGridSchema, GridType.COLUMNS, registry);
605
+ const uiOptions = getUiOptions(uiSchema);
606
+ const GridTemplate = getTemplate('GridTemplate', registry, uiOptions);
607
+ return children.map((child) => (_jsx(GridTemplate, { column: true, "data-testid": LayoutGridField.TEST_IDS.col, ...gridProps, children: this.renderChildren([child]) }, `column-${hashObject(child)}`)));
608
+ }
609
+ /** Renders a material-ui `GridTemplate` as a container. The
610
+ * `layoutGridSchema` for the `GridType.ROW` is separated into the `children` and other `gridProps`. The `gridProps`
611
+ * will be spread onto the outer `GridTemplate`. Inside of the `GridTemplate` all of the `children` are rendered.
612
+ *
613
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
614
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
615
+ */
616
+ renderRow(layoutGridSchema) {
617
+ const { registry, uiSchema } = this.props;
618
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps(layoutGridSchema, GridType.ROW, registry);
619
+ const uiOptions = getUiOptions(uiSchema);
620
+ const GridTemplate = getTemplate('GridTemplate', registry, uiOptions);
621
+ return (_jsx(GridTemplate, { ...gridProps, "data-testid": LayoutGridField.TEST_IDS.row, children: this.renderChildren(children) }));
622
+ }
623
+ /** Iterates through all the `childrenLayoutGridSchema`, rendering a nested `LayoutGridField` for each item in the
624
+ * list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
625
+ * `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
626
+ * `childrenLayoutGridSchema` is passed as `layoutGridSchema`.
627
+ *
628
+ * @param childrenLayoutGridSchema - The list of strings or objects that represents the configurations for the
629
+ * children fields
630
+ * @returns - The nested `LayoutGridField`s
631
+ */
632
+ renderChildren(childrenLayoutGridSchema) {
633
+ const { registry, schema: rawSchema, formData } = this.props;
634
+ const { schemaUtils } = registry;
635
+ const schema = schemaUtils.retrieveSchema(rawSchema, formData);
636
+ return childrenLayoutGridSchema.map((layoutGridSchema) => (_createElement(LayoutGridField, { ...this.props, key: `layoutGrid-${hashObject(layoutGridSchema)}`, schema: schema, layoutGridSchema: layoutGridSchema })));
637
+ }
638
+ /** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
639
+ * to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
640
+ * other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
641
+ * specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
642
+ * and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
643
+ * schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
644
+ * `uiSchema`, `errorSchema`, `idSchema` and `formData` drilled down to the dotted-path field, spreading any other
645
+ * props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
646
+ * then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
647
+ * schema was located, but a custom render component was found, then it will be rendered with many of the non-event
648
+ * handling props. If none of the previous render paths are valid, then a null is returned.
649
+ *
650
+ * @param gridSchema - The string or object that represents the configuration for the grid field
651
+ * @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
652
+ */
653
+ renderField(gridSchema) {
654
+ const { schema: initialSchema, uiSchema, errorSchema, idSchema, onBlur, onFocus, formData, readonly, registry, idSeparator, layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
655
+ ...otherProps } = this.props;
656
+ const { fields, schemaUtils } = registry;
657
+ const { SchemaField, LayoutMultiSchemaField } = fields;
658
+ const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
659
+ if (uiComponentProps.rendered) {
660
+ return uiComponentProps.rendered;
661
+ }
662
+ const { name, UIComponent, uiProps } = uiComponentProps;
663
+ const { schema, isRequired, isReadonly, optionsInfo, idSchema: fieldIdSchema, } = LayoutGridField.getSchemaDetailsForField(schemaUtils, name, initialSchema, formData, idSchema, idSeparator);
664
+ if (schema) {
665
+ const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField : SchemaField;
666
+ // Call this function to get the appropriate UISchema, which will always have its `readonly` state matching the
667
+ // `uiReadonly` flag that it returns. This is done since the `SchemaField` will always defer to the `readonly`
668
+ // state in the uiSchema over anything in the props or schema. Because we are implementing the "readonly" state of
669
+ // the `Form` via the prop passed to `LayoutGridField` we need to make sure the uiSchema always has a true value
670
+ // when it is needed
671
+ const { fieldUiSchema, uiReadonly } = LayoutGridField.computeFieldUiSchema(name, uiProps, uiSchema, isReadonly, readonly);
672
+ return (_jsx(Field, { "data-testid": optionsInfo?.hasDiscriminator
673
+ ? LayoutGridField.TEST_IDS.layoutMultiSchemaField
674
+ : LayoutGridField.TEST_IDS.field, ...otherProps, name: name, required: isRequired, readonly: uiReadonly, schema: schema, uiSchema: fieldUiSchema, errorSchema: get(errorSchema, name), idSchema: fieldIdSchema, idSeparator: idSeparator, formData: get(formData, name), onChange: this.onFieldChange(name), onBlur: onBlur, onFocus: onFocus, options: optionsInfo?.options, registry: registry }));
675
+ }
676
+ if (UIComponent) {
677
+ return (_jsx(UIComponent, { "data-testid": LayoutGridField.TEST_IDS.uiComponent, ...otherProps, name: name, required: isRequired, formData: formData, readOnly: !!isReadonly || readonly, errorSchema: errorSchema, uiSchema: uiSchema, schema: initialSchema, idSchema: idSchema, idSeparator: idSeparator, onBlur: onBlur, onFocus: onFocus, registry: registry, ...uiProps }));
678
+ }
679
+ return null;
680
+ }
681
+ /** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
682
+ * `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
683
+ * match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
684
+ * generic `renderField()` function with the `layoutGridSchema`.
685
+ *
686
+ * @returns - the rendered `LayoutGridField`
687
+ */
688
+ render() {
689
+ const { uiSchema } = this.props;
690
+ let { layoutGridSchema } = this.props;
691
+ const uiOptions = getUiOptions(uiSchema);
692
+ if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
693
+ layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
694
+ }
695
+ if (isObject(layoutGridSchema)) {
696
+ if (GridType.ROW in layoutGridSchema) {
697
+ return this.renderRow(layoutGridSchema);
698
+ }
699
+ if (GridType.COLUMN in layoutGridSchema) {
700
+ return this.renderCol(layoutGridSchema);
701
+ }
702
+ if (GridType.COLUMNS in layoutGridSchema) {
703
+ return this.renderColumns(layoutGridSchema);
704
+ }
705
+ if (GridType.CONDITION in layoutGridSchema) {
706
+ return this.renderCondition(layoutGridSchema);
707
+ }
708
+ }
709
+ return this.renderField(layoutGridSchema);
710
+ }
711
+ }