Skip to content

Commit

Permalink
feat: toolbar config - insertKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfupeng1988 committed Nov 10, 2021
1 parent 1cd0829 commit a2f3c4b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function genToolbarConfig(userConfig?: Partial<IToolbarConfig>): IToolbar
// 默认配置
toolbarKeys: [],
excludeKeys: [],
insertKeys: { index: 0, keys: [] },

// 合并用户配置
...(userConfig || {}),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ export interface IEditorConfig {
*/
export interface IToolbarConfig {
toolbarKeys: Array<string | IMenuGroup>
insertKeys: { index: number; keys: string | Array<string | IMenuGroup> }
excludeKeys: Array<string> // 排除哪些菜单
}
13 changes: 12 additions & 1 deletion packages/core/src/menus/bar/Toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ class Toolbar {
private registerItems() {
let prevKey = ''
const $toolbar = this.$toolbar
const { toolbarKeys = [], excludeKeys = [] } = this.config // 格式如 ['a', '|', 'b', 'c', '|', 'd']
const { toolbarKeys = [], insertKeys = { index: 0, keys: [] }, excludeKeys = [] } = this.config // 格式如 ['a', '|', 'b', 'c', '|', 'd']

// 新插入菜单
if (insertKeys.keys.length > 0) {
if (typeof insertKeys.keys === 'string') {
insertKeys.keys = [insertKeys.keys]
}

insertKeys.keys.forEach((k, i) => {
toolbarKeys.splice(insertKeys.index + i, 0, k)
})
}

// 排除某些菜单
const filteredKeys = toolbarKeys.filter(key => {
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/examples/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@
'redo',
'|', // 最后一个是 `|` 不显示
],
// insertKeys: {
// index: 5,
// keys: ['insertImage', 'insertVideo']
// },
// excludeKeys: ['headerSelect', 'underline', 'group-more-style', 'fontFamily']
}
},
})
</script>
</body>
Expand Down

0 comments on commit a2f3c4b

Please sign in to comment.