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/18201
Vanessa61175d0ed133
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.tsindex 5f109794dc..dc3094071b 100644--- a/app/src/protyle/render/av/action.ts+++ b/app/src/protyle/render/av/action.ts@@ -383,6 +383,12 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positiclearSelect(["galleryItem"], blockElement);}rowElement.classList.add("av__gallery-item--select");+ const bodyElement = hasClosestByClassName(rowElement, "av__body") as HTMLElement;+ const rowId = rowElement.getAttribute("data-id");+ if (bodyElement && rowId) {+ updateAVRowSelect(bodyElement, rowId, true);+ }+ updateHeader(rowElement);}const menu = new Menu();const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select");diff --git a/app/src/protyle/render/av/gallery/render.ts b/app/src/protyle/render/av/gallery/render.tsindex 9e9aa6f809..f44e10ed7f 100644--- a/app/src/protyle/render/av/gallery/render.ts+++ b/app/src/protyle/render/av/gallery/render.ts@@ -8,7 +8,7 @@ import {processRender} from "../../../util/processCode";import {getPageSize} from "../groups";import {renderKanban} from "../kanban/render";import {getBodyVirtualData, initVirtualScroll} from "../virtualScroll";-import {getRowHTML} from "../row";+import {getRowHTML, updateHeader} from "../row";interface IIds {groupId: string,@@ -118,6 +118,11 @@ export const afterRenderGallery = (options: ITableOptions) => {itemElement.classList.add("av__gallery-item--select");}});+ // 重渲后恢复的选中态需刷新计数器显示+ const restoredItem = options.blockElement.querySelector(".av__gallery-item--select") as HTMLElement;+ if (restoredItem) {+ updateHeader(restoredItem);+ }options.resetData.editIds.find(selectId => {let itemElement = options.blockElement.querySelector(`.av__body[data-group-id="${selectId.groupId}"] .av__gallery-item[data-id="${selectId.fieldId}"]`) as HTMLElement;if (!itemElement) {diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.tsindex 58edd617e2..f5016bc32d 100644--- a/app/src/protyle/render/av/row.ts+++ b/app/src/protyle/render/av/row.ts@@ -283,24 +283,33 @@ export const updateHeader = (rowElement: HTMLElement) => {if (!blockElement) {return;}- const bodyElement = rowElement.parentElement as HTMLElement;- // 虚拟滚动下 DOM 内只有渲染窗口的行,直接计数会低估;优先用选中快照与已加载行总数。- const stat = getAVSelectStat(bodyElement);- const selectCount = stat ? stat.selectCount : bodyElement.querySelectorAll(".av__row--select:not(.av__row--header)").length;- const count = stat ? stat.loadedCount : bodyElement.querySelectorAll(".av__row:not(.av__row--header)").length;-- const headElement = bodyElement.firstElementChild;- const headUseElement = headElement.querySelector("use");-- if (count === selectCount && count !== 0) {- headElement.classList.add("av__row--select");- headUseElement.setAttribute("xlink:href", "#iconCheck");- } else if (selectCount === 0) {- headElement.classList.remove("av__row--select");- headUseElement.setAttribute("xlink:href", "#iconUncheck");- } else if (selectCount > 0) {- headElement.classList.add("av__row--select");- headUseElement.setAttribute("xlink:href", "#iconIndeterminateCheck");+ const avType = blockElement.getAttribute("data-av-type") as TAVView;+ let selectCount: number;+ if (avType === "table") {+ const bodyElement = rowElement.parentElement as HTMLElement;+ // 虚拟滚动下 DOM 内只有渲染窗口的行,直接计数会低估;优先用选中快照与已加载行总数。+ const stat = getAVSelectStat(bodyElement);+ selectCount = stat ? stat.selectCount : bodyElement.querySelectorAll(".av__row--select:not(.av__row--header)").length;+ const count = stat ? stat.loadedCount : bodyElement.querySelectorAll(".av__row:not(.av__row--header)").length;+ const headElement = bodyElement.firstElementChild as HTMLElement;+ const headUseElement = headElement.querySelector("use");+ if (count === selectCount && count !== 0) {+ headElement.classList.add("av__row--select");+ headUseElement.setAttribute("xlink:href", "#iconCheck");+ } else if (selectCount === 0) {+ headElement.classList.remove("av__row--select");+ headUseElement.setAttribute("xlink:href", "#iconUncheck");+ } else if (selectCount > 0) {+ headElement.classList.add("av__row--select");+ headUseElement.setAttribute("xlink:href", "#iconIndeterminateCheck");+ }+ } else {+ // 卡片/看板视图按分组(.av__body)聚合选中数,看板与分组卡片视图存在多个 body。+ selectCount = 0;+ blockElement.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => {+ const stat = getAVSelectStat(bodyItem);+ selectCount += stat ? stat.selectCount : bodyItem.querySelectorAll(".av__gallery-item--select").length;+ });}const counterElement = blockElement.querySelector(".av__counter");diff --git a/app/src/protyle/util/clear.ts b/app/src/protyle/util/clear.tsindex 08346b68a5..7e415e72a8 100644--- a/app/src/protyle/util/clear.ts+++ b/app/src/protyle/util/clear.ts@@ -1,5 +1,6 @@import {updateHeader} from "../render/av/row";import {resetAVRowSelect} from "../render/av/virtualScroll";+import {hasClosestByClassName} from "./hasClosest";import {Constants} from "../../constants";export const clearBlockElement = (element: Element, keepRefcount = false) => {@@ -40,8 +41,9 @@ export const clearSelect = (types: ("av" | "img" | "cell" | "row" | "galleryItem});}if (types.includes("galleryItem")) {+ const clearedBodies = new Set<HTMLElement>();element.querySelectorAll(".av__gallery-item--select").forEach((item: HTMLElement) => {- item.classList.remove("av__gallery-item--select");+ clearGalleryItem(item, clearedBodies);});}if (types.includes("av")) {@@ -56,9 +58,11 @@ export const clearSelect = (types: ("av" | "img" | "cell" | "row" | "galleryItemclearedBodies.add(bodyEl);}updateHeader(item);+ } else if (item.classList.contains("av__gallery-item--select")) {+ clearGalleryItem(item, clearedBodies);} else {item.querySelector(".av__drag-fill")?.remove();- item.classList.remove("av__cell--select", "av__cell--active", "av__gallery-item--select");+ item.classList.remove("av__cell--select", "av__cell--active");}});}@@ -69,3 +73,13 @@ export const clearSelect = (types: ("av" | "img" | "cell" | "row" | "galleryItem}};++const clearGalleryItem = (item: HTMLElement, clearedBodies: Set<HTMLElement>) => {+ item.classList.remove("av__gallery-item--select");+ const bodyEl = hasClosestByClassName(item, "av__body") as HTMLElement;+ if (bodyEl && !clearedBodies.has(bodyEl)) {+ resetAVRowSelect(bodyEl, []);+ clearedBodies.add(bodyEl);+ }+ updateHeader(item);+};diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 1db9bc0144..cfcc11fbc4 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -79,7 +79,8 @@ import {removeSearchMark} from "../toolbar/util";import {activeBlur} from "../../mobile/util/keyboardToolbar";import {commonClick} from "./commonClick";import {avClick, avContextmenu, updateAVName} from "../render/av/action";-import {selectRow, stickyRow} from "../render/av/row";+import {selectRow, stickyRow, updateHeader} from "../render/av/row";+import {updateAVRowSelect} from "../render/av/virtualScroll";import {showColMenu} from "../render/av/col";import {openViewMenu} from "../render/av/view";import {checkFold} from "../../util/noRelyPCFunction";@@ -613,9 +614,17 @@ export class WYSIWYG {break;}}- previousList.concat(nextList).forEach(item => {+ // 锚点卡片及范围内卡片统一选中并同步虚拟滚动选中快照+ const shiftSelectItems = [galleryItemElement].concat(previousList as HTMLElement[]).concat(nextList as HTMLElement[]);+ shiftSelectItems.forEach(item => {item.classList.add("av__gallery-item--select");+ const galleryBodyElement = hasClosestByClassName(item, "av__body") as HTMLElement;+ const galleryRowId = item.getAttribute("data-id");+ if (galleryBodyElement && galleryRowId) {+ updateAVRowSelect(galleryBodyElement, galleryRowId, true);+ }});+ updateHeader(galleryItemElement);event.preventDefault();} else if (startElement && endElement && startElement !== endElement) {let toDown = true;@@ -721,7 +730,13 @@ export class WYSIWYG {const rowElement = hasClosestByClassName(target, "av__row");if (!hasSelectClassElement && (galleryItemElement || (rowElement && !rowElement.classList.contains("av__row--header")))) {if (galleryItemElement) {- galleryItemElement.classList.toggle("av__gallery-item--select");+ const galleryBodyElement = hasClosestByClassName(galleryItemElement, "av__body") as HTMLElement;+ const galleryRowId = galleryItemElement.getAttribute("data-id");+ if (galleryBodyElement && galleryRowId) {+ updateAVRowSelect(galleryBodyElement, galleryRowId,+ galleryItemElement.classList.toggle("av__gallery-item--select"));+ }+ updateHeader(galleryItemElement);} else if (rowElement) {selectRow(rowElement.querySelector(".av__firstcol"), "toggle");}