Skip to content

Commit

Permalink
fix: add table cell border default property
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuna authored and cycleccc committed Aug 12, 2024
1 parent fde2a69 commit f6a26d8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/table-module/src/module/parse-style-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { IDomEditor } from '@wangeditor-next/core'
import $, { DOMElement, getStyleValue } from '../utils/dom'
import { TableCellElement } from './custom-types'

// 获取 var(--w-e-textarea-border-color) 变量的实际样式值
const DEFAULT_BORDER_COLOR = window
?.getComputedStyle(document.documentElement)
?.getPropertyValue('--w-e-textarea-border-color')

export function parseStyleHtml(elem: DOMElement, node: Descendant, editor: IDomEditor): Descendant {
if (elem.tagName !== 'TABLE' && elem.tagName !== 'TD') return node

Expand All @@ -19,8 +24,14 @@ export function parseStyleHtml(elem: DOMElement, node: Descendant, editor: IDomE
tableNode.backgroundColor = backgroundColor
}

// eslint-disable-next-line no-unsafe-optional-chaining
let [borderWidth, borderStyle, borderColor] = getStyleValue($elem, 'border')?.split(' ')
let border = getStyleValue($elem, 'border')
if (!border && elem.tagName === 'TD') {
// https://github.com/cycleccc/wangEditor-next/blob/master/packages/table-module/src/assets/index.less#L20
// TD存在默认的css样式,尝试用getComputedStyle获取不到,只能写死
border = `1px solid ${DEFAULT_BORDER_COLOR}`
}

let [borderWidth, borderStyle, borderColor] = border?.split(' ') || []
borderWidth = getStyleValue($elem, 'border-width') || borderWidth // border 宽度
if (borderWidth) {
tableNode.borderWidth = borderWidth.replace(/[^\d]/g, '')
Expand Down

0 comments on commit f6a26d8

Please sign in to comment.