Feat:转换富文本节点数据的逻辑由Render类移至RichText插件本身

This commit is contained in:
街角小林
2024-12-09 18:35:31 +08:00
parent 322975528e
commit ade7a95f3c
2 changed files with 10 additions and 8 deletions

View File

@@ -112,20 +112,17 @@ class Render {
// 设置布局结构
setLayout() {
const { layout } = this.mindMap.opt
this.layout = new (
layouts[this.mindMap.opt.layout]
? layouts[this.mindMap.opt.layout]
layouts[layout]
? layouts[layout]
: layouts[CONSTANTS.LAYOUT.LOGICAL_STRUCTURE]
)(this, this.mindMap.opt.layout)
)(this, layout)
}
// 重新设置思维导图数据
setData(data) {
if (this.hasRichTextPlugin()) {
this.renderTree = data ? this.mindMap.richText.handleSetData(data) : null
} else {
this.renderTree = data
}
this.renderTree = data || null
}
// 绑定事件

View File

@@ -81,9 +81,12 @@ class RichText {
this.onCompositionStart = this.onCompositionStart.bind(this)
this.onCompositionUpdate = this.onCompositionUpdate.bind(this)
this.onCompositionEnd = this.onCompositionEnd.bind(this)
this.handleSetData = this.handleSetData.bind(this)
window.addEventListener('compositionstart', this.onCompositionStart)
window.addEventListener('compositionupdate', this.onCompositionUpdate)
window.addEventListener('compositionend', this.onCompositionEnd)
this.mindMap.on('before_update_data', this.handleSetData)
this.mindMap.on('before_set_data', this.handleSetData)
}
// 解绑事件
@@ -91,6 +94,8 @@ class RichText {
window.removeEventListener('compositionstart', this.onCompositionStart)
window.removeEventListener('compositionupdate', this.onCompositionUpdate)
window.removeEventListener('compositionend', this.onCompositionEnd)
this.mindMap.off('before_update_data', this.handleSetData)
this.mindMap.off('before_set_data', this.handleSetData)
}
// 插入样式