diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 8c586d705..5070d92f7 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -3,7 +3,7 @@ import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../
import {transaction} from "../../wysiwyg/transaction";
import {openEditorTab} from "../../../menus/util";
import {copySubMenu} from "../../../menus/commonMenuItem";
-import {getCellText, getTypeByCellElement, popTextCell} from "./cell";
+import {getCellText, getTypeByCellElement, popTextCell, renderCell, updateHeaderCell} from "./cell";
import {getColIconByType, showColMenu} from "./col";
import {deleteRow, insertAttrViewBlockAnimation, setPageSize, updateHeader} from "./row";
import {emitOpenMenu} from "../../../plugin/EventBus";
@@ -413,8 +413,17 @@ export const updateAVName = (protyle: IProtyle, blockElement: Element) => {
});
};
-export const updateAttrViewCellAnimation = (cellElement: HTMLElement) => {
- cellElement.style.backgroundColor = "var(--b3-av-hover)";
+export const updateAttrViewCellAnimation = (cellElement: HTMLElement, value: IAVCellValue, headerValue?: {
+ icon?: string,
+ name?: string,
+ pin?: boolean,
+ type?: TAVCol
+}) => {
+ if (headerValue) {
+ updateHeaderCell(cellElement, headerValue);
+ } else {
+ cellElement.innerHTML = renderCell(value, cellElement.dataset.wrap === "true");
+ }
};
export const removeAttrViewColAnimation = (blockElement: Element, id: string) => {
diff --git a/app/src/protyle/render/av/asset.ts b/app/src/protyle/render/av/asset.ts
index df9398b86..cd38f97fe 100644
--- a/app/src/protyle/render/av/asset.ts
+++ b/app/src/protyle/render/av/asset.ts
@@ -133,7 +133,7 @@ export const updateAssetCell = (options: {
// 为空时 cellId 每次请求都不一致
cellData.id = item.dataset.id;
if (!cellData.value || !cellData.value.mAsset) {
- cellData.value = {mAsset: []} as IAVCellValue;
+ cellData.value = {type: "mAsset", mAsset: []} as IAVCellValue;
}
} else {
cellData = row.cells.find(cellItem => {
@@ -206,7 +206,7 @@ export const updateAssetCell = (options: {
if (item.classList.contains("custom-attr__avvalue")) {
item.innerHTML = genAVValueHTML(cellData.value);
} else {
- updateAttrViewCellAnimation(item);
+ updateAttrViewCellAnimation(item, cellData.value);
}
});
transaction(options.protyle, cellDoOperations, cellUndoOperations);
diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts
index 4d7d9ef42..1958a8260 100644
--- a/app/src/protyle/render/av/blockAttr.ts
+++ b/app/src/protyle/render/av/blockAttr.ts
@@ -88,7 +88,7 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle?: IP
keyID: string,
id: string,
blockID: string,
- type?: TAVCol & IAVCellValue
+ type: TAVCol & IAVCellValue
} []
}[],
blockIDs: string[],
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 20748a2cd..8dc24a3c7 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -7,6 +7,8 @@ import {objEquals} from "../../../util/functions";
import {fetchPost} from "../../../util/fetch";
import {focusBlock} from "../../util/selection";
import * as dayjs from "dayjs";
+import {unicode2Emoji} from "../../../emoji";
+import {getColIconByType} from "./col";
export const getCellText = (cellElement: HTMLElement | false) => {
if (!cellElement) {
@@ -438,7 +440,11 @@ const updateCellValueByInput = (protyle: IProtyle, type: TAVCol, cellElements: H
data: blockElement.getAttribute("updated"),
});
if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
- updateAttrViewCellAnimation(item);
+ updateAttrViewCellAnimation(item, {
+ [type]: inputValue,
+ isDetached: true,
+ type
+ });
}
});
}
@@ -487,14 +493,14 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
const colId = item.getAttribute("data-col-id");
text += getCellText(item);
-
+ const cellValue = genCellValue(type, value);
doOperations.push({
action: "updateAttrViewCell",
id: cellId,
avID,
keyID: colId,
rowID,
- data: genCellValue(type, value)
+ data: cellValue
});
undoOperations.push({
action: "updateAttrViewCell",
@@ -505,7 +511,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
data: genCellValueByElement(type, item)
});
if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
- updateAttrViewCellAnimation(item);
+ updateAttrViewCellAnimation(item, cellValue);
}
});
if (doOperations.length > 0) {
@@ -523,3 +529,91 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
}
return text;
};
+
+export const renderCell = (cellValue: IAVCellValue, wrap: boolean) => {
+ let text = "";
+ if (["text", "template"].includes(cellValue.type)) {
+ text = `${cellValue ? (cellValue[cellValue.type as "text"].content || "") : ""}`;
+ } else if (["url", "email", "phone"].includes(cellValue.type)) {
+ const urlContent = cellValue ? cellValue[cellValue.type as "url"].content : "";
+ // https://github.com/siyuan-note/siyuan/issues/9291
+ let urlAttr = "";
+ if (cellValue.type === "url") {
+ urlAttr = ` data-href="${urlContent}"`;
+ }
+ text = `${urlContent}`;
+ } else if (cellValue.type === "block") {
+ if (cellValue?.isDetached) {
+ text = `${cellValue.block.content || ""}
+${window.siyuan.languages.more}`;
+ } else {
+ text = `${cellValue.block.content || ""}
+${window.siyuan.languages.update}`;
+ }
+ } else if (cellValue.type === "number") {
+ text = `${cellValue?.number.formattedContent || ""}`;
+ } else if (cellValue.type === "mSelect" || cellValue.type === "select") {
+ cellValue?.mSelect?.forEach((item) => {
+ text += `${item.content}`;
+ });
+ } else if (cellValue.type === "date") {
+ const dataValue = cellValue ? cellValue.date : null;
+ text = ``;
+ if (dataValue && dataValue.isNotEmpty) {
+ text += dayjs(dataValue.content).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
+ }
+ if (dataValue && dataValue.hasEndDate && dataValue.isNotEmpty && dataValue.isNotEmpty2) {
+ text += `${dayjs(dataValue.content2).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
+ }
+ text += "";
+ } else if (["created", "updated"].includes(cellValue.type)) {
+ const dataValue = cellValue ? cellValue[cellValue.type as "date"] : null;
+ text = ``;
+ if (dataValue && dataValue.isNotEmpty) {
+ text += dayjs(dataValue.content).format("YYYY-MM-DD HH:mm");
+ }
+ text += "";
+ } else if (cellValue.type === "mAsset") {
+ cellValue?.mAsset?.forEach((item) => {
+ if (item.type === "image") {
+ text += ``;
+ } else {
+ text += `${item.name}`;
+ }
+ });
+ } else if (cellValue.type === "checkbox") {
+ text += ``;
+ }
+ if (["text", "template", "url", "email", "phone", "number", "date", "created", "updated"].includes(cellValue.type) &&
+ cellValue && cellValue[cellValue.type as "url"].content) {
+ text += ``;
+ }
+ return text;
+}
+
+export const updateHeaderCell = (cellElement: HTMLElement, headerValue: {
+ icon?: string,
+ name?: string,
+ pin?: boolean,
+}) => {
+ if (typeof headerValue.icon !== "undefined") {
+ cellElement.dataset.icon = headerValue.icon;
+ cellElement.querySelector(".av__cellheadericon").outerHTML = headerValue.icon ? unicode2Emoji(headerValue.icon, "av__cellheadericon", true) : ``
+ }
+ if (typeof headerValue.name !== "undefined") {
+ cellElement.querySelector(".av__celltext").textContent = headerValue.name;
+ }
+ if (typeof headerValue.pin !== "undefined") {
+ const textElement = cellElement.querySelector(".av__celltext")
+ if (headerValue.pin) {
+ if (!textElement.nextElementSibling) {
+ textElement.insertAdjacentHTML("afterend", '