提交 e4cbc93e authored 作者: 王鹏飞's avatar 王鹏飞

refactor(admin): colocate editor content tools

上级 b11b04e1
const parseFontSize = value => {
const size = Number.parseInt(value, 10)
return Number.isFinite(size) ? size : 18
}
export const getSelectionFontSize = editor => {
const path = editor?.selection?.anchor?.path
if (!path) return 18
const node = path.slice(0, 2).reduce(
(value, index) => value?.children?.[index],
{ children: editor.children },
)
if (!node) return 18
if (node.fontSize) return parseFontSize(node.fontSize)
if (!editor.toDOMNode) return 18
const element = editor.toDOMNode(node)
const text = element?.querySelector("[data-slate-string='true']")
return parseFontSize(window.getComputedStyle(text || element).fontSize)
}
import { defineEditorFeature } from '../../core/define-editor-feature'
import convertTooltipMenu from '../../customer/ConvertTooltipType'
import removeSpacesMenu from '../../customer/RemoveSpaces'
import convertTooltipMenu from './convert-tooltip-type-menu'
import removeSpacesMenu from './remove-spaces-menu'
export default defineEditorFeature({
id: 'content-tools',
......
import { describe, expect, it } from 'vitest'
import { getSelectionFontSize } from '@/common/wangeditor-customer/core/selection'
describe('getSelectionFontSize', () => {
it('uses the default size without a selection', () => {
expect(getSelectionFontSize({ selection: null })).toBe(18)
})
it('reads the selected Slate node synchronously', () => {
const editor = {
selection: { anchor: { path: [0, 0] } },
children: [{ children: [{ text: '正文', fontSize: '21px' }] }],
}
expect(getSelectionFontSize(editor)).toBe(21)
})
})
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论