mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
This commit is contained in:
parent
44db6a8d5f
commit
5c77de0a09
3 changed files with 49 additions and 30 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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>";
|
||||
});
|
||||
|
|
|
|||
11
app/src/types/index.d.ts
vendored
11
app/src/types/index.d.ts
vendored
|
|
@ -23,6 +23,7 @@ type TOperation =
|
|||
| "addFlashcards"
|
||||
| "removeFlashcards"
|
||||
| "updateAttrViewCell"
|
||||
| "updateAttrViewCol"
|
||||
type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins"
|
||||
type TCardType = "doc" | "notebook" | "all"
|
||||
type TEventBus = "ws-main" |
|
||||
|
|
@ -31,7 +32,7 @@ type TEventBus = "ws-main" |
|
|||
"open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
|
||||
"open-menu-av" | "open-menu-content" |
|
||||
"loaded-protyle"
|
||||
type TAVCol = "text" | "date" | "number" | "relation" | "rollup" | "select" | "block"
|
||||
type TAVCol = "text" | "date" | "number" | "relation" | "rollup" | "select" | "block"| "mSelect"
|
||||
|
||||
declare module "blueimp-md5"
|
||||
|
||||
|
|
@ -280,7 +281,7 @@ interface IScrollAttr {
|
|||
interface IOperation {
|
||||
action: TOperation, // move, delete 不需要传 data
|
||||
id?: string,
|
||||
data?: string, // updateAttr 时为 { old: IObject, new: IObject }
|
||||
data?: any, // updateAttr 时为 { old: IObject, new: IObject }, updateAttrViewCell 时为 {TAVCol: {content: string}}
|
||||
parentID?: string // 为 insertAttrViewBlock 传 avid
|
||||
previousID?: string
|
||||
retData?: any
|
||||
|
|
@ -836,10 +837,6 @@ interface IAVCell {
|
|||
id: string,
|
||||
color: string,
|
||||
bgColor: string,
|
||||
value: string,
|
||||
value: any,
|
||||
valueType: TAVCol,
|
||||
renderValue: {
|
||||
content: string,
|
||||
id: string,
|
||||
} | string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue