@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.
- package/README.md +3 -3
- package/dist/collection_editor/_cms_internals.d.ts +0 -1
- package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
- package/dist/components/AdditionalFieldValue.d.ts +9 -3
- package/dist/components/AdditionalFieldValue.js +7 -4
- package/dist/components/AdditionalFieldValue.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +117 -18
- package/dist/components/CollectionPanel.js +115 -37
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
- package/dist/components/CollectionTableBinding/column_utils.js +6 -3
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
- package/dist/components/CollectionTableBinding/internal/common.js +88 -4
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
- package/dist/components/CollectionViewBinding/RowActions.js +60 -0
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
- package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
- package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
- package/dist/components/CollectionViewBinding/fields.js +47 -0
- package/dist/components/CollectionViewBinding/fields.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
- package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +3 -3
- package/dist/components/CollectionsProvider.js +4 -4
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/CollectionsScopeContext.d.ts +1 -1
- package/dist/components/CollectionsScopeContext.js +1 -1
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +2 -2
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +32 -68
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js +5 -4
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -2
- package/dist/components/EditViewBinding.js +25 -15
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.js +8 -5
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +8 -1
- package/dist/components/EntityViewBinding.js +43 -14
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +40 -0
- package/dist/components/EntityViewBody.js +90 -0
- package/dist/components/EntityViewBody.js.map +1 -0
- package/dist/components/FieldValue.d.ts +50 -0
- package/dist/components/FieldValue.js +81 -0
- package/dist/components/FieldValue.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PanelNotFound.d.ts +5 -0
- package/dist/components/PanelNotFound.js +21 -0
- package/dist/components/PanelNotFound.js.map +1 -0
- package/dist/components/RebaseCMS.d.ts +1 -1
- package/dist/components/RebaseCMS.js +11 -3
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +9 -3
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RebaseShell.js +10 -5
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/RecordDetail.d.ts +61 -0
- package/dist/components/RecordDetail.js +123 -0
- package/dist/components/RecordDetail.js.map +1 -0
- package/dist/components/RecordForm.d.ts +126 -0
- package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
- package/dist/components/RecordForm.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
- package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +5 -3
- package/dist/components/ReferenceWidget.js +10 -7
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.js +4 -4
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +2 -3
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
- package/dist/components/SelectableTable/SelectionStore.js +1 -1
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SidePanelBinding.js +13 -12
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/collection_prop.d.ts +18 -0
- package/dist/components/collection_prop.js +23 -0
- package/dist/components/collection_prop.js.map +1 -0
- package/dist/components/common/default_entity_actions.js +54 -54
- package/dist/components/common/default_entity_actions.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +4 -1
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
- package/dist/data_export/export/ExportCollectionAction.js +4 -3
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +6 -3
- package/dist/data_export/export/additional_fields.js +8 -4
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.js +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +255 -150
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js +3 -2
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +22 -11
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormField.d.ts +36 -0
- package/dist/form/FormField.js +41 -0
- package/dist/form/FormField.js.map +1 -0
- package/dist/form/FormFieldsContext.d.ts +69 -0
- package/dist/form/FormFieldsContext.js +143 -0
- package/dist/form/FormFieldsContext.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +4 -4
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/collection_showing.d.ts +8 -0
- package/dist/form/collection_showing.js +29 -0
- package/dist/form/collection_showing.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +2 -1
- package/dist/form/components/ErrorFocus.js.map +1 -1
- package/dist/form/components/FieldBlock.js +3 -1
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +5 -1
- package/dist/form/components/FormRail.js +5 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/FormSections.d.ts +5 -1
- package/dist/form/components/FormSections.js +11 -4
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/form_dom_ids.d.ts +25 -0
- package/dist/form/form_dom_ids.js +42 -0
- package/dist/form/form_dom_ids.js.map +1 -0
- package/dist/form/index.d.ts +3 -1
- package/dist/form/resolve_cell_property.d.ts +5 -0
- package/dist/form/resolve_cell_property.js +22 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.js +9 -9
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useEntityDisplay.js +6 -4
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useRecordActions.js +2 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useSelectionDialog.d.ts +20 -7
- package/dist/hooks/useSelectionDialog.js +29 -8
- package/dist/hooks/useSelectionDialog.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -9
- package/dist/mcp-view.d.ts +9 -0
- package/dist/mcp-view.js +2 -0
- package/dist/mcp_view/app_modules.d.ts +29 -0
- package/dist/mcp_view/app_modules.js +163 -0
- package/dist/mcp_view/app_modules.js.map +1 -0
- package/dist/mcp_view/bridge.d.ts +90 -0
- package/dist/mcp_view/bridge.js +205 -0
- package/dist/mcp_view/bridge.js.map +1 -0
- package/dist/mcp_view/code_app.d.ts +65 -0
- package/dist/mcp_view/code_app.js +139 -0
- package/dist/mcp_view/code_app.js.map +1 -0
- package/dist/mcp_view/index.d.ts +54 -0
- package/dist/mcp_view/index.js +262 -0
- package/dist/mcp_view/index.js.map +1 -0
- package/dist/mcp_view/payload.d.ts +78 -0
- package/dist/mcp_view/payload.js +155 -0
- package/dist/mcp_view/payload.js.map +1 -0
- package/dist/mcp_view/screen.d.ts +30 -0
- package/dist/mcp_view/screen.js +245 -0
- package/dist/mcp_view/screen.js.map +1 -0
- package/dist/mcp_view/storage_source.d.ts +14 -0
- package/dist/mcp_view/storage_source.js +29 -0
- package/dist/mcp_view/storage_source.js.map +1 -0
- package/dist/mcp_view/store.d.ts +9 -0
- package/dist/mcp_view/store.js +27 -0
- package/dist/mcp_view/store.js.map +1 -0
- package/dist/mcp_view/tool_driver.d.ts +160 -0
- package/dist/mcp_view/tool_driver.js +575 -0
- package/dist/mcp_view/tool_driver.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +34 -1
- package/dist/preview/components/DatePreview.js +72 -37
- package/dist/preview/components/DatePreview.js.map +1 -1
- package/dist/routes/RebaseRoute.js +1 -1
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +5 -3
- package/dist/selection/SelectionMenu.js +16 -9
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/resolve_selection.d.ts +61 -7
- package/dist/selection/resolve_selection.js +93 -11
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +60 -10
- package/dist/types/fields.d.ts +2 -65
- package/dist/util/dataControllerAdapter.d.ts +8 -0
- package/dist/util/dataControllerAdapter.js +11 -0
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/navigation_utils.d.ts +5 -4
- package/dist/util/navigation_utils.js +6 -6
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +8 -0
- package/dist/util/propertyConfigMapper.js +16 -2
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/package.json +15 -9
- package/recipes/README.md +79 -26
- package/recipes/approval-queue.tsx +79 -0
- package/recipes/bulk-set-status.tsx +23 -17
- package/recipes/calendar-view.tsx +28 -23
- package/recipes/master-detail.tsx +75 -0
- package/recipes/my-preferences.tsx +3 -3
- package/recipes/orders-dashboard.tsx +58 -84
- package/recipes/site-settings.tsx +4 -4
- package/dist/components/EntityFormPanel.d.ts +0 -63
- package/dist/components/EntityFormPanel.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_driver.js","names":[],"sources":["../../src/mcp_view/tool_driver.ts"],"sourcesContent":["/**\n * The admin panel's data layer, over the MCP tools of the server that served\n * this view.\n *\n * `<Rebase>` reads and writes through a `DataDriver`; this one turns each read\n * and write into a `tools/call` the host relays to the server — the same\n * tools, the same person, the same RLS as the model's own calls. Rows go and\n * come in the REST shape those tools speak (dates as ISO text, a belongsTo as\n * its foreign key); `<Rebase>` turns them into the admin panel's view model\n * and back, as it does for any driver.\n *\n * An app's row hooks (`useRows`, `useAggregate`, …) read the same driver\n * through the flat data layer (`buildRebaseData`), which keeps the wire's\n * rows and takes aggregates from `restFetchService`: here, the aggregate tool.\n *\n * A write the server answers with a plan (the hosted connector's two-step\n * `write`) is held: the person is shown the plan and the write is sent again\n * with its token only if they confirm. The row hooks write through\n * `confirmingDriver`, which asks the person before any other write too: code\n * can write without a click, while a save made with the admin's own controls\n * was the person's click. Either way the admin panel sees one save that took\n * a moment longer, or one that failed with \"Not saved\".\n *\n * The driver does not subscribe (no `listenCollection`/`listenOne`): every\n * write it makes comes through `<Rebase>`'s data layers, which say so on the\n * `<Rebase>`'s change signal, and each view of the collection reads again on\n * it. It learns of no change it did not make — the host relays no other\n * tool's calls — so it has nothing to announce either\n * (`subscribeToExternalChanges`).\n */\nimport {\n DEFAULT_DATA_SOURCE_KEY,\n type CollectionConfig,\n type DataDriver,\n type DeleteProps,\n type FetchCollectionProps,\n type FetchOneProps,\n type RestFetchService,\n type SaveProps\n} from \"@rebasepro/types\";\nimport {\n buildCompositeId,\n fieldKeyForColumn,\n getDeclaredPrimaryKeys,\n resolveCollectionRelations,\n resolvePrimaryKeys,\n type PrimaryKeyInfo\n} from \"@rebasepro/common\";\nimport { toWireRow } from \"@rebasepro/app\";\nimport { isRecord, type ToolResult } from \"./bridge\";\n\n/** A tool the view calls, and the arguments it always sends to it. */\nexport interface ToolAction {\n tool: string;\n arguments: Record<string, unknown>;\n /**\n * The tool answers a plan before it changes anything (the hosted\n * connector's `write`), so the person confirms there. Not set, a change\n * the row hooks make is confirmed in the view before it is sent.\n */\n plans?: boolean;\n}\n\n/**\n * The tools the view reads and writes with. The server that served it may\n * name its own (`actions` in a show_* result): the hosted Rebase connector\n * reads with `query` and writes with `write`, each with the project. Absent,\n * they are an app's own `/mcp` tools.\n */\nexport interface ViewActions {\n page: ToolAction;\n get: ToolAction;\n count: ToolAction;\n create: ToolAction;\n update: ToolAction;\n delete: ToolAction;\n /** `count`/`sum`/`avg`/`min`/`max` over the matching rows, grouped or not, as REST's `select` and `groupBy`. */\n aggregate: ToolAction;\n}\n\nexport const DEFAULT_ACTIONS: ViewActions = {\n page: { tool: \"query_collection\", arguments: {} },\n get: { tool: \"get_document\", arguments: {} },\n count: { tool: \"count_documents\", arguments: {} },\n create: { tool: \"create_document\", arguments: {} },\n update: { tool: \"update_document\", arguments: {} },\n delete: { tool: \"delete_document\", arguments: {} },\n aggregate: { tool: \"aggregate_documents\", arguments: {} }\n};\n\n/** What a write's first call answered instead of running: what it will do, for the person to confirm. */\nexport interface WritePlan {\n summary: string;\n effects?: string[];\n reversible?: string;\n}\n\n/** One change the person made here, as the model is told about it. */\nexport interface ViewChange {\n action: \"created\" | \"updated\" | \"deleted\";\n collection: string;\n id: string;\n /** The row as the person knows it — its title — where the driver can tell; see {@link ToolDriverOptions.rowLabel}. */\n label?: string;\n fields?: string[];\n}\n\n/** A write the server refused: what was tried, on which row, and the server's words. */\nexport interface WriteFailure {\n action: \"create\" | \"update\" | \"delete\";\n collection: string;\n /** The row, as {@link ToolDriverOptions.rowLabel} names it; absent for a create. */\n row?: string;\n message: string;\n}\n\n/** The calls the driver makes: the bridge's `callTool`, as a function so a test can stand in for the host. */\nexport type CallTool = (name: string, args: Record<string, unknown>) => Promise<ToolResult>;\n\n/**\n * A page a result already carries: the rows the server read — for the model\n * (show_collection), or ahead of an app's first render (show_app) — and the\n * arguments it read them with.\n */\nexport interface SeedPage {\n collection: string;\n /** As the read tools take them: `where`, `orderBy`, `searchString`, `limit`, `offset`. */\n args: Record<string, unknown>;\n rows: Record<string, unknown>[];\n /** How many rows the read's filter matches, where the server counted them: answers that count, once. */\n total?: number;\n}\n\nexport interface ToolDriverOptions {\n callTool: CallTool;\n actions: ViewActions;\n /** Show the person a write's plan; true when they confirm it. */\n confirm: (plan: WritePlan) => Promise<boolean>;\n /**\n * A page already read: served once in place of the read tool's call, to\n * a read asking for exactly it, and dropped by any write or once it is\n * older than the driver's read cache keeps a row.\n */\n seed?: SeedPage;\n /**\n * Pages read ahead of an app's first render, one per collection it\n * names: each served once as {@link seed} is, its rows answering a read\n * by key, and its `total` the count of the collection's rows.\n */\n seeds?: SeedPage[];\n /** Every change made through this driver, in order, after each one. */\n onChange?: (changes: readonly ViewChange[]) => void;\n /**\n * How a row is named to the person — in a write's confirmation, in a\n * refusal — given the row where the driver has read it: its title, say.\n * Without it, or where it says nothing, `row <id>`.\n */\n rowLabel?: (collection: string, id: string, row: Record<string, unknown> | undefined) => string | undefined;\n /**\n * A write through {@link ToolDriver.confirmingDriver} that the server\n * refused. App code can drop the rejection it gets; this is how the\n * person and the model still learn of it. A write the person declined is\n * not one.\n */\n onWriteFailed?: (failure: WriteFailure) => void;\n /**\n * The collection a name the tools take names — its slug or its data\n * path: an app names collections as the model wrote them, the admin\n * panel by slug. A write's values are sent by its config (a date-only\n * column as its day, a belongsTo under its foreign key), and drop what\n * was read of it under either name.\n */\n collection?: (name: string) => CollectionConfig | undefined;\n}\n\ntype Row = Record<string, unknown>;\n\nexport interface ToolDriver {\n /** For `<Rebase>`: the admin panel's reads and saves. */\n driver: DataDriver;\n /**\n * The same driver, asking the person before each write the tool does not\n * plan itself: for the row hooks (`useRowWrites`), since code can write\n * without a click. A declined write rejects with {@link SaveCancelledError}\n * and nothing is sent.\n */\n confirmingDriver: DataDriver;\n}\n\n/** A row asked for by key, waiting on its batch's page. */\ninterface QueuedRead {\n resolve: (row: Record<string, unknown> | undefined) => void;\n reject: (error: unknown) => void;\n}\n\n/** A save the person declined at the plan. The form shows it as the save's error. */\nexport class SaveCancelledError extends Error {\n constructor() {\n super(\"Not saved: the change was not confirmed.\");\n this.name = \"SaveCancelledError\";\n }\n}\n\n/** The ceiling every read tool takes for `limit` (`MAX_LIST_LIMIT`). */\nconst MAX_LIMIT = 1000;\n\n/**\n * How long a row read, or the seeded page, answers in place of the server.\n * Long enough for one render's relation previews and concurrent reads to\n * share a call, and for a row the person picks off the page they are looking\n * at to open with none; short enough that a row the model changed with its\n * own tools — which takes the person's message and the model's turn — is\n * read afresh when it is refreshed or opened again.\n */\nconst READ_TTL_MS = 30_000;\n\nexport function createToolDriver(options: ToolDriverOptions): ToolDriver {\n const { callTool, actions, confirm, onChange } = options;\n const configOf = options.collection ?? (() => undefined);\n const canonical = (collection: string) => configOf(collection)?.slug ?? collection;\n // Each seed answers its page once and its count once.\n let seeds = [...(options.seed ? [options.seed] : []), ...(options.seeds ?? [])]\n .map(page => ({ page, pageTaken: false, countTaken: page.total === undefined }));\n const seededAt = Date.now();\n const changes: ViewChange[] = [];\n // A table draws each row's relations by reading the related row, so a\n // page of orders asks for the same customer many times over. Each read is\n // a round trip through the host: one per row is shared until a write, or\n // until it is older than `READ_TTL_MS`, since the model can change a row\n // with its own tools and this driver never hears of it.\n const rows = new Map<string, { read: Promise<Record<string, unknown> | undefined>; at: number }>();\n // The counts asked for and not yet answered, by what they count.\n const counting = new Map<string, Promise<number>>();\n // The rows asked for by key in this tick and not yet read, by collection:\n // each collection's are read by one page call (`readQueued`).\n const queued = new Map<string, { key: PrimaryKeyInfo; reads: Map<string, QueuedRead> }>();\n let readsQueued = false;\n\n const call = async (action: ToolAction, args: Record<string, unknown>): Promise<unknown> => {\n const result = await callTool(action.tool, { ...action.arguments, ...args });\n if (result.isError) throw new Error(textOf(result) ?? \"The server refused this call.\");\n return result.structuredContent ?? parseText(result);\n };\n\n /** A write, through its plan where the server asks for one. */\n const write = async (action: ToolAction, args: Record<string, unknown>): Promise<unknown> => {\n const first = await call(action, args);\n const plan = planOf(first);\n if (!plan) return first;\n if (!await confirm(plan.plan)) throw new SaveCancelledError();\n const second = await call(action, { ...args, confirm: plan.token });\n if (planOf(second)) throw new Error(\"The server asked for confirmation again; nothing was saved.\");\n return second;\n };\n\n /**\n * What a write changed: what was read of its collection is dropped (the\n * seeded page, the rows), and the model is told. The views read again on\n * `<Rebase>`'s change signal, which the write's data layer emits.\n */\n const changed = (change: ViewChange) => {\n // Every seed, not only this collection's: a page carries the related\n // rows it includes, and a write to those changes it too.\n seeds = [];\n // A count asked before the write answers for before it; the views'\n // refresh asks again.\n counting.clear();\n const key = canonical(change.collection);\n for (const row of rows.keys()) if (canonical(row.slice(0, row.lastIndexOf(\"/\"))) === key) rows.delete(row);\n changes.push(change);\n onChange?.(changes);\n };\n\n /** A save's values as the write tools take them, by the collection's config where it is known. */\n const wireValues = (props: SaveProps, collection: string): Record<string, unknown> => {\n const defined = Object.fromEntries(Object.entries(props.values).filter(([, value]) => value !== undefined));\n return toWireRow(defined, props.collection ?? configOf(collection) ?? NO_CONFIG, { included: false });\n };\n\n /**\n * A page's rows into the row cache, keyed as {@link fetchOne} asks for\n * them: the row a view lists is the row its record opens with, and a row\n * an app was just shown opens with no call of its own. By the\n * collection's key where its config is known, by `id` otherwise; a write\n * to the collection drops them, as it drops every row read. Not a page\n * that lists deleted rows: `get` answers none for those.\n */\n const remember = (collection: string, page: Row[], config?: FetchCollectionProps[\"collection\"]) => {\n const keys = config ? getDeclaredPrimaryKeys(config) : [];\n for (const row of page) {\n const id = keys.length > 1 ? buildCompositeId(row, keys) : row[keys[0]?.fieldName ?? \"id\"];\n if (typeof id !== \"string\" && typeof id !== \"number\") continue;\n rows.set(`${collection}/${String(id)}`, { read: Promise.resolve(row), at: Date.now() });\n }\n };\n // A seeded row opens with no call of its own — a record form, a detail,\n // a relation's title — even where no read asks for the page it came in.\n for (const { page } of seeds) remember(page.collection, page.rows, configOf(page.collection));\n\n /**\n * The seeded page, once, to a read asking for exactly it — or for more\n * of the same rows where the seed already holds every one: a view asks\n * one row past its page to learn whether there are more, and a page\n * shorter than its limit has answered that.\n */\n const takeSeed = (collection: string, args: Record<string, unknown>): Row[] | undefined => {\n if (Date.now() - seededAt > READ_TTL_MS) seeds = [];\n const seed = seeds.find(candidate => !candidate.pageTaken\n && canonical(candidate.page.collection) === canonical(collection) && readKey(candidate.page.args) === readKey(args));\n if (!seed) return undefined;\n const seedLimit = limitOf(seed.page.args);\n const readLimit = limitOf(args);\n const complete = seedLimit === undefined || seed.page.rows.length < seedLimit;\n const answers = readLimit === seedLimit || (complete && (readLimit === undefined || seedLimit === undefined || readLimit > seedLimit));\n if (!answers) return undefined;\n seed.pageTaken = true;\n return seed.page.rows;\n };\n\n /** The count a seed's `total` answers — the collection's rows, unfiltered — once. */\n const takeSeedCount = (collection: string, args: Record<string, unknown>): number | undefined => {\n if (Date.now() - seededAt > READ_TTL_MS) seeds = [];\n if (args.where !== undefined || args.searchString !== undefined || args.deleted !== undefined) return undefined;\n const seed = seeds.find(candidate => !candidate.countTaken && canonical(candidate.page.collection) === canonical(collection)\n && candidate.page.args.where === undefined && candidate.page.args.searchString === undefined);\n if (!seed || seed.page.total === undefined) return undefined;\n seed.countTaken = true;\n return seed.page.total;\n };\n\n const fetchCollection = async (props: FetchCollectionProps): Promise<Record<string, unknown>[]> => {\n const collection = collectionArg(props.path);\n const args = readArgs(props);\n let found = takeSeed(collection, args);\n if (!found) {\n const page = await call(actions.page, { collection, ...args });\n if (!isRecord(page) || !Array.isArray(page.data)) throw new Error(\"The read returned no rows.\");\n found = page.data.filter(isRecord);\n }\n if (!props.withDeleted) remember(collection, found, props.collection);\n return found;\n };\n\n /**\n * The rows asked for by key in one tick, read together: one page call per\n * collection, `where <key> in [ids]`, however many relation previews a\n * render draws — as the admin's `useBatchedFetch` reads them, chunked at\n * the read tools' ceiling. A row the page does not carry is absent or not\n * visible to the person: one answer for both, as the get tool gives.\n */\n const readQueued = () => {\n readsQueued = false;\n const batches = [...queued];\n queued.clear();\n for (const [collection, { key, reads }] of batches) {\n const ids = [...reads.keys()];\n for (let i = 0; i < ids.length; i += MAX_LIMIT) {\n const chunk = ids.slice(i, i + MAX_LIMIT);\n const values = chunk.map(id => key.type === \"number\" && id.trim() !== \"\" && !Number.isNaN(Number(id)) ? Number(id) : id);\n call(actions.page, { collection, where: { [key.fieldName]: [\"in\", values] }, limit: chunk.length })\n .then(page => {\n if (!isRecord(page) || !Array.isArray(page.data)) throw new Error(\"The read returned no rows.\");\n const byId = new Map(page.data.filter(isRecord).map(row => [String(row[key.fieldName]), row]));\n for (const id of chunk) reads.get(id)?.resolve(byId.get(id));\n })\n .catch((error: unknown) => {\n for (const id of chunk) reads.get(id)?.reject(error);\n });\n }\n }\n };\n\n const readByKey = (collection: string, id: string, key: PrimaryKeyInfo): Promise<Row | undefined> =>\n new Promise((resolve, reject) => {\n let batch = queued.get(collection);\n if (!batch) {\n batch = { key, reads: new Map() };\n queued.set(collection, batch);\n }\n batch.reads.set(id, { resolve, reject });\n if (!readsQueued) {\n readsQueued = true;\n queueMicrotask(readQueued);\n }\n });\n\n /** A row of a collection with no single key column to put an `in` on, or none known: by the get tool. */\n const readById = (collection: string, id: string): Promise<Row | undefined> =>\n call(actions.get, { collection, id })\n .then(row => isRecord(row) ? row : undefined)\n .catch((error: unknown) => {\n // One answer for \"absent\" and \"not visible to you\", by design.\n if (error instanceof Error && /^No row with id/.test(error.message)) return undefined;\n throw error;\n });\n\n /**\n * A row: by the page tool wherever its collection has one key column — a\n * lone row as well as a crowd of previews. One rule, so a row is read the\n * same way however many are drawn beside it; and the page tool is the one\n * every server names (a hosted result may name no `get`), whose answer\n * for an absent row is an empty page rather than an error told apart by\n * its text.\n */\n const fetchOne = (props: FetchOneProps): Promise<Record<string, unknown> | undefined> => {\n const collection = collectionArg(props.path);\n const key = `${collection}/${String(props.id)}`;\n const cached = rows.get(key);\n if (cached && Date.now() - cached.at <= READ_TTL_MS) return cached.read;\n const config = props.collection ?? configOf(collection);\n const keys = config ? resolvePrimaryKeys(config) : [];\n const read: Promise<Row | undefined> = (keys.length === 1\n ? readByKey(collection, String(props.id), keys[0])\n : readById(collection, String(props.id)))\n .catch((error: unknown) => {\n if (rows.get(key)?.read === read) rows.delete(key);\n throw error;\n });\n rows.set(key, { read, at: Date.now() });\n return read;\n };\n\n /**\n * The flat data layer's reads: the same tools and the same rows as the\n * admin panel's, and the aggregate tool.\n */\n const restFetchService: RestFetchService = {\n fetchCollectionForRest(path, options = {}) {\n refuseUnsupported(options);\n return fetchCollection({\n path,\n ...(options.filter && { filter: options.filter }),\n ...(options.orderBy !== undefined && { orderBy: options.orderBy }),\n ...(options.order && { order: options.order }),\n ...(options.limit !== undefined && { limit: options.limit }),\n ...(options.offset !== undefined && { offset: options.offset }),\n ...(options.searchString && { searchString: options.searchString }),\n ...(options.withDeleted !== undefined && { withDeleted: options.withDeleted })\n });\n },\n async fetchOneForRest(path, id) {\n return await fetchOne({ path, id }) ?? null;\n },\n async aggregate(path, options) {\n refuseUnsupported(options);\n const where = options.filter ? wireFilter(options.filter, undefined) : undefined;\n const answer = await call(actions.aggregate, {\n collection: collectionArg(path),\n select: options.aggregates.map(aggregate => aggregate.fn === \"percentile\"\n ? `${aggregate.fn}(${aggregate.field ?? \"\"},${aggregate.p})`\n : `${aggregate.fn}(${aggregate.field ?? \"\"})`),\n ...(options.groupBy && options.groupBy.length > 0 && {\n groupBy: options.groupBy.map(group => typeof group === \"string\" ? group : `${group.transform}(${group.field})`)\n }),\n ...(where && Object.keys(where).length > 0 && { where }),\n ...(options.searchString && { searchString: options.searchString }),\n ...(options.orderBy && options.orderBy.length > 0 && { orderBy: options.orderBy }),\n ...(options.limit !== undefined && { limit: Math.min(options.limit, MAX_LIMIT) }),\n ...(options.offset && { offset: options.offset }),\n ...(options.withDeleted && { deleted: options.withDeleted === \"only\" ? \"only\" : \"include\" })\n });\n if (!isRecord(answer) || !Array.isArray(answer.data)) throw new Error(\"The aggregate returned no rows.\");\n return answer.data.filter(isRecord);\n }\n };\n\n const driver: DataDriver = {\n key: DEFAULT_DATA_SOURCE_KEY,\n initialised: true,\n\n fetchCollection,\n fetchOne,\n restFetchService,\n\n async save(props: SaveProps): Promise<Record<string, unknown>> {\n const collection = collectionArg(props.path);\n const data = wireValues(props, collection);\n const creating = props.status !== \"existing\";\n const action = creating ? actions.create : actions.update;\n const saved = creating\n ? await write(action, { collection, data, ...(props.id !== undefined && { id: String(props.id) }) })\n : await write(action, { collection, id: String(props.id), data });\n const row = isRecord(saved) ? saved : { ...data };\n const id = String(row.id ?? props.id ?? \"\");\n const label = options.rowLabel?.(collection, id, row);\n changed({ action: creating ? \"created\" : \"updated\", collection, id, ...(label && { label }), fields: Object.keys(data) });\n return row;\n },\n\n async delete(props: DeleteProps): Promise<void> {\n const collection = collectionArg(props.row.path);\n const id = String(props.row.id);\n // Named before the write: it drops what was read of the collection.\n const cached = await rows.get(`${collection}/${id}`)?.read.catch(() => undefined);\n const label = options.rowLabel?.(collection, id, cached ?? undefined);\n await write(actions.delete, { collection, id });\n changed({ action: \"deleted\", collection, id, ...(label && { label }) });\n },\n\n async count(props: FetchCollectionProps): Promise<number> {\n const collection = collectionArg(props.path);\n const args = pickRead(readArgs(props), [\"where\", \"searchString\", \"deleted\"]);\n const seeded = takeSeedCount(collection, args);\n if (seeded !== undefined) return seeded;\n // One call for the same count asked twice at once — a KPI tile and\n // the panel listing the same rows, on one render.\n const key = `${canonical(collection)}|${readKey(args)}`;\n const inFlight = counting.get(key);\n if (inFlight) return inFlight;\n const counted: Promise<number> = call(actions.count, { collection, ...args }).then((answer) => {\n if (isRecord(answer) && typeof answer.count === \"number\") return answer.count;\n throw new Error(\"The count returned no number.\");\n }).finally(() => {\n // Only its own entry: a write may have cleared it, and a new count taken its place.\n if (counting.get(key) === counted) counting.delete(key);\n });\n counting.set(key, counted);\n return counted;\n },\n\n // The server checks a unique field when the row is written; a check\n // here would be one more round trip through the host for each keystroke.\n async checkUniqueField(): Promise<boolean> {\n return true;\n }\n };\n\n /** The person's yes before a write the tool does not plan; their no rejects, and nothing is sent. */\n const confirmFirst = async (action: ToolAction, plan: WritePlan): Promise<void> => {\n if (!action.plans && !await confirm(plan)) throw new SaveCancelledError();\n };\n\n /** A row as the person knows it: its title where it has been read, else `row <id>`. */\n const labelOf = async (collection: string, id: string): Promise<string> => {\n const row = await rows.get(`${collection}/${id}`)?.read.catch(() => undefined);\n return options.rowLabel?.(collection, id, row ?? undefined) || `row ${id}`;\n };\n\n /** A refused write, told; the rejection still reaches the caller. */\n const reported = async <T, >(failure: Omit<WriteFailure, \"message\">, write: () => Promise<T>): Promise<T> => {\n try {\n return await write();\n } catch (error) {\n if (!(error instanceof SaveCancelledError)) {\n options.onWriteFailed?.({ ...failure, message: error instanceof Error ? error.message : String(error) });\n }\n throw error;\n }\n };\n\n const confirmingDriver: DataDriver = {\n ...driver,\n async save(props: SaveProps): Promise<Record<string, unknown>> {\n const collection = collectionArg(props.path);\n const creating = props.status !== \"existing\";\n const row = creating ? undefined : await labelOf(collection, String(props.id));\n await confirmFirst(creating ? actions.create : actions.update, creating\n ? { summary: `Create a row in ${collection}.` }\n : { summary: `Change ${Object.keys(wireValues(props, collection)).join(\", \")} on ${row} of ${collection}.` });\n return reported({ action: creating ? \"create\" : \"update\", collection, ...(row && { row }) }, () => driver.save(props));\n },\n async delete(props: DeleteProps): Promise<void> {\n const collection = collectionArg(props.row.path);\n const row = await labelOf(collection, String(props.row.id));\n await confirmFirst(actions.delete, { summary: `Delete ${row} of ${collection}.` });\n return reported({ action: \"delete\", collection, row }, () => driver.delete(props));\n }\n };\n\n return { driver, confirmingDriver };\n}\n\n/**\n * The collection a driver path names. The views open top-level collections\n * only; a subcollection path has no tool to read it.\n */\nfunction collectionArg(path: string): string {\n if (path.includes(\"/\")) throw new Error(`\"${path}\" is a subcollection, which this view cannot open.`);\n return path;\n}\n\n/** A read's arguments, as the read tools take them. */\nfunction readArgs(props: FetchCollectionProps): Record<string, unknown> {\n const where = props.filter ? wireFilter(props.filter, props.collection) : undefined;\n const orderBy = wireOrderBy(props, props.collection);\n return {\n ...(where && Object.keys(where).length > 0 && { where }),\n ...(orderBy && { orderBy }),\n ...(props.searchString && { searchString: props.searchString }),\n ...(props.limit !== undefined && { limit: Math.min(props.limit, MAX_LIMIT) }),\n ...(props.offset && { offset: props.offset }),\n ...(props.withDeleted !== undefined && props.withDeleted !== false && {\n deleted: props.withDeleted === \"only\" ? \"only\" : \"include\"\n })\n };\n}\n\n/** What the read tools cannot express, refused rather than read wider than asked. */\nfunction refuseUnsupported(options: { logical?: unknown; vectorSearch?: unknown }): void {\n if (options.logical) throw new Error(\"This view's tools cannot filter by an or()/and() group.\");\n if (options.vectorSearch) throw new Error(\"This view's tools cannot run a vector search.\");\n}\n\n/**\n * Which rows a read asks for, as one comparable string: the same rows however\n * the read was written — a sort as `\"field:desc\"` or `[[\"field\", \"desc\"]]`, a\n * filter's fields in any order, no offset or offset 0. How many is\n * {@link limitOf}'s.\n */\nfunction readKey(args: Record<string, unknown>): string {\n const where = isRecord(args.where) ? args.where : {};\n return JSON.stringify([\n Object.keys(where).sort().map(key => [key, where[key]]),\n sortOf(args.orderBy),\n typeof args.searchString === \"string\" ? args.searchString : \"\",\n typeof args.offset === \"number\" ? args.offset : 0,\n typeof args.deleted === \"string\" ? args.deleted : null\n ]);\n}\n\nfunction limitOf(args: Record<string, unknown>): number | undefined {\n return typeof args.limit === \"number\" ? args.limit : undefined;\n}\n\nfunction sortOf(orderBy: unknown): unknown[] {\n if (typeof orderBy === \"string\" && orderBy !== \"\") {\n const [field, direction] = orderBy.split(\":\");\n return [[field, direction === \"desc\" ? \"desc\" : \"asc\"]];\n }\n if (!Array.isArray(orderBy) || orderBy.length === 0) return [];\n const entries: unknown[] = Array.isArray(orderBy[0]) ? orderBy : [orderBy];\n return entries.map(entry => Array.isArray(entry) ? [entry[0], entry[1] === \"desc\" ? \"desc\" : \"asc\"] : entry);\n}\n\nfunction pickRead(args: Record<string, unknown>, names: readonly string[]): Record<string, unknown> {\n return Object.fromEntries(Object.entries(args).filter(([name]) => names.includes(name)));\n}\n\n/**\n * The admin panel's filter as the read tools' `where`: a belongsTo is\n * filtered by its foreign key there, and a value is the wire's — a relation\n * its id, a date its ISO text.\n */\nfunction wireFilter(filter: Record<string, unknown>, collection: CollectionConfig | undefined): Record<string, unknown> {\n const keys = foreignKeys(collection);\n const where: Record<string, unknown> = {};\n for (const [key, condition] of Object.entries(filter)) {\n if (condition === undefined) continue;\n // A condition is `[op, value]`, each part converted as a row's value is.\n where[keys.get(key) ?? key] = toWireRow({ condition }, NO_CONFIG).condition;\n }\n return where;\n}\n\n/** No properties, so {@link toWireRow} converts each value by what it is: a relation to its id, a date to ISO text. */\nconst NO_CONFIG: CollectionConfig = { slug: \"\", name: \"\", properties: {} };\n\nfunction wireOrderBy(props: FetchCollectionProps, collection: CollectionConfig | undefined): string | unknown[] | undefined {\n const keys = foreignKeys(collection);\n if (typeof props.orderBy === \"string\") {\n const field = keys.get(props.orderBy) ?? props.orderBy;\n return props.order ? `${field}:${props.order}` : field;\n }\n if (Array.isArray(props.orderBy) && props.orderBy.length > 0) {\n return props.orderBy.map(entry => Array.isArray(entry) && typeof entry[0] === \"string\"\n ? [keys.get(entry[0]) ?? entry[0], ...entry.slice(1)]\n : entry);\n }\n return undefined;\n}\n\n/** A collection's belongsTo relations, by name → the foreign key its rows carry. */\nfunction foreignKeys(collection: CollectionConfig | undefined): Map<string, string> {\n const keys = new Map<string, string>();\n if (!collection) return keys;\n try {\n for (const [name, relation] of Object.entries(resolveCollectionRelations(collection))) {\n if (relation.kind === \"belongsTo\" && relation.localKey) {\n keys.set(name, fieldKeyForColumn(collection, relation.localKey));\n }\n }\n } catch {\n // A relation whose target is not in this view: no key to rename.\n }\n return keys;\n}\n\n/** A write's plan and token, where its first call answered one (the server's `confirmation.ts`). */\nfunction planOf(answer: unknown): { token: string; plan: WritePlan } | undefined {\n if (!isRecord(answer) || answer.status !== \"confirmation_required\" || typeof answer.confirm !== \"string\") return undefined;\n const plan = isRecord(answer.plan) ? answer.plan : {};\n return {\n token: answer.confirm,\n plan: {\n summary: typeof plan.summary === \"string\" ? plan.summary : \"Save this change?\",\n ...(Array.isArray(plan.effects) && { effects: plan.effects.filter((line): line is string => typeof line === \"string\") }),\n ...(typeof plan.reversible === \"string\" && { reversible: plan.reversible })\n }\n };\n}\n\n/** A result with no `structuredContent`: its text, as JSON where it is JSON. */\nfunction parseText(result: ToolResult): unknown {\n const text = textOf(result);\n if (text === undefined) return undefined;\n // The server fences rows as untrusted data; the JSON is inside the fence.\n const start = text.indexOf(\"{\");\n const end = text.lastIndexOf(\"}\");\n if (start < 0 || end < start) return undefined;\n try {\n return JSON.parse(text.slice(start, end + 1));\n } catch {\n return undefined;\n }\n}\n\nexport function textOf(result: ToolResult): string | undefined {\n return result.content?.find(block => typeof block.text === \"string\")?.text;\n}\n\n/** What the model is told the person changed here, sent with their next message. */\n/** \"update ORD-2026-0081 in orders\", \"create a row in orders\". */\nexport function describeFailedWrite(failure: WriteFailure): string {\n return failure.action === \"create\"\n ? `create a row in ${failure.collection}`\n : `${failure.action} ${failure.row ?? \"a row\"} in ${failure.collection}`;\n}\n\nexport function describeChanges(changes: readonly ViewChange[]): string {\n const rowOf = (change: ViewChange) => change.label ? `${change.label} (row ${change.id})` : `row ${change.id}`;\n const lines = changes.map(change => change.action === \"updated\"\n ? `updated ${change.fields?.join(\", \") || \"fields\"} on ${rowOf(change)} of ${change.collection}`\n : `${change.action} ${rowOf(change)} of ${change.collection}`);\n return `In the Rebase view, the user saved these changes: ${lines.join(\"; \")}. `\n + \"Rows you read before them may be out of date.\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,IAAa,kBAA+B;CACxC,MAAM;EAAE,MAAM;EAAoB,WAAW,CAAC;CAAE;CAChD,KAAK;EAAE,MAAM;EAAgB,WAAW,CAAC;CAAE;CAC3C,OAAO;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CAChD,QAAQ;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CACjD,QAAQ;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;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AAU,QAA6B;CAC5C,MAAM,OAAO,OAAO,MAAM;CAC1B,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;CAE/B,MAAM,QAAQ,KAAK,QAAQ,GAAG;CAC9B,MAAM,MAAM,KAAK,YAAY,GAAG;CAChC,IAAI,QAAQ,KAAK,MAAM,OAAO,OAAO,KAAA;CACrC,IAAI;EACA,OAAO,KAAK,MAAM,KAAK,MAAM,OAAO,MAAM,CAAC,CAAC;CAChD,QAAQ;EACJ;CACJ;AACJ;AAEA,SAAgB,OAAO,QAAwC;CAC3D,OAAO,OAAO,SAAS,MAAK,UAAS,OAAO,MAAM,SAAS,QAAQ,CAAC,EAAE;AAC1E;;;AAIA,SAAgB,oBAAoB,SAA+B;CAC/D,OAAO,QAAQ,WAAW,WACpB,mBAAmB,QAAQ,eAC3B,GAAG,QAAQ,OAAO,GAAG,QAAQ,OAAO,QAAQ,MAAM,QAAQ;AACpE;AAEA,SAAgB,gBAAgB,SAAwC;CACpE,MAAM,SAAS,WAAuB,OAAO,QAAQ,GAAG,OAAO,MAAM,QAAQ,OAAO,GAAG,KAAK,OAAO,OAAO;CAI1G,OAAO,qDAHO,QAAQ,KAAI,WAAU,OAAO,WAAW,YAChD,WAAW,OAAO,QAAQ,KAAK,IAAI,KAAK,SAAS,MAAM,MAAM,MAAM,EAAE,MAAM,OAAO,eAClF,GAAG,OAAO,OAAO,GAAG,MAAM,MAAM,EAAE,MAAM,OAAO,YACO,CAAA,CAAM,KAAK,IAAI,EAAE;AAEjF"}
|
|
@@ -1,17 +1,50 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { Locale as DateFnsLocale } from "date-fns";
|
|
2
3
|
export interface DatePreviewProps {
|
|
3
4
|
date: Date;
|
|
4
5
|
/**
|
|
5
6
|
* Display mode: "date" for date-only, "date_time" for date and time,
|
|
6
7
|
* "time" for a time of day (a `time` column) with no day at all
|
|
7
8
|
*/
|
|
8
|
-
mode?:
|
|
9
|
+
mode?: DatePreviewMode;
|
|
9
10
|
/**
|
|
10
11
|
* IANA timezone identifier (e.g., "America/New_York")
|
|
11
12
|
* When specified, the date will be displayed in this timezone
|
|
12
13
|
*/
|
|
13
14
|
timezone?: string;
|
|
14
15
|
}
|
|
16
|
+
export type DatePreviewMode = "date" | "date_time" | "time";
|
|
17
|
+
export interface DatePreviewFormatOptions {
|
|
18
|
+
mode?: DatePreviewMode;
|
|
19
|
+
timezone?: string;
|
|
20
|
+
/** The admin's configured locale (`customizationController.locale`). */
|
|
21
|
+
locale?: string;
|
|
22
|
+
/** The admin's configured format (`customizationController.dateTimeFormat`). */
|
|
23
|
+
dateTimeFormat?: string;
|
|
24
|
+
/** The date-fns locale matching `locale`, once it has loaded. */
|
|
25
|
+
dateFnsLocale?: DateFnsLocale;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The text a `DatePreview` shows, and the zone abbreviation drawn after it.
|
|
29
|
+
*
|
|
30
|
+
* Pulled out of the component so the table can size a date column from the
|
|
31
|
+
* very string its cells will render — see `getDateColumnWidth`. Two copies of
|
|
32
|
+
* this logic would drift, and a column a few characters too narrow wraps every
|
|
33
|
+
* date in it onto a second line the row has no height for.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatDatePreview(date: Date, { mode, timezone, locale, dateTimeFormat, dateFnsLocale }: DatePreviewFormatOptions): {
|
|
36
|
+
text: string;
|
|
37
|
+
zone?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The date-fns locale for the admin's configured locale.
|
|
41
|
+
*
|
|
42
|
+
* The locale arrives asynchronously (see `date_fns_locales`). Seeded from the
|
|
43
|
+
* cache so only the very first date on a page renders un-localised: by the
|
|
44
|
+
* time a table of them mounts, the module is already resolved and there is no
|
|
45
|
+
* second pass.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useDateFnsLocale(): DateFnsLocale | undefined;
|
|
15
48
|
/**
|
|
16
49
|
* @group Preview components
|
|
17
50
|
*/
|
|
@@ -27,22 +27,14 @@ function cachedFormatter(key, build) {
|
|
|
27
27
|
return formatter;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* The text a `DatePreview` shows, and the zone abbreviation drawn after it.
|
|
31
|
+
*
|
|
32
|
+
* Pulled out of the component so the table can size a date column from the
|
|
33
|
+
* very string its cells will render — see `getDateColumnWidth`. Two copies of
|
|
34
|
+
* this logic would drift, and a column a few characters too narrow wraps every
|
|
35
|
+
* date in it onto a second line the row has no height for.
|
|
31
36
|
*/
|
|
32
|
-
function
|
|
33
|
-
const customizationController = useCustomizationController();
|
|
34
|
-
const configuredLocale = customizationController?.locale;
|
|
35
|
-
const [dateUtilsLocale, setDateUtilsLocale] = React.useState(() => getLoadedDateFnsLocale(configuredLocale));
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
let cancelled = false;
|
|
38
|
-
loadDateFnsLocale(configuredLocale).then((loaded) => {
|
|
39
|
-
if (!cancelled) setDateUtilsLocale(loaded);
|
|
40
|
-
}).catch((error) => console.error(`[rebase] could not load the "${configuredLocale}" date locale`, error));
|
|
41
|
-
return () => {
|
|
42
|
-
cancelled = true;
|
|
43
|
-
};
|
|
44
|
-
}, [configuredLocale]);
|
|
45
|
-
if (!date || !(date instanceof Date) || isNaN(date.getTime())) return /* @__PURE__ */ jsx(Fragment, {});
|
|
37
|
+
function formatDatePreview(date, { mode = "date_time", timezone, locale, dateTimeFormat, dateFnsLocale }) {
|
|
46
38
|
if (timezone) {
|
|
47
39
|
const options = mode === "time" ? { timeZone: timezone } : {
|
|
48
40
|
year: "numeric",
|
|
@@ -54,34 +46,77 @@ function DatePreview({ date, mode = "date_time", timezone }) {
|
|
|
54
46
|
options.hour = "2-digit";
|
|
55
47
|
options.minute = "2-digit";
|
|
56
48
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
children: [formattedDate, tzAbbrev && /* @__PURE__ */ jsxs("span", {
|
|
66
|
-
className: "text-xs text-slate-500 dark:text-slate-400",
|
|
67
|
-
children: [
|
|
68
|
-
"(",
|
|
69
|
-
tzAbbrev,
|
|
70
|
-
")"
|
|
71
|
-
]
|
|
72
|
-
})]
|
|
73
|
-
});
|
|
49
|
+
const intlLocale = locale ?? "en-US";
|
|
50
|
+
return {
|
|
51
|
+
text: cachedFormatter(`${intlLocale}|${timezone}|${mode}`, () => new Intl.DateTimeFormat(intlLocale, options)).format(date),
|
|
52
|
+
zone: (mode === "date_time" ? cachedFormatter(`en-US|${timezone}|zone`, () => new Intl.DateTimeFormat("en-US", {
|
|
53
|
+
timeZone: timezone,
|
|
54
|
+
timeZoneName: "short"
|
|
55
|
+
})).formatToParts(date).find((p) => p.type === "timeZoneName")?.value : void 0) || void 0
|
|
56
|
+
};
|
|
74
57
|
}
|
|
75
58
|
let dateFormat;
|
|
76
59
|
if (mode === "time") dateFormat = "p";
|
|
77
|
-
else if (mode === "date") dateFormat =
|
|
78
|
-
else dateFormat =
|
|
60
|
+
else if (mode === "date") dateFormat = dateTimeFormat ? dateTimeFormat.replace(/[, ]*[HhKk].*$/, "").trim() : "PP";
|
|
61
|
+
else dateFormat = dateTimeFormat ?? defaultDateFormat;
|
|
62
|
+
return { text: format(date, dateFormat, { locale: dateFnsLocale }) };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The date-fns locale for the admin's configured locale.
|
|
66
|
+
*
|
|
67
|
+
* The locale arrives asynchronously (see `date_fns_locales`). Seeded from the
|
|
68
|
+
* cache so only the very first date on a page renders un-localised: by the
|
|
69
|
+
* time a table of them mounts, the module is already resolved and there is no
|
|
70
|
+
* second pass.
|
|
71
|
+
*/
|
|
72
|
+
function useDateFnsLocale() {
|
|
73
|
+
const configuredLocale = useCustomizationController()?.locale;
|
|
74
|
+
const [dateFnsLocale, setDateFnsLocale] = React.useState(() => getLoadedDateFnsLocale(configuredLocale));
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
let cancelled = false;
|
|
77
|
+
loadDateFnsLocale(configuredLocale).then((loaded) => {
|
|
78
|
+
if (!cancelled) setDateFnsLocale(loaded);
|
|
79
|
+
}).catch((error) => console.error(`[rebase] could not load the "${configuredLocale}" date locale`, error));
|
|
80
|
+
return () => {
|
|
81
|
+
cancelled = true;
|
|
82
|
+
};
|
|
83
|
+
}, [configuredLocale]);
|
|
84
|
+
return dateFnsLocale;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @group Preview components
|
|
88
|
+
*/
|
|
89
|
+
function DatePreview({ date, mode = "date_time", timezone }) {
|
|
90
|
+
const customizationController = useCustomizationController();
|
|
91
|
+
const dateFnsLocale = useDateFnsLocale();
|
|
92
|
+
if (!date || !(date instanceof Date) || isNaN(date.getTime())) return /* @__PURE__ */ jsx(Fragment, {});
|
|
93
|
+
const { text, zone } = formatDatePreview(date, {
|
|
94
|
+
mode,
|
|
95
|
+
timezone,
|
|
96
|
+
locale: customizationController?.locale,
|
|
97
|
+
dateTimeFormat: customizationController?.dateTimeFormat,
|
|
98
|
+
dateFnsLocale
|
|
99
|
+
});
|
|
100
|
+
if (zone) return /* @__PURE__ */ jsxs("span", {
|
|
101
|
+
className: "flex items-center gap-1 min-w-0 font-mono tabular-nums whitespace-nowrap",
|
|
102
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
103
|
+
className: "truncate",
|
|
104
|
+
children: text
|
|
105
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
106
|
+
className: "shrink-0 text-xs text-slate-500 dark:text-slate-400",
|
|
107
|
+
children: [
|
|
108
|
+
"(",
|
|
109
|
+
zone,
|
|
110
|
+
")"
|
|
111
|
+
]
|
|
112
|
+
})]
|
|
113
|
+
});
|
|
79
114
|
return /* @__PURE__ */ jsx("span", {
|
|
80
|
-
className: "font-mono tabular-nums",
|
|
81
|
-
children:
|
|
115
|
+
className: "min-w-0 truncate font-mono tabular-nums",
|
|
116
|
+
children: text
|
|
82
117
|
});
|
|
83
118
|
}
|
|
84
119
|
//#endregion
|
|
85
|
-
export { DatePreview };
|
|
120
|
+
export { DatePreview, formatDatePreview, useDateFnsLocale };
|
|
86
121
|
|
|
87
122
|
//# sourceMappingURL=DatePreview.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePreview.js","names":[],"sources":["../../../src/preview/components/DatePreview.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { format } from \"date-fns\";\nimport { useCustomizationController } from \"@rebasepro/app\";\nimport { defaultDateFormat } from \"@rebasepro/utils\";\nimport { getLoadedDateFnsLocale, loadDateFnsLocale } from \"./date_fns_locales\";\n\nexport interface DatePreviewProps {\n date: Date;\n /**\n * Display mode: \"date\" for date-only, \"date_time\" for date and time,\n * \"time\" for a time of day (a `time` column) with no day at all\n */\n mode?:
|
|
1
|
+
{"version":3,"file":"DatePreview.js","names":[],"sources":["../../../src/preview/components/DatePreview.tsx"],"sourcesContent":["import React from \"react\";\n\nimport { format } from \"date-fns\";\nimport { useCustomizationController } from \"@rebasepro/app\";\nimport { defaultDateFormat } from \"@rebasepro/utils\";\nimport type { Locale as DateFnsLocale } from \"date-fns\";\nimport { getLoadedDateFnsLocale, loadDateFnsLocale } from \"./date_fns_locales\";\n\nexport interface DatePreviewProps {\n date: Date;\n /**\n * Display mode: \"date\" for date-only, \"date_time\" for date and time,\n * \"time\" for a time of day (a `time` column) with no day at all\n */\n mode?: DatePreviewMode;\n /**\n * IANA timezone identifier (e.g., \"America/New_York\")\n * When specified, the date will be displayed in this timezone\n */\n timezone?: string;\n}\n\n/**\n * `Intl.DateTimeFormat`s already built, for dates shown in a fixed timezone.\n *\n * Building one is the expensive part of formatting (~90 µs, against ~6 µs to\n * format with it), and a table column of zoned dates used to build two per\n * cell per render. Key: locale, timezone and what is shown — everything the\n * options are made of, so a cached formatter formats exactly as a fresh one\n * would. Nothing invalidates an entry: a formatter is a pure function of its\n * key and holds no record data. Bounded anyway, since a timezone can come from\n * data: past the cap the map starts over.\n */\nconst FORMATTERS = new Map<string, Intl.DateTimeFormat>();\nconst MAX_FORMATTERS = 200;\n\nfunction cachedFormatter(key: string, build: () => Intl.DateTimeFormat): Intl.DateTimeFormat {\n const cached = FORMATTERS.get(key);\n if (cached) return cached;\n // Built before it is stored: an unknown timezone throws here exactly as it\n // did uncached, and leaves nothing behind.\n const formatter = build();\n if (FORMATTERS.size >= MAX_FORMATTERS) FORMATTERS.clear();\n FORMATTERS.set(key, formatter);\n return formatter;\n}\n\nexport type DatePreviewMode = \"date\" | \"date_time\" | \"time\";\n\nexport interface DatePreviewFormatOptions {\n mode?: DatePreviewMode;\n timezone?: string;\n /** The admin's configured locale (`customizationController.locale`). */\n locale?: string;\n /** The admin's configured format (`customizationController.dateTimeFormat`). */\n dateTimeFormat?: string;\n /** The date-fns locale matching `locale`, once it has loaded. */\n dateFnsLocale?: DateFnsLocale;\n}\n\n/**\n * The text a `DatePreview` shows, and the zone abbreviation drawn after it.\n *\n * Pulled out of the component so the table can size a date column from the\n * very string its cells will render — see `getDateColumnWidth`. Two copies of\n * this logic would drift, and a column a few characters too narrow wraps every\n * date in it onto a second line the row has no height for.\n */\nexport function formatDatePreview(date: Date, {\n mode = \"date_time\",\n timezone,\n locale,\n dateTimeFormat,\n dateFnsLocale\n}: DatePreviewFormatOptions): { text: string, zone?: string } {\n\n // If timezone is specified, format in that timezone using Intl.DateTimeFormat\n if (timezone) {\n // A time of day travels on 1970-01-01; that day is not part of it.\n const options: Intl.DateTimeFormatOptions = mode === \"time\"\n ? { timeZone: timezone }\n : {\n year: \"numeric\",\n month: \"short\",\n day: \"numeric\",\n timeZone: timezone\n };\n\n if (mode === \"date_time\" || mode === \"time\") {\n options.hour = \"2-digit\";\n options.minute = \"2-digit\";\n }\n\n const intlLocale = locale ?? \"en-US\";\n const formatter = cachedFormatter(`${intlLocale}|${timezone}|${mode}`, () => new Intl.DateTimeFormat(intlLocale, options));\n const text = formatter.format(date);\n\n // A day on its own has no time for a zone to qualify.\n const zone = mode === \"date_time\"\n ? cachedFormatter(`en-US|${timezone}|zone`, () => new Intl.DateTimeFormat(\"en-US\", {\n timeZone: timezone,\n timeZoneName: \"short\"\n })).formatToParts(date).find(p => p.type === \"timeZoneName\")?.value\n : undefined;\n\n return {\n text,\n zone: zone || undefined\n };\n }\n\n // No timezone specified: use local formatting with date-fns\n let dateFormat: string;\n if (mode === \"time\") {\n dateFormat = \"p\"; // e.g., \"9:30 AM\"\n } else if (mode === \"date\") {\n // Date-only format (no time)\n dateFormat = dateTimeFormat\n ? dateTimeFormat.replace(/[, ]*[HhKk].*$/, \"\").trim()\n : \"PP\"; // e.g., \"Apr 29, 2024\"\n } else {\n // Full date-time format\n dateFormat = dateTimeFormat ?? defaultDateFormat;\n }\n\n return { text: format(date, dateFormat, { locale: dateFnsLocale }) };\n}\n\n/**\n * The date-fns locale for the admin's configured locale.\n *\n * The locale arrives asynchronously (see `date_fns_locales`). Seeded from the\n * cache so only the very first date on a page renders un-localised: by the\n * time a table of them mounts, the module is already resolved and there is no\n * second pass.\n */\nexport function useDateFnsLocale(): DateFnsLocale | undefined {\n const customizationController = useCustomizationController();\n const configuredLocale = customizationController?.locale;\n const [dateFnsLocale, setDateFnsLocale] = React.useState(() => getLoadedDateFnsLocale(configuredLocale));\n React.useEffect(() => {\n let cancelled = false;\n loadDateFnsLocale(configuredLocale)\n .then(loaded => { if (!cancelled) setDateFnsLocale(loaded); })\n .catch(error => console.error(`[rebase] could not load the \"${configuredLocale}\" date locale`, error));\n return () => { cancelled = true; };\n }, [configuredLocale]);\n return dateFnsLocale;\n}\n\n/**\n * @group Preview components\n */\nexport function DatePreview({\n date,\n mode = \"date_time\",\n timezone\n}: DatePreviewProps): React.ReactElement {\n\n const customizationController = useCustomizationController();\n const dateFnsLocale = useDateFnsLocale();\n\n if (!date || !(date instanceof Date) || isNaN(date.getTime())) {\n return <></>;\n }\n\n const { text, zone } = formatDatePreview(date, {\n mode,\n timezone,\n locale: customizationController?.locale,\n dateTimeFormat: customizationController?.dateTimeFormat,\n dateFnsLocale\n });\n\n // A date is a measured value: the mono tier, tabular, so a column of them\n // lines up and a live one does not jitter. Size and colour are inherited\n // from where it sits — a table cell, a form value. One line, always: a\n // date broken after its year reads as two values, and in a table row the\n // second line is cut off by the row. Too narrow a space ends it in \"…\".\n if (zone) {\n return (\n <span className=\"flex items-center gap-1 min-w-0 font-mono tabular-nums whitespace-nowrap\">\n <span className=\"truncate\">{text}</span>\n <span className=\"shrink-0 text-xs text-slate-500 dark:text-slate-400\">\n ({zone})\n </span>\n </span>\n );\n }\n\n return (\n <span className=\"min-w-0 truncate font-mono tabular-nums\">\n {text}\n </span>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,IAAM,6BAAa,IAAI,IAAiC;AACxD,IAAM,iBAAiB;AAEvB,SAAS,gBAAgB,KAAa,OAAuD;CACzF,MAAM,SAAS,WAAW,IAAI,GAAG;CACjC,IAAI,QAAQ,OAAO;CAGnB,MAAM,YAAY,MAAM;CACxB,IAAI,WAAW,QAAQ,gBAAgB,WAAW,MAAM;CACxD,WAAW,IAAI,KAAK,SAAS;CAC7B,OAAO;AACX;;;;;;;;;AAuBA,SAAgB,kBAAkB,MAAY,EAC1C,OAAO,aACP,UACA,QACA,gBACA,iBAC0D;CAG1D,IAAI,UAAU;EAEV,MAAM,UAAsC,SAAS,SAC/C,EAAE,UAAU,SAAS,IACrB;GACE,MAAM;GACN,OAAO;GACP,KAAK;GACL,UAAU;EACd;EAEJ,IAAI,SAAS,eAAe,SAAS,QAAQ;GACzC,QAAQ,OAAO;GACf,QAAQ,SAAS;EACrB;EAEA,MAAM,aAAa,UAAU;EAY7B,OAAO;GACH,MAZc,gBAAgB,GAAG,WAAW,GAAG,SAAS,GAAG,cAAc,IAAI,KAAK,eAAe,YAAY,OAAO,CAC3G,CAAA,CAAU,OAAO,IAW1B;GACA,OATS,SAAS,cAChB,gBAAgB,SAAS,SAAS,cAAc,IAAI,KAAK,eAAe,SA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GAAM,WAAU;aAAY;EAAW,CAAA,GACvC,qBAAC,QAAD;GAAM,WAAU;aAAhB;IAAsE;IAChE;IAAK;GACL;IACJ;;CAId,OACI,oBAAC,QAAD;EAAM,WAAU;YACX;CACC,CAAA;AAEd"}
|
|
@@ -253,7 +253,7 @@ function EntityFullScreenRoute({ pathname, navigationEntries, isNew, isCopy }) {
|
|
|
253
253
|
},
|
|
254
254
|
onSaved: (params) => {
|
|
255
255
|
const newSelectedTab = params.selectedTab;
|
|
256
|
-
const newEntityId = params.
|
|
256
|
+
const newEntityId = params.id;
|
|
257
257
|
const savedHash = isNew ? "" : hash;
|
|
258
258
|
navigate(`${recordTabUrl(newEntityId, newSelectedTab)}${savedHash}`, { replace: true });
|
|
259
259
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RebaseRoute.js","names":[],"sources":["../../src/routes/RebaseRoute.tsx"],"sourcesContent":["\nimport type { ViewMode, AdminCollection } from \"@rebasepro/cms-types\";\nimport { useLocation } from \"react-router\";\nimport { Suspense, useCallback, useEffect, useRef, useState } from \"react\";\nimport { useNavigate } from \"react-router\";\n// Lazy: the table, the record views and the form behind them are not needed\n// until a collection opens, and a static import here preloaded all of them on\n// the login screen. See components/lazy_record_views.ts.\nimport {\n LazyCollectionViewBinding as CollectionViewBinding,\n LazyDetailViewBinding as DetailViewBinding,\n LazyEditViewBinding as EditViewBinding\n} from \"../components/lazy_record_views\";\nimport { ErrorView, NotFoundPage, useCustomizationController, useTranslation, useUserConfigurationPersistence, useComponentOverride, useNavigationBlocker } from \"@rebasepro/app\";\nimport { resolveCollectionOpenMode } from \"../util/collection_open_mode\";\nimport { isPathWithinRecord } from \"../util/navigation_utils\";\nimport { UnsavedChangesDialog } from \"@rebasepro/app\";\nimport { CenteredView, CircularProgressCenter } from \"@rebasepro/ui\";\nimport { NavigationViewCollectionInternal, NavigationViewEntityCustomInternal, NavigationViewInternal } from \"@rebasepro/app\";\nimport { getNavigationEntriesFromPath } from \"@rebasepro/app\";\nimport { toArray } from \"@rebasepro/utils\";\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useUrlController } from \"../hooks/navigation/contexts/UrlContext\";\nimport { useBreadcrumbsController } from \"../hooks/useBreadcrumbsController\";\nimport { useNavigationStateController } from \"../hooks/navigation/contexts/NavigationStateContext\";\nimport { NavigationLoadingErrorView } from \"../components/NavigationLoadingErrorView\";\nimport { decodeUrlPath, encodeUrlPathSegment, getPathAfterRecord } from \"../hooks/navigation/url_segments\";\n\nexport function RebaseRoute() {\n return <Suspense fallback={<CircularProgressCenter/>}>\n <RebaseRouteContent/>\n </Suspense>;\n}\n\nfunction RebaseRouteContent() {\n\n const location = useLocation();\n const collectionRegistry = useCollectionRegistryController();\n const urlController = useUrlController();\n const breadcrumbs = useBreadcrumbsController();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const ResolvedCollectionView = useComponentOverride(\"Collection.View\", CollectionViewBinding);\n const navigationState = useNavigationStateController();\n\n const hash = location.hash;\n // `#new_side` is a new record in the side panel, drawn by the side panel\n // (`useBuildSidePanel`); under it this route shows the collection, as it\n // does for `#side`. It contains `#new`, which made a pasted\n // `/c/products#new_side` draw a second, full-screen new form under the panel.\n const isNewInSidePanel = hash.includes(\"#new_side\");\n const isSidePanel = hash.includes(\"#side\") || isNewInSidePanel;\n const isNew = hash.includes(\"#new\") && !isNewInSidePanel;\n const isCopy = hash.includes(\"#copy\");\n const isFullScreen = hash.includes(\"#full\");\n\n const pathname = location.pathname;\n const navigationPath = urlController.urlPathToDataPath(pathname);\n\n const navigationEntries = getNavigationEntriesFromPath({\n path: navigationPath,\n collections: collectionRegistry.collections ?? []\n });\n\n useEffect(() => {\n breadcrumbs.set({\n breadcrumbs: navigationEntries.map((entry) => {\n\n if (entry.type === \"entity\") {\n return ({\n title: String(entry.entityId),\n url: urlController.buildUrlCollectionPath(entry.path)\n });\n } else if (entry.type === \"custom_view\") {\n return ({\n title: String(entry.view.name ?? entry.view.key),\n url: urlController.buildUrlCollectionPath(entry.path)\n });\n } else if (entry.type === \"collection\") {\n return ({\n title: entry.collection.name,\n url: urlController.buildUrlCollectionPath(entry.path),\n id: entry.path\n });\n } else {\n throw new Error(\"Unexpected navigation entry type\");\n }\n })\n });\n }, [navigationEntries.map(entry => entry.path).join(\",\")]);\n\n // The collections failed to load, so this URL cannot resolve to anything:\n // say why, rather than spin until a registry that will never fill does, or\n // report the collection as unregistered.\n if (navigationState.navigationLoadingError && !navigationEntries.some((entry) => entry.type === \"collection\")) {\n return <CenteredView>\n <NavigationLoadingErrorView error={navigationState.navigationLoadingError}\n onRetry={navigationState.refreshNavigation}/>\n </CenteredView>;\n }\n\n if (isNew) {\n // New entities always use full-screen mode, even for split-layout collections\n return <EntityFullScreenRoute\n pathname={pathname}\n navigationEntries={navigationEntries}\n isNew={true}\n isCopy={false}\n />;\n }\n\n if (navigationEntries.length === 1 && navigationEntries[0].type === \"collection\") {\n let collection: AdminCollection<any> | undefined;\n collection = collectionRegistry.getCollection(navigationEntries[0].id);\n if (!collection)\n collection = collectionRegistry.getCollection(navigationEntries[0].slug);\n if (!collection) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <UnresolvedCollectionView path={navigationEntries[0].slug}/>;\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n Actions={toArray(collection.Actions)}/>\n }\n\n if (isSidePanel) {\n const lastCollectionEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"collection\");\n if (lastCollectionEntry) {\n let collection: AdminCollection<any> | undefined;\n const firstEntry = navigationEntries[0] as NavigationViewCollectionInternal<any>;\n collection = collectionRegistry.getCollection(firstEntry.id);\n if (!collection)\n collection = collectionRegistry.getCollection(firstEntry.slug);\n if (!collection) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <UnresolvedCollectionView path={firstEntry.slug}/>;\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n Actions={toArray(collection.Actions)}/>;\n }\n }\n\n // Check if this is a simple entity route (collection + entity) for a split-layout collection.\n // If so, render the collection view with the entity shown in the split detail panel\n // instead of the full-screen editor. This keeps the master-detail UX with clean URLs.\n //\n // Also handles subcollection tabs: /c/customers/39/orders produces 3 entries\n // (collection→entity→subcollection). We extract the subcollection slug as selectedTab.\n const lastEntityEntry = navigationEntries.find((entry) => entry.type === \"entity\");\n const firstCollectionEntry = navigationEntries[0];\n if (\n !isFullScreen &&\n !isCopy &&\n firstCollectionEntry?.type === \"collection\" &&\n lastEntityEntry?.type === \"entity\" &&\n (navigationEntries.length === 2 || navigationEntries.length === 3)\n ) {\n let collection: AdminCollection<any> | undefined;\n collection = collectionRegistry.getCollection(firstCollectionEntry.id);\n if (!collection)\n collection = collectionRegistry.getCollection(firstCollectionEntry.slug);\n\n const effectiveOpenMode = collection\n ? resolveCollectionOpenMode({\n collection,\n search: location.search,\n savedViewMode: userConfigPersistence?.getCollectionConfig(collection.slug)?.defaultViewMode as ViewMode | undefined,\n registeredViews: customizationController.collectionViews\n })\n : undefined;\n if (collection && effectiveOpenMode === \"split\") {\n // Extract subcollection tab from the 3rd entry if present\n let selectedTab: string | undefined;\n if (navigationEntries.length === 3) {\n const thirdEntry = navigationEntries[2];\n if (thirdEntry.type === \"collection\") {\n selectedTab = thirdEntry.collection.slug;\n } else if (thirdEntry.type === \"custom_view\") {\n selectedTab = thirdEntry.view.key;\n }\n }\n // Fallback: check for unregistered tabs (e.g. __json, __rebase_history)\n // that aren't parsed as navigation entries\n if (!selectedTab && (navigationEntries.length === 2) && lastEntityEntry) {\n const trailingSegment = getPathAfterRecord(pathname, urlController.buildUrlCollectionPath(lastEntityEntry.path));\n if (trailingSegment) {\n selectedTab = trailingSegment;\n }\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n selectedEntityId={lastEntityEntry.entityId}\n selectedTab={selectedTab}\n Actions={toArray(collection.Actions)}/>;\n }\n }\n\n return <EntityFullScreenRoute\n pathname={pathname}\n navigationEntries={navigationEntries}\n isNew={isNew}\n isCopy={isCopy}\n />;\n\n}\n\nfunction getSelectedTabFromUrl(isNew: boolean, lastCustomView: NavigationViewCollectionInternal<any> | NavigationViewEntityCustomInternal<any> | undefined) {\n if (isNew) {\n return undefined;\n } else if (lastCustomView) {\n if (lastCustomView.type === \"custom_view\") {\n return lastCustomView.view.key;\n } else if (lastCustomView.type === \"collection\") {\n return lastCustomView.id ?? lastCustomView.slug;\n }\n }\n return undefined;\n}\n\nfunction EntityFullScreenRoute({\n pathname,\n navigationEntries,\n isNew,\n isCopy\n}: {\n pathname: string;\n navigationEntries: NavigationViewInternal[],\n isNew: boolean,\n isCopy: boolean\n}) {\n\n const collectionRegistry = useCollectionRegistryController();\n const urlController = useUrlController();\n const navigate = useNavigate();\n const location = useLocation();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const { t } = useTranslation();\n\n // defaultValues may be carried via location.state when openNewDocument() is called\n // for full-screen mode. We read it once on mount — after that, the form owns its state.\n const defaultValues = (location.state as { defaultValues?: Record<string, unknown> } | null)?.defaultValues;\n\n // Preserve the current hash (e.g. #full) across tab/save navigations\n const hash = location.hash;\n\n const navigationPath = urlController.urlPathToDataPath(pathname);\n\n // is navigating away blocked\n const blocked = useRef(false);\n\n const lastEntityEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"entity\");\n const navigationEntriesAfterEntity = lastEntityEntry ? navigationEntries.slice(navigationEntries.indexOf(lastEntityEntry) + 1) : [];\n\n const lastCustomView = [...navigationEntriesAfterEntity].reverse().find(\n (entry) => entry.type === \"custom_view\" || entry.type === \"collection\"\n ) as NavigationViewCollectionInternal<any> | NavigationViewEntityCustomInternal<any> | undefined;\n\n const entityId = lastEntityEntry && \"entityId\" in lastEntityEntry ? lastEntityEntry.entityId : undefined;\n\n // The record's own URL, and the URL of the collection that holds it. Built\n // from the data path, so the id in them is percent-encoded once, however\n // the pathname spells it.\n const recordUrl = lastEntityEntry && entityId !== undefined && !isNew\n ? urlController.buildUrlCollectionPath(lastEntityEntry.path)\n : undefined;\n const basePath = lastEntityEntry && recordUrl !== undefined\n ? urlController.buildUrlCollectionPath(lastEntityEntry.slug)\n : pathname;\n\n // Derive tab from navigation entries (works for registered custom views)\n let urlTab = getSelectedTabFromUrl(isNew, lastCustomView);\n\n // Fallback: internal tabs like __json or __rebase_history aren't registered as\n // entity views, so the navigation parser ignores them. Check the raw pathname\n // for a trailing segment after the entity ID to catch those cases.\n if (!urlTab && recordUrl !== undefined) {\n const trailingSegment = getPathAfterRecord(pathname, recordUrl);\n if (trailingSegment && trailingSegment !== \"edit\") {\n urlTab = trailingSegment;\n }\n }\n\n const [selectedTab, setSelectedTab] = useState<string | undefined>(urlTab);\n\n const parentCollectionSlugs = collectionRegistry.getParentCollectionSlugs(navigationPath);\n const parentEntityIds = collectionRegistry.getParentEntityIds(navigationPath);\n useEffect(() => {\n if (urlTab !== selectedTab) {\n setSelectedTab(urlTab);\n }\n }, [urlTab]);\n\n // The URL of a record in this collection, or of one of its tabs.\n const recordTabUrl = (id: string | number, tab?: string) =>\n `${basePath}/${encodeUrlPathSegment(String(id))}${tab ? \"/\" + encodeUrlPathSegment(tab) : \"\"}`;\n\n // Compared decoded: a location's pathname spells an id the way whoever\n // wrote it encoded it, and these paths are built here.\n const entityPath = decodeUrlPath(recordUrl ?? `${basePath}/${entityId}`);\n const decodedBasePath = decodeUrlPath(basePath);\n\n const blocker = useNavigationBlocker(useCallback(({\n currentLocation,\n nextLocation\n }) => {\n const nextPathname = decodeUrlPath(nextLocation.pathname);\n // Inside this record — a tab, `/edit`. By path segment: a bare\n // prefix let Back to `/c/products/12` out of `/c/products/1` without\n // asking.\n if (isPathWithinRecord(nextPathname, entityPath))\n return false;\n\n // Side panel overlay navigations preserve the underlying form via\n // base_location in router state — no data is lost in either direction.\n\n // Opening a side panel (e.g. clicking a relation arrow)\n const nextHash = nextLocation.hash;\n if (nextHash === \"#side\" || nextHash === \"#new_side\")\n return false;\n\n // Closing a side panel (navigate(-1) back to the form's own path)\n const currentHash = currentLocation.hash;\n if ((currentHash === \"#side\" || currentHash === \"#new_side\") &&\n (nextPathname === decodedBasePath ||\n isPathWithinRecord(nextPathname, entityPath)))\n return false;\n\n return blocked.current;\n }, [entityPath, decodedBasePath]));\n\n const lastCollectionEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"collection\");\n\n if (isNew && !lastCollectionEntry) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n throw new Error(\"INTERNAL: No collection found in the navigation\");\n }\n\n if (!isNew && !lastEntityEntry) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <NotFoundPage/>;\n }\n\n const rawCollection = isNew\n ? (lastCollectionEntry && \"collection\" in lastCollectionEntry ? lastCollectionEntry.collection : undefined)!\n : (lastEntityEntry && \"parentCollection\" in lastEntityEntry ? lastEntityEntry.parentCollection : undefined)!;\n const collection = collectionRegistry.getCollection(rawCollection.slug) || rawCollection;\n const fullIdPath = isNew ? lastCollectionEntry!.slug : lastEntityEntry!.slug;\n const collectionPath = urlController.resolveDatabasePathsFrom(fullIdPath);\n const isEditRoute = pathname.endsWith(\"/edit\") || pathname.split(\"/\").pop() === \"edit\";\n // Determine if this is a detail-view-first collection showing the view page\n const isDetailMode = collection.defaultEntityAction === \"view\" && !isNew && !isCopy && entityId && !isEditRoute;\n\n // A record is full screen either because its collection has no list to show\n // beside it, or because the user folded that list away. Only the second is\n // reversible, and it is reversible by dropping `#full` alone: this is the\n // same URL the split route reads, so the same conditions decide it.\n const splitListAvailable = !isNew && !isCopy && entityId !== undefined &&\n navigationEntries[0]?.type === \"collection\" &&\n (navigationEntries.length === 2 || navigationEntries.length === 3) &&\n resolveCollectionOpenMode({\n collection,\n search: location.search,\n savedViewMode: userConfigPersistence?.getCollectionConfig(collection.slug)?.defaultViewMode as ViewMode | undefined,\n registeredViews: customizationController.collectionViews\n }) === \"split\";\n\n const showList = splitListAvailable\n ? () => navigate({\n pathname,\n search: location.search,\n hash: \"\"\n })\n : undefined;\n\n if (isDetailMode) {\n return <>\n <DetailViewBinding\n key={collection.slug + \"_view_\" + entityId}\n entityId={entityId}\n collection={collection}\n layout={\"full_screen\"}\n path={collectionPath}\n selectedTab={selectedTab ?? undefined}\n onShowList={showList}\n onEditClick={() => {\n const editUrl = urlController.buildUrlCollectionPath(`${collectionPath}/${entityId}`) + \"/edit\";\n navigate(editUrl + hash);\n }}\n onTabChange={(params) => {\n setSelectedTab(params.selectedTab);\n navigate(`${recordTabUrl(entityId, params.selectedTab)}${hash}`, { replace: true });\n }}\n parentCollectionSlugs={parentCollectionSlugs}\n parentEntityIds={parentEntityIds}\n />\n </>;\n }\n\n return <>\n <EditViewBinding\n key={collection.slug + \"_\" + (isNew ? \"new\" : (isCopy ? entityId + \"_copy\" : entityId))}\n entityId={isNew ? undefined : entityId}\n collection={collection}\n layout={\"full_screen\"}\n path={collectionPath}\n copy={isCopy}\n selectedTab={selectedTab ?? undefined}\n onShowList={showList}\n defaultValues={isNew ? defaultValues : undefined}\n onValuesModified={(modified) => blocked.current = modified}\n navigateBack={() => {\n const detailUrl = urlController.buildUrlCollectionPath(`${collectionPath}/${entityId}`);\n navigate(detailUrl + hash);\n }}\n onSaved={(params) => {\n const newSelectedTab = params.selectedTab;\n const newEntityId = params.entityId ?? params.entity.id;\n const savedHash = isNew ? \"\" : hash;\n navigate(`${recordTabUrl(newEntityId, newSelectedTab)}${savedHash}`, { replace: true });\n }}\n onTabChange={(params) => {\n setSelectedTab(params.selectedTab);\n if (isNew || entityId === undefined) {\n return;\n }\n navigate(`${recordTabUrl(entityId, params.selectedTab)}${hash}`, { replace: true });\n }}\n parentCollectionSlugs={parentCollectionSlugs} parentEntityIds={parentEntityIds}\n />\n\n <UnsavedChangesDialog\n open={blocker?.state === \"blocked\"}\n handleOk={() => blocker?.proceed?.()}\n handleCancel={() => blocker?.reset?.()}\n body={t(\"unsaved_changes_in_entity\")}/>\n </>;\n}\n\n/**\n * Shown when a URL names a collection the registry cannot resolve.\n *\n * This used to be `return null`, which renders an empty pane inside the app\n * chrome: the sidebar, the nav highlight and the breadcrumb all still work,\n * because those read the collections array directly, while the view itself is\n * blank. Nothing is thrown, and the only trace is a `console.debug` — so the\n * panel looks like it lost its data rather than like it failed to find the\n * collection, and there is no string to search for.\n *\n * A slug containing slashes went unresolvable this way and cost an afternoon to\n * find. The lookup is fixed; this is the part that made it expensive.\n */\nfunction UnresolvedCollectionView({ path }: { path: string }) {\n const { t } = useTranslation();\n // Warn, not debug: this is a route that renders nothing useful, and it\n // should be visible at the console's default level.\n useEffect(() => {\n console.warn(\n `[rebase] No collection is registered for \"${path}\", so this route has nothing to render. ` +\n \"Check that the collection is in the collections array and that its slug matches the URL.\"\n );\n }, [path]);\n\n return <CenteredView>\n <ErrorView\n title={t(\"collection_not_found\")}\n error={t(\"collection_not_found_body\", { path })}\n tooltip={t(\"collection_not_found_hint\")}/>\n </CenteredView>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,cAAc;CAC1B,OAAO,oBAAC,UAAD;EAAU,UAAU,oBAAC,wBAAD,CAAwB,CAAA;YAC/C,oBAAC,oBAAD,CAAoB,CAAA;CACd,CAAA;AACd;AAEA,SAAS,qBAAqB;CAE1B,MAAM,WAAW,YAAY;CAC7B,MAAM,qBAAqB,gCAAgC;CAC3D,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,cAAc,yBAAyB;CAC7C,MAAM,wBAAwB,gCAAgC;CAC9D,MAAM,0BAA0B,2BAA2B;CAC3D,MAAM,yBAAyB,qBAAqB,mBAAmB,yBAAqB;C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ClD,oBAAoB;GAChB,MAAM,YAAY,cAAc,uBAAuB,GAAG,eAAe,GAAG,UAAU;GACtF,SAAS,YAAY,IAAI;EAC7B;EACA,UAAU,WAAW;GACjB,MAAM,iBAAiB,OAAO;GAC9B,MAAM,cAAc,OAAO,YAAY,OAAO,OAAO;GACrD,MAAM,YAAY,QAAQ,KAAK;GAC/B,SAAS,GAAG,aAAa,aAAa,cAAc,IAAI,aAAa,EAAE,SAAS,KAAK,CAAC;EAC1F;EACA,cAAc,WAAW;GACrB,eAAe,OAAO,WAAW;GACjC,IAAI,SAAS,aAAa,KAAA,GACtB;GAEJ,SAAS,GAAG,aAAa,UAAU,OAAO,WAAW,IAAI,QAAQ,EAAE,SAAS,KAAK,CAAC;EACtF;EACuB;EAAwC;CAClE,GA5BQ,WAAW,OAAO,OAAO,QAAQ,QAAS,SAAS,WAAW,UAAU,SA4BhF,GAED,oBAAC,sBAAD;EACI,MAAM,SAAS,UAAU;EACzB,gBAAgB,SAAS,UAAU;EACnC,oBAAoB,SAAS,QAAQ;EACrC,MAAM,EAAE,2BAA2B;CAAG,CAAA,CAC5C,EAAA,CAAA;AACN;;;;;;;;;;;;;;AAeA,SAAS,yBAAyB,EAAE,QAA0B;CAC1D,MAAM,EAAE,MAAM,eAAe;CAG7B,gBAAgB;EACZ,QAAQ,KACJ,6CAA6C,KAAK,iIAEtD;CACJ,GAAG,CAAC,IAAI,CAAC;CAET,OAAO,oBAAC,cAAD,EAAA,UACH,oBAAC,WAAD;EACI,OAAO,EAAE,sBAAsB;EAC/B,OAAO,EAAE,6BAA6B,EAAE,KAAK,CAAC;EAC9C,SAAS,EAAE,2BAA2B;CAAG,CAAA,EACnC,CAAA;AAClB"}
|
|
1
|
+
{"version":3,"file":"RebaseRoute.js","names":[],"sources":["../../src/routes/RebaseRoute.tsx"],"sourcesContent":["\nimport type { ViewMode, AdminCollection } from \"@rebasepro/cms-types\";\nimport { useLocation } from \"react-router\";\nimport { Suspense, useCallback, useEffect, useRef, useState } from \"react\";\nimport { useNavigate } from \"react-router\";\n// Lazy: the table, the record views and the form behind them are not needed\n// until a collection opens, and a static import here preloaded all of them on\n// the login screen. See components/lazy_record_views.ts.\nimport {\n LazyCollectionViewBinding as CollectionViewBinding,\n LazyDetailViewBinding as DetailViewBinding,\n LazyEditViewBinding as EditViewBinding\n} from \"../components/lazy_record_views\";\nimport { ErrorView, NotFoundPage, useCustomizationController, useTranslation, useUserConfigurationPersistence, useComponentOverride, useNavigationBlocker } from \"@rebasepro/app\";\nimport { resolveCollectionOpenMode } from \"../util/collection_open_mode\";\nimport { isPathWithinRecord } from \"../util/navigation_utils\";\nimport { UnsavedChangesDialog } from \"@rebasepro/app\";\nimport { CenteredView, CircularProgressCenter } from \"@rebasepro/ui\";\nimport { NavigationViewCollectionInternal, NavigationViewEntityCustomInternal, NavigationViewInternal } from \"@rebasepro/app\";\nimport { getNavigationEntriesFromPath } from \"@rebasepro/app\";\nimport { toArray } from \"@rebasepro/utils\";\nimport { useCollectionRegistryController } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useUrlController } from \"../hooks/navigation/contexts/UrlContext\";\nimport { useBreadcrumbsController } from \"../hooks/useBreadcrumbsController\";\nimport { useNavigationStateController } from \"../hooks/navigation/contexts/NavigationStateContext\";\nimport { NavigationLoadingErrorView } from \"../components/NavigationLoadingErrorView\";\nimport { decodeUrlPath, encodeUrlPathSegment, getPathAfterRecord } from \"../hooks/navigation/url_segments\";\n\nexport function RebaseRoute() {\n return <Suspense fallback={<CircularProgressCenter/>}>\n <RebaseRouteContent/>\n </Suspense>;\n}\n\nfunction RebaseRouteContent() {\n\n const location = useLocation();\n const collectionRegistry = useCollectionRegistryController();\n const urlController = useUrlController();\n const breadcrumbs = useBreadcrumbsController();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const ResolvedCollectionView = useComponentOverride(\"Collection.View\", CollectionViewBinding);\n const navigationState = useNavigationStateController();\n\n const hash = location.hash;\n // `#new_side` is a new record in the side panel, drawn by the side panel\n // (`useBuildSidePanel`); under it this route shows the collection, as it\n // does for `#side`. It contains `#new`, which made a pasted\n // `/c/products#new_side` draw a second, full-screen new form under the panel.\n const isNewInSidePanel = hash.includes(\"#new_side\");\n const isSidePanel = hash.includes(\"#side\") || isNewInSidePanel;\n const isNew = hash.includes(\"#new\") && !isNewInSidePanel;\n const isCopy = hash.includes(\"#copy\");\n const isFullScreen = hash.includes(\"#full\");\n\n const pathname = location.pathname;\n const navigationPath = urlController.urlPathToDataPath(pathname);\n\n const navigationEntries = getNavigationEntriesFromPath({\n path: navigationPath,\n collections: collectionRegistry.collections ?? []\n });\n\n useEffect(() => {\n breadcrumbs.set({\n breadcrumbs: navigationEntries.map((entry) => {\n\n if (entry.type === \"entity\") {\n return ({\n title: String(entry.entityId),\n url: urlController.buildUrlCollectionPath(entry.path)\n });\n } else if (entry.type === \"custom_view\") {\n return ({\n title: String(entry.view.name ?? entry.view.key),\n url: urlController.buildUrlCollectionPath(entry.path)\n });\n } else if (entry.type === \"collection\") {\n return ({\n title: entry.collection.name,\n url: urlController.buildUrlCollectionPath(entry.path),\n id: entry.path\n });\n } else {\n throw new Error(\"Unexpected navigation entry type\");\n }\n })\n });\n }, [navigationEntries.map(entry => entry.path).join(\",\")]);\n\n // The collections failed to load, so this URL cannot resolve to anything:\n // say why, rather than spin until a registry that will never fill does, or\n // report the collection as unregistered.\n if (navigationState.navigationLoadingError && !navigationEntries.some((entry) => entry.type === \"collection\")) {\n return <CenteredView>\n <NavigationLoadingErrorView error={navigationState.navigationLoadingError}\n onRetry={navigationState.refreshNavigation}/>\n </CenteredView>;\n }\n\n if (isNew) {\n // New entities always use full-screen mode, even for split-layout collections\n return <EntityFullScreenRoute\n pathname={pathname}\n navigationEntries={navigationEntries}\n isNew={true}\n isCopy={false}\n />;\n }\n\n if (navigationEntries.length === 1 && navigationEntries[0].type === \"collection\") {\n let collection: AdminCollection<any> | undefined;\n collection = collectionRegistry.getCollection(navigationEntries[0].id);\n if (!collection)\n collection = collectionRegistry.getCollection(navigationEntries[0].slug);\n if (!collection) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <UnresolvedCollectionView path={navigationEntries[0].slug}/>;\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n Actions={toArray(collection.Actions)}/>\n }\n\n if (isSidePanel) {\n const lastCollectionEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"collection\");\n if (lastCollectionEntry) {\n let collection: AdminCollection<any> | undefined;\n const firstEntry = navigationEntries[0] as NavigationViewCollectionInternal<any>;\n collection = collectionRegistry.getCollection(firstEntry.id);\n if (!collection)\n collection = collectionRegistry.getCollection(firstEntry.slug);\n if (!collection) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <UnresolvedCollectionView path={firstEntry.slug}/>;\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n Actions={toArray(collection.Actions)}/>;\n }\n }\n\n // Check if this is a simple entity route (collection + entity) for a split-layout collection.\n // If so, render the collection view with the entity shown in the split detail panel\n // instead of the full-screen editor. This keeps the master-detail UX with clean URLs.\n //\n // Also handles subcollection tabs: /c/customers/39/orders produces 3 entries\n // (collection→entity→subcollection). We extract the subcollection slug as selectedTab.\n const lastEntityEntry = navigationEntries.find((entry) => entry.type === \"entity\");\n const firstCollectionEntry = navigationEntries[0];\n if (\n !isFullScreen &&\n !isCopy &&\n firstCollectionEntry?.type === \"collection\" &&\n lastEntityEntry?.type === \"entity\" &&\n (navigationEntries.length === 2 || navigationEntries.length === 3)\n ) {\n let collection: AdminCollection<any> | undefined;\n collection = collectionRegistry.getCollection(firstCollectionEntry.id);\n if (!collection)\n collection = collectionRegistry.getCollection(firstCollectionEntry.slug);\n\n const effectiveOpenMode = collection\n ? resolveCollectionOpenMode({\n collection,\n search: location.search,\n savedViewMode: userConfigPersistence?.getCollectionConfig(collection.slug)?.defaultViewMode as ViewMode | undefined,\n registeredViews: customizationController.collectionViews\n })\n : undefined;\n if (collection && effectiveOpenMode === \"split\") {\n // Extract subcollection tab from the 3rd entry if present\n let selectedTab: string | undefined;\n if (navigationEntries.length === 3) {\n const thirdEntry = navigationEntries[2];\n if (thirdEntry.type === \"collection\") {\n selectedTab = thirdEntry.collection.slug;\n } else if (thirdEntry.type === \"custom_view\") {\n selectedTab = thirdEntry.view.key;\n }\n }\n // Fallback: check for unregistered tabs (e.g. __json, __rebase_history)\n // that aren't parsed as navigation entries\n if (!selectedTab && (navigationEntries.length === 2) && lastEntityEntry) {\n const trailingSegment = getPathAfterRecord(pathname, urlController.buildUrlCollectionPath(lastEntityEntry.path));\n if (trailingSegment) {\n selectedTab = trailingSegment;\n }\n }\n return <ResolvedCollectionView\n key={`collection_view_${collection.slug}`}\n {...collection}\n parentCollectionSlugs={[]} parentEntityIds={[]}\n path={collection.slug}\n updateUrl={true}\n selectedEntityId={lastEntityEntry.entityId}\n selectedTab={selectedTab}\n Actions={toArray(collection.Actions)}/>;\n }\n }\n\n return <EntityFullScreenRoute\n pathname={pathname}\n navigationEntries={navigationEntries}\n isNew={isNew}\n isCopy={isCopy}\n />;\n\n}\n\nfunction getSelectedTabFromUrl(isNew: boolean, lastCustomView: NavigationViewCollectionInternal<any> | NavigationViewEntityCustomInternal<any> | undefined) {\n if (isNew) {\n return undefined;\n } else if (lastCustomView) {\n if (lastCustomView.type === \"custom_view\") {\n return lastCustomView.view.key;\n } else if (lastCustomView.type === \"collection\") {\n return lastCustomView.id ?? lastCustomView.slug;\n }\n }\n return undefined;\n}\n\nfunction EntityFullScreenRoute({\n pathname,\n navigationEntries,\n isNew,\n isCopy\n}: {\n pathname: string;\n navigationEntries: NavigationViewInternal[],\n isNew: boolean,\n isCopy: boolean\n}) {\n\n const collectionRegistry = useCollectionRegistryController();\n const urlController = useUrlController();\n const navigate = useNavigate();\n const location = useLocation();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const { t } = useTranslation();\n\n // defaultValues may be carried via location.state when openNewDocument() is called\n // for full-screen mode. We read it once on mount — after that, the form owns its state.\n const defaultValues = (location.state as { defaultValues?: Record<string, unknown> } | null)?.defaultValues;\n\n // Preserve the current hash (e.g. #full) across tab/save navigations\n const hash = location.hash;\n\n const navigationPath = urlController.urlPathToDataPath(pathname);\n\n // is navigating away blocked\n const blocked = useRef(false);\n\n const lastEntityEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"entity\");\n const navigationEntriesAfterEntity = lastEntityEntry ? navigationEntries.slice(navigationEntries.indexOf(lastEntityEntry) + 1) : [];\n\n const lastCustomView = [...navigationEntriesAfterEntity].reverse().find(\n (entry) => entry.type === \"custom_view\" || entry.type === \"collection\"\n ) as NavigationViewCollectionInternal<any> | NavigationViewEntityCustomInternal<any> | undefined;\n\n const entityId = lastEntityEntry && \"entityId\" in lastEntityEntry ? lastEntityEntry.entityId : undefined;\n\n // The record's own URL, and the URL of the collection that holds it. Built\n // from the data path, so the id in them is percent-encoded once, however\n // the pathname spells it.\n const recordUrl = lastEntityEntry && entityId !== undefined && !isNew\n ? urlController.buildUrlCollectionPath(lastEntityEntry.path)\n : undefined;\n const basePath = lastEntityEntry && recordUrl !== undefined\n ? urlController.buildUrlCollectionPath(lastEntityEntry.slug)\n : pathname;\n\n // Derive tab from navigation entries (works for registered custom views)\n let urlTab = getSelectedTabFromUrl(isNew, lastCustomView);\n\n // Fallback: internal tabs like __json or __rebase_history aren't registered as\n // entity views, so the navigation parser ignores them. Check the raw pathname\n // for a trailing segment after the entity ID to catch those cases.\n if (!urlTab && recordUrl !== undefined) {\n const trailingSegment = getPathAfterRecord(pathname, recordUrl);\n if (trailingSegment && trailingSegment !== \"edit\") {\n urlTab = trailingSegment;\n }\n }\n\n const [selectedTab, setSelectedTab] = useState<string | undefined>(urlTab);\n\n const parentCollectionSlugs = collectionRegistry.getParentCollectionSlugs(navigationPath);\n const parentEntityIds = collectionRegistry.getParentEntityIds(navigationPath);\n useEffect(() => {\n if (urlTab !== selectedTab) {\n setSelectedTab(urlTab);\n }\n }, [urlTab]);\n\n // The URL of a record in this collection, or of one of its tabs.\n const recordTabUrl = (id: string | number, tab?: string) =>\n `${basePath}/${encodeUrlPathSegment(String(id))}${tab ? \"/\" + encodeUrlPathSegment(tab) : \"\"}`;\n\n // Compared decoded: a location's pathname spells an id the way whoever\n // wrote it encoded it, and these paths are built here.\n const entityPath = decodeUrlPath(recordUrl ?? `${basePath}/${entityId}`);\n const decodedBasePath = decodeUrlPath(basePath);\n\n const blocker = useNavigationBlocker(useCallback(({\n currentLocation,\n nextLocation\n }) => {\n const nextPathname = decodeUrlPath(nextLocation.pathname);\n // Inside this record — a tab, `/edit`. By path segment: a bare\n // prefix let Back to `/c/products/12` out of `/c/products/1` without\n // asking.\n if (isPathWithinRecord(nextPathname, entityPath))\n return false;\n\n // Side panel overlay navigations preserve the underlying form via\n // base_location in router state — no data is lost in either direction.\n\n // Opening a side panel (e.g. clicking a relation arrow)\n const nextHash = nextLocation.hash;\n if (nextHash === \"#side\" || nextHash === \"#new_side\")\n return false;\n\n // Closing a side panel (navigate(-1) back to the form's own path)\n const currentHash = currentLocation.hash;\n if ((currentHash === \"#side\" || currentHash === \"#new_side\") &&\n (nextPathname === decodedBasePath ||\n isPathWithinRecord(nextPathname, entityPath)))\n return false;\n\n return blocked.current;\n }, [entityPath, decodedBasePath]));\n\n const lastCollectionEntry = [...navigationEntries].reverse().find((entry) => entry.type === \"collection\");\n\n if (isNew && !lastCollectionEntry) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n throw new Error(\"INTERNAL: No collection found in the navigation\");\n }\n\n if (!isNew && !lastEntityEntry) {\n if (!collectionRegistry.initialised) {\n return <CircularProgressCenter/>;\n }\n return <NotFoundPage/>;\n }\n\n const rawCollection = isNew\n ? (lastCollectionEntry && \"collection\" in lastCollectionEntry ? lastCollectionEntry.collection : undefined)!\n : (lastEntityEntry && \"parentCollection\" in lastEntityEntry ? lastEntityEntry.parentCollection : undefined)!;\n const collection = collectionRegistry.getCollection(rawCollection.slug) || rawCollection;\n const fullIdPath = isNew ? lastCollectionEntry!.slug : lastEntityEntry!.slug;\n const collectionPath = urlController.resolveDatabasePathsFrom(fullIdPath);\n const isEditRoute = pathname.endsWith(\"/edit\") || pathname.split(\"/\").pop() === \"edit\";\n // Determine if this is a detail-view-first collection showing the view page\n const isDetailMode = collection.defaultEntityAction === \"view\" && !isNew && !isCopy && entityId && !isEditRoute;\n\n // A record is full screen either because its collection has no list to show\n // beside it, or because the user folded that list away. Only the second is\n // reversible, and it is reversible by dropping `#full` alone: this is the\n // same URL the split route reads, so the same conditions decide it.\n const splitListAvailable = !isNew && !isCopy && entityId !== undefined &&\n navigationEntries[0]?.type === \"collection\" &&\n (navigationEntries.length === 2 || navigationEntries.length === 3) &&\n resolveCollectionOpenMode({\n collection,\n search: location.search,\n savedViewMode: userConfigPersistence?.getCollectionConfig(collection.slug)?.defaultViewMode as ViewMode | undefined,\n registeredViews: customizationController.collectionViews\n }) === \"split\";\n\n const showList = splitListAvailable\n ? () => navigate({\n pathname,\n search: location.search,\n hash: \"\"\n })\n : undefined;\n\n if (isDetailMode) {\n return <>\n <DetailViewBinding\n key={collection.slug + \"_view_\" + entityId}\n entityId={entityId}\n collection={collection}\n layout={\"full_screen\"}\n path={collectionPath}\n selectedTab={selectedTab ?? undefined}\n onShowList={showList}\n onEditClick={() => {\n const editUrl = urlController.buildUrlCollectionPath(`${collectionPath}/${entityId}`) + \"/edit\";\n navigate(editUrl + hash);\n }}\n onTabChange={(params) => {\n setSelectedTab(params.selectedTab);\n navigate(`${recordTabUrl(entityId, params.selectedTab)}${hash}`, { replace: true });\n }}\n parentCollectionSlugs={parentCollectionSlugs}\n parentEntityIds={parentEntityIds}\n />\n </>;\n }\n\n return <>\n <EditViewBinding\n key={collection.slug + \"_\" + (isNew ? \"new\" : (isCopy ? entityId + \"_copy\" : entityId))}\n entityId={isNew ? undefined : entityId}\n collection={collection}\n layout={\"full_screen\"}\n path={collectionPath}\n copy={isCopy}\n selectedTab={selectedTab ?? undefined}\n onShowList={showList}\n defaultValues={isNew ? defaultValues : undefined}\n onValuesModified={(modified) => blocked.current = modified}\n navigateBack={() => {\n const detailUrl = urlController.buildUrlCollectionPath(`${collectionPath}/${entityId}`);\n navigate(detailUrl + hash);\n }}\n onSaved={(params) => {\n const newSelectedTab = params.selectedTab;\n const newEntityId = params.id;\n const savedHash = isNew ? \"\" : hash;\n navigate(`${recordTabUrl(newEntityId, newSelectedTab)}${savedHash}`, { replace: true });\n }}\n onTabChange={(params) => {\n setSelectedTab(params.selectedTab);\n if (isNew || entityId === undefined) {\n return;\n }\n navigate(`${recordTabUrl(entityId, params.selectedTab)}${hash}`, { replace: true });\n }}\n parentCollectionSlugs={parentCollectionSlugs} parentEntityIds={parentEntityIds}\n />\n\n <UnsavedChangesDialog\n open={blocker?.state === \"blocked\"}\n handleOk={() => blocker?.proceed?.()}\n handleCancel={() => blocker?.reset?.()}\n body={t(\"unsaved_changes_in_entity\")}/>\n </>;\n}\n\n/**\n * Shown when a URL names a collection the registry cannot resolve.\n *\n * This used to be `return null`, which renders an empty pane inside the app\n * chrome: the sidebar, the nav highlight and the breadcrumb all still work,\n * because those read the collections array directly, while the view itself is\n * blank. Nothing is thrown, and the only trace is a `console.debug` — so the\n * panel looks like it lost its data rather than like it failed to find the\n * collection, and there is no string to search for.\n *\n * A slug containing slashes went unresolvable this way and cost an afternoon to\n * find. The lookup is fixed; this is the part that made it expensive.\n */\nfunction UnresolvedCollectionView({ path }: { path: string }) {\n const { t } = useTranslation();\n // Warn, not debug: this is a route that renders nothing useful, and it\n // should be visible at the console's default level.\n useEffect(() => {\n console.warn(\n `[rebase] No collection is registered for \"${path}\", so this route has nothing to render. ` +\n \"Check that the collection is in the collections array and that its slug matches the URL.\"\n );\n }, [path]);\n\n return <CenteredView>\n <ErrorView\n title={t(\"collection_not_found\")}\n error={t(\"collection_not_found_body\", { path })}\n tooltip={t(\"collection_not_found_hint\")}/>\n </CenteredView>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,cAAc;CAC1B,OAAO,oBAAC,UAAD;EAAU,UAAU,oBAAC,wBAAD,CAAwB,CAAA;YAC/C,oBAAC,oBAAD,CAAoB,CAAA;CACd,CAAA;AACd;AAEA,SAAS,qBAAqB;CAE1B,MAAM,WAAW,YAAY;CAC7B,MAAM,qBAAqB,gCAAgC;CAC3D,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,cAAc,yBAAyB;CAC7C,MAAM,wBAAwB,gCAAgC;CAC9D,MAAM,0BAA0B,2BAA2B;CAC3D,MAAM,yBAAyB,qBAAqB,mBAAmB,yBAAqB;CAC5F,MAAM,kBAAkB,6BAA6B;CAErD,MAAM,OAAO,SAAS;CAKtB,MAAM,mBAAmB,KAAK,SAAS,WAAW;CAClD,MAAM,cAAc,KAAK,SAAS,OAAO,KAAK;CAC9C,MAAM,QAAQ,KAAK,SAAS,MAAM,KAAK,CAAC;CACxC,MAAM,SAAS,KAAK,SAAS,OAAO;CACpC,MAAM,eAAe,KAAK,SAAS,OAAO;CAE1C,MAAM,WAAW,SAAS;CAG1B,MAAM,oBAAoB,6BAA6B;EACnD,MAHmB,cAAc,kBAAkB,QAG7C;EACN,aAAa,mBAAmB,eAAe,CAAC;CACpD,CAAC;CAED,gBAAgB;EACZ,YAAY,IAAI,EACZ,aAAa,kBAAkB,KAAK,UAAU;GAE1C,IAAI,MAAM,SAAS,UACf,OAAQ;IACJ,OAAO,OAAO,MAAM,QAAQ;IAC5B,KAAK,cAAc,uBAAuB,MAAM,IAAI;GACxD;QACG,IAAI,MAAM,SAAS,eACtB,OAAQ;IACJ,OAAO,OAAO,MAAM,KAAK,QAAQ,MAAM,KAAK,GAAG;IAC/C,KAAK,cAAc,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AAA;AACN;;;;;;;;;;;;;;AAeA,SAAS,yBAAyB,EAAE,QAA0B;CAC1D,MAAM,EAAE,MAAM,eAAe;CAG7B,gBAAgB;EACZ,QAAQ,KACJ,6CAA6C,KAAK,iIAEtD;CACJ,GAAG,CAAC,IAAI,CAAC;CAET,OAAO,oBAAC,cAAD,EAAA,UACH,oBAAC,WAAD;EACI,OAAO,EAAE,sBAAsB;EAC/B,OAAO,EAAE,6BAA6B,EAAE,KAAK,CAAC;EAC9C,SAAS,EAAE,2BAA2B;CAAG,CAAA,EACnC,CAAA;AAClB"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import type { CollectionConfig } from "@rebasepro/types";
|
|
3
3
|
import { SelectionController, SelectionQuery } from "@rebasepro/cms-types";
|
|
4
4
|
export interface SelectionMenuProps<M extends Record<string, unknown>> {
|
|
5
5
|
selectionController: SelectionController<M>;
|
|
6
6
|
/** The rows the view is holding right now. */
|
|
7
|
-
|
|
7
|
+
loadedRows: Record<string, unknown>[];
|
|
8
|
+
/** The rows' collection: what a row's id is read by. */
|
|
9
|
+
collection: CollectionConfig;
|
|
8
10
|
/** The view's live query — what "all matching" stands for. */
|
|
9
11
|
query: SelectionQuery<M>;
|
|
10
12
|
/** The view's filtered count. `undefined` while loading, or where the accessor has none. */
|
|
@@ -24,4 +26,4 @@ export interface SelectionMenuProps<M extends Record<string, unknown>> {
|
|
|
24
26
|
* So the escalation is a menu item — clicked deliberately, costing no layout,
|
|
25
27
|
* and in the place you already go to select everything.
|
|
26
28
|
*/
|
|
27
|
-
export declare function SelectionMenu<M extends Record<string, unknown>>({ selectionController,
|
|
29
|
+
export declare function SelectionMenu<M extends Record<string, unknown>>({ selectionController, loadedRows, collection, query, collectionEntitiesCount, collectionName }: SelectionMenuProps<M>): React.JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Checkbox, ChevronDownIcon, Menu, MenuItem, Tooltip, cls, iconSize } from "@rebasepro/ui";
|
|
4
|
-
import { useTranslation } from "@rebasepro/app";
|
|
4
|
+
import { idOfRow, useTranslation } from "@rebasepro/app";
|
|
5
5
|
//#region src/selection/SelectionMenu.tsx
|
|
6
6
|
/**
|
|
7
7
|
* The whole of selecting rows, in one control: a checkbox for the common case
|
|
@@ -16,14 +16,21 @@ import { useTranslation } from "@rebasepro/app";
|
|
|
16
16
|
* So the escalation is a menu item — clicked deliberately, costing no layout,
|
|
17
17
|
* and in the place you already go to select everything.
|
|
18
18
|
*/
|
|
19
|
-
function SelectionMenu({ selectionController,
|
|
19
|
+
function SelectionMenu({ selectionController, loadedRows, collection, query, collectionEntitiesCount, collectionName }) {
|
|
20
20
|
const { t } = useTranslation();
|
|
21
|
-
const { selection, selectedCount, hasSelection,
|
|
22
|
-
const selectedLoaded = useMemo(() =>
|
|
23
|
-
|
|
21
|
+
const { selection, selectedCount, hasSelection, isSelected, setSelectedRows, selectAllMatching, clearSelection } = selectionController;
|
|
22
|
+
const selectedLoaded = useMemo(() => loadedRows.filter((row) => {
|
|
23
|
+
const id = idOfRow(row, collection);
|
|
24
|
+
return id !== void 0 && isSelected(id);
|
|
25
|
+
}).length, [
|
|
26
|
+
loadedRows,
|
|
27
|
+
collection,
|
|
28
|
+
isSelected
|
|
29
|
+
]);
|
|
30
|
+
const allLoadedSelected = loadedRows.length > 0 && selectedLoaded === loadedRows.length;
|
|
24
31
|
const someSelected = selectedLoaded > 0 && !allLoadedSelected;
|
|
25
32
|
const isQuery = selection.type === "query";
|
|
26
|
-
const moreThanLoaded = collectionEntitiesCount !== void 0 && collectionEntitiesCount >
|
|
33
|
+
const moreThanLoaded = collectionEntitiesCount !== void 0 && collectionEntitiesCount > loadedRows.length;
|
|
27
34
|
const label = hasSelection ? t("selection_deselect_all") ?? "Deselect all" : t("selection_select_all_loaded") ?? "Select all loaded rows";
|
|
28
35
|
return /* @__PURE__ */ jsxs("div", {
|
|
29
36
|
className: cls("flex items-center rounded-md", hasSelection && "bg-surface-hover"),
|
|
@@ -36,11 +43,11 @@ function SelectionMenu({ selectionController, loadedEntities, query, collectionE
|
|
|
36
43
|
size: "small",
|
|
37
44
|
padding: false,
|
|
38
45
|
"aria-label": label,
|
|
39
|
-
disabled:
|
|
46
|
+
disabled: loadedRows.length === 0 && !isQuery,
|
|
40
47
|
checked: allLoadedSelected || isQuery,
|
|
41
48
|
indeterminate: someSelected,
|
|
42
49
|
onCheckedChange: (checked) => {
|
|
43
|
-
if (checked)
|
|
50
|
+
if (checked) setSelectedRows(loadedRows);
|
|
44
51
|
else clearSelection();
|
|
45
52
|
}
|
|
46
53
|
})
|
|
@@ -57,7 +64,7 @@ function SelectionMenu({ selectionController, loadedEntities, query, collectionE
|
|
|
57
64
|
children: [
|
|
58
65
|
/* @__PURE__ */ jsx(MenuItem, {
|
|
59
66
|
dense: true,
|
|
60
|
-
onClick: () =>
|
|
67
|
+
onClick: () => setSelectedRows(loadedRows),
|
|
61
68
|
children: t("selection_menu_all_loaded") ?? "All on this page"
|
|
62
69
|
}),
|
|
63
70
|
moreThanLoaded && /* @__PURE__ */ jsx(MenuItem, {
|