@rebasepro/cms 0.17.3 → 0.18.1

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 (449) hide show
  1. package/README.md +4 -0
  2. package/dist/{CollectionEditorDialog-B-akreOU.js → CollectionEditorDialog-BeX4b92r.js} +13 -7
  3. package/dist/{CollectionEditorDialog-B-akreOU.js.map → CollectionEditorDialog-BeX4b92r.js.map} +1 -1
  4. package/dist/{PropertyEditView-CiY84wkR.js → PropertyEditView-C7thfj4L.js} +3 -3
  5. package/dist/{PropertyEditView-CiY84wkR.js.map → PropertyEditView-C7thfj4L.js.map} +1 -1
  6. package/dist/{RouterCollectionsStudioView-DkAWda4N.js → RouterCollectionsStudioView-BtjzvB6E.js} +4 -4
  7. package/dist/{RouterCollectionsStudioView-DkAWda4N.js.map → RouterCollectionsStudioView-BtjzvB6E.js.map} +1 -1
  8. package/dist/{SchemaChangeDialog-DceT8QFX.js → SchemaChangeDialog-CkqK6KOC.js} +4 -2
  9. package/dist/{SchemaChangeDialog-DceT8QFX.js.map → SchemaChangeDialog-CkqK6KOC.js.map} +1 -1
  10. package/dist/collection_editor/api/generateCollectionApi.d.ts +1 -2
  11. package/dist/collection_editor_ui.d.ts +2 -0
  12. package/dist/collection_editor_ui.js +6 -5
  13. package/dist/collection_editor_ui.js.map +1 -1
  14. package/dist/components/DeleteEntityDialog.d.ts +2 -3
  15. package/dist/components/RebaseLayout.d.ts +11 -4
  16. package/dist/components/field_configs.d.ts +1 -1
  17. package/dist/editor/sanitize-html.d.ts +15 -0
  18. package/dist/editor.js +195 -10
  19. package/dist/editor.js.map +1 -1
  20. package/dist/{export-Ben8E355.js → export--arni_VY.js} +2 -2
  21. package/dist/{export-Ben8E355.js.map → export--arni_VY.js.map} +1 -1
  22. package/dist/form/components/LabelWithIcon.d.ts +10 -0
  23. package/dist/{history-DIEVd26f.js → history-C2TpoQwi.js} +2 -2
  24. package/dist/{history-DIEVd26f.js.map → history-C2TpoQwi.js.map} +1 -1
  25. package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +1 -1
  26. package/dist/hooks/navigation/useResolvedViews.d.ts +1 -1
  27. package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -1
  28. package/dist/{import-D25x7ko-.js → import-DTkXNoBg.js} +2 -2
  29. package/dist/{import-D25x7ko-.js.map → import-DTkXNoBg.js.map} +1 -1
  30. package/dist/index.js +78 -33
  31. package/dist/index.js.map +1 -1
  32. package/dist/util/propertyConfigMapper.d.ts +1 -1
  33. package/dist/util-CfLFggP7.js +57 -0
  34. package/dist/util-CfLFggP7.js.map +1 -0
  35. package/dist/{util-DVqnqlLn.js → util-DE1WQW6h.js} +134 -112
  36. package/dist/util-DE1WQW6h.js.map +1 -0
  37. package/package.json +42 -34
  38. package/dist/util-DVqnqlLn.js.map +0 -1
  39. package/src/collection_editor/CollectionEditorDialogsContext.tsx +0 -25
  40. package/src/collection_editor/ConfigControllerProvider.tsx +0 -395
  41. package/src/collection_editor/_cms_internals.ts +0 -41
  42. package/src/collection_editor/api/generateCollectionApi.ts +0 -126
  43. package/src/collection_editor/api/index.ts +0 -1
  44. package/src/collection_editor/extensibility_types.ts +0 -168
  45. package/src/collection_editor/index.ts +0 -108
  46. package/src/collection_editor/liveSchemaClient.ts +0 -285
  47. package/src/collection_editor/relation_kinds.ts +0 -44
  48. package/src/collection_editor/serializable_types.ts +0 -535
  49. package/src/collection_editor/serializable_utils.ts +0 -729
  50. package/src/collection_editor/types/collection_editor_controller.tsx +0 -62
  51. package/src/collection_editor/types/collection_inference.ts +0 -18
  52. package/src/collection_editor/types/config_controller.tsx +0 -121
  53. package/src/collection_editor/ui/AddKanbanColumnAction.tsx +0 -199
  54. package/src/collection_editor/ui/CollectionViewHeaderAction.tsx +0 -51
  55. package/src/collection_editor/ui/EditorCollectionAction.tsx +0 -54
  56. package/src/collection_editor/ui/EditorCollectionActionStart.tsx +0 -90
  57. package/src/collection_editor/ui/EditorEntityAction.tsx +0 -50
  58. package/src/collection_editor/ui/HomePageEditorCollectionAction.tsx +0 -114
  59. package/src/collection_editor/ui/KanbanSetupAction.tsx +0 -43
  60. package/src/collection_editor/ui/MissingReferenceWidget.tsx +0 -35
  61. package/src/collection_editor/ui/NewCollectionButton.tsx +0 -27
  62. package/src/collection_editor/ui/NewCollectionCard.tsx +0 -48
  63. package/src/collection_editor/ui/PropertyAddColumnComponent.tsx +0 -49
  64. package/src/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.tsx +0 -260
  65. package/src/collection_editor/ui/collection_editor/AIModifiedPathsContext.tsx +0 -90
  66. package/src/collection_editor/ui/collection_editor/CollectionDetailsForm.tsx +0 -388
  67. package/src/collection_editor/ui/collection_editor/CollectionEditorDialog.tsx +0 -1098
  68. package/src/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.tsx +0 -301
  69. package/src/collection_editor/ui/collection_editor/CollectionJsonImportDialog.tsx +0 -172
  70. package/src/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.tsx +0 -620
  71. package/src/collection_editor/ui/collection_editor/CollectionRLSTab.tsx +0 -530
  72. package/src/collection_editor/ui/collection_editor/CollectionRelationsTab.tsx +0 -462
  73. package/src/collection_editor/ui/collection_editor/CollectionStudioView.tsx +0 -104
  74. package/src/collection_editor/ui/collection_editor/CollectionYupValidation.tsx +0 -9
  75. package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +0 -199
  76. package/src/collection_editor/ui/collection_editor/DisplaySettingsForm.tsx +0 -315
  77. package/src/collection_editor/ui/collection_editor/EntityActionsEditTab.tsx +0 -164
  78. package/src/collection_editor/ui/collection_editor/EntityActionsSelectDialog.tsx +0 -40
  79. package/src/collection_editor/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +0 -39
  80. package/src/collection_editor/ui/collection_editor/EnumForm.tsx +0 -373
  81. package/src/collection_editor/ui/collection_editor/GeneralSettingsForm.tsx +0 -288
  82. package/src/collection_editor/ui/collection_editor/GetCodeDialog.tsx +0 -141
  83. package/src/collection_editor/ui/collection_editor/KanbanConfigSection.tsx +0 -194
  84. package/src/collection_editor/ui/collection_editor/LayoutModeSwitch.tsx +0 -53
  85. package/src/collection_editor/ui/collection_editor/PropertyEditView.tsx +0 -980
  86. package/src/collection_editor/ui/collection_editor/PropertyFieldPreview.tsx +0 -164
  87. package/src/collection_editor/ui/collection_editor/PropertyTree.tsx +0 -364
  88. package/src/collection_editor/ui/collection_editor/RouterCollectionStudioView.tsx +0 -44
  89. package/src/collection_editor/ui/collection_editor/RouterCollectionsStudioView.tsx +0 -41
  90. package/src/collection_editor/ui/collection_editor/SchemaChangeDialog.tsx +0 -470
  91. package/src/collection_editor/ui/collection_editor/SubcollectionsEditTab.tsx +0 -256
  92. package/src/collection_editor/ui/collection_editor/SwitchControl.tsx +0 -39
  93. package/src/collection_editor/ui/collection_editor/ViewModeSwitch.tsx +0 -68
  94. package/src/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +0 -67
  95. package/src/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.tsx +0 -296
  96. package/src/collection_editor/ui/collection_editor/import/clean_import_data.ts +0 -57
  97. package/src/collection_editor/ui/collection_editor/properties/BlockPropertyField.tsx +0 -147
  98. package/src/collection_editor/ui/collection_editor/properties/BooleanPropertyField.tsx +0 -41
  99. package/src/collection_editor/ui/collection_editor/properties/CommonPropertyFields.tsx +0 -113
  100. package/src/collection_editor/ui/collection_editor/properties/DateTimePropertyField.tsx +0 -250
  101. package/src/collection_editor/ui/collection_editor/properties/EnumPropertyField.tsx +0 -126
  102. package/src/collection_editor/ui/collection_editor/properties/KeyValuePropertyField.tsx +0 -20
  103. package/src/collection_editor/ui/collection_editor/properties/MapPropertyField.tsx +0 -153
  104. package/src/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.tsx +0 -217
  105. package/src/collection_editor/ui/collection_editor/properties/NumberPropertyField.tsx +0 -117
  106. package/src/collection_editor/ui/collection_editor/properties/ReferencePropertyField.tsx +0 -129
  107. package/src/collection_editor/ui/collection_editor/properties/RelationPropertyField.tsx +0 -335
  108. package/src/collection_editor/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -107
  109. package/src/collection_editor/ui/collection_editor/properties/StoragePropertyField.tsx +0 -403
  110. package/src/collection_editor/ui/collection_editor/properties/StringPropertyField.tsx +0 -148
  111. package/src/collection_editor/ui/collection_editor/properties/UrlPropertyField.tsx +0 -91
  112. package/src/collection_editor/ui/collection_editor/properties/VectorPropertyField.tsx +0 -34
  113. package/src/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +0 -49
  114. package/src/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.tsx +0 -925
  115. package/src/collection_editor/ui/collection_editor/properties/conditions/ConditionsPanel.tsx +0 -28
  116. package/src/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.tsx +0 -626
  117. package/src/collection_editor/ui/collection_editor/properties/conditions/index.ts +0 -6
  118. package/src/collection_editor/ui/collection_editor/properties/conditions/property_paths.ts +0 -93
  119. package/src/collection_editor/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +0 -52
  120. package/src/collection_editor/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +0 -63
  121. package/src/collection_editor/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +0 -114
  122. package/src/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +0 -154
  123. package/src/collection_editor/ui/collection_editor/properties/validation/ValidationPanel.tsx +0 -28
  124. package/src/collection_editor/ui/collection_editor/templates/blog_template.ts +0 -112
  125. package/src/collection_editor/ui/collection_editor/templates/pages_template.ts +0 -183
  126. package/src/collection_editor/ui/collection_editor/templates/products_template.ts +0 -88
  127. package/src/collection_editor/ui/collection_editor/templates/users_template.ts +0 -42
  128. package/src/collection_editor/ui/collection_editor/util.ts +0 -28
  129. package/src/collection_editor/ui/collection_editor/utils/strings.ts +0 -1
  130. package/src/collection_editor/ui/collection_editor/utils/supported_fields.tsx +0 -39
  131. package/src/collection_editor/ui/collection_editor/utils/update_property_for_widget.ts +0 -276
  132. package/src/collection_editor/useCollectionEditorController.tsx +0 -9
  133. package/src/collection_editor/useCollectionsConfigController.tsx +0 -9
  134. package/src/collection_editor/useJsonCollectionsConfigController.tsx +0 -297
  135. package/src/collection_editor/useLiveSchemaEditing.tsx +0 -315
  136. package/src/collection_editor/useLocalCollectionsConfigController.tsx +0 -341
  137. package/src/collection_editor/useSafeSnackbarController.ts +0 -9
  138. package/src/collection_editor/validateCollectionJson.ts +0 -440
  139. package/src/collection_editor_ui.ts +0 -21
  140. package/src/components/AdditionalFieldValue.tsx +0 -68
  141. package/src/components/AdminModeSyncer.tsx +0 -56
  142. package/src/components/ArrayContainer.tsx +0 -542
  143. package/src/components/ClearFilterSortButton.tsx +0 -56
  144. package/src/components/CollectionEditorDialogs.tsx +0 -69
  145. package/src/components/CollectionPanel.tsx +0 -179
  146. package/src/components/CollectionTableBinding/CollectionRowActions.tsx +0 -244
  147. package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +0 -394
  148. package/src/components/CollectionTableBinding/CollectionTableBindingProps.tsx +0 -172
  149. package/src/components/CollectionTableBinding/PropertyTableCell.tsx +0 -350
  150. package/src/components/CollectionTableBinding/column_utils.tsx +0 -155
  151. package/src/components/CollectionTableBinding/fields/TableMultipleRelationField.tsx +0 -131
  152. package/src/components/CollectionTableBinding/fields/TableReferenceField.tsx +0 -193
  153. package/src/components/CollectionTableBinding/fields/TableRelationField.tsx +0 -192
  154. package/src/components/CollectionTableBinding/fields/TableRelationSelectorField.tsx +0 -42
  155. package/src/components/CollectionTableBinding/fields/TableStorageUpload.tsx +0 -324
  156. package/src/components/CollectionTableBinding/fields/VirtualTableSelect.tsx +0 -132
  157. package/src/components/CollectionTableBinding/fields/VirtualTableUserSelect.tsx +0 -41
  158. package/src/components/CollectionTableBinding/index.tsx +0 -14
  159. package/src/components/CollectionTableBinding/internal/CollectionTableToolbar.tsx +0 -96
  160. package/src/components/CollectionTableBinding/internal/EntityTableCell.tsx +0 -309
  161. package/src/components/CollectionTableBinding/internal/EntityTableCellActions.tsx +0 -80
  162. package/src/components/CollectionTableBinding/internal/common.tsx +0 -74
  163. package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +0 -422
  164. package/src/components/CollectionTableBinding/internal/popup_field/useDraggable.tsx +0 -99
  165. package/src/components/CollectionTableBinding/internal/popup_field/useWindowSize.tsx +0 -22
  166. package/src/components/CollectionTableBinding/table_bindings.tsx +0 -350
  167. package/src/components/CollectionViewBinding/BoardCardBinding.tsx +0 -263
  168. package/src/components/CollectionViewBinding/CollectionBoardViewBinding.tsx +0 -662
  169. package/src/components/CollectionViewBinding/CollectionCardViewBinding.tsx +0 -159
  170. package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +0 -1430
  171. package/src/components/CollectionViewBinding/CollectionViewActions.tsx +0 -227
  172. package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +0 -1603
  173. package/src/components/CollectionViewBinding/CollectionViewStartActions.tsx +0 -240
  174. package/src/components/CollectionViewBinding/EntityCardBinding.tsx +0 -239
  175. package/src/components/CollectionViewBinding/FilterPresetsButton.tsx +0 -298
  176. package/src/components/CollectionViewBinding/FiltersDialog.tsx +0 -218
  177. package/src/components/CollectionViewBinding/SearchExplanation.tsx +0 -106
  178. package/src/components/CollectionViewBinding/SearchHighlight.tsx +0 -311
  179. package/src/components/CollectionViewBinding/SlotValue.tsx +0 -156
  180. package/src/components/CollectionViewBinding/SortButton.tsx +0 -354
  181. package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +0 -49
  182. package/src/components/CollectionViewBinding/SplitListShowButton.tsx +0 -28
  183. package/src/components/CollectionViewBinding/SplitListView.tsx +0 -488
  184. package/src/components/CollectionViewBinding/SplitViewContext.tsx +0 -34
  185. package/src/components/CollectionViewBinding/ViewModeToggle.tsx +0 -250
  186. package/src/components/CollectionViewBinding/hooks/useCollectionInlineEditor.ts +0 -81
  187. package/src/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.ts +0 -181
  188. package/src/components/CollectionViewBinding/useBoardDataController.tsx +0 -802
  189. package/src/components/CollectionViewBinding/usePreviewSlots.ts +0 -703
  190. package/src/components/CollectionViewBinding/useSelectionController.tsx +0 -40
  191. package/src/components/CollectionViewBinding/utils.ts +0 -22
  192. package/src/components/DefaultAppBar.tsx +0 -264
  193. package/src/components/DefaultDrawer.tsx +0 -593
  194. package/src/components/DeleteEntityDialog.tsx +0 -205
  195. package/src/components/DetailViewBinding.tsx +0 -731
  196. package/src/components/DrawerNavigationGroup.tsx +0 -141
  197. package/src/components/DrawerNavigationItem.tsx +0 -115
  198. package/src/components/EditFormActions.tsx +0 -303
  199. package/src/components/EditViewBinding.tsx +0 -1069
  200. package/src/components/EntityDisplayHeader.tsx +0 -170
  201. package/src/components/EntityIdentityBar.tsx +0 -428
  202. package/src/components/EntityInspector.tsx +0 -156
  203. package/src/components/EntityPreviewBinding.tsx +0 -432
  204. package/src/components/EntityPreviewNesting.tsx +0 -50
  205. package/src/components/EntityViewBinding.tsx +0 -374
  206. package/src/components/FieldCaption.tsx +0 -14
  207. package/src/components/HomePage/ContentHomePage.tsx +0 -586
  208. package/src/components/HomePage/FavouritesView.tsx +0 -60
  209. package/src/components/HomePage/HomePageDnD.tsx +0 -704
  210. package/src/components/HomePage/NavigationCard.tsx +0 -81
  211. package/src/components/HomePage/NavigationCardBinding.tsx +0 -107
  212. package/src/components/HomePage/NavigationGroup.tsx +0 -156
  213. package/src/components/HomePage/RenameGroupDialog.tsx +0 -123
  214. package/src/components/HomePage/SmallNavigationCard.tsx +0 -41
  215. package/src/components/HomePage/index.tsx +0 -5
  216. package/src/components/InlineEntityPreview.tsx +0 -149
  217. package/src/components/JsonPreviewBinding.tsx +0 -66
  218. package/src/components/PropertyCollectionView.tsx +0 -336
  219. package/src/components/PropertyConfigBadge.tsx +0 -28
  220. package/src/components/PropertyIdCopyTooltip.tsx +0 -47
  221. package/src/components/RebaseAuthGate.tsx +0 -44
  222. package/src/components/RebaseCMS.tsx +0 -30
  223. package/src/components/RebaseLayout.tsx +0 -80
  224. package/src/components/RebaseNavigation.tsx +0 -369
  225. package/src/components/RebaseRouteDefs.tsx +0 -127
  226. package/src/components/RebaseShell.tsx +0 -83
  227. package/src/components/ReferenceTable/SelectionTableBinding.tsx +0 -389
  228. package/src/components/ReferenceWidget.tsx +0 -156
  229. package/src/components/RelationSelector.tsx +0 -926
  230. package/src/components/SearchIconsView.tsx +0 -78
  231. package/src/components/SelectableTable/SelectableTable.tsx +0 -309
  232. package/src/components/SelectableTable/SelectableTableContext.tsx +0 -7
  233. package/src/components/SelectableTable/SelectionStore.ts +0 -43
  234. package/src/components/SelectableTable/filters/BooleanFilterField.tsx +0 -59
  235. package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +0 -146
  236. package/src/components/SelectableTable/filters/FilterFieldBinding.tsx +0 -190
  237. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +0 -250
  238. package/src/components/SelectableTable/filters/RelationFilterField.tsx +0 -238
  239. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +0 -282
  240. package/src/components/SelectableTable/filters/null_filter.ts +0 -63
  241. package/src/components/SideDialogs.tsx +0 -238
  242. package/src/components/SidePanelBinding.tsx +0 -361
  243. package/src/components/SidePanelProvider.tsx +0 -80
  244. package/src/components/UserSelector.tsx +0 -513
  245. package/src/components/admin/CreationResultDialog.tsx +0 -138
  246. package/src/components/admin/index.ts +0 -1
  247. package/src/components/app/AppBar.tsx +0 -17
  248. package/src/components/app/Drawer.tsx +0 -38
  249. package/src/components/app/Scaffold.tsx +0 -366
  250. package/src/components/app/index.ts +0 -4
  251. package/src/components/app/useApp.tsx +0 -36
  252. package/src/components/common/default_entity_actions.tsx +0 -440
  253. package/src/components/common/index.ts +0 -1
  254. package/src/components/field_configs.tsx +0 -506
  255. package/src/components/history/EntityHistoryEntry.tsx +0 -203
  256. package/src/components/history/EntityHistoryView.tsx +0 -206
  257. package/src/components/history/LastEditedByFormAction.tsx +0 -24
  258. package/src/components/history/LastEditedByIndicator.tsx +0 -95
  259. package/src/components/history/UserChip.tsx +0 -15
  260. package/src/components/history/index.tsx +0 -5
  261. package/src/components/index.ts +0 -63
  262. package/src/contexts/BreacrumbsContext.tsx +0 -45
  263. package/src/contexts/SideDialogsControllerContext.tsx +0 -5
  264. package/src/contexts/SidePanelControllerContext.tsx +0 -5
  265. package/src/data_export/export/BasicExportAction.tsx +0 -142
  266. package/src/data_export/export/ExportCollectionAction.tsx +0 -321
  267. package/src/data_export/export/export.ts +0 -295
  268. package/src/data_export/export/fetch_export_data.ts +0 -90
  269. package/src/data_export/export/index.ts +0 -4
  270. package/src/data_export/index.ts +0 -1
  271. package/src/data_import/components/DataNewPropertiesMapping.tsx +0 -261
  272. package/src/data_import/components/ImportFileUpload.tsx +0 -42
  273. package/src/data_import/components/ImportNewPropertyFieldPreview.tsx +0 -58
  274. package/src/data_import/components/ImportSaveInProgress.tsx +0 -121
  275. package/src/data_import/components/index.ts +0 -4
  276. package/src/data_import/hooks/index.ts +0 -1
  277. package/src/data_import/hooks/useImportConfig.tsx +0 -34
  278. package/src/data_import/import/ImportCollectionAction.tsx +0 -461
  279. package/src/data_import/import/index.ts +0 -1
  280. package/src/data_import/index.ts +0 -5
  281. package/src/data_import/types/column_mapping.ts +0 -32
  282. package/src/data_import/types/index.ts +0 -1
  283. package/src/data_import/utils/csv.ts +0 -153
  284. package/src/data_import/utils/data.ts +0 -181
  285. package/src/data_import/utils/file_headers.ts +0 -14
  286. package/src/data_import/utils/file_to_json.ts +0 -149
  287. package/src/data_import/utils/get_import_inference_type.ts +0 -33
  288. package/src/data_import/utils/get_properties_mapping.ts +0 -67
  289. package/src/data_import/utils/index.ts +0 -5
  290. package/src/data_import/utils/save_entities.ts +0 -138
  291. package/src/data_import/utils/transforms.ts +0 -70
  292. package/src/editor/components/SlashCommandMenu.tsx +0 -532
  293. package/src/editor/components/editor-bubble-item.tsx +0 -32
  294. package/src/editor/components/editor-bubble.tsx +0 -143
  295. package/src/editor/components/image-bubble.tsx +0 -183
  296. package/src/editor/components/index.ts +0 -14
  297. package/src/editor/components/table-bubble.tsx +0 -233
  298. package/src/editor/editor.tsx +0 -529
  299. package/src/editor/extensions/HighlightDecorationExtension.ts +0 -115
  300. package/src/editor/extensions/Image.ts +0 -159
  301. package/src/editor/extensions/TextLoadingDecorationExtension.tsx +0 -107
  302. package/src/editor/extensions/clipboard.ts +0 -72
  303. package/src/editor/extensions/custom-keymap.ts +0 -25
  304. package/src/editor/extensions/drag-and-drop.tsx +0 -508
  305. package/src/editor/hooks/useProseMirror.ts +0 -126
  306. package/src/editor/hooks/useProseMirrorContext.ts +0 -15
  307. package/src/editor/index.ts +0 -2
  308. package/src/editor/markdown-it-plugins.d.ts +0 -24
  309. package/src/editor/markdown.ts +0 -204
  310. package/src/editor/nodeViews/ImageComponent.tsx +0 -20
  311. package/src/editor/nodeViews/ReactNodeView.tsx +0 -89
  312. package/src/editor/nodeViews/TaskItemComponent.tsx +0 -30
  313. package/src/editor/nodeViews/index.ts +0 -35
  314. package/src/editor/plugins/index.ts +0 -58
  315. package/src/editor/plugins/inputrules.ts +0 -82
  316. package/src/editor/plugins/placeholderPlugin.ts +0 -55
  317. package/src/editor/plugins/slashCommandPlugin.ts +0 -65
  318. package/src/editor/schema.ts +0 -339
  319. package/src/editor/selectors/ai-selector.tsx +0 -110
  320. package/src/editor/selectors/color-selector.tsx +0 -199
  321. package/src/editor/selectors/link-selector.tsx +0 -122
  322. package/src/editor/selectors/node-selector.tsx +0 -159
  323. package/src/editor/selectors/text-buttons.tsx +0 -79
  324. package/src/editor/types.ts +0 -6
  325. package/src/editor/useProseMirror.ts +0 -125
  326. package/src/editor/utils/prosemirror-utils.ts +0 -113
  327. package/src/editor/utils/remove_classes.ts +0 -18
  328. package/src/editor/utils/useDebouncedCallback.ts +0 -25
  329. package/src/form/EntityForm.tsx +0 -761
  330. package/src/form/EntityFormActions.tsx +0 -160
  331. package/src/form/EntityFormBinding.tsx +0 -342
  332. package/src/form/PropertyFieldBinding.tsx +0 -348
  333. package/src/form/components/ErrorFocus.tsx +0 -44
  334. package/src/form/components/FieldBlock.tsx +0 -189
  335. package/src/form/components/FieldHelperText.tsx +0 -84
  336. package/src/form/components/FormRail.tsx +0 -153
  337. package/src/form/components/FormSections.tsx +0 -145
  338. package/src/form/components/LabelWithIcon.tsx +0 -43
  339. package/src/form/components/LabelWithIconAndTooltip.tsx +0 -28
  340. package/src/form/components/LocalChangesMenu.tsx +0 -147
  341. package/src/form/components/StorageItemPreview.tsx +0 -81
  342. package/src/form/components/StorageUploadProgress.tsx +0 -118
  343. package/src/form/components/index.tsx +0 -6
  344. package/src/form/components/useRailVisible.tsx +0 -47
  345. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +0 -109
  346. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +0 -172
  347. package/src/form/field_bindings/BinaryFieldBinding.tsx +0 -177
  348. package/src/form/field_bindings/BlockFieldBinding.tsx +0 -282
  349. package/src/form/field_bindings/DateTimeFieldBinding.tsx +0 -78
  350. package/src/form/field_bindings/GeopointFieldBinding.tsx +0 -200
  351. package/src/form/field_bindings/KeyValueFieldBinding.tsx +0 -574
  352. package/src/form/field_bindings/MapFieldBinding.tsx +0 -120
  353. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +0 -259
  354. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +0 -130
  355. package/src/form/field_bindings/MultipleRelationFieldBinding.tsx +0 -168
  356. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +0 -94
  357. package/src/form/field_bindings/ReferenceFieldBinding.tsx +0 -146
  358. package/src/form/field_bindings/RelationFieldBinding.tsx +0 -202
  359. package/src/form/field_bindings/RepeatFieldBinding.tsx +0 -143
  360. package/src/form/field_bindings/SelectFieldBinding.tsx +0 -111
  361. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +0 -521
  362. package/src/form/field_bindings/SwitchFieldBinding.tsx +0 -70
  363. package/src/form/field_bindings/TextFieldBinding.tsx +0 -189
  364. package/src/form/field_bindings/UserSelectFieldBinding.tsx +0 -71
  365. package/src/form/field_bindings/VectorFieldBinding.tsx +0 -209
  366. package/src/form/form_utils.ts +0 -243
  367. package/src/form/index.tsx +0 -36
  368. package/src/form/useClearRestoreValue.tsx +0 -36
  369. package/src/form/useUndoableDiscard.ts +0 -39
  370. package/src/form/validation.ts +0 -583
  371. package/src/hooks/index.ts +0 -16
  372. package/src/hooks/navigation/contexts/CollectionRegistryContext.tsx +0 -22
  373. package/src/hooks/navigation/contexts/NavigationStateContext.tsx +0 -16
  374. package/src/hooks/navigation/contexts/UrlContext.tsx +0 -24
  375. package/src/hooks/navigation/contexts/index.ts +0 -14
  376. package/src/hooks/navigation/useAsyncResolver.ts +0 -100
  377. package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +0 -218
  378. package/src/hooks/navigation/useBuildNavigationStateController.tsx +0 -134
  379. package/src/hooks/navigation/useBuildUrlController.tsx +0 -66
  380. package/src/hooks/navigation/useNavigationResolution.ts +0 -271
  381. package/src/hooks/navigation/useResolvedCollections.ts +0 -102
  382. package/src/hooks/navigation/useResolvedViews.tsx +0 -139
  383. package/src/hooks/navigation/useTopLevelNavigation.ts +0 -273
  384. package/src/hooks/navigation/utils.ts +0 -200
  385. package/src/hooks/useAdminContext.tsx +0 -83
  386. package/src/hooks/useBreadcrumbsController.tsx +0 -17
  387. package/src/hooks/useBuildSideDialogsController.tsx +0 -145
  388. package/src/hooks/useBuildSidePanel.tsx +0 -315
  389. package/src/hooks/useChildViewSource.ts +0 -46
  390. package/src/hooks/useEntityDisplay.tsx +0 -262
  391. package/src/hooks/useEntityDisplayTitle.tsx +0 -49
  392. package/src/hooks/useHistory.ts +0 -178
  393. package/src/hooks/useRecordActions.tsx +0 -69
  394. package/src/hooks/useResolvedNavigationFrom.tsx +0 -167
  395. package/src/hooks/useResolvedUsers.ts +0 -148
  396. package/src/hooks/useSelectionDialog.tsx +0 -58
  397. package/src/hooks/useSideDialogsController.tsx +0 -25
  398. package/src/hooks/useSidePanel.tsx +0 -13
  399. package/src/index.ts +0 -124
  400. package/src/preview/PropertyPreview.tsx +0 -331
  401. package/src/preview/compact_text.ts +0 -68
  402. package/src/preview/components/ArrayEnumPreview.tsx +0 -39
  403. package/src/preview/components/BooleanPreview.tsx +0 -28
  404. package/src/preview/components/DatePreview.tsx +0 -106
  405. package/src/preview/components/EmptyValue.tsx +0 -10
  406. package/src/preview/components/EnumValuesChip.tsx +0 -39
  407. package/src/preview/components/ImagePreview.tsx +0 -144
  408. package/src/preview/components/InlineEntityListPreview.tsx +0 -42
  409. package/src/preview/components/ReferencePreview.tsx +0 -235
  410. package/src/preview/components/RelationPreview.tsx +0 -271
  411. package/src/preview/components/StorageThumbnail.tsx +0 -147
  412. package/src/preview/components/UrlComponentPreview.tsx +0 -116
  413. package/src/preview/components/UserPreview.tsx +0 -30
  414. package/src/preview/components/date_fns_locales.ts +0 -125
  415. package/src/preview/index.ts +0 -26
  416. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +0 -73
  417. package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +0 -67
  418. package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +0 -77
  419. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +0 -49
  420. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +0 -70
  421. package/src/preview/property_previews/ArrayOneOfPreview.tsx +0 -79
  422. package/src/preview/property_previews/ArrayPropertyEnumPreview.tsx +0 -35
  423. package/src/preview/property_previews/ArrayPropertyPreview.tsx +0 -79
  424. package/src/preview/property_previews/MapPropertyPreview.tsx +0 -198
  425. package/src/preview/property_previews/NumberPropertyPreview.tsx +0 -39
  426. package/src/preview/property_previews/SkeletonPropertyComponent.tsx +0 -276
  427. package/src/preview/property_previews/StringPropertyPreview.tsx +0 -70
  428. package/src/preview/util.ts +0 -39
  429. package/src/routes/CustomViewRoute.tsx +0 -33
  430. package/src/routes/RebaseRoute.tsx +0 -467
  431. package/src/routes/index.ts +0 -2
  432. package/src/types/components/EntityFormActionsProps.tsx +0 -20
  433. package/src/types/components/EntityFormProps.tsx +0 -119
  434. package/src/types/components/PropertyPreviewProps.tsx +0 -85
  435. package/src/types/components/formex.tsx +0 -2
  436. package/src/types/components/index.ts +0 -3
  437. package/src/types/fields.tsx +0 -340
  438. package/src/types/index.ts +0 -4
  439. package/src/util/dataControllerAdapter.ts +0 -88
  440. package/src/util/entity_actions.ts +0 -28
  441. package/src/util/index.ts +0 -5
  442. package/src/util/navigation_utils.ts +0 -89
  443. package/src/util/number_format.ts +0 -46
  444. package/src/util/previews.ts +0 -131
  445. package/src/util/propertyConfigMapper.ts +0 -134
  446. package/src/util/property_utils.tsx +0 -236
  447. package/src/util/resolutions.ts +0 -96
  448. package/src/util/view_constants.ts +0 -33
  449. package/src/util/view_mode.ts +0 -176
