Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(ckeditor): create shared type for editor
Elian Doran70ec38d53423
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex a0ebd6a6a9..1855876d36 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -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>;diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.tsindex f1500ee42a..81eae41e1a 100644--- a/apps/client/src/components/note_context.ts+++ b/apps/client/src/components/note_context.ts@@ -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,diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.tsindex 3e8163f98d..e3caf18b30 100644--- a/apps/client/src/widgets/type_widgets/editable_text.ts+++ b/apps/client/src/widgets/type_widgets/editable_text.ts@@ -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 stopsdiff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.tsindex 7ce7f501b8..2edbae35a9 100644--- a/packages/ckeditor5/src/index.ts+++ b/packages/ckeditor5/src/index.ts@@ -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;