Skip to content

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

:art: Refine table edge control interactions https://github.com/siyuan-note/siyuan/issues/18489

Daniel0ec53f812050
diff --git a/app/src/assets/scss/component/_typography.scss b/app/src/assets/scss/component/_typography.scss
index 2d6d6a99eb..5c90957e39 100644
--- a/app/src/assets/scss/component/_typography.scss
+++ b/app/src/assets/scss/component/_typography.scss
@@ -348,18 +348,6 @@
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 4620d45530..c8117bdcbd 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -780,29 +780,49 @@ table + .protyle-action__table {
justify-content: center;
box-sizing: border-box;
padding: 0;
- color: var(--b3-theme-on-surface);
- background-color: var(--b3-theme-background);
- border: 1px solid var(--b3-border-color);
- border-radius: var(--b3-border-radius-s);
- box-shadow: var(--b3-point-shadow);
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, -50%);
-
- svg {
- width: 14px;
- height: 14px;
- }
-
- &:hover {
- color: var(--b3-theme-primary);
- background-image: linear-gradient(var(--b3-list-hover), var(--b3-list-hover));
- }
}
&__handle {
width: 24px;
height: 24px;
+ color: var(--b3-theme-on-primary);
+ background-color: transparent;
+ border: 0;
+ box-shadow: none;
+
+ &::before {
+ position: absolute;
+ content: "";
+ background-color: var(--b3-theme-on-surface-light);
+ border-radius: var(--b3-border-radius-b);
+ pointer-events: none;
+ }
+
+ svg {
+ box-sizing: border-box;
+ width: 16px;
+ height: 20px;
+ padding: 2px;
+ opacity: 0;
+ background-color: var(--b3-theme-primary);
+ border-radius: var(--b3-border-radius-s);
+ box-shadow: var(--b3-point-shadow);
+ transition: opacity 150ms linear;
+ }
+
+ &:hover,
+ &:focus-visible {
+ &::before {
+ opacity: 0;
+ }
+
+ svg {
+ opacity: 1;
+ }
+ }
&--row,
&--column {
@@ -810,15 +830,19 @@ table + .protyle-action__table {
}
&--row {
- border-radius: var(--b3-border-radius-s) 0 0 var(--b3-border-radius-s);
- }
-
- &--row-first {
- border-bottom-left-radius: 0;
+ &::before {
+ width: 3px;
+ height: 16px;
+ max-height: calc(100% - 4px);
+ }
}
&--column {
- border-radius: var(--b3-border-radius-s) var(--b3-border-radius-s) 0 0;
+ &::before {
+ width: 16px;
+ max-width: calc(100% - 4px);
+ height: 3px;
+ }
svg {
transform: rotate(90deg);
@@ -830,14 +854,34 @@ table + .protyle-action__table {
}
&--cell {
- width: 20px;
- height: 20px;
+ width: 16px;
+ height: 24px;
+
+ &::before {
+ width: 3px;
+ height: 16px;
+ }
}
}
&__add {
width: 24px;
height: 24px;
+ color: var(--b3-theme-on-surface);
+ background-color: var(--b3-theme-background);
+ border: 1px solid var(--b3-border-color);
+ border-radius: var(--b3-border-radius-s);
+ box-shadow: var(--b3-point-shadow);
+
+ svg {
+ width: 14px;
+ height: 14px;
+ }
+
+ &:hover {
+ color: var(--b3-theme-primary);
+ background-image: linear-gradient(var(--b3-list-hover), var(--b3-list-hover));
+ }
&--row {
border-radius: 0 0 var(--b3-border-radius-s) var(--b3-border-radius-s);
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 8189e1526b..1115136147 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -884,6 +884,11 @@
// 导出 html 不需要编辑样式
.protyle-wysiwyg[data-readonly="false"] {
+ &[contenteditable="true"] [data-node-id].table {
+ padding-right: 20px;
+ padding-bottom: 20px;
+ }
+
caption {
cursor: pointer;
}
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index c65f8de0c1..7f15b3c796 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -781,22 +781,21 @@ export class TableControl {
const rect = intersectRects(row.getBoundingClientRect(), viewportRect);
return rect.height > 0 && clientY >= rect.top && clientY <= rect.bottom;
});
- const firstRow = rowIndex === 0;
- const rowControlHovered = firstRow ?
- clientX >= viewportRect.left &&
- clientX <= Math.min(viewportRect.left + TABLE_EDGE_CONTROL_TRIGGER_SIZE, viewportRect.right) :
- clientX >= viewportRect.left - TABLE_HANDLE_THICKNESS && clientX <= viewportRect.left;
+ const rowControlHovered = clientX >= viewportRect.left - TABLE_EDGE_CONTROL_TRIGGER_SIZE / 2 &&
+ clientX <= Math.min(viewportRect.left + TABLE_EDGE_CONTROL_TRIGGER_SIZE / 2,
+ viewportRect.right);
const cell = rowControlHovered ? grid.grid[rowIndex]?.find(item => item) : undefined;
if (cell && rowIndex > -1) {
candidates.push({
cell,
type: "row",
- distance: firstRow ? clientX - viewportRect.left : viewportRect.left - clientX,
+ distance: Math.abs(viewportRect.left - clientX),
index: rowIndex,
});
}
}
- if (clientY >= viewportRect.top - TABLE_HANDLE_THICKNESS && clientY <= viewportRect.top &&
+ if (clientY >= viewportRect.top - TABLE_EDGE_CONTROL_TRIGGER_SIZE / 2 &&
+ clientY <= viewportRect.top + TABLE_EDGE_CONTROL_TRIGGER_SIZE / 2 &&
clientX >= viewportRect.left && clientX <= viewportRect.right) {
let columnIndex = -1;
for (let index = 0; index < grid.columnCount; index++) {
@@ -815,7 +814,7 @@ export class TableControl {
candidates.push({
cell,
type: "column",
- distance: viewportRect.top - clientY,
+ distance: Math.abs(viewportRect.top - clientY),
index: columnIndex,
});
}
@@ -902,40 +901,30 @@ export class TableControl {
(this.selection?.table === table && this.selection.mode === "row" &&
this.selection.indexes.size > 1 && this.selection.indexes.has(0)));
this.columnHandle.classList.toggle("protyle-table-control__handle--drag-disabled", merged);
- if (this.hoverType === "row" && visibleRowRect?.width > 0 && visibleRowRect.height > 0) {
+ if ((this.hoverType === "row" || this.hoverType === "cell") &&
+ visibleRowRect?.width > 0 && visibleRowRect.height > 0) {
this.rowHandle.classList.remove("fn__none");
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),
+ this.setPosition(this.rowHandle, viewportRect.left,
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) {
+ if ((this.hoverType === "column" || this.hoverType === "cell") &&
+ visibleColumnRect?.width > 0 && viewportRect.height > 0) {
this.columnHandle.classList.remove("fn__none");
this.columnHandle.style.width = `${visibleColumnRect.width}px`;
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;
- }
+ viewportRect.top);
}
if (!this.dragState && this.hoverType === "cell" &&
visibleCellRect.width > 0 && visibleCellRect.height > 0) {
this.cellHandle.classList.remove("fn__none");
- this.setPosition(this.cellHandle, visibleCellRect.right - 3, visibleCellRect.top + 3);
+ const nextToAddColumn = Math.abs(visibleCellRect.right - tableRect.right) <= 1 &&
+ tableRect.right <= viewportRect.right + 1;
+ this.setPosition(this.cellHandle, visibleCellRect.right -
+ (nextToAddColumn ? TABLE_EDGE_CONTROL_TRIGGER_SIZE / 2 : 0),
+ visibleCellRect.top + visibleCellRect.height / 2);
}
if (this.hoverType === "add-row" && viewportRect.width > 0 &&
addRowEdge >= contentRect.top && addRowEdge <= contentRect.bottom + 1) {
@@ -1023,9 +1012,7 @@ export class TableControl {
return;
}
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");
+ "protyle-table-control__table--add-column");
this.joinedControlTable = undefined;
}