diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index ffcf09a..64340d1 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -168,6 +168,16 @@ action: () => void; } + function insertTimestamp(kind: 'date' | 'time' | 'datetime') { + if (!editor) return; + const now = new Date(); + const pad = (n: number) => String(n).padStart(2, '0'); + const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; + const time = `${pad(now.getHours())}:${pad(now.getMinutes())}`; + const text = kind === 'date' ? date : kind === 'time' ? time : `${date} ${time}`; + editor.chain().focus().insertContent(text).run(); + } + function getSlashCommands(): SlashCommand[] { return [ { label: 'Heading 1', aliases: ['h1', 'heading1', 'title'], icon: '', action: () => editor?.chain().focus().toggleHeading({ level: 1 }).run() }, @@ -184,6 +194,9 @@ { label: 'Page Break', aliases: ['pagebreak', 'page', 'break', 'newpage', 'print'], icon: '', action: () => editor?.chain().focus().insertContent({ type: 'pageBreak' }).run() }, { label: 'Math Block', aliases: ['math', 'latex', 'equation', 'formula', 'tex', 'katex'], icon: '', action: () => openMathInsert('block') }, { label: 'Math Inline', aliases: ['mathinline', 'inline-math', 'imath', 'inlinemath'], icon: '', action: () => openMathInsert('inline') }, + { label: 'Date', aliases: ['date', 'today', 'day'], icon: '', action: () => insertTimestamp('date') }, + { label: 'Time', aliases: ['time', 'clock'], icon: '', action: () => insertTimestamp('time') }, + { label: 'Date & Time', aliases: ['datetime', 'now', 'timestamp', 'stamp'], icon: '', action: () => insertTimestamp('datetime') }, ]; } @@ -3443,6 +3456,11 @@ closeTextContextMenu(); } + function ctxTimestamp() { + insertTimestamp('datetime'); + closeTextContextMenu(); + } + function openDetailsEl(el: HTMLElement) { if (!el.classList.contains('is-open')) { el.classList.add('is-open'); @@ -4679,6 +4697,13 @@
+ + + + + + {/if} @@ -5161,6 +5190,10 @@ Collapsible Section +