Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: type https://github.com/siyuan-note/siyuan/issues/7536

Vanessa5c77de0a09d0
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index ad969f4d76..58b8fa579e 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -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({
diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts
index 83dcd15a7f..3a11e07470 100644
--- a/app/src/protyle/render/av/render.ts
+++ b/app/src/protyle/render/av/render.ts
@@ -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>";
});
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 28f7865f67..28fa3dc3f2 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -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
}