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-11-20 11:14:39 +08:00
|
|
|
|
import {addDragFill, cellScrollIntoView, 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";
|
2024-11-16 10:19:55 +08:00
|
|
|
|
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
|
2024-05-12 23:49:01 +08:00
|
|
|
|
import {stickyRow, updateHeader} from "./row";
|
2023-11-20 11:19:56 +08:00
|
|
|
|
import {getCalcValue} from "./calc";
|
2024-01-18 22:14:08 +08:00
|
|
|
|
import {renderAVAttribute} from "./blockAttr";
|
2024-03-06 11:00:12 +08:00
|
|
|
|
import {showMessage} from "../../../dialog/message";
|
2024-03-09 11:08:11 +08:00
|
|
|
|
import {addClearButton} from "../../../util/addClearButton";
|
2024-11-18 11:55:18 +08:00
|
|
|
|
import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
|
2024-12-28 00:05:33 +08:00
|
|
|
|
import {electronUndo} from "../../undo";
|
2025-04-13 12:11:18 +08:00
|
|
|
|
import {isInAndroid, isInHarmony, isInIOS} from "../../util/compatibility";
|
|
|
|
|
|
import {isMobile} from "../../../util/functions";
|
2025-06-09 17:56:43 +08:00
|
|
|
|
import {renderGallery} from "./gallery/render";
|
2025-07-26 11:30:57 +08:00
|
|
|
|
import {getFieldsByData, getViewIcon} from "./view";
|
2025-07-11 10:32:30 +08:00
|
|
|
|
import {openMenuPanel} from "./openMenuPanel";
|
2023-06-08 18:21:10 +08:00
|
|
|
|
|
2025-07-26 11:30:57 +08:00
|
|
|
|
export const genTabHeaderHTML = (data: IAV, showSearch: boolean, editable: boolean) => {
|
|
|
|
|
|
let tabHTML = "";
|
|
|
|
|
|
let viewData: IAVView;
|
|
|
|
|
|
let hasFilter = false;
|
|
|
|
|
|
getFieldsByData(data).forEach((item) => {
|
|
|
|
|
|
if (!hasFilter) {
|
|
|
|
|
|
data.view.filters.find(filterItem => {
|
|
|
|
|
|
if (filterItem.value.type === item.type && item.id === filterItem.column) {
|
|
|
|
|
|
hasFilter = true;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
data.views.forEach((item: IAVView) => {
|
|
|
|
|
|
tabHTML += `<div draggable="true" data-position="north" data-av-type="${item.type}" data-id="${item.id}" data-page="${item.pageSize}" data-desc="${escapeAriaLabel(item.desc || "")}" class="ariaLabel item${item.id === data.viewID ? " item--focus" : ""}">
|
|
|
|
|
|
${item.icon ? unicode2Emoji(item.icon, "item__graphic", true) : `<svg class="item__graphic"><use xlink:href="#${getViewIcon(item.type)}"></use></svg>`}
|
|
|
|
|
|
<span class="item__text">${escapeHtml(item.name)}</span>
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
if (item.id === data.viewID) {
|
|
|
|
|
|
viewData = item;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return `<div class="av__header">
|
|
|
|
|
|
<div class="fn__flex av__views${showSearch ? " av__views--show" : ""}">
|
|
|
|
|
|
<div class="layout-tab-bar fn__flex">
|
|
|
|
|
|
${tabHTML}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-add" class="block__icon ariaLabel" data-position="8south" aria-label="${window.siyuan.languages.newView}">
|
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__flex-1"></div>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-switcher" aria-label="${window.siyuan.languages.allViews}" data-position="8south" class="ariaLabel block__icon${data.views.length > 0 ? "" : " fn__none"}">
|
|
|
|
|
|
<svg><use xlink:href="#iconDown"></use></svg>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<small>${data.views.length}</small>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-filter" aria-label="${window.siyuan.languages.filter}" data-position="8south" class="ariaLabel block__icon${hasFilter ? " block__icon--active" : ""}">
|
|
|
|
|
|
<svg><use xlink:href="#iconFilter"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-sort" aria-label="${window.siyuan.languages.sort}" data-position="8south" class="ariaLabel block__icon${data.view.sorts.length > 0 ? " block__icon--active" : ""}">
|
|
|
|
|
|
<svg><use xlink:href="#iconSort"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<button data-type="av-search-icon" aria-label="${window.siyuan.languages.search}" data-position="8south" class="ariaLabel block__icon">
|
|
|
|
|
|
<svg><use xlink:href="#iconSearch"></use></svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<div style="position: relative" class="fn__flex">
|
|
|
|
|
|
<input style="${showSearch ? "width:128px" : "width:0;padding-left: 0;padding-right: 0;"}" data-type="av-search" class="b3-text-field b3-text-field--text" placeholder="${window.siyuan.languages.search}">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-more" aria-label="${window.siyuan.languages.config}" data-position="8south" class="ariaLabel block__icon">
|
|
|
|
|
|
<svg><use xlink:href="#iconSettings"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<span data-type="av-add-more" class="block__icon ariaLabel" data-position="8south" aria-label="${window.siyuan.languages.newRow}">
|
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
${data.isMirror ? ` <span data-av-id="${data.id}" data-popover-url="/api/av/getMirrorDatabaseBlocks" class="popover__block block__icon block__icon--show ariaLabel" data-position="8south" aria-label="${window.siyuan.languages.mirrorTip}">
|
|
|
|
|
|
<svg><use xlink:href="#iconSplitLR"></use></svg></span><div class="fn__space"></div>` : ""}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div contenteditable="${editable}" spellcheck="${window.siyuan.config.editor.spellcheck.toString()}" class="av__title${viewData.hideAttrViewName ? " fn__none" : ""}" data-title="${data.name || ""}" data-tip="${window.siyuan.languages.title}">${data.name || ""}</div>
|
|
|
|
|
|
<div class="av__counter fn__none"></div>
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getTableHTMLs = (data: IAVTable, e: HTMLElement) => {
|
|
|
|
|
|
let calcHTML = "";
|
|
|
|
|
|
let contentHTML = '<div class="av__row av__row--header"><div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (eWidth === 0) {
|
|
|
|
|
|
pinMaxIndex = pinIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
pinIndex = Math.min(pinIndex, pinMaxIndex);
|
|
|
|
|
|
if (pinIndex > -1) {
|
|
|
|
|
|
contentHTML = '<div class="av__row av__row--header"><div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div>';
|
|
|
|
|
|
calcHTML = '<div class="av__colsticky">';
|
|
|
|
|
|
}
|
|
|
|
|
|
let hasCalc = false;
|
|
|
|
|
|
data.columns.forEach((column: IAVColumn, index: number) => {
|
|
|
|
|
|
if (column.hidden) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
contentHTML += `<div class="av__cell av__cell--header" data-col-id="${column.id}" draggable="true"
|
|
|
|
|
|
data-icon="${column.icon}" data-dtype="${column.type}" data-wrap="${column.wrap}" data-pin="${column.pin}"
|
|
|
|
|
|
data-desc="${escapeAttr(column.desc)}" data-position="north"
|
|
|
|
|
|
style="width: ${column.width || "200px"};">
|
|
|
|
|
|
${column.icon ? unicode2Emoji(column.icon, "av__cellheadericon", true) : `<svg class="av__cellheadericon"><use xlink:href="#${getColIconByType(column.type)}"></use></svg>`}
|
|
|
|
|
|
<span class="av__celltext fn__flex-1">${escapeHtml(column.name)}</span>
|
|
|
|
|
|
${column.pin ? '<svg class="av__cellheadericon av__cellheadericon--pin"><use xlink:href="#iconPin"></use></svg>' : ""}
|
|
|
|
|
|
<div class="av__widthdrag"></div>
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
if (pinIndex === index) {
|
|
|
|
|
|
contentHTML += "</div>";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (column.type === "lineNumber") {
|
|
|
|
|
|
// lineNumber type 不参与计算操作
|
|
|
|
|
|
calcHTML += `<div data-col-id="${column.id}" data-dtype="${column.type}" class="av__calc" style="width: ${column.width || "200px"}"> </div>`;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
calcHTML += `<div class="av__calc${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><small>${window.siyuan.languages.calc}</small>`}</div>`;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (column.calc && column.calc.operator !== "") {
|
|
|
|
|
|
hasCalc = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pinIndex === index) {
|
|
|
|
|
|
calcHTML += "</div>";
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
contentHTML += `<div class="block__icons" style="min-height: auto">
|
|
|
|
|
|
<div class="block__icon block__icon--show" data-type="av-header-more"><svg><use xlink:href="#iconMore"></use></svg></div>
|
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
|
<div class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.newCol}" data-type="av-header-add" data-position="4south"><svg><use xlink:href="#iconAdd"></use></svg></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
// body
|
|
|
|
|
|
data.rows.forEach((row: IAVRow, rowIndex: number) => {
|
|
|
|
|
|
contentHTML += `<div class="av__row" data-id="${row.id}">`;
|
|
|
|
|
|
if (pinIndex > -1) {
|
|
|
|
|
|
contentHTML += '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div>';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
contentHTML += '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
row.cells.forEach((cell, index) => {
|
|
|
|
|
|
if (data.columns[index].hidden) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/10262
|
|
|
|
|
|
let checkClass = "";
|
|
|
|
|
|
if (cell.valueType === "checkbox") {
|
|
|
|
|
|
checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";
|
|
|
|
|
|
}
|
|
|
|
|
|
contentHTML += `<div class="av__cell${checkClass}" data-id="${cell.id}" data-col-id="${data.columns[index].id}"
|
|
|
|
|
|
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""} data-wrap="${data.columns[index].wrap}"
|
|
|
|
|
|
data-dtype="${data.columns[index].type}"
|
|
|
|
|
|
${cell.value?.isDetached ? ' data-detached="true"' : ""}
|
|
|
|
|
|
style="width: ${data.columns[index].width || "200px"};
|
|
|
|
|
|
${cell.valueType === "number" ? "text-align: right;" : ""}
|
|
|
|
|
|
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
|
|
|
|
|
|
${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex, data.showIcon)}</div>`;
|
|
|
|
|
|
|
|
|
|
|
|
if (pinIndex === index) {
|
|
|
|
|
|
contentHTML += "</div>";
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
contentHTML += "<div></div></div>";
|
|
|
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
|
|
|
contentHTML,
|
|
|
|
|
|
footerHTML: `<div class="av__row--footer${hasCalc ? " av__readonly--show" : ""}">${calcHTML}</div>`
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const renderGroupTable = (options: {
|
|
|
|
|
|
blockElement: HTMLElement,
|
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
|
cb?: (data: IAV) => void,
|
|
|
|
|
|
renderAll: boolean
|
|
|
|
|
|
data: IAV
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
const searchInputElement = options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement;
|
|
|
|
|
|
const isSearching = searchInputElement && document.activeElement === searchInputElement;
|
|
|
|
|
|
const query = searchInputElement?.value || "";
|
|
|
|
|
|
|
|
|
|
|
|
let avBodyHTML = "";
|
|
|
|
|
|
options.data.view.groups.forEach((group: IAVTable) => {
|
|
|
|
|
|
if (group.groupHidden === 0) {
|
|
|
|
|
|
group.columns = (options.data.view as IAVTable).columns;
|
|
|
|
|
|
avBodyHTML += `<div>${group.name}</div>${getTableHTMLs(group, options.blockElement).contentHTML}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (options.renderAll) {
|
|
|
|
|
|
options.blockElement.firstElementChild.outerHTML = `<div class="av__container">
|
|
|
|
|
|
${genTabHeaderHTML(options.data, isSearching || !!query, options.protyle.disabled || !!hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}
|
|
|
|
|
|
<div class="av__scroll">
|
|
|
|
|
|
${avBodyHTML}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="av__cursor" contenteditable="true">${Constants.ZWSP}</div>
|
|
|
|
|
|
</div>`;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
options.blockElement.firstElementChild.querySelector(".av__scroll").innerHTML = avBodyHTML;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-16 23:32:48 +08:00
|
|
|
|
export const avRender = (element: Element, protyle: IProtyle, cb?: (data: IAV) => void, renderAll = true) => {
|
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) => {
|
2025-06-25 18:03:11 +08:00
|
|
|
|
if (e.getAttribute("data-render") === "true" || hasClosestByClassName(e, "av__gallery-content")) {
|
2023-06-07 11:55:45 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-13 12:11:18 +08:00
|
|
|
|
if (isMobile() || isInIOS() || isInAndroid() || isInHarmony()) {
|
|
|
|
|
|
e.classList.add("av--touch");
|
|
|
|
|
|
}
|
2025-06-09 12:23:44 +08:00
|
|
|
|
|
2025-06-09 17:56:43 +08:00
|
|
|
|
if (e.getAttribute("data-av-type") === "gallery") {
|
2025-06-16 23:32:48 +08:00
|
|
|
|
renderGallery({blockElement: e, protyle, cb, renderAll});
|
2025-06-09 17:56:43 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-06-09 12:23:44 +08:00
|
|
|
|
|
2024-03-08 16:06:19 +08:00
|
|
|
|
const alignSelf = e.style.alignSelf;
|
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;
|
2024-05-11 17:53:15 +08:00
|
|
|
|
const selectRowIds: string[] = [];
|
|
|
|
|
|
e.querySelectorAll(".av__row--select").forEach(rowItem => {
|
|
|
|
|
|
const rowId = rowItem.getAttribute("data-id");
|
|
|
|
|
|
if (rowId) {
|
|
|
|
|
|
selectRowIds.push(rowId);
|
|
|
|
|
|
}
|
2024-05-12 12:36:30 +08:00
|
|
|
|
});
|
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
|
|
|
|
}
|
2024-03-22 16:58:25 +08:00
|
|
|
|
let dragFillId = "";
|
2024-03-22 11:08:21 +08:00
|
|
|
|
const dragFillElement = e.querySelector(".av__drag-fill") as HTMLElement;
|
|
|
|
|
|
if (dragFillElement) {
|
|
|
|
|
|
dragFillId = (hasClosestByClassName(dragFillElement, "av__row") as HTMLElement).dataset.id + Constants.ZWSP + dragFillElement.parentElement.getAttribute("data-col-id");
|
|
|
|
|
|
}
|
|
|
|
|
|
const activeIds: string[] = [];
|
|
|
|
|
|
e.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
|
|
|
|
|
activeIds.push((hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id + Constants.ZWSP + item.getAttribute("data-col-id"));
|
2024-03-22 16:58:25 +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;
|
2024-03-09 11:32:26 +08:00
|
|
|
|
let searchInputElement = e.querySelector('[data-type="av-search"]') as HTMLInputElement;
|
2025-07-23 13:08:38 +08:00
|
|
|
|
const isSearching = searchInputElement && document.activeElement === searchInputElement;
|
2024-03-09 11:32:26 +08:00
|
|
|
|
const query = searchInputElement?.value || "";
|
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,
|
2025-06-16 23:32:48 +08:00
|
|
|
|
viewID: e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "",
|
2025-07-15 17:24:58 +08:00
|
|
|
|
query: query.trim(),
|
|
|
|
|
|
blockID: e.getAttribute("data-node-id"),
|
2023-07-31 23:58:45 +08:00
|
|
|
|
}, (response) => {
|
2023-07-11 21:34:22 +08:00
|
|
|
|
const data = response.data.view as IAVTable;
|
2025-06-24 10:02:48 +08:00
|
|
|
|
if (response.data.viewType === "gallery") {
|
|
|
|
|
|
e.setAttribute("data-av-type", "table");
|
|
|
|
|
|
renderGallery({blockElement: e, protyle, cb, renderAll});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-07-26 11:30:57 +08:00
|
|
|
|
if (data.groups?.length > 0) {
|
|
|
|
|
|
renderGroupTable({blockElement: e, protyle, cb, renderAll, data: response.data});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-12-08 22:25:42 +08:00
|
|
|
|
if (!e.dataset.pageSize) {
|
|
|
|
|
|
e.dataset.pageSize = data.pageSize.toString();
|
|
|
|
|
|
}
|
2025-07-26 11:30:57 +08:00
|
|
|
|
const tableHTMLs = getTableHTMLs(data, e);
|
2024-12-28 00:05:33 +08:00
|
|
|
|
const avBodyHTML = `<div class="av__body">
|
2025-07-26 11:30:57 +08:00
|
|
|
|
${tableHTMLs.contentHTML}
|
2024-12-28 00:05:33 +08:00
|
|
|
|
<div class="av__row--util${data.rowCount > data.rows.length ? " av__readonly--show" : ""}">
|
|
|
|
|
|
<div class="av__colsticky">
|
2025-06-12 22:23:52 +08:00
|
|
|
|
<button class="b3-button av__button" data-type="av-add-bottom">
|
2024-12-28 00:05:33 +08:00
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
|
<span>${window.siyuan.languages.newRow}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<span class="fn__space"></span>
|
2025-06-12 22:23:52 +08:00
|
|
|
|
<button class="b3-button av__button${data.rowCount > data.rows.length ? "" : " fn__none"}" data-type="av-load-more">
|
2024-12-28 00:05:33 +08:00
|
|
|
|
<svg><use xlink:href="#iconArrowDown"></use></svg>
|
|
|
|
|
|
<span>${window.siyuan.languages.loadMore}</span>
|
|
|
|
|
|
<svg data-type="set-page-size" data-size="${data.pageSize}"><use xlink:href="#iconMore"></use></svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-26 11:30:57 +08:00
|
|
|
|
${tableHTMLs.footerHTML}
|
2024-12-30 10:17:32 +08:00
|
|
|
|
</div>`;
|
2024-12-28 00:05:33 +08:00
|
|
|
|
if (renderAll) {
|
|
|
|
|
|
e.firstElementChild.outerHTML = `<div class="av__container">
|
2025-07-26 11:30:57 +08:00
|
|
|
|
${genTabHeaderHTML(response.data, isSearching || !!query, protyle.disabled || !!hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed"))}
|
2023-06-08 10:07:26 +08:00
|
|
|
|
<div class="av__scroll">
|
2024-12-28 00:05:33 +08:00
|
|
|
|
${avBodyHTML}
|
2023-06-08 10:07:26 +08:00
|
|
|
|
</div>
|
2024-04-12 23:44:53 +08:00
|
|
|
|
<div class="av__cursor" contenteditable="true">${Constants.ZWSP}</div>
|
2023-06-08 10:07:26 +08:00
|
|
|
|
</div>`;
|
2024-12-28 00:05:33 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
e.firstElementChild.querySelector(".av__scroll").innerHTML = avBodyHTML;
|
|
|
|
|
|
}
|
2023-12-13 16:44:29 +08:00
|
|
|
|
e.setAttribute("data-render", "true");
|
|
|
|
|
|
// 历史兼容
|
|
|
|
|
|
e.style.margin = "";
|
|
|
|
|
|
if (left) {
|
|
|
|
|
|
e.querySelector(".av__scroll").scrollLeft = left;
|
|
|
|
|
|
}
|
2024-03-08 16:06:19 +08:00
|
|
|
|
if (alignSelf) {
|
|
|
|
|
|
e.style.alignSelf = alignSelf;
|
|
|
|
|
|
}
|
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 {
|
2025-01-11 23:20:55 +08:00
|
|
|
|
// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
stickyRow(e, editRect, "top");
|
2025-01-16 10:00:30 +08:00
|
|
|
|
}, Constants.TIMEOUT_LOAD);
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (footerTransform) {
|
|
|
|
|
|
(e.querySelector(".av__row--footer") as HTMLElement).style.transform = footerTransform;
|
|
|
|
|
|
} else {
|
2025-01-11 23:20:55 +08:00
|
|
|
|
// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
stickyRow(e, editRect, "bottom");
|
|
|
|
|
|
}, Constants.TIMEOUT_LOAD);
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
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");
|
2025-07-01 23:25:50 +08:00
|
|
|
|
cellScrollIntoView(e, newCellElement);
|
2023-11-15 09:07:52 +08:00
|
|
|
|
}
|
2023-12-14 12:22:18 +08:00
|
|
|
|
const avMaskElement = document.querySelector(".av__mask");
|
2025-07-01 23:25:50 +08:00
|
|
|
|
const avPanelElement = document.querySelector(".av__panel");
|
2023-12-14 12:22:18 +08:00
|
|
|
|
if (avMaskElement) {
|
2024-01-04 12:46:57 +08:00
|
|
|
|
(avMaskElement.querySelector("textarea, input") as HTMLTextAreaElement)?.focus();
|
2025-07-01 23:25:50 +08:00
|
|
|
|
} else if (!avPanelElement && !isSearching && getSelection().rangeCount > 0) {
|
2025-04-15 18:32:49 +08:00
|
|
|
|
const range = getSelection().getRangeAt(0);
|
|
|
|
|
|
const blockElement = hasClosestBlock(range.startContainer);
|
2025-07-23 13:08:38 +08:00
|
|
|
|
if (blockElement && e === blockElement) {
|
2025-04-15 18:32:49 +08:00
|
|
|
|
focusBlock(e);
|
|
|
|
|
|
}
|
2025-07-01 23:25:50 +08:00
|
|
|
|
} else if (avPanelElement && !newCellElement) {
|
|
|
|
|
|
avPanelElement.remove();
|
2023-11-15 09:07:52 +08:00
|
|
|
|
}
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
2024-05-12 23:49:01 +08:00
|
|
|
|
selectRowIds.forEach((selectRowId, index) => {
|
|
|
|
|
|
const rowElement = e.querySelector(`.av__row[data-id="${selectRowId}"]`) as HTMLElement;
|
|
|
|
|
|
if (rowElement) {
|
|
|
|
|
|
rowElement.classList.add("av__row--select");
|
|
|
|
|
|
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (index === selectRowIds.length - 1 && rowElement) {
|
|
|
|
|
|
updateHeader(rowElement);
|
|
|
|
|
|
}
|
2024-05-11 17:53:15 +08:00
|
|
|
|
});
|
2024-05-12 23:49:01 +08:00
|
|
|
|
|
2024-03-22 11:08:21 +08:00
|
|
|
|
if (dragFillId) {
|
2024-03-22 16:58:25 +08:00
|
|
|
|
addDragFill(e.querySelector(`.av__row[data-id="${dragFillId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${dragFillId.split(Constants.ZWSP)[1]}"]`));
|
2024-03-22 11:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
activeIds.forEach(activeId => {
|
2024-03-22 16:58:25 +08:00
|
|
|
|
e.querySelector(`.av__row[data-id="${activeId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${activeId.split(Constants.ZWSP)[1]}"]`)?.classList.add("av__cell--active");
|
|
|
|
|
|
});
|
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);
|
2025-07-23 13:08:38 +08:00
|
|
|
|
if (blockElement && e === blockElement && !isSearching) {
|
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
|
|
|
|
}
|
2025-07-09 10:28:11 +08:00
|
|
|
|
e.querySelector(".layout-tab-bar").scrollLeft = (e.querySelector(".layout-tab-bar .item--focus") as HTMLElement).offsetLeft - 30;
|
2023-12-13 16:44:29 +08:00
|
|
|
|
if (cb) {
|
2025-06-11 11:18:23 +08:00
|
|
|
|
cb(response.data);
|
2023-12-13 16:44:29 +08:00
|
|
|
|
}
|
2024-12-28 00:05:33 +08:00
|
|
|
|
if (!renderAll) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-09 11:08:11 +08:00
|
|
|
|
const viewsElement = e.querySelector(".av__views") as HTMLElement;
|
2024-03-09 11:32:26 +08:00
|
|
|
|
searchInputElement = e.querySelector('[data-type="av-search"]') as HTMLInputElement;
|
2024-08-07 22:34:56 +08:00
|
|
|
|
searchInputElement.value = query || "";
|
2024-03-09 11:32:26 +08:00
|
|
|
|
if (isSearching) {
|
|
|
|
|
|
searchInputElement.focus();
|
|
|
|
|
|
}
|
2024-12-13 11:09:03 +08:00
|
|
|
|
searchInputElement.addEventListener("compositionstart", (event: KeyboardEvent) => {
|
|
|
|
|
|
event.stopPropagation();
|
2024-12-13 21:56:06 +08:00
|
|
|
|
});
|
2024-12-28 00:05:33 +08:00
|
|
|
|
searchInputElement.addEventListener("keydown", (event: KeyboardEvent) => {
|
|
|
|
|
|
if (event.isComposing) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
electronUndo(event);
|
|
|
|
|
|
});
|
2024-03-09 11:08:11 +08:00
|
|
|
|
searchInputElement.addEventListener("input", (event: KeyboardEvent) => {
|
2024-12-13 11:09:03 +08:00
|
|
|
|
event.stopPropagation();
|
2024-03-09 11:08:11 +08:00
|
|
|
|
if (event.isComposing) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-07-23 13:08:38 +08:00
|
|
|
|
if (searchInputElement.value || document.activeElement === searchInputElement) {
|
2024-03-09 11:08:11 +08:00
|
|
|
|
viewsElement.classList.add("av__views--show");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
viewsElement.classList.remove("av__views--show");
|
|
|
|
|
|
}
|
2024-03-10 11:56:09 +08:00
|
|
|
|
updateSearch(e, protyle);
|
2024-03-09 11:08:11 +08:00
|
|
|
|
});
|
2024-03-10 11:13:15 +08:00
|
|
|
|
searchInputElement.addEventListener("compositionend", () => {
|
2024-03-10 11:56:09 +08:00
|
|
|
|
updateSearch(e, protyle);
|
2024-03-09 11:08:11 +08:00
|
|
|
|
});
|
|
|
|
|
|
searchInputElement.addEventListener("blur", (event: KeyboardEvent) => {
|
|
|
|
|
|
if (event.isComposing) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!searchInputElement.value) {
|
|
|
|
|
|
viewsElement.classList.remove("av__views--show");
|
|
|
|
|
|
searchInputElement.style.width = "0";
|
|
|
|
|
|
searchInputElement.style.paddingLeft = "0";
|
|
|
|
|
|
searchInputElement.style.paddingRight = "0";
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
addClearButton({
|
|
|
|
|
|
inputElement: searchInputElement,
|
|
|
|
|
|
right: 0,
|
2024-05-04 14:45:21 +08:00
|
|
|
|
width: "1em",
|
2024-03-09 11:08:11 +08:00
|
|
|
|
height: searchInputElement.clientHeight,
|
|
|
|
|
|
clearCB() {
|
|
|
|
|
|
viewsElement.classList.remove("av__views--show");
|
|
|
|
|
|
searchInputElement.style.width = "0";
|
|
|
|
|
|
searchInputElement.style.paddingLeft = "0";
|
|
|
|
|
|
searchInputElement.style.paddingRight = "0";
|
2024-03-10 11:27:51 +08:00
|
|
|
|
focusBlock(e);
|
|
|
|
|
|
updateSearch(e, protyle);
|
2024-03-09 11:08:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-06-11 23:17:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-03-10 11:56:09 +08:00
|
|
|
|
let searchTimeout: number;
|
2024-03-10 11:13:15 +08:00
|
|
|
|
|
2025-06-09 17:56:43 +08:00
|
|
|
|
export const updateSearch = (e: HTMLElement, protyle: IProtyle) => {
|
2024-03-10 11:56:09 +08:00
|
|
|
|
clearTimeout(searchTimeout);
|
2024-03-10 11:13:15 +08:00
|
|
|
|
searchTimeout = window.setTimeout(() => {
|
|
|
|
|
|
e.removeAttribute("data-render");
|
2025-06-16 23:32:48 +08:00
|
|
|
|
avRender(e, protyle, undefined, false);
|
2024-03-10 11:13:15 +08:00
|
|
|
|
}, Constants.TIMEOUT_INPUT);
|
2024-03-10 11:56:09 +08:00
|
|
|
|
};
|
2024-03-10 11:13:15 +08:00
|
|
|
|
|
2023-12-11 22:03:27 +08:00
|
|
|
|
const refreshTimeouts: {
|
|
|
|
|
|
[key: string]: number;
|
|
|
|
|
|
} = {};
|
2025-07-26 11:30:57 +08:00
|
|
|
|
|
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;
|
2025-06-17 11:25:30 +08:00
|
|
|
|
if (!cellElement || cellElement.style.width === operation.data || item.getAttribute(Constants.CUSTOM_SY_AV_VIEW) !== operation.keyID) {
|
2023-12-07 21:12:29 +08:00
|
|
|
|
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;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-06-26 22:26:55 +08:00
|
|
|
|
} else if (operation.action === "setAttrViewCardSize") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
const galleryElement = item.querySelector(".av__gallery") as HTMLElement;
|
|
|
|
|
|
if (galleryElement) {
|
|
|
|
|
|
galleryElement.classList.remove("av__gallery--small", "av__gallery--big");
|
|
|
|
|
|
if (operation.data === 0) {
|
|
|
|
|
|
galleryElement.classList.add("av__gallery--small");
|
|
|
|
|
|
} else if (operation.data === 2) {
|
|
|
|
|
|
galleryElement.classList.add("av__gallery--big");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (operation.action === "setAttrViewCardAspectRatio") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.querySelectorAll(".av__gallery-cover").forEach(coverItem => {
|
|
|
|
|
|
coverItem.className = "av__gallery-cover av__gallery-cover--" + operation.data;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-06-27 10:21:16 +08:00
|
|
|
|
} else if (operation.action === "hideAttrViewName") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
2025-06-28 10:55:44 +08:00
|
|
|
|
const titleElement = item.querySelector(".av__title");
|
|
|
|
|
|
if (titleElement) {
|
2025-06-27 10:21:16 +08:00
|
|
|
|
if (!operation.data) {
|
2025-06-28 10:55:44 +08:00
|
|
|
|
titleElement.classList.remove("fn__none");
|
2025-06-27 10:21:16 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
// hide
|
2025-06-28 10:55:44 +08:00
|
|
|
|
titleElement.classList.add("fn__none");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.getAttribute("data-av-type") === "gallery") {
|
|
|
|
|
|
const galleryElement = item.querySelector(".av__gallery");
|
|
|
|
|
|
if (!operation.data) {
|
|
|
|
|
|
galleryElement.classList.remove("av__gallery--top");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// hide
|
|
|
|
|
|
galleryElement.classList.add("av__gallery--top");
|
|
|
|
|
|
}
|
2025-06-27 10:21:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-06-30 15:46:22 +08:00
|
|
|
|
} else if (operation.action === "setAttrViewWrapField") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.querySelectorAll(".av__cell").forEach(fieldItem => {
|
|
|
|
|
|
fieldItem.setAttribute("data-wrap", operation.data.toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (operation.action === "setAttrViewShowIcon") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
2025-07-01 11:30:50 +08:00
|
|
|
|
item.querySelectorAll('.av__cell[data-dtype="block"] .b3-menu__avemoji, .av__cell[data-dtype="relation"] .b3-menu__avemoji').forEach(cellItem => {
|
2025-06-30 15:46:22 +08:00
|
|
|
|
if (operation.data) {
|
2025-07-01 11:30:50 +08:00
|
|
|
|
cellItem.classList.remove("fn__none");
|
2025-06-30 15:46:22 +08:00
|
|
|
|
} else {
|
2025-07-01 11:30:50 +08:00
|
|
|
|
cellItem.classList.add("fn__none");
|
2025-06-30 15:46:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-07-01 11:30:50 +08:00
|
|
|
|
} else if (operation.action === "setAttrViewColWrap") {
|
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.querySelectorAll(`.av__cell[data-col-id="${operation.id}"],.av__cell[data-field-id="${operation.id}"]`).forEach(cellItem => {
|
2025-07-01 16:53:21 +08:00
|
|
|
|
cellItem.setAttribute("data-wrap", operation.data.toString());
|
2025-07-01 11:30:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2023-12-07 21:12:29 +08:00
|
|
|
|
} else {
|
2024-10-14 11:23:10 +08:00
|
|
|
|
// 修改表格名 avID 传入到 id 上了 https://github.com/siyuan-note/siyuan/issues/12724
|
2024-10-15 10:28:30 +08:00
|
|
|
|
const avID = operation.action === "setAttrViewName" ? operation.id : operation.avID;
|
2024-10-14 11:23:10 +08:00
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avID}"]`)).forEach((item: HTMLElement) => {
|
2023-12-07 21:12:29 +08:00
|
|
|
|
item.removeAttribute("data-render");
|
2025-06-14 14:03:35 +08:00
|
|
|
|
const updateRow = item.querySelector('[data-need-update="true"]');
|
2024-03-22 11:49:32 +08:00
|
|
|
|
if (operation.action === "sortAttrViewCol" || operation.action === "sortAttrViewRow") {
|
|
|
|
|
|
item.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.classList.remove("av__cell--active");
|
|
|
|
|
|
item.querySelector(".av__drag-fill")?.remove();
|
|
|
|
|
|
});
|
|
|
|
|
|
addDragFill(item.querySelector(".av__cell--select"));
|
2025-07-10 09:47:20 +08:00
|
|
|
|
} else if (operation.action === "setAttrViewBlockView") {
|
2025-06-16 23:32:48 +08:00
|
|
|
|
const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement;
|
|
|
|
|
|
if (viewTabElement) {
|
|
|
|
|
|
item.dataset.pageSize = viewTabElement.dataset.page;
|
2025-06-11 11:18:23 +08:00
|
|
|
|
}
|
2025-07-10 09:47:20 +08:00
|
|
|
|
} else if (operation.action === "addAttrViewView") {
|
2025-07-03 18:45:01 +08:00
|
|
|
|
item.dataset.pageSize = "50";
|
2025-07-10 09:47:20 +08:00
|
|
|
|
} else if (operation.action === "removeAttrViewView") {
|
2025-07-08 11:41:21 +08:00
|
|
|
|
item.dataset.pageSize = item.querySelector(`.av__views > .layout-tab-bar .item[data-id="${item.getAttribute(Constants.CUSTOM_SY_AV_VIEW)}"]`)?.getAttribute("data-page");
|
2025-07-10 09:47:20 +08:00
|
|
|
|
} else if (operation.action === "sortAttrViewView" && operation.data === "unRefresh") {
|
|
|
|
|
|
const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement;
|
|
|
|
|
|
if (viewTabElement && !operation.previousID && !viewTabElement.previousElementSibling) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else if (viewTabElement && operation.previousID && viewTabElement.previousElementSibling?.getAttribute("data-id") === operation.previousID) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-07-08 11:41:21 +08:00
|
|
|
|
}
|
2025-06-16 23:32:48 +08:00
|
|
|
|
avRender(item, protyle, () => {
|
2024-10-14 11:23:10 +08:00
|
|
|
|
const attrElement = document.querySelector(`.b3-dialog--open[data-key="${Constants.DIALOG_ATTR}"] div[data-av-id="${avID}"]`) as HTMLElement;
|
2024-01-21 12:21:31 +08:00
|
|
|
|
if (attrElement) {
|
|
|
|
|
|
// 更新属性面板
|
2024-02-26 23:39:10 +08:00
|
|
|
|
renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle);
|
2024-03-06 11:00:12 +08:00
|
|
|
|
} else {
|
2025-06-21 11:20:21 +08:00
|
|
|
|
if (operation.action === "insertAttrViewBlock") {
|
|
|
|
|
|
if (updateRow && !item.querySelector(`[data-id="${updateRow.getAttribute("data-id")}"]`)) {
|
|
|
|
|
|
showMessage(window.siyuan.languages.insertRowTip);
|
|
|
|
|
|
document.querySelector(".av__mask")?.remove();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.getAttribute("data-av-type") === "gallery") {
|
2025-07-08 15:40:12 +08:00
|
|
|
|
operation.srcs.forEach(srcItem => {
|
|
|
|
|
|
const filesElement = item.querySelector(`.av__gallery-item[data-id="${srcItem.id}"]`)?.querySelector(".av__gallery-fields");
|
|
|
|
|
|
if (filesElement && filesElement.querySelector('[data-dtype="block"]')?.getAttribute("data-empty") === "true") {
|
|
|
|
|
|
filesElement.classList.add("av__gallery-fields--edit");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-06-21 11:20:21 +08:00
|
|
|
|
}
|
2025-07-11 10:32:30 +08:00
|
|
|
|
} else if (operation.action === "addAttrViewView") {
|
2025-07-14 19:44:34 +08:00
|
|
|
|
if (item.getAttribute("data-node-id") === operation.blockID) {
|
|
|
|
|
|
openMenuPanel({protyle, blockElement: item, type: "config"});
|
|
|
|
|
|
}
|
2024-03-06 11:00:12 +08:00
|
|
|
|
}
|
2024-01-18 22:14:08 +08:00
|
|
|
|
}
|
2024-03-07 11:51:15 +08:00
|
|
|
|
item.removeAttribute("data-loading");
|
2024-03-04 16:07:16 +08:00
|
|
|
|
});
|
2023-12-07 21:12:29 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-02-26 23:39:10 +08:00
|
|
|
|
}, ["insertAttrViewBlock"].includes(operation.action) ? 2 : 100);
|
2023-06-07 11:56:34 +08:00
|
|
|
|
};
|