diff --git a/.github/workflows/issue-automated.yml b/.github/workflows/issue-automated.yml index edd8e9cea7..da4a366e6f 100644 --- a/.github/workflows/issue-automated.yml +++ b/.github/workflows/issue-automated.yml @@ -17,6 +17,12 @@ permissions: jobs: issue-response: + if: >- + ${{ + github.event_name != 'issues' || + github.event.action != 'edited' || + github.event.issue.state == 'open' + }} runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/scripts/issue-automated.js b/.github/workflows/scripts/issue-automated.js index 84d3214e6f..c646b471a7 100644 --- a/.github/workflows/scripts/issue-automated.js +++ b/.github/workflows/scripts/issue-automated.js @@ -22,6 +22,15 @@ module.exports = async ({ github, core, context, issue }) => { const issueNumber = issue.number; const issueTitle = issue.title; + if ( + context.eventName === "issues" && + context.payload.action === "edited" && + issue.state === "closed" + ) { + core.info(`跳过已关闭 issue #${issueNumber} 的编辑事件`); + return; + } + core.info(`处理 issue #${issueNumber}: ${issueTitle}`); const { response, source } = await getAutomatedReply({ @@ -45,4 +54,3 @@ module.exports = async ({ github, core, context, issue }) => { core.error(error.stack); } }; - diff --git a/packages/s2-core/__tests__/spreadsheet/__snapshots__/theme-spec.ts.snap b/packages/s2-core/__tests__/spreadsheet/__snapshots__/theme-spec.ts.snap index a7087fa63a..fec9ff99e7 100644 --- a/packages/s2-core/__tests__/spreadsheet/__snapshots__/theme-spec.ts.snap +++ b/packages/s2-core/__tests__/spreadsheet/__snapshots__/theme-spec.ts.snap @@ -1764,6 +1764,594 @@ Object { } `; +exports[`SpreadSheet Theme Tests Theme Default Value Tests should get excel theme 1`] = ` +Object { + "background": Object { + "color": "#FFFFFF", + "opacity": 1, + }, + "colCell": Object { + "bolderText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "center", + "textBaseline": "middle", + }, + "cell": Object { + "backgroundColor": "#F3F2F1", + "backgroundColorOpacity": 1, + "borderDash": Array [], + "horizontalBorderColor": "#D4D4D4", + "horizontalBorderColorOpacity": 1, + "horizontalBorderWidth": 1, + "interactionState": Object { + "highlight": Object { + "backgroundColor": "#E2EFDA", + "backgroundOpacity": 1, + }, + "hover": Object { + "backgroundColor": "#E1DFDD", + "backgroundOpacity": 0.6, + }, + "prepareSelect": Object { + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "searchResult": Object { + "backgroundColor": "#FFFF00", + "backgroundOpacity": 1, + }, + "selected": Object { + "backgroundColor": "#E1DFDD", + "backgroundOpacity": 0.6, + }, + "unselected": Object { + "backgroundOpacity": 0.3, + "opacity": 0.3, + "textOpacity": 0.3, + }, + }, + "padding": Object { + "bottom": 8, + "left": 8, + "right": 8, + "top": 8, + }, + "verticalBorderColor": "#D4D4D4", + "verticalBorderColorOpacity": 1, + "verticalBorderWidth": 1, + }, + "icon": Object { + "fill": "#000000", + "margin": Object { + "bottom": 6, + "left": 4, + "right": 4, + "top": 6, + }, + "size": 10, + }, + "measureText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + "text": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "center", + "textBaseline": "middle", + }, + }, + "cornerCell": Object { + "bolderText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + "cell": Object { + "backgroundColor": "#F3F2F1", + "backgroundColorOpacity": 1, + "borderDash": Array [], + "horizontalBorderColor": "#D4D4D4", + "horizontalBorderColorOpacity": 1, + "horizontalBorderWidth": 1, + "interactionState": Object { + "highlight": Object { + "backgroundColor": "#E2EFDA", + "backgroundOpacity": 1, + }, + "hover": Object { + "backgroundColor": "#E1DFDD", + "backgroundOpacity": 0.6, + }, + "prepareSelect": Object { + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "searchResult": Object { + "backgroundColor": "#FFFF00", + "backgroundOpacity": 1, + }, + "selected": Object { + "backgroundColor": "#E1DFDD", + "backgroundOpacity": 0.6, + }, + "unselected": Object { + "backgroundOpacity": 0.3, + "opacity": 0.3, + "textOpacity": 0.3, + }, + }, + "padding": Object { + "bottom": 8, + "left": 8, + "right": 8, + "top": 8, + }, + "verticalBorderColor": "#D4D4D4", + "verticalBorderColorOpacity": 1, + "verticalBorderWidth": 1, + }, + "icon": Object { + "fill": "#000000", + "margin": Object { + "left": 4, + "right": 4, + }, + "size": 10, + }, + "measureText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "opacity": 1, + "textAlign": "left", + "textBaseline": "middle", + }, + "text": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "opacity": 1, + "textAlign": "left", + "textBaseline": "middle", + }, + }, + "dataCell": Object { + "bolderText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + "cell": Object { + "backgroundColor": "#FFFFFF", + "backgroundColorOpacity": 1, + "crossBackgroundColor": "#FFFFFF", + "horizontalBorderColor": "#D4D4D4", + "horizontalBorderColorOpacity": 1, + "horizontalBorderWidth": 1, + "interactionState": Object { + "highlight": Object { + "backgroundColor": "#E2EFDA", + "backgroundOpacity": 1, + }, + "hover": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "hoverFocus": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "prepareSelect": Object { + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "searchResult": Object { + "backgroundColor": "#FFFF00", + "backgroundOpacity": 1, + }, + "selected": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "unselected": Object { + "backgroundOpacity": 0.3, + "opacity": 0.3, + "textOpacity": 0.3, + }, + }, + "padding": Object { + "bottom": 8, + "left": 8, + "right": 8, + "top": 8, + }, + "verticalBorderColor": "#D4D4D4", + "verticalBorderColorOpacity": 1, + "verticalBorderWidth": 1, + }, + "icon": Object { + "fill": "#000000", + "margin": Object { + "left": 4, + "right": 4, + }, + "size": 10, + }, + "miniChart": Object { + "bar": Object { + "fill": "#0563C1", + "intervalPadding": 4, + "opacity": 1, + }, + "bullet": Object { + "backgroundColor": "#E9E9E9", + "comparativeMeasure": Object { + "fill": "#000000", + "height": 12, + "opacity": 0.25, + "width": 1, + }, + "progressBar": Object { + "height": 10, + "innerHeight": 6, + "widthPercent": 0.6, + }, + "rangeColors": Object { + "bad": "#FF0000", + "good": "#00B050", + "satisfactory": "#FFFF00", + }, + }, + "interval": Object { + "fill": "#217346", + "height": 12, + }, + "line": Object { + "linkLine": Object { + "fill": "#0563C1", + "opacity": 0.6, + "size": 1.5, + }, + "point": Object { + "fill": "#0563C1", + "opacity": 1, + "size": 2.2, + }, + }, + }, + "text": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + }, + "empty": Object { + "description": Object { + "fill": "#217346", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "opacity": 1, + }, + "icon": Object { + "fill": "", + "height": 41, + "margin": Object { + "bottom": 24, + "left": 0, + "right": 0, + "top": 0, + }, + "width": 64, + }, + }, + "mergedCell": Object { + "bolderText": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + "cell": Object { + "backgroundColor": "#FFFFFF", + "backgroundColorOpacity": 1, + "crossBackgroundColor": "#FFFFFF", + "horizontalBorderColor": "#D4D4D4", + "horizontalBorderColorOpacity": 1, + "horizontalBorderWidth": 1, + "interactionState": Object { + "highlight": Object { + "backgroundColor": "#E2EFDA", + "backgroundOpacity": 1, + }, + "hover": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "hoverFocus": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "prepareSelect": Object { + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "searchResult": Object { + "backgroundColor": "#FFFF00", + "backgroundOpacity": 1, + }, + "selected": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "unselected": Object { + "backgroundOpacity": 0.3, + "opacity": 0.3, + "textOpacity": 0.3, + }, + }, + "padding": Object { + "bottom": 8, + "left": 8, + "right": 8, + "top": 8, + }, + "verticalBorderColor": "#D4D4D4", + "verticalBorderColorOpacity": 1, + "verticalBorderWidth": 1, + }, + "icon": Object { + "fill": "#000000", + "margin": Object { + "left": 4, + "right": 4, + }, + "size": 10, + }, + "miniChart": Object { + "bar": Object { + "fill": "#0563C1", + "intervalPadding": 4, + "opacity": 1, + }, + "bullet": Object { + "backgroundColor": "#E9E9E9", + "comparativeMeasure": Object { + "fill": "#000000", + "height": 12, + "opacity": 0.25, + "width": 1, + }, + "progressBar": Object { + "height": 10, + "innerHeight": 6, + "widthPercent": 0.6, + }, + "rangeColors": Object { + "bad": "#FF0000", + "good": "#00B050", + "satisfactory": "#FFFF00", + }, + }, + "interval": Object { + "fill": "#217346", + "height": 12, + }, + "line": Object { + "linkLine": Object { + "fill": "#0563C1", + "opacity": 0.6, + "size": 1.5, + }, + "point": Object { + "fill": "#0563C1", + "opacity": 1, + "size": 2.2, + }, + }, + }, + "text": Object { + "fill": "#000000", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "right", + "textBaseline": "middle", + }, + }, + "prepareSelectMask": Object { + "backgroundColor": "#217346", + "backgroundOpacity": 0.3, + }, + "resizeArea": Object { + "background": "#217346", + "backgroundOpacity": 0, + "guideLineColor": "#217346", + "guideLineDash": Array [ + 3, + 3, + ], + "guideLineDisableColor": "rgba(0,0,0,0.25)", + "interactionState": Object { + "hover": Object { + "backgroundColor": "#217346", + "backgroundOpacity": 1, + }, + }, + "size": 3, + }, + "rowCell": Object { + "bolderText": Object { + "fill": "#217346", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": 700, + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "left", + "textBaseline": "middle", + }, + "cell": Object { + "backgroundColor": "#FFFFFF", + "backgroundColorOpacity": 1, + "borderDash": Array [], + "horizontalBorderColor": "#D4D4D4", + "horizontalBorderColorOpacity": 1, + "horizontalBorderWidth": 1, + "interactionState": Object { + "highlight": Object { + "backgroundColor": "#E2EFDA", + "backgroundOpacity": 1, + }, + "hover": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "prepareSelect": Object { + "borderColor": "#217346", + "borderOpacity": 1, + "borderWidth": 1, + }, + "searchResult": Object { + "backgroundColor": "#FFFF00", + "backgroundOpacity": 1, + }, + "selected": Object { + "backgroundColor": "#F2F2F2", + "backgroundOpacity": 0.6, + }, + "unselected": Object { + "backgroundOpacity": 0.3, + "opacity": 0.3, + "textOpacity": 0.3, + }, + }, + "padding": Object { + "bottom": 8, + "left": 8, + "right": 8, + "top": 8, + }, + "verticalBorderColor": "#D4D4D4", + "verticalBorderColorOpacity": 1, + "verticalBorderWidth": 1, + }, + "icon": Object { + "fill": "#217346", + "margin": Object { + "left": 4, + "right": 4, + }, + "size": 10, + }, + "measureText": Object { + "fill": "#217346", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "left", + "textBaseline": "middle", + }, + "seriesNumberWidth": 80, + "seriesText": Object { + "fill": "#217346", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "center", + "textBaseline": "middle", + }, + "text": Object { + "fill": "#217346", + "fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif", + "fontSize": 12, + "fontWeight": "normal", + "linkTextFill": "#0563C1", + "opacity": 1, + "textAlign": "left", + "textBaseline": "middle", + }, + }, + "scrollBar": Object { + "hoverSize": 8, + "lineCap": "round", + "size": 6, + "thumbColor": "rgba(0,0,0,0.15)", + "thumbHorizontalMinSize": 32, + "thumbHoverColor": "rgba(0,0,0,0.25)", + "thumbVerticalMinSize": 32, + "trackColor": "rgba(0,0,0,0.01)", + }, + "splitLine": Object { + "borderDash": Array [], + "horizontalBorderColor": "#217346", + "horizontalBorderColorOpacity": 0.2, + "horizontalBorderWidth": 2, + "shadowColors": Object { + "left": "rgba(0,0,0,0.1)", + "right": "rgba(0,0,0,0)", + }, + "shadowWidth": 8, + "showShadow": true, + "verticalBorderColor": "#217346", + "verticalBorderColorOpacity": 0.25, + "verticalBorderWidth": 2, + }, +} +`; + exports[`SpreadSheet Theme Tests Theme Default Value Tests should get gray theme 1`] = ` Object { "background": Object { diff --git a/packages/s2-core/__tests__/spreadsheet/theme-spec.ts b/packages/s2-core/__tests__/spreadsheet/theme-spec.ts index 1bccef59be..e37f961e2c 100644 --- a/packages/s2-core/__tests__/spreadsheet/theme-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/theme-spec.ts @@ -71,7 +71,7 @@ describe('SpreadSheet Theme Tests', () => { expect(tableSheet.theme).toMatchSnapshot(); }); - test.each(['dark', 'gray', 'colorful', 'default'] as ThemeName[])( + test.each(['dark', 'gray', 'colorful', 'default', 'excel'] as ThemeName[])( 'should get %s theme', (name) => { s2.setThemeCfg({ diff --git a/packages/s2-core/__tests__/unit/utils/__snapshots__/theme-spec.ts.snap b/packages/s2-core/__tests__/unit/utils/__snapshots__/theme-spec.ts.snap index 40f1746e59..92c274ab9d 100644 --- a/packages/s2-core/__tests__/unit/utils/__snapshots__/theme-spec.ts.snap +++ b/packages/s2-core/__tests__/unit/utils/__snapshots__/theme-spec.ts.snap @@ -311,3 +311,36 @@ Object { }, } `; + +exports[`Theme Utils Tests should get correctly palette 5`] = ` +Object { + "basicColorRelations": Array [], + "basicColors": Array [ + "#000000", + "#FFFFFF", + "#F2F2F2", + "#F3F2F1", + "#E1DFDD", + "#217346", + "#0563C1", + "#217346", + "#FFFFFF", + "#D4D4D4", + "#D4D4D4", + "#217346", + "#217346", + "#000000", + "#217346", + ], + "brandColor": "#217346", + "others": Object { + "highlight": "#E2EFDA", + "results": "#FFFF00", + }, + "semanticColors": Object { + "green": "#00B050", + "red": "#FF0000", + "yellow": "#FFFF00", + }, +} +`; diff --git a/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts b/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts index ee875a6d41..a23483b5f9 100644 --- a/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/g-mini-charts-spec.ts @@ -394,11 +394,19 @@ describe('Render Chart Shape Tests', () => { }); test('should render bar shape', () => { + const originalRectCount = cell + .getChildren() + .filter((shape) => shape.get('type') === 'rect').length; + drawBar(getChartData(MiniChartType.Bar), cell); - expect( - cell.getChildren().filter((shape) => shape.get('type') === 'rect'), - ).toHaveLength(9); + const currentRectCount = cell + .getChildren() + .filter((shape) => shape.get('type') === 'rect').length; + + expect(currentRectCount - originalRectCount).toBe( + getChartData(MiniChartType.Bar).data.length, + ); }); test('should render bullet shape', () => { diff --git a/packages/s2-core/__tests__/unit/utils/theme-spec.ts b/packages/s2-core/__tests__/unit/utils/theme-spec.ts index 13a548538b..83c5d956b6 100644 --- a/packages/s2-core/__tests__/unit/utils/theme-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/theme-spec.ts @@ -6,5 +6,6 @@ describe('Theme Utils Tests', () => { expect(getPalette('default')).toMatchSnapshot(); expect(getPalette('colorful')).toMatchSnapshot(); expect(getPalette('gray')).toMatchSnapshot(); + expect(getPalette('excel')).toMatchSnapshot(); }); }); diff --git a/packages/s2-core/src/cell/base-cell.ts b/packages/s2-core/src/cell/base-cell.ts index 723cdfb393..782da9e5da 100644 --- a/packages/s2-core/src/cell/base-cell.ts +++ b/packages/s2-core/src/cell/base-cell.ts @@ -8,7 +8,7 @@ import type { Text, TextStyleProps, } from '@antv/g'; -import { Group, RectStyleProps } from '@antv/g'; +import { Group, Path, RectStyleProps } from '@antv/g'; import { each, get, @@ -427,15 +427,93 @@ export abstract class BaseCell extends Group { }); } + protected getSelectionPath( + bbox: { x: number; y: number; width: number; height: number }, + borderWidth = 1, + ): string { + const { x, y, width, height } = bbox; + const activeCells = this.spreadsheet.interaction.getActiveCells(); + const halfSize = borderWidth / 2; + const px = x + halfSize; + const py = y + halfSize; + const pw = width - borderWidth; + const ph = height - borderWidth; + + if (activeCells.length <= 1) { + return `M ${px} ${py} L ${px + pw} ${py} L ${px + pw} ${py + ph} L ${px} ${py + ph} Z`; + } + + const sameTypeCells = activeCells.filter( + (c) => c.cellType === this.cellType, + ); + + if (sameTypeCells.length <= 1) { + return `M ${px} ${py} L ${px + pw} ${py} L ${px + pw} ${py + ph} L ${px} ${py + ph} Z`; + } + + const meta = this.meta as any; + + if (!meta || meta.rowIndex == null || meta.colIndex == null) { + return `M ${px} ${py} L ${px + pw} ${py} L ${px + pw} ${py + ph} L ${px} ${py + ph} Z`; + } + + const { rowIndex, colIndex } = meta; + + const isTop = !sameTypeCells.some( + (c) => + (c.getMeta() as any).rowIndex === rowIndex - 1 && + (c.getMeta() as any).colIndex === colIndex, + ); + const isBottom = !sameTypeCells.some( + (c) => + (c.getMeta() as any).rowIndex === rowIndex + 1 && + (c.getMeta() as any).colIndex === colIndex, + ); + const isLeft = !sameTypeCells.some( + (c) => + (c.getMeta() as any).rowIndex === rowIndex && + (c.getMeta() as any).colIndex === colIndex - 1, + ); + const isRight = !sameTypeCells.some( + (c) => + (c.getMeta() as any).rowIndex === rowIndex && + (c.getMeta() as any).colIndex === colIndex + 1, + ); + + let path = ''; + + if (isTop) { + path += `M ${px} ${py} L ${px + pw} ${py} `; + } + + if (isBottom) { + path += `M ${px} ${py + ph} L ${px + pw} ${py + ph} `; + } + + if (isLeft) { + path += `M ${px} ${py} L ${px} ${py + ph} `; + } + + if (isRight) { + path += `M ${px + pw} ${py} L ${px + pw} ${py + ph} `; + } + + return path || 'M 0 0'; + } + /** * 绘制 hover 悬停,刷选的外框 */ protected drawInteractiveBorderShape() { + const { x, y, width, height } = this.getBBoxByType(CellClipBox.PADDING_BOX); + const defaultPath = `M ${x + 0.5} ${y + 0.5} L ${x + width - 0.5} ${y + 0.5} L ${x + width - 0.5} ${y + height - 0.5} L ${x + 0.5} ${y + height - 0.5} Z`; + const style = { - ...this.getBBoxByType(CellClipBox.PADDING_BOX), + d: defaultPath, + fill: 'transparent', visibility: 'hidden', pointerEvents: 'none', - } as RectStyleProps; + } as any; const interactiveBorderShape = this.stateShapes.get( 'interactiveBorderShape', @@ -444,7 +522,13 @@ export abstract class BaseCell extends Group { if (interactiveBorderShape) { batchSetStyle(interactiveBorderShape, style); } else { - this.stateShapes.set('interactiveBorderShape', renderRect(this, style)); + const pathShape = this.appendChild( + new Path({ + style, + }), + ); + + this.stateShapes.set('interactiveBorderShape', pathShape); } } @@ -669,16 +753,27 @@ export abstract class BaseCell extends Group { }); } - // 根据 borderWidth 更新 borderShape 大小 https://github.com/antvis/S2/pull/705 + // 根据 borderWidth/path 更新 borderShape 大小 https://github.com/antvis/S2/pull/705 if ( shapeName === 'interactiveBorderShape' && styleKey === 'borderWidth' ) { if (isNumber(style)) { - const marginStyle = this.getInteractiveBorderShapeStyle(style); - - each(marginStyle, (currentStyle, currentStyleKey) => { - updateShapeAttr(shapes, currentStyleKey, currentStyle); + const borderWidth = style; + const { x, y, width, height } = this.getBBoxByType( + CellClipBox.PADDING_BOX, + ); + const pathStr = + stateName === 'selected' || stateName === 'hoverFocus' + ? this.getSelectionPath({ x, y, width, height }, borderWidth) + : `M ${x + borderWidth / 2} ${y + borderWidth / 2} L ${ + x + width - borderWidth / 2 + } ${y + borderWidth / 2} L ${x + width - borderWidth / 2} ${ + y + height - borderWidth / 2 + } L ${x + borderWidth / 2} ${y + height - borderWidth / 2} Z`; + + shapes.forEach((shape) => { + shape?.setAttribute('d', pathStr); }); } } diff --git a/packages/s2-core/src/common/constant/theme.ts b/packages/s2-core/src/common/constant/theme.ts index 56d6c82aee..ed1f5dd431 100644 --- a/packages/s2-core/src/common/constant/theme.ts +++ b/packages/s2-core/src/common/constant/theme.ts @@ -1,6 +1,7 @@ import { paletteColorful } from '../../theme/palette/colorful'; import { paletteDark } from '../../theme/palette/dark'; import { paletteDefault } from '../../theme/palette/default'; +import { paletteExcel } from '../../theme/palette/excel'; import { paletteGray } from '../../theme/palette/gray'; import type { ThemeName } from '../interface'; import { S2_PREFIX_CLS } from './classnames'; @@ -10,6 +11,7 @@ export const PALETTE_MAP = { colorful: paletteColorful, gray: paletteGray, dark: paletteDark, + excel: paletteExcel, } as const; /** @@ -34,6 +36,7 @@ export const G2_THEME_TYPE: Record = { colorful: 'light', gray: 'light', dark: 'dark', + excel: 'light', }; export const CELL_PADDING = 8; diff --git a/packages/s2-core/src/common/interface/theme.ts b/packages/s2-core/src/common/interface/theme.ts index 4cd57550f7..1c21336d0d 100644 --- a/packages/s2-core/src/common/interface/theme.ts +++ b/packages/s2-core/src/common/interface/theme.ts @@ -1,6 +1,7 @@ import type { LineStyleProps, TextStyleProps } from '@antv/g'; import type { Omit } from 'lodash'; import type { CellType } from '../../common/constant/interaction'; +import type { SpreadSheet } from '../../sheet-type'; import type { InteractionStateName } from '../constant'; import type { PALETTE_MAP } from '../constant/theme'; import type { DeepRequired } from './type-utils'; @@ -375,6 +376,12 @@ export interface ThemeCfg { /** 主题名 */ name?: ThemeName; + + /** 自定义主题 */ + getCustomTheme?: ( + palette: SimplePalette, + spreadsheet?: SpreadSheet, + ) => S2Theme; } /** 子弹图状态颜色 */ diff --git a/packages/s2-core/src/sheet-type/spread-sheet.ts b/packages/s2-core/src/sheet-type/spread-sheet.ts index 23910d8884..d5102e7170 100644 --- a/packages/s2-core/src/sheet-type/spread-sheet.ts +++ b/packages/s2-core/src/sheet-type/spread-sheet.ts @@ -596,7 +596,7 @@ export abstract class SpreadSheet extends EE { const newTheme = getTheme({ ...themeCfg, spreadsheet: this, - getCustomTheme, + getCustomTheme: getCustomTheme || themeCfg?.getCustomTheme, }); this.theme = customMerge(newTheme, theme); diff --git a/packages/s2-core/src/theme/palette/excel.ts b/packages/s2-core/src/theme/palette/excel.ts new file mode 100644 index 0000000000..8b4824d014 --- /dev/null +++ b/packages/s2-core/src/theme/palette/excel.ts @@ -0,0 +1,73 @@ +import type { Palette } from '../../common'; + +/** + * Microsoft Excel style palette + * Replicates the default visual style of Microsoft Excel spreadsheets + */ +export const paletteExcel: Palette = { + // Excel's primary accent color (green) + brandColor: '#217346', + // Semantic colors for conditional formatting + semanticColors: { + red: '#FF0000', + green: '#00B050', + yellow: '#FFFF00', + }, + others: { + // Search results highlight + results: '#FFFF00', + // Cell highlight + highlight: '#E2EFDA', + }, + /** + * Basic colors mapping for Excel theme: + * 0: Corner header text, column header text (#000000 - black) + * 1: Row header background, data cell background zebra (#FFFFFF - white) + * 2: Row & data cell interactions hover/selected (#F2F2F2 - Excel light gray hover) + * 3: Corner header background, column header background (#E6E6E6 - Excel gray header) + * 4: Column header interaction hover/selected (#D9D9D9 - Excel header hover gray) + * 5: Brush selection mask (#217346 - Excel green) + * 6: Row header link (#0563C1 - Excel hyperlink blue) + * 7: Mini bar, resize interaction (#217346 - Excel green) + * 8: Data cell background (non-zebra), table background (#FFFFFF - white) + * 9: Row header border, data cell border (#D4D4D4 - Excel gridline gray) + * 10: Corner header border, column header border (#B4B4B4 - darker gray for header) + * 11: Vertical split line (#217346 - Excel green) + * 12: Horizontal split line (#217346 - Excel green) + * 13: Data cell text (#000000 - black) + * 14: Row header text, hover/selection border color (#217346 - Excel green for selection border) + */ + basicColors: [ + // 0: header text color + '#000000', + // 1: row header bg / data cell zebra bg + '#FFFFFF', + // 2: row & data cell interaction (hover, selected) - Excel light gray + '#F2F2F2', + // 3: corner/col header background + '#F3F2F1', + // 4: col header interaction (hover, selected) - Excel header hover gray + '#E1DFDD', + // 5: brush selection mask + '#217346', + // 6: link color (Excel hyperlink blue) + '#0563C1', + // 7: mini bar, resize guide line (Excel green) + '#217346', + // 8: data cell bg / table background + '#FFFFFF', + // 9: row header border, data cell border (Excel gridline) + '#D4D4D4', + // 10: corner/col header border + '#D4D4D4', + // 11: vertical split line + '#217346', + // 12: horizontal split line + '#217346', + // 13: data cell text + '#000000', + // 14: row header text, hover/selection border color (Excel green) + '#217346', + ], + basicColorRelations: [], +}; diff --git a/packages/s2-react/playground/index.tsx b/packages/s2-react/playground/index.tsx index a8219debcb..59060ecc1f 100644 --- a/packages/s2-react/playground/index.tsx +++ b/packages/s2-react/playground/index.tsx @@ -1,1785 +1,1401 @@ -/* eslint-disable no-underscore-dangle */ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -/* eslint-disable no-console */ -import { - DARK_THEME_CLS, - DEFAULT_FROZEN_COUNTS, - DEFAULT_STYLE, - Node, +/* eslint-disable max-classes-per-file */ +import { CheckCircleOutlined, UndoOutlined } from '@ant-design/icons'; +import type { + S2CellType, + S2DataConfig, + SimplePalette, SpreadSheet, - customMerge, - generatePalette, - getDefaultSeriesNumberText, - getPalette, - safeJsonParse, - type Adaptive, - type CustomHeaderFields, - type HeaderActionIconProps, - type InteractionCellHighlightOptions, - type InteractionOptions, - type S2DataConfig, - type SheetType, - type TargetCellInfo, - type ThemeCfg, - type TooltipAutoAdjustBoundary, + ViewMeta, } from '@antv/s2'; -import '@antv/s2/src/styles/theme/dark.css'; -import { useUpdateEffect } from 'ahooks'; import { - Button, - Collapse, - DatePicker, - Divider, - Input, - InputNumber, - Pagination, - Popover, - Radio, - Select, - Slider, - Space, - Switch, - Tabs, - Tooltip, - type RadioChangeEvent, -} from 'antd'; -import cls from 'classnames'; -import { debounce, isEmpty, random } from 'lodash'; -import React from 'react'; -import { ChromePicker } from 'react-color'; -import type { SheetComponentOptions } from '../src'; + CellClipBox, + CellType, + InteractionStateName, + KEY_GROUP_COL_RESIZE_AREA, + KEY_GROUP_ROW_RESIZE_AREA, + S2Event, + SERIES_NUMBER_FIELD, + TableColCell, + TableCornerCell, + TableDataCell, + TableSeriesNumberCell, +} from '@antv/s2'; +import { Button, Card, Switch, Tag, Typography } from 'antd'; +import React, { useMemo, useRef, useState } from 'react'; +import type { SheetComponentOptions, SheetComponentProps } from '../src'; import { SheetComponent } from '../src'; import { reactRender } from '../src/utils/reactRender'; -import { BigDataSheet } from './components/BigDataSheet'; -import { ChartSheet } from './components/ChartSheet'; -import { PlaygroundSheetConfigProvider } from './components/ConfigProvider'; -import { CustomGrid } from './components/CustomGrid'; -import { CustomTree } from './components/CustomTree'; -import { EditableSheet } from './components/EditableSheet'; -import { GridAnalysisSheet } from './components/GridAnalysisSheet'; -import { PlaygroundSheetHeader } from './components/Header'; -import { LinkGroup } from './components/LinkGroup'; -import { PivotChartSheet } from './components/PivotChartSheet'; -import { PluginsSheet } from './components/Plugins'; -import { ResizeConfig } from './components/ResizeConfig'; -import { StickyHeaderSheet } from './components/StickyHeaderSheet'; -import { StrategySheet } from './components/StrategySheet'; -import { - PivotSheetFrozenOptions, - TableSheetFrozenOptions, - defaultOptions, - headerActionIcons, - pivotSheetDataCfg, - pivotSheetDataCfgForCompactMode, - pivotSheetMultiLineTextDataCfg, - s2ConditionsOptions, - s2Options, - s2ThemeConfig, - sliderOptions, - tableSheetDataCfg, - tableSheetMultipleColumns, - tableSheetSingleColumns, -} from './config'; -import { PlaygroundContext } from './context/playground.context'; -import { partDrillDown } from './drill-down'; import './index.less'; -import { onSheetMounted } from './utils'; -type TableSheetColumnType = 'single' | 'multiple'; +const { Text, Title } = Typography; +const EXCEL_ACTIVE_COLOR = '#217346'; +const EXCEL_HEADER_SELECTED_BACKGROUND = '#C0DAC9'; +const EXCEL_HEADER_HOVER_BACKGROUND = '#A2C7AE'; +const EXCEL_ROW_COL_SELECTED_BACKGROUND = '#c6c6c6'; +const EXCEL_ROW_COL_SELECTION_BORDER_ID = 'excel-row-col-selection-border'; +const EXCEL_CORNER_DIAGONAL_ID = 'excel-corner-diagonal'; +const EXCEL_CORNER_UPPER_BACKGROUND_ID = 'excel-corner-upper-background'; +const EXCEL_CORNER_LOWER_BACKGROUND_ID = 'excel-corner-lower-background'; +const EXCEL_CORNER_UPPER_BACKGROUND = '#F8F8F8'; +const EXCEL_CORNER_LOWER_BACKGROUND = '#DFDFDF'; +const EXCEL_CORNER_LOWER_HOVER_BACKGROUND = '#9E9E9E'; +const EXCEL_SERIES_NUMBER_MIN_WIDTH = 32; -const CustomTooltip = () => ( -
- 自定义 Tooltip
1
-
我很宽很长
- node.parentElement!} /> -
-); +function setExcelCellCursor(shape?: unknown) { + ( + shape as + | { + setAttribute: (name: 'cursor', value: 'cell') => void; + } + | undefined + )?.setAttribute('cursor', 'cell'); +} -const CustomColTooltip = () =>
custom colTooltip
; +function setShapeFillOpacity(shape: unknown, fillOpacity: number) { + ( + shape as + | { + setAttribute: (name: 'fillOpacity', value: number) => void; + } + | undefined + )?.setAttribute('fillOpacity', fillOpacity); +} -const ActionIconTooltip = ({ name }: { name: React.ReactNode }) => ( -
{name} Tooltip
-); +class ExcelDataCell extends TableDataCell { + protected drawBackgroundShape() { + super.drawBackgroundShape(); + setExcelCellCursor(this.backgroundShape); + } -function MainLayout() { - // ================== State ======================== - const [render, setRender] = React.useState(true); - const [sheetType, setSheetType] = React.useState( - (localStorage.getItem('debugSheetType') as SheetType) || 'pivot', - ); - const [showPagination, setShowPagination] = React.useState(false); - const [showTotals, setShowTotals] = React.useState(false); - const [themeCfg, setThemeCfg] = React.useState(s2ThemeConfig); - const [themeColor, setThemeColor] = React.useState('#FFF'); - const [showCustomTooltip, setShowCustomTooltip] = React.useState(false); - const [adaptive, setAdaptive] = React.useState(false); - const [options, setOptions] = - React.useState>(defaultOptions); - const [dataCfg, setDataCfg] = React.useState>( - sheetType === 'pivot' ? pivotSheetDataCfg : tableSheetDataCfg, - ); - const [columnOptions, setColumnOptions] = React.useState( - [], - ); - const [tableSheetColumnType, setTableSheetColumnType] = - React.useState( - (localStorage.getItem( - 'debugTableSheetColumnType', - ) as TableSheetColumnType) || 'single', + protected afterDrawText() { + super.afterDrawText(); + setExcelCellCursor(this.textShape); + this.textShapes?.forEach((shape) => { + setExcelCellCursor(shape); + }); + } + + private getRowColSelectionType() { + const selectedCells = this.spreadsheet.interaction.getCells(); + + if ( + selectedCells.length && + selectedCells.every((cell) => cell.type === CellType.ROW_CELL) + ) { + return CellType.ROW_CELL; + } + + if ( + selectedCells.length && + selectedCells.every((cell) => cell.type === CellType.COL_CELL) + ) { + return CellType.COL_CELL; + } + } + + private isCellInRowColSelection(cell: S2CellType, selectionType: CellType) { + const meta = cell.getMeta(); + const { cells = [], nodes = [] } = this.spreadsheet.interaction.getState(); + const selectedItems = [...nodes, ...cells]; + + if (selectionType === CellType.ROW_CELL) { + return selectedItems.some((item) => item.rowIndex === meta.rowIndex); + } + + if (this.spreadsheet.isTableMode() && nodes.length) { + const leafNodes = nodes[0]?.hierarchy?.getLeaves?.() ?? []; + + return leafNodes.some((node, index) => { + return nodes.includes(node) && index === meta.colIndex; + }); + } + + return selectedItems.some((item) => item.colIndex === meta.colIndex); + } + + private getSelectedDataCells(selectionType: CellType) { + return ( + this.spreadsheet.facet?.getCells().filter((cell) => { + const meta = cell.getMeta(); + + return ( + cell.cellType === CellType.DATA_CELL && + meta.valueField !== SERIES_NUMBER_FIELD && + this.isCellInRowColSelection(cell, selectionType) + ); + }) ?? [] ); + } - // ================== Refs ======================== - const s2Ref = React.useRef(null); - const scrollTimer = React.useRef(); + private getBrushSelectedDataCells() { + const selectedCells = this.spreadsheet.interaction.getCells([ + CellType.DATA_CELL, + ]); + const currentStateName = this.spreadsheet.interaction.getCurrentStateName(); + const isDataCellBrushSelectionState = [ + InteractionStateName.DATA_CELL_BRUSH_SELECTED, + InteractionStateName.PREPARE_SELECT, + ].includes(currentStateName as InteractionStateName); - // ================== Callback ======================== - const updateOptions = (newOptions: Partial) => { - setOptions(customMerge(options, newOptions)); - }; + if (!isDataCellBrushSelectionState || !selectedCells.length) { + return []; + } - const updateDataCfg = (newDataCfg: Partial) => { - const currentDataCfg = - sheetType === 'pivot' ? pivotSheetDataCfg : tableSheetDataCfg; + const selectedCellIds = new Set(selectedCells.map((cell) => cell.id)); - setDataCfg(customMerge(currentDataCfg, newDataCfg)); - }; + return ( + this.spreadsheet.facet?.getCells().filter((cell) => { + const meta = cell.getMeta(); - const onAutoAdjustBoundaryChange = (value: TooltipAutoAdjustBoundary) => { - updateOptions({ - tooltip: { - autoAdjustBoundary: value || null, - }, - }); - }; + return ( + cell.cellType === CellType.DATA_CELL && + meta.valueField !== SERIES_NUMBER_FIELD && + selectedCellIds.has(meta.id) + ); + }) ?? [] + ); + } - const onOverscrollBehaviorChange = ( - overscrollBehavior: InteractionOptions['overscrollBehavior'], - ) => { - updateOptions({ - interaction: { - overscrollBehavior, - }, + private hideRowColSelectionBorder() { + this.spreadsheet.facet?.foregroundGroup + ?.getElementById(EXCEL_ROW_COL_SELECTION_BORDER_ID) + ?.setAttribute('visibility', 'hidden'); + } + + private updateSelectedDataCellsStyle(selectedDataCells: S2CellType[]) { + if (!selectedDataCells.length) { + return false; + } + + const selectedMetas = selectedDataCells.map((cell) => cell.getMeta()); + const { scrollX, scrollY } = this.spreadsheet.facet.getScrollOffset(); + const { x: panelX, y: panelY } = this.spreadsheet.facet.panelBBox; + const minX = Math.min(...selectedMetas.map((meta) => meta.x)); + const minY = Math.min(...selectedMetas.map((meta) => meta.y)); + const maxX = Math.max(...selectedMetas.map((meta) => meta.x + meta.width)); + const maxY = Math.max(...selectedMetas.map((meta) => meta.y + meta.height)); + const borderWidth = 2; + const halfBorderWidth = borderWidth / 2; + const left = minX + panelX - scrollX + halfBorderWidth; + const right = maxX + panelX - scrollX - halfBorderWidth; + const top = minY + panelY - scrollY + halfBorderWidth; + const bottom = maxY + panelY - scrollY - halfBorderWidth; + const selectionBorderPath = `M ${left} ${top} L ${right} ${top} L ${right} ${bottom} L ${left} ${bottom} Z`; + const interactiveBgShape = this.getStateShapes().get('interactiveBgShape'); + const interactiveBorderShape = this.getStateShapes().get( + 'interactiveBorderShape', + ); + const foregroundGroup = this.spreadsheet.facet?.foregroundGroup; + const existedSelectionBorder = foregroundGroup?.getElementById( + EXCEL_ROW_COL_SELECTION_BORDER_ID, + ); + + interactiveBgShape?.setAttribute('visibility', 'visible'); + interactiveBgShape?.setAttribute('fill', EXCEL_ROW_COL_SELECTED_BACKGROUND); + interactiveBgShape?.setAttribute('fillOpacity', 1); + + interactiveBorderShape?.setAttribute('visibility', 'visible'); + interactiveBorderShape?.setAttribute('d', 'M 0 0'); + interactiveBorderShape?.setAttribute('fill', 'transparent'); + interactiveBorderShape?.setAttribute('stroke', 'transparent'); + interactiveBorderShape?.setAttribute('strokeOpacity', 0); + interactiveBorderShape?.setAttribute('lineWidth', borderWidth); + interactiveBorderShape?.setAttribute('opacity', 1); + + if (existedSelectionBorder) { + existedSelectionBorder.setAttribute('d', selectionBorderPath); + existedSelectionBorder.setAttribute('visibility', 'visible'); + } else if (foregroundGroup && interactiveBorderShape) { + const BorderShape = interactiveBorderShape.constructor as new (config: { + id: string; + style: Record; + }) => NonNullable; + + foregroundGroup.appendChild( + new BorderShape({ + id: EXCEL_ROW_COL_SELECTION_BORDER_ID, + style: { + d: selectionBorderPath, + fill: 'transparent', + stroke: EXCEL_ACTIVE_COLOR, + strokeOpacity: 1, + lineWidth: borderWidth, + pointerEvents: 'none', + zIndex: 10, + }, + }), + ); + } + + return true; + } + + private updateRowColSelectedStyle(selectionType: CellType) { + return this.updateSelectedDataCellsStyle( + this.getSelectedDataCells(selectionType), + ); + } + + private updateBrushSelectedStyle() { + return this.updateSelectedDataCellsStyle(this.getBrushSelectedDataCells()); + } + + public updateByState( + stateName: Parameters[0], + ) { + const rowColSelectionType = this.getRowColSelectionType(); + + if (stateName === 'selected' && rowColSelectionType) { + this.hideInteractionShape(); + + if (!this.updateRowColSelectedStyle(rowColSelectionType)) { + super.updateByState(stateName); + + return; + } + + this.spreadsheet.interaction.setInteractedCells(this); + + return; + } + + if ( + (stateName === InteractionStateName.SELECTED && + this.spreadsheet.interaction.getCurrentStateName() === + InteractionStateName.DATA_CELL_BRUSH_SELECTED) || + stateName === InteractionStateName.PREPARE_SELECT + ) { + this.hideInteractionShape(); + + if (!this.updateBrushSelectedStyle()) { + super.updateByState(stateName); + + return; + } + + this.spreadsheet.interaction.setInteractedCells(this); + + return; + } + + if (stateName === 'selected') { + this.hideRowColSelectionBorder(); + } + + super.updateByState(stateName); + } + + public hideInteractionShape() { + super.hideInteractionShape(); + this.hideRowColSelectionBorder(); + } + + public drawResizeArea() {} +} + +class ExcelSeriesNumberCell extends TableSeriesNumberCell { + protected drawBackgroundShape() { + super.drawBackgroundShape(); + setExcelCellCursor(this.backgroundShape); + } + + protected afterDrawText() { + super.afterDrawText(); + setExcelCellCursor(this.textShape); + this.textShapes?.forEach((shape) => { + setExcelCellCursor(shape); }); - }; + } - const onLayoutWidthTypeChange = (e: RadioChangeEvent) => { - updateOptions({ - style: { - layoutWidthType: e.target.value, - }, + private isDirectSeriesNumberSelection() { + return this.spreadsheet.interaction.getCells().some((cell) => { + return ( + cell.type === CellType.ROW_CELL && + cell.rowIndex === this.meta.rowIndex && + cell.colIndex === this.meta.colIndex + ); }); - }; + } - const onTableColumnTypeChange = (e: RadioChangeEvent) => { - setTableSheetColumnType(e.target.value); - }; + private getFirstDataColIndex() { + const dataColIndexes = + this.spreadsheet.facet + ?.getCells() + .filter((cell) => { + const meta = cell.getMeta(); - const onSizeChange = (type: 'width' | 'height') => - debounce((e) => { - updateOptions({ - [type]: Number(e.target.value), - }); - }, 300); - - const onScrollSpeedRatioChange = - (type: 'horizontal' | 'vertical') => (value: number) => { - updateOptions({ - interaction: { - scrollSpeedRatio: { - [type]: value, - }, - }, - }); - }; + return ( + cell.cellType === CellType.DATA_CELL && + meta.valueField !== SERIES_NUMBER_FIELD + ); + }) + .map((cell) => cell.getMeta().colIndex) ?? []; - const onToggleRender = () => { - setRender(!render); - }; + if (!dataColIndexes.length) { + return 0; + } + + return Math.min(...dataColIndexes); + } + + private isFirstColDataCellSelection() { + const firstDataColIndex = this.getFirstDataColIndex(); - const onThemeChange = (e: RadioChangeEvent) => { - setThemeCfg({ - name: e.target.value, + return this.spreadsheet.interaction.getCells().some((cell) => { + return ( + cell.type === CellType.DATA_CELL && cell.colIndex === firstDataColIndex + ); }); - }; + } - const logHandler = - (name: string, callback?: (...args: any[]) => void) => - (...args: any[]) => { - if (s2Ref.current?.options?.debug) { - console.log(name, ...args); - } + private updateSeriesNumberSelectedStyle() { + const interactiveBgShape = this.getStateShapes().get('interactiveBgShape'); + const interactiveBorderShape = this.getStateShapes().get( + 'interactiveBorderShape', + ); + const { x, y, width, height } = this.getBBoxByType(CellClipBox.PADDING_BOX); + const borderWidth = 2; + const borderX = x + width - borderWidth / 2; + const isDirectSelection = this.isDirectSeriesNumberSelection(); + const shouldDrawRightBorder = + !isDirectSelection && !this.isFirstColDataCellSelection(); - callback?.(...args); - }; + interactiveBgShape?.setAttribute('visibility', 'visible'); + interactiveBgShape?.setAttribute( + 'fill', + isDirectSelection ? EXCEL_HEADER_SELECTED_BACKGROUND : 'transparent', + ); + interactiveBgShape?.setAttribute('fillOpacity', isDirectSelection ? 1 : 0); - const onColCellClick = (cellInfo: TargetCellInfo) => { - logHandler('onColCellClick')(cellInfo); + interactiveBorderShape?.setAttribute('visibility', 'visible'); + interactiveBorderShape?.setAttribute( + 'd', + shouldDrawRightBorder + ? [ + ['M', borderX, y], + ['L', borderX, y + height], + ] + : 'M 0 0', + ); + interactiveBorderShape?.setAttribute('fill', 'transparent'); + interactiveBorderShape?.setAttribute( + 'stroke', + shouldDrawRightBorder ? EXCEL_ACTIVE_COLOR : 'transparent', + ); + interactiveBorderShape?.setAttribute( + 'strokeOpacity', + shouldDrawRightBorder ? 1 : 0, + ); + interactiveBorderShape?.setAttribute('lineWidth', borderWidth); + interactiveBorderShape?.setAttribute('opacity', 1); + } - if (showCustomTooltip) { - const { event } = cellInfo; + private updateSeriesNumberHoverStyle() { + const interactiveBgShape = this.getStateShapes().get('interactiveBgShape'); - s2Ref.current?.showTooltip({ - position: { x: event.clientX, y: event.clientY }, - content: , - }); + interactiveBgShape?.setAttribute('visibility', 'visible'); + interactiveBgShape?.setAttribute('fill', EXCEL_HEADER_HOVER_BACKGROUND); + interactiveBgShape?.setAttribute('fillOpacity', 1); + } + + public updateByState( + stateName: Parameters[0], + ) { + if (stateName === 'hover') { + this.hideInteractionShape(); + this.updateSeriesNumberHoverStyle(); + this.spreadsheet.interaction.setInteractedCells(this); + + return; } - }; - const getColumnOptions = React.useCallback( - (type: SheetType) => { - if (type === 'table') { - return dataCfg.fields?.columns || []; + if (stateName !== 'selected') { + super.updateByState(stateName); + + return; + } + + this.hideInteractionShape(); + this.updateSeriesNumberSelectedStyle(); + this.spreadsheet.interaction.setInteractedCells(this); + } + + public drawResizeArea() { + super.drawResizeArea(); + + const resizeArea = this.spreadsheet.facet?.foregroundGroup?.getElementById( + KEY_GROUP_ROW_RESIZE_AREA, + ); + const children = resizeArea?.children ?? []; + const resizeShape = children[children.length - 1]; + + if (!resizeShape) { + return; + } + + const { x, width } = this.getBBoxByType(); + + ( + resizeShape as unknown as { + attr: (style: { x: number; width: number }) => void; } + ).attr({ x, width }); + } +} - return ( - s2Ref.current?.facet?.getInitColLeafNodes().map(({ id }) => id) || [] +class ExcelCornerCell extends TableCornerCell { + private getPathShapeConstructor() { + const interactiveBorderShape = this.getStateShapes().get( + 'interactiveBorderShape', + ); + + if (!interactiveBorderShape) { + return; + } + + return interactiveBorderShape.constructor as new (config: { + id: string; + style: Record; + }) => NonNullable; + } + + private drawCornerBackground() { + const PathShape = this.getPathShapeConstructor(); + + if (!PathShape) { + return; + } + + const { x, y, width, height } = this.getBBoxByType(); + const upperPath = `M ${x} ${y} L ${x + width} ${y} L ${x} ${y + height} Z`; + const lowerPath = `M ${x + width} ${y} L ${x + width} ${y + height} L ${x} ${y + height} Z`; + const upperBackground = this.getElementById( + EXCEL_CORNER_UPPER_BACKGROUND_ID, + ); + const lowerBackground = this.getElementById( + EXCEL_CORNER_LOWER_BACKGROUND_ID, + ); + + if (upperBackground) { + upperBackground.setAttribute('d', upperPath); + upperBackground.setAttribute('fill', EXCEL_CORNER_UPPER_BACKGROUND); + } else { + this.appendChild( + new PathShape({ + id: EXCEL_CORNER_UPPER_BACKGROUND_ID, + style: { + d: upperPath, + fill: EXCEL_CORNER_UPPER_BACKGROUND, + fillOpacity: 1, + stroke: 'transparent', + pointerEvents: 'none', + }, + }), ); - }, - [dataCfg.fields?.columns], - ); + } - const onSheetTypeChange = (e: RadioChangeEvent) => { - const selectedSheetType = e.target.value; + if (lowerBackground) { + lowerBackground.setAttribute('d', lowerPath); + lowerBackground.setAttribute('fill', EXCEL_CORNER_LOWER_BACKGROUND); + } else { + this.appendChild( + new PathShape({ + id: EXCEL_CORNER_LOWER_BACKGROUND_ID, + style: { + d: lowerPath, + fill: EXCEL_CORNER_LOWER_BACKGROUND, + fillOpacity: 1, + stroke: 'transparent', + pointerEvents: 'none', + }, + }), + ); + } + } + + private setLowerBackground(fill: string) { + this.getElementById(EXCEL_CORNER_LOWER_BACKGROUND_ID)?.setAttribute( + 'fill', + fill, + ); + } - setSheetType(e.target.value); + private drawDiagonalLine() { + const PathShape = this.getPathShapeConstructor(); - switch (selectedSheetType) { - case 'table': - setDataCfg(tableSheetDataCfg); - updateOptions(defaultOptions); - break; - default: - setDataCfg(pivotSheetDataCfg); - updateOptions(defaultOptions); - break; + if (!PathShape) { + return; } - setColumnOptions(getColumnOptions(sheetType)); - }; - // ================== Hooks ======================== + const { x, y, width, height } = this.getBBoxByType(); + const diagonalPath = `M ${x + width} ${y} L ${x} ${y + height}`; + const existedDiagonalLine = this.getElementById(EXCEL_CORNER_DIAGONAL_ID); - React.useEffect(() => { - console.log('env:', process.env); + if (existedDiagonalLine) { + existedDiagonalLine.setAttribute('d', diagonalPath); - if (sheetType !== 'table') { return; } - setDataCfg( - customMerge(tableSheetDataCfg, { - fields: { - columns: - tableSheetColumnType === 'single' - ? tableSheetSingleColumns - : tableSheetMultipleColumns, + this.appendChild( + new PathShape({ + id: EXCEL_CORNER_DIAGONAL_ID, + style: { + d: diagonalPath, + fill: 'transparent', + stroke: '#b4b4b4', + strokeOpacity: 1, + lineWidth: 1, + pointerEvents: 'none', }, }), ); - }, [sheetType, tableSheetColumnType]); + } - const onSheetDestroy = logHandler('onDestroy', () => { - clearInterval(scrollTimer.current!); - }); + protected drawBackgroundShape() { + super.drawBackgroundShape(); + setShapeFillOpacity(this.backgroundShape, 0); + setExcelCellCursor(this.backgroundShape); + } - useUpdateEffect(() => { - switch (options!.style!.layoutWidthType) { - case 'compact': - updateOptions({ - style: { - dataCell: { - width: 200, - }, - }, - }); - setDataCfg(pivotSheetDataCfgForCompactMode); - break; - - default: - updateOptions({ - style: DEFAULT_STYLE, - }); - setDataCfg(pivotSheetDataCfg); + protected afterDrawText() { + super.afterDrawText(); + setExcelCellCursor(this.textShape); + this.textShapes?.forEach((shape) => { + setExcelCellCursor(shape); + }); + this.drawCornerBackground(); + this.drawDiagonalLine(); + } + + public updateByState( + stateName: Parameters[0], + ) { + const selectedCells = this.spreadsheet.interaction.getCells(); + const isSeriesNumberSelection = selectedCells.every((cell) => { + return cell.type === CellType.ROW_CELL; + }); + + if (stateName === 'hover') { + this.hideInteractionShape(); + this.setLowerBackground(EXCEL_CORNER_LOWER_HOVER_BACKGROUND); + this.spreadsheet.interaction.setInteractedCells(this); + + return; + } + + this.setLowerBackground(EXCEL_CORNER_LOWER_BACKGROUND); + + if (stateName === 'selected' && isSeriesNumberSelection) { + this.hideInteractionShape(); + + return; + } + + super.updateByState(stateName); + } + + public hideInteractionShape() { + super.hideInteractionShape(); + this.setLowerBackground(EXCEL_CORNER_LOWER_BACKGROUND); + } +} + +class ExcelColCell extends TableColCell { + protected drawBackgroundShape() { + super.drawBackgroundShape(); + setExcelCellCursor(this.backgroundShape); + } + + protected afterDrawText() { + super.afterDrawText(); + setExcelCellCursor(this.textShape); + this.textShapes?.forEach((shape) => { + setExcelCellCursor(shape); + }); + } + + private isDataCellSelection() { + const selectedCells = this.spreadsheet.interaction.getCells(); + + return ( + selectedCells.length > 0 && + selectedCells.every((cell) => cell.type === CellType.DATA_CELL) + ); + } + + private isFirstRowDataCellSelection() { + return this.spreadsheet.interaction.getCells().some((cell) => { + return cell.type === CellType.DATA_CELL && cell.rowIndex === 0; + }); + } + + private updateColHeaderSelectedByDataCellStyle() { + const interactiveBgShape = this.getStateShapes().get('interactiveBgShape'); + const interactiveBorderShape = this.getStateShapes().get( + 'interactiveBorderShape', + ); + const { x, y, width, height } = this.getBBoxByType(CellClipBox.PADDING_BOX); + const borderWidth = 2; + const borderY = y + height - borderWidth / 2; + const shouldDrawBottomBorder = + this.meta.isLeaf && !this.isFirstRowDataCellSelection(); + + interactiveBgShape?.setAttribute('visibility', 'visible'); + interactiveBgShape?.setAttribute('fill', 'transparent'); + interactiveBgShape?.setAttribute('fillOpacity', 0); + + interactiveBorderShape?.setAttribute('visibility', 'visible'); + interactiveBorderShape?.setAttribute( + 'd', + shouldDrawBottomBorder + ? [ + ['M', x, borderY], + ['L', x + width, borderY], + ] + : 'M 0 0', + ); + interactiveBorderShape?.setAttribute('fill', 'transparent'); + interactiveBorderShape?.setAttribute( + 'stroke', + shouldDrawBottomBorder ? EXCEL_ACTIVE_COLOR : 'transparent', + ); + interactiveBorderShape?.setAttribute( + 'strokeOpacity', + shouldDrawBottomBorder ? 1 : 0, + ); + interactiveBorderShape?.setAttribute('lineWidth', borderWidth); + interactiveBorderShape?.setAttribute('opacity', 1); + } + + public updateByState( + stateName: Parameters[0], + ) { + if (stateName === 'selected' && this.isDataCellSelection()) { + this.hideInteractionShape(); + this.updateColHeaderSelectedByDataCellStyle(); + this.spreadsheet.interaction.setInteractedCells(this); + + return; + } + + super.updateByState(stateName); + } + + protected drawVerticalResizeArea() { + if (this.meta.isLeaf || !this.meta.extra?.isCustomNode) { + super.drawVerticalResizeArea(); + + return; } - }, [options.style!.layoutWidthType]); - // ================== Config ======================== + const [leafNode] = this.meta.children ?? []; + + if (!leafNode) { + return; + } + + const originalIsLeaf = this.meta.isLeaf; + + this.meta.isLeaf = true; + super.drawVerticalResizeArea(); + this.meta.isLeaf = originalIsLeaf; + + const resizeArea = this.spreadsheet.facet?.foregroundGroup?.getElementById( + KEY_GROUP_COL_RESIZE_AREA, + ); + const resizeShape = (resizeArea?.children ?? []).find((shape) => { + return ( + (shape as unknown as { appendInfo?: { cell?: ExcelColCell } }) + .appendInfo?.cell === this + ); + }); - const mergedOptions: SheetComponentOptions = customMerge( + if (!resizeShape) { + return; + } + + const appendInfo = ( + resizeShape as unknown as { + appendInfo?: { meta?: Record }; + } + ).appendInfo; + + if (appendInfo) { + appendInfo.meta = { + ...this.meta, + field: leafNode.field, + }; + } + } +} + +// 2. 转换函数:0 -> A, 1 -> B, 25 -> Z, 26 -> AA +function getExcelColumnLabel(index: number): string { + let label = ''; + let temp = index; + + while (temp >= 0) { + label = String.fromCharCode((temp % 26) + 65) + label; + temp = Math.floor(temp / 26) - 1; + } + + return label; +} + +function getExcelSeriesNumberWidth(rowCount: number) { + const digitCount = String(Math.max(rowCount, 1)).length; + + return Math.max(EXCEL_SERIES_NUMBER_MIN_WIDTH, digitCount * 8 + 20); +} + +// 原始测试数据 +const RAW_DATA = [ + { + col0: 'Apples', + col1: 50, + col2: 1.2, + col3: 'Fruit', + col4: '2026-05-01', + col5: 60, + col6: 'In Stock', + col7: 'Aisle 1', + }, + { + col0: 'Bananas', + col1: 120, + col2: 0.8, + col3: 'Fruit', + col4: '2026-05-02', + col5: 96, + col6: 'In Stock', + col7: 'Aisle 1', + }, + { + col0: 'Carrots', + col1: 80, + col2: 1.5, + col3: 'Vegetable', + col4: '2026-05-03', + col5: 120, + col6: 'Low Stock', + col7: 'Aisle 2', + }, + { + col0: 'Dates', + col1: 15, + col2: 5.0, + col3: 'Fruit', + col4: '2026-05-04', + col5: 75, + col6: 'Out of Stock', + col7: 'Aisle 3', + }, + { + col0: 'Eggplant', + col1: 40, + col2: 2.0, + col3: 'Vegetable', + col4: '2026-05-05', + col5: 80, + col6: 'In Stock', + col7: 'Aisle 2', + }, + { + col0: 'Figs', + col1: 30, + col2: 4.5, + col3: 'Fruit', + col4: '2026-05-06', + col5: 135, + col6: 'In Stock', + col7: 'Aisle 3', + }, + { + col0: 'Grapes', + col1: 150, + col2: 2.5, + col3: 'Fruit', + col4: '2026-05-07', + col5: 375, + col6: 'In Stock', + col7: 'Aisle 1', + }, + { + col0: 'Honey', + col1: 25, + col2: 8.5, + col3: 'Sweetener', + col4: '2026-05-08', + col5: 212.5, + col6: 'In Stock', + col7: 'Aisle 4', + }, +]; + +interface ChatMessage { + id: number; + sender: 'user' | 'assistant'; + text: string; +} + +function MainLayout() { + const s2Ref = useRef(null); + const sheetContainerRef = useRef(null); + + // 基础开关配置 + const [useExcelTheme, setUseExcelTheme] = useState(true); + const [useExcelHeaders, setUseExcelHeaders] = useState(true); + const [disableCrosshair, setDisableCrosshair] = useState(true); + + // 表格数据 & 条件高亮状态 + const [data, setData] = useState(RAW_DATA); + const [highlightedCol, setHighlightedCol] = useState(null); + + // Chat Excel 模拟器状态 + const [, setChatQuery] = useState(''); + const [, setMessages] = useState([ { - pagination: showPagination && { - current: 1, - pageSize: 4, - }, - tooltip: { - content: showCustomTooltip ? : null, - }, - totals: showTotals && { - row: { - showGrandTotals: true, - showSubTotals: true, - subTotalsDimensions: ['province'], - }, - col: { - showGrandTotals: true, - showSubTotals: true, - subTotalsDimensions: ['type'], - }, - }, - customSVGIcons: !options.showDefaultHeaderActionIcon && [ - { - name: 'Filter', - src: 'https://gw.alipayobjects.com/zos/antfincdn/gu1Fsz3fw0/filter%26sort_filter.svg', - }, + id: 1, + sender: 'assistant', + text: '你好!我是 Chat Excel 助手。你可以让我对表格进行【筛选】、【高亮】或【排序】,例如:\n1. "筛选出 Fruit 商品"\n2. "高亮总额大于 100 的格子"\n3. "按数量降序排序"', + }, + ]); + + // 处理 Chat 命令 + const handleCommand = (queryText: string) => { + if (!queryText.trim()) { + return; + } + + // 1. 添加用户消息 + const userMsg: ChatMessage = { + id: Date.now(), + sender: 'user', + text: queryText, + }; + + setMessages((prev) => [...prev, userMsg]); + setChatQuery(''); + + // 2. 模拟 AI 逻辑处理并更新表格 + setTimeout(() => { + let replyText = '抱歉,我不明白这个指令。试着点击下方的快捷提示词吧!'; + const cleanQuery = queryText.toLowerCase(); + + if (cleanQuery.includes('fruit') || cleanQuery.includes('水果')) { + setData(RAW_DATA.filter((item) => item.col3 === 'Fruit')); + replyText = '✨ 已为您筛选出分类 (Category) 为 "Fruit" 的所有数据!'; + } else if ( + cleanQuery.includes('大于100') || + cleanQuery.includes('> 100') || + cleanQuery.includes('highlight') || + cleanQuery.includes('高亮') + ) { + // col5 是总额 (Total) + setHighlightedCol('col5'); + replyText = '✨ 已为您高亮标记总额 (Total) 大于 100 的单元格!'; + } else if ( + cleanQuery.includes('排序') || + cleanQuery.includes('sort') || + cleanQuery.includes('降序') + ) { + const sorted = [...RAW_DATA].sort((a, b) => b.col1 - a.col1); + + setData(sorted); + replyText = '✨ 已按数量 (Quantity) 列进行降序排列!'; + } else if ( + cleanQuery.includes('重置') || + cleanQuery.includes('reset') || + cleanQuery.includes('恢复') + ) { + setData(RAW_DATA); + setHighlightedCol(null); + replyText = '✨ 表格数据与高亮状态已恢复初始设置!'; + } + + setMessages((prev) => [ + ...prev, { - name: 'FilterAsc', - src: 'https://gw.alipayobjects.com/zos/antfincdn/UxDm6TCYP3/filter%26sort_asc%2Bfilter.svg', + id: Date.now() + 1, + sender: 'assistant', + text: replyText, }, - ], - headerActionIcons: !options.showDefaultHeaderActionIcon && [ - { - icons: ['Filter'], - belongsCell: 'colCell', - displayCondition: (node: Node) => - node.id !== 'root[&]家具[&]桌子[&]number', - onClick: ({ event }: HeaderActionIconProps) => { - s2Ref.current?.showTooltip({ - position: { x: event!.clientX, y: event!.clientY }, - content: , - }); + ]); + }, 600); + }; + + // 生成 S2 的 dataCfg + const dataCfg = useMemo(() => { + const fieldsList = Array.from({ length: 8 }, (_, i) => `col${i}`); + + // 原始业务标题映射 + const defaultMeta = [ + { field: 'col0', name: 'Product Name' }, + { field: 'col1', name: 'Quantity' }, + { field: 'col2', name: 'Unit Price ($)' }, + { field: 'col3', name: 'Category' }, + { field: 'col4', name: 'Date' }, + { field: 'col5', name: 'Total ($)' }, + { field: 'col6', name: 'Status' }, + { field: 'col7', name: 'Location' }, + ]; + + // If useExcelHeaders is true, columns is a hierarchical custom tree node list + const columns = useExcelHeaders + ? defaultMeta.map((m, idx) => ({ + field: `${m.field}_parent`, + title: getExcelColumnLabel(idx), + children: [ + { + field: m.field, + title: m.name, + }, + ], + })) + : fieldsList; + + // 条件高亮配置 (模拟 Chat Excel 指令) + const conditions = highlightedCol + ? { + background: [ + { + field: highlightedCol, + mapping: (value: number) => { + if (value > 100) { + return { + // Excel 浅绿色 + fill: '#E2EFDA', + }; + } + + return {}; + }, + }, + ], + } + : undefined; + + return { + fields: { + columns, + }, + meta: defaultMeta, + data, + conditions, + }; + }, [data, useExcelHeaders, highlightedCol]); + + const themeCfg = useMemo(() => { + return { + name: (useExcelTheme ? 'excel' : 'default') as 'excel' | 'default', + getCustomTheme: (palette: SimplePalette) => { + if (!useExcelTheme) { + return {}; + } + + return { + rowCell: { + seriesNumberWidth: getExcelSeriesNumberWidth(data.length), + cell: { + // Excel header gray (#E6E6E6) + backgroundColor: palette.basicColors[3], + // Gray header border (#B4B4B4) + horizontalBorderColor: palette.basicColors[10], + verticalBorderColor: palette.basicColors[10], + interactionState: { + hover: { + backgroundColor: EXCEL_HEADER_HOVER_BACKGROUND, + backgroundOpacity: 1, + }, + selected: { + backgroundColor: EXCEL_HEADER_SELECTED_BACKGROUND, + backgroundOpacity: 1, + }, + }, + }, + seriesText: { + fill: '#000000', + }, + text: { + fill: '#000000', + }, }, - }, - { - icons: ['SortDown'], - belongsCell: 'colCell', - displayCondition: (node: Node) => - node.id === 'root[&]家具[&]桌子[&]number', - onClick: ({ event }: HeaderActionIconProps) => { - s2Ref.current?.showTooltip({ - position: { x: event!.clientX, y: event!.clientY }, - content: , - }); + colCell: { + cell: { + interactionState: { + hover: { + backgroundColor: EXCEL_HEADER_HOVER_BACKGROUND, + backgroundOpacity: 1, + }, + selected: { + backgroundColor: EXCEL_HEADER_SELECTED_BACKGROUND, + backgroundOpacity: 1, + }, + }, + }, }, - }, - { - icons: ['FilterAsc'], - belongsCell: 'cornerCell', - onClick: ({ event }: HeaderActionIconProps) => { - s2Ref.current?.showTooltip({ - position: { x: event!.clientX, y: event!.clientY }, - content: , - }); + dataCell: { + cell: { + interactionState: { + selected: { + // Light gray background selection mask + backgroundColor: palette.basicColors[2], + backgroundOpacity: 0.2, + // Excel green border + borderColor: (palette as any).brandColor, + borderWidth: 2, + borderOpacity: 1, + }, + hoverFocus: { + backgroundColor: palette.basicColors[2], + backgroundOpacity: 0.2, + borderColor: (palette as any).brandColor, + borderWidth: 2, + borderOpacity: 1, + }, + }, + }, }, - }, - { - icons: ['SortDown', 'Filter'], - belongsCell: 'rowCell', - onClick: ({ event }: HeaderActionIconProps) => { - s2Ref.current?.showTooltip({ - position: { x: event!.clientX, y: event!.clientY }, - content: , - }); + }; + }, + }; + }, [data.length, useExcelTheme]); + + // 生成 S2 的 options + const options = useMemo(() => { + const interactionConfig = disableCrosshair + ? { + // 仅高亮行头/列头,去掉十字形选中高亮 + hoverHighlight: { + rowHeader: false, + colHeader: false, + currentRow: false, + currentCol: false, }, + selectedCellHighlight: { + rowHeader: true, + colHeader: true, + currentRow: false, + currentCol: false, + }, + } + : { + // 默认十字高亮效果 + hoverHighlight: true, + selectedCellHighlight: true, + }; + + return { + width: 780, + height: 400, + tooltip: { + enable: false, + }, + dataCell: useExcelTheme + ? (viewMeta: ViewMeta, spreadsheet: SpreadSheet) => { + if (viewMeta.valueField === SERIES_NUMBER_FIELD) { + return new ExcelSeriesNumberCell(viewMeta, spreadsheet); + } + + return new ExcelDataCell(viewMeta, spreadsheet); + } + : undefined, + colCell: useExcelTheme + ? (...args) => { + return new ExcelColCell(...args); + } + : undefined, + seriesNumberCell: useExcelTheme + ? (...args) => { + return new ExcelCornerCell(...args) as never; + } + : undefined, + // 禁用默认的序号行为以防冲突 + showSeriesNumber: false, + seriesNumber: { + // 开启数字序号列 + enable: useExcelHeaders, + // 序号列顶部角头显示为空 + text: '', + }, + placeholder: { + cell: (cell) => { + const meta = cell?.['getMeta']?.(); + + if (meta?.field === '$$series_number$$') { + return ' '; + } + + return '-'; }, - ], - }, - options, - ); + }, + interaction: { + ...interactionConfig, + // 不启用选中变暗效果,保持 excel 式的聚焦 + selectedCellsSpotlight: false, + resize: useExcelTheme + ? { + // Excel 模式只允许通过列头调整列宽。 + // 行高热区由自定义 dataCell 控制:只让 123 序号格绘制。 + rowCellVertical: true, + // 不开放普通角头行头宽度调整;序号列宽度由列头上的序号节点承担。 + cornerCellHorizontal: false, + // 列头叶子节点可调列宽,包含 seriesNumber 开启后的左侧序号列节点。 + colCellHorizontal: true, + // 不允许调整列头高度。 + colCellVertical: false, + rowResizeType: 'current', + colResizeType: 'current', + } + : true, + }, + }; + }, [useExcelHeaders, disableCrosshair, useExcelTheme]); + + const updateSelectedSeriesNumberCell: SheetComponentProps['onDataCellSelected'] = + (cells) => { + const selectedDataCell = cells.find((cell) => { + return cell.getMeta().valueField !== SERIES_NUMBER_FIELD; + }); + + if (!selectedDataCell) { + return; + } + + const selectedRowIndex = selectedDataCell.getMeta().rowIndex; + const seriesNumberCells = ( + s2Ref.current?.facet as unknown as { + getSeriesNumberCells?: () => ExcelSeriesNumberCell[]; + } + )?.getSeriesNumberCells?.(); + const seriesNumberCell = seriesNumberCells?.find((cell) => { + return cell.getMeta().rowIndex === selectedRowIndex; + }); + + seriesNumberCell?.updateByState('selected'); + }; return ( - - + {/* 头部样式插入 */} +