From 66acf8576d1b7ec129fc63e836e36ae3b7454bde Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 26 Jan 2024 20:34:11 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10262 --- app/src/protyle/render/av/action.ts | 3 ++- app/src/protyle/render/av/cell.ts | 18 ++++++++++++++++++ app/src/protyle/render/av/render.ts | 14 ++++++++++++-- app/src/protyle/render/av/row.ts | 14 +++++++++----- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 3c844a327..806f3e665 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -3,7 +3,7 @@ import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../ import {transaction} from "../../wysiwyg/transaction"; import {openEditorTab} from "../../../menus/util"; import {copySubMenu} from "../../../menus/commonMenuItem"; -import {getCellText, getTypeByCellElement, popTextCell, renderCell, updateHeaderCell} from "./cell"; +import {getCellText, getTypeByCellElement, popTextCell, renderCell, renderCellAttr, updateHeaderCell} from "./cell"; import {getColIconByType, showColMenu} from "./col"; import {deleteRow, insertAttrViewBlockAnimation, setPageSize, updateHeader} from "./row"; import {emitOpenMenu} from "../../../plugin/EventBus"; @@ -400,6 +400,7 @@ export const updateAttrViewCellAnimation = (cellElement: HTMLElement, value: IAV updateHeaderCell(cellElement, headerValue); } else { cellElement.innerHTML = renderCell(value); + renderCellAttr(cellElement, value); } }; diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 48381bc58..21d74da03 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -517,6 +517,23 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va return text; }; +export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => { + if (value.type === "checkbox") { + if (value.checkbox.checked) { + cellElement.classList.add("av__cell-check"); + cellElement.classList.remove("av__cell-uncheck"); + } else { + cellElement.classList.remove("av__cell-check"); + cellElement.classList.add("av__cell-uncheck"); + } + } else if (value.type === "block") { + cellElement.setAttribute("data-block-id", value.block.id || ""); + if (value.isDetached) { + cellElement.setAttribute("data-detached", "true"); + } + } +} + export const renderCell = (cellValue: IAVCellValue) => { let text = ""; if (["text", "template"].includes(cellValue.type)) { @@ -722,6 +739,7 @@ export const dragFillCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, data }); item.element.innerHTML = renderCell(data); + renderCellAttr(item.element, data); delete item.colId; delete item.element; undoOperations.push({ diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index af67b584e..f934febe8 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -130,7 +130,12 @@ style="width: ${index === 0 ? ((parseInt(column.width || "200") + 24) + "px") : if (data.columns[index].hidden) { return; } - tableHTML += `
{ // 更新属性面板 renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle, (newElment) => { if (operation.action === "addAttrViewCol") { - openMenuPanel({protyle, blockElement: newElment.querySelector(`div[data-av-id="${operation.avID}"]`), type: "edit", colId: operation.id}); + openMenuPanel({ + protyle, + blockElement: newElment.querySelector(`div[data-av-id="${operation.avID}"]`), + type: "edit", + colId: operation.id + }); } }); } diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts index 3aa126f5c..2c4d7c4ce 100644 --- a/app/src/protyle/render/av/row.ts +++ b/app/src/protyle/render/av/row.ts @@ -2,7 +2,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest"; import {focusBlock} from "../../util/selection"; import {Menu} from "../../../plugin/Menu"; import {transaction} from "../../wysiwyg/transaction"; -import {genCellValueByElement, getTypeByCellElement, popTextCell, renderCell} from "./cell"; +import {genCellValueByElement, getTypeByCellElement, popTextCell, renderCell, renderCellAttr} from "./cell"; import {fetchPost} from "../../../util/fetch"; export const selectRow = (checkElement: Element, type: "toggle" | "select" | "unselect" | "unselectAll") => { @@ -108,13 +108,17 @@ ${(item.getAttribute("data-block-id") || item.dataset.dtype === "block") ? ' dat fetchPost("/api/av/getAttributeViewFilterSort", {id: avId}, (response) => { response.data.filters.forEach((item: IAVFilter) => { const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement; - currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML = - renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement)); + const cellElement = currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`); + const cellValue = genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement); + cellElement.innerHTML = renderCell(cellValue); + renderCellAttr(cellElement, cellValue); }); response.data.sorts.forEach((item: IAVSort) => { const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement; - currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML = - renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement)); + const cellElement = currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`); + const cellValue = genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement); + cellElement.innerHTML = renderCell(cellValue); + renderCellAttr(cellElement, cellValue); }); popTextCell(protyle, [currentRow.querySelector('.av__cell[data-detached="true"]')], "block"); });