Files
Trilium/packages/ckeditor5/src/extra_slash_commands.ts

79 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-06-16 20:15:44 +03:00
import type { Editor } from 'ckeditor5';
import type { SlashCommandEditorConfig } from 'ckeditor5-premium-features';
import { icons as admonitionIcons } from '@triliumnext/ckeditor5-admonition';
2025-06-16 20:20:33 +03:00
import { icons as footnoteIcons } from '@triliumnext/ckeditor5-footnotes';
2025-06-16 21:10:39 +03:00
import IconPageBreak from "@ckeditor/ckeditor5-icons/theme/icons/page-break.svg?raw";
2025-06-16 20:58:42 +03:00
import { COMMAND_NAME as INSERT_DATE_TIME_COMMAND } from './plugins/insert_date_time.js';
import { COMMAND_NAME as INTERNAL_LINK_COMMAND } from './plugins/internallink.js';
import { COMMAND_NAME as INCLUDE_NOTE_COMMAND } from './plugins/includenote.js';
2025-06-16 20:15:44 +03:00
import { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition';
2025-06-16 20:42:55 +03:00
import dateTimeIcon from './icons/date-time.svg?raw';
2025-06-16 20:48:01 +03:00
import internalLinkIcon from './icons/trilium.svg?raw';
2025-06-16 20:58:42 +03:00
import noteIcon from './icons/note.svg?raw';
2025-06-16 20:55:02 +03:00
import { icons as mathIcons, MathUI } from '@triliumnext/ckeditor5-math';
2025-06-16 20:15:44 +03:00
type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
export default function buildExtraCommands(): SlashCommandDefinition[] {
return [
2025-06-16 20:20:33 +03:00
...buildAdmonitionExtraCommands(),
2025-06-16 20:42:55 +03:00
{
id: 'footnote',
title: 'Footnote',
description: 'Create a new footnote and reference it here',
icon: footnoteIcons.insertFootnoteIcon,
commandName: "InsertFootnote"
},
{
id: "datetime",
title: "Insert Date/Time",
description: "Insert the current date and time",
icon: dateTimeIcon,
2025-06-16 20:48:01 +03:00
commandName: INSERT_DATE_TIME_COMMAND
},
{
id: "internal-link",
title: "Internal Trilium link",
description: "Insert a link to another Trilium note",
icon: internalLinkIcon,
commandName: INTERNAL_LINK_COMMAND
2025-06-16 20:55:02 +03:00
},
{
id: "math",
title: "Math equation",
description: "Insert a math equation",
icon: mathIcons.ckeditor,
execute: (editor: Editor) => editor.plugins.get(MathUI)._showUI()
2025-06-16 20:58:42 +03:00
},
{
id: "include-note",
title: "Include note",
description: "Display the content of another note in this note",
icon: noteIcon,
commandName: INCLUDE_NOTE_COMMAND
2025-06-16 21:10:39 +03:00
},
{
id: "page-break",
title: "Page break",
description: "Insert a page break (for printing)",
icon: IconPageBreak,
commandName: "pageBreak"
2025-06-16 20:42:55 +03:00
}
2025-06-16 20:15:44 +03:00
];
}
function buildAdmonitionExtraCommands(): SlashCommandDefinition[] {
const commands: SlashCommandDefinition[] = [];
for (const [ keyword, definition ] of Object.entries(ADMONITION_TYPES)) {
commands.push({
id: keyword,
title: definition.title,
description: "Inserts a new admonition",
2025-06-16 20:15:44 +03:00
icon: admonitionIcons.admonitionIcon,
execute: (editor: Editor) => editor.execute("admonition", { forceValue: keyword as AdmonitionType })
});
}
return commands;
}
2025-06-16 20:20:33 +03:00