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 62a2d6ad8d
commit a820b45c90
8 changed files with 36 additions and 35 deletions

View file

@ -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",

View file

@ -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<CommandData>;
@ -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<string> => {
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 "";
}
}

View file

@ -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<string> {
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) {

View file

@ -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:*",

View file

@ -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<HTMLElement>, href: string): Promise<void>;
// 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;
}

View file

@ -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<EditorComponent>(editorEl);

View file

@ -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";

View file

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