Skip to content

Commit 8f499d1

Browse files
contributorJakob Schlanstedt
authored andcommitted
rename MentionAction to CreateNoteAction and move to packages/common
1 parent bc87aae commit 8f499d1

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

apps/client/src/services/note_autocomplete.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import froca from "./froca.js";
55
import { t } from "./i18n.js";
66
import commandRegistry from "./command_registry.js";
77
import type { MentionFeedObjectItem } from "@triliumnext/ckeditor5";
8-
import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js";
8+
import { CreateNoteAction } from "@triliumnext/commons"
99

1010
/**
1111
* Extends CKEditor's MentionFeedObjectItem with extra fields used by Trilium.
@@ -42,14 +42,14 @@ let searchDelay = getSearchDelay(notesCount);
4242

4343
// String values ensure stable, human-readable identifiers across serialization (JSON, CKEditor, logs).
4444
export enum SuggestionAction {
45-
// These values intentionally mirror MentionAction string values 1:1.
45+
// These values intentionally mirror CreateNoteAction string values 1:1.
4646
// This overlap ensures that when a suggestion triggers a note creation callback,
4747
// the receiving features (e.g. note creation handlers, CKEditor mentions) can interpret
4848
// the action type consistently
49-
CreateNoteIntoInbox = MentionAction.CreateNoteIntoInbox,
50-
CreateNoteIntoPath = MentionAction.CreateNoteIntoPath,
51-
CreateAndLinkNoteIntoInbox = MentionAction.CreateAndLinkNoteIntoInbox,
52-
CreateAndLinkNoteIntoPath = MentionAction.CreateAndLinkNoteIntoPath,
49+
CreateNoteIntoInbox = CreateNoteAction.CreateNoteIntoInbox,
50+
CreateNoteIntoPath = CreateNoteAction.CreateNoteIntoPath,
51+
CreateAndLinkNoteIntoInbox = CreateNoteAction.CreateAndLinkNoteIntoInbox,
52+
CreateAndLinkNoteIntoPath = CreateNoteAction.CreateAndLinkNoteIntoPath,
5353

5454
SearchNotes = "search-notes",
5555
ExternalLink = "external-link",

apps/client/src/widgets/ribbon/components/AttributeEditor.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { CommandData, FilteredCommandNames } from "../../../components/app_
2020
import { AttributeType } from "@triliumnext/commons";
2121
import attributes from "../../../services/attributes";
2222
import note_create from "../../../services/note_create";
23-
import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js";
23+
import { CreateNoteAction } from "@triliumnext/commons";
2424

2525
type AttributeCommandNames = FilteredCommandNames<CommandData>;
2626

@@ -256,25 +256,25 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
256256
createNoteFromCkEditor: async (
257257
title: string,
258258
parentNotePath: string | undefined,
259-
action: MentionAction
259+
action: CreateNoteAction
260260
): Promise<string> => {
261261
if (!parentNotePath) {
262262
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
263263
return "";
264264
}
265265

266266
switch (action) {
267-
case MentionAction.CreateNoteIntoInbox:
268-
case MentionAction.CreateAndLinkNoteIntoInbox: {
267+
case CreateNoteAction.CreateNoteIntoInbox:
268+
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
269269
const { note } = await note_create.createNoteIntoInbox({
270270
title,
271271
activate: false
272272
});
273273
return note?.getBestNotePathString() ?? "";
274274
}
275275

276-
case MentionAction.CreateNoteIntoPath:
277-
case MentionAction.CreateAndLinkNoteIntoPath: {
276+
case CreateNoteAction.CreateNoteIntoPath:
277+
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
278278
const resp = await note_create.createNoteIntoPathWithTypePrompt(parentNotePath, {
279279
title,
280280
activate: false
@@ -283,7 +283,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
283283
}
284284

285285
default:
286-
console.warn("Unknown MentionAction:", action);
286+
console.warn("Unknown CreateNoteAction:", action);
287287
return "";
288288
}
289289
}

apps/client/src/widgets/type_widgets/editable_text.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { buildConfig, BuildEditorOptions, OPEN_SOURCE_LICENSE_KEY } from "./cked
1313
import type FNote from "../../entities/fnote.js";
1414
import { PopupEditor, ClassicEditor, EditorWatchdog, type CKTextEditor, type MentionFeed, type WatchdogConfig, EditorConfig } from "@triliumnext/ckeditor5";
1515
import { updateTemplateCache } from "./ckeditor/snippets.js";
16-
import { MentionAction } from "@triliumnext/ckeditor5/src/augmentation.js";
16+
import { CreateNoteAction } from "@triliumnext/commons";
1717
import note_create from "../../services/note_create.js";
1818

1919
export type BoxSize = "small" | "medium" | "full";
@@ -468,12 +468,12 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
468468
async createNoteFromCkEditor (
469469
title: string,
470470
parentNotePath: string | undefined,
471-
action: MentionAction
471+
action: CreateNoteAction
472472
): Promise<string> {
473473
try {
474474
switch (action) {
475475
// --- Create note INTO inbox ---
476-
case MentionAction.CreateNoteIntoInbox: {
476+
case CreateNoteAction.CreateNoteIntoInbox: {
477477
const { success, noteType, templateNoteId } = await note_create.chooseNoteType();
478478
if (!success) return "";
479479

@@ -488,7 +488,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
488488
}
489489

490490
// --- Create note INTO current path ---
491-
case MentionAction.CreateNoteIntoPath: {
491+
case CreateNoteAction.CreateNoteIntoPath: {
492492
const { success, noteType, templateNoteId, notePath } = await note_create.chooseNoteType();
493493
if (!success) return "";
494494

@@ -503,7 +503,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
503503
}
504504

505505
// --- Create & link note INTO inbox ---
506-
case MentionAction.CreateAndLinkNoteIntoInbox: {
506+
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
507507
const { success, noteType, templateNoteId } = await note_create.chooseNoteType();
508508
if (!success) return "";
509509

@@ -518,7 +518,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
518518
}
519519

520520
// --- Create & link note INTO current path ---
521-
case MentionAction.CreateAndLinkNoteIntoPath: {
521+
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
522522
const { success, noteType, templateNoteId, notePath } = await note_create.chooseNoteType();
523523
if (!success) return "";
524524

@@ -533,7 +533,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
533533
}
534534

535535
default:
536-
console.warn("Unknown MentionAction:", action);
536+
console.warn("Unknown CreateNoteAction:", action);
537537
return "";
538538
}
539539
} catch (err) {

packages/ckeditor5/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"type": "module",
77
"main": "./src/index.ts",
88
"dependencies": {
9+
"@triliumnext/commons": "workspace:*",
910
"@triliumnext/ckeditor5-admonition": "workspace:*",
1011
"@triliumnext/ckeditor5-footnotes": "workspace:*",
1112
"@triliumnext/ckeditor5-keyboard-marker": "workspace:*",

packages/ckeditor5/src/augmentation.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import "ckeditor5";
2-
import { CKTextEditor } from "src";
3-
4-
export enum MentionAction {
5-
CreateNoteIntoInbox = "create-note-into-inbox",
6-
CreateNoteIntoPath = "create-note-into-path",
7-
CreateAndLinkNoteIntoInbox = "create-and-link-note-into-inbox",
8-
CreateAndLinkNoteIntoPath = "create-and-link-note-into-path"
9-
}
2+
import { type CreateNoteAction } from "@triliumnext/commons"
103

114
declare global {
125
interface Component {
@@ -16,7 +9,7 @@ declare global {
169
interface EditorComponent extends Component {
1710
loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>;
1811
// Must Return Note Path
19-
createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: MentionAction): Promise<string>;
12+
createNoteFromCkEditor(title: string, parentNotePath: string | undefined, action: CreateNoteAction): Promise<string>;
2013
loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>): void;
2114
}
2215

packages/ckeditor5/src/plugins/mention_customization.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command, Mention, Plugin, ModelRange, type ModelSelectable } from "ckeditor5";
2-
import { MentionAction } from "../augmentation";
2+
import { type CreateNoteAction } from "@triliumnext/commons"
33

44
/**
55
* 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 {
3737

3838
interface MentionAttribute {
3939
id: string;
40-
action?: MentionAction;
40+
action?: CreateNoteAction;
4141
noteTitle: string;
4242
notePath: string;
4343
parentNoteId?: string;
@@ -59,10 +59,10 @@ class CustomMentionCommand extends Command {
5959
});
6060
}
6161
else if (
62-
mention.action === MentionAction.CreateNoteIntoInbox ||
63-
mention.action === MentionAction.CreateNoteIntoPath ||
64-
mention.action === MentionAction.CreateAndLinkNoteIntoInbox ||
65-
mention.action === MentionAction.CreateAndLinkNoteIntoPath
62+
mention.action === CreateNoteAction.CreateNoteIntoInbox ||
63+
mention.action === CreateNoteAction.CreateNoteIntoPath ||
64+
mention.action === CreateNoteAction.CreateAndLinkNoteIntoInbox ||
65+
mention.action === CreateNoteAction.CreateAndLinkNoteIntoPath
6666
) {
6767
const editorEl = this.editor.editing.view.getDomRoot();
6868
const component = glob.getComponentByEl<EditorComponent>(editorEl);

packages/commons/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export * from "./lib/server_api.js";
1010
export * from "./lib/shared_constants.js";
1111
export * from "./lib/ws_api.js";
1212
export * from "./lib/attribute_names.js";
13+
export * from "./lib/create_note_actions.js";
1314
export * from "./lib/utils.js";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum CreateNoteAction {
2+
CreateNoteIntoInbox,
3+
CreateNoteIntoPath,
4+
CreateAndLinkNoteIntoInbox,
5+
CreateAndLinkNoteIntoPath
6+
}

0 commit comments

Comments
 (0)