Skip to content

Commit

Permalink
feat: add Table Props[columnWidths] & toHTML add display:none
Browse files Browse the repository at this point in the history
  • Loading branch information
藜灰 committed Jul 9, 2024
1 parent 26250fa commit 4956621
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/table-module/src/module/column-resize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import throttle from 'lodash.throttle'
import { Element as SlateElement, Transforms, Editor } from 'slate'
import { DomEditor, IDomEditor } from '@wangeditor/core'
import { DomEditor, IDomEditor } from '@wangeditor-next/core'
import { TableElement } from './custom-types'
import { isOfType } from '../utils'
import $ from '../utils/dom'
Expand Down
6 changes: 4 additions & 2 deletions packages/table-module/src/module/elem-to-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TableCellElement, TableRowElement, TableElement } from './custom-types'
function tableToHtml(elemNode: Element, childrenHtml: string): string {
const { width = 'auto' } = elemNode as TableElement

return `<table style="width: ${width};"><tbody>${childrenHtml}</tbody></table>`
return `<table style="width: ${width};table-layout: fixed;"><tbody>${childrenHtml}</tbody></table>`
}

function tableRowToHtml(elem: Element, childrenHtml: string): string {
Expand All @@ -22,9 +22,11 @@ function tableCellToHtml(cellNode: Element, childrenHtml: string): string {
rowSpan = 1,
isHeader = false,
width = 'auto',
hidden = false
} = cellNode as TableCellElement
const tag = isHeader ? 'th' : 'td'
return `<${tag} colSpan="${colSpan}" rowSpan="${rowSpan}" width="${width}">${childrenHtml}</${tag}>`
const style = hidden ? 'display:none' : ''
return `<${tag} colSpan="${colSpan}" rowSpan="${rowSpan}" width="${width}" style="${style}">${childrenHtml}</${tag}>`
}

export const tableToHtmlConf = {
Expand Down
1 change: 0 additions & 1 deletion packages/table-module/src/module/menu/InsertCol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IButtonMenu, IDomEditor, DomEditor, t } from '@wangeditor-next/core'
import { ADD_COL_SVG } from '../../constants/svg'
import { TableCellElement, TableElement } from '../custom-types'
import { isTableWithHeader } from '../helpers'
import { isTableWithHeader } from '../helpers'
import { filledMatrix } from '../../utils'

class InsertCol implements IButtonMenu {
Expand Down
2 changes: 2 additions & 0 deletions packages/table-module/src/module/menu/InsertTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TableElement, TableCellElement, TableRowElement } from '../custom-types
function genTableNode(rowNum: number, colNum: number): TableElement {
// 拼接 rows
const rows: TableRowElement[] = []
const columnWidths: number[] = Array(colNum).fill(60)
for (let i = 0; i < rowNum; i++) {
// 拼接 cells
const cells: TableCellElement[] = []
Expand All @@ -38,6 +39,7 @@ function genTableNode(rowNum: number, colNum: number): TableElement {
type: 'table',
width: 'auto',
children: rows,
columnWidths
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/table-module/src/module/menu/MergeCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor, Path, Transforms, Node } from 'slate'
import { IButtonMenu, IDomEditor, t } from '@wangeditor/core'
import { IButtonMenu, IDomEditor, t } from '@wangeditor-next/core'
import { MERGE_CELL_SVG } from '../../constants/svg'
import { EDITOR_TO_SELECTION } from '../weak-maps'
import { TableCursor } from '../table-cursor'
Expand Down
2 changes: 1 addition & 1 deletion packages/table-module/src/module/menu/SplitCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor, Path, Transforms } from 'slate'
import { IButtonMenu, IDomEditor, t } from '@wangeditor/core'
import { IButtonMenu, IDomEditor, t } from '@wangeditor-next/core'
import { SPLIT_CELL_SVG } from '../../constants/svg'
import { EDITOR_TO_SELECTION } from '../weak-maps'
import { filledMatrix, isOfType, CellElement } from '../../utils'
Expand Down

0 comments on commit 4956621

Please sign in to comment.