feat(insert time): Add inserting time via UI

This commit is contained in:
SiriusXT 2025-06-01 19:15:59 +08:00
parent 22586bfcc0
commit cef362c123
4 changed files with 46 additions and 2 deletions

View File

@ -189,7 +189,7 @@ export function buildClassicToolbar(multilineToolbar: boolean) {
{
label: "Insert",
icon: "plus",
items: ["imageUpload", "|", "link", "bookmark", "internallink", "includeNote", "|", "specialCharacters", "emoji", "math", "mermaid", "horizontalLine", "pageBreak"]
items: ["imageUpload", "|", "link", "bookmark", "internallink", "includeNote", "|", "specialCharacters", "emoji", "math", "mermaid", "horizontalLine", "pageBreak", "dateTime"]
},
"|",
"outdent",
@ -244,7 +244,7 @@ export function buildFloatingToolbar() {
{
label: "Insert",
icon: "plus",
items: ["internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak"]
items: ["internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak", "dateTime"]
},
"|",
"outdent",

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" xmlns="http://www.w3.org/2000/svg"
width="800px" height="800px" viewBox="0 0 52 52" enable-background="new 0 0 52 52" xml:space="preserve">
<path d="M43.6,6.8h-4V5.2c0-1.8-1.4-3.2-3.2-3.2c-1.8,0-3.2,1.4-3.2,3.2v1.6H18.8V5.2c0-1.8-1.4-3.2-3.2-3.2
s-3.2,1.4-3.2,3.2v1.6h-4c-2.6,0-4.8,2.2-4.8,4.8v1.6c0,0.9,0.7,1.6,1.6,1.6h41.6c0.9,0,1.6-0.7,1.6-1.6v-1.6
C48.4,9,46.2,6.8,43.6,6.8z"/>
<path d="M46.8,19.6H5.2c-0.9,0-1.6,0.7-1.6,1.6v24c0,2.6,2.2,4.8,4.8,4.8h35.2c2.6,0,4.8-2.2,4.8-4.8v-24
C48.4,20.3,47.7,19.6,46.8,19.6z M26,46.7c-6.6,0-11.9-5.4-11.9-11.9c0-6.6,5.4-11.9,11.9-11.9s11.9,5.4,11.9,11.9
C37.9,41.4,32.6,46.7,26,46.7z"/>
<path d="M27.2,34.3v-5.1c0-0.4-0.4-0.8-0.8-0.8h-0.8c-0.4,0-0.8,0.4-0.8,0.8v5.6c0,0.3,0.1,0.6,0.4,0.8l3.8,3.8
c0.3,0.3,0.8,0.3,1.1,0l0.6-0.6c0.3-0.3,0.3-0.8,0-1.1L27.2,34.3z"/>
</svg>

After

Width:  |  Height:  |  Size: 958 B

View File

@ -5,6 +5,7 @@ import UploadimagePlugin from "./plugins/uploadimage.js";
import ItalicAsEmPlugin from "./plugins/italic_as_em.js";
import StrikethroughAsDel from "./plugins/strikethrough_as_del.js";
import InternalLinkPlugin from "./plugins/internallink.js";
import InsertDateTimePlugin from "./plugins/insertDateTime.js";
import ReferenceLink from "./plugins/referencelink.js";
import RemoveFormatLinksPlugin from "./plugins/remove_format_links.js";
import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js";
@ -36,6 +37,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [
ItalicAsEmPlugin,
StrikethroughAsDel,
InternalLinkPlugin,
InsertDateTimePlugin,
RemoveFormatLinksPlugin,
IndentBlockShortcutPlugin,
MarkdownImportPlugin,

View File

@ -0,0 +1,30 @@
import { ButtonView, Plugin } from 'ckeditor5';
import dateTimeIcon from '../icons/date-time.svg?raw';
export default class InsertDateTimePlugin extends Plugin {
init() {
const editor = this.editor;
editor.ui.componentFactory.add('dateTime', locale => {
const view = new ButtonView( locale );
view.set( {
label: 'Date time',
icon: dateTimeIcon,
tooltip: true
} );
// enable internal link only if the editor is not read only
view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly);
view.on('execute', () => {
const editorEl = editor.editing.view.getDomRoot();
const component = glob.getComponentByEl(editorEl);
component.triggerCommand('insertDateTimeToText');
} );
return view;
});
}
}