Skip to content

Commit

Permalink
feat: add table border color #897
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Nov 27, 2024
1 parent 2430bf7 commit 7e8af04
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 3 deletions.
10 changes: 10 additions & 0 deletions docs/en/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ Usage:
instance.command.executeTableBorderType(payload: TableBorder)
```

## executeTableBorderColor

Feature: Table border color

Usage:

```javascript
instance.command.executeTableBorderColor(payload: string)
```

## executeTableTdBorderType

Feature: Table td border type
Expand Down
1 change: 1 addition & 0 deletions docs/en/guide/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface IElement {
}[];
}[];
borderType?: TableBorder;
borderColor?: string;
// Hyperlinks
url?: string;
// Superscript and subscript
Expand Down
10 changes: 10 additions & 0 deletions docs/guide/command-execute.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ instance.command.executeTableTdVerticalAlign(payload: VerticalAlign)
instance.command.executeTableBorderType(payload: TableBorder)
```

## executeTableBorderColor

功能:表格边框颜色

用法:

```javascript
instance.command.executeTableBorderColor(payload: string)
```

## executeTableTdBorderType

功能:表格单元格边框类型
Expand Down
1 change: 1 addition & 0 deletions docs/guide/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface IElement {
}[];
}[];
borderType?: TableBorder;
borderColor?: string;
// 超链接
url?: string;
// 上下标
Expand Down
2 changes: 2 additions & 0 deletions src/editor/core/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Command {
public executeCancelMergeTableCell: CommandAdapt['cancelMergeTableCell']
public executeTableTdVerticalAlign: CommandAdapt['tableTdVerticalAlign']
public executeTableBorderType: CommandAdapt['tableBorderType']
public executeTableBorderColor: CommandAdapt['tableBorderColor']
public executeTableTdBorderType: CommandAdapt['tableTdBorderType']
public executeTableTdSlashType: CommandAdapt['tableTdSlashType']
public executeTableTdBackgroundColor: CommandAdapt['tableTdBackgroundColor']
Expand Down Expand Up @@ -176,6 +177,7 @@ export class Command {
this.executeCancelMergeTableCell = adapt.cancelMergeTableCell.bind(adapt)
this.executeTableTdVerticalAlign = adapt.tableTdVerticalAlign.bind(adapt)
this.executeTableBorderType = adapt.tableBorderType.bind(adapt)
this.executeTableBorderColor = adapt.tableBorderColor.bind(adapt)
this.executeTableTdBorderType = adapt.tableTdBorderType.bind(adapt)
this.executeTableTdSlashType = adapt.tableTdSlashType.bind(adapt)
this.executeTableTdBackgroundColor =
Expand Down
6 changes: 6 additions & 0 deletions src/editor/core/command/CommandAdapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,12 @@ export class CommandAdapt {
this.tableOperate.tableBorderType(payload)
}

public tableBorderColor(payload: string) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
this.tableOperate.tableBorderColor(payload)
}

public tableTdBorderType(payload: TdBorder) {
const isReadonly = this.draw.isReadonly()
if (isReadonly) return
Expand Down
21 changes: 21 additions & 0 deletions src/editor/core/draw/particle/table/TableOperate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,27 @@ export class TableOperate {
})
}

public tableBorderColor(payload: string) {
const positionContext = this.position.getPositionContext()
if (!positionContext.isTable) return
const { index } = positionContext
const originalElementList = this.draw.getOriginalElementList()
const element = originalElementList[index!]
if (
(!element.borderColor &&
payload === this.options.table.defaultBorderColor) ||
element.borderColor === payload
) {
return
}
element.borderColor = payload
const { endIndex } = this.range.getRange()
this.draw.render({
curIndex: endIndex,
isCompute: false
})
}

public tableTdBorderType(payload: TdBorder) {
const rowCol = this.tableParticle.getRangeRowCol()
if (!rowCol) return
Expand Down
8 changes: 6 additions & 2 deletions src/editor/core/draw/particle/table/TableParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ export class TableParticle {
startX: number,
startY: number
) {
const { colgroup, trList, borderType } = element
const { colgroup, trList, borderType, borderColor } = element
if (!colgroup || !trList) return
const { scale } = this.options
const {
scale,
table: { defaultBorderColor }
} = this.options
const tableWidth = element.width! * scale
const tableHeight = element.height! * scale
// 无边框
Expand All @@ -166,6 +169,7 @@ export class TableParticle {
ctx.setLineDash([3, 3])
}
ctx.lineWidth = scale
ctx.strokeStyle = borderColor || defaultBorderColor
// 渲染边框
if (!isEmptyBorderType && !isInternalBorderType) {
this._drawOuterBorder({
Expand Down
1 change: 1 addition & 0 deletions src/editor/dataset/constant/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
'dashArray',
'trList',
'borderType',
'borderColor',
'width',
'height',
'url',
Expand Down
3 changes: 2 additions & 1 deletion src/editor/dataset/constant/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { ITableOption } from '../../interface/table/Table'
export const defaultTableOption: Readonly<Required<ITableOption>> = {
tdPadding: [0, 5, 5, 5],
defaultTrMinHeight: 42,
defaultColMinWidth: 40
defaultColMinWidth: 40,
defaultBorderColor: '#000000'
}
1 change: 1 addition & 0 deletions src/editor/interface/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface ITableAttr {
colgroup?: IColgroup[]
trList?: ITr[]
borderType?: TableBorder
borderColor?: string
}

export interface ITableElement {
Expand Down
1 change: 1 addition & 0 deletions src/editor/interface/table/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ITableOption {
tdPadding?: IPadding
defaultTrMinHeight?: number
defaultColMinWidth?: number
defaultBorderColor?: string
}

0 comments on commit 7e8af04

Please sign in to comment.