Skip to content

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

:art: Join table handles with table corners https://github.com/siyuan-note/siyuan/issues/4785

Danielbe7c241eb11a
diff --git a/app/src/assets/scss/component/_typography.scss b/app/src/assets/scss/component/_typography.scss
index 5c90957e39..2d6d6a99eb 100644
--- a/app/src/assets/scss/component/_typography.scss
+++ b/app/src/assets/scss/component/_typography.scss
@@ -348,6 +348,18 @@
border-bottom-right-radius: 0;
}
+ &.protyle-table-control__table--handle-row-end {
+ border-bottom-left-radius: 0;
+ }
+
+ &.protyle-table-control__table--handle-column-start {
+ border-top-left-radius: 0;
+ }
+
+ &.protyle-table-control__table--handle-column-end {
+ border-top-right-radius: 0;
+ }
+
tr:nth-child(even) td {
background-color: var(--b3-table-even-background);
}
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 7498ee4516..be68df96db 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -809,6 +809,18 @@ table + .protyle-action__table {
cursor: grab;
}
+ &--row {
+ border-radius: var(--b3-border-radius-s) 0 0 var(--b3-border-radius-s);
+ }
+
+ &--row-first {
+ border-bottom-left-radius: 0;
+ }
+
+ &--column {
+ border-radius: var(--b3-border-radius-s) var(--b3-border-radius-s) 0 0;
+ }
+
&--drag-disabled {
cursor: pointer;
}
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index b20370dab7..8079671260 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -128,7 +128,7 @@ export class TableControl {
private cellHandle: HTMLButtonElement;
private addRowButton: HTMLButtonElement;
private addColumnButton: HTMLButtonElement;
- private addControlTable: HTMLTableElement;
+ private joinedControlTable: HTMLTableElement;
private dropIndicator: HTMLElement;
private selection: ITableSelection;
private hoverCell: HTMLTableCellElement;
@@ -190,7 +190,7 @@ export class TableControl {
this.abortController.abort();
this.observer.disconnect();
cancelAnimationFrame(this.frame);
- this.clearAddControlTable();
+ this.clearJoinedControlTable();
this.element.remove();
}
@@ -395,7 +395,7 @@ export class TableControl {
event.preventDefault();
event.stopPropagation();
if (type === "add-row" || type === "add-column") {
- this.clearAddControlTable();
+ this.clearJoinedControlTable();
this.addAtEnd(type);
return;
}
@@ -782,7 +782,7 @@ export class TableControl {
}
private render() {
- this.clearAddControlTable();
+ this.clearJoinedControlTable();
const cell = this.hoverCell?.isConnected ? this.hoverCell : this.selection?.activeCell;
const node = getTableNode(cell);
const table = cell?.closest("table") as HTMLTableElement;
@@ -817,9 +817,15 @@ export class TableControl {
this.rowHandle.style.width = `${TABLE_HANDLE_THICKNESS}px`;
this.rowHandle.style.height = `${visibleRowRect.height}px`;
const firstRow = rowIndex === 0;
+ const lastRow = rowIndex === table.rows.length - 1;
+ this.rowHandle.classList.toggle("protyle-table-control__handle--row-first", firstRow && !lastRow);
this.setPosition(this.rowHandle, viewportRect.left +
(firstRow ? TABLE_HANDLE_THICKNESS / 2 : -TABLE_HANDLE_THICKNESS / 2),
visibleRowRect.top + visibleRowRect.height / 2);
+ if (!firstRow && lastRow) {
+ table.classList.add("protyle-table-control__table--handle-row-end");
+ this.joinedControlTable = table;
+ }
}
if (this.hoverType === "column" && visibleColumnRect?.width > 0 && viewportRect.height > 0) {
this.columnHandle.classList.remove("fn__none");
@@ -827,6 +833,14 @@ export class TableControl {
this.columnHandle.style.height = `${TABLE_HANDLE_THICKNESS}px`;
this.setPosition(this.columnHandle, visibleColumnRect.left + visibleColumnRect.width / 2,
viewportRect.top - TABLE_HANDLE_THICKNESS / 2);
+ if (columnIndex === 0) {
+ table.classList.add("protyle-table-control__table--handle-column-start");
+ this.joinedControlTable = table;
+ }
+ if (columnIndex === grid.columnCount - 1) {
+ table.classList.add("protyle-table-control__table--handle-column-end");
+ this.joinedControlTable = table;
+ }
}
if (this.hoverType === "cell" && visibleCellRect.width > 0 && visibleCellRect.height > 0) {
this.cellHandle.classList.remove("fn__none");
@@ -841,7 +855,7 @@ export class TableControl {
this.setPosition(this.addRowButton, viewportRect.left + viewportRect.width / 2,
tableRect.bottom + TABLE_ADD_CONTROL_THICKNESS / 2);
table.classList.add("protyle-table-control__table--add-row");
- this.addControlTable = table;
+ this.joinedControlTable = table;
}
if (this.hoverType === "add-column" && viewportRect.height > 0 &&
tableRect.right <= viewportRect.right + 1 &&
@@ -852,7 +866,7 @@ export class TableControl {
this.setPosition(this.addColumnButton, tableRect.right + TABLE_ADD_CONTROL_THICKNESS / 2,
viewportRect.top + viewportRect.height / 2);
table.classList.add("protyle-table-control__table--add-column");
- this.addControlTable = table;
+ this.joinedControlTable = table;
}
}
this.selectionElementIndex = 0;
@@ -914,13 +928,15 @@ export class TableControl {
}
}
- private clearAddControlTable() {
- if (!this.addControlTable) {
+ private clearJoinedControlTable() {
+ if (!this.joinedControlTable) {
return;
}
- this.addControlTable.classList.remove("protyle-table-control__table--add-row",
- "protyle-table-control__table--add-column");
- this.addControlTable = undefined;
+ this.joinedControlTable.classList.remove("protyle-table-control__table--add-row",
+ "protyle-table-control__table--add-column", "protyle-table-control__table--handle-row-end",
+ "protyle-table-control__table--handle-column-start",
+ "protyle-table-control__table--handle-column-end");
+ this.joinedControlTable = undefined;
}
private openMenu(x: number, y: number) {
@@ -1571,6 +1587,7 @@ export class TableControl {
const state = this.dragState;
this.dropIndicator.classList.add("fn__none");
if (state.dragging && state.target >= 0) {
+ this.clearJoinedControlTable();
this.moveSelection(state.target);
event.preventDefault();
}