mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-20 02:50:58 +08:00
This commit is contained in:
parent
e51fb3cde7
commit
a5d6d4e848
@ -53,7 +53,7 @@ export const bindAssetEvent = (options: {
|
||||
|
||||
export const getAssetHTML = (cellElements: HTMLElement[]) => {
|
||||
let html = "";
|
||||
genCellValueByElement(getTypeByCellElement(cellElements[0]), cellElements[0]).mAsset.forEach(item => {
|
||||
genCellValueByElement("mAsset", cellElements[0]).mAsset.forEach(item => {
|
||||
if (!item.content) {
|
||||
return;
|
||||
}
|
||||
|
@ -106,24 +106,25 @@ export const genAVValueHTML = (value: IAVCellValue) => {
|
||||
break;
|
||||
case "relation":
|
||||
value.relation?.blockIDs?.forEach((item, index) => {
|
||||
html += `<span class="av__celltext--url" style="margin-right: 8px" data-id="${item}">${value.relation?.contents[index]}</span>`;
|
||||
html += `<span class="av__celltext--url" style="margin-right: 8px" data-id="${item}">${value.relation?.contents[index] || "Untitled"}</span>`;
|
||||
});
|
||||
break;
|
||||
case "rollup":
|
||||
value?.rollup?.contents?.forEach((item, index) => {
|
||||
value?.rollup?.contents?.forEach((item) => {
|
||||
const rollupText = ["select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? genAVValueHTML(item) : genAVRollupHTML(item);
|
||||
if (!rollupText && html) {
|
||||
html = html.substring(0, html.length - 2);
|
||||
} else {
|
||||
html += rollupText + ((index === value.rollup.contents.length - 1 || !rollupText) ? "" : ", ");
|
||||
if (rollupText) {
|
||||
html += rollupText + ", ";
|
||||
}
|
||||
});
|
||||
if (html && html.endsWith(", ")) {
|
||||
html = html.substring(0, html.length - 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return html;
|
||||
};
|
||||
|
||||
export const renderAVAttribute = (element: HTMLElement, id: string, protyle?: IProtyle) => {
|
||||
export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IProtyle) => {
|
||||
fetchPost("/api/av/getAttributeViewKeys", {id}, (response) => {
|
||||
let html = "";
|
||||
response.data.forEach((table: {
|
||||
@ -167,40 +168,42 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes
|
||||
});
|
||||
html += "</div>";
|
||||
});
|
||||
element.innerHTML = html;
|
||||
element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !element.isSameNode(target)) {
|
||||
const type = target.getAttribute("data-type");
|
||||
if (type === "date") {
|
||||
popTextCell(protyle, [target], "date");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "select" || type === "mSelect") {
|
||||
popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "mAsset") {
|
||||
popTextCell(protyle, [target], "mAsset");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "checkbox") {
|
||||
popTextCell(protyle, [target], "checkbox");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "relation") {
|
||||
popTextCell(protyle, [target], "relation");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
if (element.innerHTML === "") {
|
||||
element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !element.isSameNode(target)) {
|
||||
const type = target.getAttribute("data-type");
|
||||
if (type === "date") {
|
||||
popTextCell(protyle, [target], "date");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "select" || type === "mSelect") {
|
||||
popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "mAsset") {
|
||||
popTextCell(protyle, [target], "mAsset");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "checkbox") {
|
||||
popTextCell(protyle, [target], "checkbox");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "relation") {
|
||||
popTextCell(protyle, [target], "relation");
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
element.innerHTML = html;
|
||||
element.querySelectorAll(".b3-text-field--text").forEach((item: HTMLInputElement) => {
|
||||
item.addEventListener("change", () => {
|
||||
let value;
|
||||
|
@ -8,6 +8,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
|
||||
import {stickyRow} from "./row";
|
||||
import {getCalcValue} from "./calc";
|
||||
import {openMenuPanel} from "./openMenuPanel";
|
||||
import {renderAVAttribute} from "./blockAttr";
|
||||
|
||||
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => {
|
||||
let avElements: Element[] = [];
|
||||
@ -295,6 +296,13 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
||||
if (operation.action === "addAttrViewCol" && isPulse) {
|
||||
openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id});
|
||||
}
|
||||
if (operation.action === "updateAttrViewCell") {
|
||||
const attrElement = document.querySelector(`.b3-dialog--open[data-key="${Constants.DIALOG_ATTR}"] div[data-av-id="${operation.avID}"]`) as HTMLElement
|
||||
if (attrElement) {
|
||||
// 更新属性面板
|
||||
renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle);
|
||||
}
|
||||
}
|
||||
}, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id :
|
||||
(operation.action === "removeAttrViewView" ? null : undefined));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user