mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	chore(ckeditor): create shared type for editor
This commit is contained in:
		| @@ -26,7 +26,7 @@ import type TypeWidget from "../widgets/type_widgets/type_widget.js"; | ||||
| import type EditableTextTypeWidget from "../widgets/type_widgets/editable_text.js"; | ||||
| import type { NativeImage, TouchBar } from "electron"; | ||||
| import TouchBarComponent from "./touch_bar.js"; | ||||
| import type { ClassicEditor, PopupEditor } from "@triliumnext/ckeditor5"; | ||||
| import type { CKTextEditor } from "@triliumnext/ckeditor5"; | ||||
|  | ||||
| interface Layout { | ||||
|     getRootWidget: (appContext: AppContext) => RootWidget; | ||||
| @@ -188,7 +188,7 @@ export type CommandMappings = { | ||||
|         callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void; | ||||
|     }; | ||||
|     executeWithTextEditor: CommandData & | ||||
|     ExecuteCommandData<ClassicEditor | PopupEditor> & { | ||||
|     ExecuteCommandData<CKTextEditor> & { | ||||
|         callback?: GetTextEditorCallback; | ||||
|     }; | ||||
|     executeWithCodeEditor: CommandData & ExecuteCommandData<CodeMirrorInstance>; | ||||
|   | ||||
| @@ -10,14 +10,14 @@ import options from "../services/options.js"; | ||||
| import type { ViewScope } from "../services/link.js"; | ||||
| import type FNote from "../entities/fnote.js"; | ||||
| import type TypeWidget from "../widgets/type_widgets/type_widget.js"; | ||||
| import type { ClassicEditor, PopupEditor } from "@triliumnext/ckeditor5"; | ||||
| import type { CKTextEditor } from "@triliumnext/ckeditor5"; | ||||
|  | ||||
| export interface SetNoteOpts { | ||||
|     triggerSwitchEvent?: unknown; | ||||
|     viewScope?: ViewScope; | ||||
| } | ||||
|  | ||||
| export type GetTextEditorCallback = (editor: ClassicEditor | PopupEditor) => void; | ||||
| export type GetTextEditorCallback = (editor: CKTextEditor) => void; | ||||
|  | ||||
| class NoteContext extends Component implements EventListener<"entitiesReloaded"> { | ||||
|     ntxId: string | null; | ||||
| @@ -299,7 +299,7 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded"> | ||||
|     } | ||||
|  | ||||
|     async getTextEditor(callback?: GetTextEditorCallback) { | ||||
|         return this.timeout<ClassicEditor | PopupEditor>( | ||||
|         return this.timeout<CKTextEditor>( | ||||
|             new Promise((resolve) => | ||||
|                 appContext.triggerCommand("executeWithTextEditor", { | ||||
|                     callback, | ||||
|   | ||||
| @@ -18,7 +18,7 @@ import { buildSelectedBackgroundColor } from "../../components/touch_bar.js"; | ||||
| import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js"; | ||||
| import type FNote from "../../entities/fnote.js"; | ||||
| import { getMermaidConfig } from "../../services/mermaid.js"; | ||||
| import { PopupEditor, ClassicEditor, EditorWatchdog } from "@triliumnext/ckeditor5"; | ||||
| import { PopupEditor, ClassicEditor, EditorWatchdog, type CKTextEditor } from "@triliumnext/ckeditor5"; | ||||
|  | ||||
| const ENABLE_INSPECTOR = false; | ||||
|  | ||||
| @@ -128,7 +128,7 @@ function buildListOfLanguages() { | ||||
| export default class EditableTextTypeWidget extends AbstractTextTypeWidget { | ||||
|  | ||||
|     private contentLanguage?: string | null; | ||||
|     private watchdog!: EditorWatchdog<ClassicEditor | PopupEditor>; | ||||
|     private watchdog!: EditorWatchdog<CKTextEditor>; | ||||
|  | ||||
|     private $editor!: JQuery<HTMLElement>; | ||||
|  | ||||
| @@ -158,7 +158,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { | ||||
|         // display of $widget in both branches. | ||||
|         this.$widget.show(); | ||||
|  | ||||
|         this.watchdog = new EditorWatchdog<ClassicEditor | PopupEditor>(editorClass, { | ||||
|         this.watchdog = new EditorWatchdog<CKTextEditor>(editorClass, { | ||||
|             // An average number of milliseconds between the last editor errors (defaults to 5000). | ||||
|             // When the period of time between errors is lower than that and the crashNumberLimit | ||||
|             // is also reached, the watchdog changes its state to crashedPermanently, and it stops | ||||
|   | ||||
| @@ -3,18 +3,33 @@ import { COMMON_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins"; | ||||
| import { BalloonEditor, DecoupledEditor } from "ckeditor5"; | ||||
| export { EditorWatchdog } from "ckeditor5"; | ||||
|  | ||||
| /** | ||||
|  * Short-hand for the CKEditor classes supported by Trilium for text editing. | ||||
|  * Specialized editors such as the {@link AttributeEditor} are not included. | ||||
|  */ | ||||
| export type CKTextEditor = ClassicEditor | PopupEditor; | ||||
|  | ||||
| /** | ||||
|  * The text editor that can be used for editing attributes and relations. | ||||
|  */ | ||||
| export class AttributeEditor extends BalloonEditor { | ||||
|     static override get builtinPlugins() { | ||||
|         return []; | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * A text editor configured as a {@link DecoupledEditor} (fixed toolbar mode), as well as its preconfigured plugins. | ||||
|  */ | ||||
| export class ClassicEditor extends DecoupledEditor { | ||||
|     static override get builtinPlugins() { | ||||
|         return COMMON_PLUGINS; | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * A text editor configured as a {@link BalloonEditor} (floating toolbar mode), as well as its preconfigured plugins. | ||||
|  */ | ||||
| export class PopupEditor extends BalloonEditor { | ||||
|     static override get builtinPlugins() { | ||||
|         return POPUP_EDITOR_PLUGINS; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user