This commit is contained in:
Vanessa 2023-07-01 12:04:23 +08:00
parent 44db6a8d5f
commit 5c77de0a09
3 changed files with 49 additions and 30 deletions

View file

@ -51,20 +51,25 @@ const updateCellValue = (protyle: IProtyle, cellElement: HTMLElement, type: TAVC
}
const avMaskElement = document.querySelector(".av__mask");
const inputElement = avMaskElement.querySelector(".b3-text-field") as HTMLInputElement;
const cellId = cellElement.getAttribute("data-id")
const avId = blockElement.getAttribute("data-av-id")
const rowId = rowElement.getAttribute("data-id")
transaction(protyle, [{
action: "updateAttrViewCell",
id: cellElement.getAttribute("data-id"),
rowID: rowElement.getAttribute("data-id"),
parentID: blockElement.getAttribute("data-av-id"),
type,
data: inputElement.value,
id: cellId,
rowID: rowId,
parentID: avId,
data: {
[type]: {content: inputElement.value}
}
}], [{
action: "updateAttrViewCell",
id: blockElement.getAttribute("data-node-id"),
rowID: blockElement.getAttribute("data-av-id"),
type,
data: cellElement.textContent.trim(),
id: cellId,
rowID: rowId,
parentID: avId,
data: {
[type]: {content: cellElement.textContent.trim()}
}
}]);
cellElement.textContent = inputElement.value;
setTimeout(() => {
@ -85,13 +90,28 @@ const removeCol = (cellElement: HTMLElement) => {
export const showHeaderCellMenu = (protyle: IProtyle, blockElement: HTMLElement, cellElement: HTMLElement) => {
const type = cellElement.getAttribute("data-dtype") as TAVCol;
const menu = new Menu("av-header-cell");
const menu = new Menu("av-header-cell", () => {
const newValue = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value
if (newValue === cellElement.textContent.trim()) {
return;
}
transaction(protyle, [{
action: "updateAttrViewCol",
id: cellElement.getAttribute("data-id"),
parentID: blockElement.getAttribute("data-av-id"),
name: newValue,
type: cellElement.getAttribute("data-dtype") as TAVCol,
}], [{
action: "updateAttrViewCol",
id: cellElement.getAttribute("data-id"),
parentID: blockElement.getAttribute("data-av-id"),
name: cellElement.textContent.trim(),
type: cellElement.getAttribute("data-dtype") as TAVCol,
}]);
});
menu.addItem({
icon: getColIconByType(type),
label: `<input style="margin: 4px 0" class="b3-text-field" type="text" value="${cellElement.innerText.trim()}">`,
bind() {
}
});
if (type !== "block") {
menu.addItem({

View file

@ -50,17 +50,19 @@ export const avRender = (element: Element, cb?: () => void) => {
row.cells.forEach((cell, index) => {
let text: string
if (cell.valueType === "text") {
text = cell.renderValue as string || ""
text = cell.value?.content || ""
} else if (cell.valueType === "block") {
text = (cell.renderValue as {
content: string,
id: string,
}).content as string || ""
text = cell.value.block.content || ""
} else if (cell.valueType === "number") {
text = cell.value.number.content || ""
} else if (cell.valueType === "select") {
text = cell.value.select.content || ""
} else if (cell.valueType === "mSelect") {
text = cell.value.mSelect.content || ""
} else if (cell.valueType === "date") {
text = cell.value.date.content || ""
}
tableHTML += `<div class="av__cell" ${index === 0 ? 'data-block-id="' + ((cell.renderValue as {
content: string,
id: string
}).id || "") + '"' : ""} data-id="${cell.id}" data-index="${index}" style="width: ${data.columns[index].width || 200}px;${cell.bgColor ? `background-color:${cell.bgColor};` : ""}${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
tableHTML += `<div class="av__cell" ${index === 0 ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""} data-id="${cell.id}" data-index="${index}" style="width: ${data.columns[index].width || 200}px;${cell.bgColor ? `background-color:${cell.bgColor};` : ""}${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
});
tableHTML += "<div></div></div>";
});