mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
rename MentionAction to CreateNoteAction and move to packages/common
This commit is contained in:
parent
74bf93059c
commit
2b55db05e1
@ -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",
|
||||
|
||||
@ -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>;
|
||||
|
||||
@ -251,7 +251,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()");
|
||||
@ -259,8 +259,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
|
||||
@ -268,8 +268,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
|
||||
@ -278,7 +278,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
}
|
||||
|
||||
default:
|
||||
console.warn("Unknown MentionAction:", action);
|
||||
console.warn("Unknown CreateNoteAction:", action);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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";
|
||||
|
||||
6
packages/commons/src/lib/create_note_actions.ts
Normal file
6
packages/commons/src/lib/create_note_actions.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export enum CreateNoteAction {
|
||||
CreateNoteIntoInbox,
|
||||
CreateNoteIntoPath,
|
||||
CreateAndLinkNoteIntoInbox,
|
||||
CreateAndLinkNoteIntoPath
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user