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
Vanessa41f15109b8ef
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scssindex 236dac80be..602dc02885 100644--- a/app/src/assets/scss/business/_av.scss+++ b/app/src/assets/scss/business/_av.scss@@ -194,11 +194,6 @@}}- &--header,- &--footer {- background-color: var(--b3-parent-background);- }-&--footer {display: flex;border-top: 1px solid var(--b3-theme-surface-lighter);@@ -255,6 +250,15 @@}}+ &--header,+ &--footer {+ background-color: var(--b3-parent-background);++ &--fixed {+ position: fixed;+ }+ }+&--util {display: flex;diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.tsindex e7c6ee965c..f86566c672 100644--- a/app/src/protyle/render/av/render.ts+++ b/app/src/protyle/render/av/render.ts@@ -289,7 +289,7 @@ const afterRenderTable = (options: ITableOptions) => {} else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787setTimeout(() => {- stickyRow(options.blockElement, editRect, "top");+ stickyRow(options.blockElement, options.protyle.contentElement, "top");}, Constants.TIMEOUT_LOAD);}if (options.resetData.footerTransform) {@@ -300,7 +300,7 @@ const afterRenderTable = (options: ITableOptions) => {} else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787setTimeout(() => {- stickyRow(options.blockElement, editRect, "bottom");+ stickyRow(options.blockElement, options.protyle.contentElement, "bottom");}, Constants.TIMEOUT_LOAD);}if (options.resetData.selectCellId) {diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.tsindex 8d7086d7f1..4f4f33d161 100644--- a/app/src/protyle/render/av/row.ts+++ b/app/src/protyle/render/av/row.ts@@ -181,7 +181,7 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rohtml += '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';}- tableRow.cells.forEach((cell, index) => {+ tableRow.cells.forEach((cell, index) => {const column = tableData.columns[index];if (column.hidden) {return;@@ -384,37 +384,130 @@ ${colType === "block" ? ' data-detached="true"' : ""}>${renderCell(genCellValue(});};-export const stickyRow = (blockElement: HTMLElement, elementRect: DOMRect, status: "top" | "bottom" | "all") => {+const applyFixedClip = (el: HTMLElement, scrollEl: HTMLElement) => {+ const scrollLeft = scrollEl.scrollLeft;+ const clientWidth = scrollEl.clientWidth;+ const scrollWidth = scrollEl.scrollWidth;+ if (scrollWidth <= clientWidth) {+ if (el.style.clipPath) {+ el.style.clipPath = "";+ }+ return;+ }+ const right = Math.max(0, scrollWidth - scrollLeft - clientWidth);+ el.style.clipPath = `inset(0 ${right}px 0 ${scrollLeft}px)`;+};++const stickyScrollElMap = new WeakMap<HTMLElement, HTMLElement>();++const bindHeaderScrollSync = (blockElement: HTMLElement, scrollEl: HTMLElement) => {+ if (stickyScrollElMap.get(blockElement) === scrollEl) {+ return;+ }+ stickyScrollElMap.set(blockElement, scrollEl);+ const syncHeaders = () => {+ const x = -scrollEl.scrollLeft;+ blockElement.querySelectorAll(".av__row--header--fixed, .av__row--footer--fixed").forEach((el: HTMLElement) => {+ el.style.transform = `translateX(${x}px)`;+ applyFixedClip(el, scrollEl);+ });+ };+ scrollEl.addEventListener("scroll", syncHeaders, {passive: true});+ if (scrollEl.scrollLeft > 0) {+ syncHeaders();+ }+};++const addFixedRow = (item: HTMLElement, fixedClass: string, placeholderClass: string, height: number, width: number) => {+ item.classList.add(fixedClass);+ const placeholder = document.createElement("div");+ placeholder.className = placeholderClass;+ placeholder.style.height = height + "px";+ placeholder.style.width = width + "px";+ item.insertAdjacentElement("afterend", placeholder);+};++const removeFixedRow = (item: HTMLElement, fixedClass: string, placeholderClass: string) => {+ if (!item.classList.contains(fixedClass)) {+ return;+ }+ item.classList.remove(fixedClass);+ item.style.top = "";+ item.style.bottom = "";+ item.style.left = "";+ item.style.width = "";+ item.style.transform = "";+ item.style.clipPath = "";+ const next = item.nextElementSibling as HTMLElement;+ if (next?.classList.contains(placeholderClass)) {+ next.remove();+ }+};++const syncFixedRowPos = (item: HTMLElement, bodyRect: DOMRect, scrollLeft: number, scrollEl: HTMLElement) => {+ item.style.left = Math.round(bodyRect.left + scrollLeft) + "px";+ item.style.width = Math.round(bodyRect.width) + "px";+ item.style.transform = `translateX(${-scrollLeft}px)`;+ if (scrollEl) {+ applyFixedClip(item, scrollEl);+ }+};++export const stickyRow = (blockElement: HTMLElement, scrollElement: HTMLElement, status: "top" | "bottom" | "all") => {if (blockElement.dataset.avType !== "table") {return;}- // 只读模式下也需固定 https://github.com/siyuan-note/siyuan/issues/11338- const headerElements = blockElement.querySelectorAll(".av__row--header");- if (headerElements.length > 0 && (status === "top" || status === "all")) {- headerElements.forEach((item: HTMLElement) => {- const bodyRect = item.parentElement.getBoundingClientRect();- const distance = Math.floor(elementRect.top - bodyRect.top);- if (distance > 0 && distance < bodyRect.height - item.clientHeight) {- item.style.transform = `translateY(${distance}px)`;+ const elementRect = scrollElement.getBoundingClientRect();+ const scrollTop = scrollElement.scrollTop;+ const scrollEl = blockElement.querySelector(".av__scroll") as HTMLElement;+ if (scrollEl) {+ bindHeaderScrollSync(blockElement, scrollEl);+ }++ if (status === "top" || status === "all") {+ blockElement.querySelectorAll(".av__row--header").forEach((item: HTMLElement) => {+ const body = item.parentElement as HTMLElement;+ const bodyRect = body.getBoundingClientRect();+ const offset = Math.round(bodyRect.top - elementRect.top + scrollTop);+ const headerH = item.offsetHeight;+ const bodyH = body.offsetHeight;+ if (scrollTop > offset && scrollTop < offset + bodyH) {+ const scrollLeft = scrollEl ? scrollEl.scrollLeft : 0;+ if (!item.classList.contains("av__row--header--fixed")) {+ addFixedRow(item, "av__row--header--fixed", "av__row--header-placeholder", headerH, Math.round(bodyRect.width));+ }+ syncFixedRowPos(item, bodyRect, scrollLeft, scrollEl);+ const stickyTop = Math.round(elementRect.top);+ item.style.top = bodyRect.bottom < stickyTop + headerH+ ? Math.round(bodyRect.bottom - headerH) + "px"+ : stickyTop + "px";} else {- item.style.transform = "";+ removeFixedRow(item, "av__row--header--fixed", "av__row--header-placeholder");}});}- const footerElements = blockElement.querySelectorAll(".av__row--footer");- if (footerElements.length > 0 && (status === "bottom" || status === "all")) {- footerElements.forEach((item: HTMLElement) => {- if (item.querySelector(".av__calc--ashow")) {- const bodyRect = item.parentElement.getBoundingClientRect();- const distance = Math.ceil(elementRect.bottom - bodyRect.bottom);- if (distance < 0 && -distance < bodyRect.height - item.clientHeight) {- item.style.transform = `translateY(${distance}px)`;- } else {- item.style.transform = "";+ if (status === "bottom" || status === "all") {+ blockElement.querySelectorAll(".av__row--footer").forEach((item: HTMLElement) => {+ if (!item.querySelector(".av__calc--ashow")) {+ return;+ }+ const body = item.parentElement as HTMLElement;+ const bodyRect = body.getBoundingClientRect();+ const bottomInit = Math.round(bodyRect.bottom + scrollTop);+ const footerH = item.offsetHeight;+ const bodyH = body.offsetHeight;+ const bottomOffset = bottomInit - Math.round(elementRect.bottom);+ const footerDist = bottomInit - scrollTop - Math.round(elementRect.bottom);+ if (scrollTop < bottomOffset && footerDist < bodyH - footerH) {+ const scrollLeft = scrollEl ? scrollEl.scrollLeft : 0;+ if (!item.classList.contains("av__row--footer--fixed")) {+ addFixedRow(item, "av__row--footer--fixed", "av__row--footer-placeholder", footerH, Math.round(bodyRect.width));}+ syncFixedRowPos(item, bodyRect, scrollLeft, scrollEl);+ item.style.bottom = Math.round(window.innerHeight - elementRect.bottom) + "px";} else {- item.style.transform = "";+ removeFixedRow(item, "av__row--footer--fixed", "av__row--footer-placeholder");}});}@@ -595,7 +688,7 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {rowElements.forEach(item => {item.remove();});- stickyRow(blockElement, protyle.contentElement.getBoundingClientRect(), "all");+ stickyRow(blockElement, protyle.contentElement, "all");updateHeader(blockElement.querySelector(".av__row"));blockElement.setAttribute("updated", newUpdated);};diff --git a/app/src/protyle/scroll/event.ts b/app/src/protyle/scroll/event.tsindex f51d0060a7..f60bc60809 100644--- a/app/src/protyle/scroll/event.ts+++ b/app/src/protyle/scroll/event.ts@@ -26,7 +26,7 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {if (item.dataset.render !== "true") {return;}- stickyRow(item, elementRect, "all");+ stickyRow(item, element, "all");trimAVRows(item, elementRect);});diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex 72a32f3556..bc235c4d02 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -447,10 +447,9 @@ export const enableProtyle = (protyle: IProtyle) => {protyle.wysiwyg.element.querySelectorAll('.protyle-action[draggable="false"]').forEach(item => {item.setAttribute("draggable", "true");});- const contentRect = protyle.contentElement.getBoundingClientRect();protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => {if (item.querySelector(".av__scroll")) {- stickyRow(item, contentRect, "all");+ stickyRow(item, protyle.contentElement, "all");}});if (protyle.breadcrumb) {diff --git a/app/src/protyle/util/resize.ts b/app/src/protyle/util/resize.tsindex 5f2f4fe925..ecd19d0703 100644--- a/app/src/protyle/util/resize.ts+++ b/app/src/protyle/util/resize.ts@@ -57,10 +57,9 @@ export const resize = (protyle: IProtyle) => {protyle.scroll.element.parentElement.setAttribute("style", `--b3-dynamicscroll-width:${Math.min(protyle.contentElement.clientHeight - 49, 200)}px`);}if (!protyle.disabled) {- const contentRect = protyle.contentElement.getBoundingClientRect();protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => {if (item.querySelector(".av__scroll")) {- stickyRow(item, contentRect, "all");+ stickyRow(item, protyle.contentElement, "all");}});}diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex b0e91a25f3..82dfff7f9c 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -766,7 +766,7 @@ export class WYSIWYG {scrollElement.querySelectorAll(".av__row, .av__row--footer").forEach(item => {(item.querySelector(`[data-col-id="${dragColId}"]`) as HTMLElement).style.width = newWidth + "px";});- stickyRow(nodeElement, contentRect, "bottom");+ stickyRow(nodeElement, protyle.contentElement, "bottom");};documentSelf.onmouseup = () => {@@ -1808,10 +1808,9 @@ export class WYSIWYG {private bindEvent(protyle: IProtyle) {// 删除块时,av 头尾需重新计算位置protyle.observer = new ResizeObserver(() => {- const contentRect = protyle.contentElement.getBoundingClientRect();protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => {if (item.querySelector(".av__scroll")) {- stickyRow(item, contentRect, "all");+ stickyRow(item, protyle.contentElement, "all");}});});