@rebasepro/cms 0.30.0 → 0.31.0-canary.g902a0ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/collection_editor/ConfigControllerProvider.js +25 -22
- package/dist/collection_editor/ConfigControllerProvider.js.map +1 -1
- package/dist/collection_editor/firestore_callee.d.ts +10 -0
- package/dist/collection_editor/firestore_callee.js +15 -0
- package/dist/collection_editor/firestore_callee.js.map +1 -0
- package/dist/collection_editor/firestore_edit.d.ts +62 -0
- package/dist/collection_editor/firestore_edit.js +339 -0
- package/dist/collection_editor/firestore_edit.js.map +1 -0
- package/dist/collection_editor/index.d.ts +2 -3
- package/dist/collection_editor/liveSchemaClient.d.ts +44 -22
- package/dist/collection_editor/liveSchemaClient.js +9 -3
- package/dist/collection_editor/liveSchemaClient.js.map +1 -1
- package/dist/collection_editor/property_column.d.ts +86 -0
- package/dist/collection_editor/property_column.js +719 -0
- package/dist/collection_editor/property_column.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +2 -24
- package/dist/collection_editor/serializable_utils.d.ts +1 -1
- package/dist/collection_editor/serializable_utils.js +2 -1
- package/dist/collection_editor/serializable_utils.js.map +1 -1
- package/dist/collection_editor/split_edit.d.ts +106 -0
- package/dist/collection_editor/split_edit.js +564 -0
- package/dist/collection_editor/split_edit.js.map +1 -0
- package/dist/collection_editor/split_edit_error.d.ts +25 -0
- package/dist/collection_editor/split_edit_error.js +35 -0
- package/dist/collection_editor/split_edit_error.js.map +1 -0
- package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
- package/dist/collection_editor/types/config_controller.d.ts +67 -1
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +6 -5
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +44 -12
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +18 -3
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +94 -55
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +2 -1
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +3 -3
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -3
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +7 -4
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js +15 -5
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.d.ts +20 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js +74 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.d.ts +34 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js +50 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -2
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -1
- package/dist/collection_editor/useDetachRulesConfirmation.d.ts +16 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js +48 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js.map +1 -0
- package/dist/collection_editor/useLiveSchemaEditing.d.ts +2 -2
- package/dist/collection_editor/useLiveSchemaEditing.js +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +54 -10
- package/dist/collection_editor/useLocalCollectionsConfigController.js +394 -122
- package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -1
- package/dist/collection_editor/validateCollectionJson.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +10 -9
- package/dist/components/CollectionPanel.js +5 -2
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +1 -2
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +3 -5
- package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +1 -1
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.d.ts +2 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.d.ts +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +2 -2
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionTableBinding/table_bindings.d.ts +2 -2
- package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -5
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +2 -4
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +6 -6
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +1 -2
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntitiesCount.js +3 -3
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +1 -2
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/RowActions.d.ts +1 -2
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/SortButton.d.ts +1 -1
- package/dist/components/CollectionViewBinding/SortButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +1 -2
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.d.ts +2 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.js +3 -3
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +2 -4
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +14 -19
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -1
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +1 -3
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +1 -2
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +23 -8
- package/dist/components/CollectionsProvider.js +23 -7
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/DefaultDrawer.js +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +1 -1
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +3 -3
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -1
- package/dist/components/EditViewBinding.js +6 -6
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.d.ts +1 -2
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityInspector.d.ts +1 -2
- package/dist/components/EntityInspector.js.map +1 -1
- package/dist/components/EntityPreviewBinding.d.ts +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +1 -1
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +1 -1
- package/dist/components/EntityViewBody.js +3 -4
- package/dist/components/EntityViewBody.js.map +1 -1
- package/dist/components/FieldValue.js +2 -2
- package/dist/components/FieldValue.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +12 -3
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/InlineEntityPreview.d.ts +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PropertyCollectionView.d.ts +2 -2
- package/dist/components/PropertyCollectionView.js.map +1 -1
- package/dist/components/PropertyConfigBadge.js.map +1 -1
- package/dist/components/RebaseCMS.d.ts +22 -3
- package/dist/components/RebaseCMS.js +32 -14
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +106 -31
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RecordDetail.js +4 -1
- package/dist/components/RecordDetail.js.map +1 -1
- package/dist/components/RecordForm.d.ts +5 -5
- package/dist/components/RecordForm.js +5 -2
- package/dist/components/RecordForm.js.map +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +2 -2
- package/dist/components/ReferenceTable/SelectionTableBinding.js +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +2 -1
- package/dist/components/ReferenceWidget.js +2 -2
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.d.ts +2 -1
- package/dist/components/RelationSelector.js +2 -3
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.d.ts +2 -2
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.d.ts +2 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js +3 -3
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/null_filter.d.ts +1 -3
- package/dist/components/SelectableTable/filters/null_filter.js.map +1 -1
- package/dist/components/SidePanelBinding.js +1 -1
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/field_configs.d.ts +1 -2
- package/dist/components/field_configs.js.map +1 -1
- package/dist/components/field_ids.d.ts +1 -1
- package/dist/components/field_ids.js +1 -1
- package/dist/components/field_ids.js.map +1 -1
- package/dist/components/history/EntityHistoryEntry.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +1 -2
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/data_export/export/BasicExportAction.d.ts +1 -1
- package/dist/data_export/export/BasicExportAction.js.map +1 -1
- package/dist/data_export/export/ExportCollectionAction.js +2 -2
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +1 -1
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_export/export/export.d.ts +1 -1
- package/dist/data_export/export/export.js +1 -1
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/data_export/export/fetch_export_data.d.ts +3 -2
- package/dist/data_export/export/fetch_export_data.js.map +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -1
- package/dist/data_import/hooks/useImportConfig.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.d.ts +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/data_import/types/column_mapping.d.ts +1 -1
- package/dist/data_import/utils/data.d.ts +1 -2
- package/dist/data_import/utils/data.js +1 -2
- package/dist/data_import/utils/data.js.map +1 -1
- package/dist/data_import/utils/get_import_inference_type.d.ts +1 -1
- package/dist/data_import/utils/get_import_inference_type.js.map +1 -1
- package/dist/data_import/utils/id_column.d.ts +1 -1
- package/dist/data_import/utils/id_column.js.map +1 -1
- package/dist/data_import/utils/import_columns.d.ts +1 -1
- package/dist/data_import/utils/import_columns.js.map +1 -1
- package/dist/data_import/utils/save_entities.d.ts +3 -3
- package/dist/data_import/utils/save_entities.js +1 -1
- package/dist/data_import/utils/save_entities.js.map +1 -1
- package/dist/form/EntityForm.js +2 -1
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.js +2 -2
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormFieldsContext.d.ts +1 -4
- package/dist/form/FormFieldsContext.js +1 -1
- package/dist/form/FormFieldsContext.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +6 -8
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/components/FieldBlock.d.ts +1 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FieldHelperText.d.ts +1 -1
- package/dist/form/components/FieldHelperText.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +1 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/LocalChangesMenu.d.ts +1 -1
- package/dist/form/components/LocalChangesMenu.js.map +1 -1
- package/dist/form/components/StorageItemPreview.d.ts +1 -1
- package/dist/form/components/StorageItemPreview.js.map +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.js +1 -2
- package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MapFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +3 -3
- package/dist/form/form_utils.js +1 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/label_placement.d.ts +1 -2
- package/dist/form/label_placement.js.map +1 -1
- package/dist/form/resolve_cell_property.d.ts +1 -2
- package/dist/form/resolve_cell_property.js +1 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/form/resolve_form_properties.d.ts +2 -2
- package/dist/form/resolve_form_properties.js +1 -1
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/form/useClearRestoreValue.d.ts +1 -1
- package/dist/form/useClearRestoreValue.js.map +1 -1
- package/dist/form/validation.d.ts +2 -2
- package/dist/form/validation.js +1 -1
- package/dist/form/validation.js.map +1 -1
- package/dist/hooks/navigation/compose_collections.d.ts +59 -0
- package/dist/hooks/navigation/compose_collections.js +48 -0
- package/dist/hooks/navigation/compose_collections.js.map +1 -0
- package/dist/hooks/navigation/compose_collections_input.d.ts +8 -0
- package/dist/hooks/navigation/compose_collections_input.js +17 -0
- package/dist/hooks/navigation/compose_collections_input.js.map +1 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +1 -1
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -1
- package/dist/hooks/navigation/registered_collection.d.ts +15 -0
- package/dist/hooks/navigation/registered_collection.js +20 -0
- package/dist/hooks/navigation/registered_collection.js.map +1 -0
- package/dist/hooks/navigation/ui_preferences.d.ts +47 -0
- package/dist/hooks/navigation/ui_preferences.js +179 -0
- package/dist/hooks/navigation/ui_preferences.js.map +1 -0
- package/dist/hooks/navigation/useAsyncResolver.d.ts +8 -1
- package/dist/hooks/navigation/useAsyncResolver.js +9 -3
- package/dist/hooks/navigation/useAsyncResolver.js.map +1 -1
- package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +1 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js +3 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +9 -5
- package/dist/hooks/navigation/useBuildNavigationStateController.js +2 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useBuildUrlController.d.ts +1 -1
- package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.js +1 -2
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/usePanelTables.d.ts +11 -0
- package/dist/hooks/navigation/usePanelTables.js +33 -0
- package/dist/hooks/navigation/usePanelTables.js.map +1 -0
- package/dist/hooks/navigation/useResolvedCollections.d.ts +8 -3
- package/dist/hooks/navigation/useResolvedCollections.js +3 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +1 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -2
- package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -1
- package/dist/hooks/navigation/user_preferences_overlay.d.ts +21 -0
- package/dist/hooks/navigation/user_preferences_overlay.js +101 -0
- package/dist/hooks/navigation/user_preferences_overlay.js.map +1 -0
- package/dist/hooks/navigation/utils.js +1 -1
- package/dist/hooks/navigation/utils.js.map +1 -1
- package/dist/hooks/useAdminContext.d.ts +1 -2
- package/dist/hooks/useAdminContext.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.d.ts +1 -2
- package/dist/hooks/useBuildSidePanel.js +2 -1
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useChildViewSource.d.ts +1 -1
- package/dist/hooks/useChildViewSource.js +1 -1
- package/dist/hooks/useChildViewSource.js.map +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +1 -2
- package/dist/hooks/useEntityDisplay.js +1 -1
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useEntityDisplayTitle.d.ts +2 -2
- package/dist/hooks/useEntityDisplayTitle.js.map +1 -1
- package/dist/hooks/useHistory.js +1 -1
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/hooks/useRecordActions.d.ts +1 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useReferencePaths.d.ts +21 -7
- package/dist/hooks/useReferencePaths.js +23 -6
- package/dist/hooks/useReferencePaths.js.map +1 -1
- package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
- package/dist/hooks/useResolvedNavigationFrom.js +1 -1
- package/dist/hooks/useResolvedNavigationFrom.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -2
- package/dist/mcp_view/app_modules.d.ts +2 -2
- package/dist/mcp_view/app_modules.js +4 -4
- package/dist/mcp_view/app_modules.js.map +1 -1
- package/dist/mcp_view/index.d.ts +16 -19
- package/dist/mcp_view/index.js +43 -62
- package/dist/mcp_view/index.js.map +1 -1
- package/dist/mcp_view/payload.d.ts +54 -18
- package/dist/mcp_view/payload.js +49 -24
- package/dist/mcp_view/payload.js.map +1 -1
- package/dist/mcp_view/screen.js +11 -11
- package/dist/mcp_view/screen.js.map +1 -1
- package/dist/mcp_view/tool_driver.d.ts +5 -34
- package/dist/mcp_view/tool_driver.js +17 -16
- package/dist/mcp_view/tool_driver.js.map +1 -1
- package/dist/mcp_view/write_review.d.ts +1 -2
- package/dist/mcp_view/write_review.js +1 -1
- package/dist/mcp_view/write_review.js.map +1 -1
- package/dist/preview/PropertyPreview.d.ts +1 -1
- package/dist/preview/PropertyPreview.js +4 -3
- package/dist/preview/PropertyPreview.js.map +1 -1
- package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
- package/dist/preview/components/ArrayEnumPreview.js.map +1 -1
- package/dist/preview/components/BooleanPreview.d.ts +1 -1
- package/dist/preview/components/BooleanPreview.js.map +1 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/components/EnumValuesChip.js +1 -1
- package/dist/preview/components/EnumValuesChip.js.map +1 -1
- package/dist/preview/components/ReferencePreview.d.ts +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.d.ts +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/preview/components/StorageThumbnail.js +2 -1
- package/dist/preview/components/StorageThumbnail.js.map +1 -1
- package/dist/preview/components/UserPreview.d.ts +1 -1
- package/dist/preview/components/UserPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js +2 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -1
- package/dist/preview/util.d.ts +1 -1
- package/dist/preview/util.js.map +1 -1
- package/dist/routes/RebaseRoute.js +2 -2
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/saved_apps/SavedAppsView.d.ts +1 -1
- package/dist/saved_apps/SavedAppsView.js +1 -1
- package/dist/saved_apps/SavedAppsView.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +1 -1
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/resolve_selection.d.ts +3 -3
- package/dist/selection/resolve_selection.js +3 -2
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/tables/apply_customization.d.ts +65 -0
- package/dist/tables/apply_customization.js +644 -0
- package/dist/tables/apply_customization.js.map +1 -0
- package/dist/tables/column_property.d.ts +64 -0
- package/dist/tables/column_property.js +549 -0
- package/dist/tables/column_property.js.map +1 -0
- package/dist/tables/customize_table.d.ts +39 -0
- package/dist/tables/customize_table.js +247 -0
- package/dist/tables/customize_table.js.map +1 -0
- package/dist/tables/index.d.ts +12 -0
- package/dist/tables/labels.d.ts +18 -0
- package/dist/tables/labels.js +18 -0
- package/dist/tables/labels.js.map +1 -0
- package/dist/tables/project_table.d.ts +79 -0
- package/dist/tables/project_table.js +148 -0
- package/dist/tables/project_table.js.map +1 -0
- package/dist/tables/relations.d.ts +47 -0
- package/dist/tables/relations.js +112 -0
- package/dist/tables/relations.js.map +1 -0
- package/dist/tables/rls.d.ts +39 -0
- package/dist/tables/rls.js +111 -0
- package/dist/tables/rls.js.map +1 -0
- package/dist/tables/update_record.d.ts +32 -0
- package/dist/tables/update_record.js +40 -0
- package/dist/tables/update_record.js.map +1 -0
- package/dist/types/components/EntityFormActionsProps.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +2 -2
- package/dist/types/fields.d.ts +2 -2
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/entity_pages.d.ts +2 -1
- package/dist/util/entity_pages.js.map +1 -1
- package/dist/util/find_entities_by_ids.d.ts +2 -2
- package/dist/util/find_entities_by_ids.js +1 -1
- package/dist/util/find_entities_by_ids.js.map +1 -1
- package/dist/util/format_collection_date.d.ts +1 -1
- package/dist/util/format_collection_date.js.map +1 -1
- package/dist/util/identity.d.ts +8 -0
- package/dist/util/identity.js +16 -0
- package/dist/util/identity.js.map +1 -0
- package/dist/util/navigation_utils.js +1 -1
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/previews.js +1 -1
- package/dist/util/previews.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +1 -1
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/dist/util/property_utils.d.ts +1 -3
- package/dist/util/property_utils.js +1 -1
- package/dist/util/property_utils.js.map +1 -1
- package/dist/util/relations.d.ts +18 -0
- package/dist/util/relations.js +32 -0
- package/dist/util/relations.js.map +1 -0
- package/package.json +12 -10
- package/recipes/README.md +4 -4
- package/recipes/my-preferences.tsx +34 -26
- package/recipes/site-settings.tsx +34 -27
- package/dist/collection_editor/collection_wire.d.ts +0 -13
- package/dist/collection_editor/collection_wire.js +0 -49
- package/dist/collection_editor/collection_wire.js.map +0 -1
- package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +0 -37
- package/dist/collection_editor/useJsonCollectionsConfigController.js +0 -191
- package/dist/collection_editor/useJsonCollectionsConfigController.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayOfReferencesFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx"],"sourcesContent":["import { useEntitySelectionDialog } from \"../../hooks/useSelectionDialog\";\n\nimport type { FieldProps } from \"../../types/fields\";\nimport
|
|
1
|
+
{"version":3,"file":"ArrayOfReferencesFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx"],"sourcesContent":["import { useEntitySelectionDialog } from \"../../hooks/useSelectionDialog\";\n\nimport type { FieldProps } from \"../../types/fields\";\nimport React, { useCallback, useMemo } from \"react\";\nimport { EntityReference, Entity } from \"@rebasepro/cms-types\";\nimport { ReferencePreview } from \"../../preview\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { ArrayContainer, ArrayEntryParams } from \"../../components/ArrayContainer\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\nimport { useTranslation, ErrorView } from \"@rebasepro/app\";\nimport { Button, cls, ExpandablePanel, fieldBackgroundMixin, PencilIcon, Typography } from \"@rebasepro/ui\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../../hooks/useReferencePaths\";\nimport type { AdminCollection, ArrayProperty, Property } from \"@rebasepro/cms-types\";\n\ntype ArrayOfReferencesFieldProps = FieldProps<ArrayProperty, EntityReference[]>;\n\n/**\n * This field allows selecting multiple references.\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 ArrayOfReferencesFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n disabled,\n isSubmitting,\n minimalistView: minimalistViewProp,\n property,\n includeDescription,\n setValue,\n setFieldValue\n}: ArrayOfReferencesFieldProps) {\n\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n const { t } = useTranslation();\n\n const ofProperty = property.of as Property;\n if (ofProperty.type !== \"reference\") {\n throw Error(\"ArrayOfReferencesField expected a property containing references\");\n }\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n const selectedEntityIds = value && Array.isArray(value) ? value.map((ref) => ref.id) : [];\n\n const collectionRegistryController = useCollectionRegistryController();\n const { targetPath, referenceTo } = useReferencePaths();\n const collectionPath = ofProperty.path ? targetPath(ofProperty.path) : undefined;\n const collection: AdminCollection | undefined = useMemo(() => {\n return collectionPath ? collectionRegistryController.getCollection(collectionPath) : undefined;\n }, [collectionPath]);\n\n if (!collection) {\n throw Error(`Couldn't find the corresponding collection for the path: ${ofProperty.path}`);\n }\n\n const onMultipleEntitiesSelected = useCallback((entities: Entity<Record<string, unknown>>[]) => {\n const refs = entities.map(e => referenceTo(e));\n setValue(refs);\n }, [setValue, referenceTo]);\n\n const referenceDialogController = useEntitySelectionDialog({\n multiselect: true,\n path: collectionPath,\n collection,\n onMultipleEntitiesSelected,\n selectedEntityIds,\n fixedFilter: ofProperty.admin?.fixedFilter\n }\n );\n\n const onEntryClick = (e: React.SyntheticEvent) => {\n e.preventDefault();\n if (disabled || isSubmitting) return;\n referenceDialogController.open();\n };\n\n const buildEntry = useCallback(({\n index,\n internalId,\n storedProps,\n storeProps\n }: ArrayEntryParams) => {\n const entryValue = value && value.length > index ? value[index] : undefined;\n if (!entryValue)\n return <div>Internal ERROR</div>;\n return (\n <ReferencePreview\n key={internalId}\n disabled={!ofProperty.path}\n previewProperties={ofProperty.admin?.previewProperties}\n size={\"medium\"}\n onClick={onEntryClick}\n hover={!disabled}\n reference={entryValue}\n includeId={ofProperty.admin?.includeId}\n includeEntityLink={ofProperty.admin?.includeEntityLink}\n />\n );\n }, [ofProperty.path, ofProperty.admin?.previewProperties, value, disabled, isSubmitting]);\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 flex 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 = <>\n {!collection && <ErrorView\n error={\"The specified collection does not exist. Check console\"}/>}\n\n {collection && <div className={\"group\"}>\n\n <ArrayContainer droppableId={propertyKey}\n value={value}\n disabled={disabled || isSubmitting}\n buildEntry={buildEntry}\n canAddElements={false}\n addLabel={property.name ? t(\"add_reference_to\", { name: property.name }) : t(\"add_reference\")}\n newDefaultEntry={property.of && \"defaultValue\" in property.of ? property.of?.defaultValue : null}\n onValueChange={(value) => setFieldValue(propertyKey, value)}\n />\n\n <Button\n className=\"ml-3.5 my-4 justify-center text-left\"\n variant=\"text\"\n disabled={disabled || isSubmitting}\n onClick={onEntryClick}>\n <PencilIcon size={16}/>\n {t(\"edit_name\", { name: property.name ?? propertyKey })}\n </Button>\n </div>}\n </>;\n\n return (\n <>\n\n {!minimalistView &&\n <ExpandablePanel\n titleClassName={fieldBackgroundMixin}\n innerClassName={cls(\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\", fieldBackgroundMixin)}\n initiallyExpanded={expanded}\n title={title}>\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":";;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,8BAA8B,EAC1C,aACA,OACA,OACA,WACA,UACA,cACA,gBAAgB,oBAChB,UACA,oBACA,UACA,iBAC4B;CAE5B,MAAM,iBAAiB,sBAAsB,SAAS,OAAO;CAC7D,MAAM,EAAE,MAAM,eAAe;CAE7B,MAAM,aAAa,SAAS;CAC5B,IAAI,WAAW,SAAS,aACpB,MAAM,MAAM,kEAAkE;CAGlF,MAAM,WAAW,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO;CACjF,MAAM,oBAAoB,SAAS,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,QAAQ,IAAI,EAAE,IAAI,CAAC;CAExF,MAAM,+BAA+B,gCAAgC;CACrE,MAAM,EAAE,YAAY,gBAAgB,kBAAkB;CACtD,MAAM,iBAAiB,WAAW,OAAO,WAAW,WAAW,IAAI,IAAI,KAAA;CACvE,MAAM,aAA0C,cAAc;EAC1D,OAAO,iBAAiB,6BAA6B,cAAc,cAAc,IAAI,KAAA;CACzF,GAAG,CAAC,cAAc,CAAC;CAEnB,IAAI,CAAC,YACD,MAAM,MAAM,4DAA4D,WAAW,MAAM;CAQ7F,MAAM,4BAA4B,yBA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U,YAAY;GACV;GACZ,gBAAgB;GAChB,UAAU,SAAS,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,KAAK,CAAC,IAAI,EAAE,eAAe;GAC5F,iBAAiB,SAAS,MAAM,kBAAkB,SAAS,KAAK,SAAS,IAAI,eAAe;GAC5F,gBAAgB,UAAU,cAAc,aAAa,KAAK;EAC7D,CAAA,GAED,qBAAC,QAAD;GACI,WAAU;GACV,SAAQ;GACR,UAAU,YAAY;GACtB,SAAS;aAJb,CAKI,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA,GACrB,EAAE,aAAa,EAAE,MAAM,SAAS,QAAQ,YAAY,CAAC,CAClD;IACP;GACP,EAAA,CAAA;CAEF,OACI,qBAAA,UAAA,EAAA,UAAA;EAEK,CAAC,kBACE,oBAAC,iBAAD;GACI,gBAAgB;GAChB,gBAAgB,IAAI,0CAA0C,oBAAoB;GAClF,mBAAmB;GACZ;aACN;EACY,CAAA;EAEpB,kBAAkB;EAEnB,oBAAC,iBAAD;GAAqC;GACtB;GACJ;GACG;GACA;EAAU,CAAA;CAE1B,EAAA,CAAA;AAEV"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FieldProps } from "../../types/fields.js";
|
|
2
|
-
import type { BinaryProperty } from "@rebasepro/types";
|
|
2
|
+
import type { BinaryProperty } from "@rebasepro/cms-types";
|
|
3
3
|
import React from "react";
|
|
4
4
|
/** Base64, optionally padded. Empty is allowed — that is a cleared field. */
|
|
5
5
|
export declare const BASE64: RegExp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BinaryFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/BinaryFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { BinaryProperty } from \"@rebasepro/types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { Button, CheckIcon, cls, defaultBorderMixin, IconButton, PencilIcon, TextField, Trash2Icon } from \"@rebasepro/ui\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/** Base64, optionally padded. Empty is allowed — that is a cleared field. */\nexport const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n\n/** Decoded byte count of a base64 string, without decoding it. */\nexport function decodedBytes(base64: string): number {\n const clean = base64.replace(/\\s/g, \"\");\n if (!clean) return 0;\n const padding = clean.endsWith(\"==\") ? 2 : clean.endsWith(\"=\") ? 1 : 0;\n return Math.max(0, (clean.length * 3) / 4 - padding);\n}\n\nexport function humanSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\n/**\n * Field binding for `type: \"binary\"`, whose value is a base64-encoded string.\n *\n * Before this there was no binary field. The widget lookup mapped the type\n * straight to `text_field`, so a binary column rendered as an ordinary string\n * input — offering multiline, markdown and email options that mean nothing for\n * bytes, and, worse, pushing the property through a widget whose editor merges\n * `type: \"string\"`. Opening a binary property and touching its widget silently\n * changed its type.\n *\n * Shown collapsed by default. Base64 is long, unreadable and never worth\n * scrolling past to reach the next field; what a person actually wants to know\n * is whether there is anything in there and how big it is.\n *\n * @group Form fields\n */\nexport function BinaryFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<BinaryProperty>) {\n\n const stored = typeof value === \"string\" ? value : \"\";\n const [text, setText] = useState(stored);\n const [isEditing, setIsEditing] = useState(false);\n\n useEffect(() => {\n setText(typeof value === \"string\" ? value : \"\");\n }, [value]);\n\n const handleClear = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setText(\"\");\n setValue(null);\n }, [setValue]);\n\n const onChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const raw = e.target.value;\n setText(raw);\n setValue(raw === \"\" ? null : (raw));\n }, [setValue]);\n\n const malformed = text.trim() !== \"\" && !BASE64.test(text.replace(/\\s/g, \"\"));\n const bytes = malformed ? 0 : decodedBytes(text);\n const isPopulated = text.trim() !== \"\";\n\n const localError = malformed ? \"Not valid base64\" : undefined;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* The row goes away with the label rather than emptying out. Left\n unconditional it still contributed its `mb-1` and the column's\n `gap-2`, which — on top of the `mt-2` that used to sit on the\n wrapper — pushed this control 20px below the one next to it\n while the two labels stayed level. */}\n {!hideLabel && <div className=\"flex items-center justify-between mb-1\">\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n </div>}\n\n <div className=\"w-full\">\n {!isEditing ? (\n <div className={cls(\"flex items-center justify-between gap-2 p-4 rounded-xl border bg-surface-field\", defaultBorderMixin)}>\n <div className=\"flex items-center gap-2.5 min-w-0\">\n <div className={`w-2.5 h-2.5 rounded-full shrink-0 ${isPopulated ? \"bg-emerald-500\" : \"bg-surface-300 dark:bg-surface-600\"}`}/>\n <span className=\"text-sm font-semibold text-text-primary truncate\">\n {malformed\n ? \"Invalid base64\"\n : isPopulated ? `${humanSize(bytes)} of binary data` : \"Empty\"}\n </span>\n </div>\n <div className=\"flex items-center gap-2 shrink-0\">\n {!disabled && (\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(true)}\n startIcon={<PencilIcon size={14}/>}\n >\n {isPopulated ? \"Edit base64\" : \"Add base64\"}\n </Button>\n )}\n {isPopulated && !disabled && (\n <IconButton\n size=\"small\"\n onClick={handleClear}\n className=\"text-text-secondary hover:text-red-500\"\n aria-label=\"Clear binary value\"\n >\n <Trash2Icon size={14}/>\n </IconButton>\n )}\n </div>\n </div>\n ) : (\n <div className={cls(\"flex flex-col gap-2 p-4 rounded-xl border\", defaultBorderMixin)}>\n <TextField\n size={size}\n aria-label={`${property.name ?? propertyKey} base64 value`}\n value={text}\n onChange={onChange}\n autoFocus={autoFocus ?? true}\n multiline\n minRows={4}\n disabled={disabled}\n placeholder=\"Base64-encoded bytes, e.g. iVBORw0KGgo…\"\n error={showError ? Boolean(error) || malformed : malformed}\n inputClassName={`font-mono text-xs ${malformed ? \"text-red-500\" : \"\"}`}\n />\n <div className=\"flex justify-end\">\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n startIcon={<CheckIcon size={14}/>}\n >\n Done\n </Button>\n </div>\n </div>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError || malformed}\n error={error || localError}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,SAAS;;AAGtB,SAAgB,aAAa,QAAwB;CACjD,MAAM,QAAQ,OAAO,QAAQ,OAAO,EAAE;CACtC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,UAAU,MAAM,SAAS,IAAI,IAAI,IAAI,MAAM,SAAS,GAAG,IAAI,IAAI;CACrE,OAAO,KAAK,IAAI,GAAI,MAAM,SAAS,IAAK,IAAI,OAAO;AACvD;AAEA,SAAgB,UAAU,OAAuB;CAC7C,IAAI,QAAQ,MAAM,OAAO,GAAG,MAAM;CAClC,IAAI,QAAQ,OAAO,MAAM,OAAO,IAAI,QAAQ,KAAA,CAAM,QAAQ,CAAC,EAAE;CAC7D,OAAO,IAAI,SAAS,OAAO,MAAA,CAAO,QAAQ,CAAC,EAAE;AACjD;;;;;;;;;;;;;;;;;AAkBA,SAAgB,mBAAmB,EAC/B,aACA,OACA,UACA,OACA,WACA,UACA,WACA,UACA,oBACA,WACA,OAAO,WACoB;CAG3B,MAAM,CAAC,MAAM,WAAW,SADT,OAAO,UAAU,WAAW,QAAQ,EACZ;CACvC,MAAM,CAAC,WAAW,gBAAgB,SAAS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AI;OAChC,WAAW,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA;iBAEhC,cAAc,gBAAgB;MAC3B,CAAA,GAEX,eAAe,CAAC,YACb,oBAAC,YAAD;OACI,MAAK;OACL,SAAS;OACT,WAAU;OACV,cAAW;iBAEX,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA;MACd,CAAA,CAEf;OACJ;SAEL,qBAAC,OAAD;KAAK,WAAW,IAAI,6CAA6C,kBAAkB;eAAnF,CACI,oBAAC,WAAD;MACU;MACN,cAAY,GAAG,SAAS,QAAQ,YAAY;MAC5C,OAAO;MACG;MACV,WAAW,aAAa;MACxB,WAAA;MACA,SAAS;MACC;MACV,aAAY;MACZ,OAAO,YAAY,QAAQ,KAAK,KAAK,YAAY;MACjD,gBAAgB,qBAAqB,YAAY,iBAAiB;KACrE,CAAA,GACD,oBAAC,OAAD;MAAK,WAAU;gBACX,oBAAC,QAAD;OACI,SAAQ;OACR,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,WAAW,oBAAC,WAAD,EAAW,MAAM,GAAI,CAAA;iBACnC;MAEO,CAAA;KACP,CAAA,CACJ;;GAER,CAAA;GAEL,oBAAC,iBAAD;IACwB;IACpB,WAAW,aAAa;IACxB,OAAO,SAAS;IACN;IACA;GACb,CAAA;EACA;;AAEb"}
|
|
1
|
+
{"version":3,"file":"BinaryFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/BinaryFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { BinaryProperty } from \"@rebasepro/cms-types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { Button, CheckIcon, cls, defaultBorderMixin, IconButton, PencilIcon, TextField, Trash2Icon } from \"@rebasepro/ui\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/** Base64, optionally padded. Empty is allowed — that is a cleared field. */\nexport const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n\n/** Decoded byte count of a base64 string, without decoding it. */\nexport function decodedBytes(base64: string): number {\n const clean = base64.replace(/\\s/g, \"\");\n if (!clean) return 0;\n const padding = clean.endsWith(\"==\") ? 2 : clean.endsWith(\"=\") ? 1 : 0;\n return Math.max(0, (clean.length * 3) / 4 - padding);\n}\n\nexport function humanSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\n/**\n * Field binding for `type: \"binary\"`, whose value is a base64-encoded string.\n *\n * Before this there was no binary field. The widget lookup mapped the type\n * straight to `text_field`, so a binary column rendered as an ordinary string\n * input — offering multiline, markdown and email options that mean nothing for\n * bytes, and, worse, pushing the property through a widget whose editor merges\n * `type: \"string\"`. Opening a binary property and touching its widget silently\n * changed its type.\n *\n * Shown collapsed by default. Base64 is long, unreadable and never worth\n * scrolling past to reach the next field; what a person actually wants to know\n * is whether there is anything in there and how big it is.\n *\n * @group Form fields\n */\nexport function BinaryFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<BinaryProperty>) {\n\n const stored = typeof value === \"string\" ? value : \"\";\n const [text, setText] = useState(stored);\n const [isEditing, setIsEditing] = useState(false);\n\n useEffect(() => {\n setText(typeof value === \"string\" ? value : \"\");\n }, [value]);\n\n const handleClear = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setText(\"\");\n setValue(null);\n }, [setValue]);\n\n const onChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n const raw = e.target.value;\n setText(raw);\n setValue(raw === \"\" ? null : (raw));\n }, [setValue]);\n\n const malformed = text.trim() !== \"\" && !BASE64.test(text.replace(/\\s/g, \"\"));\n const bytes = malformed ? 0 : decodedBytes(text);\n const isPopulated = text.trim() !== \"\";\n\n const localError = malformed ? \"Not valid base64\" : undefined;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* The row goes away with the label rather than emptying out. Left\n unconditional it still contributed its `mb-1` and the column's\n `gap-2`, which — on top of the `mt-2` that used to sit on the\n wrapper — pushed this control 20px below the one next to it\n while the two labels stayed level. */}\n {!hideLabel && <div className=\"flex items-center justify-between mb-1\">\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n </div>}\n\n <div className=\"w-full\">\n {!isEditing ? (\n <div className={cls(\"flex items-center justify-between gap-2 p-4 rounded-xl border bg-surface-field\", defaultBorderMixin)}>\n <div className=\"flex items-center gap-2.5 min-w-0\">\n <div className={`w-2.5 h-2.5 rounded-full shrink-0 ${isPopulated ? \"bg-emerald-500\" : \"bg-surface-300 dark:bg-surface-600\"}`}/>\n <span className=\"text-sm font-semibold text-text-primary truncate\">\n {malformed\n ? \"Invalid base64\"\n : isPopulated ? `${humanSize(bytes)} of binary data` : \"Empty\"}\n </span>\n </div>\n <div className=\"flex items-center gap-2 shrink-0\">\n {!disabled && (\n <Button\n variant=\"outlined\"\n size=\"small\"\n onClick={() => setIsEditing(true)}\n startIcon={<PencilIcon size={14}/>}\n >\n {isPopulated ? \"Edit base64\" : \"Add base64\"}\n </Button>\n )}\n {isPopulated && !disabled && (\n <IconButton\n size=\"small\"\n onClick={handleClear}\n className=\"text-text-secondary hover:text-red-500\"\n aria-label=\"Clear binary value\"\n >\n <Trash2Icon size={14}/>\n </IconButton>\n )}\n </div>\n </div>\n ) : (\n <div className={cls(\"flex flex-col gap-2 p-4 rounded-xl border\", defaultBorderMixin)}>\n <TextField\n size={size}\n aria-label={`${property.name ?? propertyKey} base64 value`}\n value={text}\n onChange={onChange}\n autoFocus={autoFocus ?? true}\n multiline\n minRows={4}\n disabled={disabled}\n placeholder=\"Base64-encoded bytes, e.g. iVBORw0KGgo…\"\n error={showError ? Boolean(error) || malformed : malformed}\n inputClassName={`font-mono text-xs ${malformed ? \"text-red-500\" : \"\"}`}\n />\n <div className=\"flex justify-end\">\n <Button\n variant=\"filled\"\n size=\"small\"\n onClick={() => setIsEditing(false)}\n startIcon={<CheckIcon size={14}/>}\n >\n Done\n </Button>\n </div>\n </div>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError || malformed}\n error={error || localError}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,SAAS;;AAGtB,SAAgB,aAAa,QAAwB;CACjD,MAAM,QAAQ,OAAO,QAAQ,OAAO,EAAE;CACtC,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,UAAU,MAAM,SAAS,IAAI,IAAI,IAAI,MAAM,SAAS,GAAG,IAAI,IAAI;CACrE,OAAO,KAAK,IAAI,GAAI,MAAM,SAAS,IAAK,IAAI,OAAO;AACvD;AAEA,SAAgB,UAAU,OAAuB;CAC7C,IAAI,QAAQ,MAAM,OAAO,GAAG,MAAM;CAClC,IAAI,QAAQ,OAAO,MAAM,OAAO,IAAI,QAAQ,KAAA,CAAM,QAAQ,CAAC,EAAE;CAC7D,OAAO,IAAI,SAAS,OAAO,MAAA,CAAO,QAAQ,CAAC,EAAE;AACjD;;;;;;;;;;;;;;;;;AAkBA,SAAgB,mBAAmB,EAC/B,aACA,OACA,UACA,OACA,WACA,UACA,WACA,UACA,oBACA,WACA,OAAO,WACoB;CAG3B,MAAM,CAAC,MAAM,WAAW,SADT,OAAO,UAAU,WAAW,QAAQ,EACZ;CACvC,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,gBAAgB;EACZ,QAAQ,OAAO,UAAU,WAAW,QAAQ,EAAE;CAClD,GAAG,CAAC,KAAK,CAAC;CAEV,MAAM,cAAc,aAAa,MAAwB;EACrD,EAAE,gBAAgB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ACT,WAAU;OACV,cAAW;iBAEX,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA;MACd,CAAA,CAEf;OACJ;SAEL,qBAAC,OAAD;KAAK,WAAW,IAAI,6CAA6C,kBAAkB;eAAnF,CACI,oBAAC,WAAD;MACU;MACN,cAAY,GAAG,SAAS,QAAQ,YAAY;MAC5C,OAAO;MACG;MACV,WAAW,aAAa;MACxB,WAAA;MACA,SAAS;MACC;MACV,aAAY;MACZ,OAAO,YAAY,QAAQ,KAAK,KAAK,YAAY;MACjD,gBAAgB,qBAAqB,YAAY,iBAAiB;KACrE,CAAA,GACD,oBAAC,OAAD;MAAK,WAAU;gBACX,oBAAC,QAAD;OACI,SAAQ;OACR,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,WAAW,oBAAC,WAAD,EAAW,MAAM,GAAI,CAAA;iBACnC;MAEO,CAAA;KACP,CAAA,CACJ;;GAER,CAAA;GAEL,oBAAC,iBAAD;IACwB;IACpB,WAAW,aAAa;IACxB,OAAO,SAAS;IACN;IACA;GACb,CAAA;EACA;;AAEb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FieldProps } from "../../types/fields.js";
|
|
2
|
-
import type { ArrayProperty } from "@rebasepro/types";
|
|
2
|
+
import type { ArrayProperty } from "@rebasepro/cms-types";
|
|
3
3
|
import React from "react";
|
|
4
4
|
/**
|
|
5
5
|
* If the `oneOf` property is specified, this fields render each array entry as
|
|
@@ -7,7 +7,7 @@ import { PropertyFieldBinding } from "../PropertyFieldBinding.js";
|
|
|
7
7
|
import { useCallback, useEffect, useState } from "react";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { ExpandablePanel, Select, SelectItem, Typography, cls, paperMixin } from "@rebasepro/ui";
|
|
10
|
-
import { DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, getDefaultValueFor } from "@rebasepro/
|
|
10
|
+
import { DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, getDefaultValueFor } from "@rebasepro/cms-types";
|
|
11
11
|
import { isDisabled, useTranslation } from "@rebasepro/app";
|
|
12
12
|
import { getIn, useFormexGetter, useFormexSelector } from "@rebasepro/forms";
|
|
13
13
|
import { mergeDeep } from "@rebasepro/utils";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/BlockFieldBinding.tsx"],"sourcesContent":["import type { FieldProps, FormContext, PropertyFieldBindingProps } from \"../../types/fields\";\nimport type { ArrayProperty, Property } from \"@rebasepro/types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { EnumValuesChip } from \"../../preview\";\n\n;\nimport { DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, getDefaultValueFor } from \"@rebasepro/common\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { cls, ExpandablePanel, paperMixin, Select, SelectItem, Typography } from \"@rebasepro/ui\";\nimport { isDisabled, useTranslation } from \"@rebasepro/app\";\nimport { ArrayContainer, ArrayEntryParams } from \"../../components/ArrayContainer\";\nimport { mergeDeep } from \"@rebasepro/utils\";\n\n/**\n * If the `oneOf` property is specified, this fields render each array entry as\n * a `type` select and the corresponding field widget to the selected `type.\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 BlockFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n isSubmitting,\n setValue,\n setFieldValue,\n minimalistView: minimalistViewProp,\n property,\n includeDescription,\n underlyingValueHasChanged,\n context,\n disabled\n }: FieldProps<ArrayProperty>) {\n\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n const { t } = useTranslation();\n\n if (!property.oneOf)\n throw Error(\"ArrayOneOfField misconfiguration. Property `oneOf` not set\");\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n\n const [lastAddedId, setLastAddedId] = useState<number | undefined>();\n\n const buildEntry = ({\n index,\n internalId,\n storedProps,\n storeProps\n }: ArrayEntryParams) => {\n\n return <BlockEntry\n key={`array_one_of_${internalId}`}\n name={`${propertyKey}.${index}`}\n index={index}\n value={value[index]}\n typeField={property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE}\n valueField={property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE}\n properties={property.oneOf!.properties}\n autoFocus={internalId === lastAddedId}\n context={context}\n storeProps={storeProps}\n storedProps={storedProps}/>;\n };\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={\"text-text-secondary dark:text-text-secondary-dark\"}/>\n );\n\n const firstOneOfKey = Object.keys(property.oneOf.properties)[0];\n const body = <ArrayContainer value={value}\n className={\"flex flex-col gap-3\"}\n droppableId={propertyKey}\n addLabel={property.name ? t(\"add_to_field\", { fieldName: property.name }) : t(\"add_entry\")}\n buildEntry={buildEntry}\n onInternalIdAdded={setLastAddedId}\n disabled={isSubmitting || isDisabled(property)}\n canAddElements={!isDisabled(property)}\n onValueChange={(value) => setFieldValue(propertyKey, value)}\n newDefaultEntry={{\n [property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE]: firstOneOfKey,\n [property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE]: getDefaultValueFor(property.oneOf.properties[firstOneOfKey])\n }}/>;\n return (\n\n <>\n\n {!minimalistView &&\n <ExpandablePanel\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\"}\n initiallyExpanded={expanded}\n title={title}>\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\ninterface BlockEntryProps {\n name: string;\n index: number;\n value: Record<string, unknown>;\n /**\n * Name of the field to use as the discriminator for type\n * Defaults to `type`\n */\n typeField: string;\n /**\n * Name of the field to use as the value\n * Defaults to `value`\n */\n valueField: string;\n\n autoFocus: boolean;\n /**\n * Record of properties, where the key is the `type` and the value\n * is the corresponding property\n */\n properties: Record<string, Property>;\n\n /**\n * Additional values related to the state of the form or the entity\n */\n context: FormContext;\n\n storedProps?: object,\n storeProps: (props: object) => void\n\n}\n\nfunction BlockEntry({\n name,\n index,\n value,\n typeField,\n valueField,\n properties,\n autoFocus,\n context,\n storedProps,\n storeProps\n }: BlockEntryProps) {\n\n const type = value && (value[typeField] as string | undefined);\n const [typeInternal, setTypeInternal] = useState<string | undefined>(type ?? undefined);\n\n const typeFieldName = `${name}.${typeField}`;\n const valueFieldName = `${name}.${valueField}`;\n\n // The picked type, and nothing else of the form: through `useFormex` every\n // entry of every block array — its type picker included — re-rendered on\n // every keystroke anywhere in the record.\n const selectType = useCallback((formex: FormexController) => getIn(formex.values, typeFieldName), [typeFieldName]);\n const typeValue = useFormexSelector(selectType);\n const getFormex = useFormexGetter();\n const { t } = useTranslation();\n\n useEffect(() => {\n if (!type) {\n // Auto-fix empty blocks silently — set the default type WITHOUT\n // marking as touched so the form doesn't become dirty on mount.\n const defaultType = Object.keys(properties)[0];\n const newSelectedProperty = defaultType ? properties[defaultType] : undefined;\n setTypeInternal(defaultType);\n const formex = getFormex();\n formex.setFieldValue(typeFieldName, defaultType);\n formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);\n }\n }, []);\n\n useEffect(() => {\n if (type !== typeInternal) {\n setTypeInternal(type);\n }\n }, [type]);\n\n const propertyInternal = typeInternal ? properties[typeInternal] : undefined;\n\n const property = storedProps && typeof propertyInternal === \"object\" ? mergeDeep(propertyInternal, storedProps) : propertyInternal;\n\n const enumValuesConfigs = Object.entries(properties)\n .map(([key, property]) => ({\n id: key,\n label: property.name ?? key\n }));\n\n const fieldProps: PropertyFieldBindingProps | undefined = property\n ? {\n propertyKey: valueFieldName,\n property,\n context,\n autoFocus,\n partOfArray: false,\n partOfBlock: true,\n minimalistView: true,\n onPropertyChange: storeProps\n }\n : undefined;\n\n const updateType = (newType: string | undefined) => {\n const newSelectedProperty = newType ? properties[newType] : undefined;\n setTypeInternal(newType);\n const formex = getFormex();\n formex.setFieldTouched(typeFieldName, true);\n formex.setFieldValue(typeFieldName, newType);\n formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);\n };\n\n return (\n <div className={cls(paperMixin, \"bg-transparent p-2\")}>\n\n <Select\n className=\"mb-2\"\n // The placeholder is an element, so this\n // control had no name of its own either.\n aria-label={t(\"type\")}\n placeholder={<Typography variant={\"caption\"}\n className={\"px-4 py-2 font-medium\"}>{t(\"type\")}</Typography>}\n size={\"medium\"}\n fullWidth={true}\n position={\"item-aligned\"}\n value={typeValue !== undefined && typeValue !== null ? typeValue as string : \"\"}\n renderValue={(enumKey: string) =>\n <EnumValuesChip\n enumKey={enumKey}\n enumValues={enumValuesConfigs}\n size={\"small\"}/>\n }\n onValueChange={(value) => {\n updateType(value);\n }}>\n {enumValuesConfigs.map((enumConfig) => (\n <SelectItem\n key={enumConfig.id}\n value={String(enumConfig.id)}>\n <EnumValuesChip\n enumKey={enumConfig.id}\n enumValues={enumValuesConfigs}\n size={\"small\"}/>\n </SelectItem>)\n )}\n </Select>\n\n {fieldProps && (\n // It is important to use this key to force a re-render of the field on type change\n <PropertyFieldBinding key={`form_control_${name}_${typeInternal}`} {...fieldProps}/>\n )}\n\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,kBAAkB,EACI,aACA,OACA,OACA,WACA,cACA,UACA,eACA,gBAAgB,oBAChB,UACA,oBACA,2BACA,SACA,YAC0B;CAE5D,MAAM,iBAAiB,s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KAAA;CAEN,MAAM,cAAc,YAAgC;EAChD,MAAM,sBAAsB,UAAU,WAAW,WAAW,KAAA;EAC5D,gBAAgB,OAAO;EACvB,MAAM,SAAS,UAAU;EACzB,OAAO,gBAAgB,eAAe,IAAI;EAC1C,OAAO,cAAc,eAAe,OAAO;EAC3C,OAAO,cAAc,gBAAgB,sBAAsB,mBAAmB,mBAAmB,IAAI,IAAI;CAC7G;CAEA,OACI,qBAAC,OAAD;EAAK,WAAW,IAAI,YAAY,oBAAoB;YAApD,CAEI,oBAAC,QAAD;GACI,WAAU;GAGV,cAAY,EAAE,MAAM;GACpB,aAAa,oBAAC,YAAD;IAAY,SAAS;IACT,WAAW;cAA0B,EAAE,MAAM;GAAc,CAAA;GACpF,MAAM;GACN,WAAW;GACX,UAAU;GACV,OAAO,cAAc,KAAA,KAAa,cAAc,OAAO,YAAsB;GAC7E,cAAc,YACV,oBAAC,gBAAD;IACa;IACT,YAAY;IACZ,MAAM;GAAS,CAAA;GAEvB,gBAAgB,UAAU;IACtB,WAAW,KAAK;GACpB;aACC,kBAAkB,KAAK,eACpB,oBAAC,YAAD;IAEI,OAAO,OAAO,WAAW,EAAE;cAC3B,oBAAC,gBAAD;KACI,SAAS,WAAW;KACpB,YAAY;KACZ,MAAM;IAAS,CAAA;GACX,GANH,WAAW,EAMR,CAChB;EACI,CAAA,GAEP,cAEG,oBAAC,sBAAD,EAAmE,GAAI,WAAY,GAAxD,gBAAgB,KAAK,GAAG,cAAgC,CAGtF;;AAEb"}
|
|
1
|
+
{"version":3,"file":"BlockFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/BlockFieldBinding.tsx"],"sourcesContent":["import type { FieldProps, FormContext, PropertyFieldBindingProps } from \"../../types/fields\";\nimport type { ArrayProperty, Property } from \"@rebasepro/cms-types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\n\nimport { FormexController, getIn, useFormexGetter, useFormexSelector } from \"@rebasepro/forms\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { EnumValuesChip } from \"../../preview\";\n\n;\nimport { DEFAULT_ONE_OF_TYPE, DEFAULT_ONE_OF_VALUE, getDefaultValueFor } from \"@rebasepro/cms-types\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { cls, ExpandablePanel, paperMixin, Select, SelectItem, Typography } from \"@rebasepro/ui\";\nimport { isDisabled, useTranslation } from \"@rebasepro/app\";\nimport { ArrayContainer, ArrayEntryParams } from \"../../components/ArrayContainer\";\nimport { mergeDeep } from \"@rebasepro/utils\";\n\n/**\n * If the `oneOf` property is specified, this fields render each array entry as\n * a `type` select and the corresponding field widget to the selected `type.\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 BlockFieldBinding({\n propertyKey,\n value,\n error,\n showError,\n isSubmitting,\n setValue,\n setFieldValue,\n minimalistView: minimalistViewProp,\n property,\n includeDescription,\n underlyingValueHasChanged,\n context,\n disabled\n }: FieldProps<ArrayProperty>) {\n\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n const { t } = useTranslation();\n\n if (!property.oneOf)\n throw Error(\"ArrayOneOfField misconfiguration. Property `oneOf` not set\");\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n\n const [lastAddedId, setLastAddedId] = useState<number | undefined>();\n\n const buildEntry = ({\n index,\n internalId,\n storedProps,\n storeProps\n }: ArrayEntryParams) => {\n\n return <BlockEntry\n key={`array_one_of_${internalId}`}\n name={`${propertyKey}.${index}`}\n index={index}\n value={value[index]}\n typeField={property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE}\n valueField={property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE}\n properties={property.oneOf!.properties}\n autoFocus={internalId === lastAddedId}\n context={context}\n storeProps={storeProps}\n storedProps={storedProps}/>;\n };\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={\"text-text-secondary dark:text-text-secondary-dark\"}/>\n );\n\n const firstOneOfKey = Object.keys(property.oneOf.properties)[0];\n const body = <ArrayContainer value={value}\n className={\"flex flex-col gap-3\"}\n droppableId={propertyKey}\n addLabel={property.name ? t(\"add_to_field\", { fieldName: property.name }) : t(\"add_entry\")}\n buildEntry={buildEntry}\n onInternalIdAdded={setLastAddedId}\n disabled={isSubmitting || isDisabled(property)}\n canAddElements={!isDisabled(property)}\n onValueChange={(value) => setFieldValue(propertyKey, value)}\n newDefaultEntry={{\n [property.oneOf!.typeField ?? DEFAULT_ONE_OF_TYPE]: firstOneOfKey,\n [property.oneOf!.valueField ?? DEFAULT_ONE_OF_VALUE]: getDefaultValueFor(property.oneOf.properties[firstOneOfKey])\n }}/>;\n return (\n\n <>\n\n {!minimalistView &&\n <ExpandablePanel\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\"}\n initiallyExpanded={expanded}\n title={title}>\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\ninterface BlockEntryProps {\n name: string;\n index: number;\n value: Record<string, unknown>;\n /**\n * Name of the field to use as the discriminator for type\n * Defaults to `type`\n */\n typeField: string;\n /**\n * Name of the field to use as the value\n * Defaults to `value`\n */\n valueField: string;\n\n autoFocus: boolean;\n /**\n * Record of properties, where the key is the `type` and the value\n * is the corresponding property\n */\n properties: Record<string, Property>;\n\n /**\n * Additional values related to the state of the form or the entity\n */\n context: FormContext;\n\n storedProps?: object,\n storeProps: (props: object) => void\n\n}\n\nfunction BlockEntry({\n name,\n index,\n value,\n typeField,\n valueField,\n properties,\n autoFocus,\n context,\n storedProps,\n storeProps\n }: BlockEntryProps) {\n\n const type = value && (value[typeField] as string | undefined);\n const [typeInternal, setTypeInternal] = useState<string | undefined>(type ?? undefined);\n\n const typeFieldName = `${name}.${typeField}`;\n const valueFieldName = `${name}.${valueField}`;\n\n // The picked type, and nothing else of the form: through `useFormex` every\n // entry of every block array — its type picker included — re-rendered on\n // every keystroke anywhere in the record.\n const selectType = useCallback((formex: FormexController) => getIn(formex.values, typeFieldName), [typeFieldName]);\n const typeValue = useFormexSelector(selectType);\n const getFormex = useFormexGetter();\n const { t } = useTranslation();\n\n useEffect(() => {\n if (!type) {\n // Auto-fix empty blocks silently — set the default type WITHOUT\n // marking as touched so the form doesn't become dirty on mount.\n const defaultType = Object.keys(properties)[0];\n const newSelectedProperty = defaultType ? properties[defaultType] : undefined;\n setTypeInternal(defaultType);\n const formex = getFormex();\n formex.setFieldValue(typeFieldName, defaultType);\n formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);\n }\n }, []);\n\n useEffect(() => {\n if (type !== typeInternal) {\n setTypeInternal(type);\n }\n }, [type]);\n\n const propertyInternal = typeInternal ? properties[typeInternal] : undefined;\n\n const property = storedProps && typeof propertyInternal === \"object\" ? mergeDeep(propertyInternal, storedProps) : propertyInternal;\n\n const enumValuesConfigs = Object.entries(properties)\n .map(([key, property]) => ({\n id: key,\n label: property.name ?? key\n }));\n\n const fieldProps: PropertyFieldBindingProps | undefined = property\n ? {\n propertyKey: valueFieldName,\n property,\n context,\n autoFocus,\n partOfArray: false,\n partOfBlock: true,\n minimalistView: true,\n onPropertyChange: storeProps\n }\n : undefined;\n\n const updateType = (newType: string | undefined) => {\n const newSelectedProperty = newType ? properties[newType] : undefined;\n setTypeInternal(newType);\n const formex = getFormex();\n formex.setFieldTouched(typeFieldName, true);\n formex.setFieldValue(typeFieldName, newType);\n formex.setFieldValue(valueFieldName, newSelectedProperty ? getDefaultValueFor(newSelectedProperty) : null);\n };\n\n return (\n <div className={cls(paperMixin, \"bg-transparent p-2\")}>\n\n <Select\n className=\"mb-2\"\n // The placeholder is an element, so this\n // control had no name of its own either.\n aria-label={t(\"type\")}\n placeholder={<Typography variant={\"caption\"}\n className={\"px-4 py-2 font-medium\"}>{t(\"type\")}</Typography>}\n size={\"medium\"}\n fullWidth={true}\n position={\"item-aligned\"}\n value={typeValue !== undefined && typeValue !== null ? typeValue as string : \"\"}\n renderValue={(enumKey: string) =>\n <EnumValuesChip\n enumKey={enumKey}\n enumValues={enumValuesConfigs}\n size={\"small\"}/>\n }\n onValueChange={(value) => {\n updateType(value);\n }}>\n {enumValuesConfigs.map((enumConfig) => (\n <SelectItem\n key={enumConfig.id}\n value={String(enumConfig.id)}>\n <EnumValuesChip\n enumKey={enumConfig.id}\n enumValues={enumValuesConfigs}\n size={\"small\"}/>\n </SelectItem>)\n )}\n </Select>\n\n {fieldProps && (\n // It is important to use this key to force a re-render of the field on type change\n <PropertyFieldBinding key={`form_control_${name}_${typeInternal}`} {...fieldProps}/>\n )}\n\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,kBAAkB,EACI,aACA,OACA,OACA,WACA,cACA,UACA,eACA,gBAAgB,oBAChB,UACA,oBACA,2BACA,SACA,YAC0B;CAE5D,MAAM,iBAAiB,sBAAsB,SAAS,OAAO;CAC7D,MAAM,EAAE,MAAM,eAAe;CAE7B,IAAI,CAAC,SAAS,OACV,MAAM,MAAM,4DAA4D;CAE5E,MAAM,WAAW,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO;CAEjF,MAAM,CAAC,aAAa,kBAAkB,SAA6B;CAEnE,MAAM,cAAc,EACI,OACA,YACA,aACA,iBACoB;EAExC,OAAO,oBAAC,YAAD;GAEH,MAAM,GAAG,YAAY,GAAG;GACjB;GACP,OAAO,MAAM;GACb,WAAW,SAAS,MAAO,aAAa;GACxC,YAAY,SAAS,MAAO,cAAc;GAC1C,YAAY,SAAS,MAAO;GAC5B,WAAW,eAAe;GACjB;GACG;GACC;EAAa,GAVrB,gBAAgB,YAUK;CAClC;CAEA,M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AAO,cAAc,KAAA,KAAa,cAAc,OAAO,YAAsB;GAC7E,cAAc,YACV,oBAAC,gBAAD;IACa;IACT,YAAY;IACZ,MAAM;GAAS,CAAA;GAEvB,gBAAgB,UAAU;IACtB,WAAW,KAAK;GACpB;aACC,kBAAkB,KAAK,eACpB,oBAAC,YAAD;IAEI,OAAO,OAAO,WAAW,EAAE;cAC3B,oBAAC,gBAAD;KACI,SAAS,WAAW;KACpB,YAAY;KACZ,MAAM;IAAS,CAAA;GACX,GANH,WAAW,EAMR,CAChB;EACI,CAAA,GAEP,cAEG,oBAAC,sBAAD,EAAmE,GAAI,WAAY,GAAxD,gBAAgB,KAAK,GAAG,cAAgC,CAGtF;;AAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTimeFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/DateTimeFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { DateProperty } from \"@rebasepro/types\";\nimport React from \"react\";\n\n;\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { useCustomizationController } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { DateTimeField } from \"@rebasepro/ui\";\nimport { getDatePropertyMode, getDatePropertyTimezone } from \"../../preview/util\";\n\ntype DateTimeFieldProps = FieldProps<DateProperty>;\n\n/**\n * Field that allows selecting a date\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 DateTimeFieldBinding({\n propertyKey,\n value,\n setValue,\n autoFocus,\n error,\n showError,\n disabled,\n touched,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: DateTimeFieldProps) {\n\n const { locale } = useCustomizationController();\n const internalValue = value || null;\n\n return (\n <>\n {/* The form's `size`, like every other control. It was dropped\n here, so a date field drew at the kit's own default whatever\n the form asked for: while the form was `small`, 16px taller\n than the 32px text fields beside it. */}\n <DateTimeField\n size={size}\n value={internalValue}\n onChange={(dateValue) => setValue(dateValue)}\n mode={getDatePropertyMode(property)}\n timezone={getDatePropertyTimezone(property)}\n clearable={property.admin?.clearable}\n locale={locale}\n error={showError}\n disabled={disabled}\n label={hideLabel ? undefined : <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n className={showError ? \"text-red-500 dark:text-red-500\" : \"text-text-secondary dark:text-text-secondary-dark\"}\n title={property.name ?? propertyKey}/>}\n // The entity form sets `hideLabel` for every field FieldBlock\n // labels on its behalf, and FieldBlock's label is a <span> that\n // points at nothing — so without this the control is nameless.\n aria-label={hideLabel ? (property.name ?? propertyKey) : undefined}\n // 16px under the label, as the text field beside it: the 64px\n // labelled box is sized for a 24px line.\n inputClassName={!hideLabel && size === \"large\" ? \"text-base\" : undefined}\n />\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,SAAgB,qBAAqB,EACjC,aACA,OACA,UACA,WACA,OACA,WACA,UACA,SACA,UACA,oBACA,WACA,OAAO,WACY;CAEnB,MAAM,EAAE,WAAW,2BAA2B;CAG9C,OACI,qBAAA,UAAA,EAAA,UAAA,CAKI,oBAAC,eAAD;EACU;EACN,OAVU,SAAS;EAWnB,WAAW,cAAc,SAAS,SAAS;EAC3C,MAAM,oBAAoB,QAAQ;EAClC,UAAU,wBAAwB,QAAQ;EAC1C,WAAW,SAAS,OAAO;EACnB;EACR,OAAO;EACG;EACV,OAAO,YAAY,KAAA,IAAY,oBAAC,eAAD;GAC3B,MAAM,mBAAmB,UAAU,OAAO;GAC1C,UAAU,SAAS,YAAY;GAC/B,WAAW,YAAY,mCAAmC;GAC1D,OAAO,SAAS,QAAQ;EAAa,CAAA;EAIzC,cAAY,YAAa,SAAS,QAAQ,cAAe,KAAA;EAGzD,gBAAgB,CAAC,aAAa,SAAS,UAAU,cAAc,KAAA;CAClE,CAAA,GAED,oBAAC,iBAAD;EAAqC;EACtB;EACJ;EACG;EACA;CAAU,CAAA,CAE1B,EAAA,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"DateTimeFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/DateTimeFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { DateProperty } from \"@rebasepro/cms-types\";\nimport React from \"react\";\n\n;\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { useCustomizationController } from \"@rebasepro/app\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { DateTimeField } from \"@rebasepro/ui\";\nimport { getDatePropertyMode, getDatePropertyTimezone } from \"../../preview/util\";\n\ntype DateTimeFieldProps = FieldProps<DateProperty>;\n\n/**\n * Field that allows selecting a date\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 DateTimeFieldBinding({\n propertyKey,\n value,\n setValue,\n autoFocus,\n error,\n showError,\n disabled,\n touched,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: DateTimeFieldProps) {\n\n const { locale } = useCustomizationController();\n const internalValue = value || null;\n\n return (\n <>\n {/* The form's `size`, like every other control. It was dropped\n here, so a date field drew at the kit's own default whatever\n the form asked for: while the form was `small`, 16px taller\n than the 32px text fields beside it. */}\n <DateTimeField\n size={size}\n value={internalValue}\n onChange={(dateValue) => setValue(dateValue)}\n mode={getDatePropertyMode(property)}\n timezone={getDatePropertyTimezone(property)}\n clearable={property.admin?.clearable}\n locale={locale}\n error={showError}\n disabled={disabled}\n label={hideLabel ? undefined : <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n className={showError ? \"text-red-500 dark:text-red-500\" : \"text-text-secondary dark:text-text-secondary-dark\"}\n title={property.name ?? propertyKey}/>}\n // The entity form sets `hideLabel` for every field FieldBlock\n // labels on its behalf, and FieldBlock's label is a <span> that\n // points at nothing — so without this the control is nameless.\n aria-label={hideLabel ? (property.name ?? propertyKey) : undefined}\n // 16px under the label, as the text field beside it: the 64px\n // labelled box is sized for a 24px line.\n inputClassName={!hideLabel && size === \"large\" ? \"text-base\" : undefined}\n />\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,SAAgB,qBAAqB,EACjC,aACA,OACA,UACA,WACA,OACA,WACA,UACA,SACA,UACA,oBACA,WACA,OAAO,WACY;CAEnB,MAAM,EAAE,WAAW,2BAA2B;CAG9C,OACI,qBAAA,UAAA,EAAA,UAAA,CAKI,oBAAC,eAAD;EACU;EACN,OAVU,SAAS;EAWnB,WAAW,cAAc,SAAS,SAAS;EAC3C,MAAM,oBAAoB,QAAQ;EAClC,UAAU,wBAAwB,QAAQ;EAC1C,WAAW,SAAS,OAAO;EACnB;EACR,OAAO;EACG;EACV,OAAO,YAAY,KAAA,IAAY,oBAAC,eAAD;GAC3B,MAAM,mBAAmB,UAAU,OAAO;GAC1C,UAAU,SAAS,YAAY;GAC/B,WAAW,YAAY,mCAAmC;GAC1D,OAAO,SAAS,QAAQ;EAAa,CAAA;EAIzC,cAAY,YAAa,SAAS,QAAQ,cAAe,KAAA;EAGzD,gBAAgB,CAAC,aAAa,SAAS,UAAU,cAAc,KAAA;CAClE,CAAA,GAED,oBAAC,iBAAD;EAAqC;EACtB;EACJ;EACG;EACA;CAAU,CAAA,CAE1B,EAAA,CAAA;AAEV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeopointFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/GeopointFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { GeopointProperty } from \"@rebasepro/types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { IconButton, TextField, Trash2Icon } from \"@rebasepro/ui\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/** Latitude runs −90…90, longitude −180…180. Anything else is not a place. */\nconst LAT_RANGE: [number, number] = [-90, 90];\nconst LNG_RANGE: [number, number] = [-180, 180];\n\ninterface Coordinates { latitude: number; longitude: number }\n\n/**\n * Read whatever the driver handed us as a pair of coordinates.\n *\n * A geopoint arrives as a `GeoPoint` instance from the client, but as a plain\n * object once it has been through JSON — and PostGIS-backed rows may present it\n * as `{ x, y }`, where `x` is the longitude. Reading only one of those shapes\n * would render an empty field over data that is actually there.\n */\nexport function readCoordinates(value: unknown): Coordinates | null {\n if (!value || typeof value !== \"object\") return null;\n const v = value as Record<string, unknown>;\n\n const lat = typeof v.latitude === \"number\" ? v.latitude : (typeof v.y === \"number\" ? v.y : undefined);\n const lng = typeof v.longitude === \"number\" ? v.longitude : (typeof v.x === \"number\" ? v.x : undefined);\n\n if (typeof lat !== \"number\" || typeof lng !== \"number\") return null;\n return { latitude: lat, longitude: lng };\n}\n\nconst inRange = (n: number, [min, max]: [number, number]) => n >= min && n <= max;\n\n/**\n * Field binding for `type: \"geopoint\"`.\n *\n * The model has defined this type all along and the admin had no way to render\n * it: the widget lookup fell off the end of its chain, logged to the console\n * and returned undefined, so the field simply did not appear on the form. A\n * geopoint column was invisible in the admin panel, and unreachable in the\n * property editor.\n *\n * Two number inputs rather than a map. A map needs a tile provider, which means\n * a network dependency and an API key, and neither belongs in a field binding\n * that has to work offline and in every deployment. Coordinates are typed,\n * pasted and copied far more often than they are dropped on a map.\n *\n * @group Form fields\n */\nexport function GeopointFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<GeopointProperty>) {\n\n const coordinates = readCoordinates(value);\n\n // Held as text while editing: a half-typed \"-\" or \"12.\" is not a number\n // yet, and rounding it through `Number` on every keystroke fights the user.\n const [latText, setLatText] = useState(() => coordinates ? String(coordinates.latitude) : \"\");\n const [lngText, setLngText] = useState(() => coordinates ? String(coordinates.longitude) : \"\");\n\n useEffect(() => {\n const next = readCoordinates(value);\n setLatText(next ? String(next.latitude) : \"\");\n setLngText(next ? String(next.longitude) : \"\");\n }, [coordinates?.latitude, coordinates?.longitude]);\n\n const commit = useCallback((rawLat: string, rawLng: string) => {\n // Both empty means \"no location\", which is different from 0,0 — a real\n // point in the Gulf of Guinea, and the classic way a cleared field\n // turns into a wrong one.\n if (rawLat.trim() === \"\" && rawLng.trim() === \"\") {\n setValue(null);\n return;\n }\n // One side filled and the other still empty is a location half typed,\n // not a location. Committing it would send the empty side through\n // `Number(\"\")`, which is 0 and perfectly finite — so typing a latitude\n // and pausing used to write longitude 0 and drop the point in the Gulf\n // of Guinea. Hold until both sides are there; `halfEntered` below says\n // so in the meantime.\n if (rawLat.trim() === \"\" || rawLng.trim() === \"\") return;\n\n const latitude = Number(rawLat);\n const longitude = Number(rawLng);\n if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return;\n setValue({ latitude, longitude });\n }, [setValue]);\n\n const handleClear = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setLatText(\"\");\n setLngText(\"\");\n setValue(null);\n }, [setValue]);\n\n const latNumber = Number(latText);\n const lngNumber = Number(lngText);\n const latInvalid = latText.trim() !== \"\" && (!Number.isFinite(latNumber) || !inRange(latNumber, LAT_RANGE));\n const lngInvalid = lngText.trim() !== \"\" && (!Number.isFinite(lngNumber) || !inRange(lngNumber, LNG_RANGE));\n\n // One side filled and the other empty is not a point.\n const halfEntered = (latText.trim() === \"\") !== (lngText.trim() === \"\");\n\n const localError = latInvalid\n ? `Latitude must be between ${LAT_RANGE[0]} and ${LAT_RANGE[1]}`\n : lngInvalid\n ? `Longitude must be between ${LNG_RANGE[0]} and ${LNG_RANGE[1]}`\n : halfEntered\n ? \"A location needs both a latitude and a longitude\"\n : undefined;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Label only, and only when there is one: a row that survives\n `hideLabel` still spends its `mb-1` and the column's `gap-2`, so\n the pair of inputs sat below the control next to them even\n though the two labels were level. */}\n {!hideLabel && <div className=\"flex items-center justify-between mb-1\">\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n </div>}\n\n {/* Clear sits beside the inputs rather than above them, so\n entering a location does not grow the field by a row and\n knock it out of line with its neighbour. */}\n <div className=\"flex gap-4 w-full items-center\">\n <TextField\n className=\"flex-1\"\n size={size}\n label=\"Latitude\"\n value={latText}\n autoFocus={autoFocus}\n disabled={disabled}\n error={showError ? Boolean(error) || latInvalid : latInvalid}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLatText(e.target.value);\n commit(e.target.value, lngText);\n }}\n placeholder=\"e.g. 41.3874\"\n inputClassName=\"font-mono\"\n />\n <TextField\n className=\"flex-1\"\n size={size}\n label=\"Longitude\"\n value={lngText}\n disabled={disabled}\n error={showError ? Boolean(error) || lngInvalid : lngInvalid}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLngText(e.target.value);\n commit(latText, e.target.value);\n }}\n placeholder=\"e.g. 2.1686\"\n inputClassName=\"font-mono\"\n />\n {!disabled && (latText || lngText) && (\n <IconButton\n size=\"small\"\n onClick={handleClear}\n className=\"shrink-0 text-text-secondary hover:text-red-500\"\n aria-label=\"Clear location\"\n >\n <Trash2Icon size={14}/>\n </IconButton>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError || Boolean(localError)}\n error={error || localError}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAUA,IAAM,YAA8B,CAAC,KAAK,EAAE;AAC5C,IAAM,YAA8B,CAAC,MAAM,GAAG;;;;;;;;;AAY9C,SAA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N,OAAO;MACG;MACV,OAAO,YAAY,QAAQ,KAAK,KAAK,aAAa;MAClD,WAAW,MAAiE;OACxE,WAAW,EAAE,OAAO,KAAK;OACzB,OAAO,SAAS,EAAE,OAAO,KAAK;MAClC;MACA,aAAY;MACZ,gBAAe;KAClB,CAAA;KACA,CAAC,aAAa,WAAW,YACtB,oBAAC,YAAD;MACI,MAAK;MACL,SAAS;MACT,WAAU;MACV,cAAW;gBAEX,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA;KACd,CAAA;IAEf;;GAEL,oBAAC,iBAAD;IACwB;IACpB,WAAW,aAAa,QAAQ,UAAU;IAC1C,OAAO,SAAS;IACN;IACA;GACb,CAAA;EACA;;AAEb"}
|
|
1
|
+
{"version":3,"file":"GeopointFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/GeopointFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { GeopointProperty } from \"@rebasepro/cms-types\";\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport { IconButton, TextField, Trash2Icon } from \"@rebasepro/ui\";\n\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { getIconForProperty } from \"../../util/property_utils\";\n\n/** Latitude runs −90…90, longitude −180…180. Anything else is not a place. */\nconst LAT_RANGE: [number, number] = [-90, 90];\nconst LNG_RANGE: [number, number] = [-180, 180];\n\ninterface Coordinates { latitude: number; longitude: number }\n\n/**\n * Read whatever the driver handed us as a pair of coordinates.\n *\n * A geopoint arrives as a `GeoPoint` instance from the client, but as a plain\n * object once it has been through JSON — and PostGIS-backed rows may present it\n * as `{ x, y }`, where `x` is the longitude. Reading only one of those shapes\n * would render an empty field over data that is actually there.\n */\nexport function readCoordinates(value: unknown): Coordinates | null {\n if (!value || typeof value !== \"object\") return null;\n const v = value as Record<string, unknown>;\n\n const lat = typeof v.latitude === \"number\" ? v.latitude : (typeof v.y === \"number\" ? v.y : undefined);\n const lng = typeof v.longitude === \"number\" ? v.longitude : (typeof v.x === \"number\" ? v.x : undefined);\n\n if (typeof lat !== \"number\" || typeof lng !== \"number\") return null;\n return { latitude: lat, longitude: lng };\n}\n\nconst inRange = (n: number, [min, max]: [number, number]) => n >= min && n <= max;\n\n/**\n * Field binding for `type: \"geopoint\"`.\n *\n * The model has defined this type all along and the admin had no way to render\n * it: the widget lookup fell off the end of its chain, logged to the console\n * and returned undefined, so the field simply did not appear on the form. A\n * geopoint column was invisible in the admin panel, and unreachable in the\n * property editor.\n *\n * Two number inputs rather than a map. A map needs a tile provider, which means\n * a network dependency and an API key, and neither belongs in a field binding\n * that has to work offline and in every deployment. Coordinates are typed,\n * pasted and copied far more often than they are dropped on a map.\n *\n * @group Form fields\n */\nexport function GeopointFieldBinding({\n propertyKey,\n value,\n setValue,\n error,\n showError,\n disabled,\n autoFocus,\n property,\n includeDescription,\n hideLabel,\n size = \"large\"\n}: FieldProps<GeopointProperty>) {\n\n const coordinates = readCoordinates(value);\n\n // Held as text while editing: a half-typed \"-\" or \"12.\" is not a number\n // yet, and rounding it through `Number` on every keystroke fights the user.\n const [latText, setLatText] = useState(() => coordinates ? String(coordinates.latitude) : \"\");\n const [lngText, setLngText] = useState(() => coordinates ? String(coordinates.longitude) : \"\");\n\n useEffect(() => {\n const next = readCoordinates(value);\n setLatText(next ? String(next.latitude) : \"\");\n setLngText(next ? String(next.longitude) : \"\");\n }, [coordinates?.latitude, coordinates?.longitude]);\n\n const commit = useCallback((rawLat: string, rawLng: string) => {\n // Both empty means \"no location\", which is different from 0,0 — a real\n // point in the Gulf of Guinea, and the classic way a cleared field\n // turns into a wrong one.\n if (rawLat.trim() === \"\" && rawLng.trim() === \"\") {\n setValue(null);\n return;\n }\n // One side filled and the other still empty is a location half typed,\n // not a location. Committing it would send the empty side through\n // `Number(\"\")`, which is 0 and perfectly finite — so typing a latitude\n // and pausing used to write longitude 0 and drop the point in the Gulf\n // of Guinea. Hold until both sides are there; `halfEntered` below says\n // so in the meantime.\n if (rawLat.trim() === \"\" || rawLng.trim() === \"\") return;\n\n const latitude = Number(rawLat);\n const longitude = Number(rawLng);\n if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return;\n setValue({ latitude, longitude });\n }, [setValue]);\n\n const handleClear = useCallback((e: React.MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n setLatText(\"\");\n setLngText(\"\");\n setValue(null);\n }, [setValue]);\n\n const latNumber = Number(latText);\n const lngNumber = Number(lngText);\n const latInvalid = latText.trim() !== \"\" && (!Number.isFinite(latNumber) || !inRange(latNumber, LAT_RANGE));\n const lngInvalid = lngText.trim() !== \"\" && (!Number.isFinite(lngNumber) || !inRange(lngNumber, LNG_RANGE));\n\n // One side filled and the other empty is not a point.\n const halfEntered = (latText.trim() === \"\") !== (lngText.trim() === \"\");\n\n const localError = latInvalid\n ? `Latitude must be between ${LAT_RANGE[0]} and ${LAT_RANGE[1]}`\n : lngInvalid\n ? `Longitude must be between ${LNG_RANGE[0]} and ${LNG_RANGE[1]}`\n : halfEntered\n ? \"A location needs both a latitude and a longitude\"\n : undefined;\n\n return (\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Label only, and only when there is one: a row that survives\n `hideLabel` still spends its `mb-1` and the column's `gap-2`, so\n the pair of inputs sat below the control next to them even\n though the two labels were level. */}\n {!hideLabel && <div className=\"flex items-center justify-between mb-1\">\n <LabelWithIcon\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n />\n </div>}\n\n {/* Clear sits beside the inputs rather than above them, so\n entering a location does not grow the field by a row and\n knock it out of line with its neighbour. */}\n <div className=\"flex gap-4 w-full items-center\">\n <TextField\n className=\"flex-1\"\n size={size}\n label=\"Latitude\"\n value={latText}\n autoFocus={autoFocus}\n disabled={disabled}\n error={showError ? Boolean(error) || latInvalid : latInvalid}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLatText(e.target.value);\n commit(e.target.value, lngText);\n }}\n placeholder=\"e.g. 41.3874\"\n inputClassName=\"font-mono\"\n />\n <TextField\n className=\"flex-1\"\n size={size}\n label=\"Longitude\"\n value={lngText}\n disabled={disabled}\n error={showError ? Boolean(error) || lngInvalid : lngInvalid}\n onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLngText(e.target.value);\n commit(latText, e.target.value);\n }}\n placeholder=\"e.g. 2.1686\"\n inputClassName=\"font-mono\"\n />\n {!disabled && (latText || lngText) && (\n <IconButton\n size=\"small\"\n onClick={handleClear}\n className=\"shrink-0 text-text-secondary hover:text-red-500\"\n aria-label=\"Clear location\"\n >\n <Trash2Icon size={14}/>\n </IconButton>\n )}\n </div>\n\n <FieldHelperText\n includeDescription={includeDescription}\n showError={showError || Boolean(localError)}\n error={error || localError}\n disabled={disabled}\n property={property}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAUA,IAAM,YAA8B,CAAC,KAAK,EAAE;AAC5C,IAAM,YAA8B,CAAC,MAAM,GAAG;;;;;;;;;AAY9C,SAAgB,gBAAgB,OAAoC;CAChE,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAChD,MAAM,IAAI;CAEV,MAAM,MAAM,OAAO,EAAE,aAAa,WAAW,EAAE,WAAY,OAAO,EAAE,MAAM,WAAW,EAAE,IAAI,KAAA;CAC3F,MAAM,MAAM,OAAO,EAAE,cAAc,WAAW,EAAE,YAAa,OAAO,EAAE,MAAM,WAAW,EAAE,IAAI,KAAA;CAE7F,IAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAAU,OAAO;CAC/D,OAAO;EAAE,UAAU;EAAK,WAAW;CAAI;AAC3C;AAEA,IAAM,WAAW,GAAW,CAAC,KAAK,SAA2B,KAAK,OAAO,KAAK;;;;;;;;;;;;;;;;;AAkB9E,SAAgB,qBAAqB,EACjC,aACA,OACA,UACA,OACA,WACA,UACA,WACA,UACA,oBACA,WACA,OAAO,WACsB;CAE7B,MAAM,c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AEpE,MAAM,aAAa,aACb,4BAA4B,UAAU,GAAG,OAAO,UAAU,OAC1D,aACI,6BAA6B,UAAU,GAAG,OAAO,UAAU,OAC3D,cACI,qDACA,KAAA;CAEd,OACI,qBAAC,OAAD;EAAK,WAAU;YAAf;GAKK,CAAC,aAAa,oBAAC,OAAD;IAAK,WAAU;cAC1B,oBAAC,eAAD;KACI,MAAM,mBAAmB,UAAU,OAAO;KAC1C,UAAU,SAAS,YAAY;KAC/B,OAAO,SAAS,QAAQ;IAC3B,CAAA;GACA,CAAA;GAKL,qBAAC,OAAD;IAAK,WAAU;cAAf;KACI,oBAAC,WAAD;MACI,WAAU;MACJ;MACN,OAAM;MACN,OAAO;MACI;MACD;MACV,OAAO,YAAY,QAAQ,KAAK,KAAK,aAAa;MAClD,WAAW,MAAiE;OACxE,WAAW,EAAE,OAAO,KAAK;OACzB,OAAO,EAAE,OAAO,OAAO,OAAO;MAClC;MACA,aAAY;MACZ,gBAAe;KAClB,CAAA;KACD,oBAAC,WAAD;MACI,WAAU;MACJ;MACN,OAAM;MACN,OAAO;MACG;MACV,OAAO,YAAY,QAAQ,KAAK,KAAK,aAAa;MAClD,WAAW,MAAiE;OACxE,WAAW,EAAE,OAAO,KAAK;OACzB,OAAO,SAAS,EAAE,OAAO,KAAK;MAClC;MACA,aAAY;MACZ,gBAAe;KAClB,CAAA;KACA,CAAC,aAAa,WAAW,YACtB,oBAAC,YAAD;MACI,MAAK;MACL,SAAS;MACT,WAAU;MACV,cAAW;gBAEX,oBAAC,YAAD,EAAY,MAAM,GAAI,CAAA;KACd,CAAA;IAEf;;GAEL,oBAAC,iBAAD;IACwB;IACpB,WAAW,aAAa,QAAQ,UAAU;IAC1C,OAAO,SAAS;IACN;IACA;GACb,CAAA;EACA;;AAEb"}
|
|
@@ -5,10 +5,9 @@ import { ArrayContainer } from "../../components/ArrayContainer.js";
|
|
|
5
5
|
import React, { useEffect, useState } from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { BooleanSwitchWithLabel, Button, ChevronDownIcon, DateTimeField, ExpandablePanel, IconButton, Menu, MenuItem, MinusIcon, PlusIcon, TextField, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
8
|
-
import { getDefaultValueFortype } from "@rebasepro/
|
|
8
|
+
import { GeoPoint, getDefaultValueFortype } from "@rebasepro/cms-types";
|
|
9
9
|
import { useCustomizationController, useTranslation } from "@rebasepro/app";
|
|
10
10
|
import { getIn } from "@rebasepro/forms";
|
|
11
|
-
import { GeoPoint } from "@rebasepro/types";
|
|
12
11
|
//#region src/form/field_bindings/KeyValueFieldBinding.tsx
|
|
13
12
|
/**
|
|
14
13
|
* Field that allows edition of key value pairs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/KeyValueFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { MapProperty } from \"@rebasepro/types\";\nimport React, { useEffect, useState } from \"react\";\nimport { DataType, GeoPoint } from \"@rebasepro/types\";\n\nimport { ArrayContainer } from \"../../components/ArrayContainer\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport {\n BooleanSwitchWithLabel,\n Button,\n ChevronDownIcon,\n cls,\n DateTimeField,\n defaultBorderMixin,\n ExpandablePanel,\n IconButton,\n iconSize,\n Menu,\n MenuItem,\n MinusIcon,\n PlusIcon,\n TextField,\n Typography\n} from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { useCustomizationController, useTranslation } from \"@rebasepro/app\";\nimport { getIn } from \"@rebasepro/forms\";\nimport { getDefaultValueFortype } from \"@rebasepro/common\";\n\ntype MapEditViewRowState = [number, {\n key: string,\n type: DataType\n}];\n\n/**\n * Field that allows edition of key value pairs.\n *\n * @group Form fields\n */\nexport function KeyValueFieldBinding({\n propertyKey,\n value,\n showError,\n error,\n disabled,\n property,\n setValue,\n minimalistView,\n includeDescription,\n underlyingValueHasChanged,\n autoFocus,\n context\n }: FieldProps<MapProperty>) {\n\n const expanded = (property.admin?.expanded === undefined ? true : property.admin?.expanded) || autoFocus;\n\n if (!property.keyValue) {\n throw Error(`Your property ${propertyKey} needs to have the 'keyValue' prop in order to use this field binding`);\n }\n\n const initialValues = getIn(context.formex.initialValues, propertyKey) as Record<string, unknown> | undefined;\n\n const mapFormView = <MapEditView value={value}\n setValue={setValue}\n disabled={disabled}\n initialValue={initialValues}\n fieldName={property.name ?? propertyKey}/>;\n\n const title = <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"text-text-secondary dark:text-text-secondary-dark\"}/>;\n\n return (\n <>\n\n {!minimalistView && <ExpandablePanel initiallyExpanded={expanded}\n title={title}\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\"}>{mapFormView}</ExpandablePanel>}\n\n {minimalistView && mapFormView}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n\ninterface MapEditViewParams<T extends Record<string, unknown>> {\n value?: T;\n initialValue?: T;\n setValue: (value: (T | null)) => void;\n fieldName?: string,\n disabled?: boolean\n}\n\nfunction MapEditView<T extends Record<string, unknown>>({\n value,\n initialValue,\n setValue,\n fieldName,\n disabled\n }: MapEditViewParams<T>) {\n const [internalState, setInternalState] = React.useState<MapEditViewRowState[]>(\n Object.keys(initialValue ?? {}).map((key) => [getRandomId(), {\n key,\n type: gettype(initialValue?.[key]) ?? \"string\"\n }])\n );\n const { t } = useTranslation();\n\n useEffect(() => {\n const currentKeys = internalState.map(([id, { key }]) => key);\n const newKeys = Object.entries(value ?? {}).filter(([key, v]) => v !== undefined).map(([key]) => key);\n const keysToAdd = newKeys.filter((key) => !currentKeys.includes(key));\n // A row without a name yet is the form's alone: it is not in the value.\n const keysToRemove = currentKeys.filter((key) => key !== \"\" && !newKeys.includes(key));\n const newRowIds = [...internalState];\n keysToAdd.forEach((key) => {\n newRowIds.push([getRandomId(), {\n key,\n type: gettype(value?.[key]) ?? \"string\"\n }]);\n });\n keysToRemove.forEach((key) => {\n const index = newRowIds.findIndex(([id, { key: k }]) => k === key);\n newRowIds.splice(index, 1);\n });\n setInternalState(newRowIds);\n }, [value]);\n\n const updatetype = (id: number, type: DataType) => {\n if (!id) {\n console.warn(\"No key selected for data type update\");\n return;\n }\n setInternalState(internalState.map((row) => {\n if (row[0] === id) {\n return [row[0], {\n key: row[1].key,\n type\n }];\n }\n return row;\n }));\n // A row with no key yet is not in the value, and choosing its type does\n // not put it there: `{ \"\": … }` would be saved as an entry under the\n // empty key.\n const key = internalState.find((row) => row[0] === id)?.[1].key;\n if (!key) return;\n setValue({\n ...(value ?? {} as T),\n [key]: getDefaultValueFortype(type)\n })\n };\n\n return <div className=\"py-1 flex flex-col gap-1\">\n {internalState\n .map(([id, {\n key: fieldKey,\n type\n }], index) => {\n const entryValue = fieldKey ? value?.[fieldKey] : \"\";\n const onFieldKeyChange = (newKey: string) => {\n\n setInternalState(internalState.map((currentId) => {\n if (currentId[0] === id) {\n return [id, {\n key: newKey ?? \"\",\n type: currentId[1].type\n }];\n }\n return currentId;\n }));\n\n if (typeof value === \"object\" && newKey in value) {\n // if the key is already there, don't delete the previous value\n return;\n }\n\n const newValue = { ...(value ?? {}) } as T;\n if (typeof initialValue === \"object\" && fieldKey in initialValue) {\n (newValue as Record<string, unknown>)[fieldKey] = undefined; // set to undefined to remove from the object, the driver will remove it from the backend\n } else {\n delete (newValue as Record<string, unknown>)[fieldKey];\n }\n setValue({\n ...newValue,\n [newKey ?? \"\"]: entryValue\n });\n };\n return <MapKeyValueRow id={id}\n key={id}\n fieldKey={fieldKey}\n value={value ?? {} as T}\n onDeleteClick={() => {\n const newValue = { ...(value ?? {}) as T };\n if (initialValue && fieldKey in initialValue) {\n (newValue as Record<string, unknown>)[fieldKey] = undefined;\n } else {\n delete (newValue as Record<string, unknown>)[fieldKey];\n }\n setInternalState(internalState.filter((currentId) => currentId[0] !== id));\n setValue({\n ...newValue\n });\n }}\n onFieldKeyChange={onFieldKeyChange}\n setValue={setValue}\n entryValue={entryValue}\n type={type}\n disabled={disabled}\n updatetype={updatetype}/>;\n }\n )}\n\n <Button variant={\"text\"}\n size={\"small\"}\n className=\"w-full\"\n disabled={disabled}\n startIcon={<PlusIcon/>}\n onClick={(e) => {\n e.preventDefault();\n // Only a row: written into the value as `{ \"\": null }`, a\n // record saved before the key was named stored an entry\n // under the empty key.\n setInternalState([...internalState, [getRandomId(), {\n key: \"\",\n type: \"string\"\n }]]);\n }\n }>\n {fieldName ? t(\"add_to_field\", { fieldName }) : t(\"add\")}\n </Button>\n\n </div>;\n}\n\nfunction MapKeyValueRow<T extends Record<string, unknown>>({\n id,\n fieldKey,\n value,\n onFieldKeyChange,\n onDeleteClick,\n setValue,\n entryValue,\n type,\n updatetype,\n disabled\n }: {\n id: number,\n fieldKey: string,\n value: T,\n onFieldKeyChange: (newKey: string) => void,\n onDeleteClick: () => void,\n setValue: (value: (T | null)) => void,\n entryValue: unknown,\n type: DataType,\n disabled?: boolean,\n updatetype: (id: number, type: DataType) => void\n}) {\n\n const { locale } = useCustomizationController();\n const { t } = useTranslation();\n\n function buildInput(entryValue: unknown, fieldKey: string, type: DataType) {\n if (type === \"string\" || type === \"number\") {\n return <TextField\n key={type}\n aria-label={fieldKey ? `${t(\"value\")}: ${fieldKey}` : t(\"value\")}\n placeholder={\"value\"}\n value={entryValue as string | number | undefined}\n type={type === \"number\" ? \"number\" : \"text\"}\n size={\"medium\"}\n disabled={disabled || !fieldKey}\n onChange={(event) => {\n if (type === \"number\") {\n const numberValue = event.target.value ? parseFloat(event.target.value) : undefined;\n if (numberValue && isNaN(numberValue)) {\n setValue({\n ...value,\n [fieldKey]: null\n });\n } else if (numberValue !== undefined && numberValue !== null) {\n setValue({\n ...value,\n [fieldKey]: numberValue\n });\n } else {\n setValue({\n ...value,\n [fieldKey]: null\n });\n }\n } else {\n setValue({\n ...value,\n [fieldKey]: event.target.value\n });\n }\n }}/>;\n } else if (type === \"date\") {\n return <DateTimeField value={entryValue as Date | null | undefined}\n size={\"medium\"}\n locale={locale}\n disabled={disabled || !fieldKey}\n onChange={(date) => {\n setValue({\n ...value,\n [fieldKey]: date\n });\n }}/>;\n } else if (type === \"boolean\") {\n return <BooleanSwitchWithLabel value={entryValue as boolean | null}\n size={\"medium\"}\n position={\"start\"}\n disabled={disabled || !fieldKey}\n onValueChange={(newValue) => {\n setValue({\n ...value,\n [fieldKey]: newValue\n });\n }}/>;\n } else if (type === \"array\") {\n const arrayValue = (entryValue as string[]) || [];\n return <div\n className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <ArrayContainer value={arrayValue}\n newDefaultEntry={\"\"}\n droppableId={id.toString()}\n addLabel={fieldKey ? t(\"add_to_field\", { fieldName: fieldKey }) : t(\"add\")}\n size={\"small\"}\n disabled={disabled || !fieldKey}\n canAddElements={true}\n onValueChange={(newValue) => {\n setValue({\n ...value,\n [fieldKey]: newValue\n });\n }}\n buildEntry={({\n index,\n internalId\n }) => {\n return <ArrayKeyValueRow\n index={index}\n id={internalId}\n value={arrayValue[index]}\n disabled={disabled || !fieldKey}\n setValue={(newValue) => {\n const newArrayValue = [...arrayValue] as unknown[];\n newArrayValue[index] = newValue;\n setValue({\n ...value,\n [fieldKey]: newArrayValue\n });\n }}\n />\n }}/>\n </div>;\n } else if (type === \"map\") {\n return <div\n className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <MapEditView value={entryValue as Record<string, unknown> | undefined}\n fieldName={fieldKey}\n setValue={(updatedValue) => {\n setValue({\n ...value,\n [fieldKey]: updatedValue\n });\n }}/>\n </div>;\n } else {\n return <Typography\n variant={\"caption\"}>\n {`Data type ${type} not supported yet`}\n </Typography>;\n }\n }\n\n function doUpdatetype(type: DataType) {\n updatetype(id, type);\n }\n\n return (<>\n <Typography key={id.toString()}\n component={\"div\"}\n className=\"font-mono flex flex-row gap-1\">\n <div className=\"w-[300px] max-w-[30%]\">\n <TextField\n value={fieldKey}\n aria-label={t(\"key\")}\n placeholder={\"key\"}\n disabled={disabled || (entryValue !== undefined && entryValue !== null && entryValue !== \"\")}\n size={\"medium\"}\n onChange={(event) => {\n onFieldKeyChange(event.target.value);\n }}/>\n </div>\n\n <div className=\"grow\">\n {(type !== \"map\" && type !== \"array\") && buildInput(entryValue, fieldKey, type)}\n </div>\n <div className={\"flex flex-col\"}>\n <Menu\n trigger={<IconButton aria-label={t(\"change_value_type\")} size={\"smallest\"}>\n <ChevronDownIcon size={iconSize.small}/>\n </IconButton>}\n >\n <MenuItem dense\n onClick={() => doUpdatetype(\"string\")}>string</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"number\")}>number</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"boolean\")}>boolean</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"date\")}>date</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"map\")}>map</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"array\")}>array</MenuItem>\n </Menu>\n\n <IconButton aria-label=\"delete\"\n size={\"smallest\"}\n onClick={onDeleteClick}>\n <MinusIcon size={iconSize.smallest}/>\n </IconButton>\n </div>\n </Typography>\n\n {(type === \"map\" || type === \"array\") && buildInput(entryValue, fieldKey, type)}\n\n </>\n\n );\n}\n\nfunction ArrayKeyValueRow<T>({\n id,\n index,\n value,\n setValue\n }: {\n id: number,\n index: number,\n value: T,\n setValue: (value: T | null) => void,\n disabled?: boolean,\n}) {\n const { t } = useTranslation();\n\n const { locale } = useCustomizationController();\n const [selectedtype, setSelectedtype] = useState<DataType>(gettype(value) ?? \"string\");\n\n function doUpdatetype(type: DataType) {\n setSelectedtype(type);\n }\n\n function buildInput(entryValue: unknown, type: DataType) {\n if (type === \"string\" || type === \"number\") {\n return <TextField value={entryValue as string | number | undefined}\n aria-label={`Value ${index + 1}`}\n type={type === \"number\" ? \"number\" : \"text\"}\n size={\"medium\"}\n onChange={(event) => {\n if (type === \"number\") {\n const numberValue = event.target.value ? parseFloat(event.target.value) : undefined;\n if (numberValue && isNaN(numberValue)) {\n setValue(null);\n } else if (numberValue !== undefined && numberValue !== null) {\n setValue(numberValue as T);\n } else {\n setValue(null);\n }\n } else {\n setValue(event.target.value as T);\n }\n }}/>;\n } else if (type === \"date\") {\n return <DateTimeField value={entryValue as Date | null | undefined}\n size={\"medium\"}\n locale={locale}\n onChange={(date) => {\n setValue(date as T);\n }}/>;\n } else if (type === \"boolean\") {\n return <BooleanSwitchWithLabel value={entryValue as boolean | null}\n size={\"small\"}\n position={\"start\"}\n onValueChange={(v) => {\n setValue(v as T);\n }}/>;\n } else if (type === \"array\") {\n return <Typography variant={\"caption\"}>\n Arrays of arrays are not supported.\n </Typography>;\n } else if (type === \"map\") {\n const mapValue = (entryValue && typeof entryValue === \"object\") ? (entryValue as Record<string, unknown>) : undefined;\n return <div className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <MapEditView value={mapValue}\n setValue={(updatedValue) => {\n setValue(updatedValue as T | null);\n }}/>\n </div>;\n } else {\n return <Typography\n variant={\"caption\"}>\n {`Data type ${type} not supported yet`}\n </Typography>;\n }\n }\n\n return (<>\n <Typography key={id.toString()}\n component={\"div\"}\n className=\"font-mono flex min-h-12 flex-row gap-1 items-center\">\n\n <div className=\"grow\">\n {selectedtype !== \"map\" && buildInput(value, selectedtype)}\n </div>\n\n <Menu\n trigger={<IconButton aria-label={t(\"change_value_type\")} size={\"small\"}\n className=\"h-7 w-7\">\n <ChevronDownIcon/>\n </IconButton>}>\n <MenuItem dense\n onClick={() => doUpdatetype(\"string\")}>string</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"number\")}>number</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"boolean\")}>boolean</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"map\")}>map</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"date\")}>date</MenuItem>\n </Menu>\n\n </Typography>\n\n {selectedtype === \"map\" && buildInput(value, selectedtype)}\n\n </>\n\n );\n}\n\nfunction getRandomId() {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));\n}\n\nfunction gettype(value: unknown): DataType | undefined {\n if (typeof value === \"string\" || value === null) {\n return \"string\";\n } else if (typeof value === \"number\") {\n return \"number\";\n } else if (typeof value === \"boolean\") {\n return \"boolean\";\n } else if (Array.isArray(value)) {\n return \"array\";\n } else if (value instanceof Date) {\n return \"date\";\n } else if (value && typeof value === \"object\" && \"isEntityReference\" in value && typeof (value as Record<string, unknown>).isEntityReference === \"function\" && (value as Record<string, (...args: unknown[]) => unknown>).isEntityReference()) {\n return \"reference\";\n } else if (value instanceof GeoPoint) {\n return \"geopoint\";\n } else if (typeof value === \"object\") {\n return \"map\";\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,SAAgB,qBAAqB,EACI,aACA,OACA,WACA,OACA,UACA,UACA,UACA,gBACA,oBACA,2BACA,WACA,WACwB;CAE7D,MAAM,YAAY,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO,aAAa;CAE/F,IAAI,CAAC,SAAS,UACV,MAAM,MAAM,iBAAiB,YAAY,sEAAsE;CAKnH,MAAM,cAAc,oBAAC,aAAD;EAAoB;EACG;EACA;EACV,cALX,MAAM,QAAQ,OAAO,eAAe,WAKX;EACd,WAAW,SAAS,QAAQ;CAAa,CAAA;CAE1E,MAAM,QAAQ,oBAAC,eAAD;EACG;EACb,MAAM,mBAAmB,UAAU,OAAO;EAC1C,UAAU,SAAS,YAAY;EAC/B,OAAO,SAAS,QAAQ;EACxB,WAAW;CAAqD,CAAA;CAEpE,OACI,qBAAA,U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AAO,UAAU,YAAY,UAAU,MACvC,OAAO;MACJ,IAAI,OAAO,UAAU,UACxB,OAAO;MACJ,IAAI,OAAO,UAAU,WACxB,OAAO;MACJ,IAAI,MAAM,QAAQ,KAAK,GAC1B,OAAO;MACJ,IAAI,iBAAiB,MACxB,OAAO;MACJ,IAAI,SAAS,OAAO,UAAU,YAAY,uBAAuB,SAAS,OAAQ,MAAkC,sBAAsB,cAAe,MAA0D,kBAAkB,GACxO,OAAO;MACJ,IAAI,iBAAiB,UACxB,OAAO;MACJ,IAAI,OAAO,UAAU,UACxB,OAAO;AAIf"}
|
|
1
|
+
{"version":3,"file":"KeyValueFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/KeyValueFieldBinding.tsx"],"sourcesContent":["import type { FieldProps } from \"../../types/fields\";\nimport type { MapProperty } from \"@rebasepro/cms-types\";\nimport React, { useEffect, useState } from \"react\";\n\nimport { ArrayContainer } from \"../../components/ArrayContainer\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport {\n BooleanSwitchWithLabel,\n Button,\n ChevronDownIcon,\n cls,\n DateTimeField,\n defaultBorderMixin,\n ExpandablePanel,\n IconButton,\n iconSize,\n Menu,\n MenuItem,\n MinusIcon,\n PlusIcon,\n TextField,\n Typography\n} from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { useCustomizationController, useTranslation } from \"@rebasepro/app\";\nimport { getIn } from \"@rebasepro/forms\";\nimport { getDefaultValueFortype, DataType, GeoPoint } from \"@rebasepro/cms-types\";\n\ntype MapEditViewRowState = [number, {\n key: string,\n type: DataType\n}];\n\n/**\n * Field that allows edition of key value pairs.\n *\n * @group Form fields\n */\nexport function KeyValueFieldBinding({\n propertyKey,\n value,\n showError,\n error,\n disabled,\n property,\n setValue,\n minimalistView,\n includeDescription,\n underlyingValueHasChanged,\n autoFocus,\n context\n }: FieldProps<MapProperty>) {\n\n const expanded = (property.admin?.expanded === undefined ? true : property.admin?.expanded) || autoFocus;\n\n if (!property.keyValue) {\n throw Error(`Your property ${propertyKey} needs to have the 'keyValue' prop in order to use this field binding`);\n }\n\n const initialValues = getIn(context.formex.initialValues, propertyKey) as Record<string, unknown> | undefined;\n\n const mapFormView = <MapEditView value={value}\n setValue={setValue}\n disabled={disabled}\n initialValue={initialValues}\n fieldName={property.name ?? propertyKey}/>;\n\n const title = <LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"text-text-secondary dark:text-text-secondary-dark\"}/>;\n\n return (\n <>\n\n {!minimalistView && <ExpandablePanel initiallyExpanded={expanded}\n title={title}\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2\"}>{mapFormView}</ExpandablePanel>}\n\n {minimalistView && mapFormView}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError}\n error={error}\n disabled={disabled}\n property={property}/>\n\n </>\n );\n}\n\ninterface MapEditViewParams<T extends Record<string, unknown>> {\n value?: T;\n initialValue?: T;\n setValue: (value: (T | null)) => void;\n fieldName?: string,\n disabled?: boolean\n}\n\nfunction MapEditView<T extends Record<string, unknown>>({\n value,\n initialValue,\n setValue,\n fieldName,\n disabled\n }: MapEditViewParams<T>) {\n const [internalState, setInternalState] = React.useState<MapEditViewRowState[]>(\n Object.keys(initialValue ?? {}).map((key) => [getRandomId(), {\n key,\n type: gettype(initialValue?.[key]) ?? \"string\"\n }])\n );\n const { t } = useTranslation();\n\n useEffect(() => {\n const currentKeys = internalState.map(([id, { key }]) => key);\n const newKeys = Object.entries(value ?? {}).filter(([key, v]) => v !== undefined).map(([key]) => key);\n const keysToAdd = newKeys.filter((key) => !currentKeys.includes(key));\n // A row without a name yet is the form's alone: it is not in the value.\n const keysToRemove = currentKeys.filter((key) => key !== \"\" && !newKeys.includes(key));\n const newRowIds = [...internalState];\n keysToAdd.forEach((key) => {\n newRowIds.push([getRandomId(), {\n key,\n type: gettype(value?.[key]) ?? \"string\"\n }]);\n });\n keysToRemove.forEach((key) => {\n const index = newRowIds.findIndex(([id, { key: k }]) => k === key);\n newRowIds.splice(index, 1);\n });\n setInternalState(newRowIds);\n }, [value]);\n\n const updatetype = (id: number, type: DataType) => {\n if (!id) {\n console.warn(\"No key selected for data type update\");\n return;\n }\n setInternalState(internalState.map((row) => {\n if (row[0] === id) {\n return [row[0], {\n key: row[1].key,\n type\n }];\n }\n return row;\n }));\n // A row with no key yet is not in the value, and choosing its type does\n // not put it there: `{ \"\": … }` would be saved as an entry under the\n // empty key.\n const key = internalState.find((row) => row[0] === id)?.[1].key;\n if (!key) return;\n setValue({\n ...(value ?? {} as T),\n [key]: getDefaultValueFortype(type)\n })\n };\n\n return <div className=\"py-1 flex flex-col gap-1\">\n {internalState\n .map(([id, {\n key: fieldKey,\n type\n }], index) => {\n const entryValue = fieldKey ? value?.[fieldKey] : \"\";\n const onFieldKeyChange = (newKey: string) => {\n\n setInternalState(internalState.map((currentId) => {\n if (currentId[0] === id) {\n return [id, {\n key: newKey ?? \"\",\n type: currentId[1].type\n }];\n }\n return currentId;\n }));\n\n if (typeof value === \"object\" && newKey in value) {\n // if the key is already there, don't delete the previous value\n return;\n }\n\n const newValue = { ...(value ?? {}) } as T;\n if (typeof initialValue === \"object\" && fieldKey in initialValue) {\n (newValue as Record<string, unknown>)[fieldKey] = undefined; // set to undefined to remove from the object, the driver will remove it from the backend\n } else {\n delete (newValue as Record<string, unknown>)[fieldKey];\n }\n setValue({\n ...newValue,\n [newKey ?? \"\"]: entryValue\n });\n };\n return <MapKeyValueRow id={id}\n key={id}\n fieldKey={fieldKey}\n value={value ?? {} as T}\n onDeleteClick={() => {\n const newValue = { ...(value ?? {}) as T };\n if (initialValue && fieldKey in initialValue) {\n (newValue as Record<string, unknown>)[fieldKey] = undefined;\n } else {\n delete (newValue as Record<string, unknown>)[fieldKey];\n }\n setInternalState(internalState.filter((currentId) => currentId[0] !== id));\n setValue({\n ...newValue\n });\n }}\n onFieldKeyChange={onFieldKeyChange}\n setValue={setValue}\n entryValue={entryValue}\n type={type}\n disabled={disabled}\n updatetype={updatetype}/>;\n }\n )}\n\n <Button variant={\"text\"}\n size={\"small\"}\n className=\"w-full\"\n disabled={disabled}\n startIcon={<PlusIcon/>}\n onClick={(e) => {\n e.preventDefault();\n // Only a row: written into the value as `{ \"\": null }`, a\n // record saved before the key was named stored an entry\n // under the empty key.\n setInternalState([...internalState, [getRandomId(), {\n key: \"\",\n type: \"string\"\n }]]);\n }\n }>\n {fieldName ? t(\"add_to_field\", { fieldName }) : t(\"add\")}\n </Button>\n\n </div>;\n}\n\nfunction MapKeyValueRow<T extends Record<string, unknown>>({\n id,\n fieldKey,\n value,\n onFieldKeyChange,\n onDeleteClick,\n setValue,\n entryValue,\n type,\n updatetype,\n disabled\n }: {\n id: number,\n fieldKey: string,\n value: T,\n onFieldKeyChange: (newKey: string) => void,\n onDeleteClick: () => void,\n setValue: (value: (T | null)) => void,\n entryValue: unknown,\n type: DataType,\n disabled?: boolean,\n updatetype: (id: number, type: DataType) => void\n}) {\n\n const { locale } = useCustomizationController();\n const { t } = useTranslation();\n\n function buildInput(entryValue: unknown, fieldKey: string, type: DataType) {\n if (type === \"string\" || type === \"number\") {\n return <TextField\n key={type}\n aria-label={fieldKey ? `${t(\"value\")}: ${fieldKey}` : t(\"value\")}\n placeholder={\"value\"}\n value={entryValue as string | number | undefined}\n type={type === \"number\" ? \"number\" : \"text\"}\n size={\"medium\"}\n disabled={disabled || !fieldKey}\n onChange={(event) => {\n if (type === \"number\") {\n const numberValue = event.target.value ? parseFloat(event.target.value) : undefined;\n if (numberValue && isNaN(numberValue)) {\n setValue({\n ...value,\n [fieldKey]: null\n });\n } else if (numberValue !== undefined && numberValue !== null) {\n setValue({\n ...value,\n [fieldKey]: numberValue\n });\n } else {\n setValue({\n ...value,\n [fieldKey]: null\n });\n }\n } else {\n setValue({\n ...value,\n [fieldKey]: event.target.value\n });\n }\n }}/>;\n } else if (type === \"date\") {\n return <DateTimeField value={entryValue as Date | null | undefined}\n size={\"medium\"}\n locale={locale}\n disabled={disabled || !fieldKey}\n onChange={(date) => {\n setValue({\n ...value,\n [fieldKey]: date\n });\n }}/>;\n } else if (type === \"boolean\") {\n return <BooleanSwitchWithLabel value={entryValue as boolean | null}\n size={\"medium\"}\n position={\"start\"}\n disabled={disabled || !fieldKey}\n onValueChange={(newValue) => {\n setValue({\n ...value,\n [fieldKey]: newValue\n });\n }}/>;\n } else if (type === \"array\") {\n const arrayValue = (entryValue as string[]) || [];\n return <div\n className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <ArrayContainer value={arrayValue}\n newDefaultEntry={\"\"}\n droppableId={id.toString()}\n addLabel={fieldKey ? t(\"add_to_field\", { fieldName: fieldKey }) : t(\"add\")}\n size={\"small\"}\n disabled={disabled || !fieldKey}\n canAddElements={true}\n onValueChange={(newValue) => {\n setValue({\n ...value,\n [fieldKey]: newValue\n });\n }}\n buildEntry={({\n index,\n internalId\n }) => {\n return <ArrayKeyValueRow\n index={index}\n id={internalId}\n value={arrayValue[index]}\n disabled={disabled || !fieldKey}\n setValue={(newValue) => {\n const newArrayValue = [...arrayValue] as unknown[];\n newArrayValue[index] = newValue;\n setValue({\n ...value,\n [fieldKey]: newArrayValue\n });\n }}\n />\n }}/>\n </div>;\n } else if (type === \"map\") {\n return <div\n className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <MapEditView value={entryValue as Record<string, unknown> | undefined}\n fieldName={fieldKey}\n setValue={(updatedValue) => {\n setValue({\n ...value,\n [fieldKey]: updatedValue\n });\n }}/>\n </div>;\n } else {\n return <Typography\n variant={\"caption\"}>\n {`Data type ${type} not supported yet`}\n </Typography>;\n }\n }\n\n function doUpdatetype(type: DataType) {\n updatetype(id, type);\n }\n\n return (<>\n <Typography key={id.toString()}\n component={\"div\"}\n className=\"font-mono flex flex-row gap-1\">\n <div className=\"w-[300px] max-w-[30%]\">\n <TextField\n value={fieldKey}\n aria-label={t(\"key\")}\n placeholder={\"key\"}\n disabled={disabled || (entryValue !== undefined && entryValue !== null && entryValue !== \"\")}\n size={\"medium\"}\n onChange={(event) => {\n onFieldKeyChange(event.target.value);\n }}/>\n </div>\n\n <div className=\"grow\">\n {(type !== \"map\" && type !== \"array\") && buildInput(entryValue, fieldKey, type)}\n </div>\n <div className={\"flex flex-col\"}>\n <Menu\n trigger={<IconButton aria-label={t(\"change_value_type\")} size={\"smallest\"}>\n <ChevronDownIcon size={iconSize.small}/>\n </IconButton>}\n >\n <MenuItem dense\n onClick={() => doUpdatetype(\"string\")}>string</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"number\")}>number</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"boolean\")}>boolean</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"date\")}>date</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"map\")}>map</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"array\")}>array</MenuItem>\n </Menu>\n\n <IconButton aria-label=\"delete\"\n size={\"smallest\"}\n onClick={onDeleteClick}>\n <MinusIcon size={iconSize.smallest}/>\n </IconButton>\n </div>\n </Typography>\n\n {(type === \"map\" || type === \"array\") && buildInput(entryValue, fieldKey, type)}\n\n </>\n\n );\n}\n\nfunction ArrayKeyValueRow<T>({\n id,\n index,\n value,\n setValue\n }: {\n id: number,\n index: number,\n value: T,\n setValue: (value: T | null) => void,\n disabled?: boolean,\n}) {\n const { t } = useTranslation();\n\n const { locale } = useCustomizationController();\n const [selectedtype, setSelectedtype] = useState<DataType>(gettype(value) ?? \"string\");\n\n function doUpdatetype(type: DataType) {\n setSelectedtype(type);\n }\n\n function buildInput(entryValue: unknown, type: DataType) {\n if (type === \"string\" || type === \"number\") {\n return <TextField value={entryValue as string | number | undefined}\n aria-label={`Value ${index + 1}`}\n type={type === \"number\" ? \"number\" : \"text\"}\n size={\"medium\"}\n onChange={(event) => {\n if (type === \"number\") {\n const numberValue = event.target.value ? parseFloat(event.target.value) : undefined;\n if (numberValue && isNaN(numberValue)) {\n setValue(null);\n } else if (numberValue !== undefined && numberValue !== null) {\n setValue(numberValue as T);\n } else {\n setValue(null);\n }\n } else {\n setValue(event.target.value as T);\n }\n }}/>;\n } else if (type === \"date\") {\n return <DateTimeField value={entryValue as Date | null | undefined}\n size={\"medium\"}\n locale={locale}\n onChange={(date) => {\n setValue(date as T);\n }}/>;\n } else if (type === \"boolean\") {\n return <BooleanSwitchWithLabel value={entryValue as boolean | null}\n size={\"small\"}\n position={\"start\"}\n onValueChange={(v) => {\n setValue(v as T);\n }}/>;\n } else if (type === \"array\") {\n return <Typography variant={\"caption\"}>\n Arrays of arrays are not supported.\n </Typography>;\n } else if (type === \"map\") {\n const mapValue = (entryValue && typeof entryValue === \"object\") ? (entryValue as Record<string, unknown>) : undefined;\n return <div className={cls(defaultBorderMixin, \"ml-2 pl-2 border-l border-solid\")}>\n <MapEditView value={mapValue}\n setValue={(updatedValue) => {\n setValue(updatedValue as T | null);\n }}/>\n </div>;\n } else {\n return <Typography\n variant={\"caption\"}>\n {`Data type ${type} not supported yet`}\n </Typography>;\n }\n }\n\n return (<>\n <Typography key={id.toString()}\n component={\"div\"}\n className=\"font-mono flex min-h-12 flex-row gap-1 items-center\">\n\n <div className=\"grow\">\n {selectedtype !== \"map\" && buildInput(value, selectedtype)}\n </div>\n\n <Menu\n trigger={<IconButton aria-label={t(\"change_value_type\")} size={\"small\"}\n className=\"h-7 w-7\">\n <ChevronDownIcon/>\n </IconButton>}>\n <MenuItem dense\n onClick={() => doUpdatetype(\"string\")}>string</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"number\")}>number</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"boolean\")}>boolean</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"map\")}>map</MenuItem>\n <MenuItem dense\n onClick={() => doUpdatetype(\"date\")}>date</MenuItem>\n </Menu>\n\n </Typography>\n\n {selectedtype === \"map\" && buildInput(value, selectedtype)}\n\n </>\n\n );\n}\n\nfunction getRandomId() {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));\n}\n\nfunction gettype(value: unknown): DataType | undefined {\n if (typeof value === \"string\" || value === null) {\n return \"string\";\n } else if (typeof value === \"number\") {\n return \"number\";\n } else if (typeof value === \"boolean\") {\n return \"boolean\";\n } else if (Array.isArray(value)) {\n return \"array\";\n } else if (value instanceof Date) {\n return \"date\";\n } else if (value && typeof value === \"object\" && \"isEntityReference\" in value && typeof (value as Record<string, unknown>).isEntityReference === \"function\" && (value as Record<string, (...args: unknown[]) => unknown>).isEntityReference()) {\n return \"reference\";\n } else if (value instanceof GeoPoint) {\n return \"geopoint\";\n } else if (typeof value === \"object\") {\n return \"map\";\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,SAAgB,qBAAqB,EACI,aACA,OACA,WACA,OACA,UACA,UACA,UACA,gBACA,oBACA,2BACA,WACA,WACwB;CAE7D,MAAM,YAAY,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO,aAAa;CAE/F,IAAI,CAAC,SAAS,UACV,MAAM,MAAM,iBAAiB,YAAY,sEAAsE;CAKnH,MAAM,cAAc,oBAAC,aAAD;EAAoB;EACG;EACA;EACV,cALX,MAAM,QAAQ,OAAO,eAAe,WAKX;EACd,WAAW,SAAS,QAAQ;CAAa,CAAA;CAE1E,MAAM,QAAQ,oBAAC,eAAD;EACG;EACb,MAAM,mBAAmB,UAAU,OAAO;EAC1C,UAAU,SAAS,YAAY;EAC/B,OAAO,SAAS,QAAQ;EACxB,WAAW;CAAqD,CAAA;CAEpE,OACI,qBAAA,UAAA,EAAA,UAAA;EAEK,CAAC,kBAAkB,oBAAC,iBAAD;GAAiB,mBAAmB;GACZ;GACP,gBAAgB;aAA2C;EAA6B,CAAA;EAE5H,kBAAkB;EAEnB,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,KAAK,GAC1B,OAAO;MACJ,IAAI,iBAAiB,MACxB,OAAO;MACJ,IAAI,SAAS,OAAO,UAAU,YAAY,uBAAuB,SAAS,OAAQ,MAAkC,sBAAsB,cAAe,MAA0D,kBAAkB,GACxO,OAAO;MACJ,IAAI,iBAAiB,UACxB,OAAO;MACJ,IAAI,OAAO,UAAU,UACxB,OAAO;AAIf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/MapFieldBinding.tsx"],"sourcesContent":["import type { FieldProps, PropertyFieldBindingProps } from \"../../types/fields\";\nimport type { MapProperty } from \"@rebasepro/types\";\nimport React from \"react\";\n;\nimport { useTranslation } from \"@rebasepro/app\";\n\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { cls, ExpandablePanel } from \"@rebasepro/ui\";\n\n/**\n * Field that renders the children property fields\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 MapFieldBinding({\n propertyKey,\n value,\n showError,\n error,\n disabled,\n property,\n partOfArray,\n minimalistView: minimalistViewProp,\n includeDescription,\n autoFocus,\n context,\n onPropertyChange\n}: FieldProps<MapProperty>) {\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n const { t } = useTranslation();\n\n if (!property.properties) {\n throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property '${propertyKey}'${property.name ? ` (\"${property.name}\")` : \"\"}`);\n }\n\n const mapProperties = property.properties;\n\n const mapFormView = <>\n <div\n className={\"py-1 flex flex-col space-y-2\"}>\n {Object.entries(mapProperties)\n .filter(([_, property]) => !isHidden(property))\n .map(([entryKey, childProperty], index) => {\n const thisDisabled = isReadOnly(childProperty) || isDisabled(childProperty);\n const fieldBindingProps: PropertyFieldBindingProps<Record<string, unknown>> = {\n propertyKey: `${propertyKey}.${entryKey}`,\n disabled: disabled || thisDisabled,\n property: childProperty,\n includeDescription,\n context,\n partOfArray: false,\n minimalistView: false,\n autoFocus: autoFocus && index === 0,\n onPropertyChange: function (updatedProperty) {\n onPropertyChange?.({\n properties: {\n [entryKey]: updatedProperty\n }\n } as Partial<MapProperty>);\n }\n };\n\n return (\n <div key={`map-${propertyKey}-${index}`} className={\"relative\"}>\n <ErrorBoundary>\n <PropertyFieldBinding\n {...fieldBindingProps}/>\n </ErrorBoundary>\n </div>\n );\n }\n )\n }\n </div>\n\n\n </>\n ;\n\n return (\n <ErrorBoundary>\n\n {!minimalistView && <ExpandablePanel initiallyExpanded={expanded}\n onExpandedChange={(expanded: boolean) => {\n onPropertyChange?.({\n admin: { ...property.admin,\nexpanded }\n });\n }}\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2 bg-surface-card\"}\n title={<LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"text-text-secondary dark:text-text-secondary-dark\"}/>}>\n {mapFormView}\n </ExpandablePanel>}\n\n {minimalistView && mapFormView}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError ?? false}\n error={error && !partOfArray ? error : undefined}\n disabled={disabled}\n property={property}/>\n\n </ErrorBoundary>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,SAAgB,gBAAgB,EAC5B,aACA,OACA,WACA,OACA,UACA,UACA,aACA,gBAAgB,oBAChB,oBACA,WACA,SACA,oBACwB;CAExB,MAAM,WAAW,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO;CACjF,MAAM,iBAAiB,sBAAsB,SAAS,OAAO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S,CAAC,cAAc,QAAQ,KAAA;GAC7B;GACA;EAAU,CAAA;CAEb,EAAA,CAAA;AAEvB"}
|
|
1
|
+
{"version":3,"file":"MapFieldBinding.js","names":[],"sources":["../../../src/form/field_bindings/MapFieldBinding.tsx"],"sourcesContent":["import type { FieldProps, PropertyFieldBindingProps } from \"../../types/fields\";\nimport type { MapProperty } from \"@rebasepro/cms-types\";\nimport React from \"react\";\n;\nimport { useTranslation } from \"@rebasepro/app\";\n\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { getIconForProperty } from \"../../util/property_utils\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\nimport { FieldHelperText } from \"../components/FieldHelperText\";\nimport { LabelWithIcon } from \"../components/LabelWithIcon\";\nimport { PropertyFieldBinding } from \"../PropertyFieldBinding\";\nimport { cls, ExpandablePanel } from \"@rebasepro/ui\";\n\n/**\n * Field that renders the children property fields\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 MapFieldBinding({\n propertyKey,\n value,\n showError,\n error,\n disabled,\n property,\n partOfArray,\n minimalistView: minimalistViewProp,\n includeDescription,\n autoFocus,\n context,\n onPropertyChange\n}: FieldProps<MapProperty>) {\n\n const expanded = property.admin?.expanded === undefined ? true : property.admin?.expanded;\n const minimalistView = minimalistViewProp || property.admin?.minimalistView;\n const { t } = useTranslation();\n\n if (!property.properties) {\n throw Error(`You need to specify a 'properties' prop (or specify a custom field) in your map property '${propertyKey}'${property.name ? ` (\"${property.name}\")` : \"\"}`);\n }\n\n const mapProperties = property.properties;\n\n const mapFormView = <>\n <div\n className={\"py-1 flex flex-col space-y-2\"}>\n {Object.entries(mapProperties)\n .filter(([_, property]) => !isHidden(property))\n .map(([entryKey, childProperty], index) => {\n const thisDisabled = isReadOnly(childProperty) || isDisabled(childProperty);\n const fieldBindingProps: PropertyFieldBindingProps<Record<string, unknown>> = {\n propertyKey: `${propertyKey}.${entryKey}`,\n disabled: disabled || thisDisabled,\n property: childProperty,\n includeDescription,\n context,\n partOfArray: false,\n minimalistView: false,\n autoFocus: autoFocus && index === 0,\n onPropertyChange: function (updatedProperty) {\n onPropertyChange?.({\n properties: {\n [entryKey]: updatedProperty\n }\n } as Partial<MapProperty>);\n }\n };\n\n return (\n <div key={`map-${propertyKey}-${index}`} className={\"relative\"}>\n <ErrorBoundary>\n <PropertyFieldBinding\n {...fieldBindingProps}/>\n </ErrorBoundary>\n </div>\n );\n }\n )\n }\n </div>\n\n\n </>\n ;\n\n return (\n <ErrorBoundary>\n\n {!minimalistView && <ExpandablePanel initiallyExpanded={expanded}\n onExpandedChange={(expanded: boolean) => {\n onPropertyChange?.({\n admin: { ...property.admin,\nexpanded }\n });\n }}\n innerClassName={\"px-2 md:px-4 pb-2 md:pb-4 pt-1 md:pt-2 bg-surface-card\"}\n title={<LabelWithIcon\n propertyKey={propertyKey}\n icon={getIconForProperty(property, \"small\")}\n required={property.validation?.required}\n title={property.name ?? propertyKey}\n className={\"text-text-secondary dark:text-text-secondary-dark\"}/>}>\n {mapFormView}\n </ExpandablePanel>}\n\n {minimalistView && mapFormView}\n\n <FieldHelperText includeDescription={includeDescription}\n showError={showError ?? false}\n error={error && !partOfArray ? error : undefined}\n disabled={disabled}\n property={property}/>\n\n </ErrorBoundary>\n );\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,SAAgB,gBAAgB,EAC5B,aACA,OACA,WACA,OACA,UACA,UACA,aACA,gBAAgB,oBAChB,oBACA,WACA,SACA,oBACwB;CAExB,MAAM,WAAW,SAAS,OAAO,aAAa,KAAA,IAAY,OAAO,SAAS,OAAO;CACjF,MAAM,iBAAiB,sBAAsB,SAAS,OAAO;CAC7D,MAAM,EAAE,MAAM,eAAe;CAE7B,IAAI,CAAC,SAAS,YACV,MAAM,MAAM,6FAA6F,YAAY,GAAG,SAAS,OAAO,MAAM,SAAS,KAAK,MAAM,IAAI;CAG1K,MAAM,gBAAgB,SAAS;CAE/B,MAAM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type { StringProperty } from "@rebasepro/types";
|
|
3
|
+
import type { StringProperty } from "@rebasepro/cms-types";
|
|
4
4
|
import type { RichTextEditorProps } from "../../editor/index.js";
|
|
5
5
|
interface MarkdownEditorFieldProps {
|
|
6
6
|
highlight?: {
|
|
@@ -6,7 +6,7 @@ import { LabelWithIcon } from "../components/LabelWithIcon.js";
|
|
|
6
6
|
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { IconButton, Skeleton, XIcon, cls, fieldBackgroundDisabledMixin, fieldBackgroundHoverMixin, fieldBackgroundMixin, lazyChunk } from "@rebasepro/ui";
|
|
9
|
-
import { resolveStorageFilenameString, resolveStoragePathString, resolveStorageSource } from "@rebasepro/
|
|
9
|
+
import { resolveStorageFilenameString, resolveStoragePathString, resolveStorageSource } from "@rebasepro/cms-types";
|
|
10
10
|
import { useAuthController, useStorageSource, useStorageSources, useTranslation } from "@rebasepro/app";
|
|
11
11
|
import { resourceKeyOf, storageReference } from "@rebasepro/types";
|
|
12
12
|
import { randomString } from "@rebasepro/utils";
|