Vanessa 2024-11-13 16:37:28 +08:00
parent 1eaa79c999
commit ce4e2c1dde
2 changed files with 42 additions and 6 deletions

View file

@ -662,10 +662,30 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
} else if (type === "mSelect") {
// 不传入为删除
if (typeof value === "string") {
value = oldValue.mSelect.concat({
content: value,
color: (oldValue.mSelect.length + 1).toString()
});
const newMSelectValue: IAVCellSelectValue[] = [];
let colorIndex = oldValue.mSelect.length;
// 以逗号分隔,去重,去空,去换行后做为选项
[...new Set(value.split(",").map(v => v.trim().replace(/\n|\r\n|\r|\u2028|\u2029/g, "")))].forEach((item) => {
if (!item) {
return;
}
let hasSameContent = false
oldValue.mSelect.find((mSelectItem) => {
if (mSelectItem.content === item) {
hasSameContent = true
return true
}
})
if (hasSameContent) {
return;
}
colorIndex++;
newMSelectValue.push({
content: item,
color: colorIndex.toString()
})
})
value = oldValue.mSelect.concat(newMSelectValue);
}
}
const cellValue = genCellValue(type, value);

View file

@ -186,13 +186,29 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
}
const text = protyle.lute.BlockDOM2Content(html);
const cellsElement: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--select"));
const cellsElement: HTMLElement[] = Array.from(blockElement.querySelectorAll(".av__cell--active, .av__cell--select"));
const rowsElement = blockElement.querySelector(".av__row--select");
if (rowsElement) {
updateCellsValue(protyle, blockElement as HTMLElement, text, undefined, columns, html);
} else if (cellsElement.length > 0) {
updateCellsValue(protyle, blockElement as HTMLElement, text, cellsElement, columns, html);
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++;
} else {
return true;
}
})
} else {
updateCellsValue(protyle, blockElement as HTMLElement, text, cellsElement, columns, html);
}
document.querySelector(".av__panel")?.remove();
} else if (hasClosestByClassName(range.startContainer, "av__title")) {
range.insertNode(document.createTextNode(text));