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 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: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,
|
|
|
|
|
commandName: "insertDateTimeToText"
|
|
|
|
|
}
|
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,
|
2025-06-16 20:22:37 +03:00
|
|
|
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
|
|
|
|