2023-06-08 18:21:10 +08:00
|
|
|
|
import {fetchPost} from "../../../util/fetch";
|
2023-09-21 10:54:41 +08:00
|
|
|
|
import {getColIconByType} from "./col";
|
2023-07-01 23:15:21 +08:00
|
|
|
|
import {Constants} from "../../../constants";
|
2024-01-08 23:23:59 +08:00
|
|
|
|
import {renderCell} from "./cell";
|
2023-10-05 11:16:44 +08:00
|
|
|
|
import {unicode2Emoji} from "../../../emoji";
|
2023-10-13 13:37:32 +08:00
|
|
|
|
import {focusBlock} from "../../util/selection";
|
2023-12-13 12:16:45 +08:00
|
|
|
|
import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
|
2023-11-15 18:40:01 +08:00
|
|
|
|
import {stickyRow} from "./row";
|
2023-11-20 11:19:56 +08:00
|
|
|
|
import {getCalcValue} from "./calc";
|
2023-12-24 12:17:05 +08:00
|
|
|
|
import {openMenuPanel} from "./openMenuPanel";
|
2023-06-08 18:21:10 +08:00
|
|
|
|
|
2023-11-30 23:30:19 +08:00
|
|
|
|
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => {
|
2023-06-07 11:55:45 +08:00
|
|
|
|
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) {
|
2023-06-08 22:55:31 +08:00
|
|
|
|
avElements.forEach((e: HTMLElement) => {
|
2023-06-07 11:55:45 +08:00
|
|
|
|
if (e.getAttribute("data-render") === "true") {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-10-12 17:34:19 +08:00
|
|
|
|
if (e.firstElementChild.innerHTML === "") {
|
2023-10-14 00:04:16 +08:00
|
|
|
|
e.style.alignSelf = "";
|
2023-10-12 17:34:19 +08:00
|
|
|
|
let html = "";
|
2023-10-12 20:21:53 +08:00
|
|
|
|
[1, 2, 3].forEach(() => {
|
2023-10-12 17:34:19 +08:00
|
|
|
|
html += `<div class="av__row">
|
2023-10-14 10:01:42 +08:00
|
|
|
|
<div style="width: 24px;flex-shrink: 0"></div>
|
2023-10-12 17:34:19 +08:00
|
|
|
|
<div class="av__cell" style="width: 200px"><span class="av__pulse"></span></div>
|
|
|
|
|
|
<div class="av__cell" style="width: 200px"><span class="av__pulse"></span></div>
|
|
|
|
|
|
<div class="av__cell" style="width: 200px"><span class="av__pulse"></span></div>
|
|
|
|
|
|
<div class="av__cell" style="width: 200px"><span class="av__pulse"></span></div>
|
|
|
|
|
|
</div>`;
|
2023-10-12 20:23:18 +08:00
|
|
|
|
});
|
|
|
|
|
|
e.firstElementChild.innerHTML = html;
|
2023-10-12 17:34:19 +08:00
|
|
|
|
}
|
2023-08-01 21:29:15 +08:00
|
|
|
|
const left = e.querySelector(".av__scroll")?.scrollLeft || 0;
|
2023-11-15 09:07:52 +08:00
|
|
|
|
const headerTransform = (e.querySelector(".av__row--header") as HTMLElement)?.style.transform;
|
|
|
|
|
|
const footerTransform = (e.querySelector(".av__row--footer") as HTMLElement)?.style.transform;
|
2023-10-13 13:37:32 +08:00
|
|
|
|
let selectCellId = "";
|
|
|
|
|
|
const selectCellElement = e.querySelector(".av__cell--select") as HTMLElement;
|
|
|
|
|
|
if (selectCellElement) {
|
2023-11-14 12:58:45 +08:00
|
|
|
|
selectCellId = (hasClosestByClassName(selectCellElement, "av__row") as HTMLElement).dataset.id + Constants.ZWSP + selectCellElement.getAttribute("data-col-id");
|
2023-10-13 13:37:32 +08:00
|
|
|
|
}
|
2023-11-24 00:00:57 +08:00
|
|
|
|
const created = protyle.options.history?.created;
|
2023-11-24 00:19:20 +08:00
|
|
|
|
const snapshot = protyle.options.history?.snapshot;
|
2023-12-01 11:05:27 +08:00
|
|
|
|
let newViewID = "";
|
|
|
|
|
|
if (typeof viewID === "string") {
|
|
|
|
|
|
newViewID = viewID;
|
|
|
|
|
|
} else if (typeof viewID === "undefined") {
|
2023-12-01 11:50:34 +08:00
|
|
|
|
newViewID = e.querySelector(".av__header .item--focus")?.getAttribute("data-id");
|
2023-12-01 11:05:27 +08:00
|
|
|
|
}
|
2023-11-24 00:19:20 +08:00
|
|
|
|
fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), {
|
2023-07-31 23:58:45 +08:00
|
|
|
|
id: e.getAttribute("data-av-id"),
|
2023-11-24 00:19:20 +08:00
|
|
|
|
created,
|
2023-11-30 23:02:14 +08:00
|
|
|
|
snapshot,
|
2023-12-08 22:17:36 +08:00
|
|
|
|
pageSize: parseInt(e.dataset.pageSize) || undefined,
|
2023-12-01 11:05:27 +08:00
|
|
|
|
viewID: newViewID
|
2023-07-31 23:58:45 +08:00
|
|
|
|
}, (response) => {
|
2023-07-11 21:34:22 +08:00
|
|
|
|
const data = response.data.view as IAVTable;
|
2023-12-08 22:25:42 +08:00
|
|
|
|
if (!e.dataset.pageSize) {
|
|
|
|
|
|
e.dataset.pageSize = data.pageSize.toString();
|
|
|
|
|
|
}
|
2023-06-08 19:21:33 +08:00
|
|
|
|
// header
|
2024-01-10 23:23:28 +08:00
|
|
|
|
let tableHTML = '<div class="av__row av__row--header"><div class="av__colsticky"><div class="av__firstcol"><svg class="av__check"><use xlink:href="#iconUncheck"></use></svg></div>';
|
|
|
|
|
|
let calcHTML = '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconMath"></use></svg></div>';
|
2023-11-14 12:58:45 +08:00
|
|
|
|
let pinIndex = -1;
|
|
|
|
|
|
let pinMaxIndex = -1;
|
|
|
|
|
|
let indexWidth = 0;
|
|
|
|
|
|
const eWidth = e.clientWidth;
|
|
|
|
|
|
data.columns.forEach((item, index) => {
|
|
|
|
|
|
if (!item.hidden) {
|
|
|
|
|
|
if (item.pin) {
|
|
|
|
|
|
pinIndex = index;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (indexWidth < eWidth - 200) {
|
|
|
|
|
|
indexWidth += parseInt(item.width) || 200;
|
|
|
|
|
|
pinMaxIndex = index;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-14 23:18:18 +08:00
|
|
|
|
});
|
2023-11-14 12:58:45 +08:00
|
|
|
|
pinIndex = Math.min(pinIndex, pinMaxIndex);
|
2024-01-10 23:23:28 +08:00
|
|
|
|
if (pinIndex < 0) {
|
|
|
|
|
|
tableHTML += '</div>';
|
|
|
|
|
|
calcHTML += '</div>';
|
2023-11-14 12:58:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
data.columns.forEach((column: IAVColumn, index: number) => {
|
2023-06-08 22:55:31 +08:00
|
|
|
|
if (column.hidden) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-14 12:58:45 +08:00
|
|
|
|
tableHTML += `<div class="av__cell" data-col-id="${column.id}"
|
2023-12-05 22:41:12 +08:00
|
|
|
|
data-icon="${column.icon}" data-dtype="${column.type}" data-wrap="${column.wrap}" data-pin="${column.pin}"
|
|
|
|
|
|
style="width: ${column.width || "200px"};">
|
2023-07-02 23:58:00 +08:00
|
|
|
|
<div draggable="true" class="av__cellheader">
|
2023-11-20 11:12:02 +08:00
|
|
|
|
${column.icon ? unicode2Emoji(column.icon, "av__cellheadericon", true) : `<svg class="av__cellheadericon"><use xlink:href="#${getColIconByType(column.type)}"></use></svg>`}
|
2024-01-10 11:33:49 +08:00
|
|
|
|
<span class="av__celltext fn__flex-shrink">${column.name}</span>
|
2023-11-20 11:12:02 +08:00
|
|
|
|
${column.pin ? '<div class="fn__flex-1"></div><svg class="av__cellheadericon"><use xlink:href="#iconPin"></use></svg>' : ""}
|
2023-07-02 23:58:00 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="av__widthdrag"></div>
|
2023-06-08 22:56:52 +08:00
|
|
|
|
</div>`;
|
2023-11-14 12:58:45 +08:00
|
|
|
|
if (pinIndex === index) {
|
2023-11-14 23:18:18 +08:00
|
|
|
|
tableHTML += "</div>";
|
2023-11-14 12:58:45 +08:00
|
|
|
|
}
|
2023-07-15 23:18:35 +08:00
|
|
|
|
calcHTML += `<div class="av__calc${calcHTML ? "" : " av__calc--show"}${column.calc && column.calc.operator !== "" ? " av__calc--ashow" : ""}" data-col-id="${column.id}" data-dtype="${column.type}" data-operator="${column.calc?.operator || ""}"
|
|
|
|
|
|
style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use xlink:href="#iconDown"></use></svg>' + window.siyuan.languages.calc}</div>`;
|
2023-11-14 12:58:45 +08:00
|
|
|
|
if (pinIndex === index) {
|
2023-11-14 23:18:18 +08:00
|
|
|
|
calcHTML += "</div>";
|
2023-11-14 12:58:45 +08:00
|
|
|
|
}
|
2023-06-08 18:21:10 +08:00
|
|
|
|
});
|
2023-07-15 00:07:27 +08:00
|
|
|
|
tableHTML += `<div class="block__icons" style="min-height: auto">
|
2023-06-08 19:21:33 +08:00
|
|
|
|
<div class="block__icon block__icon--show" data-type="av-header-add"><svg><use xlink:href="#iconAdd"></use></svg></div>
|
2023-06-08 12:03:04 +08:00
|
|
|
|
<div class="fn__space"></div>
|
2023-06-08 19:21:33 +08:00
|
|
|
|
<div class="block__icon block__icon--show" data-type="av-header-more"><svg><use xlink:href="#iconMore"></use></svg></div>
|
2023-06-08 12:03:04 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>`;
|
2023-06-08 19:21:33 +08:00
|
|
|
|
// body
|
2023-06-08 18:25:33 +08:00
|
|
|
|
data.rows.forEach((row: IAVRow) => {
|
2024-01-10 23:23:28 +08:00
|
|
|
|
tableHTML += `<div class="av__row" data-id="${row.id}">
|
|
|
|
|
|
<div class="av__colsticky">
|
|
|
|
|
|
<div class="av__firstcol">
|
|
|
|
|
|
<svg class="av__check"><use xlink:href="#iconUncheck"></use></svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
if (pinIndex < 0) {
|
|
|
|
|
|
tableHTML += '</div>';
|
2023-11-14 12:58:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-08 18:21:10 +08:00
|
|
|
|
row.cells.forEach((cell, index) => {
|
2023-07-02 20:52:16 +08:00
|
|
|
|
if (data.columns[index].hidden) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-09 17:00:55 +08:00
|
|
|
|
tableHTML += `<div class="av__cell" data-id="${cell.id}" data-col-id="${data.columns[index].id}"
|
2023-12-05 22:41:12 +08:00
|
|
|
|
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""} data-wrap="${data.columns[index].wrap}"
|
2023-09-27 23:58:48 +08:00
|
|
|
|
${cell.value?.isDetached ? ' data-detached="true"' : ""}
|
2023-07-02 23:58:00 +08:00
|
|
|
|
style="width: ${data.columns[index].width || "200px"};
|
2023-07-02 22:37:17 +08:00
|
|
|
|
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
|
2023-12-18 20:47:22 +08:00
|
|
|
|
${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, data.columns[index].wrap)}</div>`;
|
2023-11-14 12:58:45 +08:00
|
|
|
|
|
|
|
|
|
|
if (pinIndex === index) {
|
2023-11-14 23:18:18 +08:00
|
|
|
|
tableHTML += "</div>";
|
2023-11-14 12:58:45 +08:00
|
|
|
|
}
|
2023-06-08 18:21:10 +08:00
|
|
|
|
});
|
2023-06-08 22:56:52 +08:00
|
|
|
|
tableHTML += "<div></div></div>";
|
2023-06-08 10:07:26 +08:00
|
|
|
|
});
|
2023-07-12 00:08:00 +08:00
|
|
|
|
let tabHTML = "";
|
2023-07-11 23:13:19 +08:00
|
|
|
|
response.data.views.forEach((item: IAVView) => {
|
2023-11-30 23:02:14 +08:00
|
|
|
|
tabHTML += `<div data-id="${item.id}" class="item${item.id === response.data.viewID ? " item--focus" : ""}">
|
2023-12-01 20:58:53 +08:00
|
|
|
|
${item.icon ? unicode2Emoji(item.icon, "item__graphic", true) : '<svg class="item__graphic"><use xlink:href="#iconTable"></use></svg>'}
|
2023-07-11 21:34:22 +08:00
|
|
|
|
<span class="item__text">${item.name}</span>
|
2023-07-12 00:08:00 +08:00
|
|
|
|
</div>`;
|
|
|
|
|
|
});
|
2023-12-13 16:44:29 +08:00
|
|
|
|
e.firstElementChild.outerHTML = `<div class="av__container" style="--av-background:${e.style.backgroundColor || "var(--b3-theme-background)"}">
|
2023-10-14 10:49:35 +08:00
|
|
|
|
<div class="av__header">
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<div class="fn__flex av__views">
|
2023-12-01 20:18:58 +08:00
|
|
|
|
<div class="layout-tab-bar fn__flex">
|
|
|
|
|
|
${tabHTML}
|
|
|
|
|
|
</div>
|
2023-11-30 22:05:23 +08:00
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<span data-type="av-add" class="block__icon">
|
2023-11-30 22:05:23 +08:00
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
</span>
|
2023-12-01 16:59:04 +08:00
|
|
|
|
<div class="fn__flex-1"></div>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<span data-type="av-switcher" class="block__icon${response.data.views.length > 0 ? "" : " fn__none"}">
|
2023-12-01 16:59:04 +08:00
|
|
|
|
<svg><use xlink:href="#iconDown"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<span data-type="av-filter" class="block__icon${data.filters.length > 0 ? " block__icon--active" : ""}">
|
2023-07-02 20:52:16 +08:00
|
|
|
|
<svg><use xlink:href="#iconFilter"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<span data-type="av-sort" class="block__icon${data.sorts.length > 0 ? " block__icon--active" : ""}">
|
2023-07-02 20:52:16 +08:00
|
|
|
|
<svg><use xlink:href="#iconSort"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
<span data-type="av-more" class="block__icon">
|
2023-07-02 20:52:16 +08:00
|
|
|
|
<svg><use xlink:href="#iconMore"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-08 12:48:16 +08:00
|
|
|
|
<span data-type="av-add-more" class="block__icon">
|
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
2023-12-01 20:46:42 +08:00
|
|
|
|
${response.data.isMirror ? ` <span class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.mirrorTip}">
|
2023-12-01 09:56:29 +08:00
|
|
|
|
<svg><use xlink:href="#iconSplitLR"></use></svg></span><div class="fn__space"></div>` : ""}
|
2023-06-08 10:07:26 +08:00
|
|
|
|
</div>
|
2023-12-01 09:56:29 +08:00
|
|
|
|
<div contenteditable="${protyle.disabled ? "false" : "true"}" spellcheck="${window.siyuan.config.editor.spellcheck.toString()}" class="av__title" data-title="${response.data.name || ""}" data-tip="${window.siyuan.languages.title}">${response.data.name || ""}</div>
|
2023-06-30 23:57:11 +08:00
|
|
|
|
<div class="av__counter fn__none"></div>
|
2023-06-08 10:07:26 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="av__scroll">
|
2023-12-05 22:41:12 +08:00
|
|
|
|
<div class="av__body">
|
2023-06-08 10:07:26 +08:00
|
|
|
|
${tableHTML}
|
2023-12-08 13:26:13 +08:00
|
|
|
|
<div class="av__row--util">
|
2023-11-14 12:58:45 +08:00
|
|
|
|
<div class="av__colsticky">
|
2024-01-10 23:23:28 +08:00
|
|
|
|
<div class="av__firstcol">
|
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
</div>
|
2023-12-08 13:26:13 +08:00
|
|
|
|
<button class="b3-button" data-type="av-add-bottom">
|
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
${window.siyuan.languages.addAttr}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<span class="fn__space"></span>
|
2023-12-08 21:56:48 +08:00
|
|
|
|
<button class="b3-button${data.rowCount > data.rows.length ? "" : " fn__none"}">
|
2023-12-08 13:26:13 +08:00
|
|
|
|
<svg data-type="av-load-more"><use xlink:href="#iconArrowDown"></use></svg>
|
|
|
|
|
|
<span data-type="av-load-more">
|
|
|
|
|
|
${window.siyuan.languages.loadMore}
|
|
|
|
|
|
</span>
|
2023-12-08 21:56:48 +08:00
|
|
|
|
<svg data-type="set-page-size" data-size="${data.pageSize}"><use xlink:href="#iconMore"></use></svg>
|
2023-12-08 13:26:13 +08:00
|
|
|
|
</button>
|
2023-11-14 12:58:45 +08:00
|
|
|
|
</div>
|
2023-06-08 12:03:04 +08:00
|
|
|
|
</div>
|
2023-11-14 12:58:45 +08:00
|
|
|
|
<div class="av__row--footer">${calcHTML}</div>
|
2023-06-08 10:07:26 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>`;
|
2023-12-13 16:44:29 +08:00
|
|
|
|
e.setAttribute("data-render", "true");
|
|
|
|
|
|
// 历史兼容
|
|
|
|
|
|
e.style.margin = "";
|
|
|
|
|
|
if (left) {
|
|
|
|
|
|
e.querySelector(".av__scroll").scrollLeft = left;
|
|
|
|
|
|
}
|
2023-11-15 18:40:01 +08:00
|
|
|
|
|
2023-12-13 16:44:29 +08:00
|
|
|
|
const editRect = protyle.contentElement.getBoundingClientRect();
|
|
|
|
|
|
if (headerTransform) {
|
|
|
|
|
|
(e.querySelector(".av__row--header") as HTMLElement).style.transform = headerTransform;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
stickyRow(e, editRect, "top");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (footerTransform) {
|
|
|
|
|
|
(e.querySelector(".av__row--footer") as HTMLElement).style.transform = footerTransform;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
stickyRow(e, editRect, "bottom");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (selectCellId) {
|
|
|
|
|
|
const newCellElement = e.querySelector(`.av__row[data-id="${selectCellId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${selectCellId.split(Constants.ZWSP)[1]}"]`);
|
|
|
|
|
|
if (newCellElement) {
|
|
|
|
|
|
newCellElement.classList.add("av__cell--select");
|
2023-11-15 09:07:52 +08:00
|
|
|
|
}
|
2023-12-14 12:22:18 +08:00
|
|
|
|
const avMaskElement = document.querySelector(".av__mask");
|
|
|
|
|
|
if (avMaskElement) {
|
2024-01-04 12:46:57 +08:00
|
|
|
|
(avMaskElement.querySelector("textarea, input") as HTMLTextAreaElement)?.focus();
|
2023-12-14 12:22:18 +08:00
|
|
|
|
} else if (!document.querySelector(".av__panel")) {
|
2023-12-13 16:44:29 +08:00
|
|
|
|
focusBlock(e);
|
2023-11-15 09:07:52 +08:00
|
|
|
|
}
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
// 修改表头后光标重新定位
|
|
|
|
|
|
const range = getSelection().getRangeAt(0);
|
|
|
|
|
|
if (!hasClosestByClassName(range.startContainer, "av__title")) {
|
|
|
|
|
|
const blockElement = hasClosestBlock(range.startContainer);
|
|
|
|
|
|
if (blockElement && e.isSameNode(blockElement)) {
|
2023-11-14 12:58:45 +08:00
|
|
|
|
focusBlock(e);
|
|
|
|
|
|
}
|
2023-10-13 13:37:32 +08:00
|
|
|
|
}
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
e.querySelector(".layout-tab-bar").scrollLeft = (e.querySelector(".layout-tab-bar .item--focus") as HTMLElement).offsetLeft;
|
|
|
|
|
|
if (cb) {
|
|
|
|
|
|
cb();
|
|
|
|
|
|
}
|
2023-06-11 23:17:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-12-11 22:03:27 +08:00
|
|
|
|
const refreshTimeouts: {
|
|
|
|
|
|
[key: string]: number;
|
|
|
|
|
|
} = {};
|
2024-01-08 23:23:59 +08:00
|
|
|
|
export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
2023-10-14 11:00:46 +08:00
|
|
|
|
if (operation.action === "setAttrViewName") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.id}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
const titleElement = item.querySelector(".av__title") as HTMLElement;
|
|
|
|
|
|
if (!titleElement) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
titleElement.textContent = operation.data;
|
|
|
|
|
|
titleElement.dataset.title = operation.data;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2023-12-11 22:05:31 +08:00
|
|
|
|
// 只能 setTimeout,以前方案快速输入后最后一次修改会被忽略;必须为每一个 protyle 单独设置,否则有多个 protyle 时,其余无法被执行
|
2023-12-11 22:03:27 +08:00
|
|
|
|
clearTimeout(refreshTimeouts[protyle.id]);
|
|
|
|
|
|
refreshTimeouts[protyle.id] = window.setTimeout(() => {
|
2023-12-07 21:12:29 +08:00
|
|
|
|
if (operation.action === "setAttrViewColWidth") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
const cellElement = item.querySelector(`.av__cell[data-col-id="${operation.id}"]`) as HTMLElement;
|
|
|
|
|
|
if (!cellElement || cellElement.style.width === operation.data) {
|
|
|
|
|
|
return;
|
2023-11-10 17:44:04 +08:00
|
|
|
|
}
|
2023-12-07 21:12:29 +08:00
|
|
|
|
item.querySelectorAll(".av__row").forEach(rowItem => {
|
|
|
|
|
|
(rowItem.querySelector(`[data-col-id="${operation.id}"]`) as HTMLElement).style.width = operation.data;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.removeAttribute("data-render");
|
|
|
|
|
|
avRender(item, protyle, () => {
|
2024-01-10 11:33:49 +08:00
|
|
|
|
if (operation.action === "addAttrViewCol" && item.querySelector(".av__pulse")) {
|
2023-12-24 12:17:05 +08:00
|
|
|
|
openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id});
|
2023-12-20 23:30:08 +08:00
|
|
|
|
}
|
2023-12-07 21:12:29 +08:00
|
|
|
|
}, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id :
|
|
|
|
|
|
(operation.action === "removeAttrViewView" ? null : undefined));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2023-12-19 08:33:11 +08:00
|
|
|
|
}, ["insertAttrViewBlock", "addAttrViewCol"].includes(operation.action) ? 2 : 100);
|
2023-06-07 11:56:34 +08:00
|
|
|
|
};
|