An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/17830
Vanessa41da98940d80
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scssindex e9549bb9aa..ceae4dd573 100644--- a/app/src/assets/scss/business/_av.scss+++ b/app/src/assets/scss/business/_av.scss@@ -140,6 +140,7 @@}&__spacer {+ grid-column: 1 / -1;pointer-events: none;}diff --git a/app/src/protyle/render/av/gallery/render.ts b/app/src/protyle/render/av/gallery/render.tsindex 6f3c8911c2..a8ecaa6a1b 100644--- a/app/src/protyle/render/av/gallery/render.ts+++ b/app/src/protyle/render/av/gallery/render.ts@@ -17,6 +17,7 @@ import {activeBlur} from "../../../../mobile/util/keyboardToolbar";/// #endifimport {renderKanban} from "../kanban/render";import {initVirtualScroll} from "../virtualScroll";+import {getRowHTML} from "../row";interface IIds {groupId: string,@@ -38,84 +39,24 @@ interface ITableOptions {query: string,oldOffset: number,left?: number,+ virtualData: { [key: string]: IAVVirtualData },}}-const getGalleryHTML = (data: IAVGallery, e: HTMLElement) => {+const getGalleryHTML = (data: IAVGallery, e: HTMLElement, virtualData: IAVVirtualData) => {let galleryHTML = "";// bodydata.cards.forEach((item: IAVGalleryItem, rowIndex: number) => {- if (data.pageSize > 100 && rowIndex > 99) {+ if (virtualData && virtualData.renderedEnd) {e.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");- return true;- }- galleryHTML += `<div data-id="${item.id}" draggable="true" class="av__gallery-item">`;- if (data.coverFrom !== 0) {- const coverClass = "av__gallery-cover av__gallery-cover--" + data.cardAspectRatio;- if (item.coverURL) {- if (item.coverURL.startsWith("background")) {- galleryHTML += `<div class="${coverClass}"><img class="av__gallery-img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" style="${item.coverURL}"></div>`;- } else {- galleryHTML += `<div class="${coverClass}"><img loading="lazy" class="av__gallery-img${data.fitImage ? " av__gallery-img--fit" : ""}" src="${getCompressURL(item.coverURL)}"></div>`;- }- } else if (item.coverContent) {- galleryHTML += `<div class="${coverClass}"><div class="av__gallery-content">${item.coverContent}</div><div></div></div>`;- } else {- galleryHTML += `<div class="${coverClass}"></div>`;- }- }- galleryHTML += '<div class="av__gallery-fields">';- item.values.forEach((cell, fieldsIndex) => {- if (data.fields[fieldsIndex].hidden) {+ if (rowIndex > virtualData.renderedEnd || rowIndex < virtualData.renderedStart) {return;}- let checkClass = "";- if (cell.valueType === "checkbox") {- checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";- }- const isEmpty = cellValueIsEmpty(cell.value);- // NOTE: innerHTML 中不能换行否则 https://github.com/siyuan-note/siyuan/issues/15132- let ariaLabel = escapeAttr(data.fields[fieldsIndex].name) || getColNameByType(data.fields[fieldsIndex].type);- if (data.fields[fieldsIndex].desc) {- ariaLabel += escapeAttr(`<div class="ft__on-surface">${data.fields[fieldsIndex].desc}</div>`);- }-- if (cell.valueType === "checkbox" && !data.displayFieldName) {- cell.value.checkbox.content = data.fields[fieldsIndex].name || getColNameByType(data.fields[fieldsIndex].type);- }- const cellHTML = `<div class="av__cell${checkClass}${data.displayFieldName ? "" : " ariaLabel"}"-data-wrap="${data.fields[fieldsIndex].wrap}"-aria-label="${ariaLabel}"-data-position="5west"-data-id="${cell.id}"-data-field-id="${data.fields[fieldsIndex].id}"-data-dtype="${cell.valueType}"-${cell.value?.isDetached ? ' data-detached="true"' : ""}-style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}-${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex, data.showIcon, "gallery")}</div>`;- if (data.displayFieldName) {- galleryHTML += `<div class="av__gallery-field av__gallery-field--name" data-empty="${isEmpty}">- <div class="av__gallery-name">- ${data.fields[fieldsIndex].icon ? unicode2Emoji(data.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(data.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(data.fields[fieldsIndex].name)}- ${data.fields[fieldsIndex].desc ? `<svg aria-label="${data.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}- </div>- ${cellHTML}-</div>`;- } else {- galleryHTML += `<div class="av__gallery-field" data-empty="${isEmpty}">- <div class="av__gallery-tip">- ${data.fields[fieldsIndex].icon ? unicode2Emoji(data.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(data.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(data.fields[fieldsIndex].name)}- </div>- ${cellHTML}-</div>`;- }- });- galleryHTML += `</div>- <div class="av__gallery-actions">- <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>- <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>- </div>-</div>`;+ } else if (data.pageSize > 100 && rowIndex > 99) {+ e.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");+ return true;+ }+ galleryHTML += getRowHTML({data, row: item, rowIndex, type: "gallery"});});galleryHTML += `<div class="av__gallery-add" data-type="av-add-bottom"><svg class="svg"><use xlink:href="#iconAdd"></use></svg><span class="fn__space"></span>${window.siyuan.languages.newRow}</div>`;return `<div class="av__gallery${data.cardSize === 0 ? " av__gallery--small" : (data.cardSize === 2 ? " av__gallery--big" : "")}">@@ -139,7 +80,7 @@ const renderGroupGallery = (options: ITableOptions) => {options.data.view.groups.forEach((group: IAVGallery) => {if (group.groupHidden === 0) {avBodyHTML += `${getGroupTitleHTML(group, group.cardCount)}-<div data-group-id="${group.id}" data-page-size="${group.pageSize}" data-dtype="${group.groupKey.type}" data-content="${Lute.EscapeHTMLStr(group.groupValue.text?.content || "")}" class="av__body${group.groupFolded ? " fn__none" : ""}">${getGalleryHTML(group, options.blockElement)}</div>`;+<div data-group-id="${group.id}" data-page-size="${group.pageSize}" data-dtype="${group.groupKey.type}" data-content="${Lute.EscapeHTMLStr(group.groupValue.text?.content || "")}" class="av__body${group.groupFolded ? " fn__none" : ""}">${getGalleryHTML(group, options.blockElement, options.resetData.virtualData[group.id])}</div>`;}});if (options.renderAll) {@@ -304,8 +245,17 @@ export const renderGallery = async (options: {}});const pageSizes: { [key: string]: string } = {};+ const virtualData: { [key: string]: IAVVirtualData } = {};options.blockElement.querySelectorAll(".av__body").forEach((item: HTMLElement) => {pageSizes[item.dataset.groupId || "unGroup"] = item.dataset.pageSize;+ if (!item.querySelector(".av__gallery-item")) {+ return;+ }+ virtualData[item.getAttribute("data-group-id") || "all"] = ({+ renderedStart: parseInt(item.querySelector(".av__gallery-item").getAttribute("data-index")),+ renderedEnd: parseInt(item.querySelector(".av__gallery-add").previousElementSibling.getAttribute("data-index")),+ topSpacerHeight: item.querySelector(".av__spacer")?.clientHeight || 0,+ });});const resetData = {isSearching: searchInputElement && document.activeElement === searchInputElement,@@ -315,6 +265,7 @@ export const renderGallery = async (options: {editIds,selectItemIds,pageSizes,+ virtualData};if (options.blockElement.firstElementChild.innerHTML === "") {options.blockElement.style.alignSelf = "";@@ -369,7 +320,7 @@ export const renderGallery = async (options: {});return;}- const bodyHTML = getGalleryHTML(view, options.blockElement);+ const bodyHTML = getGalleryHTML(view, options.blockElement, virtualData.all);if (options.renderAll) {options.blockElement.firstElementChild.outerHTML = `<div class="av__container fn__block">${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, !options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}diff --git a/app/src/protyle/render/av/kanban/render.ts b/app/src/protyle/render/av/kanban/render.tsindex e921740eaa..35e1988e8e 100644--- a/app/src/protyle/render/av/kanban/render.ts+++ b/app/src/protyle/render/av/kanban/render.ts@@ -4,11 +4,8 @@ import {fetchSyncPost} from "../../../../util/fetch";import {Constants} from "../../../../constants";import {avRender, genTabHeaderHTML} from "../render";import {afterRenderGallery, renderGallery} from "../gallery/render";-import {escapeAttr, escapeHtml} from "../../../../util/escape";-import {getCompressURL} from "../../../../util/image";-import {cellValueIsEmpty, renderCell} from "../cell";-import {getColIconByType, getColNameByType} from "../col";-import {unicode2Emoji} from "../../../../emoji";+import {escapeHtml} from "../../../../util/escape";+import {getRowHTML} from "../row";interface IIds {groupId: string,@@ -35,79 +32,20 @@ const getKanbanTitleHTML = (group: IAVView, counter: number) => {</div>`;};-const getKanbanHTML = (data: IAVKanban, e:HTMLElement) => {+const getKanbanHTML = (data: IAVKanban, e: HTMLElement, virtualData: IAVVirtualData) => {let galleryHTML = "";// bodydata.cards.forEach((item: IAVGalleryItem, rowIndex: number) => {- if (data.pageSize > 100 && rowIndex > 99) {+ if (virtualData && virtualData.renderedEnd) {e.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");- return true;- }- galleryHTML += `<div data-id="${item.id}" draggable="true" class="av__gallery-item">`;- if (data.coverFrom !== 0) {- const coverClass = "av__gallery-cover av__gallery-cover--" + data.cardAspectRatio;- if (item.coverURL) {- if (item.coverURL.startsWith("background")) {- galleryHTML += `<div class="${coverClass}"><img class="av__gallery-img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" style="${item.coverURL}"></div>`;- } else {- galleryHTML += `<div class="${coverClass}"><img loading="lazy" class="av__gallery-img${data.fitImage ? " av__gallery-img--fit" : ""}" src="${getCompressURL(item.coverURL)}"></div>`;- }- } else if (item.coverContent.trim()) {- galleryHTML += `<div class="${coverClass}"><div class="av__gallery-content">${item.coverContent}</div><div></div></div>`;- }- }- galleryHTML += '<div class="av__gallery-fields">';- item.values.forEach((cell, fieldsIndex) => {- if (data.fields[fieldsIndex].hidden) {+ if (rowIndex > virtualData.renderedEnd || rowIndex < virtualData.renderedStart) {return;}- let checkClass = "";- if (cell.valueType === "checkbox") {- checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";- }- const isEmpty = cellValueIsEmpty(cell.value);- // NOTE: innerHTML 中不能换行否则 https://github.com/siyuan-note/siyuan/issues/15132- let ariaLabel = escapeAttr(data.fields[fieldsIndex].name) || getColNameByType(data.fields[fieldsIndex].type);- if (data.fields[fieldsIndex].desc) {- ariaLabel += escapeAttr(`<div class="ft__on-surface">${data.fields[fieldsIndex].desc}</div>`);- }-- if (cell.valueType === "checkbox" && !data.displayFieldName) {- cell.value.checkbox.content = data.fields[fieldsIndex].name || getColNameByType(data.fields[fieldsIndex].type);- }- const cellHTML = `<div class="av__cell${checkClass}${data.displayFieldName ? "" : " ariaLabel"}"-data-wrap="${data.fields[fieldsIndex].wrap}"-aria-label="${ariaLabel}"-data-position="5west"-data-id="${cell.id}"-data-field-id="${data.fields[fieldsIndex].id}"-data-dtype="${cell.valueType}"-${cell.value?.isDetached ? ' data-detached="true"' : ""}-style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}-${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex, data.showIcon, "kanban")}</div>`;- if (data.displayFieldName) {- galleryHTML += `<div class="av__gallery-field av__gallery-field--name" data-empty="${isEmpty}">- <div class="av__gallery-name">- ${data.fields[fieldsIndex].icon ? unicode2Emoji(data.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(data.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(data.fields[fieldsIndex].name)}- ${data.fields[fieldsIndex].desc ? `<svg aria-label="${data.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}- </div>- ${cellHTML}-</div>`;- } else {- galleryHTML += `<div class="av__gallery-field" data-empty="${isEmpty}">- <div class="av__gallery-tip">- ${data.fields[fieldsIndex].icon ? unicode2Emoji(data.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(data.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(data.fields[fieldsIndex].name)}- </div>- ${cellHTML}-</div>`;- }- });- galleryHTML += `</div>- <div class="av__gallery-actions">- <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>- <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>- </div>-</div>`;+ } else if (data.pageSize > 100 && rowIndex > 99) {+ e.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");+ return true;+ }+ galleryHTML += getRowHTML({data, row: item, rowIndex, type: "kanban"});});galleryHTML += `<div class="av__gallery-add" data-type="av-add-bottom"><svg class="svg"><use xlink:href="#iconAdd"></use></svg><span class="fn__space"></span>${window.siyuan.languages.newRow}</div>`;return `<div class="av__gallery av__gallery--small">@@ -148,8 +86,17 @@ export const renderKanban = async (options: {}});const pageSizes: { [key: string]: string } = {};+ const virtualData: { [key: string]: IAVVirtualData } = {};options.blockElement.querySelectorAll(".av__body").forEach((item: HTMLElement) => {pageSizes[item.dataset.groupId || "unGroup"] = item.dataset.pageSize;+ if (!item.querySelector(".av__gallery-item")) {+ return;+ }+ virtualData[item.getAttribute("data-group-id")] = ({+ renderedStart: parseInt(item.querySelector(".av__gallery-item").getAttribute("data-index")),+ renderedEnd: parseInt(item.querySelector(".av__gallery-add").previousElementSibling.getAttribute("data-index")),+ topSpacerHeight: item.querySelector(".av__spacer")?.clientHeight || 0,+ });});const resetData = {isSearching: searchInputElement && document.activeElement === searchInputElement,@@ -160,6 +107,7 @@ export const renderKanban = async (options: {selectItemIds,pageSizes,left: options.blockElement.querySelector(".av__kanban")?.scrollLeft,+ virtualData};if (options.blockElement.firstElementChild.innerHTML === "") {options.blockElement.style.alignSelf = "";@@ -222,7 +170,7 @@ export const renderKanban = async (options: {}bodyHTML += `<div class="av__kanban-group${group.cardSize === 0 ? " av__kanban-group--small" : (group.cardSize === 2 ? " av__kanban-group--big" : "")}"${selectBg}>${getKanbanTitleHTML(group, group.cardCount)}- <div data-group-id="${group.id}" data-page-size="${group.pageSize}" data-dtype="${group.groupKey.type}" data-content="${Lute.EscapeHTMLStr(group.groupValue.text?.content || "")}" class="av__body">${getKanbanHTML(group, options.blockElement)}</div>+ <div data-group-id="${group.id}" data-page-size="${group.pageSize}" data-dtype="${group.groupKey.type}" data-content="${Lute.EscapeHTMLStr(group.groupValue.text?.content || "")}" class="av__body">${getKanbanHTML(group, options.blockElement, virtualData[group.id])}</div></div>`;}});diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.tsindex 6b3db19f6d..d0ebb17539 100644--- a/app/src/protyle/render/av/render.ts+++ b/app/src/protyle/render/av/render.ts@@ -31,12 +31,6 @@ interface IIds {colId?: string}-interface IVirtualData {- renderedStart: number;- renderedEnd: number;- topSpacerHeight: number;-}-interface ITableOptions {protyle: IProtyle,blockElement: HTMLElement,@@ -55,7 +49,7 @@ interface ITableOptions {activeIds: IIds[],query: string,pageSizes: { [key: string]: string },- virtualData: { [key: string]: IVirtualData },+ virtualData: { [key: string]: IAVVirtualData },}}@@ -130,7 +124,7 @@ export const genTabHeaderHTML = (data: IAV, showSearch: boolean, editable: boole</div>`;};-const getTableHTMLs = (data: IAVTable, e: HTMLElement, virtualData: IVirtualData) => {+const getTableHTMLs = (data: IAVTable, e: HTMLElement, virtualData: IAVVirtualData) => {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;@@ -199,7 +193,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || `<svg><use x}// bodydata.rows.find((row: IAVRow, rowIndex: number) => {- if (virtualData) {+ if (virtualData && virtualData.renderedEnd) {e.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");if (rowIndex > virtualData.renderedEnd || rowIndex < virtualData.renderedStart) {return;@@ -208,7 +202,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || `<svg><use xe.setAttribute(Constants.ATTRIBUTE_V_SCROLL, "true");return true;}- contentHTML += getRowHTML(data, row, rowIndex, pinIndex);+ contentHTML += getRowHTML({data, row, rowIndex, pinIndex, type: "table"});});return `${contentHTML}<div class="av__row--util${data.rowCount > data.rows.length ? " av__readonly--show" : ""}"><div class="av__colsticky">@@ -508,19 +502,20 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data:});const searchInputElement = e.querySelector('[data-type="av-search"]') as HTMLInputElement;const pageSizes: { [key: string]: string } = {};+ const virtualData: { [key: string]: IAVVirtualData } = {};e.querySelectorAll(".av__body").forEach((item: HTMLElement) => {pageSizes[item.dataset.groupId || "unGroup"] = item.dataset.pageSize;- });- const headerTransformElement = e.querySelector('.av__row--header[style^="transform"]') as HTMLElement;- const footerTransformElement = e.querySelector('.av__row--footer[style^="transform"]') as HTMLElement;- const virtualData: { [key: string]: IVirtualData } = {};- e.querySelectorAll(".av__body").forEach(item => {+ if (!item.querySelector(".av__row")) {+ return;+ }virtualData[item.getAttribute("data-group-id") || "all"] = ({renderedStart: parseInt(item.querySelectorAll(".av__row")[1].getAttribute("data-index")),renderedEnd: parseInt(item.querySelector(".av__row--util").previousElementSibling.getAttribute("data-index")),topSpacerHeight: item.querySelector(".av__spacer")?.clientHeight || 0,});});+ const headerTransformElement = e.querySelector('.av__row--header[style^="transform"]') as HTMLElement;+ const footerTransformElement = e.querySelector('.av__row--footer[style^="transform"]') as HTMLElement;const resetData = {selectCellId,alignSelf: e.style.alignSelf,diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.tsindex 54b88d4247..8d7086d7f1 100644--- a/app/src/protyle/render/av/row.ts+++ b/app/src/protyle/render/av/row.ts@@ -2,24 +2,187 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";import {focusBlock} from "../../util/selection";import {Menu} from "../../../plugin/Menu";import {transaction} from "../../wysiwyg/transaction";-import {genCellValue, genCellValueByElement, getTypeByCellElement, renderCell, renderCellAttr} from "./cell";+import {+ cellValueIsEmpty,+ genCellValue,+ genCellValueByElement,+ getTypeByCellElement,+ renderCell,+ renderCellAttr+} from "./cell";import {fetchPost} from "../../../util/fetch";import * as dayjs from "dayjs";import {Constants} from "../../../constants";import {insertGalleryItemAnimation} from "./gallery/item";import {clearSelect} from "../../util/clear";import {isCustomAttr} from "./blockAttr";+import {getColIconByType, getColNameByType} from "./col";+import {unicode2Emoji} from "../../../emoji";+import {escapeAttr} from "../../../util/escape";+import {getCompressURL} from "../../../util/image";-export const getRowHTML = (data: IAVView, row: IAVRow, rowIndex: number, pinIndex: number) => {- let html = `<div class="av__row" data-index="${rowIndex}" data-id="${row.id}">`;- if (pinIndex > -1) {+export const getRowHTML = (options: {+ data: IAVView+ row: IAVRow | IAVGalleryItem+ rowIndex: number+ type: TAVView+ pinIndex?: number+}) => {+ let html = "";+ if (options.type === "gallery") {+ const galleryRow = options.row as IAVGalleryItem;+ const kanbanData = options.data as IAVGallery;+ html += `<div data-id="${galleryRow.id}" data-index="${options.rowIndex}" draggable="true" class="av__gallery-item">`;+ if (kanbanData.coverFrom !== 0) {+ const coverClass = "av__gallery-cover av__gallery-cover--" + kanbanData.cardAspectRatio;+ if (galleryRow.coverURL) {+ if (galleryRow.coverURL.startsWith("background")) {+ html += `<div class="${coverClass}"><img class="av__gallery-img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" style="${galleryRow.coverURL}"></div>`;+ } else {+ html += `<div class="${coverClass}"><img loading="lazy" class="av__gallery-img${kanbanData.fitImage ? " av__gallery-img--fit" : ""}" src="${getCompressURL(galleryRow.coverURL)}"></div>`;+ }+ } else if (galleryRow.coverContent) {+ html += `<div class="${coverClass}"><div class="av__gallery-content">${galleryRow.coverContent}</div><div></div></div>`;+ } else {+ html += `<div class="${coverClass}"></div>`;+ }+ }+ html += '<div class="av__gallery-fields">';+ galleryRow.values.forEach((cell, fieldsIndex) => {+ if (kanbanData.fields[fieldsIndex].hidden) {+ return;+ }+ let checkClass = "";+ if (cell.valueType === "checkbox") {+ checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";+ }+ const isEmpty = cellValueIsEmpty(cell.value);+ // NOTE: innerHTML 中不能换行否则 https://github.com/siyuan-note/siyuan/issues/15132+ let ariaLabel = escapeAttr(kanbanData.fields[fieldsIndex].name) || getColNameByType(kanbanData.fields[fieldsIndex].type);+ if (kanbanData.fields[fieldsIndex].desc) {+ ariaLabel += escapeAttr(`<div class="ft__on-surface">${kanbanData.fields[fieldsIndex].desc}</div>`);+ }++ if (cell.valueType === "checkbox" && !kanbanData.displayFieldName) {+ cell.value.checkbox.content = kanbanData.fields[fieldsIndex].name || getColNameByType(kanbanData.fields[fieldsIndex].type);+ }+ const cellHTML = `<div class="av__cell${checkClass}${kanbanData.displayFieldName ? "" : " ariaLabel"}"+data-wrap="${kanbanData.fields[fieldsIndex].wrap}"+aria-label="${ariaLabel}"+data-position="5west"+data-id="${cell.id}"+data-field-id="${kanbanData.fields[fieldsIndex].id}"+data-dtype="${cell.valueType}"+${cell.value?.isDetached ? ' data-detached="true"' : ""}+style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}+${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rowIndex, kanbanData.showIcon, "gallery")}</div>`;+ if (kanbanData.displayFieldName) {+ html += `<div class="av__gallery-field av__gallery-field--name" data-empty="${isEmpty}">+ <div class="av__gallery-name">+ ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}+ ${kanbanData.fields[fieldsIndex].desc ? `<svg aria-label="${kanbanData.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}+ </div>+ ${cellHTML}+</div>`;+ } else {+ html += `<div class="av__gallery-field" data-empty="${isEmpty}">+ <div class="av__gallery-tip">+ ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}+ </div>+ ${cellHTML}+</div>`;+ }+ });+ html += `</div>+ <div class="av__gallery-actions">+ <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>+ <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>+ </div>+</div>`;+ return html;+ }+ if (options.type === "kanban") {+ const kanbanRow = options.row as IAVGalleryItem;+ const kanbanData = options.data as IAVKanban;+ html += `<div data-id="${kanbanRow.id}" data-index="${options.rowIndex}" draggable="true" class="av__gallery-item">`;+ if (kanbanData.coverFrom !== 0) {+ const coverClass = "av__gallery-cover av__gallery-cover--" + kanbanData.cardAspectRatio;+ if (kanbanRow.coverURL) {+ if (kanbanRow.coverURL.startsWith("background")) {+ html += `<div class="${coverClass}"><img class="av__gallery-img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" style="${kanbanRow.coverURL}"></div>`;+ } else {+ html += `<div class="${coverClass}"><img loading="lazy" class="av__gallery-img${kanbanData.fitImage ? " av__gallery-img--fit" : ""}" src="${getCompressURL(kanbanRow.coverURL)}"></div>`;+ }+ } else if (kanbanRow.coverContent.trim()) {+ html += `<div class="${coverClass}"><div class="av__gallery-content">${kanbanRow.coverContent}</div><div></div></div>`;+ }+ }+ html += '<div class="av__gallery-fields">';+ kanbanRow.values.forEach((cell, fieldsIndex) => {+ if (kanbanData.fields[fieldsIndex].hidden) {+ return;+ }+ let checkClass = "";+ if (cell.valueType === "checkbox") {+ checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";+ }+ const isEmpty = cellValueIsEmpty(cell.value);+ // NOTE: innerHTML 中不能换行否则 https://github.com/siyuan-note/siyuan/issues/15132+ let ariaLabel = escapeAttr(kanbanData.fields[fieldsIndex].name) || getColNameByType(kanbanData.fields[fieldsIndex].type);+ if (kanbanData.fields[fieldsIndex].desc) {+ ariaLabel += escapeAttr(`<div class="ft__on-surface">${kanbanData.fields[fieldsIndex].desc}</div>`);+ }++ if (cell.valueType === "checkbox" && !kanbanData.displayFieldName) {+ cell.value.checkbox.content = kanbanData.fields[fieldsIndex].name || getColNameByType(kanbanData.fields[fieldsIndex].type);+ }+ const cellHTML = `<div class="av__cell${checkClass}${kanbanData.displayFieldName ? "" : " ariaLabel"}"+data-wrap="${kanbanData.fields[fieldsIndex].wrap}"+aria-label="${ariaLabel}"+data-position="5west"+data-id="${cell.id}"+data-field-id="${kanbanData.fields[fieldsIndex].id}"+data-dtype="${cell.valueType}"+${cell.value?.isDetached ? ' data-detached="true"' : ""}+style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}+${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rowIndex, kanbanData.showIcon, "kanban")}</div>`;+ if (kanbanData.displayFieldName) {+ html += `<div class="av__gallery-field av__gallery-field--name" data-empty="${isEmpty}">+ <div class="av__gallery-name">+ ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}+ ${kanbanData.fields[fieldsIndex].desc ? `<svg aria-label="${kanbanData.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}+ </div>+ ${cellHTML}+</div>`;+ } else {+ html += `<div class="av__gallery-field" data-empty="${isEmpty}">+ <div class="av__gallery-tip">+ ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}+ </div>+ ${cellHTML}+</div>`;+ }+ });+ html += `</div>+ <div class="av__gallery-actions">+ <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>+ <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>+ </div>+</div>`;+ return html;+ }+ const tableRow = options.row as IAVRow;+ const tableData = options.data as IAVTable;++ html = `<div class="av__row" data-index="${options.rowIndex}" data-id="${tableRow.id}">`;+ if (options.pinIndex > -1) {html += '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div>';} else {html += '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';}- row.cells.forEach((cell, index) => {- const column = (data as IAVTable).columns[index];+ tableRow.cells.forEach((cell, index) => {+ const column = tableData.columns[index];if (column.hidden) {return;}@@ -35,9 +198,9 @@ ${cell.value?.isDetached ? ' data-detached="true"' : ""}style="width: ${column.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>`;+${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rowIndex, tableData.showIcon)}</div>`;- if (pinIndex === index) {+ if (options.pinIndex === index) {html += "</div>";}});diff --git a/app/src/protyle/render/av/virtualScroll.ts b/app/src/protyle/render/av/virtualScroll.tsindex 8108cd0fa5..14b1742748 100644--- a/app/src/protyle/render/av/virtualScroll.ts+++ b/app/src/protyle/render/av/virtualScroll.ts@@ -2,14 +2,13 @@ import {Constants} from "../../../constants";import {getRowHTML} from "./row";const BUFFER_RATIO = 1;-const ESTIMATED_ROW_HEIGHT = 36;interface IBodyState {renderedStart: number;renderedEnd: number;view: IAVView;- pinIndex: number;topSpacerHeight: number;+ pinIndex?: number;}const dataStore = new Map<string, {@@ -35,50 +34,81 @@ const doTrim = (blockElement: HTMLElement, elementRect: DOMRect): void => {return;}+ const type = blockElement.getAttribute("data-av-type") as TAVView;const bodies = blockElement.querySelectorAll(".av__body:not(.fn__none)") as NodeListOf<HTMLElement>;bodies.forEach((bodyEl: HTMLElement) => {const state = bodyStates.get(bodyEl);- const dataRows = (state.view as IAVTable).rows;- const headerElement = bodyEl.querySelector(".av__row--header") as HTMLElement;- const currentRows = bodyEl.querySelectorAll(".av__row:not(.av__row--header):not(.av__row--footer):not(.av__row--util)") as NodeListOf<HTMLElement>;-+ const dataRows = type === "table" ? (state.view as IAVTable).rows : (state.view as IAVKanban).cards;+ let currentRows;+ let bottomElement;+ if (type === "table") {+ currentRows = bodyEl.querySelectorAll(".av__row:not(.av__row--header):not(.av__row--footer):not(.av__row--util)") as NodeListOf<HTMLElement>;+ bottomElement = bodyEl.querySelector(".av__row--util");+ } else {+ currentRows = bodyEl.querySelectorAll(".av__gallery-item") as NodeListOf<HTMLElement>;+ bottomElement = bodyEl.querySelector(".av__gallery-add");+ }+ if (currentRows.length === 0) {+ return;+ }+ let topElement = currentRows[0];+ const spacerElement = bodyEl.querySelector(".av__spacer") as HTMLElement;let firstVisibleIndex: number;let lastVisibleIndex: number;const toRemoveAbove: HTMLElement[] = [];const toRemoveBelow: HTMLElement[] = [];-+ let galleryColumn = type === "gallery" ? 0 : 1;+ const rowHeight = currentRows[0].offsetHeight;+ const firstTop = currentRows[0].getBoundingClientRect().top;for (let i = 0; i < currentRows.length; i++) {const rect = currentRows[i].getBoundingClientRect();+ if (rect.top === firstTop) {+ galleryColumn++;+ }if (rect.top > topLimit) {if (typeof firstVisibleIndex === "undefined") {firstVisibleIndex = parseInt(currentRows[i].getAttribute("data-index"));}} else {- if (!isScrollingUp) {+ if (!isScrollingUp && toRemoveAbove.length + 10 < currentRows.length) {toRemoveAbove.push(currentRows[i]);}}if (rect.bottom < bottomLimit) {lastVisibleIndex = parseInt(currentRows[i].getAttribute("data-index"));} else {- if (isScrollingUp) {+ if (isScrollingUp && toRemoveAbove.length + 10 < currentRows.length) {toRemoveBelow.push(currentRows[i]);}}if (i === currentRows.length - 1 && !isScrollingUp && rect.bottom < bottomLimit) {- lastVisibleIndex = Math.min(state.renderedEnd + Math.ceil((bottomLimit - rect.bottom) / ESTIMATED_ROW_HEIGHT), dataRows.length - 1);- }- if (i === 0 && isScrollingUp && rect.top > topLimit) {- firstVisibleIndex = Math.max(0, state.renderedStart - Math.ceil((rect.top - topLimit) / ESTIMATED_ROW_HEIGHT));+ lastVisibleIndex = Math.min(state.renderedEnd + Math.ceil((bottomLimit - rect.bottom) / rowHeight) * galleryColumn, dataRows.length - 1);}}-- const spacerElement = bodyEl.querySelector(".av__spacer") as HTMLElement;+ // 需等待 galleryColumn 计算完成+ if (isScrollingUp && firstTop > topLimit) {+ firstVisibleIndex = Math.max(0, state.renderedStart - Math.ceil((firstTop - topLimit) / rowHeight) * galleryColumn);+ }if (!isScrollingUp) {if (toRemoveAbove.length > 0) {let removeHeight = 0;- toRemoveAbove.forEach((row) => {- removeHeight += row.offsetHeight;+ toRemoveAbove.forEach((row, index) => {+ topElement = row.nextElementSibling as HTMLElement;+ if (type === "table") {+ removeHeight += row.offsetHeight;+ } else if (type === "gallery") {+ if (removeHeight === 0 || topElement.offsetTop !== row.offsetTop) {+ removeHeight += row.offsetHeight;+ if (state.topSpacerHeight !== 0 && index !== 0) {+ removeHeight += 16; // .av__kanban-group gap: 16px;+ }+ }+ } else if (type === "kanban") {+ if (state.topSpacerHeight !== 0 && index !== 0) {+ removeHeight += 16; // .av__kanban-group gap: 16px;+ }+ removeHeight += row.offsetHeight;+ }row.remove();});state.topSpacerHeight += removeHeight;@@ -87,16 +117,23 @@ const doTrim = (blockElement: HTMLElement, elementRect: DOMRect): void => {if (spacerElement) {spacerElement.style.height = state.topSpacerHeight + "px";} else if (state.topSpacerHeight > 0) {- headerElement.insertAdjacentHTML("afterend", `<div class="av__spacer" style="height:${state.topSpacerHeight}px"></div>`);+ topElement.insertAdjacentHTML("beforebegin", `<div class="av__spacer" style="height:${state.topSpacerHeight}px"></div>`);}+ protyle.contentElement.scrollTop = lastScrollTop;}if (lastVisibleIndex > state.renderedEnd) {let rowsHTML = "";for (let i = state.renderedEnd + 1; i <= lastVisibleIndex; i++) {- rowsHTML += getRowHTML(state.view, dataRows[i], i, state.pinIndex);+ rowsHTML += getRowHTML({+ data: state.view,+ row: dataRows[i],+ rowIndex: i,+ pinIndex: state.pinIndex,+ type: blockElement.getAttribute("data-av-type") as TAVView+ });}- bodyEl.querySelector(".av__row--util").insertAdjacentHTML("beforebegin", rowsHTML);+ bottomElement.insertAdjacentHTML("beforebegin", rowsHTML);state.renderedEnd = lastVisibleIndex;}} else {@@ -105,23 +142,37 @@ const doTrim = (blockElement: HTMLElement, elementRect: DOMRect): void => {state.renderedEnd = state.renderedEnd - toRemoveBelow.length;}- if (firstVisibleIndex < state.renderedStart) {+ if (typeof firstVisibleIndex === "number" && firstVisibleIndex < state.renderedStart) {let rowsHTML = "";for (let i = firstVisibleIndex; i < state.renderedStart; i++) {- rowsHTML += getRowHTML(state.view, dataRows[i], i, state.pinIndex);+ rowsHTML += getRowHTML({+ data: state.view,+ row: dataRows[i],+ rowIndex: i,+ pinIndex: state.pinIndex,+ type: blockElement.getAttribute("data-av-type") as TAVView+ });}- (spacerElement || headerElement).insertAdjacentHTML("afterend", rowsHTML);+ topElement.insertAdjacentHTML("beforebegin", rowsHTML);let renderedHeight = 0;- let newRowElement = (spacerElement || headerElement).nextElementSibling as HTMLElement;+ let newRowElement = topElement.previousElementSibling as HTMLElement;while (newRowElement) {- if (parseInt(newRowElement.getAttribute("data-index"), 10) >= state.renderedStart) {+ if (type === "table") {+ renderedHeight += newRowElement.offsetHeight;+ } else if (type === "gallery") {+ if (renderedHeight === 0 || (topElement.previousElementSibling as HTMLElement).offsetTop !== newRowElement.offsetTop) {+ renderedHeight += newRowElement.offsetHeight + 16;+ }+ } else if (type === "kanban") {+ renderedHeight += newRowElement.offsetHeight + 16;+ }+ newRowElement = newRowElement.previousElementSibling as HTMLElement;+ if (!newRowElement || newRowElement.classList.contains("av__spacer") ||+ newRowElement.classList.contains("av__row--header")) {break;}- renderedHeight += newRowElement.offsetHeight;- newRowElement = newRowElement.nextElementSibling as HTMLElement;}-state.topSpacerHeight = Math.max(0, state.topSpacerHeight - renderedHeight);if (state.topSpacerHeight === 0) {spacerElement?.remove();@@ -129,6 +180,7 @@ const doTrim = (blockElement: HTMLElement, elementRect: DOMRect): void => {spacerElement.style.height = state.topSpacerHeight + "px";}state.renderedStart = firstVisibleIndex;+ protyle.contentElement.scrollTop = lastScrollTop;}}bodyStates.set(bodyEl, state);@@ -167,13 +219,22 @@ export const initVirtualScroll = (options: {data: options.data,});- options.blockElement.querySelectorAll(".av__body").forEach((bodyEl: HTMLElement) => {- bodyStates.set(bodyEl, {- renderedStart: parseInt(bodyEl.querySelectorAll(".av__row")[1].getAttribute("data-index")),- pinIndex: parseInt(bodyEl.querySelector(".av__row--header > .block__icons")?.getAttribute("data-pinindex")),- renderedEnd: parseInt(bodyEl.querySelector(".av__row--util").previousElementSibling.getAttribute("data-index")),- view: getBodyData(bodyEl),- topSpacerHeight: bodyEl.querySelector(".av__spacer")?.clientHeight || 0,- });+ options.blockElement.querySelectorAll(".av__body").forEach((item: HTMLElement) => {+ if (options.data.viewType === "table") {+ bodyStates.set(item, {+ renderedStart: parseInt(item.querySelectorAll(".av__row")[1].getAttribute("data-index")),+ pinIndex: parseInt(item.querySelector(".av__row--header > .block__icons")?.getAttribute("data-pinindex")),+ renderedEnd: parseInt(item.querySelector(".av__row--util").previousElementSibling.getAttribute("data-index")),+ view: getBodyData(item),+ topSpacerHeight: item.querySelector(".av__spacer")?.clientHeight || 0,+ });+ } else {+ bodyStates.set(item, {+ renderedStart: parseInt(item.querySelector(".av__gallery-item").getAttribute("data-index")),+ renderedEnd: parseInt(item.querySelector(".av__gallery-add").previousElementSibling.getAttribute("data-index")),+ view: getBodyData(item),+ topSpacerHeight: item.querySelector(".av__spacer")?.clientHeight || 0,+ });+ }});};diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex e4c57203a3..e5a0ad9e72 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -974,6 +974,12 @@ interface IAVTable extends IAVView {rowCount: number,}+interface IAVVirtualData {+ renderedStart: number;+ renderedEnd: number;+ topSpacerHeight: number;+}+interface IAVGallery extends IAVView {coverFrom: number; // 0:无,1:内容图,2:资源字段,3:内容块coverFromAssetKeyID?: string;