@rebasepro/cms 0.28.2 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/collection_editor/_cms_internals.d.ts +0 -1
- package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
- package/dist/components/AdditionalFieldValue.d.ts +9 -3
- package/dist/components/AdditionalFieldValue.js +7 -4
- package/dist/components/AdditionalFieldValue.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +117 -18
- package/dist/components/CollectionPanel.js +115 -37
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
- package/dist/components/CollectionTableBinding/column_utils.js +6 -3
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
- package/dist/components/CollectionTableBinding/internal/common.js +88 -4
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
- package/dist/components/CollectionViewBinding/RowActions.js +60 -0
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
- package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
- package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
- package/dist/components/CollectionViewBinding/fields.js +47 -0
- package/dist/components/CollectionViewBinding/fields.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
- package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +3 -3
- package/dist/components/CollectionsProvider.js +4 -4
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/CollectionsScopeContext.d.ts +1 -1
- package/dist/components/CollectionsScopeContext.js +1 -1
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +2 -2
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +32 -68
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js +5 -4
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -2
- package/dist/components/EditViewBinding.js +25 -15
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.js +8 -5
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +8 -1
- package/dist/components/EntityViewBinding.js +43 -14
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +40 -0
- package/dist/components/EntityViewBody.js +90 -0
- package/dist/components/EntityViewBody.js.map +1 -0
- package/dist/components/FieldValue.d.ts +50 -0
- package/dist/components/FieldValue.js +81 -0
- package/dist/components/FieldValue.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PanelNotFound.d.ts +5 -0
- package/dist/components/PanelNotFound.js +21 -0
- package/dist/components/PanelNotFound.js.map +1 -0
- package/dist/components/RebaseCMS.d.ts +1 -1
- package/dist/components/RebaseCMS.js +11 -3
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +9 -3
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RebaseShell.js +10 -5
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/RecordDetail.d.ts +61 -0
- package/dist/components/RecordDetail.js +123 -0
- package/dist/components/RecordDetail.js.map +1 -0
- package/dist/components/RecordForm.d.ts +126 -0
- package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
- package/dist/components/RecordForm.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
- package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +5 -3
- package/dist/components/ReferenceWidget.js +10 -7
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.js +4 -4
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +2 -3
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
- package/dist/components/SelectableTable/SelectionStore.js +1 -1
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SidePanelBinding.js +13 -12
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/collection_prop.d.ts +18 -0
- package/dist/components/collection_prop.js +23 -0
- package/dist/components/collection_prop.js.map +1 -0
- package/dist/components/common/default_entity_actions.js +54 -54
- package/dist/components/common/default_entity_actions.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +4 -1
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
- package/dist/data_export/export/ExportCollectionAction.js +4 -3
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +6 -3
- package/dist/data_export/export/additional_fields.js +8 -4
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.js +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +255 -150
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js +3 -2
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +22 -11
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormField.d.ts +36 -0
- package/dist/form/FormField.js +41 -0
- package/dist/form/FormField.js.map +1 -0
- package/dist/form/FormFieldsContext.d.ts +69 -0
- package/dist/form/FormFieldsContext.js +143 -0
- package/dist/form/FormFieldsContext.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +4 -4
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/collection_showing.d.ts +8 -0
- package/dist/form/collection_showing.js +29 -0
- package/dist/form/collection_showing.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +2 -1
- package/dist/form/components/ErrorFocus.js.map +1 -1
- package/dist/form/components/FieldBlock.js +3 -1
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +5 -1
- package/dist/form/components/FormRail.js +5 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/FormSections.d.ts +5 -1
- package/dist/form/components/FormSections.js +11 -4
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/form_dom_ids.d.ts +25 -0
- package/dist/form/form_dom_ids.js +42 -0
- package/dist/form/form_dom_ids.js.map +1 -0
- package/dist/form/index.d.ts +3 -1
- package/dist/form/resolve_cell_property.d.ts +5 -0
- package/dist/form/resolve_cell_property.js +22 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.js +9 -9
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useEntityDisplay.js +6 -4
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useRecordActions.js +2 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useSelectionDialog.d.ts +20 -7
- package/dist/hooks/useSelectionDialog.js +29 -8
- package/dist/hooks/useSelectionDialog.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -9
- package/dist/mcp-view.d.ts +9 -0
- package/dist/mcp-view.js +2 -0
- package/dist/mcp_view/app_modules.d.ts +29 -0
- package/dist/mcp_view/app_modules.js +163 -0
- package/dist/mcp_view/app_modules.js.map +1 -0
- package/dist/mcp_view/bridge.d.ts +90 -0
- package/dist/mcp_view/bridge.js +205 -0
- package/dist/mcp_view/bridge.js.map +1 -0
- package/dist/mcp_view/code_app.d.ts +65 -0
- package/dist/mcp_view/code_app.js +139 -0
- package/dist/mcp_view/code_app.js.map +1 -0
- package/dist/mcp_view/index.d.ts +54 -0
- package/dist/mcp_view/index.js +262 -0
- package/dist/mcp_view/index.js.map +1 -0
- package/dist/mcp_view/payload.d.ts +78 -0
- package/dist/mcp_view/payload.js +155 -0
- package/dist/mcp_view/payload.js.map +1 -0
- package/dist/mcp_view/screen.d.ts +30 -0
- package/dist/mcp_view/screen.js +245 -0
- package/dist/mcp_view/screen.js.map +1 -0
- package/dist/mcp_view/storage_source.d.ts +14 -0
- package/dist/mcp_view/storage_source.js +29 -0
- package/dist/mcp_view/storage_source.js.map +1 -0
- package/dist/mcp_view/store.d.ts +9 -0
- package/dist/mcp_view/store.js +27 -0
- package/dist/mcp_view/store.js.map +1 -0
- package/dist/mcp_view/tool_driver.d.ts +160 -0
- package/dist/mcp_view/tool_driver.js +575 -0
- package/dist/mcp_view/tool_driver.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +34 -1
- package/dist/preview/components/DatePreview.js +72 -37
- package/dist/preview/components/DatePreview.js.map +1 -1
- package/dist/routes/RebaseRoute.js +1 -1
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +5 -3
- package/dist/selection/SelectionMenu.js +16 -9
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/resolve_selection.d.ts +61 -7
- package/dist/selection/resolve_selection.js +93 -11
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +60 -10
- package/dist/types/fields.d.ts +2 -65
- package/dist/util/dataControllerAdapter.d.ts +8 -0
- package/dist/util/dataControllerAdapter.js +11 -0
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/navigation_utils.d.ts +5 -4
- package/dist/util/navigation_utils.js +6 -6
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +8 -0
- package/dist/util/propertyConfigMapper.js +16 -2
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/package.json +15 -9
- package/recipes/README.md +79 -26
- package/recipes/approval-queue.tsx +79 -0
- package/recipes/bulk-set-status.tsx +23 -17
- package/recipes/calendar-view.tsx +28 -23
- package/recipes/master-detail.tsx +75 -0
- package/recipes/my-preferences.tsx +3 -3
- package/recipes/orders-dashboard.tsx +58 -84
- package/recipes/site-settings.tsx +4 -4
- package/dist/components/EntityFormPanel.d.ts +0 -63
- package/dist/components/EntityFormPanel.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadOnlyFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ReadOnlyFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport React from \"react\";\n\nimport { PropertyPreview } from \"../../preview\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { cls, ErrorBoundary, InputLabel } from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { readOnlyLabelsInside } from \"../label_placement\";\n\n/**\n *\n * Simply render the non-editable preview of a field\n *\n * This is one of the internal components that get mapped natively inside forms\n * and tables to the specified properties.\n * @group Form fields\n */\nexport function ReadOnlyFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n minimalistView,\n property,\n includeDescription,\n hideLabel,\n context,\n size = \"large\"\n}: FieldProps<Property>) {\n\n // if (!context.
|
|
1
|
+
{"version":3,"file":"ReadOnlyFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ReadOnlyFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport React from \"react\";\n\nimport { PropertyPreview } from \"../../preview\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { cls, ErrorBoundary, InputLabel } from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { readOnlyLabelsInside } from \"../label_placement\";\n\n/**\n *\n * Simply render the non-editable preview of a field\n *\n * This is one of the internal components that get mapped natively inside forms\n * and tables to the specified properties.\n * @group Form fields\n */\nexport function ReadOnlyFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n minimalistView,\n property,\n includeDescription,\n hideLabel,\n context,\n size = \"large\"\n}: FieldProps<Property>) {\n\n // if (!context.id)\n // throw new Error(\"ReadOnlyFieldBinding: Entity id is null\");\n\n const skipCardWrapper = property.type === \"relation\" || property.type === \"reference\";\n\n // No required marker on either label: the asterisk asks the person filling\n // the form for a value, and nobody fills this one in. `validation.required`\n // on a read-only field is about the column (NOT NULL), not about them.\n\n // A one-line value at the form's size is drawn like the one-line fields\n // around it: the same 64px box, the label shrunk into its top edge. It keeps\n // the outline and drops the fill — that is what says it cannot be edited.\n if (!minimalistView && !hideLabel && size === \"large\" && readOnlyLabelsInside(property)) {\n return (\n <>\n <div className={\"relative w-full min-h-[66px] rounded-lg border border-hairline-strong px-3 pt-8 pb-2 text-base\"}>\n {/* `left-0` is the box's padding edge, where a text field's\n label starts; left to its static position it would\n start after the `px-3`, 12px too far in. */}\n <InputLabel shrink\n className={\"pointer-events-none absolute top-1 left-0 text-text-secondary dark:text-text-secondary-dark\"}>\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n title={property.name ?? propertyKey}/>\n </InputLabel>\n <div className={\"min-h-6 flex items-center overflow-x-auto no-scrollbar opacity-80\"}>\n <ErrorBoundary>\n <PropertyPreview propertyKey={propertyKey}\n value={value}\n property={property}\n hideLabel\n size={\"medium\"}/>\n </ErrorBoundary>\n </div>\n </div>\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n property={property}/>\n </>\n );\n }\n\n return (\n\n <>\n\n {!minimalistView && !hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3\"}/>\n }\n\n <div\n className={cls(\n \"w-full overflow-x-scroll no-scrollbar flex items-center\",\n skipCardWrapper\n ? \"\"\n // `px-3` is what `TextField` gives its input, so a\n // read-only value starts on the same vertical line as\n // the text beside it. It was `px-4 md:px-6`, which in a\n // one-column span spent a sixth of the box on empty\n // margin and pushed short values towards the middle.\n : cls(\"rounded-lg border border-hairline-strong px-3 text-sm opacity-80\", {\n // The height an editable field of the form's `size`\n // renders at — the kit's control height plus its 1px\n // hairline on each side — so a row holding one of\n // each has its baselines and bottom edges agree. This\n // was a fixed `min-h-12` (48px) with the page's 16px\n // text: 2px short of a `large` text field, 14px taller\n // than a `small` one, and a size above every input's\n // `text-sm` at either.\n \"min-h-[34px]\": size === \"small\",\n \"min-h-[42px]\": size === \"medium\",\n \"min-h-[50px]\": size === \"large\"\n })\n )}>\n\n <ErrorBoundary>\n {/* The field is labelled either just above by this\n component, or by the `FieldBlock` that asked for\n `hideLabel` — never by the preview. `BooleanPreview`\n prints the property name beside its checkbox, so a\n read-only boolean read as \"Procesado por LLM\" over a\n checkbox saying \"Procesado por LLM\", wrapped over two\n lines in a one-column span. */}\n <PropertyPreview propertyKey={propertyKey}\n value={value}\n property={property}\n hideLabel={hideLabel || !minimalistView}\n size={\"medium\"}/>\n </ErrorBoundary>\n\n </div>\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n property={property}/>\n\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,qBAAqB,EACjC,aACA,OACA,OACA,WACA,gBACA,UACA,oBACA,WACA,SACA,OAAO,WACc;CAKrB,MAAM,kBAAkB,SAAS,SAAS,cAAc,SAAS,SAAS;CAS1E,IAAI,CAAC,kBAAkB,CAAC,aAAa,SAAS,WAAW,qBAAqB,QAAQ,GAClF,OACI,qBAAA,UAAA,EAAA,UAAA,CACI,qBAAC,OAAD;EAAK,WAAW;YAAhB,CAII,oBAAC,YAAD;GAAY,QAAA;GACR,WAAW;aACX,oBAAC,eAAD;IACI,MAAM,mBAAmB,UAAU,OAAO;IAC1C,OAAO,SAAS,QAAQ;GAAa,CAAA;EACjC,CAAA,GACZ,oBAAC,OAAD;GAAK,WAAW;aACZ,oBAAC,eAAD,EAAA,UACI,oBAAC,iBAAD;IAA8B;IACnB;IACG;IACV,WAAA;IACA,MAAM;GAAU,CAAA,EACT,CAAA;EACd,CAAA,CACJ;KAEL,oBAAC,iBAAD;EAAqC;EACtB;EACJ;EACG;CAAU,CAAA,CAC1B,EAAA,CAAA;CAIV,OAEI,qBAAA,UAAA,EAAA,UAAA;EAEK,CAAC,kBAAkB,CAAC,aAAa,oBAAC,eAAD;GACjB;GACb,MAAM,mBAAmB,UAAU,OAAO;GAC1C,OAAO,SAAS,QAAQ;GACxB,WAAW;EAA8D,CAAA;EAG7E,oBAAC,OAAD;GACI,WAAW,IACP,2DACA,kBACM,KAMA,IAAI,oEAAoE;IAStE,gBAAgB,SAAS;IACzB,gBAAgB,SAAS;IACzB,gBAAgB,SAAS;GAC7B,CAAC,CACT;aAEA,oBAAC,eAAD,EAAA,UAQI,oBAAC,iBAAD;IAA8B;IACnB;IACG;IACV,WAAW,aAAa,CAAC;IACzB,MAAM;GAAU,CAAA,EACT,CAAA;EAEd,CAAA;EAEL,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;EAAU,CAAA;CAE1B,EAAA,CAAA;AAEV"}
|
|
@@ -6,7 +6,7 @@ import { ReferencePreview } from "../../preview/components/ReferencePreview.js";
|
|
|
6
6
|
import { FieldHelperText } from "../components/FieldHelperText.js";
|
|
7
7
|
import { LabelWithIcon } from "../components/LabelWithIcon.js";
|
|
8
8
|
import { ReadOnlyFieldBinding } from "./ReadOnlyFieldBinding.js";
|
|
9
|
-
import {
|
|
9
|
+
import { useEntitySelectionDialog } from "../../hooks/useSelectionDialog.js";
|
|
10
10
|
import { useCallback, useMemo } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { cls } from "@rebasepro/ui";
|
|
@@ -35,7 +35,7 @@ function ReferenceFieldBindingInternal({ propertyKey, value, setValue, error, sh
|
|
|
35
35
|
return collectionRegistryController.getCollection(collectionPath);
|
|
36
36
|
}, [collectionPath]);
|
|
37
37
|
if (!collection) throw Error(`Couldn't find the corresponding collection for the path: ${property.path}`);
|
|
38
|
-
const referenceDialogController =
|
|
38
|
+
const referenceDialogController = useEntitySelectionDialog({
|
|
39
39
|
multiselect: false,
|
|
40
40
|
path: collectionPath,
|
|
41
41
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferenceFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ReferenceFieldBinding.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ReferenceFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ReferenceFieldBinding.tsx"],"sourcesContent":["import { useEntitySelectionDialog } from \"../../hooks/useSelectionDialog\";\n\nimport type { FieldProps } from \"../../types/fields\";\nimport type { Property, ReferenceProperty } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo } from \"react\";\n\nimport { Entity, EntityReference } from \"@rebasepro/types\";\nimport { ErrorView } from \"@rebasepro/app\";\nimport { ReadOnlyFieldBinding } from \"./ReadOnlyFieldBinding\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport { ReferencePreview } from \"../../preview\";\nimport { IconForView, useTranslation } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { cls } from \"@rebasepro/ui\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../../hooks/useReferencePaths\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\n/**\n * Field that opens a reference selection dialog.\n *\n * This is one of the internal components that get mapped natively inside forms\n * and tables to the specified properties.\n * @group Form fields\n */\nexport function ReferenceFieldBinding(props: FieldProps<ReferenceProperty>) {\n\n if (typeof props.property.path !== \"string\") {\n return <ReadOnlyFieldBinding {...props as FieldProps<Property>}/>\n }\n\n return <ReferenceFieldBindingInternal {...props}/>;\n\n}\n\nfunction ReferenceFieldBindingInternal({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n isSubmitting,\n disabled,\n minimalistView,\n touched,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"medium\"\n}: FieldProps<ReferenceProperty>) {\n if (!property.path) {\n throw new Error(\"Property path is required for ReferenceFieldBinding\");\n }\n\n const { t } = useTranslation();\n const refValue = value as EntityReference | null | undefined;\n\n const validValue = refValue && typeof refValue === \"object\" && \"isEntityReference\" in refValue && refValue.isEntityReference();\n\n const collectionRegistryController = useCollectionRegistryController();\n const { toCollectionPath, referenceTo } = useReferencePaths();\n const collectionPath = toCollectionPath(property.path);\n const collection: AdminCollection | undefined = useMemo(() => {\n return collectionRegistryController.getCollection(collectionPath);\n }, [collectionPath]);\n\n if (!collection) {\n throw Error(`Couldn't find the corresponding collection for the path: ${property.path}`);\n }\n\n const onSingleEntitySelected = useCallback((e: Entity<Record<string, unknown>> | null) => {\n const ref = e ? referenceTo(e) : null;\n setValue(ref);\n }, [setValue, propertyKey, referenceTo]);\n\n const referenceDialogController = useEntitySelectionDialog({\n multiselect: false,\n path: collectionPath,\n collection,\n onSingleEntitySelected,\n selectedEntityIds: validValue && refValue ? [refValue.id] : undefined,\n fixedFilter: property.admin?.fixedFilter\n }\n );\n\n const onEntryClick = (e: React.SyntheticEvent) => {\n e.preventDefault();\n if (disabled || isSubmitting) return;\n referenceDialogController.open();\n };\n\n return (\n <>\n {!minimalistView && !hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n {!collection && <ErrorView\n error={\"The specified collection does not exist. Check console\"}/>}\n\n {collection && <>\n\n {refValue && <ReferencePreview\n disabled={!property.path}\n previewProperties={property.admin?.previewProperties}\n hover={!disabled}\n size={size}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n reference={refValue}\n includeEntityLink={property.admin?.includeEntityLink}\n includeId={property.admin?.includeId}\n />}\n\n {!refValue && <div className=\"justify-center text-left\">\n <EntityPreviewContainer className={cls(\"px-6 h-12 text-sm font-medium flex items-center gap-6\",\n disabled || isSubmitting\n ? \"text-surface-accent-500\"\n : \"cursor-pointer text-surface-accent-700 dark:text-surface-accent-300 hover:bg-surface-hover group-hover:bg-surface-hover\")}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n size={\"medium\"}>\n <IconForView collectionOrView={collection}\n className={\"text-surface-300 dark:text-surface-600\"}/>\n {t(\"edit_name\", { name: property.name ?? propertyKey }).toUpperCase()}\n </EntityPreviewContainer>\n </div>}\n </>}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBAAsB,OAAsC;CAExE,IAAI,OAAO,MAAM,SAAS,SAAS,UAC/B,OAAO,oBAAC,sBAAD,EAAsB,GAAI,MAA+B,CAAA;CAGpE,OAAO,oBAAC,+BAAD,EAA+B,GAAI,MAAO,CAAA;AAErD;AAEA,SAAS,8BAA8B,EACnC,aACA,OACA,UACA,OACA,WACA,cACA,UACA,gBACA,SACA,WACA,UACA,oBACA,WACA,OAAO,YACuB;CAC9B,IAAI,CAAC,SAAS,MACV,MAAM,IAAI,MAAM,qDAAqD;CAGzE,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,WAAW;CAEjB,MAAM,aAAa,YAAY,OAAO,aAAa,YAAY,uBAAuB,YAAY,SAAS,kBAAkB;CAE7H,MAAM,+BAA+B,gCAAgC;CACrE,MAAM,EAAE,kBAAkB,gBAAgB,kBAAkB;CAC5D,MAAM,iBAAiB,iBAAiB,SAAS,IAAI;CACrD,MAAM,aAA0C,cAAc;EAC1D,OAAO,6BAA6B,cAAc,cAAc;CACpE,GAAG,CAAC,cAAc,CAAC;CAEnB,IAAI,CAAC,YACD,MAAM,MAAM,4DAA4D,SAAS,MAAM;CAQ3F,MAAM,4BAA4B,yBAAyB;EACvD,aAAa;EACb,MAAM;EACN;EACA,wBAT2B,aAAa,MAA8C;GAEtF,SADY,IAAI,YAAY,CAAC,IAAI,IACrB;EAChB,GAAG;GAAC;GAAU;GAAa;EAAW,CAMlC;EACA,mBAAmB,cAAc,WAAW,CAAC,SAAS,EAAE,IAAI,KAAA;EAC5D,aAAa,SAAS,OAAO;CACjC,CACA;CAEA,MAAM,gBAAgB,MAA4B;EAC9C,EAAE,eAAe;EACjB,IAAI,YAAY,cAAc;EAC9B,0BAA0B,KAAK;CACnC;CAEA,OACI,qBAAA,UAAA,EAAA,UAAA;EACK,CAAC,kBAAkB,CAAC,aAAa,oBAAC,eAAD;GACjB;GACb,MAAM,mBAAmB,UAAU,OAAO;GAC1C,UAAU,SAAS,YAAY;GAC/B,OAAO,SAAS,QAAQ;GACxB,WAAW;EAAgE,CAAA;EAE9E,CAAC,cAAc,oBAAC,WAAD,EACZ,OAAO,yDAA0D,CAAA;EAEpE,cAAc,qBAAA,UAAA,EAAA,UAAA,CAEV,YAAY,oBAAC,kBAAD;GACT,UAAU,CAAC,SAAS;GACpB,mBAAmB,SAAS,OAAO;GACnC,OAAO,CAAC;GACF;GACN,SAAS,YAAY,eAAe,KAAA,IAAY;GAChD,WAAW;GACX,mBAAmB,SAAS,OAAO;GACnC,WAAW,SAAS,OAAO;EAC9B,CAAA,GAEA,CAAC,YAAY,oBAAC,OAAD;GAAK,WAAU;aACzB,qBAAC,wBAAD;IAAwB,WAAW,IAAI,yDACnC,YAAY,eACN,4BACA,yHAAyH;IAC/H,SAAS,YAAY,eAAe,KAAA,IAAY;IAChD,MAAM;cALV,CAMI,oBAAC,aAAD;KAAa,kBAAkB;KAC3B,WAAW;IAA0C,CAAA,GACxD,EAAE,aAAa,EAAE,MAAM,SAAS,QAAQ,YAAY,CAAC,CAAC,CAAC,YAAY,CAChD;;EACvB,CAAA,CACP,EAAA,CAAA;EAEF,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;GACA;EAAU,CAAA;CAE1B,EAAA,CAAA;AAGV"}
|
|
@@ -4,7 +4,7 @@ import { RelationPreview } from "../../preview/components/RelationPreview.js";
|
|
|
4
4
|
import { FieldHelperText } from "../components/FieldHelperText.js";
|
|
5
5
|
import { LabelWithIcon } from "../components/LabelWithIcon.js";
|
|
6
6
|
import { RelationSelector } from "../../components/RelationSelector.js";
|
|
7
|
-
import {
|
|
7
|
+
import { useEntitySelectionDialog } from "../../hooks/useSelectionDialog.js";
|
|
8
8
|
import { MultipleRelationFieldBinding } from "./MultipleRelationFieldBinding.js";
|
|
9
9
|
import { useCallback } from "react";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -80,7 +80,7 @@ function SingleRelationFieldBinding({ propertyKey, value, size, error, showError
|
|
|
80
80
|
const onSingleEntitySelected = useCallback((e) => {
|
|
81
81
|
setValue(e ? getRelationFrom(e) : null);
|
|
82
82
|
}, [setValue]);
|
|
83
|
-
const referenceDialogController =
|
|
83
|
+
const referenceDialogController = useEntitySelectionDialog({
|
|
84
84
|
multiselect: false,
|
|
85
85
|
path: getCollectionDataPath(collection),
|
|
86
86
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/RelationFieldBinding.tsx"],"sourcesContent":["import { useSelectionDialog } from \"../../hooks/useSelectionDialog\";\nimport type { FieldProps } from \"../../types/fields\";\nimport type { RelationProperty } from \"@rebasepro/types\";\nimport { Entity, getCollectionDataPath, getDataSourceCapabilities, Relation } from \"@rebasepro/types\";\nimport React, { useCallback } from \"react\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport { ErrorView, IconForView, useTranslation } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { getRelationFrom, normalizeToEntityRelation, resolveRelationProperty } from \"@rebasepro/common\";\nimport { cls } from \"@rebasepro/ui\";\nimport { RelationPreview } from \"../../preview\";\nimport { RelationSelector } from \"../../components/RelationSelector\";\nimport { MultipleRelationFieldBinding } from \"./MultipleRelationFieldBinding\";\n\nexport function RelationFieldBinding(props: FieldProps<RelationProperty>) {\n const { property, propertyKey, context } = props;\n\n if (property.type !== \"relation\") {\n throw Error(\"RelationFieldBinding expected a property containing a relation\");\n }\n const collection = context.collection;\n const capabilities = collection ? getDataSourceCapabilities(collection.engine) : undefined;\n // Only two things have to hold here: there is a collection, and its engine\n // has relations at all. Whether *this* property's relation can be resolved\n // is `resolveRelationProperty`'s question, and it answers it across all\n // three forms — a pre-stamped `resolvedRelation`, an inline `relation`, or\n // a lookup by name in the collection's `relations` array — with an error\n // naming the property and the collection when it cannot.\n //\n // This used to demand the `relations` array as well, which the inline form\n // does not produce. That is the documented way to declare a relation, so\n // every collection using it threw here and rendered the error boundary\n // instead of the field.\n if (!collection || !capabilities?.supportsRelations) {\n throw Error(\"RelationFieldBinding expected a collection whose engine supports relations\");\n }\n const resolvedProperty = resolveRelationProperty(property, collection, propertyKey);\n const relation = resolvedProperty;\n\n // A multi-hop `via` is read-only (`writable: false`): the server refuses a\n // write naming one (RELATION_NOT_WRITABLE), so its picker could only lead\n // to a failed save. Shown, not offered. A single-hop `via` is writable.\n const fieldProps = relation && !relation.writable ? { ...props, disabled: true } : props;\n\n const manyRelation = relation?.cardinality === \"many\";\n const widget = property.admin?.widget ?? \"select\";\n\n if (widget === \"select\" && relation) {\n return <RelationSelectorBinding {...fieldProps} relation={relation} manyRelation={manyRelation} />;\n }\n\n if (manyRelation) {\n return <MultipleRelationFieldBinding {...fieldProps} />;\n }\n\n return <SingleRelationFieldBinding {...fieldProps} relation={relation} />;\n}\n\nfunction RelationSelectorBinding({\n propertyKey,\n value,\n size,\n error,\n showError,\n disabled,\n isSubmitting,\n property,\n includeDescription,\n hideLabel,\n setValue,\n relation,\n manyRelation\n}: FieldProps<RelationProperty> & { relation: Relation; manyRelation: boolean }) {\n const normalizedSingle = (!manyRelation && value && !Array.isArray(value)) ? normalizeToEntityRelation(value) : null;\n const singleValue = normalizedSingle ?? null;\n const multipleValue = (manyRelation && Array.isArray(value)) ? value : [];\n\n // Passed straight through. Mapping the form's `large` onto the selector's\n // `medium` produced a 56px box next to 48px text fields — the labels lined\n // up and the boxes did not.\n const selectorSize = size;\n\n return (\n <div className=\"\">\n {!hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n <RelationSelector\n relation={relation}\n value={manyRelation ? multipleValue : singleValue}\n onValueChange={(newVal) => {\n if (manyRelation) {\n setValue(Array.isArray(newVal) ? newVal : []);\n } else {\n setValue(!Array.isArray(newVal) ? (newVal ?? null) : null);\n }\n }}\n disabled={disabled || isSubmitting}\n fixedFilter={property.admin?.fixedFilter}\n size={selectorSize}\n />\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n </div>\n );\n}\n\nfunction SingleRelationFieldBinding({\n propertyKey,\n value,\n size,\n error,\n showError,\n disabled,\n isSubmitting,\n property,\n includeDescription,\n hideLabel,\n setValue,\n relation\n}: FieldProps<RelationProperty> & { relation: Relation | undefined }) {\n const { t } = useTranslation();\n const normalizedValue = value && !Array.isArray(value) ? normalizeToEntityRelation(value) : null;\n const validValue = !!normalizedValue;\n\n const collection = relation?.target();\n\n if (!collection) {\n throw Error(`Couldn't find the corresponding collection for the relation: ${propertyKey}`);\n }\n\n const onSingleEntitySelected = useCallback((e: Entity<Record<string, unknown>> | null) => {\n setValue(e ? getRelationFrom(e) : null);\n }, [setValue]);\n\n const referenceDialogController = useSelectionDialog({\n multiselect: false,\n path: getCollectionDataPath(collection),\n collection,\n onSingleEntitySelected,\n selectedEntityIds: validValue && normalizedValue ? [normalizedValue.id] : undefined,\n fixedFilter: property.admin?.fixedFilter\n });\n\n const onEntryClick = (e: React.SyntheticEvent) => {\n e.preventDefault();\n if (disabled || isSubmitting) return;\n referenceDialogController.open();\n };\n\n const usedRelation = Array.isArray(value) ? undefined : normalizedValue ?? undefined;\n\n return (\n <>\n {!hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n {!collection && <ErrorView\n error={\"The specified collection does not exist. Check console\"}/>}\n\n {collection && <>\n\n {usedRelation && <RelationPreview\n disabled={!usedRelation}\n previewProperties={property.admin?.previewProperties}\n hover={!disabled}\n size={size}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n relation={usedRelation}\n includeEntityLink={property.admin?.includeEntityLink}\n includeId={property.admin?.includeId}\n />}\n\n {!value && <div className=\"justify-center text-left\">\n <EntityPreviewContainer className={cls(\"px-6 h-12 text-sm font-medium flex items-center gap-6\",\n disabled || isSubmitting\n ? \"text-surface-accent-500\"\n : \"cursor-pointer text-surface-accent-700 dark:text-surface-accent-300 hover:bg-surface-hover group-hover:bg-surface-hover\")}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n size={\"medium\"}>\n <IconForView collectionOrView={collection}\n className={\"text-surface-300 dark:text-surface-600\"}/>\n {t(\"edit_name\", { name: property.name ?? propertyKey }).toUpperCase()}\n </EntityPreviewContainer>\n </div>}\n </>}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,qBAAqB,OAAqC;CACtE,MAAM,EAAE,UAAU,aAAa,YAAY;CAE3C,IAAI,SAAS,SAAS,YAClB,MAAM,MAAM,gEAAgE;CAEhF,MAAM,aAAa,QAAQ;CAC3B,MAAM,eAAe,aAAa,0BAA0B,WAAW,MAAM,IAAI,KAAA;CAYjF,IAAI,CAAC,cAAc,CAAC,cAAc,mBAC9B,MAAM,MAAM,4EAA4E;CAG5F,MAAM,WADmB,wBAAwB,UAAU,YAAY,WACtD;CAKjB,MAAM,aAAa,YAAY,CAAC,SAAS,WAAW;EAAE,G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A,yHAAyH;IAC/H,SAAS,YAAY,eAAe,KAAA,IAAY;IAChD,MAAM;cALV,CAMI,oBAAC,aAAD;KAAa,kBAAkB;KAC3B,WAAW;IAA0C,CAAA,GACxD,EAAE,aAAa,EAAE,MAAM,SAAS,QAAQ,YAAY,CAAC,CAAC,CAAC,YAAY,CAChD;;EACvB,CAAA,CACP,EAAA,CAAA;EAEF,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;GACA;EAAU,CAAA;CAC1B,EAAA,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"RelationFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/RelationFieldBinding.tsx"],"sourcesContent":["import { useEntitySelectionDialog } from \"../../hooks/useSelectionDialog\";\nimport type { FieldProps } from \"../../types/fields\";\nimport type { RelationProperty } from \"@rebasepro/types\";\nimport { Entity, getCollectionDataPath, getDataSourceCapabilities, Relation } from \"@rebasepro/types\";\nimport React, { useCallback } from \"react\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport { ErrorView, IconForView, useTranslation } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { getRelationFrom, normalizeToEntityRelation, resolveRelationProperty } from \"@rebasepro/common\";\nimport { cls } from \"@rebasepro/ui\";\nimport { RelationPreview } from \"../../preview\";\nimport { RelationSelector } from \"../../components/RelationSelector\";\nimport { MultipleRelationFieldBinding } from \"./MultipleRelationFieldBinding\";\n\nexport function RelationFieldBinding(props: FieldProps<RelationProperty>) {\n const { property, propertyKey, context } = props;\n\n if (property.type !== \"relation\") {\n throw Error(\"RelationFieldBinding expected a property containing a relation\");\n }\n const collection = context.collection;\n const capabilities = collection ? getDataSourceCapabilities(collection.engine) : undefined;\n // Only two things have to hold here: there is a collection, and its engine\n // has relations at all. Whether *this* property's relation can be resolved\n // is `resolveRelationProperty`'s question, and it answers it across all\n // three forms — a pre-stamped `resolvedRelation`, an inline `relation`, or\n // a lookup by name in the collection's `relations` array — with an error\n // naming the property and the collection when it cannot.\n //\n // This used to demand the `relations` array as well, which the inline form\n // does not produce. That is the documented way to declare a relation, so\n // every collection using it threw here and rendered the error boundary\n // instead of the field.\n if (!collection || !capabilities?.supportsRelations) {\n throw Error(\"RelationFieldBinding expected a collection whose engine supports relations\");\n }\n const resolvedProperty = resolveRelationProperty(property, collection, propertyKey);\n const relation = resolvedProperty;\n\n // A multi-hop `via` is read-only (`writable: false`): the server refuses a\n // write naming one (RELATION_NOT_WRITABLE), so its picker could only lead\n // to a failed save. Shown, not offered. A single-hop `via` is writable.\n const fieldProps = relation && !relation.writable ? { ...props, disabled: true } : props;\n\n const manyRelation = relation?.cardinality === \"many\";\n const widget = property.admin?.widget ?? \"select\";\n\n if (widget === \"select\" && relation) {\n return <RelationSelectorBinding {...fieldProps} relation={relation} manyRelation={manyRelation} />;\n }\n\n if (manyRelation) {\n return <MultipleRelationFieldBinding {...fieldProps} />;\n }\n\n return <SingleRelationFieldBinding {...fieldProps} relation={relation} />;\n}\n\nfunction RelationSelectorBinding({\n propertyKey,\n value,\n size,\n error,\n showError,\n disabled,\n isSubmitting,\n property,\n includeDescription,\n hideLabel,\n setValue,\n relation,\n manyRelation\n}: FieldProps<RelationProperty> & { relation: Relation; manyRelation: boolean }) {\n const normalizedSingle = (!manyRelation && value && !Array.isArray(value)) ? normalizeToEntityRelation(value) : null;\n const singleValue = normalizedSingle ?? null;\n const multipleValue = (manyRelation && Array.isArray(value)) ? value : [];\n\n // Passed straight through. Mapping the form's `large` onto the selector's\n // `medium` produced a 56px box next to 48px text fields — the labels lined\n // up and the boxes did not.\n const selectorSize = size;\n\n return (\n <div className=\"\">\n {!hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n <RelationSelector\n relation={relation}\n value={manyRelation ? multipleValue : singleValue}\n onValueChange={(newVal) => {\n if (manyRelation) {\n setValue(Array.isArray(newVal) ? newVal : []);\n } else {\n setValue(!Array.isArray(newVal) ? (newVal ?? null) : null);\n }\n }}\n disabled={disabled || isSubmitting}\n fixedFilter={property.admin?.fixedFilter}\n size={selectorSize}\n />\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n </div>\n );\n}\n\nfunction SingleRelationFieldBinding({\n propertyKey,\n value,\n size,\n error,\n showError,\n disabled,\n isSubmitting,\n property,\n includeDescription,\n hideLabel,\n setValue,\n relation\n}: FieldProps<RelationProperty> & { relation: Relation | undefined }) {\n const { t } = useTranslation();\n const normalizedValue = value && !Array.isArray(value) ? normalizeToEntityRelation(value) : null;\n const validValue = !!normalizedValue;\n\n const collection = relation?.target();\n\n if (!collection) {\n throw Error(`Couldn't find the corresponding collection for the relation: ${propertyKey}`);\n }\n\n const onSingleEntitySelected = useCallback((e: Entity<Record<string, unknown>> | null) => {\n setValue(e ? getRelationFrom(e) : null);\n }, [setValue]);\n\n const referenceDialogController = useEntitySelectionDialog({\n multiselect: false,\n path: getCollectionDataPath(collection),\n collection,\n onSingleEntitySelected,\n selectedEntityIds: validValue && normalizedValue ? [normalizedValue.id] : undefined,\n fixedFilter: property.admin?.fixedFilter\n });\n\n const onEntryClick = (e: React.SyntheticEvent) => {\n e.preventDefault();\n if (disabled || isSubmitting) return;\n referenceDialogController.open();\n };\n\n const usedRelation = Array.isArray(value) ? undefined : normalizedValue ?? undefined;\n\n return (\n <>\n {!hideLabel && <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n {!collection && <ErrorView\n error={\"The specified collection does not exist. Check console\"}/>}\n\n {collection && <>\n\n {usedRelation && <RelationPreview\n disabled={!usedRelation}\n previewProperties={property.admin?.previewProperties}\n hover={!disabled}\n size={size}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n relation={usedRelation}\n includeEntityLink={property.admin?.includeEntityLink}\n includeId={property.admin?.includeId}\n />}\n\n {!value && <div className=\"justify-center text-left\">\n <EntityPreviewContainer className={cls(\"px-6 h-12 text-sm font-medium flex items-center gap-6\",\n disabled || isSubmitting\n ? \"text-surface-accent-500\"\n : \"cursor-pointer text-surface-accent-700 dark:text-surface-accent-300 hover:bg-surface-hover group-hover:bg-surface-hover\")}\n onClick={disabled || isSubmitting ? undefined : onEntryClick}\n size={\"medium\"}>\n <IconForView collectionOrView={collection}\n className={\"text-surface-300 dark:text-surface-600\"}/>\n {t(\"edit_name\", { name: property.name ?? propertyKey }).toUpperCase()}\n </EntityPreviewContainer>\n </div>}\n </>}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,qBAAqB,OAAqC;CACtE,MAAM,EAAE,UAAU,aAAa,YAAY;CAE3C,IAAI,SAAS,SAAS,YAClB,MAAM,MAAM,gEAAgE;CAEhF,MAAM,aAAa,QAAQ;CAC3B,MAAM,eAAe,aAAa,0BAA0B,WAAW,MAAM,IAAI,KAAA;CAYjF,IAAI,CAAC,cAAc,CAAC,cAAc,mBAC9B,MAAM,MAAM,4EAA4E;CAG5F,MAAM,WADmB,wBAAwB,UAAU,YAAY,WACtD;CAKjB,MAAM,aAAa,YAAY,CAAC,SAAS,WAAW;EAAE,GAAG;EAAO,UAAU;CAAK,IAAI;CAEnF,MAAM,eAAe,UAAU,gBAAgB;CAG/C,KAFe,SAAS,OAAO,UAAU,cAE1B,YAAY,UACvB,OAAO,oBAAC,yBAAD;EAAyB,GAAI;EAAsB;EAAwB;CAAe,CAAA;CAGrG,IAAI,cACA,OAAO,oBAAC,8BAAD,EAA8B,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ACP,EAAA,CAAA;EAEF,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;GACA;EAAU,CAAA;CAC1B,EAAA,CAAA;AAEV"}
|
|
@@ -24,7 +24,7 @@ function StorageUploadFieldBinding({ propertyKey, value, setValue, error, showEr
|
|
|
24
24
|
const disabled = isReadOnly(property) || isDisabled(property) || isSubmitting || context.disabled;
|
|
25
25
|
const { internalValue, setInternalValue, onFilesAdded, storage, onFileUploadComplete, storagePathBuilder, multipleFilesSupported, resolvedStorageSource } = useStorageUploadController({
|
|
26
26
|
entityValues: context.values,
|
|
27
|
-
entityId: context.
|
|
27
|
+
entityId: context.id,
|
|
28
28
|
path: context.path,
|
|
29
29
|
collectionSlug: context.collection?.slug,
|
|
30
30
|
property,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageUploadFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/StorageUploadFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { ArrayProperty, StringProperty } from \"@rebasepro/types\";\nimport React, { useCallback, useState } from \"react\";\n\nimport { StorageConfig } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useDropzone } from \"react-dropzone\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\n\nimport { isDisabled, isReadOnly } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { useAuthController, useSnackbarController, useStorageSource, useTranslation } from \"@rebasepro/app\";\nimport { StorageSourceContext } from \"@rebasepro/app\";\nimport {\n closestCenter,\n DndContext,\n DragEndEvent,\n DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors\n} from \"@dnd-kit/core\";\nimport {\n horizontalListSortingStrategy,\n SortableContext,\n sortableKeyboardCoordinates,\n useSortable\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport { StorageFieldItem, useStorageUploadController } from \"@rebasepro/app\";\nimport { StorageUploadProgress } from \"../components/StorageUploadProgress\";\nimport { StorageItemPreview } from \"../components/StorageItemPreview\";\nimport {\n cls,\n fieldBackgroundDisabledMixin,\n fieldBackgroundHoverMixin,\n fieldBackgroundMixin,\n Typography\n} from \"@rebasepro/ui\";\n\n// Height comes from the thumbnails now. It used to be a flat `min-h-[254px]`\n// on top of another 250px inside, so a field holding one small image\n// reserved close to 300px of the form for mostly empty space.\n// One fixed height for the whole zone — 126px of preview row, 34px of hint,\n// and the padding between. Pinned on the root rather than on the children\n// because the hint reflows once files exist (\"Drag to reorder\"), and any\n// content-driven height makes a filled field taller than the same field\n// empty. Extra thumbnails scroll horizontally instead of growing it.\nconst dropZoneClasses = \"box-border relative pt-[2px] h-[172px] items-center border border-transparent outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary\";\nconst disabledClasses = fieldBackgroundDisabledMixin;\nconst nonActiveDropClasses = fieldBackgroundHoverMixin\nconst activeDropClasses = \"pt-0 border-2 border-solid\"\nconst acceptDropClasses = \"transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500\"\nconst rejectDropClasses = \"transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500\"\n\nexport function StorageUploadFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n autoFocus,\n minimalistView,\n property,\n includeDescription,\n hideLabel,\n context,\n isSubmitting\n }: FieldProps<StringProperty | ArrayProperty>) {\n\n const authController = useAuthController();\n\n const storageSource = useStorageSource();\n const disabled = isReadOnly(property) || isDisabled(property) || isSubmitting || context.disabled;\n\n const {\n internalValue,\n setInternalValue,\n onFilesAdded,\n storage,\n onFileUploadComplete,\n storagePathBuilder,\n multipleFilesSupported,\n resolvedStorageSource\n } = useStorageUploadController({\n entityValues: context.values,\n entityId: context.entityId,\n path: context.path,\n collectionSlug: context.collection?.slug,\n property,\n propertyKey,\n value: value as string | string[] | null,\n storageSource,\n disabled: disabled ?? false,\n onChange: setValue\n });\n\n return (\n\n <>\n\n {!minimalistView && !hideLabel &&\n <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n <StorageSourceContext.Provider value={resolvedStorageSource}>\n <StorageUpload\n value={internalValue}\n name={propertyKey}\n disabled={disabled ?? false}\n autoFocus={autoFocus ?? false}\n property={property}\n onChange={setValue}\n setInternalValue={setInternalValue}\n onFilesAdded={onFilesAdded}\n onFileUploadComplete={onFileUploadComplete}\n storagePathBuilder={storagePathBuilder}\n storage={storage}\n multipleFilesSupported={multipleFilesSupported}/>\n </StorageSourceContext.Provider>\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n\ninterface SortableStorageItemProps {\n id: number;\n entry: StorageFieldItem;\n property: StringProperty;\n name: string;\n metadata?: Record<string, unknown>;\n storagePathBuilder: (file: File) => string;\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>;\n onClear: (clearedStoragePathOrDownloadUrl: string) => void;\n disabled: boolean;\n isSortable: boolean; // Kept for consistency, though dnd-kit handles sortability via context\n}\n\nfunction SortableStorageItem({\n id,\n entry,\n property,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n onClear,\n disabled\n }: SortableStorageItemProps) {\n\n const {\n attributes,\n listeners,\n setNodeRef,\n transform,\n transition,\n isDragging\n } = useSortable({ id });\n\n const style: React.CSSProperties = {\n transform: CSS.Transform.toString(transform),\n transition,\n zIndex: isDragging ? 100 : undefined\n };\n\n const getImageSizeNumber = (previewSize: PreviewSize): number => {\n switch (previewSize) {\n case \"small\":\n return 40;\n case \"medium\":\n return 118;\n case \"large\":\n return 220;\n default:\n return 118;\n }\n };\n\n let child: React.ReactNode;\n if (entry.storagePathOrDownloadUrl) {\n child = (\n <StorageItemPreview\n name={`storage_preview_${entry.storagePathOrDownloadUrl}`}\n property={property}\n disabled={disabled}\n value={entry.storagePathOrDownloadUrl}\n onRemove={() => onClear(entry.storagePathOrDownloadUrl!)}\n size={entry.size as PreviewSize}/>\n );\n } else if (entry.file) {\n child = (\n <StorageUploadProgress\n entry={entry}\n metadata={metadata}\n storagePath={storagePathBuilder(entry.file)}\n onFileUploadComplete={onFileUploadComplete}\n imageSize={getImageSizeNumber(entry.size as PreviewSize)}\n simple={false}\n />\n );\n }\n\n return (\n <div\n ref={setNodeRef}\n style={style}\n {...attributes}\n {...listeners}\n // No vertical margin: the strip already pads itself, and `m-1` made\n // each item 8px taller than the row's content box — enough to make a\n // field holding one image scroll vertically behind a hidden\n // scrollbar. `shrink-0` keeps thumbnails square once there are more\n // of them than fit across.\n className={cls(\"rounded-md shrink-0\")}\n tabIndex={-1}\n >\n {child}\n </div>\n );\n}\n\nfunction FileDropComponent({\n storage,\n disabled,\n onFilesAdded,\n multipleFilesSupported,\n autoFocus,\n internalValue,\n property,\n onClear,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n name,\n helpText,\n isDndItemDragging\n }: {\n storage: StorageConfig,\n disabled: boolean,\n onFilesAdded: (acceptedFiles: File[]) => Promise<void>,\n multipleFilesSupported: boolean,\n autoFocus: boolean,\n internalValue: StorageFieldItem[],\n property: StringProperty,\n onClear: (clearedStoragePathOrDownloadUrl: string) => void,\n metadata?: Record<string, unknown>,\n storagePathBuilder: (file: File) => string,\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>,\n name: string,\n helpText: string,\n isDndItemDragging?: boolean\n}) {\n\n const snackbarContext = useSnackbarController();\n\n const {\n getRootProps,\n getInputProps,\n isDragActive, // This is for files dragged from OS\n isDragAccept,\n isDragReject\n } = useDropzone({\n accept: storage.acceptedFiles ? storage.acceptedFiles.reduce((acc, ext) => ({\n ...acc,\n [ext]: []\n }), {}) : undefined,\n disabled: disabled || isDndItemDragging,\n // react-dropzone defaults to `multiple: true`, so a\n // `type: \"string\"` property with a storage config offered a picker\n // that took several files, uploaded the first, and never mentioned\n // the rest — one thumbnail, one 201, and the others gone without a\n // word. The field holds one path; the picker should ask for one.\n multiple: multipleFilesSupported,\n noDragEventsBubbling: true,\n maxSize: storage.maxSize,\n onDrop: onFilesAdded,\n onDropRejected: (fileRejections) => {\n for (const fileRejection of fileRejections) {\n for (const error of fileRejection.errors) {\n console.error(\"Error uploading file: \", error);\n if (error.code === \"file-too-large\") {\n snackbarContext.open({\n type: \"error\",\n message: `Error uploading file: File is larger than ${storage.maxSize} bytes`\n });\n } else if (error.code === \"file-invalid-type\") {\n snackbarContext.open({\n type: \"error\",\n message: \"Error uploading file: File type is not supported\"\n });\n }\n }\n }\n }\n }\n );\n\n return (\n <div\n {...getRootProps()}\n className={cls(\n fieldBackgroundMixin,\n disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,\n disabled ? \"text-surface-accent-600 dark:text-surface-accent-500\" : \"\",\n dropZoneClasses,\n multipleFilesSupported && internalValue.length ? \"\" : \"flex\",\n {\n [nonActiveDropClasses]: !isDragActive,\n [activeDropClasses]: isDragActive, // OS file drag active\n [rejectDropClasses]: isDragReject, // OS file drag reject\n [acceptDropClasses]: isDragAccept, // OS file drag accept\n [disabledClasses]: disabled || isDndItemDragging // Visually disable if internal drag\n })}\n >\n <div\n className={cls(\"flex items-center gap-2 p-1 px-3 no-scrollbar\",\n // Horizontal only. `overflow-auto` scrolls both axes, so any\n // pixel of vertical overflow turned the field into a\n // scrollable box with nothing visible to scroll to.\n multipleFilesSupported && internalValue.length ? \"overflow-x-auto overflow-y-hidden\" : \"\",\n // A fixed height, not a minimum: the 118px preview overflowed\n // a `min-h`, so a field with a file stood taller than the same\n // field empty. 126px is the preview plus its padding.\n \"h-[126px]\"\n )}\n >\n <input\n autoFocus={autoFocus}\n {...getInputProps()}/>\n\n {internalValue.map((entry) => (\n <SortableStorageItem\n key={entry.id}\n id={entry.id}\n entry={entry}\n property={property}\n name={name}\n metadata={metadata}\n storagePathBuilder={storagePathBuilder}\n onFileUploadComplete={onFileUploadComplete}\n onClear={onClear}\n disabled={disabled}\n isSortable={multipleFilesSupported}\n />\n ))}\n\n {/* Placeholder for empty dropzone text is handled by the outer Typography */}\n </div>\n\n <div\n // Two lines' worth, fixed: the hint gains \"Drag to reorder\" once\n // the field holds something, and a reflow there put the filled\n // state 25px taller than the empty one.\n className=\"box-border mx-3 mb-2.5 h-[34px] flex items-center justify-center text-center\">\n <Typography align={\"center\"}\n variant={\"caption\"}\n className={disabled ? \"text-surface-accent-600 dark:text-surface-accent-500\" : \"\"}>\n {helpText}\n </Typography>\n </div>\n </div>\n );\n}\n\nexport interface StorageUploadProps {\n value: StorageFieldItem[];\n setInternalValue: (v: StorageFieldItem[]) => void;\n name: string;\n property: StringProperty | ArrayProperty;\n onChange: (value: string | string[] | null) => void;\n multipleFilesSupported: boolean;\n autoFocus: boolean;\n disabled: boolean;\n storage: StorageConfig;\n onFilesAdded: (acceptedFiles: File[]) => Promise<void>; // Updated from useStorageUploadController\n storagePathBuilder: (file: File) => string;\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>;\n}\n\nexport function StorageUpload({\n property,\n name,\n value, // This is internalValue from useStorageUploadController\n setInternalValue,\n onChange,\n multipleFilesSupported,\n onFileUploadComplete,\n disabled,\n onFilesAdded,\n autoFocus,\n storage,\n storagePathBuilder\n }: StorageUploadProps) {\n\n if (multipleFilesSupported) {\n const arrayProperty = property as ArrayProperty;\n if (arrayProperty.of) {\n if (Array.isArray(arrayProperty.of)) {\n throw Error(\"Storage field using array must be of data type string\");\n }\n if (arrayProperty.of.type !== \"string\") {\n throw Error(\"Storage field using array must be of data type string\");\n }\n } else {\n throw Error(\"Storage field using array must be of data type string\");\n }\n }\n\n const metadata: Record<string, unknown> | undefined = storage?.metadata;\n const [isDndItemDragging, setIsDndItemDragging] = useState(false);\n\n const moveItem = useCallback((fromIndex: number, toIndex: number) => {\n if (!multipleFilesSupported || fromIndex === toIndex) return;\n const newValue = [...value];\n const item = newValue[fromIndex];\n newValue.splice(fromIndex, 1);\n newValue.splice(toIndex, 0, item);\n setInternalValue(newValue);\n const fieldValue = newValue\n .filter(e => !!e.storagePathOrDownloadUrl)\n .map(e => e.storagePathOrDownloadUrl as string);\n onChange(fieldValue);\n }, [multipleFilesSupported, onChange, setInternalValue, value]);\n\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5 // Start dragging after 5px movement\n }\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates\n })\n );\n\n const handleDragStart = useCallback((event: DragStartEvent) => {\n setIsDndItemDragging(true);\n }, []);\n\n const handleDragEnd = useCallback((event: DragEndEvent) => {\n setIsDndItemDragging(false);\n const {\n active,\n over\n } = event;\n if (over && active.id !== over.id) {\n const oldIndex = value.findIndex(item => item.id === active.id);\n const newIndex = value.findIndex(item => item.id === over.id);\n if (oldIndex !== -1 && newIndex !== -1) {\n moveItem(oldIndex, newIndex);\n }\n }\n }, [value, moveItem]);\n\n const onClear = useCallback((clearedStoragePathOrDownloadUrl: string) => {\n let newValue: StorageFieldItem[];\n if (multipleFilesSupported) {\n newValue = value.filter(v => v.storagePathOrDownloadUrl !== clearedStoragePathOrDownloadUrl);\n onChange(newValue.filter(v => !!v.storagePathOrDownloadUrl).map(v => v.storagePathOrDownloadUrl as string));\n } else {\n newValue = [];\n onChange(null);\n }\n setInternalValue(newValue);\n }, [value, multipleFilesSupported, onChange, setInternalValue]);\n\n const { t } = useTranslation();\n const helpText = multipleFilesSupported\n ? t(\"drag_drop_multiple\")\n : t(\"drag_drop_single\");\n\n const renderProperty: StringProperty = multipleFilesSupported\n ? (property as ArrayProperty).of as StringProperty\n : property as StringProperty;\n\n const fileDropProps = {\n storage,\n disabled,\n onFilesAdded,\n multipleFilesSupported,\n autoFocus,\n internalValue: value, // Pass current internalValue\n property: renderProperty,\n onClear,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n name,\n helpText,\n isDndItemDragging // Pass this down\n };\n\n if (multipleFilesSupported) {\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <SortableContext items={(value ?? []).map(v => v.id)} strategy={horizontalListSortingStrategy}>\n <FileDropComponent {...fileDropProps}/>\n </SortableContext>\n </DndContext>\n );\n } else {\n // For single file, no D&D context is needed\n return <FileDropComponent {...fileDropProps} isDndItemDragging={false}/>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAkDA,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AACxB,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAE1B,SAAgB,0BAA0B,EACI,aACA,OACA,UACA,OACA,WACA,WACA,gBACA,UACA,oBACA,WACA,SACA,gBAC2C;CAE9D,kBAAkB;CAEzC,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,WAAW,WAAW,QAAQ,KAAK,WAAW,QAAQ,KAAK,gBAAgB,QAAQ;CAEzF,MAAM,EACF,eACA,kBACA,cACA,SACA,sBACA,oBACA,wBACA,0BACA,2BAA2B;EAC3B,cAAc,QAAQ;EACtB,UAAU,QAAQ;EAClB,MAAM,QAAQ;EACd,gBAAgB,QAAQ,YAAY;EACpC;EACA;EACO;EACP;EACA,UAAU,YAAY;EACtB,UAAU;CACd,CAAC;CAED,OAEI,qBAAA,UAAA,EAAA,UAAA;EAEK,CAAC,kBAAkB,CAAC,aACjB,oBAAC,eAAD;GACiB;GACb,MAAM,mBAAmB,UAAU,OAAO;GAC1C,UAAU,SAAS,YAAY;GAC/B,OAAO,SAAS,QAAQ;GACxB,WAAW;EAAgE,CAAA;EAEnF,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AAO,KAAK,EAAE;GAC5D,IAAI,aAAa,MAAM,aAAa,IAChC,SAAS,UAAU,QAAQ;EAEnC;CACJ,GAAG,CAAC,OAAO,QAAQ,CAAC;CAEpB,MAAM,UAAU,aAAa,oCAA4C;EACrE,IAAI;EACJ,IAAI,wBAAwB;GACxB,WAAW,MAAM,QAAO,MAAK,EAAE,6BAA6B,+BAA+B;GAC3F,SAAS,SAAS,QAAO,MAAK,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC,KAAI,MAAK,EAAE,wBAAkC,CAAC;EAC9G,OAAO;GACH,WAAW,CAAC;GACZ,SAAS,IAAI;EACjB;EACA,iBAAiB,QAAQ;CAC7B,GAAG;EAAC;EAAO;EAAwB;EAAU;CAAgB,CAAC;CAE9D,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,WAAW,yBACX,EAAE,oBAAoB,IACtB,EAAE,kBAAkB;CAM1B,MAAM,gBAAgB;EAClB;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,UAXmC,yBAChC,SAA2B,KAC5B;EAUF;EACA;EACA;EACA;EACA;EACA;EACA;CACJ;CAEA,IAAI,wBACA,OACI,oBAAC,YAAD;EACa;EACT,oBAAoB;EACpB,aAAa;EACb,WAAW;YAEX,oBAAC,iBAAD;GAAiB,QAAQ,SAAS,CAAC,EAAA,CAAG,KAAI,MAAK,EAAE,EAAE;GAAG,UAAU;aAC5D,oBAAC,mBAAD,EAAmB,GAAI,cAAe,CAAA;EACzB,CAAA;CACT,CAAA;MAIhB,OAAO,oBAAC,mBAAD;EAAmB,GAAI;EAAe,mBAAmB;CAAO,CAAA;AAE/E"}
|
|
1
|
+
{"version":3,"file":"StorageUploadFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/StorageUploadFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { ArrayProperty, StringProperty } from \"@rebasepro/types\";\nimport React, { useCallback, useState } from \"react\";\n\nimport { StorageConfig } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useDropzone } from \"react-dropzone\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\n\nimport { isDisabled, isReadOnly } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { useAuthController, useSnackbarController, useStorageSource, useTranslation } from \"@rebasepro/app\";\nimport { StorageSourceContext } from \"@rebasepro/app\";\nimport {\n closestCenter,\n DndContext,\n DragEndEvent,\n DragStartEvent,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors\n} from \"@dnd-kit/core\";\nimport {\n horizontalListSortingStrategy,\n SortableContext,\n sortableKeyboardCoordinates,\n useSortable\n} from \"@dnd-kit/sortable\";\nimport { CSS } from \"@dnd-kit/utilities\";\nimport { StorageFieldItem, useStorageUploadController } from \"@rebasepro/app\";\nimport { StorageUploadProgress } from \"../components/StorageUploadProgress\";\nimport { StorageItemPreview } from \"../components/StorageItemPreview\";\nimport {\n cls,\n fieldBackgroundDisabledMixin,\n fieldBackgroundHoverMixin,\n fieldBackgroundMixin,\n Typography\n} from \"@rebasepro/ui\";\n\n// Height comes from the thumbnails now. It used to be a flat `min-h-[254px]`\n// on top of another 250px inside, so a field holding one small image\n// reserved close to 300px of the form for mostly empty space.\n// One fixed height for the whole zone — 126px of preview row, 34px of hint,\n// and the padding between. Pinned on the root rather than on the children\n// because the hint reflows once files exist (\"Drag to reorder\"), and any\n// content-driven height makes a filled field taller than the same field\n// empty. Extra thumbnails scroll horizontally instead of growing it.\nconst dropZoneClasses = \"box-border relative pt-[2px] h-[172px] items-center border border-transparent outline-none rounded-md duration-200 ease-[cubic-bezier(0.4,0,0.2,1)] focus:border-primary\";\nconst disabledClasses = fieldBackgroundDisabledMixin;\nconst nonActiveDropClasses = fieldBackgroundHoverMixin\nconst activeDropClasses = \"pt-0 border-2 border-solid\"\nconst acceptDropClasses = \"transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-green-500\"\nconst rejectDropClasses = \"transition-colors duration-200 ease-[cubic-bezier(0,0,0.2,1)] border-2 border-solid border-red-500\"\n\nexport function StorageUploadFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n autoFocus,\n minimalistView,\n property,\n includeDescription,\n hideLabel,\n context,\n isSubmitting\n }: FieldProps<StringProperty | ArrayProperty>) {\n\n const authController = useAuthController();\n\n const storageSource = useStorageSource();\n const disabled = isReadOnly(property) || isDisabled(property) || isSubmitting || context.disabled;\n\n const {\n internalValue,\n setInternalValue,\n onFilesAdded,\n storage,\n onFileUploadComplete,\n storagePathBuilder,\n multipleFilesSupported,\n resolvedStorageSource\n } = useStorageUploadController({\n entityValues: context.values,\n entityId: context.id,\n path: context.path,\n collectionSlug: context.collection?.slug,\n property,\n propertyKey,\n value: value as string | string[] | null,\n storageSource,\n disabled: disabled ?? false,\n onChange: setValue\n });\n\n return (\n\n <>\n\n {!minimalistView && !hideLabel &&\n <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 text-text-secondary dark:text-text-secondary-dark ml-3.5\"}/>}\n\n <StorageSourceContext.Provider value={resolvedStorageSource}>\n <StorageUpload\n value={internalValue}\n name={propertyKey}\n disabled={disabled ?? false}\n autoFocus={autoFocus ?? false}\n property={property}\n onChange={setValue}\n setInternalValue={setInternalValue}\n onFilesAdded={onFilesAdded}\n onFileUploadComplete={onFileUploadComplete}\n storagePathBuilder={storagePathBuilder}\n storage={storage}\n multipleFilesSupported={multipleFilesSupported}/>\n </StorageSourceContext.Provider>\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n\ninterface SortableStorageItemProps {\n id: number;\n entry: StorageFieldItem;\n property: StringProperty;\n name: string;\n metadata?: Record<string, unknown>;\n storagePathBuilder: (file: File) => string;\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>;\n onClear: (clearedStoragePathOrDownloadUrl: string) => void;\n disabled: boolean;\n isSortable: boolean; // Kept for consistency, though dnd-kit handles sortability via context\n}\n\nfunction SortableStorageItem({\n id,\n entry,\n property,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n onClear,\n disabled\n }: SortableStorageItemProps) {\n\n const {\n attributes,\n listeners,\n setNodeRef,\n transform,\n transition,\n isDragging\n } = useSortable({ id });\n\n const style: React.CSSProperties = {\n transform: CSS.Transform.toString(transform),\n transition,\n zIndex: isDragging ? 100 : undefined\n };\n\n const getImageSizeNumber = (previewSize: PreviewSize): number => {\n switch (previewSize) {\n case \"small\":\n return 40;\n case \"medium\":\n return 118;\n case \"large\":\n return 220;\n default:\n return 118;\n }\n };\n\n let child: React.ReactNode;\n if (entry.storagePathOrDownloadUrl) {\n child = (\n <StorageItemPreview\n name={`storage_preview_${entry.storagePathOrDownloadUrl}`}\n property={property}\n disabled={disabled}\n value={entry.storagePathOrDownloadUrl}\n onRemove={() => onClear(entry.storagePathOrDownloadUrl!)}\n size={entry.size as PreviewSize}/>\n );\n } else if (entry.file) {\n child = (\n <StorageUploadProgress\n entry={entry}\n metadata={metadata}\n storagePath={storagePathBuilder(entry.file)}\n onFileUploadComplete={onFileUploadComplete}\n imageSize={getImageSizeNumber(entry.size as PreviewSize)}\n simple={false}\n />\n );\n }\n\n return (\n <div\n ref={setNodeRef}\n style={style}\n {...attributes}\n {...listeners}\n // No vertical margin: the strip already pads itself, and `m-1` made\n // each item 8px taller than the row's content box — enough to make a\n // field holding one image scroll vertically behind a hidden\n // scrollbar. `shrink-0` keeps thumbnails square once there are more\n // of them than fit across.\n className={cls(\"rounded-md shrink-0\")}\n tabIndex={-1}\n >\n {child}\n </div>\n );\n}\n\nfunction FileDropComponent({\n storage,\n disabled,\n onFilesAdded,\n multipleFilesSupported,\n autoFocus,\n internalValue,\n property,\n onClear,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n name,\n helpText,\n isDndItemDragging\n }: {\n storage: StorageConfig,\n disabled: boolean,\n onFilesAdded: (acceptedFiles: File[]) => Promise<void>,\n multipleFilesSupported: boolean,\n autoFocus: boolean,\n internalValue: StorageFieldItem[],\n property: StringProperty,\n onClear: (clearedStoragePathOrDownloadUrl: string) => void,\n metadata?: Record<string, unknown>,\n storagePathBuilder: (file: File) => string,\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>,\n name: string,\n helpText: string,\n isDndItemDragging?: boolean\n}) {\n\n const snackbarContext = useSnackbarController();\n\n const {\n getRootProps,\n getInputProps,\n isDragActive, // This is for files dragged from OS\n isDragAccept,\n isDragReject\n } = useDropzone({\n accept: storage.acceptedFiles ? storage.acceptedFiles.reduce((acc, ext) => ({\n ...acc,\n [ext]: []\n }), {}) : undefined,\n disabled: disabled || isDndItemDragging,\n // react-dropzone defaults to `multiple: true`, so a\n // `type: \"string\"` property with a storage config offered a picker\n // that took several files, uploaded the first, and never mentioned\n // the rest — one thumbnail, one 201, and the others gone without a\n // word. The field holds one path; the picker should ask for one.\n multiple: multipleFilesSupported,\n noDragEventsBubbling: true,\n maxSize: storage.maxSize,\n onDrop: onFilesAdded,\n onDropRejected: (fileRejections) => {\n for (const fileRejection of fileRejections) {\n for (const error of fileRejection.errors) {\n console.error(\"Error uploading file: \", error);\n if (error.code === \"file-too-large\") {\n snackbarContext.open({\n type: \"error\",\n message: `Error uploading file: File is larger than ${storage.maxSize} bytes`\n });\n } else if (error.code === \"file-invalid-type\") {\n snackbarContext.open({\n type: \"error\",\n message: \"Error uploading file: File type is not supported\"\n });\n }\n }\n }\n }\n }\n );\n\n return (\n <div\n {...getRootProps()}\n className={cls(\n fieldBackgroundMixin,\n disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,\n disabled ? \"text-surface-accent-600 dark:text-surface-accent-500\" : \"\",\n dropZoneClasses,\n multipleFilesSupported && internalValue.length ? \"\" : \"flex\",\n {\n [nonActiveDropClasses]: !isDragActive,\n [activeDropClasses]: isDragActive, // OS file drag active\n [rejectDropClasses]: isDragReject, // OS file drag reject\n [acceptDropClasses]: isDragAccept, // OS file drag accept\n [disabledClasses]: disabled || isDndItemDragging // Visually disable if internal drag\n })}\n >\n <div\n className={cls(\"flex items-center gap-2 p-1 px-3 no-scrollbar\",\n // Horizontal only. `overflow-auto` scrolls both axes, so any\n // pixel of vertical overflow turned the field into a\n // scrollable box with nothing visible to scroll to.\n multipleFilesSupported && internalValue.length ? \"overflow-x-auto overflow-y-hidden\" : \"\",\n // A fixed height, not a minimum: the 118px preview overflowed\n // a `min-h`, so a field with a file stood taller than the same\n // field empty. 126px is the preview plus its padding.\n \"h-[126px]\"\n )}\n >\n <input\n autoFocus={autoFocus}\n {...getInputProps()}/>\n\n {internalValue.map((entry) => (\n <SortableStorageItem\n key={entry.id}\n id={entry.id}\n entry={entry}\n property={property}\n name={name}\n metadata={metadata}\n storagePathBuilder={storagePathBuilder}\n onFileUploadComplete={onFileUploadComplete}\n onClear={onClear}\n disabled={disabled}\n isSortable={multipleFilesSupported}\n />\n ))}\n\n {/* Placeholder for empty dropzone text is handled by the outer Typography */}\n </div>\n\n <div\n // Two lines' worth, fixed: the hint gains \"Drag to reorder\" once\n // the field holds something, and a reflow there put the filled\n // state 25px taller than the empty one.\n className=\"box-border mx-3 mb-2.5 h-[34px] flex items-center justify-center text-center\">\n <Typography align={\"center\"}\n variant={\"caption\"}\n className={disabled ? \"text-surface-accent-600 dark:text-surface-accent-500\" : \"\"}>\n {helpText}\n </Typography>\n </div>\n </div>\n );\n}\n\nexport interface StorageUploadProps {\n value: StorageFieldItem[];\n setInternalValue: (v: StorageFieldItem[]) => void;\n name: string;\n property: StringProperty | ArrayProperty;\n onChange: (value: string | string[] | null) => void;\n multipleFilesSupported: boolean;\n autoFocus: boolean;\n disabled: boolean;\n storage: StorageConfig;\n onFilesAdded: (acceptedFiles: File[]) => Promise<void>; // Updated from useStorageUploadController\n storagePathBuilder: (file: File) => string;\n onFileUploadComplete: (uploadedPath: string, entry: StorageFieldItem, fileMetadata?: Record<string, unknown>) => Promise<void>;\n}\n\nexport function StorageUpload({\n property,\n name,\n value, // This is internalValue from useStorageUploadController\n setInternalValue,\n onChange,\n multipleFilesSupported,\n onFileUploadComplete,\n disabled,\n onFilesAdded,\n autoFocus,\n storage,\n storagePathBuilder\n }: StorageUploadProps) {\n\n if (multipleFilesSupported) {\n const arrayProperty = property as ArrayProperty;\n if (arrayProperty.of) {\n if (Array.isArray(arrayProperty.of)) {\n throw Error(\"Storage field using array must be of data type string\");\n }\n if (arrayProperty.of.type !== \"string\") {\n throw Error(\"Storage field using array must be of data type string\");\n }\n } else {\n throw Error(\"Storage field using array must be of data type string\");\n }\n }\n\n const metadata: Record<string, unknown> | undefined = storage?.metadata;\n const [isDndItemDragging, setIsDndItemDragging] = useState(false);\n\n const moveItem = useCallback((fromIndex: number, toIndex: number) => {\n if (!multipleFilesSupported || fromIndex === toIndex) return;\n const newValue = [...value];\n const item = newValue[fromIndex];\n newValue.splice(fromIndex, 1);\n newValue.splice(toIndex, 0, item);\n setInternalValue(newValue);\n const fieldValue = newValue\n .filter(e => !!e.storagePathOrDownloadUrl)\n .map(e => e.storagePathOrDownloadUrl as string);\n onChange(fieldValue);\n }, [multipleFilesSupported, onChange, setInternalValue, value]);\n\n const sensors = useSensors(\n useSensor(PointerSensor, {\n activationConstraint: {\n distance: 5 // Start dragging after 5px movement\n }\n }),\n useSensor(KeyboardSensor, {\n coordinateGetter: sortableKeyboardCoordinates\n })\n );\n\n const handleDragStart = useCallback((event: DragStartEvent) => {\n setIsDndItemDragging(true);\n }, []);\n\n const handleDragEnd = useCallback((event: DragEndEvent) => {\n setIsDndItemDragging(false);\n const {\n active,\n over\n } = event;\n if (over && active.id !== over.id) {\n const oldIndex = value.findIndex(item => item.id === active.id);\n const newIndex = value.findIndex(item => item.id === over.id);\n if (oldIndex !== -1 && newIndex !== -1) {\n moveItem(oldIndex, newIndex);\n }\n }\n }, [value, moveItem]);\n\n const onClear = useCallback((clearedStoragePathOrDownloadUrl: string) => {\n let newValue: StorageFieldItem[];\n if (multipleFilesSupported) {\n newValue = value.filter(v => v.storagePathOrDownloadUrl !== clearedStoragePathOrDownloadUrl);\n onChange(newValue.filter(v => !!v.storagePathOrDownloadUrl).map(v => v.storagePathOrDownloadUrl as string));\n } else {\n newValue = [];\n onChange(null);\n }\n setInternalValue(newValue);\n }, [value, multipleFilesSupported, onChange, setInternalValue]);\n\n const { t } = useTranslation();\n const helpText = multipleFilesSupported\n ? t(\"drag_drop_multiple\")\n : t(\"drag_drop_single\");\n\n const renderProperty: StringProperty = multipleFilesSupported\n ? (property as ArrayProperty).of as StringProperty\n : property as StringProperty;\n\n const fileDropProps = {\n storage,\n disabled,\n onFilesAdded,\n multipleFilesSupported,\n autoFocus,\n internalValue: value, // Pass current internalValue\n property: renderProperty,\n onClear,\n metadata,\n storagePathBuilder,\n onFileUploadComplete,\n name,\n helpText,\n isDndItemDragging // Pass this down\n };\n\n if (multipleFilesSupported) {\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragStart={handleDragStart}\n onDragEnd={handleDragEnd}\n >\n <SortableContext items={(value ?? []).map(v => v.id)} strategy={horizontalListSortingStrategy}>\n <FileDropComponent {...fileDropProps}/>\n </SortableContext>\n </DndContext>\n );\n } else {\n // For single file, no D&D context is needed\n return <FileDropComponent {...fileDropProps} isDndItemDragging={false}/>;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAkDA,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AACxB,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAE1B,SAAgB,0BAA0B,EACI,aACA,OACA,UACA,OACA,WACA,WACA,gBACA,UACA,oBACA,WACA,SACA,gBAC2C;CAE9D,kBAAkB;CAEz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AAC,YAAD;EACa;EACT,oBAAoB;EACpB,aAAa;EACb,WAAW;YAEX,oBAAC,iBAAD;GAAiB,QAAQ,SAAS,CAAC,EAAA,CAAG,KAAI,MAAK,EAAE,EAAE;GAAG,UAAU;aAC5D,oBAAC,mBAAD,EAAmB,GAAI,cAAe,CAAA;EACzB,CAAA;CACT,CAAA;MAIhB,OAAO,oBAAC,mBAAD;EAAmB,GAAI;EAAe,mBAAmB;CAAO,CAAA;AAE/E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The DOM ids a record form gives its fields and sections, unique per form.
|
|
4
|
+
*
|
|
5
|
+
* Two forms on one page — a record and the record it links to, a form in a
|
|
6
|
+
* dialog over another — each drew `form_field_title`, and an id that is not
|
|
7
|
+
* unique sends a label, an `aria-controls` or a scroll-to-error to the wrong
|
|
8
|
+
* form. Each form takes a scope of its own and every id under it carries it.
|
|
9
|
+
*
|
|
10
|
+
* Ids are for the page's own wiring. To find a field from outside — a test, an
|
|
11
|
+
* e2e script — select by the attributes, which stay the same in every form:
|
|
12
|
+
* `[data-form-field="<key>"]` inside `[data-form-path="<path>"]`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const FormDomScopeContext: React.Context<string | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* The scope of the form this renders in, or one of the caller's own outside
|
|
17
|
+
* any form (the read-only view of a record draws the same blocks).
|
|
18
|
+
*/
|
|
19
|
+
export declare function useFormDomScope(): string;
|
|
20
|
+
/** A `useId` value as an id fragment: no characters a CSS selector would need escaped. */
|
|
21
|
+
export declare function domScopeFromId(id: string): string;
|
|
22
|
+
export declare function fieldDomId(scope: string, propertyKey: string): string;
|
|
23
|
+
export declare function sectionDomId(scope: string, sectionKey: string): string;
|
|
24
|
+
/** The selector for one field's block, by its key, in any form. */
|
|
25
|
+
export declare function fieldSelector(propertyKey: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useContext, useId } from "react";
|
|
2
|
+
//#region src/form/form_dom_ids.ts
|
|
3
|
+
/**
|
|
4
|
+
* The DOM ids a record form gives its fields and sections, unique per form.
|
|
5
|
+
*
|
|
6
|
+
* Two forms on one page — a record and the record it links to, a form in a
|
|
7
|
+
* dialog over another — each drew `form_field_title`, and an id that is not
|
|
8
|
+
* unique sends a label, an `aria-controls` or a scroll-to-error to the wrong
|
|
9
|
+
* form. Each form takes a scope of its own and every id under it carries it.
|
|
10
|
+
*
|
|
11
|
+
* Ids are for the page's own wiring. To find a field from outside — a test, an
|
|
12
|
+
* e2e script — select by the attributes, which stay the same in every form:
|
|
13
|
+
* `[data-form-field="<key>"]` inside `[data-form-path="<path>"]`.
|
|
14
|
+
*/
|
|
15
|
+
var FormDomScopeContext = React.createContext(void 0);
|
|
16
|
+
/**
|
|
17
|
+
* The scope of the form this renders in, or one of the caller's own outside
|
|
18
|
+
* any form (the read-only view of a record draws the same blocks).
|
|
19
|
+
*/
|
|
20
|
+
function useFormDomScope() {
|
|
21
|
+
const scope = useContext(FormDomScopeContext);
|
|
22
|
+
const own = useId();
|
|
23
|
+
return scope ?? domScopeFromId(own);
|
|
24
|
+
}
|
|
25
|
+
/** A `useId` value as an id fragment: no characters a CSS selector would need escaped. */
|
|
26
|
+
function domScopeFromId(id) {
|
|
27
|
+
return "form" + id.replace(/[^a-zA-Z0-9_-]/g, "");
|
|
28
|
+
}
|
|
29
|
+
function fieldDomId(scope, propertyKey) {
|
|
30
|
+
return `${scope}_field_${propertyKey}`;
|
|
31
|
+
}
|
|
32
|
+
function sectionDomId(scope, sectionKey) {
|
|
33
|
+
return `${scope}_section_${sectionKey}`;
|
|
34
|
+
}
|
|
35
|
+
/** The selector for one field's block, by its key, in any form. */
|
|
36
|
+
function fieldSelector(propertyKey) {
|
|
37
|
+
return `[data-form-field="${propertyKey.replace(/["\\]/g, "\\$&")}"]`;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { FormDomScopeContext, domScopeFromId, fieldDomId, fieldSelector, sectionDomId, useFormDomScope };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=form_dom_ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form_dom_ids.js","names":[],"sources":["../../src/form/form_dom_ids.ts"],"sourcesContent":["import React, { useContext, useId } from \"react\";\n\n/**\n * The DOM ids a record form gives its fields and sections, unique per form.\n *\n * Two forms on one page — a record and the record it links to, a form in a\n * dialog over another — each drew `form_field_title`, and an id that is not\n * unique sends a label, an `aria-controls` or a scroll-to-error to the wrong\n * form. Each form takes a scope of its own and every id under it carries it.\n *\n * Ids are for the page's own wiring. To find a field from outside — a test, an\n * e2e script — select by the attributes, which stay the same in every form:\n * `[data-form-field=\"<key>\"]` inside `[data-form-path=\"<path>\"]`.\n */\nexport const FormDomScopeContext = React.createContext<string | undefined>(undefined);\n\n/**\n * The scope of the form this renders in, or one of the caller's own outside\n * any form (the read-only view of a record draws the same blocks).\n */\nexport function useFormDomScope(): string {\n const scope = useContext(FormDomScopeContext);\n const own = useId();\n return scope ?? domScopeFromId(own);\n}\n\n/** A `useId` value as an id fragment: no characters a CSS selector would need escaped. */\nexport function domScopeFromId(id: string): string {\n return \"form\" + id.replace(/[^a-zA-Z0-9_-]/g, \"\");\n}\n\nexport function fieldDomId(scope: string, propertyKey: string): string {\n return `${scope}_field_${propertyKey}`;\n}\n\nexport function sectionDomId(scope: string, sectionKey: string): string {\n return `${scope}_section_${sectionKey}`;\n}\n\n/** The selector for one field's block, by its key, in any form. */\nexport function fieldSelector(propertyKey: string): string {\n return `[data-form-field=\"${propertyKey.replace(/[\"\\\\]/g, \"\\\\$&\")}\"]`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,IAAa,sBAAsB,MAAM,cAAkC,KAAA,CAAS;;;;;AAMpF,SAAgB,kBAA0B;CACtC,MAAM,QAAQ,WAAW,mBAAmB;CAC5C,MAAM,MAAM,MAAM;CAClB,OAAO,SAAS,eAAe,GAAG;AACtC;;AAGA,SAAgB,eAAe,IAAoB;CAC/C,OAAO,SAAS,GAAG,QAAQ,mBAAmB,EAAE;AACpD;AAEA,SAAgB,WAAW,OAAe,aAA6B;CACnE,OAAO,GAAG,MAAM,SAAS;AAC7B;AAEA,SAAgB,aAAa,OAAe,YAA4B;CACpE,OAAO,GAAG,MAAM,WAAW;AAC/B;;AAGA,SAAgB,cAAc,aAA6B;CACvD,OAAO,qBAAqB,YAAY,QAAQ,UAAU,MAAM,EAAE;AACtE"}
|
package/dist/form/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { EntityForm } from "./EntityForm.js";
|
|
2
|
-
export type { EntityFormProps,
|
|
2
|
+
export type { EntityFormProps, OnSavedParams } from "../types/components/EntityFormProps.js";
|
|
3
3
|
export { EntityFormBinding } from "./EntityFormBinding.js";
|
|
4
4
|
export type { EntityFormBindingProps } from "./EntityFormBinding.js";
|
|
5
5
|
export { SelectFieldBinding } from "./field_bindings/SelectFieldBinding.js";
|
|
@@ -20,5 +20,7 @@ export { ArrayCustomShapedFieldBinding } from "./field_bindings/ArrayCustomShape
|
|
|
20
20
|
export { VectorFieldBinding } from "./field_bindings/VectorFieldBinding.js";
|
|
21
21
|
export * from "./components/index.js";
|
|
22
22
|
export { PropertyFieldBinding } from "./PropertyFieldBinding.js";
|
|
23
|
+
export { FormField } from "./FormField.js";
|
|
24
|
+
export type { FormFieldProps } from "./FormField.js";
|
|
23
25
|
export * from "./useClearRestoreValue.js";
|
|
24
26
|
export { extractTouchedValues, removeEmptyContainers, getChanges, getInitialEntityValues, zodToFormErrors, getParentLinkValues, getTouchedPropertyValues, getUnappliedLocalChanges, overlayEdit } from "./form_utils.js";
|
|
@@ -24,6 +24,11 @@ export declare function resolveCellProperty(property: Property, propertyKey: str
|
|
|
24
24
|
* would block the save where no one could see it.
|
|
25
25
|
*/
|
|
26
26
|
export declare function propertiesOfCell(properties: Properties, propertyKey: string): Properties;
|
|
27
|
+
/**
|
|
28
|
+
* The properties that judge a form showing only `keys`: each key's property as
|
|
29
|
+
* {@link propertiesOfCell} cuts it, two children of one map under one map.
|
|
30
|
+
*/
|
|
31
|
+
export declare function propertiesOfFields(properties: Properties, keys: Iterable<string>): Properties;
|
|
27
32
|
/**
|
|
28
33
|
* What the popup judges a cell by, given the values it holds now: the
|
|
29
34
|
* collection's properties resolved as the record form resolves them on submit
|
|
@@ -59,6 +59,27 @@ function propertiesOfCell(properties, propertyKey) {
|
|
|
59
59
|
} } : {};
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
+
* The properties that judge a form showing only `keys`: each key's property as
|
|
63
|
+
* {@link propertiesOfCell} cuts it, two children of one map under one map.
|
|
64
|
+
*/
|
|
65
|
+
function propertiesOfFields(properties, keys) {
|
|
66
|
+
let result = {};
|
|
67
|
+
for (const key of keys) result = mergeProperties(result, propertiesOfCell(properties, key));
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function mergeProperties(a, b) {
|
|
71
|
+
const merged = { ...a };
|
|
72
|
+
for (const [key, property] of Object.entries(b)) {
|
|
73
|
+
const existing = merged[key];
|
|
74
|
+
merged[key] = existing?.type === "map" && property.type === "map" && existing !== property ? {
|
|
75
|
+
...existing,
|
|
76
|
+
...property,
|
|
77
|
+
properties: mergeProperties(existing.properties ?? {}, property.properties ?? {})
|
|
78
|
+
} : property;
|
|
79
|
+
}
|
|
80
|
+
return merged;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
62
83
|
* What the popup judges a cell by, given the values it holds now: the
|
|
63
84
|
* collection's properties resolved as the record form resolves them on submit
|
|
64
85
|
* (so a field a rule hides or disables is not judged), cut to the cell.
|
|
@@ -75,6 +96,6 @@ function cellValidationProperties(properties, propertyKey, values, previousValue
|
|
|
75
96
|
}), propertyKey);
|
|
76
97
|
}
|
|
77
98
|
//#endregion
|
|
78
|
-
export { cellValidationProperties, propertiesOfCell, resolveCellProperty };
|
|
99
|
+
export { cellValidationProperties, propertiesOfCell, propertiesOfFields, resolveCellProperty };
|
|
79
100
|
|
|
80
101
|
//# sourceMappingURL=resolve_cell_property.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve_cell_property.js","names":[],"sources":["../../src/form/resolve_cell_property.ts"],"sourcesContent":["import type { AuthController, PropertyConfig } from \"@rebasepro/cms-types\";\nimport type { Entity, Properties, Property } from \"@rebasepro/types\";\nimport { isPropertyBuilder } from \"@rebasepro/common\";\nimport { resolveFormProperty, resolvePropertiesForValidation } from \"./resolve_form_properties\";\n\n/**\n * The table's two editors — the inline cell and the popup — judged a value\n * against the raw declaration, as the record form once did: a `dynamicProps`\n * validation or a `conditions` rule (`disabled`, `min`, `required`…) applied\n * in the form and nowhere in the table. These resolve a cell's property\n * against its own row, with the record form's {@link resolveFormProperty}.\n */\nexport interface CellResolutionContext {\n path: string;\n authController: AuthController;\n propertyConfigs?: Record<string, PropertyConfig>;\n}\n\n/**\n * Resolved per row, and held as long as the row object is: a column of plain\n * properties keeps its property object (and so its cached schema and its\n * memoised cells); only a builder or a property with `conditions` is resolved,\n * once per row value.\n */\nconst resolvedByRow = new WeakMap<object, Map<string, { raw: Property; resolved: Property | null }>>();\n\nexport function resolveCellProperty(\n property: Property,\n propertyKey: string,\n entity: Entity<Record<string, unknown>>,\n context: CellResolutionContext\n): Property | null {\n if (!isPropertyBuilder(property) && !property.conditions) return property;\n const rowKey: object = entity.values ?? entity;\n let byKey = resolvedByRow.get(rowKey);\n if (!byKey) {\n byKey = new Map();\n resolvedByRow.set(rowKey, byKey);\n }\n const cached = byKey.get(propertyKey);\n if (cached && cached.raw === property) return cached.resolved;\n const resolved = resolveFormProperty({\n property,\n propertyKey,\n values: entity.values,\n previousValues: entity.values,\n path: context.path,\n entityId: entity.id,\n propertyConfigs: context.propertyConfigs,\n authController: context.authController,\n ignoreMissingFields: true\n });\n byKey.set(propertyKey, { raw: property, resolved });\n return resolved;\n}\n\n/**\n * The properties that judge one cell: the property at `propertyKey`, under the\n * maps its key goes through, and nothing beside it.\n *\n * A spread map's child is `address.street`, a path into `properties` rather\n * than a key of it; looked up as a key it found nothing, and the popup\n * validated nothing. The maps on the way carry only the edited child and none\n * of their own rules: the popup shows one field, and an error anywhere else\n * would block the save where no one could see it.\n */\nexport function propertiesOfCell(properties: Properties, propertyKey: string): Properties {\n if (propertyKey in properties) return { [propertyKey]: properties[propertyKey] };\n const dot = propertyKey.indexOf(\".\");\n if (dot === -1) return {};\n const mapKey = propertyKey.slice(0, dot);\n const map = properties[mapKey];\n if (map?.type !== \"map\" || !map.properties) return {};\n const children = propertiesOfCell(map.properties, propertyKey.slice(dot + 1));\n return Object.keys(children).length > 0\n ? { [mapKey]: { type: \"map\", properties: children } }\n : {};\n}\n\n/**\n * What the popup judges a cell by, given the values it holds now: the\n * collection's properties resolved as the record form resolves them on submit\n * (so a field a rule hides or disables is not judged), cut to the cell.\n */\nexport function cellValidationProperties<M extends Record<string, unknown>>(\n properties: Properties,\n propertyKey: string,\n values: Partial<M>,\n previousValues: Partial<M> | undefined,\n entityId: string | number | undefined,\n context: CellResolutionContext\n): Properties {\n const resolved = resolvePropertiesForValidation<M>({\n properties,\n values,\n previousValues,\n path: context.path,\n entityId,\n propertyConfigs: context.propertyConfigs,\n authController: context.authController\n });\n return propertiesOfCell(resolved, propertyKey);\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,gCAAgB,IAAI,QAA2E;AAErG,SAAgB,oBACZ,UACA,aACA,QACA,SACe;CACf,IAAI,CAAC,kBAAkB,QAAQ,KAAK,CAAC,SAAS,YAAY,OAAO;CACjE,MAAM,SAAiB,OAAO,UAAU;CACxC,IAAI,QAAQ,cAAc,IAAI,MAAM;CACpC,IAAI,CAAC,OAAO;EACR,wBAAQ,IAAI,IAAI;EAChB,cAAc,IAAI,QAAQ,KAAK;CACnC;CACA,MAAM,SAAS,MAAM,IAAI,WAAW;CACpC,IAAI,UAAU,OAAO,QAAQ,UAAU,OAAO,OAAO;CACrD,MAAM,WAAW,oBAAoB;EACjC;EACA;EACA,QAAQ,OAAO;EACf,gBAAgB,OAAO;EACvB,MAAM,QAAQ;EACd,UAAU,OAAO;EACjB,iBAAiB,QAAQ;EACzB,gBAAgB,QAAQ;EACxB,qBAAqB;CACzB,CAAC;CACD,MAAM,IAAI,aAAa;EAAE,KAAK;EAAU;CAAS,CAAC;CAClD,OAAO;AACX;;;;;;;;;;;AAYA,SAAgB,iBAAiB,YAAwB,aAAiC;CACtF,IAAI,eAAe,YAAY,OAAO,GAAG,cAAc,WAAW,aAAa;CAC/E,MAAM,MAAM,YAAY,QAAQ,GAAG;CACnC,IAAI,QAAQ,IAAI,OAAO,CAAC;CACxB,MAAM,SAAS,YAAY,MAAM,GAAG,GAAG;CACvC,MAAM,MAAM,WAAW;CACvB,IAAI,KAAK,SAAS,SAAS,CAAC,IAAI,YAAY,OAAO,CAAC;CACpD,MAAM,WAAW,iBAAiB,IAAI,YAAY,YAAY,MAAM,MAAM,CAAC,CAAC;CAC5E,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,IAChC,GAAG,SAAS;EAAE,MAAM;EAAO,YAAY;CAAS,EAAE,IAClD,CAAC;AACX;;;;;;AAOA,SAAgB,yBACZ,YACA,aACA,QACA,gBACA,UACA,SACU;CAUV,OAAO,iBATU,+BAAkC;EAC/C;EACA;EACA;EACA,MAAM,QAAQ;EACd;EACA,iBAAiB,QAAQ;EACzB,gBAAgB,QAAQ;CAC5B,CACwB,GAAU,WAAW;AACjD"}
|
|
1
|
+
{"version":3,"file":"resolve_cell_property.js","names":[],"sources":["../../src/form/resolve_cell_property.ts"],"sourcesContent":["import type { AuthController, PropertyConfig } from \"@rebasepro/cms-types\";\nimport type { Entity, Properties, Property } from \"@rebasepro/types\";\nimport { isPropertyBuilder } from \"@rebasepro/common\";\nimport { resolveFormProperty, resolvePropertiesForValidation } from \"./resolve_form_properties\";\n\n/**\n * The table's two editors — the inline cell and the popup — judged a value\n * against the raw declaration, as the record form once did: a `dynamicProps`\n * validation or a `conditions` rule (`disabled`, `min`, `required`…) applied\n * in the form and nowhere in the table. These resolve a cell's property\n * against its own row, with the record form's {@link resolveFormProperty}.\n */\nexport interface CellResolutionContext {\n path: string;\n authController: AuthController;\n propertyConfigs?: Record<string, PropertyConfig>;\n}\n\n/**\n * Resolved per row, and held as long as the row object is: a column of plain\n * properties keeps its property object (and so its cached schema and its\n * memoised cells); only a builder or a property with `conditions` is resolved,\n * once per row value.\n */\nconst resolvedByRow = new WeakMap<object, Map<string, { raw: Property; resolved: Property | null }>>();\n\nexport function resolveCellProperty(\n property: Property,\n propertyKey: string,\n entity: Entity<Record<string, unknown>>,\n context: CellResolutionContext\n): Property | null {\n if (!isPropertyBuilder(property) && !property.conditions) return property;\n const rowKey: object = entity.values ?? entity;\n let byKey = resolvedByRow.get(rowKey);\n if (!byKey) {\n byKey = new Map();\n resolvedByRow.set(rowKey, byKey);\n }\n const cached = byKey.get(propertyKey);\n if (cached && cached.raw === property) return cached.resolved;\n const resolved = resolveFormProperty({\n property,\n propertyKey,\n values: entity.values,\n previousValues: entity.values,\n path: context.path,\n entityId: entity.id,\n propertyConfigs: context.propertyConfigs,\n authController: context.authController,\n ignoreMissingFields: true\n });\n byKey.set(propertyKey, { raw: property, resolved });\n return resolved;\n}\n\n/**\n * The properties that judge one cell: the property at `propertyKey`, under the\n * maps its key goes through, and nothing beside it.\n *\n * A spread map's child is `address.street`, a path into `properties` rather\n * than a key of it; looked up as a key it found nothing, and the popup\n * validated nothing. The maps on the way carry only the edited child and none\n * of their own rules: the popup shows one field, and an error anywhere else\n * would block the save where no one could see it.\n */\nexport function propertiesOfCell(properties: Properties, propertyKey: string): Properties {\n if (propertyKey in properties) return { [propertyKey]: properties[propertyKey] };\n const dot = propertyKey.indexOf(\".\");\n if (dot === -1) return {};\n const mapKey = propertyKey.slice(0, dot);\n const map = properties[mapKey];\n if (map?.type !== \"map\" || !map.properties) return {};\n const children = propertiesOfCell(map.properties, propertyKey.slice(dot + 1));\n return Object.keys(children).length > 0\n ? { [mapKey]: { type: \"map\", properties: children } }\n : {};\n}\n\n/**\n * The properties that judge a form showing only `keys`: each key's property as\n * {@link propertiesOfCell} cuts it, two children of one map under one map.\n */\nexport function propertiesOfFields(properties: Properties, keys: Iterable<string>): Properties {\n let result: Properties = {};\n for (const key of keys) result = mergeProperties(result, propertiesOfCell(properties, key));\n return result;\n}\n\nfunction mergeProperties(a: Properties, b: Properties): Properties {\n const merged: Properties = { ...a };\n for (const [key, property] of Object.entries(b)) {\n const existing = merged[key];\n merged[key] = existing?.type === \"map\" && property.type === \"map\" && existing !== property\n ? { ...existing, ...property, properties: mergeProperties(existing.properties ?? {}, property.properties ?? {}) }\n : property;\n }\n return merged;\n}\n\n/**\n * What the popup judges a cell by, given the values it holds now: the\n * collection's properties resolved as the record form resolves them on submit\n * (so a field a rule hides or disables is not judged), cut to the cell.\n */\nexport function cellValidationProperties<M extends Record<string, unknown>>(\n properties: Properties,\n propertyKey: string,\n values: Partial<M>,\n previousValues: Partial<M> | undefined,\n entityId: string | number | undefined,\n context: CellResolutionContext\n): Properties {\n const resolved = resolvePropertiesForValidation<M>({\n properties,\n values,\n previousValues,\n path: context.path,\n entityId,\n propertyConfigs: context.propertyConfigs,\n authController: context.authController\n });\n return propertiesOfCell(resolved, propertyKey);\n}\n"],"mappings":";;;;;;;;;AAwBA,IAAM,gCAAgB,IAAI,QAA2E;AAErG,SAAgB,oBACZ,UACA,aACA,QACA,SACe;CACf,IAAI,CAAC,kBAAkB,QAAQ,KAAK,CAAC,SAAS,YAAY,OAAO;CACjE,MAAM,SAAiB,OAAO,UAAU;CACxC,IAAI,QAAQ,cAAc,IAAI,MAAM;CACpC,IAAI,CAAC,OAAO;EACR,wBAAQ,IAAI,IAAI;EAChB,cAAc,IAAI,QAAQ,KAAK;CACnC;CACA,MAAM,SAAS,MAAM,IAAI,WAAW;CACpC,IAAI,UAAU,OAAO,QAAQ,UAAU,OAAO,OAAO;CACrD,MAAM,WAAW,o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OAAO;AACX;;;;;;AAOA,SAAgB,yBACZ,YACA,aACA,QACA,gBACA,UACA,SACU;CAUV,OAAO,iBATU,+BAAkC;EAC/C;EACA;EACA;EACA,MAAM,QAAQ;EACd;EACA,iBAAiB,QAAQ;EACzB,gBAAgB,QAAQ;CAC5B,CACwB,GAAU,WAAW;AACjD"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./useSidePanel.js";
|
|
2
|
-
export
|
|
2
|
+
export { useSelectionDialog } from "./useSelectionDialog.js";
|
|
3
3
|
export * from "./useBuildSidePanel.js";
|
|
4
4
|
export * from "./useResolvedNavigationFrom.js";
|
|
5
5
|
export * from "./useResolvedUsers.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AppView, RebasePlugin, NavigationStateController, UrlController, NavigationGroupMapping, AdminCollection } from "@rebasepro/cms-types";
|
|
2
|
-
import {
|
|
2
|
+
import { RebaseSdkData, CollectionRegistryController, User } from "@rebasepro/types";
|
|
3
3
|
import { AuthController } from "@rebasepro/cms-types";
|
|
4
4
|
import type { EffectiveRoleController } from "@rebasepro/types";
|
|
5
5
|
import type { CollectionConfigsBuilder, AppViewsBuilder } from "@rebasepro/cms-types";
|
|
@@ -9,7 +9,7 @@ export type BuildNavigationStateProps<EC extends AdminCollection, USER extends U
|
|
|
9
9
|
collections?: EC[] | CollectionConfigsBuilder<EC>;
|
|
10
10
|
views?: AppView[] | AppViewsBuilder;
|
|
11
11
|
adminViews?: AppView[] | AppViewsBuilder;
|
|
12
|
-
data:
|
|
12
|
+
data: RebaseSdkData;
|
|
13
13
|
plugins?: RebasePlugin[];
|
|
14
14
|
navigationGroupMappings?: NavigationGroupMapping[];
|
|
15
15
|
disabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBuildNavigationStateController.js","names":[],"sources":["../../../src/hooks/navigation/useBuildNavigationStateController.tsx"],"sourcesContent":["\nimport type { AppView, NavigationResult, RebasePlugin, NavigationStateController, UrlController, NavigationGroupMapping, AdminCollection } from \"@rebasepro/cms-types\";\nimport { useCallback, useMemo, useRef } from \"react\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"useBuildNavigationStateController.js","names":[],"sources":["../../../src/hooks/navigation/useBuildNavigationStateController.tsx"],"sourcesContent":["\nimport type { AppView, NavigationResult, RebasePlugin, NavigationStateController, UrlController, NavigationGroupMapping, AdminCollection } from \"@rebasepro/cms-types\";\nimport { useCallback, useMemo, useRef } from \"react\";\n\nimport { RebaseSdkData, CollectionRegistryController, User } from \"@rebasepro/types\";\nimport { AuthController } from \"@rebasepro/cms-types\";\nimport type { EffectiveRoleController } from \"@rebasepro/types\";\nimport type { CollectionConfigsBuilder, AppViewsBuilder } from \"@rebasepro/cms-types\";\nimport { CollectionRegistry } from \"@rebasepro/common\";\n\nimport { useResolvedCollections } from \"./useResolvedCollections\";\nimport { useResolvedViews } from \"./useResolvedViews\";\nimport { useTopLevelNavigation } from \"./useTopLevelNavigation\";\n\nexport type BuildNavigationStateProps<EC extends AdminCollection, USER extends User> = {\n authController: AuthController<USER>;\n collections?: EC[] | CollectionConfigsBuilder<EC>;\n views?: AppView[] | AppViewsBuilder;\n adminViews?: AppView[] | AppViewsBuilder;\n data: RebaseSdkData;\n plugins?: RebasePlugin[];\n navigationGroupMappings?: NavigationGroupMapping[];\n disabled?: boolean;\n viewsOrder?: string[];\n collectionRegistryController: CollectionRegistryController<EC> & { collectionRegistryRef: React.MutableRefObject<CollectionRegistry> };\n urlController: UrlController;\n adminMode?: \"cms\" | \"studio\";\n effectiveRoleController?: EffectiveRoleController;\n\n};\n\n/**\n * Main hook that resolves collections, views, and admin views into a\n * NavigationStateController. This is a thin composition of three focused hooks:\n *\n * - useResolvedCollections: resolves collection props and registers with CollectionRegistry\n * - useResolvedViews: resolves view/admin view props\n * - useTopLevelNavigation: computes the NavigationResult from resolved data\n *\n * The NavigationStateController type is preserved as a public API.\n */\nexport function useBuildNavigationStateController<EC extends AdminCollection, USER extends User>(\n props: BuildNavigationStateProps<EC, USER>\n): NavigationStateController {\n\n const {\n authController,\n collections: collectionsProp,\n views: viewsProp,\n adminViews: adminViewsProp,\n viewsOrder,\n plugins,\n data,\n disabled,\n navigationGroupMappings,\n collectionRegistryController,\n urlController,\n adminMode = \"cms\",\n effectiveRoleController\n } = props;\n\n const {\n collections,\n loading: collectionsLoading,\n error: collectionsError,\n refresh: refreshCollections\n } = useResolvedCollections({\n authController,\n collections: collectionsProp,\n data,\n plugins,\n disabled,\n collectionRegistryController\n });\n\n const {\n views,\n adminViews,\n loading: viewsLoading,\n error: viewsError,\n refresh: refreshViews\n } = useResolvedViews({\n authController,\n views: viewsProp,\n adminViews: adminViewsProp,\n data,\n plugins,\n adminMode,\n effectiveRoleController\n });\n\n // Step 3: Compute top-level navigation (pure derived state)\n const { topLevelNavigation } = useTopLevelNavigation({\n collections,\n views,\n adminViews,\n plugins,\n navigationGroupMappings,\n viewsOrder,\n urlController,\n adminMode,\n collectionRegistryController\n });\n\n // Expose a combined refresh function with microtask batching\n const pendingRefreshRef = useRef(false);\n const refreshNavigation = useCallback(() => {\n if (pendingRefreshRef.current) return;\n pendingRefreshRef.current = true;\n queueMicrotask(() => {\n pendingRefreshRef.current = false;\n refreshCollections();\n refreshViews();\n });\n }, [refreshCollections, refreshViews]);\n\n return useMemo(() => ({\n views,\n adminViews,\n topLevelNavigation,\n loading: collectionsLoading || viewsLoading,\n navigationLoadingError: collectionsError ?? viewsError,\n refreshNavigation\n }), [\n views,\n adminViews,\n topLevelNavigation,\n collectionsLoading,\n viewsLoading,\n collectionsError,\n viewsError,\n refreshNavigation\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyCA,SAAgB,kCACZ,OACyB;CAEzB,MAAM,EACF,gBACA,aAAa,iBACb,OAAO,WACP,YAAY,gBACZ,YACA,SACA,MACA,UACA,yBACA,8BACA,eACA,YAAY,OACZ,4BACA;CAEJ,MAAM,EACF,aACA,SAAS,oBACT,OAAO,kBACP,SAAS,uBACT,uBAAuB;EACvB;EACA,aAAa;EACb;EACA;EACA;EACA;CACJ,CAAC;CAED,MAAM,EACF,OACA,YACA,SAAS,cACT,OAAO,YACP,SAAS,iBACT,iBAAiB;EACjB;EACA,OAAO;EACP,YAAY;EACZ;EACA;EACA;EACA;CACJ,CAAC;CAGD,MAAM,EAAE,uBAAuB,sBAAsB;EACjD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC;CAGD,MAAM,oBAAoB,OAAO,KAAK;CACtC,MAAM,oBAAoB,kBAAkB;EACxC,IAAI,kBAAkB,SAAS;EAC/B,kBAAkB,UAAU;EAC5B,qBAAqB;GACjB,kBAAkB,UAAU;GAC5B,mBAAmB;GACnB,aAAa;EACjB,CAAC;CACL,GAAG,CAAC,oBAAoB,YAAY,CAAC;CAErC,OAAO,eAAe;EAClB;EACA;EACA;EACA,SAAS,sBAAsB;EAC/B,wBAAwB,oBAAoB;EAC5C;CACJ,IAAI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC;AACL"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AppView, AppViewsBuilder, CollectionConfigsBuilder, RebasePlugin, AdminCollection } from "@rebasepro/cms-types";
|
|
2
|
-
import { type
|
|
2
|
+
import { type RebaseSdkData } from "@rebasepro/types";
|
|
3
3
|
import { type AuthController } from "@rebasepro/cms-types";
|
|
4
4
|
export declare function filterOutNotAllowedCollections(resolvedCollections: AdminCollection[], authController: AuthController): AdminCollection[];
|
|
5
5
|
export declare function applyPluginModifyCollection(resolvedCollections: AdminCollection[], modifyCollection: (collection: AdminCollection) => AdminCollection): AdminCollection[];
|
|
6
|
-
export declare function resolveCollections(collections: undefined | AdminCollection[] | CollectionConfigsBuilder, authController: AuthController, data:
|
|
7
|
-
export declare function resolveAppViews(baseViews: AppView[] | AppViewsBuilder | undefined, authController: AuthController, data:
|
|
6
|
+
export declare function resolveCollections(collections: undefined | AdminCollection[] | CollectionConfigsBuilder, authController: AuthController, data: RebaseSdkData, plugins: RebasePlugin[] | undefined): Promise<AdminCollection[]>;
|
|
7
|
+
export declare function resolveAppViews(baseViews: AppView[] | AppViewsBuilder | undefined, authController: AuthController, data: RebaseSdkData, plugins?: RebasePlugin[]): Promise<AppView[]>;
|