From 7a3c8da349807296d4e480b8312bfb13083bba4a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 1 Aug 2023 14:42:33 +0800 Subject: [PATCH] :sparkles: https://github.com/siyuan-note/siyuan/issues/8868 date --- app/src/menus/Menu.ts | 2 +- app/src/protyle/render/av/render.ts | 40 ++++++++++------------------- app/src/types/index.d.ts | 2 +- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts index fe3fbe194..37ef2f8c5 100644 --- a/app/src/menus/Menu.ts +++ b/app/src/menus/Menu.ts @@ -179,7 +179,7 @@ export class MenuItem { if (this.element.getAttribute("disabled")) { return; } - let keepOpen = options.click(this.element); + let keepOpen = options.click(this.element, event); if (keepOpen instanceof Promise) { keepOpen = false; } diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 92fc44e45..7e6de2b6d 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -93,10 +93,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '`; - } - if (cell.value?.date.content2) { - text += dayjs(cell.value.date.content2).format("YYYY-MM-DD HH:mm"); + text += `${dayjs(cell.value.date.content2).format("YYYY-MM-DD HH:mm")}`; } text += ""; } @@ -227,10 +224,7 @@ const genAVValueHTML = (value: IAVCellValue) => { html = `${dayjs(value.date.content).format("YYYY-MM-DD HH:mm")}`; } if (value.date.hasEndDate && value.date.content && value.date.content2) { - html += ``; - } - if (value.date.content2) { - html += `${dayjs(value.date.content2).format("YYYY-MM-DD HH:mm")}`; + html += `${dayjs(value.date.content2).format("YYYY-MM-DD HH:mm")}`; } break; case "url": @@ -297,10 +291,7 @@ export const renderAVAttribute = (element: HTMLElement, id: string) => { dataHTML = `${dayjs(textElements[0].value).format("YYYY-MM-DD HH:mm")}` } if (hasEndDate && textElements[0].value && textElements[1].value) { - dataHTML += `` - } - if (textElements[1].value) { - dataHTML += `${dayjs(textElements[1].value).format("YYYY-MM-DD HH:mm")}` + dataHTML += `${dayjs(textElements[1].value).format("YYYY-MM-DD HH:mm")}` } dateElement.innerHTML = dataHTML; }); @@ -325,10 +316,13 @@ export const renderAVAttribute = (element: HTMLElement, id: string) => { `, - click(element) { + click(element, event) { const switchElement = element.querySelector(".b3-switch") as HTMLInputElement - // TODO - switchElement.checked = !switchElement.checked + if ((event.target as HTMLElement).tagName !== "INPUT") { + switchElement.checked = !switchElement.checked; + } else { + switchElement.outerHTML = ``; + } window.siyuan.menus.menu.element.querySelectorAll('[type="datetime-local"]')[1].classList.toggle("fn__none"); return true; } @@ -338,18 +332,10 @@ export const renderAVAttribute = (element: HTMLElement, id: string) => { icon: "iconTrashcan", label: window.siyuan.languages.clear, click() { - fetchPost("/api/av/setAttributeViewBlockAttr", { - avID: dateElement.dataset.avId, - keyID: dateElement.dataset.keyId, - rowID: dateElement.dataset.blockId, - cellID: dateElement.dataset.id, - value: { - date: { - content: null, content2: null, hasEndDate: false - } - } - }); - dateElement.innerHTML = "" + const textElements = window.siyuan.menus.menu.element.querySelectorAll(".b3-text-field") as NodeListOf + textElements[0].value = ""; + textElements[1].value = ""; + (window.siyuan.menus.menu.element.querySelector(".b3-switch") as HTMLInputElement).checked = false } }) const targetRect = target.getBoundingClientRect() diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 2d896dbc3..4cc024237 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -812,7 +812,7 @@ interface IModels { interface IMenu { label?: string, - click?: (element: HTMLElement) => boolean | void | Promise + click?: (element: HTMLElement, event: MouseEvent) => boolean | void | Promise type?: "separator" | "submenu" | "readonly", accelerator?: string, action?: string,