@rebasepro/cms 0.28.2 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/README.md +3 -3
  2. package/dist/collection_editor/_cms_internals.d.ts +0 -1
  3. package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
  4. package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
  5. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
  6. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
  7. package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
  8. package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
  9. package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
  10. package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
  11. package/dist/components/AdditionalFieldValue.d.ts +9 -3
  12. package/dist/components/AdditionalFieldValue.js +7 -4
  13. package/dist/components/AdditionalFieldValue.js.map +1 -1
  14. package/dist/components/CollectionPanel.d.ts +117 -18
  15. package/dist/components/CollectionPanel.js +115 -37
  16. package/dist/components/CollectionPanel.js.map +1 -1
  17. package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
  18. package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
  19. package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
  20. package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
  21. package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
  22. package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
  23. package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
  24. package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
  25. package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
  26. package/dist/components/CollectionTableBinding/column_utils.js +6 -3
  27. package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
  28. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
  29. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
  30. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
  31. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
  32. package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
  33. package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
  34. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
  35. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
  36. package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
  37. package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
  38. package/dist/components/CollectionTableBinding/internal/common.js +88 -4
  39. package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
  40. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
  41. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
  42. package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
  43. package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
  44. package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
  45. package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
  46. package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
  47. package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
  48. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
  49. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
  50. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
  51. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
  52. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
  53. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
  54. package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
  55. package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
  56. package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
  57. package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
  58. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
  59. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
  60. package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
  61. package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
  62. package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
  63. package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
  64. package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
  65. package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
  66. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
  67. package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
  68. package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
  69. package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
  70. package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
  71. package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
  72. package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
  73. package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
  74. package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
  75. package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
  76. package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
  77. package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
  78. package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
  79. package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
  80. package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
  81. package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
  82. package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
  83. package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
  84. package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
  85. package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
  86. package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
  87. package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
  88. package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
  89. package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
  90. package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
  91. package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
  92. package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
  93. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
  94. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
  95. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
  96. package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
  97. package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
  98. package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
  99. package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
  100. package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
  101. package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
  102. package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
  103. package/dist/components/CollectionViewBinding/RowActions.js +60 -0
  104. package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
  105. package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
  106. package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
  107. package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
  108. package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
  109. package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
  110. package/dist/components/CollectionViewBinding/fields.js +47 -0
  111. package/dist/components/CollectionViewBinding/fields.js.map +1 -0
  112. package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
  113. package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
  114. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
  115. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
  116. package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
  117. package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
  118. package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
  119. package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
  120. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
  121. package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
  122. package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
  123. package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
  124. package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
  125. package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
  126. package/dist/components/CollectionsProvider.d.ts +3 -3
  127. package/dist/components/CollectionsProvider.js +4 -4
  128. package/dist/components/CollectionsProvider.js.map +1 -1
  129. package/dist/components/CollectionsScopeContext.d.ts +1 -1
  130. package/dist/components/CollectionsScopeContext.js +1 -1
  131. package/dist/components/CollectionsScopeContext.js.map +1 -1
  132. package/dist/components/DeleteEntityDialog.d.ts +1 -1
  133. package/dist/components/DeleteEntityDialog.js +2 -2
  134. package/dist/components/DeleteEntityDialog.js.map +1 -1
  135. package/dist/components/DetailViewBinding.js +32 -68
  136. package/dist/components/DetailViewBinding.js.map +1 -1
  137. package/dist/components/EditFormActions.js +5 -4
  138. package/dist/components/EditFormActions.js.map +1 -1
  139. package/dist/components/EditViewBinding.d.ts +2 -2
  140. package/dist/components/EditViewBinding.js +25 -15
  141. package/dist/components/EditViewBinding.js.map +1 -1
  142. package/dist/components/EntityDisplayHeader.js +8 -5
  143. package/dist/components/EntityDisplayHeader.js.map +1 -1
  144. package/dist/components/EntityPreviewBinding.js +1 -1
  145. package/dist/components/EntityPreviewBinding.js.map +1 -1
  146. package/dist/components/EntityViewBinding.d.ts +8 -1
  147. package/dist/components/EntityViewBinding.js +43 -14
  148. package/dist/components/EntityViewBinding.js.map +1 -1
  149. package/dist/components/EntityViewBody.d.ts +40 -0
  150. package/dist/components/EntityViewBody.js +90 -0
  151. package/dist/components/EntityViewBody.js.map +1 -0
  152. package/dist/components/FieldValue.d.ts +50 -0
  153. package/dist/components/FieldValue.js +81 -0
  154. package/dist/components/FieldValue.js.map +1 -0
  155. package/dist/components/InlineEntityPreview.js +1 -1
  156. package/dist/components/InlineEntityPreview.js.map +1 -1
  157. package/dist/components/PanelNotFound.d.ts +5 -0
  158. package/dist/components/PanelNotFound.js +21 -0
  159. package/dist/components/PanelNotFound.js.map +1 -0
  160. package/dist/components/RebaseCMS.d.ts +1 -1
  161. package/dist/components/RebaseCMS.js +11 -3
  162. package/dist/components/RebaseCMS.js.map +1 -1
  163. package/dist/components/RebaseNavigation.js +9 -3
  164. package/dist/components/RebaseNavigation.js.map +1 -1
  165. package/dist/components/RebaseShell.js +10 -5
  166. package/dist/components/RebaseShell.js.map +1 -1
  167. package/dist/components/RecordDetail.d.ts +61 -0
  168. package/dist/components/RecordDetail.js +123 -0
  169. package/dist/components/RecordDetail.js.map +1 -0
  170. package/dist/components/RecordForm.d.ts +126 -0
  171. package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
  172. package/dist/components/RecordForm.js.map +1 -0
  173. package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
  174. package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
  175. package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
  176. package/dist/components/ReferenceWidget.d.ts +5 -3
  177. package/dist/components/ReferenceWidget.js +10 -7
  178. package/dist/components/ReferenceWidget.js.map +1 -1
  179. package/dist/components/RelationSelector.js +4 -4
  180. package/dist/components/RelationSelector.js.map +1 -1
  181. package/dist/components/SelectableTable/SelectableTable.js +2 -3
  182. package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
  183. package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
  184. package/dist/components/SelectableTable/SelectionStore.js +1 -1
  185. package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
  186. package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
  187. package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
  188. package/dist/components/SidePanelBinding.js +13 -12
  189. package/dist/components/SidePanelBinding.js.map +1 -1
  190. package/dist/components/collection_prop.d.ts +18 -0
  191. package/dist/components/collection_prop.js +23 -0
  192. package/dist/components/collection_prop.js.map +1 -0
  193. package/dist/components/common/default_entity_actions.js +54 -54
  194. package/dist/components/common/default_entity_actions.js.map +1 -1
  195. package/dist/components/history/EntityHistoryView.d.ts +4 -1
  196. package/dist/components/history/EntityHistoryView.js +1 -1
  197. package/dist/components/history/EntityHistoryView.js.map +1 -1
  198. package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
  199. package/dist/components/index.d.ts +4 -2
  200. package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
  201. package/dist/data_export/export/ExportCollectionAction.js +4 -3
  202. package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
  203. package/dist/data_export/export/additional_fields.d.ts +6 -3
  204. package/dist/data_export/export/additional_fields.js +8 -4
  205. package/dist/data_export/export/additional_fields.js.map +1 -1
  206. package/dist/data_import/import/ImportCollectionAction.js +2 -2
  207. package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
  208. package/dist/form/EntityForm.d.ts +1 -1
  209. package/dist/form/EntityForm.js +255 -150
  210. package/dist/form/EntityForm.js.map +1 -1
  211. package/dist/form/EntityFormActions.js +3 -2
  212. package/dist/form/EntityFormActions.js.map +1 -1
  213. package/dist/form/EntityFormBinding.d.ts +1 -1
  214. package/dist/form/EntityFormBinding.js +22 -11
  215. package/dist/form/EntityFormBinding.js.map +1 -1
  216. package/dist/form/FormField.d.ts +36 -0
  217. package/dist/form/FormField.js +41 -0
  218. package/dist/form/FormField.js.map +1 -0
  219. package/dist/form/FormFieldsContext.d.ts +69 -0
  220. package/dist/form/FormFieldsContext.js +143 -0
  221. package/dist/form/FormFieldsContext.js.map +1 -0
  222. package/dist/form/PropertyFieldBinding.js +4 -4
  223. package/dist/form/PropertyFieldBinding.js.map +1 -1
  224. package/dist/form/collection_showing.d.ts +8 -0
  225. package/dist/form/collection_showing.js +29 -0
  226. package/dist/form/collection_showing.js.map +1 -0
  227. package/dist/form/components/ErrorFocus.js +2 -1
  228. package/dist/form/components/ErrorFocus.js.map +1 -1
  229. package/dist/form/components/FieldBlock.js +3 -1
  230. package/dist/form/components/FieldBlock.js.map +1 -1
  231. package/dist/form/components/FormRail.d.ts +5 -1
  232. package/dist/form/components/FormRail.js +5 -1
  233. package/dist/form/components/FormRail.js.map +1 -1
  234. package/dist/form/components/FormSections.d.ts +5 -1
  235. package/dist/form/components/FormSections.js +11 -4
  236. package/dist/form/components/FormSections.js.map +1 -1
  237. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
  238. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
  239. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
  240. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
  241. package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
  242. package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
  243. package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
  244. package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
  245. package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
  246. package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
  247. package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
  248. package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
  249. package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
  250. package/dist/form/form_dom_ids.d.ts +25 -0
  251. package/dist/form/form_dom_ids.js +42 -0
  252. package/dist/form/form_dom_ids.js.map +1 -0
  253. package/dist/form/index.d.ts +3 -1
  254. package/dist/form/resolve_cell_property.d.ts +5 -0
  255. package/dist/form/resolve_cell_property.js +22 -1
  256. package/dist/form/resolve_cell_property.js.map +1 -1
  257. package/dist/hooks/index.d.ts +1 -1
  258. package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
  259. package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
  260. package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
  261. package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
  262. package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
  263. package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
  264. package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
  265. package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
  266. package/dist/hooks/useBuildSidePanel.js +9 -9
  267. package/dist/hooks/useBuildSidePanel.js.map +1 -1
  268. package/dist/hooks/useEntityDisplay.js +6 -4
  269. package/dist/hooks/useEntityDisplay.js.map +1 -1
  270. package/dist/hooks/useRecordActions.js +2 -2
  271. package/dist/hooks/useRecordActions.js.map +1 -1
  272. package/dist/hooks/useSelectionDialog.d.ts +20 -7
  273. package/dist/hooks/useSelectionDialog.js +29 -8
  274. package/dist/hooks/useSelectionDialog.js.map +1 -1
  275. package/dist/index.d.ts +8 -3
  276. package/dist/index.js +15 -9
  277. package/dist/mcp-view.d.ts +9 -0
  278. package/dist/mcp-view.js +2 -0
  279. package/dist/mcp_view/app_modules.d.ts +29 -0
  280. package/dist/mcp_view/app_modules.js +163 -0
  281. package/dist/mcp_view/app_modules.js.map +1 -0
  282. package/dist/mcp_view/bridge.d.ts +90 -0
  283. package/dist/mcp_view/bridge.js +205 -0
  284. package/dist/mcp_view/bridge.js.map +1 -0
  285. package/dist/mcp_view/code_app.d.ts +65 -0
  286. package/dist/mcp_view/code_app.js +139 -0
  287. package/dist/mcp_view/code_app.js.map +1 -0
  288. package/dist/mcp_view/index.d.ts +54 -0
  289. package/dist/mcp_view/index.js +262 -0
  290. package/dist/mcp_view/index.js.map +1 -0
  291. package/dist/mcp_view/payload.d.ts +78 -0
  292. package/dist/mcp_view/payload.js +155 -0
  293. package/dist/mcp_view/payload.js.map +1 -0
  294. package/dist/mcp_view/screen.d.ts +30 -0
  295. package/dist/mcp_view/screen.js +245 -0
  296. package/dist/mcp_view/screen.js.map +1 -0
  297. package/dist/mcp_view/storage_source.d.ts +14 -0
  298. package/dist/mcp_view/storage_source.js +29 -0
  299. package/dist/mcp_view/storage_source.js.map +1 -0
  300. package/dist/mcp_view/store.d.ts +9 -0
  301. package/dist/mcp_view/store.js +27 -0
  302. package/dist/mcp_view/store.js.map +1 -0
  303. package/dist/mcp_view/tool_driver.d.ts +160 -0
  304. package/dist/mcp_view/tool_driver.js +575 -0
  305. package/dist/mcp_view/tool_driver.js.map +1 -0
  306. package/dist/preview/components/DatePreview.d.ts +34 -1
  307. package/dist/preview/components/DatePreview.js +72 -37
  308. package/dist/preview/components/DatePreview.js.map +1 -1
  309. package/dist/routes/RebaseRoute.js +1 -1
  310. package/dist/routes/RebaseRoute.js.map +1 -1
  311. package/dist/selection/SelectionMenu.d.ts +5 -3
  312. package/dist/selection/SelectionMenu.js +16 -9
  313. package/dist/selection/SelectionMenu.js.map +1 -1
  314. package/dist/selection/index.d.ts +2 -1
  315. package/dist/selection/resolve_selection.d.ts +61 -7
  316. package/dist/selection/resolve_selection.js +93 -11
  317. package/dist/selection/resolve_selection.js.map +1 -1
  318. package/dist/types/components/EntityFormProps.d.ts +60 -10
  319. package/dist/types/fields.d.ts +2 -65
  320. package/dist/util/dataControllerAdapter.d.ts +8 -0
  321. package/dist/util/dataControllerAdapter.js +11 -0
  322. package/dist/util/dataControllerAdapter.js.map +1 -1
  323. package/dist/util/navigation_utils.d.ts +5 -4
  324. package/dist/util/navigation_utils.js +6 -6
  325. package/dist/util/navigation_utils.js.map +1 -1
  326. package/dist/util/propertyConfigMapper.d.ts +8 -0
  327. package/dist/util/propertyConfigMapper.js +16 -2
  328. package/dist/util/propertyConfigMapper.js.map +1 -1
  329. package/package.json +15 -9
  330. package/recipes/README.md +79 -26
  331. package/recipes/approval-queue.tsx +79 -0
  332. package/recipes/bulk-set-status.tsx +23 -17
  333. package/recipes/calendar-view.tsx +28 -23
  334. package/recipes/master-detail.tsx +75 -0
  335. package/recipes/my-preferences.tsx +3 -3
  336. package/recipes/orders-dashboard.tsx +58 -84
  337. package/recipes/site-settings.tsx +4 -4
  338. package/dist/components/EntityFormPanel.d.ts +0 -63
  339. package/dist/components/EntityFormPanel.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"EntityFormBinding.js","names":[],"sources":["../../src/form/EntityFormBinding.tsx"],"sourcesContent":["\nimport type { PluginFormActionProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport { hasEntityId } from \"@rebasepro/common\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { Entity, EntityStatus, EntityValues } from \"@rebasepro/types\";\nimport { AnalyticsEvent } from \"@rebasepro/cms-types\";\nimport type { EntityFormProps, OnUpdateParams } from \"../types/components/EntityFormProps\";\nimport type { EntityFormActionsProps } from \"../types/components/EntityFormActionsProps\";\n\nimport { getLocalChangesBackup } from \"@rebasepro/app\";\n\nimport {\n saveEntityWithCallbacks,\n useAuthController,\n useCustomizationController,\n useData,\n useSnackbarController,\n useTranslation,\n useSlot\n} from \"@rebasepro/app\";\nimport { FormexController } from \"@rebasepro/forms\";\nimport { useAnalyticsController } from \"@rebasepro/app\";\n\nimport {\n getEntityFromCache,\n removeEntityFromCache,\n removeEntityFromMemoryCache,\n saveEntityToCache\n} from \"@rebasepro/app\";\n\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useSidePanel } from \"../hooks/useSidePanel\";\nimport { useAdminContext } from \"../hooks/useAdminContext\";\nimport { EntityForm } from \"./EntityForm\";\nimport {\n getInitialEntityValues,\n getParentLinkValues,\n getTouchedPropertyValues,\n getUnappliedLocalChanges,\n overlayEdit\n} from \"./form_utils\";\n\n/**\n * Props for the admin-connected EntityFormBinding wrapper.\n * Extends EntityFormProps — you can pass all the same props as EntityForm,\n * but the binding provides admin context (save, caching, analytics, plugin slots)\n * automatically.\n */\nexport type EntityFormBindingProps<M extends Record<string, unknown>> = Omit<EntityFormProps<M>,\n | \"onSubmit\"\n | \"onValuesChangeDeferred\"\n | \"onReset\"\n | \"uniqueFieldValidator\"\n | \"lockedPropertyKeys\"\n | \"beforeFields\"\n | \"afterFields\"\n | \"pluginActions\"\n | \"computedInitialValues\"\n | \"hasLocalChanges\"\n | \"localChangesData\"\n | \"manualApplyLocalChanges\"\n | \"localChangesCacheKey\"\n | \"onClearLocalChanges\"\n>;\n\n/**\n * admin-connected wrapper around EntityForm.\n *\n * Provides all backend concerns that the headless EntityForm delegates via callbacks:\n * - Save via the data layer (`saveEntityWithCallbacks`)\n * - Unique field validation via the data layer\n * - Entity caching (local changes backup/restore)\n * - Plugin slots (form.before, form.after, form.actions)\n * - Snackbar notifications on save success/error\n * - Analytics events\n * - Navigation via side entity controller\n *\n * Use this component inside the admin (`<RebaseShell>`).\n * For headless usage outside the admin, use `EntityForm` directly.\n *\n * @group Components\n */\nexport function EntityFormBinding<M extends Record<string, unknown>>({\n path,\n entityId: entityIdProp,\n collection,\n entity,\n initialStatus,\n onSaved,\n onValuesModified,\n onEntityChange,\n onStatusChange,\n openEntityMode = \"full_screen\",\n navigateBack: navigateBackProp,\n initialDirtyValues,\n ...restProps\n}: EntityFormBindingProps<M>) {\n\n const { t } = useTranslation();\n const sidePanelController = useSidePanel();\n const collectionRegistryController = useCollectionRegistryController();\n const authController = useAuthController();\n const dataClient = useData();\n const snackbarController = useSnackbarController();\n const customizationController = useCustomizationController();\n const context = useAdminContext();\n const analyticsController = useAnalyticsController();\n\n const [status, setStatus] = useState<EntityStatus>(initialStatus);\n // The record a create made, until the `entity` prop names it: from the\n // create on, the form edits that record, and a caller that does not hand\n // it back would otherwise leave an \"existing\" form with nothing behind it.\n const [savedEntity, setSavedEntity] = useState<Entity<M> | undefined>(undefined);\n const currentEntity = entity ?? (status === \"existing\" ? savedEntity : undefined);\n // A new record given an id is created under it — a settings record kept\n // at a known key, a profile keyed by its user. Where the collection\n // declares its key property, the id is that property's value, set and\n // locked; where it declares none, it is the id the record is created with.\n // A copy never keeps the id: it is the original's.\n const idKeyValues = useMemo(\n () => newRecordIdValues(collection, status, entityIdProp),\n [collection, status, entityIdProp]);\n const [entityId, setEntityId] = useState<string | number | undefined>(() => {\n if (status === \"copy\") return undefined;\n if (status === \"new\") return Object.keys(idKeyValues).length > 0 ? undefined : entityIdProp;\n return entityIdProp;\n });\n\n // A record created under `parent/{id}/{relation}` belongs to that parent:\n // the server stamps the link on the create, so the form opens with it set\n // and does not offer it for editing. See `getParentLinkValues`.\n //\n // Keyed on the two callbacks rather than the controller. The controller is\n // a new object whenever its provider renders, which would hand the form a\n // new baseline each time.\n const { getCollection, getParentEntityIds } = collectionRegistryController;\n const parentLinkValues = useMemo(\n () => status === \"new\" || status === \"copy\"\n ? { ...getParentLinkValues({ getCollection, getParentEntityIds }, path, collection), ...idKeyValues }\n : {},\n [getCollection, getParentEntityIds, path, collection, status, idKeyValues]\n );\n const lockedPropertyKeys = useMemo(() => Object.keys(parentLinkValues), [parentLinkValues]);\n\n // --- Compute initial values with local changes ---\n const baseInitialValues = useMemo(\n () => ({\n ...getInitialEntityValues(authController, collection, path, status, currentEntity, customizationController.propertyConfigs),\n ...parentLinkValues\n }),\n [authController, collection, path, status, currentEntity, customizationController.propertyConfigs, parentLinkValues]\n );\n\n const localChangesBackup = getLocalChangesBackup(collection);\n const autoApplyLocalChanges = localChangesBackup === \"auto_apply\";\n const manualApplyLocalChanges = localChangesBackup === \"manual_apply\";\n\n const localChangesDataRaw = useMemo(() => hasEntityId(entityId)\n ? getEntityFromCache(path + \"/\" + entityId)\n : getEntityFromCache(path + \"#new\"), [entityId, path]);\n\n const [localChangesCleared, setLocalChangesCleared] = useState<boolean>(false);\n\n // `initialDirtyValues` is deliberately *not* merged in here any more. This\n // value is the form's baseline, and an edit folded into the baseline is\n // indistinguishable from saved data — which is how an edit carried over\n // from the side panel arrived reading \"Saved\". {@link EntityForm} applies\n // it as an overlay on the values instead, so the difference survives.\n //\n // The auto-applied local-changes backup is still folded in, unchanged, and\n // has the same shape of problem: a restored draft opens undirty and cannot\n // be saved until a field is touched. Left as it is rather than changed\n // blind, since nothing here exercises that path.\n const computedInitialValues = useMemo(() => {\n return autoApplyLocalChanges && localChangesDataRaw\n ? overlayEdit(baseInitialValues, localChangesDataRaw as Partial<M>)\n : baseInitialValues;\n }, [autoApplyLocalChanges, localChangesDataRaw, baseInitialValues]);\n\n const localChangesData = useMemo(() => {\n if (!localChangesDataRaw) return undefined;\n // What the form opens showing: the baseline plus any edit handed over by\n // the layout this one replaced. See {@link getUnappliedLocalChanges} for\n // why the banner is measured against that and not against the baseline.\n const openingValues = initialDirtyValues\n ? overlayEdit(computedInitialValues, initialDirtyValues)\n : computedInitialValues;\n return getUnappliedLocalChanges(\n localChangesDataRaw as Partial<M>,\n openingValues as Partial<M>\n );\n }, [localChangesDataRaw, computedInitialValues, initialDirtyValues]);\n\n const hasLocalChanges = !localChangesCleared && !!localChangesData && Object.keys(localChangesData as object).length > 0;\n\n const localChangesCacheKey = useMemo(() => {\n return (status === \"new\" || status === \"copy\") ? path + \"#new\" : path + \"/\" + entityId;\n }, [status, path, entityId]);\n\n // --- Navigate back ---\n const navigateBack = useCallback(() => {\n if (navigateBackProp) {\n navigateBackProp();\n return;\n }\n if (openEntityMode === \"side_panel\" || openEntityMode === \"dialog\") {\n sidePanelController.close();\n } else {\n window.history.back();\n }\n }, [navigateBackProp, openEntityMode, sidePanelController]);\n\n // --- Cache operations ---\n const clearDirtyCache = useCallback(() => {\n if (status === \"new\" || status === \"copy\") {\n removeEntityFromMemoryCache(path + \"#new\");\n removeEntityFromCache(path + \"#new\");\n } else {\n removeEntityFromMemoryCache(path + \"/\" + entityId);\n removeEntityFromCache(path + \"/\" + entityId);\n }\n }, [status, path, entityId]);\n\n const onReset = useCallback(() => {\n clearDirtyCache();\n }, [clearDirtyCache]);\n\n const onValuesChangeDeferred = useCallback((values: M, controller: FormexController<M>) => {\n const key = (status === \"new\" || status === \"copy\") ? path + \"#new\" : path + \"/\" + entityId;\n if (controller.dirty) {\n const touchedValues = getTouchedPropertyValues(values, controller.touched);\n if (Object.keys(touchedValues).length > 0) {\n saveEntityToCache(key, touchedValues);\n } else {\n removeEntityFromCache(key);\n }\n }\n }, [status, path, entityId]);\n\n // --- Save via data layer ---\n const onSubmit = useCallback(async (values: M, formex: FormexController<M>): Promise<Entity<M> | void> => {\n try {\n const savedEntity = await saveEntityWithCallbacks<M>({\n path,\n entityId,\n values,\n previousValues: currentEntity?.values,\n collection,\n status,\n // The version the form's baseline is — it follows the live\n // record, tag and all — so a save made against a version that\n // someone has since replaced is refused, not written over it.\n ifMatch: status === \"existing\" ? currentEntity?.etag : undefined,\n data: dataClient,\n context,\n afterSave: (updatedEntity: Entity<M>) => {\n setSavedEntity(updatedEntity);\n clearDirtyCache();\n onValuesModified?.(false, updatedEntity.values);\n onEntityChange?.(updatedEntity);\n setStatus(\"existing\");\n setEntityId(updatedEntity.id);\n onStatusChange?.(\"existing\");\n\n if (onSaved) {\n onSaved({\n entity: updatedEntity,\n status,\n path,\n entityId: updatedEntity.id,\n collection\n });\n }\n },\n afterSaveError: (e: Error) => {\n // Refused because the record moved on between the last\n // version the form saw and this save. The new version is\n // on its way over the listener, and the form rebases the\n // edit onto it, marking what changed underneath.\n // Read by code, not `instanceof`: the error can come from\n // another copy of the types package.\n const changedElsewhere = typeof e === \"object\" && e !== null\n && \"code\" in e && e.code === \"PRECONDITION_FAILED\";\n snackbarController.open({\n type: \"error\",\n title: t(\"error_saving_entity\"),\n message: changedElsewhere ? t(\"error_record_changed_elsewhere\") : e?.message\n });\n console.error(\"Error saving entity\", path, entityId, e);\n }\n });\n\n const autoSave = collection.formAutoSave;\n if (!autoSave) {\n snackbarController.open({\n type: \"success\",\n message: `${collection.singularName ?? collection.name}: ${t(\"saved_correctly\")}`\n });\n }\n\n const eventName: AnalyticsEvent = status === \"new\"\n ? \"new_entity_saved\"\n : (status === \"copy\" ? \"entity_copied\" : (status === \"existing\" ? \"entity_edited\" : \"unmapped_event\"));\n analyticsController.onAnalyticsEvent?.(eventName, { path });\n\n return savedEntity;\n } catch (e: unknown) {\n console.error(e);\n throw e;\n }\n }, [path, entityId, currentEntity, collection, status, dataClient, context, clearDirtyCache, onValuesModified, onEntityChange, onSaved, onStatusChange, snackbarController, analyticsController, t]);\n\n // --- Unique field validation via data layer ---\n const uniqueFieldValidator = useCallback(async ({\n name,\n value\n }: { name: string; value: unknown }) => {\n try {\n const accessor = dataClient.collection(path);\n const { data } = await accessor.find({\n where: { [name]: [\"==\", value] },\n limit: 2\n });\n const otherEntities = hasEntityId(entityId) ? data.filter(e => String(e.id) !== String(entityId)) : data;\n return otherEntities.length === 0;\n } catch (e: unknown) {\n console.error(\"Error checking unique field\", e);\n return true;\n }\n }, [dataClient, path, entityId]);\n\n // --- Plugin slots ---\n const parentCollectionSlugs = collectionRegistryController.getParentCollectionSlugs(path);\n const parentEntityIds = collectionRegistryController.getParentEntityIds(path);\n\n // Build a minimal formContext for plugin slot props — the full one is built inside EntityForm\n const formActionProps: PluginFormActionProps = useMemo(() => ({\n entityId,\n parentCollectionSlugs,\n parentEntityIds,\n path,\n status,\n collection: collection as AdminCollection,\n context,\n // Genuinely absent here, and `PluginFormActionProps` declares it\n // optional — so this needed no conversion at all. Asserting a\n // `FormContext` onto `undefined` told every plugin slot the opposite of\n // the comment three lines up.\n formContext: undefined,\n openEntityMode,\n disabled: false\n }), [entityId, parentCollectionSlugs, parentEntityIds, path, status, collection, context, openEntityMode]);\n\n // `form.actions` is rendered by the entity view's identity bar, which has\n // the real formContext and does not cost a footer. Rendering it here too\n // would show Autofill twice.\n const pluginFormBefore = useSlot(\"form.before\", formActionProps);\n const pluginFormAfter = useSlot(\"form.after\", formActionProps);\n\n return (\n <EntityForm<M>\n {...restProps}\n path={path}\n entityId={entityIdProp}\n collection={collection}\n entity={currentEntity}\n initialStatus={initialStatus}\n initialDirtyValues={initialDirtyValues}\n // Not handed down: `onSubmit` above reports the save, for Save and\n // autosave alike. The form reporting it too called it twice.\n onValuesModified={onValuesModified}\n onEntityChange={onEntityChange}\n onStatusChange={onStatusChange}\n openEntityMode={openEntityMode}\n navigateBack={navigateBack}\n // Headless callbacks\n onSubmit={onSubmit}\n onValuesChangeDeferred={onValuesChangeDeferred}\n onReset={onReset}\n uniqueFieldValidator={uniqueFieldValidator}\n lockedPropertyKeys={lockedPropertyKeys}\n // Slots\n beforeFields={pluginFormBefore}\n afterFields={pluginFormAfter}\n pluginActions={[]}\n // Local changes\n computedInitialValues={computedInitialValues as Partial<M>}\n hasLocalChanges={hasLocalChanges}\n localChangesData={localChangesData as Partial<M>}\n manualApplyLocalChanges={manualApplyLocalChanges}\n localChangesCacheKey={localChangesCacheKey}\n onClearLocalChanges={() => setLocalChangesCleared(true)}\n />\n );\n}\n\n/**\n * The key property's value for a new record created under a known id: the id,\n * under the one property the collection marks `isId`. Empty when the record\n * is not new, has no id, or the collection declares no single key property —\n * then the id travels as the id the record is created with instead.\n */\nfunction newRecordIdValues(\n collection: AdminCollection,\n status: EntityStatus,\n entityId: string | number | undefined\n): Record<string, unknown> {\n if (status !== \"new\" || entityId === undefined) return {};\n const keys = Object.entries(collection.properties ?? {})\n .filter(([, property]) => typeof property === \"object\" && property !== null && \"isId\" in property && Boolean(property.isId))\n .map(([key]) => key);\n return keys.length === 1 ? { [keys[0]]: entityId } : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,kBAAqD,EACjE,MACA,UAAU,cACV,YACA,QACA,eACA,SACA,kBACA,gBACA,gBACA,iBAAiB,eACjB,cAAc,kBACd,oBACA,GAAG,aACuB;CAE1B,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,sBAAsB,aAAa;CACzC,MAAM,+BAA+B,gCAAgC;CACrE,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,aAAa,QAAQ;CAC3B,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,0BAA0B,2BAA2B;CAC3D,MAAM,UAAU,gBAAgB;CAChC,MAAM,sBAAsB,uBAAuB;CAEnD,MAAM,CAAC,QAAQ,aAAa,SAAuB,aAAa;CAIhE,MAAM,CAAC,aAAa,kBAAkB,SAAgC,KAAA,CAAS;CAC/E,MAAM,gBAAgB,WAAW,WAAW,aAAa,cAAc,KAAA;CAMvE,MAAM,cAAc,cACV,kBAAkB,YAAY,QAAQ,YAAY,GACxD;EAAC;EAAY;EAAQ;CAAY,CAAC;CACtC,MAAM,CAAC,UAAU,eAAe,eAA4C;EACxE,IAAI,WAAW,QAAQ,OAAO,KAAA;EAC9B,IAAI,WAAW,OAAO,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,SAAS,IAAI,KAAA,IAAY;EAC/E,OAAO;CACX,CAAC;CASD,MAAM,EAAE,eAAe,uBAAuB;CAC9C,MAAM,mBAAmB,cACf,WAAW,SAAS,WAAW,SAC/B;EAAE,GAAG,oBAAoB;GAAE;GAAe;EAAmB,GAAG,MAAM,UAAU;EAAG,GAAG;CAAY,IAClG,CAAC,GACP;EAAC;EAAe;EAAoB;EAAM;EAAY;EAAQ;CAAW,CAC7E;CACA,MAAM,qBAAqB,cAAc,OAA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ACb;EACA,UAAU;CACd,IAAI;EAAC;EAAU;EAAuB;EAAiB;EAAM;EAAQ;EAAY;EAAS;CAAc,CAAC;CAKzG,MAAM,mBAAmB,QAAQ,eAAe,eAAe;CAC/D,MAAM,kBAAkB,QAAQ,cAAc,eAAe;CAE7D,OACI,oBAAC,YAAD;EACI,GAAI;EACE;EACN,UAAU;EACE;EACZ,QAAQ;EACO;EACK;EAGF;EACF;EACA;EACA;EACF;EAEJ;EACc;EACf;EACa;EACF;EAEpB,cAAc;EACd,aAAa;EACb,eAAe,CAAC;EAEO;EACN;EACC;EACO;EACH;EACtB,2BAA2B,uBAAuB,IAAI;CACzD,CAAA;AAET;;;;;;;AAQA,SAAS,kBACL,YACA,QACA,UACuB;CACvB,IAAI,WAAW,SAAS,aAAa,KAAA,GAAW,OAAO,CAAC;CACxD,MAAM,OAAO,OAAO,QAAQ,WAAW,cAAc,CAAC,CAAC,CAAC,CACnD,QAAQ,GAAG,cAAc,OAAO,aAAa,YAAY,aAAa,QAAQ,UAAU,YAAY,QAAQ,SAAS,IAAI,CAAC,CAAC,CAC3H,KAAK,CAAC,SAAS,GAAG;CACvB,OAAO,KAAK,WAAW,IAAI,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC;AAC1D"}
