@rebasepro/cms 0.30.1 → 0.31.0-canary.g902a0ce
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 +8 -8
- package/dist/collection_editor/ConfigControllerProvider.js +25 -22
- package/dist/collection_editor/ConfigControllerProvider.js.map +1 -1
- package/dist/collection_editor/firestore_callee.d.ts +10 -0
- package/dist/collection_editor/firestore_callee.js +15 -0
- package/dist/collection_editor/firestore_callee.js.map +1 -0
- package/dist/collection_editor/firestore_edit.d.ts +62 -0
- package/dist/collection_editor/firestore_edit.js +339 -0
- package/dist/collection_editor/firestore_edit.js.map +1 -0
- package/dist/collection_editor/index.d.ts +2 -3
- package/dist/collection_editor/liveSchemaClient.d.ts +44 -22
- package/dist/collection_editor/liveSchemaClient.js +9 -3
- package/dist/collection_editor/liveSchemaClient.js.map +1 -1
- package/dist/collection_editor/property_column.d.ts +86 -0
- package/dist/collection_editor/property_column.js +719 -0
- package/dist/collection_editor/property_column.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +2 -24
- package/dist/collection_editor/serializable_utils.d.ts +1 -1
- package/dist/collection_editor/serializable_utils.js +2 -1
- package/dist/collection_editor/serializable_utils.js.map +1 -1
- package/dist/collection_editor/split_edit.d.ts +106 -0
- package/dist/collection_editor/split_edit.js +564 -0
- package/dist/collection_editor/split_edit.js.map +1 -0
- package/dist/collection_editor/split_edit_error.d.ts +25 -0
- package/dist/collection_editor/split_edit_error.js +35 -0
- package/dist/collection_editor/split_edit_error.js.map +1 -0
- package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
- package/dist/collection_editor/types/config_controller.d.ts +67 -1
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +6 -5
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +44 -12
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +18 -3
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +94 -55
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +2 -1
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +3 -3
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -3
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +7 -4
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js +15 -5
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.d.ts +20 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js +74 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.d.ts +34 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js +50 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -2
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -1
- package/dist/collection_editor/useDetachRulesConfirmation.d.ts +16 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js +48 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js.map +1 -0
- package/dist/collection_editor/useLiveSchemaEditing.d.ts +2 -2
- package/dist/collection_editor/useLiveSchemaEditing.js +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +54 -10
- package/dist/collection_editor/useLocalCollectionsConfigController.js +394 -122
- package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -1
- package/dist/collection_editor/validateCollectionJson.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +10 -9
- package/dist/components/CollectionPanel.js +5 -2
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +1 -2
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +3 -5
- package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +1 -1
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.d.ts +2 -2
- 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.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.d.ts +2 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.d.ts +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +2 -2
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionTableBinding/table_bindings.d.ts +2 -2
- package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -5
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +2 -4
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +6 -6
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +1 -2
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntitiesCount.js +3 -3
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +1 -2
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/RowActions.d.ts +1 -2
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/SortButton.d.ts +1 -1
- package/dist/components/CollectionViewBinding/SortButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +1 -2
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.d.ts +2 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.js +3 -3
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +2 -4
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +14 -19
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -1
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +1 -3
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +1 -2
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +23 -8
- package/dist/components/CollectionsProvider.js +23 -7
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/DefaultDrawer.js +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +1 -1
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +3 -3
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -1
- package/dist/components/EditViewBinding.js +6 -6
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.d.ts +1 -2
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityInspector.d.ts +1 -2
- package/dist/components/EntityInspector.js.map +1 -1
- package/dist/components/EntityPreviewBinding.d.ts +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +1 -1
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +1 -1
- package/dist/components/EntityViewBody.js +3 -4
- package/dist/components/EntityViewBody.js.map +1 -1
- package/dist/components/FieldValue.js +2 -2
- package/dist/components/FieldValue.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +12 -3
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/InlineEntityPreview.d.ts +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PropertyCollectionView.d.ts +2 -2
- package/dist/components/PropertyCollectionView.js.map +1 -1
- package/dist/components/PropertyConfigBadge.js.map +1 -1
- package/dist/components/RebaseCMS.d.ts +22 -3
- package/dist/components/RebaseCMS.js +32 -14
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +106 -31
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RecordDetail.js +4 -1
- package/dist/components/RecordDetail.js.map +1 -1
- package/dist/components/RecordForm.d.ts +5 -5
- package/dist/components/RecordForm.js +5 -2
- package/dist/components/RecordForm.js.map +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +2 -2
- package/dist/components/ReferenceTable/SelectionTableBinding.js +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +2 -1
- package/dist/components/ReferenceWidget.js +2 -2
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.d.ts +2 -1
- package/dist/components/RelationSelector.js +2 -3
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.d.ts +2 -2
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.d.ts +2 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js +3 -3
- package/dist/components/SelectableTable/filters/FilterFieldBinding.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/SelectableTable/filters/RelationFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/null_filter.d.ts +1 -3
- package/dist/components/SelectableTable/filters/null_filter.js.map +1 -1
- package/dist/components/SidePanelBinding.js +1 -1
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/field_configs.d.ts +1 -2
- package/dist/components/field_configs.js.map +1 -1
- package/dist/components/field_ids.d.ts +1 -1
- package/dist/components/field_ids.js +1 -1
- package/dist/components/field_ids.js.map +1 -1
- package/dist/components/history/EntityHistoryEntry.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +1 -2
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/data_export/export/BasicExportAction.d.ts +1 -1
- package/dist/data_export/export/BasicExportAction.js.map +1 -1
- package/dist/data_export/export/ExportCollectionAction.js +2 -2
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +1 -1
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_export/export/export.d.ts +1 -1
- package/dist/data_export/export/export.js +1 -1
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/data_export/export/fetch_export_data.d.ts +3 -2
- package/dist/data_export/export/fetch_export_data.js.map +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -1
- package/dist/data_import/hooks/useImportConfig.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.d.ts +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/data_import/types/column_mapping.d.ts +1 -1
- package/dist/data_import/utils/data.d.ts +1 -2
- package/dist/data_import/utils/data.js +1 -2
- package/dist/data_import/utils/data.js.map +1 -1
- package/dist/data_import/utils/get_import_inference_type.d.ts +1 -1
- package/dist/data_import/utils/get_import_inference_type.js.map +1 -1
- package/dist/data_import/utils/id_column.d.ts +1 -1
- package/dist/data_import/utils/id_column.js.map +1 -1
- package/dist/data_import/utils/import_columns.d.ts +1 -1
- package/dist/data_import/utils/import_columns.js.map +1 -1
- package/dist/data_import/utils/save_entities.d.ts +3 -3
- package/dist/data_import/utils/save_entities.js +1 -1
- package/dist/data_import/utils/save_entities.js.map +1 -1
- package/dist/form/EntityForm.js +2 -1
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.js +2 -2
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormFieldsContext.d.ts +1 -4
- package/dist/form/FormFieldsContext.js +1 -1
- package/dist/form/FormFieldsContext.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +6 -8
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/components/FieldBlock.d.ts +1 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FieldHelperText.d.ts +1 -1
- package/dist/form/components/FieldHelperText.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +1 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/LocalChangesMenu.d.ts +1 -1
- package/dist/form/components/LocalChangesMenu.js.map +1 -1
- package/dist/form/components/StorageItemPreview.d.ts +1 -1
- package/dist/form/components/StorageItemPreview.js.map +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.js +1 -2
- package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MapFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +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/MultiSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +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.d.ts +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +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.d.ts +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/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +3 -3
- package/dist/form/form_utils.js +1 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/label_placement.d.ts +1 -2
- package/dist/form/label_placement.js.map +1 -1
- package/dist/form/resolve_cell_property.d.ts +1 -2
- package/dist/form/resolve_cell_property.js +1 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/form/resolve_form_properties.d.ts +2 -2
- package/dist/form/resolve_form_properties.js +1 -1
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/form/useClearRestoreValue.d.ts +1 -1
- package/dist/form/useClearRestoreValue.js.map +1 -1
- package/dist/form/validation.d.ts +2 -2
- package/dist/form/validation.js +1 -1
- package/dist/form/validation.js.map +1 -1
- package/dist/hooks/navigation/compose_collections.d.ts +59 -0
- package/dist/hooks/navigation/compose_collections.js +48 -0
- package/dist/hooks/navigation/compose_collections.js.map +1 -0
- package/dist/hooks/navigation/compose_collections_input.d.ts +8 -0
- package/dist/hooks/navigation/compose_collections_input.js +17 -0
- package/dist/hooks/navigation/compose_collections_input.js.map +1 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +1 -1
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -1
- package/dist/hooks/navigation/registered_collection.d.ts +15 -0
- package/dist/hooks/navigation/registered_collection.js +20 -0
- package/dist/hooks/navigation/registered_collection.js.map +1 -0
- package/dist/hooks/navigation/ui_preferences.d.ts +47 -0
- package/dist/hooks/navigation/ui_preferences.js +179 -0
- package/dist/hooks/navigation/ui_preferences.js.map +1 -0
- package/dist/hooks/navigation/useAsyncResolver.d.ts +8 -1
- package/dist/hooks/navigation/useAsyncResolver.js +9 -3
- package/dist/hooks/navigation/useAsyncResolver.js.map +1 -1
- package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +1 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js +3 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +9 -5
- package/dist/hooks/navigation/useBuildNavigationStateController.js +2 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useBuildUrlController.d.ts +1 -1
- package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.js +1 -2
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/usePanelTables.d.ts +11 -0
- package/dist/hooks/navigation/usePanelTables.js +33 -0
- package/dist/hooks/navigation/usePanelTables.js.map +1 -0
- package/dist/hooks/navigation/useResolvedCollections.d.ts +8 -3
- package/dist/hooks/navigation/useResolvedCollections.js +3 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +1 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -2
- package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -1
- package/dist/hooks/navigation/user_preferences_overlay.d.ts +21 -0
- package/dist/hooks/navigation/user_preferences_overlay.js +101 -0
- package/dist/hooks/navigation/user_preferences_overlay.js.map +1 -0
- package/dist/hooks/navigation/utils.js +1 -1
- package/dist/hooks/navigation/utils.js.map +1 -1
- package/dist/hooks/useAdminContext.d.ts +1 -2
- package/dist/hooks/useAdminContext.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.d.ts +1 -2
- package/dist/hooks/useBuildSidePanel.js +2 -1
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useChildViewSource.d.ts +1 -1
- package/dist/hooks/useChildViewSource.js +1 -1
- package/dist/hooks/useChildViewSource.js.map +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +1 -2
- package/dist/hooks/useEntityDisplay.js +1 -1
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useEntityDisplayTitle.d.ts +2 -2
- package/dist/hooks/useEntityDisplayTitle.js.map +1 -1
- package/dist/hooks/useHistory.js +1 -1
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/hooks/useRecordActions.d.ts +1 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useReferencePaths.d.ts +21 -7
- package/dist/hooks/useReferencePaths.js +23 -6
- package/dist/hooks/useReferencePaths.js.map +1 -1
- package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
- package/dist/hooks/useResolvedNavigationFrom.js +1 -1
- package/dist/hooks/useResolvedNavigationFrom.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -2
- package/dist/mcp_view/app_modules.d.ts +2 -2
- package/dist/mcp_view/app_modules.js +4 -4
- package/dist/mcp_view/app_modules.js.map +1 -1
- package/dist/mcp_view/index.d.ts +16 -19
- package/dist/mcp_view/index.js +43 -62
- package/dist/mcp_view/index.js.map +1 -1
- package/dist/mcp_view/payload.d.ts +54 -18
- package/dist/mcp_view/payload.js +49 -24
- package/dist/mcp_view/payload.js.map +1 -1
- package/dist/mcp_view/screen.js +11 -11
- package/dist/mcp_view/screen.js.map +1 -1
- package/dist/mcp_view/tool_driver.d.ts +5 -34
- package/dist/mcp_view/tool_driver.js +17 -16
- package/dist/mcp_view/tool_driver.js.map +1 -1
- package/dist/mcp_view/write_review.d.ts +1 -2
- package/dist/mcp_view/write_review.js +1 -1
- package/dist/mcp_view/write_review.js.map +1 -1
- package/dist/preview/PropertyPreview.d.ts +1 -1
- package/dist/preview/PropertyPreview.js +4 -3
- package/dist/preview/PropertyPreview.js.map +1 -1
- package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
- package/dist/preview/components/ArrayEnumPreview.js.map +1 -1
- package/dist/preview/components/BooleanPreview.d.ts +1 -1
- package/dist/preview/components/BooleanPreview.js.map +1 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/components/EnumValuesChip.js +1 -1
- package/dist/preview/components/EnumValuesChip.js.map +1 -1
- package/dist/preview/components/ReferencePreview.d.ts +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.d.ts +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/preview/components/StorageThumbnail.js +2 -1
- package/dist/preview/components/StorageThumbnail.js.map +1 -1
- package/dist/preview/components/UserPreview.d.ts +1 -1
- package/dist/preview/components/UserPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js +2 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -1
- package/dist/preview/util.d.ts +1 -1
- package/dist/preview/util.js.map +1 -1
- package/dist/routes/RebaseRoute.js +2 -2
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/saved_apps/SavedAppsView.d.ts +1 -1
- package/dist/saved_apps/SavedAppsView.js +1 -1
- package/dist/saved_apps/SavedAppsView.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +1 -1
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/resolve_selection.d.ts +3 -3
- package/dist/selection/resolve_selection.js +3 -2
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/tables/apply_customization.d.ts +65 -0
- package/dist/tables/apply_customization.js +644 -0
- package/dist/tables/apply_customization.js.map +1 -0
- package/dist/tables/column_property.d.ts +64 -0
- package/dist/tables/column_property.js +549 -0
- package/dist/tables/column_property.js.map +1 -0
- package/dist/tables/customize_table.d.ts +39 -0
- package/dist/tables/customize_table.js +247 -0
- package/dist/tables/customize_table.js.map +1 -0
- package/dist/tables/index.d.ts +12 -0
- package/dist/tables/labels.d.ts +18 -0
- package/dist/tables/labels.js +18 -0
- package/dist/tables/labels.js.map +1 -0
- package/dist/tables/project_table.d.ts +79 -0
- package/dist/tables/project_table.js +148 -0
- package/dist/tables/project_table.js.map +1 -0
- package/dist/tables/relations.d.ts +47 -0
- package/dist/tables/relations.js +112 -0
- package/dist/tables/relations.js.map +1 -0
- package/dist/tables/rls.d.ts +39 -0
- package/dist/tables/rls.js +111 -0
- package/dist/tables/rls.js.map +1 -0
- package/dist/tables/update_record.d.ts +32 -0
- package/dist/tables/update_record.js +40 -0
- package/dist/tables/update_record.js.map +1 -0
- package/dist/types/components/EntityFormActionsProps.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +2 -2
- package/dist/types/fields.d.ts +2 -2
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/entity_pages.d.ts +2 -1
- package/dist/util/entity_pages.js.map +1 -1
- package/dist/util/find_entities_by_ids.d.ts +2 -2
- package/dist/util/find_entities_by_ids.js +1 -1
- package/dist/util/find_entities_by_ids.js.map +1 -1
- package/dist/util/format_collection_date.d.ts +1 -1
- package/dist/util/format_collection_date.js.map +1 -1
- package/dist/util/identity.d.ts +8 -0
- package/dist/util/identity.js +16 -0
- package/dist/util/identity.js.map +1 -0
- package/dist/util/navigation_utils.js +1 -1
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/previews.js +1 -1
- package/dist/util/previews.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +1 -1
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/dist/util/property_utils.d.ts +1 -3
- package/dist/util/property_utils.js +1 -1
- package/dist/util/property_utils.js.map +1 -1
- package/dist/util/relations.d.ts +18 -0
- package/dist/util/relations.js +32 -0
- package/dist/util/relations.js.map +1 -0
- package/package.json +12 -10
- package/recipes/README.md +4 -4
- package/recipes/my-preferences.tsx +34 -26
- package/recipes/site-settings.tsx +34 -27
- package/dist/collection_editor/collection_wire.d.ts +0 -13
- package/dist/collection_editor/collection_wire.js +0 -49
- package/dist/collection_editor/collection_wire.js.map +0 -1
- package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +0 -37
- package/dist/collection_editor/useJsonCollectionsConfigController.js +0 -191
- package/dist/collection_editor/useJsonCollectionsConfigController.js.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { FilterPreset } from "@rebasepro/types";
|
|
3
|
-
import type { EntityTableController, PropertyPath } from "@rebasepro/cms-types";
|
|
2
|
+
import type { EntityTableController, PropertyPath, FilterPreset } from "@rebasepro/cms-types";
|
|
4
3
|
export interface FilterPresetsButtonProps<M extends Record<string, unknown>> {
|
|
5
4
|
filterPresets: FilterPreset<PropertyPath<M>>[];
|
|
6
5
|
tableController: EntityTableController<M>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useCallback, useMemo } from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { CheckIcon, ChevronsUpDownIcon, FilterChip, Menu, MenuItem, Tooltip, cls } from "@rebasepro/ui";
|
|
4
|
-
import { normalizeOrderBy } from "@rebasepro/common";
|
|
5
4
|
import { useTranslation } from "@rebasepro/app";
|
|
5
|
+
import { normalizeOrderBy } from "@rebasepro/common";
|
|
6
6
|
//#region src/components/CollectionViewBinding/FilterPresetsButton.tsx
|
|
7
7
|
/**
|
|
8
8
|
* Maximum number of presets shown as inline toggle chips before the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterPresetsButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FilterPresetsButton.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from \"react\";\nimport { CheckIcon, ChevronsUpDownIcon, cls, FilterChip, Menu, MenuItem, Tooltip } from \"@rebasepro/ui\";\nimport type { FilterValues, FilterPreset, OrderByTuple } from \"@rebasepro/types\";\nimport { normalizeOrderBy } from \"@rebasepro/common\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport type { EntityTableController, PropertyPath } from \"@rebasepro/cms-types\";\n\nexport interface FilterPresetsButtonProps<M extends Record<string, unknown>> {\n // Matches `admin.filterPresets`, which is keyed by property path — the\n // component is fed straight from the collection.\n filterPresets: FilterPreset<PropertyPath<M>>[];\n tableController: EntityTableController<M>;\n compact?: boolean;\n}\n\n/**\n * Maximum number of presets shown as inline toggle chips before the\n * rest are collapsed into an overflow menu.\n */\nconst MAX_VISIBLE_PRESETS = 4;\n\n/** Max characters for a chip label before truncation. */\nconst MAX_LABEL_LENGTH = 22;\n\n// ─── Helpers ────────────────────────────────────────────────────────\n\n/**\n * Deep equality without JSON.stringify.\n * Handles primitives, arrays, Dates, and plain objects recursively.\n */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a == null || b == null) return false;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((v, i) => deepEqual(v, b[i]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aKeys = Object.keys(a as Record<string, unknown>);\n const bKeys = Object.keys(b as Record<string, unknown>);\n if (aKeys.length !== bKeys.length) return false;\n return aKeys.every(k =>\n deepEqual(\n (a as Record<string, unknown>)[k],\n (b as Record<string, unknown>)[k]\n )\n );\n }\n return false;\n}\n\n/**\n * Check if a preset's filters are a subset of the controller's\n * current filter values (key-by-key deep comparison on the tuples).\n */\nfunction isPresetActive(\n preset: FilterPreset<string>,\n controllerFilters: Record<string, unknown> | undefined\n): boolean {\n if (!controllerFilters) return false;\n const entries = Object.entries(preset.filterValues);\n if (entries.length === 0) return false;\n for (const [key, presetTuple] of entries) {\n const controllerTuple = controllerFilters[key];\n if (!controllerTuple || !presetTuple) return false;\n if (!deepEqual(presetTuple, controllerTuple)) return false;\n }\n return true;\n}\n\n/**\n * Generate a human-readable label from filter keys when no explicit label is provided.\n */\nfunction generateLabel(filterValues: FilterValues<string>, emptyLabel: string): string {\n const keys = Object.keys(filterValues);\n if (keys.length === 0) return emptyLabel;\n if (keys.length === 1) return keys[0].replace(/_/g, \" \");\n if (keys.length === 2) return keys.map(k => k.replace(/_/g, \" \")).join(\" + \");\n return `${keys[0].replace(/_/g, \" \")} +${keys.length - 1}`;\n}\n\n/**\n * Truncate a label if it exceeds MAX_LABEL_LENGTH.\n */\nfunction truncateLabel(label: string): { display: string; truncated: boolean } {\n if (label.length <= MAX_LABEL_LENGTH) return { display: label,\ntruncated: false };\n return { display: label.slice(0, MAX_LABEL_LENGTH - 1) + \"…\",\ntruncated: true };\n}\n\n// ─── Overflow Menu ──────────────────────────────────────────────────\n\ninterface OverflowMenuProps {\n presets: { preset: FilterPreset<string>; originalIndex: number }[];\n activeSet: Set<number>;\n onToggle: (index: number) => void;\n}\n\nfunction OverflowMenu({ presets, activeSet, onToggle }: OverflowMenuProps) {\n const { t } = useTranslation();\n const activeCount = presets.filter(p => activeSet.has(p.originalIndex)).length;\n\n const trigger = (\n <FilterChip\n active={activeCount > 0}\n icon={<ChevronsUpDownIcon size={12} />}\n >\n +{presets.length}\n </FilterChip>\n );\n\n return (\n <Menu trigger={trigger} side=\"bottom\" align=\"start\">\n <div className=\"min-w-[180px] max-w-[300px] max-h-[320px] overflow-y-auto\">\n {presets.map(({ preset, originalIndex }) => {\n const rawLabel = preset.label ?? generateLabel(preset.filterValues as FilterValues<string>, t(\"filter\"));\n const active = activeSet.has(originalIndex);\n\n return (\n <MenuItem\n key={originalIndex}\n dense\n onClick={() => onToggle(originalIndex)}\n className={cls(active && \"bg-primary/10 dark:bg-primary/20\")}\n >\n <span className=\"flex items-center gap-2 w-full min-w-0\">\n {active && <CheckIcon size={14} className=\"text-primary shrink-0\" />}\n <span className={cls(\"truncate\", active ? \"text-primary font-medium\" : \"\")}>\n {rawLabel}\n </span>\n </span>\n </MenuItem>\n );\n })}\n </div>\n </Menu>\n );\n}\n\n// ─── Main Component ─────────────────────────────────────────────────\n\n/**\n * Filter Presets — displayed as inline toggle chips in the collection toolbar.\n *\n * Active state is **derived** from the controller's actual filter values,\n * not tracked locally. A chip is \"active\" when ALL of its filter entries\n * match the current controller state (deep value comparison, no JSON.stringify).\n *\n * This means:\n * - Toggling a preset on adds its filters to the controller.\n * - Toggling it off removes its filter keys.\n * - Changing filters via the dialog automatically deactivates unmatched chips.\n * - Clearing all filters deactivates all chips.\n * - Multiple presets can be active simultaneously.\n */\nexport function FilterPresetsButton<M extends Record<string, unknown>>({\n filterPresets,\n tableController,\n compact\n}: FilterPresetsButtonProps<M>) {\n const { t } = useTranslation();\n\n // ── Derive active state from controller ─────────────────────────\n const activeSet = useMemo(() => {\n const set = new Set<number>();\n if (!filterPresets.length || !tableController.setFilterValues) return set;\n for (let i = 0; i < filterPresets.length; i++) {\n if (isPresetActive(\n filterPresets[i] as FilterPreset<string>,\n tableController.filterValues as Record<string, unknown> | undefined\n )) {\n set.add(i);\n }\n }\n return set;\n }, [filterPresets, tableController.filterValues, tableController.setFilterValues]);\n\n // ── Toggle handler ──────────────────────────────────────────────\n const handleToggle = useCallback((index: number) => {\n const preset = filterPresets[index] as FilterPreset<string>;\n const currentFilters = { ...(tableController.filterValues ?? {}) } as Record<string, [string, unknown]>;\n const wasActive = isPresetActive(preset, currentFilters);\n\n if (wasActive) {\n // Toggle OFF: remove this preset's filter keys\n for (const key of Object.keys(preset.filterValues)) {\n delete currentFilters[key];\n }\n // Re-apply overlapping keys from other still-active presets\n for (let i = 0; i < filterPresets.length; i++) {\n if (i === index) continue;\n const other = filterPresets[i] as FilterPreset<string>;\n if (isPresetActive(other, currentFilters)) {\n Object.assign(currentFilters, other.filterValues);\n }\n }\n } else {\n // Toggle ON: merge this preset's filters on top\n Object.assign(currentFilters, preset.filterValues);\n }\n\n // Apply\n if (Object.keys(currentFilters).length === 0) {\n if (tableController.clearFilter) {\n tableController.clearFilter();\n } else {\n tableController.setFilterValues?.(\n {} as FilterValues<Extract<keyof M, string> | (string & {})>\n );\n }\n tableController.setSortBy?.(undefined);\n } else {\n tableController.setFilterValues?.(\n currentFilters as FilterValues<Extract<keyof M, string> | (string & {})>\n );\n\n // Resolve sort: use the toggled preset's sort if toggling on,\n // otherwise find sort from remaining active presets\n if (!wasActive && preset.sort) {\n tableController.setSortBy?.(\n normalizeOrderBy(preset.sort) as OrderByTuple<Extract<keyof M, string> | (string & {})>[]\n );\n } else if (wasActive) {\n let remainingSort: OrderByTuple[] | undefined;\n for (let i = 0; i < filterPresets.length; i++) {\n if (i === index) continue;\n const other = filterPresets[i] as FilterPreset<string>;\n if (isPresetActive(other, currentFilters) && other.sort) {\n remainingSort = normalizeOrderBy(other.sort);\n }\n }\n tableController.setSortBy?.(\n remainingSort as OrderByTuple<Extract<keyof M, string> | (string & {})>[] | undefined\n );\n }\n }\n }, [filterPresets, tableController]);\n\n // ── Guard (after hooks to preserve Rules of Hooks) ──────────────\n if (!filterPresets.length || !tableController.setFilterValues) return null;\n\n // ── Split visible vs overflow ───────────────────────────────────\n const maxVisible = compact ? 2 : MAX_VISIBLE_PRESETS;\n const needsOverflow = filterPresets.length > maxVisible;\n const visibleCount = needsOverflow ? maxVisible - 1 : filterPresets.length;\n\n const visiblePresets = filterPresets.slice(0, visibleCount);\n const overflowPresets = needsOverflow\n ? filterPresets.slice(visibleCount).map((preset, i) => ({\n preset: preset as FilterPreset<string>,\n originalIndex: visibleCount + i\n }))\n : [];\n\n const hasOverflow = overflowPresets.length > 0;\n\n return (\n <div className=\"flex items-center gap-1 min-w-0 overflow-hidden\">\n {/* Scrollable chip area — on narrow screens chips scroll,\n on desktop there's enough space so no scroll occurs.\n py-0.5 gives the inset shadow breathing room inside the clip area. */}\n <div\n className=\"flex items-center gap-1 min-w-0 overflow-x-auto py-0.5\"\n style={{ scrollbarWidth: \"none\" }}\n >\n {visiblePresets.map((preset, index) => {\n const rawLabel = preset.label ?? generateLabel(preset.filterValues as FilterValues<string>, t(\"filter\"));\n const { display, truncated } = truncateLabel(rawLabel);\n const active = activeSet.has(index);\n\n const chip = (\n <FilterChip\n key={index}\n active={active}\n onClick={() => handleToggle(index)}\n size=\"small\"\n >\n {display}\n </FilterChip>\n );\n\n if (truncated) {\n return <Tooltip key={index} title={rawLabel}>{chip}</Tooltip>;\n }\n return chip;\n })}\n </div>\n\n {/* Overflow button — always pinned outside the scroll area */}\n {hasOverflow && (\n <OverflowMenu\n presets={overflowPresets}\n activeSet={activeSet}\n onToggle={handleToggle}\n />\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAmBA,IAAM,sBAAsB;;AAG5B,IAAM,mBAAmB;;;;;AAQzB,SAAS,UAAU,GAAY,GAAqB;CAChD,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,KAAK,QAAQ,KAAK,MAAM,OAAO;CACnC,IAAI,aAAa,QAAQ,aAAa,MAAM,OAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;CAC7E,IAAI,MAAM,QA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,IAAI;CACjC,MAAM,gBAAgB,cAAc,SAAS;CAC7C,MAAM,eAAe,gBAAgB,aAAa,IAAI,cAAc;CAEpE,MAAM,iBAAiB,cAAc,MAAM,GAAG,YAAY;CAC1D,MAAM,kBAAkB,gBAClB,cAAc,MAAM,YAAY,CAAC,CAAC,KAAK,QAAQ,OAAO;EAC5C;EACR,eAAe,eAAe;CAClC,EAAE,IACA,CAAC;CAEP,MAAM,cAAc,gBAAgB,SAAS;CAE7C,OACI,qBAAC,OAAD;EAAK,WAAU;YAAf,CAII,oBAAC,OAAD;GACI,WAAU;GACV,OAAO,EAAE,gBAAgB,OAAO;aAE/B,eAAe,KAAK,QAAQ,UAAU;IACnC,MAAM,WAAW,OAAO,SAAS,cAAc,OAAO,cAAsC,EAAE,QAAQ,CAAC;IACvG,MAAM,EAAE,SAAS,cAAc,cAAc,QAAQ;IAGrD,MAAM,OACF,oBAAC,YAAD;KAEY,QALD,UAAU,IAAI,KAKb;KACR,eAAe,aAAa,KAAK;KACjC,MAAK;eAEJ;IACO,GANH,KAMG;IAGhB,IAAI,WACA,OAAO,oBAAC,SAAD;KAAqB,OAAO;eAAW;IAAc,GAAvC,KAAuC;IAEhE,OAAO;GACX,CAAC;EACA,CAAA,GAGJ,eACG,oBAAC,cAAD;GACI,SAAS;GACE;GACX,UAAU;EACb,CAAA,CAEJ;;AAEb"}
|
|
1
|
+
{"version":3,"file":"FilterPresetsButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FilterPresetsButton.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from \"react\";\nimport { CheckIcon, ChevronsUpDownIcon, cls, FilterChip, Menu, MenuItem, Tooltip } from \"@rebasepro/ui\";\nimport type { FilterValues, OrderByTuple } from \"@rebasepro/types\";\nimport { normalizeOrderBy } from \"@rebasepro/common\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport type { EntityTableController, PropertyPath, FilterPreset } from \"@rebasepro/cms-types\";\n\nexport interface FilterPresetsButtonProps<M extends Record<string, unknown>> {\n // Matches `admin.filterPresets`, which is keyed by property path — the\n // component is fed straight from the collection.\n filterPresets: FilterPreset<PropertyPath<M>>[];\n tableController: EntityTableController<M>;\n compact?: boolean;\n}\n\n/**\n * Maximum number of presets shown as inline toggle chips before the\n * rest are collapsed into an overflow menu.\n */\nconst MAX_VISIBLE_PRESETS = 4;\n\n/** Max characters for a chip label before truncation. */\nconst MAX_LABEL_LENGTH = 22;\n\n// ─── Helpers ────────────────────────────────────────────────────────\n\n/**\n * Deep equality without JSON.stringify.\n * Handles primitives, arrays, Dates, and plain objects recursively.\n */\nfunction deepEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a == null || b == null) return false;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((v, i) => deepEqual(v, b[i]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aKeys = Object.keys(a as Record<string, unknown>);\n const bKeys = Object.keys(b as Record<string, unknown>);\n if (aKeys.length !== bKeys.length) return false;\n return aKeys.every(k =>\n deepEqual(\n (a as Record<string, unknown>)[k],\n (b as Record<string, unknown>)[k]\n )\n );\n }\n return false;\n}\n\n/**\n * Check if a preset's filters are a subset of the controller's\n * current filter values (key-by-key deep comparison on the tuples).\n */\nfunction isPresetActive(\n preset: FilterPreset<string>,\n controllerFilters: Record<string, unknown> | undefined\n): boolean {\n if (!controllerFilters) return false;\n const entries = Object.entries(preset.filterValues);\n if (entries.length === 0) return false;\n for (const [key, presetTuple] of entries) {\n const controllerTuple = controllerFilters[key];\n if (!controllerTuple || !presetTuple) return false;\n if (!deepEqual(presetTuple, controllerTuple)) return false;\n }\n return true;\n}\n\n/**\n * Generate a human-readable label from filter keys when no explicit label is provided.\n */\nfunction generateLabel(filterValues: FilterValues<string>, emptyLabel: string): string {\n const keys = Object.keys(filterValues);\n if (keys.length === 0) return emptyLabel;\n if (keys.length === 1) return keys[0].replace(/_/g, \" \");\n if (keys.length === 2) return keys.map(k => k.replace(/_/g, \" \")).join(\" + \");\n return `${keys[0].replace(/_/g, \" \")} +${keys.length - 1}`;\n}\n\n/**\n * Truncate a label if it exceeds MAX_LABEL_LENGTH.\n */\nfunction truncateLabel(label: string): { display: string; truncated: boolean } {\n if (label.length <= MAX_LABEL_LENGTH) return { display: label,\ntruncated: false };\n return { display: label.slice(0, MAX_LABEL_LENGTH - 1) + \"…\",\ntruncated: true };\n}\n\n// ─── Overflow Menu ──────────────────────────────────────────────────\n\ninterface OverflowMenuProps {\n presets: { preset: FilterPreset<string>; originalIndex: number }[];\n activeSet: Set<number>;\n onToggle: (index: number) => void;\n}\n\nfunction OverflowMenu({ presets, activeSet, onToggle }: OverflowMenuProps) {\n const { t } = useTranslation();\n const activeCount = presets.filter(p => activeSet.has(p.originalIndex)).length;\n\n const trigger = (\n <FilterChip\n active={activeCount > 0}\n icon={<ChevronsUpDownIcon size={12} />}\n >\n +{presets.length}\n </FilterChip>\n );\n\n return (\n <Menu trigger={trigger} side=\"bottom\" align=\"start\">\n <div className=\"min-w-[180px] max-w-[300px] max-h-[320px] overflow-y-auto\">\n {presets.map(({ preset, originalIndex }) => {\n const rawLabel = preset.label ?? generateLabel(preset.filterValues as FilterValues<string>, t(\"filter\"));\n const active = activeSet.has(originalIndex);\n\n return (\n <MenuItem\n key={originalIndex}\n dense\n onClick={() => onToggle(originalIndex)}\n className={cls(active && \"bg-primary/10 dark:bg-primary/20\")}\n >\n <span className=\"flex items-center gap-2 w-full min-w-0\">\n {active && <CheckIcon size={14} className=\"text-primary shrink-0\" />}\n <span className={cls(\"truncate\", active ? \"text-primary font-medium\" : \"\")}>\n {rawLabel}\n </span>\n </span>\n </MenuItem>\n );\n })}\n </div>\n </Menu>\n );\n}\n\n// ─── Main Component ─────────────────────────────────────────────────\n\n/**\n * Filter Presets — displayed as inline toggle chips in the collection toolbar.\n *\n * Active state is **derived** from the controller's actual filter values,\n * not tracked locally. A chip is \"active\" when ALL of its filter entries\n * match the current controller state (deep value comparison, no JSON.stringify).\n *\n * This means:\n * - Toggling a preset on adds its filters to the controller.\n * - Toggling it off removes its filter keys.\n * - Changing filters via the dialog automatically deactivates unmatched chips.\n * - Clearing all filters deactivates all chips.\n * - Multiple presets can be active simultaneously.\n */\nexport function FilterPresetsButton<M extends Record<string, unknown>>({\n filterPresets,\n tableController,\n compact\n}: FilterPresetsButtonProps<M>) {\n const { t } = useTranslation();\n\n // ── Derive active state from controller ─────────────────────────\n const activeSet = useMemo(() => {\n const set = new Set<number>();\n if (!filterPresets.length || !tableController.setFilterValues) return set;\n for (let i = 0; i < filterPresets.length; i++) {\n if (isPresetActive(\n filterPresets[i] as FilterPreset<string>,\n tableController.filterValues as Record<string, unknown> | undefined\n )) {\n set.add(i);\n }\n }\n return set;\n }, [filterPresets, tableController.filterValues, tableController.setFilterValues]);\n\n // ── Toggle handler ──────────────────────────────────────────────\n const handleToggle = useCallback((index: number) => {\n const preset = filterPresets[index] as FilterPreset<string>;\n const currentFilters = { ...(tableController.filterValues ?? {}) } as Record<string, [string, unknown]>;\n const wasActive = isPresetActive(preset, currentFilters);\n\n if (wasActive) {\n // Toggle OFF: remove this preset's filter keys\n for (const key of Object.keys(preset.filterValues)) {\n delete currentFilters[key];\n }\n // Re-apply overlapping keys from other still-active presets\n for (let i = 0; i < filterPresets.length; i++) {\n if (i === index) continue;\n const other = filterPresets[i] as FilterPreset<string>;\n if (isPresetActive(other, currentFilters)) {\n Object.assign(currentFilters, other.filterValues);\n }\n }\n } else {\n // Toggle ON: merge this preset's filters on top\n Object.assign(currentFilters, preset.filterValues);\n }\n\n // Apply\n if (Object.keys(currentFilters).length === 0) {\n if (tableController.clearFilter) {\n tableController.clearFilter();\n } else {\n tableController.setFilterValues?.(\n {} as FilterValues<Extract<keyof M, string> | (string & {})>\n );\n }\n tableController.setSortBy?.(undefined);\n } else {\n tableController.setFilterValues?.(\n currentFilters as FilterValues<Extract<keyof M, string> | (string & {})>\n );\n\n // Resolve sort: use the toggled preset's sort if toggling on,\n // otherwise find sort from remaining active presets\n if (!wasActive && preset.sort) {\n tableController.setSortBy?.(\n normalizeOrderBy(preset.sort) as OrderByTuple<Extract<keyof M, string> | (string & {})>[]\n );\n } else if (wasActive) {\n let remainingSort: OrderByTuple[] | undefined;\n for (let i = 0; i < filterPresets.length; i++) {\n if (i === index) continue;\n const other = filterPresets[i] as FilterPreset<string>;\n if (isPresetActive(other, currentFilters) && other.sort) {\n remainingSort = normalizeOrderBy(other.sort);\n }\n }\n tableController.setSortBy?.(\n remainingSort as OrderByTuple<Extract<keyof M, string> | (string & {})>[] | undefined\n );\n }\n }\n }, [filterPresets, tableController]);\n\n // ── Guard (after hooks to preserve Rules of Hooks) ──────────────\n if (!filterPresets.length || !tableController.setFilterValues) return null;\n\n // ── Split visible vs overflow ───────────────────────────────────\n const maxVisible = compact ? 2 : MAX_VISIBLE_PRESETS;\n const needsOverflow = filterPresets.length > maxVisible;\n const visibleCount = needsOverflow ? maxVisible - 1 : filterPresets.length;\n\n const visiblePresets = filterPresets.slice(0, visibleCount);\n const overflowPresets = needsOverflow\n ? filterPresets.slice(visibleCount).map((preset, i) => ({\n preset: preset as FilterPreset<string>,\n originalIndex: visibleCount + i\n }))\n : [];\n\n const hasOverflow = overflowPresets.length > 0;\n\n return (\n <div className=\"flex items-center gap-1 min-w-0 overflow-hidden\">\n {/* Scrollable chip area — on narrow screens chips scroll,\n on desktop there's enough space so no scroll occurs.\n py-0.5 gives the inset shadow breathing room inside the clip area. */}\n <div\n className=\"flex items-center gap-1 min-w-0 overflow-x-auto py-0.5\"\n style={{ scrollbarWidth: \"none\" }}\n >\n {visiblePresets.map((preset, index) => {\n const rawLabel = preset.label ?? generateLabel(preset.filterValues as FilterValues<string>, t(\"filter\"));\n const { display, truncated } = truncateLabel(rawLabel);\n const active = activeSet.has(index);\n\n const chip = (\n <FilterChip\n key={index}\n active={active}\n onClick={() => handleToggle(index)}\n size=\"small\"\n >\n {display}\n </FilterChip>\n );\n\n if (truncated) {\n return <Tooltip key={index} title={rawLabel}>{chip}</Tooltip>;\n }\n return chip;\n })}\n </div>\n\n {/* Overflow button — always pinned outside the scroll area */}\n {hasOverflow && (\n <OverflowMenu\n presets={overflowPresets}\n activeSet={activeSet}\n onToggle={handleToggle}\n />\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAmBA,IAAM,sBAAsB;;AAG5B,IAAM,mBAAmB;;;;;AAQzB,SAAS,UAAU,GAAY,GAAqB;CAChD,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,KAAK,QAAQ,KAAK,MAAM,OAAO;CACnC,IAAI,aAAa,QAAQ,aAAa,MAAM,OAAO,EAAE,QAAQ,MAAM,EAAE,QAAQ;CAC7E,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG;EACtC,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;EAClC,OAAO,EAAE,OAAO,GAAG,MAAM,UAAU,GAAG,EAAE,EAAE,CAAC;CAC/C;CACA,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAChD,MAAM,QAAQ,OAAO,KAAK,CAA4B;EACtD,MAAM,QAAQ,OAAO,KAAK,CAA4B;EACtD,IAAI,MAAM,WAAW,MAAM,QAAQ,OAAO;EAC1C,OAAO,MAAM,OAAM,MACf,UACK,EAA8B,IAC9B,EAA8B,EACnC,CACJ;CACJ;CACA,OAAO;AACX;;;;;AAMA,SAAS,eACL,QACA,mBACO;CACP,IAAI,CAAC,mBAAmB,OAAO;CAC/B,MAAM,UAAU,OAAO,QAAQ,OAAO,YAAY;CAClD,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,KAAK,MAAM,CAAC,KAAK,gBAAgB,SAAS;EACtC,MAAM,kBAAkB,kBAAkB;EAC1C,IAAI,CAAC,mBAAmB,CAAC,aAAa,OAAO;EAC7C,IAAI,CAAC,UAAU,aAAa,eAAe,GAAG,OAAO;CACzD;CACA,OAAO;AACX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AAC;EACA,CAAA,GAGJ,eACG,oBAAC,cAAD;GACI,SAAS;GACE;GACX,UAAU;EACb,CAAA,CAEJ;;AAEb"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Properties } from "@rebasepro/types";
|
|
2
|
-
import type { EntityTableController } from "@rebasepro/cms-types";
|
|
1
|
+
import type { EntityTableController, Properties } from "@rebasepro/cms-types";
|
|
3
2
|
import type { FilterValues } from "@rebasepro/types";
|
|
4
3
|
import React from "react";
|
|
5
4
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiltersButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersButton.tsx"],"sourcesContent":["import type { Properties } from \"@rebasepro/
|
|
1
|
+
{"version":3,"file":"FiltersButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersButton.tsx"],"sourcesContent":["import type { EntityTableController, Properties } from \"@rebasepro/cms-types\";\nimport type { FilterValues } from \"@rebasepro/types\";\nimport React, { useState } from \"react\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { Badge, Button, cls, FilterIcon, IconButton, iconSize, Tooltip } from \"@rebasepro/ui\";\nimport { FiltersDialog } from \"./FiltersDialog\";\n\n/**\n * The toolbar's filters control — labelled, or its icon-only form — with the\n * count of filters the person set, and the dialog it opens.\n */\nexport function FiltersButton<M extends Record<string, unknown>>({\n tableController,\n properties,\n fixedFilter,\n iconOnly\n}: {\n tableController: EntityTableController<M>;\n properties: Properties;\n /** The collection's scope: not a filter the person set, so not counted. */\n fixedFilter?: FilterValues<string>;\n iconOnly: boolean;\n}) {\n const { t } = useTranslation();\n const [open, setOpen] = useState(false);\n\n // Count active filters (excluding force filters)\n const filterValues = tableController.filterValues;\n const activeFilterCount = filterValues\n ? Object.keys(filterValues).filter(key => !fixedFilter || !(key in fixedFilter)).length\n : 0;\n\n if (!tableController.setFilterValues) return null;\n\n return (\n <>\n <Tooltip title={t(\"filters\")}>\n <Badge\n color=\"primary\"\n invisible={activeFilterCount === 0}\n >\n {!iconOnly ? (\n <Button\n variant=\"text\"\n size=\"small\"\n onClick={() => setOpen(true)}\n startIcon={<FilterIcon size={iconSize.small}/>}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n {activeFilterCount > 0 ? `(${activeFilterCount})` : t(\"filters\")}\n </Button>\n ) : (\n <IconButton aria-label={t(\"filters\")}\n size={\"small\"}\n onClick={() => setOpen(true)}\n className={cls(activeFilterCount > 0 && \"text-primary\")}\n >\n <FilterIcon size={iconSize.smallest}/>\n </IconButton>\n )}\n </Badge>\n </Tooltip>\n <FiltersDialog\n open={open}\n onOpenChange={setOpen}\n properties={properties}\n filterValues={tableController.filterValues}\n setFilterValues={(values) => tableController.setFilterValues?.(values ?? {})}\n fixedFilter={fixedFilter}\n />\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,cAAiD,EAC7D,iBACA,YACA,aACA,YAOD;CACC,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAGtC,MAAM,eAAe,gBAAgB;CACrC,MAAM,oBAAoB,eACpB,OAAO,KAAK,YAAY,CAAC,CAAC,QAAO,QAAO,CAAC,eAAe,EAAE,OAAO,YAAY,CAAC,CAAC,SAC/E;CAEN,IAAI,CAAC,gBAAgB,iBAAiB,OAAO;CAE7C,OACI,qBAAA,UAAA,EAAA,UAAA,CACI,oBAAC,SAAD;EAAS,OAAO,EAAE,SAAS;YACvB,oBAAC,OAAD;GACI,OAAM;GACN,WAAW,sBAAsB;aAEhC,CAAC,WACE,oBAAC,QAAD;IACI,SAAQ;IACR,MAAK;IACL,eAAe,QAAQ,IAAI;IAC3B,WAAW,oBAAC,YAAD,EAAY,MAAM,SAAS,MAAO,CAAA;IAC7C,WAAW,IAAI,oBAAoB,KAAK,cAAc;cAErD,oBAAoB,IAAI,IAAI,kBAAkB,KAAK,EAAE,SAAS;GAC3D,CAAA,IAER,oBAAC,YAAD;IAAY,cAAY,EAAE,SAAS;IAC/B,MAAM;IACN,eAAe,QAAQ,IAAI;IAC3B,WAAW,IAAI,oBAAoB,KAAK,cAAc;cAEtD,oBAAC,YAAD,EAAY,MAAM,SAAS,SAAU,CAAA;GAC7B,CAAA;EAEb,CAAA;CACF,CAAA,GACT,oBAAC,eAAD;EACU;EACN,cAAc;EACF;EACZ,cAAc,gBAAgB;EAC9B,kBAAkB,WAAW,gBAAgB,kBAAkB,UAAU,CAAC,CAAC;EAC9D;CAChB,CAAA,CACH,EAAA,CAAA;AAEV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiltersDialog.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersDialog.tsx"],"sourcesContent":["\nimport type { Property } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { FilterValues, WhereFilterOp } from \"@rebasepro/types\";\nimport { Button, Chip, cls, defaultBorderMixin, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport { FilterIcon, VirtualTableWhereFilterOp } from \"@rebasepro/ui\";\nimport { isPropertyFilterable } from \"@rebasepro/app\";\nimport { useCollectionScope, useTranslation } from \"@rebasepro/app\";\nimport { FilterFieldBinding } from \"../SelectableTable/filters/FilterFieldBinding\";\n\n/**\n * `WhereFilterOp` is declared twice: once in `@rebasepro/types` as the canonical\n * operator set every driver translates, and once in `@rebasepro/ui` for the\n * table's own props. That is deliberate — `ui` is a standalone design system and\n * depends on no Rebase package, so it cannot import the canonical one (and a\n * type-only import would not help: `ui` emits declarations with `tsc`, which\n * references external types rather than inlining them, so its published `.d.ts`\n * would demand `@rebasepro/types` from every consumer).\n *\n * This file is where the two meet and get cast into each other, so it is where\n * their agreement is checked. Adding an operator to one and not the other stops\n * this line compiling instead of silently producing a filter the table can build\n * and no driver can run — or one a driver supports and the table cannot offer.\n */\ntype MutuallyAssignable<A, B> = [A] extends [B] ? ([B] extends [A] ? true : never) : never;\nconst _whereFilterOpDefinitionsAgree: MutuallyAssignable<WhereFilterOp, VirtualTableWhereFilterOp> = true;\nvoid _whereFilterOpDefinitionsAgree;\n\n/**\n * The properties the dialog lists, each with a filter field: every property\n * that can be filtered, bar the collection's fixed-filter fields.\n */\nexport function getFilterableProperties(\n properties: Record<string, Property>,\n fixedFilter?: FilterValues<string>,\n engine?: string\n): [string, Property][] {\n return Object.entries(properties).filter(([key, property]) => {\n if (!property) return false;\n // Force filter properties should not be editable\n if (fixedFilter && key in fixedFilter) return false;\n // The table header asks the same question, so the two cannot list\n // different properties.\n return isPropertyFilterable(property, engine);\n });\n}\n\nexport interface FiltersDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n properties: Record<string, Property>;\n filterValues: FilterValues<any> | undefined;\n setFilterValues: (filterValues?: FilterValues<any>) => void;\n fixedFilter?: FilterValues<any>;\n}\n\n/**\n * Dialog that displays all filterable properties from a collection\n * and allows setting filter values for each.\n */\nexport function FiltersDialog({\n open,\n onOpenChange,\n properties,\n filterValues,\n setFilterValues,\n fixedFilter\n}: FiltersDialogProps) {\n const { t } = useTranslation();\n // Engine of the collection this dialog filters — read from the\n // surrounding CollectionScopeProvider mounted by the collection view.\n const engine = useCollectionScope()?.engine;\n // Local state for filters being edited\n const [localFilters, setLocalFilters] = useState<FilterValues<any>>(filterValues ?? {});\n\n // Track hidden state for reference fields (when reference dialog is open)\n const [hiddenFields, setHiddenFields] = useState<Record<string, boolean>>({});\n\n /**\n * Bumped by \"Clear all\", and part of each field's key, so every field\n * starts again from no value. A field keeps what it shows in its own\n * state — an operator picked before any value is not a filter yet — and\n * seeds it from `value` once, so emptying the filters alone left every\n * field showing the value it had.\n */\n const [fieldsGeneration, setFieldsGeneration] = useState(0);\n\n // Reset local state when dialog opens\n React.useEffect(() => {\n if (open) {\n setLocalFilters(filterValues ?? {});\n }\n }, [open, filterValues]);\n\n // Get list of filterable properties\n const filterableProperties = useMemo(\n () => getFilterableProperties(properties, fixedFilter, engine),\n [properties, fixedFilter, engine]);\n\n const handleFilterChange = useCallback((propertyKey: string, value?: [VirtualTableWhereFilterOp, any]) => {\n setLocalFilters(prev => {\n const newFilters = { ...prev };\n if (value) {\n newFilters[propertyKey] = value as [WhereFilterOp, any];\n } else {\n delete newFilters[propertyKey];\n }\n return newFilters;\n });\n }, []);\n\n const handleApply = useCallback(() => {\n const hasFilters = Object.keys(localFilters).length > 0;\n setFilterValues(hasFilters ? { ...localFilters,\n...fixedFilter } : (fixedFilter || undefined));\n onOpenChange(false);\n }, [localFilters, setFilterValues, fixedFilter, onOpenChange]);\n\n const handleClearAll = useCallback(() => {\n setLocalFilters({});\n setFieldsGeneration(generation => generation + 1);\n }, []);\n\n const setHiddenForField = useCallback((propertyKey: string, hidden: boolean) => {\n setHiddenFields(prev => ({\n ...prev,\n [propertyKey]: hidden\n }));\n }, []);\n\n // Check if any reference field's dialog is currently open (should hide this dialog)\n const isAnyFieldHidden = Object.values(hiddenFields).some(hidden => hidden);\n const activeFilterCount = Object.keys(localFilters).length;\n\n const renderFilterField = useCallback((propertyKey: string, property: Property) => {\n const filterValue = localFilters[propertyKey] as [WhereFilterOp, any] | undefined;\n const setValue = (value?: [WhereFilterOp, any]) => handleFilterChange(propertyKey, value as [VirtualTableWhereFilterOp, any] | undefined);\n\n return (\n <FilterFieldBinding\n key={`${propertyKey}:${fieldsGeneration}`}\n propertyKey={propertyKey}\n property={property}\n engine={engine}\n value={filterValue}\n setValue={setValue}\n hidden={hiddenFields[propertyKey] ?? false}\n setHidden={(hidden) => setHiddenForField(propertyKey, hidden)}\n />\n );\n }, [localFilters, handleFilterChange, hiddenFields, setHiddenForField, engine, fieldsGeneration]);\n\n return (\n <Dialog\n open={open}\n onOpenChange={onOpenChange}\n maxWidth=\"3xl\"\n fullWidth\n containerClassName={isAnyFieldHidden ? \"hidden\" : undefined}\n >\n <DialogTitle className=\"flex items-center gap-2\" variant=\"h6\">\n {t(\"filters\")}\n {activeFilterCount > 0 && (\n <Chip size=\"small\" className=\"ml-2\">\n {activeFilterCount}\n </Chip>\n )}\n </DialogTitle>\n\n <DialogContent >\n {filterableProperties.length === 0 ? (\n <Typography color=\"secondary\" className=\"py-8 text-center\">\n {t(\"no_filterable_properties\")}\n </Typography>\n ) : (\n <div className=\"grid grid-cols-[160px_minmax(0,1fr)] items-center\">\n {filterableProperties.map(([propertyKey, property], index) => {\n const hasFilter = propertyKey in localFilters;\n const rowBorder = index > 0 && cls(\"border-t\", defaultBorderMixin);\n return (\n <React.Fragment key={propertyKey}>\n {/* Property name on the left */}\n <div className={cls(\"py-3 pr-4 self-stretch flex items-center\", rowBorder)}>\n <Typography\n variant=\"body2\"\n className={cls(\n \"font-medium\",\n hasFilter && \"text-primary\"\n )}\n >\n {property.name || propertyKey}\n </Typography>\n </div>\n\n {/* The filter field on the right */}\n <div className={cls(\"py-3\", rowBorder)}>\n {renderFilterField(propertyKey, property)}\n </div>\n </React.Fragment>\n );\n })}\n </div>\n )}\n </DialogContent>\n\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={handleClearAll}\n disabled={activeFilterCount === 0}\n >\n {t(\"clear_all\")}\n </Button>\n <div className=\"flex-grow\"/>\n <Button\n variant=\"text\"\n onClick={() => onOpenChange(false)}\n >\n {t(\"cancel\")}\n </Button>\n <Button\n variant=\"filled\"\n onClick={handleApply}\n >\n {t(\"apply_filters\")}\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,wBACZ,YACA,aACA,QACoB;CACpB,OAAO,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,cAAc;EAC1D,IAAI,CAAC,UAAU,OAAO;EAEtB,IAAI,eAAe,OAAO,aAAa,OAAO;EAG9C,OAAO,qBAAqB,UAAU,MAAM;CAChD,CAAC;AACL;;;;;AAeA,SAAgB,cAAc,EAC1B,MACA,cACA,YACA,cACA,iBACA,eACmB;CACnB,MAAM,EAAE,MAAM,eAAe;CAG7B,MAAM,SAAS,mBAA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V,CAAA;IACR,oBAAC,OAAD,EAAK,WAAU,YAAY,CAAA;IAC3B,oBAAC,QAAD;KACI,SAAQ;KACR,eAAe,aAAa,KAAK;eAEhC,EAAE,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,SAAQ;KACR,SAAS;eAER,EAAE,eAAe;IACd,CAAA;GACG,EAAA,CAAA;EACX;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"FiltersDialog.js","names":[],"sources":["../../../src/components/CollectionViewBinding/FiltersDialog.tsx"],"sourcesContent":["\nimport type { Property } from \"@rebasepro/cms-types\";\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { FilterValues, WhereFilterOp } from \"@rebasepro/types\";\nimport { Button, Chip, cls, defaultBorderMixin, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport { FilterIcon, VirtualTableWhereFilterOp } from \"@rebasepro/ui\";\nimport { isPropertyFilterable } from \"@rebasepro/app\";\nimport { useCollectionScope, useTranslation } from \"@rebasepro/app\";\nimport { FilterFieldBinding } from \"../SelectableTable/filters/FilterFieldBinding\";\n\n/**\n * `WhereFilterOp` is declared twice: once in `@rebasepro/types` as the canonical\n * operator set every driver translates, and once in `@rebasepro/ui` for the\n * table's own props. That is deliberate — `ui` is a standalone design system and\n * depends on no Rebase package, so it cannot import the canonical one (and a\n * type-only import would not help: `ui` emits declarations with `tsc`, which\n * references external types rather than inlining them, so its published `.d.ts`\n * would demand `@rebasepro/types` from every consumer).\n *\n * This file is where the two meet and get cast into each other, so it is where\n * their agreement is checked. Adding an operator to one and not the other stops\n * this line compiling instead of silently producing a filter the table can build\n * and no driver can run — or one a driver supports and the table cannot offer.\n */\ntype MutuallyAssignable<A, B> = [A] extends [B] ? ([B] extends [A] ? true : never) : never;\nconst _whereFilterOpDefinitionsAgree: MutuallyAssignable<WhereFilterOp, VirtualTableWhereFilterOp> = true;\nvoid _whereFilterOpDefinitionsAgree;\n\n/**\n * The properties the dialog lists, each with a filter field: every property\n * that can be filtered, bar the collection's fixed-filter fields.\n */\nexport function getFilterableProperties(\n properties: Record<string, Property>,\n fixedFilter?: FilterValues<string>,\n engine?: string\n): [string, Property][] {\n return Object.entries(properties).filter(([key, property]) => {\n if (!property) return false;\n // Force filter properties should not be editable\n if (fixedFilter && key in fixedFilter) return false;\n // The table header asks the same question, so the two cannot list\n // different properties.\n return isPropertyFilterable(property, engine);\n });\n}\n\nexport interface FiltersDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n properties: Record<string, Property>;\n filterValues: FilterValues<any> | undefined;\n setFilterValues: (filterValues?: FilterValues<any>) => void;\n fixedFilter?: FilterValues<any>;\n}\n\n/**\n * Dialog that displays all filterable properties from a collection\n * and allows setting filter values for each.\n */\nexport function FiltersDialog({\n open,\n onOpenChange,\n properties,\n filterValues,\n setFilterValues,\n fixedFilter\n}: FiltersDialogProps) {\n const { t } = useTranslation();\n // Engine of the collection this dialog filters — read from the\n // surrounding CollectionScopeProvider mounted by the collection view.\n const engine = useCollectionScope()?.engine;\n // Local state for filters being edited\n const [localFilters, setLocalFilters] = useState<FilterValues<any>>(filterValues ?? {});\n\n // Track hidden state for reference fields (when reference dialog is open)\n const [hiddenFields, setHiddenFields] = useState<Record<string, boolean>>({});\n\n /**\n * Bumped by \"Clear all\", and part of each field's key, so every field\n * starts again from no value. A field keeps what it shows in its own\n * state — an operator picked before any value is not a filter yet — and\n * seeds it from `value` once, so emptying the filters alone left every\n * field showing the value it had.\n */\n const [fieldsGeneration, setFieldsGeneration] = useState(0);\n\n // Reset local state when dialog opens\n React.useEffect(() => {\n if (open) {\n setLocalFilters(filterValues ?? {});\n }\n }, [open, filterValues]);\n\n // Get list of filterable properties\n const filterableProperties = useMemo(\n () => getFilterableProperties(properties, fixedFilter, engine),\n [properties, fixedFilter, engine]);\n\n const handleFilterChange = useCallback((propertyKey: string, value?: [VirtualTableWhereFilterOp, any]) => {\n setLocalFilters(prev => {\n const newFilters = { ...prev };\n if (value) {\n newFilters[propertyKey] = value as [WhereFilterOp, any];\n } else {\n delete newFilters[propertyKey];\n }\n return newFilters;\n });\n }, []);\n\n const handleApply = useCallback(() => {\n const hasFilters = Object.keys(localFilters).length > 0;\n setFilterValues(hasFilters ? { ...localFilters,\n...fixedFilter } : (fixedFilter || undefined));\n onOpenChange(false);\n }, [localFilters, setFilterValues, fixedFilter, onOpenChange]);\n\n const handleClearAll = useCallback(() => {\n setLocalFilters({});\n setFieldsGeneration(generation => generation + 1);\n }, []);\n\n const setHiddenForField = useCallback((propertyKey: string, hidden: boolean) => {\n setHiddenFields(prev => ({\n ...prev,\n [propertyKey]: hidden\n }));\n }, []);\n\n // Check if any reference field's dialog is currently open (should hide this dialog)\n const isAnyFieldHidden = Object.values(hiddenFields).some(hidden => hidden);\n const activeFilterCount = Object.keys(localFilters).length;\n\n const renderFilterField = useCallback((propertyKey: string, property: Property) => {\n const filterValue = localFilters[propertyKey] as [WhereFilterOp, any] | undefined;\n const setValue = (value?: [WhereFilterOp, any]) => handleFilterChange(propertyKey, value as [VirtualTableWhereFilterOp, any] | undefined);\n\n return (\n <FilterFieldBinding\n key={`${propertyKey}:${fieldsGeneration}`}\n propertyKey={propertyKey}\n property={property}\n engine={engine}\n value={filterValue}\n setValue={setValue}\n hidden={hiddenFields[propertyKey] ?? false}\n setHidden={(hidden) => setHiddenForField(propertyKey, hidden)}\n />\n );\n }, [localFilters, handleFilterChange, hiddenFields, setHiddenForField, engine, fieldsGeneration]);\n\n return (\n <Dialog\n open={open}\n onOpenChange={onOpenChange}\n maxWidth=\"3xl\"\n fullWidth\n containerClassName={isAnyFieldHidden ? \"hidden\" : undefined}\n >\n <DialogTitle className=\"flex items-center gap-2\" variant=\"h6\">\n {t(\"filters\")}\n {activeFilterCount > 0 && (\n <Chip size=\"small\" className=\"ml-2\">\n {activeFilterCount}\n </Chip>\n )}\n </DialogTitle>\n\n <DialogContent >\n {filterableProperties.length === 0 ? (\n <Typography color=\"secondary\" className=\"py-8 text-center\">\n {t(\"no_filterable_properties\")}\n </Typography>\n ) : (\n <div className=\"grid grid-cols-[160px_minmax(0,1fr)] items-center\">\n {filterableProperties.map(([propertyKey, property], index) => {\n const hasFilter = propertyKey in localFilters;\n const rowBorder = index > 0 && cls(\"border-t\", defaultBorderMixin);\n return (\n <React.Fragment key={propertyKey}>\n {/* Property name on the left */}\n <div className={cls(\"py-3 pr-4 self-stretch flex items-center\", rowBorder)}>\n <Typography\n variant=\"body2\"\n className={cls(\n \"font-medium\",\n hasFilter && \"text-primary\"\n )}\n >\n {property.name || propertyKey}\n </Typography>\n </div>\n\n {/* The filter field on the right */}\n <div className={cls(\"py-3\", rowBorder)}>\n {renderFilterField(propertyKey, property)}\n </div>\n </React.Fragment>\n );\n })}\n </div>\n )}\n </DialogContent>\n\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={handleClearAll}\n disabled={activeFilterCount === 0}\n >\n {t(\"clear_all\")}\n </Button>\n <div className=\"flex-grow\"/>\n <Button\n variant=\"text\"\n onClick={() => onOpenChange(false)}\n >\n {t(\"cancel\")}\n </Button>\n <Button\n variant=\"filled\"\n onClick={handleApply}\n >\n {t(\"apply_filters\")}\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,wBACZ,YACA,aACA,QACoB;CACpB,OAAO,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,cAAc;EAC1D,IAAI,CAAC,UAAU,OAAO;EAEtB,IAAI,eAAe,OAAO,aAAa,OAAO;EAG9C,OAAO,qBAAqB,UAAU,MAAM;CAChD,CAAC;AACL;;;;;AAeA,SAAgB,cAAc,EAC1B,MACA,cACA,YACA,cACA,iBACA,eACmB;CACnB,MAAM,EAAE,MAAM,eAAe;CAG7B,MAAM,SAAS,mBAAmB,CAAC,EAAE;CAErC,MAAM,CAAC,cAAc,mBAAmB,SAA4B,gBAAgB,CAAC,CAAC;CAGtF,MAAM,CAAC,cAAc,mBAAmB,SAAkC,C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,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,SAAQ;KACR,SAAS;eAER,EAAE,eAAe;IACd,CAAA;GACG,EAAA,CAAA;EACX;;AAEhB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Property } from "@rebasepro/types";
|
|
2
|
-
import type { AdminCollection, SlotContribution, TableController } from "@rebasepro/cms-types";
|
|
1
|
+
import type { AdminCollection, SlotContribution, TableController, Property } from "@rebasepro/cms-types";
|
|
3
2
|
import React from "react";
|
|
4
3
|
export declare const EMPTY_ARRAY: never[];
|
|
5
4
|
/** What the plugins contributed to the table's add-column slot, for {@link PluginAddColumnComponents}. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginColumnSlots.js","names":[],"sources":["../../../src/components/CollectionViewBinding/PluginColumnSlots.tsx"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"PluginColumnSlots.js","names":[],"sources":["../../../src/components/CollectionViewBinding/PluginColumnSlots.tsx"],"sourcesContent":["import type { AdminCollection, SlotContribution, TableController, Property } from \"@rebasepro/cms-types\";\nimport React from \"react\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\n\nexport const EMPTY_ARRAY: never[] = [];\n\n/** What the plugins contributed to the table's add-column slot, for {@link PluginAddColumnComponents}. */\nexport const PluginAddColumnsContext = React.createContext<React.ReactNode[]>(EMPTY_ARRAY);\n\nexport function PluginAddColumnComponents() {\n const components = React.useContext(PluginAddColumnsContext);\n return (\n <div className=\"flex flex-row items-center gap-2\">\n {components}\n </div>\n );\n}\n\n/**\n * What the plugins' column-header actions are handed besides their column:\n * this render's collection and table controller. `null` when no plugin\n * contributes one.\n */\nexport type HeaderActionsScope = {\n contributions: SlotContribution<\"collection.header.action\">[],\n path: string,\n collection: AdminCollection,\n tableController: TableController,\n parentCollectionSlugs: string[],\n parentEntityIds: string[]\n};\nexport const PluginHeaderActionsContext = React.createContext<HeaderActionsScope | null>(null);\n\n/**\n * The `collection.header.action` contributions for one column. One component\n * type for the life of the view, like {@link PluginAddColumnComponents}: the\n * table's columns are built once, and their headers re-render only when their\n * own props change, so what the actions are handed reaches them through\n * context. It was closed over when the header was built — the table controller\n * of the first render (a search, filter or sort typed since never reached a\n * header action) and the collection of the render before.\n */\nexport function PluginHeaderActions({\n property,\n propertyKey,\n onHover\n}: {\n property: Property,\n propertyKey: string,\n onHover: boolean\n}) {\n const scope = React.useContext(PluginHeaderActionsContext);\n if (!scope) return null;\n const headerSlotProps = {\n property,\n propertyKey,\n onHover,\n path: scope.path,\n collection: scope.collection,\n tableController: scope.tableController,\n parentCollectionSlugs: scope.parentCollectionSlugs,\n parentEntityIds: scope.parentEntityIds\n };\n return <>{scope.contributions.map((s, i) => (\n <ErrorBoundary key={`header_action_${propertyKey}_${i}`}>\n <s.Component {...headerSlotProps} {...(s.props ?? {})}/>\n </ErrorBoundary>\n ))}</>;\n}\n"],"mappings":";;;;AAIA,IAAa,cAAuB,CAAC;;AAGrC,IAAa,0BAA0B,MAAM,cAAiC,WAAW;AAEzF,SAAgB,4BAA4B;CAExC,OACI,oBAAC,OAAD;EAAK,WAAU;YAFA,MAAM,WAAW,uBAG3B;CACA,CAAA;AAEb;AAeA,IAAa,6BAA6B,MAAM,cAAyC,IAAI;;;;;;;;;;AAW7F,SAAgB,oBAAoB,EAChC,UACA,aACA,WAKD;CACC,MAAM,QAAQ,MAAM,WAAW,0BAA0B;CACzD,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,kBAAkB;EACpB;EACA;EACA;EACA,MAAM,MAAM;EACZ,YAAY,MAAM;EAClB,iBAAiB,MAAM;EACvB,uBAAuB,MAAM;EAC7B,iBAAiB,MAAM;CAC3B;CACA,OAAO,oBAAA,UAAA,EAAA,UAAG,MAAM,cAAc,KAAK,GAAG,MAClC,oBAAC,eAAD,EAAA,UACI,oBAAC,EAAE,WAAH;EAAa,GAAI;EAAiB,GAAK,EAAE,SAAS,CAAC;CAAI,CAAA,EAC5C,GAFK,iBAAiB,YAAY,GAAG,GAErC,CAClB,EAAI,CAAA;AACT"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { AdditionalFieldDelegate, AdminCollection } from "@rebasepro/cms-types";
|
|
3
|
-
import type { Entity } from "@rebasepro/types";
|
|
2
|
+
import type { AdditionalFieldDelegate, AdminCollection, Entity } from "@rebasepro/cms-types";
|
|
4
3
|
/**
|
|
5
4
|
* What `CollectionPanel`'s `rowActions` draws on a row: its own JSX, handed
|
|
6
5
|
* the row as the server sends it and the record's id.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/RowActions.tsx"],"sourcesContent":["import React, { useCallback, useContext } from \"react\";\nimport type { AdditionalFieldDelegate, AdditionalFieldDelegateProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport
|
|
1
|
+
{"version":3,"file":"RowActions.js","names":[],"sources":["../../../src/components/CollectionViewBinding/RowActions.tsx"],"sourcesContent":["import React, { useCallback, useContext } from \"react\";\nimport type { AdditionalFieldDelegate, AdditionalFieldDelegateProps, AdminCollection, Entity } from \"@rebasepro/cms-types\";\nimport { ROW_ACTIONS_COLUMN, rowOfEntity } from \"@rebasepro/app\";\n\n/**\n * What `CollectionPanel`'s `rowActions` draws on a row: its own JSX, handed\n * the row as the server sends it and the record's id.\n */\nexport type RowActionsRenderer = (row: Record<string, unknown>, id: string) => React.ReactNode;\n\n/**\n * The renderer of the panel drawn here, and the path its rows live at.\n *\n * Through context rather than props: the cards, the board and the table's\n * cells are memoised, and a caller's `rowActions` closes over its own state\n * (a `saving` flag, the row being shipped), so a new one has to reach them\n * without redrawing every row. The path keeps it to the panel's own rows: a\n * record opened in the split beside the list draws its relation tables inside\n * the same tree.\n */\nexport const RowActionsContext = React.createContext<{ path: string; render: RowActionsRenderer } | null>(null);\n\n/** A row's `rowActions`, or nothing where the panel has none or the row is not its own. */\nexport function useRowActionsNode(entity: Entity<Record<string, unknown>>, collection: AdminCollection | undefined, path: string | undefined): React.ReactNode {\n const scope = useContext(RowActionsContext);\n if (!scope || scope.path !== (path ?? entity.path)) return null;\n return scope.render(rowOfEntity(entity, collection), String(entity.id));\n}\n\n/**\n * A row's `rowActions` where a list row or a card puts them. A click on them\n * is theirs: it does not reach the row, which would open the record.\n */\nexport function RowActionsSlot({ entity, collection, path, className }: {\n entity: Entity<Record<string, unknown>>;\n collection: AdminCollection | undefined;\n path: string | undefined;\n className?: string;\n}) {\n const node = useRowActionsNode(entity, collection, path);\n const stopPropagation = useCallback((event: React.MouseEvent) => event.stopPropagation(), []);\n if (node === null || node === undefined || node === false) return null;\n return <div className={className ?? \"flex items-center gap-1 shrink-0\"} onClick={stopPropagation}>{node}</div>;\n}\n\nfunction RowActionsCell({ row, id }: AdditionalFieldDelegateProps) {\n const scope = useContext(RowActionsContext);\n const stopPropagation = useCallback((event: React.MouseEvent) => event.stopPropagation(), []);\n if (!scope) return null;\n return <div className=\"flex items-center gap-1\" onClick={stopPropagation}>{scope.render(row, String(id))}</div>;\n}\n\n/**\n * The table's column for `rowActions`: the last one, always visible. One\n * object for the life of the module, so the collection it is added to only\n * changes when `rowActions` comes or goes, not each time it is a new function.\n */\nexport const ROW_ACTIONS_FIELD: AdditionalFieldDelegate = {\n key: ROW_ACTIONS_COLUMN,\n name: \"\",\n width: 160,\n Builder: (props) => <RowActionsCell {...props}/>\n};\n"],"mappings":";;;;;;;;;;;;;;AAoBA,IAAa,oBAAoB,MAAM,cAAmE,IAAI;;AAG9G,SAAgB,kBAAkB,QAAyC,YAAyC,MAA2C;CAC3J,MAAM,QAAQ,WAAW,iBAAiB;CAC1C,IAAI,CAAC,SAAS,MAAM,UAAU,QAAQ,OAAO,OAAO,OAAO;CAC3D,OAAO,MAAM,OAAO,YAAY,QAAQ,UAAU,GAAG,OAAO,OAAO,EAAE,CAAC;AAC1E;;;;;AAMA,SAAgB,eAAe,EAAE,QAAQ,YAAY,MAAM,aAKxD;CACC,MAAM,OAAO,kBAAkB,QAAQ,YAAY,IAAI;CACvD,MAAM,kBAAkB,aAAa,UAA4B,MAAM,gBAAgB,GAAG,CAAC,CAAC;CAC5F,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,SAAS,OAAO,OAAO;CAClE,OAAO,oBAAC,OAAD;EAAK,WAAW,aAAa;EAAoC,SAAS;YAAkB;CAAU,CAAA;AACjH;AAEA,SAAS,eAAe,EAAE,KAAK,MAAoC;CAC/D,MAAM,QAAQ,WAAW,iBAAiB;CAC1C,MAAM,kBAAkB,aAAa,UAA4B,MAAM,gBAAgB,GAAG,CAAC,CAAC;CAC5F,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,oBAAC,OAAD;EAAK,WAAU;EAA0B,SAAS;YAAkB,MAAM,OAAO,KAAK,OAAO,EAAE,CAAC;CAAO,CAAA;AAClH;;;;;;AAOA,IAAa,oBAA6C;CACtD,KAAK;CACL,MAAM;CACN,OAAO;CACP,UAAU,UAAU,oBAAC,gBAAD,EAAgB,GAAI,MAAO,CAAA;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/SortButton.tsx"],"sourcesContent":["import type { OrderByTuple, Properties } from \"@rebasepro/types\";\n\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { EntityTableController } from \"@rebasepro/cms-types\";\nimport {\n ArrowDownIcon,\n ArrowUpDownIcon,\n ArrowUpIcon,\n Button,\n ChevronDownIcon,\n ChevronUpIcon,\n cls,\n defaultBorderMixin,\n iconSize,\n IconButton,\n Popover,\n Typography,\n XIcon\n} from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { getSortablePropertyOptions } from \"../CollectionTableBinding/column_utils\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\nexport type SortButtonProps<M extends Record<string, unknown>> = {\n tableController: EntityTableController<M>;\n /**\n * Resolved properties of the collection. The sortable ones among them are\n * the options offered.\n */\n properties: Properties;\n /**\n * Toolbar showing icon-only controls (split view, or a layout too narrow\n * for the filters button's label). Only decides the icon size, which\n * follows that button — see `CollectionViewStartActions`.\n */\n compact?: boolean;\n};\n\n/**\n * Toolbar control that orders the collection.\n *\n * The table orders by clicking a column header, which leaves every other view\n * mode — list, cards, and either of them inside a split view — with no way to\n * order at all, even though the controller has always carried `sortBy` and the\n * query has always honoured it. This binds a control to it.\n *\n * It edits the *whole* order rather than a single key. A sort can have several\n * keys, applied in the order shown: the second decides between rows the first\n * calls equal, the third between rows the first two do. So the active keys sit\n * at the top, numbered and movable, and the properties below them are the ones\n * that can still be added under the last. Shift-clicking a column header does\n * the same thing from the table; this is the view for the modes that have no\n * headers, and the only place the order between keys can be changed.\n *\n * Clicking an active key flips its direction, so ascending → descending is one\n * click rather than a trip through a direction selector; clicking an inactive\n * one appends it ascending. The popover stays open through all of it — building\n * a two-key order out of a control that closes on every click is four round\n * trips through a button.\n */\nexport function SortButton<M extends Record<string, unknown>>({\n tableController,\n properties,\n compact\n}: SortButtonProps<M>) {\n\n const { t } = useTranslation();\n const [open, setOpen] = useState(false);\n\n const options = useMemo(() => getSortablePropertyOptions(properties), [properties]);\n\n const {\n sortBy,\n setSortBy,\n setItemCount,\n pageSize,\n filterValues,\n checkFilterCombination\n } = tableController;\n\n const keys = useMemo(() => (sortBy ?? []) as OrderByTuple[], [sortBy]);\n const activeIndex = useMemo(() => {\n const index = new Map<string, { direction: \"asc\" | \"desc\"; position: number }>();\n keys.forEach(([key, direction], position) => {\n if (!index.has(key)) index.set(key, { direction,\nposition });\n });\n return index;\n }, [keys]);\n\n const applySort = useCallback((next?: OrderByTuple[]) => {\n setSortBy?.((next && next.length > 0 ? next : undefined) as Parameters<NonNullable<typeof setSortBy>>[0]);\n // Re-ordering a partially loaded collection is the same event as\n // clicking a table header: the rows already fetched are no longer the\n // ones the query answers with, so pagination starts over rather than\n // holding on to a page of the previous order (`SelectableTable` resets\n // it for the same reason).\n if (pageSize !== undefined)\n setItemCount?.(pageSize);\n }, [setSortBy, setItemCount, pageSize]);\n\n /** Flip an active key's direction, or append an inactive one ascending. */\n const onOptionClick = useCallback((key: string) => {\n const active = activeIndex.get(key);\n if (!active) {\n applySort([...keys, [key, \"asc\"]]);\n return;\n }\n applySort(keys.map(entry => entry[0] === key\n ? [key, active.direction === \"asc\" ? \"desc\" : \"asc\"] as OrderByTuple\n : entry));\n }, [activeIndex, applySort, keys]);\n\n const removeKey = useCallback((key: string) => {\n applySort(keys.filter(([existing]) => existing !== key));\n }, [applySort, keys]);\n\n /** What a click on an active key will do to it, for the tooltip and the label. */\n const flipLabel = useCallback(\n (direction: \"asc\" | \"desc\") => direction === \"asc\" ? t(\"sort_descending\") : t(\"sort_ascending\"),\n [t]\n );\n\n /** Swap a key with its neighbour, which is what changes which one decides. */\n const moveKey = useCallback((position: number, delta: -1 | 1) => {\n const target = position + delta;\n if (target < 0 || target >= keys.length) return;\n const next = [...keys];\n [next[position], next[target]] = [next[target], next[position]];\n applySort(next);\n }, [applySort, keys]);\n\n if (!setSortBy || options.length === 0) {\n return null;\n }\n\n const primary = keys[0];\n // The key's own name when it has no option to be titled by — a sort can\n // outlive the column it names (a property hidden since, a `collection.sort`\n // on something the panel does not render). Falling back to \"Sort\" there\n // showed the neutral icon and the inactive label over a collection that\n // *was* sorted, which is the one thing this control exists to report.\n const primaryTitle = primary\n ? options.find(option => option.key === primary[0])?.title ?? primary[0]\n : undefined;\n const label = primaryTitle\n ? keys.length > 1\n ? `${t(\"sort_by\")}: ${primaryTitle} +${keys.length - 1}`\n : `${t(\"sort_by\")}: ${primaryTitle}`\n : t(\"sort\");\n\n // Icon only, at every width. The arrow says which way the order runs; which\n // property it runs on is in the popover, and in the tooltip for anyone who\n // wants it without opening one.\n //\n // No `onClick` here and no `Tooltip` wrapper: the popover is controlled in\n // this component, and Radix's trigger — which reaches the button through\n // `asChild` — is what toggles it. A handler of our own would toggle it a\n // second time in the same click and the popover would never open; a\n // `Tooltip` in between would swallow the trigger's ref.\n const arrowSize = compact ? iconSize.smallest : iconSize.small;\n const primaryDirection = primary?.[1];\n\n const trigger = (\n <IconButton\n size={\"small\"}\n aria-label={label}\n title={label}\n className={cls(primaryTitle && \"text-primary\")}\n >\n {/* Same icon size as the filter controls it sits between: 16 in the\n split view's narrow toolbar, 20 everywhere else. It was a flat\n 16, which read as a smaller button next to them. */}\n {primaryDirection === \"desc\"\n ? <ArrowDownIcon size={arrowSize}/>\n : primaryDirection === \"asc\"\n ? <ArrowUpIcon size={arrowSize}/>\n : <ArrowUpDownIcon size={arrowSize}/>}\n </IconButton>\n );\n\n const inactiveOptions = options.filter(option => !activeIndex.has(option.key));\n\n return (\n <Popover\n open={open}\n onOpenChange={setOpen}\n modal={false}\n side=\"bottom\"\n align=\"start\"\n trigger={trigger}\n >\n <div className=\"py-2 min-w-[280px] max-w-[360px] flex flex-col\">\n <Typography\n variant=\"caption\"\n color=\"secondary\"\n className=\"font-medium uppercase tracking-wider px-3 pb-1\"\n >\n {t(\"sort_by\")}\n </Typography>\n\n {keys.length > 0 && (\n // Bounded for the same reason the option list below is: the\n // active keys are as many as the collection has sortable\n // columns, and an unbounded column pushed \"Clear sort\" off\n // the bottom of the screen on a wide collection.\n <div className=\"flex flex-col max-h-[200px] overflow-y-auto\">\n {keys.map(([key, direction], position) => {\n const option = options.find(o => o.key === key);\n return (\n <div\n key={key}\n className=\"flex items-center gap-1 pl-3 pr-2 py-1 text-sm text-primary\"\n >\n {/* The rank, not decoration: it is the only\n thing on screen saying which key wins. */}\n <span className=\"flex-shrink-0 w-4 text-xs tabular-nums text-text-secondary dark:text-text-secondary-dark\">\n {position + 1}\n </span>\n <button\n type=\"button\"\n onClick={() => onOptionClick(key)}\n title={flipLabel(direction)}\n aria-label={`${option?.title ?? key} — ${t(\"sort_key_position\", { position: position + 1 })}. ${flipLabel(direction)}`}\n className=\"flex items-center gap-2 flex-grow min-w-0 text-left cursor-pointer\"\n >\n {option && (\n <span className=\"flex-shrink-0 flex items-center\">\n {getIconForProperty(option.property, \"smallest\")}\n </span>\n )}\n <span className=\"flex-grow truncate\">{option?.title ?? key}</span>\n <span className=\"flex-shrink-0 flex items-center\">\n {direction === \"desc\"\n ? <ArrowDownIcon size={iconSize.smallest}/>\n : <ArrowUpIcon size={iconSize.smallest}/>}\n </span>\n </button>\n {/* Ruled off from the key itself. The row\n carries two arrows that mean different\n things — the direction this key runs, and\n which key outranks which — and side by\n side at 14px they read as one control\n with a stutter. The rule says where the\n key ends and the controls on it begin. */}\n <div className={cls(\n \"flex-shrink-0 flex items-center gap-0.5 ml-1 pl-1 border-l\",\n defaultBorderMixin\n )}>\n {keys.length > 1 && (\n <>\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_move_up\")}\n title={t(\"sort_move_up\")}\n disabled={position === 0}\n onClick={() => moveKey(position, -1)}\n >\n <ChevronUpIcon size={iconSize.smallest}/>\n </IconButton>\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_move_down\")}\n title={t(\"sort_move_down\")}\n disabled={position === keys.length - 1}\n onClick={() => moveKey(position, 1)}\n >\n <ChevronDownIcon size={iconSize.smallest}/>\n </IconButton>\n </>\n )}\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_remove_key\")}\n title={t(\"sort_remove_key\")}\n onClick={() => removeKey(key)}\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n </div>\n </div>\n );\n })}\n </div>\n )}\n\n {/* Only once there is a key to come *after*. With none, the\n \"Sort by\" heading above already names the list, and an empty\n caption here left a band of padding that read as a divider\n between two groups where there was only one. */}\n {keys.length > 0 && inactiveOptions.length > 0 && (\n <Typography\n variant=\"caption\"\n color=\"secondary\"\n className=\"font-medium uppercase tracking-wider px-3 pt-2 pb-1\"\n >\n {t(\"sort_then_by\")}\n </Typography>\n )}\n\n <div className=\"max-h-[280px] overflow-y-auto flex flex-col\">\n {inactiveOptions.map(({ key, title, property }) => {\n // A driver may refuse a sort next to the filter that is\n // already applied. Offering it would turn the click\n // into a failed request, so it is disabled with the\n // same authority the table headers ask.\n const disabled = checkFilterCombination\n ? !checkFilterCombination(filterValues ?? {}, [...keys, [key, \"asc\"]])\n : false;\n return (\n <button\n key={key}\n type=\"button\"\n // Not `menuitemradio`: a sort is a *list* of\n // keys, so picking one does not unpick another,\n // and the role announced the opposite. There is\n // no `role=\"menu\"` around this either, which\n // left the radio orphaned as well as wrong.\n aria-label={keys.length > 0\n ? `${t(\"sort_then_by\")} ${title}`\n : `${t(\"sort_by\")} ${title}`}\n disabled={disabled}\n onClick={() => onOptionClick(key)}\n className={cls(\n \"flex items-center gap-2 px-3 py-1.5 text-sm text-left w-full\",\n disabled\n ? \"opacity-50 cursor-not-allowed\"\n : \"cursor-pointer hover:bg-surface-hover\"\n )}\n >\n <span className=\"flex-shrink-0 flex items-center\">\n {getIconForProperty(property, \"smallest\")}\n </span>\n <span className=\"flex-grow truncate\">{title}</span>\n </button>\n );\n })}\n </div>\n\n <div className=\"px-3 pt-2\">\n <Button\n variant=\"text\"\n size=\"small\"\n className=\"w-full\"\n disabled={keys.length === 0}\n onClick={() => applySort(undefined)}\n >\n {t(\"clear_sort\")}\n </Button>\n </div>\n </div>\n </Popover>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAgB,WAA8C,EAC1D,iBACA,YACA,WACmB;CAEnB,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAEtC,MAAM,UAAU,cAAc,2BAA2B,UAAU,GAAG,CAAC,UAAU,CAAC;CAElF,MAAM,EACF,QACA,WACA,cACA,UACA,cACA,2BACA;CAEJ,MAAM,OAAO,cAAe,UAAU,CAAC,GAAsB,CAAC,MAAM,CAAC;CACrE,MAAM,cAAc,cAAc;EAC9B,MAAM,wBAAQ,IAAI,IAA6D;EAC/E,KAAK,SAAS,CAAC,KAAK,YAAY,aAAa;GACzC,IAAI,CAAC,MAAM,IAAI,GAAG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BAAgB,KAAK,EAAE,KAAK,OAAO,eAAe;MAK/C,MAAM,WAAW,yBACX,CAAC,uBAAuB,gBAAgB,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,IACnE;MACN,OACI,qBAAC,UAAD;OAEI,MAAK;OAML,cAAY,KAAK,SAAS,IACpB,GAAG,EAAE,cAAc,EAAE,GAAG,UACxB,GAAG,EAAE,SAAS,EAAE,GAAG;OACf;OACV,eAAe,cAAc,GAAG;OAChC,WAAW,IACP,gEACA,WACM,kCACA,uCACV;iBAlBJ,CAoBI,oBAAC,QAAD;QAAM,WAAU;kBACX,mBAAmB,UAAU,UAAU;OACtC,CAAA,GACN,oBAAC,QAAD;QAAM,WAAU;kBAAsB;OAAY,CAAA,CAC9C;SAvBC,GAuBD;KAEhB,CAAC;IACA,CAAA;IAEL,oBAAC,OAAD;KAAK,WAAU;eACX,oBAAC,QAAD;MACI,SAAQ;MACR,MAAK;MACL,WAAU;MACV,UAAU,KAAK,WAAW;MAC1B,eAAe,UAAU,KAAA,CAAS;gBAEjC,EAAE,YAAY;KACX,CAAA;IACP,CAAA;GACJ;;CACA,CAAA;AAEjB"}
|
|
1
|
+
{"version":3,"file":"SortButton.js","names":[],"sources":["../../../src/components/CollectionViewBinding/SortButton.tsx"],"sourcesContent":["import type { OrderByTuple } from \"@rebasepro/types\";\nimport type { Properties } from \"@rebasepro/cms-types\";\n\nimport React, { useCallback, useMemo, useState } from \"react\";\nimport { EntityTableController } from \"@rebasepro/cms-types\";\nimport {\n ArrowDownIcon,\n ArrowUpDownIcon,\n ArrowUpIcon,\n Button,\n ChevronDownIcon,\n ChevronUpIcon,\n cls,\n defaultBorderMixin,\n iconSize,\n IconButton,\n Popover,\n Typography,\n XIcon\n} from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { getSortablePropertyOptions } from \"../CollectionTableBinding/column_utils\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\nexport type SortButtonProps<M extends Record<string, unknown>> = {\n tableController: EntityTableController<M>;\n /**\n * Resolved properties of the collection. The sortable ones among them are\n * the options offered.\n */\n properties: Properties;\n /**\n * Toolbar showing icon-only controls (split view, or a layout too narrow\n * for the filters button's label). Only decides the icon size, which\n * follows that button — see `CollectionViewStartActions`.\n */\n compact?: boolean;\n};\n\n/**\n * Toolbar control that orders the collection.\n *\n * The table orders by clicking a column header, which leaves every other view\n * mode — list, cards, and either of them inside a split view — with no way to\n * order at all, even though the controller has always carried `sortBy` and the\n * query has always honoured it. This binds a control to it.\n *\n * It edits the *whole* order rather than a single key. A sort can have several\n * keys, applied in the order shown: the second decides between rows the first\n * calls equal, the third between rows the first two do. So the active keys sit\n * at the top, numbered and movable, and the properties below them are the ones\n * that can still be added under the last. Shift-clicking a column header does\n * the same thing from the table; this is the view for the modes that have no\n * headers, and the only place the order between keys can be changed.\n *\n * Clicking an active key flips its direction, so ascending → descending is one\n * click rather than a trip through a direction selector; clicking an inactive\n * one appends it ascending. The popover stays open through all of it — building\n * a two-key order out of a control that closes on every click is four round\n * trips through a button.\n */\nexport function SortButton<M extends Record<string, unknown>>({\n tableController,\n properties,\n compact\n}: SortButtonProps<M>) {\n\n const { t } = useTranslation();\n const [open, setOpen] = useState(false);\n\n const options = useMemo(() => getSortablePropertyOptions(properties), [properties]);\n\n const {\n sortBy,\n setSortBy,\n setItemCount,\n pageSize,\n filterValues,\n checkFilterCombination\n } = tableController;\n\n const keys = useMemo(() => (sortBy ?? []) as OrderByTuple[], [sortBy]);\n const activeIndex = useMemo(() => {\n const index = new Map<string, { direction: \"asc\" | \"desc\"; position: number }>();\n keys.forEach(([key, direction], position) => {\n if (!index.has(key)) index.set(key, { direction,\nposition });\n });\n return index;\n }, [keys]);\n\n const applySort = useCallback((next?: OrderByTuple[]) => {\n setSortBy?.((next && next.length > 0 ? next : undefined) as Parameters<NonNullable<typeof setSortBy>>[0]);\n // Re-ordering a partially loaded collection is the same event as\n // clicking a table header: the rows already fetched are no longer the\n // ones the query answers with, so pagination starts over rather than\n // holding on to a page of the previous order (`SelectableTable` resets\n // it for the same reason).\n if (pageSize !== undefined)\n setItemCount?.(pageSize);\n }, [setSortBy, setItemCount, pageSize]);\n\n /** Flip an active key's direction, or append an inactive one ascending. */\n const onOptionClick = useCallback((key: string) => {\n const active = activeIndex.get(key);\n if (!active) {\n applySort([...keys, [key, \"asc\"]]);\n return;\n }\n applySort(keys.map(entry => entry[0] === key\n ? [key, active.direction === \"asc\" ? \"desc\" : \"asc\"] as OrderByTuple\n : entry));\n }, [activeIndex, applySort, keys]);\n\n const removeKey = useCallback((key: string) => {\n applySort(keys.filter(([existing]) => existing !== key));\n }, [applySort, keys]);\n\n /** What a click on an active key will do to it, for the tooltip and the label. */\n const flipLabel = useCallback(\n (direction: \"asc\" | \"desc\") => direction === \"asc\" ? t(\"sort_descending\") : t(\"sort_ascending\"),\n [t]\n );\n\n /** Swap a key with its neighbour, which is what changes which one decides. */\n const moveKey = useCallback((position: number, delta: -1 | 1) => {\n const target = position + delta;\n if (target < 0 || target >= keys.length) return;\n const next = [...keys];\n [next[position], next[target]] = [next[target], next[position]];\n applySort(next);\n }, [applySort, keys]);\n\n if (!setSortBy || options.length === 0) {\n return null;\n }\n\n const primary = keys[0];\n // The key's own name when it has no option to be titled by — a sort can\n // outlive the column it names (a property hidden since, a `collection.sort`\n // on something the panel does not render). Falling back to \"Sort\" there\n // showed the neutral icon and the inactive label over a collection that\n // *was* sorted, which is the one thing this control exists to report.\n const primaryTitle = primary\n ? options.find(option => option.key === primary[0])?.title ?? primary[0]\n : undefined;\n const label = primaryTitle\n ? keys.length > 1\n ? `${t(\"sort_by\")}: ${primaryTitle} +${keys.length - 1}`\n : `${t(\"sort_by\")}: ${primaryTitle}`\n : t(\"sort\");\n\n // Icon only, at every width. The arrow says which way the order runs; which\n // property it runs on is in the popover, and in the tooltip for anyone who\n // wants it without opening one.\n //\n // No `onClick` here and no `Tooltip` wrapper: the popover is controlled in\n // this component, and Radix's trigger — which reaches the button through\n // `asChild` — is what toggles it. A handler of our own would toggle it a\n // second time in the same click and the popover would never open; a\n // `Tooltip` in between would swallow the trigger's ref.\n const arrowSize = compact ? iconSize.smallest : iconSize.small;\n const primaryDirection = primary?.[1];\n\n const trigger = (\n <IconButton\n size={\"small\"}\n aria-label={label}\n title={label}\n className={cls(primaryTitle && \"text-primary\")}\n >\n {/* Same icon size as the filter controls it sits between: 16 in the\n split view's narrow toolbar, 20 everywhere else. It was a flat\n 16, which read as a smaller button next to them. */}\n {primaryDirection === \"desc\"\n ? <ArrowDownIcon size={arrowSize}/>\n : primaryDirection === \"asc\"\n ? <ArrowUpIcon size={arrowSize}/>\n : <ArrowUpDownIcon size={arrowSize}/>}\n </IconButton>\n );\n\n const inactiveOptions = options.filter(option => !activeIndex.has(option.key));\n\n return (\n <Popover\n open={open}\n onOpenChange={setOpen}\n modal={false}\n side=\"bottom\"\n align=\"start\"\n trigger={trigger}\n >\n <div className=\"py-2 min-w-[280px] max-w-[360px] flex flex-col\">\n <Typography\n variant=\"caption\"\n color=\"secondary\"\n className=\"font-medium uppercase tracking-wider px-3 pb-1\"\n >\n {t(\"sort_by\")}\n </Typography>\n\n {keys.length > 0 && (\n // Bounded for the same reason the option list below is: the\n // active keys are as many as the collection has sortable\n // columns, and an unbounded column pushed \"Clear sort\" off\n // the bottom of the screen on a wide collection.\n <div className=\"flex flex-col max-h-[200px] overflow-y-auto\">\n {keys.map(([key, direction], position) => {\n const option = options.find(o => o.key === key);\n return (\n <div\n key={key}\n className=\"flex items-center gap-1 pl-3 pr-2 py-1 text-sm text-primary\"\n >\n {/* The rank, not decoration: it is the only\n thing on screen saying which key wins. */}\n <span className=\"flex-shrink-0 w-4 text-xs tabular-nums text-text-secondary dark:text-text-secondary-dark\">\n {position + 1}\n </span>\n <button\n type=\"button\"\n onClick={() => onOptionClick(key)}\n title={flipLabel(direction)}\n aria-label={`${option?.title ?? key} — ${t(\"sort_key_position\", { position: position + 1 })}. ${flipLabel(direction)}`}\n className=\"flex items-center gap-2 flex-grow min-w-0 text-left cursor-pointer\"\n >\n {option && (\n <span className=\"flex-shrink-0 flex items-center\">\n {getIconForProperty(option.property, \"smallest\")}\n </span>\n )}\n <span className=\"flex-grow truncate\">{option?.title ?? key}</span>\n <span className=\"flex-shrink-0 flex items-center\">\n {direction === \"desc\"\n ? <ArrowDownIcon size={iconSize.smallest}/>\n : <ArrowUpIcon size={iconSize.smallest}/>}\n </span>\n </button>\n {/* Ruled off from the key itself. The row\n carries two arrows that mean different\n things — the direction this key runs, and\n which key outranks which — and side by\n side at 14px they read as one control\n with a stutter. The rule says where the\n key ends and the controls on it begin. */}\n <div className={cls(\n \"flex-shrink-0 flex items-center gap-0.5 ml-1 pl-1 border-l\",\n defaultBorderMixin\n )}>\n {keys.length > 1 && (\n <>\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_move_up\")}\n title={t(\"sort_move_up\")}\n disabled={position === 0}\n onClick={() => moveKey(position, -1)}\n >\n <ChevronUpIcon size={iconSize.smallest}/>\n </IconButton>\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_move_down\")}\n title={t(\"sort_move_down\")}\n disabled={position === keys.length - 1}\n onClick={() => moveKey(position, 1)}\n >\n <ChevronDownIcon size={iconSize.smallest}/>\n </IconButton>\n </>\n )}\n <IconButton\n size=\"smallest\"\n aria-label={t(\"sort_remove_key\")}\n title={t(\"sort_remove_key\")}\n onClick={() => removeKey(key)}\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n </div>\n </div>\n );\n })}\n </div>\n )}\n\n {/* Only once there is a key to come *after*. With none, the\n \"Sort by\" heading above already names the list, and an empty\n caption here left a band of padding that read as a divider\n between two groups where there was only one. */}\n {keys.length > 0 && inactiveOptions.length > 0 && (\n <Typography\n variant=\"caption\"\n color=\"secondary\"\n className=\"font-medium uppercase tracking-wider px-3 pt-2 pb-1\"\n >\n {t(\"sort_then_by\")}\n </Typography>\n )}\n\n <div className=\"max-h-[280px] overflow-y-auto flex flex-col\">\n {inactiveOptions.map(({ key, title, property }) => {\n // A driver may refuse a sort next to the filter that is\n // already applied. Offering it would turn the click\n // into a failed request, so it is disabled with the\n // same authority the table headers ask.\n const disabled = checkFilterCombination\n ? !checkFilterCombination(filterValues ?? {}, [...keys, [key, \"asc\"]])\n : false;\n return (\n <button\n key={key}\n type=\"button\"\n // Not `menuitemradio`: a sort is a *list* of\n // keys, so picking one does not unpick another,\n // and the role announced the opposite. There is\n // no `role=\"menu\"` around this either, which\n // left the radio orphaned as well as wrong.\n aria-label={keys.length > 0\n ? `${t(\"sort_then_by\")} ${title}`\n : `${t(\"sort_by\")} ${title}`}\n disabled={disabled}\n onClick={() => onOptionClick(key)}\n className={cls(\n \"flex items-center gap-2 px-3 py-1.5 text-sm text-left w-full\",\n disabled\n ? \"opacity-50 cursor-not-allowed\"\n : \"cursor-pointer hover:bg-surface-hover\"\n )}\n >\n <span className=\"flex-shrink-0 flex items-center\">\n {getIconForProperty(property, \"smallest\")}\n </span>\n <span className=\"flex-grow truncate\">{title}</span>\n </button>\n );\n })}\n </div>\n\n <div className=\"px-3 pt-2\">\n <Button\n variant=\"text\"\n size=\"small\"\n className=\"w-full\"\n disabled={keys.length === 0}\n onClick={() => applySort(undefined)}\n >\n {t(\"clear_sort\")}\n </Button>\n </div>\n </div>\n </Popover>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,WAA8C,EAC1D,iBACA,YACA,WACmB;CAEnB,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAEtC,MAAM,UAAU,cAAc,2BAA2B,UAAU,GAAG,CAAC,UAAU,CAAC;CAElF,MAAM,EACF,QACA,WACA,cACA,UACA,cACA,2BACA;CAEJ,MAAM,OAAO,cAAe,UAAU,CAAC,GAAsB,CAAC,MAAM,CAAC;CACrE,MAAM,cAAc,cAAc;EAC9B,MAAM,wBAAQ,IAAI,IAA6D;EAC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N,WAAU;eAET,EAAE,cAAc;IACT,CAAA;IAGhB,oBAAC,OAAD;KAAK,WAAU;eACV,gBAAgB,KAAK,EAAE,KAAK,OAAO,eAAe;MAK/C,MAAM,WAAW,yBACX,CAAC,uBAAuB,gBAAgB,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,IACnE;MACN,OACI,qBAAC,UAAD;OAEI,MAAK;OAML,cAAY,KAAK,SAAS,IACpB,GAAG,EAAE,cAAc,EAAE,GAAG,UACxB,GAAG,EAAE,SAAS,EAAE,GAAG;OACf;OACV,eAAe,cAAc,GAAG;OAChC,WAAW,IACP,gEACA,WACM,kCACA,uCACV;iBAlBJ,CAoBI,oBAAC,QAAD;QAAM,WAAU;kBACX,mBAAmB,UAAU,UAAU;OACtC,CAAA,GACN,oBAAC,QAAD;QAAM,WAAU;kBAAsB;OAAY,CAAA,CAC9C;SAvBC,GAuBD;KAEhB,CAAC;IACA,CAAA;IAEL,oBAAC,OAAD;KAAK,WAAU;eACX,oBAAC,QAAD;MACI,SAAQ;MACR,MAAK;MACL,WAAU;MACV,UAAU,KAAK,WAAW;MAC1B,eAAe,UAAU,KAAA,CAAS;gBAEjC,EAAE,YAAY;KACX,CAAA;IACP,CAAA;GACJ;;CACA,CAAA;AAEjB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Entity } from "@rebasepro/types";
|
|
3
|
-
import { CollectionSize, EntityTableController, EntitySelectionController, AdminCollection } from "@rebasepro/cms-types";
|
|
2
|
+
import { CollectionSize, EntityTableController, EntitySelectionController, AdminCollection, Entity } from "@rebasepro/cms-types";
|
|
4
3
|
export type SplitListViewProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
5
4
|
collection: AdminCollection<M>;
|
|
6
5
|
tableController: EntityTableController<M>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitListView.js","names":[],"sources":["../../../src/components/CollectionViewBinding/SplitListView.tsx"],"sourcesContent":["\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { Entity } from \"@rebasepro/types\";\nimport { CollectionSize, EntityTableController, EntitySelectionController, AdminCollection } from \"@rebasepro/cms-types\";\nimport { EditViewBinding } from \"../EditViewBinding\";\nimport { DetailViewBinding } from \"../DetailViewBinding\";\nimport {\n cls,\n isKeyHandled,\n SplitView\n} from \"@rebasepro/ui\";\nimport { UnsavedChangesDialog, useNavigationBlocker } from \"@rebasepro/app\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useNavigate, useLocation } from \"react-router\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { withListState } from \"../../util/view_mode\";\nimport { SplitViewProvider } from \"./SplitViewContext\";\n\nexport type SplitListViewProps<M extends Record<string, unknown> = Record<string, unknown>> = {\n collection: AdminCollection<M>;\n tableController: EntityTableController<M>;\n onEntityClick?: (entity: Entity<M>) => void;\n onNewClick?: () => void;\n selectionController?: EntitySelectionController<M>;\n selectionEnabled?: boolean;\n highlightedEntities?: Entity<M>[];\n emptyComponent?: React.ReactNode;\n onScroll?: (props: {\n scrollDirection: \"forward\" | \"backward\";\n scrollOffset: number;\n scrollUpdateWasRequested: boolean;\n }) => void;\n initialScroll?: number;\n size?: CollectionSize;\n path: string;\n parentCollectionSlugs?: string[], parentEntityIds?: string[];\n /**\n * The entity ID to show in the detail panel.\n * Comes from the URL path (e.g. /c/authors/14 → selectedEntityId = \"14\").\n * When undefined, no detail panel is shown.\n */\n selectedEntityId?: string | number;\n /**\n * When provided, the detail panel will open this tab (e.g. a subcollection slug).\n * Used by the router to pass the subcollection tab from the URL.\n */\n selectedTab?: string;\n /**\n * Toolbar to render above the content in the left panel.\n */\n toolbar?: React.ReactNode;\n /**\n * The collection view to render on the left side.\n */\n children: React.ReactNode;\n};\n\nconst PANEL_SIZE_KEY = \"rebase_split_list_panel_size\";\n\n/**\n * Whether the element accepts text, and therefore owns the keystroke.\n * Covers native fields plus the ARIA roles custom editors expose.\n */\nfunction isTextEntryTarget(target: HTMLElement | null): boolean {\n if (!target) return false;\n const tag = target.tagName;\n if (tag === \"INPUT\" || tag === \"TEXTAREA\" || tag === \"SELECT\") return true;\n if (target.isContentEditable) return true;\n return Boolean(target.closest('[contenteditable=\"true\"], [role=\"textbox\"], [role=\"combobox\"], [role=\"searchbox\"]'));\n}\n\n/**\n * Whether a bare letter shortcut may act on this target. Only the list side of\n * the split owns them — inside the detail panel a keystroke belongs to the form.\n */\nfunction isListShortcutTarget(target: HTMLElement | null, detailPanel: HTMLElement | null): boolean {\n if (!target || target === document.body) return true;\n // Focus inside a layer opened above the page — a dialog, a menu, a select\n // list — means the keystroke is that layer's. A modal traps focus, so this\n // is also what keeps a bare `j` from moving the list behind an open dialog.\n if (target.closest('[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]')) return false;\n return !detailPanel?.contains(target);\n}\n\n/**\n * The list's share of the split, as a percentage, before anyone drags it.\n *\n * The list only has to identify a record — a title, a subtitle and a status\n * chip — while the detail beside it carries the whole record and its rail. At\n * 30% the list was taking width from the side that had four columns of fields\n * to lay out; 26% still was, by about the width of one field.\n *\n * A default, not a constraint: {@link savePanelSize} remembers the drag per\n * collection, so anyone who has already sized this list keeps their size. The\n * drag floor is `minPanelSizePx`, and it holds below ~1100px of split — at that\n * width this percentage is already the floor.\n */\nconst DEFAULT_PANEL_SIZE = 22;\n\nfunction getSavedPanelSize(path: string): number {\n try {\n const saved = localStorage.getItem(`${PANEL_SIZE_KEY}_${path}`);\n if (saved !== null) {\n const val = parseFloat(saved);\n if (!isNaN(val) && val > 0 && val < 100) return val;\n }\n } catch { /* ignore */ }\n return DEFAULT_PANEL_SIZE;\n}\n\nfunction savePanelSize(path: string, size: number) {\n try {\n localStorage.setItem(`${PANEL_SIZE_KEY}_${path}`, size.toString());\n } catch { /* ignore */ }\n}\n\n/** The list's floor while it sits beside the record: a title, a subtitle and a status chip still read. */\nconst MIN_LIST_WIDTH = 240;\n\n/**\n * Master-detail split view: the kit's {@link SplitView}, with the list as its\n * master and the record as its detail, wired to the router.\n *\n * The split follows its own width: side by side when the collection view is\n * wide, the record covering the list when it is narrow.\n *\n * Animation approach:\n * - The list always renders at full width.\n * - When a detail opens, the list shrinks to `panelSize%` and the detail slides in.\n * - On close, the reverse plays.\n *\n * State management:\n * - The selected entity is driven by the URL path (e.g. /c/authors/14).\n * `selectedEntityId` comes from props via RebaseRoute, NOT from internal state.\n * - Clicking a entity navigates to /c/authors/{id} via the standard onEntityClick handler.\n * - Closing the detail navigates back to /c/authors.\n */\nexport function SplitListView<M extends Record<string, unknown> = Record<string, unknown>>({\n collection,\n tableController,\n onEntityClick: externalOnEntityClick,\n onNewClick: externalOnNewClick,\n selectionController,\n selectionEnabled = true,\n highlightedEntities,\n emptyComponent,\n onScroll,\n initialScroll,\n size = \"m\",\n path,\n parentCollectionSlugs, parentEntityIds,\n selectedEntityId,\n selectedTab,\n toolbar,\n children\n}: SplitListViewProps<M>) {\n const collectionRegistryController = useCollectionRegistryController();\n const location = useLocation();\n const isEditMode = location.pathname.endsWith(\"/edit\") || location.pathname.split(\"/\").pop() === \"edit\";\n const navigate = useNavigate();\n const urlController = useUrlController();\n\n const showDetail = selectedEntityId !== undefined;\n\n // ── Unsaved changes ──\n // The detail form lives inside the split layout, so every way out of it\n // (Escape, j/k, clicking another row, the browser back button) is a plain\n // router navigation. A ref — not state — because the blocker predicate must\n // observe the change synchronously, before the navigation it is guarding.\n const dirty = useRef(false);\n const detailPanelRef = useRef<HTMLDivElement>(null);\n const setDirty = useCallback((modified: boolean) => {\n dirty.current = modified;\n }, []);\n\n // The form remounts per entity, so its dirty state must not leak into the\n // next one — and it has to be cleared here rather than left to the next\n // form's own first report, because that form spends the load in a skeleton\n // and a navigation during it would prompt about the record before it.\n //\n // On a *change* of record only, never on this view's own mount: a record\n // arriving from full screen carries its edit back in and opens dirty, and\n // the form says so from its first effect — which runs before this one, being\n // a child's. Clearing unconditionally overwrote that report with `false`,\n // and the way out of the split stopped asking about a live edit.\n const previousEntityId = useRef(selectedEntityId);\n useEffect(() => {\n if (previousEntityId.current === selectedEntityId) return;\n previousEntityId.current = selectedEntityId;\n dirty.current = false;\n }, [selectedEntityId]);\n\n const blocker = useNavigationBlocker(useCallback(({\n currentLocation,\n nextLocation\n }) => {\n if (!dirty.current) return false;\n if (currentLocation.pathname === nextLocation.pathname) return false;\n // Side panel overlays (e.g. following a relation) render above the form\n // and leave it mounted — nothing is lost in either direction.\n const nextHash = nextLocation.hash;\n if (nextHash === \"#side\" || nextHash === \"#new_side\") return false;\n const currentHash = currentLocation.hash;\n if (currentHash === \"#side\" || currentHash === \"#new_side\") return false;\n return true;\n }, []));\n\n // Panel size state with persistence.\n //\n // Written on drag, not on mount. An effect that saved on mount stored\n // {@link DEFAULT_PANEL_SIZE} under this collection's key the first time\n // anyone opened the split — after which the default was frozen in every\n // browser that had ever seen it, and changing it here reached nobody but a\n // new visitor. Only a size someone chose is a size worth remembering.\n const [panelSize] = useState(() => getSavedPanelSize(path));\n\n const handlePanelSizeChange = useCallback((size: number) => {\n savePanelSize(path, size);\n }, [path]);\n\n // ── Animation state ──\n // We track the \"rendered\" entity to keep the detail panel mounted during the exit animation.\n const [renderedEntityId, setRenderedEntityId] = useState<string | number | undefined>(selectedEntityId);\n const [animationPhase, setAnimationPhase] = useState<\"idle\" | \"entering\" | \"entered\" | \"exiting\">(\n selectedEntityId !== undefined ? \"entered\" : \"idle\"\n );\n const animationTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Transition duration (ms) — keep in sync with CSS\n const TRANSITION_DURATION = 150;\n\n useEffect(() => {\n if (animationTimer.current) {\n clearTimeout(animationTimer.current);\n animationTimer.current = null;\n }\n\n if (selectedEntityId !== undefined) {\n // Opening or switching entity\n setRenderedEntityId(selectedEntityId);\n if (animationPhase === \"idle\" || animationPhase === \"exiting\") {\n // Fresh open — trigger enter\n setAnimationPhase(\"entering\");\n // Use requestAnimationFrame to ensure the \"entering\" class is painted\n // before transitioning to \"entered\".\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n setAnimationPhase(\"entered\");\n });\n });\n }\n // If already entered (switching entities), keep \"entered\"\n } else {\n // Closing\n if (animationPhase === \"entered\" || animationPhase === \"entering\") {\n setAnimationPhase(\"exiting\");\n animationTimer.current = setTimeout(() => {\n setAnimationPhase(\"idle\");\n setRenderedEntityId(undefined);\n }, TRANSITION_DURATION);\n }\n }\n\n return () => {\n if (animationTimer.current) clearTimeout(animationTimer.current);\n };\n }, [selectedEntityId]); // Intentionally only depend on selectedEntityId\n\n // Build a URL below this collection, carrying the list's whole URL state —\n // view mode, search, filters and sort — the way the record was opened.\n // The list reads that state back from the URL on every navigation, so a\n // URL carrying only the view mode reset the search box and the filters\n // each time the record was closed or one of its tabs changed.\n const buildUrl = useCallback((subPath: string) => {\n return withListState(urlController.buildUrlCollectionPath(subPath));\n }, [urlController]);\n\n // Close the detail panel: navigate back to the collection path\n const handleCloseDetail = useCallback(() => {\n navigate(buildUrl(path));\n }, [navigate, buildUrl, path]);\n\n // ── Keyboard navigation ──\n const entityIds = useMemo(\n () => tableController.data.map((e: Entity<M>) => e.id),\n [tableController.data]\n );\n\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n const target = e.target as HTMLElement | null;\n\n // A layer above the record — a dialog, a menu, a select list, the\n // inspector — claims the key it acts on with preventDefault(). Asking\n // the DOM for an open `role=\"dialog\"` instead missed every layer that\n // is not a dialog, so Escape on an open dropdown closed the record too.\n if (isKeyHandled(e)) return;\n\n if (e.key === \"Escape\") {\n if (!selectedEntityId) return;\n // First Escape leaves the field (which may also be dismissing its\n // own dropdown), a second one closes the panel. Closing straight\n // from a focused field would discard an in-progress edit.\n if (isTextEntryTarget(target)) {\n target?.blur();\n e.preventDefault();\n return;\n }\n handleCloseDetail();\n e.preventDefault();\n return;\n }\n\n // Record navigation only belongs to the list side. Inside the detail\n // panel these keys are the form's — arrows move between fields, and a\n // bare letter is input for widgets that aren't native fields (rich\n // text, code editors, comboboxes).\n if (!isListShortcutTarget(target, detailPanelRef.current)) return;\n if (isTextEntryTarget(target)) return;\n\n // Arrow down / j → next entity\n if ((e.key === \"ArrowDown\" || e.key === \"j\") && !e.metaKey && !e.ctrlKey) {\n e.preventDefault();\n if (entityIds.length === 0) return;\n\n if (selectedEntityId === undefined) {\n const firstEntity = tableController.data[0];\n if (firstEntity) externalOnEntityClick?.(firstEntity);\n } else {\n const currentIndex = entityIds.indexOf(selectedEntityId);\n if (currentIndex >= 0 && currentIndex < entityIds.length - 1) {\n const nextEntity = tableController.data[currentIndex + 1];\n if (nextEntity) externalOnEntityClick?.(nextEntity);\n }\n }\n return;\n }\n\n // Arrow up / k → previous entity\n if ((e.key === \"ArrowUp\" || e.key === \"k\") && !e.metaKey && !e.ctrlKey) {\n e.preventDefault();\n if (entityIds.length === 0) return;\n\n if (selectedEntityId === undefined) {\n const lastEntity = tableController.data[tableController.data.length - 1];\n if (lastEntity) externalOnEntityClick?.(lastEntity);\n } else {\n const currentIndex = entityIds.indexOf(selectedEntityId);\n if (currentIndex > 0) {\n const prevEntity = tableController.data[currentIndex - 1];\n if (prevEntity) externalOnEntityClick?.(prevEntity);\n }\n }\n return;\n }\n\n // n → new entity\n if (e.key === \"n\" && !e.metaKey && !e.ctrlKey && !e.altKey) {\n externalOnNewClick?.();\n e.preventDefault();\n return;\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => window.removeEventListener(\"keydown\", handleKeyDown);\n }, [selectedEntityId, handleCloseDetail, externalOnEntityClick, externalOnNewClick, entityIds, tableController.data]);\n\n const usedParentCollectionIds = parentCollectionSlugs ?? collectionRegistryController.getParentCollectionSlugs(path);\n const usedParentEntityIds = parentEntityIds ?? collectionRegistryController.getParentEntityIds(path);\n\n const isDetailVisible = animationPhase !== \"idle\";\n\n // ── Layout: the kit's SplitView ──\n // What changes with the arrangement is styled off the split's own\n // `data-layout` (`group-data-[layout=stacked]/split:`), so the classes\n // and the split always agree on which one it is.\n\n const listPanel = (\n <div className=\"flex flex-col h-full min-w-0 w-full\">\n {/* Toolbar stays fixed above the scrollable area */}\n {toolbar}\n {/* Scrollable content: title + insights + list rows */}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden min-h-0\">\n {children}\n </div>\n </div>\n );\n\n const detailPanel = renderedEntityId !== undefined ? (\n <div\n ref={detailPanelRef}\n className={cls(\n \"flex-1 flex flex-col min-w-0 h-full transition-all ease-out w-full\",\n // The record is an object opened beside the list, so it carries\n // its own left edge — the way a card carries its hairline. The\n // resize handle between the panes is transparent; this line is\n // the record's, not a divider hanging in the gap. Side-by-side\n // only: stacked, the record has no left neighbour.\n \"border-l border-hairline group-data-[layout=stacked]/split:border-l-0\",\n animationPhase === \"entered\"\n ? \"opacity-100 translate-x-0\"\n : \"opacity-0 translate-x-8 group-data-[layout=stacked]/split:translate-x-1/3\"\n )}\n style={{ transitionDuration: `${TRANSITION_DURATION}ms` }}\n >\n <ErrorBoundary>\n {collection.defaultEntityAction === \"view\" && !isEditMode\n ? <DetailViewBinding\n key={String(renderedEntityId)}\n path={path}\n collection={collection as AdminCollection<Record<string, unknown>>}\n entityId={renderedEntityId}\n parentCollectionSlugs={usedParentCollectionIds}\n parentEntityIds={usedParentEntityIds}\n selectedTab={selectedTab}\n layout=\"split\"\n onCloseRequest={handleCloseDetail}\n onEditClick={() => {\n navigate(buildUrl(`${path}/${renderedEntityId}/edit`));\n }}\n onTabChange={(params) => {\n const newSelectedTab = params.selectedTab;\n navigate(buildUrl(\n newSelectedTab\n ? `${path}/${renderedEntityId}/${newSelectedTab}`\n : `${path}/${renderedEntityId}`\n ));\n }}\n />\n : <EditViewBinding\n key={String(renderedEntityId)}\n path={path}\n collection={collection as AdminCollection<Record<string, unknown>>}\n entityId={renderedEntityId}\n parentCollectionSlugs={usedParentCollectionIds}\n parentEntityIds={usedParentEntityIds}\n selectedTab={selectedTab}\n layout=\"split\"\n // The ✕, and where \"save and close\" lands. A plain\n // navigation: `useNavigationBlocker` above already\n // stands between it and an unsaved edit, so the ✕ asks\n // exactly what Escape and the browser's Back ask.\n onCloseRequest={handleCloseDetail}\n onValuesModified={setDirty}\n onSaved={() => {\n setDirty(false);\n navigate(buildUrl(`${path}/${renderedEntityId}`), { replace: true });\n }}\n navigateBack={() => {\n navigate(buildUrl(`${path}/${renderedEntityId}`));\n }}\n onTabChange={(params) => {\n const newSelectedTab = params.selectedTab;\n navigate(buildUrl(\n newSelectedTab\n ? `${path}/${renderedEntityId}/${newSelectedTab}`\n : `${path}/${renderedEntityId}`\n ));\n }}\n />\n }\n </ErrorBoundary>\n </div>\n ) : null;\n\n // Closing the list is the full-screen entity route: the same `#full` the\n // entity pane's expand button used, so there is one way to give the record\n // the whole window and one way back out of it.\n const openFullScreen = useCallback(() => {\n if (selectedEntityId === undefined) return;\n const suffix = isEditMode ? \"/edit\" : \"\";\n navigate(`${buildUrl(`${path}/${selectedEntityId}${suffix}`)}#full`);\n }, [navigate, buildUrl, path, selectedEntityId, isEditMode]);\n\n const splitViewController = useMemo(() => ({\n detailOpen: selectedEntityId !== undefined,\n openFullScreen\n }), [selectedEntityId, openFullScreen]);\n\n return (\n <SplitViewProvider value={splitViewController}>\n <SplitView\n className=\"group/split\"\n master={listPanel}\n detail={isDetailVisible ? detailPanel : null}\n defaultMasterPercent={panelSize}\n onMasterPercentChange={handlePanelSizeChange}\n minPaneWidth={MIN_LIST_WIDTH}\n />\n\n <UnsavedChangesDialog\n open={blocker?.state === \"blocked\"}\n handleOk={() => {\n dirty.current = false;\n blocker?.proceed?.();\n }}\n handleCancel={() => blocker?.reset?.()}\n body={<>You have unsaved changes in this <b>{collection.singularName ?? collection.name}</b>.</>}/>\n </SplitViewProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA0DA,IAAM,iBAAiB;;;;;AAMvB,SAAS,kBAAkB,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ACI,oBAAC,WAAD;GACI,WAAU;GACV,QAAQ;GACR,QAAQ,kBAAkB,cAAc;GACxC,sBAAsB;GACtB,uBAAuB;GACvB,cAAc;EACjB,CAAA,GAED,oBAAC,sBAAD;GACI,MAAM,SAAS,UAAU;GACzB,gBAAgB;IACZ,MAAM,UAAU;IAChB,SAAS,UAAU;GACvB;GACA,oBAAoB,SAAS,QAAQ;GACrC,MAAM,qBAAA,UAAA,EAAA,UAAA;IAAE;IAAiC,oBAAC,KAAD,EAAA,UAAI,WAAW,gBAAgB,WAAW,KAAQ,CAAA;IAAC;GAAG,EAAA,CAAA;EAAG,CAAA,CACvF;;AAE3B"}
|
|
1
|
+
{"version":3,"file":"SplitListView.js","names":[],"sources":["../../../src/components/CollectionViewBinding/SplitListView.tsx"],"sourcesContent":["\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { CollectionSize, EntityTableController, EntitySelectionController, AdminCollection, Entity } from \"@rebasepro/cms-types\";\nimport { EditViewBinding } from \"../EditViewBinding\";\nimport { DetailViewBinding } from \"../DetailViewBinding\";\nimport {\n cls,\n isKeyHandled,\n SplitView\n} from \"@rebasepro/ui\";\nimport { UnsavedChangesDialog, useNavigationBlocker } from \"@rebasepro/app\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useNavigate, useLocation } from \"react-router\";\nimport { useUrlController } from \"../../hooks/navigation/contexts/UrlContext\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { withListState } from \"../../util/view_mode\";\nimport { SplitViewProvider } from \"./SplitViewContext\";\n\nexport type SplitListViewProps<M extends Record<string, unknown> = Record<string, unknown>> = {\n collection: AdminCollection<M>;\n tableController: EntityTableController<M>;\n onEntityClick?: (entity: Entity<M>) => void;\n onNewClick?: () => void;\n selectionController?: EntitySelectionController<M>;\n selectionEnabled?: boolean;\n highlightedEntities?: Entity<M>[];\n emptyComponent?: React.ReactNode;\n onScroll?: (props: {\n scrollDirection: \"forward\" | \"backward\";\n scrollOffset: number;\n scrollUpdateWasRequested: boolean;\n }) => void;\n initialScroll?: number;\n size?: CollectionSize;\n path: string;\n parentCollectionSlugs?: string[], parentEntityIds?: string[];\n /**\n * The entity ID to show in the detail panel.\n * Comes from the URL path (e.g. /c/authors/14 → selectedEntityId = \"14\").\n * When undefined, no detail panel is shown.\n */\n selectedEntityId?: string | number;\n /**\n * When provided, the detail panel will open this tab (e.g. a subcollection slug).\n * Used by the router to pass the subcollection tab from the URL.\n */\n selectedTab?: string;\n /**\n * Toolbar to render above the content in the left panel.\n */\n toolbar?: React.ReactNode;\n /**\n * The collection view to render on the left side.\n */\n children: React.ReactNode;\n};\n\nconst PANEL_SIZE_KEY = \"rebase_split_list_panel_size\";\n\n/**\n * Whether the element accepts text, and therefore owns the keystroke.\n * Covers native fields plus the ARIA roles custom editors expose.\n */\nfunction isTextEntryTarget(target: HTMLElement | null): boolean {\n if (!target) return false;\n const tag = target.tagName;\n if (tag === \"INPUT\" || tag === \"TEXTAREA\" || tag === \"SELECT\") return true;\n if (target.isContentEditable) return true;\n return Boolean(target.closest('[contenteditable=\"true\"], [role=\"textbox\"], [role=\"combobox\"], [role=\"searchbox\"]'));\n}\n\n/**\n * Whether a bare letter shortcut may act on this target. Only the list side of\n * the split owns them — inside the detail panel a keystroke belongs to the form.\n */\nfunction isListShortcutTarget(target: HTMLElement | null, detailPanel: HTMLElement | null): boolean {\n if (!target || target === document.body) return true;\n // Focus inside a layer opened above the page — a dialog, a menu, a select\n // list — means the keystroke is that layer's. A modal traps focus, so this\n // is also what keeps a bare `j` from moving the list behind an open dialog.\n if (target.closest('[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]')) return false;\n return !detailPanel?.contains(target);\n}\n\n/**\n * The list's share of the split, as a percentage, before anyone drags it.\n *\n * The list only has to identify a record — a title, a subtitle and a status\n * chip — while the detail beside it carries the whole record and its rail. At\n * 30% the list was taking width from the side that had four columns of fields\n * to lay out; 26% still was, by about the width of one field.\n *\n * A default, not a constraint: {@link savePanelSize} remembers the drag per\n * collection, so anyone who has already sized this list keeps their size. The\n * drag floor is `minPanelSizePx`, and it holds below ~1100px of split — at that\n * width this percentage is already the floor.\n */\nconst DEFAULT_PANEL_SIZE = 22;\n\nfunction getSavedPanelSize(path: string): number {\n try {\n const saved = localStorage.getItem(`${PANEL_SIZE_KEY}_${path}`);\n if (saved !== null) {\n const val = parseFloat(saved);\n if (!isNaN(val) && val > 0 && val < 100) return val;\n }\n } catch { /* ignore */ }\n return DEFAULT_PANEL_SIZE;\n}\n\nfunction savePanelSize(path: string, size: number) {\n try {\n localStorage.setItem(`${PANEL_SIZE_KEY}_${path}`, size.toString());\n } catch { /* ignore */ }\n}\n\n/** The list's floor while it sits beside the record: a title, a subtitle and a status chip still read. */\nconst MIN_LIST_WIDTH = 240;\n\n/**\n * Master-detail split view: the kit's {@link SplitView}, with the list as its\n * master and the record as its detail, wired to the router.\n *\n * The split follows its own width: side by side when the collection view is\n * wide, the record covering the list when it is narrow.\n *\n * Animation approach:\n * - The list always renders at full width.\n * - When a detail opens, the list shrinks to `panelSize%` and the detail slides in.\n * - On close, the reverse plays.\n *\n * State management:\n * - The selected entity is driven by the URL path (e.g. /c/authors/14).\n * `selectedEntityId` comes from props via RebaseRoute, NOT from internal state.\n * - Clicking a entity navigates to /c/authors/{id} via the standard onEntityClick handler.\n * - Closing the detail navigates back to /c/authors.\n */\nexport function SplitListView<M extends Record<string, unknown> = Record<string, unknown>>({\n collection,\n tableController,\n onEntityClick: externalOnEntityClick,\n onNewClick: externalOnNewClick,\n selectionController,\n selectionEnabled = true,\n highlightedEntities,\n emptyComponent,\n onScroll,\n initialScroll,\n size = \"m\",\n path,\n parentCollectionSlugs, parentEntityIds,\n selectedEntityId,\n selectedTab,\n toolbar,\n children\n}: SplitListViewProps<M>) {\n const collectionRegistryController = useCollectionRegistryController();\n const location = useLocation();\n const isEditMode = location.pathname.endsWith(\"/edit\") || location.pathname.split(\"/\").pop() === \"edit\";\n const navigate = useNavigate();\n const urlController = useUrlController();\n\n const showDetail = selectedEntityId !== undefined;\n\n // ── Unsaved changes ──\n // The detail form lives inside the split layout, so every way out of it\n // (Escape, j/k, clicking another row, the browser back button) is a plain\n // router navigation. A ref — not state — because the blocker predicate must\n // observe the change synchronously, before the navigation it is guarding.\n const dirty = useRef(false);\n const detailPanelRef = useRef<HTMLDivElement>(null);\n const setDirty = useCallback((modified: boolean) => {\n dirty.current = modified;\n }, []);\n\n // The form remounts per entity, so its dirty state must not leak into the\n // next one — and it has to be cleared here rather than left to the next\n // form's own first report, because that form spends the load in a skeleton\n // and a navigation during it would prompt about the record before it.\n //\n // On a *change* of record only, never on this view's own mount: a record\n // arriving from full screen carries its edit back in and opens dirty, and\n // the form says so from its first effect — which runs before this one, being\n // a child's. Clearing unconditionally overwrote that report with `false`,\n // and the way out of the split stopped asking about a live edit.\n const previousEntityId = useRef(selectedEntityId);\n useEffect(() => {\n if (previousEntityId.current === selectedEntityId) return;\n previousEntityId.current = selectedEntityId;\n dirty.current = false;\n }, [selectedEntityId]);\n\n const blocker = useNavigationBlocker(useCallback(({\n currentLocation,\n nextLocation\n }) => {\n if (!dirty.current) return false;\n if (currentLocation.pathname === nextLocation.pathname) return false;\n // Side panel overlays (e.g. following a relation) render above the form\n // and leave it mounted — nothing is lost in either direction.\n const nextHash = nextLocation.hash;\n if (nextHash === \"#side\" || nextHash === \"#new_side\") return false;\n const currentHash = currentLocation.hash;\n if (currentHash === \"#side\" || currentHash === \"#new_side\") return false;\n return true;\n }, []));\n\n // Panel size state with persistence.\n //\n // Written on drag, not on mount. An effect that saved on mount stored\n // {@link DEFAULT_PANEL_SIZE} under this collection's key the first time\n // anyone opened the split — after which the default was frozen in every\n // browser that had ever seen it, and changing it here reached nobody but a\n // new visitor. Only a size someone chose is a size worth remembering.\n const [panelSize] = useState(() => getSavedPanelSize(path));\n\n const handlePanelSizeChange = useCallback((size: number) => {\n savePanelSize(path, size);\n }, [path]);\n\n // ── Animation state ──\n // We track the \"rendered\" entity to keep the detail panel mounted during the exit animation.\n const [renderedEntityId, setRenderedEntityId] = useState<string | number | undefined>(selectedEntityId);\n const [animationPhase, setAnimationPhase] = useState<\"idle\" | \"entering\" | \"entered\" | \"exiting\">(\n selectedEntityId !== undefined ? \"entered\" : \"idle\"\n );\n const animationTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Transition duration (ms) — keep in sync with CSS\n const TRANSITION_DURATION = 150;\n\n useEffect(() => {\n if (animationTimer.current) {\n clearTimeout(animationTimer.current);\n animationTimer.current = null;\n }\n\n if (selectedEntityId !== undefined) {\n // Opening or switching entity\n setRenderedEntityId(selectedEntityId);\n if (animationPhase === \"idle\" || animationPhase === \"exiting\") {\n // Fresh open — trigger enter\n setAnimationPhase(\"entering\");\n // Use requestAnimationFrame to ensure the \"entering\" class is painted\n // before transitioning to \"entered\".\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n setAnimationPhase(\"entered\");\n });\n });\n }\n // If already entered (switching entities), keep \"entered\"\n } else {\n // Closing\n if (animationPhase === \"entered\" || animationPhase === \"entering\") {\n setAnimationPhase(\"exiting\");\n animationTimer.current = setTimeout(() => {\n setAnimationPhase(\"idle\");\n setRenderedEntityId(undefined);\n }, TRANSITION_DURATION);\n }\n }\n\n return () => {\n if (animationTimer.current) clearTimeout(animationTimer.current);\n };\n }, [selectedEntityId]); // Intentionally only depend on selectedEntityId\n\n // Build a URL below this collection, carrying the list's whole URL state —\n // view mode, search, filters and sort — the way the record was opened.\n // The list reads that state back from the URL on every navigation, so a\n // URL carrying only the view mode reset the search box and the filters\n // each time the record was closed or one of its tabs changed.\n const buildUrl = useCallback((subPath: string) => {\n return withListState(urlController.buildUrlCollectionPath(subPath));\n }, [urlController]);\n\n // Close the detail panel: navigate back to the collection path\n const handleCloseDetail = useCallback(() => {\n navigate(buildUrl(path));\n }, [navigate, buildUrl, path]);\n\n // ── Keyboard navigation ──\n const entityIds = useMemo(\n () => tableController.data.map((e: Entity<M>) => e.id),\n [tableController.data]\n );\n\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n const target = e.target as HTMLElement | null;\n\n // A layer above the record — a dialog, a menu, a select list, the\n // inspector — claims the key it acts on with preventDefault(). Asking\n // the DOM for an open `role=\"dialog\"` instead missed every layer that\n // is not a dialog, so Escape on an open dropdown closed the record too.\n if (isKeyHandled(e)) return;\n\n if (e.key === \"Escape\") {\n if (!selectedEntityId) return;\n // First Escape leaves the field (which may also be dismissing its\n // own dropdown), a second one closes the panel. Closing straight\n // from a focused field would discard an in-progress edit.\n if (isTextEntryTarget(target)) {\n target?.blur();\n e.preventDefault();\n return;\n }\n handleCloseDetail();\n e.preventDefault();\n return;\n }\n\n // Record navigation only belongs to the list side. Inside the detail\n // panel these keys are the form's — arrows move between fields, and a\n // bare letter is input for widgets that aren't native fields (rich\n // text, code editors, comboboxes).\n if (!isListShortcutTarget(target, detailPanelRef.current)) return;\n if (isTextEntryTarget(target)) return;\n\n // Arrow down / j → next entity\n if ((e.key === \"ArrowDown\" || e.key === \"j\") && !e.metaKey && !e.ctrlKey) {\n e.preventDefault();\n if (entityIds.length === 0) return;\n\n if (selectedEntityId === undefined) {\n const firstEntity = tableController.data[0];\n if (firstEntity) externalOnEntityClick?.(firstEntity);\n } else {\n const currentIndex = entityIds.indexOf(selectedEntityId);\n if (currentIndex >= 0 && currentIndex < entityIds.length - 1) {\n const nextEntity = tableController.data[currentIndex + 1];\n if (nextEntity) externalOnEntityClick?.(nextEntity);\n }\n }\n return;\n }\n\n // Arrow up / k → previous entity\n if ((e.key === \"ArrowUp\" || e.key === \"k\") && !e.metaKey && !e.ctrlKey) {\n e.preventDefault();\n if (entityIds.length === 0) return;\n\n if (selectedEntityId === undefined) {\n const lastEntity = tableController.data[tableController.data.length - 1];\n if (lastEntity) externalOnEntityClick?.(lastEntity);\n } else {\n const currentIndex = entityIds.indexOf(selectedEntityId);\n if (currentIndex > 0) {\n const prevEntity = tableController.data[currentIndex - 1];\n if (prevEntity) externalOnEntityClick?.(prevEntity);\n }\n }\n return;\n }\n\n // n → new entity\n if (e.key === \"n\" && !e.metaKey && !e.ctrlKey && !e.altKey) {\n externalOnNewClick?.();\n e.preventDefault();\n return;\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => window.removeEventListener(\"keydown\", handleKeyDown);\n }, [selectedEntityId, handleCloseDetail, externalOnEntityClick, externalOnNewClick, entityIds, tableController.data]);\n\n const usedParentCollectionIds = parentCollectionSlugs ?? collectionRegistryController.getParentCollectionSlugs(path);\n const usedParentEntityIds = parentEntityIds ?? collectionRegistryController.getParentEntityIds(path);\n\n const isDetailVisible = animationPhase !== \"idle\";\n\n // ── Layout: the kit's SplitView ──\n // What changes with the arrangement is styled off the split's own\n // `data-layout` (`group-data-[layout=stacked]/split:`), so the classes\n // and the split always agree on which one it is.\n\n const listPanel = (\n <div className=\"flex flex-col h-full min-w-0 w-full\">\n {/* Toolbar stays fixed above the scrollable area */}\n {toolbar}\n {/* Scrollable content: title + insights + list rows */}\n <div className=\"flex-1 overflow-y-auto overflow-x-hidden min-h-0\">\n {children}\n </div>\n </div>\n );\n\n const detailPanel = renderedEntityId !== undefined ? (\n <div\n ref={detailPanelRef}\n className={cls(\n \"flex-1 flex flex-col min-w-0 h-full transition-all ease-out w-full\",\n // The record is an object opened beside the list, so it carries\n // its own left edge — the way a card carries its hairline. The\n // resize handle between the panes is transparent; this line is\n // the record's, not a divider hanging in the gap. Side-by-side\n // only: stacked, the record has no left neighbour.\n \"border-l border-hairline group-data-[layout=stacked]/split:border-l-0\",\n animationPhase === \"entered\"\n ? \"opacity-100 translate-x-0\"\n : \"opacity-0 translate-x-8 group-data-[layout=stacked]/split:translate-x-1/3\"\n )}\n style={{ transitionDuration: `${TRANSITION_DURATION}ms` }}\n >\n <ErrorBoundary>\n {collection.defaultEntityAction === \"view\" && !isEditMode\n ? <DetailViewBinding\n key={String(renderedEntityId)}\n path={path}\n collection={collection as AdminCollection<Record<string, unknown>>}\n entityId={renderedEntityId}\n parentCollectionSlugs={usedParentCollectionIds}\n parentEntityIds={usedParentEntityIds}\n selectedTab={selectedTab}\n layout=\"split\"\n onCloseRequest={handleCloseDetail}\n onEditClick={() => {\n navigate(buildUrl(`${path}/${renderedEntityId}/edit`));\n }}\n onTabChange={(params) => {\n const newSelectedTab = params.selectedTab;\n navigate(buildUrl(\n newSelectedTab\n ? `${path}/${renderedEntityId}/${newSelectedTab}`\n : `${path}/${renderedEntityId}`\n ));\n }}\n />\n : <EditViewBinding\n key={String(renderedEntityId)}\n path={path}\n collection={collection as AdminCollection<Record<string, unknown>>}\n entityId={renderedEntityId}\n parentCollectionSlugs={usedParentCollectionIds}\n parentEntityIds={usedParentEntityIds}\n selectedTab={selectedTab}\n layout=\"split\"\n // The ✕, and where \"save and close\" lands. A plain\n // navigation: `useNavigationBlocker` above already\n // stands between it and an unsaved edit, so the ✕ asks\n // exactly what Escape and the browser's Back ask.\n onCloseRequest={handleCloseDetail}\n onValuesModified={setDirty}\n onSaved={() => {\n setDirty(false);\n navigate(buildUrl(`${path}/${renderedEntityId}`), { replace: true });\n }}\n navigateBack={() => {\n navigate(buildUrl(`${path}/${renderedEntityId}`));\n }}\n onTabChange={(params) => {\n const newSelectedTab = params.selectedTab;\n navigate(buildUrl(\n newSelectedTab\n ? `${path}/${renderedEntityId}/${newSelectedTab}`\n : `${path}/${renderedEntityId}`\n ));\n }}\n />\n }\n </ErrorBoundary>\n </div>\n ) : null;\n\n // Closing the list is the full-screen entity route: the same `#full` the\n // entity pane's expand button used, so there is one way to give the record\n // the whole window and one way back out of it.\n const openFullScreen = useCallback(() => {\n if (selectedEntityId === undefined) return;\n const suffix = isEditMode ? \"/edit\" : \"\";\n navigate(`${buildUrl(`${path}/${selectedEntityId}${suffix}`)}#full`);\n }, [navigate, buildUrl, path, selectedEntityId, isEditMode]);\n\n const splitViewController = useMemo(() => ({\n detailOpen: selectedEntityId !== undefined,\n openFullScreen\n }), [selectedEntityId, openFullScreen]);\n\n return (\n <SplitViewProvider value={splitViewController}>\n <SplitView\n className=\"group/split\"\n master={listPanel}\n detail={isDetailVisible ? detailPanel : null}\n defaultMasterPercent={panelSize}\n onMasterPercentChange={handlePanelSizeChange}\n minPaneWidth={MIN_LIST_WIDTH}\n />\n\n <UnsavedChangesDialog\n open={blocker?.state === \"blocked\"}\n handleOk={() => {\n dirty.current = false;\n blocker?.proceed?.();\n }}\n handleCancel={() => blocker?.reset?.()}\n body={<>You have unsaved changes in this <b>{collection.singularName ?? collection.name}</b>.</>}/>\n </SplitViewProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAyDA,IAAM,iBAAiB;;;;;AAMvB,SAAS,kBAAkB,QAAqC;CAC5D,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,MAAM,OAAO;CACnB,IAAI,QAAQ,WAAW,QAAQ,cAAc,QAAQ,UAAU,OAAO;CACtE,IAAI,OAAO,mBAAmB,OAAO;CACrC,OAAO,QAAQ,OAAO,QAAQ,2FAAmF,CAAC;AACtH;;;;;AAMA,SAAS,qBAAqB,QAA4B,aAA0C;CAChG,IAAI,CAAC,UAAU,WAAW,SAAS,MAAM,OAAO;CAIhD,IAAI,OAAO,QAAQ,gFAAwE,GAAG,OAAO;CACrG,OAAO,CAAC,aAAa,SAAS,MAAM;AACxC;;;;;;;;;;;;;;AAeA,IAAM,qBAAqB;AAE3B,SAAS,kBAAkB,MAAsB;CAC7C,IAAI;EACA,MAAM,QAAQ,aAAa,QAAQ,GAAG,eAAe,GAAG,MAAM;EAC9D,IAAI,UAAU,MAAM;GAChB,MAAM,MAAM,WAAW,KAAK;GAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,MAAM,KAAK,MAAM,KAAK,OAAO;EACpD;CACJ,QAAQ,CAAe;CACvB,OAAO;AACX;AAEA,SAAS,cAAc,MAAc,MAAc;CAC/C,IAAI;EACA,aAAa,QAAQ,GAAG,eAAe,GAAG,QAAQ,KAAK,SAAS,C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AAG,iBAAiB,GAAG,mBAC/B,GAAG,KAAK,GAAG,kBACrB,CAAC;GACL;EACH,GA7BQ,OAAO,gBAAgB,CA6B/B,EAEM,CAAA;CACd,CAAA,IACL;CAKJ,MAAM,iBAAiB,kBAAkB;EACrC,IAAI,qBAAqB,KAAA,GAAW;EAEpC,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,mBADjB,aAAa,UAAU,IACqB,EAAE,MAAM;CACvE,GAAG;EAAC;EAAU;EAAU;EAAM;EAAkB;CAAU,CAAC;CAO3D,OACI,qBAAC,mBAAD;EAAmB,OANK,eAAe;GACvC,YAAY,qBAAqB,KAAA;GACjC;EACJ,IAAI,CAAC,kBAAkB,cAAc,CAGP;YAA1B,CACI,oBAAC,WAAD;GACI,WAAU;GACV,QAAQ;GACR,QAAQ,kBAAkB,cAAc;GACxC,sBAAsB;GACtB,uBAAuB;GACvB,cAAc;EACjB,CAAA,GAED,oBAAC,sBAAD;GACI,MAAM,SAAS,UAAU;GACzB,gBAAgB;IACZ,MAAM,UAAU;IAChB,SAAS,UAAU;GACvB;GACA,oBAAoB,SAAS,QAAQ;GACrC,MAAM,qBAAA,UAAA,EAAA,UAAA;IAAE;IAAiC,oBAAC,KAAD,EAAA,UAAI,WAAW,gBAAgB,WAAW,KAAQ,CAAA;IAAC;GAAG,EAAA,CAAA;EAAG,CAAA,CACvF;;AAE3B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { RebaseData } from "@rebasepro/types";
|
|
2
|
-
import { RebaseContext, AdminCollection } from "@rebasepro/cms-types";
|
|
1
|
+
import { RebaseContext, AdminCollection, RebaseData } from "@rebasepro/cms-types";
|
|
3
2
|
import { OnCellValueChange, UniqueFieldValidator } from "@rebasepro/app";
|
|
4
3
|
export interface UseCollectionInlineEditorParams<M extends Record<string, unknown>> {
|
|
5
4
|
path: string;
|
|
@@ -4,7 +4,7 @@ import { getIn, setIn } from "@rebasepro/forms";
|
|
|
4
4
|
//#region src/components/CollectionViewBinding/hooks/useCollectionInlineEditor.ts
|
|
5
5
|
function useCollectionInlineEditor({ path, collection, dataClient, context }) {
|
|
6
6
|
const uniqueFieldValidator = useCallback(async ({ name, value, property, entityId }) => {
|
|
7
|
-
const conflictingEntities = (await dataClient.
|
|
7
|
+
const conflictingEntities = (await dataClient.table(path).find({ where: { [name]: ["==", value] } })).data;
|
|
8
8
|
return conflictingEntities.length === 0 || conflictingEntities.length === 1 && conflictingEntities[0].id === entityId;
|
|
9
9
|
}, [path, dataClient]);
|
|
10
10
|
const onValueChange = useCallback(({ value, propertyKey, onValueUpdated, setError, data: entity }) => {
|