An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Assign dates to entries created from the calendar header https://github.com/siyuan-note/siyuan/issues/19727
Daniel817e72318277
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.tsindex 1f5f823d83..6ea60781d6 100644--- a/app/src/protyle/render/av/action.ts+++ b/app/src/protyle/render/av/action.ts@@ -405,7 +405,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElereturn true;} else if (type === "av-add-more" && !protyle.disabled) {const templateID = blockElement.querySelector<HTMLElement>(".av__header")?.dataset.defaultTemplateId;- if (templateID) {+ if (templateID || blockElement.getAttribute("data-av-type") === "calendar") {createAttributeViewItem({blockElement, protyle, templateID});} else {insertRows({diff --git a/app/src/protyle/render/av/calendar/state.test.ts b/app/src/protyle/render/av/calendar/state.test.tsindex 0323f427b6..f297df441c 100644--- a/app/src/protyle/render/av/calendar/state.test.ts+++ b/app/src/protyle/render/av/calendar/state.test.ts@@ -44,3 +44,62 @@ test("only a calendar with an ordinary date source supplies the date of a new engetCalendarState(table).dateType = "date";assert.equal(getCalendarCreationDate(table), undefined);});++test("calendar header creation supplies the browsing date with and without a template", () => {+ const action = ts.createSourceFile("action.ts", readFileSync(join(__dirname, "../action.ts"), "utf8"),+ ts.ScriptTarget.Latest, true);+ let branch = "";+ const visit = (node: ts.Node) => {+ if (ts.isIfStatement(node) && node.expression.getText(action) === 'type === "av-add-more" && !protyle.disabled') {+ branch = node.thenStatement.getText(action);+ }+ ts.forEachChild(node, visit);+ };+ visit(action);+ assert.ok(branch);+ const template = ts.createSourceFile("newItemTemplate.ts",+ readFileSync(join(__dirname, "../newItemTemplate.ts"), "utf8"), ts.ScriptTarget.Latest, true);+ const create = template.statements.find(statement => ts.isVariableStatement(statement) &&+ statement.declarationList.declarations.some(declaration => declaration.name.getText(template) === "createAttributeViewItem"));+ assert.ok(create);+ const compiled = ts.transpileModule(create.getText(template).replace(/^export /, "") + `\n(() => ${branch})();`, {+ compilerOptions: {target: ts.ScriptTarget.ES2022},+ }).outputText;+ for (const layout of ["calendar", "table"]) {+ for (const templateID of ["", "template-id"]) {+ for (const dateType of ["date", "created", "updated"] as const) {+ const blockElement = {+ dataset: {avId: "database", nodeId: "carrier"},+ getAttribute: (key: string) => key === "data-av-type" ? layout : "view-id",+ querySelector: () => ({dataset: {defaultTemplateId: templateID}}),+ } as unknown as HTMLElement;+ const state = getCalendarState(blockElement);+ state.anchor = new Date("2019-01-15T00:00:00").getTime();+ state.dateType = dateType;+ const requests: {calendarDate?: number, templateID: string, viewID: string}[] = [];+ let inserted = 0;+ runInNewContext(compiled, {+ blockElement, getCalendarCreationDate,+ Constants: {CUSTOM_SY_AV_VIEW: "custom-sy-av-view"},+ protyle: {app: {appId: "app"}, id: "editor"},+ event: {preventDefault() {}, stopPropagation() {}},+ fetchPost: (url: string, payload: typeof requests[number]) => {+ assert.equal(url, "/api/av/createAttributeViewItem");+ requests.push(payload);+ },+ insertRows: () => inserted++,+ });+ if (layout === "table" && !templateID) {+ assert.equal(inserted, 1);+ assert.equal(requests.length, 0);+ } else {+ assert.equal(inserted, 0);+ assert.equal(requests.length, 1);+ assert.equal(requests[0].templateID, templateID);+ assert.equal(requests[0].viewID, "view-id");+ assert.equal(requests[0].calendarDate, layout === "calendar" && dateType === "date" ? state.anchor : undefined);+ }+ }+ }+ }+});