diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index b160d393f..ec90c751b 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -733,7 +733,7 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme let item = cellElements[elementIndex] as HTMLElement; const rowID = getFieldIdByCellElement(item, viewType); if (!rowID) { - return; + break; } if (!nodeElement.contains(item)) { if (viewType === "table") { @@ -746,11 +746,11 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme if (!item) { // 兼容新增行后台隐藏 - return; + break; } const type = getTypeByCellElement(item) || item.dataset.type as TAVCol; if (["created", "updated", "template", "rollup"].includes(type)) { - return; + break; } const cellId = item.dataset.id; // 刚创建时无 id,更新需和 oldValue 保持一致 const colId = getColId(item, viewType); @@ -794,7 +794,7 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme name = value; } if (!link && !name && !imgSrc) { - return; + break; } if (imgSrc) { // 支持解析 ![]() https://github.com/siyuan-note/siyuan/issues/11487 @@ -858,7 +858,7 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme cellValue.id = cellId; if ((cellValue.type === "date" && typeof cellValue.date === "string") || (cellValue.type === "relation" && typeof cellValue.relation === "string")) { - return; + break; } if (columns && (type === "select" || type === "mSelect")) { const operations = mergeAddOption(columns.find(e => e.id === colId), cellValue, avID); @@ -876,7 +876,7 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme cellValue.date.formattedContent = oldValue.date.formattedContent; } if (objEquals(cellValue, oldValue)) { - return; + break; } doOperations.push({ diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index 99439e2e1..7944a67d3 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -41,7 +41,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: }); } const avID = blockElement.dataset.avId; - fetchPost("/api/av/getAttributeViewKeysByAvID", {avID}, (response) => { + fetchPost("/api/av/getAttributeViewKeysByAvID", {avID}, async (response) => { const columns: IAVColumn[] = response.data; const cellElements: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--active, .av__cell--select")) || []; if (values && Array.isArray(values) && values.length > 0) { @@ -61,17 +61,18 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: const id = blockElement.dataset.nodeId; let currentRowElement: Element; const firstColIndex = cellElements[0].getAttribute("data-col-id"); - values.find(rowItem => { + for (let i = 0; i < values.length; i++) { if (!currentRowElement) { currentRowElement = hasClosestByClassName(cellElements[0].parentElement, "av__row") as HTMLElement; } else { currentRowElement = currentRowElement.nextElementSibling; } if (!currentRowElement.classList.contains("av__row")) { - return true; + break; } let cellElement: HTMLElement; - rowItem.find(cellValue => { + for (let j = 0; j < values[i].length; j++) { + const cellValue = values[i][j]; if (!cellElement) { cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement; } else { @@ -82,16 +83,16 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: } } if (!cellElement.classList.contains("av__cell")) { - return true; + break; } - const operations = updateCellsValue(protyle, blockElement as HTMLElement, + const operations = await updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, html, true); if (operations.doOperations.length > 0) { doOperations.push(...operations.doOperations); undoOperations.push(...operations.undoOperations); } - }); - }); + } + } if (doOperations.length > 0) { doOperations.push({ action: "doUpdateUpdated", @@ -162,17 +163,17 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: const doOperations: IOperation[] = []; const undoOperations: IOperation[] = []; const firstColIndex = cellElements[0].getAttribute("data-col-id"); - textJSON.forEach((rowValue) => { + for (let i = 0; i < textJSON.length; i++) { if (!currentRowElement) { currentRowElement = hasClosestByClassName(cellElements[0].parentElement, "av__row") as HTMLElement; } else { currentRowElement = currentRowElement.nextElementSibling; } if (!currentRowElement.classList.contains("av__row")) { - return true; + break; } let cellElement: HTMLElement; - rowValue.forEach((cellValue) => { + for (let j = 0; j < textJSON[i].length; j++) { if (!cellElement) { cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement; } else { @@ -183,15 +184,16 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: } } if (!cellElement.classList.contains("av__cell")) { - return true; + break; } - const operations = updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, html, true); + const cellValue = textJSON[i][j]; + const operations = await updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, html, true); if (operations.doOperations.length > 0) { doOperations.push(...operations.doOperations); undoOperations.push(...operations.undoOperations); } - }); - }); + } + } if (doOperations.length > 0) { const id = blockElement.getAttribute("data-node-id"); doOperations.push({