@rebasepro/cms 0.30.1 → 0.31.0-canary.g59cd6fd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/collection_editor/ConfigControllerProvider.js +25 -22
- package/dist/collection_editor/ConfigControllerProvider.js.map +1 -1
- package/dist/collection_editor/firestore_callee.d.ts +10 -0
- package/dist/collection_editor/firestore_callee.js +15 -0
- package/dist/collection_editor/firestore_callee.js.map +1 -0
- package/dist/collection_editor/firestore_edit.d.ts +62 -0
- package/dist/collection_editor/firestore_edit.js +339 -0
- package/dist/collection_editor/firestore_edit.js.map +1 -0
- package/dist/collection_editor/index.d.ts +2 -3
- package/dist/collection_editor/liveSchemaClient.d.ts +44 -22
- package/dist/collection_editor/liveSchemaClient.js +9 -3
- package/dist/collection_editor/liveSchemaClient.js.map +1 -1
- package/dist/collection_editor/property_column.d.ts +86 -0
- package/dist/collection_editor/property_column.js +719 -0
- package/dist/collection_editor/property_column.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +2 -24
- package/dist/collection_editor/serializable_utils.d.ts +1 -1
- package/dist/collection_editor/serializable_utils.js +2 -1
- package/dist/collection_editor/serializable_utils.js.map +1 -1
- package/dist/collection_editor/split_edit.d.ts +106 -0
- package/dist/collection_editor/split_edit.js +564 -0
- package/dist/collection_editor/split_edit.js.map +1 -0
- package/dist/collection_editor/split_edit_error.d.ts +25 -0
- package/dist/collection_editor/split_edit_error.js +35 -0
- package/dist/collection_editor/split_edit_error.js.map +1 -0
- package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
- package/dist/collection_editor/types/config_controller.d.ts +67 -1
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +6 -5
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +44 -12
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +18 -3
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +94 -55
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +2 -1
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +3 -3
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -3
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +7 -4
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js +15 -5
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.d.ts +20 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js +74 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.d.ts +34 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js +50 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -2
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -1
- package/dist/collection_editor/useDetachRulesConfirmation.d.ts +16 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js +48 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js.map +1 -0
- package/dist/collection_editor/useLiveSchemaEditing.d.ts +2 -2
- package/dist/collection_editor/useLiveSchemaEditing.js +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +54 -10
- package/dist/collection_editor/useLocalCollectionsConfigController.js +394 -122
- package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -1
- package/dist/collection_editor/validateCollectionJson.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +10 -9
- package/dist/components/CollectionPanel.js +5 -2
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +1 -2
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +3 -5
- package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +1 -1
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.d.ts +2 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.d.ts +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +2 -2
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionTableBinding/table_bindings.d.ts +2 -2
- package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -5
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +2 -4
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +6 -6
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +1 -2
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntitiesCount.js +3 -3
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +1 -2
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/RowActions.d.ts +1 -2
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/SortButton.d.ts +1 -1
- package/dist/components/CollectionViewBinding/SortButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +1 -2
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.d.ts +2 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.js +3 -3
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +2 -4
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +14 -19
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -1
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +1 -3
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +1 -2
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +23 -8
- package/dist/components/CollectionsProvider.js +23 -7
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/DefaultDrawer.js +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +1 -1
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +3 -3
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -1
- package/dist/components/EditViewBinding.js +6 -6
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.d.ts +1 -2
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityInspector.d.ts +1 -2
- package/dist/components/EntityInspector.js.map +1 -1
- package/dist/components/EntityPreviewBinding.d.ts +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +1 -1
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +1 -1
- package/dist/components/EntityViewBody.js +3 -4
- package/dist/components/EntityViewBody.js.map +1 -1
- package/dist/components/FieldValue.js +2 -2
- package/dist/components/FieldValue.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +12 -3
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/InlineEntityPreview.d.ts +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PropertyCollectionView.d.ts +2 -2
- package/dist/components/PropertyCollectionView.js.map +1 -1
- package/dist/components/PropertyConfigBadge.js.map +1 -1
- package/dist/components/RebaseCMS.d.ts +22 -3
- package/dist/components/RebaseCMS.js +32 -14
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +106 -31
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RecordDetail.js +4 -1
- package/dist/components/RecordDetail.js.map +1 -1
- package/dist/components/RecordForm.d.ts +5 -5
- package/dist/components/RecordForm.js +5 -2
- package/dist/components/RecordForm.js.map +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +2 -2
- package/dist/components/ReferenceTable/SelectionTableBinding.js +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +2 -1
- package/dist/components/ReferenceWidget.js +2 -2
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.d.ts +2 -1
- package/dist/components/RelationSelector.js +2 -3
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.d.ts +2 -2
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.d.ts +2 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js +3 -3
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/null_filter.d.ts +1 -3
- package/dist/components/SelectableTable/filters/null_filter.js.map +1 -1
- package/dist/components/SidePanelBinding.js +1 -1
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/field_configs.d.ts +1 -2
- package/dist/components/field_configs.js.map +1 -1
- package/dist/components/field_ids.d.ts +1 -1
- package/dist/components/field_ids.js +1 -1
- package/dist/components/field_ids.js.map +1 -1
- package/dist/components/history/EntityHistoryEntry.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +1 -2
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/data_export/export/BasicExportAction.d.ts +1 -1
- package/dist/data_export/export/BasicExportAction.js.map +1 -1
- package/dist/data_export/export/ExportCollectionAction.js +2 -2
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +1 -1
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_export/export/export.d.ts +1 -1
- package/dist/data_export/export/export.js +1 -1
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/data_export/export/fetch_export_data.d.ts +3 -2
- package/dist/data_export/export/fetch_export_data.js.map +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -1
- package/dist/data_import/hooks/useImportConfig.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.d.ts +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/data_import/types/column_mapping.d.ts +1 -1
- package/dist/data_import/utils/data.d.ts +1 -2
- package/dist/data_import/utils/data.js +1 -2
- package/dist/data_import/utils/data.js.map +1 -1
- package/dist/data_import/utils/get_import_inference_type.d.ts +1 -1
- package/dist/data_import/utils/get_import_inference_type.js.map +1 -1
- package/dist/data_import/utils/id_column.d.ts +1 -1
- package/dist/data_import/utils/id_column.js.map +1 -1
- package/dist/data_import/utils/import_columns.d.ts +1 -1
- package/dist/data_import/utils/import_columns.js.map +1 -1
- package/dist/data_import/utils/save_entities.d.ts +3 -3
- package/dist/data_import/utils/save_entities.js +1 -1
- package/dist/data_import/utils/save_entities.js.map +1 -1
- package/dist/form/EntityForm.js +2 -1
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.js +2 -2
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormFieldsContext.d.ts +1 -4
- package/dist/form/FormFieldsContext.js +1 -1
- package/dist/form/FormFieldsContext.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +6 -8
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/components/FieldBlock.d.ts +1 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FieldHelperText.d.ts +1 -1
- package/dist/form/components/FieldHelperText.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +1 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/LocalChangesMenu.d.ts +1 -1
- package/dist/form/components/LocalChangesMenu.js.map +1 -1
- package/dist/form/components/StorageItemPreview.d.ts +1 -1
- package/dist/form/components/StorageItemPreview.js.map +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.js +1 -2
- package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MapFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +3 -3
- package/dist/form/form_utils.js +1 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/label_placement.d.ts +1 -2
- package/dist/form/label_placement.js.map +1 -1
- package/dist/form/resolve_cell_property.d.ts +1 -2
- package/dist/form/resolve_cell_property.js +1 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/form/resolve_form_properties.d.ts +2 -2
- package/dist/form/resolve_form_properties.js +1 -1
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/form/useClearRestoreValue.d.ts +1 -1
- package/dist/form/useClearRestoreValue.js.map +1 -1
- package/dist/form/validation.d.ts +2 -2
- package/dist/form/validation.js +1 -1
- package/dist/form/validation.js.map +1 -1
- package/dist/hooks/navigation/compose_collections.d.ts +59 -0
- package/dist/hooks/navigation/compose_collections.js +48 -0
- package/dist/hooks/navigation/compose_collections.js.map +1 -0
- package/dist/hooks/navigation/compose_collections_input.d.ts +8 -0
- package/dist/hooks/navigation/compose_collections_input.js +17 -0
- package/dist/hooks/navigation/compose_collections_input.js.map +1 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +1 -1
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -1
- package/dist/hooks/navigation/registered_collection.d.ts +15 -0
- package/dist/hooks/navigation/registered_collection.js +20 -0
- package/dist/hooks/navigation/registered_collection.js.map +1 -0
- package/dist/hooks/navigation/ui_preferences.d.ts +47 -0
- package/dist/hooks/navigation/ui_preferences.js +179 -0
- package/dist/hooks/navigation/ui_preferences.js.map +1 -0
- package/dist/hooks/navigation/useAsyncResolver.d.ts +8 -1
- package/dist/hooks/navigation/useAsyncResolver.js +9 -3
- package/dist/hooks/navigation/useAsyncResolver.js.map +1 -1
- package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +1 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js +3 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +9 -5
- package/dist/hooks/navigation/useBuildNavigationStateController.js +2 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useBuildUrlController.d.ts +1 -1
- package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.js +1 -2
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/usePanelTables.d.ts +11 -0
- package/dist/hooks/navigation/usePanelTables.js +33 -0
- package/dist/hooks/navigation/usePanelTables.js.map +1 -0
- package/dist/hooks/navigation/useResolvedCollections.d.ts +8 -3
- package/dist/hooks/navigation/useResolvedCollections.js +3 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +1 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -2
- package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -1
- package/dist/hooks/navigation/user_preferences_overlay.d.ts +21 -0
- package/dist/hooks/navigation/user_preferences_overlay.js +101 -0
- package/dist/hooks/navigation/user_preferences_overlay.js.map +1 -0
- package/dist/hooks/navigation/utils.js +1 -1
- package/dist/hooks/navigation/utils.js.map +1 -1
- package/dist/hooks/useAdminContext.d.ts +1 -2
- package/dist/hooks/useAdminContext.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.d.ts +1 -2
- package/dist/hooks/useBuildSidePanel.js +2 -1
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useChildViewSource.d.ts +1 -1
- package/dist/hooks/useChildViewSource.js +1 -1
- package/dist/hooks/useChildViewSource.js.map +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +1 -2
- package/dist/hooks/useEntityDisplay.js +1 -1
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useEntityDisplayTitle.d.ts +2 -2
- package/dist/hooks/useEntityDisplayTitle.js.map +1 -1
- package/dist/hooks/useHistory.js +1 -1
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/hooks/useRecordActions.d.ts +1 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useReferencePaths.d.ts +21 -7
- package/dist/hooks/useReferencePaths.js +23 -6
- package/dist/hooks/useReferencePaths.js.map +1 -1
- package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
- package/dist/hooks/useResolvedNavigationFrom.js +1 -1
- package/dist/hooks/useResolvedNavigationFrom.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -2
- package/dist/mcp_view/app_modules.d.ts +2 -2
- package/dist/mcp_view/app_modules.js +4 -4
- package/dist/mcp_view/app_modules.js.map +1 -1
- package/dist/mcp_view/index.d.ts +16 -19
- package/dist/mcp_view/index.js +43 -62
- package/dist/mcp_view/index.js.map +1 -1
- package/dist/mcp_view/payload.d.ts +54 -18
- package/dist/mcp_view/payload.js +49 -24
- package/dist/mcp_view/payload.js.map +1 -1
- package/dist/mcp_view/screen.js +11 -11
- package/dist/mcp_view/screen.js.map +1 -1
- package/dist/mcp_view/tool_driver.d.ts +5 -34
- package/dist/mcp_view/tool_driver.js +17 -16
- package/dist/mcp_view/tool_driver.js.map +1 -1
- package/dist/mcp_view/write_review.d.ts +1 -2
- package/dist/mcp_view/write_review.js +1 -1
- package/dist/mcp_view/write_review.js.map +1 -1
- package/dist/preview/PropertyPreview.d.ts +1 -1
- package/dist/preview/PropertyPreview.js +4 -3
- package/dist/preview/PropertyPreview.js.map +1 -1
- package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
- package/dist/preview/components/ArrayEnumPreview.js.map +1 -1
- package/dist/preview/components/BooleanPreview.d.ts +1 -1
- package/dist/preview/components/BooleanPreview.js.map +1 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/components/EnumValuesChip.js +1 -1
- package/dist/preview/components/EnumValuesChip.js.map +1 -1
- package/dist/preview/components/ReferencePreview.d.ts +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.d.ts +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/preview/components/StorageThumbnail.js +2 -1
- package/dist/preview/components/StorageThumbnail.js.map +1 -1
- package/dist/preview/components/UserPreview.d.ts +1 -1
- package/dist/preview/components/UserPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js +2 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -1
- package/dist/preview/util.d.ts +1 -1
- package/dist/preview/util.js.map +1 -1
- package/dist/routes/RebaseRoute.js +2 -2
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/saved_apps/SavedAppsView.d.ts +1 -1
- package/dist/saved_apps/SavedAppsView.js +1 -1
- package/dist/saved_apps/SavedAppsView.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +1 -1
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/resolve_selection.d.ts +3 -3
- package/dist/selection/resolve_selection.js +3 -2
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/tables/apply_customization.d.ts +65 -0
- package/dist/tables/apply_customization.js +644 -0
- package/dist/tables/apply_customization.js.map +1 -0
- package/dist/tables/column_property.d.ts +64 -0
- package/dist/tables/column_property.js +549 -0
- package/dist/tables/column_property.js.map +1 -0
- package/dist/tables/customize_table.d.ts +39 -0
- package/dist/tables/customize_table.js +247 -0
- package/dist/tables/customize_table.js.map +1 -0
- package/dist/tables/index.d.ts +12 -0
- package/dist/tables/labels.d.ts +18 -0
- package/dist/tables/labels.js +18 -0
- package/dist/tables/labels.js.map +1 -0
- package/dist/tables/project_table.d.ts +79 -0
- package/dist/tables/project_table.js +148 -0
- package/dist/tables/project_table.js.map +1 -0
- package/dist/tables/relations.d.ts +47 -0
- package/dist/tables/relations.js +112 -0
- package/dist/tables/relations.js.map +1 -0
- package/dist/tables/rls.d.ts +39 -0
- package/dist/tables/rls.js +111 -0
- package/dist/tables/rls.js.map +1 -0
- package/dist/tables/update_record.d.ts +32 -0
- package/dist/tables/update_record.js +40 -0
- package/dist/tables/update_record.js.map +1 -0
- package/dist/types/components/EntityFormActionsProps.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +2 -2
- package/dist/types/fields.d.ts +2 -2
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/entity_pages.d.ts +2 -1
- package/dist/util/entity_pages.js.map +1 -1
- package/dist/util/find_entities_by_ids.d.ts +2 -2
- package/dist/util/find_entities_by_ids.js +1 -1
- package/dist/util/find_entities_by_ids.js.map +1 -1
- package/dist/util/format_collection_date.d.ts +1 -1
- package/dist/util/format_collection_date.js.map +1 -1
- package/dist/util/identity.d.ts +8 -0
- package/dist/util/identity.js +16 -0
- package/dist/util/identity.js.map +1 -0
- package/dist/util/navigation_utils.js +1 -1
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/previews.js +1 -1
- package/dist/util/previews.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +1 -1
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/dist/util/property_utils.d.ts +1 -3
- package/dist/util/property_utils.js +1 -1
- package/dist/util/property_utils.js.map +1 -1
- package/dist/util/relations.d.ts +18 -0
- package/dist/util/relations.js +32 -0
- package/dist/util/relations.js.map +1 -0
- package/package.json +12 -10
- package/recipes/README.md +4 -4
- package/recipes/my-preferences.tsx +34 -26
- package/recipes/site-settings.tsx +34 -27
- package/dist/collection_editor/collection_wire.d.ts +0 -13
- package/dist/collection_editor/collection_wire.js +0 -49
- package/dist/collection_editor/collection_wire.js.map +0 -1
- package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +0 -37
- package/dist/collection_editor/useJsonCollectionsConfigController.js +0 -191
- package/dist/collection_editor/useJsonCollectionsConfigController.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldsContext.js","names":[],"sources":["../../src/form/FormFieldsContext.tsx"],"sourcesContent":["import React, { useCallback, useContext } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\";\nimport type { Entity } from \"@rebasepro/types\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\nimport type { AuthState, Property } from \"@rebasepro/types\";\nimport type { ResolvedFormField } from \"@rebasepro/app\";\nimport { isHidden, useAuthController, useCustomizationController, useRebaseContext } from \"@rebasepro/app\";\nimport type { ResolvePropertyProps } from \"@rebasepro/common\";\nimport { effectiveAccess } from \"@rebasepro/common\";\nimport { AlignLeftIcon, cls, paperMixin } from \"@rebasepro/ui\";\nimport { FormexController, useFormexSelector } from \"@rebasepro/forms\";\n\nimport type { FormContext, PropertyFieldBindingProps } from \"../types/fields\";\nimport { AdditionalFieldValue } from \"../components/AdditionalFieldValue\";\nimport { rowOfEntity } from \"@rebasepro/app\";\nimport { FieldBlock, isSelfLabellingProperty, LABEL_ICON_SIZE, spanClass } from \"./components/FieldBlock\";\nimport { labelsInsideControl } from \"./label_placement\";\nimport { PropertyFieldBinding } from \"./PropertyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\n\ntype Values = Record<string, unknown>;\ntype CollectionProperty = NonNullable<AdminCollection[\"properties\"][string]>;\n\n/**\n * What a record form gives every field it renders: the rules that place,\n * label, disable and hide one, and the context it binds to.\n *\n * `EntityForm` provides it, and every field of the form is drawn through\n * {@link FormFieldsContextValue.renderField} — the generated sections, the\n * rail and `<FormField>` alike — so a field has one set of rules wherever it\n * sits.\n *\n * Its identity changes only with what a field draws from it, never with a\n * keystroke: a field reads the values it depends on through the form's\n * selector, so typing in one field does not re-render another.\n */\nexport interface FormFieldsContextValue {\n collection: AdminCollection<Values>;\n path: string;\n entityId?: string | number;\n entity?: Entity<Values>;\n status: \"new\" | \"existing\" | \"copy\";\n /** The memoised context the bindings take; see `EntityForm`. */\n fieldContext: FormContext<Values>;\n /** What the form opened with, which `conditions` read as the previous values. */\n previousValues: Partial<Values>;\n /** Values the record changed to underneath an edit, by top-level key. */\n underlyingChanges: Record<string, unknown>;\n autoSave: boolean;\n /** The field that takes focus when a new record opens. */\n autoFocusKey?: string;\n /** Every control's height: `large` in the record form, `medium` in a compact one. */\n fieldSize: \"medium\" | \"large\";\n /** Every rule that disables a field, except a save in progress. */\n isFieldDisabled: (key: string, property: CollectionProperty) => boolean;\n /** One field, with every rule of the form. */\n renderField: (field: ResolvedFormField) => React.ReactNode;\n /** The field for a key — placed as the form's layout places it, when it does — or nothing for a key the collection lacks. */\n fieldFor: (key: string) => ResolvedFormField | undefined;\n /** Marks a field as shown, for validation; returns the call that unmarks it. */\n register: (key: string) => () => void;\n}\n\nexport const FormFieldsContext = React.createContext<FormFieldsContextValue | undefined>(undefined);\n\nexport function useFormFieldsContext(): FormFieldsContextValue | undefined {\n return useContext(FormFieldsContext);\n}\n\n/**\n * Whether a record shows a field, for these values, to this user: no\n * `conditions.hidden` rule hides it and the user's field access lets them read\n * it. The form's cells and the read-only view both ask here, so a field a rule\n * hides while editing is not on the page that reads the record either.\n */\nexport function isFieldShown<M extends Record<string, unknown>>(props: {\n propertyKey: string;\n property: Property;\n values: Partial<M>;\n previousValues?: Partial<M>;\n path: string;\n entityId?: string | number;\n propertyConfigs?: ResolvePropertyProps<M>[\"propertyConfigs\"];\n authController: AuthState;\n}): boolean {\n const { property } = props;\n // Most fields carry neither rule, and resolving one runs its dynamicProps.\n if (!property.conditions?.hidden && !effectiveAccess(property)) return true;\n const shown = resolveFormProperty<M>({\n ...props,\n ignoreMissingFields: true\n });\n return shown !== null && !isHidden(shown);\n}\n\n/** What {@link FormFieldsContextValue.renderField} renders: one cell, keyed for a list. */\nexport function renderFormField(field: ResolvedFormField): React.ReactNode {\n return <FormFieldCell key={`${field.additional ? \"additional\" : \"field\"}_${field.key}`} field={field}/>;\n}\n\n/**\n * One field of the form. Memoised on its placement: it re-renders when the\n * form's rules change, or when one of the few things it reads from the values\n * changes — whether a rule hides it, whether the record changed under it,\n * whether a save is running.\n */\nconst FormFieldCell = React.memo(function FieldCell({ field }: { field: ResolvedFormField }) {\n\n const fields = useContext(FormFieldsContext);\n if (!fields) throw new Error(\"INTERNAL: a form field rendered outside its form\");\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n const rebaseContext = useRebaseContext();\n\n const {\n collection,\n path,\n entityId,\n entity,\n previousValues,\n underlyingChanges,\n autoSave,\n autoFocusKey,\n isFieldDisabled,\n fieldContext\n } = fields;\n\n const property = field.additional ? undefined : collection.properties?.[field.key];\n\n // A field a rule hides for these values, or that this user may not read,\n // takes its label with it: the binding renders nothing, and a heading over\n // nothing is worse. Selected as a yes or no, so the cell re-renders when\n // that answer flips and not on every value its rule reads.\n const selectShown = useCallback((formex: FormexController<Values>): boolean => {\n if (!property) return true;\n return isFieldShown({\n propertyKey: field.key,\n property,\n values: formex.values,\n previousValues,\n path,\n entityId,\n propertyConfigs: customizationController.propertyConfigs,\n authController\n });\n }, [property, field.key, previousValues, path, entityId, customizationController.propertyConfigs, authController]);\n const shown = useFormexSelector(selectShown);\n\n const selectUnderlyingChanged = useCallback((formex: FormexController<Values>): boolean =>\n field.key in underlyingChanges && !equal(formex.values[field.key], underlyingChanges[field.key]),\n [field.key, underlyingChanges]);\n const underlyingValueHasChanged = useFormexSelector(selectUnderlyingChanged);\n\n const selectSubmitting = useCallback((formex: FormexController<Values>): boolean =>\n !autoSave && formex.isSubmitting, [autoSave]);\n const submitting = useFormexSelector(selectSubmitting);\n\n if (field.additional) {\n const additionalField = collection.additionalFields?.find(f => f.key === field.key);\n if (!additionalField || !entity) return null;\n\n const AdditionalFieldBuilder = additionalField.Builder;\n if (!AdditionalFieldBuilder && !additionalField.value) {\n throw new Error(\"When using additional fields you need to provide a Builder or a value\");\n }\n const row = rowOfEntity(entity, collection);\n const id = String(entity.id);\n const child = AdditionalFieldBuilder\n ? <AdditionalFieldBuilder row={row} id={id} context={rebaseContext}/>\n : <div className={\"w-full\"}>\n <AdditionalFieldValue\n field={additionalField}\n row={row}\n id={id}\n context={rebaseContext}/>\n </div>;\n\n return (\n // Through FieldBlock like every other cell, so a computed column\n // is labelled at the same size, with the same gap to its box, as\n // the property next to it on the grid.\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n showLabel={true}\n label={additionalField.name}\n icon={<AlignLeftIcon size={LABEL_ICON_SIZE}/>}>\n <div className={cls(paperMixin, \"w-full min-h-12 p-4 md:p-6 overflow-x-auto no-scrollbar\")}>\n {child}\n </div>\n </FieldBlock>\n </div>\n );\n }\n\n if (!property) {\n console.warn(`Property ${field.key} not found in collection ${collection.name} in properties or additional fields. Skipping.`);\n return null;\n }\n if (!shown) return null;\n\n const disabled = submitting || isFieldDisabled(field.key, property);\n // Three places a label can be. The panel-style editors carry their own\n // header. The one-line controls draw it inside their box, FireCMS-style,\n // so they all stand the same height. Everything else — multi-selects,\n // uploads, markdown, relations — is labelled above by FieldBlock.\n const selfLabelling = isSelfLabellingProperty(property);\n const labelInside = !selfLabelling\n && labelsInsideControl(property, customizationController.propertyConfigs);\n\n const bindingProps: PropertyFieldBindingProps<Values> = {\n propertyKey: field.key,\n disabled,\n property,\n // FieldBlock owns the description, so the binding must not repeat it —\n // it still renders validation errors, which belong against the control\n // rather than under the label.\n includeDescription: false,\n hideLabel: !selfLabelling && !labelInside,\n underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,\n context: fieldContext,\n partOfArray: false,\n minimalistView: false,\n // One height for every control in the form. Left to their own\n // defaults, a text field came out 48px, a select 44 and a switch 64.\n // `large`: the record-form density — a 64px box with the label inside\n // and a 16px value, or a 48px box under a label. See DESIGN.md \"Form\n // density\". A compact form takes `medium`.\n size: fields.fieldSize,\n autoFocus: autoFocusKey === field.key\n };\n\n return (\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n property={property}\n showLabel={!selfLabelling && !labelInside}\n labelInside={labelInside}>\n <PropertyFieldBinding {...bindingProps}/>\n </FieldBlock>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;AA+DA,IAAa,oBAAoB,MAAM,cAAkD,KAAA,CAAS;AAElG,SAAgB,uBAA2D;CACvE,OAAO,WAAW,iBAAiB;AACvC;;;;;;;AAQA,SAAgB,aAAgD,OASpD;CACR,MAAM,EAAE,aAAa;CAErB,IAAI,CAAC,SAAS,YAAY,UAAU,CAAC,gBAAgB,QAAQ,GAAG,OAAO;CACvE,MAAM,QAAQ,oBAAuB;EACjC,GAAG;EACH,qBAAqB;CACzB,CAAC;CACD,OAAO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,iBAAiB,CAAC;GACjB;aACb,oBAAC,sBAAD,EAAsB,GAAI,aAAc,CAAA;EAChC,CAAA;CACX,CAAA;AAEb,CAAC"}
|
|
1
|
+
{"version":3,"file":"FormFieldsContext.js","names":[],"sources":["../../src/form/FormFieldsContext.tsx"],"sourcesContent":["import React, { useCallback, useContext } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\";\nimport type { AdminCollection, ResolvePropertyProps, Property, Entity, AuthState } from \"@rebasepro/cms-types\";\nimport type { ResolvedFormField } from \"@rebasepro/app\";\nimport { isHidden, useAuthController, useCustomizationController, useRebaseContext } from \"@rebasepro/app\";\nimport { effectiveAccess } from \"@rebasepro/cms-types\";\nimport { AlignLeftIcon, cls, paperMixin } from \"@rebasepro/ui\";\nimport { FormexController, useFormexSelector } from \"@rebasepro/forms\";\n\nimport type { FormContext, PropertyFieldBindingProps } from \"../types/fields\";\nimport { AdditionalFieldValue } from \"../components/AdditionalFieldValue\";\nimport { rowOfEntity } from \"@rebasepro/app\";\nimport { FieldBlock, isSelfLabellingProperty, LABEL_ICON_SIZE, spanClass } from \"./components/FieldBlock\";\nimport { labelsInsideControl } from \"./label_placement\";\nimport { PropertyFieldBinding } from \"./PropertyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\n\ntype Values = Record<string, unknown>;\ntype CollectionProperty = NonNullable<AdminCollection[\"properties\"][string]>;\n\n/**\n * What a record form gives every field it renders: the rules that place,\n * label, disable and hide one, and the context it binds to.\n *\n * `EntityForm` provides it, and every field of the form is drawn through\n * {@link FormFieldsContextValue.renderField} — the generated sections, the\n * rail and `<FormField>` alike — so a field has one set of rules wherever it\n * sits.\n *\n * Its identity changes only with what a field draws from it, never with a\n * keystroke: a field reads the values it depends on through the form's\n * selector, so typing in one field does not re-render another.\n */\nexport interface FormFieldsContextValue {\n collection: AdminCollection<Values>;\n path: string;\n entityId?: string | number;\n entity?: Entity<Values>;\n status: \"new\" | \"existing\" | \"copy\";\n /** The memoised context the bindings take; see `EntityForm`. */\n fieldContext: FormContext<Values>;\n /** What the form opened with, which `conditions` read as the previous values. */\n previousValues: Partial<Values>;\n /** Values the record changed to underneath an edit, by top-level key. */\n underlyingChanges: Record<string, unknown>;\n autoSave: boolean;\n /** The field that takes focus when a new record opens. */\n autoFocusKey?: string;\n /** Every control's height: `large` in the record form, `medium` in a compact one. */\n fieldSize: \"medium\" | \"large\";\n /** Every rule that disables a field, except a save in progress. */\n isFieldDisabled: (key: string, property: CollectionProperty) => boolean;\n /** One field, with every rule of the form. */\n renderField: (field: ResolvedFormField) => React.ReactNode;\n /** The field for a key — placed as the form's layout places it, when it does — or nothing for a key the collection lacks. */\n fieldFor: (key: string) => ResolvedFormField | undefined;\n /** Marks a field as shown, for validation; returns the call that unmarks it. */\n register: (key: string) => () => void;\n}\n\nexport const FormFieldsContext = React.createContext<FormFieldsContextValue | undefined>(undefined);\n\nexport function useFormFieldsContext(): FormFieldsContextValue | undefined {\n return useContext(FormFieldsContext);\n}\n\n/**\n * Whether a record shows a field, for these values, to this user: no\n * `conditions.hidden` rule hides it and the user's field access lets them read\n * it. The form's cells and the read-only view both ask here, so a field a rule\n * hides while editing is not on the page that reads the record either.\n */\nexport function isFieldShown<M extends Record<string, unknown>>(props: {\n propertyKey: string;\n property: Property;\n values: Partial<M>;\n previousValues?: Partial<M>;\n path: string;\n entityId?: string | number;\n propertyConfigs?: ResolvePropertyProps<M>[\"propertyConfigs\"];\n authController: AuthState;\n}): boolean {\n const { property } = props;\n // Most fields carry neither rule, and resolving one runs its dynamicProps.\n if (!property.conditions?.hidden && !effectiveAccess(property)) return true;\n const shown = resolveFormProperty<M>({\n ...props,\n ignoreMissingFields: true\n });\n return shown !== null && !isHidden(shown);\n}\n\n/** What {@link FormFieldsContextValue.renderField} renders: one cell, keyed for a list. */\nexport function renderFormField(field: ResolvedFormField): React.ReactNode {\n return <FormFieldCell key={`${field.additional ? \"additional\" : \"field\"}_${field.key}`} field={field}/>;\n}\n\n/**\n * One field of the form. Memoised on its placement: it re-renders when the\n * form's rules change, or when one of the few things it reads from the values\n * changes — whether a rule hides it, whether the record changed under it,\n * whether a save is running.\n */\nconst FormFieldCell = React.memo(function FieldCell({ field }: { field: ResolvedFormField }) {\n\n const fields = useContext(FormFieldsContext);\n if (!fields) throw new Error(\"INTERNAL: a form field rendered outside its form\");\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n const rebaseContext = useRebaseContext();\n\n const {\n collection,\n path,\n entityId,\n entity,\n previousValues,\n underlyingChanges,\n autoSave,\n autoFocusKey,\n isFieldDisabled,\n fieldContext\n } = fields;\n\n const property = field.additional ? undefined : collection.properties?.[field.key];\n\n // A field a rule hides for these values, or that this user may not read,\n // takes its label with it: the binding renders nothing, and a heading over\n // nothing is worse. Selected as a yes or no, so the cell re-renders when\n // that answer flips and not on every value its rule reads.\n const selectShown = useCallback((formex: FormexController<Values>): boolean => {\n if (!property) return true;\n return isFieldShown({\n propertyKey: field.key,\n property,\n values: formex.values,\n previousValues,\n path,\n entityId,\n propertyConfigs: customizationController.propertyConfigs,\n authController\n });\n }, [property, field.key, previousValues, path, entityId, customizationController.propertyConfigs, authController]);\n const shown = useFormexSelector(selectShown);\n\n const selectUnderlyingChanged = useCallback((formex: FormexController<Values>): boolean =>\n field.key in underlyingChanges && !equal(formex.values[field.key], underlyingChanges[field.key]),\n [field.key, underlyingChanges]);\n const underlyingValueHasChanged = useFormexSelector(selectUnderlyingChanged);\n\n const selectSubmitting = useCallback((formex: FormexController<Values>): boolean =>\n !autoSave && formex.isSubmitting, [autoSave]);\n const submitting = useFormexSelector(selectSubmitting);\n\n if (field.additional) {\n const additionalField = collection.additionalFields?.find(f => f.key === field.key);\n if (!additionalField || !entity) return null;\n\n const AdditionalFieldBuilder = additionalField.Builder;\n if (!AdditionalFieldBuilder && !additionalField.value) {\n throw new Error(\"When using additional fields you need to provide a Builder or a value\");\n }\n const row = rowOfEntity(entity, collection);\n const id = String(entity.id);\n const child = AdditionalFieldBuilder\n ? <AdditionalFieldBuilder row={row} id={id} context={rebaseContext}/>\n : <div className={\"w-full\"}>\n <AdditionalFieldValue\n field={additionalField}\n row={row}\n id={id}\n context={rebaseContext}/>\n </div>;\n\n return (\n // Through FieldBlock like every other cell, so a computed column\n // is labelled at the same size, with the same gap to its box, as\n // the property next to it on the grid.\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n showLabel={true}\n label={additionalField.name}\n icon={<AlignLeftIcon size={LABEL_ICON_SIZE}/>}>\n <div className={cls(paperMixin, \"w-full min-h-12 p-4 md:p-6 overflow-x-auto no-scrollbar\")}>\n {child}\n </div>\n </FieldBlock>\n </div>\n );\n }\n\n if (!property) {\n console.warn(`Property ${field.key} not found in collection ${collection.name} in properties or additional fields. Skipping.`);\n return null;\n }\n if (!shown) return null;\n\n const disabled = submitting || isFieldDisabled(field.key, property);\n // Three places a label can be. The panel-style editors carry their own\n // header. The one-line controls draw it inside their box, FireCMS-style,\n // so they all stand the same height. Everything else — multi-selects,\n // uploads, markdown, relations — is labelled above by FieldBlock.\n const selfLabelling = isSelfLabellingProperty(property);\n const labelInside = !selfLabelling\n && labelsInsideControl(property, customizationController.propertyConfigs);\n\n const bindingProps: PropertyFieldBindingProps<Values> = {\n propertyKey: field.key,\n disabled,\n property,\n // FieldBlock owns the description, so the binding must not repeat it —\n // it still renders validation errors, which belong against the control\n // rather than under the label.\n includeDescription: false,\n hideLabel: !selfLabelling && !labelInside,\n underlyingValueHasChanged: underlyingValueHasChanged && !autoSave,\n context: fieldContext,\n partOfArray: false,\n minimalistView: false,\n // One height for every control in the form. Left to their own\n // defaults, a text field came out 48px, a select 44 and a switch 64.\n // `large`: the record-form density — a 64px box with the label inside\n // and a 16px value, or a 48px box under a label. See DESIGN.md \"Form\n // density\". A compact form takes `medium`.\n size: fields.fieldSize,\n autoFocus: autoFocusKey === field.key\n };\n\n return (\n <div className={spanClass(field.span)}>\n <FieldBlock propertyKey={field.key}\n property={property}\n showLabel={!selfLabelling && !labelInside}\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wB,QAAQ;CACtD,MAAM,cAAc,CAAC,iBACd,oBAAoB,UAAU,wBAAwB,eAAe;CAE5E,MAAM,eAAkD;EACpD,aAAa,MAAM;EACnB;EACA;EAIA,oBAAoB;EACpB,WAAW,CAAC,iBAAiB,CAAC;EAC9B,2BAA2B,6BAA6B,CAAC;EACzD,SAAS;EACT,aAAa;EACb,gBAAgB;EAMhB,MAAM,OAAO;EACb,WAAW,iBAAiB,MAAM;CACtC;CAEA,OACI,oBAAC,OAAD;EAAK,WAAW,UAAU,MAAM,IAAI;YAChC,oBAAC,YAAD;GAAY,aAAa,MAAM;GACjB;GACV,WAAW,CAAC,iBAAiB,CAAC;GACjB;aACb,oBAAC,sBAAD,EAAsB,GAAI,aAAc,CAAA;EAChC,CAAA;CACX,CAAA;AAEb,CAAC"}
|
|
@@ -7,8 +7,8 @@ import React, { Suspense, useCallback, useRef } from "react";
|
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { deepEqual } from "fast-equals";
|
|
9
9
|
import { ErrorBoundary, Typography } from "@rebasepro/ui";
|
|
10
|
-
import { isPropertyBuilder, resolveProperty } from "@rebasepro/
|
|
11
|
-
import { isDisabled, isHidden, isReadOnly,
|
|
10
|
+
import { isPropertyBuilder, resolveProperty } from "@rebasepro/cms-types";
|
|
11
|
+
import { isDisabled, isHidden, isReadOnly, useAuthController, useCustomizationController, useRebaseContext, useSlot, useTranslation } from "@rebasepro/app";
|
|
12
12
|
import { getIn, useFormexGetter, useFormexSelector } from "@rebasepro/forms";
|
|
13
13
|
//#region src/form/PropertyFieldBinding.tsx
|
|
14
14
|
/**
|
|
@@ -89,13 +89,11 @@ function PropertyFieldBindingInternal({ propertyKey, property, context, includeD
|
|
|
89
89
|
const disabled = disabledProp || readOnly || (resolvedProperty ? isDisabled(resolvedProperty) : false) || context.disabled;
|
|
90
90
|
if (resolvedProperty === null || isHidden(resolvedProperty)) return /* @__PURE__ */ jsx(Fragment, {});
|
|
91
91
|
else if (readOnly) Component = ReadOnlyFieldBinding;
|
|
92
|
-
else if (resolvedProperty.admin?.Field)
|
|
93
|
-
|
|
94
|
-
if (resolved) Component = resolved;
|
|
95
|
-
} else {
|
|
92
|
+
else if (resolvedProperty.admin?.Field) Component = resolvedProperty.admin.Field;
|
|
93
|
+
else {
|
|
96
94
|
const propertyConfig = getFieldConfig(resolvedProperty, customizationController.propertyConfigs);
|
|
97
95
|
if (!propertyConfig) throw new Error(`INTERNAL: Could not find field config for property ${propertyKey}`);
|
|
98
|
-
Component =
|
|
96
|
+
Component = resolveProperty({
|
|
99
97
|
propertyKey,
|
|
100
98
|
property: propertyConfig.property,
|
|
101
99
|
values,
|
|
@@ -104,7 +102,7 @@ function PropertyFieldBindingInternal({ propertyKey, property, context, includeD
|
|
|
104
102
|
propertyConfigs: customizationController.propertyConfigs,
|
|
105
103
|
index,
|
|
106
104
|
authController
|
|
107
|
-
})?.admin?.Field
|
|
105
|
+
})?.admin?.Field;
|
|
108
106
|
}
|
|
109
107
|
if (!Component) {
|
|
110
108
|
console.warn(`No field component found for property ${propertyKey}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyFieldBinding.js","names":[],"sources":["../../src/form/PropertyFieldBinding.tsx"],"sourcesContent":["\nimport type { FieldProps as CoreFieldProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport type { FieldProps, PropertyFieldBindingProps } from \"../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport type { RebasePlugin, PluginFieldBuilderParams, PropertyConfig } from \"@rebasepro/cms-types\";\nimport React, { ComponentType, ReactElement, Suspense, useCallback, useRef } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\"\n\nimport { resolveComponentRef } from \"@rebasepro/app\";\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\n;\nimport { ReadOnlyFieldBinding } from \"./field_bindings/ReadOnlyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\nimport { useClearRestoreValue } from \"./useClearRestoreValue\";\n\nimport { isPropertyBuilder, resolveProperty } from \"@rebasepro/common\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { useAuthController, useCustomizationController, useRebaseContext, useSlot, useTranslation } from \"@rebasepro/app\";\nimport { Typography } from \"@rebasepro/ui\";\nimport { getFieldConfig, getFieldId } from \"../components/field_configs\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\n\n/**\n * This component renders a form field creating the corresponding configuration\n * from a property. For example if bound to a string property, it will generate\n * a text field.\n *\n * You can use it when you are creating a custom field, and need to\n * render additional fields mapped to properties. This is useful if you\n * need to build a complex property mapping, like an array where each index\n * is a different property.\n *\n * Please note that if you build a custom field in a component, the\n * **validation** passed in the property will have no effect. You need to set\n * the validation in the `AdminCollection` definition.\n *\n * @param propertyKey You can use nested names such as `address.street` or `friends[2]`\n * @param property\n * @param context\n * @param includeDescription\n * @param underlyingValueHasChanged\n * @param disabled\n * @param tableMode\n * @param partOfArray\n * @param autoFocus\n * @group Form custom fields\n */\nexport const PropertyFieldBinding = React.memo(PropertyFieldBindingInternal,\n (a: PropertyFieldBindingProps<Record<string, unknown>>, b: PropertyFieldBindingProps<Record<string, unknown>>) =>\n sameProps(a, b, DEEP_COMPARED_BINDING_PROPS)\n) as typeof PropertyFieldBindingInternal;\n\n/**\n * Props compared by value rather than identity: a property is re-resolved\n * (`dynamicProps`, enums, a parent's `mergeDeep`) into a new object on every\n * render of whatever holds it, and an error for an array or map is a new\n * sub-object of the errors map whenever anything is validated.\n */\nconst DEEP_COMPARED_BINDING_PROPS = new Set([\"property\"]);\nconst DEEP_COMPARED_FIELD_PROPS = new Set([\"property\", \"error\", \"customProps\"]);\n\nfunction sameProps(a: object, b: object, deep: Set<string>): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) {\n const x: unknown = Reflect.get(a, key);\n const y: unknown = Reflect.get(b, key);\n if (Object.is(x, y)) continue;\n if (deep.has(key) && equal(x, y)) continue;\n return false;\n }\n return true;\n}\n\nfunction PropertyFieldBindingInternal<M extends Record<string, unknown> = Record<string, unknown>>\n({\n propertyKey,\n property,\n context,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n disabled: disabledProp,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n index,\n size,\n onPropertyChange\n }: PropertyFieldBindingProps<M>): ReactElement<PropertyFieldBindingProps<M>> {\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n // Decided on the property as declared: once resolved, a builder or a rule\n // no longer says it was one.\n const alwaysRender = shouldPropertyReRender(property as Property, customizationController.plugins, customizationController.propertyConfigs);\n\n // This field's own slice of the form, so a change anywhere else does not\n // reach it. Through the form's context — which `Field` read — every field\n // of a record form re-rendered on every keystroke anywhere in it: all 500\n // items of an array nobody was typing into. A field that reads the rest of\n // the form while rendering takes the whole controller, and with it every\n // change, as it always has.\n const selectSlice = useCallback((formex: FormexController<Record<string, unknown>>): FieldSlice => ({\n formex: alwaysRender ? formex : undefined,\n value: getIn(formex.values, propertyKey),\n error: getIn(formex.errors, propertyKey) as FieldSlice[\"error\"],\n touched: getIn(formex.touched, propertyKey) as boolean | undefined,\n submitted: formex.submitCount > 0,\n isSubmitting: formex.isSubmitting\n }), [propertyKey, alwaysRender]);\n const slice = useFormexSelector(selectSlice, sameSlice);\n const getFormex = useFormexGetter<Record<string, unknown>>();\n // What the property is resolved against. Read, not subscribed to, for a\n // field that is not `alwaysRender`: nothing it declares reads the values.\n const values = (slice.formex ?? getFormex()).values;\n\n let Component: ComponentType<FieldProps<Property, any, any>> | undefined;\n // `dynamicProps` and `conditions` both, as the save judges it.\n const resolvedProperty = resolveFormProperty({\n propertyKey,\n property: property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n\n const readOnly = resolvedProperty ? isReadOnly(resolvedProperty) : true;\n const disabled = disabledProp || readOnly || (resolvedProperty ? isDisabled(resolvedProperty) : false) || context.disabled;\n\n if (resolvedProperty === null || isHidden(resolvedProperty)) {\n return <></>;\n } else if (readOnly) {\n Component = ReadOnlyFieldBinding;\n } else if (resolvedProperty.admin?.Field) {\n const resolved = resolveComponentRef(resolvedProperty.admin.Field);\n if (resolved) {\n Component = resolved as ComponentType<FieldProps<Property, any, any>>;\n }\n } else {\n const propertyConfig = getFieldConfig(resolvedProperty, customizationController.propertyConfigs);\n if (!propertyConfig) {\n throw new Error(`INTERNAL: Could not find field config for property ${propertyKey}`);\n }\n const configProperty = resolveProperty({\n propertyKey,\n property: propertyConfig.property as Property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n Component = resolveComponentRef(configProperty?.admin?.Field) as ComponentType<FieldProps<Property, any, any>> | undefined;\n }\n if (!Component) {\n console.warn(`No field component found for property ${propertyKey}`);\n console.warn(\"Property:\", property);\n return (\n <div className={\"w-full\"}>\n {`Currently the field ${resolvedProperty.type} is not supported`}\n </div>\n );\n }\n\n const componentProps: ResolvedPropertyFieldBindingProps<M> = {\n propertyKey,\n property: resolvedProperty,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n context,\n disabled,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n size,\n onPropertyChange\n };\n\n // Keyed on the path, as the `Field` it replaces was: an array item that\n // moves to another index is a new field there.\n return <FieldInternal\n key={propertyKey}\n Component={Component as ComponentType<FieldProps<Property, any, any>>}\n alwaysRender={alwaysRender}\n componentProps={componentProps}\n slice={slice}\n getFormex={getFormex}/>;\n\n}\n\n/**\n * What one field reads from the form. `formex` is set only for a field that\n * re-renders on every change (see {@link shouldPropertyReRender}).\n */\ntype FieldSlice = {\n formex: FormexController<Record<string, unknown>> | undefined;\n value: unknown;\n error: string | string[] | Record<string, unknown> | undefined;\n touched: boolean | undefined;\n submitted: boolean;\n isSubmitting: boolean;\n};\n\nfunction sameSlice(a: FieldSlice, b: FieldSlice): boolean {\n return a.formex === b.formex &&\n Object.is(a.value, b.value) &&\n a.touched === b.touched &&\n a.submitted === b.submitted &&\n a.isSubmitting === b.isSubmitting &&\n // An array's or a map's error is a sub-object of the errors map, new\n // whenever anything is validated.\n (Object.is(a.error, b.error) || equal(a.error, b.error));\n}\n\ntype ResolvedPropertyFieldBindingProps<M extends Record<string, unknown> = Record<string, unknown>> =\n Omit<PropertyFieldBindingProps<M>, \"property\">\n & {\n property: Property\n};\n\nfunction FieldInternal<CustomProps, M extends Record<string, unknown>>\n({\n Component,\n alwaysRender,\n componentProps: {\n propertyKey,\n property,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n context,\n disabled,\n size,\n onPropertyChange\n },\n slice,\n getFormex\n }:\n {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n componentProps: ResolvedPropertyFieldBindingProps<M>,\n slice: FieldSlice,\n getFormex: () => FormexController<Record<string, unknown>>\n }) {\n\n const { plugins } = useCustomizationController();\n const { t } = useTranslation();\n\n // This is the one component every form field goes through, which is why the\n // two field slots render here rather than in each field binding: a slot\n // honoured by the string field and not by the date field is worse than one\n // that never renders at all.\n const rebaseContext = useRebaseContext();\n const fieldSlotProps = React.useMemo(() => ({\n propertyKey,\n property,\n path: context.path ?? \"\",\n id: context.id,\n collection: context.collection,\n context: rebaseContext\n }), [propertyKey, property, context.path, context.id, context.collection, rebaseContext]);\n const beforeField = useSlot(\"entity.field.before\", fieldSlotProps);\n const afterField = useSlot(\"entity.field.after\", fieldSlotProps);\n\n const customFieldProps: unknown = property.admin?.customProps;\n const { value, error, touched, isSubmitting } = slice;\n\n const showError = Boolean(error &&\n (slice.submitted || property.validation?.unique) &&\n (!Array.isArray(error) || !!error.filter((e: unknown) => !!e).length));\n\n const WrappedComponent: ComponentType<FieldProps<Property, any, any>> | null = useWrappedComponent<unknown, any>({\n path: context.path,\n collection: context.collection,\n propertyKey: propertyKey,\n property: property,\n Component: Component as ComponentType<FieldProps<Property, unknown, M>>,\n plugins: plugins\n });\n const UsedComponent: ComponentType<FieldProps<Property, any, any>> = WrappedComponent ?? Component;\n\n // Read the controller when called, not when rendered: this component\n // re-renders with its own slice only, and the form moves on without it.\n const setValue = useCallback((value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(propertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n const setFieldValue = useCallback((otherPropertyKey: string, value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(otherPropertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n // `disabled: { clearOnDisabled: true }`, for every field: called here and\n // not in each binding, where six of them never did and a disabled relation\n // kept its value and saved it.\n useClearRestoreValue({ property: property as Property, value, setValue });\n\n // A parent that builds `onPropertyChange` inline (an array item's\n // `storeProps`, a map's wrapper) would otherwise hand every child a new\n // function on each of its renders, and every child would re-render for it.\n const onPropertyChangeRef = useRef(onPropertyChange);\n onPropertyChangeRef.current = onPropertyChange;\n const stableOnPropertyChange = useCallback((changed: Partial<Property>) => onPropertyChangeRef.current?.(changed), []);\n\n const cmsFieldProps: FieldProps<Property, CustomProps, M> = {\n propertyKey,\n value,\n setValue,\n setFieldValue,\n error: error as string | undefined,\n touched,\n showError,\n isSubmitting,\n includeDescription: includeDescription ?? true,\n hideLabel: hideLabel ?? false,\n property: property as Property,\n disabled: disabled ?? false,\n underlyingValueHasChanged: underlyingValueHasChanged ?? false,\n partOfArray: partOfArray ?? false,\n partOfBlock: partOfBlock ?? false,\n minimalistView: minimalistView ?? false,\n autoFocus: autoFocus ?? false,\n customProps: customFieldProps as CustomProps,\n context,\n size,\n onPropertyChange: onPropertyChange ? stableOnPropertyChange : undefined\n };\n\n return (\n <ErrorBoundary>\n {beforeField}\n\n <Suspense fallback={null}>\n <MemoisedField Component={UsedComponent}\n alwaysRender={alwaysRender}\n fieldProps={cmsFieldProps as FieldProps<Property, any, any>}/>\n </Suspense>\n\n {afterField}\n\n {underlyingValueHasChanged && !isSubmitting &&\n <Typography variant={\"caption\"} className={\"ml-3.5\"}>\n {t(\"value_updated_elsewhere\")}\n </Typography>}\n\n </ErrorBoundary>);\n\n}\n\ntype MemoisedFieldProps = {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n fieldProps: FieldProps<Property, any, any>\n};\n\n/**\n * The field's own component, rendered again only when its own slice of the\n * form changed — value, error, touched, the flags — or when the context it\n * draws the record from did (see `fieldContext` in `EntityForm`). Every field\n * of the form used to re-render on every keystroke anywhere in it.\n *\n * A field that may read *another* field's value while rendering cannot know\n * when to re-render from its own props, so those always do: see\n * {@link shouldPropertyReRender}.\n */\nconst MemoisedField = React.memo(\n function MemoisedField({ Component, fieldProps }: MemoisedFieldProps) {\n return <Component {...fieldProps}/>;\n },\n (prev: MemoisedFieldProps, next: MemoisedFieldProps) =>\n !next.alwaysRender &&\n prev.Component === next.Component &&\n sameProps(prev.fieldProps, next.fieldProps, DEEP_COMPARED_FIELD_PROPS)\n);\n\n/**\n * Whether a field has to re-render on every change to the form, because what\n * it draws can depend on values other than its own:\n * - a plugin `fieldBuilder` wraps it in a component of the plugin's;\n * - a custom `admin.Field` gets the whole form through `context`;\n * - `dynamicProps` and `conditions` are functions of every value;\n * - a storage path or file name given as a function is built from the values\n * the binding holds;\n * - a custom `propertyConfig` whose property says any of the above, since the\n * field is resolved through it.\n * Inside maps, arrays and blocks too, since their bindings render the children.\n */\nconst shouldPropertyReRender = (property: Property | undefined, plugins?: RebasePlugin[], propertyConfigs?: Record<string, PropertyConfig>): boolean => {\n if (!property) return false;\n if (plugins?.some((plugin) => plugin.fieldBuilder)) {\n return true;\n }\n const recurse = (child: unknown) => shouldPropertyReRender(child as Property, plugins, propertyConfigs);\n if (isPropertyBuilder(property) || property.conditions || property.admin?.Field) {\n return true;\n }\n const storage = \"storage\" in property ? property.storage : undefined;\n if (storage && (typeof storage.storagePath === \"function\" || typeof storage.fileName === \"function\")) {\n return true;\n }\n const configProperty = property.propertyConfig ? propertyConfigs?.[property.propertyConfig]?.property : undefined;\n if (configProperty && configProperty !== property && recurse(configProperty)) {\n return true;\n }\n if (property.type === \"map\" && property.properties) {\n return Object.values(property.properties).some(recurse);\n }\n if (property.type === \"array\") {\n if (Array.isArray(property.of)) {\n return property.of.some(recurse);\n }\n if (property.of && recurse(property.of)) {\n return true;\n }\n if (property.oneOf?.properties) {\n return Object.values(property.oneOf.properties).some(recurse);\n }\n }\n return false;\n}\n\ninterface UseWrappedComponentParams<M extends Record<string, unknown> = Record<string, unknown>> {\n path?: string,\n collection?: AdminCollection<M>,\n propertyKey: string,\n property: Property,\n Component: ComponentType<FieldProps<Property, unknown, M>>,\n plugins?: RebasePlugin[]\n}\n\nfunction useWrappedComponent<T, M extends Record<string, unknown> = Record<string, unknown>>(\n {\n path,\n collection,\n propertyKey,\n property,\n Component,\n plugins\n }: UseWrappedComponentParams<M>\n): ComponentType<FieldProps<Property, unknown, M>> | null {\n\n // A fold, in plugin order: each plugin's `wrap` is handed the field as the\n // plugins before it left it, so every wrapper renders — the first plugin's\n // closest to the field, the last one's outermost. A plugin that returns\n // null, or is not `enabled` for this field, passes it on unchanged.\n const wrapperRef = useRef<ComponentType<FieldProps<Property, unknown, M>> | null>((() => {\n let Wrapped: ComponentType<FieldProps<Property, unknown, M>> | null = null;\n if (plugins) {\n plugins.forEach((plugin) => {\n const fieldId = getFieldId(property);\n if (fieldId && plugin.fieldBuilder) {\n const params: PluginFieldBuilderParams = {\n fieldConfigId: fieldId,\n propertyKey,\n property,\n Field: (Wrapped ?? Component) as ComponentType<CoreFieldProps<Property, unknown, Record<string, unknown>>>,\n plugin,\n path,\n collection: collection as AdminCollection | undefined\n };\n const enabled = plugin.fieldBuilder.enabled?.(params);\n if (enabled === undefined || enabled)\n Wrapped = (plugin.fieldBuilder.wrap(params) as ComponentType<FieldProps<Property, unknown, M>> | null) ?? Wrapped;\n }\n if (!fieldId) {\n console.warn(\"INTERNAL: Field id not found for property\", property);\n }\n });\n }\n return Wrapped;\n })());\n\n return wrapperRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,uBAAuB,MAAM,KAAK,+BAC1C,GAAuD,MACpD,UAAU,GAAG,GAAG,2BAA2B,CACnD;;;;;;;AAQA,IAAM,8CAA8B,IAAI,IAAI,CAAC,UAAU,CAAC;AACxD,IAAM,4CAA4B,IAAI,IAAI;CAAC;CAAY;CAAS;AAAa,CAAC;AAE9E,SAAS,UAAU,GAAW,GAAW,MAA4B;CACjE,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,KAAK,MAAM,OAAO,MAAM;EACpB,MAAM,IAAa,QAAQ,IAAI,GAAG,GAAG;EACrC,MAAM,IAAa,QAAQ,IAAI,GAAG,GAAG;EACrC,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG;EACrB,IAAI,KAAK,IAAI,GAAG,KAAK,UAAM,GAAG,CAAC,GAAG;EAClC,OAAO;CACX;CACA,OAAO;AACX;AAEA,SAAS,6BACR,EACI,aACA,UACA,SACA,oBACA,WACA,2BACA,UAAU,cACV,aACA,aACA,gBACA,WACA,OACA,MACA,oBACyE;CAE1E,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,0BAA0B,2BAA2B;CAG3D,MAAM,eAAe,uBAAuB,UAAsB,wBAAwB,SAAS,wBAAwB,eAAe;CAgB1I,MAAM,QAAQ,kBARM,aAAa,YAAmE;EAChG,QAAQ,eAAe,SAAS,KAAA;EAChC,OAAO,MAAM,OAAO,QAAQ,WAAW;EACvC,OAAO,MAAM,OAAO,QAAQ,WAAW;EACvC,SAAS,MAAM,OAAO,SAAS,WAAW;EAC1C,WAAW,OAAO,cA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UAAW,OAAO,aAAa,KAAK,MAAM,KAAgE;GAClH;GACA,IAAI,CAAC,SACD,QAAQ,KAAK,6CAA6C,QAAQ;EAE1E,CAAC;EAEL,OAAO;CACX,EAAA,CAAG,CAEI,CAAA,CAAW;AACtB"}
|
|
1
|
+
{"version":3,"file":"PropertyFieldBinding.js","names":[],"sources":["../../src/form/PropertyFieldBinding.tsx"],"sourcesContent":["\nimport type { FieldProps as CoreFieldProps, AdminCollection } from \"@rebasepro/cms-types\";\nimport type { FieldProps, PropertyFieldBindingProps } from \"../types/fields\";\nimport type { RebasePlugin, PluginFieldBuilderParams, PropertyConfig, Property } from \"@rebasepro/cms-types\";\nimport React, { ComponentType, ReactElement, Suspense, useCallback, useRef } from \"react\";\nimport { deepEqual as equal } from \"fast-equals\"\n\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\n;\nimport { ReadOnlyFieldBinding } from \"./field_bindings/ReadOnlyFieldBinding\";\nimport { resolveFormProperty } from \"./resolve_form_properties\";\nimport { useClearRestoreValue } from \"./useClearRestoreValue\";\n\nimport { isPropertyBuilder, resolveProperty } from \"@rebasepro/cms-types\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { useAuthController, useCustomizationController, useRebaseContext, useSlot, useTranslation } from \"@rebasepro/app\";\nimport { Typography } from \"@rebasepro/ui\";\nimport { getFieldConfig, getFieldId } from \"../components/field_configs\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\n\n/**\n * This component renders a form field creating the corresponding configuration\n * from a property. For example if bound to a string property, it will generate\n * a text field.\n *\n * You can use it when you are creating a custom field, and need to\n * render additional fields mapped to properties. This is useful if you\n * need to build a complex property mapping, like an array where each index\n * is a different property.\n *\n * Please note that if you build a custom field in a component, the\n * **validation** passed in the property will have no effect. You need to set\n * the validation in the `AdminCollection` definition.\n *\n * @param propertyKey You can use nested names such as `address.street` or `friends[2]`\n * @param property\n * @param context\n * @param includeDescription\n * @param underlyingValueHasChanged\n * @param disabled\n * @param tableMode\n * @param partOfArray\n * @param autoFocus\n * @group Form custom fields\n */\nexport const PropertyFieldBinding = React.memo(PropertyFieldBindingInternal,\n (a: PropertyFieldBindingProps<Record<string, unknown>>, b: PropertyFieldBindingProps<Record<string, unknown>>) =>\n sameProps(a, b, DEEP_COMPARED_BINDING_PROPS)\n) as typeof PropertyFieldBindingInternal;\n\n/**\n * Props compared by value rather than identity: a property is re-resolved\n * (`dynamicProps`, enums, a parent's `mergeDeep`) into a new object on every\n * render of whatever holds it, and an error for an array or map is a new\n * sub-object of the errors map whenever anything is validated.\n */\nconst DEEP_COMPARED_BINDING_PROPS = new Set([\"property\"]);\nconst DEEP_COMPARED_FIELD_PROPS = new Set([\"property\", \"error\", \"customProps\"]);\n\nfunction sameProps(a: object, b: object, deep: Set<string>): boolean {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) {\n const x: unknown = Reflect.get(a, key);\n const y: unknown = Reflect.get(b, key);\n if (Object.is(x, y)) continue;\n if (deep.has(key) && equal(x, y)) continue;\n return false;\n }\n return true;\n}\n\nfunction PropertyFieldBindingInternal<M extends Record<string, unknown> = Record<string, unknown>>\n({\n propertyKey,\n property,\n context,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n disabled: disabledProp,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n index,\n size,\n onPropertyChange\n }: PropertyFieldBindingProps<M>): ReactElement<PropertyFieldBindingProps<M>> {\n\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n // Decided on the property as declared: once resolved, a builder or a rule\n // no longer says it was one.\n const alwaysRender = shouldPropertyReRender(property as Property, customizationController.plugins, customizationController.propertyConfigs);\n\n // This field's own slice of the form, so a change anywhere else does not\n // reach it. Through the form's context — which `Field` read — every field\n // of a record form re-rendered on every keystroke anywhere in it: all 500\n // items of an array nobody was typing into. A field that reads the rest of\n // the form while rendering takes the whole controller, and with it every\n // change, as it always has.\n const selectSlice = useCallback((formex: FormexController<Record<string, unknown>>): FieldSlice => ({\n formex: alwaysRender ? formex : undefined,\n value: getIn(formex.values, propertyKey),\n error: getIn(formex.errors, propertyKey) as FieldSlice[\"error\"],\n touched: getIn(formex.touched, propertyKey) as boolean | undefined,\n submitted: formex.submitCount > 0,\n isSubmitting: formex.isSubmitting\n }), [propertyKey, alwaysRender]);\n const slice = useFormexSelector(selectSlice, sameSlice);\n const getFormex = useFormexGetter<Record<string, unknown>>();\n // What the property is resolved against. Read, not subscribed to, for a\n // field that is not `alwaysRender`: nothing it declares reads the values.\n const values = (slice.formex ?? getFormex()).values;\n\n let Component: ComponentType<FieldProps<Property, any, any>> | undefined;\n // `dynamicProps` and `conditions` both, as the save judges it.\n const resolvedProperty = resolveFormProperty({\n propertyKey,\n property: property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n\n const readOnly = resolvedProperty ? isReadOnly(resolvedProperty) : true;\n const disabled = disabledProp || readOnly || (resolvedProperty ? isDisabled(resolvedProperty) : false) || context.disabled;\n\n if (resolvedProperty === null || isHidden(resolvedProperty)) {\n return <></>;\n } else if (readOnly) {\n Component = ReadOnlyFieldBinding;\n } else if (resolvedProperty.admin?.Field) {\n Component = resolvedProperty.admin.Field;\n } else {\n const propertyConfig = getFieldConfig(resolvedProperty, customizationController.propertyConfigs);\n if (!propertyConfig) {\n throw new Error(`INTERNAL: Could not find field config for property ${propertyKey}`);\n }\n const configProperty = resolveProperty({\n propertyKey,\n property: propertyConfig.property as Property,\n values,\n path: context.path,\n entityId: context.id,\n propertyConfigs: customizationController.propertyConfigs,\n index,\n authController\n }) as Property | null;\n Component = configProperty?.admin?.Field;\n }\n if (!Component) {\n console.warn(`No field component found for property ${propertyKey}`);\n console.warn(\"Property:\", property);\n return (\n <div className={\"w-full\"}>\n {`Currently the field ${resolvedProperty.type} is not supported`}\n </div>\n );\n }\n\n const componentProps: ResolvedPropertyFieldBindingProps<M> = {\n propertyKey,\n property: resolvedProperty,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n context,\n disabled,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n size,\n onPropertyChange\n };\n\n // Keyed on the path, as the `Field` it replaces was: an array item that\n // moves to another index is a new field there.\n return <FieldInternal\n key={propertyKey}\n Component={Component as ComponentType<FieldProps<Property, any, any>>}\n alwaysRender={alwaysRender}\n componentProps={componentProps}\n slice={slice}\n getFormex={getFormex}/>;\n\n}\n\n/**\n * What one field reads from the form. `formex` is set only for a field that\n * re-renders on every change (see {@link shouldPropertyReRender}).\n */\ntype FieldSlice = {\n formex: FormexController<Record<string, unknown>> | undefined;\n value: unknown;\n error: string | string[] | Record<string, unknown> | undefined;\n touched: boolean | undefined;\n submitted: boolean;\n isSubmitting: boolean;\n};\n\nfunction sameSlice(a: FieldSlice, b: FieldSlice): boolean {\n return a.formex === b.formex &&\n Object.is(a.value, b.value) &&\n a.touched === b.touched &&\n a.submitted === b.submitted &&\n a.isSubmitting === b.isSubmitting &&\n // An array's or a map's error is a sub-object of the errors map, new\n // whenever anything is validated.\n (Object.is(a.error, b.error) || equal(a.error, b.error));\n}\n\ntype ResolvedPropertyFieldBindingProps<M extends Record<string, unknown> = Record<string, unknown>> =\n Omit<PropertyFieldBindingProps<M>, \"property\">\n & {\n property: Property\n};\n\nfunction FieldInternal<CustomProps, M extends Record<string, unknown>>\n({\n Component,\n alwaysRender,\n componentProps: {\n propertyKey,\n property,\n includeDescription,\n hideLabel,\n underlyingValueHasChanged,\n partOfArray,\n partOfBlock,\n minimalistView,\n autoFocus,\n context,\n disabled,\n size,\n onPropertyChange\n },\n slice,\n getFormex\n }:\n {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n componentProps: ResolvedPropertyFieldBindingProps<M>,\n slice: FieldSlice,\n getFormex: () => FormexController<Record<string, unknown>>\n }) {\n\n const { plugins } = useCustomizationController();\n const { t } = useTranslation();\n\n // This is the one component every form field goes through, which is why the\n // two field slots render here rather than in each field binding: a slot\n // honoured by the string field and not by the date field is worse than one\n // that never renders at all.\n const rebaseContext = useRebaseContext();\n const fieldSlotProps = React.useMemo(() => ({\n propertyKey,\n property,\n path: context.path ?? \"\",\n id: context.id,\n collection: context.collection,\n context: rebaseContext\n }), [propertyKey, property, context.path, context.id, context.collection, rebaseContext]);\n const beforeField = useSlot(\"entity.field.before\", fieldSlotProps);\n const afterField = useSlot(\"entity.field.after\", fieldSlotProps);\n\n const customFieldProps: unknown = property.admin?.customProps;\n const { value, error, touched, isSubmitting } = slice;\n\n const showError = Boolean(error &&\n (slice.submitted || property.validation?.unique) &&\n (!Array.isArray(error) || !!error.filter((e: unknown) => !!e).length));\n\n const WrappedComponent: ComponentType<FieldProps<Property, any, any>> | null = useWrappedComponent<unknown, any>({\n path: context.path,\n collection: context.collection,\n propertyKey: propertyKey,\n property: property,\n Component: Component as ComponentType<FieldProps<Property, unknown, M>>,\n plugins: plugins\n });\n const UsedComponent: ComponentType<FieldProps<Property, any, any>> = WrappedComponent ?? Component;\n\n // Read the controller when called, not when rendered: this component\n // re-renders with its own slice only, and the form moves on without it.\n const setValue = useCallback((value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(propertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n const setFieldValue = useCallback((otherPropertyKey: string, value: unknown | null, shouldValidate?: boolean) => {\n const formex = getFormex();\n formex.setFieldTouched(propertyKey, true, false);\n formex.setFieldValue(otherPropertyKey, value, shouldValidate);\n }, [getFormex, propertyKey]);\n\n // `disabled: { clearOnDisabled: true }`, for every field: called here and\n // not in each binding, where six of them never did and a disabled relation\n // kept its value and saved it.\n useClearRestoreValue({ property: property as Property, value, setValue });\n\n // A parent that builds `onPropertyChange` inline (an array item's\n // `storeProps`, a map's wrapper) would otherwise hand every child a new\n // function on each of its renders, and every child would re-render for it.\n const onPropertyChangeRef = useRef(onPropertyChange);\n onPropertyChangeRef.current = onPropertyChange;\n const stableOnPropertyChange = useCallback((changed: Partial<Property>) => onPropertyChangeRef.current?.(changed), []);\n\n const cmsFieldProps: FieldProps<Property, CustomProps, M> = {\n propertyKey,\n value,\n setValue,\n setFieldValue,\n error: error as string | undefined,\n touched,\n showError,\n isSubmitting,\n includeDescription: includeDescription ?? true,\n hideLabel: hideLabel ?? false,\n property: property as Property,\n disabled: disabled ?? false,\n underlyingValueHasChanged: underlyingValueHasChanged ?? false,\n partOfArray: partOfArray ?? false,\n partOfBlock: partOfBlock ?? false,\n minimalistView: minimalistView ?? false,\n autoFocus: autoFocus ?? false,\n customProps: customFieldProps as CustomProps,\n context,\n size,\n onPropertyChange: onPropertyChange ? stableOnPropertyChange : undefined\n };\n\n return (\n <ErrorBoundary>\n {beforeField}\n\n <Suspense fallback={null}>\n <MemoisedField Component={UsedComponent}\n alwaysRender={alwaysRender}\n fieldProps={cmsFieldProps as FieldProps<Property, any, any>}/>\n </Suspense>\n\n {afterField}\n\n {underlyingValueHasChanged && !isSubmitting &&\n <Typography variant={\"caption\"} className={\"ml-3.5\"}>\n {t(\"value_updated_elsewhere\")}\n </Typography>}\n\n </ErrorBoundary>);\n\n}\n\ntype MemoisedFieldProps = {\n Component: ComponentType<FieldProps<Property, any, any>>,\n alwaysRender: boolean,\n fieldProps: FieldProps<Property, any, any>\n};\n\n/**\n * The field's own component, rendered again only when its own slice of the\n * form changed — value, error, touched, the flags — or when the context it\n * draws the record from did (see `fieldContext` in `EntityForm`). Every field\n * of the form used to re-render on every keystroke anywhere in it.\n *\n * A field that may read *another* field's value while rendering cannot know\n * when to re-render from its own props, so those always do: see\n * {@link shouldPropertyReRender}.\n */\nconst MemoisedField = React.memo(\n function MemoisedField({ Component, fieldProps }: MemoisedFieldProps) {\n return <Component {...fieldProps}/>;\n },\n (prev: MemoisedFieldProps, next: MemoisedFieldProps) =>\n !next.alwaysRender &&\n prev.Component === next.Component &&\n sameProps(prev.fieldProps, next.fieldProps, DEEP_COMPARED_FIELD_PROPS)\n);\n\n/**\n * Whether a field has to re-render on every change to the form, because what\n * it draws can depend on values other than its own:\n * - a plugin `fieldBuilder` wraps it in a component of the plugin's;\n * - a custom `admin.Field` gets the whole form through `context`;\n * - `dynamicProps` and `conditions` are functions of every value;\n * - a storage path or file name given as a function is built from the values\n * the binding holds;\n * - a custom `propertyConfig` whose property says any of the above, since the\n * field is resolved through it.\n * Inside maps, arrays and blocks too, since their bindings render the children.\n */\nconst shouldPropertyReRender = (property: Property | undefined, plugins?: RebasePlugin[], propertyConfigs?: Record<string, PropertyConfig>): boolean => {\n if (!property) return false;\n if (plugins?.some((plugin) => plugin.fieldBuilder)) {\n return true;\n }\n const recurse = (child: unknown) => shouldPropertyReRender(child as Property, plugins, propertyConfigs);\n if (isPropertyBuilder(property) || property.conditions || property.admin?.Field) {\n return true;\n }\n const storage = \"storage\" in property ? property.storage : undefined;\n if (storage && (typeof storage.storagePath === \"function\" || typeof storage.fileName === \"function\")) {\n return true;\n }\n const configProperty = property.propertyConfig ? propertyConfigs?.[property.propertyConfig]?.property : undefined;\n if (configProperty && configProperty !== property && recurse(configProperty)) {\n return true;\n }\n if (property.type === \"map\" && property.properties) {\n return Object.values(property.properties).some(recurse);\n }\n if (property.type === \"array\") {\n if (Array.isArray(property.of)) {\n return property.of.some(recurse);\n }\n if (property.of && recurse(property.of)) {\n return true;\n }\n if (property.oneOf?.properties) {\n return Object.values(property.oneOf.properties).some(recurse);\n }\n }\n return false;\n}\n\ninterface UseWrappedComponentParams<M extends Record<string, unknown> = Record<string, unknown>> {\n path?: string,\n collection?: AdminCollection<M>,\n propertyKey: string,\n property: Property,\n Component: ComponentType<FieldProps<Property, unknown, M>>,\n plugins?: RebasePlugin[]\n}\n\nfunction useWrappedComponent<T, M extends Record<string, unknown> = Record<string, unknown>>(\n {\n path,\n collection,\n propertyKey,\n property,\n Component,\n plugins\n }: UseWrappedComponentParams<M>\n): ComponentType<FieldProps<Property, unknown, M>> | null {\n\n // A fold, in plugin order: each plugin's `wrap` is handed the field as the\n // plugins before it left it, so every wrapper renders — the first plugin's\n // closest to the field, the last one's outermost. A plugin that returns\n // null, or is not `enabled` for this field, passes it on unchanged.\n const wrapperRef = useRef<ComponentType<FieldProps<Property, unknown, M>> | null>((() => {\n let Wrapped: ComponentType<FieldProps<Property, unknown, M>> | null = null;\n if (plugins) {\n plugins.forEach((plugin) => {\n const fieldId = getFieldId(property);\n if (fieldId && plugin.fieldBuilder) {\n const params: PluginFieldBuilderParams = {\n fieldConfigId: fieldId,\n propertyKey,\n property,\n Field: (Wrapped ?? Component) as ComponentType<CoreFieldProps<Property, unknown, Record<string, unknown>>>,\n plugin,\n path,\n collection: collection as AdminCollection | undefined\n };\n const enabled = plugin.fieldBuilder.enabled?.(params);\n if (enabled === undefined || enabled)\n Wrapped = (plugin.fieldBuilder.wrap(params) as ComponentType<FieldProps<Property, unknown, M>> | null) ?? Wrapped;\n }\n if (!fieldId) {\n console.warn(\"INTERNAL: Field id not found for property\", property);\n }\n });\n }\n return Wrapped;\n })());\n\n return wrapperRef.current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,uBAAuB,MAAM,KAAK,+BAC1C,GAAuD,MACpD,UAAU,GAAG,GAAG,2BAA2B,CACnD;;;;;;;AAQA,IAAM,8CAA8B,IAAI,IAAI,CAAC,UAAU,CAAC;AACxD,IAAM,4CAA4B,IAAI,IAAI;CAAC;CAAY;CAAS;AAAa,CAAC;AAE9E,SAAS,UAAU,GAAW,GAAW,MAA4B;CACjE,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,KAAK,MAAM,OAAO,MAAM;EACpB,MAAM,IAAa,QAAQ,IAAI,GAAG,GAAG;EACrC,MAAM,IAAa,QAAQ,IAAI,GAAG,GAAG;EACrC,IAAI,OAAO,GAAG,GAAG,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EAEX,IAAI,SAAS,OAAO,YAChB,OAAO,OAAO,OAAO,SAAS,MAAM,UAAU,CAAC,CAAC,KAAK,OAAO;CAEpE;CACA,OAAO;AACX;AAWA,SAAS,oBACL,EACI,MACA,YACA,aACA,UACA,WACA,WAEkD;CAiCtD,OA3BmB,cAAsE;EACrF,IAAI,UAAkE;EACtE,IAAI,SACA,QAAQ,SAAS,WAAW;GACxB,MAAM,UAAU,WAAW,QAAQ;GACnC,IAAI,WAAW,OAAO,cAAc;IAChC,MAAM,SAAmC;KACrC,eAAe;KACf;KACA;KACA,OAAQ,WAAW;KACnB;KACA;KACY;IAChB;IACA,MAAM,UAAU,OAAO,aAAa,UAAU,MAAM;IACpD,IAAI,YAAY,KAAA,KAAa,SACzB,UAAW,OAAO,aAAa,KAAK,MAAM,KAAgE;GAClH;GACA,IAAI,CAAC,SACD,QAAQ,KAAK,6CAA6C,QAAQ;EAE1E,CAAC;EAEL,OAAO;CACX,EAAA,CAAG,CAEI,CAAA,CAAW;AACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldBlock.js","names":[],"sources":["../../../src/form/components/FieldBlock.tsx"],"sourcesContent":["import type { Property } from \"@rebasepro/types\";\nimport type { PropertySpan } from \"@rebasepro/cms-types\";\nimport React from \"react\";\nimport { cls, ErrorBoundary, Typography } from \"@rebasepro/ui\";\nimport { isReadOnly } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { PropertyKeyHint } from \"../../components/PropertyKeyHint\";\nimport { fieldDomId, useFormDomScope } from \"../form_dom_ids\";\n\n/**\n * Grid placement for a span.\n *\n * Written out as literal class strings rather than composed, because Tailwind\n * scans source text: a template literal would produce classes that exist at\n * runtime and were never generated into the stylesheet.\n *\n * Below the column breakpoint every field takes the single available column, so\n * the side panel, the dialog and mobile all get a plain stack.\n *\n * Lives here rather than in the form, because the read-only rendering of a\n * record places its fields on the same grid — a record that changes shape when\n * you press Edit is the bug this whole layout exists to avoid.\n */\nexport function spanClass(span: PropertySpan): string {\n switch (span) {\n case 1: return \"@2xl/col:col-span-1\";\n case 2: return \"@2xl/col:col-span-2\";\n case 3: return \"@2xl/col:col-span-3\";\n case 4: return \"@2xl/col:col-span-4\";\n }\n}\n\n/**\n * Does this property's editor supply its own heading?\n *\n * Arrays, maps, `oneOf` blocks and key-value editors render as a collapsible\n * panel whose header *is* the label — hiding it would leave a panel you cannot\n * identify or, worse, cannot expand. Those keep their own; everything else gets\n * its label from {@link FieldBlock}, which is what makes a text field and a\n * select finally agree on where a label goes.\n *\n * Exported because the layout resolver's span rules and this rule have to stay\n * in step: the self-labelling types are exactly the ones that take a full row.\n */\nexport function isSelfLabellingProperty(property: Property | undefined): boolean {\n if (!property) return false;\n switch (property.type) {\n case \"map\":\n // `spreadChildren` inlines the children into the parent grid, so\n // there is no panel and therefore no header to reuse as the label.\n return !property.admin?.spreadChildren;\n case \"array\": {\n // Most arrays render as an expandable panel whose header is the\n // label — `repeat`, `block`, `custom_array`, `multi_references`.\n // The exceptions are the ones that resolve to an inline control:\n // an enum array is a multi-select and a storage array is a\n // dropzone, and both take their label from the form.\n //\n // This mirrors `getFieldConfig`'s array branch. Getting it backwards\n // is visible: an array of plain strings is a `repeat` panel, and\n // treating it as inline printed \"Available Locales\" twice, once\n // from the form and once from the panel's own header.\n if (property.oneOf) return true;\n if (Array.isArray(property.of) || !property.of) return true;\n const of = property.of;\n if (of.type === \"string\" && (of.enum || of.storage)) return false;\n if (of.type === \"number\" && of.enum) return false;\n return true;\n }\n default:\n return false;\n }\n}\n\n/**\n * The type icon in a field label, in px.\n *\n * Matched to the label's 13px rather than taken from `iconSize.smallest` (16),\n * which is sized for buttons. Exported so the surfaces that draw a label\n * themselves — the additional-field cards, the rail — can stay in step.\n */\nexport const LABEL_ICON_SIZE = 14;\n\nexport interface FieldBlockProps {\n propertyKey: string;\n property?: Property;\n /** Rendered by the form rather than by the field, unless self-labelling. */\n showLabel: boolean;\n /**\n * The control draws its label inside its own box — the one-line fields of a\n * record form (see `labelsInsideControl`). The block then draws no label\n * row, but it still owns what goes under the box: the description, indented\n * to the value inside the box, and the property's key, on that same line.\n */\n labelInside?: boolean;\n /**\n * Which of the two renderings this block frames.\n *\n * The **label is identical in both** — same size, same weight, same colour,\n * same type icon, same required marker. A field is the same field whether or\n * not you are editing it, and a record whose labels restyle themselves under\n * Edit reads as two different screens.\n *\n * What `\"read\"` drops is the *description*, which is not part of the label:\n * it is input help. \"Sum of all line items before tax and shipping\" under a\n * number that is visibly a sum tells a reader nothing, and a line of it\n * under every field is what a record has instead of room.\n */\n mode?: \"edit\" | \"read\";\n /**\n * Label text, when there is no property to take it from.\n *\n * For additional fields, which are columns a collection computes rather\n * than stores. They go on the same grid as the properties and so have to\n * carry the same label — drawing their own is how they ended up a size out\n * and a couple of pixels off from the field beside them.\n */\n label?: string;\n /** Type icon, when there is no property to derive one from. */\n icon?: React.ReactNode;\n children: React.ReactNode;\n}\n\n/**\n * One field's worth of the form grid: label, control, description.\n *\n * The same block frames the read-only rendering of a record, so a field sits in\n * the same place, at the same width, under the same label whether or not you are\n * editing it — see {@link EntityViewBinding}.\n *\n * The label is one size down from the control it names (13px against the body's\n * 14) with its icon matched to it at 14px. Labels are scaffolding: you read them\n * to find the value, then read the value. Setting them at body size made a\n * column of records scan as a column of field names with data attached.\n */\nexport function FieldBlock({\n propertyKey,\n property,\n showLabel,\n labelInside = false,\n mode = \"edit\",\n label,\n icon,\n children\n}: FieldBlockProps) {\n\n const reading = mode === \"read\";\n const description = property?.description?.trim();\n // Only where someone can supply the value: on a read-only field the marker\n // asks for input nobody can give, and `validation.required` there states\n // what the column holds, which the form need not shout about.\n const required = Boolean(property?.validation?.required) && !(property && isReadOnly(property));\n const footed = labelInside && !reading;\n const domScope = useFormDomScope();\n\n return (\n // Top-aligned: with the description below the control, every label is a\n // single line, so the controls line up on their own. (Bottom-aligning\n // was only needed while the description sat between label and control.)\n <div\n id={fieldDomId(domScope, propertyKey)}\n data-form-field={propertyKey}\n // With the label inside the control there is no label row to hover\n // for the key; the whole field reveals it instead.\n className={cls(\"relative flex flex-col min-w-0\", footed && \"group/label\")}>\n\n {showLabel && (\n <div className={cls(\n \"group/label flex items-center gap-1.5 min-w-0 font-medium leading-tight mb-1.5\",\n // Primary, not secondary: the label names the field and the\n // reference sets its labels in the primary ink; the type icon\n // beside it stays muted so the name carries the row.\n \"text-[13px] text-text-primary dark:text-text-primary-dark\"\n )}>\n {/* Small and quiet: enough to tell a number from a\n relation at a glance, not enough to compete with the\n field name. Matched to the label's 13px rather than\n left at the 16px `smallest` token, which put the\n heaviest mark on the row on the least important\n thing in it. */}\n {(property || icon) && (\n <span className={\"shrink-0 text-text-disabled dark:text-text-disabled-dark\"}>\n {property ? getIconForProperty(property, LABEL_ICON_SIZE) : icon}\n </span>\n )}\n <span className={\"truncate\"}>{property?.name ?? label ?? propertyKey}</span>\n {required && <span className={\"text-red-500 dark:text-red-500 -ml-1\"}>*</span>}\n {/* In the row, not over it. This was a tooltip on the\n label and on the control, which opened whenever a\n field took focus and covered the label being read. */}\n {property && <PropertyKeyHint propertyKey={propertyKey}/>}\n </div>\n )}\n\n {/* `data-field-control` names the slot for anything measuring the\n control itself. A class cannot: the label row carries\n `min-w-0` too, and a selector for it measured the label. */}\n <div className={\"min-w-0\"} data-field-control={\"\"}>\n <ErrorBoundary>\n {children}\n </ErrorBoundary>\n </div>\n\n {/* Under the control, where it reads as a note about the thing you\n just filled in rather than a subtitle of the next label. */}\n {showLabel && description && !reading && (\n <Typography variant={\"caption\"}\n color={\"disabled\"}\n className={\"mt-1.5 ml-0.5 leading-snug\"}>\n {description}\n </Typography>\n )}\n\n {/* A label drawn inside the box: the description is indented to\n the value, as the binding's own error line is (`ml-3.5`), and\n the key sits at the end of that line. A field with no\n description has no line to put it on, so the key hangs in the\n row gap below the box rather than reserving a line under every\n field for something only a hover shows. */}\n {footed && (description || property) && (\n <div className={cls(\n \"flex items-start gap-2 min-w-0 ml-3.5\",\n description ? \"mt-1.5\" : \"absolute top-full right-0 mt-1\"\n )}>\n {description && (\n <Typography variant={\"caption\"}\n color={\"disabled\"}\n className={\"grow min-w-0 leading-snug\"}>\n {description}\n </Typography>\n )}\n {property && <PropertyKeyHint propertyKey={propertyKey}\n className={description ? \"ml-auto shrink-0\" : undefined}/>}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,UAAU,MAA4B;CAClD,QAAQ,MAAR;EACI,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;CACnB;AACJ;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,UAAyC;CAC7E,IAAI,CAAC,UAAU,OAAO;CACtB,QAAQ,SAAS,MAAjB;EACI,KAAK,OAGD,OAAO,CAAC,SAAS,OAAO;EAC5B,KAAK,SAAS;GAWV,IAAI,SAAS,OAAO,OAAO;GAC3B,IAAI,MAAM,QAAQ,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,OAAO;GACvD,MAAM,KAAK,SAAS;GACpB,IAAI,GAAG,SAAS,aAAa,GAAG,QAAQ,GAAG,UAAU,OAAO;GAC5D,IAAI,GAAG,SAAS,YAAY,GAAG,MAAM,OAAO;GAC5C,OAAO;EACX;EACA,SACI,OAAO;CACf;AACJ;;;;;;;;AASA,IAAa,kBAAkB;;;;;;;;;;;;;AAsD/B,SAAgB,WAAW,EACvB,aACA,UACA,WACA,cAAc,OACd,OAAO,QACP,OACA,MACA,YACgB;CAEhB,MAAM,UAAU,SAAS;CACzB,MAAM,cAAc,UAAU,aAAa,KAAK;CAIhD,MAAM,WAAW,QAAQ,UAAU,YAAY,QAAQ,KAAK,EAAE,YAAY,WAAW,QAAQ;CAC7F,MAAM,SAAS,eAAe,CAAC;CAG/B,OAII,qBAAC,OAAD;EACI,IAAI,WAPK,gBAOM,GAAU,WAAW;EACpC,mBAAiB;EAGjB,WAAW,IAAI,kCAAkC,UAAU,aAAa;YAL5E;GAOK,aACG,qBAAC,OAAD;IAAK,WAAW,IACZ,kFAIA,2DACJ;cANA;MAaM,YAAY,SACV,oBAAC,QAAD;MAAM,WAAW;gBACZ,WAAW,mBAAmB,UAAA,EAAyB,IAAI;KAC1D,CAAA;KAEV,oBAAC,QAAD;MAAM,WAAW;gBAAa,UAAU,QAAQ,SAAS;KAAkB,CAAA;KAC1E,YAAY,oBAAC,QAAD;MAAM,WAAW;gBAAwC;KAAO,CAAA;KAI5E,YAAY,oBAAC,iBAAD,EAA8B,YAAa,CAAA;IACvD;;GAMT,oBAAC,OAAD;IAAK,WAAW;IAAW,sBAAoB;cAC3C,oBAAC,eAAD,EACK,SACU,CAAA;GACd,CAAA;GAIJ,aAAa,eAAe,CAAC,WAC1B,oBAAC,YAAD;IAAY,SAAS;IACjB,OAAO;IACP,WAAW;cACV;GACO,CAAA;GASf,WAAW,eAAe,aACvB,qBAAC,OAAD;IAAK,WAAW,IACZ,yCACA,cAAc,WAAW,gCAC7B;cAHA,CAIK,eACG,oBAAC,YAAD;KAAY,SAAS;KACjB,OAAO;KACP,WAAW;eACV;IACO,CAAA,GAEf,YAAY,oBAAC,iBAAD;KAA8B;KACvC,WAAW,cAAc,qBAAqB,KAAA;IAAW,CAAA,CAC5D;;EAER;;AAEb"}
|
|
1
|
+
{"version":3,"file":"FieldBlock.js","names":[],"sources":["../../../src/form/components/FieldBlock.tsx"],"sourcesContent":["import type { PropertySpan, Property } from \"@rebasepro/cms-types\";\nimport React from \"react\";\nimport { cls, ErrorBoundary, Typography } from \"@rebasepro/ui\";\nimport { isReadOnly } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { PropertyKeyHint } from \"../../components/PropertyKeyHint\";\nimport { fieldDomId, useFormDomScope } from \"../form_dom_ids\";\n\n/**\n * Grid placement for a span.\n *\n * Written out as literal class strings rather than composed, because Tailwind\n * scans source text: a template literal would produce classes that exist at\n * runtime and were never generated into the stylesheet.\n *\n * Below the column breakpoint every field takes the single available column, so\n * the side panel, the dialog and mobile all get a plain stack.\n *\n * Lives here rather than in the form, because the read-only rendering of a\n * record places its fields on the same grid — a record that changes shape when\n * you press Edit is the bug this whole layout exists to avoid.\n */\nexport function spanClass(span: PropertySpan): string {\n switch (span) {\n case 1: return \"@2xl/col:col-span-1\";\n case 2: return \"@2xl/col:col-span-2\";\n case 3: return \"@2xl/col:col-span-3\";\n case 4: return \"@2xl/col:col-span-4\";\n }\n}\n\n/**\n * Does this property's editor supply its own heading?\n *\n * Arrays, maps, `oneOf` blocks and key-value editors render as a collapsible\n * panel whose header *is* the label — hiding it would leave a panel you cannot\n * identify or, worse, cannot expand. Those keep their own; everything else gets\n * its label from {@link FieldBlock}, which is what makes a text field and a\n * select finally agree on where a label goes.\n *\n * Exported because the layout resolver's span rules and this rule have to stay\n * in step: the self-labelling types are exactly the ones that take a full row.\n */\nexport function isSelfLabellingProperty(property: Property | undefined): boolean {\n if (!property) return false;\n switch (property.type) {\n case \"map\":\n // `spreadChildren` inlines the children into the parent grid, so\n // there is no panel and therefore no header to reuse as the label.\n return !property.admin?.spreadChildren;\n case \"array\": {\n // Most arrays render as an expandable panel whose header is the\n // label — `repeat`, `block`, `custom_array`, `multi_references`.\n // The exceptions are the ones that resolve to an inline control:\n // an enum array is a multi-select and a storage array is a\n // dropzone, and both take their label from the form.\n //\n // This mirrors `getFieldConfig`'s array branch. Getting it backwards\n // is visible: an array of plain strings is a `repeat` panel, and\n // treating it as inline printed \"Available Locales\" twice, once\n // from the form and once from the panel's own header.\n if (property.oneOf) return true;\n if (Array.isArray(property.of) || !property.of) return true;\n const of = property.of;\n if (of.type === \"string\" && (of.enum || of.storage)) return false;\n if (of.type === \"number\" && of.enum) return false;\n return true;\n }\n default:\n return false;\n }\n}\n\n/**\n * The type icon in a field label, in px.\n *\n * Matched to the label's 13px rather than taken from `iconSize.smallest` (16),\n * which is sized for buttons. Exported so the surfaces that draw a label\n * themselves — the additional-field cards, the rail — can stay in step.\n */\nexport const LABEL_ICON_SIZE = 14;\n\nexport interface FieldBlockProps {\n propertyKey: string;\n property?: Property;\n /** Rendered by the form rather than by the field, unless self-labelling. */\n showLabel: boolean;\n /**\n * The control draws its label inside its own box — the one-line fields of a\n * record form (see `labelsInsideControl`). The block then draws no label\n * row, but it still owns what goes under the box: the description, indented\n * to the value inside the box, and the property's key, on that same line.\n */\n labelInside?: boolean;\n /**\n * Which of the two renderings this block frames.\n *\n * The **label is identical in both** — same size, same weight, same colour,\n * same type icon, same required marker. A field is the same field whether or\n * not you are editing it, and a record whose labels restyle themselves under\n * Edit reads as two different screens.\n *\n * What `\"read\"` drops is the *description*, which is not part of the label:\n * it is input help. \"Sum of all line items before tax and shipping\" under a\n * number that is visibly a sum tells a reader nothing, and a line of it\n * under every field is what a record has instead of room.\n */\n mode?: \"edit\" | \"read\";\n /**\n * Label text, when there is no property to take it from.\n *\n * For additional fields, which are columns a collection computes rather\n * than stores. They go on the same grid as the properties and so have to\n * carry the same label — drawing their own is how they ended up a size out\n * and a couple of pixels off from the field beside them.\n */\n label?: string;\n /** Type icon, when there is no property to derive one from. */\n icon?: React.ReactNode;\n children: React.ReactNode;\n}\n\n/**\n * One field's worth of the form grid: label, control, description.\n *\n * The same block frames the read-only rendering of a record, so a field sits in\n * the same place, at the same width, under the same label whether or not you are\n * editing it — see {@link EntityViewBinding}.\n *\n * The label is one size down from the control it names (13px against the body's\n * 14) with its icon matched to it at 14px. Labels are scaffolding: you read them\n * to find the value, then read the value. Setting them at body size made a\n * column of records scan as a column of field names with data attached.\n */\nexport function FieldBlock({\n propertyKey,\n property,\n showLabel,\n labelInside = false,\n mode = \"edit\",\n label,\n icon,\n children\n}: FieldBlockProps) {\n\n const reading = mode === \"read\";\n const description = property?.description?.trim();\n // Only where someone can supply the value: on a read-only field the marker\n // asks for input nobody can give, and `validation.required` there states\n // what the column holds, which the form need not shout about.\n const required = Boolean(property?.validation?.required) && !(property && isReadOnly(property));\n const footed = labelInside && !reading;\n const domScope = useFormDomScope();\n\n return (\n // Top-aligned: with the description below the control, every label is a\n // single line, so the controls line up on their own. (Bottom-aligning\n // was only needed while the description sat between label and control.)\n <div\n id={fieldDomId(domScope, propertyKey)}\n data-form-field={propertyKey}\n // With the label inside the control there is no label row to hover\n // for the key; the whole field reveals it instead.\n className={cls(\"relative flex flex-col min-w-0\", footed && \"group/label\")}>\n\n {showLabel && (\n <div className={cls(\n \"group/label flex items-center gap-1.5 min-w-0 font-medium leading-tight mb-1.5\",\n // Primary, not secondary: the label names the field and the\n // reference sets its labels in the primary ink; the type icon\n // beside it stays muted so the name carries the row.\n \"text-[13px] text-text-primary dark:text-text-primary-dark\"\n )}>\n {/* Small and quiet: enough to tell a number from a\n relation at a glance, not enough to compete with the\n field name. Matched to the label's 13px rather than\n left at the 16px `smallest` token, which put the\n heaviest mark on the row on the least important\n thing in it. */}\n {(property || icon) && (\n <span className={\"shrink-0 text-text-disabled dark:text-text-disabled-dark\"}>\n {property ? getIconForProperty(property, LABEL_ICON_SIZE) : icon}\n </span>\n )}\n <span className={\"truncate\"}>{property?.name ?? label ?? propertyKey}</span>\n {required && <span className={\"text-red-500 dark:text-red-500 -ml-1\"}>*</span>}\n {/* In the row, not over it. This was a tooltip on the\n label and on the control, which opened whenever a\n field took focus and covered the label being read. */}\n {property && <PropertyKeyHint propertyKey={propertyKey}/>}\n </div>\n )}\n\n {/* `data-field-control` names the slot for anything measuring the\n control itself. A class cannot: the label row carries\n `min-w-0` too, and a selector for it measured the label. */}\n <div className={\"min-w-0\"} data-field-control={\"\"}>\n <ErrorBoundary>\n {children}\n </ErrorBoundary>\n </div>\n\n {/* Under the control, where it reads as a note about the thing you\n just filled in rather than a subtitle of the next label. */}\n {showLabel && description && !reading && (\n <Typography variant={\"caption\"}\n color={\"disabled\"}\n className={\"mt-1.5 ml-0.5 leading-snug\"}>\n {description}\n </Typography>\n )}\n\n {/* A label drawn inside the box: the description is indented to\n the value, as the binding's own error line is (`ml-3.5`), and\n the key sits at the end of that line. A field with no\n description has no line to put it on, so the key hangs in the\n row gap below the box rather than reserving a line under every\n field for something only a hover shows. */}\n {footed && (description || property) && (\n <div className={cls(\n \"flex items-start gap-2 min-w-0 ml-3.5\",\n description ? \"mt-1.5\" : \"absolute top-full right-0 mt-1\"\n )}>\n {description && (\n <Typography variant={\"caption\"}\n color={\"disabled\"}\n className={\"grow min-w-0 leading-snug\"}>\n {description}\n </Typography>\n )}\n {property && <PropertyKeyHint propertyKey={propertyKey}\n className={description ? \"ml-auto shrink-0\" : undefined}/>}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UAAU,MAA4B;CAClD,QAAQ,MAAR;EACI,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;EACf,KAAK,GAAG,OAAO;CACnB;AACJ;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,UAAyC;CAC7E,IAAI,CAAC,UAAU,OAAO;CACtB,QAAQ,SAAS,MAAjB;EACI,KAAK,OAGD,OAAO,CAAC,SAAS,OAAO;EAC5B,KAAK,SAAS;GAWV,IAAI,SAAS,OAAO,OAAO;GAC3B,IAAI,MAAM,QAAQ,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,OAAO;GACvD,MAAM,KAAK,SAAS;GACpB,IAAI,GAAG,SAAS,aAAa,GAAG,QAAQ,GAAG,UAAU,OAAO;GAC5D,IAAI,GAAG,SAAS,YAAY,GAAG,MAAM,OAAO;GAC5C,OAAO;EACX;EACA,SACI,OAAO;CACf;AACJ;;;;;;;;AASA,IAAa,kBAAkB;;;;;;;;;;;;;AAsD/B,SAAgB,WAAW,EACvB,aACA,UACA,WACA,cAAc,OACd,OAAO,QACP,OACA,MACA,YACgB;CAEhB,MAAM,UAAU,SAAS;CACzB,MAAM,cAAc,UAAU,aAAa,KAAK;CAIhD,MAAM,WAAW,QAAQ,UAAU,YAAY,QAAQ,KAAK,EAAE,YAAY,WAAW,QAAQ;CAC7F,MAAM,SAAS,eAAe,CAAC;CAG/B,OAII,qBAAC,OAAD;EACI,IAAI,WAPK,gBAOM,GAAU,WAAW;EACpC,mBAAiB;EAGjB,WAAW,IAAI,kCAAkC,UAAU,aAAa;YAL5E;GAOK,aACG,qBAAC,OAAD;IAAK,WAAW,IACZ,kFAIA,2DACJ;cANA;MAaM,YAAY,SACV,oBAAC,QAAD;MAAM,WAAW;gBACZ,WAAW,mBAAmB,UAAA,EAAyB,IAAI;KAC1D,CAAA;KAEV,oBAAC,QAAD;MAAM,WAAW;gBAAa,UAAU,QAAQ,SAAS;KAAkB,CAAA;KAC1E,YAAY,oBAAC,QAAD;MAAM,WAAW;gBAAwC;KAAO,CAAA;KAI5E,YAAY,oBAAC,iBAAD,EAA8B,YAAa,CAAA;IACvD;;GAMT,oBAAC,OAAD;IAAK,WAAW;IAAW,sBAAoB;cAC3C,oBAAC,eAAD,EACK,SACU,CAAA;GACd,CAAA;GAIJ,aAAa,eAAe,CAAC,WAC1B,oBAAC,YAAD;IAAY,SAAS;IACjB,OAAO;IACP,WAAW;cACV;GACO,CAAA;GASf,WAAW,eAAe,aACvB,qBAAC,OAAD;IAAK,WAAW,IACZ,yCACA,cAAc,WAAW,gCAC7B;cAHA,CAIK,eACG,oBAAC,YAAD;KAAY,SAAS;KACjB,OAAO;KACP,WAAW;eACV;IACO,CAAA,GAEf,YAAY,oBAAC,iBAAD;KAA8B;KACvC,WAAW,cAAc,qBAAqB,KAAA;IAAW,CAAA,CAC5D;;EAER;;AAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldHelperText.js","names":[],"sources":["../../../src/form/components/FieldHelperText.tsx"],"sourcesContent":["import type { Property } from \"@rebasepro/types\";\nimport { IconButton, InfoIcon, Tooltip, Typography } from \"@rebasepro/ui\";\n\n/**\n * Normalize an error value to a displayable string.\n * Handles cases where the error is an array (e.g. per-element validation\n * errors from array fields) or an object (e.g. raw Zod issue objects).\n */\nfunction normalizeError(error: unknown): string | undefined {\n if (error === undefined || error === null) return undefined;\n if (typeof error === \"string\") return error;\n if (Array.isArray(error)) {\n // Find the first non-falsy element and extract its message\n const firstError = error.find((e) => !!e);\n if (!firstError) return undefined;\n return normalizeError(firstError);\n }\n if (typeof error === \"object\") {\n if (\"message\" in error) {\n return String((error as { message: unknown }).message);\n }\n\n // Extract all string values from the object (e.g., nested validation errors)\n const messages: string[] = [];\n const extractMessages = (obj: Record<string, unknown>) => {\n for (const key in obj) {\n if (typeof obj[key] === \"string\") {\n messages.push(obj[key] as string);\n } else if (typeof obj[key] === \"object\" && obj[key] !== null) {\n extractMessages(obj[key] as Record<string, unknown>);\n }\n }\n };\n extractMessages(error as Record<string, unknown>);\n if (messages.length > 0) {\n return Array.from(new Set(messages)).join(\", \");\n }\n }\n return String(error);\n}\n\n/**\n * Component in charge of rendering the description of a field\n * as well as the error message if any.\n */\nexport function FieldHelperText<T>({\n error,\n showError,\n property,\n includeDescription = true,\n disabled\n}: {\n error?: string,\n showError?: boolean,\n property: Property | Property,\n includeDescription?: boolean,\n disabled?: boolean,\n}\n) {\n\n const displayError = normalizeError(error);\n const hasDescription = property.description !== undefined && property.description.trim().length > 0;\n\n if (!(showError && displayError) && (!includeDescription || !hasDescription))\n return null;\n\n if (showError && displayError) {\n return <Typography variant={\"caption\"}\n className={\"ml-3.5 text-red-500 dark:text-red-500\"}>\n {displayError}\n </Typography>\n }\n\n const disabledTooltip: string | undefined = typeof property.admin?.disabled === \"object\" ? property.admin?.disabled.disabledMessage : undefined;\n\n return <div className={\"flex ml-3.5 mt-1\"}>\n <Typography variant={\"caption\"}\n color={disabled ? \"disabled\" : \"secondary\"}\n className={\"grow\"}>\n {disabledTooltip || property.description}\n </Typography>\n\n </div>\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,eAAe,OAAoC;CACxD,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,KAAA;CAClD,IAAI,OAAO,UAAU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.js","names":[],"sources":["../../../src/form/components/FieldHelperText.tsx"],"sourcesContent":["import type { Property } from \"@rebasepro/cms-types\";\nimport { IconButton, InfoIcon, Tooltip, Typography } from \"@rebasepro/ui\";\n\n/**\n * Normalize an error value to a displayable string.\n * Handles cases where the error is an array (e.g. per-element validation\n * errors from array fields) or an object (e.g. raw Zod issue objects).\n */\nfunction normalizeError(error: unknown): string | undefined {\n if (error === undefined || error === null) return undefined;\n if (typeof error === \"string\") return error;\n if (Array.isArray(error)) {\n // Find the first non-falsy element and extract its message\n const firstError = error.find((e) => !!e);\n if (!firstError) return undefined;\n return normalizeError(firstError);\n }\n if (typeof error === \"object\") {\n if (\"message\" in error) {\n return String((error as { message: unknown }).message);\n }\n\n // Extract all string values from the object (e.g., nested validation errors)\n const messages: string[] = [];\n const extractMessages = (obj: Record<string, unknown>) => {\n for (const key in obj) {\n if (typeof obj[key] === \"string\") {\n messages.push(obj[key] as string);\n } else if (typeof obj[key] === \"object\" && obj[key] !== null) {\n extractMessages(obj[key] as Record<string, unknown>);\n }\n }\n };\n extractMessages(error as Record<string, unknown>);\n if (messages.length > 0) {\n return Array.from(new Set(messages)).join(\", \");\n }\n }\n return String(error);\n}\n\n/**\n * Component in charge of rendering the description of a field\n * as well as the error message if any.\n */\nexport function FieldHelperText<T>({\n error,\n showError,\n property,\n includeDescription = true,\n disabled\n}: {\n error?: string,\n showError?: boolean,\n property: Property | Property,\n includeDescription?: boolean,\n disabled?: boolean,\n}\n) {\n\n const displayError = normalizeError(error);\n const hasDescription = property.description !== undefined && property.description.trim().length > 0;\n\n if (!(showError && displayError) && (!includeDescription || !hasDescription))\n return null;\n\n if (showError && displayError) {\n return <Typography variant={\"caption\"}\n className={\"ml-3.5 text-red-500 dark:text-red-500\"}>\n {displayError}\n </Typography>\n }\n\n const disabledTooltip: string | undefined = typeof property.admin?.disabled === \"object\" ? property.admin?.disabled.disabledMessage : undefined;\n\n return <div className={\"flex ml-3.5 mt-1\"}>\n <Typography variant={\"caption\"}\n color={disabled ? \"disabled\" : \"secondary\"}\n className={\"grow\"}>\n {disabledTooltip || property.description}\n </Typography>\n\n </div>\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,eAAe,OAAoC;CACxD,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,KAAA;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,MAAM,QAAQ,KAAK,GAAG;EAEtB,MAAM,aAAa,MAAM,MAAM,MAAM,CAAC,CAAC,CAAC;EACxC,IAAI,CAAC,YAAY,OAAO,KAAA;EACxB,OAAO,eAAe,UAAU;CACpC;CACA,IAAI,OAAO,UAAU,UAAU;EAC3B,IAAI,aAAa,OACb,OAAO,OAAQ,MAA+B,OAAO;EAIzD,MAAM,WAAqB,CAAC;EAC5B,MAAM,mBAAmB,QAAiC;GACtD,KAAK,MAAM,OAAO,KACd,IAAI,OAAO,IAAI,SAAS,UACpB,SAAS,KAAK,IAAI,IAAc;QAC7B,IAAI,OAAO,IAAI,SAAS,YAAY,IAAI,SAAS,MACpD,gBAAgB,IAAI,IAA+B;EAG/D;EACA,gBAAgB,KAAgC;EAChD,IAAI,SAAS,SAAS,GAClB,OAAO,MAAM,KAAK,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI;CAEtD;CACA,OAAO,OAAO,KAAK;AACvB;;;;;AAMA,SAAgB,gBAAmB,EAC/B,OACA,WACA,UACA,qBAAqB,MACrB,YAQF;CAEE,MAAM,eAAe,eAAe,KAAK;CACzC,MAAM,iBAAiB,SAAS,gBAAgB,KAAA,KAAa,SAAS,YAAY,KAAK,CAAC,CAAC,SAAS;CAElG,IAAI,EAAE,aAAa,kBAAkB,CAAC,sBAAsB,CAAC,iBACzD,OAAO;CAEX,IAAI,aAAa,cACb,OAAO,oBAAC,YAAD;EAAY,SAAS;EACxB,WAAW;YACV;CACO,CAAA;CAGhB,MAAM,kBAAsC,OAAO,SAAS,OAAO,aAAa,WAAW,SAAS,OAAO,SAAS,kBAAkB,KAAA;CAEtI,OAAO,oBAAC,OAAD;EAAK,WAAW;YACnB,oBAAC,YAAD;GAAY,SAAS;GACjB,OAAO,WAAW,aAAa;GAC/B,WAAW;aACV,mBAAmB,SAAS;EACrB,CAAA;CAEX,CAAA;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRail.js","names":[],"sources":["../../../src/form/components/FormRail.tsx"],"sourcesContent":["import type { Entity } from \"@rebasepro/types\";\nimport type { ResolvedFormField } from \"@rebasepro/app\";\nimport React from \"react\";\nimport { CheckIcon, cls, CopyIcon, IconButton, iconSize, Tooltip, Typography } from \"@rebasepro/ui\";\nimport { useFormFieldsContext } from \"../FormFieldsContext\";\n\nexport interface FormRailProps {\n fields: ResolvedFormField[];\n showRecordMeta: boolean;\n entity?: Entity<Record<string, unknown>>;\n /**\n * Renders one field. Defaults to the enclosing record form's own, which\n * applies every rule the form has for a field.\n */\n renderField?: (field: ResolvedFormField) => React.ReactNode;\n}\n\n/**\n * The metadata column beside the form.\n *\n * This replaces a `w-80 2xl:w-96` rail that held a Save button and several\n * hundred pixels of nothing. It renders only when it has something to say, and\n * the actions it used to hold now live in the identity bar, where they stay\n * visible while you scroll.\n */\nexport function FormRail({\n fields,\n showRecordMeta,\n entity,\n renderField\n}: FormRailProps) {\n\n const formFields = useFormFieldsContext();\n const render = renderField ?? formFields?.renderField;\n\n if (!fields.length && !showRecordMeta) return null;\n if (fields.length > 0 && !render) throw new Error(\"FormRail needs `renderField` outside a record form\");\n\n return (\n <aside className={cls(\n // No responsive hiding here. The caller decides whether the rail is\n // shown, by measuring; a CSS `hidden` would leave the fields the\n // resolver moved in here unreachable rather than folding them back.\n //\n // `w-76` (304px), between the old 288 and a full `w-80`. The rail\n // holds real controls — a status select, a date picker — plus a\n // record block whose id is a 36-character UUID, so 288 left the\n // select tighter than the identical select in the column.\n //\n // 304 is the floor rather than the answer everywhere. It was chosen\n // against the *narrow* end, where 320 took more than it gave back —\n // past about 300px the extra went to the gap beside a chip. That\n // stops being true once the form is genuinely wide: `@7xl/form`\n // (1280px of form) is the same signal the column widens on, and by\n // then 32px is coming out of gutters, not out of the column.\n //\n // Container, not viewport, for the reason the whole rail is\n // measured rather than breakpointed: a side panel inside a large\n // window is not a wide form. Both surfaces that render a rail —\n // `EntityForm` and `EntityViewBinding` — name their form element\n // `@container/form`, so a panel that never gets that wide keeps 304.\n // No left rule: the rail is sheet beside the form's card, and that\n // step is the separation. Regions meet with a step, not a line.\n \"flex flex-col gap-6 shrink-0 w-76 @7xl/form:w-84 overflow-y-auto\",\n \"px-5 py-6 bg-surface-sheet\"\n )}>\n {fields.length > 0 && (\n <div className={\"flex flex-col gap-5\"}>\n {render && fields.map(render)}\n </div>\n )}\n\n {showRecordMeta && entity && <RecordMeta entity={entity}/>}\n </aside>\n );\n}\n\n/**\n * The record's id and audit timestamps.\n *\n * Exported because the rail is not the only place it renders. The rail is shown\n * only when it has been *measured* to fit, and every layout narrower than that —\n * the split pane, the side panel, the dialog — folds its contents back into the\n * column. The fields folded back but this block did not, so on three of the four\n * layouts a record simply had no id on screen: the only copy of it was the\n * truncated `e166a394…b422` chip in the identity bar.\n */\nexport function RecordMeta({ entity }: { entity: Entity<Record<string, unknown>> }) {\n\n const createdAt = pickDate(entity.values, [\"created_at\", \"createdAt\", \"created_on\"]);\n const updatedAt = pickDate(entity.values, [\"updated_at\", \"updatedAt\", \"modified_at\"]);\n\n return (\n <div className={\"flex flex-col gap-2.5\"}>\n <Typography variant={\"caption\"}\n className={\"text-xs font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark\"}>\n Record\n </Typography>\n\n <MetaRow label={\"ID\"} value={String(entity.id)} copyable/>\n {createdAt && <MetaRow label={\"Created\"} value={createdAt}/>}\n {updatedAt && <MetaRow label={\"Updated\"} value={updatedAt}/>}\n </div>\n );\n}\n\nfunction MetaRow({\n label,\n value,\n copyable\n}: {\n label: string;\n value: string;\n copyable?: boolean;\n}) {\n const [copied, setCopied] = React.useState(false);\n\n const copy = () => {\n navigator.clipboard?.writeText(value).then(() => {\n setCopied(true);\n setTimeout(() => setCopied(false), 1600);\n }, () => undefined);\n };\n\n return (\n <div className={\"flex items-baseline justify-between gap-3 min-w-0\"}>\n <span className={\"text-xs text-text-disabled dark:text-text-disabled-dark shrink-0\"}>\n {label}\n </span>\n <span className={\"flex items-center gap-1 min-w-0\"}>\n <span className={\"font-mono text-xs text-text-secondary dark:text-text-secondary-dark truncate\"}\n title={value}>\n {value}\n </span>\n {copyable && (\n <Tooltip title={copied ? \"Copied\" : \"Copy\"}>\n <IconButton aria-label={copied ? \"Copied\" : \"Copy\"} size={\"smallest\"} onClick={copy}>\n {copied ? <CheckIcon size={iconSize.smallest}/> : <CopyIcon size={iconSize.smallest}/>}\n </IconButton>\n </Tooltip>\n )}\n </span>\n </div>\n );\n}\n\n/**\n * Audit timestamps are a convention, not a contract — a collection may name them\n * anything or not have them at all — so this reads the values it recognises and\n * stays quiet otherwise rather than rendering an empty row.\n */\nfunction pickDate(values: Record<string, unknown> | undefined, keys: string[]): string | undefined {\n if (!values) return undefined;\n for (const key of keys) {\n const value = values[key];\n if (value instanceof Date) return value.toLocaleDateString();\n if (typeof value === \"string\" && value) {\n const parsed = new Date(value);\n if (!Number.isNaN(parsed.getTime())) return parsed.toLocaleDateString();\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,SAAS,EACrB,QACA,gBACA,QACA,eACc;CAEd,MAAM,aAAa,qBAAqB;CACxC,MAAM,SAAS,eAAe,YAAY;CAE1C,IAAI,CAAC,OAAO,UAAU,CAAC,gBAAgB,OAAO;CAC9C,IAAI,OAAO,SAAS,KAAK,CAAC,QAAQ,MAAM,IAAI,MAAM,oDAAoD;CAEtG,OACI,qBAAC,SAAD;EAAO,WAAW,IAwBd,oEACA,4BACJ;YA1BA,CA2BK,OAAO,SAAS,KACb,oBAAC,OAAD;GAAK,WAAW;aACX,UAAU,OAAO,IAAI,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,SAAU,CAAA;IAC7E,CAAA;GACP,CAAA,CAEX;IACL;;AAEb;;;;;;AAOA,SAAS,SAAS,QAA6C,MAAoC;CAC/F,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,KAAK,MAAM,OAAO,MAAM;EACpB,MAAM,QAAQ,OAAO;EACrB,IAAI,iBAAiB,MAAM,OAAO,MAAM,mBAAmB;EAC3D,IAAI,OAAO,UAAU,YAAY,OAAO;GACpC,MAAM,SAAS,IAAI,KAAK,KAAK;GAC7B,IAAI,CAAC,OAAO,MAAM,OAAO,QAAQ,CAAC,GAAG,OAAO,OAAO,mBAAmB;EAC1E;CACJ;AAEJ"}
|
|
1
|
+
{"version":3,"file":"FormRail.js","names":[],"sources":["../../../src/form/components/FormRail.tsx"],"sourcesContent":["import type { Entity } from \"@rebasepro/cms-types\";\nimport type { ResolvedFormField } from \"@rebasepro/app\";\nimport React from \"react\";\nimport { CheckIcon, cls, CopyIcon, IconButton, iconSize, Tooltip, Typography } from \"@rebasepro/ui\";\nimport { useFormFieldsContext } from \"../FormFieldsContext\";\n\nexport interface FormRailProps {\n fields: ResolvedFormField[];\n showRecordMeta: boolean;\n entity?: Entity<Record<string, unknown>>;\n /**\n * Renders one field. Defaults to the enclosing record form's own, which\n * applies every rule the form has for a field.\n */\n renderField?: (field: ResolvedFormField) => React.ReactNode;\n}\n\n/**\n * The metadata column beside the form.\n *\n * This replaces a `w-80 2xl:w-96` rail that held a Save button and several\n * hundred pixels of nothing. It renders only when it has something to say, and\n * the actions it used to hold now live in the identity bar, where they stay\n * visible while you scroll.\n */\nexport function FormRail({\n fields,\n showRecordMeta,\n entity,\n renderField\n}: FormRailProps) {\n\n const formFields = useFormFieldsContext();\n const render = renderField ?? formFields?.renderField;\n\n if (!fields.length && !showRecordMeta) return null;\n if (fields.length > 0 && !render) throw new Error(\"FormRail needs `renderField` outside a record form\");\n\n return (\n <aside className={cls(\n // No responsive hiding here. The caller decides whether the rail is\n // shown, by measuring; a CSS `hidden` would leave the fields the\n // resolver moved in here unreachable rather than folding them back.\n //\n // `w-76` (304px), between the old 288 and a full `w-80`. The rail\n // holds real controls — a status select, a date picker — plus a\n // record block whose id is a 36-character UUID, so 288 left the\n // select tighter than the identical select in the column.\n //\n // 304 is the floor rather than the answer everywhere. It was chosen\n // against the *narrow* end, where 320 took more than it gave back —\n // past about 300px the extra went to the gap beside a chip. That\n // stops being true once the form is genuinely wide: `@7xl/form`\n // (1280px of form) is the same signal the column widens on, and by\n // then 32px is coming out of gutters, not out of the column.\n //\n // Container, not viewport, for the reason the whole rail is\n // measured rather than breakpointed: a side panel inside a large\n // window is not a wide form. Both surfaces that render a rail —\n // `EntityForm` and `EntityViewBinding` — name their form element\n // `@container/form`, so a panel that never gets that wide keeps 304.\n // No left rule: the rail is sheet beside the form's card, and that\n // step is the separation. Regions meet with a step, not a line.\n \"flex flex-col gap-6 shrink-0 w-76 @7xl/form:w-84 overflow-y-auto\",\n \"px-5 py-6 bg-surface-sheet\"\n )}>\n {fields.length > 0 && (\n <div className={\"flex flex-col gap-5\"}>\n {render && fields.map(render)}\n </div>\n )}\n\n {showRecordMeta && entity && <RecordMeta entity={entity}/>}\n </aside>\n );\n}\n\n/**\n * The record's id and audit timestamps.\n *\n * Exported because the rail is not the only place it renders. The rail is shown\n * only when it has been *measured* to fit, and every layout narrower than that —\n * the split pane, the side panel, the dialog — folds its contents back into the\n * column. The fields folded back but this block did not, so on three of the four\n * layouts a record simply had no id on screen: the only copy of it was the\n * truncated `e166a394…b422` chip in the identity bar.\n */\nexport function RecordMeta({ entity }: { entity: Entity<Record<string, unknown>> }) {\n\n const createdAt = pickDate(entity.values, [\"created_at\", \"createdAt\", \"created_on\"]);\n const updatedAt = pickDate(entity.values, [\"updated_at\", \"updatedAt\", \"modified_at\"]);\n\n return (\n <div className={\"flex flex-col gap-2.5\"}>\n <Typography variant={\"caption\"}\n className={\"text-xs font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark\"}>\n Record\n </Typography>\n\n <MetaRow label={\"ID\"} value={String(entity.id)} copyable/>\n {createdAt && <MetaRow label={\"Created\"} value={createdAt}/>}\n {updatedAt && <MetaRow label={\"Updated\"} value={updatedAt}/>}\n </div>\n );\n}\n\nfunction MetaRow({\n label,\n value,\n copyable\n}: {\n label: string;\n value: string;\n copyable?: boolean;\n}) {\n const [copied, setCopied] = React.useState(false);\n\n const copy = () => {\n navigator.clipboard?.writeText(value).then(() => {\n setCopied(true);\n setTimeout(() => setCopied(false), 1600);\n }, () => undefined);\n };\n\n return (\n <div className={\"flex items-baseline justify-between gap-3 min-w-0\"}>\n <span className={\"text-xs text-text-disabled dark:text-text-disabled-dark shrink-0\"}>\n {label}\n </span>\n <span className={\"flex items-center gap-1 min-w-0\"}>\n <span className={\"font-mono text-xs text-text-secondary dark:text-text-secondary-dark truncate\"}\n title={value}>\n {value}\n </span>\n {copyable && (\n <Tooltip title={copied ? \"Copied\" : \"Copy\"}>\n <IconButton aria-label={copied ? \"Copied\" : \"Copy\"} size={\"smallest\"} onClick={copy}>\n {copied ? <CheckIcon size={iconSize.smallest}/> : <CopyIcon size={iconSize.smallest}/>}\n </IconButton>\n </Tooltip>\n )}\n </span>\n </div>\n );\n}\n\n/**\n * Audit timestamps are a convention, not a contract — a collection may name them\n * anything or not have them at all — so this reads the values it recognises and\n * stays quiet otherwise rather than rendering an empty row.\n */\nfunction pickDate(values: Record<string, unknown> | undefined, keys: string[]): string | undefined {\n if (!values) return undefined;\n for (const key of keys) {\n const value = values[key];\n if (value instanceof Date) return value.toLocaleDateString();\n if (typeof value === \"string\" && value) {\n const parsed = new Date(value);\n if (!Number.isNaN(parsed.getTime())) return parsed.toLocaleDateString();\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,SAAS,EACrB,QACA,gBACA,QACA,eACc;CAEd,MAAM,aAAa,qBAAqB;CACxC,MAAM,SAAS,eAAe,YAAY;CAE1C,IAAI,CAAC,OAAO,UAAU,CAAC,gBAAgB,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CAAA,GACL,YACG,oBAAC,SAAD;IAAS,OAAO,SAAS,WAAW;cAChC,oBAAC,YAAD;KAAY,cAAY,SAAS,WAAW;KAAQ,MAAM;KAAY,SAAS;eAC1E,SAAS,oBAAC,WAAD,EAAW,MAAM,SAAS,SAAU,CAAA,IAAI,oBAAC,UAAD,EAAU,MAAM,SAAS,SAAU,CAAA;IAC7E,CAAA;GACP,CAAA,CAEX;IACL;;AAEb;;;;;;AAOA,SAAS,SAAS,QAA6C,MAAoC;CAC/F,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,KAAK,MAAM,OAAO,MAAM;EACpB,MAAM,QAAQ,OAAO;EACrB,IAAI,iBAAiB,MAAM,OAAO,MAAM,mBAAmB;EAC3D,IAAI,OAAO,UAAU,YAAY,OAAO;GACpC,MAAM,SAAS,IAAI,KAAK,KAAK;GAC7B,IAAI,CAAC,OAAO,MAAM,OAAO,QAAQ,CAAC,GAAG,OAAO,OAAO,mBAAmB;EAC1E;CACJ;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalChangesMenu.js","names":[],"sources":["../../../src/form/components/LocalChangesMenu.tsx"],"sourcesContent":["\nimport type { Properties } from \"@rebasepro/types\";\nimport React, { useState } from \"react\";\nimport {\n AlertTriangleIcon,\n Button,\n CheckIcon,\n ChevronDownIcon,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n EyeIcon,\n iconSize,\n Menu,\n MenuItem,\n Typography,\n XCircleIcon\n} from \"@rebasepro/ui\";\nimport { FormexController } from \"@rebasepro/forms\";\nimport { useSnackbarController, useTranslation } from \"@rebasepro/app\";\nimport { flattenKeys, removeEntityFromCache } from \"@rebasepro/app\";\n;\nimport { PropertyCollectionView } from \"../../components/PropertyCollectionView\";\nimport { overlayEdit } from \"../form_utils\";\n\ninterface LocalChangesMenuProps<M extends Record<string, unknown>> {\n cacheKey: string;\n cachedData: Partial<M>;\n formex: FormexController<M>;\n onClearLocalChanges?: () => void;\n properties: Properties;\n}\n\nexport function LocalChangesMenu<M extends Record<string, unknown>>({\n cachedData,\n formex,\n onClearLocalChanges,\n cacheKey,\n properties\n}: LocalChangesMenuProps<M>) {\n\n const snackbarController = useSnackbarController();\n const { t } = useTranslation();\n const [previewDialogOpen, setPreviewDialogOpen] = useState(false);\n const [open, setOpen] = useState(false);\n\n const handleOpenMenu = () => setOpen(true);\n const handleCloseMenu = () => setOpen(false);\n\n const handlePreview = () => {\n setPreviewDialogOpen(true);\n handleCloseMenu();\n };\n\n const handleApply = () => {\n // Each cached property whole, over what the form holds — see\n // `overlayEdit` for why not a deep merge.\n const mergedValues = overlayEdit(formex.values, cachedData) as M;\n const touched = { ...formex.touched };\n const cachedKeys = flattenKeys(cachedData);\n cachedKeys.forEach((key) => {\n touched[key] = true;\n });\n\n formex.setTouched(touched);\n formex.setValues(mergedValues);\n snackbarController.open({\n type: \"info\",\n message: t(\"local_changes_applied\")\n });\n handleCloseMenu();\n onClearLocalChanges?.();\n };\n\n const handleDiscard = () => {\n removeEntityFromCache(cacheKey);\n snackbarController.open({\n type: \"info\",\n message: t(\"local_changes_discarded\")\n });\n handleCloseMenu();\n onClearLocalChanges?.();\n };\n\n return (\n <>\n <Menu\n trigger={\n <Button\n size={\"small\"}\n className={\n \"font-semibold text-xs rounded-full px-4 py-1 bg-yellow-200 dark:bg-yellow-900 hover:bg-yellow-300 dark:hover:bg-yellow-800 text-yellow-800 dark:text-yellow-200\"\n }\n onClick={handleOpenMenu}\n >\n <AlertTriangleIcon size={iconSize.smallest} className={\"mr-1 text-yellow-600 dark:text-yellow-400\"}/>\n {t(\"unsaved_local_changes\")}\n <ChevronDownIcon size={iconSize.smallest}/>\n </Button>\n }\n open={open}\n onOpenChange={setOpen}\n >\n <div className={\"max-w-xs px-4 py-4 text-sm text-gray-700 dark:text-gray-300\"}>\n {t(\"unsaved_local_changes_description\")}\n </div>\n <MenuItem dense onClick={handlePreview}><EyeIcon size={iconSize.small}/>{t(\"preview_changes\")}</MenuItem>\n <MenuItem dense onClick={handleApply}><CheckIcon size={iconSize.small}/>{t(\"apply_changes\")}</MenuItem>\n <MenuItem dense onClick={handleDiscard}><XCircleIcon size={iconSize.small}/>{t(\"discard_local_changes\")}</MenuItem>\n </Menu>\n\n <Dialog\n open={previewDialogOpen}\n onOpenChange={setPreviewDialogOpen}\n maxWidth={\"4xl\"}\n >\n <DialogTitle variant={\"h6\"}>{t(\"preview_local_changes\")}</DialogTitle>\n <DialogContent className={\"my-4\"}>\n <Typography variant={\"body2\"} className={\"mb-4\"}>\n {t(\"preview_local_changes_description\")}\n </Typography>\n <div className={`border rounded-lg ${defaultBorderMixin}`} style={{\n maxHeight: 520,\n overflow: \"auto\"\n }}>\n <div className=\"p-4\">\n <PropertyCollectionView data={cachedData}\n properties={properties as Properties}/>\n </div>\n </div>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setPreviewDialogOpen(false)}>{t(\"close\")}</Button>\n <Button\n variant={\"filled\"}\n onClick={() => {\n handleApply();\n setPreviewDialogOpen(false);\n }}\n >\n {t(\"apply_changes\")}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n );\n}\n"],"mappings":";;;;;;;AAmCA,SAAgB,iBAAoD,EAChE,YACA,QACA,qBACA,UACA,cACyB;CAEzB,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,KAAK;CAChE,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAEtC,MAAM,uBAAuB,QAAQ,IAAI;CACzC,MAAM,wBAAwB,QAAQ,KAAK;CAE3C,MAAM,sBAAsB;EACxB,qBAAqB,IAAI;EACzB,gBAAgB;CACpB;CAEA,MAAM,oBAAoB;EAGtB,MAAM,eAAe,YAAY,OAAO,QAAQ,UAAU;EAC1D,MAAM,UAAU,EAAE,GAAG,OAAO,QAAQ;EAEpC,YAD+B,UAC/B,CAAA,CAAW,SAAS,QAAQ;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,oBAAC,YAAD;KAAY,SAAS;KAAS,WAAW;eACpC,EAAE,mCAAmC;IAC9B,CAAA,GACZ,oBAAC,OAAD;KAAK,WAAW,qBAAqB;KAAsB,OAAO;MAC9D,WAAW;MACX,UAAU;KACd;eACI,oBAAC,OAAD;MAAK,WAAU;gBACX,oBAAC,wBAAD;OAAwB,MAAM;OACd;MAA0B,CAAA;KACzC,CAAA;IACJ,CAAA,CACM;;GACf,qBAAC,eAAD,EAAA,UAAA,CACI,oBAAC,QAAD;IAAQ,eAAe,qBAAqB,KAAK;cAAI,EAAE,OAAO;GAAU,CAAA,GACxE,oBAAC,QAAD;IACI,SAAS;IACT,eAAe;KACX,YAAY;KACZ,qBAAqB,KAAK;IAC9B;cAEC,EAAE,eAAe;GACd,CAAA,CACG,EAAA,CAAA;EACX;GACV,EAAA,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"LocalChangesMenu.js","names":[],"sources":["../../../src/form/components/LocalChangesMenu.tsx"],"sourcesContent":["\nimport type { Properties } from \"@rebasepro/cms-types\";\nimport React, { useState } from \"react\";\nimport {\n AlertTriangleIcon,\n Button,\n CheckIcon,\n ChevronDownIcon,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n EyeIcon,\n iconSize,\n Menu,\n MenuItem,\n Typography,\n XCircleIcon\n} from \"@rebasepro/ui\";\nimport { FormexController } from \"@rebasepro/forms\";\nimport { useSnackbarController, useTranslation } from \"@rebasepro/app\";\nimport { flattenKeys, removeEntityFromCache } from \"@rebasepro/app\";\n;\nimport { PropertyCollectionView } from \"../../components/PropertyCollectionView\";\nimport { overlayEdit } from \"../form_utils\";\n\ninterface LocalChangesMenuProps<M extends Record<string, unknown>> {\n cacheKey: string;\n cachedData: Partial<M>;\n formex: FormexController<M>;\n onClearLocalChanges?: () => void;\n properties: Properties;\n}\n\nexport function LocalChangesMenu<M extends Record<string, unknown>>({\n cachedData,\n formex,\n onClearLocalChanges,\n cacheKey,\n properties\n}: LocalChangesMenuProps<M>) {\n\n const snackbarController = useSnackbarController();\n const { t } = useTranslation();\n const [previewDialogOpen, setPreviewDialogOpen] = useState(false);\n const [open, setOpen] = useState(false);\n\n const handleOpenMenu = () => setOpen(true);\n const handleCloseMenu = () => setOpen(false);\n\n const handlePreview = () => {\n setPreviewDialogOpen(true);\n handleCloseMenu();\n };\n\n const handleApply = () => {\n // Each cached property whole, over what the form holds — see\n // `overlayEdit` for why not a deep merge.\n const mergedValues = overlayEdit(formex.values, cachedData) as M;\n const touched = { ...formex.touched };\n const cachedKeys = flattenKeys(cachedData);\n cachedKeys.forEach((key) => {\n touched[key] = true;\n });\n\n formex.setTouched(touched);\n formex.setValues(mergedValues);\n snackbarController.open({\n type: \"info\",\n message: t(\"local_changes_applied\")\n });\n handleCloseMenu();\n onClearLocalChanges?.();\n };\n\n const handleDiscard = () => {\n removeEntityFromCache(cacheKey);\n snackbarController.open({\n type: \"info\",\n message: t(\"local_changes_discarded\")\n });\n handleCloseMenu();\n onClearLocalChanges?.();\n };\n\n return (\n <>\n <Menu\n trigger={\n <Button\n size={\"small\"}\n className={\n \"font-semibold text-xs rounded-full px-4 py-1 bg-yellow-200 dark:bg-yellow-900 hover:bg-yellow-300 dark:hover:bg-yellow-800 text-yellow-800 dark:text-yellow-200\"\n }\n onClick={handleOpenMenu}\n >\n <AlertTriangleIcon size={iconSize.smallest} className={\"mr-1 text-yellow-600 dark:text-yellow-400\"}/>\n {t(\"unsaved_local_changes\")}\n <ChevronDownIcon size={iconSize.smallest}/>\n </Button>\n }\n open={open}\n onOpenChange={setOpen}\n >\n <div className={\"max-w-xs px-4 py-4 text-sm text-gray-700 dark:text-gray-300\"}>\n {t(\"unsaved_local_changes_description\")}\n </div>\n <MenuItem dense onClick={handlePreview}><EyeIcon size={iconSize.small}/>{t(\"preview_changes\")}</MenuItem>\n <MenuItem dense onClick={handleApply}><CheckIcon size={iconSize.small}/>{t(\"apply_changes\")}</MenuItem>\n <MenuItem dense onClick={handleDiscard}><XCircleIcon size={iconSize.small}/>{t(\"discard_local_changes\")}</MenuItem>\n </Menu>\n\n <Dialog\n open={previewDialogOpen}\n onOpenChange={setPreviewDialogOpen}\n maxWidth={\"4xl\"}\n >\n <DialogTitle variant={\"h6\"}>{t(\"preview_local_changes\")}</DialogTitle>\n <DialogContent className={\"my-4\"}>\n <Typography variant={\"body2\"} className={\"mb-4\"}>\n {t(\"preview_local_changes_description\")}\n </Typography>\n <div className={`border rounded-lg ${defaultBorderMixin}`} style={{\n maxHeight: 520,\n overflow: \"auto\"\n }}>\n <div className=\"p-4\">\n <PropertyCollectionView data={cachedData}\n properties={properties as Properties}/>\n </div>\n </div>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setPreviewDialogOpen(false)}>{t(\"close\")}</Button>\n <Button\n variant={\"filled\"}\n onClick={() => {\n handleApply();\n setPreviewDialogOpen(false);\n }}\n >\n {t(\"apply_changes\")}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n );\n}\n"],"mappings":";;;;;;;AAmCA,SAAgB,iBAAoD,EAChE,YACA,QACA,qBACA,UACA,cACyB;CAEzB,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,KAAK;CAChE,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CAEtC,MAAM,uBAAuB,QAAQ,IAAI;CACzC,MAAM,wBAAwB,QAAQ,KAAK;CAE3C,MAAM,sBAAsB;EACxB,qBAAqB,IAAI;EACzB,gBAAgB;CACpB;CAEA,MAAM,oBAAoB;EAGtB,MAAM,eAAe,YAAY,OAAO,QAAQ,UAAU;EAC1D,MAAM,UAAU,EAAE,GAAG,OAAO,QAAQ;EAEpC,YAD+B,UAC/B,CAAA,CAAW,SAAS,QAAQ;GACxB,QAAQ,OAAO;EACnB,CAAC;EAED,OAAO,WAAW,OAAO;EACzB,OAAO,UAAU,YAAY;EAC7B,mBAAmB,KAAK;GACpB,MAAM;G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AAsB,OAAO;MAC9D,WAAW;MACX,UAAU;KACd;eACI,oBAAC,OAAD;MAAK,WAAU;gBACX,oBAAC,wBAAD;OAAwB,MAAM;OACd;MAA0B,CAAA;KACzC,CAAA;IACJ,CAAA,CACM;;GACf,qBAAC,eAAD,EAAA,UAAA,CACI,oBAAC,QAAD;IAAQ,eAAe,qBAAqB,KAAK;cAAI,EAAE,OAAO;GAAU,CAAA,GACxE,oBAAC,QAAD;IACI,SAAS;IACT,eAAe;KACX,YAAY;KACZ,qBAAqB,KAAK;IAC9B;cAEC,EAAE,eAAe;GACd,CAAA,CACG,EAAA,CAAA;EACX;GACV,EAAA,CAAA;AAEV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageItemPreview.js","names":[],"sources":["../../../src/form/components/StorageItemPreview.tsx"],"sourcesContent":["import type { StringProperty } from \"@rebasepro/types\";\nimport React from \"react\";\n\nimport { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { PropertyPreview } from \"../../preview\";\n\nimport { cls, IconButton, paperMixin, Tooltip } from \"@rebasepro/ui\";\nimport { ErrorBoundary, FileTextIcon, MinusIcon } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\n\ninterface StorageItemPreviewProps {\n name: string;\n property: StringProperty;\n value: string,\n onRemove: (value: string) => void;\n size: PreviewSize;\n disabled: boolean;\n placeholder?: boolean;\n className?: string;\n}\n\nexport function StorageItemPreview({\n name,\n property,\n value,\n onRemove,\n disabled,\n size,\n placeholder,\n className\n}: StorageItemPreviewProps) {\n const { t } = useTranslation();\n\n return (\n <div className={cls(\n \"relative border-box flex items-center justify-center\",\n size === \"large\" ? \"min-w-[220px] min-h-[220px] max-w-[220px]\" : \"min-w-[118px] min-h-[118px] max-w-[118px]\",\n paperMixin,\n className)}>\n\n {!placeholder && !disabled &&\n <div\n className=\"absolute rounded-full -top-2 -right-2 z-10 bg-surface-card\">\n\n <Tooltip\n asChild={true}\n title={t(\"remove\")}>\n <IconButton aria-label={t(\"remove\")}\n size={\"small\"}\n onClick={(event) => {\n event.stopPropagation();\n onRemove(value);\n }}>\n <MinusIcon/>\n </IconButton>\n </Tooltip>\n </div>\n }\n\n {!placeholder && value &&\n <ErrorBoundary>\n <PropertyPreview propertyKey={name}\n value={value}\n property={property}\n interactive={false}\n size={size}/>\n </ErrorBoundary>\n }\n\n {placeholder &&\n <div\n onClick={(e) => e.stopPropagation()}\n className=\"flex flex-col items-center justify-center w-full h-full\">\n <FileTextIcon className=\"text-surface-700 dark:text-surface-300\"/>\n </div>\n }\n\n </div>\n );\n\n}\n"],"mappings":";;;;;;AAqBA,SAAgB,mBAAmB,EAC/B,MACA,UACA,OACA,UACA,UACA,MACA,aACA,aACwB;CACxB,MAAM,EAAE,MAAM,eAAe;CAE7B,OACI,qBAAC,OAAD;EAAK,WAAW,IACZ,wDACA,SAAS,UAAU,8CAA8C,6CACjE,YACA,SAAS;YAJb;GAMK,CAAC,eAAe,CAAC,YACd,oBAAC,OAAD;IACI,WAAU;cAEV,oBAAC,SAAD;KACI,SAAS;KACT,OAAO,EAAE,QAAQ;eACjB,oBAAC,YAAD;MAAY,cAAY,EAAE,QAAQ;MAC9B,MAAM;MACN,UAAU,UAAU;OAChB,MAAM,gBAAgB;OACtB,SAAS,KAAK;MAClB;gBACA,oBAAC,WAAD,CAAW,CAAA;KACH,CAAA;IACP,CAAA;GACR,CAAA;GAGR,CAAC,eAAe,SACb,oBAAC,eAAD,EAAA,UACI,oBAAC,iBAAD;IAAiB,aAAa;IACnB;IACG;IACV,aAAa;IACP;GAAM,CAAA,EACL,CAAA;GAGlB,eACG,oBAAC,OAAD;IACI,UAAU,MAAM,EAAE,gBAAgB;IAClC,WAAU;cACV,oBAAC,cAAD,EAAc,WAAU,yCAAyC,CAAA;GAChE,CAAA;EAGR;;AAGb"}
|
|
1
|
+
{"version":3,"file":"StorageItemPreview.js","names":[],"sources":["../../../src/form/components/StorageItemPreview.tsx"],"sourcesContent":["import type { StringProperty } from \"@rebasepro/cms-types\";\nimport React from \"react\";\n\nimport { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { PropertyPreview } from \"../../preview\";\n\nimport { cls, IconButton, paperMixin, Tooltip } from \"@rebasepro/ui\";\nimport { ErrorBoundary, FileTextIcon, MinusIcon } from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\n\ninterface StorageItemPreviewProps {\n name: string;\n property: StringProperty;\n value: string,\n onRemove: (value: string) => void;\n size: PreviewSize;\n disabled: boolean;\n placeholder?: boolean;\n className?: string;\n}\n\nexport function StorageItemPreview({\n name,\n property,\n value,\n onRemove,\n disabled,\n size,\n placeholder,\n className\n}: StorageItemPreviewProps) {\n const { t } = useTranslation();\n\n return (\n <div className={cls(\n \"relative border-box flex items-center justify-center\",\n size === \"large\" ? \"min-w-[220px] min-h-[220px] max-w-[220px]\" : \"min-w-[118px] min-h-[118px] max-w-[118px]\",\n paperMixin,\n className)}>\n\n {!placeholder && !disabled &&\n <div\n className=\"absolute rounded-full -top-2 -right-2 z-10 bg-surface-card\">\n\n <Tooltip\n asChild={true}\n title={t(\"remove\")}>\n <IconButton aria-label={t(\"remove\")}\n size={\"small\"}\n onClick={(event) => {\n event.stopPropagation();\n onRemove(value);\n }}>\n <MinusIcon/>\n </IconButton>\n </Tooltip>\n </div>\n }\n\n {!placeholder && value &&\n <ErrorBoundary>\n <PropertyPreview propertyKey={name}\n value={value}\n property={property}\n interactive={false}\n size={size}/>\n </ErrorBoundary>\n }\n\n {placeholder &&\n <div\n onClick={(e) => e.stopPropagation()}\n className=\"flex flex-col items-center justify-center w-full h-full\">\n <FileTextIcon className=\"text-surface-700 dark:text-surface-300\"/>\n </div>\n }\n\n </div>\n );\n\n}\n"],"mappings":";;;;;;AAqBA,SAAgB,mBAAmB,EAC/B,MACA,UACA,OACA,UACA,UACA,MACA,aACA,aACwB;CACxB,MAAM,EAAE,MAAM,eAAe;CAE7B,OACI,qBAAC,OAAD;EAAK,WAAW,IACZ,wDACA,SAAS,UAAU,8CAA8C,6CACjE,YACA,SAAS;YAJb;GAMK,CAAC,eAAe,CAAC,YACd,oBAAC,OAAD;IACI,WAAU;cAEV,oBAAC,SAAD;KACI,SAAS;KACT,OAAO,EAAE,QAAQ;eACjB,oBAAC,YAAD;MAAY,cAAY,EAAE,QAAQ;MAC9B,MAAM;MACN,UAAU,UAAU;OAChB,MAAM,gBAAgB;OACtB,SAAS,KAAK;MAClB;gBACA,oBAAC,WAAD,CAAW,CAAA;KACH,CAAA;IACP,CAAA;GACR,CAAA;GAGR,CAAC,eAAe,SACb,oBAAC,eAAD,EAAA,UACI,oBAAC,iBAAD;IAAiB,aAAa;IACnB;IACG;IACV,aAAa;IACP;GAAM,CAAA,EACL,CAAA;GAGlB,eACG,oBAAC,OAAD;IACI,UAAU,MAAM,EAAE,gBAAgB;IAClC,WAAU;cACV,oBAAC,cAAD,EAAc,WAAU,yCAAyC,CAAA;GAChE,CAAA;EAGR;;AAGb"}
|
|
@@ -5,7 +5,7 @@ import { PropertyFieldBinding } from "../PropertyFieldBinding.js";
|
|
|
5
5
|
import "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { ExpandablePanel, Typography } from "@rebasepro/ui";
|
|
8
|
-
import { getArrayResolvedProperties } from "@rebasepro/
|
|
8
|
+
import { getArrayResolvedProperties } from "@rebasepro/cms-types";
|
|
9
9
|
import { isDisabled, isReadOnly, useAuthController } from "@rebasepro/app";
|
|
10
10
|
//#region src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayCustomShapedFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { ArrayProperty, Property } from \"@rebasepro/types\";\nimport React from \"react\";\n;\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { ExpandablePanel, Typography } from \"@rebasepro/ui\";\nimport { getArrayResolvedProperties } from \"@rebasepro/
|
|
1
|
+
{"version":3,"file":"ArrayCustomShapedFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { ArrayProperty, Property } from \"@rebasepro/cms-types\";\nimport React from \"react\";\n;\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { ExpandablePanel, Typography } from \"@rebasepro/ui\";\nimport { getArrayResolvedProperties } from \"@rebasepro/cms-types\";\nimport { isDisabled, isReadOnly } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { useAuthController } from \"@rebasepro/app\";\n\n/**\n * Array field used for custom\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 ArrayCustomShapedFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n isSubmitting,\n setValue,\n setFieldValue,\n customProps,\n minimalistView: minimalistViewProp,\n property,\n includeDescription,\n context,\n disabled\n}: FieldProps<ArrayProperty | ArrayProperty>) {\n\n const authController = useAuthController();\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n\n const resolvedProperties: Property[] | undefined = getArrayResolvedProperties({\n propertyValue: value,\n propertyKey,\n property,\n ignoreMissingFields: false,\n authController\n })\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n\n const title = (<>\n <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"h-8 grow text-text-secondary dark:text-text-secondary-dark\"}/>\n {Array.isArray(value) && <Typography variant={\"caption\"} className={\"px-4\"}>({value.length})</Typography>}\n </>);\n\n const body = (resolvedProperties ?? []).map((childProperty, index) => {\n const thisDisabled = isReadOnly(childProperty) || isDisabled(childProperty);\n const fieldProps = {\n propertyKey: `${propertyKey}[${index}]`,\n disabled: disabled || thisDisabled,\n property: childProperty,\n includeDescription,\n context,\n partOfArray: true,\n minimalistView: false,\n autoFocus: false,\n value,\n setValue,\n setFieldValue,\n customProps\n } as FieldProps;\n return <div key={`custom_shaped_array_${index}`} className=\"pb-4\">\n <PropertyFieldBinding {...fieldProps}/>\n </div>;\n });\n\n return (\n\n <>\n\n {!minimalistView &&\n <ExpandablePanel initiallyExpanded={expanded}\n title={title}\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\"}>\n {body}\n </ExpandablePanel>}\n\n {minimalistView && body}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,8BAA8B,EAC1C,aACA,OACA,OACA,WACA,cACA,UACA,eACA,aACA,gBAAgB,oBAChB,UACA,oBACA,SACA,YAC0C;CAE1C,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,iBAAiB,sBAAsB,SAAS,OAAO;CAE7D,MAAM,qBAA6C,2BAA2B;EAC1E,eAAe;EACf;EACA;EACA,qBAAqB;EACrB;CACJ,CAAC;CAED,MAAM,WAAW,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO;CAEjF,MAAM,QAAS,qBAAA,UAAA,EAAA,UAAA,CACX,oBAAC,eAAD;EACiB;EACb,MAAM,mBAAmB,UAAU,OAAO;EAC1C,UAAU,SAAS,YAAY;EAC/B,OAAO,SAAS,QAAQ;EACxB,WAAW;CAA8D,CAAA,GAC5E,MAAM,QAAQ,KAAK,KAAK,qBAAC,YAAD;EAAY,SAAS;EAAW,WAAW;YAA3C;GAAmD;GAAE,MAAM;GAAO;EAAa;GAC1G,EAAA,CAAA;CAEF,MAAM,QAAQ,sBAAsB,CAAC,EAAA,CAAG,KAAK,eAAe,UAAU;EAClE,MAAM,eAAe,WAAW,aAAa,KAAK,WAAW,aAAa;EAe1E,OAAO,oBAAC,OAAD;GAA0C,WAAU;aACvD,oBAAC,sBAAD;IAdA,aAAa,GAAG,YAAY,GAAG,MAAM;IACrC,UAAU,YAAY;IACtB,UAAU;IACV;IACA;IACA,aAAa;IACb,gBAAgB;IAChB,WAAW;IACX;IACA;IACA;IACA;GAGsC,CAAA;EACrC,GAFY,uBAAuB,OAEnC;CACT,CAAC;CAED,OAEI,qBAAA,UAAA,EAAA,UAAA;EAEK,CAAC,kBACE,oBAAC,iBAAD;GAAiB,mBAAmB;GACzB;GACP,gBAAgB;aACf;EACY,CAAA;EAEpB,kBAAkB;EAEnB,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;GACA;EAAU,CAAA;CAE1B,EAAA,CAAA;AAEV"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FieldProps } from "../../types/fields.js";
|
|
2
|
-
import type { ArrayProperty } from "@rebasepro/types";
|
|
3
2
|
import React from "react";
|
|
4
|
-
import { EntityReference } from "@rebasepro/types";
|
|
3
|
+
import { EntityReference } from "@rebasepro/cms-types";
|
|
4
|
+
import type { ArrayProperty } from "@rebasepro/cms-types";
|
|
5
5
|
type ArrayOfReferencesFieldProps = FieldProps<ArrayProperty, EntityReference[]>;
|
|
6
6
|
/**
|
|
7
7
|
* This field allows selecting multiple references.
|
|
@@ -26,8 +26,8 @@ function ArrayOfReferencesFieldBinding({ propertyKey, value, error, showError, d
|
|
|
26
26
|
const expanded = property.admin?.expanded === void 0 ? true : property.admin?.expanded;
|
|
27
27
|
const selectedEntityIds = value && Array.isArray(value) ? value.map((ref) => ref.id) : [];
|
|
28
28
|
const collectionRegistryController = useCollectionRegistryController();
|
|
29
|
-
const {
|
|
30
|
-
const collectionPath = ofProperty.path ?
|
|
29
|
+
const { targetPath, referenceTo } = useReferencePaths();
|
|
30
|
+
const collectionPath = ofProperty.path ? targetPath(ofProperty.path) : void 0;
|
|
31
31
|
const collection = useMemo(() => {
|
|
32
32
|
return collectionPath ? collectionRegistryController.getCollection(collectionPath) : void 0;
|
|
33
33
|
}, [collectionPath]);
|