/** * @description 初始化编辑器 DOM 结构 * @author wangfupeng */ import Editor from '../index' import $, { DomElement } from '../../utils/dom-core' import { getRandom } from '../../utils/util' 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 let $toolbarElem: DomElement let $textContainerElem: DomElement let $textElem: DomElement let $children: DomElement | null if (textSelector == null) { // 只有 toolbarSelector ,即是容器的选择器或元素,toolbar 和 text 的元素自行创建 $toolbarElem = $('
') $textContainerElem = $('') // 将编辑器区域原有的内容,暂存起来 $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 都有 $toolbarElem = $toolbarSelector $textContainerElem = $(textSelector) // 将编辑器区域原有的内容,暂存起来 $children = $textContainerElem.children() } // 编辑区域 $textElem = $('') $textElem.attr('contenteditable', 'true').css('width', '100%').css('height', '100%') // 添加 placeholder const $placeholder = $(`