Vanessa 2025-07-15 12:36:19 +08:00
parent 306fab4fee
commit dda4634126
2 changed files with 23 additions and 7 deletions

View file

@ -59,7 +59,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
const firstColIndex = cellElements[0].getAttribute("data-col-id");
values.find(rowItem => {
if (!currentRowElement) {
currentRowElement = cellElements[0].parentElement;
currentRowElement = hasClosestByClassName(cellElements[0].parentElement, "av__row") as HTMLElement;
} else {
currentRowElement = currentRowElement.nextElementSibling;
}
@ -71,7 +71,11 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
if (!cellElement) {
cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement;
} else {
cellElement = cellElement.nextElementSibling as HTMLElement;
if (cellElement.nextElementSibling) {
cellElement = cellElement.nextElementSibling as HTMLElement;
} else if (cellElement.parentElement.classList.contains("av__colsticky")) {
cellElement = cellElement.parentElement.nextElementSibling as HTMLElement;
}
}
if (!cellElement.classList.contains("av__cell")) {
return true;
@ -156,7 +160,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
const firstColIndex = cellElements[0].getAttribute("data-col-id");
textJSON.forEach((rowValue) => {
if (!currentRowElement) {
currentRowElement = cellElements[0].parentElement;
currentRowElement = hasClosestByClassName(cellElements[0].parentElement, "av__row") as HTMLElement;
} else {
currentRowElement = currentRowElement.nextElementSibling;
}
@ -168,7 +172,11 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
if (!cellElement) {
cellElement = currentRowElement.querySelector(`.av__cell[data-col-id="${firstColIndex}"]`) as HTMLElement;
} else {
cellElement = cellElement.nextElementSibling as HTMLElement;
if (cellElement.nextElementSibling) {
cellElement = cellElement.nextElementSibling as HTMLElement;
} else if (cellElement.parentElement.classList.contains("av__colsticky")) {
cellElement = cellElement.parentElement.nextElementSibling as HTMLElement;
}
}
if (!cellElement.classList.contains("av__cell")) {
return true;

View file

@ -318,14 +318,22 @@ export class WYSIWYG {
html = "[";
cellElements.forEach((item: HTMLElement, index) => {
const cellText = getCellText(item);
if (index === 0 || !cellElements[index - 1].isSameNode(item.previousElementSibling)) {
if (index === 0 || (
!cellElements[index - 1].isSameNode(item.previousElementSibling) &&
!(item.previousElementSibling?.classList.contains("av__colsticky") && !cellElements[index - 1].nextElementSibling && cellElements[index - 1].parentElement.isSameNode(item.previousElementSibling))
)) {
html += "[";
}
html += JSON.stringify(genCellValueByElement(getTypeByCellElement(item), item)) + ",";
if (index === cellElements.length - 1 || !cellElements[index + 1].isSameNode(item.nextElementSibling)) {
if (index === cellElements.length - 1 || (
!cellElements[index + 1].isSameNode(item.nextElementSibling) &&
!(!item.nextElementSibling && item.parentElement.nextElementSibling.isSameNode(cellElements[index + 1]))
)) {
html = html.substring(0, html.length - 1) + "],";
textPlain += cellText + "\n";
} else {
textPlain += cellText + "\t";
}
textPlain += cellText + ((cellElements[index + 1] && item.nextElementSibling && item.nextElementSibling.isSameNode(cellElements[index + 1])) ? "\t" : "\n\n");
});
textPlain = textPlain.substring(0, textPlain.length - 2);
html = html.substring(0, html.length - 1) + "]";