Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Align pinned table corners with scroll viewport https://github.com/siyuan-note/siyuan/issues/18537

Daniel8db99e23e5b7
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 3fed886db1..2ea0e2d80a 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -763,6 +763,32 @@ table + .protyle-action__table {
transition: var(--b3-transition);
z-index: 3;
}
+
+ .table[custom-pinthead="true"] &::before {
+ --b3-table-frame-radius: var(--b3-border-radius-s);
+ position: absolute;
+ left: var(--b3-table-frame-left);
+ top: var(--b3-table-frame-top);
+ z-index: 2;
+ width: var(--b3-table-frame-width);
+ height: var(--b3-table-frame-height);
+ background-image: radial-gradient(circle var(--b3-table-frame-radius) at bottom right, transparent calc(100% - 1px), var(--b3-theme-surface-lighter) calc(100% - .5px), var(--b3-parent-background) 100%),
+ radial-gradient(circle var(--b3-table-frame-radius) at bottom left, transparent calc(100% - 1px), var(--b3-theme-surface-lighter) calc(100% - .5px), var(--b3-parent-background) 100%),
+ radial-gradient(circle var(--b3-table-frame-radius) at top right, transparent calc(100% - 1px), var(--b3-theme-surface-lighter) calc(100% - .5px), var(--b3-parent-background) 100%),
+ radial-gradient(circle var(--b3-table-frame-radius) at top left, transparent calc(100% - 1px), var(--b3-theme-surface-lighter) calc(100% - .5px), var(--b3-parent-background) 100%);
+ background-repeat: no-repeat;
+ background-position: top left, top right, bottom left, bottom right;
+ background-size: var(--b3-table-frame-radius) var(--b3-table-frame-radius);
+ content: "";
+ pointer-events: none;
+ }
+}
+
+.protyle-wysiwyg--select,
+.protyle-wysiwyg--hl {
+ .protyle-action__table::before {
+ display: none;
+ }
}
.protyle-table-control {
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 8c591abe4f..c9284fa541 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -560,7 +560,6 @@
max-height: 50vh;
overflow: auto;
border-radius: var(--b3-table-border-radius-top-left) var(--b3-table-border-radius-top-right) var(--b3-table-border-radius-bottom-right) var(--b3-table-border-radius-bottom-left);
- clip-path: inset(0 round var(--b3-table-border-radius-top-left) var(--b3-table-border-radius-top-right) var(--b3-table-border-radius-bottom-right) var(--b3-table-border-radius-bottom-left));
box-shadow: inset 0 -1px 0 var(--b3-theme-surface-lighter);
&::-webkit-scrollbar-track:vertical,
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index 42f8945850..aa519ed564 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -309,6 +309,8 @@ export class TableControl {
private suppressAddClick = false;
private bypassClipboardEvent = false;
private observer: MutationObserver;
+ private pinnedTableResizeObserver: ResizeObserver;
+ private pinnedTableActions = new Map<HTMLTableElement, HTMLElement>();
private abortController = new AbortController();
constructor(protyle: IProtyle, wysiwygElement: HTMLElement) {
@@ -347,7 +349,8 @@ export class TableControl {
this.dropIndicator = this.element.querySelector(".protyle-table-control__drop");
protyle.element.append(this.element);
this.bindEvents();
- this.observer = new MutationObserver(() => {
+ this.pinnedTableResizeObserver = new ResizeObserver(() => this.scheduleRender());
+ this.observer = new MutationObserver(mutations => {
if (this.resizeState && !this.resizeState.node.isConnected) {
this.resizeState = undefined;
this.resizeLabel.classList.add("fn__none");
@@ -366,17 +369,33 @@ export class TableControl {
this.caretCell = undefined;
render = true;
}
+ const pinnedTableSelector = '[data-type="NodeTable"][custom-pinthead="true"]';
+ if (mutations.some(mutation => mutation.type === "attributes" ||
+ (mutation.target instanceof Element && !!mutation.target.closest(pinnedTableSelector)) ||
+ [...mutation.addedNodes, ...mutation.removedNodes].some(node => node instanceof Element &&
+ (node.matches(pinnedTableSelector) || !!node.querySelector(pinnedTableSelector))))) {
+ render = true;
+ }
if (render) {
this.scheduleRender();
}
});
- this.observer.observe(this.wysiwygElement, {childList: true, subtree: true});
+ this.observer.observe(this.wysiwygElement, {
+ attributeFilter: ["custom-pinthead"],
+ attributes: true,
+ childList: true,
+ subtree: true,
+ });
+ this.scheduleRender();
}
public destroy() {
this.cancelResize();
this.abortController.abort();
this.observer.disconnect();
+ this.pinnedTableResizeObserver.disconnect();
+ this.pinnedTableActions.forEach(action => this.clearPinnedTableFrame(action));
+ this.pinnedTableActions.clear();
cancelAnimationFrame(this.frame);
this.element.remove();
}
@@ -1123,7 +1142,50 @@ export class TableControl {
this.resizeLabel.classList.remove("fn__none");
}
+ private clearPinnedTableFrame(action: HTMLElement) {
+ ["--b3-table-frame-left", "--b3-table-frame-top", "--b3-table-frame-width",
+ "--b3-table-frame-height"].forEach(name => action.style.removeProperty(name));
+ }
+
+ private renderPinnedTableFrames() {
+ const actions = new Map<HTMLTableElement, HTMLElement>();
+ this.wysiwygElement.querySelectorAll<HTMLTableElement>(
+ '[data-type="NodeTable"][custom-pinthead="true"] table').forEach(table => {
+ const action = table.nextElementSibling as HTMLElement;
+ if (!action?.classList.contains("protyle-action__table")) {
+ return;
+ }
+ const previousAction = this.pinnedTableActions.get(table);
+ if (previousAction !== action) {
+ if (previousAction) {
+ this.clearPinnedTableFrame(previousAction);
+ } else {
+ this.pinnedTableResizeObserver.observe(table);
+ }
+ }
+ actions.set(table, action);
+ const tableRect = table.getBoundingClientRect();
+ const actionRect = action.getBoundingClientRect();
+ action.style.setProperty("--b3-table-frame-left",
+ `${tableRect.left + table.clientLeft - actionRect.left}px`);
+ action.style.setProperty("--b3-table-frame-top",
+ `${tableRect.top + table.clientTop - actionRect.top}px`);
+ action.style.setProperty("--b3-table-frame-width", `${table.clientWidth}px`);
+ action.style.setProperty("--b3-table-frame-height", `${table.clientHeight}px`);
+ });
+ this.pinnedTableActions.forEach((action, table) => {
+ if (actions.get(table) !== action) {
+ this.clearPinnedTableFrame(action);
+ if (!actions.has(table)) {
+ this.pinnedTableResizeObserver.unobserve(table);
+ }
+ }
+ });
+ this.pinnedTableActions = actions;
+ }
+
private render() {
+ this.renderPinnedTableFrames();
if (this.resizeState?.dragging && this.resizeState.table.isConnected) {
this.renderResize();
return;