Vanessa 2024-01-27 22:06:22 +08:00
parent 483a1406a3
commit 76ac9912dc
3 changed files with 35 additions and 17 deletions

View file

@ -76,6 +76,9 @@ export const genCellValueByElement = (colType: TAVCol, cellElement: HTMLElement)
} else if (colType === "mAsset") {
const mAsset: IAVCellAssetValue[] = [];
Array.from(cellElement.children).forEach((item) => {
if (item.classList.contains("av__drag-fill")) {
return;
}
const isImg = item.classList.contains("av__cellassetimg");
mAsset.push({
type: isImg ? "image" : "file",
@ -420,11 +423,12 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
const avID = nodeElement.dataset.avId;
const id = nodeElement.dataset.nodeId;
let text = "";
const json: IAVCellValue[] = [];
let cellElements: Element[];
if (cElements?.length > 0) {
cellElements = cElements;
} else {
cellElements = Array.from(nodeElement.querySelectorAll(".av__cell--select"));
cellElements = Array.from(nodeElement.querySelectorAll(".av__cell--active, .av__cell--select"));
if (cellElements.length === 0) {
nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(rowElement => {
rowElement.querySelectorAll(".av__cell").forEach(cellElement => {
@ -451,8 +455,9 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
const cellId = item.getAttribute("data-id");
const colId = item.getAttribute("data-col-id");
text += getCellText(item);
text += getCellText(item) + " ";
const oldValue = genCellValueByElement(type, item);
json.push(oldValue);
// relation 为全部更新,以下类型为添加
if (type === "mAsset") {
if (Array.isArray(value)) {
@ -514,7 +519,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
});
transaction(protyle, doOperations, undoOperations);
}
return text;
return {text: text.substring(0, text.length - 1), json};
};
export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => {

View file

@ -23,10 +23,13 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
if (!rowElement) {
return false;
}
nodeElement.querySelectorAll(".av__cell--active").forEach(item => {
item.classList.remove("av__cell--active");
item.querySelector(".av__drag-fill")?.remove();
});
// 复制、粘贴
if (!event.ctrlKey && !event.metaKey) {
nodeElement.querySelectorAll(".av__cell--active").forEach(item => {
item.classList.remove("av__cell--active");
item.querySelector(".av__drag-fill")?.remove();
});
}
if (event.key === "Escape") {
selectCellElement.classList.remove("av__cell--select");
selectRow(rowElement.querySelector(".av__firstcol"), "select");

View file

@ -294,7 +294,7 @@ export class WYSIWYG {
});
}
} else if (selectAVElement) {
const cellElements: Element[] = Array.from(nodeElement.querySelectorAll(".av__cell--select")) || [];
const cellElements: Element[] = Array.from(nodeElement.querySelectorAll(".av__cell--active, .av__cell--select")) || [];
if (cellElements.length === 0) {
nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(rowElement => {
rowElement.querySelectorAll(".av__cell").forEach(cellElement => {
@ -302,11 +302,16 @@ export class WYSIWYG {
});
});
}
cellElements.forEach((item: HTMLElement) => {
const cellText = getCellText(item);
html += cellText;
textPlain += cellText;
});
if (cellElements.length > 0) {
html = "[";
cellElements.forEach((item: HTMLElement) => {
const cellText = getCellText(item);
html += JSON.stringify(genCellValueByElement(getTypeByCellElement(item), item)) + ",";
textPlain += cellText + " ";
});
textPlain = textPlain.substring(0, textPlain.length - 1);
html = html.substring(0, html.length - 1) + "]";
}
} else {
const tempElement = document.createElement("div");
// https://github.com/siyuan-note/siyuan/issues/5540
@ -369,7 +374,7 @@ export class WYSIWYG {
textPlain = textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd();
textPlain = textPlain.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
event.clipboardData.setData("text/plain", textPlain);
event.clipboardData.setData("text/html", protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/html", selectAVElement ? html : protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/siyuan", html);
});
@ -1269,6 +1274,7 @@ export class WYSIWYG {
selectElements = [nodeElement];
}
let html = "";
let textPlain = "";
if (selectElements.length > 0) {
if (selectElements[0].getAttribute("data-type") === "NodeListItem" &&
selectElements[0].parentElement.classList.contains("list") && // 反链复制列表项 https://github.com/siyuan-note/siyuan/issues/6555
@ -1294,7 +1300,9 @@ export class WYSIWYG {
focusBlock(nextElement);
}
} else if (selectAVElement) {
html = updateCellsValue(protyle, nodeElement);
const cellsValue = updateCellsValue(protyle, nodeElement);
html = JSON.stringify(cellsValue.json)
textPlain = cellsValue.text;
} else {
const id = nodeElement.getAttribute("data-node-id");
const oldHTML = nodeElement.outerHTML;
@ -1439,10 +1447,12 @@ export class WYSIWYG {
}
}
protyle.hint.render(protyle);
let textPlain = protyle.lute.BlockDOM2StdMd(html).trimEnd(); // 需要 trimEnd否则 \n 会导致 https://github.com/siyuan-note/siyuan/issues/6218
if (!selectAVElement) {
textPlain = protyle.lute.BlockDOM2StdMd(html).trimEnd(); // 需要 trimEnd否则 \n 会导致 https://github.com/siyuan-note/siyuan/issues/6218
}
textPlain = textPlain.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
event.clipboardData.setData("text/plain", textPlain);
event.clipboardData.setData("text/html", protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/html", selectAVElement ? html : protyle.lute.BlockDOM2HTML(html));
event.clipboardData.setData("text/siyuan", html);
});