rename MentionAction to CreateNoteAction and move to packages/common

This commit is contained in:
contributor 2025-10-12 23:06:53 +03:00 committed by Jakob Schlanstedt
parent 74bf93059c
commit 2b55db05e1
6 changed files with 28 additions and 28 deletions

View File

@ -5,7 +5,7 @@ import froca from "./froca.js";
import { t } from "./i18n.js"; import { t } from "./i18n.js";
import commandRegistry from "./command_registry.js"; import commandRegistry from "./command_registry.js";
import type { MentionFeedObjectItem } from "@triliumnext/ckeditor5"; 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. * 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). // String values ensure stable, human-readable identifiers across serialization (JSON, CKEditor, logs).
export enum SuggestionAction { 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, // 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 receiving features (e.g. note creation handlers, CKEditor mentions) can interpret
// the action type consistently // the action type consistently
CreateNoteIntoInbox = MentionAction.CreateNoteIntoInbox, CreateNoteIntoInbox = CreateNoteAction.CreateNoteIntoInbox,
CreateNoteIntoPath = MentionAction.CreateNoteIntoPath, CreateNoteIntoPath = CreateNoteAction.CreateNoteIntoPath,
CreateAndLinkNoteIntoInbox = MentionAction.CreateAndLinkNoteIntoInbox, CreateAndLinkNoteIntoInbox = CreateNoteAction.CreateAndLinkNoteIntoInbox,
CreateAndLinkNoteIntoPath = MentionAction.CreateAndLinkNoteIntoPath, CreateAndLinkNoteIntoPath = CreateNoteAction.CreateAndLinkNoteIntoPath,
SearchNotes = "search-notes", SearchNotes = "search-notes",
ExternalLink = "external-link", ExternalLink = "external-link",

View File

@ -20,7 +20,7 @@ import type { CommandData, FilteredCommandNames } from "../../../components/app_
import { AttributeType } from "@triliumnext/commons"; import { AttributeType } from "@triliumnext/commons";
import attributes from "../../../services/attributes"; import attributes from "../../../services/attributes";
import note_create from "../../../services/note_create"; import note_create from "../../../services/note_create";
import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js"; import { CreateNoteAction } from "@triliumnext/commons";
type AttributeCommandNames = FilteredCommandNames<CommandData>; type AttributeCommandNames = FilteredCommandNames<CommandData>;
@ -251,7 +251,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
createNoteFromCkEditor: async ( createNoteFromCkEditor: async (
title: string, title: string,
parentNotePath: string | undefined, parentNotePath: string | undefined,
action: MentionAction action: CreateNoteAction
): Promise<string> => { ): Promise<string> => {
if (!parentNotePath) { if (!parentNotePath) {
console.warn("Missing parentNotePath in createNoteFromCkEditor()"); console.warn("Missing parentNotePath in createNoteFromCkEditor()");
@ -259,8 +259,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
} }
switch (action) { switch (action) {
case MentionAction.CreateNoteIntoInbox: case CreateNoteAction.CreateNoteIntoInbox:
case MentionAction.CreateAndLinkNoteIntoInbox: { case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
const { note } = await note_create.createNoteIntoInbox({ const { note } = await note_create.createNoteIntoInbox({
title, title,
activate: false activate: false
@ -268,8 +268,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
return note?.getBestNotePathString() ?? ""; return note?.getBestNotePathString() ?? "";
} }
case MentionAction.CreateNoteIntoPath: case CreateNoteAction.CreateNoteIntoPath:
case MentionAction.CreateAndLinkNoteIntoPath: { case CreateNoteAction.CreateAndLinkNoteIntoPath: {
const resp = await note_create.createNoteIntoPathWithTypePrompt(parentNotePath, { const resp = await note_create.createNoteIntoPathWithTypePrompt(parentNotePath, {
title, title,
activate: false activate: false
@ -278,7 +278,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
} }
default: default:
console.warn("Unknown MentionAction:", action); console.warn("Unknown CreateNoteAction:", action);
return ""; return "";
} }
} }

View File

@ -1,12 +1,5 @@
import "ckeditor5"; import "ckeditor5";
import { CKTextEditor } from "src"; import { type CreateNoteAction } from "@triliumnext/commons"
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"
}
declare global { declare global {
interface Component { interface Component {
@ -16,7 +9,7 @@ declare global {
interface EditorComponent extends Component { interface EditorComponent extends Component {
loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>; loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>;
// Must Return Note Path // Must Return Note Path
createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: MentionAction): Promise<string>; createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: CreateNoteAction): Promise<string>;
loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>): void; loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>): void;
} }

View File

@ -1,5 +1,5 @@
import { Command, Mention, Plugin, ModelRange, type ModelSelectable } from "ckeditor5"; 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): * 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 { interface MentionAttribute {
id: string; id: string;
action?: MentionAction; action?: CreateNoteAction;
noteTitle: string; noteTitle: string;
notePath: string; notePath: string;
parentNoteId?: string; parentNoteId?: string;
@ -59,10 +59,10 @@ class CustomMentionCommand extends Command {
}); });
} }
else if ( else if (
mention.action === MentionAction.CreateNoteIntoInbox || mention.action === CreateNoteAction.CreateNoteIntoInbox ||
mention.action === MentionAction.CreateNoteIntoPath || mention.action === CreateNoteAction.CreateNoteIntoPath ||
mention.action === MentionAction.CreateAndLinkNoteIntoInbox || mention.action === CreateNoteAction.CreateAndLinkNoteIntoInbox ||
mention.action === MentionAction.CreateAndLinkNoteIntoPath mention.action === CreateNoteAction.CreateAndLinkNoteIntoPath
) { ) {
const editorEl = this.editor.editing.view.getDomRoot(); const editorEl = this.editor.editing.view.getDomRoot();
const component = glob.getComponentByEl<EditorComponent>(editorEl); const component = glob.getComponentByEl<EditorComponent>(editorEl);

View File

@ -10,4 +10,5 @@ export * from "./lib/server_api.js";
export * from "./lib/shared_constants.js"; export * from "./lib/shared_constants.js";
export * from "./lib/ws_api.js"; export * from "./lib/ws_api.js";
export * from "./lib/attribute_names.js"; export * from "./lib/attribute_names.js";
export * from "./lib/create_note_actions.js";
export * from "./lib/utils.js"; export * from "./lib/utils.js";

View File

@ -0,0 +1,6 @@
export enum CreateNoteAction {
CreateNoteIntoInbox,
CreateNoteIntoPath,
CreateAndLinkNoteIntoInbox,
CreateAndLinkNoteIntoPath
}