/** * @description 初始化编辑器 DOM 结构 * @author wangfupeng */ import Editor from '../index' import $, { DomElement } from '../../utils/dom-core' import { getRandom } from '../../utils/util' import { EMPTY_P } from '../../utils/const' const styleSettings = { border: '1px solid #c9d8db', toolbarBgColor: '#FFF', toolbarBottomBorder: '1px solid #EEE', } export default function (editor: Editor): void { const toolbarSelector = editor.toolbarSelector const $toolbarSelector = $(toolbarSelector) const textSelector = editor.textSelector const config = editor.config const height = config.height const i18next = editor.i18next const $toolbarElem: DomElement = $('
') const $textContainerElem: DomElement = $('') let $textElem: DomElement let $children: DomElement | null let $subChildren: DomElement | null = null if (textSelector == null) { // 将编辑器区域原有的内容,暂存起来 $children = $toolbarSelector.children() // 添加到 DOM 结构中 $toolbarSelector.append($toolbarElem).append($textContainerElem) // 自行创建的,需要配置默认的样式 $toolbarElem .css('background-color', styleSettings.toolbarBgColor) .css('border', styleSettings.border) .css('border-bottom', styleSettings.toolbarBottomBorder) $textContainerElem .css('border', styleSettings.border) .css('border-top', 'none') .css('height', `${height}px`) } else { // toolbarSelector 和 textSelector 都有 $toolbarSelector.append($toolbarElem) // 菜单分离后,文本区域内容暂存 $subChildren = $(textSelector).children() $(textSelector).append($textContainerElem) // 将编辑器区域原有的内容,暂存起来 $children = $textContainerElem.children() } // 编辑区域 $textElem = $('') $textElem.attr('contenteditable', 'true').css('width', '100%').css('height', '100%') // 添加 placeholder const $placeholder = $(`