@@ -1,282 +0,0 @@
1
- import type { FieldProps, FormContext, PropertyFieldBindingProps } from "../../types/fields";
2
- import type { ArrayProperty, Property } from "@rebasepro/types";
3
- import React, { useEffect, useState } from "react";
4
-
5
- import { Field, useFormex } from "@rebasepro/forms";
6
-
7
- import { FieldHelperText } from "../components/FieldHelperText";
8
- import { LabelWithIconAndTooltip } from "../components/LabelWithIconAndTooltip";
9
- import { PropertyFieldBinding } from "../PropertyFieldBinding";
10
- import { EnumValuesChip } from "../../preview";
11
-
12
- ;
13
- import { DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, getDefaultValueFor } from "@rebasepro/common";
14
- import { getIconForProperty } from "../../util/property_utils";
15
- import { cls, ExpandablePanel, paperMixin, Select, SelectItem, Typography } from "@rebasepro/ui";
16
- import { isDisabled, useTranslation } from "@rebasepro/app";
17
- import { useClearRestoreValue } from "../useClearRestoreValue";
18
- import { ArrayContainer, ArrayEntryParams } from "../../components/ArrayContainer";
19
- import { mergeDeep } from "@rebasepro/utils";
20
-
21
- /**
22
- * If the `oneOf` property is specified, this fields render each array entry as
23
- * a `type` select and the corresponding field widget to the selected `type.
24
- *
25
- * This is one of the internal components that get mapped natively inside forms
26
- * and tables to the specified properties.
27
- * @group Form fields
28
- */
29
- export function BlockFieldBinding({
30
- propertyKey,
31
- value,
32
- error,
33
- showError,
34
- isSubmitting,
35
- setValue,
36
- setFieldValue,
37
- minimalistView: minimalistViewProp,
38
- property,
39
- includeDescription,
40
- underlyingValueHasChanged,
41
- context,
42
- disabled
43
- }: FieldProps<ArrayProperty>) {
44
-
45
- const minimalistView = minimalistViewProp || property.admin?.minimalistView;
46
- const { t } = useTranslation();
47
-
48
- if (!property.oneOf)
49
- throw Error("ArrayOneOfField misconfiguration. Property `oneOf` not set");
50
-
51
- const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;
52
- useClearRestoreValue({
53
- property,
54
- value,
55
- setValue
56
- });
57
-
58
- const [lastAddedId, setLastAddedId] = useState<number | undefined>();
59
-
60
- const buildEntry = ({
61
- index,
62
- internalId,
63
- storedProps,
64
- storeProps
65
- }: ArrayEntryParams) => {
66
-
67
- return <BlockEntry
68
- key={`array_one_of_${internalId}`}
69
- name={`${propertyKey}.${index}`}
70
- index={index}
71
- value={value[index]}
72
- typeField={property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE}
73
- valueField={property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE}
74
- properties={property.oneOf!.properties}
75
- autoFocus={internalId === lastAddedId}
76
- context={context}
77
- storeProps={storeProps}
78
- storedProps={storedProps}/>;
79
- };
80
-
81
- const title = (
82
- <LabelWithIconAndTooltip
83
- propertyKey={propertyKey}
84
- icon={getIconForProperty(property, "small")}
85
- required={property.validation?.required}
86
- title={property.name ?? propertyKey}
87
- className={"text-text-secondary dark:text-text-secondary-dark"}/>
88
- );
89
-
90
- const firstOneOfKey = Object.keys(property.oneOf.properties)[0];
91
- const body = <ArrayContainer value={value}
92
- className={"flex flex-col gap-3"}
93
- droppableId={propertyKey}
94
- addLabel={property.name ? t("add_to_field", { fieldName: property.name }) : t("add_entry")}
95
- buildEntry={buildEntry}
96
- onInternalIdAdded={setLastAddedId}
97
- disabled={isSubmitting || isDisabled(property)}
98
- canAddElements={!isDisabled(property)}
99
- onValueChange={(value) => setFieldValue(propertyKey, value)}
100
- newDefaultEntry={{
101
- [property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE]: firstOneOfKey,
102
- [property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE]: getDefaultValueFor(property.oneOf.properties[firstOneOfKey])
103
- }}/>;
104
- return (
105
-
106
- <>
107
-
108
- {!minimalistView &&
109
- <ExpandablePanel
110
- innerClassName={"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2"}
111
- initiallyExpanded={expanded}
112
- title={title}>
113
- {body}
114
- </ExpandablePanel>}
115
-
116
- {minimalistView && body}
117
-
118
- <FieldHelperText includeDescription={includeDescription}
119
- showError={showError}
120
- error={error}
121
- disabled={disabled}
122
- property={property}/>
123
-
124
- </>
125
- );
126
- }
127
-
128
- interface BlockEntryProps {
129
- name: string;
130
- index: number;
131
- value: Record<string, unknown>;
132
- /**
133
- * Name of the field to use as the discriminator for type
134
- * Defaults to `type`
135
- */
136
- typeField: string;
137
- /**
138
- * Name of the field to use as the value
139
- * Defaults to `value`
140
- */
141
- valueField: string;
142
-
143
- autoFocus: boolean;
144
- /**
145
- * Record of properties, where the key is the `type` and the value
146
- * is the corresponding property
147
- */
148
- properties: Record<string, Property>;
149
-
150
- /**
151
- * Additional values related to the state of the form or the entity
152
- */
153
- context: FormContext;
154
-
155
- storedProps?: object,
156
- storeProps: (props: object) => void
157
-
158
- }
159
-
160
- function BlockEntry({
161
- name,
162
- index,
163
- value,
164
- typeField,
165
- valueField,
166
- properties,
167
- autoFocus,
168
- context,
169
- storedProps,
170
- storeProps
171
- }: BlockEntryProps) {
172
-
173
- const type = value && (value[typeField] as string | undefined);
174
- const [typeInternal, setTypeInternal] = useState<string | undefined>(type ?? undefined);
175
-
176
- const formex = useFormex();
177
- const { t } = useTranslation();
178
-
179
- useEffect(() => {
180
- if (!type) {
181
- // Auto-fix empty blocks silently — set the default type WITHOUT
182
- // marking as touched so the form doesn't become dirty on mount.
183
- const defaultType = Object.keys(properties)[0];
184
- const newSelectedProperty = defaultType ? properties[defaultType] : undefined;
185
- setTypeInternal(defaultType);
186
- formex.setFieldValue(typeFieldName, defaultType);
187
- formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);
188
- }
189
- }, []);
190
-
191
- useEffect(() => {
192
- if (type !== typeInternal) {
193
- setTypeInternal(type);
194
- }
195
- }, [type]);
196
-
197
- const propertyInternal = typeInternal ? properties[typeInternal] : undefined;
198
-
199
- const property = storedProps && typeof propertyInternal === "object" ? mergeDeep(propertyInternal, storedProps) : propertyInternal;
200
-
201
- const enumValuesConfigs = Object.entries(properties)
202
- .map(([key, property]) => ({
203
- id: key,
204
- label: property.name ?? key
205
- }));
206
-
207
- const typeFieldName = `${name}.${typeField}`;
208
- const valueFieldName = `${name}.${valueField}`;
209
-
210
- const fieldProps: PropertyFieldBindingProps | undefined = property
211
- ? {
212
- propertyKey: valueFieldName,
213
- property,
214
- context,
215
- autoFocus,
216
- partOfArray: false,
217
- partOfBlock: true,
218
- minimalistView: true,
219
- onPropertyChange: storeProps
220
- }
221
- : undefined;
222
-
223
- const updateType = (newType: string | undefined) => {
224
- const newSelectedProperty = newType ? properties[newType] : undefined;
225
- setTypeInternal(newType);
226
- formex.setFieldTouched(typeFieldName, true);
227
- formex.setFieldValue(typeFieldName, newType);
228
- formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);
229
- };
230
-
231
- return (
232
- <div className={cls(paperMixin, "bg-transparent p-2")}>
233
-
234
- <Field
235
- name={typeFieldName}
236
- >
237
- {(fieldProps) => {
238
- const value1 = fieldProps.field.value !== undefined && fieldProps.field.value !== null ? fieldProps.field.value as string : "";
239
- return (
240
- <>
241
- <Select
242
- className="mb-2"
243
- placeholder={<Typography variant={"caption"}
244
- className={"px-4 py-2 font-medium"}>{t("type")}</Typography>}
245
- size={"medium"}
246
- fullWidth={true}
247
- position={"item-aligned"}
248
- value={value1}
249
- renderValue={(enumKey: string) =>
250
- <EnumValuesChip
251
- enumKey={enumKey}
252
- enumValues={enumValuesConfigs}
253
- size={"small"}/>
254
- }
255
- onValueChange={(value) => {
256
- updateType(value);
257
- }}>
258
- {enumValuesConfigs.map((enumConfig) => (
259
- <SelectItem
260
- key={enumConfig.id}
261
- value={String(enumConfig.id)}>
262
- <EnumValuesChip
263
- enumKey={enumConfig.id}
264
- enumValues={enumValuesConfigs}
265
- size={"small"}/>
266
- </SelectItem>)
267
- )}
268
- </Select>
269
- </>
270
- );
271
- }
272
- }
273
- </Field>
274
-
275
- {fieldProps && (
276
- // It is important to use this key to force a re-render of the field on type change
277
- <PropertyFieldBinding key={`form_control_${name}_${typeInternal}`} {...fieldProps}/>
278
- )}
279
-
280
- </div>
281
- );
282
- }
@@ -1,78 +0,0 @@
1
- import type { FieldProps } from "../../types/fields";
2
- import type { DateProperty } from "@rebasepro/types";
3
- import React from "react";
4
-
5
- ;
6
-
7
- import { FieldHelperText } from "../components/FieldHelperText";
8
- import { LabelWithIcon } from "../components/LabelWithIcon";
9
- import { useCustomizationController } from "@rebasepro/app";
10
- import { getIconForProperty } from "../../util/property_utils";
11
- import { DateTimeField } from "@rebasepro/ui";
12
- import { useClearRestoreValue } from "../useClearRestoreValue";
13
- import { PropertyIdCopyTooltip } from "../../components/PropertyIdCopyTooltip";
14
-
15
- type DateTimeFieldProps = FieldProps<DateProperty>;
16
-
17
- /**
18
- * Field that allows selecting a date
19
- *
20
- * This is one of the internal components that get mapped natively inside forms
21
- * and tables to the specified properties.
22
- * @group Form fields
23
- */
24
- export function DateTimeFieldBinding({
25
- propertyKey,
26
- value,
27
- setValue,
28
- autoFocus,
29
- error,
30
- showError,
31
- disabled,
32
- touched,
33
- property,
34
- includeDescription,
35
- hideLabel
36
- }: DateTimeFieldProps) {
37
-
38
- const { locale } = useCustomizationController();
39
- const internalValue = value || null;
40
-
41
- useClearRestoreValue({
42
- property,
43
- value,
44
- setValue
45
- });
46
-
47
- return (
48
- <>
49
- <PropertyIdCopyTooltip propertyKey={propertyKey}>
50
- <DateTimeField
51
- value={internalValue}
52
- onChange={(dateValue) => setValue(dateValue)}
53
- mode={property.mode}
54
- clearable={property.admin?.clearable}
55
- locale={locale}
56
- error={showError}
57
- disabled={disabled}
58
- label={hideLabel ? undefined : <LabelWithIcon
59
- icon={getIconForProperty(property, "small")}
60
- required={property.validation?.required}
61
- className={showError ? "text-red-500 dark:text-red-500" : "text-text-secondary dark:text-text-secondary-dark"}
62
- title={property.name ?? propertyKey}/>}
63
- // The entity form sets `hideLabel` for every field FieldBlock
64
- // labels on its behalf, and FieldBlock's label is a <span> that
65
- // points at nothing — so without this the control is nameless.
66
- aria-label={hideLabel ? (property.name ?? propertyKey) : undefined}
67
- />
68
- </PropertyIdCopyTooltip>
69
-
70
- <FieldHelperText includeDescription={includeDescription}
71
- showError={showError}
72
- error={error}
73
- disabled={disabled}
74
- property={property}/>
75
-
76
- </>
77
- );
78
- }
@@ -1,200 +0,0 @@
1
- import type { FieldProps } from "../../types/fields";
2
- import type { GeopointProperty } from "@rebasepro/types";
3
- import React, { useCallback, useEffect, useState } from "react";
4
- import { IconButton, TextField, Trash2Icon } from "@rebasepro/ui";
5
-
6
- import { FieldHelperText } from "../components/FieldHelperText";
7
- import { LabelWithIcon } from "../components/LabelWithIcon";
8
- import { useClearRestoreValue } from "../useClearRestoreValue";
9
- import { PropertyIdCopyTooltip } from "../../components/PropertyIdCopyTooltip";
10
- import { getIconForProperty } from "../../util/property_utils";
11
-
12
- /** Latitude runs −90…90, longitude −180…180. Anything else is not a place. */
13
- const LAT_RANGE: [number, number] = [-90, 90];
14
- const LNG_RANGE: [number, number] = [-180, 180];
15
-
16
- interface Coordinates { latitude: number; longitude: number }
17
-
18
- /**
19
- * Read whatever the driver handed us as a pair of coordinates.
20
- *
21
- * A geopoint arrives as a `GeoPoint` instance from the client, but as a plain
22
- * object once it has been through JSON — and PostGIS-backed rows may present it
23
- * as `{ x, y }`, where `x` is the longitude. Reading only one of those shapes
24
- * would render an empty field over data that is actually there.
25
- */
26
- export function readCoordinates(value: unknown): Coordinates | null {
27
- if (!value || typeof value !== "object") return null;
28
- const v = value as Record<string, unknown>;
29
-
30
- const lat = typeof v.latitude === "number" ? v.latitude : (typeof v.y === "number" ? v.y : undefined);
31
- const lng = typeof v.longitude === "number" ? v.longitude : (typeof v.x === "number" ? v.x : undefined);
32
-
33
- if (typeof lat !== "number" || typeof lng !== "number") return null;
34
- return { latitude: lat, longitude: lng };
35
- }
36
-
37
- const inRange = (n: number, [min, max]: [number, number]) => n >= min && n <= max;
38
-
39
- /**
40
- * Field binding for `type: "geopoint"`.
41
- *
42
- * The model has defined this type all along and the admin had no way to render
43
- * it: the widget lookup fell off the end of its chain, logged to the console
44
- * and returned undefined, so the field simply did not appear on the form. A
45
- * geopoint column was invisible in the admin panel, and unreachable in the
46
- * property editor.
47
- *
48
- * Two number inputs rather than a map. A map needs a tile provider, which means
49
- * a network dependency and an API key, and neither belongs in a field binding
50
- * that has to work offline and in every deployment. Coordinates are typed,
51
- * pasted and copied far more often than they are dropped on a map.
52
- *
53
- * @group Form fields
54
- */
55
- export function GeopointFieldBinding({
56
- propertyKey,
57
- value,
58
- setValue,
59
- error,
60
- showError,
61
- disabled,
62
- autoFocus,
63
- property,
64
- includeDescription,
65
- hideLabel,
66
- size = "large"
67
- }: FieldProps<GeopointProperty>) {
68
-
69
- const coordinates = readCoordinates(value);
70
-
71
- // Held as text while editing: a half-typed "-" or "12." is not a number
72
- // yet, and rounding it through `Number` on every keystroke fights the user.
73
- const [latText, setLatText] = useState(() => coordinates ? String(coordinates.latitude) : "");
74
- const [lngText, setLngText] = useState(() => coordinates ? String(coordinates.longitude) : "");
75
-
76
- useEffect(() => {
77
- const next = readCoordinates(value);
78
- setLatText(next ? String(next.latitude) : "");
79
- setLngText(next ? String(next.longitude) : "");
80
- }, [coordinates?.latitude, coordinates?.longitude]);
81
-
82
- useClearRestoreValue({ property, value, setValue });
83
-
84
- const commit = useCallback((rawLat: string, rawLng: string) => {
85
- // Both empty means "no location", which is different from 0,0 — a real
86
- // point in the Gulf of Guinea, and the classic way a cleared field
87
- // turns into a wrong one.
88
- if (rawLat.trim() === "" && rawLng.trim() === "") {
89
- setValue(null);
90
- return;
91
- }
92
- // One side filled and the other still empty is a location half typed,
93
- // not a location. Committing it would send the empty side through
94
- // `Number("")`, which is 0 and perfectly finite — so typing a latitude
95
- // and pausing used to write longitude 0 and drop the point in the Gulf
96
- // of Guinea. Hold until both sides are there; `halfEntered` below says
97
- // so in the meantime.
98
- if (rawLat.trim() === "" || rawLng.trim() === "") return;
99
-
100
- const latitude = Number(rawLat);
101
- const longitude = Number(rawLng);
102
- if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return;
103
- setValue({ latitude, longitude } as never);
104
- }, [setValue]);
105
-
106
- const handleClear = useCallback((e: React.MouseEvent) => {
107
- e.stopPropagation();
108
- e.preventDefault();
109
- setLatText("");
110
- setLngText("");
111
- setValue(null);
112
- }, [setValue]);
113
-
114
- const latNumber = Number(latText);
115
- const lngNumber = Number(lngText);
116
- const latInvalid = latText.trim() !== "" && (!Number.isFinite(latNumber) || !inRange(latNumber, LAT_RANGE));
117
- const lngInvalid = lngText.trim() !== "" && (!Number.isFinite(lngNumber) || !inRange(lngNumber, LNG_RANGE));
118
-
119
- // One side filled and the other empty is not a point.
120
- const halfEntered = (latText.trim() === "") !== (lngText.trim() === "");
121
-
122
- const localError = latInvalid
123
- ? `Latitude must be between ${LAT_RANGE[0]} and ${LAT_RANGE[1]}`
124
- : lngInvalid
125
- ? `Longitude must be between ${LNG_RANGE[0]} and ${LNG_RANGE[1]}`
126
- : halfEntered
127
- ? "A location needs both a latitude and a longitude"
128
- : undefined;
129
-
130
- return (
131
- <div className="flex flex-col gap-2 w-full">
132
- {/* Label only, and only when there is one: a row that survives
133
- `hideLabel` still spends its `mb-1` and the column's `gap-2`, so
134
- the pair of inputs sat below the control next to them even
135
- though the two labels were level. */}
136
- {!hideLabel && <div className="flex items-center justify-between mb-1">
137
- <LabelWithIcon
138
- icon={getIconForProperty(property, "small")}
139
- required={property.validation?.required}
140
- title={property.name ?? propertyKey}
141
- />
142
- </div>}
143
-
144
- <PropertyIdCopyTooltip propertyKey={propertyKey}>
145
- {/* Clear sits beside the inputs rather than above them, so
146
- entering a location does not grow the field by a row and
147
- knock it out of line with its neighbour. */}
148
- <div className="flex gap-4 w-full items-center">
149
- <TextField
150
- className="flex-1"
151
- size={size}
152
- label="Latitude"
153
- value={latText}
154
- autoFocus={autoFocus}
155
- disabled={disabled}
156
- error={showError ? Boolean(error) || latInvalid : latInvalid}
157
- onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
158
- setLatText(e.target.value);
159
- commit(e.target.value, lngText);
160
- }}
161
- placeholder="e.g. 41.3874"
162
- inputClassName="font-mono"
163
- />
164
- <TextField
165
- className="flex-1"
166
- size={size}
167
- label="Longitude"
168
- value={lngText}
169
- disabled={disabled}
170
- error={showError ? Boolean(error) || lngInvalid : lngInvalid}
171
- onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
172
- setLngText(e.target.value);
173
- commit(latText, e.target.value);
174
- }}
175
- placeholder="e.g. 2.1686"
176
- inputClassName="font-mono"
177
- />
178
- {!disabled && (latText || lngText) && (
179
- <IconButton
180
- size="small"
181
- onClick={handleClear}
182
- className="shrink-0 text-text-secondary hover:text-red-500"
183
- aria-label="Clear location"
184
- >
185
- <Trash2Icon size={14}/>
186
- </IconButton>
187
- )}
188
- </div>
189
- </PropertyIdCopyTooltip>
190
-
191
- <FieldHelperText
192
- includeDescription={includeDescription}
193
- showError={showError || Boolean(localError)}
194
- error={error || localError}
195
- disabled={disabled}
196
- property={property}
197
- />
198
- </div>
199
- );
200
- }