1
+ {"version":3,"file":"EntityFormBinding.js","names":[],"sources":["../../src/form/EntityFormBinding.tsx"],"sourcesContent":["\nimport type { PluginFormActionProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport { hasEntityId } from \"@rebasepro/common\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { Entity, EntityStatus, EntityValues } from \"@rebasepro/types\";\nimport { AnalyticsEvent } from \"@rebasepro/cms-types\";\nimport type { EntityFormProps, OnSavedParams } from \"../types/components/EntityFormProps\";\nimport type { EntityFormActionsProps } from \"../types/components/EntityFormActionsProps\";\n\nimport { getLocalChangesBackup } from \"@rebasepro/app\";\n\nimport {\n saveEntityWithCallbacks,\n useAuthController,\n useCustomizationController,\n useData,\n useSnackbarController,\n useTranslation,\n useSlot\n} from \"@rebasepro/app\";\nimport { FormexController } from \"@rebasepro/forms\";\nimport { useAnalyticsController } from \"@rebasepro/app\";\n\nimport {\n getEntityFromCache,\n removeEntityFromCache,\n removeEntityFromMemoryCache,\n saveEntityToCache\n} from \"@rebasepro/app\";\n\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useSidePanel } from \"../hooks/useSidePanel\";\nimport { useAdminContext } from \"../hooks/useAdminContext\";\nimport { EntityForm } from \"./EntityForm\";\nimport { entityOfRow, idOfRow, rowOfEntity } from \"@rebasepro/app\";\nimport {\n getInitialEntityValues,\n getParentLinkValues,\n getTouchedPropertyValues,\n getUnappliedLocalChanges,\n overlayEdit\n} from \"./form_utils\";\n\n/**\n * Props for the admin-connected EntityFormBinding wrapper.\n * Extends EntityFormProps — you can pass all the same props as EntityForm,\n * but the binding provides admin context (save, caching, analytics, plugin slots)\n * automatically.\n */\nexport type EntityFormBindingProps<M extends Record<string, unknown>> = Omit<EntityFormProps<M>,\n | \"onSubmit\"\n | \"onValuesChangeDeferred\"\n | \"onReset\"\n | \"uniqueFieldValidator\"\n | \"lockedPropertyKeys\"\n | \"beforeFields\"\n | \"afterFields\"\n | \"pluginActions\"\n | \"computedInitialValues\"\n | \"hasLocalChanges\"\n | \"localChangesData\"\n | \"manualApplyLocalChanges\"\n | \"localChangesCacheKey\"\n | \"onClearLocalChanges\"\n>;\n\n/**\n * admin-connected wrapper around EntityForm.\n *\n * Provides all backend concerns that the headless EntityForm delegates via callbacks:\n * - Save via the data layer (`saveEntityWithCallbacks`)\n * - Unique field validation via the data layer\n * - Entity caching (local changes backup/restore)\n * - Plugin slots (form.before, form.after, form.actions)\n * - Snackbar notifications on save success/error\n * - Analytics events\n * - Navigation via side entity controller\n *\n * Use this component inside the admin (`<RebaseShell>`).\n * For headless usage outside the admin, use `EntityForm` directly.\n *\n * @group Components\n */\nexport function EntityFormBinding<M extends Record<string, unknown>>({\n path,\n id: entityIdProp,\n collection,\n row,\n initialStatus,\n onSaved,\n onValuesModified,\n onRowChange,\n onStatusChange,\n openEntityMode = \"full_screen\",\n navigateBack: navigateBackProp,\n initialDirtyValues,\n ...restProps\n}: EntityFormBindingProps<M>) {\n\n const { t } = useTranslation();\n const sidePanelController = useSidePanel();\n const collectionRegistryController = useCollectionRegistryController();\n const authController = useAuthController();\n const dataClient = useData();\n const snackbarController = useSnackbarController();\n const customizationController = useCustomizationController();\n const context = useAdminContext();\n const analyticsController = useAnalyticsController();\n\n const [status, setStatus] = useState<EntityStatus>(initialStatus);\n // The record the row stands for: the admin's own, where the row came from\n // it — its version kept, so a save is refused over a newer one.\n const entity = useMemo(() => row\n ? entityOfRow(row, entityIdProp ?? idOfRow(row, collection) ?? \"\", path, collection) as Entity<M>\n : undefined, [row, entityIdProp, path, collection]);\n // The record a create made, until the `row` prop names it: from the\n // create on, the form edits that record, and a caller that does not hand\n // it back would otherwise leave an \"existing\" form with nothing behind it.\n const [savedEntity, setSavedEntity] = useState<Entity<M> | undefined>(undefined);\n const currentEntity = entity ?? (status === \"existing\" ? savedEntity : undefined);\n // A new record given an id is created under it — a settings record kept\n // at a known key, a profile keyed by its user. Where the collection\n // declares its key property, the id is that property's value, set and\n // locked; where it declares none, it is the id the record is created with.\n // A copy never keeps the id: it is the original's.\n const idKeyValues = useMemo(\n () => newRecordIdValues(collection, status, entityIdProp),\n [collection, status, entityIdProp]);\n const [entityId, setEntityId] = useState<string | number | undefined>(() => {\n if (status === \"copy\") return undefined;\n if (status === \"new\") return Object.keys(idKeyValues).length > 0 ? undefined : entityIdProp;\n return entityIdProp;\n });\n\n // A record created under `parent/{id}/{relation}` belongs to that parent:\n // the server stamps the link on the create, so the form opens with it set\n // and does not offer it for editing. See `getParentLinkValues`.\n //\n // Keyed on the two callbacks rather than the controller. The controller is\n // a new object whenever its provider renders, which would hand the form a\n // new baseline each time.\n const { getCollection, getParentEntityIds } = collectionRegistryController;\n const parentLinkValues = useMemo(\n () => status === \"new\" || status === \"copy\"\n ? { ...getParentLinkValues({ getCollection, getParentEntityIds }, path, collection), ...idKeyValues }\n : {},\n [getCollection, getParentEntityIds, path, collection, status, idKeyValues]\n );\n const lockedPropertyKeys = useMemo(() => Object.keys(parentLinkValues), [parentLinkValues]);\n\n // --- Compute initial values with local changes ---\n const baseInitialValues = useMemo(\n () => ({\n ...getInitialEntityValues(authController, collection, path, status, currentEntity, customizationController.propertyConfigs),\n ...parentLinkValues\n }),\n [authController, collection, path, status, currentEntity, customizationController.propertyConfigs, parentLinkValues]\n );\n\n const localChangesBackup = getLocalChangesBackup(collection);\n const autoApplyLocalChanges = localChangesBackup === \"auto_apply\";\n const manualApplyLocalChanges = localChangesBackup === \"manual_apply\";\n\n const localChangesDataRaw = useMemo(() => hasEntityId(entityId)\n ? getEntityFromCache(path + \"/\" + entityId)\n : getEntityFromCache(path + \"#new\"), [entityId, path]);\n\n const [localChangesCleared, setLocalChangesCleared] = useState<boolean>(false);\n\n // `initialDirtyValues` is deliberately *not* merged in here any more. This\n // value is the form's baseline, and an edit folded into the baseline is\n // indistinguishable from saved data — which is how an edit carried over\n // from the side panel arrived reading \"Saved\". {@link EntityForm} applies\n // it as an overlay on the values instead, so the difference survives.\n //\n // The auto-applied local-changes backup is still folded in, unchanged, and\n // has the same shape of problem: a restored draft opens undirty and cannot\n // be saved until a field is touched. Left as it is rather than changed\n // blind, since nothing here exercises that path.\n const computedInitialValues = useMemo(() => {\n return autoApplyLocalChanges && localChangesDataRaw\n ? overlayEdit(baseInitialValues, localChangesDataRaw as Partial<M>)\n : baseInitialValues;\n }, [autoApplyLocalChanges, localChangesDataRaw, baseInitialValues]);\n\n const localChangesData = useMemo(() => {\n if (!localChangesDataRaw) return undefined;\n // What the form opens showing: the baseline plus any edit handed over by\n // the layout this one replaced. See {@link getUnappliedLocalChanges} for\n // why the banner is measured against that and not against the baseline.\n const openingValues = initialDirtyValues\n ? overlayEdit(computedInitialValues, initialDirtyValues)\n : computedInitialValues;\n return getUnappliedLocalChanges(\n localChangesDataRaw as Partial<M>,\n openingValues as Partial<M>\n );\n }, [localChangesDataRaw, computedInitialValues, initialDirtyValues]);\n\n const hasLocalChanges = !localChangesCleared && !!localChangesData && Object.keys(localChangesData as object).length > 0;\n\n const localChangesCacheKey = useMemo(() => {\n return (status === \"new\" || status === \"copy\") ? path + \"#new\" : path + \"/\" + entityId;\n }, [status, path, entityId]);\n\n // --- Navigate back ---\n const navigateBack = useCallback(() => {\n if (navigateBackProp) {\n navigateBackProp();\n return;\n }\n if (openEntityMode === \"side_panel\" || openEntityMode === \"dialog\") {\n sidePanelController.close();\n } else {\n window.history.back();\n }\n }, [navigateBackProp, openEntityMode, sidePanelController]);\n\n // --- Cache operations ---\n const clearDirtyCache = useCallback(() => {\n if (status === \"new\" || status === \"copy\") {\n removeEntityFromMemoryCache(path + \"#new\");\n removeEntityFromCache(path + \"#new\");\n } else {\n removeEntityFromMemoryCache(path + \"/\" + entityId);\n removeEntityFromCache(path + \"/\" + entityId);\n }\n }, [status, path, entityId]);\n\n const onReset = useCallback(() => {\n clearDirtyCache();\n }, [clearDirtyCache]);\n\n const onValuesChangeDeferred = useCallback((values: M, controller: FormexController<M>) => {\n const key = (status === \"new\" || status === \"copy\") ? path + \"#new\" : path + \"/\" + entityId;\n if (controller.dirty) {\n const touchedValues = getTouchedPropertyValues(values, controller.touched);\n if (Object.keys(touchedValues).length > 0) {\n saveEntityToCache(key, touchedValues);\n } else {\n removeEntityFromCache(key);\n }\n }\n }, [status, path, entityId]);\n\n // --- Save via data layer ---\n const onSubmit = useCallback(async (values: M, formex: FormexController<M>): Promise<{ row: Record<string, unknown>; id: string | number } | void> => {\n try {\n const savedEntity = await saveEntityWithCallbacks<M>({\n path,\n entityId,\n values,\n previousValues: currentEntity?.values,\n collection,\n status,\n // The version the form's baseline is — it follows the live\n // record, tag and all — so a save made against a version that\n // someone has since replaced is refused, not written over it.\n ifMatch: status === \"existing\" ? currentEntity?.etag : undefined,\n data: dataClient,\n context,\n afterSave: (updatedEntity: Entity<M>) => {\n setSavedEntity(updatedEntity);\n clearDirtyCache();\n onValuesModified?.(false, updatedEntity.values);\n onRowChange?.({ row: rowOfEntity(updatedEntity, collection), id: String(updatedEntity.id) });\n setStatus(\"existing\");\n setEntityId(updatedEntity.id);\n onStatusChange?.(\"existing\");\n\n if (onSaved) {\n onSaved({\n row: rowOfEntity(updatedEntity, collection),\n id: String(updatedEntity.id),\n status,\n path,\n collection\n });\n }\n },\n afterSaveError: (e: Error) => {\n // Refused because the record moved on between the last\n // version the form saw and this save. The new version is\n // on its way over the listener, and the form rebases the\n // edit onto it, marking what changed underneath.\n // Read by code, not `instanceof`: the error can come from\n // another copy of the types package.\n const changedElsewhere = typeof e === \"object\" && e !== null\n && \"code\" in e && e.code === \"PRECONDITION_FAILED\";\n snackbarController.open({\n type: \"error\",\n title: t(\"error_saving_entity\"),\n message: changedElsewhere ? t(\"error_record_changed_elsewhere\") : e?.message\n });\n console.error(\"Error saving entity\", path, entityId, e);\n }\n });\n\n const autoSave = collection.formAutoSave;\n if (!autoSave) {\n snackbarController.open({\n type: \"success\",\n message: `${collection.singularName ?? collection.name}: ${t(\"saved_correctly\")}`\n });\n }\n\n const eventName: AnalyticsEvent = status === \"new\"\n ? \"new_entity_saved\"\n : (status === \"copy\" ? \"entity_copied\" : (status === \"existing\" ? \"entity_edited\" : \"unmapped_event\"));\n analyticsController.onAnalyticsEvent?.(eventName, { path });\n\n return { row: rowOfEntity(savedEntity, collection), id: savedEntity.id };\n } catch (e: unknown) {\n console.error(e);\n throw e;\n }\n }, [path, entityId, currentEntity, collection, status, dataClient, context, clearDirtyCache, onValuesModified, onRowChange, onSaved, onStatusChange, snackbarController, analyticsController, t]);\n\n // --- Unique field validation via data layer ---\n const uniqueFieldValidator = useCallback(async ({\n name,\n value\n }: { name: string; value: unknown }) => {\n try {\n const accessor = dataClient.collection(path);\n const { data } = await accessor.find({\n where: { [name]: [\"==\", value] },\n limit: 2\n });\n const otherEntities = hasEntityId(entityId) ? data.filter(e => String(e.id) !== String(entityId)) : data;\n return otherEntities.length === 0;\n } catch (e: unknown) {\n console.error(\"Error checking unique field\", e);\n return true;\n }\n }, [dataClient, path, entityId]);\n\n // --- Plugin slots ---\n const parentCollectionSlugs = collectionRegistryController.getParentCollectionSlugs(path);\n const parentEntityIds = collectionRegistryController.getParentEntityIds(path);\n\n // Build a minimal formContext for plugin slot props — the full one is built inside EntityForm\n const formActionProps: PluginFormActionProps = useMemo(() => ({\n id: entityId,\n parentCollectionSlugs,\n parentEntityIds,\n path,\n status,\n collection: collection as AdminCollection,\n context,\n // Genuinely absent here, and `PluginFormActionProps` declares it\n // optional — so this needed no conversion at all. Asserting a\n // `FormContext` onto `undefined` told every plugin slot the opposite of\n // the comment three lines up.\n formContext: undefined,\n openEntityMode,\n disabled: false\n }), [entityId, parentCollectionSlugs, parentEntityIds, path, status, collection, context, openEntityMode]);\n\n // `form.actions` is rendered by the entity view's identity bar, which has\n // the real formContext and does not cost a footer. Rendering it here too\n // would show Autofill twice.\n const pluginFormBefore = useSlot(\"form.before\", formActionProps);\n const pluginFormAfter = useSlot(\"form.after\", formActionProps);\n\n return (\n <EntityForm<M>\n {...restProps}\n path={path}\n id={entityIdProp}\n collection={collection}\n row={currentEntity ? rowOfEntity(currentEntity, collection) : undefined}\n initialStatus={initialStatus}\n initialDirtyValues={initialDirtyValues}\n // Not handed down: `onSubmit` above reports the save, for Save and\n // autosave alike. The form reporting it too called it twice.\n onValuesModified={onValuesModified}\n onStatusChange={onStatusChange}\n openEntityMode={openEntityMode}\n navigateBack={navigateBack}\n // Headless callbacks\n onSubmit={onSubmit}\n onValuesChangeDeferred={onValuesChangeDeferred}\n onReset={onReset}\n uniqueFieldValidator={uniqueFieldValidator}\n lockedPropertyKeys={lockedPropertyKeys}\n // Slots\n beforeFields={pluginFormBefore}\n afterFields={pluginFormAfter}\n pluginActions={[]}\n // Local changes\n computedInitialValues={computedInitialValues as Partial<M>}\n hasLocalChanges={hasLocalChanges}\n localChangesData={localChangesData as Partial<M>}\n manualApplyLocalChanges={manualApplyLocalChanges}\n localChangesCacheKey={localChangesCacheKey}\n onClearLocalChanges={() => setLocalChangesCleared(true)}\n />\n );\n}\n\n/**\n * The key property's value for a new record created under a known id: the id,\n * under the one property the collection marks `isId`. Empty when the record\n * is not new, has no id, or the collection declares no single key property —\n * then the id travels as the id the record is created with instead.\n */\nfunction newRecordIdValues(\n collection: AdminCollection,\n status: EntityStatus,\n entityId: string | number | undefined\n): Record<string, unknown> {\n if (status !== \"new\" || entityId === undefined) return {};\n const keys = Object.entries(collection.properties ?? {})\n .filter(([, property]) => typeof property === \"object\" && property !== null && \"isId\" in property && Boolean(property.isId))\n .map(([key]) => key);\n return keys.length === 1 ? { [keys[0]]: entityId } : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,SAAgB,kBAAqD,EACjE,MACA,IAAI,cACJ,YACA,KACA,eACA,SACA,kBACA,aACA,gBACA,iBAAiB,eACjB,cAAc,kBACd,oBACA,GAAG,aACuB;CAE1B,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,sBAAsB,aAAa;CACzC,MAAM,+BAA+B,gCAAgC;CACrE,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,aAAa,QAAQ;CAC3B,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,0BAA0B,2BAA2B;CAC3D,MAAM,UAAU,gBAAgB;CAChC,MAAM,sBAAsB,uBAAuB;CAEnD,MAAM,CAAC,QAAQ,aAAa,SAAuB,aAAa;CAGhE,MAAM,SAAS,cAAc,MACvB,YAAY,KAAK,gBAAgB,QAAQ,KAAK,UAAU,KAAK,IAAI,MAAM,UAAU,IACjF,KAAA,GAAW;EAAC;EAAK;EAAc;EAAM;CAAU,CAAC;CAItD,MAAM,CAAC,aAAa,kBAAkB,SAAgC,KAAA,CAAS;CAC/E,MAAM,gBAAgB,WAAW,WAAW,aAAa,cAAc,KAAA;CAMvE,MAA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AM,OAAO,OAAO,QAAQ,WAAW,cAAc,CAAC,CAAC,CAAC,CACnD,QAAQ,GAAG,cAAc,OAAO,aAAa,YAAY,aAAa,QAAQ,UAAU,YAAY,QAAQ,SAAS,IAAI,CAAC,CAAC,CAC3H,KAAK,CAAC,SAAS,GAAG;CACvB,OAAO,KAAK,WAAW,IAAI,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC;AAC1D"}
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ /**
3
+ * Props for {@link FormField}.
4
+ *
5
+ * @group Form custom fields
6
+ */
7
+ export interface FormFieldProps {
8
+ /** The key of the property, or of the `additionalFields` entry, to render. */
9
+ name: string;
10
+ }
11
+ /**
12
+ * One field of the record form it is rendered in, bound to the collection's
13
+ * property of that name: the same label, density, disabled and hidden rules,
14
+ * validation and autosave as the generated form gives it.
15
+ *
16
+ * Place it anywhere inside a record form — among `RecordForm`'s children,
17
+ * or in a collection's `formView.Builder` — to arrange the fields yourself.
18
+ * A field drawn this way counts as shown: where the form is laid out with
19
+ * `<FormField>`s, it validates the fields they render and no others.
20
+ *
21
+ * Typing in one field does not re-render another.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * <RecordForm collection="orders" id={id}>
26
+ * <div className="grid grid-cols-2 gap-4">
27
+ * <FormField name="customer"/>
28
+ * <FormField name="status"/>
29
+ * </div>
30
+ * <FormField name="notes"/>
31
+ * </RecordForm>
32
+ * ```
33
+ *
34
+ * @group Form custom fields
35
+ */
36
+ export declare function FormField({ name }: FormFieldProps): React.ReactNode;
@@ -0,0 +1,41 @@
1
+ import { useFormFieldsContext } from "./FormFieldsContext.js";
2
+ import { useEffect } from "react";
3
+ //#region src/form/FormField.tsx
4
+ /**
5
+ * One field of the record form it is rendered in, bound to the collection's
6
+ * property of that name: the same label, density, disabled and hidden rules,
7
+ * validation and autosave as the generated form gives it.
8
+ *
9
+ * Place it anywhere inside a record form — among `RecordForm`'s children,
10
+ * or in a collection's `formView.Builder` — to arrange the fields yourself.
11
+ * A field drawn this way counts as shown: where the form is laid out with
12
+ * `<FormField>`s, it validates the fields they render and no others.
13
+ *
14
+ * Typing in one field does not re-render another.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * <RecordForm collection="orders" id={id}>
19
+ * <div className="grid grid-cols-2 gap-4">
20
+ * <FormField name="customer"/>
21
+ * <FormField name="status"/>
22
+ * </div>
23
+ * <FormField name="notes"/>
24
+ * </RecordForm>
25
+ * ```
26
+ *
27
+ * @group Form custom fields
28
+ */
29
+ function FormField({ name }) {
30
+ const fields = useFormFieldsContext();
31
+ const field = fields?.fieldFor(name);
32
+ const register = field ? fields?.register : void 0;
33
+ useEffect(() => register?.(name), [register, name]);
34
+ if (!fields) throw new Error(`<FormField name="${name}"/> is rendered outside a record form. Render it inside RecordForm, as its children, in a collection's \`formView.Builder\`, or another child of EntityForm.`);
35
+ if (!field) throw new Error(`<FormField name="${name}"/>: the collection "${fields.collection.slug}" has no property or additional field named "${name}".`);
36
+ return fields.renderField(field);
37
+ }
38
+ //#endregion
39
+ export { FormField };
40
+
41
+ //# sourceMappingURL=FormField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormField.js","names":[],"sources":["../../src/form/FormField.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { useFormFieldsContext } from \"./FormFieldsContext\";\n\n/**\n * Props for {@link FormField}.\n *\n * @group Form custom fields\n */\nexport interface FormFieldProps {\n /** The key of the property, or of the `additionalFields` entry, to render. */\n name: string;\n}\n\n/**\n * One field of the record form it is rendered in, bound to the collection's\n * property of that name: the same label, density, disabled and hidden rules,\n * validation and autosave as the generated form gives it.\n *\n * Place it anywhere inside a record form — among `RecordForm`'s children,\n * or in a collection's `formView.Builder` — to arrange the fields yourself.\n * A field drawn this way counts as shown: where the form is laid out with\n * `<FormField>`s, it validates the fields they render and no others.\n *\n * Typing in one field does not re-render another.\n *\n * @example\n * ```tsx\n * <RecordForm collection=\"orders\" id={id}>\n * <div className=\"grid grid-cols-2 gap-4\">\n * <FormField name=\"customer\"/>\n * <FormField name=\"status\"/>\n * </div>\n * <FormField name=\"notes\"/>\n * </RecordForm>\n * ```\n *\n * @group Form custom fields\n */\nexport function FormField({ name }: FormFieldProps): React.ReactNode {\n const fields = useFormFieldsContext();\n const field = fields?.fieldFor(name);\n const register = field ? fields?.register : undefined;\n useEffect(() => register?.(name), [register, name]);\n if (!fields) {\n throw new Error(`<FormField name=\"${name}\"/> is rendered outside a record form. Render it inside RecordForm, as its children, in a collection's \\`formView.Builder\\`, or another child of EntityForm.`);\n }\n if (!field) {\n throw new Error(`<FormField name=\"${name}\"/>: the collection \"${fields.collection.slug}\" has no property or additional field named \"${name}\".`);\n }\n return fields.renderField(field);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,UAAU,EAAE,QAAyC;CACjE,MAAM,SAAS,qBAAqB;CACpC,MAAM,QAAQ,QAAQ,SAAS,IAAI;CACnC,MAAM,WAAW,QAAQ,QAAQ,WAAW,KAAA;CAC5C,gBAAgB,WAAW,IAAI,GAAG,CAAC,UAAU,IAAI,CAAC;CAClD,IAAI,CAAC,QACD,MAAM,IAAI,MAAM,oBAAoB,KAAK,6JAA6J;CAE1M,IAAI,CAAC,OACD,MAAM,IAAI,MAAM,oBAAoB,KAAK,uBAAuB,OAAO,WAAW,KAAK,+CAA+C,KAAK,GAAG;CAElJ,OAAO,OAAO,YAAY,KAAK;AACnC"}
@@ -0,0 +1,69 @@
1
+ import React from "react";
2
+ import type { Entity } from "@rebasepro/types";
3
+ import type { AdminCollection } from "@rebasepro/cms-types";
4
+ import type { AuthState, Property } from "@rebasepro/types";
5
+ import type { ResolvedFormField } from "@rebasepro/app";
6
+ import type { ResolvePropertyProps } from "@rebasepro/common";
7
+ import type { FormContext } from "../types/fields.js";
8
+ type Values = Record<string, unknown>;
9
+ type CollectionProperty = NonNullable<AdminCollection["properties"][string]>;
10
+ /**
11
+ * What a record form gives every field it renders: the rules that place,
12
+ * label, disable and hide one, and the context it binds to.
13
+ *
14
+ * `EntityForm` provides it, and every field of the form is drawn through
15
+ * {@link FormFieldsContextValue.renderField} — the generated sections, the
16
+ * rail and `<FormField>` alike — so a field has one set of rules wherever it
17
+ * sits.
18
+ *
19
+ * Its identity changes only with what a field draws from it, never with a
20
+ * keystroke: a field reads the values it depends on through the form's
21
+ * selector, so typing in one field does not re-render another.
22
+ */
23
+ export interface FormFieldsContextValue {
24
+ collection: AdminCollection<Values>;
25
+ path: string;
26
+ entityId?: string | number;
27
+ entity?: Entity<Values>;
28
+ status: "new" | "existing" | "copy";
29
+ /** The memoised context the bindings take; see `EntityForm`. */
30
+ fieldContext: FormContext<Values>;
31
+ /** What the form opened with, which `conditions` read as the previous values. */
32
+ previousValues: Partial<Values>;
33
+ /** Values the record changed to underneath an edit, by top-level key. */
34
+ underlyingChanges: Record<string, unknown>;
35
+ autoSave: boolean;
36
+ /** The field that takes focus when a new record opens. */
37
+ autoFocusKey?: string;
38
+ /** Every control's height: `large` in the record form, `medium` in a compact one. */
39
+ fieldSize: "medium" | "large";
40
+ /** Every rule that disables a field, except a save in progress. */
41
+ isFieldDisabled: (key: string, property: CollectionProperty) => boolean;
42
+ /** One field, with every rule of the form. */
43
+ renderField: (field: ResolvedFormField) => React.ReactNode;
44
+ /** The field for a key — placed as the form's layout places it, when it does — or nothing for a key the collection lacks. */
45
+ fieldFor: (key: string) => ResolvedFormField | undefined;
46
+ /** Marks a field as shown, for validation; returns the call that unmarks it. */
47
+ register: (key: string) => () => void;
48
+ }
49
+ export declare const FormFieldsContext: React.Context<FormFieldsContextValue | undefined>;
50
+ export declare function useFormFieldsContext(): FormFieldsContextValue | undefined;
51
+ /**
52
+ * Whether a record shows a field, for these values, to this user: no
53
+ * `conditions.hidden` rule hides it and the user's field access lets them read
54
+ * it. The form's cells and the read-only view both ask here, so a field a rule
55
+ * hides while editing is not on the page that reads the record either.
56
+ */
57
+ export declare function isFieldShown<M extends Record<string, unknown>>(props: {
58
+ propertyKey: string;
59
+ property: Property;
60
+ values: Partial<M>;
61
+ previousValues?: Partial<M>;
62
+ path: string;
63
+ entityId?: string | number;
64
+ propertyConfigs?: ResolvePropertyProps<M>["propertyConfigs"];
65
+ authController: AuthState;
66
+ }): boolean;
67
+ /** What {@link FormFieldsContextValue.renderField} renders: one cell, keyed for a list. */
68
+ export declare function renderFormField(field: ResolvedFormField): React.ReactNode;
69
+ export {};
@@ -0,0 +1,143 @@
1
+ import { AdditionalFieldValue } from "../components/AdditionalFieldValue.js";
2
+ import { FieldBlock, isSelfLabellingProperty, spanClass } from "./components/FieldBlock.js";
3
+ import { labelsInsideControl } from "./label_placement.js";
4
+ import { resolveFormProperty } from "./resolve_form_properties.js";
5
+ import { PropertyFieldBinding } from "./PropertyFieldBinding.js";
6
+ import React, { useCallback, useContext } from "react";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { deepEqual } from "fast-equals";
9
+ import { AlignLeftIcon, cls, paperMixin } from "@rebasepro/ui";
10
+ import { effectiveAccess } from "@rebasepro/common";
11
+ import { isHidden, rowOfEntity, useAuthController, useCustomizationController, useRebaseContext } from "@rebasepro/app";
12
+ import { useFormexSelector } from "@rebasepro/forms";
13
+ //#region src/form/FormFieldsContext.tsx
14
+ var FormFieldsContext = React.createContext(void 0);
15
+ function useFormFieldsContext() {
16
+ return useContext(FormFieldsContext);
17
+ }
18
+ /**
19
+ * Whether a record shows a field, for these values, to this user: no
20
+ * `conditions.hidden` rule hides it and the user's field access lets them read
21
+ * it. The form's cells and the read-only view both ask here, so a field a rule
22
+ * hides while editing is not on the page that reads the record either.
23
+ */
24
+ function isFieldShown(props) {
25
+ const { property } = props;
26
+ if (!property.conditions?.hidden && !effectiveAccess(property)) return true;
27
+ const shown = resolveFormProperty({
28
+ ...props,
29
+ ignoreMissingFields: true
30
+ });
31
+ return shown !== null && !isHidden(shown);
32
+ }
33
+ /** What {@link FormFieldsContextValue.renderField} renders: one cell, keyed for a list. */
34
+ function renderFormField(field) {
35
+ return /* @__PURE__ */ jsx(FormFieldCell, { field }, `${field.additional ? "additional" : "field"}_${field.key}`);
36
+ }
37
+ /**
38
+ * One field of the form. Memoised on its placement: it re-renders when the
39
+ * form's rules change, or when one of the few things it reads from the values
40
+ * changes — whether a rule hides it, whether the record changed under it,
41
+ * whether a save is running.
42
+ */
43
+ var FormFieldCell = React.memo(function FieldCell({ field }) {
44
+ const fields = useContext(FormFieldsContext);
45
+ if (!fields) throw new Error("INTERNAL: a form field rendered outside its form");
46
+ const authController = useAuthController();
47
+ const customizationController = useCustomizationController();
48
+ const rebaseContext = useRebaseContext();
49
+ const { collection, path, entityId, entity, previousValues, underlyingChanges, autoSave, autoFocusKey, isFieldDisabled, fieldContext } = fields;
50
+ const property = field.additional ? void 0 : collection.properties?.[field.key];
51
+ const shown = useFormexSelector(useCallback((formex) => {
52
+ if (!property) return true;
53
+ return isFieldShown({
54
+ propertyKey: field.key,
55
+ property,
56
+ values: formex.values,
57
+ previousValues,
58
+ path,
59
+ entityId,
60
+ propertyConfigs: customizationController.propertyConfigs,
61
+ authController
62
+ });
63
+ }, [
64
+ property,
65
+ field.key,
66
+ previousValues,
67
+ path,
68
+ entityId,
69
+ customizationController.propertyConfigs,
70
+ authController
71
+ ]));
72
+ const underlyingValueHasChanged = useFormexSelector(useCallback((formex) => field.key in underlyingChanges && !deepEqual(formex.values[field.key], underlyingChanges[field.key]), [field.key, underlyingChanges]));
73
+ const submitting = useFormexSelector(useCallback((formex) => !autoSave && formex.isSubmitting, [autoSave]));
74
+ if (field.additional) {
75
+ const additionalField = collection.additionalFields?.find((f) => f.key === field.key);
76
+ if (!additionalField || !entity) return null;
77
+ const AdditionalFieldBuilder = additionalField.Builder;
78
+ if (!AdditionalFieldBuilder && !additionalField.value) throw new Error("When using additional fields you need to provide a Builder or a value");
79
+ const row = rowOfEntity(entity, collection);
80
+ const id = String(entity.id);
81
+ const child = AdditionalFieldBuilder ? /* @__PURE__ */ jsx(AdditionalFieldBuilder, {
82
+ row,
83
+ id,
84
+ context: rebaseContext
85
+ }) : /* @__PURE__ */ jsx("div", {
86
+ className: "w-full",
87
+ children: /* @__PURE__ */ jsx(AdditionalFieldValue, {
88
+ field: additionalField,
89
+ row,
90
+ id,
91
+ context: rebaseContext
92
+ })
93
+ });
94
+ return /* @__PURE__ */ jsx("div", {
95
+ className: spanClass(field.span),
96
+ children: /* @__PURE__ */ jsx(FieldBlock, {
97
+ propertyKey: field.key,
98
+ showLabel: true,
99
+ label: additionalField.name,
100
+ icon: /* @__PURE__ */ jsx(AlignLeftIcon, { size: 14 }),
101
+ children: /* @__PURE__ */ jsx("div", {
102
+ className: cls(paperMixin, "w-full min-h-12 p-4 md:p-6 overflow-x-auto no-scrollbar"),
103
+ children: child
104
+ })
105
+ })
106
+ });
107
+ }
108
+ if (!property) {
109
+ console.warn(`Property ${field.key} not found in collection ${collection.name} in properties or additional fields. Skipping.`);
110
+ return null;
111
+ }
112
+ if (!shown) return null;
113
+ const disabled = submitting || isFieldDisabled(field.key, property);
114
+ const selfLabelling = isSelfLabellingProperty(property);
115
+ const labelInside = !selfLabelling && labelsInsideControl(property, customizationController.propertyConfigs);
116
+ const bindingProps = {
117
+ propertyKey: field.key,
118
+ disabled,
119
+ property,
120
+ includeDescription: false,
121
+ hideLabel: !selfLabelling && !labelInside,
122
+ underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,
123
+ context: fieldContext,
124
+ partOfArray: false,
125
+ minimalistView: false,
126
+ size: fields.fieldSize,
127
+ autoFocus: autoFocusKey === field.key
128
+ };
129
+ return /* @__PURE__ */ jsx("div", {
130
+ className: spanClass(field.span),
131
+ children: /* @__PURE__ */ jsx(FieldBlock, {
132
+ propertyKey: field.key,
133
+ property,
134
+ showLabel: !selfLabelling && !labelInside,
135
+ labelInside,
136
+ children: /* @__PURE__ */ jsx(PropertyFieldBinding, { ...bindingProps })
137
+ })
138
+ });
139
+ });
140
+ //#endregion
141
+ export { FormFieldsContext, isFieldShown, renderFormField, useFormFieldsContext };
142
+
143
+ //# sourceMappingURL=FormFieldsContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldsContext.js","names":[],"sources":["../../src/form/FormFieldsContext.tsx"],"sourcesContent":["import React, { useCallback, useContext } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\";\nimport type { Entity } from \"@rebasepro/types\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\nimport type { AuthState, Property } from \"@rebasepro/types\";\nimport type { ResolvedFormField } from \"@rebasepro/app\";\nimport { isHidden, useAuthController, useCustomizationController, useRebaseContext } from \"@rebasepro/app\";\nimport type { ResolvePropertyProps } from \"@rebasepro/common\";\nimport { effectiveAccess } from \"@rebasepro/common\";\nimport { AlignLeftIcon, cls, paperMixin } from \"@rebasepro/ui\";\nimport { FormexController, useFormexSelector } from \"@rebasepro/forms\";\n\nimport type { FormContext, PropertyFieldBindingProps } from \"../types/fields\";\nimport { AdditionalFieldValue } from \"../components/AdditionalFieldValue\";\nimport { rowOfEntity } from \"@rebasepro/app\";\nimport { FieldBlock, isSelfLabellingProperty, LABEL_ICON_SIZE, spanClass } from \"./components/FieldBlock\";\nimport { labelsInsideControl } from \"./label_placement\";\nimport { PropertyFieldBinding } from \"./PropertyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\n\ntype Values = Record<string, unknown>;\ntype CollectionProperty = NonNullable<AdminCollection[\"properties\"][string]>;\n\n/**\n * What a record form gives every field it renders: the rules that place,\n * label, disable and hide one, and the context it binds to.\n *\n * `EntityForm` provides it, and every field of the form is drawn through\n * {@link FormFieldsContextValue.renderField} — the generated sections, the\n * rail and `<FormField>` alike — so a field has one set of rules wherever it\n * sits.\n *\n * Its identity changes only with what a field draws from it, never with a\n * keystroke: a field reads the values it depends on through the form's\n * selector, so typing in one field does not re-render another.\n */\nexport interface FormFieldsContextValue {\n collection: AdminCollection<Values>;\n path: string;\n entityId?: string | number;\n entity?: Entity<Values>;\n status: \"new\" | \"existing\" | \"copy\";\n /** The memoised context the bindings take; see `EntityForm`. */\n fieldContext: FormContext<Values>;\n /** What the form opened with, which `conditions` read as the previous values. */\n previousValues: Partial<Values>;\n /** Values the record changed to underneath an edit, by top-level key. */\n underlyingChanges: Record<string, unknown>;\n autoSave: boolean;\n /** The field that takes focus when a new record opens. */\n autoFocusKey?: string;\n /** Every control's height: `large` in the record form, `medium` in a compact one. */\n fieldSize: \"medium\" | \"large\";\n /** Every rule that disables a field, except a save in progress. */\n isFieldDisabled: (key: string, property: CollectionProperty) => boolean;\n /** One field, with every rule of the form. */\n renderField: (field: ResolvedFormField) => React.ReactNode;\n /** The field for a key — placed as the form's layout places it, when it does — or nothing for a key the collection lacks. */\n fieldFor: (key: string) => ResolvedFormField | undefined;\n /** Marks a field as shown, for validation; returns the call that unmarks it. */\n register: (key: string) => () => void;\n}\n\nexport const FormFieldsContext = React.createContext<FormFieldsContextValue | undefined>(undefined);\n\nexport function useFormFieldsContext(): FormFieldsContextValue | undefined {\n return useContext(FormFieldsContext);\n}\n\n/**\n * Whether a record shows a field, for these values, to this user: no\n * `conditions.hidden` rule hides it and the user's field access lets them read\n * it. The form's cells and the read-only view both ask here, so a field a rule\n * hides while editing is not on the page that reads the record either.\n */\nexport function isFieldShown<M extends Record<string, unknown>>(props: {\n propertyKey: string;\n property: Property;\n values: Partial<M>;\n previousValues?: Partial<M>;\n path: string;\n entityId?: string | number;\n propertyConfigs?: ResolvePropertyProps<M>[\"propertyConfigs\"];\n authController: AuthState;\n}): boolean {\n const { property } = props;\n // Most fields carry neither rule, and resolving one runs its dynamicProps.\n if (!property.conditions?.hidden && !effectiveAccess(property)) return true;\n const shown = resolveFormProperty<M>({\n ...props,\n ignoreMissingFields: true\n });\n return shown !== null && !isHidden(shown);\n}\n\n/** What {@link FormFieldsContextValue.renderField} renders: one cell, keyed for a list. */\nexport function renderFormField(field: ResolvedFormField): React.ReactNode {\n return <FormFieldCell key={`${field.additional ? \"additional\" : \"field\"}_${field.key}`} field={field}/>;\n}\n\n/**\n * One field of the form. Memoised on its placement: it re-renders when the\n * form's rules change, or when one of the few things it reads from the values\n * changes — whether a rule hides it, whether the record changed under it,\n * whether a save is running.\n */\nconst FormFieldCell = React.memo(function FieldCell({ field }: { field: ResolvedFormField }) {\n\n const fields = useContext(FormFieldsContext);\n if (!fields) throw new Error(\"INTERNAL: a form field rendered outside its form\");\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n const rebaseContext = useRebaseContext();\n\n const {\n collection,\n path,\n entityId,\n entity,\n previousValues,\n underlyingChanges,\n autoSave,\n autoFocusKey,\n isFieldDisabled,\n fieldContext\n } = fields;\n\n const property = field.additional ? undefined : collection.properties?.[field.key];\n\n // A field a rule hides for these values, or that this user may not read,\n // takes its label with it: the binding renders nothing, and a heading over\n // nothing is worse. Selected as a yes or no, so the cell re-renders when\n // that answer flips and not on every value its rule reads.\n const selectShown = useCallback((formex: FormexController<Values>): boolean => {\n if (!property) return true;\n return isFieldShown({\n propertyKey: field.key,\n property,\n values: formex.values,\n previousValues,\n path,\n entityId,\n propertyConfigs: customizationController.propertyConfigs,\n authController\n });\n }, [property, field.key, previousValues, path, entityId, customizationController.propertyConfigs, authController]);\n const shown = useFormexSelector(selectShown);\n\n const selectUnderlyingChanged = useCallback((formex: FormexController<Values>): boolean =>\n field.key in underlyingChanges && !equal(formex.values[field.key], underlyingChanges[field.key]),\n [field.key, underlyingChanges]);\n const underlyingValueHasChanged = useFormexSelector(selectUnderlyingChanged);\n\n const selectSubmitting = useCallback((formex: FormexController<Values>): boolean =>\n !autoSave && formex.isSubmitting, [autoSave]);\n const submitting = useFormexSelector(selectSubmitting);\n\n if (field.additional) {\n const additionalField = collection.additionalFields?.find(f => f.key === field.key);\n if (!additionalField || !entity) return null;\n\n const AdditionalFieldBuilder = additionalField.Builder;\n if (!AdditionalFieldBuilder && !additionalField.value) {\n throw new Error(\"When using additional fields you need to provide a Builder or a value\");\n }\n const row = rowOfEntity(entity, collection);\n const id = String(entity.id);\n const child = AdditionalFieldBuilder\n ? <AdditionalFieldBuilder row={row} id={id} context={rebaseContext}/>\n : <div className={\"w-full\"}>\n <AdditionalFieldValue\n field={additionalField}\n row={row}\n id={id}\n context={rebaseContext}/>\n </div>;\n\n return (\n // Through FieldBlock like every other cell, so a computed column\n // is labelled at the same size, with the same gap to its box, as\n // the property next to it on the grid.\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n showLabel={true}\n label={additionalField.name}\n icon={<AlignLeftIcon size={LABEL_ICON_SIZE}/>}>\n <div className={cls(paperMixin, \"w-full min-h-12 p-4 md:p-6 overflow-x-auto no-scrollbar\")}>\n {child}\n </div>\n </FieldBlock>\n </div>\n );\n }\n\n if (!property) {\n console.warn(`Property ${field.key} not found in collection ${collection.name} in properties or additional fields. Skipping.`);\n return null;\n }\n if (!shown) return null;\n\n const disabled = submitting || isFieldDisabled(field.key, property);\n // Three places a label can be. The panel-style editors carry their own\n // header. The one-line controls draw it inside their box, FireCMS-style,\n // so they all stand the same height. Everything else — multi-selects,\n // uploads, markdown, relations — is labelled above by FieldBlock.\n const selfLabelling = isSelfLabellingProperty(property);\n const labelInside = !selfLabelling\n && labelsInsideControl(property, customizationController.propertyConfigs);\n\n const bindingProps: PropertyFieldBindingProps<Values> = {\n propertyKey: field.key,\n disabled,\n property,\n // FieldBlock owns the description, so the binding must not repeat it —\n // it still renders validation errors, which belong against the control\n // rather than under the label.\n includeDescription: false,\n hideLabel: !selfLabelling && !labelInside,\n underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,\n context: fieldContext,\n partOfArray: false,\n minimalistView: false,\n // One height for every control in the form. Left to their own\n // defaults, a text field came out 48px, a select 44 and a switch 64.\n // `large`: the record-form density — a 64px box with the label inside\n // and a 16px value, or a 48px box under a label. See DESIGN.md \"Form\n // density\". A compact form takes `medium`.\n size: fields.fieldSize,\n autoFocus: autoFocusKey === field.key\n };\n\n return (\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n property={property}\n showLabel={!selfLab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BAAgB,wBAAwB,QAAQ;CACtD,MAAM,cAAc,CAAC,iBACd,oBAAoB,UAAU,wBAAwB,eAAe;CAE5E,MAAM,eAAkD;EACpD,aAAa,MAAM;EACnB;EACA;EAIA,oBAAoB;EACpB,WAAW,CAAC,iBAAiB,CAAC;EAC9B,2BAA2B,6BAA6B,CAAC;EACzD,SAAS;EACT,aAAa;EACb,gBAAgB;EAMhB,MAAM,OAAO;EACb,WAAW,iBAAiB,MAAM;CACtC;CAEA,OACI,oBAAC,OAAD;EAAK,WAAW,UAAU,MAAM,IAAI;YAChC,oBAAC,YAAD;GAAY,aAAa,MAAM;GACjB;GACV,WAAW,CAAC,iBAAiB,CAAC;GACjB;aACb,oBAAC,sBAAD,EAAsB,GAAI,aAAc,CAAA;EAChC,CAAA;CACX,CAAA;AAEb,CAAC"}
@@ -78,7 +78,7 @@ function PropertyFieldBindingInternal({ propertyKey, property, context, includeD
78
78
  property,
79
79
  values,
80
80
  path: context.path,
81
- entityId: context.entityId,
81
+ entityId: context.id,
82
82
  propertyConfigs: customizationController.propertyConfigs,
83
83
  index,
84
84
  authController
@@ -98,7 +98,7 @@ function PropertyFieldBindingInternal({ propertyKey, property, context, includeD
98
98
  property: propertyConfig.property,
99
99
  values,
100
100
  path: context.path,
101
- entityId: context.entityId,
101
+ entityId: context.id,
102
102
  propertyConfigs: customizationController.propertyConfigs,
103
103
  index,
104
104
  authController
@@ -145,14 +145,14 @@ function FieldInternal({ Component, alwaysRender, componentProps: { propertyKey,
145
145
  propertyKey,
146
146
  property,
147
147
  path: context.path ?? "",
148
- entityId: context.entityId,
148
+ id: context.id,
149
149
  collection: context.collection,
150
150
  context: rebaseContext
151
151
  }), [
152
152
  propertyKey,
153
153
  property,
154
154
  context.path,
155
- context.entityId,
155
+ context.id,
156
156
  context.collection,
157
157
  rebaseContext
158
158
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"PropertyFieldBinding.js","names":[],"sources":["../../src/form/PropertyFieldBinding.tsx"],"sourcesContent":["\nimport type { FieldProps as CoreFieldProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport type { FieldProps, PropertyFieldBindingProps } from \"../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport type { RebasePlugin, PluginFieldBuilderParams, PropertyConfig } from \"@rebasepro/cms-types\";\nimport React, { ComponentType, ReactElement, Suspense, useCallback, useRef } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\"\n\nimport { resolveComponentRef } from \"@rebasepro/app\";\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\n;\nimport { ReadOnlyFieldBinding } from \"./field_bindings/ReadOnlyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\nimport { useClearRestoreValue } from \"./useClearRestoreValue\";\n\nimport { isPropertyBuilder, resolveProperty } from \"@rebasepro/common\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { useAuthController, useCustomizationController, useRebaseContext, useSlot, useTranslation } from \"@rebasepro/app\";\nimport { Typography } from \"@rebasepro/ui\";\nimport { getFieldConfig, getFieldId } from \"../components/field_configs\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\n\n/**\n * This component renders a form field creating the corresponding configuration\n * from a property. For example if bound to a string property, it will generate\n * a text field.\n *\n * You can use it when you are creating a custom field, and need to\n * render additional fields mapped to properties. This is useful if you\n * need to build a complex property mapping, like an array where each index\n * is a different property.\n *\n * Please note that if you build a custom field in a component, the\n * **validation** passed in the property will have no effect. You need to set\n * the validation in the `AdminCollection` definition.\n *\n * @param propertyKey You can use nested names such as `address.street` or `friends[2]`\n * @param property\n * @param context\n * @param includeDescription\n * @param underlyingValueHasChanged\n * @param disabled\n * @param tableMode\n * @param partOfArray\n * @param autoFocus\n * @group Form custom fields\n */\nexport const PropertyFieldBinding = React.memo(PropertyFieldBindingInternal,\n (a: PropertyFieldBindingProps<Record<string, unknown>>, b: PropertyFieldBindingProps<Record<string, unknown>>) =>\n sameProps(a as unknown as Record<string, unknown>, b as unknown as Record<string, unknown>, DEEP_COMPARED_BINDING_PROPS)\n) as typeof PropertyFieldBindingInternal;\n\n/**\n * Props compared by value rather than identity: a property is re-resolved\n * (`dynamicProps`, enums, a parent's `mergeDeep`) into a new object on every\n * render of whatever holds it, and an error for an array or map is a new\n * sub-object of the errors map whenever anything is validated.\n */\nconst DEEP_COMPARED_BINDING_PROPS = new Set([\"property\"]);\nconst DEEP_COMPARED_FIELD_PROPS = new Set([\"property\", \"error\", \"customProps\"]);\n\nfunction sameProps(a: Record<string, unknown>, b: Record<string, unknown>, deep: Set<string>): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) {\n if (Object.is(a[key], b[key])) continue;\n if (deep.has(key) && equal(a[key], b[key])) continue;\n return false;\n }\n return true;\n}\n\nfunction PropertyFieldBindingInternal<M extends Record<string, unknown> = Record<string, unknown>>\n({\n propertyKey,\n property,\n context,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n disabled: disabledProp,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n index,\n size,\n onPropertyChange\n }: PropertyFieldBindingProps<M>): ReactElement<PropertyFieldBindingProps<M>> {\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n // Decided on the property as declared: once resolved, a builder or a rule\n // no longer says it was one.\n const alwaysRender = shouldPropertyReRender(property as Property, customizationController.plugins, customizationController.propertyConfigs);\n\n // This field's own slice of the form, so a change anywhere else does not\n // reach it. Through the form's context — which `Field` read — every field\n // of a record form re-rendered on every keystroke anywhere in it: all 500\n // items of an array nobody was typing into. A field that reads the rest of\n // the form while rendering takes the whole controller, and with it every\n // change, as it always has.\n const selectSlice = useCallback((formex: FormexController<Record<string, unknown>>): FieldSlice => ({\n formex: alwaysRender ? formex : undefined,\n value: getIn(formex.values, propertyKey),\n error: getIn(formex.errors, propertyKey) as FieldSlice[\"error\"],\n touched: getIn(formex.touched, propertyKey) as boolean | undefined,\n submitted: formex.submitCount > 0,\n isSubmitting: formex.isSubmitting\n }), [propertyKey, alwaysRender]);\n const slice = useFormexSelector(selectSlice, sameSlice);\n const getFormex = useFormexGetter<Record<string, unknown>>();\n // What the property is resolved against. Read, not subscribed to, for a\n // field that is not `alwaysRender`: nothing it declares reads the values.\n const values = (slice.formex ?? getFormex()).values;\n\n let Component: ComponentType<FieldProps<Property, any, any>> | undefined;\n // `dynamicProps` and `conditions` both, as the save judges it.\n const resolvedProperty = resolveFormProperty({\n propertyKey,\n property: property,\n values,\n path: context.path,\n entityId: context.entityId,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n\n const readOnly = resolvedProperty ? isReadOnly(resolvedProperty) : true;\n const disabled = disabledProp || readOnly || (resolvedProperty ? isDisabled(resolvedProperty) : false) || context.disabled;\n\n if (resolvedProperty === null || isHidden(resolvedProperty)) {\n return <></>;\n } else if (readOnly) {\n Component = ReadOnlyFieldBinding;\n } else if (resolvedProperty.admin?.Field) {\n const resolved = resolveComponentRef(resolvedProperty.admin.Field);\n if (resolved) {\n Component = resolved as ComponentType<FieldProps<Property, any, any>>;\n }\n } else {\n const propertyConfig = getFieldConfig(resolvedProperty, customizationController.propertyConfigs);\n if (!propertyConfig) {\n throw new Error(`INTERNAL: Could not find field config for property ${propertyKey}`);\n }\n const configProperty = resolveProperty({\n propertyKey,\n property: propertyConfig.property as Property,\n values,\n path: context.path,\n entityId: context.entityId,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n Component = resolveComponentRef(configProperty?.admin?.Field) as ComponentType<FieldProps<Property, any, any>> | undefined;\n }\n if (!Component) {\n console.warn(`No field component found for property ${propertyKey}`);\n console.warn(\"Property:\", property);\n return (\n <div className={\"w-full\"}>\n {`Currently the field ${resolvedProperty.type} is not supported`}\n </div>\n );\n }\n\n const componentProps: ResolvedPropertyFieldBindingProps<M> = {\n propertyKey,\n property: resolvedProperty,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n context,\n disabled,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n size,\n onPropertyChange\n };\n\n // Keyed on the path, as the `Field` it replaces was: an array item that\n // moves to another index is a new field there.\n return <FieldInternal\n key={propertyKey}\n Component={Component as ComponentType<FieldProps<Property, any, any>>}\n alwaysRender={alwaysRender}\n componentProps={componentProps}\n slice={slice}\n getFormex={getFormex}/>;\n\n}\n\n/**\n * What one field reads from the form. `formex` is set only for a field that\n * re-renders on every change (see {@link shouldPropertyReRender}).\n */\ntype FieldSlice = {\n formex: FormexController<Record<string, unknown>> | undefined;\n value: unknown;\n error: string | string[] | Record<string, unknown> | undefined;\n touched: boolean | undefined;\n submitted: boolean;\n isSubmitting: boolean;\n};\n\nfunction sameSlice(a: FieldSlice, b: FieldSlice): boolean {\n return a.formex === b.formex &&\n Object.is(a.value, b.value) &&\n a.touched === b.touched &&\n a.submitted === b.submitted &&\n a.isSubmitting === b.isSubmitting &&\n // An array's or a map's error is a sub-object of the errors map, new\n // whenever anything is validated.\n (Object.is(a.error, b.error) || equal(a.error, b.error));\n}\n\ntype ResolvedPropertyFieldBindingProps<M extends Record<string, unknown> = Record<string, unknown>> =\n Omit<PropertyFieldBindingProps<M>, \"property\">\n & {\n property: Property\n};\n\nfunction FieldInternal<CustomProps, M extends Record<string, unknown>>\n({\n Component,\n alwaysRender,\n componentProps: {\n propertyKey,\n property,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n context,\n disabled,\n size,\n onPropertyChange\n },\n slice,\n getFormex\n }:\n {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n componentProps: ResolvedPropertyFieldBindingProps<M>,\n slice: FieldSlice,\n getFormex: () => FormexController<Record<string, unknown>>\n }) {\n\n const { plugins } = useCustomizationController();\n const { t } = useTranslation();\n\n // This is the one component every form field goes through, which is why the\n // two field slots render here rather than in each field binding: a slot\n // honoured by the string field and not by the date field is worse than one\n // that never renders at all.\n const rebaseContext = useRebaseContext();\n const fieldSlotProps = React.useMemo(() => ({\n propertyKey,\n property,\n path: context.path ?? \"\",\n entityId: context.entityId,\n collection: context.collection,\n context: rebaseContext\n }), [propertyKey, property, context.path, context.entityId, context.collection, rebaseContext]);\n const beforeField = useSlot(\"entity.field.before\", fieldSlotProps);\n const afterField = useSlot(\"entity.field.after\", fieldSlotProps);\n\n const customFieldProps: unknown = property.admin?.customProps;\n const { value, error, touched, isSubmitting } = slice;\n\n const showError = Boolean(error &&\n (slice.submitted || property.validation?.unique) &&\n (!Array.isArray(error) || !!error.filter((e: unknown) => !!e).length));\n\n const WrappedComponent: ComponentType<FieldProps<Property, any, any>> | null = useWrappedComponent<unknown, any>({\n path: context.path,\n collection: context.collection,\n propertyKey: propertyKey,\n property: property,\n Component: Component as ComponentType<FieldProps<Property, unknown, M>>,\n plugins: plugins\n });\n const UsedComponent: ComponentType<FieldProps<Property, any, any>> = WrappedComponent ?? Component;\n\n // Read the controller when called, not when rendered: this component\n // re-renders with its own slice only, and the form moves on without it.\n const setValue = useCallback((value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(propertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n const setFieldValue = useCallback((otherPropertyKey: string, value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(otherPropertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n // `disabled: { clearOnDisabled: true }`, for every field: called here and\n // not in each binding, where six of them never did and a disabled relation\n // kept its value and saved it.\n useClearRestoreValue({ property: property as Property, value, setValue });\n\n // A parent that builds `onPropertyChange` inline (an array item's\n // `storeProps`, a map's wrapper) would otherwise hand every child a new\n // function on each of its renders, and every child would re-render for it.\n const onPropertyChangeRef = useRef(onPropertyChange);\n onPropertyChangeRef.current = onPropertyChange;\n const stableOnPropertyChange = useCallback((changed: Partial<Property>) => onPropertyChangeRef.current?.(changed), []);\n\n const cmsFieldProps: FieldProps<Property, CustomProps, M> = {\n propertyKey,\n value,\n setValue,\n setFieldValue,\n error: error as string | undefined,\n touched,\n showError,\n isSubmitting,\n includeDescription: includeDescription ?? true,\n hideLabel: hideLabel ?? false,\n property: property as Property,\n disabled: disabled ?? false,\n underlyingValueHasChanged: underlyingValueHasChanged ?? false,\n partOfArray: partOfArray ?? false,\n partOfBlock: partOfBlock ?? false,\n minimalistView: minimalistView ?? false,\n autoFocus: autoFocus ?? false,\n customProps: customFieldProps as CustomProps,\n context,\n size,\n onPropertyChange: onPropertyChange ? stableOnPropertyChange : undefined\n };\n\n return (\n <ErrorBoundary>\n {beforeField}\n\n <Suspense fallback={null}>\n <MemoisedField Component={UsedComponent}\n alwaysRender={alwaysRender}\n fieldProps={cmsFieldProps as FieldProps<Property, any, any>}/>\n </Suspense>\n\n {afterField}\n\n {underlyingValueHasChanged && !isSubmitting &&\n <Typography variant={\"caption\"} className={\"ml-3.5\"}>\n {t(\"value_updated_elsewhere\")}\n </Typography>}\n\n </ErrorBoundary>);\n\n}\n\ntype MemoisedFieldProps = {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n fieldProps: FieldProps<Property, any, any>\n};\n\n/**\n * The field's own component, rendered again only when its own slice of the\n * form changed — value, error, touched, the flags — or when the context it\n * draws the record from did (see `fieldContext` in `EntityForm`). Every field\n * of the form used to re-render on every keystroke anywhere in it.\n *\n * A field that may read *another* field's value while rendering cannot know\n * when to re-render from its own props, so those always do: see\n * {@link shouldPropertyReRender}.\n */\nconst MemoisedField = React.memo(\n function MemoisedField({ Component, fieldProps }: MemoisedFieldProps) {\n return <Component {...fieldProps}/>;\n },\n (prev: MemoisedFieldProps, next: MemoisedFieldProps) =>\n !next.alwaysRender &&\n prev.Component === next.Component &&\n sameProps(prev.fieldProps as unknown as Record<string, unknown>, next.fieldProps as unknown as Record<string, unknown>, DEEP_COMPARED_FIELD_PROPS)\n);\n\n/**\n * Whether a field has to re-render on every change to the form, because what\n * it draws can depend on values other than its own:\n * - a plugin `fieldBuilder` wraps it in a component of the plugin's;\n * - a custom `admin.Field` gets the whole form through `context`;\n * - `dynamicProps` and `conditions` are functions of every value;\n * - a storage path or file name given as a function is built from the values\n * the binding holds;\n * - a custom `propertyConfig` whose property says any of the above, since the\n * field is resolved through it.\n * Inside maps, arrays and blocks too, since their bindings render the children.\n */\nconst shouldPropertyReRender = (property: Property | undefined, plugins?: RebasePlugin[], propertyConfigs?: Record<string, PropertyConfig>): boolean => {\n if (!property) return false;\n if (plugins?.some((plugin) => plugin.fieldBuilder)) {\n return true;\n }\n const recurse = (child: unknown) => shouldPropertyReRender(child as Property, plugins, propertyConfigs);\n if (isPropertyBuilder(property) || property.conditions || property.admin?.Field) {\n return true;\n }\n const storage = \"storage\" in property ? property.storage : undefined;\n if (storage && (typeof storage.storagePath === \"function\" || typeof storage.fileName === \"function\")) {\n return true;\n }\n const configProperty = property.propertyConfig ? propertyConfigs?.[property.propertyConfig]?.property : undefined;\n if (configProperty && configProperty !== property && recurse(configProperty)) {\n return true;\n }\n if (property.type === \"map\" && property.properties) {\n return Object.values(property.properties).some(recurse);\n }\n if (property.type === \"array\") {\n if (Array.isArray(property.of)) {\n return property.of.some(recurse);\n }\n if (property.of && recurse(property.of)) {\n return true;\n }\n if (property.oneOf?.properties) {\n return Object.values(property.oneOf.properties).some(recurse);\n }\n }\n return false;\n}\n\ninterface UseWrappedComponentParams<M extends Record<string, unknown> = Record<string, unknown>> {\n path?: string,\n collection?: AdminCollection<M>,\n propertyKey: string,\n property: Property,\n Component: ComponentType<FieldProps<Property, unknown, M>>,\n plugins?: RebasePlugin[]\n}\n\nfunction useWrappedComponent<T, M extends Record<string, unknown> = Record<string, unknown>>(\n {\n path,\n collection,\n propertyKey,\n property,\n Component,\n plugins\n }: UseWrappedComponentParams<M>\n): ComponentType<FieldProps<Property, unknown, M>> | null {\n\n // A fold, in plugin order: each plugin's `wrap` is handed the field as the\n // plugins before it left it, so every wrapper renders — the first plugin's\n // closest to the field, the last one's outermost. A plugin that returns\n // null, or is not `enabled` for this field, passes it on unchanged.\n const wrapperRef = useRef<ComponentType<FieldProps<Property, unknown, M>> | null>((() => {\n let Wrapped: ComponentType<FieldProps<Property, unknown, M>> | null = null;\n if (plugins) {\n plugins.forEach((plugin) => {\n const fieldId = getFieldId(property);\n if (fieldId && plugin.fieldBuilder) {\n const params: PluginFieldBuilderParams = {\n fieldConfigId: fieldId,\n propertyKey,\n property,\n Field: (Wrapped ?? Component) as ComponentType<CoreFieldProps<Property, unknown, Record<string, unknown>>>,\n plugin,\n path,\n collection: collection as AdminCollection | undefined\n };\n const enabled = plugin.fieldBuilder.enabled?.(params);\n if (enabled === undefined || enabled)\n Wrapped = (plugin.fieldBuilder.wrap(params) as ComponentType<FieldProps<Property, unknown, M>> | null) ?? Wrapped;\n }\n if (!fieldId) {\n console.warn(\"INTERNAL: Field id not found for property\", property);\n }\n });\n }\n return Wrapped;\n })());\n\n return wrapperRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,uBAAuB,MAAM,KAAK,+BAC1C,GAAuD,MACpD,UAAU,GAAyC,GAAyC,2BAA2B,CAC/H;;;;;;;AAQA,IAAM,8CAA8B,IAAI,IAAI,CAAC,UAAU,CAAC;AACxD,IAAM,4CAA4B,IAAI,IAAI;CAAC;CAAY;CAAS;AAAa,CAAC;AAE9E,SAAS,UAAU,GAA4B,GAA4B,MAA4B;CACnG,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,KAAK,MAAM,OAAO,MAAM;EACpB,IAAI,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,GAAG;EAC/B,IAAI,KAAK,IAAI,GAAG,KAAK,UAAM,EAAE,MAAM,EAAE,IAAI,GAAG;EAC5C,OAAO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,SAAS,OAAO,YAChB,OAAO,OAAO,OAAO,SAAS,MAAM,UAAU,CAAC,CAAC,KAAK,OAAO;CAEpE;CACA,OAAO;AACX;AAWA,SAAS,oBACL,EACI,MACA,YACA,aACA,UACA,WACA,WAEkD;CAiCtD,OA3BmB,cAAsE;EACrF,IAAI,UAAkE;EACtE,IAAI,SACA,QAAQ,SAAS,WAAW;GACxB,MAAM,UAAU,WAAW,QAAQ;GACnC,IAAI,WAAW,OAAO,cAAc;IAChC,MAAM,SAAmC;KACrC,eAAe;KACf;KACA;KACA,OAAQ,WAAW;KACnB;KACA;KACY;IAChB;IACA,MAAM,UAAU,OAAO,aAAa,UAAU,MAAM;IACpD,IAAI,YAAY,KAAA,KAAa,SACzB,UAAW,OAAO,aAAa,KAAK,MAAM,KAAgE;GAClH;GACA,IAAI,CAAC,SACD,QAAQ,KAAK,6CAA6C,QAAQ;EAE1E,CAAC;EAEL,OAAO;CACX,EAAA,CAAG,CAEI,CAAA,CAAW;AACtB"}
1
+ {"version":3,"file":"PropertyFieldBinding.js","names":[],"sources":["../../src/form/PropertyFieldBinding.tsx"],"sourcesContent":["\nimport type { FieldProps as CoreFieldProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport type { FieldProps, PropertyFieldBindingProps } from \"../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport type { RebasePlugin, PluginFieldBuilderParams, PropertyConfig } from \"@rebasepro/cms-types\";\nimport React, { ComponentType, ReactElement, Suspense, useCallback, useRef } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\"\n\nimport { resolveComponentRef } from \"@rebasepro/app\";\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\n;\nimport { ReadOnlyFieldBinding } from \"./field_bindings/ReadOnlyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\nimport { useClearRestoreValue } from \"./useClearRestoreValue\";\n\nimport { isPropertyBuilder, resolveProperty } from \"@rebasepro/common\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { useAuthController, useCustomizationController, useRebaseContext, useSlot, useTranslation } from \"@rebasepro/app\";\nimport { Typography } from \"@rebasepro/ui\";\nimport { getFieldConfig, getFieldId } from \"../components/field_configs\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\n\n/**\n * This component renders a form field creating the corresponding configuration\n * from a property. For example if bound to a string property, it will generate\n * a text field.\n *\n * You can use it when you are creating a custom field, and need to\n * render additional fields mapped to properties. This is useful if you\n * need to build a complex property mapping, like an array where each index\n * is a different property.\n *\n * Please note that if you build a custom field in a component, the\n * **validation** passed in the property will have no effect. You need to set\n * the validation in the `AdminCollection` definition.\n *\n * @param propertyKey You can use nested names such as `address.street` or `friends[2]`\n * @param property\n * @param context\n * @param includeDescription\n * @param underlyingValueHasChanged\n * @param disabled\n * @param tableMode\n * @param partOfArray\n * @param autoFocus\n * @group Form custom fields\n */\nexport const PropertyFieldBinding = React.memo(PropertyFieldBindingInternal,\n (a: PropertyFieldBindingProps<Record<string, unknown>>, b: PropertyFieldBindingProps<Record<string, unknown>>) =>\n sameProps(a as unknown as Record<string, unknown>, b as unknown as Record<string, unknown>, DEEP_COMPARED_BINDING_PROPS)\n) as typeof PropertyFieldBindingInternal;\n\n/**\n * Props compared by value rather than identity: a property is re-resolved\n * (`dynamicProps`, enums, a parent's `mergeDeep`) into a new object on every\n * render of whatever holds it, and an error for an array or map is a new\n * sub-object of the errors map whenever anything is validated.\n */\nconst DEEP_COMPARED_BINDING_PROPS = new Set([\"property\"]);\nconst DEEP_COMPARED_FIELD_PROPS = new Set([\"property\", \"error\", \"customProps\"]);\n\nfunction sameProps(a: Record<string, unknown>, b: Record<string, unknown>, deep: Set<string>): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) {\n if (Object.is(a[key], b[key])) continue;\n if (deep.has(key) && equal(a[key], b[key])) continue;\n return false;\n }\n return true;\n}\n\nfunction PropertyFieldBindingInternal<M extends Record<string, unknown> = Record<string, unknown>>\n({\n propertyKey,\n property,\n context,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n disabled: disabledProp,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n index,\n size,\n onPropertyChange\n }: PropertyFieldBindingProps<M>): ReactElement<PropertyFieldBindingProps<M>> {\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n // Decided on the property as declared: once resolved, a builder or a rule\n // no longer says it was one.\n const alwaysRender = shouldPropertyReRender(property as Property, customizationController.plugins, customizationController.propertyConfigs);\n\n // This field's own slice of the form, so a change anywhere else does not\n // reach it. Through the form's context — which `Field` read — every field\n // of a record form re-rendered on every keystroke anywhere in it: all 500\n // items of an array nobody was typing into. A field that reads the rest of\n // the form while rendering takes the whole controller, and with it every\n // change, as it always has.\n const selectSlice = useCallback((formex: FormexController<Record<string, unknown>>): FieldSlice => ({\n formex: alwaysRender ? formex : undefined,\n value: getIn(formex.values, propertyKey),\n error: getIn(formex.errors, propertyKey) as FieldSlice[\"error\"],\n touched: getIn(formex.touched, propertyKey) as boolean | undefined,\n submitted: formex.submitCount > 0,\n isSubmitting: formex.isSubmitting\n }), [propertyKey, alwaysRender]);\n const slice = useFormexSelector(selectSlice, sameSlice);\n const getFormex = useFormexGetter<Record<string, unknown>>();\n // What the property is resolved against. Read, not subscribed to, for a\n // field that is not `alwaysRender`: nothing it declares reads the values.\n const values = (slice.formex ?? getFormex()).values;\n\n let Component: ComponentType<FieldProps<Property, any, any>> | undefined;\n // `dynamicProps` and `conditions` both, as the save judges it.\n const resolvedProperty = resolveFormProperty({\n propertyKey,\n property: property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n\n const readOnly = resolvedProperty ? isReadOnly(resolvedProperty) : true;\n const disabled = disabledProp || readOnly || (resolvedProperty ? isDisabled(resolvedProperty) : false) || context.disabled;\n\n if (resolvedProperty === null || isHidden(resolvedProperty)) {\n return <></>;\n } else if (readOnly) {\n Component = ReadOnlyFieldBinding;\n } else if (resolvedProperty.admin?.Field) {\n const resolved = resolveComponentRef(resolvedProperty.admin.Field);\n if (resolved) {\n Component = resolved as ComponentType<FieldProps<Property, any, any>>;\n }\n } else {\n const propertyConfig = getFieldConfig(resolvedProperty, customizationController.propertyConfigs);\n if (!propertyConfig) {\n throw new Error(`INTERNAL: Could not find field config for property ${propertyKey}`);\n }\n const configProperty = resolveProperty({\n propertyKey,\n property: propertyConfig.property as Property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n Component = resolveComponentRef(configProperty?.admin?.Field) as ComponentType<FieldProps<Property, any, any>> | undefined;\n }\n if (!Component) {\n console.warn(`No field component found for property ${propertyKey}`);\n console.warn(\"Property:\", property);\n return (\n <div className={\"w-full\"}>\n {`Currently the field ${resolvedProperty.type} is not supported`}\n </div>\n );\n }\n\n const componentProps: ResolvedPropertyFieldBindingProps<M> = {\n propertyKey,\n property: resolvedProperty,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n context,\n disabled,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n size,\n onPropertyChange\n };\n\n // Keyed on the path, as the `Field` it replaces was: an array item that\n // moves to another index is a new field there.\n return <FieldInternal\n key={propertyKey}\n Component={Component as ComponentType<FieldProps<Property, any, any>>}\n alwaysRender={alwaysRender}\n componentProps={componentProps}\n slice={slice}\n getFormex={getFormex}/>;\n\n}\n\n/**\n * What one field reads from the form. `formex` is set only for a field that\n * re-renders on every change (see {@link shouldPropertyReRender}).\n */\ntype FieldSlice = {\n formex: FormexController<Record<string, unknown>> | undefined;\n value: unknown;\n error: string | string[] | Record<string, unknown> | undefined;\n touched: boolean | undefined;\n submitted: boolean;\n isSubmitting: boolean;\n};\n\nfunction sameSlice(a: FieldSlice, b: FieldSlice): boolean {\n return a.formex === b.formex &&\n Object.is(a.value, b.value) &&\n a.touched === b.touched &&\n a.submitted === b.submitted &&\n a.isSubmitting === b.isSubmitting &&\n // An array's or a map's error is a sub-object of the errors map, new\n // whenever anything is validated.\n (Object.is(a.error, b.error) || equal(a.error, b.error));\n}\n\ntype ResolvedPropertyFieldBindingProps<M extends Record<string, unknown> = Record<string, unknown>> =\n Omit<PropertyFieldBindingProps<M>, \"property\">\n & {\n property: Property\n};\n\nfunction FieldInternal<CustomProps, M extends Record<string, unknown>>\n({\n Component,\n alwaysRender,\n componentProps: {\n propertyKey,\n property,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n context,\n disabled,\n size,\n onPropertyChange\n },\n slice,\n getFormex\n }:\n {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n componentProps: ResolvedPropertyFieldBindingProps<M>,\n slice: FieldSlice,\n getFormex: () => FormexController<Record<string, unknown>>\n }) {\n\n const { plugins } = useCustomizationController();\n const { t } = useTranslation();\n\n // This is the one component every form field goes through, which is why the\n // two field slots render here rather than in each field binding: a slot\n // honoured by the string field and not by the date field is worse than one\n // that never renders at all.\n const rebaseContext = useRebaseContext();\n const fieldSlotProps = React.useMemo(() => ({\n propertyKey,\n property,\n path: context.path ?? \"\",\n id: context.id,\n collection: context.collection,\n context: rebaseContext\n }), [propertyKey, property, context.path, context.id, context.collection, rebaseContext]);\n const beforeField = useSlot(\"entity.field.before\", fieldSlotProps);\n const afterField = useSlot(\"entity.field.after\", fieldSlotProps);\n\n const customFieldProps: unknown = property.admin?.customProps;\n const { value, error, touched, isSubmitting } = slice;\n\n const showError = Boolean(error &&\n (slice.submitted || property.validation?.unique) &&\n (!Array.isArray(error) || !!error.filter((e: unknown) => !!e).length));\n\n const WrappedComponent: ComponentType<FieldProps<Property, any, any>> | null = useWrappedComponent<unknown, any>({\n path: context.path,\n collection: context.collection,\n propertyKey: propertyKey,\n property: property,\n Component: Component as ComponentType<FieldProps<Property, unknown, M>>,\n plugins: plugins\n });\n const UsedComponent: ComponentType<FieldProps<Property, any, any>> = WrappedComponent ?? Component;\n\n // Read the controller when called, not when rendered: this component\n // re-renders with its own slice only, and the form moves on without it.\n const setValue = useCallback((value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(propertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n const setFieldValue = useCallback((otherPropertyKey: string, value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(otherPropertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n // `disabled: { clearOnDisabled: true }`, for every field: called here and\n // not in each binding, where six of them never did and a disabled relation\n // kept its value and saved it.\n useClearRestoreValue({ property: property as Property, value, setValue });\n\n // A parent that builds `onPropertyChange` inline (an array item's\n // `storeProps`, a map's wrapper) would otherwise hand every child a new\n // function on each of its renders, and every child would re-render for it.\n const onPropertyChangeRef = useRef(onPropertyChange);\n onPropertyChangeRef.current = onPropertyChange;\n const stableOnPropertyChange = useCallback((changed: Partial<Property>) => onPropertyChangeRef.current?.(changed), []);\n\n const cmsFieldProps: FieldProps<Property, CustomProps, M> = {\n propertyKey,\n value,\n setValue,\n setFieldValue,\n error: error as string | undefined,\n touched,\n showError,\n isSubmitting,\n includeDescription: includeDescription ?? true,\n hideLabel: hideLabel ?? false,\n property: property as Property,\n disabled: disabled ?? false,\n underlyingValueHasChanged: underlyingValueHasChanged ?? false,\n partOfArray: partOfArray ?? false,\n partOfBlock: partOfBlock ?? false,\n minimalistView: minimalistView ?? false,\n autoFocus: autoFocus ?? false,\n customProps: customFieldProps as CustomProps,\n context,\n size,\n onPropertyChange: onPropertyChange ? stableOnPropertyChange : undefined\n };\n\n return (\n <ErrorBoundary>\n {beforeField}\n\n <Suspense fallback={null}>\n <MemoisedField Component={UsedComponent}\n alwaysRender={alwaysRender}\n fieldProps={cmsFieldProps as FieldProps<Property, any, any>}/>\n </Suspense>\n\n {afterField}\n\n {underlyingValueHasChanged && !isSubmitting &&\n <Typography variant={\"caption\"} className={\"ml-3.5\"}>\n {t(\"value_updated_elsewhere\")}\n </Typography>}\n\n </ErrorBoundary>);\n\n}\n\ntype MemoisedFieldProps = {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n fieldProps: FieldProps<Property, any, any>\n};\n\n/**\n * The field's own component, rendered again only when its own slice of the\n * form changed — value, error, touched, the flags — or when the context it\n * draws the record from did (see `fieldContext` in `EntityForm`). Every field\n * of the form used to re-render on every keystroke anywhere in it.\n *\n * A field that may read *another* field's value while rendering cannot know\n * when to re-render from its own props, so those always do: see\n * {@link shouldPropertyReRender}.\n */\nconst MemoisedField = React.memo(\n function MemoisedField({ Component, fieldProps }: MemoisedFieldProps) {\n return <Component {...fieldProps}/>;\n },\n (prev: MemoisedFieldProps, next: MemoisedFieldProps) =>\n !next.alwaysRender &&\n prev.Component === next.Component &&\n sameProps(prev.fieldProps as unknown as Record<string, unknown>, next.fieldProps as unknown as Record<string, unknown>, DEEP_COMPARED_FIELD_PROPS)\n);\n\n/**\n * Whether a field has to re-render on every change to the form, because what\n * it draws can depend on values other than its own:\n * - a plugin `fieldBuilder` wraps it in a component of the plugin's;\n * - a custom `admin.Field` gets the whole form through `context`;\n * - `dynamicProps` and `conditions` are functions of every value;\n * - a storage path or file name given as a function is built from the values\n * the binding holds;\n * - a custom `propertyConfig` whose property says any of the above, since the\n * field is resolved through it.\n * Inside maps, arrays and blocks too, since their bindings render the children.\n */\nconst shouldPropertyReRender = (property: Property | undefined, plugins?: RebasePlugin[], propertyConfigs?: Record<string, PropertyConfig>): boolean => {\n if (!property) return false;\n if (plugins?.some((plugin) => plugin.fieldBuilder)) {\n return true;\n }\n const recurse = (child: unknown) => shouldPropertyReRender(child as Property, plugins, propertyConfigs);\n if (isPropertyBuilder(property) || property.conditions || property.admin?.Field) {\n return true;\n }\n const storage = \"storage\" in property ? property.storage : undefined;\n if (storage && (typeof storage.storagePath === \"function\" || typeof storage.fileName === \"function\")) {\n return true;\n }\n const configProperty = property.propertyConfig ? propertyConfigs?.[property.propertyConfig]?.property : undefined;\n if (configProperty && configProperty !== property && recurse(configProperty)) {\n return true;\n }\n if (property.type === \"map\" && property.properties) {\n return Object.values(property.properties).some(recurse);\n }\n if (property.type === \"array\") {\n if (Array.isArray(property.of)) {\n return property.of.some(recurse);\n }\n if (property.of && recurse(property.of)) {\n return true;\n }\n if (property.oneOf?.properties) {\n return Object.values(property.oneOf.properties).some(recurse);\n }\n }\n return false;\n}\n\ninterface UseWrappedComponentParams<M extends Record<string, unknown> = Record<string, unknown>> {\n path?: string,\n collection?: AdminCollection<M>,\n propertyKey: string,\n property: Property,\n Component: ComponentType<FieldProps<Property, unknown, M>>,\n plugins?: RebasePlugin[]\n}\n\nfunction useWrappedComponent<T, M extends Record<string, unknown> = Record<string, unknown>>(\n {\n path,\n collection,\n propertyKey,\n property,\n Component,\n plugins\n }: UseWrappedComponentParams<M>\n): ComponentType<FieldProps<Property, unknown, M>> | null {\n\n // A fold, in plugin order: each plugin's `wrap` is handed the field as the\n // plugins before it left it, so every wrapper renders — the first plugin's\n // closest to the field, the last one's outermost. A plugin that returns\n // null, or is not `enabled` for this field, passes it on unchanged.\n const wrapperRef = useRef<ComponentType<FieldProps<Property, unknown, M>> | null>((() => {\n let Wrapped: ComponentType<FieldProps<Property, unknown, M>> | null = null;\n if (plugins) {\n plugins.forEach((plugin) => {\n const fieldId = getFieldId(property);\n if (fieldId && plugin.fieldBuilder) {\n const params: PluginFieldBuilderParams = {\n fieldConfigId: fieldId,\n propertyKey,\n property,\n Field: (Wrapped ?? Component) as ComponentType<CoreFieldProps<Property, unknown, Record<string, unknown>>>,\n plugin,\n path,\n collection: collection as AdminCollection | undefined\n };\n const enabled = plugin.fieldBuilder.enabled?.(params);\n if (enabled === undefined || enabled)\n Wrapped = (plugin.fieldBuilder.wrap(params) as ComponentType<FieldProps<Property, unknown, M>> | null) ?? Wrapped;\n }\n if (!fieldId) {\n console.warn(\"INTERNAL: Field id not found for property\", property);\n }\n });\n }\n return Wrapped;\n })());\n\n return wrapperRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,uBAAuB,MAAM,KAAK,+BAC1C,GAAuD,MACpD,UAAU,GAAyC,GAAyC,2BAA2B,CAC/H;;;;;;;AAQA,IAAM,8CAA8B,IAAI,IAAI,CAAC,UAAU,CAAC;AACxD,IAAM,4CAA4B,IAAI,IAAI;CAAC;CAAY;CAAS;AAAa,CAAC;AAE9E,SAAS,UAAU,GAA4B,GAA4B,MAA4B;CACnG,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,KAAK,MAAM,OAAO,MAAM;EACpB,IAAI,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,GAAG;EAC/B,IAAI,KAAK,IAAI,GAAG,KAAK,UAAM,EAAE,MAAM,EAAE,IAAI,GAAG;EAC5C,OAAO;CACX;CACA,OAAO;AACX;AAEA,SAAS,6BACR,EACI,aACA,UACA,SACA,oBACA,WACA,2BACA,UAAU,cACV,aACA,aACA,gBACA,WACA,OACA,MACA,oBACyE;CAE1E,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,0BAA0B,2BAA2B;CAG3D,MAAM,eAAe,uBAAuB,UAAsB,wBAAwB,SAAS,wBAAwB,eAAe;CAgB1I,MAAM,QAAQ,kBARM,aAAa,YAAmE;EAChG,QAAQ,eAAe,SAAS,KAAA;EAChC,OAAO,MAAM,OAAO,QAAQ,WAAW;EACvC,OAAO,MAAM,OAAO,QAAQ,WAAW;EACvC,SAAS,MAAM,OAAO,SAAS,WAAW;EAC1C,WAAW,OAAO,cAAc;EAChC,cAAc,OAAO;CACzB,IAAI,CAAC,aAAa,YAAY,CACE,GAAa,SAAS;CACtD,MAAM,YAAY,gBAAyC;CAG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