import {fetchPost} from "../../../util/fetch"; import {getColIconByType} from "./col"; import {Constants} from "../../../constants"; import {addDragFill, cellScrollIntoView, popTextCell, renderCell} from "./cell"; import {unicode2Emoji} from "../../../emoji"; import {focusBlock} from "../../util/selection"; import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest"; import {stickyRow, updateHeader} from "./row"; import {getCalcValue} from "./calc"; import {renderAVAttribute} from "./blockAttr"; import {addClearButton} from "../../../util/addClearButton"; import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape"; import {electronUndo} from "../../undo"; import {isInAndroid, isInHarmony, isInIOS} from "../../util/compatibility"; import {isMobile} from "../../../util/functions"; import {renderGallery} from "./gallery/render"; import {getFieldsByData, getViewIcon} from "./view"; import {openMenuPanel} from "./openMenuPanel"; import {getPageSize} from "./groups"; import {clearSelect} from "../../util/clearSelect"; import {showMessage} from "../../../dialog/message"; interface IIds { groupId: string, rowId: string, colId?: string } interface ITableOptions { protyle: IProtyle, blockElement: HTMLElement, cb: (data: IAV) => void, data: IAV, renderAll: boolean, resetData: { left: number, alignSelf: string, headerTransform: string, footerTransform: string, isSearching: boolean, selectCellId: IIds, selectRowIds: IIds[], dragFillId: IIds, activeIds: IIds[], query: string, pageSizes: { [key: string]: string }, } } 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 += `
${item.icon ? unicode2Emoji(item.icon, "item__graphic", true) : ``} ${escapeHtml(item.name)}
`; if (item.id === data.viewID) { viewData = item; } }); return `
${tabHTML}
${data.views.length}
${data.isMirror ? `
` : ""}
${data.name || ""}
`; }; const getTableHTMLs = (data: IAVTable, e: HTMLElement) => { let calcHTML = ""; let contentHTML = '
'; 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 = '
'; calcHTML = '
'; } let hasCalc = false; data.columns.forEach((column: IAVColumn, index: number) => { if (column.hidden) { return; } contentHTML += `
${column.icon ? unicode2Emoji(column.icon, "av__cellheadericon", true) : ``} ${escapeHtml(column.name)} ${column.pin ? '' : ""}
`; if (pinIndex === index) { contentHTML += "
"; } if (column.type === "lineNumber") { // lineNumber type 不参与计算操作 calcHTML += `
 
`; } else { calcHTML += `
${getCalcValue(column) || `${window.siyuan.languages.calc}`}
`; } if (column.calc && column.calc.operator !== "") { hasCalc = true; } if (pinIndex === index) { calcHTML += "
"; } }); contentHTML += `
`; // body data.rows.forEach((row: IAVRow, rowIndex: number) => { contentHTML += `
`; if (pinIndex > -1) { contentHTML += '
'; } else { contentHTML += '
'; } 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 += `
${renderCell(cell.value, rowIndex, data.showIcon)}
`; if (pinIndex === index) { contentHTML += "
"; } }); contentHTML += "
"; }); return `${contentHTML}
${calcHTML}
`; }; export const getGroupTitleHTML = (group: IAVView, counter: number) => { let nameHTML = ""; if (["mSelect", "select"].includes(group.groupValue.type)) { group.groupValue.mSelect.forEach((item) => { nameHTML += `${escapeHtml(item.content)}`; }); } else { nameHTML = group.name; } return `
${nameHTML} ${counter === 0 ? '' : `${counter}`}
`; }; const renderGroupTable = (options: ITableOptions) => { 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) { avBodyHTML += `${getGroupTitleHTML(group, group.rows.length)}
${getTableHTMLs(group, options.blockElement)}
`; } }); if (options.renderAll) { options.blockElement.firstElementChild.outerHTML = `
${genTabHeaderHTML(options.data, isSearching || !!query, !options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}
${avBodyHTML}
${Constants.ZWSP}
`; } else { options.blockElement.firstElementChild.querySelector(".av__scroll").innerHTML = avBodyHTML; } afterRenderTable(options); }; const afterRenderTable = (options: ITableOptions) => { options.blockElement.setAttribute("data-render", "true"); options.blockElement.querySelector(".av__scroll").scrollLeft = options.resetData.left; options.blockElement.style.alignSelf = options.resetData.alignSelf; const editRect = options.protyle.contentElement.getBoundingClientRect(); if (options.resetData.headerTransform) { const headerTransformElement = options.blockElement.querySelector('.av__row--header[style^="transform"]') as HTMLElement; if (headerTransformElement) { headerTransformElement.style.transform = options.resetData.headerTransform; } } else { // 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787 setTimeout(() => { stickyRow(options.blockElement, editRect, "top"); }, Constants.TIMEOUT_LOAD); } if (options.resetData.footerTransform) { const footerTransformElement = options.blockElement.querySelector('.av__row--footer[style^="transform"]') as HTMLElement; if (footerTransformElement) { footerTransformElement.style.transform = options.resetData.footerTransform; } } else { // 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787 setTimeout(() => { stickyRow(options.blockElement, editRect, "bottom"); }, Constants.TIMEOUT_LOAD); } if (options.resetData.selectCellId) { let newCellElement = options.blockElement.querySelector(`.av__body[data-group-id="${options.resetData.selectCellId.groupId}"] .av__row[data-id="${options.resetData.selectCellId.rowId}"] .av__cell[data-col-id="${options.resetData.selectCellId.colId}"]`); if (!newCellElement) { newCellElement = options.blockElement.querySelector(`.av__row[data-id="${options.resetData.selectCellId.rowId}"] .av__cell[data-col-id="${options.resetData.selectCellId.colId}"]`); } if (newCellElement) { newCellElement.classList.add("av__cell--select"); cellScrollIntoView(options.blockElement, newCellElement); } const avMaskElement = document.querySelector(".av__mask"); const avPanelElement = document.querySelector(".av__panel"); if (avMaskElement) { (avMaskElement.querySelector("textarea, input") as HTMLTextAreaElement)?.focus(); } else if (!avPanelElement && !options.resetData.isSearching && getSelection().rangeCount > 0) { const range = getSelection().getRangeAt(0); const blockElement = hasClosestBlock(range.startContainer); if (blockElement && options.blockElement === blockElement) { focusBlock(options.blockElement); } } else if (avPanelElement && !newCellElement) { avPanelElement.remove(); } } options.resetData.selectRowIds.forEach((selectRowId, index) => { let rowElement = options.blockElement.querySelector(`.av__body[data-group-id="${selectRowId.groupId}"] .av__row[data-id="${selectRowId.rowId}"]`) as HTMLElement; if (!rowElement) { rowElement = options.blockElement.querySelector(`.av__row[data-id="${selectRowId.rowId}"]`) as HTMLElement; } if (rowElement) { rowElement.classList.add("av__row--select"); rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck"); } if (index === options.resetData.selectRowIds.length - 1 && rowElement) { updateHeader(rowElement); } }); Object.keys(options.resetData.pageSizes).forEach((groupId) => { if (groupId === "unGroup") { (options.blockElement.querySelector(".av__body") as HTMLElement).dataset.pageSize = options.resetData.pageSizes[groupId]; return; } const bodyElement = options.blockElement.querySelector(`.av__body[data-group-id="${groupId}"]`) as HTMLElement; if (bodyElement) { bodyElement.dataset.pageSize = options.resetData.pageSizes[groupId]; } }); if (options.resetData.dragFillId) { let dragCellElement = options.blockElement.querySelector(`.av__body[data-group-id="${options.resetData.dragFillId.groupId}"] .av__row[data-id="${options.resetData.dragFillId.rowId}"] .av__cell[data-col-id="${options.resetData.dragFillId.colId}"]`); if (!dragCellElement) { dragCellElement = options.blockElement.querySelector(`.av__row[data-id="${options.resetData.dragFillId.rowId}"] .av__cell[data-col-id="${options.resetData.dragFillId.colId}"]`); } addDragFill(dragCellElement); } options.resetData.activeIds.forEach(activeId => { let activeCellElement = options.blockElement.querySelector(`.av__body[data-group-id="${activeId.groupId}"] .av__row[data-id="${activeId.rowId}"] .av__cell[data-col-id="${activeId.colId}"]`); if (!activeCellElement) { activeCellElement = options.blockElement.querySelector(`.av__row[data-id="${activeId.rowId}"] .av__cell[data-col-id="${activeId.colId}"]`); } activeCellElement?.classList.add("av__cell--active"); }); if (getSelection().rangeCount > 0) { // 修改表头后光标重新定位 const range = getSelection().getRangeAt(0); if (!hasClosestByClassName(range.startContainer, "av__title")) { const blockElement = hasClosestBlock(range.startContainer); if (blockElement && options.blockElement === blockElement && !options.resetData.isSearching) { focusBlock(options.blockElement); } } } options.blockElement.querySelector(".layout-tab-bar").scrollLeft = (options.blockElement.querySelector(".layout-tab-bar .item--focus") as HTMLElement).offsetLeft - 30; if (options.cb) { options.cb(options.data); } if (!options.renderAll) { return; } const viewsElement = options.blockElement.querySelector(".av__views") as HTMLElement; const searchInputElement = options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement; searchInputElement.value = options.resetData.query || ""; if (options.resetData.isSearching) { searchInputElement.focus(); } searchInputElement.addEventListener("compositionstart", (event: KeyboardEvent) => { event.stopPropagation(); }); searchInputElement.addEventListener("keydown", (event: KeyboardEvent) => { if (event.isComposing) { return; } electronUndo(event); }); searchInputElement.addEventListener("input", (event: KeyboardEvent) => { event.stopPropagation(); if (event.isComposing) { return; } if (searchInputElement.value || document.activeElement === searchInputElement) { viewsElement.classList.add("av__views--show"); } else { viewsElement.classList.remove("av__views--show"); } updateSearch(options.blockElement, options.protyle); }); searchInputElement.addEventListener("compositionend", () => { updateSearch(options.blockElement, options.protyle); }); 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, width: "1em", height: searchInputElement.clientHeight, clearCB() { viewsElement.classList.remove("av__views--show"); searchInputElement.style.width = "0"; searchInputElement.style.paddingLeft = "0"; searchInputElement.style.paddingRight = "0"; focusBlock(options.blockElement); updateSearch(options.blockElement, options.protyle); } }); }; export const avRender = (element: Element, protyle: IProtyle, cb?: (data: IAV) => void, renderAll = true) => { 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: HTMLElement) => { if (e.getAttribute("data-render") === "true" || hasClosestByClassName(e, "av__gallery-content")) { return; } if (isMobile() || isInIOS() || isInAndroid() || isInHarmony()) { e.classList.add("av--touch"); } if (e.getAttribute("data-av-type") === "gallery") { renderGallery({blockElement: e, protyle, cb, renderAll}); return; } let selectCellId; const selectCellElement = e.querySelector(".av__cell--select") as HTMLElement; if (selectCellElement) { selectCellId = { groupId: (hasClosestByClassName(selectCellElement, "av__body") as HTMLElement).dataset.groupId || "", rowId: (hasClosestByClassName(selectCellElement, "av__row") as HTMLElement).dataset.id, colId: selectCellElement.getAttribute("data-col-id"), }; } const selectRowIds: IIds[] = []; e.querySelectorAll(".av__row--select").forEach(rowItem => { const rowId = rowItem.getAttribute("data-id"); if (rowId) { selectRowIds.push({ groupId: (hasClosestByClassName(rowItem, "av__body") as HTMLElement).dataset.groupId || "", rowId }); } }); let dragFillId; const dragFillElement = e.querySelector(".av__drag-fill") as HTMLElement; if (dragFillElement) { dragFillId = { groupId: (hasClosestByClassName(dragFillElement, "av__body") as HTMLElement).dataset.groupId || "", rowId: (hasClosestByClassName(dragFillElement, "av__row") as HTMLElement).dataset.id, colId: dragFillElement.parentElement.getAttribute("data-col-id"), }; } const activeIds: IIds[] = []; e.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => { activeIds.push({ groupId: (hasClosestByClassName(item, "av__body") as HTMLElement).dataset.groupId || "", rowId: (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id, colId: item.getAttribute("data-col-id"), }); }); const searchInputElement = e.querySelector('[data-type="av-search"]') as HTMLInputElement; const pageSizes: { [key: string]: string } = {}; e.querySelectorAll(".av__body").forEach((item: HTMLElement) => { pageSizes[item.dataset.groupId || "unGroup"] = item.dataset.pageSize; }); const resetData = { selectCellId, alignSelf: e.style.alignSelf, left: e.querySelector(".av__scroll")?.scrollLeft || 0, headerTransform: (e.querySelector('.av__row--header[style^="transform"]') as HTMLElement)?.style.transform, footerTransform: (e.querySelector(".av__row--footer") as HTMLElement)?.style.transform, isSearching: searchInputElement && document.activeElement === searchInputElement, selectRowIds, dragFillId, activeIds, query: searchInputElement?.value || "", pageSizes }; if (e.firstElementChild.innerHTML === "") { e.style.alignSelf = ""; let html = ""; [1, 2, 3].forEach(() => { html += `
`; }); e.firstElementChild.innerHTML = html; } const created = protyle.options.history?.created; const snapshot = protyle.options.history?.snapshot; const avPageSize = getPageSize(e); fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), { id: e.getAttribute("data-av-id"), created, snapshot, pageSize: avPageSize.unGroupPageSize, groupPaging: avPageSize.groupPageSize, viewID: e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "", query: resetData.query.trim(), blockID: e.getAttribute("data-node-id"), }, (response) => { const data = response.data.view as IAVTable; if (response.data.viewType === "gallery") { e.setAttribute("data-av-type", "table"); renderGallery({blockElement: e, protyle, cb, renderAll, data: response.data}); return; } if (data.groups?.length > 0) { renderGroupTable({blockElement: e, protyle, cb, renderAll, data: response.data, resetData}); return; } const avBodyHTML = `
${getTableHTMLs(data, e)}
`; if (renderAll) { e.firstElementChild.outerHTML = `
${genTabHeaderHTML(response.data, resetData.isSearching || !!resetData.query, !protyle.disabled && !hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed"))}
${avBodyHTML}
${Constants.ZWSP}
`; } else { e.firstElementChild.querySelector(".av__scroll").innerHTML = avBodyHTML; } afterRenderTable({ renderAll, data: response.data, cb, protyle, blockElement: e, resetData }); // 历史兼容 e.style.margin = ""; }); }); } }; let searchTimeout: number; export const updateSearch = (e: HTMLElement, protyle: IProtyle) => { clearTimeout(searchTimeout); searchTimeout = window.setTimeout(() => { e.removeAttribute("data-render"); avRender(e, protyle, undefined, false); }, Constants.TIMEOUT_INPUT); }; const refreshTimeouts: { [key: string]: number; } = {}; export const refreshAV = (protyle: IProtyle, operation: IOperation) => { if (operation.action === "setAttrViewName") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[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; }); } if (operation.action === "setAttrViewColWidth") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[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 || item.getAttribute(Constants.CUSTOM_SY_AV_VIEW) !== operation.keyID) { return; } item.querySelectorAll(".av__row").forEach(rowItem => { (rowItem.querySelector(`[data-col-id="${operation.id}"]`) as HTMLElement).style.width = operation.data; }); }); return; } if (operation.action === "setAttrViewCardSize") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { item.querySelectorAll(".av__gallery").forEach(galleryItem => { galleryItem.classList.remove("av__gallery--small", "av__gallery--big"); if (operation.data === 0) { galleryItem.classList.add("av__gallery--small"); } else if (operation.data === 2) { galleryItem.classList.add("av__gallery--big"); } }); }); return; } if (operation.action === "setAttrViewCardAspectRatio") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[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; }); }); return; } if (operation.action === "hideAttrViewName") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { const titleElement = item.querySelector(".av__title"); if (titleElement) { if (!operation.data) { titleElement.classList.remove("fn__none"); } else { // hide titleElement.classList.add("fn__none"); } if (item.getAttribute("data-av-type") === "gallery" && !item.querySelector(".av__group-title")) { const galleryElement = item.querySelector(".av__gallery"); if (!operation.data) { galleryElement.classList.remove("av__gallery--top"); } else { // hide galleryElement.classList.add("av__gallery--top"); } } } }); return; } if (operation.action === "setAttrViewWrapField") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { item.querySelectorAll(".av__cell").forEach(fieldItem => { fieldItem.setAttribute("data-wrap", operation.data.toString()); }); }); return; } if (operation.action === "setAttrViewShowIcon") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { item.querySelectorAll('.av__cell[data-dtype="block"] .b3-menu__avemoji, .av__cell[data-dtype="relation"] .b3-menu__avemoji').forEach(cellItem => { if (operation.data) { cellItem.classList.remove("fn__none"); } else { cellItem.classList.add("fn__none"); } }); }); return; } if (operation.action === "setAttrViewColWrap") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[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 => { cellItem.setAttribute("data-wrap", operation.data.toString()); }); }); return; } if (operation.action === "foldAttrViewGroup") { Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => { const foldElement = item.querySelector(`[data-type="av-group-fold"][data-id="${operation.id}"]`); if (foldElement) { if (operation.data) { foldElement.firstElementChild.classList.remove("av__group-arrow--open"); foldElement.parentElement.nextElementSibling.classList.add("fn__none"); } else { foldElement.firstElementChild.classList.add("av__group-arrow--open"); foldElement.parentElement.nextElementSibling.classList.remove("fn__none"); } foldElement.removeAttribute("data-folding"); } }); return; } // 只能 setTimeout,以前方案快速输入后最后一次修改会被忽略;必须为每一个 protyle 单独设置,否则有多个 protyle 时,其余无法被执行 clearTimeout(refreshTimeouts[protyle.id]); refreshTimeouts[protyle.id] = window.setTimeout(() => { // 修改表格名 avID 传入到 id 上了 https://github.com/siyuan-note/siyuan/issues/12724 const avID = operation.action === "setAttrViewName" ? operation.id : operation.avID; Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-av-id="${avID}"]`)).forEach((item: HTMLElement) => { item.removeAttribute("data-render"); if (operation.action === "sortAttrViewRow") { clearSelect(["cell"], item); } else if (operation.action === "sortAttrViewCol") { 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")); } else if (operation.action === "setAttrViewBlockView") { const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement; if (viewTabElement) { item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => { bodyItem.dataset.pageSize = viewTabElement.dataset.page; }); } } else if (operation.action === "addAttrViewView") { item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => { bodyItem.dataset.pageSize = "50"; }); } else if (operation.action === "removeAttrViewView") { item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => { bodyItem.dataset.pageSize = item.querySelector(`.av__views > .layout-tab-bar .item[data-id="${item.getAttribute(Constants.CUSTOM_SY_AV_VIEW)}"]`)?.getAttribute("data-page"); }); } 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; } } avRender(item, protyle, () => { const attrElement = document.querySelector(`.b3-dialog--open[data-key="${Constants.DIALOG_ATTR}"] .av[data-av-id="${avID}"]`) as HTMLElement; if (attrElement) { // 更新属性面板 renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle); } else { if (operation.action === "insertAttrViewBlock") { const groupQuery = operation.groupID ? `[data-group-id="${operation.groupID}"]` : ""; if (item.getAttribute("data-av-type") === "gallery") { operation.srcs.forEach(srcItem => { const filesElement = item.querySelector(`.av__body${groupQuery} .av__gallery-item[data-id="${srcItem.itemID}"]`)?.querySelector(".av__gallery-fields"); if (filesElement && filesElement.querySelector('[data-dtype="block"]')?.getAttribute("data-empty") === "true") { filesElement.classList.add("av__gallery-fields--edit"); } }); } if (operation.srcs.length === 1) { let popCellElement = item.querySelector(`.av__body${groupQuery} [data-id="${operation.srcs[0].itemID}"] .av__cell[data-dtype="block"]`) as HTMLElement; if (!popCellElement) { const popCellElements = item.querySelectorAll(`.av__body [data-id="${operation.srcs[0].itemID}"] .av__cell[data-dtype="block"]`); if (popCellElements.length === 1) { popCellElement = popCellElements[0] as HTMLElement; } } if (popCellElement && popCellElement.getAttribute("data-detached") === "true") { popTextCell(protyle, [popCellElement], "block"); } } operation.srcs.find((srcItem) => { if (!item.querySelector(`.av__body [data-id="${srcItem.itemID}"]`)) { showMessage(window.siyuan.languages.insertRowTip); return true; } }); } else if (operation.action === "addAttrViewView") { if (item.getAttribute("data-node-id") === operation.blockID) { openMenuPanel({protyle, blockElement: item, type: "config"}); } } } item.removeAttribute("data-loading"); }); }); }, ["insertAttrViewBlock"].includes(operation.action) ? 2 : 100); };