diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts index 23d3f9409..80f323957 100644 --- a/apps/client/src/services/note_autocomplete.ts +++ b/apps/client/src/services/note_autocomplete.ts @@ -5,7 +5,7 @@ import froca from "./froca.js"; import { t } from "./i18n.js"; import commandRegistry from "./command_registry.js"; import type { MentionFeedObjectItem } from "@triliumnext/ckeditor5"; -import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js"; +import { CreateNoteAction } from "@triliumnext/commons" /** * Extends CKEditor's MentionFeedObjectItem with extra fields used by Trilium. @@ -42,14 +42,14 @@ let searchDelay = getSearchDelay(notesCount); // String values ensure stable, human-readable identifiers across serialization (JSON, CKEditor, logs). export enum SuggestionAction { - // These values intentionally mirror MentionAction string values 1:1. + // These values intentionally mirror CreateNoteAction string values 1:1. // This overlap ensures that when a suggestion triggers a note creation callback, // the receiving features (e.g. note creation handlers, CKEditor mentions) can interpret // the action type consistently - CreateNoteIntoInbox = MentionAction.CreateNoteIntoInbox, - CreateNoteIntoPath = MentionAction.CreateNoteIntoPath, - CreateAndLinkNoteIntoInbox = MentionAction.CreateAndLinkNoteIntoInbox, - CreateAndLinkNoteIntoPath = MentionAction.CreateAndLinkNoteIntoPath, + CreateNoteIntoInbox = CreateNoteAction.CreateNoteIntoInbox, + CreateNoteIntoPath = CreateNoteAction.CreateNoteIntoPath, + CreateAndLinkNoteIntoInbox = CreateNoteAction.CreateAndLinkNoteIntoInbox, + CreateAndLinkNoteIntoPath = CreateNoteAction.CreateAndLinkNoteIntoPath, SearchNotes = "search-notes", ExternalLink = "external-link", diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index dd5f556b7..40fe34794 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -20,7 +20,7 @@ import type { CommandData, FilteredCommandNames } from "../../../components/app_ import { AttributeType } from "@triliumnext/commons"; import attributes from "../../../services/attributes"; import note_create from "../../../services/note_create"; -import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js"; +import { CreateNoteAction } from "@triliumnext/commons"; type AttributeCommandNames = FilteredCommandNames; @@ -256,7 +256,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI createNoteFromCkEditor: async ( title: string, parentNotePath: string | undefined, - action: MentionAction + action: CreateNoteAction ): Promise => { if (!parentNotePath) { console.warn("Missing parentNotePath in createNoteFromCkEditor()"); @@ -264,8 +264,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI } switch (action) { - case MentionAction.CreateNoteIntoInbox: - case MentionAction.CreateAndLinkNoteIntoInbox: { + case CreateNoteAction.CreateNoteIntoInbox: + case CreateNoteAction.CreateAndLinkNoteIntoInbox: { const { note } = await note_create.createNoteIntoInbox({ title, activate: false @@ -273,8 +273,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI return note?.getBestNotePathString() ?? ""; } - case MentionAction.CreateNoteIntoPath: - case MentionAction.CreateAndLinkNoteIntoPath: { + case CreateNoteAction.CreateNoteIntoPath: + case CreateNoteAction.CreateAndLinkNoteIntoPath: { const resp = await note_create.createNoteIntoPathWithTypePrompt(parentNotePath, { title, activate: false @@ -283,7 +283,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI } default: - console.warn("Unknown MentionAction:", action); + console.warn("Unknown CreateNoteAction:", action); return ""; } } diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.ts index e61e3a652..3d0899647 100644 --- a/apps/client/src/widgets/type_widgets/editable_text.ts +++ b/apps/client/src/widgets/type_widgets/editable_text.ts @@ -13,7 +13,7 @@ import { buildConfig, BuildEditorOptions, OPEN_SOURCE_LICENSE_KEY } from "./cked import type FNote from "../../entities/fnote.js"; import { PopupEditor, ClassicEditor, EditorWatchdog, type CKTextEditor, type MentionFeed, type WatchdogConfig, EditorConfig } from "@triliumnext/ckeditor5"; import { updateTemplateCache } from "./ckeditor/snippets.js"; -import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js"; +import { CreateNoteAction } from "@triliumnext/commons"; import note_create from "../../services/note_create.js"; export type BoxSize = "small" | "medium" | "full"; @@ -496,12 +496,12 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { async createNoteFromCkEditor ( title: string, parentNotePath: string | undefined, - action: MentionAction + action: CreateNoteAction ): Promise { try { switch (action) { // --- Create note INTO inbox --- - case MentionAction.CreateNoteIntoInbox: { + case CreateNoteAction.CreateNoteIntoInbox: { const { success, noteType, templateNoteId } = await note_create.chooseNoteType(); if (!success) return ""; @@ -516,7 +516,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } // --- Create note INTO current path --- - case MentionAction.CreateNoteIntoPath: { + case CreateNoteAction.CreateNoteIntoPath: { const { success, noteType, templateNoteId, notePath } = await note_create.chooseNoteType(); if (!success) return ""; @@ -531,7 +531,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } // --- Create & link note INTO inbox --- - case MentionAction.CreateAndLinkNoteIntoInbox: { + case CreateNoteAction.CreateAndLinkNoteIntoInbox: { const { success, noteType, templateNoteId } = await note_create.chooseNoteType(); if (!success) return ""; @@ -546,7 +546,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } // --- Create & link note INTO current path --- - case MentionAction.CreateAndLinkNoteIntoPath: { + case CreateNoteAction.CreateAndLinkNoteIntoPath: { const { success, noteType, templateNoteId, notePath } = await note_create.chooseNoteType(); if (!success) return ""; @@ -561,7 +561,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { } default: - console.warn("Unknown MentionAction:", action); + console.warn("Unknown CreateNoteAction:", action); return ""; } } catch (err) { diff --git a/packages/ckeditor5/package.json b/packages/ckeditor5/package.json index a467432da..0f24c73aa 100644 --- a/packages/ckeditor5/package.json +++ b/packages/ckeditor5/package.json @@ -6,6 +6,7 @@ "type": "module", "main": "./src/index.ts", "dependencies": { + "@triliumnext/commons": "workspace:*", "@triliumnext/ckeditor5-admonition": "workspace:*", "@triliumnext/ckeditor5-footnotes": "workspace:*", "@triliumnext/ckeditor5-keyboard-marker": "workspace:*", diff --git a/packages/ckeditor5/src/augmentation.ts b/packages/ckeditor5/src/augmentation.ts index 79e298244..f77ee4ce5 100644 --- a/packages/ckeditor5/src/augmentation.ts +++ b/packages/ckeditor5/src/augmentation.ts @@ -1,12 +1,5 @@ import "ckeditor5"; -import { CKTextEditor } from "src"; - -export enum MentionAction { - CreateNoteIntoInbox = "create-note-into-inbox", - CreateNoteIntoPath = "create-note-into-path", - CreateAndLinkNoteIntoInbox = "create-and-link-note-into-inbox", - CreateAndLinkNoteIntoPath = "create-and-link-note-into-path" -} +import { type CreateNoteAction } from "@triliumnext/commons" declare global { interface Component { @@ -16,7 +9,7 @@ declare global { interface EditorComponent extends Component { loadReferenceLinkTitle($el: JQuery, href: string): Promise; // Must Return Note Path - createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: MentionAction): Promise; + createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: CreateNoteAction): Promise; loadIncludedNote(noteId: string, $el: JQuery): void; } diff --git a/packages/ckeditor5/src/plugins/mention_customization.ts b/packages/ckeditor5/src/plugins/mention_customization.ts index ec9109174..9b8db2c5c 100644 --- a/packages/ckeditor5/src/plugins/mention_customization.ts +++ b/packages/ckeditor5/src/plugins/mention_customization.ts @@ -1,5 +1,5 @@ import { Command, Mention, Plugin, ModelRange, type ModelSelectable } from "ckeditor5"; -import { MentionAction } from "../augmentation"; +import { type CreateNoteAction } from "@triliumnext/commons" /** * Overrides the actions taken by the Mentions plugin (triggered by `@` in the text editor, or `~` & `#` in the attribute editor): @@ -37,7 +37,7 @@ interface MentionOpts { interface MentionAttribute { id: string; - action?: MentionAction; + action?: CreateNoteAction; noteTitle: string; notePath: string; parentNoteId?: string; @@ -59,10 +59,10 @@ class CustomMentionCommand extends Command { }); } else if ( - mention.action === MentionAction.CreateNoteIntoInbox || - mention.action === MentionAction.CreateNoteIntoPath || - mention.action === MentionAction.CreateAndLinkNoteIntoInbox || - mention.action === MentionAction.CreateAndLinkNoteIntoPath + mention.action === CreateNoteAction.CreateNoteIntoInbox || + mention.action === CreateNoteAction.CreateNoteIntoPath || + mention.action === CreateNoteAction.CreateAndLinkNoteIntoInbox || + mention.action === CreateNoteAction.CreateAndLinkNoteIntoPath ) { const editorEl = this.editor.editing.view.getDomRoot(); const component = glob.getComponentByEl(editorEl); diff --git a/packages/commons/src/index.ts b/packages/commons/src/index.ts index c74cd758f..a942b1576 100644 --- a/packages/commons/src/index.ts +++ b/packages/commons/src/index.ts @@ -10,4 +10,5 @@ export * from "./lib/server_api.js"; export * from "./lib/shared_constants.js"; export * from "./lib/ws_api.js"; export * from "./lib/attribute_names.js"; +export * from "./lib/create_note_actions.js"; export * from "./lib/utils.js"; diff --git a/packages/commons/src/lib/create_note_actions.ts b/packages/commons/src/lib/create_note_actions.ts new file mode 100644 index 000000000..6b6594963 --- /dev/null +++ b/packages/commons/src/lib/create_note_actions.ts @@ -0,0 +1,6 @@ +export enum CreateNoteAction { + CreateNoteIntoInbox, + CreateNoteIntoPath, + CreateAndLinkNoteIntoInbox, + CreateAndLinkNoteIntoPath +}