diff --git a/packages/@typex-core/model/content.js b/packages/@typex-core/model/content.js index 59236eb..707e3b1 100644 --- a/packages/@typex-core/model/content.js +++ b/packages/@typex-core/model/content.js @@ -439,14 +439,14 @@ export default class Content extends Component { /** * @description 格式设置 - * @param {*} range + * @param {Range} range * @param {function} callback 格式处理回调 * @memberof Content * @instance */ setFormat (range, callback) { const commonPath = range.startContainer.queryCommonPath(range.endContainer) - const selectedPath = this.$editor.selection.getSeletedPath() + const selectedPath = this.$editor.selection.getLeafPaths() for (const path of selectedPath) { callback(path) } @@ -455,4 +455,23 @@ export default class Content extends Component { this.$editor.selection.drawRangeBg() }) } + + /** + * @description 组件设置 + * @param {Range} range + * @param {function} callback 格式处理回调 + * @memberof Content + * @instance + */ + setComponent (range, callback) { + const commonPath = range.startContainer.queryCommonPath(range.endContainer) + const selectedPath = this.$editor.selection.getPeerPaths() + for (const path of selectedPath) { + callback(path) + } + commonPath.currentComponent.$path.parent.currentComponent.update().then(() => { + range.updateCaret() + this.$editor.selection.drawRangeBg() + }) + } } diff --git a/packages/@typex-core/selection/index.js b/packages/@typex-core/selection/index.js index 1e994fe..d4cb3de 100644 --- a/packages/@typex-core/selection/index.js +++ b/packages/@typex-core/selection/index.js @@ -378,7 +378,7 @@ export default class Selection { * @memberof Selection * @instance */ - getSeletedPath () { + getLeafPaths () { if (this.collapsed) return [] const range = this.ranges[0] let start, @@ -433,6 +433,17 @@ export default class Selection { }, } } + + /** + * @description 获取同级path + * @memberof Selection + */ + getPeerPaths () { + if (this.collapse) { + return [this.ranges[0].container.currentComponent.$path] + } + } + recoverRangesFromSnapshot (rangesSnapshot) { this.removeAllRanges() this.ranges = rangesSnapshot.map((jsonRange) => diff --git a/packages/@typex-platform/web/dom.js b/packages/@typex-platform/web/dom.js index cf5f842..cfe81ea 100644 --- a/packages/@typex-platform/web/dom.js +++ b/packages/@typex-platform/web/dom.js @@ -26,7 +26,6 @@ export function appendChild (parentNode, newNode) { } export function removeChild (parentNode, referenceNode) { execDestory(referenceNode) - console.log(1); return parentNode.removeChild(referenceNode) } diff --git a/packages/editor/data.js b/packages/editor/data.js index fc917b7..d8f05d8 100644 --- a/packages/editor/data.js +++ b/packages/editor/data.js @@ -21,7 +21,6 @@ export const mockData = { data: [ { data: '这是1121一个基于Typex编写的简单富文本编辑器demo', - formats: { color: '#666', bold: true, fontSize: '20px' }, }, ], formats: { paragraph: true }, diff --git a/packages/editor/formats/components/Header.js b/packages/editor/formats/components/Header.js index 8d41c88..38cac2b 100644 --- a/packages/editor/formats/components/Header.js +++ b/packages/editor/formats/components/Header.js @@ -8,11 +8,6 @@ import Block from './block' export default class Header extends Block { render (h) { - // return h(`h${this.props.level}`, null, this.$path.render()) - return ( -
- {this.$path.render()} -
- ) + return h(`h${this.props.level}`, null, this.$path.render()) } } diff --git a/packages/editor/toolBar/compinents/Dialog.js b/packages/editor/toolBar/compinents/Dialog.js index ad77fb4..97beffd 100644 --- a/packages/editor/toolBar/compinents/Dialog.js +++ b/packages/editor/toolBar/compinents/Dialog.js @@ -9,7 +9,7 @@ export class Dialog extends Component { return (