Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Add a date picker to database calendars https://github.com/siyuan-note/siyuan/issues/19725

Daniela2843669161f
diff --git a/app/src/dialog/inputDialog.test.ts b/app/src/dialog/inputDialog.test.ts
index bc13eabdcc..37987cedcd 100644
--- a/app/src/dialog/inputDialog.test.ts
+++ b/app/src/dialog/inputDialog.test.ts
@@ -26,6 +26,12 @@ class Control {
class Input extends Control {
type = "text";
+ min = "";
+ max = "";
+ valid = true;
+ reportValidity() {
+ return this.valid;
+ }
}
const loadDialog = () => {
@@ -150,6 +156,55 @@ it("supports multiline values and lets autocomplete own keyboard events", () =>
assert.equal(autocomplete.enter, undefined);
});
+it("calendar date jump waits for confirmation and uses local midnight without changing the view mode", () => {
+ const file = "src/protyle/render/av/calendar/render.ts";
+ const source = createSourceFile(file, readFileSync(file, "utf8"), ScriptTarget.Latest, true);
+ let call = "";
+ const visit = (node: import("typescript").Node) => {
+ if (isCallExpression(node) && node.expression.getText(source) === "openInputDialog") {
+ call = node.getText(source);
+ }
+ forEachChild(node, visit);
+ };
+ visit(source);
+ assert.ok(call);
+ for (const mode of ["month", "week"]) {
+ const open = loadDialog();
+ let dialog: ReturnType<typeof open>;
+ const initial = new Date("2026-09-21T00:00:00").getTime();
+ const state = {anchor: initial, mode, expandedWeeks: new Set([initial])};
+ let refreshed = 0;
+ runInNewContext(transpileModule(call, {compilerOptions: {target: ScriptTarget.ES2020}}).outputText, {
+ openInputDialog: (options: Parameters<typeof open>[0]) => { dialog = open(options); },
+ window: {siyuan: {languages: {calendarJumpDate: "Go to date"}}},
+ state, dayjs: require("dayjs"), Date,
+ refresh: () => refreshed++,
+ });
+ const input = dialog.input as Input;
+ assert.equal(input.type, "date");
+ assert.equal(input.value, "2026-09-21");
+ assert.equal(input.min, "0001-01-01");
+ assert.equal(input.max, "9999-12-31");
+ for (const [value, valid] of [["", true], ["10000-01-01", false]] as const) {
+ input.value = value;
+ input.valid = valid;
+ dialog.enter();
+ assert.equal(dialog.closed, false);
+ assert.equal(state.anchor, initial);
+ assert.equal(refreshed, 0);
+ }
+ input.value = "2024-02-29";
+ input.valid = true;
+ assert.equal(state.anchor, initial);
+ dialog.enter();
+ assert.equal(state.anchor, new Date("2024-02-29T00:00:00").getTime());
+ assert.equal(state.mode, mode);
+ assert.equal(state.expandedWeeks.size, 0);
+ assert.equal(dialog.closed, true);
+ assert.equal(refreshed, 1);
+ }
+});
+
for (const file of ["src/history/doc.ts", "src/history/history.ts"]) {
it(`${file} keeps all page jump dialogs open for empty input and clamps valid pages`, () => {
const source = createSourceFile(file, readFileSync(file, "utf8"), ScriptTarget.Latest, true);
diff --git a/app/src/dialog/inputDialog.ts b/app/src/dialog/inputDialog.ts
index 481e2818cd..345b1d2538 100644
--- a/app/src/dialog/inputDialog.ts
+++ b/app/src/dialog/inputDialog.ts
@@ -9,7 +9,7 @@ export const openInputDialog = (options: {
width?: string,
positionId?: string,
maxLength?: number,
- type?: "text" | "number" | "password",
+ type?: "text" | "number" | "password" | "date",
multiline?: boolean,
resize?: "none" | "vertical",
min?: string,
diff --git a/app/src/protyle/render/av/calendar/render.ts b/app/src/protyle/render/av/calendar/render.ts
index d79f02d3b1..e295cffb9d 100644
--- a/app/src/protyle/render/av/calendar/render.ts
+++ b/app/src/protyle/render/av/calendar/render.ts
@@ -1,4 +1,5 @@
import {Constants} from "../../../../constants";
+import {openInputDialog} from "../../../../dialog/inputDialog";
import * as dayjs from "dayjs";
import {Menu} from "../../../../plugin/Menu";
import {escapeAttr, escapeHtml} from "../../../../util/escape";
@@ -238,6 +239,7 @@ export const renderCalendar = async (blockElement: HTMLElement, protyle: IProtyl
${iconButton("previous", "iconLeft", window.siyuan.languages.previous)}
<button type="button" class="av__calendar-today" data-calendar-action="today">${window.siyuan.languages.calendarToday}</button>
${iconButton("next", "iconRight", window.siyuan.languages.next)}
+ ${iconButton("jump", "iconCalendar", window.siyuan.languages.calendarJumpDate)}
<select class="b3-select" data-calendar-mode aria-label="${window.siyuan.languages.calendarView}"><option value="month"${state.mode === "month" ? " selected" : ""}>${window.siyuan.languages.month}</option><option value="week"${state.mode === "week" ? " selected" : ""}>${window.siyuan.languages.week}</option></select>
</div>
</div>
@@ -272,6 +274,26 @@ export const renderCalendar = async (blockElement: HTMLElement, protyle: IProtyl
}
const action = target.closest<HTMLElement>("[data-calendar-action]")?.dataset.calendarAction;
if (action) {
+ if (action === "jump") {
+ openInputDialog({
+ title: window.siyuan.languages.calendarJumpDate,
+ type: "date",
+ value: dayjs(state.anchor).format("YYYY-MM-DD"),
+ min: "0001-01-01",
+ max: "9999-12-31",
+ onConfirm: (value, dialog) => {
+ const input = dialog.element.querySelector<HTMLInputElement>("[data-dialog-input]");
+ if (!value || !input.reportValidity()) {
+ return;
+ }
+ state.anchor = new Date(`${value}T00:00:00`).getTime();
+ state.expandedWeeks.clear();
+ dialog.destroy();
+ refresh();
+ },
+ });
+ return;
+ }
if (action === "today") {
state.anchor = calendarDay(Date.now());
} else if (state.mode === "week") {