@rebasepro/cms 0.23.0 → 0.24.1-canary.g19596ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/collection_editor/CollectionEditorDialogsContext.js +10 -0
- package/dist/collection_editor/CollectionEditorDialogsContext.js.map +1 -0
- package/dist/collection_editor/ConfigControllerProvider.js +274 -0
- package/dist/collection_editor/ConfigControllerProvider.js.map +1 -0
- package/dist/collection_editor/_cms_internals.d.ts +2 -1
- package/dist/collection_editor/api/generateCollectionApi.js +64 -0
- package/dist/collection_editor/api/generateCollectionApi.js.map +1 -0
- package/dist/collection_editor/collection_wire.d.ts +13 -0
- package/dist/collection_editor/collection_wire.js +49 -0
- package/dist/collection_editor/collection_wire.js.map +1 -0
- package/dist/collection_editor/liveSchemaClient.d.ts +38 -18
- package/dist/collection_editor/liveSchemaClient.js +130 -0
- package/dist/collection_editor/liveSchemaClient.js.map +1 -0
- package/dist/collection_editor/relation_kinds.js +74 -0
- package/dist/collection_editor/relation_kinds.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +6 -1
- package/dist/collection_editor/serializable_utils.js +504 -0
- package/dist/collection_editor/serializable_utils.js.map +1 -0
- package/dist/collection_editor/types/config_controller.d.ts +11 -0
- package/dist/collection_editor/ui/EditorCollectionAction.js +37 -0
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -0
- package/dist/collection_editor/ui/MissingReferenceWidget.js +39 -0
- package/dist/collection_editor/ui/MissingReferenceWidget.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js +160 -0
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/AIModifiedPathsContext.js +61 -0
- package/dist/collection_editor/ui/collection_editor/AIModifiedPathsContext.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +731 -0
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.js +220 -0
- package/dist/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionJsonImportDialog.js +160 -0
- package/dist/collection_editor/ui/collection_editor/CollectionJsonImportDialog.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +394 -0
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +616 -0
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionStudioView.js +68 -0
- package/dist/collection_editor/ui/collection_editor/CollectionStudioView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionYupValidation.js +11 -0
- package/dist/collection_editor/ui/collection_editor/CollectionYupValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/CollectionsStudioView.js +148 -0
- package/dist/collection_editor/ui/collection_editor/CollectionsStudioView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js +244 -0
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/EnumForm.js +222 -0
- package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +204 -0
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/GetCodeDialog.js +108 -0
- package/dist/collection_editor/ui/collection_editor/GetCodeDialog.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js +163 -0
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/LayoutModeSwitch.js +59 -0
- package/dist/collection_editor/ui/collection_editor/LayoutModeSwitch.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +640 -0
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +141 -0
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js +210 -0
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/RouterCollectionStudioView.js +31 -0
- package/dist/collection_editor/ui/collection_editor/RouterCollectionStudioView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/RouterCollectionsStudioView.js +25 -0
- package/dist/collection_editor/ui/collection_editor/RouterCollectionsStudioView.js.map +1 -0
- package/dist/{SchemaChangeDialog-BeP0A4MJ.js → collection_editor/ui/collection_editor/SchemaChangeDialog.js} +73 -69
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/SwitchControl.js +24 -0
- package/dist/collection_editor/ui/collection_editor/SwitchControl.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/ViewModeSwitch.js +66 -0
- package/dist/collection_editor/ui/collection_editor/ViewModeSwitch.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +61 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js +188 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +12 -0
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js +74 -0
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js +100 -0
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/BooleanPropertyField.js +34 -0
- package/dist/collection_editor/ui/collection_editor/properties/BooleanPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/CommonPropertyFields.js +75 -0
- package/dist/collection_editor/ui/collection_editor/properties/CommonPropertyFields.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js +338 -0
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +83 -0
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/KeyValuePropertyField.js +15 -0
- package/dist/collection_editor/ui/collection_editor/properties/KeyValuePropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js +121 -0
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +127 -0
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js +151 -0
- package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js +77 -0
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js +254 -0
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js +71 -0
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +356 -0
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js +173 -0
- package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/UrlPropertyField.js +79 -0
- package/dist/collection_editor/ui/collection_editor/properties/UrlPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/VectorPropertyField.js +34 -0
- package/dist/collection_editor/ui/collection_editor/properties/VectorPropertyField.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.js +47 -0
- package/dist/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/ArrayPropertyValidation.js +47 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/ArrayPropertyValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/GeneralPropertyValidation.js +62 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/GeneralPropertyValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/NumberPropertyValidation.js +119 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/NumberPropertyValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.d.ts +10 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.js +178 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/ValidationPanel.js +23 -0
- package/dist/collection_editor/ui/collection_editor/properties/validation/ValidationPanel.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/templates/blog_template.js +116 -0
- package/dist/collection_editor/ui/collection_editor/templates/blog_template.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/templates/pages_template.js +182 -0
- package/dist/collection_editor/ui/collection_editor/templates/pages_template.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/templates/products_template.js +87 -0
- package/dist/collection_editor/ui/collection_editor/templates/products_template.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/templates/users_template.js +46 -0
- package/dist/collection_editor/ui/collection_editor/templates/users_template.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/util.js +20 -0
- package/dist/collection_editor/ui/collection_editor/util.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/strings.js +2 -0
- package/dist/collection_editor/ui/collection_editor/utils/supported_fields.js +37 -0
- package/dist/collection_editor/ui/collection_editor/utils/supported_fields.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js +192 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -0
- package/dist/collection_editor/useCollectionEditorController.js +12 -0
- package/dist/collection_editor/useCollectionEditorController.js.map +1 -0
- package/dist/collection_editor/useCollectionsConfigController.js +12 -0
- package/dist/collection_editor/useCollectionsConfigController.js.map +1 -0
- package/dist/collection_editor/useJsonCollectionsConfigController.js +191 -0
- package/dist/collection_editor/useJsonCollectionsConfigController.js.map +1 -0
- package/dist/collection_editor/useLiveSchemaEditing.d.ts +5 -5
- package/dist/collection_editor/useLiveSchemaEditing.js +214 -0
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -0
- package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +7 -0
- package/dist/collection_editor/useLocalCollectionsConfigController.js +228 -0
- package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -0
- package/dist/collection_editor/useSafeSnackbarController.js +13 -0
- package/dist/collection_editor/useSafeSnackbarController.js.map +1 -0
- package/dist/collection_editor/validateCollectionJson.js +289 -0
- package/dist/collection_editor/validateCollectionJson.js.map +1 -0
- package/dist/collection_editor_ui.js +7 -33
- package/dist/components/AdditionalFieldValue.js +60 -0
- package/dist/components/AdditionalFieldValue.js.map +1 -0
- package/dist/components/AdminModeSyncer.js +41 -0
- package/dist/components/AdminModeSyncer.js.map +1 -0
- package/dist/components/ArrayContainer.d.ts +8 -2
- package/dist/components/ArrayContainer.js +363 -0
- package/dist/components/ArrayContainer.js.map +1 -0
- package/dist/components/ClearFilterSortButton.d.ts +7 -1
- package/dist/components/ClearFilterSortButton.js +33 -0
- package/dist/components/ClearFilterSortButton.js.map +1 -0
- package/dist/components/CollectionEditorDialogs.js +49 -0
- package/dist/components/CollectionEditorDialogs.js.map +1 -0
- package/dist/components/CollectionPanel.d.ts +26 -5
- package/dist/components/CollectionPanel.js +142 -0
- package/dist/components/CollectionPanel.js.map +1 -0
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +165 -0
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -0
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +329 -0
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -0
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +311 -0
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -0
- package/dist/components/CollectionTableBinding/column_utils.js +85 -0
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/CompactEntityCellField.js +45 -0
- package/dist/components/CollectionTableBinding/fields/CompactEntityCellField.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +66 -0
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +86 -0
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +93 -0
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js +33 -0
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js +171 -0
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +91 -0
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -0
- package/dist/components/CollectionTableBinding/fields/VirtualTableUserSelect.js +36 -0
- package/dist/components/CollectionTableBinding/fields/VirtualTableUserSelect.js.map +1 -0
- package/dist/components/CollectionTableBinding/index.js +6 -0
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +50 -0
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.d.ts +2 -0
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.js +223 -0
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/EntityTableCellActions.js +58 -0
- package/dist/components/CollectionTableBinding/internal/EntityTableCellActions.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/TableCellOpener.js +53 -0
- package/dist/components/CollectionTableBinding/internal/TableCellOpener.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/common.js +40 -0
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +270 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/useDraggable.js +68 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/useDraggable.js.map +1 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/useWindowSize.js +24 -0
- package/dist/components/CollectionTableBinding/internal/popup_field/useWindowSize.js.map +1 -0
- package/dist/components/CollectionTableBinding/table_bindings.js +306 -0
- package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -0
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +160 -0
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +471 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +108 -0
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +988 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +6 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +5 -2
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +1209 -0
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +133 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +133 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -0
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js +203 -0
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +5 -0
- package/dist/components/CollectionViewBinding/FiltersDialog.js +148 -0
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -0
- package/dist/components/CollectionViewBinding/SearchExplanation.js +86 -0
- package/dist/components/CollectionViewBinding/SearchExplanation.js.map +1 -0
- package/dist/components/CollectionViewBinding/SearchHighlight.js +262 -0
- package/dist/components/CollectionViewBinding/SearchHighlight.js.map +1 -0
- package/dist/components/CollectionViewBinding/SlotValue.js +117 -0
- package/dist/components/CollectionViewBinding/SlotValue.js.map +1 -0
- package/dist/components/CollectionViewBinding/SortButton.js +214 -0
- package/dist/components/CollectionViewBinding/SortButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListCloseButton.js +41 -0
- package/dist/components/CollectionViewBinding/SplitListCloseButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListShowButton.js +29 -0
- package/dist/components/CollectionViewBinding/SplitListShowButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.js +311 -0
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitViewContext.js +21 -0
- package/dist/components/CollectionViewBinding/SplitViewContext.js.map +1 -0
- package/dist/components/CollectionViewBinding/ViewModeToggle.js +150 -0
- package/dist/components/CollectionViewBinding/ViewModeToggle.js.map +1 -0
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +49 -0
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -0
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js +122 -0
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +530 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +4 -1
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +384 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/useSelectionController.js +104 -0
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -0
- package/dist/components/CollectionViewBinding/utils.js +21 -0
- package/dist/components/CollectionViewBinding/utils.js.map +1 -0
- package/dist/components/CollectionsProvider.d.ts +44 -0
- package/dist/components/CollectionsProvider.js +137 -0
- package/dist/components/CollectionsProvider.js.map +1 -0
- package/dist/components/CollectionsScopeContext.d.ts +18 -0
- package/dist/components/CollectionsScopeContext.js +25 -0
- package/dist/components/CollectionsScopeContext.js.map +1 -0
- package/dist/components/DefaultAppBar.js +179 -0
- package/dist/components/DefaultAppBar.js.map +1 -0
- package/dist/components/DefaultDrawer.js +364 -0
- package/dist/components/DefaultDrawer.js.map +1 -0
- package/dist/components/DeleteEntityDialog.js +256 -0
- package/dist/components/DeleteEntityDialog.js.map +1 -0
- package/dist/components/DetailViewBinding.js +504 -0
- package/dist/components/DetailViewBinding.js.map +1 -0
- package/dist/components/DrawerNavigationGroup.js +74 -0
- package/dist/components/DrawerNavigationGroup.js.map +1 -0
- package/dist/components/DrawerNavigationItem.d.ts +8 -0
- package/dist/components/DrawerNavigationItem.js +45 -0
- package/dist/components/DrawerNavigationItem.js.map +1 -0
- package/dist/components/EditFormActions.js +210 -0
- package/dist/components/EditFormActions.js.map +1 -0
- package/dist/components/EditViewBinding.d.ts +7 -1
- package/dist/components/EditViewBinding.js +802 -0
- package/dist/components/EditViewBinding.js.map +1 -0
- package/dist/components/EntityDisplayHeader.js +139 -0
- package/dist/components/EntityDisplayHeader.js.map +1 -0
- package/dist/components/EntityFormPanel.d.ts +58 -0
- package/dist/components/EntityFormPanel.js +126 -0
- package/dist/components/EntityFormPanel.js.map +1 -0
- package/dist/components/EntityIdentityBar.d.ts +29 -4
- package/dist/components/EntityIdentityBar.js +364 -0
- package/dist/components/EntityIdentityBar.js.map +1 -0
- package/dist/components/EntityInspector.js +96 -0
- package/dist/components/EntityInspector.js.map +1 -0
- package/dist/components/EntityPreviewBinding.js +282 -0
- package/dist/components/EntityPreviewBinding.js.map +1 -0
- package/dist/components/EntityPreviewNesting.js +53 -0
- package/dist/components/EntityPreviewNesting.js.map +1 -0
- package/dist/components/EntityViewBinding.js +246 -0
- package/dist/components/EntityViewBinding.js.map +1 -0
- package/dist/components/FieldCaption.js +17 -0
- package/dist/components/FieldCaption.js.map +1 -0
- package/dist/components/HomePage/ContentHomePage.js +326 -0
- package/dist/components/HomePage/ContentHomePage.js.map +1 -0
- package/dist/components/HomePage/FavouritesView.js +44 -0
- package/dist/components/HomePage/FavouritesView.js.map +1 -0
- package/dist/components/HomePage/HomePageDnD.js +436 -0
- package/dist/components/HomePage/HomePageDnD.js.map +1 -0
- package/dist/components/HomePage/NavigationCard.js +59 -0
- package/dist/components/HomePage/NavigationCard.js.map +1 -0
- package/dist/components/HomePage/NavigationCardBinding.js +70 -0
- package/dist/components/HomePage/NavigationCardBinding.js.map +1 -0
- package/dist/components/HomePage/NavigationGroup.js +98 -0
- package/dist/components/HomePage/NavigationGroup.js.map +1 -0
- package/dist/components/HomePage/RenameGroupDialog.js +89 -0
- package/dist/components/HomePage/RenameGroupDialog.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +116 -0
- package/dist/components/InlineEntityPreview.js.map +1 -0
- package/dist/{JsonPreviewBinding-v0w3H0fp.js → components/JsonPreviewBinding.js} +2 -2
- package/dist/components/JsonPreviewBinding.js.map +1 -0
- package/dist/components/NavigationLoadingErrorView.d.ts +16 -0
- package/dist/components/NavigationLoadingErrorView.js +27 -0
- package/dist/components/NavigationLoadingErrorView.js.map +1 -0
- package/dist/components/PickerTrigger.js +27 -0
- package/dist/components/PickerTrigger.js.map +1 -0
- package/dist/components/PropertyCollectionView.js +215 -0
- package/dist/components/PropertyCollectionView.js.map +1 -0
- package/dist/components/PropertyConfigBadge.js +19 -0
- package/dist/components/PropertyConfigBadge.js.map +1 -0
- package/dist/components/PropertyKeyHint.js +58 -0
- package/dist/components/PropertyKeyHint.js.map +1 -0
- package/dist/components/RebaseAuthGate.js +35 -0
- package/dist/components/RebaseAuthGate.js.map +1 -0
- package/dist/components/RebaseCMS.js +44 -0
- package/dist/components/RebaseCMS.js.map +1 -0
- package/dist/components/RebaseLayout.js +59 -0
- package/dist/components/RebaseLayout.js.map +1 -0
- package/dist/components/RebaseNavigation.js +215 -0
- package/dist/components/RebaseNavigation.js.map +1 -0
- package/dist/components/RebaseRouteDefs.js +96 -0
- package/dist/components/RebaseRouteDefs.js.map +1 -0
- package/dist/components/RebaseShell.js +50 -0
- package/dist/components/RebaseShell.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.js +224 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -0
- package/dist/components/ReferenceWidget.js +100 -0
- package/dist/components/ReferenceWidget.js.map +1 -0
- package/dist/components/RelationSelector.js +625 -0
- package/dist/components/RelationSelector.js.map +1 -0
- package/dist/components/SearchIconsView.js +52 -0
- package/dist/components/SearchIconsView.js.map +1 -0
- package/dist/components/SelectableTable/SelectableTable.d.ts +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +158 -0
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -0
- package/dist/components/SelectableTable/SelectableTableContext.js +8 -0
- package/dist/components/SelectableTable/SelectableTableContext.js.map +1 -0
- package/dist/components/SelectableTable/SelectionStore.js +29 -0
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -0
- package/dist/components/SelectableTable/filters/BooleanFilterField.js +28 -0
- package/dist/components/SelectableTable/filters/BooleanFilterField.js.map +1 -0
- package/dist/components/SelectableTable/filters/DateTimeFilterField.d.ts +2 -1
- package/dist/components/SelectableTable/filters/DateTimeFilterField.js +93 -0
- package/dist/components/SelectableTable/filters/DateTimeFilterField.js.map +1 -0
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js +132 -0
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js.map +1 -0
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +157 -0
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -0
- package/dist/components/SelectableTable/filters/RelationFilterField.js +169 -0
- package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -0
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js +181 -0
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -0
- package/dist/components/SelectableTable/filters/null_filter.js +36 -0
- package/dist/components/SelectableTable/filters/null_filter.js.map +1 -0
- package/dist/components/SideDialogs.js +149 -0
- package/dist/components/SideDialogs.js.map +1 -0
- package/dist/components/SidePanelBinding.js +287 -0
- package/dist/components/SidePanelBinding.js.map +1 -0
- package/dist/components/SidePanelProvider.js +69 -0
- package/dist/components/SidePanelProvider.js.map +1 -0
- package/dist/components/UserSelector.d.ts +2 -0
- package/dist/components/UserSelector.js +418 -0
- package/dist/components/UserSelector.js.map +1 -0
- package/dist/components/admin/CreationResultDialog.js +118 -0
- package/dist/components/admin/CreationResultDialog.js.map +1 -0
- package/dist/components/app/AppBar.js +14 -0
- package/dist/components/app/AppBar.js.map +1 -0
- package/dist/components/app/Drawer.js +26 -0
- package/dist/components/app/Drawer.js.map +1 -0
- package/dist/components/app/Scaffold.js +229 -0
- package/dist/components/app/Scaffold.js.map +1 -0
- package/dist/components/app/useApp.js +24 -0
- package/dist/components/app/useApp.js.map +1 -0
- package/dist/components/common/ActionMenuLabel.d.ts +15 -0
- package/dist/components/common/ActionMenuLabel.js +30 -0
- package/dist/components/common/ActionMenuLabel.js.map +1 -0
- package/dist/components/common/default_entity_actions.d.ts +37 -0
- package/dist/components/common/default_entity_actions.js +590 -0
- package/dist/components/common/default_entity_actions.js.map +1 -0
- package/dist/components/drawer_expansion.d.ts +25 -0
- package/dist/components/drawer_expansion.js +44 -0
- package/dist/components/drawer_expansion.js.map +1 -0
- package/dist/components/field_configs.d.ts +2 -2
- package/dist/components/field_configs.js +431 -0
- package/dist/components/field_configs.js.map +1 -0
- package/dist/components/field_ids.d.ts +11 -0
- package/dist/components/field_ids.js +58 -0
- package/dist/components/field_ids.js.map +1 -0
- package/dist/components/history/EntityHistoryEntry.js +151 -0
- package/dist/components/history/EntityHistoryEntry.js.map +1 -0
- package/dist/components/history/EntityHistoryView.js +157 -0
- package/dist/components/history/EntityHistoryView.js.map +1 -0
- package/dist/components/history/UserChip.js +21 -0
- package/dist/components/history/UserChip.js.map +1 -0
- package/dist/components/history/index.js +4 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/lazy_record_views.d.ts +10 -0
- package/dist/components/lazy_record_views.js +57 -0
- package/dist/components/lazy_record_views.js.map +1 -0
- package/dist/contexts/BreacrumbsContext.js +28 -0
- package/dist/contexts/BreacrumbsContext.js.map +1 -0
- package/dist/contexts/EditorAIControllerContext.d.ts +18 -0
- package/dist/contexts/EditorAIControllerContext.js +29 -0
- package/dist/contexts/EditorAIControllerContext.js.map +1 -0
- package/dist/contexts/SideDialogsControllerContext.js +7 -0
- package/dist/contexts/SideDialogsControllerContext.js.map +1 -0
- package/dist/data_export/export/BasicExportAction.js +151 -0
- package/dist/data_export/export/BasicExportAction.js.map +1 -0
- package/dist/data_export/export/ExportCollectionAction.js +297 -0
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -0
- package/dist/data_export/export/additional_fields.js +40 -0
- package/dist/data_export/export/additional_fields.js.map +1 -0
- package/dist/data_export/export/export.d.ts +35 -0
- package/dist/data_export/export/export.js +400 -0
- package/dist/data_export/export/export.js.map +1 -0
- package/dist/data_export/export/fetch_export_data.d.ts +17 -7
- package/dist/data_export/export/fetch_export_data.js +67 -0
- package/dist/data_export/export/fetch_export_data.js.map +1 -0
- package/dist/data_export/export/index.d.ts +4 -2
- package/dist/data_export/export/index.js +5 -0
- package/dist/data_import/components/DataNewPropertiesMapping.js +207 -0
- package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -0
- package/dist/data_import/components/ImportConversionProblems.d.ts +11 -0
- package/dist/data_import/components/ImportConversionProblems.js +89 -0
- package/dist/data_import/components/ImportConversionProblems.js.map +1 -0
- package/dist/data_import/components/ImportFileUpload.js +43 -0
- package/dist/data_import/components/ImportFileUpload.js.map +1 -0
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js +42 -0
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -0
- package/dist/data_import/components/ImportSaveInProgress.js +105 -0
- package/dist/data_import/components/ImportSaveInProgress.js.map +1 -0
- package/dist/data_import/components/index.d.ts +1 -0
- package/dist/data_import/hooks/useImportConfig.js +34 -0
- package/dist/data_import/hooks/useImportConfig.js.map +1 -0
- package/dist/{import-TCgkTVlS.js → data_import/import/ImportCollectionAction.js} +84 -92
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -0
- package/dist/data_import/import/index.js +2 -0
- package/dist/data_import/utils/csv.js +146 -0
- package/dist/data_import/utils/csv.js.map +1 -0
- package/dist/data_import/utils/data.d.ts +81 -4
- package/dist/data_import/utils/data.js +366 -0
- package/dist/data_import/utils/data.js.map +1 -0
- package/dist/data_import/utils/file_headers.js +32 -0
- package/dist/data_import/utils/file_headers.js.map +1 -0
- package/dist/data_import/utils/file_to_json.js +149 -0
- package/dist/data_import/utils/file_to_json.js.map +1 -0
- package/dist/data_import/utils/get_import_inference_type.js +14 -0
- package/dist/data_import/utils/get_import_inference_type.js.map +1 -0
- package/dist/data_import/utils/id_column.js +27 -0
- package/dist/data_import/utils/id_column.js.map +1 -0
- package/dist/data_import/utils/import_columns.d.ts +48 -0
- package/dist/data_import/utils/import_columns.js +92 -0
- package/dist/data_import/utils/import_columns.js.map +1 -0
- package/dist/data_import/utils/save_entities.d.ts +33 -4
- package/dist/data_import/utils/save_entities.js +244 -0
- package/dist/data_import/utils/save_entities.js.map +1 -0
- package/dist/data_import/utils/transforms.js +83 -0
- package/dist/data_import/utils/transforms.js.map +1 -0
- package/dist/editor/components/SlashCommandMenu.js +497 -0
- package/dist/editor/components/SlashCommandMenu.js.map +1 -0
- package/dist/editor/components/editor-bubble-item.js +24 -0
- package/dist/editor/components/editor-bubble-item.js.map +1 -0
- package/dist/editor/components/editor-bubble.js +97 -0
- package/dist/editor/components/editor-bubble.js.map +1 -0
- package/dist/editor/components/image-bubble.js +148 -0
- package/dist/editor/components/image-bubble.js.map +1 -0
- package/dist/editor/components/table-bubble.js +406 -0
- package/dist/editor/components/table-bubble.js.map +1 -0
- package/dist/editor/editor.d.ts +7 -1
- package/dist/editor/editor.js +423 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/extensions/HighlightDecorationExtension.js +74 -0
- package/dist/editor/extensions/HighlightDecorationExtension.js.map +1 -0
- package/dist/editor/extensions/Image.d.ts +28 -1
- package/dist/editor/extensions/Image.js +160 -0
- package/dist/editor/extensions/Image.js.map +1 -0
- package/dist/editor/extensions/TextLoadingDecorationExtension.js +82 -0
- package/dist/editor/extensions/TextLoadingDecorationExtension.js.map +1 -0
- package/dist/editor/extensions/clipboard.js +63 -0
- package/dist/editor/extensions/clipboard.js.map +1 -0
- package/dist/editor/extensions/drag-and-drop.js +354 -0
- package/dist/editor/extensions/drag-and-drop.js.map +1 -0
- package/dist/editor/hooks/useProseMirror.d.ts +4 -1
- package/dist/editor/hooks/useProseMirror.js +101 -0
- package/dist/editor/hooks/useProseMirror.js.map +1 -0
- package/dist/editor/hooks/useProseMirrorContext.js +11 -0
- package/dist/editor/hooks/useProseMirrorContext.js.map +1 -0
- package/dist/editor/markdown.js +154 -0
- package/dist/editor/markdown.js.map +1 -0
- package/dist/editor/nodeViews/ImageComponent.js +35 -0
- package/dist/editor/nodeViews/ImageComponent.js.map +1 -0
- package/dist/editor/nodeViews/ReactNodeView.js +57 -0
- package/dist/editor/nodeViews/ReactNodeView.js.map +1 -0
- package/dist/editor/nodeViews/TaskItemComponent.js +29 -0
- package/dist/editor/nodeViews/TaskItemComponent.js.map +1 -0
- package/dist/editor/nodeViews/index.js +21 -0
- package/dist/editor/nodeViews/index.js.map +1 -0
- package/dist/editor/plugins/index.js +54 -0
- package/dist/editor/plugins/index.js.map +1 -0
- package/dist/editor/plugins/inputrules.js +54 -0
- package/dist/editor/plugins/inputrules.js.map +1 -0
- package/dist/editor/plugins/placeholderPlugin.js +38 -0
- package/dist/editor/plugins/placeholderPlugin.js.map +1 -0
- package/dist/editor/plugins/slashCommandPlugin.js +40 -0
- package/dist/editor/plugins/slashCommandPlugin.js.map +1 -0
- package/dist/editor/sanitize-html.js +190 -0
- package/dist/editor/sanitize-html.js.map +1 -0
- package/dist/{markdown-CCqp8ibf.js → editor/schema.js} +2 -159
- package/dist/editor/schema.js.map +1 -0
- package/dist/editor/selectors/link-selector.js +118 -0
- package/dist/editor/selectors/link-selector.js.map +1 -0
- package/dist/editor/selectors/node-selector.js +118 -0
- package/dist/editor/selectors/node-selector.js.map +1 -0
- package/dist/editor/selectors/text-buttons.js +71 -0
- package/dist/editor/selectors/text-buttons.js.map +1 -0
- package/dist/editor/utils/prosemirror-utils.js +92 -0
- package/dist/editor/utils/prosemirror-utils.js.map +1 -0
- package/dist/editor/utils/remove_classes.js +16 -0
- package/dist/editor/utils/remove_classes.js.map +1 -0
- package/dist/editor.js +1 -3085
- package/dist/form/EntityForm.js +734 -0
- package/dist/form/EntityForm.js.map +1 -0
- package/dist/form/EntityFormActions.js +101 -0
- package/dist/form/EntityFormActions.js.map +1 -0
- package/dist/form/EntityFormBinding.js +256 -0
- package/dist/form/EntityFormBinding.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +298 -0
- package/dist/form/PropertyFieldBinding.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +33 -0
- package/dist/form/components/ErrorFocus.js.map +1 -0
- package/dist/form/components/FieldBlock.js +118 -0
- package/dist/form/components/FieldBlock.js.map +1 -0
- package/dist/form/components/FieldHelperText.js +56 -0
- package/dist/form/components/FieldHelperText.js.map +1 -0
- package/dist/form/components/FormRail.js +118 -0
- package/dist/form/components/FormRail.js.map +1 -0
- package/dist/form/components/FormSections.js +63 -0
- package/dist/form/components/FormSections.js.map +1 -0
- package/dist/form/components/LabelWithIcon.js +29 -0
- package/dist/form/components/LabelWithIcon.js.map +1 -0
- package/dist/form/components/LocalChangesMenu.js +127 -0
- package/dist/form/components/LocalChangesMenu.js.map +1 -0
- package/dist/form/components/StorageItemPreview.js +46 -0
- package/dist/form/components/StorageItemPreview.js.map +1 -0
- package/dist/form/components/StorageUploadProgress.js +84 -0
- package/dist/form/components/StorageUploadProgress.js.map +1 -0
- package/dist/form/components/useRailVisible.js +43 -0
- package/dist/form/components/useRailVisible.js.map +1 -0
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +84 -0
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +125 -0
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/BinaryFieldBinding.js +135 -0
- package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/BlockFieldBinding.js +164 -0
- package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/DateTimeFieldBinding.js +47 -0
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/GeopointFieldBinding.js +148 -0
- package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/KeyValueFieldBinding.js +450 -0
- package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/MapFieldBinding.js +77 -0
- package/dist/form/field_bindings/MapFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +215 -0
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/MultiSelectFieldBinding.js +88 -0
- package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +118 -0
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js +52 -0
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/ReferenceFieldBinding.js +99 -0
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/RelationFieldBinding.js +135 -0
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/RepeatFieldBinding.js +103 -0
- package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/SelectFieldBinding.js +80 -0
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +266 -0
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/SwitchFieldBinding.js +41 -0
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/TextFieldBinding.js +114 -0
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/UserSelectFieldBinding.js +48 -0
- package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -0
- package/dist/form/field_bindings/VectorFieldBinding.js +147 -0
- package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -0
- package/dist/form/form_keyboard_scope.d.ts +26 -0
- package/dist/form/form_keyboard_scope.js +39 -0
- package/dist/form/form_keyboard_scope.js.map +1 -0
- package/dist/form/form_uploads.d.ts +24 -0
- package/dist/form/form_uploads.js +31 -0
- package/dist/form/form_uploads.js.map +1 -0
- package/dist/form/form_utils.d.ts +48 -0
- package/dist/form/form_utils.js +280 -0
- package/dist/form/form_utils.js.map +1 -0
- package/dist/form/resolve_cell_property.d.ts +32 -0
- package/dist/form/resolve_cell_property.js +80 -0
- package/dist/form/resolve_cell_property.js.map +1 -0
- package/dist/form/resolve_form_properties.d.ts +27 -0
- package/dist/form/resolve_form_properties.js +78 -0
- package/dist/form/resolve_form_properties.js.map +1 -0
- package/dist/form/useClearRestoreValue.js +27 -0
- package/dist/form/useClearRestoreValue.js.map +1 -0
- package/dist/form/useUndoableDiscard.js +36 -0
- package/dist/form/useUndoableDiscard.js.map +1 -0
- package/dist/form/validation.d.ts +20 -0
- package/dist/form/validation.js +416 -0
- package/dist/form/validation.js.map +1 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js +22 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -0
- package/dist/hooks/navigation/contexts/NavigationStateContext.js +15 -0
- package/dist/hooks/navigation/contexts/NavigationStateContext.js.map +1 -0
- package/dist/hooks/navigation/contexts/UrlContext.js +22 -0
- package/dist/hooks/navigation/contexts/UrlContext.js.map +1 -0
- package/dist/hooks/navigation/useAsyncResolver.js +68 -0
- package/dist/hooks/navigation/useAsyncResolver.js.map +1 -0
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js +141 -0
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -0
- package/dist/hooks/navigation/useBuildNavigationStateController.js +77 -0
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -0
- package/dist/hooks/navigation/useBuildUrlController.js +57 -0
- package/dist/hooks/navigation/useBuildUrlController.js.map +1 -0
- package/dist/hooks/navigation/useNavigationResolution.js +177 -0
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -0
- package/dist/hooks/navigation/useResolvedCollections.js +56 -0
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -0
- package/dist/hooks/navigation/useResolvedViews.js +94 -0
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -0
- package/dist/hooks/navigation/useTopLevelNavigation.js +162 -0
- package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -0
- package/dist/hooks/navigation/utils.js +125 -0
- package/dist/hooks/navigation/utils.js.map +1 -0
- package/dist/hooks/useAdminContext.js +45 -0
- package/dist/hooks/useAdminContext.js.map +1 -0
- package/dist/hooks/useBreadcrumbsController.js +17 -0
- package/dist/hooks/useBreadcrumbsController.js.map +1 -0
- package/dist/hooks/useBuildSideDialogsController.js +96 -0
- package/dist/hooks/useBuildSideDialogsController.js.map +1 -0
- package/dist/hooks/useBuildSidePanel.js +221 -0
- package/dist/hooks/useBuildSidePanel.js.map +1 -0
- package/dist/hooks/useChildViewSource.js +41 -0
- package/dist/hooks/useChildViewSource.js.map +1 -0
- package/dist/hooks/useEntityDisplay.js +136 -0
- package/dist/hooks/useEntityDisplay.js.map +1 -0
- package/dist/hooks/useEntityDisplayTitle.js +34 -0
- package/dist/hooks/useEntityDisplayTitle.js.map +1 -0
- package/dist/hooks/useHistory.js +137 -0
- package/dist/hooks/useHistory.js.map +1 -0
- package/dist/hooks/useRecordActions.d.ts +28 -6
- package/dist/hooks/useRecordActions.js +108 -0
- package/dist/hooks/useRecordActions.js.map +1 -0
- package/dist/hooks/useReferencePaths.d.ts +21 -0
- package/dist/hooks/useReferencePaths.js +32 -0
- package/dist/hooks/useReferencePaths.js.map +1 -0
- package/dist/hooks/useResolvedNavigationFrom.js +83 -0
- package/dist/hooks/useResolvedNavigationFrom.js.map +1 -0
- package/dist/hooks/useResolvedUsers.js +109 -0
- package/dist/hooks/useResolvedUsers.js.map +1 -0
- package/dist/hooks/useSelectionDialog.js +53 -0
- package/dist/hooks/useSelectionDialog.js.map +1 -0
- package/dist/hooks/useSideDialogsController.js +8 -0
- package/dist/hooks/useSideDialogsController.js.map +1 -0
- package/dist/hooks/useSidePanel.js +15 -0
- package/dist/hooks/useSidePanel.js.map +1 -0
- package/dist/hooks/useStorageReferenceResolver.d.ts +25 -0
- package/dist/hooks/useStorageReferenceResolver.js +49 -0
- package/dist/hooks/useStorageReferenceResolver.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +151 -3793
- package/dist/preview/PropertyPreview.js +260 -0
- package/dist/preview/PropertyPreview.js.map +1 -0
- package/dist/preview/compact_text.js +52 -0
- package/dist/preview/compact_text.js.map +1 -0
- package/dist/preview/components/ArrayEnumPreview.js +24 -0
- package/dist/preview/components/ArrayEnumPreview.js.map +1 -0
- package/dist/preview/components/BooleanPreview.js +25 -0
- package/dist/preview/components/BooleanPreview.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +3 -2
- package/dist/preview/components/DatePreview.js +87 -0
- package/dist/preview/components/DatePreview.js.map +1 -0
- package/dist/preview/components/EmptyValue.js +13 -0
- package/dist/preview/components/EmptyValue.js.map +1 -0
- package/dist/preview/components/EnumValuesChip.js +26 -0
- package/dist/preview/components/EnumValuesChip.js.map +1 -0
- package/dist/preview/components/ImagePreview.d.ts +7 -1
- package/dist/preview/components/ImagePreview.js +112 -0
- package/dist/preview/components/ImagePreview.js.map +1 -0
- package/dist/preview/components/InlineEntityListPreview.js +31 -0
- package/dist/preview/components/InlineEntityListPreview.js.map +1 -0
- package/dist/preview/components/ReferencePreview.js +162 -0
- package/dist/preview/components/ReferencePreview.js.map +1 -0
- package/dist/preview/components/RelationPreview.js +196 -0
- package/dist/preview/components/RelationPreview.js.map +1 -0
- package/dist/preview/components/StorageMarkdown.d.ts +11 -0
- package/dist/preview/components/StorageMarkdown.js +49 -0
- package/dist/preview/components/StorageMarkdown.js.map +1 -0
- package/dist/preview/components/StorageThumbnail.js +183 -0
- package/dist/preview/components/StorageThumbnail.js.map +1 -0
- package/dist/preview/components/UrlComponentPreview.d.ts +3 -1
- package/dist/preview/components/UrlComponentPreview.js +88 -0
- package/dist/preview/components/UrlComponentPreview.js.map +1 -0
- package/dist/preview/components/UserPreview.js +30 -0
- package/dist/preview/components/UserPreview.js.map +1 -0
- package/dist/preview/components/date_fns_locales.js +124 -0
- package/dist/preview/components/date_fns_locales.js.map +1 -0
- package/dist/preview/components/storageRenditions.d.ts +10 -0
- package/dist/preview/components/storageRenditions.js +95 -0
- package/dist/preview/components/storageRenditions.js.map +1 -0
- package/dist/preview/property_previews/ArrayOfMapsPreview.js +44 -0
- package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js +48 -0
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js +50 -0
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js +30 -0
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayOfStringsPreview.js +42 -0
- package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayOneOfPreview.js +47 -0
- package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +25 -0
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -0
- package/dist/preview/property_previews/ArrayPropertyPreview.js +48 -0
- package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -0
- package/dist/preview/property_previews/MapPropertyPreview.js +137 -0
- package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -0
- package/dist/preview/property_previews/NumberPropertyPreview.js +34 -0
- package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -0
- package/dist/preview/property_previews/SkeletonPropertyComponent.js +151 -0
- package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -0
- package/dist/preview/property_previews/StringPropertyPreview.js +49 -0
- package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -0
- package/dist/preview/util.d.ts +8 -3
- package/dist/{util-CC0ozHoD.js → preview/util.js} +13 -6
- package/dist/preview/util.js.map +1 -0
- package/dist/routes/CustomViewRoute.js +26 -0
- package/dist/routes/CustomViewRoute.js.map +1 -0
- package/dist/routes/RebaseRoute.js +311 -0
- package/dist/routes/RebaseRoute.js.map +1 -0
- package/dist/selection/SelectionMenu.js +90 -0
- package/dist/selection/SelectionMenu.js.map +1 -0
- package/dist/selection/resolve_selection.js +79 -0
- package/dist/selection/resolve_selection.js.map +1 -0
- package/dist/util/caller_scopes.d.ts +15 -0
- package/dist/util/caller_scopes.js +25 -0
- package/dist/util/caller_scopes.js.map +1 -0
- package/dist/util/collection_open_mode.d.ts +20 -0
- package/dist/util/collection_open_mode.js +32 -0
- package/dist/util/collection_open_mode.js.map +1 -0
- package/dist/util/dataControllerAdapter.js +65 -0
- package/dist/util/dataControllerAdapter.js.map +1 -0
- package/dist/util/entity_actions.d.ts +42 -1
- package/dist/util/entity_actions.js +77 -0
- package/dist/util/entity_actions.js.map +1 -0
- package/dist/util/entity_pages.d.ts +37 -3
- package/dist/util/entity_pages.js +71 -0
- package/dist/util/entity_pages.js.map +1 -0
- package/dist/util/find_entities_by_ids.d.ts +23 -0
- package/dist/util/find_entities_by_ids.js +55 -0
- package/dist/util/find_entities_by_ids.js.map +1 -0
- package/dist/util/fit_inline_actions.d.ts +20 -0
- package/dist/util/fit_inline_actions.js +40 -0
- package/dist/util/fit_inline_actions.js.map +1 -0
- package/dist/util/format_collection_date.d.ts +29 -0
- package/dist/util/format_collection_date.js +60 -0
- package/dist/util/format_collection_date.js.map +1 -0
- package/dist/util/map_with_concurrency.js +46 -0
- package/dist/util/map_with_concurrency.js.map +1 -0
- package/dist/util/navigation_utils.js +45 -0
- package/dist/util/navigation_utils.js.map +1 -0
- package/dist/util/number_format.js +33 -0
- package/dist/util/number_format.js.map +1 -0
- package/dist/util/previews.js +71 -0
- package/dist/util/previews.js.map +1 -0
- package/dist/util/propertyConfigMapper.js +83 -0
- package/dist/util/propertyConfigMapper.js.map +1 -0
- package/dist/util/property_utils.js +141 -0
- package/dist/util/property_utils.js.map +1 -0
- package/dist/util/resolutions.js +55 -0
- package/dist/util/resolutions.js.map +1 -0
- package/dist/util/view_constants.js +35 -0
- package/dist/util/view_constants.js.map +1 -0
- package/dist/util/view_mode.js +112 -0
- package/dist/util/view_mode.js.map +1 -0
- package/package.json +13 -9
- package/dist/CollectionEditorDialog-DLHCka00.js +0 -3630
- package/dist/CollectionEditorDialog-DLHCka00.js.map +0 -1
- package/dist/JsonPreviewBinding-v0w3H0fp.js.map +0 -1
- package/dist/PropertyEditView-_pu5hzZn.js +0 -3837
- package/dist/PropertyEditView-_pu5hzZn.js.map +0 -1
- package/dist/RouterCollectionsStudioView-ChPNl_uU.js +0 -212
- package/dist/RouterCollectionsStudioView-ChPNl_uU.js.map +0 -1
- package/dist/SchemaChangeDialog-BeP0A4MJ.js.map +0 -1
- package/dist/collection_editor/ui/CollectionViewHeaderAction.d.ts +0 -13
- package/dist/collection_editor/ui/PropertyAddColumnComponent.d.ts +0 -8
- package/dist/collection_editor_ui.js.map +0 -1
- package/dist/editor.js.map +0 -1
- package/dist/export-4bJWdlDK.js +0 -520
- package/dist/export-4bJWdlDK.js.map +0 -1
- package/dist/history-BElrZ5Rw.js +0 -313
- package/dist/history-BElrZ5Rw.js.map +0 -1
- package/dist/import-TCgkTVlS.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/markdown-CCqp8ibf.js.map +0 -1
- package/dist/rolldown-runtime-D7D4PA-g.js +0 -13
- package/dist/util-CC0ozHoD.js.map +0 -1
- package/dist/util-DybQBkug.js +0 -26390
- package/dist/util-DybQBkug.js.map +0 -1
package/dist/editor.js
CHANGED
|
@@ -1,3086 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as schema, n as parser, r as serializer } from "./markdown-CCqp8ibf.js";
|
|
3
|
-
import React, { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { BoldIcon, Button, CheckIcon, CheckSquareIcon, Checkbox, ChevronDownIcon, CodeIcon, Heading1Icon, Heading2Icon, Heading3Icon, IconButton, ImageIcon, ItalicIcon, Label, ListIcon, ListOrderedIcon, Popover, QuoteIcon, Separator, Slot, StrikethroughIcon, TableIcon, TextField, TextareaAutosize, Tooltip, Trash2Icon, TypeIcon, UnderlineIcon, Wand2Icon, cls, defaultBorderMixin, focusedDisabled, iconSize, useInjectStyles } from "@rebasepro/ui";
|
|
5
|
-
import { useTranslation } from "@rebasepro/app";
|
|
6
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { EditorState, NodeSelection, Plugin, PluginKey, Selection, TextSelection } from "prosemirror-state";
|
|
8
|
-
import { autoUpdate, computePosition, flip, offset, shift } from "@floating-ui/dom";
|
|
9
|
-
import { DOMParser as DOMParser$1, DOMSerializer, Fragment as Fragment$1 } from "prosemirror-model";
|
|
10
|
-
import { baseKeymap, setBlockType, toggleMark, wrapIn } from "prosemirror-commands";
|
|
11
|
-
import { liftListItem, sinkListItem, splitListItem, wrapInList } from "prosemirror-schema-list";
|
|
12
|
-
import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, columnResizing, deleteColumn, deleteRow, deleteTable, goToNextCell, tableEditing } from "prosemirror-tables";
|
|
13
|
-
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
14
|
-
import { keymap } from "prosemirror-keymap";
|
|
15
|
-
import { history, redo, undo } from "prosemirror-history";
|
|
16
|
-
import { dropPoint } from "prosemirror-transform";
|
|
17
|
-
import { gapCursor } from "prosemirror-gapcursor";
|
|
18
|
-
import { InputRule, ellipsis, emDash, inputRules, smartQuotes, textblockTypeInputRule, wrappingInputRule } from "prosemirror-inputrules";
|
|
19
|
-
import { createRoot } from "react-dom/client";
|
|
20
|
-
//#region src/editor/hooks/useProseMirrorContext.ts
|
|
21
|
-
var ProseMirrorContext = createContext({
|
|
22
|
-
state: null,
|
|
23
|
-
view: null
|
|
24
|
-
});
|
|
25
|
-
var useProseMirrorContext = () => useContext(ProseMirrorContext);
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/editor/components/editor-bubble.tsx
|
|
28
|
-
var EditorBubble = forwardRef(({ children, options, className }, ref) => {
|
|
29
|
-
const { view, state } = useProseMirrorContext();
|
|
30
|
-
const menuRef = useRef(null);
|
|
31
|
-
const [show, setShow] = useState(false);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!view || !state) return;
|
|
34
|
-
const timer = setTimeout(() => {
|
|
35
|
-
const { selection } = state;
|
|
36
|
-
const { empty } = selection;
|
|
37
|
-
let isImage = false;
|
|
38
|
-
state.doc.nodesBetween(selection.from, selection.to, (node) => {
|
|
39
|
-
if (node.type.name === "image") isImage = true;
|
|
40
|
-
});
|
|
41
|
-
if (isImage || empty || selection instanceof NodeSelection) {
|
|
42
|
-
setShow(false);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
setShow(true);
|
|
46
|
-
}, 0);
|
|
47
|
-
return () => clearTimeout(timer);
|
|
48
|
-
}, [view, state]);
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!show || !view || !state || !menuRef.current) return;
|
|
51
|
-
const { from, to } = state.selection;
|
|
52
|
-
let start = view.coordsAtPos(from);
|
|
53
|
-
let end = view.coordsAtPos(to);
|
|
54
|
-
const virtualEl = { getBoundingClientRect() {
|
|
55
|
-
const top = Math.min(start.top, end.top);
|
|
56
|
-
const bottom = Math.max(start.bottom, end.bottom);
|
|
57
|
-
const left = Math.min(start.left, end.left);
|
|
58
|
-
const right = Math.max(start.right, end.right);
|
|
59
|
-
return {
|
|
60
|
-
width: right - left,
|
|
61
|
-
height: bottom - top,
|
|
62
|
-
x: left,
|
|
63
|
-
y: top,
|
|
64
|
-
top,
|
|
65
|
-
left,
|
|
66
|
-
right,
|
|
67
|
-
bottom
|
|
68
|
-
};
|
|
69
|
-
} };
|
|
70
|
-
const cleanup = autoUpdate(virtualEl, menuRef.current, () => {
|
|
71
|
-
if (!menuRef.current) return;
|
|
72
|
-
try {
|
|
73
|
-
start = view.coordsAtPos(state.selection.from);
|
|
74
|
-
end = view.coordsAtPos(state.selection.to);
|
|
75
|
-
} catch (e) {}
|
|
76
|
-
computePosition(virtualEl, menuRef.current, {
|
|
77
|
-
placement: options?.placement || "top",
|
|
78
|
-
middleware: [
|
|
79
|
-
offset(options?.offset || 8),
|
|
80
|
-
flip(),
|
|
81
|
-
shift()
|
|
82
|
-
],
|
|
83
|
-
strategy: "fixed"
|
|
84
|
-
}).then(({ x, y }) => {
|
|
85
|
-
if (menuRef.current) Object.assign(menuRef.current.style, {
|
|
86
|
-
left: `${x}px`,
|
|
87
|
-
top: `${y}px`,
|
|
88
|
-
visibility: "visible"
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
return () => cleanup();
|
|
93
|
-
}, [
|
|
94
|
-
show,
|
|
95
|
-
view,
|
|
96
|
-
state,
|
|
97
|
-
options
|
|
98
|
-
]);
|
|
99
|
-
if (!show) return null;
|
|
100
|
-
return /* @__PURE__ */ jsx("div", {
|
|
101
|
-
ref: menuRef,
|
|
102
|
-
className,
|
|
103
|
-
style: {
|
|
104
|
-
position: "fixed",
|
|
105
|
-
zIndex: 9999,
|
|
106
|
-
visibility: "hidden"
|
|
107
|
-
},
|
|
108
|
-
onMouseDown: (e) => {
|
|
109
|
-
e.preventDefault();
|
|
110
|
-
},
|
|
111
|
-
children
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
EditorBubble.displayName = "EditorBubble";
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/editor/components/editor-bubble-item.tsx
|
|
117
|
-
var EditorBubbleItem = forwardRef(({ children, asChild, onSelect, ...rest }, ref) => {
|
|
118
|
-
const { view } = useProseMirrorContext();
|
|
119
|
-
const Comp = asChild ? Slot : "div";
|
|
120
|
-
if (!view) return null;
|
|
121
|
-
return /* @__PURE__ */ jsx(Comp, {
|
|
122
|
-
ref,
|
|
123
|
-
...rest,
|
|
124
|
-
onMouseDown: (e) => {
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
},
|
|
127
|
-
onClick: () => onSelect?.(),
|
|
128
|
-
children
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
EditorBubbleItem.displayName = "EditorBubbleItem";
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/editor/plugins/slashCommandPlugin.ts
|
|
134
|
-
var SlashCommandPluginKey = new PluginKey("slash-command");
|
|
135
|
-
function slashCommandPlugin() {
|
|
136
|
-
return new Plugin({
|
|
137
|
-
key: SlashCommandPluginKey,
|
|
138
|
-
state: {
|
|
139
|
-
init() {
|
|
140
|
-
return { active: false };
|
|
141
|
-
},
|
|
142
|
-
apply(tr, value, oldState, newState) {
|
|
143
|
-
const meta = tr.getMeta(SlashCommandPluginKey);
|
|
144
|
-
if (meta !== void 0) return meta;
|
|
145
|
-
const { selection } = newState;
|
|
146
|
-
if (!(selection instanceof TextSelection) || !selection.empty) return { active: false };
|
|
147
|
-
const $anchor = selection.$anchor;
|
|
148
|
-
if ($anchor.parent.type.name === "code_block") return { active: false };
|
|
149
|
-
const match = $anchor.parent.textBetween(Math.max(0, $anchor.parentOffset - 20), $anchor.parentOffset, void 0, "").match(/(?:\s|^)(\/)([a-zA-Z0-9]*)$/);
|
|
150
|
-
if (!match) return { active: false };
|
|
151
|
-
if (value.dismissed) return {
|
|
152
|
-
active: false,
|
|
153
|
-
dismissed: true
|
|
154
|
-
};
|
|
155
|
-
const query = match[2];
|
|
156
|
-
return {
|
|
157
|
-
active: true,
|
|
158
|
-
range: {
|
|
159
|
-
from: $anchor.pos - query.length - 1,
|
|
160
|
-
to: $anchor.pos
|
|
161
|
-
},
|
|
162
|
-
query
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/editor/extensions/Image.ts
|
|
170
|
-
async function onFileRead(view, readerEvent, pos, upload, image) {
|
|
171
|
-
const { schema } = view.state;
|
|
172
|
-
const plugin = view.state.plugins.find((p) => p.spec.key === ImagePluginKey);
|
|
173
|
-
if (!plugin) {
|
|
174
|
-
console.error("Image plugin not found");
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const decoId = Math.random().toString(36).substring(7);
|
|
178
|
-
const placeholder = document.createElement("div");
|
|
179
|
-
const imageElement = document.createElement("img");
|
|
180
|
-
imageElement.setAttribute("class", "opacity-40 rounded-lg border " + defaultBorderMixin);
|
|
181
|
-
imageElement.src = readerEvent.target?.result;
|
|
182
|
-
placeholder.appendChild(imageElement);
|
|
183
|
-
const deco = Decoration.widget(pos, placeholder, { id: decoId });
|
|
184
|
-
let decorationSet = plugin.getState(view.state);
|
|
185
|
-
decorationSet = decorationSet?.add(view.state.doc, [deco]);
|
|
186
|
-
view.dispatch(view.state.tr.setMeta(plugin, { decorationSet }));
|
|
187
|
-
const src = await upload(image);
|
|
188
|
-
console.debug("Uploaded image", src);
|
|
189
|
-
const replacePlaceholder = () => {
|
|
190
|
-
let currentDecos = plugin.getState(view.state);
|
|
191
|
-
const foundDecos = currentDecos.find(void 0, void 0, (spec) => spec.id === decoId);
|
|
192
|
-
if (foundDecos.length === 0) {
|
|
193
|
-
console.warn("Image placeholder removed before upload completed.");
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const currentPos = foundDecos[0].from;
|
|
197
|
-
const imageNode = view.state.schema.nodes.image.create({ src });
|
|
198
|
-
const tr = view.state.tr.replaceWith(currentPos, currentPos, imageNode);
|
|
199
|
-
currentDecos = currentDecos.remove(foundDecos);
|
|
200
|
-
tr.setMeta(plugin, { decorationSet: currentDecos });
|
|
201
|
-
view.dispatch(tr);
|
|
202
|
-
};
|
|
203
|
-
const preloader = new Image();
|
|
204
|
-
preloader.src = src;
|
|
205
|
-
preloader.onload = replacePlaceholder;
|
|
206
|
-
preloader.onerror = replacePlaceholder;
|
|
207
|
-
}
|
|
208
|
-
var ImagePluginKey = new PluginKey("imagePlugin");
|
|
209
|
-
var createDropImagePlugin = (upload) => {
|
|
210
|
-
const plugin = new Plugin({
|
|
211
|
-
key: ImagePluginKey,
|
|
212
|
-
state: {
|
|
213
|
-
init: () => DecorationSet.empty,
|
|
214
|
-
apply: (tr, old) => {
|
|
215
|
-
const meta = tr.getMeta(plugin);
|
|
216
|
-
if (meta && meta.decorationSet) return meta.decorationSet;
|
|
217
|
-
return old.map(tr.mapping, tr.doc);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
props: {
|
|
221
|
-
handleDOMEvents: {
|
|
222
|
-
dragover: (view, event) => {
|
|
223
|
-
if (event.dataTransfer?.types?.includes("Files")) {
|
|
224
|
-
event.preventDefault();
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
},
|
|
229
|
-
drop: (view, event) => {
|
|
230
|
-
if (!event.dataTransfer?.files || event.dataTransfer?.files.length === 0) return false;
|
|
231
|
-
event.preventDefault();
|
|
232
|
-
const images = Array.from(event.dataTransfer.files).filter((file) => /image/i.test(file.type));
|
|
233
|
-
if (images.length === 0) {
|
|
234
|
-
console.debug("No images found in dropped files");
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
images.forEach((image) => {
|
|
238
|
-
const position = view.posAtCoords({
|
|
239
|
-
left: event.clientX,
|
|
240
|
-
top: event.clientY
|
|
241
|
-
});
|
|
242
|
-
if (!position) return;
|
|
243
|
-
const reader = new FileReader();
|
|
244
|
-
reader.onload = async (readerEvent) => {
|
|
245
|
-
await onFileRead(view, readerEvent, position.pos, upload, image);
|
|
246
|
-
};
|
|
247
|
-
reader.readAsDataURL(image);
|
|
248
|
-
});
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
handlePaste(view, event) {
|
|
253
|
-
const html = event.clipboardData?.getData("text/html");
|
|
254
|
-
if (html && html.includes("<img")) return false;
|
|
255
|
-
const items = Array.from(event.clipboardData?.items || []);
|
|
256
|
-
const pos = view.state.selection.from;
|
|
257
|
-
let anyImageFound = false;
|
|
258
|
-
items.filter((item) => item.type.startsWith("image/")).forEach((item) => {
|
|
259
|
-
const image = item.getAsFile();
|
|
260
|
-
if (image) {
|
|
261
|
-
anyImageFound = true;
|
|
262
|
-
const reader = new FileReader();
|
|
263
|
-
reader.onload = async (readerEvent) => {
|
|
264
|
-
await onFileRead(view, readerEvent, pos, upload, image);
|
|
265
|
-
};
|
|
266
|
-
reader.readAsDataURL(image);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
return anyImageFound;
|
|
270
|
-
},
|
|
271
|
-
decorations(state) {
|
|
272
|
-
return plugin.getState(state);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
return plugin;
|
|
277
|
-
};
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region src/editor/sanitize-html.ts
|
|
280
|
-
/**
|
|
281
|
-
* HTML the editor is willing to put into the document.
|
|
282
|
-
*
|
|
283
|
-
* Three places in the editor took a string of HTML and assigned it to
|
|
284
|
-
* `innerHTML` on an element belonging to the live document: the loading
|
|
285
|
-
* decoration that renders an AI completion as it streams, the final result of
|
|
286
|
-
* that completion, and the paste transform. All three are the same mistake, and
|
|
287
|
-
* the middle word is the one that matters — `innerHTML` on a LIVE element runs
|
|
288
|
-
* the content. `<img src=x onerror=…>` fires during the assignment; an
|
|
289
|
-
* `<iframe src>` loads; a `<script>` is inert but `<svg><script>` and
|
|
290
|
-
* `<object data>` are not, depending on the browser.
|
|
291
|
-
*
|
|
292
|
-
* Inside the Cloud console that is the console's own origin: the session, the
|
|
293
|
-
* project list, the deploy API, and an env-var reveal route are all one fetch
|
|
294
|
-
* away from anything that runs there.
|
|
295
|
-
*
|
|
296
|
-
* ## Why not "the AI is ours, so its output is trusted"
|
|
297
|
-
*
|
|
298
|
-
* Because it is not the AI's output. `autocomplete` is given the surrounding
|
|
299
|
-
* document text as context, and the document is a customer's content —
|
|
300
|
-
* frequently content some other person typed into their app. So the payload
|
|
301
|
-
* route is: put HTML in a record, ask an editor's AI to continue writing near
|
|
302
|
-
* it, and have the model repeat it back. Prompt injection is the ordinary case
|
|
303
|
-
* here, not the exotic one.
|
|
304
|
-
*
|
|
305
|
-
* ## The shape of the fix
|
|
306
|
-
*
|
|
307
|
-
* Parse INERTLY, then keep an allowlist.
|
|
308
|
-
*
|
|
309
|
-
* `new DOMParser().parseFromString(html, "text/html")` builds a document with
|
|
310
|
-
* no browsing context: scripts do not run, and `src` attributes do not fetch.
|
|
311
|
-
* That alone closes the live-execution half. The allowlist then decides what
|
|
312
|
-
* survives, and it is an allowlist rather than a list of banned tags because
|
|
313
|
-
* the set of dangerous elements is not one anybody can finish writing — but the
|
|
314
|
-
* set of elements a rich-text editor can actually represent is small, closed,
|
|
315
|
-
* and already written down in its schema.
|
|
316
|
-
*
|
|
317
|
-
* Anything not on the list is UNWRAPPED rather than dropped: a `<div>` around a
|
|
318
|
-
* paragraph is not an attack, and deleting its contents would lose a person's
|
|
319
|
-
* writing to a tag they never chose. Elements that carry no text worth keeping
|
|
320
|
-
* — script, style, iframe — are removed outright.
|
|
321
|
-
*/
|
|
322
|
-
/** Elements the editor's own schema can represent. */
|
|
323
|
-
var ALLOWED_ELEMENTS = /* @__PURE__ */ new Set([
|
|
324
|
-
"p",
|
|
325
|
-
"br",
|
|
326
|
-
"hr",
|
|
327
|
-
"h1",
|
|
328
|
-
"h2",
|
|
329
|
-
"h3",
|
|
330
|
-
"h4",
|
|
331
|
-
"h5",
|
|
332
|
-
"h6",
|
|
333
|
-
"strong",
|
|
334
|
-
"b",
|
|
335
|
-
"em",
|
|
336
|
-
"i",
|
|
337
|
-
"u",
|
|
338
|
-
"s",
|
|
339
|
-
"strike",
|
|
340
|
-
"del",
|
|
341
|
-
"mark",
|
|
342
|
-
"sub",
|
|
343
|
-
"sup",
|
|
344
|
-
"a",
|
|
345
|
-
"img",
|
|
346
|
-
"ul",
|
|
347
|
-
"ol",
|
|
348
|
-
"li",
|
|
349
|
-
"blockquote",
|
|
350
|
-
"pre",
|
|
351
|
-
"code",
|
|
352
|
-
"table",
|
|
353
|
-
"thead",
|
|
354
|
-
"tbody",
|
|
355
|
-
"tfoot",
|
|
356
|
-
"tr",
|
|
357
|
-
"th",
|
|
358
|
-
"td",
|
|
359
|
-
"span",
|
|
360
|
-
"div"
|
|
361
|
-
]);
|
|
362
|
-
/**
|
|
363
|
-
* Elements removed with their contents, rather than unwrapped.
|
|
364
|
-
*
|
|
365
|
-
* Everything else that is not allowed keeps its text, because the text is
|
|
366
|
-
* somebody's writing. These four have no text worth keeping and every reason
|
|
367
|
-
* to be gone: `script` and `style` are code, `iframe`/`object`/`embed` are
|
|
368
|
-
* another document, and `template`'s contents are invisible to a
|
|
369
|
-
* `querySelectorAll` sweep, which makes it a good place to hide things.
|
|
370
|
-
*/
|
|
371
|
-
var DROPPED_ELEMENTS = /* @__PURE__ */ new Set([
|
|
372
|
-
"script",
|
|
373
|
-
"style",
|
|
374
|
-
"iframe",
|
|
375
|
-
"object",
|
|
376
|
-
"embed",
|
|
377
|
-
"template",
|
|
378
|
-
"noscript",
|
|
379
|
-
"link",
|
|
380
|
-
"meta",
|
|
381
|
-
"base",
|
|
382
|
-
"form",
|
|
383
|
-
"input",
|
|
384
|
-
"button",
|
|
385
|
-
"textarea",
|
|
386
|
-
"select"
|
|
387
|
-
]);
|
|
388
|
-
/** Attributes each allowed element may keep. */
|
|
389
|
-
var ALLOWED_ATTRIBUTES = {
|
|
390
|
-
a: /* @__PURE__ */ new Set([
|
|
391
|
-
"href",
|
|
392
|
-
"title",
|
|
393
|
-
"target",
|
|
394
|
-
"rel"
|
|
395
|
-
]),
|
|
396
|
-
img: /* @__PURE__ */ new Set([
|
|
397
|
-
"src",
|
|
398
|
-
"alt",
|
|
399
|
-
"title",
|
|
400
|
-
"width",
|
|
401
|
-
"height"
|
|
402
|
-
]),
|
|
403
|
-
td: /* @__PURE__ */ new Set(["colspan", "rowspan"]),
|
|
404
|
-
th: /* @__PURE__ */ new Set([
|
|
405
|
-
"colspan",
|
|
406
|
-
"rowspan",
|
|
407
|
-
"scope"
|
|
408
|
-
]),
|
|
409
|
-
ol: /* @__PURE__ */ new Set(["start"])
|
|
410
|
-
};
|
|
411
|
-
/** Attributes any element may keep. Deliberately almost empty. */
|
|
412
|
-
var GLOBAL_ATTRIBUTES = /* @__PURE__ */ new Set(["title"]);
|
|
413
|
-
/** Attributes whose value is a URL, and so goes through {@link sanitizeUrl}. */
|
|
414
|
-
var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src"]);
|
|
415
|
-
/**
|
|
416
|
-
* Parse and sanitize into a detached element, for a caller that wants nodes
|
|
417
|
-
* rather than a string.
|
|
418
|
-
*
|
|
419
|
-
* Same work, one serialize-and-reparse fewer. The element belongs to an inert
|
|
420
|
-
* document until the caller adopts it.
|
|
421
|
-
*/
|
|
422
|
-
function parseSanitizedHtml(html) {
|
|
423
|
-
const doc = new DOMParser().parseFromString(html || "", "text/html");
|
|
424
|
-
sanitizeNode(doc.body);
|
|
425
|
-
return doc.body;
|
|
426
|
-
}
|
|
427
|
-
/** Walk children depth-first, editing in place. */
|
|
428
|
-
function sanitizeNode(parent) {
|
|
429
|
-
for (const child of Array.from(parent.children)) {
|
|
430
|
-
const tag = child.tagName.toLowerCase();
|
|
431
|
-
if (DROPPED_ELEMENTS.has(tag)) {
|
|
432
|
-
child.remove();
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
sanitizeNode(child);
|
|
436
|
-
if (!ALLOWED_ELEMENTS.has(tag)) {
|
|
437
|
-
while (child.firstChild) parent.insertBefore(child.firstChild, child);
|
|
438
|
-
child.remove();
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
sanitizeAttributes(child, tag);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function sanitizeAttributes(element, tag) {
|
|
445
|
-
const allowed = ALLOWED_ATTRIBUTES[tag];
|
|
446
|
-
for (const attribute of Array.from(element.attributes)) {
|
|
447
|
-
const name = attribute.name.toLowerCase();
|
|
448
|
-
if (name.startsWith("on")) {
|
|
449
|
-
element.removeAttribute(attribute.name);
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
if (!GLOBAL_ATTRIBUTES.has(name) && !allowed?.has(name)) {
|
|
453
|
-
element.removeAttribute(attribute.name);
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
if (URL_ATTRIBUTES.has(name)) {
|
|
457
|
-
const safe = sanitizeUrl(attribute.value);
|
|
458
|
-
if (safe === "about:blank") element.removeAttribute(attribute.name);
|
|
459
|
-
else element.setAttribute(attribute.name, safe);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if (tag === "a" && element.getAttribute("target")) element.setAttribute("rel", "noopener noreferrer");
|
|
463
|
-
}
|
|
464
|
-
//#endregion
|
|
465
|
-
//#region src/editor/extensions/TextLoadingDecorationExtension.tsx
|
|
466
|
-
var loadingDecorationKey = new PluginKey("loadingDecoration");
|
|
467
|
-
var textLoadingCommands = {
|
|
468
|
-
toggleLoadingDecoration: (state, dispatch, loadingHtml) => {
|
|
469
|
-
const { selection } = state;
|
|
470
|
-
const pos = selection.from;
|
|
471
|
-
if (!dispatch) return false;
|
|
472
|
-
dispatch(state.tr.setMeta(loadingDecorationKey, {
|
|
473
|
-
pos,
|
|
474
|
-
type: "loadingDecoration",
|
|
475
|
-
remove: false,
|
|
476
|
-
loadingHtml
|
|
477
|
-
}));
|
|
478
|
-
return true;
|
|
479
|
-
},
|
|
480
|
-
removeLoadingDecoration: (state, dispatch) => {
|
|
481
|
-
if (!dispatch) return false;
|
|
482
|
-
dispatch(state.tr.setMeta(loadingDecorationKey, {
|
|
483
|
-
pos: 0,
|
|
484
|
-
type: "loadingDecoration",
|
|
485
|
-
remove: true
|
|
486
|
-
}));
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
/**
|
|
491
|
-
* This plugin is used to display streaming content from an LLM.
|
|
492
|
-
*/
|
|
493
|
-
var textLoadingDecorationPlugin = () => {
|
|
494
|
-
return new Plugin({
|
|
495
|
-
key: loadingDecorationKey,
|
|
496
|
-
state: {
|
|
497
|
-
init() {
|
|
498
|
-
return {
|
|
499
|
-
decorationSet: DecorationSet.empty,
|
|
500
|
-
hasDecoration: false
|
|
501
|
-
};
|
|
502
|
-
},
|
|
503
|
-
apply(tr, oldState) {
|
|
504
|
-
const action = tr.getMeta(loadingDecorationKey);
|
|
505
|
-
if (action?.type === "loadingDecoration") {
|
|
506
|
-
const { pos, remove, loadingHtml } = action;
|
|
507
|
-
if (remove) return {
|
|
508
|
-
decorationSet: DecorationSet.empty,
|
|
509
|
-
hasDecoration: false
|
|
510
|
-
};
|
|
511
|
-
const decoration = Decoration.widget(pos, () => {
|
|
512
|
-
const container = document.createElement("span");
|
|
513
|
-
container.className = "loading-decoration";
|
|
514
|
-
if (loadingHtml) {
|
|
515
|
-
const safe = parseSanitizedHtml(loadingHtml);
|
|
516
|
-
while (safe.firstChild) container.appendChild(safe.firstChild);
|
|
517
|
-
} else {
|
|
518
|
-
const span = document.createElement("span");
|
|
519
|
-
span.innerText = "loading...";
|
|
520
|
-
container.appendChild(span);
|
|
521
|
-
}
|
|
522
|
-
return container;
|
|
523
|
-
});
|
|
524
|
-
return {
|
|
525
|
-
decorationSet: DecorationSet.empty.add(tr.doc, [decoration]),
|
|
526
|
-
hasDecoration: true
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
return {
|
|
530
|
-
decorationSet: oldState.decorationSet.map(tr.mapping, tr.doc),
|
|
531
|
-
hasDecoration: oldState.hasDecoration
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
props: { decorations(state) {
|
|
536
|
-
return this.getState(state)?.decorationSet || DecorationSet.empty;
|
|
537
|
-
} }
|
|
538
|
-
});
|
|
539
|
-
};
|
|
540
|
-
//#endregion
|
|
541
|
-
//#region src/editor/components/SlashCommandMenu.tsx
|
|
542
|
-
var suggestionItems = [
|
|
543
|
-
{
|
|
544
|
-
title: "Text",
|
|
545
|
-
description: "Just start typing with plain text.",
|
|
546
|
-
searchTerms: ["p", "paragraph"],
|
|
547
|
-
icon: /* @__PURE__ */ jsx(TypeIcon, { size: iconSize.small }),
|
|
548
|
-
command: (view, range) => {
|
|
549
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
550
|
-
setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);
|
|
551
|
-
}
|
|
552
|
-
},
|
|
553
|
-
{
|
|
554
|
-
title: "To-do List",
|
|
555
|
-
description: "Track tasks with a to-do list.",
|
|
556
|
-
searchTerms: [
|
|
557
|
-
"todo",
|
|
558
|
-
"task",
|
|
559
|
-
"list",
|
|
560
|
-
"check",
|
|
561
|
-
"checkbox"
|
|
562
|
-
],
|
|
563
|
-
icon: /* @__PURE__ */ jsx(CheckSquareIcon, { size: iconSize.small }),
|
|
564
|
-
command: (view, range) => {
|
|
565
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
566
|
-
wrapInList(schema.nodes.task_list)(view.state, view.dispatch);
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
title: "Heading 1",
|
|
571
|
-
description: "Big section heading.",
|
|
572
|
-
searchTerms: [
|
|
573
|
-
"title",
|
|
574
|
-
"big",
|
|
575
|
-
"large"
|
|
576
|
-
],
|
|
577
|
-
icon: /* @__PURE__ */ jsx(Heading1Icon, { size: iconSize.small }),
|
|
578
|
-
command: (view, range) => {
|
|
579
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
580
|
-
setBlockType(schema.nodes.heading, { level: 1 })(view.state, view.dispatch);
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
title: "Heading 2",
|
|
585
|
-
description: "Medium section heading.",
|
|
586
|
-
searchTerms: ["subtitle", "medium"],
|
|
587
|
-
icon: /* @__PURE__ */ jsx(Heading2Icon, { size: iconSize.small }),
|
|
588
|
-
command: (view, range) => {
|
|
589
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
590
|
-
setBlockType(schema.nodes.heading, { level: 2 })(view.state, view.dispatch);
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
title: "Heading 3",
|
|
595
|
-
description: "Small section heading.",
|
|
596
|
-
searchTerms: ["subtitle", "small"],
|
|
597
|
-
icon: /* @__PURE__ */ jsx(Heading3Icon, { size: iconSize.small }),
|
|
598
|
-
command: (view, range) => {
|
|
599
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
600
|
-
setBlockType(schema.nodes.heading, { level: 3 })(view.state, view.dispatch);
|
|
601
|
-
}
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
title: "Bullet List",
|
|
605
|
-
description: "Create a simple bullet list.",
|
|
606
|
-
searchTerms: ["unordered", "point"],
|
|
607
|
-
icon: /* @__PURE__ */ jsx(ListIcon, { size: iconSize.small }),
|
|
608
|
-
command: (view, range) => {
|
|
609
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
610
|
-
wrapInList(schema.nodes.bullet_list)(view.state, view.dispatch);
|
|
611
|
-
}
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
title: "Numbered List",
|
|
615
|
-
description: "Create a list with numbering.",
|
|
616
|
-
searchTerms: ["ordered"],
|
|
617
|
-
icon: /* @__PURE__ */ jsx(ListOrderedIcon, { size: iconSize.small }),
|
|
618
|
-
command: (view, range) => {
|
|
619
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
620
|
-
wrapInList(schema.nodes.ordered_list)(view.state, view.dispatch);
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
title: "Quote",
|
|
625
|
-
description: "Capture a quote.",
|
|
626
|
-
searchTerms: ["blockquote"],
|
|
627
|
-
icon: /* @__PURE__ */ jsx(QuoteIcon, { size: iconSize.small }),
|
|
628
|
-
command: (view, range) => {
|
|
629
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
630
|
-
wrapIn(schema.nodes.blockquote)(view.state, view.dispatch);
|
|
631
|
-
}
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
title: "Code",
|
|
635
|
-
description: "Capture a code snippet.",
|
|
636
|
-
searchTerms: ["codeblock"],
|
|
637
|
-
icon: /* @__PURE__ */ jsx(CodeIcon, { size: iconSize.small }),
|
|
638
|
-
command: (view, range) => {
|
|
639
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
640
|
-
setBlockType(schema.nodes.code_block)(view.state, view.dispatch);
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
{
|
|
644
|
-
title: "Image",
|
|
645
|
-
description: "Upload an image from your computer.",
|
|
646
|
-
searchTerms: [
|
|
647
|
-
"photo",
|
|
648
|
-
"picture",
|
|
649
|
-
"media",
|
|
650
|
-
"upload",
|
|
651
|
-
"file"
|
|
652
|
-
],
|
|
653
|
-
icon: /* @__PURE__ */ jsx(ImageIcon, { size: iconSize.small }),
|
|
654
|
-
command: (view, range, upload) => {
|
|
655
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
656
|
-
const input = document.createElement("input");
|
|
657
|
-
input.type = "file";
|
|
658
|
-
input.accept = "image/*";
|
|
659
|
-
input.onchange = async () => {
|
|
660
|
-
if (input.files?.length) {
|
|
661
|
-
if (!input.files[0]) return;
|
|
662
|
-
const pos = view.state.selection.from;
|
|
663
|
-
const images = Array.from(input.files).filter((f) => /image/i.test(f.type));
|
|
664
|
-
if (images.length === 0) return false;
|
|
665
|
-
images.forEach((image) => {
|
|
666
|
-
const reader = new FileReader();
|
|
667
|
-
reader.onload = async (readerEvent) => {
|
|
668
|
-
await onFileRead(view, readerEvent, pos, upload, image);
|
|
669
|
-
};
|
|
670
|
-
reader.readAsDataURL(image);
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
return true;
|
|
674
|
-
};
|
|
675
|
-
input.click();
|
|
676
|
-
}
|
|
677
|
-
},
|
|
678
|
-
{
|
|
679
|
-
title: "Table",
|
|
680
|
-
description: "Insert a custom grid table.",
|
|
681
|
-
searchTerms: [
|
|
682
|
-
"table",
|
|
683
|
-
"grid",
|
|
684
|
-
"row",
|
|
685
|
-
"col"
|
|
686
|
-
],
|
|
687
|
-
icon: /* @__PURE__ */ jsx(TableIcon, { size: iconSize.small }),
|
|
688
|
-
command: (view, range, upload, aiController, setSubView) => {
|
|
689
|
-
if (setSubView) setSubView("table-grid");
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
];
|
|
693
|
-
var autocompleteSuggestionItem = {
|
|
694
|
-
title: "Autocomplete",
|
|
695
|
-
description: "Add text based on the context.",
|
|
696
|
-
searchTerms: ["ai"],
|
|
697
|
-
icon: /* @__PURE__ */ jsx(Wand2Icon, { size: iconSize.small }),
|
|
698
|
-
command: async (view, range, upload, aiController) => {
|
|
699
|
-
if (!aiController) throw Error("No AiController");
|
|
700
|
-
view.dispatch(view.state.tr.deleteRange(range.from, range.to));
|
|
701
|
-
setBlockType(schema.nodes.paragraph)(view.state, view.dispatch);
|
|
702
|
-
const { state } = view;
|
|
703
|
-
const { from, to } = state.selection;
|
|
704
|
-
const textBeforeCursor = state.doc.textBetween(0, from, "\n");
|
|
705
|
-
const textAfterCursor = state.doc.textBetween(to, state.doc.content.size, "\n");
|
|
706
|
-
let buffer = "";
|
|
707
|
-
const result = await aiController.autocomplete(textBeforeCursor, textAfterCursor, (delta) => {
|
|
708
|
-
buffer += delta;
|
|
709
|
-
if (delta.length !== 0) textLoadingCommands.toggleLoadingDecoration(view.state, view.dispatch, buffer);
|
|
710
|
-
});
|
|
711
|
-
try {
|
|
712
|
-
const unescapedResult = result.replace(/\\n/g, "\n").replace(/\\t/g, " ");
|
|
713
|
-
const isHTML = /<\/?[a-z][\s\S]*>/i.test(unescapedResult);
|
|
714
|
-
let parsedDoc;
|
|
715
|
-
if (isHTML) parsedDoc = DOMParser$1.fromSchema(view.state.schema).parse(parseSanitizedHtml(unescapedResult));
|
|
716
|
-
else parsedDoc = parser.parse(unescapedResult);
|
|
717
|
-
if (parsedDoc) {
|
|
718
|
-
const tr = view.state.tr.replaceWith(view.state.selection.from, view.state.selection.from, parsedDoc.content);
|
|
719
|
-
view.dispatch(tr);
|
|
720
|
-
} else view.dispatch(view.state.tr.insertText(unescapedResult));
|
|
721
|
-
} catch (e) {
|
|
722
|
-
console.error(e);
|
|
723
|
-
view.dispatch(view.state.tr.insertText(result));
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
};
|
|
727
|
-
var SlashCommandMenu = ({ upload, aiController }) => {
|
|
728
|
-
const { view, state } = useProseMirrorContext();
|
|
729
|
-
const menuRef = useRef(null);
|
|
730
|
-
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
731
|
-
const [subView, setSubView] = useState(null);
|
|
732
|
-
const [tableGridCoords, setTableGridCoords] = useState({
|
|
733
|
-
r: 0,
|
|
734
|
-
c: 0
|
|
735
|
-
});
|
|
736
|
-
const pluginState = state ? SlashCommandPluginKey.getState(state) : null;
|
|
737
|
-
const isActive = pluginState?.active;
|
|
738
|
-
const query = pluginState?.query || "";
|
|
739
|
-
const range = pluginState?.range;
|
|
740
|
-
const filteredItems = React.useMemo(() => {
|
|
741
|
-
if (!isActive) return [];
|
|
742
|
-
const availableItems = [...suggestionItems];
|
|
743
|
-
if (aiController) availableItems.push(autocompleteSuggestionItem);
|
|
744
|
-
return availableItems.filter((item) => {
|
|
745
|
-
const inTitle = item.title.toLowerCase().includes(query.toLowerCase());
|
|
746
|
-
if (inTitle) return inTitle;
|
|
747
|
-
return item.searchTerms?.some((term) => term.toLowerCase().includes(query.toLowerCase()));
|
|
748
|
-
});
|
|
749
|
-
}, [
|
|
750
|
-
query,
|
|
751
|
-
isActive,
|
|
752
|
-
aiController
|
|
753
|
-
]);
|
|
754
|
-
useEffect(() => {
|
|
755
|
-
setSelectedIndex(0);
|
|
756
|
-
}, [query]);
|
|
757
|
-
useEffect(() => {
|
|
758
|
-
if (!isActive) setSubView(null);
|
|
759
|
-
}, [isActive]);
|
|
760
|
-
useEffect(() => {
|
|
761
|
-
if (!view || !isActive || !range || !menuRef.current) return;
|
|
762
|
-
const start = view.coordsAtPos(range.from);
|
|
763
|
-
const virtualEl = { getBoundingClientRect() {
|
|
764
|
-
return {
|
|
765
|
-
width: 0,
|
|
766
|
-
height: start.bottom - start.top,
|
|
767
|
-
x: start.left,
|
|
768
|
-
y: start.top,
|
|
769
|
-
top: start.top,
|
|
770
|
-
left: start.left,
|
|
771
|
-
right: start.left,
|
|
772
|
-
bottom: start.bottom
|
|
773
|
-
};
|
|
774
|
-
} };
|
|
775
|
-
const cleanup = autoUpdate(virtualEl, menuRef.current, () => {
|
|
776
|
-
if (!menuRef.current) return;
|
|
777
|
-
computePosition(virtualEl, menuRef.current, {
|
|
778
|
-
placement: "bottom-start",
|
|
779
|
-
middleware: [
|
|
780
|
-
offset(4),
|
|
781
|
-
flip(),
|
|
782
|
-
shift()
|
|
783
|
-
],
|
|
784
|
-
strategy: "fixed"
|
|
785
|
-
}).then(({ x, y }) => {
|
|
786
|
-
if (menuRef.current) Object.assign(menuRef.current.style, {
|
|
787
|
-
left: `${x}px`,
|
|
788
|
-
top: `${y}px`,
|
|
789
|
-
visibility: "visible"
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
});
|
|
793
|
-
return () => cleanup();
|
|
794
|
-
}, [
|
|
795
|
-
view,
|
|
796
|
-
isActive,
|
|
797
|
-
range
|
|
798
|
-
]);
|
|
799
|
-
useEffect(() => {
|
|
800
|
-
if (!isActive || !view) return;
|
|
801
|
-
const handleKeyDown = (e) => {
|
|
802
|
-
if (subView === "table-grid") {
|
|
803
|
-
if (e.key === "Escape") {
|
|
804
|
-
e.preventDefault();
|
|
805
|
-
e.stopPropagation();
|
|
806
|
-
e.stopImmediatePropagation();
|
|
807
|
-
setSubView(null);
|
|
808
|
-
setTableGridCoords({
|
|
809
|
-
r: 0,
|
|
810
|
-
c: 0
|
|
811
|
-
});
|
|
812
|
-
} else if (e.key === "ArrowUp") {
|
|
813
|
-
e.preventDefault();
|
|
814
|
-
e.stopPropagation();
|
|
815
|
-
setTableGridCoords((prev) => ({
|
|
816
|
-
r: Math.max(0, prev.r - 1),
|
|
817
|
-
c: prev.c
|
|
818
|
-
}));
|
|
819
|
-
} else if (e.key === "ArrowDown") {
|
|
820
|
-
e.preventDefault();
|
|
821
|
-
e.stopPropagation();
|
|
822
|
-
setTableGridCoords((prev) => ({
|
|
823
|
-
r: Math.min(4, prev.r + 1),
|
|
824
|
-
c: prev.c
|
|
825
|
-
}));
|
|
826
|
-
} else if (e.key === "ArrowLeft") {
|
|
827
|
-
e.preventDefault();
|
|
828
|
-
e.stopPropagation();
|
|
829
|
-
setTableGridCoords((prev) => ({
|
|
830
|
-
r: prev.r,
|
|
831
|
-
c: Math.max(0, prev.c - 1)
|
|
832
|
-
}));
|
|
833
|
-
} else if (e.key === "ArrowRight") {
|
|
834
|
-
e.preventDefault();
|
|
835
|
-
e.stopPropagation();
|
|
836
|
-
setTableGridCoords((prev) => ({
|
|
837
|
-
r: prev.r,
|
|
838
|
-
c: Math.min(4, prev.c + 1)
|
|
839
|
-
}));
|
|
840
|
-
} else if (e.key === "Enter") {
|
|
841
|
-
e.preventDefault();
|
|
842
|
-
e.stopPropagation();
|
|
843
|
-
if (range) {
|
|
844
|
-
const tableNode = createTableNode(view.state.schema, tableGridCoords.r + 1, tableGridCoords.c + 1);
|
|
845
|
-
const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);
|
|
846
|
-
try {
|
|
847
|
-
const selection = TextSelection.create(tr.doc, range.from + 4);
|
|
848
|
-
tr.setSelection(selection);
|
|
849
|
-
} catch (e) {
|
|
850
|
-
console.warn("Could not select first cell", e);
|
|
851
|
-
}
|
|
852
|
-
tr.setMeta(SlashCommandPluginKey, { active: false });
|
|
853
|
-
view.dispatch(tr);
|
|
854
|
-
view.focus();
|
|
855
|
-
setSubView(null);
|
|
856
|
-
setTableGridCoords({
|
|
857
|
-
r: 0,
|
|
858
|
-
c: 0
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
if (e.key === "ArrowUp") {
|
|
865
|
-
e.preventDefault();
|
|
866
|
-
e.stopPropagation();
|
|
867
|
-
setSelectedIndex((prev) => (prev + filteredItems.length - 1) % filteredItems.length);
|
|
868
|
-
} else if (e.key === "ArrowDown") {
|
|
869
|
-
e.preventDefault();
|
|
870
|
-
e.stopPropagation();
|
|
871
|
-
setSelectedIndex((prev) => (prev + 1) % filteredItems.length);
|
|
872
|
-
} else if (e.key === "Enter") {
|
|
873
|
-
e.preventDefault();
|
|
874
|
-
e.stopPropagation();
|
|
875
|
-
if (filteredItems[selectedIndex] && range) {
|
|
876
|
-
filteredItems[selectedIndex].command(view, range, upload, aiController, setSubView);
|
|
877
|
-
setTimeout(() => {}, 0);
|
|
878
|
-
}
|
|
879
|
-
} else if (e.key === "Escape") {
|
|
880
|
-
e.preventDefault();
|
|
881
|
-
e.stopPropagation();
|
|
882
|
-
e.stopImmediatePropagation();
|
|
883
|
-
view.dispatch(view.state.tr.setMeta(SlashCommandPluginKey, {
|
|
884
|
-
active: false,
|
|
885
|
-
dismissed: true
|
|
886
|
-
}));
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
window.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
890
|
-
return () => window.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
891
|
-
}, [
|
|
892
|
-
isActive,
|
|
893
|
-
selectedIndex,
|
|
894
|
-
filteredItems,
|
|
895
|
-
view,
|
|
896
|
-
range,
|
|
897
|
-
upload,
|
|
898
|
-
aiController,
|
|
899
|
-
subView,
|
|
900
|
-
tableGridCoords
|
|
901
|
-
]);
|
|
902
|
-
const itemRefs = useRef([]);
|
|
903
|
-
useEffect(() => {
|
|
904
|
-
if (itemRefs.current[selectedIndex]) itemRefs.current[selectedIndex]?.scrollIntoView({ block: "nearest" });
|
|
905
|
-
}, [selectedIndex]);
|
|
906
|
-
useEffect(() => {
|
|
907
|
-
if (!subView) setTableGridCoords({
|
|
908
|
-
r: 0,
|
|
909
|
-
c: 0
|
|
910
|
-
});
|
|
911
|
-
}, [subView]);
|
|
912
|
-
if (!isActive || filteredItems.length === 0) return null;
|
|
913
|
-
if (subView === "table-grid" && range && view) return /* @__PURE__ */ jsx("div", {
|
|
914
|
-
ref: menuRef,
|
|
915
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
916
|
-
style: {
|
|
917
|
-
position: "fixed",
|
|
918
|
-
zIndex: 9999,
|
|
919
|
-
visibility: "hidden"
|
|
920
|
-
},
|
|
921
|
-
className: cls("text-surface-900 dark:text-white rounded-md border bg-surface-card p-2 shadow transition-none", defaultBorderMixin),
|
|
922
|
-
children: /* @__PURE__ */ jsx(TableGridPicker, {
|
|
923
|
-
hoveredRow: tableGridCoords.r,
|
|
924
|
-
hoveredCol: tableGridCoords.c,
|
|
925
|
-
onHover: (r, c) => setTableGridCoords({
|
|
926
|
-
r,
|
|
927
|
-
c
|
|
928
|
-
}),
|
|
929
|
-
onSelect: (rows, cols) => {
|
|
930
|
-
const tableNode = createTableNode(view.state.schema, rows, cols);
|
|
931
|
-
const tr = view.state.tr.replaceWith(range.from, range.to, tableNode);
|
|
932
|
-
try {
|
|
933
|
-
const selection = TextSelection.create(tr.doc, range.from + 4);
|
|
934
|
-
tr.setSelection(selection);
|
|
935
|
-
} catch (e) {
|
|
936
|
-
console.warn("Could not select first cell", e);
|
|
937
|
-
}
|
|
938
|
-
tr.setMeta(SlashCommandPluginKey, { active: false });
|
|
939
|
-
view.dispatch(tr);
|
|
940
|
-
view.focus();
|
|
941
|
-
setSubView(null);
|
|
942
|
-
}
|
|
943
|
-
})
|
|
944
|
-
});
|
|
945
|
-
return /* @__PURE__ */ jsx("div", {
|
|
946
|
-
ref: menuRef,
|
|
947
|
-
style: {
|
|
948
|
-
position: "fixed",
|
|
949
|
-
zIndex: 9999,
|
|
950
|
-
visibility: "hidden"
|
|
951
|
-
},
|
|
952
|
-
className: cls("text-surface-900 dark:text-white max-h-[280px] w-72 overflow-y-auto rounded-md border bg-surface-card px-1 py-2 shadow transition-none", defaultBorderMixin),
|
|
953
|
-
children: filteredItems.map((item, index) => /* @__PURE__ */ jsxs("button", {
|
|
954
|
-
ref: (el) => {
|
|
955
|
-
itemRefs.current[index] = el;
|
|
956
|
-
},
|
|
957
|
-
onClick: (e) => {
|
|
958
|
-
e.preventDefault();
|
|
959
|
-
if (range && view) {
|
|
960
|
-
item.command(view, range, upload, aiController, setSubView);
|
|
961
|
-
if (!subView) view.focus();
|
|
962
|
-
}
|
|
963
|
-
},
|
|
964
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
965
|
-
className: cls("flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-surface-hover", index === selectedIndex ? "bg-surface-active" : ""),
|
|
966
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
967
|
-
className: cls("flex h-10 w-10 shrink-0 items-center justify-center rounded-md border bg-surface-card", defaultBorderMixin),
|
|
968
|
-
children: item.icon
|
|
969
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
970
|
-
className: "flex flex-col overflow-hidden",
|
|
971
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
972
|
-
className: "font-medium truncate",
|
|
973
|
-
children: item.title
|
|
974
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
975
|
-
className: "text-xs text-surface-700 dark:text-surface-accent-300 truncate",
|
|
976
|
-
children: item.description
|
|
977
|
-
})]
|
|
978
|
-
})]
|
|
979
|
-
}, item.title))
|
|
980
|
-
});
|
|
981
|
-
};
|
|
982
|
-
var createTableNode = (schema, rowsCount, colsCount) => {
|
|
983
|
-
const rows = [];
|
|
984
|
-
for (let r = 0; r < rowsCount; r++) {
|
|
985
|
-
const cells = [];
|
|
986
|
-
for (let c = 0; c < colsCount; c++) {
|
|
987
|
-
const cell = (r === 0 ? schema.nodes.table_header : schema.nodes.table_cell).createAndFill();
|
|
988
|
-
if (cell) cells.push(cell);
|
|
989
|
-
}
|
|
990
|
-
const row = schema.nodes.table_row.create(null, Fragment$1.from(cells));
|
|
991
|
-
rows.push(row);
|
|
992
|
-
}
|
|
993
|
-
return schema.nodes.table.create(null, Fragment$1.from(rows));
|
|
994
|
-
};
|
|
995
|
-
var TableGridPicker = ({ hoveredRow, hoveredCol, onHover, onSelect }) => {
|
|
996
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
997
|
-
className: "flex flex-col gap-1 items-center justify-center p-1 w-fit",
|
|
998
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
999
|
-
className: "text-xs text-gray-500 font-medium mb-1",
|
|
1000
|
-
children: [
|
|
1001
|
-
hoveredCol + 1,
|
|
1002
|
-
" x ",
|
|
1003
|
-
hoveredRow + 1,
|
|
1004
|
-
" Table"
|
|
1005
|
-
]
|
|
1006
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
1007
|
-
className: "flex flex-col gap-1",
|
|
1008
|
-
children: Array.from({ length: 5 }).map((_, r) => /* @__PURE__ */ jsx("div", {
|
|
1009
|
-
className: "flex gap-1",
|
|
1010
|
-
children: Array.from({ length: 5 }).map((_, c) => /* @__PURE__ */ jsx("div", {
|
|
1011
|
-
className: cls("w-5 h-5 border rounded-sm cursor-pointer transition-colors duration-75", r <= hoveredRow && c <= hoveredCol ? "bg-blue-100 border-blue-400 dark:bg-blue-900 dark:border-blue-500" : "bg-surface-card border-gray-200 dark:border-gray-700 hover:border-blue-300"),
|
|
1012
|
-
onMouseEnter: () => onHover(r, c),
|
|
1013
|
-
onClick: () => onSelect(hoveredRow + 1, hoveredCol + 1)
|
|
1014
|
-
}, c))
|
|
1015
|
-
}, r))
|
|
1016
|
-
})]
|
|
1017
|
-
});
|
|
1018
|
-
};
|
|
1019
|
-
//#endregion
|
|
1020
|
-
//#region src/editor/components/image-bubble.tsx
|
|
1021
|
-
var ImageBubble = forwardRef(({ options, className }, ref) => {
|
|
1022
|
-
const { view, state } = useProseMirrorContext();
|
|
1023
|
-
const { t } = useTranslation();
|
|
1024
|
-
const menuRef = useRef(null);
|
|
1025
|
-
const [show, setShow] = useState(false);
|
|
1026
|
-
const [alt, setAlt] = useState("");
|
|
1027
|
-
const [title, setTitle] = useState("");
|
|
1028
|
-
const [imagePos, setImagePos] = useState(null);
|
|
1029
|
-
useEffect(() => {
|
|
1030
|
-
if (!view) return;
|
|
1031
|
-
const handleContextMenu = (e) => {
|
|
1032
|
-
const posInfo = view.posAtCoords({
|
|
1033
|
-
left: e.clientX,
|
|
1034
|
-
top: e.clientY
|
|
1035
|
-
});
|
|
1036
|
-
if (posInfo && posInfo.inside >= 0) {
|
|
1037
|
-
const node = view.state.doc.nodeAt(posInfo.inside);
|
|
1038
|
-
if (node && node.type.name === "image") {
|
|
1039
|
-
e.preventDefault();
|
|
1040
|
-
const tr = view.state.tr.setSelection(NodeSelection.create(view.state.doc, posInfo.inside));
|
|
1041
|
-
view.dispatch(tr);
|
|
1042
|
-
setShow(true);
|
|
1043
|
-
setAlt(node.attrs.alt || "");
|
|
1044
|
-
setTitle(node.attrs.title || "");
|
|
1045
|
-
setImagePos(posInfo.inside);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
view.dom.addEventListener("contextmenu", handleContextMenu);
|
|
1050
|
-
const handleMousedown = (e) => {
|
|
1051
|
-
if (menuRef.current && !menuRef.current.contains(e.target) && e.button !== 2) setShow(false);
|
|
1052
|
-
};
|
|
1053
|
-
document.addEventListener("mousedown", handleMousedown);
|
|
1054
|
-
return () => {
|
|
1055
|
-
view.dom.removeEventListener("contextmenu", handleContextMenu);
|
|
1056
|
-
document.removeEventListener("mousedown", handleMousedown);
|
|
1057
|
-
};
|
|
1058
|
-
}, [view]);
|
|
1059
|
-
useEffect(() => {
|
|
1060
|
-
if (!show || !view || !state || !menuRef.current) return;
|
|
1061
|
-
const { from, to } = state.selection;
|
|
1062
|
-
let start = view.coordsAtPos(from);
|
|
1063
|
-
let end = view.coordsAtPos(to);
|
|
1064
|
-
const virtualEl = { getBoundingClientRect() {
|
|
1065
|
-
const top = Math.min(start.top, end.top);
|
|
1066
|
-
const bottom = Math.max(start.bottom, end.bottom);
|
|
1067
|
-
const left = Math.min(start.left, end.left);
|
|
1068
|
-
const right = Math.max(start.right, end.right);
|
|
1069
|
-
return {
|
|
1070
|
-
width: right - left,
|
|
1071
|
-
height: bottom - top,
|
|
1072
|
-
x: left,
|
|
1073
|
-
y: top,
|
|
1074
|
-
top,
|
|
1075
|
-
left,
|
|
1076
|
-
right,
|
|
1077
|
-
bottom
|
|
1078
|
-
};
|
|
1079
|
-
} };
|
|
1080
|
-
const cleanup = autoUpdate(virtualEl, menuRef.current, () => {
|
|
1081
|
-
if (!menuRef.current) return;
|
|
1082
|
-
try {
|
|
1083
|
-
start = view.coordsAtPos(state.selection.from);
|
|
1084
|
-
end = view.coordsAtPos(state.selection.to);
|
|
1085
|
-
} catch (e) {}
|
|
1086
|
-
computePosition(virtualEl, menuRef.current, {
|
|
1087
|
-
placement: options?.placement || "bottom",
|
|
1088
|
-
middleware: [
|
|
1089
|
-
offset(options?.offset || 8),
|
|
1090
|
-
flip(),
|
|
1091
|
-
shift()
|
|
1092
|
-
],
|
|
1093
|
-
strategy: "fixed"
|
|
1094
|
-
}).then(({ x, y }) => {
|
|
1095
|
-
if (menuRef.current) Object.assign(menuRef.current.style, {
|
|
1096
|
-
left: `${x}px`,
|
|
1097
|
-
top: `${y}px`,
|
|
1098
|
-
visibility: "visible"
|
|
1099
|
-
});
|
|
1100
|
-
});
|
|
1101
|
-
});
|
|
1102
|
-
return () => cleanup();
|
|
1103
|
-
}, [
|
|
1104
|
-
show,
|
|
1105
|
-
view,
|
|
1106
|
-
state,
|
|
1107
|
-
options
|
|
1108
|
-
]);
|
|
1109
|
-
const handleSave = (newAlt, newTitle) => {
|
|
1110
|
-
if (imagePos !== null && view) {
|
|
1111
|
-
const node = view.state.doc.nodeAt(imagePos);
|
|
1112
|
-
if (node && node.type.name === "image") {
|
|
1113
|
-
const tr = view.state.tr.setNodeMarkup(imagePos, void 0, {
|
|
1114
|
-
...node.attrs,
|
|
1115
|
-
alt: newAlt,
|
|
1116
|
-
title: newTitle
|
|
1117
|
-
});
|
|
1118
|
-
tr.setSelection(NodeSelection.create(tr.doc, imagePos));
|
|
1119
|
-
view.dispatch(tr);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
|
-
if (!show) return null;
|
|
1124
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1125
|
-
ref: menuRef,
|
|
1126
|
-
style: {
|
|
1127
|
-
visibility: "hidden",
|
|
1128
|
-
position: "fixed",
|
|
1129
|
-
zIndex: 50
|
|
1130
|
-
},
|
|
1131
|
-
className: cls("flex flex-col gap-1.5 p-2 w-56 max-w-[90vw] rounded-lg border bg-surface-card shadow-lg", defaultBorderMixin, className),
|
|
1132
|
-
onMouseDown: (e) => {
|
|
1133
|
-
if (e.target === e.currentTarget) e.preventDefault();
|
|
1134
|
-
},
|
|
1135
|
-
children: [/* @__PURE__ */ jsx(TextField, {
|
|
1136
|
-
size: "small",
|
|
1137
|
-
"aria-label": t("alt_text"),
|
|
1138
|
-
placeholder: t("alt_text"),
|
|
1139
|
-
value: alt,
|
|
1140
|
-
onChange: (e) => {
|
|
1141
|
-
setAlt(e.target.value);
|
|
1142
|
-
handleSave(e.target.value, title);
|
|
1143
|
-
}
|
|
1144
|
-
}), /* @__PURE__ */ jsx(TextField, {
|
|
1145
|
-
size: "small",
|
|
1146
|
-
"aria-label": t("title"),
|
|
1147
|
-
placeholder: t("title"),
|
|
1148
|
-
value: title,
|
|
1149
|
-
onChange: (e) => {
|
|
1150
|
-
setTitle(e.target.value);
|
|
1151
|
-
handleSave(alt, e.target.value);
|
|
1152
|
-
}
|
|
1153
|
-
})]
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
1156
|
-
ImageBubble.displayName = "ImageBubble";
|
|
1157
|
-
//#endregion
|
|
1158
|
-
//#region src/editor/components/table-bubble.tsx
|
|
1159
|
-
var isSelectionInTable = (state) => {
|
|
1160
|
-
const { $from } = state.selection;
|
|
1161
|
-
for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === "table") return true;
|
|
1162
|
-
return false;
|
|
1163
|
-
};
|
|
1164
|
-
var TableBubble = forwardRef(({ options, className }, ref) => {
|
|
1165
|
-
const { view, state } = useProseMirrorContext();
|
|
1166
|
-
const { t } = useTranslation();
|
|
1167
|
-
const menuRef = useRef(null);
|
|
1168
|
-
const [show, setShow] = useState(false);
|
|
1169
|
-
useEffect(() => {
|
|
1170
|
-
if (!state) return;
|
|
1171
|
-
setShow(isSelectionInTable(state));
|
|
1172
|
-
}, [state?.selection]);
|
|
1173
|
-
useEffect(() => {
|
|
1174
|
-
if (!show || !view || !state || !menuRef.current) return;
|
|
1175
|
-
const { from, to } = state.selection;
|
|
1176
|
-
if (view.isDestroyed) return;
|
|
1177
|
-
let start = view.coordsAtPos(from);
|
|
1178
|
-
let end = view.coordsAtPos(to);
|
|
1179
|
-
const virtualEl = { getBoundingClientRect() {
|
|
1180
|
-
const top = Math.min(start.top, end.top);
|
|
1181
|
-
const bottom = Math.max(start.bottom, end.bottom);
|
|
1182
|
-
const left = Math.min(start.left, end.left);
|
|
1183
|
-
const right = Math.max(start.right, end.right);
|
|
1184
|
-
return {
|
|
1185
|
-
width: right - left,
|
|
1186
|
-
height: bottom - top,
|
|
1187
|
-
x: left,
|
|
1188
|
-
y: top,
|
|
1189
|
-
top,
|
|
1190
|
-
bottom,
|
|
1191
|
-
left,
|
|
1192
|
-
right
|
|
1193
|
-
};
|
|
1194
|
-
} };
|
|
1195
|
-
const cleanup = autoUpdate(virtualEl, menuRef.current, () => {
|
|
1196
|
-
if (!menuRef.current || view.isDestroyed) return;
|
|
1197
|
-
try {
|
|
1198
|
-
start = view.coordsAtPos(state.selection.from);
|
|
1199
|
-
end = view.coordsAtPos(state.selection.to);
|
|
1200
|
-
} catch (e) {}
|
|
1201
|
-
computePosition(virtualEl, menuRef.current, {
|
|
1202
|
-
placement: options?.placement || "top",
|
|
1203
|
-
middleware: [
|
|
1204
|
-
offset(options?.offset || 8),
|
|
1205
|
-
flip(),
|
|
1206
|
-
shift()
|
|
1207
|
-
],
|
|
1208
|
-
strategy: "fixed"
|
|
1209
|
-
}).then(({ x, y }) => {
|
|
1210
|
-
if (menuRef.current) Object.assign(menuRef.current.style, {
|
|
1211
|
-
left: `${x}px`,
|
|
1212
|
-
top: `${y}px`,
|
|
1213
|
-
visibility: "visible"
|
|
1214
|
-
});
|
|
1215
|
-
});
|
|
1216
|
-
});
|
|
1217
|
-
return () => cleanup();
|
|
1218
|
-
}, [
|
|
1219
|
-
show,
|
|
1220
|
-
view,
|
|
1221
|
-
state,
|
|
1222
|
-
options
|
|
1223
|
-
]);
|
|
1224
|
-
if (!show || !view || !state) return null;
|
|
1225
|
-
const executeCommand = (cmd) => {
|
|
1226
|
-
cmd(state, view.dispatch);
|
|
1227
|
-
view.focus();
|
|
1228
|
-
};
|
|
1229
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1230
|
-
ref: menuRef,
|
|
1231
|
-
style: {
|
|
1232
|
-
visibility: "hidden",
|
|
1233
|
-
position: "fixed",
|
|
1234
|
-
zIndex: 50
|
|
1235
|
-
},
|
|
1236
|
-
className: cls("flex flex-row gap-1 p-1 rounded-lg border bg-surface-card shadow-lg", defaultBorderMixin, className),
|
|
1237
|
-
onMouseDown: (e) => {
|
|
1238
|
-
e.preventDefault();
|
|
1239
|
-
},
|
|
1240
|
-
children: [
|
|
1241
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1242
|
-
className: "flex gap-1 border-r pr-1 mr-1 dark:border-gray-700",
|
|
1243
|
-
children: [
|
|
1244
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1245
|
-
title: t("add_row_before"),
|
|
1246
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1247
|
-
size: "small",
|
|
1248
|
-
onClick: () => executeCommand(addRowBefore),
|
|
1249
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1250
|
-
width: "20",
|
|
1251
|
-
height: "20",
|
|
1252
|
-
viewBox: "0 0 24 24",
|
|
1253
|
-
fill: "none",
|
|
1254
|
-
stroke: "currentColor",
|
|
1255
|
-
strokeWidth: "2",
|
|
1256
|
-
strokeLinecap: "round",
|
|
1257
|
-
strokeLinejoin: "round",
|
|
1258
|
-
children: [
|
|
1259
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1260
|
-
x: "3",
|
|
1261
|
-
y: "3",
|
|
1262
|
-
width: "18",
|
|
1263
|
-
height: "18",
|
|
1264
|
-
rx: "2",
|
|
1265
|
-
ry: "2"
|
|
1266
|
-
}),
|
|
1267
|
-
/* @__PURE__ */ jsx("line", {
|
|
1268
|
-
x1: "12",
|
|
1269
|
-
y1: "8",
|
|
1270
|
-
x2: "12",
|
|
1271
|
-
y2: "16"
|
|
1272
|
-
}),
|
|
1273
|
-
/* @__PURE__ */ jsx("line", {
|
|
1274
|
-
x1: "8",
|
|
1275
|
-
y1: "12",
|
|
1276
|
-
x2: "16",
|
|
1277
|
-
y2: "12"
|
|
1278
|
-
}),
|
|
1279
|
-
/* @__PURE__ */ jsx("line", {
|
|
1280
|
-
x1: "3",
|
|
1281
|
-
y1: "9",
|
|
1282
|
-
x2: "21",
|
|
1283
|
-
y2: "9"
|
|
1284
|
-
})
|
|
1285
|
-
]
|
|
1286
|
-
})
|
|
1287
|
-
})
|
|
1288
|
-
}),
|
|
1289
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1290
|
-
title: t("add_row_after"),
|
|
1291
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1292
|
-
size: "small",
|
|
1293
|
-
onClick: () => executeCommand(addRowAfter),
|
|
1294
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1295
|
-
width: "20",
|
|
1296
|
-
height: "20",
|
|
1297
|
-
viewBox: "0 0 24 24",
|
|
1298
|
-
fill: "none",
|
|
1299
|
-
stroke: "currentColor",
|
|
1300
|
-
strokeWidth: "2",
|
|
1301
|
-
strokeLinecap: "round",
|
|
1302
|
-
strokeLinejoin: "round",
|
|
1303
|
-
children: [
|
|
1304
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1305
|
-
x: "3",
|
|
1306
|
-
y: "3",
|
|
1307
|
-
width: "18",
|
|
1308
|
-
height: "18",
|
|
1309
|
-
rx: "2",
|
|
1310
|
-
ry: "2"
|
|
1311
|
-
}),
|
|
1312
|
-
/* @__PURE__ */ jsx("line", {
|
|
1313
|
-
x1: "12",
|
|
1314
|
-
y1: "12",
|
|
1315
|
-
x2: "12",
|
|
1316
|
-
y2: "20"
|
|
1317
|
-
}),
|
|
1318
|
-
/* @__PURE__ */ jsx("line", {
|
|
1319
|
-
x1: "8",
|
|
1320
|
-
y1: "16",
|
|
1321
|
-
x2: "16",
|
|
1322
|
-
y2: "16"
|
|
1323
|
-
}),
|
|
1324
|
-
/* @__PURE__ */ jsx("line", {
|
|
1325
|
-
x1: "3",
|
|
1326
|
-
y1: "15",
|
|
1327
|
-
x2: "21",
|
|
1328
|
-
y2: "15"
|
|
1329
|
-
})
|
|
1330
|
-
]
|
|
1331
|
-
})
|
|
1332
|
-
})
|
|
1333
|
-
}),
|
|
1334
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1335
|
-
title: t("delete_row"),
|
|
1336
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1337
|
-
size: "small",
|
|
1338
|
-
onClick: () => executeCommand(deleteRow),
|
|
1339
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1340
|
-
width: "20",
|
|
1341
|
-
height: "20",
|
|
1342
|
-
viewBox: "0 0 24 24",
|
|
1343
|
-
fill: "none",
|
|
1344
|
-
stroke: "currentColor",
|
|
1345
|
-
strokeWidth: "2",
|
|
1346
|
-
strokeLinecap: "round",
|
|
1347
|
-
strokeLinejoin: "round",
|
|
1348
|
-
children: [
|
|
1349
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1350
|
-
x: "3",
|
|
1351
|
-
y: "3",
|
|
1352
|
-
width: "18",
|
|
1353
|
-
height: "18",
|
|
1354
|
-
rx: "2",
|
|
1355
|
-
ry: "2"
|
|
1356
|
-
}),
|
|
1357
|
-
/* @__PURE__ */ jsx("line", {
|
|
1358
|
-
x1: "3",
|
|
1359
|
-
y1: "12",
|
|
1360
|
-
x2: "21",
|
|
1361
|
-
y2: "12"
|
|
1362
|
-
}),
|
|
1363
|
-
/* @__PURE__ */ jsx("line", {
|
|
1364
|
-
x1: "8",
|
|
1365
|
-
y1: "12",
|
|
1366
|
-
x2: "16",
|
|
1367
|
-
y2: "12"
|
|
1368
|
-
})
|
|
1369
|
-
]
|
|
1370
|
-
})
|
|
1371
|
-
})
|
|
1372
|
-
})
|
|
1373
|
-
]
|
|
1374
|
-
}),
|
|
1375
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1376
|
-
className: "flex gap-1 border-r pr-1 mr-1 dark:border-gray-700",
|
|
1377
|
-
children: [
|
|
1378
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1379
|
-
title: t("add_column_before"),
|
|
1380
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1381
|
-
size: "small",
|
|
1382
|
-
onClick: () => executeCommand(addColumnBefore),
|
|
1383
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1384
|
-
width: "20",
|
|
1385
|
-
height: "20",
|
|
1386
|
-
viewBox: "0 0 24 24",
|
|
1387
|
-
fill: "none",
|
|
1388
|
-
stroke: "currentColor",
|
|
1389
|
-
strokeWidth: "2",
|
|
1390
|
-
strokeLinecap: "round",
|
|
1391
|
-
strokeLinejoin: "round",
|
|
1392
|
-
children: [
|
|
1393
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1394
|
-
x: "3",
|
|
1395
|
-
y: "3",
|
|
1396
|
-
width: "18",
|
|
1397
|
-
height: "18",
|
|
1398
|
-
rx: "2",
|
|
1399
|
-
ry: "2"
|
|
1400
|
-
}),
|
|
1401
|
-
/* @__PURE__ */ jsx("line", {
|
|
1402
|
-
x1: "8",
|
|
1403
|
-
y1: "12",
|
|
1404
|
-
x2: "16",
|
|
1405
|
-
y2: "12"
|
|
1406
|
-
}),
|
|
1407
|
-
/* @__PURE__ */ jsx("line", {
|
|
1408
|
-
x1: "12",
|
|
1409
|
-
y1: "8",
|
|
1410
|
-
x2: "12",
|
|
1411
|
-
y2: "16"
|
|
1412
|
-
}),
|
|
1413
|
-
/* @__PURE__ */ jsx("line", {
|
|
1414
|
-
x1: "9",
|
|
1415
|
-
y1: "3",
|
|
1416
|
-
x2: "9",
|
|
1417
|
-
y2: "21"
|
|
1418
|
-
})
|
|
1419
|
-
]
|
|
1420
|
-
})
|
|
1421
|
-
})
|
|
1422
|
-
}),
|
|
1423
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1424
|
-
title: t("add_column_after"),
|
|
1425
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1426
|
-
size: "small",
|
|
1427
|
-
onClick: () => executeCommand(addColumnAfter),
|
|
1428
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1429
|
-
width: "20",
|
|
1430
|
-
height: "20",
|
|
1431
|
-
viewBox: "0 0 24 24",
|
|
1432
|
-
fill: "none",
|
|
1433
|
-
stroke: "currentColor",
|
|
1434
|
-
strokeWidth: "2",
|
|
1435
|
-
strokeLinecap: "round",
|
|
1436
|
-
strokeLinejoin: "round",
|
|
1437
|
-
children: [
|
|
1438
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1439
|
-
x: "3",
|
|
1440
|
-
y: "3",
|
|
1441
|
-
width: "18",
|
|
1442
|
-
height: "18",
|
|
1443
|
-
rx: "2",
|
|
1444
|
-
ry: "2"
|
|
1445
|
-
}),
|
|
1446
|
-
/* @__PURE__ */ jsx("line", {
|
|
1447
|
-
x1: "12",
|
|
1448
|
-
y1: "12",
|
|
1449
|
-
x2: "20",
|
|
1450
|
-
y2: "12"
|
|
1451
|
-
}),
|
|
1452
|
-
/* @__PURE__ */ jsx("line", {
|
|
1453
|
-
x1: "16",
|
|
1454
|
-
y1: "8",
|
|
1455
|
-
x2: "16",
|
|
1456
|
-
y2: "16"
|
|
1457
|
-
}),
|
|
1458
|
-
/* @__PURE__ */ jsx("line", {
|
|
1459
|
-
x1: "15",
|
|
1460
|
-
y1: "3",
|
|
1461
|
-
x2: "15",
|
|
1462
|
-
y2: "21"
|
|
1463
|
-
})
|
|
1464
|
-
]
|
|
1465
|
-
})
|
|
1466
|
-
})
|
|
1467
|
-
}),
|
|
1468
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1469
|
-
title: t("delete_column"),
|
|
1470
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1471
|
-
size: "small",
|
|
1472
|
-
onClick: () => executeCommand(deleteColumn),
|
|
1473
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1474
|
-
width: "20",
|
|
1475
|
-
height: "20",
|
|
1476
|
-
viewBox: "0 0 24 24",
|
|
1477
|
-
fill: "none",
|
|
1478
|
-
stroke: "currentColor",
|
|
1479
|
-
strokeWidth: "2",
|
|
1480
|
-
strokeLinecap: "round",
|
|
1481
|
-
strokeLinejoin: "round",
|
|
1482
|
-
children: [
|
|
1483
|
-
/* @__PURE__ */ jsx("rect", {
|
|
1484
|
-
x: "3",
|
|
1485
|
-
y: "3",
|
|
1486
|
-
width: "18",
|
|
1487
|
-
height: "18",
|
|
1488
|
-
rx: "2",
|
|
1489
|
-
ry: "2"
|
|
1490
|
-
}),
|
|
1491
|
-
/* @__PURE__ */ jsx("line", {
|
|
1492
|
-
x1: "12",
|
|
1493
|
-
y1: "3",
|
|
1494
|
-
x2: "12",
|
|
1495
|
-
y2: "21"
|
|
1496
|
-
}),
|
|
1497
|
-
/* @__PURE__ */ jsx("line", {
|
|
1498
|
-
x1: "12",
|
|
1499
|
-
y1: "8",
|
|
1500
|
-
x2: "12",
|
|
1501
|
-
y2: "16"
|
|
1502
|
-
})
|
|
1503
|
-
]
|
|
1504
|
-
})
|
|
1505
|
-
})
|
|
1506
|
-
})
|
|
1507
|
-
]
|
|
1508
|
-
}),
|
|
1509
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
1510
|
-
title: t("delete_table"),
|
|
1511
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1512
|
-
size: "small",
|
|
1513
|
-
onClick: () => executeCommand(deleteTable),
|
|
1514
|
-
children: /* @__PURE__ */ jsxs("svg", {
|
|
1515
|
-
width: "20",
|
|
1516
|
-
height: "20",
|
|
1517
|
-
viewBox: "0 0 24 24",
|
|
1518
|
-
fill: "none",
|
|
1519
|
-
stroke: "currentColor",
|
|
1520
|
-
strokeWidth: "2",
|
|
1521
|
-
strokeLinecap: "round",
|
|
1522
|
-
strokeLinejoin: "round",
|
|
1523
|
-
children: [
|
|
1524
|
-
/* @__PURE__ */ jsx("polyline", { points: "3 6 5 6 21 6" }),
|
|
1525
|
-
/* @__PURE__ */ jsx("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }),
|
|
1526
|
-
/* @__PURE__ */ jsx("line", {
|
|
1527
|
-
x1: "10",
|
|
1528
|
-
y1: "11",
|
|
1529
|
-
x2: "10",
|
|
1530
|
-
y2: "17"
|
|
1531
|
-
}),
|
|
1532
|
-
/* @__PURE__ */ jsx("line", {
|
|
1533
|
-
x1: "14",
|
|
1534
|
-
y1: "11",
|
|
1535
|
-
x2: "14",
|
|
1536
|
-
y2: "17"
|
|
1537
|
-
})
|
|
1538
|
-
]
|
|
1539
|
-
})
|
|
1540
|
-
})
|
|
1541
|
-
})
|
|
1542
|
-
]
|
|
1543
|
-
});
|
|
1544
|
-
});
|
|
1545
|
-
TableBubble.displayName = "TableBubble";
|
|
1546
|
-
//#endregion
|
|
1547
|
-
//#region src/editor/utils/prosemirror-utils.ts
|
|
1548
|
-
function isMarkActive(state, type) {
|
|
1549
|
-
if (!state || !type) return false;
|
|
1550
|
-
const { from, $from, to, empty } = state.selection;
|
|
1551
|
-
if (empty) return !!type.isInSet(state.storedMarks || $from.marks());
|
|
1552
|
-
return state.doc.rangeHasMark(from, to, type);
|
|
1553
|
-
}
|
|
1554
|
-
function isNodeActive(state, type, attrs = {}) {
|
|
1555
|
-
if (!state || !type) return false;
|
|
1556
|
-
const selection = state.selection;
|
|
1557
|
-
const { $from, to } = selection;
|
|
1558
|
-
const node = selection instanceof TextSelection ? void 0 : selection.node;
|
|
1559
|
-
if (node) return node.type === type && (!attrs || Object.keys(attrs).every((key) => node.attrs[key] === attrs[key]));
|
|
1560
|
-
return to <= $from.end() && $from.parent.type === type && (!attrs || Object.keys(attrs).every((key) => $from.parent.attrs[key] === attrs[key]));
|
|
1561
|
-
}
|
|
1562
|
-
function getMarkAttributes(state, type) {
|
|
1563
|
-
if (!state || !type) return {};
|
|
1564
|
-
const { from, $from, to, empty } = state.selection;
|
|
1565
|
-
let mark;
|
|
1566
|
-
if (empty) mark = type.isInSet(state.storedMarks || $from.marks());
|
|
1567
|
-
else {
|
|
1568
|
-
let found = false;
|
|
1569
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
1570
|
-
if (found) return false;
|
|
1571
|
-
const m = type.isInSet(node.marks);
|
|
1572
|
-
if (m) {
|
|
1573
|
-
mark = m;
|
|
1574
|
-
found = true;
|
|
1575
|
-
}
|
|
1576
|
-
return true;
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
return mark ? mark.attrs : {};
|
|
1580
|
-
}
|
|
1581
|
-
function setMark(type, attrs) {
|
|
1582
|
-
return (state, dispatch) => {
|
|
1583
|
-
const { empty, $cursor, ranges } = state.selection;
|
|
1584
|
-
if (empty && !$cursor || !type) return false;
|
|
1585
|
-
if (dispatch) if ($cursor) dispatch(state.tr.addStoredMark(type.create(attrs)));
|
|
1586
|
-
else {
|
|
1587
|
-
const tr = state.tr;
|
|
1588
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
1589
|
-
const { $from, $to } = ranges[i];
|
|
1590
|
-
tr.addMark($from.pos, $to.pos, type.create(attrs));
|
|
1591
|
-
}
|
|
1592
|
-
dispatch(tr.scrollIntoView());
|
|
1593
|
-
}
|
|
1594
|
-
return true;
|
|
1595
|
-
};
|
|
1596
|
-
}
|
|
1597
|
-
function unsetMark(type) {
|
|
1598
|
-
return (state, dispatch) => {
|
|
1599
|
-
const { empty, $cursor, ranges } = state.selection;
|
|
1600
|
-
if (empty && !$cursor || !type) return false;
|
|
1601
|
-
if (dispatch) {
|
|
1602
|
-
const tr = state.tr;
|
|
1603
|
-
if ($cursor) {
|
|
1604
|
-
const parent = $cursor.parent;
|
|
1605
|
-
let markStart = -1;
|
|
1606
|
-
let markEnd = -1;
|
|
1607
|
-
let currentMarkStart = -1;
|
|
1608
|
-
parent.forEach((child, offset) => {
|
|
1609
|
-
const childStart = $cursor.start() + offset;
|
|
1610
|
-
const childEnd = childStart + child.nodeSize;
|
|
1611
|
-
if (type.isInSet(child.marks)) {
|
|
1612
|
-
if (currentMarkStart === -1) currentMarkStart = childStart;
|
|
1613
|
-
if ($cursor.pos >= childStart && $cursor.pos <= childEnd) markStart = currentMarkStart;
|
|
1614
|
-
} else if (currentMarkStart !== -1) {
|
|
1615
|
-
if (markStart !== -1 && markEnd === -1) markEnd = childStart;
|
|
1616
|
-
currentMarkStart = -1;
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
if (markStart !== -1 && markEnd === -1) markEnd = $cursor.end();
|
|
1620
|
-
if (markStart !== -1 && markEnd !== -1) tr.removeMark(markStart, markEnd, type);
|
|
1621
|
-
tr.removeStoredMark(type);
|
|
1622
|
-
dispatch(tr.scrollIntoView());
|
|
1623
|
-
} else {
|
|
1624
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
1625
|
-
const { $from, $to } = ranges[i];
|
|
1626
|
-
tr.removeMark($from.pos, $to.pos, type);
|
|
1627
|
-
}
|
|
1628
|
-
dispatch(tr.scrollIntoView());
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
return true;
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
//#endregion
|
|
1635
|
-
//#region src/editor/selectors/node-selector.tsx
|
|
1636
|
-
var items = [
|
|
1637
|
-
{
|
|
1638
|
-
name: "Text",
|
|
1639
|
-
labelKey: "editor_text",
|
|
1640
|
-
icon: TypeIcon,
|
|
1641
|
-
command: (state, dispatch) => setBlockType(schema.nodes.paragraph)(state, dispatch),
|
|
1642
|
-
isActive: (state) => isNodeActive(state, schema.nodes.paragraph) && !isNodeActive(state, schema.nodes.bullet_list) && !isNodeActive(state, schema.nodes.ordered_list)
|
|
1643
|
-
},
|
|
1644
|
-
{
|
|
1645
|
-
name: "Heading 1",
|
|
1646
|
-
labelKey: "editor_heading_1",
|
|
1647
|
-
icon: Heading1Icon,
|
|
1648
|
-
command: (state, dispatch) => setBlockType(schema.nodes.heading, { level: 1 })(state, dispatch),
|
|
1649
|
-
isActive: (state) => isNodeActive(state, schema.nodes.heading, { level: 1 })
|
|
1650
|
-
},
|
|
1651
|
-
{
|
|
1652
|
-
name: "Heading 2",
|
|
1653
|
-
labelKey: "editor_heading_2",
|
|
1654
|
-
icon: Heading2Icon,
|
|
1655
|
-
command: (state, dispatch) => setBlockType(schema.nodes.heading, { level: 2 })(state, dispatch),
|
|
1656
|
-
isActive: (state) => isNodeActive(state, schema.nodes.heading, { level: 2 })
|
|
1657
|
-
},
|
|
1658
|
-
{
|
|
1659
|
-
name: "Heading 3",
|
|
1660
|
-
labelKey: "editor_heading_3",
|
|
1661
|
-
icon: Heading3Icon,
|
|
1662
|
-
command: (state, dispatch) => setBlockType(schema.nodes.heading, { level: 3 })(state, dispatch),
|
|
1663
|
-
isActive: (state) => isNodeActive(state, schema.nodes.heading, { level: 3 })
|
|
1664
|
-
},
|
|
1665
|
-
{
|
|
1666
|
-
name: "To-do List",
|
|
1667
|
-
labelKey: "editor_todo_list",
|
|
1668
|
-
icon: CheckSquareIcon,
|
|
1669
|
-
command: (state, dispatch) => wrapInList(schema.nodes.task_list)(state, dispatch),
|
|
1670
|
-
isActive: (state) => isNodeActive(state, schema.nodes.task_item)
|
|
1671
|
-
},
|
|
1672
|
-
{
|
|
1673
|
-
name: "Bullet List",
|
|
1674
|
-
labelKey: "editor_bullet_list",
|
|
1675
|
-
icon: ListIcon,
|
|
1676
|
-
command: (state, dispatch) => wrapInList(schema.nodes.bullet_list)(state, dispatch),
|
|
1677
|
-
isActive: (state) => isNodeActive(state, schema.nodes.bullet_list)
|
|
1678
|
-
},
|
|
1679
|
-
{
|
|
1680
|
-
name: "Numbered List",
|
|
1681
|
-
labelKey: "editor_numbered_list",
|
|
1682
|
-
icon: ListOrderedIcon,
|
|
1683
|
-
command: (state, dispatch) => wrapInList(schema.nodes.ordered_list)(state, dispatch),
|
|
1684
|
-
isActive: (state) => isNodeActive(state, schema.nodes.ordered_list)
|
|
1685
|
-
},
|
|
1686
|
-
{
|
|
1687
|
-
name: "Quote",
|
|
1688
|
-
labelKey: "editor_quote",
|
|
1689
|
-
icon: QuoteIcon,
|
|
1690
|
-
command: (state, dispatch) => wrapIn(schema.nodes.blockquote)(state, dispatch),
|
|
1691
|
-
isActive: (state) => isNodeActive(state, schema.nodes.blockquote)
|
|
1692
|
-
},
|
|
1693
|
-
{
|
|
1694
|
-
name: "Code",
|
|
1695
|
-
labelKey: "editor_code",
|
|
1696
|
-
icon: CodeIcon,
|
|
1697
|
-
command: (state, dispatch) => setBlockType(schema.nodes.code_block)(state, dispatch),
|
|
1698
|
-
isActive: (state) => isNodeActive(state, schema.nodes.code_block)
|
|
1699
|
-
}
|
|
1700
|
-
];
|
|
1701
|
-
var NodeSelector = ({ open, onOpenChange, portalContainer }) => {
|
|
1702
|
-
const { state, view } = useProseMirrorContext();
|
|
1703
|
-
const { t } = useTranslation();
|
|
1704
|
-
if (!state || !view) return null;
|
|
1705
|
-
const activeItem = items.filter((item) => item.isActive(state)).pop() ?? {
|
|
1706
|
-
name: "Multiple",
|
|
1707
|
-
labelKey: "editor_multiple"
|
|
1708
|
-
};
|
|
1709
|
-
return /* @__PURE__ */ jsx(Popover, {
|
|
1710
|
-
sideOffset: 5,
|
|
1711
|
-
align: "start",
|
|
1712
|
-
portalContainer,
|
|
1713
|
-
className: "w-48 p-1",
|
|
1714
|
-
trigger: /* @__PURE__ */ jsxs(Button, {
|
|
1715
|
-
variant: "text",
|
|
1716
|
-
className: "gap-2 rounded-none",
|
|
1717
|
-
color: "text",
|
|
1718
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
1719
|
-
className: "whitespace-nowrap text-sm",
|
|
1720
|
-
children: t(activeItem.labelKey)
|
|
1721
|
-
}), /* @__PURE__ */ jsx(ChevronDownIcon, { size: iconSize.small })]
|
|
1722
|
-
}),
|
|
1723
|
-
modal: true,
|
|
1724
|
-
open,
|
|
1725
|
-
onOpenChange,
|
|
1726
|
-
children: items.map((item, index) => /* @__PURE__ */ jsxs(EditorBubbleItem, {
|
|
1727
|
-
onSelect: () => {
|
|
1728
|
-
item.command(view.state, view.dispatch);
|
|
1729
|
-
view.focus();
|
|
1730
|
-
onOpenChange(false);
|
|
1731
|
-
},
|
|
1732
|
-
className: "flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm hover:bg-surface-hover text-surface-900 dark:text-white",
|
|
1733
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1734
|
-
className: "flex items-center space-x-2",
|
|
1735
|
-
children: [/* @__PURE__ */ jsx(item.icon, { size: iconSize.smallest }), /* @__PURE__ */ jsx("span", { children: t(item.labelKey) })]
|
|
1736
|
-
}), activeItem.name === item.name && /* @__PURE__ */ jsx(CheckIcon, { size: iconSize.smallest })]
|
|
1737
|
-
}, index))
|
|
1738
|
-
});
|
|
1739
|
-
};
|
|
1740
|
-
//#endregion
|
|
1741
|
-
//#region src/editor/selectors/link-selector.tsx
|
|
1742
|
-
function isValidUrl(url) {
|
|
1743
|
-
try {
|
|
1744
|
-
new URL(url);
|
|
1745
|
-
return true;
|
|
1746
|
-
} catch (e) {
|
|
1747
|
-
return false;
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
function getUrlFromString(str) {
|
|
1751
|
-
if (isValidUrl(str)) return str;
|
|
1752
|
-
try {
|
|
1753
|
-
if (str.includes(".") && !str.includes(" ")) return new URL(`https://${str}`).toString();
|
|
1754
|
-
return null;
|
|
1755
|
-
} catch (e) {
|
|
1756
|
-
return null;
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
var LinkSelector = ({ open, onOpenChange }) => {
|
|
1760
|
-
const inputRef = useRef(null);
|
|
1761
|
-
const { state, view } = useProseMirrorContext();
|
|
1762
|
-
const { t } = useTranslation();
|
|
1763
|
-
useEffect(() => {
|
|
1764
|
-
if (open && inputRef.current) inputRef.current.focus();
|
|
1765
|
-
}, [open]);
|
|
1766
|
-
if (!state || !view) return null;
|
|
1767
|
-
const handleSubmit = (e) => {
|
|
1768
|
-
e.preventDefault();
|
|
1769
|
-
const value = inputRef.current?.value;
|
|
1770
|
-
if (!value) return;
|
|
1771
|
-
const url = getUrlFromString(value);
|
|
1772
|
-
if (url) {
|
|
1773
|
-
setMark(schema.marks.link, { href: url })(view.state, view.dispatch);
|
|
1774
|
-
view.focus();
|
|
1775
|
-
onOpenChange(false);
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
|
-
const handleRemoveLink = () => {
|
|
1779
|
-
unsetMark(schema.marks.link)(view.state, view.dispatch);
|
|
1780
|
-
view.focus();
|
|
1781
|
-
onOpenChange(false);
|
|
1782
|
-
};
|
|
1783
|
-
const isActive = isMarkActive(state, schema.marks.link);
|
|
1784
|
-
const href = getMarkAttributes(state, schema.marks.link).href || "";
|
|
1785
|
-
return /* @__PURE__ */ jsx(Popover, {
|
|
1786
|
-
modal: true,
|
|
1787
|
-
open,
|
|
1788
|
-
onOpenChange,
|
|
1789
|
-
trigger: /* @__PURE__ */ jsx(Button, {
|
|
1790
|
-
variant: "text",
|
|
1791
|
-
type: "button",
|
|
1792
|
-
className: "gap-2 rounded-none",
|
|
1793
|
-
color: "text",
|
|
1794
|
-
children: /* @__PURE__ */ jsx("p", {
|
|
1795
|
-
className: cls("underline decoration-stone-400 underline-offset-4", { "text-blue-500": isActive }),
|
|
1796
|
-
children: t("editor_link")
|
|
1797
|
-
})
|
|
1798
|
-
}),
|
|
1799
|
-
children: /* @__PURE__ */ jsxs("form", {
|
|
1800
|
-
onSubmit: handleSubmit,
|
|
1801
|
-
className: "flex p-1 gap-1",
|
|
1802
|
-
children: [/* @__PURE__ */ jsx(TextField, {
|
|
1803
|
-
inputRef,
|
|
1804
|
-
autoFocus: open,
|
|
1805
|
-
"aria-label": t("editor_paste_or_type_link"),
|
|
1806
|
-
placeholder: t("editor_paste_or_type_link"),
|
|
1807
|
-
defaultValue: href,
|
|
1808
|
-
size: "small",
|
|
1809
|
-
className: "flex-grow text-surface-900 dark:text-white",
|
|
1810
|
-
inputClassName: cls("bg-transparent p-1 text-sm outline-none", focusedDisabled)
|
|
1811
|
-
}), href ? /* @__PURE__ */ jsx(Button, {
|
|
1812
|
-
size: "small",
|
|
1813
|
-
variant: "text",
|
|
1814
|
-
type: "button",
|
|
1815
|
-
color: "text",
|
|
1816
|
-
className: "flex items-center",
|
|
1817
|
-
onClick: handleRemoveLink,
|
|
1818
|
-
children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.small })
|
|
1819
|
-
}) : /* @__PURE__ */ jsx(Button, {
|
|
1820
|
-
size: "small",
|
|
1821
|
-
type: "submit",
|
|
1822
|
-
variant: "text",
|
|
1823
|
-
children: /* @__PURE__ */ jsx(CheckIcon, { size: iconSize.small })
|
|
1824
|
-
})]
|
|
1825
|
-
})
|
|
1826
|
-
});
|
|
1827
|
-
};
|
|
1828
|
-
//#endregion
|
|
1829
|
-
//#region src/editor/selectors/text-buttons.tsx
|
|
1830
|
-
var TextButtons = () => {
|
|
1831
|
-
const { state, view } = useProseMirrorContext();
|
|
1832
|
-
if (!state || !view) return null;
|
|
1833
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1834
|
-
className: "flex",
|
|
1835
|
-
children: [
|
|
1836
|
-
{
|
|
1837
|
-
name: "bold",
|
|
1838
|
-
labelKey: "editor_bold",
|
|
1839
|
-
isActive: (s) => isMarkActive(s, schema.marks.bold),
|
|
1840
|
-
command: (s, dispatch) => toggleMark(schema.marks.bold)(s, dispatch),
|
|
1841
|
-
icon: BoldIcon
|
|
1842
|
-
},
|
|
1843
|
-
{
|
|
1844
|
-
name: "italic",
|
|
1845
|
-
labelKey: "editor_italic",
|
|
1846
|
-
isActive: (s) => isMarkActive(s, schema.marks.italic),
|
|
1847
|
-
command: (s, dispatch) => toggleMark(schema.marks.italic)(s, dispatch),
|
|
1848
|
-
icon: ItalicIcon
|
|
1849
|
-
},
|
|
1850
|
-
{
|
|
1851
|
-
name: "underline",
|
|
1852
|
-
labelKey: "editor_underline",
|
|
1853
|
-
isActive: (s) => isMarkActive(s, schema.marks.underline),
|
|
1854
|
-
command: (s, dispatch) => toggleMark(schema.marks.underline)(s, dispatch),
|
|
1855
|
-
icon: UnderlineIcon
|
|
1856
|
-
},
|
|
1857
|
-
{
|
|
1858
|
-
name: "strike",
|
|
1859
|
-
labelKey: "editor_strikethrough",
|
|
1860
|
-
isActive: (s) => isMarkActive(s, schema.marks.strike),
|
|
1861
|
-
command: (s, dispatch) => toggleMark(schema.marks.strike)(s, dispatch),
|
|
1862
|
-
icon: StrikethroughIcon
|
|
1863
|
-
},
|
|
1864
|
-
{
|
|
1865
|
-
name: "code",
|
|
1866
|
-
labelKey: "editor_code",
|
|
1867
|
-
isActive: (s) => isMarkActive(s, schema.marks.code),
|
|
1868
|
-
command: (s, dispatch) => toggleMark(schema.marks.code)(s, dispatch),
|
|
1869
|
-
icon: CodeIcon
|
|
1870
|
-
}
|
|
1871
|
-
].map((item, index) => /* @__PURE__ */ jsx(EditorBubbleItem, {
|
|
1872
|
-
onSelect: () => {
|
|
1873
|
-
item.command(view.state, view.dispatch);
|
|
1874
|
-
view.focus();
|
|
1875
|
-
},
|
|
1876
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
1877
|
-
size: "small",
|
|
1878
|
-
color: "text",
|
|
1879
|
-
className: "gap-2 rounded-none h-full",
|
|
1880
|
-
variant: "text",
|
|
1881
|
-
children: /* @__PURE__ */ jsx(item.icon, { className: cls({
|
|
1882
|
-
"text-inherit": !item.isActive(state),
|
|
1883
|
-
"text-blue-500": item.isActive(state)
|
|
1884
|
-
}) })
|
|
1885
|
-
})
|
|
1886
|
-
}, index))
|
|
1887
|
-
});
|
|
1888
|
-
};
|
|
1889
|
-
//#endregion
|
|
1890
|
-
//#region src/editor/utils/remove_classes.ts
|
|
1891
|
-
function removeClassesFromJson(jsonObj) {
|
|
1892
|
-
if (Array.isArray(jsonObj)) return jsonObj.map((item) => removeClassesFromJson(item));
|
|
1893
|
-
else if (typeof jsonObj === "object" && jsonObj !== null) {
|
|
1894
|
-
const obj = jsonObj;
|
|
1895
|
-
if (obj.attrs && typeof obj.attrs === "object" && obj.attrs !== null && "class" in obj.attrs) delete obj.attrs.class;
|
|
1896
|
-
Object.keys(obj).forEach((key) => {
|
|
1897
|
-
obj[key] = removeClassesFromJson(obj[key]);
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
return jsonObj;
|
|
1901
|
-
}
|
|
1902
|
-
//#endregion
|
|
1903
|
-
//#region src/editor/extensions/clipboard.ts
|
|
1904
|
-
function serializeForClipboard(view, slice) {
|
|
1905
|
-
view.someProp("transformCopied", (f) => {
|
|
1906
|
-
slice = f(slice, view);
|
|
1907
|
-
});
|
|
1908
|
-
const context = [];
|
|
1909
|
-
let { content, openStart, openEnd } = slice;
|
|
1910
|
-
while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) {
|
|
1911
|
-
openStart--;
|
|
1912
|
-
openEnd--;
|
|
1913
|
-
const node = content.firstChild;
|
|
1914
|
-
const nodeType = node.type;
|
|
1915
|
-
context.push(node.type.name, node.attrs != nodeType.defaultAttrs ? node.attrs : null);
|
|
1916
|
-
content = node.content;
|
|
1917
|
-
}
|
|
1918
|
-
const serializer = view.someProp("clipboardSerializer") || DOMSerializer.fromSchema(view.state.schema);
|
|
1919
|
-
const doc = detachedDoc(), wrap = doc.createElement("div");
|
|
1920
|
-
wrap.appendChild(serializer.serializeFragment(content, { document: doc }));
|
|
1921
|
-
let firstChild = wrap.firstChild, needsWrap, wrappers = 0;
|
|
1922
|
-
while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
|
|
1923
|
-
for (let i = needsWrap.length - 1; i >= 0; i--) {
|
|
1924
|
-
const wrapper = doc.createElement(needsWrap[i]);
|
|
1925
|
-
while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
|
|
1926
|
-
wrap.appendChild(wrapper);
|
|
1927
|
-
wrappers++;
|
|
1928
|
-
}
|
|
1929
|
-
firstChild = wrap.firstChild;
|
|
1930
|
-
}
|
|
1931
|
-
if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
|
|
1932
|
-
return {
|
|
1933
|
-
dom: wrap,
|
|
1934
|
-
text: view.someProp("clipboardTextSerializer", (f) => f(slice, view)) || slice.content.textBetween(0, slice.content.size, "\n\n"),
|
|
1935
|
-
slice
|
|
1936
|
-
};
|
|
1937
|
-
}
|
|
1938
|
-
var wrapMap = {
|
|
1939
|
-
thead: ["table"],
|
|
1940
|
-
tbody: ["table"],
|
|
1941
|
-
tfoot: ["table"],
|
|
1942
|
-
caption: ["table"],
|
|
1943
|
-
colgroup: ["table"],
|
|
1944
|
-
col: ["table", "colgroup"],
|
|
1945
|
-
tr: ["table", "tbody"],
|
|
1946
|
-
td: [
|
|
1947
|
-
"table",
|
|
1948
|
-
"tbody",
|
|
1949
|
-
"tr"
|
|
1950
|
-
],
|
|
1951
|
-
th: [
|
|
1952
|
-
"table",
|
|
1953
|
-
"tbody",
|
|
1954
|
-
"tr"
|
|
1955
|
-
]
|
|
1956
|
-
};
|
|
1957
|
-
var _detachedDoc = null;
|
|
1958
|
-
function detachedDoc() {
|
|
1959
|
-
return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title"));
|
|
1960
|
-
}
|
|
1961
|
-
//#endregion
|
|
1962
|
-
//#region src/editor/extensions/drag-and-drop.tsx
|
|
1963
|
-
function absoluteRect(element) {
|
|
1964
|
-
const data = element.getBoundingClientRect();
|
|
1965
|
-
let ancestor = element.parentElement;
|
|
1966
|
-
while (ancestor && window.getComputedStyle(ancestor).position === "static") ancestor = ancestor.parentElement;
|
|
1967
|
-
const ancestorRect = ancestor?.getBoundingClientRect();
|
|
1968
|
-
return {
|
|
1969
|
-
top: data.top - (ancestorRect?.top ?? 0),
|
|
1970
|
-
left: data.left - (ancestorRect?.left ?? 0),
|
|
1971
|
-
width: data.width
|
|
1972
|
-
};
|
|
1973
|
-
}
|
|
1974
|
-
function nodeDOMAtCoords(coords, view) {
|
|
1975
|
-
const editorRect = view.dom.getBoundingClientRect();
|
|
1976
|
-
if (coords.y < editorRect.top || coords.y > editorRect.bottom) return void 0;
|
|
1977
|
-
if (coords.x < editorRect.left - 100 || coords.x > editorRect.right + 50) return void 0;
|
|
1978
|
-
const blockSelector = "li, p, pre, blockquote, h1, h2, h3, h4, h5, h6, img, [data-type=\"taskList\"]";
|
|
1979
|
-
const block = document.elementFromPoint(coords.x, coords.y)?.closest(blockSelector);
|
|
1980
|
-
if (block && view.dom.contains(block) && block.textContent?.trim()) {
|
|
1981
|
-
const li = block.closest("li");
|
|
1982
|
-
return li && view.dom.contains(li) ? li : block;
|
|
1983
|
-
}
|
|
1984
|
-
const probeX = editorRect.left + Math.min(60, editorRect.width / 4);
|
|
1985
|
-
if (coords.x > probeX) return void 0;
|
|
1986
|
-
const probeBlock = document.elementFromPoint(probeX, coords.y)?.closest(blockSelector);
|
|
1987
|
-
if (probeBlock && probeBlock.textContent?.trim()) {
|
|
1988
|
-
if (view.dom.contains(probeBlock)) {
|
|
1989
|
-
const li = probeBlock.closest("li");
|
|
1990
|
-
return li && view.dom.contains(li) ? li : probeBlock;
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
function nodePosAtDOM(node, view, options) {
|
|
1995
|
-
try {
|
|
1996
|
-
if (!view.dom.contains(node)) return null;
|
|
1997
|
-
const pos = view.posAtDOM(node, 0);
|
|
1998
|
-
const $pos = view.state.doc.resolve(pos);
|
|
1999
|
-
if ($pos.depth > 0) return $pos.before();
|
|
2000
|
-
return pos;
|
|
2001
|
-
} catch (e) {
|
|
2002
|
-
return null;
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
function dragHandlePlugin(options = { dragHandleWidth: 24 }) {
|
|
2006
|
-
function handleDragStart(event, view) {
|
|
2007
|
-
view.focus();
|
|
2008
|
-
if (!event.dataTransfer) return;
|
|
2009
|
-
const node = nodeDOMAtCoords({
|
|
2010
|
-
x: event.clientX,
|
|
2011
|
-
y: event.clientY
|
|
2012
|
-
}, view);
|
|
2013
|
-
if (!(node instanceof Element)) return;
|
|
2014
|
-
const nodePos = nodePosAtDOM(node, view, options);
|
|
2015
|
-
if (nodePos == null || nodePos < 0) return;
|
|
2016
|
-
const draggedNodeSelection = NodeSelection.create(view.state.doc, nodePos);
|
|
2017
|
-
view.dispatch(view.state.tr.setSelection(draggedNodeSelection));
|
|
2018
|
-
const slice = view.state.selection.content();
|
|
2019
|
-
const { dom, text } = serializeForClipboard(view, slice);
|
|
2020
|
-
event.dataTransfer.clearData();
|
|
2021
|
-
event.dataTransfer.setData("text/html", dom.innerHTML);
|
|
2022
|
-
event.dataTransfer.setData("text/plain", text);
|
|
2023
|
-
event.dataTransfer.effectAllowed = "copyMove";
|
|
2024
|
-
event.dataTransfer.setDragImage(node, 0, 0);
|
|
2025
|
-
view.dragging = {
|
|
2026
|
-
slice,
|
|
2027
|
-
move: true,
|
|
2028
|
-
node: draggedNodeSelection
|
|
2029
|
-
};
|
|
2030
|
-
}
|
|
2031
|
-
function handleClick(event, view) {
|
|
2032
|
-
view.focus();
|
|
2033
|
-
view.dom.classList.remove("dragging");
|
|
2034
|
-
const node = nodeDOMAtCoords({
|
|
2035
|
-
x: event.clientX,
|
|
2036
|
-
y: event.clientY
|
|
2037
|
-
}, view);
|
|
2038
|
-
if (!(node instanceof Element)) return;
|
|
2039
|
-
const nodePos = nodePosAtDOM(node, view, options);
|
|
2040
|
-
if (!nodePos) return;
|
|
2041
|
-
view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos)));
|
|
2042
|
-
}
|
|
2043
|
-
let dragHandleElement = null;
|
|
2044
|
-
function hideDragHandle() {
|
|
2045
|
-
if (dragHandleElement) {
|
|
2046
|
-
dragHandleElement.classList.add("hide");
|
|
2047
|
-
dragHandleElement.style.opacity = "0";
|
|
2048
|
-
dragHandleElement.style.pointerEvents = "none";
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
function showDragHandle() {
|
|
2052
|
-
if (dragHandleElement) {
|
|
2053
|
-
dragHandleElement.classList.remove("hide");
|
|
2054
|
-
dragHandleElement.style.opacity = "1";
|
|
2055
|
-
dragHandleElement.style.pointerEvents = "auto";
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
return new Plugin({
|
|
2059
|
-
view: (view) => {
|
|
2060
|
-
dragHandleElement = document.createElement("div");
|
|
2061
|
-
dragHandleElement.draggable = true;
|
|
2062
|
-
dragHandleElement.dataset.dragHandle = "";
|
|
2063
|
-
dragHandleElement.classList.add("drag-handle");
|
|
2064
|
-
dragHandleElement.addEventListener("dragstart", (e) => {
|
|
2065
|
-
handleDragStart(e, view);
|
|
2066
|
-
});
|
|
2067
|
-
dragHandleElement.addEventListener("click", (e) => {
|
|
2068
|
-
handleClick(e, view);
|
|
2069
|
-
});
|
|
2070
|
-
const onMouseMove = (event) => {
|
|
2071
|
-
if (!view.editable) return;
|
|
2072
|
-
const node = nodeDOMAtCoords({
|
|
2073
|
-
x: event.clientX,
|
|
2074
|
-
y: event.clientY
|
|
2075
|
-
}, view);
|
|
2076
|
-
if (!(node instanceof Element)) {
|
|
2077
|
-
hideDragHandle();
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
const compStyle = window.getComputedStyle(node);
|
|
2081
|
-
const lineHeight = parseInt(compStyle.lineHeight, 10);
|
|
2082
|
-
const paddingTop = parseInt(compStyle.paddingTop, 10);
|
|
2083
|
-
const rect = absoluteRect(node);
|
|
2084
|
-
if (!rect) {
|
|
2085
|
-
hideDragHandle();
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
rect.top += (lineHeight - 24) / 2;
|
|
2089
|
-
rect.top += paddingTop;
|
|
2090
|
-
if (node.matches("ul:not([data-type=taskList]) li, ol li")) rect.left -= options.dragHandleWidth;
|
|
2091
|
-
rect.width = options.dragHandleWidth;
|
|
2092
|
-
if (!dragHandleElement) return;
|
|
2093
|
-
dragHandleElement.style.left = `${rect.left - rect.width}px`;
|
|
2094
|
-
dragHandleElement.style.top = `${rect.top}px`;
|
|
2095
|
-
showDragHandle();
|
|
2096
|
-
};
|
|
2097
|
-
window.addEventListener("mousemove", onMouseMove);
|
|
2098
|
-
hideDragHandle();
|
|
2099
|
-
view?.dom?.parentElement?.appendChild(dragHandleElement);
|
|
2100
|
-
return { destroy: () => {
|
|
2101
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
2102
|
-
dragHandleElement?.remove?.();
|
|
2103
|
-
dragHandleElement = null;
|
|
2104
|
-
} };
|
|
2105
|
-
},
|
|
2106
|
-
props: { handleDOMEvents: {
|
|
2107
|
-
keydown: () => {
|
|
2108
|
-
hideDragHandle();
|
|
2109
|
-
},
|
|
2110
|
-
mousewheel: () => {
|
|
2111
|
-
hideDragHandle();
|
|
2112
|
-
},
|
|
2113
|
-
dragstart: (view) => {
|
|
2114
|
-
view.dom.classList.add("dragging");
|
|
2115
|
-
},
|
|
2116
|
-
drop: (view) => {
|
|
2117
|
-
view.dom.classList.remove("dragging");
|
|
2118
|
-
},
|
|
2119
|
-
dragend: (view) => {
|
|
2120
|
-
view.dom.classList.remove("dragging");
|
|
2121
|
-
}
|
|
2122
|
-
} }
|
|
2123
|
-
});
|
|
2124
|
-
}
|
|
2125
|
-
function globalDragDropPlugin() {
|
|
2126
|
-
let dropCursorElement = null;
|
|
2127
|
-
let cleanup = null;
|
|
2128
|
-
function updateDropCursorColor(el) {
|
|
2129
|
-
const isDark = document.documentElement.getAttribute("data-theme") === "dark";
|
|
2130
|
-
const varName = isDark ? "--color-surface-accent-300" : "--color-surface-accent-600";
|
|
2131
|
-
const color = getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
|
|
2132
|
-
el.style.backgroundColor = color || (isDark ? "#cbd5e1" : "#475569");
|
|
2133
|
-
}
|
|
2134
|
-
return new Plugin({ view(editorView) {
|
|
2135
|
-
dropCursorElement = document.createElement("div");
|
|
2136
|
-
dropCursorElement.className = "prosemirror-dropcursor-block";
|
|
2137
|
-
dropCursorElement.style.cssText = "position: absolute; z-index: 50; pointer-events: none; height: 2px;";
|
|
2138
|
-
updateDropCursorColor(dropCursorElement);
|
|
2139
|
-
const observer = new MutationObserver(() => {
|
|
2140
|
-
if (dropCursorElement) updateDropCursorColor(dropCursorElement);
|
|
2141
|
-
});
|
|
2142
|
-
observer.observe(document.documentElement, {
|
|
2143
|
-
attributes: true,
|
|
2144
|
-
attributeFilter: ["data-theme"]
|
|
2145
|
-
});
|
|
2146
|
-
const removeCursor = () => {
|
|
2147
|
-
if (dropCursorElement && dropCursorElement.parentNode) dropCursorElement.parentNode.removeChild(dropCursorElement);
|
|
2148
|
-
};
|
|
2149
|
-
const getBlockInsertionPoint = (event, clampedX) => {
|
|
2150
|
-
const pos = editorView.posAtCoords({
|
|
2151
|
-
left: clampedX,
|
|
2152
|
-
top: event.clientY
|
|
2153
|
-
});
|
|
2154
|
-
if (!pos) return null;
|
|
2155
|
-
const $pos = editorView.state.doc.resolve(pos.pos);
|
|
2156
|
-
let blockDepth = 0;
|
|
2157
|
-
for (let i = $pos.depth; i > 0; i--) {
|
|
2158
|
-
const name = $pos.node(i).type.name;
|
|
2159
|
-
if (name === "list_item" || name === "taskItem") {
|
|
2160
|
-
blockDepth = i;
|
|
2161
|
-
break;
|
|
2162
|
-
}
|
|
2163
|
-
if ($pos.node(i).isBlock && name !== "bullet_list" && name !== "ordered_list" && name !== "taskList") blockDepth = i;
|
|
2164
|
-
}
|
|
2165
|
-
if (blockDepth === 0) return pos.pos;
|
|
2166
|
-
const nodeBeforePos = $pos.before(blockDepth);
|
|
2167
|
-
const nodeAfterPos = $pos.after(blockDepth);
|
|
2168
|
-
const domNode = editorView.nodeDOM(nodeBeforePos);
|
|
2169
|
-
if (domNode instanceof HTMLElement) {
|
|
2170
|
-
const rect = domNode.getBoundingClientRect();
|
|
2171
|
-
return event.clientY < rect.top + rect.height / 2 ? nodeBeforePos : nodeAfterPos;
|
|
2172
|
-
}
|
|
2173
|
-
return pos.pos;
|
|
2174
|
-
};
|
|
2175
|
-
const handleDragOver = (event) => {
|
|
2176
|
-
if (!editorView.editable || !editorView.dragging) return;
|
|
2177
|
-
if (!editorView.dragging?.node) {
|
|
2178
|
-
removeCursor();
|
|
2179
|
-
return;
|
|
2180
|
-
}
|
|
2181
|
-
event.preventDefault();
|
|
2182
|
-
const editorRect = editorView.dom.getBoundingClientRect();
|
|
2183
|
-
const clampedX = Math.max(editorRect.left + 10, Math.min(event.clientX, editorRect.right - 10));
|
|
2184
|
-
const target = getBlockInsertionPoint(event, clampedX);
|
|
2185
|
-
if (target === null) {
|
|
2186
|
-
removeCursor();
|
|
2187
|
-
return;
|
|
2188
|
-
}
|
|
2189
|
-
const $pos = editorView.state.doc.resolve(target);
|
|
2190
|
-
let rect;
|
|
2191
|
-
const before = $pos.nodeBefore;
|
|
2192
|
-
const after = $pos.nodeAfter;
|
|
2193
|
-
if (before || after) {
|
|
2194
|
-
const nodeDOM = editorView.nodeDOM(target - (before ? before.nodeSize : 0));
|
|
2195
|
-
if (nodeDOM && nodeDOM instanceof HTMLElement) {
|
|
2196
|
-
const nodeRect = nodeDOM.getBoundingClientRect();
|
|
2197
|
-
let top = before ? nodeRect.bottom : nodeRect.top;
|
|
2198
|
-
if (before && after) {
|
|
2199
|
-
const afterDOM = editorView.nodeDOM(target);
|
|
2200
|
-
if (afterDOM && afterDOM instanceof HTMLElement) top = (top + afterDOM.getBoundingClientRect().top) / 2;
|
|
2201
|
-
}
|
|
2202
|
-
rect = {
|
|
2203
|
-
left: nodeRect.left,
|
|
2204
|
-
right: nodeRect.right,
|
|
2205
|
-
top: top - 1,
|
|
2206
|
-
bottom: top + 1
|
|
2207
|
-
};
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
if (!rect) {
|
|
2211
|
-
const coords = editorView.coordsAtPos(target);
|
|
2212
|
-
rect = {
|
|
2213
|
-
left: editorRect.left + 50,
|
|
2214
|
-
right: editorRect.right - 50,
|
|
2215
|
-
top: coords.top - 1,
|
|
2216
|
-
bottom: coords.top + 1
|
|
2217
|
-
};
|
|
2218
|
-
}
|
|
2219
|
-
const parent = editorView.dom.offsetParent;
|
|
2220
|
-
let parentLeft = 0;
|
|
2221
|
-
let parentTop = 0;
|
|
2222
|
-
if (parent && parent !== document.body && getComputedStyle(parent).position !== "static") {
|
|
2223
|
-
const parentRect = parent.getBoundingClientRect();
|
|
2224
|
-
parentLeft = parentRect.left - parent.scrollLeft;
|
|
2225
|
-
parentTop = parentRect.top - parent.scrollTop;
|
|
2226
|
-
}
|
|
2227
|
-
if (!dropCursorElement.parentNode) parent.appendChild(dropCursorElement);
|
|
2228
|
-
dropCursorElement.style.left = `${rect.left - parentLeft}px`;
|
|
2229
|
-
dropCursorElement.style.top = `${rect.top - parentTop}px`;
|
|
2230
|
-
dropCursorElement.style.width = `${rect.right - rect.left}px`;
|
|
2231
|
-
};
|
|
2232
|
-
const handleDrop = (event) => {
|
|
2233
|
-
if (!editorView.editable || !editorView.dragging) return;
|
|
2234
|
-
if (!editorView.dragging?.node) {
|
|
2235
|
-
removeCursor();
|
|
2236
|
-
return;
|
|
2237
|
-
}
|
|
2238
|
-
event.preventDefault();
|
|
2239
|
-
removeCursor();
|
|
2240
|
-
editorView.dom.classList.remove("dragging");
|
|
2241
|
-
const editorRect = editorView.dom.getBoundingClientRect();
|
|
2242
|
-
const clampedX = Math.max(editorRect.left + 10, Math.min(event.clientX, editorRect.right - 10));
|
|
2243
|
-
const targetPos = getBlockInsertionPoint(event, clampedX);
|
|
2244
|
-
if (targetPos === null) return;
|
|
2245
|
-
const dragging = editorView.dragging;
|
|
2246
|
-
if (dragging && dragging.slice) {
|
|
2247
|
-
let tr = editorView.state.tr;
|
|
2248
|
-
if (dragging.move) {
|
|
2249
|
-
const { node } = dragging;
|
|
2250
|
-
if (node) node.replace(tr);
|
|
2251
|
-
else tr = tr.deleteSelection();
|
|
2252
|
-
}
|
|
2253
|
-
const mappedTarget = tr.mapping.map(targetPos);
|
|
2254
|
-
const beforeInsert = tr.doc;
|
|
2255
|
-
const { node, slice } = dragging;
|
|
2256
|
-
if (node && node.node) {
|
|
2257
|
-
let nodeToInsert = node.node;
|
|
2258
|
-
const parentName = tr.doc.resolve(mappedTarget).parent.type.name;
|
|
2259
|
-
const isTargetList = parentName === "bullet_list" || parentName === "ordered_list";
|
|
2260
|
-
const isTargetTaskList = parentName === "taskList";
|
|
2261
|
-
if ("type" in nodeToInsert && nodeToInsert.type.name === "list_item" && !isTargetList) nodeToInsert = nodeToInsert.content;
|
|
2262
|
-
else if ("type" in nodeToInsert && nodeToInsert.type.name === "taskItem" && !isTargetTaskList) nodeToInsert = nodeToInsert.content;
|
|
2263
|
-
if (!("type" in nodeToInsert) || "type" in nodeToInsert && nodeToInsert.type.name !== "list_item" && nodeToInsert.type.name !== "taskItem") {
|
|
2264
|
-
if (isTargetList) {
|
|
2265
|
-
const listItemType = editorView.state.schema.nodes.list_item;
|
|
2266
|
-
if (listItemType) nodeToInsert = listItemType.create(null, nodeToInsert);
|
|
2267
|
-
} else if (isTargetTaskList) {
|
|
2268
|
-
const taskItemType = editorView.state.schema.nodes.taskItem;
|
|
2269
|
-
if (taskItemType) nodeToInsert = taskItemType.create({ checked: false }, nodeToInsert);
|
|
2270
|
-
}
|
|
2271
|
-
}
|
|
2272
|
-
try {
|
|
2273
|
-
tr = tr.insert(mappedTarget, nodeToInsert);
|
|
2274
|
-
} catch (e) {
|
|
2275
|
-
console.warn("Could not insert dragged node exactly at target. Attempting fallback.", e);
|
|
2276
|
-
const point = dropPoint(tr.doc, mappedTarget, slice);
|
|
2277
|
-
if (point !== null) tr = tr.replace(point, point, slice);
|
|
2278
|
-
}
|
|
2279
|
-
} else if (slice) {
|
|
2280
|
-
const point = dropPoint(tr.doc, mappedTarget, slice);
|
|
2281
|
-
const finalTarget = point !== null ? point : mappedTarget;
|
|
2282
|
-
tr = tr.replace(finalTarget, finalTarget, slice);
|
|
2283
|
-
}
|
|
2284
|
-
if (!tr.doc.eq(beforeInsert)) {
|
|
2285
|
-
editorView.dispatch(tr.setMeta("uiEvent", "drop"));
|
|
2286
|
-
editorView.focus();
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
editorView.dragging = null;
|
|
2290
|
-
};
|
|
2291
|
-
const handleDragEnd = () => {
|
|
2292
|
-
removeCursor();
|
|
2293
|
-
};
|
|
2294
|
-
window.addEventListener("dragover", handleDragOver, { capture: true });
|
|
2295
|
-
window.addEventListener("drop", handleDrop, { capture: true });
|
|
2296
|
-
window.addEventListener("dragend", handleDragEnd, { capture: true });
|
|
2297
|
-
cleanup = () => {
|
|
2298
|
-
removeCursor();
|
|
2299
|
-
observer.disconnect();
|
|
2300
|
-
window.removeEventListener("dragover", handleDragOver, { capture: true });
|
|
2301
|
-
window.removeEventListener("drop", handleDrop, { capture: true });
|
|
2302
|
-
window.removeEventListener("dragend", handleDragEnd, { capture: true });
|
|
2303
|
-
};
|
|
2304
|
-
return { destroy() {
|
|
2305
|
-
if (cleanup) cleanup();
|
|
2306
|
-
} };
|
|
2307
|
-
} });
|
|
2308
|
-
}
|
|
2309
|
-
//#endregion
|
|
2310
|
-
//#region src/editor/extensions/HighlightDecorationExtension.ts
|
|
2311
|
-
var highlightDecorationKey = new PluginKey("highlightDecoration");
|
|
2312
|
-
function buildDecorationSet(highlight, doc) {
|
|
2313
|
-
const decorations = [];
|
|
2314
|
-
if (highlight) decorations.push(Decoration.inline(highlight.from, highlight.to, { class: "dark:bg-surface-accent-700 bg-surface-accent-300" }));
|
|
2315
|
-
return DecorationSet.create(doc, decorations);
|
|
2316
|
-
}
|
|
2317
|
-
/**
|
|
2318
|
-
* Commands to toggle the highlight
|
|
2319
|
-
*/
|
|
2320
|
-
var highlightCommands = {
|
|
2321
|
-
toggleAutocompleteHighlight: (range) => (state, dispatch) => {
|
|
2322
|
-
const { selection } = state;
|
|
2323
|
-
const pos = selection.from;
|
|
2324
|
-
if (!dispatch) return false;
|
|
2325
|
-
dispatch(state.tr.setMeta(highlightDecorationKey, {
|
|
2326
|
-
pos,
|
|
2327
|
-
type: "highlightDecoration",
|
|
2328
|
-
remove: false,
|
|
2329
|
-
range
|
|
2330
|
-
}));
|
|
2331
|
-
return true;
|
|
2332
|
-
},
|
|
2333
|
-
removeAutocompleteHighlight: () => (state, dispatch) => {
|
|
2334
|
-
if (!dispatch) return false;
|
|
2335
|
-
dispatch(state.tr.setMeta(highlightDecorationKey, {
|
|
2336
|
-
pos: 0,
|
|
2337
|
-
type: "highlightDecoration",
|
|
2338
|
-
remove: true
|
|
2339
|
-
}));
|
|
2340
|
-
return true;
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
/**
|
|
2344
|
-
* This plugin is used to highlight the current autocomplete suggestion.
|
|
2345
|
-
* It allows to set a range and remove it.
|
|
2346
|
-
*/
|
|
2347
|
-
var highlightDecorationPlugin = (initialHighlight) => {
|
|
2348
|
-
return new Plugin({
|
|
2349
|
-
key: highlightDecorationKey,
|
|
2350
|
-
state: {
|
|
2351
|
-
init: (_, { doc }) => {
|
|
2352
|
-
return {
|
|
2353
|
-
decorationSet: initialHighlight && doc ? buildDecorationSet(initialHighlight, doc) : DecorationSet.empty,
|
|
2354
|
-
highlight: initialHighlight
|
|
2355
|
-
};
|
|
2356
|
-
},
|
|
2357
|
-
apply(transaction, oldState) {
|
|
2358
|
-
const action = transaction.getMeta(highlightDecorationKey);
|
|
2359
|
-
const highlight = action?.range;
|
|
2360
|
-
if (action?.type === "highlightDecoration") {
|
|
2361
|
-
const doc = transaction.doc;
|
|
2362
|
-
const { remove } = action;
|
|
2363
|
-
if (remove) return { decorationSet: DecorationSet.empty };
|
|
2364
|
-
return {
|
|
2365
|
-
decorationSet: buildDecorationSet(highlight, doc),
|
|
2366
|
-
highlight
|
|
2367
|
-
};
|
|
2368
|
-
} else return oldState;
|
|
2369
|
-
}
|
|
2370
|
-
},
|
|
2371
|
-
props: { decorations(state) {
|
|
2372
|
-
const autocompleteState = this.getState(state);
|
|
2373
|
-
if (autocompleteState?.decorationSet) return autocompleteState.decorationSet;
|
|
2374
|
-
else return DecorationSet.empty;
|
|
2375
|
-
} }
|
|
2376
|
-
});
|
|
2377
|
-
};
|
|
2378
|
-
//#endregion
|
|
2379
|
-
//#region src/editor/plugins/inputrules.ts
|
|
2380
|
-
var blockQuoteRule = wrappingInputRule(/^\s*>\s$/, schema.nodes.blockquote);
|
|
2381
|
-
var orderedListRule = wrappingInputRule(/^(\d+)\.\s$/, schema.nodes.ordered_list, (match) => ({ order: +match[1] }), (match, node) => node.childCount + node.attrs.order === +match[1]);
|
|
2382
|
-
var bulletListRule = wrappingInputRule(/^\s*([-+*])\s$/, schema.nodes.bullet_list);
|
|
2383
|
-
var taskListRule = wrappingInputRule(/^\s*(\[ \])\s$/, schema.nodes.task_list);
|
|
2384
|
-
var codeBlockRule = textblockTypeInputRule(/^```$/, schema.nodes.code_block);
|
|
2385
|
-
var headingRule = textblockTypeInputRule(/* @__PURE__ */ new RegExp("^(#{1,6})\\s$"), schema.nodes.heading, (match) => ({ level: match[1].length }));
|
|
2386
|
-
var horizontalRuleInputRule = new InputRule(/^(?:---|—-|___\s|\*\*\*\s)$/, (state, match, start, end) => {
|
|
2387
|
-
const tr = state.tr;
|
|
2388
|
-
tr.replaceWith(start - 1, end, schema.nodes.horizontal_rule.create());
|
|
2389
|
-
return tr;
|
|
2390
|
-
});
|
|
2391
|
-
function markInputRule(regexp, markType, getAttrs) {
|
|
2392
|
-
return new InputRule(regexp, (state, match, start, end) => {
|
|
2393
|
-
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
|
|
2394
|
-
const tr = state.tr;
|
|
2395
|
-
if (match[1]) {
|
|
2396
|
-
const textStart = start + match[0].indexOf(match[1]);
|
|
2397
|
-
const textEnd = textStart + match[1].length;
|
|
2398
|
-
if (textEnd < end) tr.delete(textEnd, end);
|
|
2399
|
-
if (textStart > start) tr.delete(start, textStart);
|
|
2400
|
-
end = start + match[1].length;
|
|
2401
|
-
}
|
|
2402
|
-
tr.addMark(start, end, markType.create(attrs));
|
|
2403
|
-
tr.removeStoredMark(markType);
|
|
2404
|
-
return tr;
|
|
2405
|
-
});
|
|
2406
|
-
}
|
|
2407
|
-
var strongRule = markInputRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, schema.marks.bold);
|
|
2408
|
-
var emRule = markInputRule(/(?:^|[^*_])(?:\*|_)([^*_]+)(?:\*|_)$/, schema.marks.italic);
|
|
2409
|
-
var codeRule = markInputRule(/(?:`)([^`]+)(?:`)$/, schema.marks.code);
|
|
2410
|
-
var strikeRule = markInputRule(/(?:~~)([^~]+)(?:~~)$/, schema.marks.strike);
|
|
2411
|
-
var markdownInputRules = inputRules({ rules: [
|
|
2412
|
-
...smartQuotes,
|
|
2413
|
-
ellipsis,
|
|
2414
|
-
emDash,
|
|
2415
|
-
blockQuoteRule,
|
|
2416
|
-
orderedListRule,
|
|
2417
|
-
bulletListRule,
|
|
2418
|
-
codeBlockRule,
|
|
2419
|
-
headingRule,
|
|
2420
|
-
taskListRule,
|
|
2421
|
-
horizontalRuleInputRule,
|
|
2422
|
-
strongRule,
|
|
2423
|
-
emRule,
|
|
2424
|
-
codeRule,
|
|
2425
|
-
strikeRule
|
|
2426
|
-
] });
|
|
2427
|
-
//#endregion
|
|
2428
|
-
//#region src/editor/plugins/placeholderPlugin.ts
|
|
2429
|
-
var placeholderPluginKey = new PluginKey("placeholderPlugin");
|
|
2430
|
-
function isNodeEmpty(node) {
|
|
2431
|
-
const defaultContent = node.type.createAndFill();
|
|
2432
|
-
if (!defaultContent) return true;
|
|
2433
|
-
return node.content.eq(defaultContent.content);
|
|
2434
|
-
}
|
|
2435
|
-
function placeholderPlugin(text) {
|
|
2436
|
-
return new Plugin({
|
|
2437
|
-
key: placeholderPluginKey,
|
|
2438
|
-
props: { decorations: (state) => {
|
|
2439
|
-
const doc = state.doc;
|
|
2440
|
-
const decorations = [];
|
|
2441
|
-
const isEmptyDoc = doc.childCount === 1 && doc.firstChild?.isTextblock && doc.firstChild.content.size === 0;
|
|
2442
|
-
const { anchor } = state.selection;
|
|
2443
|
-
doc.descendants((node, pos) => {
|
|
2444
|
-
if (!node.isLeaf && isNodeEmpty(node)) {
|
|
2445
|
-
const nodeEnd = pos + node.nodeSize;
|
|
2446
|
-
if (!(anchor >= pos && anchor <= nodeEnd) && !isEmptyDoc) return false;
|
|
2447
|
-
const classes = ["is-empty"];
|
|
2448
|
-
if (isEmptyDoc) classes.push("is-editor-empty");
|
|
2449
|
-
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
2450
|
-
class: classes.join(" "),
|
|
2451
|
-
"data-placeholder": text
|
|
2452
|
-
}));
|
|
2453
|
-
}
|
|
2454
|
-
return false;
|
|
2455
|
-
});
|
|
2456
|
-
return DecorationSet.create(doc, decorations);
|
|
2457
|
-
} }
|
|
2458
|
-
});
|
|
2459
|
-
}
|
|
2460
|
-
//#endregion
|
|
2461
|
-
//#region src/editor/plugins/index.ts
|
|
2462
|
-
var customKeymap = {
|
|
2463
|
-
"Tab": goToNextCell(1),
|
|
2464
|
-
"Shift-Tab": goToNextCell(-1),
|
|
2465
|
-
"Mod-z": undo,
|
|
2466
|
-
"Mod-y": redo,
|
|
2467
|
-
"Shift-Mod-z": redo,
|
|
2468
|
-
"Mod-b": toggleMark(schema.marks.bold),
|
|
2469
|
-
"Mod-i": toggleMark(schema.marks.italic),
|
|
2470
|
-
"Mod-u": toggleMark(schema.marks.underline),
|
|
2471
|
-
"Mod-Shift-s": toggleMark(schema.marks.strike),
|
|
2472
|
-
"Mod-e": toggleMark(schema.marks.code),
|
|
2473
|
-
"Mod-Shift-h": toggleMark(schema.marks.highlight),
|
|
2474
|
-
"Enter": splitListItem(schema.nodes.list_item),
|
|
2475
|
-
"Shift-Enter": splitListItem(schema.nodes.task_item),
|
|
2476
|
-
"Mod-[": liftListItem(schema.nodes.list_item),
|
|
2477
|
-
"Mod-]": sinkListItem(schema.nodes.list_item),
|
|
2478
|
-
"Shift-Mod-8": setBlockType(schema.nodes.bullet_list),
|
|
2479
|
-
"Shift-Mod-9": setBlockType(schema.nodes.ordered_list),
|
|
2480
|
-
"Mod-Alt-1": setBlockType(schema.nodes.heading, { level: 1 }),
|
|
2481
|
-
"Mod-Alt-2": setBlockType(schema.nodes.heading, { level: 2 }),
|
|
2482
|
-
"Mod-Alt-3": setBlockType(schema.nodes.heading, { level: 3 }),
|
|
2483
|
-
"Mod-Alt-0": setBlockType(schema.nodes.paragraph)
|
|
2484
|
-
};
|
|
2485
|
-
var getCorePlugins = () => [
|
|
2486
|
-
history(),
|
|
2487
|
-
keymap(customKeymap),
|
|
2488
|
-
keymap(baseKeymap),
|
|
2489
|
-
globalDragDropPlugin(),
|
|
2490
|
-
gapCursor(),
|
|
2491
|
-
slashCommandPlugin(),
|
|
2492
|
-
dragHandlePlugin(),
|
|
2493
|
-
highlightDecorationPlugin(),
|
|
2494
|
-
textLoadingDecorationPlugin(),
|
|
2495
|
-
markdownInputRules,
|
|
2496
|
-
placeholderPlugin("Press '/' for commands")
|
|
2497
|
-
];
|
|
2498
|
-
//#endregion
|
|
2499
|
-
//#region src/editor/nodeViews/ReactNodeView.tsx
|
|
2500
|
-
/**
|
|
2501
|
-
* A utility class that implements the ProseMirror NodeView interface but delegates rendering
|
|
2502
|
-
* to a React component.
|
|
2503
|
-
* Note: This uses createRoot, so it does not automatically inherit React Contexts.
|
|
2504
|
-
* If contexts are needed, wrap them manually or use a portal-based approach instead.
|
|
2505
|
-
*/
|
|
2506
|
-
var ReactNodeView = class {
|
|
2507
|
-
node;
|
|
2508
|
-
view;
|
|
2509
|
-
getPos;
|
|
2510
|
-
dom;
|
|
2511
|
-
contentDOM;
|
|
2512
|
-
root;
|
|
2513
|
-
Component;
|
|
2514
|
-
constructor(node, view, getPos, Component, as = "div", className, contentDOMElement) {
|
|
2515
|
-
this.node = node;
|
|
2516
|
-
this.view = view;
|
|
2517
|
-
this.getPos = getPos;
|
|
2518
|
-
this.Component = Component;
|
|
2519
|
-
this.dom = document.createElement(as);
|
|
2520
|
-
if (className) this.dom.className = className;
|
|
2521
|
-
if (contentDOMElement) this.contentDOM = contentDOMElement;
|
|
2522
|
-
const container = document.createElement("div");
|
|
2523
|
-
this.dom.appendChild(container);
|
|
2524
|
-
if (this.contentDOM) this.dom.appendChild(this.contentDOM);
|
|
2525
|
-
this.root = createRoot(container);
|
|
2526
|
-
this.render();
|
|
2527
|
-
}
|
|
2528
|
-
render() {
|
|
2529
|
-
this.root.render(/* @__PURE__ */ jsx(this.Component, {
|
|
2530
|
-
node: this.node,
|
|
2531
|
-
view: this.view,
|
|
2532
|
-
getPos: this.getPos
|
|
2533
|
-
}));
|
|
2534
|
-
}
|
|
2535
|
-
update(node) {
|
|
2536
|
-
if (node.type !== this.node.type) return false;
|
|
2537
|
-
this.node = node;
|
|
2538
|
-
this.render();
|
|
2539
|
-
return true;
|
|
2540
|
-
}
|
|
2541
|
-
destroy() {
|
|
2542
|
-
this.root.unmount();
|
|
2543
|
-
}
|
|
2544
|
-
ignoreMutation(mutation) {
|
|
2545
|
-
if (!this.contentDOM) return true;
|
|
2546
|
-
return !this.contentDOM.contains(mutation.target);
|
|
2547
|
-
}
|
|
2548
|
-
};
|
|
2549
|
-
//#endregion
|
|
2550
|
-
//#region src/editor/nodeViews/TaskItemComponent.tsx
|
|
2551
|
-
var TaskItemComponent = ({ node, view, getPos }) => {
|
|
2552
|
-
const checked = node.attrs.checked;
|
|
2553
|
-
const handleCheckedChange = (isChecked) => {
|
|
2554
|
-
const pos = getPos();
|
|
2555
|
-
if (typeof pos !== "number") return;
|
|
2556
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, void 0, {
|
|
2557
|
-
...node.attrs,
|
|
2558
|
-
checked: isChecked
|
|
2559
|
-
}));
|
|
2560
|
-
};
|
|
2561
|
-
return /* @__PURE__ */ jsx(Label, {
|
|
2562
|
-
contentEditable: false,
|
|
2563
|
-
className: "flex items-start select-none px-1 cursor-pointer",
|
|
2564
|
-
children: /* @__PURE__ */ jsx(Checkbox, {
|
|
2565
|
-
checked,
|
|
2566
|
-
onCheckedChange: handleCheckedChange,
|
|
2567
|
-
padding: false,
|
|
2568
|
-
size: "small"
|
|
2569
|
-
})
|
|
2570
|
-
});
|
|
2571
|
-
};
|
|
2572
|
-
//#endregion
|
|
2573
|
-
//#region src/editor/nodeViews/ImageComponent.tsx
|
|
2574
|
-
var ImageComponent = ({ node, view, getPos }) => {
|
|
2575
|
-
const selected = view.state.selection.from === getPos();
|
|
2576
|
-
return /* @__PURE__ */ jsx("img", {
|
|
2577
|
-
src: node.attrs.src,
|
|
2578
|
-
alt: node.attrs.alt || "",
|
|
2579
|
-
title: node.attrs.title || "",
|
|
2580
|
-
className: cls("rounded-lg max-w-full !m-0", selected ? "" : "")
|
|
2581
|
-
});
|
|
2582
|
-
};
|
|
2583
|
-
//#endregion
|
|
2584
|
-
//#region src/editor/nodeViews/index.ts
|
|
2585
|
-
function createReactNodeView(Component, as = "div", className, createContentDOM) {
|
|
2586
|
-
return (node, view, getPos) => {
|
|
2587
|
-
return new ReactNodeView(node, view, getPos, Component, as, className, createContentDOM ? createContentDOM() : void 0);
|
|
2588
|
-
};
|
|
2589
|
-
}
|
|
2590
|
-
var nodeViews = {
|
|
2591
|
-
task_item: createReactNodeView(TaskItemComponent, "li", "flex items-start", () => {
|
|
2592
|
-
const dom = document.createElement("div");
|
|
2593
|
-
dom.className = "flex-grow min-w-0";
|
|
2594
|
-
return dom;
|
|
2595
|
-
}),
|
|
2596
|
-
image: createReactNodeView(ImageComponent, "span", "inline-block w-full")
|
|
2597
|
-
};
|
|
2598
|
-
//#endregion
|
|
2599
|
-
//#region src/editor/hooks/useProseMirror.ts
|
|
2600
|
-
var trailingNodePlugin = new Plugin({ appendTransaction: (_, oldState, newState) => {
|
|
2601
|
-
const doc = newState.doc;
|
|
2602
|
-
if (doc.lastChild && doc.lastChild.type.name !== "paragraph") return newState.tr.insert(doc.content.size, newState.schema.nodes.paragraph.create());
|
|
2603
|
-
return null;
|
|
2604
|
-
} });
|
|
2605
|
-
function useProseMirror({ initialContent, editable = true, handleImageUpload }) {
|
|
2606
|
-
const plugins = [
|
|
2607
|
-
...getCorePlugins(),
|
|
2608
|
-
columnResizing(),
|
|
2609
|
-
tableEditing(),
|
|
2610
|
-
trailingNodePlugin
|
|
2611
|
-
];
|
|
2612
|
-
if (handleImageUpload) plugins.push(createDropImagePlugin(handleImageUpload));
|
|
2613
|
-
const defaultState = EditorState.create({
|
|
2614
|
-
doc: typeof initialContent === "string" ? parser.parse(initialContent) : initialContent ? schema.nodeFromJSON(initialContent) : schema.node("doc", null, [schema.node("paragraph")]),
|
|
2615
|
-
schema,
|
|
2616
|
-
plugins
|
|
2617
|
-
});
|
|
2618
|
-
const [state, setState] = useState(defaultState);
|
|
2619
|
-
const [view, setView] = useState(null);
|
|
2620
|
-
const editorRef = useRef(null);
|
|
2621
|
-
const viewRef = useRef(null);
|
|
2622
|
-
useLayoutEffect(() => {
|
|
2623
|
-
if (!editorRef.current) return;
|
|
2624
|
-
const editorView = new EditorView(editorRef.current, {
|
|
2625
|
-
state: defaultState,
|
|
2626
|
-
editable: () => editable,
|
|
2627
|
-
dispatchTransaction: (tr) => {
|
|
2628
|
-
const newState = editorView.state.apply(tr);
|
|
2629
|
-
editorView.updateState(newState);
|
|
2630
|
-
setState(newState);
|
|
2631
|
-
},
|
|
2632
|
-
nodeViews,
|
|
2633
|
-
transformPastedHTML(html) {
|
|
2634
|
-
const div = parseSanitizedHtml(html);
|
|
2635
|
-
div.querySelectorAll("*").forEach((el) => {
|
|
2636
|
-
el.removeAttribute("style");
|
|
2637
|
-
el.removeAttribute("class");
|
|
2638
|
-
el.removeAttribute("color");
|
|
2639
|
-
el.removeAttribute("bgcolor");
|
|
2640
|
-
el.removeAttribute("face");
|
|
2641
|
-
});
|
|
2642
|
-
return div.innerHTML;
|
|
2643
|
-
}
|
|
2644
|
-
});
|
|
2645
|
-
const originalPosAtCoords = editorView.posAtCoords.bind(editorView);
|
|
2646
|
-
editorView.posAtCoords = (coords) => {
|
|
2647
|
-
const res = originalPosAtCoords(coords);
|
|
2648
|
-
if (!res) {
|
|
2649
|
-
const editorRect = editorView.dom.getBoundingClientRect();
|
|
2650
|
-
if (coords.left <= editorRect.left) {
|
|
2651
|
-
const probeX = editorRect.left + Math.min(60, editorRect.width / 4);
|
|
2652
|
-
return originalPosAtCoords({
|
|
2653
|
-
left: probeX,
|
|
2654
|
-
top: coords.top
|
|
2655
|
-
});
|
|
2656
|
-
}
|
|
2657
|
-
if (coords.left >= editorRect.right) {
|
|
2658
|
-
const probeX = editorRect.right - Math.min(60, editorRect.width / 4);
|
|
2659
|
-
return originalPosAtCoords({
|
|
2660
|
-
left: probeX,
|
|
2661
|
-
top: coords.top
|
|
2662
|
-
});
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
return res;
|
|
2666
|
-
};
|
|
2667
|
-
viewRef.current = editorView;
|
|
2668
|
-
setView(editorView);
|
|
2669
|
-
return () => {
|
|
2670
|
-
editorView.destroy();
|
|
2671
|
-
viewRef.current = null;
|
|
2672
|
-
};
|
|
2673
|
-
}, []);
|
|
2674
|
-
useEffect(() => {
|
|
2675
|
-
if (viewRef.current) viewRef.current.setProps({ editable: () => editable });
|
|
2676
|
-
}, [editable]);
|
|
2677
|
-
return {
|
|
2678
|
-
state,
|
|
2679
|
-
view,
|
|
2680
|
-
editorRef
|
|
2681
|
-
};
|
|
2682
|
-
}
|
|
2683
|
-
//#endregion
|
|
2684
|
-
//#region src/editor/editor.tsx
|
|
2685
|
-
var proseClasses = {
|
|
2686
|
-
"sm": "prose-sm",
|
|
2687
|
-
"base": "prose-base",
|
|
2688
|
-
"lg": "prose-lg"
|
|
2689
|
-
};
|
|
2690
|
-
var RichTextEditor = ({ content, onJsonContentChange, onHtmlContentChange, onMarkdownContentChange, version, textSize = "base", highlight, handleImageUpload, aiController, disabled }) => {
|
|
2691
|
-
const { t } = useTranslation();
|
|
2692
|
-
const [openNode, setOpenNode] = useState(false);
|
|
2693
|
-
const [openLink, setOpenLink] = useState(false);
|
|
2694
|
-
const [isMarkdownMode, setIsMarkdownMode] = useState(false);
|
|
2695
|
-
const [internalMarkdown, setInternalMarkdown] = useState("");
|
|
2696
|
-
useEffect(() => {
|
|
2697
|
-
if (!isMarkdownMode) return;
|
|
2698
|
-
const timeout = setTimeout(() => {
|
|
2699
|
-
if (callbacksRef.current.onMarkdownContentChange) callbacksRef.current.onMarkdownContentChange(internalMarkdown);
|
|
2700
|
-
}, 250);
|
|
2701
|
-
return () => clearTimeout(timeout);
|
|
2702
|
-
}, [internalMarkdown, isMarkdownMode]);
|
|
2703
|
-
const handleToggleMarkdown = () => {
|
|
2704
|
-
if (!isMarkdownMode) {
|
|
2705
|
-
if (view) setInternalMarkdown(serializer.serialize(view.state.doc));
|
|
2706
|
-
setIsMarkdownMode(true);
|
|
2707
|
-
} else {
|
|
2708
|
-
if (view) {
|
|
2709
|
-
const newDoc = parser.parse(internalMarkdown);
|
|
2710
|
-
if (newDoc) {
|
|
2711
|
-
const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);
|
|
2712
|
-
view.dispatch(tr);
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
setIsMarkdownMode(false);
|
|
2716
|
-
}
|
|
2717
|
-
};
|
|
2718
|
-
const handleMarkdownChange = (e) => {
|
|
2719
|
-
setInternalMarkdown(e.target.value);
|
|
2720
|
-
};
|
|
2721
|
-
const handleMarkdownBlur = () => {
|
|
2722
|
-
const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;
|
|
2723
|
-
if (onMarkdownContentChange) onMarkdownContentChange(internalMarkdown);
|
|
2724
|
-
if (onJsonContentChange) try {
|
|
2725
|
-
const newDoc = parser.parse(internalMarkdown);
|
|
2726
|
-
if (newDoc) onJsonContentChange(removeClassesFromJson(newDoc.toJSON()));
|
|
2727
|
-
} catch (e) {
|
|
2728
|
-
console.warn("Could not parse markdown to JSON", e);
|
|
2729
|
-
}
|
|
2730
|
-
};
|
|
2731
|
-
useInjectStyles("Editor", cssStyles);
|
|
2732
|
-
const callbacksRef = useRef({
|
|
2733
|
-
onMarkdownContentChange,
|
|
2734
|
-
onJsonContentChange
|
|
2735
|
-
});
|
|
2736
|
-
useEffect(() => {
|
|
2737
|
-
callbacksRef.current = {
|
|
2738
|
-
onMarkdownContentChange,
|
|
2739
|
-
onJsonContentChange
|
|
2740
|
-
};
|
|
2741
|
-
}, [onMarkdownContentChange, onJsonContentChange]);
|
|
2742
|
-
const flushChanges = (currentState) => {
|
|
2743
|
-
const { onMarkdownContentChange, onJsonContentChange } = callbacksRef.current;
|
|
2744
|
-
if (onMarkdownContentChange) try {
|
|
2745
|
-
onMarkdownContentChange(serializer.serialize(currentState.doc));
|
|
2746
|
-
} catch (e) {
|
|
2747
|
-
console.warn("[RichTextEditor] Could not serialize editor state to markdown:", e);
|
|
2748
|
-
}
|
|
2749
|
-
if (onJsonContentChange) onJsonContentChange(removeClassesFromJson(currentState.doc.toJSON()));
|
|
2750
|
-
};
|
|
2751
|
-
const { state, view, editorRef } = useProseMirror({
|
|
2752
|
-
initialContent: content,
|
|
2753
|
-
editable: !disabled,
|
|
2754
|
-
handleImageUpload
|
|
2755
|
-
});
|
|
2756
|
-
const versionRef = useRef(version);
|
|
2757
|
-
useEffect(() => {
|
|
2758
|
-
if (versionRef.current === version) return;
|
|
2759
|
-
versionRef.current = version;
|
|
2760
|
-
if (!view) return;
|
|
2761
|
-
try {
|
|
2762
|
-
const newDoc = typeof content === "string" ? parser.parse(content ?? "") : content ? schema.nodeFromJSON(content) : schema.node("doc", null, [schema.node("paragraph")]);
|
|
2763
|
-
if (newDoc) {
|
|
2764
|
-
const tr = view.state.tr.replaceWith(0, view.state.doc.content.size, newDoc.content);
|
|
2765
|
-
view.dispatch(tr);
|
|
2766
|
-
}
|
|
2767
|
-
} catch (e) {
|
|
2768
|
-
console.warn("[RichTextEditor] Could not reset editor content:", e);
|
|
2769
|
-
}
|
|
2770
|
-
if (isMarkdownMode) setInternalMarkdown(typeof content === "string" ? content : "");
|
|
2771
|
-
mountTimeRef.current = Date.now();
|
|
2772
|
-
hasUserEditedRef.current = false;
|
|
2773
|
-
}, [version]);
|
|
2774
|
-
const doc = state?.doc;
|
|
2775
|
-
const mountTimeRef = useRef(Date.now());
|
|
2776
|
-
const hasUserEditedRef = useRef(false);
|
|
2777
|
-
useEffect(() => {
|
|
2778
|
-
if (!state) return;
|
|
2779
|
-
if (Date.now() - mountTimeRef.current < 500 && !hasUserEditedRef.current) return;
|
|
2780
|
-
hasUserEditedRef.current = true;
|
|
2781
|
-
const timeout = setTimeout(() => {
|
|
2782
|
-
flushChanges(state);
|
|
2783
|
-
}, 250);
|
|
2784
|
-
return () => clearTimeout(timeout);
|
|
2785
|
-
}, [doc]);
|
|
2786
|
-
useEffect(() => {
|
|
2787
|
-
if (!view) return;
|
|
2788
|
-
const dom = view.dom;
|
|
2789
|
-
const handleBlur = () => {
|
|
2790
|
-
if (!hasUserEditedRef.current) {
|
|
2791
|
-
if (Date.now() - mountTimeRef.current < 500) return;
|
|
2792
|
-
}
|
|
2793
|
-
flushChanges(view.state);
|
|
2794
|
-
};
|
|
2795
|
-
dom.addEventListener("blur", handleBlur);
|
|
2796
|
-
return () => dom.removeEventListener("blur", handleBlur);
|
|
2797
|
-
}, [view]);
|
|
2798
|
-
useEffect(() => {
|
|
2799
|
-
if (view) if (highlight) highlightCommands.toggleAutocompleteHighlight(highlight)(view.state, view.dispatch);
|
|
2800
|
-
else highlightCommands.removeAutocompleteHighlight()(view.state, view.dispatch);
|
|
2801
|
-
}, [highlight?.from, highlight?.to]);
|
|
2802
|
-
const proseClass = proseClasses[textSize];
|
|
2803
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
2804
|
-
className: "relative min-h-[200px] w-full flex flex-col",
|
|
2805
|
-
children: [/* @__PURE__ */ jsx("button", {
|
|
2806
|
-
type: "button",
|
|
2807
|
-
onClick: handleToggleMarkdown,
|
|
2808
|
-
title: isMarkdownMode ? "Switch to Visual Editor" : "Switch to Markdown",
|
|
2809
|
-
className: "absolute top-2 right-2 z-10 px-2 py-1 text-xs font-medium text-surface-400 hover:text-surface-700 dark:text-surface-600 dark:hover:text-surface-300 transition-colors opacity-50 hover:opacity-100 bg-transparent rounded",
|
|
2810
|
-
children: isMarkdownMode ? "Visual" : "Markdown"
|
|
2811
|
-
}), /* @__PURE__ */ jsxs(ProseMirrorContext.Provider, {
|
|
2812
|
-
value: useMemo(() => ({
|
|
2813
|
-
state,
|
|
2814
|
-
view
|
|
2815
|
-
}), [state, view]),
|
|
2816
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2817
|
-
style: { display: isMarkdownMode ? "none" : "flex" },
|
|
2818
|
-
className: "flex-1 flex flex-col",
|
|
2819
|
-
children: [
|
|
2820
|
-
/* @__PURE__ */ jsx("div", {
|
|
2821
|
-
ref: editorRef,
|
|
2822
|
-
onClick: (e) => {
|
|
2823
|
-
if (view && e.target === e.currentTarget) {
|
|
2824
|
-
view.focus();
|
|
2825
|
-
const end = view.state.doc.content.size;
|
|
2826
|
-
const tr = view.state.tr.setSelection(Selection.near(view.state.doc.resolve(end), -1));
|
|
2827
|
-
view.dispatch(tr);
|
|
2828
|
-
}
|
|
2829
|
-
},
|
|
2830
|
-
className: cls("relative prose dark:prose-invert cursor-text flex-1", proseClass, "prose-headings:font-title prose-headings:font-normal prose-strong:font-semibold prose-code:font-normal prose-blockquote:font-normal prose-a:font-normal font-default focus:outline-none max-w-full py-4")
|
|
2831
|
-
}),
|
|
2832
|
-
view && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2833
|
-
/* @__PURE__ */ jsxs(EditorBubble, {
|
|
2834
|
-
options: {
|
|
2835
|
-
placement: "top",
|
|
2836
|
-
offset: 6
|
|
2837
|
-
},
|
|
2838
|
-
className: cls("flex w-fit max-w-[90vw] h-10 overflow-hidden rounded border bg-surface-card shadow", defaultBorderMixin),
|
|
2839
|
-
children: [
|
|
2840
|
-
/* @__PURE__ */ jsx(NodeSelector, {
|
|
2841
|
-
portalContainer: editorRef.current,
|
|
2842
|
-
open: openNode,
|
|
2843
|
-
onOpenChange: setOpenNode
|
|
2844
|
-
}),
|
|
2845
|
-
/* @__PURE__ */ jsx(Separator, { orientation: "vertical" }),
|
|
2846
|
-
/* @__PURE__ */ jsx(LinkSelector, {
|
|
2847
|
-
open: openLink,
|
|
2848
|
-
onOpenChange: setOpenLink
|
|
2849
|
-
}),
|
|
2850
|
-
/* @__PURE__ */ jsx(Separator, { orientation: "vertical" }),
|
|
2851
|
-
/* @__PURE__ */ jsx(TextButtons, {})
|
|
2852
|
-
]
|
|
2853
|
-
}),
|
|
2854
|
-
/* @__PURE__ */ jsx(ImageBubble, { options: {
|
|
2855
|
-
placement: "bottom",
|
|
2856
|
-
offset: 6
|
|
2857
|
-
} }),
|
|
2858
|
-
/* @__PURE__ */ jsx(TableBubble, {})
|
|
2859
|
-
] }),
|
|
2860
|
-
/* @__PURE__ */ jsx(SlashCommandMenu, {
|
|
2861
|
-
upload: handleImageUpload,
|
|
2862
|
-
aiController
|
|
2863
|
-
})
|
|
2864
|
-
]
|
|
2865
|
-
}), isMarkdownMode && /* @__PURE__ */ jsx(TextareaAutosize, {
|
|
2866
|
-
value: internalMarkdown,
|
|
2867
|
-
onChange: handleMarkdownChange,
|
|
2868
|
-
onBlur: handleMarkdownBlur,
|
|
2869
|
-
className: cls("w-full h-full min-h-[200px] px-12 py-4 bg-transparent resize-none font-mono focus:ring-0", proseClass),
|
|
2870
|
-
style: {
|
|
2871
|
-
tabSize: 4,
|
|
2872
|
-
outline: "none",
|
|
2873
|
-
border: "none",
|
|
2874
|
-
boxShadow: "none"
|
|
2875
|
-
}
|
|
2876
|
-
})]
|
|
2877
|
-
})]
|
|
2878
|
-
});
|
|
2879
|
-
};
|
|
2880
|
-
var cssStyles = `
|
|
2881
|
-
.ProseMirror {
|
|
2882
|
-
box-shadow: none !important;
|
|
2883
|
-
padding-left: 2rem;
|
|
2884
|
-
padding-right: 2rem;
|
|
2885
|
-
min-height: 100%;
|
|
2886
|
-
}
|
|
2887
|
-
.ProseMirror .is-editor-empty:first-child::before {
|
|
2888
|
-
content: attr(data-placeholder);
|
|
2889
|
-
float: left;
|
|
2890
|
-
color: rgb(100 116 139); //500
|
|
2891
|
-
pointer-events: none;
|
|
2892
|
-
height: 0;
|
|
2893
|
-
}
|
|
2894
|
-
.ProseMirror .is-empty::before {
|
|
2895
|
-
content: attr(data-placeholder);
|
|
2896
|
-
float: left;
|
|
2897
|
-
color: rgb(100 116 139); //500
|
|
2898
|
-
pointer-events: none;
|
|
2899
|
-
height: 0;
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
[data-theme="dark"] {
|
|
2903
|
-
.ProseMirror .is-empty::before {
|
|
2904
|
-
color: rgb(100 116 139); //500
|
|
2905
|
-
}
|
|
2906
|
-
}
|
|
2907
|
-
|
|
2908
|
-
.is-empty {
|
|
2909
|
-
cursor: text;
|
|
2910
|
-
color: rgb(100 116 139); //500
|
|
2911
|
-
}
|
|
2912
|
-
|
|
2913
|
-
.ProseMirror img {
|
|
2914
|
-
transition: filter 0.1s ease-in-out;
|
|
2915
|
-
}
|
|
2916
|
-
.ProseMirror img:hover {
|
|
2917
|
-
cursor: pointer;
|
|
2918
|
-
filter: brightness(90%);
|
|
2919
|
-
}
|
|
2920
|
-
.ProseMirror img.ProseMirror-selectednode {
|
|
2921
|
-
filter: brightness(90%);
|
|
2922
|
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000) !important;
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2925
|
-
ul[data-type="taskList"] li > label {
|
|
2926
|
-
margin-right: 0.2rem;
|
|
2927
|
-
user-select: none;
|
|
2928
|
-
}
|
|
2929
|
-
@media screen and (max-width: 768px) {
|
|
2930
|
-
ul[data-type="taskList"] li > label {
|
|
2931
|
-
margin-right: 0.5rem;
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
[data-theme="dark"] ul[data-type="taskList"] li > label input[type="checkbox"] {
|
|
2935
|
-
background-color: rgb(30 41 59);
|
|
2936
|
-
border: 2px solid #666;
|
|
2937
|
-
}
|
|
2938
|
-
[data-theme="dark"] ul[data-type="taskList"] li > label input[type="checkbox"]:hover { background-color: rgb(51 65 85); }
|
|
2939
|
-
[data-theme="dark"] ul[data-type="taskList"] li > label input[type="checkbox"]:active { background-color: rgb(71 85 105); }
|
|
2940
|
-
ul[data-type="taskList"] li > label input[type="checkbox"] {
|
|
2941
|
-
-webkit-appearance: none;
|
|
2942
|
-
appearance: none;
|
|
2943
|
-
background-color: white;
|
|
2944
|
-
margin: 0;
|
|
2945
|
-
cursor: pointer;
|
|
2946
|
-
width: 1.2em;
|
|
2947
|
-
height: 1.2em;
|
|
2948
|
-
position: relative;
|
|
2949
|
-
top: 5px;
|
|
2950
|
-
border: 2px solid #777;
|
|
2951
|
-
border-radius: 0.25em;
|
|
2952
|
-
margin-right: 0.3rem;
|
|
2953
|
-
display: grid;
|
|
2954
|
-
place-content: center;
|
|
2955
|
-
}
|
|
2956
|
-
ul[data-type="taskList"] li > label input[type="checkbox"]:hover { background-color: rgb(241 245 249); }
|
|
2957
|
-
ul[data-type="taskList"] li > label input[type="checkbox"]:active { background-color: rgb(226 232 240); }
|
|
2958
|
-
ul[data-type="taskList"] li > label input[type="checkbox"]::before {
|
|
2959
|
-
content: "";
|
|
2960
|
-
width: 0.65em;
|
|
2961
|
-
height: 0.65em;
|
|
2962
|
-
transform: scale(0);
|
|
2963
|
-
transition: 120ms transform ease-in-out;
|
|
2964
|
-
box-shadow: inset 1em 1em;
|
|
2965
|
-
transform-origin: center;
|
|
2966
|
-
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
|
|
2967
|
-
}
|
|
2968
|
-
ul[data-type="taskList"] li > label input[type="checkbox"]:checked::before { transform: scale(1); }
|
|
2969
|
-
|
|
2970
|
-
[data-theme="dark"] {
|
|
2971
|
-
ul[data-type="taskList"] li[data-checked="true"] > div > p {
|
|
2972
|
-
color: rgb(226 232 240);
|
|
2973
|
-
text-decoration: line-through;
|
|
2974
|
-
text-decoration-thickness: 2px;
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
ul[data-type="taskList"] li[data-checked="true"] > div > p {
|
|
2978
|
-
color: rgb(51 65 85);
|
|
2979
|
-
text-decoration: line-through;
|
|
2980
|
-
text-decoration-thickness: 2px;
|
|
2981
|
-
}
|
|
2982
|
-
.tippy-box { max-width: 400px !important; }
|
|
2983
|
-
|
|
2984
|
-
.ProseMirror:not(.dragging) .ProseMirror-selectednode {
|
|
2985
|
-
background-color: rgb(219 234 254);
|
|
2986
|
-
transition: background-color 0.2s;
|
|
2987
|
-
box-shadow: none;
|
|
2988
|
-
}
|
|
2989
|
-
[data-theme="dark"] .ProseMirror:not(.dragging) .ProseMirror-selectednode {
|
|
2990
|
-
background-color: rgb(51 65 85);
|
|
2991
|
-
}
|
|
2992
|
-
.prose-base table p { margin: 0; }
|
|
2993
|
-
|
|
2994
|
-
.drag-handle {
|
|
2995
|
-
position: absolute;
|
|
2996
|
-
opacity: 1;
|
|
2997
|
-
transition: opacity ease-in 0.2s;
|
|
2998
|
-
border-radius: 0.25rem;
|
|
2999
|
-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' style='fill: rgba(128, 128, 128, 0.9)'%3E%3Cpath d='M3,2 C2.44771525,2 2,1.55228475 2,1 C2,0.44771525 2.44771525,0 3,0 C3.55228475,0 4,0.44771525 4,1 C4,1.55228475 3.55228475,2 3,2 Z M3,6 C2.44771525,6 2,5.55228475 2,5 C2,4.44771525 2.44771525,4 3,4 C3.55228475,4 4,4.44771525 4,5 C4,5.55228475 3.55228475,6 3,6 Z M3,10 C2.44771525,10 2,9.55228475 2,9 C2,8.44771525 2.44771525,8 3,8 C3.55228475,8 4,8.44771525 4,9 C4,9.55228475 3.55228475,10 3,10 Z M7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 C7.55228475,0 8,0.44771525 8,1 C8,1.55228475 7.55228475,2 7,2 Z M7,6 C6.44771525,6 6,5.55228475 6,5 C6,4.44771525 6.44771525,4 7,4 C7.55228475,4 8,4.44771525 8,5 C8,5.55228475 7.55228475,6 7,6 Z M7,10 C6.44771525,10 6,9.55228475 6,9 C6,8.44771525 6.44771525,8 7,8 C7,8.44771525 7,9 7,9 C7,9.55228475 7,10 7,10 Z'%3E%3C/path%3E%3C/svg%3E");
|
|
3000
|
-
background-size: calc(0.5em + 0.375rem) calc(0.5em + 0.375rem);
|
|
3001
|
-
background-repeat: no-repeat;
|
|
3002
|
-
background-position: center;
|
|
3003
|
-
width: 1.2rem;
|
|
3004
|
-
height: 1.5rem;
|
|
3005
|
-
z-index: 100;
|
|
3006
|
-
cursor: grab;
|
|
3007
|
-
}
|
|
3008
|
-
.drag-handle::before {
|
|
3009
|
-
content: '';
|
|
3010
|
-
position: absolute;
|
|
3011
|
-
top: -10px;
|
|
3012
|
-
bottom: -10px;
|
|
3013
|
-
left: -20px;
|
|
3014
|
-
right: 0px;
|
|
3015
|
-
z-index: -1;
|
|
3016
|
-
}
|
|
3017
|
-
.drag-handle:hover { background-color: rgb(241 245 249); transition: background-color 0.2s; }
|
|
3018
|
-
.drag-handle:active { background-color: rgb(226 232 240); transition: background-color 0.2s; }
|
|
3019
|
-
.drag-handle.hide { opacity: 0; pointer-events: none; }
|
|
3020
|
-
@media screen and (max-width: 600px) { .drag-handle { display: none; pointer-events: none; } }
|
|
3021
|
-
[data-theme="dark"] .drag-handle:hover { background-color: rgb(51 65 85); }
|
|
3022
|
-
[data-theme="dark"] .drag-handle:active { background-color: rgb(51 65 85); }
|
|
3023
|
-
.prosemirror-dropcursor-block {
|
|
3024
|
-
background-color: var(--color-surface-accent-600);
|
|
3025
|
-
}
|
|
3026
|
-
[data-theme="dark"] .prosemirror-dropcursor-block {
|
|
3027
|
-
background-color: var(--color-surface-accent-300);
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
.ProseMirror table {
|
|
3031
|
-
border-collapse: separate;
|
|
3032
|
-
border-spacing: 0;
|
|
3033
|
-
table-layout: fixed;
|
|
3034
|
-
width: 100%;
|
|
3035
|
-
margin: 1em 0;
|
|
3036
|
-
overflow: hidden;
|
|
3037
|
-
border-radius: 0.375rem;
|
|
3038
|
-
border: 1px solid #e5e7eb;
|
|
3039
|
-
}
|
|
3040
|
-
[data-theme="dark"] .ProseMirror table {
|
|
3041
|
-
border-color: #374151;
|
|
3042
|
-
}
|
|
3043
|
-
|
|
3044
|
-
.ProseMirror td, .ProseMirror th {
|
|
3045
|
-
min-width: 1em;
|
|
3046
|
-
padding: 8px 10px;
|
|
3047
|
-
vertical-align: top;
|
|
3048
|
-
box-sizing: border-box;
|
|
3049
|
-
position: relative;
|
|
3050
|
-
border-right: 1px solid #e5e7eb;
|
|
3051
|
-
border-bottom: 1px solid #e5e7eb;
|
|
3052
|
-
}
|
|
3053
|
-
[data-theme="dark"] .ProseMirror td, [data-theme="dark"] .ProseMirror th {
|
|
3054
|
-
border-right-color: #374151;
|
|
3055
|
-
border-bottom-color: #374151;
|
|
3056
|
-
}
|
|
3057
|
-
|
|
3058
|
-
.ProseMirror tr:last-child td, .ProseMirror tr:last-child th {
|
|
3059
|
-
border-bottom: none;
|
|
3060
|
-
}
|
|
3061
|
-
.ProseMirror th:last-child, .ProseMirror td:last-child {
|
|
3062
|
-
border-right: none;
|
|
3063
|
-
}
|
|
3064
|
-
|
|
3065
|
-
.ProseMirror td {
|
|
3066
|
-
background-color: transparent;
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
.ProseMirror th {
|
|
3070
|
-
font-weight: 600;
|
|
3071
|
-
text-align: left;
|
|
3072
|
-
background-color: #f3f4f6;
|
|
3073
|
-
color: #374151;
|
|
3074
|
-
}
|
|
3075
|
-
[data-theme="dark"] .ProseMirror td {
|
|
3076
|
-
background-color: transparent;
|
|
3077
|
-
}
|
|
3078
|
-
[data-theme="dark"] .ProseMirror th {
|
|
3079
|
-
background-color: rgba(255, 255, 255, 0.05);
|
|
3080
|
-
color: #d1d5db;
|
|
3081
|
-
}
|
|
3082
|
-
`;
|
|
3083
|
-
//#endregion
|
|
1
|
+
import { RichTextEditor } from "./editor/editor.js";
|
|
3084
2
|
export { RichTextEditor };
|
|
3085
|
-
|
|
3086
|
-
//# sourceMappingURL=editor.js.map
|