fix(editor): some UI bugs of table block (#9987)

close: BS-2507, BS-2508, BS-2511, BS-2519, BS-2523
This commit is contained in:
zzj3720
2025-02-06 15:42:05 +00:00
parent 7c7febd495
commit 1652e6df6b
4 changed files with 41 additions and 19 deletions

View File

@@ -4,10 +4,10 @@ import { style } from '@vanilla-extract/css';
export const addColumnButtonStyle = style({ export const addColumnButtonStyle = style({
cursor: 'col-resize', cursor: 'col-resize',
backgroundColor: cssVarV2.layer.background.hoverOverlay, backgroundColor: cssVarV2.layer.background.hoverOverlay,
fontSize: '10px', fontSize: '16px',
color: cssVarV2.icon.secondary, color: cssVarV2.icon.secondary,
display: 'flex', display: 'flex',
width: '12px', width: '16px',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
position: 'absolute', position: 'absolute',
@@ -30,10 +30,10 @@ export const addColumnButtonStyle = style({
export const addRowButtonStyle = style({ export const addRowButtonStyle = style({
cursor: 'row-resize', cursor: 'row-resize',
backgroundColor: cssVarV2.layer.background.hoverOverlay, backgroundColor: cssVarV2.layer.background.hoverOverlay,
fontSize: '10px', fontSize: '16px',
color: cssVarV2.icon.secondary, color: cssVarV2.icon.secondary,
display: 'flex', display: 'flex',
height: '12px', height: '16px',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
position: 'absolute', position: 'absolute',
@@ -56,11 +56,11 @@ export const addRowButtonStyle = style({
export const addRowColumnButtonStyle = style({ export const addRowColumnButtonStyle = style({
cursor: 'nwse-resize', cursor: 'nwse-resize',
backgroundColor: cssVarV2.layer.background.hoverOverlay, backgroundColor: cssVarV2.layer.background.hoverOverlay,
fontSize: '10px', fontSize: '16px',
color: cssVarV2.icon.secondary, color: cssVarV2.icon.secondary,
display: 'flex', display: 'flex',
width: '12px', width: '16px',
height: '12px', height: '16px',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
position: 'absolute', position: 'absolute',

View File

@@ -1,5 +1,5 @@
import { cssVar, cssVarV2 } from '@blocksuite/affine-shared/theme'; import { cssVar, cssVarV2 } from '@blocksuite/affine-shared/theme';
import { style } from '@vanilla-extract/css'; import { createVar, style } from '@vanilla-extract/css';
export const cellContainerStyle = style({ export const cellContainerStyle = style({
position: 'relative', position: 'relative',
@@ -22,11 +22,12 @@ export const columnOptionsCellStyle = style({
justifyContent: 'center', justifyContent: 'center',
}); });
const threePointerIconColorVar = createVar();
export const columnOptionsStyle = style({ export const columnOptionsStyle = style({
cursor: 'pointer', cursor: 'pointer',
zIndex: 2, zIndex: 2,
width: '22px', width: '28px',
height: '12px', height: '16px',
backgroundColor: cssVarV2.table.headerBackground.default, backgroundColor: cssVarV2.table.headerBackground.default,
borderRadius: '8px', borderRadius: '8px',
boxShadow: cssVar('buttonShadow'), boxShadow: cssVar('buttonShadow'),
@@ -35,6 +36,9 @@ export const columnOptionsStyle = style({
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
vars: {
[threePointerIconColorVar]: cssVarV2.icon.secondary,
},
selectors: { selectors: {
'&:hover': { '&:hover': {
opacity: 1, opacity: 1,
@@ -42,6 +46,9 @@ export const columnOptionsStyle = style({
'&.active': { '&.active': {
opacity: 1, opacity: 1,
backgroundColor: cssVarV2.table.indicator.activated, backgroundColor: cssVarV2.table.indicator.activated,
vars: {
[threePointerIconColorVar]: cssVarV2.table.indicator.pointerActive,
},
}, },
}, },
}); });
@@ -57,12 +64,11 @@ export const rowOptionsCellStyle = style({
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}); });
export const rowOptionsStyle = style({ export const rowOptionsStyle = style({
cursor: 'pointer', cursor: 'pointer',
zIndex: 2, zIndex: 2,
width: '12px', width: '16px',
height: '22px', height: '28px',
backgroundColor: cssVarV2.table.headerBackground.default, backgroundColor: cssVarV2.table.headerBackground.default,
borderRadius: '8px', borderRadius: '8px',
boxShadow: cssVar('buttonShadow'), boxShadow: cssVar('buttonShadow'),
@@ -71,6 +77,9 @@ export const rowOptionsStyle = style({
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
vars: {
[threePointerIconColorVar]: cssVarV2.icon.secondary,
},
selectors: { selectors: {
'&:hover': { '&:hover': {
opacity: 1, opacity: 1,
@@ -78,6 +87,9 @@ export const rowOptionsStyle = style({
'&.active': { '&.active': {
opacity: 1, opacity: 1,
backgroundColor: cssVarV2.table.indicator.activated, backgroundColor: cssVarV2.table.indicator.activated,
vars: {
[threePointerIconColorVar]: cssVarV2.table.indicator.pointerActive,
},
}, },
}, },
}); });
@@ -90,9 +102,9 @@ export const threePointerIconStyle = style({
}); });
export const threePointerIconDotStyle = style({ export const threePointerIconDotStyle = style({
width: '2px', width: '3px',
height: '2px', height: '3px',
backgroundColor: cssVarV2.icon.secondary, backgroundColor: threePointerIconColorVar,
borderRadius: '50%', borderRadius: '50%',
}); });

View File

@@ -435,6 +435,7 @@ export class TableCell extends SignalWatcher(
renderColumnOptions(column: TableColumn, columnIndex: number) { renderColumnOptions(column: TableColumn, columnIndex: number) {
const openColumnOptions = (e: Event) => { const openColumnOptions = (e: Event) => {
e.stopPropagation();
const element = e.currentTarget; const element = e.currentTarget;
if (element instanceof HTMLElement) { if (element instanceof HTMLElement) {
this.openColumnOptions( this.openColumnOptions(
@@ -461,6 +462,7 @@ export class TableCell extends SignalWatcher(
renderRowOptions(row: TableRow, rowIndex: number) { renderRowOptions(row: TableRow, rowIndex: number) {
const openRowOptions = (e: Event) => { const openRowOptions = (e: Event) => {
e.stopPropagation();
const element = e.currentTarget; const element = e.currentTarget;
if (element instanceof HTMLElement) { if (element instanceof HTMLElement) {
this.openRowOptions(popupTargetFromElement(element), row, rowIndex); this.openRowOptions(popupTargetFromElement(element), row, rowIndex);

View File

@@ -60,7 +60,12 @@ import {
} from '@blocksuite/affine-shared/utils'; } from '@blocksuite/affine-shared/utils';
import { viewPresets } from '@blocksuite/data-view/view-presets'; import { viewPresets } from '@blocksuite/data-view/view-presets';
import { assertType } from '@blocksuite/global/utils'; import { assertType } from '@blocksuite/global/utils';
import { DualLinkIcon, GroupingIcon, TeXIcon } from '@blocksuite/icons/lit'; import {
DualLinkIcon,
GroupingIcon,
TableIcon,
TeXIcon,
} from '@blocksuite/icons/lit';
import type { DeltaInsert } from '@blocksuite/inline'; import type { DeltaInsert } from '@blocksuite/inline';
import type { BlockModel } from '@blocksuite/store'; import type { BlockModel } from '@blocksuite/store';
import { Slice, Text } from '@blocksuite/store'; import { Slice, Text } from '@blocksuite/store';
@@ -259,8 +264,11 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
{ groupName: 'Content & Media' }, { groupName: 'Content & Media' },
{ {
name: 'Table', name: 'Table',
description: 'Create a table block.', description: 'Create a simple table.',
icon: DatabaseTableViewIcon20, icon: TableIcon({
width: '20',
height: '20',
}),
tooltip: slashMenuToolTips['Table View'], tooltip: slashMenuToolTips['Table View'],
showWhen: ({ model }) => !insideEdgelessText(model), showWhen: ({ model }) => !insideEdgelessText(model),
action: ({ rootComponent }) => { action: ({ rootComponent }) => {