Skip to content

Commit

Permalink
feat: add table internal border #869
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Nov 8, 2024
1 parent 85cc2b7 commit 5cc4f13
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/en/guide/contextmenu-internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Borderless
- Dashed border
- Outer border
- Internal border
- Td borders
- Top border
- Right border
Expand Down
1 change: 1 addition & 0 deletions docs/en/guide/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ interface ILang {
borderEmpty: string
borderDash: string
borderExternal: string
borderInternal: string
borderTd: string
borderTdTop: string
borderTdRight: string
Expand Down
1 change: 1 addition & 0 deletions docs/guide/contextmenu-internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- 无框线
- 虚框线
- 外侧框线
- 内侧框线
- 单元格边框
- 上边框
- 右边框
Expand Down
1 change: 1 addition & 0 deletions docs/guide/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface ILang {
borderEmpty: string
borderDash: string
borderExternal: string
borderInternal: string
borderTd: string
borderTdTop: string
borderTdRight: string
Expand Down
4 changes: 4 additions & 0 deletions src/editor/assets/css/contextmenu/contextmenu.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
background-image: url(../../../assets/images/table-border-external.svg);
}

.ce-contextmenu-border-internal {
background-image: url(../../../assets/images/table-border-internal.svg);
}

.ce-contextmenu-border-td {
background-image: url(../../../assets/images/table-border-td.svg);
}
Expand Down
1 change: 1 addition & 0 deletions src/editor/assets/images/table-border-internal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/editor/core/contextmenu/menus/tableMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
BORDER_EMPTY,
BORDER_DASH,
BORDER_EXTERNAL,
BORDER_INTERNAL,
BORDER_TD,
BORDER_TD_TOP,
BORDER_TD_LEFT,
Expand Down Expand Up @@ -92,6 +93,15 @@ export const tableMenus: IRegisterContextMenu[] = [
command.executeTableBorderType(TableBorder.EXTERNAL)
}
},
{
key: BORDER_INTERNAL,
i18nPath: 'contextmenu.table.borderInternal',
icon: 'border-internal',
when: () => true,
callback: (command: Command) => {
command.executeTableBorderType(TableBorder.INTERNAL)
}
},
{
key: BORDER_TD,
i18nPath: 'contextmenu.table.borderTd',
Expand Down
23 changes: 19 additions & 4 deletions src/editor/core/draw/particle/table/TableParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ export class TableParticle {
const isEmptyBorderType = borderType === TableBorder.EMPTY
// 仅外边框
const isExternalBorderType = borderType === TableBorder.EXTERNAL
// 内边框
const isInternalBorderType = borderType === TableBorder.INTERNAL
ctx.save()
// 虚线
if (borderType === TableBorder.DASH) {
ctx.setLineDash([3, 3])
}
ctx.lineWidth = scale
// 渲染边框
if (!isEmptyBorderType) {
if (!isEmptyBorderType && !isInternalBorderType) {
this._drawOuterBorder({
ctx,
startX,
Expand Down Expand Up @@ -221,9 +223,22 @@ export class TableParticle {
}
// 表格线
if (!isEmptyBorderType && !isExternalBorderType) {
ctx.moveTo(x, y)
ctx.lineTo(x, y + height)
ctx.lineTo(x - width, y + height)
// 右边框
if (
!isInternalBorderType ||
td.colIndex! + td.colspan < colgroup.length
) {
ctx.moveTo(x, y)
ctx.lineTo(x, y + height)
}
// 下边框
if (
!isInternalBorderType ||
td.rowIndex! + td.rowspan < trList.length
) {
ctx.moveTo(x, y + height)
ctx.lineTo(x - width, y + height)
}
ctx.stroke()
}
ctx.translate(-0.5, -0.5)
Expand Down
1 change: 1 addition & 0 deletions src/editor/core/i18n/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"borderEmpty": "Empty",
"borderDash": "Dash",
"borderExternal": "External",
"borderInternal": "Internal",
"borderTd": "Table cell border",
"borderTdTop": "Top",
"borderTdRight": "Right",
Expand Down
1 change: 1 addition & 0 deletions src/editor/core/i18n/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"borderEmpty": "无框线",
"borderDash": "虚框线",
"borderExternal": "外侧框线",
"borderInternal": "内侧框线",
"borderTd": "单元格边框",
"borderTdTop": "上边框",
"borderTdRight": "右边框",
Expand Down
1 change: 1 addition & 0 deletions src/editor/dataset/constant/ContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const INTERNAL_CONTEXT_MENU_KEY = {
BORDER_EMPTY: 'tableBorderEmpty',
BORDER_DASH: 'tableBorderDash',
BORDER_EXTERNAL: 'tableBorderExternal',
BORDER_INTERNAL: 'tableBorderInternal',
BORDER_TD: 'tableBorderTd',
BORDER_TD_TOP: 'tableBorderTdTop',
BORDER_TD_RIGHT: 'tableBorderTdRight',
Expand Down
1 change: 1 addition & 0 deletions src/editor/dataset/enum/table/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum TableBorder {
ALL = 'all',
EMPTY = 'empty',
EXTERNAL = 'external',
INTERNAL = 'internal',
DASH = 'dash'
}

Expand Down

0 comments on commit 5cc4f13

Please sign in to comment.