AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(editor): add date insertion commands
tianma-ife7915f47aef5
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 75f4b45f..c02423b8 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -913,6 +913,9 @@ const RichEditorPane = ({"code-block": "",divider: "",table: "",+ "current-date": "",+ "current-time": "",+ "current-date-time": "",attachment: "","note-link": "","external-link": "",@@ -940,6 +943,9 @@ const RichEditorPane = ({"code-block": t("editorToolbar.codeBlock"),divider: t("editorToolbar.horizontalRule"),table: t("editorToolbar.table"),+ "current-date": t("slashMenu.items.currentDate"),+ "current-time": t("slashMenu.items.currentTime"),+ "current-date-time": t("slashMenu.items.currentDateTime"),attachment: t("editorToolbar.attachment"),"note-link": t("editorToolbar.noteLink"),"external-link": t("editorToolbar.externalLink"),diff --git a/apps/web/src/components/editor/SlashCommandMenu.test.mjs b/apps/web/src/components/editor/SlashCommandMenu.test.mjsindex 35df275a..495948f7 100644--- a/apps/web/src/components/editor/SlashCommandMenu.test.mjs+++ b/apps/web/src/components/editor/SlashCommandMenu.test.mjs@@ -1,5 +1,11 @@import { describe, expect, test } from "bun:test";-import { createSlashCommandItems, filterSlashCommandItems } from "./SlashCommandMenu.tsx";+import {+ createSlashCommandItems,+ filterSlashCommandItems,+ formatCurrentDate,+ formatCurrentDateTime,+ formatCurrentTime,+} from "./SlashCommandMenu.tsx";const labels = {menu: "插入功能菜单",@@ -19,6 +25,9 @@ const labels = {"code-block": "代码块",divider: "分割线",table: "表格",+ "current-date": "当前日期",+ "current-time": "当前时间",+ "current-date-time": "当前日期和时间",attachment: "上传附件","note-link": "引用笔记","external-link": "插入超链接",@@ -29,12 +38,30 @@ describe("slash command menu", () => {const items = createSlashCommandItems(labels);test("shows all commands for a bare slash", () => {- expect(filterSlashCommandItems(items, "")).toHaveLength(15);+ const unfilteredItems = filterSlashCommandItems(items, "");+ const heading3Index = unfilteredItems.findIndex((item) => item.id === "heading-3");++ expect(unfilteredItems).toHaveLength(18);+ expect(unfilteredItems.slice(heading3Index + 1, heading3Index + 4).map((item) => item.id)).toEqual([+ "current-date",+ "current-time",+ "current-date-time",+ ]);});test("searches localized labels and aliases", () => {expect(filterSlashCommandItems(items, "AI").map((item) => item.id)).toEqual(["ai"]);expect(filterSlashCommandItems(items, "待办").map((item) => item.id)).toEqual(["task-list"]);expect(filterSlashCommandItems(items, "h2").map((item) => item.id)).toEqual(["heading-2"]);+ expect(filterSlashCommandItems(items, "今天").map((item) => item.id)).toEqual(["current-date"]);+ expect(filterSlashCommandItems(items, "timestamp").map((item) => item.id)).toEqual(["current-date-time"]);+ });++ test("formats local date and time as stable static text", () => {+ const date = new Date(2026, 0, 2, 3, 4, 5);++ expect(formatCurrentDate(date)).toBe("2026-01-02");+ expect(formatCurrentTime(date)).toBe("03:04");+ expect(formatCurrentDateTime(date)).toBe("2026-01-02 03:04");});});diff --git a/apps/web/src/components/editor/SlashCommandMenu.tsx b/apps/web/src/components/editor/SlashCommandMenu.tsxindex 0f247eb7..5e4f2eb3 100644--- a/apps/web/src/components/editor/SlashCommandMenu.tsx+++ b/apps/web/src/components/editor/SlashCommandMenu.tsx@@ -7,6 +7,9 @@ import {BetweenHorizontalStart,Bot,Braces,+ CalendarClock,+ CalendarDays,+ Clock3,FileUp,Heading1,Heading2,@@ -41,6 +44,9 @@ export type SlashCommandId =| "code-block"| "divider"| "table"+ | "current-date"+ | "current-time"+ | "current-date-time"| "attachment"| "note-link"| "external-link";@@ -74,12 +80,26 @@ export type SlashCommandItem = {const slashCommandPluginKey = new PluginKey("edgeever-slash-command");+const padDatePart = (value: number) => String(value).padStart(2, "0");++export const formatCurrentDate = (date: Date) =>+ `${date.getFullYear()}-${padDatePart(date.getMonth() + 1)}-${padDatePart(date.getDate())}`;++export const formatCurrentTime = (date: Date) =>+ `${padDatePart(date.getHours())}:${padDatePart(date.getMinutes())}`;++export const formatCurrentDateTime = (date: Date) =>+ `${formatCurrentDate(date)} ${formatCurrentTime(date)}`;+export const createSlashCommandItems = (labels: SlashCommandLabels): SlashCommandItem[] => [{ id: "ai", group: "suggested", icon: Bot, label: labels.items.ai, shortcut: "/ai", keywords: ["ai", "assistant", "人工智能", "智能", "写作"] },{ id: "paragraph", group: "basic", icon: Pilcrow, label: labels.items.paragraph, keywords: ["text", "paragraph", "正文", "文本"] },{ id: "heading-1", group: "basic", icon: Heading1, label: labels.items["heading-1"], shortcut: "#", keywords: ["h1", "heading", "标题"] },{ id: "heading-2", group: "basic", icon: Heading2, label: labels.items["heading-2"], shortcut: "##", keywords: ["h2", "heading", "标题"] },{ id: "heading-3", group: "basic", icon: Heading3, label: labels.items["heading-3"], shortcut: "###", keywords: ["h3", "heading", "标题"] },+ { id: "current-date", group: "basic", icon: CalendarDays, label: labels.items["current-date"], shortcut: "/date", keywords: ["date", "today", "日期", "今天"] },+ { id: "current-time", group: "basic", icon: Clock3, label: labels.items["current-time"], shortcut: "/time", keywords: ["time", "now", "时间", "现在"] },+ { id: "current-date-time", group: "basic", icon: CalendarClock, label: labels.items["current-date-time"], shortcut: "/datetime", keywords: ["datetime", "timestamp", "日期时间", "时间戳"] },{ id: "bullet-list", group: "basic", icon: List, label: labels.items["bullet-list"], shortcut: "-", keywords: ["bullet", "list", "无序", "列表"] },{ id: "ordered-list", group: "basic", icon: ListOrdered, label: labels.items["ordered-list"], shortcut: "1.", keywords: ["ordered", "numbered", "list", "有序", "编号"] },{ id: "task-list", group: "basic", icon: ListTodo, label: labels.items["task-list"], shortcut: "[ ]", keywords: ["task", "todo", "check", "任务", "待办"] },@@ -210,6 +230,9 @@ const runSlashCommand = ({case "code-block": chain.setCodeBlock().run(); break;case "divider": chain.setHorizontalRule().run(); break;case "table": chain.insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(); break;+ case "current-date": chain.insertContent(formatCurrentDate(new Date())).run(); break;+ case "current-time": chain.insertContent(formatCurrentTime(new Date())).run(); break;+ case "current-date-time": chain.insertContent(formatCurrentDateTime(new Date())).run(); break;case "attachment":chain.run();window.requestAnimationFrame(actions.openAttachmentPicker);diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex da751999..19d4661d 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -1103,6 +1103,9 @@ export const enUS = {},items: {ai: "Ask AI",+ currentDate: "Current date",+ currentTime: "Current time",+ currentDateTime: "Current date and time",},},editorToolbar: {diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 3f21e11d..e1a0c796 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -1103,6 +1103,9 @@ export const zhCN = {},items: {ai: "用 AI 处理",+ currentDate: "当前日期",+ currentTime: "当前时间",+ currentDateTime: "当前日期和时间",},},editorToolbar: {