diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts index 0d5d059a0..1349dbae3 100644 --- a/app/src/protyle/render/av/col.ts +++ b/app/src/protyle/render/av/col.ts @@ -109,7 +109,7 @@ export const getEditHTML = (options: { html += ` `; colData.options.forEach(item => { html += ``; + } else if (colData.type === "template") { + html += ` +`; } return `
@@ -185,6 +190,42 @@ export const bindEditEvent = (options: { protyle: IProtyle, data: IAV, menuEleme options.menuElement.parentElement.remove(); } }); + + const tplElement = options.menuElement.querySelector('[data-type="updateTemplate"]') as HTMLTextAreaElement + if (tplElement) { + tplElement.addEventListener("blur", () => { + const newValue = tplElement.value; + if (newValue === colData.template) { + return; + } + transaction(options.protyle, [{ + action: "updateAttrViewColTemplate", + id: colId, + avID, + data: newValue, + type: colData.type, + }], [{ + action: "updateAttrViewColTemplate", + id: colId, + avID, + data: colData.template, + type: colData.type, + }]); + colData.template = newValue; + }); + tplElement.addEventListener("keydown", (event: KeyboardEvent) => { + if (event.isComposing) { + return; + } + if (event.key === "Escape") { + options.menuElement.parentElement.remove(); + } else if (event.key === "Enter") { + tplElement.dispatchEvent(new CustomEvent("blur")); + options.menuElement.parentElement.remove(); + } + }); + } + const addOptionElement = options.menuElement.querySelector('[data-type="addOption"]') as HTMLInputElement; if (!addOptionElement) { return; diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 8dd42d65d..3b08698d4 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -63,7 +63,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '${cell.value ? cell.value[cell.valueType as "text"].content : ""}`; + text = `${cell.value ? (cell.value[cell.valueType as "text"].content || "") : ""}`; } else if (["url", "email", "phone"].includes(cell.valueType)) { const urlContent = cell.value ? cell.value[cell.valueType as "url"].content : ""; // https://github.com/siyuan-note/siyuan/issues/9291 diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 52cf18785..4279e73c3 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -708,7 +708,8 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: } else if (["addAttrViewCol", "insertAttrViewBlock", "updateAttrViewCol", "updateAttrViewColOptions", "updateAttrViewColOption", "updateAttrViewCell", "sortAttrViewRow", "sortAttrViewCol", "setAttrViewColHidden", "setAttrViewColWrap", "setAttrViewColWidth", "removeAttrViewColOption", "setAttrViewName", "setAttrViewFilters", - "setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat", "replaceAttrViewBlock"].includes(operation.action)) { + "setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat", + "replaceAttrViewBlock", "updateAttrViewColTemplate"].includes(operation.action)) { refreshAV(protyle, operation); } }; diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 8abc910f5..2efa1243f 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -24,6 +24,7 @@ type TOperation = | "removeFlashcards" | "updateAttrViewCell" | "updateAttrViewCol" + | "updateAttrViewColTemplate" | "sortAttrViewRow" | "sortAttrViewCol" | "setAttrViewColHidden" @@ -1022,6 +1023,7 @@ interface IAVColumn { hidden: boolean, type: TAVCol, numberFormat: string, + template: string, calc: { operator: string, result: IAVCellValue