2023-06-08 18:21:10 +08:00
|
|
|
import {fetchPost} from "../../../util/fetch";
|
|
|
|
|
|
2023-06-07 11:55:45 +08:00
|
|
|
export const avRender = (element: Element) => {
|
|
|
|
|
let avElements: Element[] = [];
|
|
|
|
|
if (element.getAttribute("data-type") === "NodeAttributeView") {
|
|
|
|
|
// 编辑器内代码块编辑渲染
|
|
|
|
|
avElements = [element];
|
|
|
|
|
} else {
|
|
|
|
|
avElements = Array.from(element.querySelectorAll('[data-type="NodeAttributeView"]'));
|
|
|
|
|
}
|
|
|
|
|
if (avElements.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (avElements.length > 0) {
|
|
|
|
|
avElements.forEach((e: HTMLDivElement) => {
|
|
|
|
|
if (e.getAttribute("data-render") === "true") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-08 18:21:10 +08:00
|
|
|
// const data = {
|
|
|
|
|
// title: "table",
|
|
|
|
|
// filter: {},
|
|
|
|
|
// sorts: {},
|
|
|
|
|
// columns: [{
|
|
|
|
|
// width: 500,
|
|
|
|
|
// icon: "",
|
|
|
|
|
// id: "",
|
|
|
|
|
// name: "columnA",
|
|
|
|
|
// wrap: false,
|
|
|
|
|
// type: "",
|
|
|
|
|
// }, {
|
|
|
|
|
// width: 500,
|
|
|
|
|
// icon: "",
|
|
|
|
|
// id: "",
|
|
|
|
|
// name: "columnB",
|
|
|
|
|
// wrap: false,
|
|
|
|
|
// type: "",
|
|
|
|
|
// }],
|
|
|
|
|
// rows: [{
|
|
|
|
|
// id: "",
|
|
|
|
|
// cells: [{
|
|
|
|
|
// value: "a",
|
|
|
|
|
// }, {
|
|
|
|
|
// color: "var(--b3-card-error-color)",
|
|
|
|
|
// bgColor: "var(--b3-card-error-background)",
|
|
|
|
|
// value: "a1",
|
|
|
|
|
// }]
|
|
|
|
|
// }, {
|
|
|
|
|
// id: "",
|
|
|
|
|
// cells: [{
|
|
|
|
|
// color: "var(--b3-card-success-color)",
|
|
|
|
|
// bgColor: "var(--b3-card-success-background)",
|
|
|
|
|
// value: "b",
|
|
|
|
|
// }, {
|
|
|
|
|
// value: "b1",
|
|
|
|
|
// }]
|
|
|
|
|
// }]
|
|
|
|
|
// };
|
|
|
|
|
fetchPost("/api/av/renderAttributeView", {id: e.getAttribute("data-node-id")}, (response) => {
|
2023-06-08 18:25:33 +08:00
|
|
|
const data = response.data.av;
|
2023-06-08 18:21:10 +08:00
|
|
|
let tableHTML = '<div class="av__row av__row--header" style="background-color: var(--b3-theme-background)"><div class="av__firstcol"><input style="margin-top: 14px" type="checkbox"></div>';
|
2023-06-08 18:25:33 +08:00
|
|
|
data.columns.forEach((column: IAVColumn) => {
|
2023-06-08 18:21:10 +08:00
|
|
|
tableHTML += `
|
2023-06-08 12:03:04 +08:00
|
|
|
<div class="av__cell" style="width: ${column.width}px;">${column.name}</div>`
|
2023-06-08 18:21:10 +08:00
|
|
|
});
|
|
|
|
|
tableHTML += `<div class="block__icons">
|
2023-06-08 12:03:04 +08:00
|
|
|
<div class="block__icon block__icon--show"><svg><use xlink:href="#iconAdd"></use></svg></div>
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
<div class="block__icon block__icon--show"><svg><use xlink:href="#iconMore"></use></svg></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
2023-06-08 18:25:33 +08:00
|
|
|
data.rows.forEach((row: IAVRow) => {
|
2023-06-08 18:21:10 +08:00
|
|
|
tableHTML += `<div class="av__row" data-id="${row.id}"><div class="av__firstcol"><input type="checkbox"></div>`;
|
|
|
|
|
row.cells.forEach((cell, index) => {
|
2023-06-08 18:25:33 +08:00
|
|
|
tableHTML += `<div class="av__cell" style="width: ${data.columns[index].width}px;background-color: ${cell.bgColor || ""};color: ${cell.color || ""}">${cell.value}</div>`
|
2023-06-08 18:21:10 +08:00
|
|
|
});
|
|
|
|
|
tableHTML += `<div></div></div>`;
|
2023-06-08 10:07:26 +08:00
|
|
|
});
|
2023-06-08 18:21:10 +08:00
|
|
|
const paddingLeft = e.parentElement.style.paddingLeft;
|
|
|
|
|
const paddingRight = e.parentElement.style.paddingRight;
|
|
|
|
|
// 10: ::-webkit-scrollbar width
|
|
|
|
|
e.style.width = (e.parentElement.clientWidth - 10) + "px";
|
|
|
|
|
e.style.alignSelf = "center";
|
|
|
|
|
e.firstElementChild.outerHTML = `<div>
|
2023-06-08 10:07:26 +08:00
|
|
|
<div style="padding-left: ${paddingLeft};padding-right: ${paddingRight}">
|
|
|
|
|
<div>
|
|
|
|
|
<div>tab1</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div contenteditable="true">
|
|
|
|
|
${data.title}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="av__scroll">
|
|
|
|
|
<div style="padding-left: ${paddingLeft};padding-right: ${paddingRight};min-width: 100%;float: left;">
|
|
|
|
|
${tableHTML}
|
2023-06-08 12:03:04 +08:00
|
|
|
<div class="block__icon block__icon--show">
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg><span class="fn__space"></span>
|
|
|
|
|
${window.siyuan.languages.addAttr}
|
|
|
|
|
</div>
|
2023-06-08 10:07:26 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
2023-06-08 18:21:10 +08:00
|
|
|
e.setAttribute("data-render", "true");
|
|
|
|
|
})
|
2023-06-07 11:55:45 +08:00
|
|
|
});
|
|
|
|
|
}
|
2023-06-07 11:56:34 +08:00
|
|
|
};
|