Vanessa 2024-12-23 00:00:08 +08:00
parent 1148a4eca5
commit d2b1769957

View file

@ -186,28 +186,52 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
}
const text = protyle.lute.BlockDOM2Content(html);
const cellsElement: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--active, .av__cell--select"));
const rowsElement = blockElement.querySelector(".av__row--select");
const cellElements: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--active, .av__cell--select"));
const rowsElement = blockElement.querySelectorAll(".av__row--select");
if (rowsElement) {
const textJSON: string[][] = [];
text.split("\n").forEach(row => {
textJSON.push(row.split("\t"));
});
if (rowsElement && textJSON.length === 1 && textJSON[0].length === 1) {
updateCellsValue(protyle, blockElement as HTMLElement, text, undefined, columns, html);
} else if (cellsElement.length > 0) {
if (cellsElement.length > 1) {
// 选择多个单元格时,逐行填充
let rowIndex = 0;
text.split("\n").find((row) => {
if (!row) {
return false;
}
if (cellsElement[rowIndex]) {
updateCellsValue(protyle, blockElement as HTMLElement, row.trim(), [cellsElement[rowIndex]], columns, html);
rowIndex++;
return;
}
if (rowsElement) {
rowsElement.forEach(rowElement => {
rowElement.querySelectorAll(".av__cell").forEach((cellElement: HTMLElement) => {
cellElements.push(cellElement);
});
});
}
if (cellElements.length > 0) {
if (textJSON.length === 1 && textJSON[0].length === 1) {
updateCellsValue(protyle, blockElement as HTMLElement, text, cellElements, columns, html);
} else {
let currentRowElement:Element
const firstColIndex = cellElements[0].getAttribute("data-col-id");
textJSON.forEach((rowValue, rowIndex) => {
if (!currentRowElement) {
currentRowElement = cellElements[0].parentElement;
} else {
currentRowElement = currentRowElement.nextElementSibling;
}
if (!currentRowElement.classList.contains("av__row")) {
return true;
}
});
} else {
updateCellsValue(protyle, blockElement as HTMLElement, text, cellsElement, columns, html);
let cellElement: HTMLElement;
rowValue.forEach((cellValue, cellIndex) => {
if (!cellElement) {
cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement;
} else {
cellElement = cellElement.nextElementSibling as HTMLElement;
}
if (!cellElement.classList.contains("av__cell")) {
return true;
}
updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, html);
});
})
}
document.querySelector(".av__panel")?.remove();
} else if (hasClosestByClassName(range.startContainer, "av__title")) {