This commit is contained in:
luochao 2020-12-13 10:25:04 +08:00
commit 1954d27eff
5 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wangEditor example</title>
<style>
</style>
</head>
<body>
<p>
wangEditor 自定义菜单
</p>
<div id="div1"></div>
<script src="../dist/wangEditor.js"></script>
<script>
const E = window.wangEditor
const editor = new E('#div1')
// editor.config.menus = ['fontSize', 'bold']
// 需要排除的菜单
editor.config.excludeMenus = ['bold']
editor.create()
</script>
</body>
</html>

View File

@ -25,6 +25,7 @@ export type ConfigType = {
languageType: string[]
languageTab: string
menus: string[]
excludeMenus: string[]
fontNames: string[]
lineHeights: string[]
indentation: IndentationType

View File

@ -34,6 +34,12 @@ class Menus {
public init(): void {
// 从用户配置的 menus 入手,看需要初始化哪些菜单
const config = this.editor.config
// 排除exclude包含的菜单
let excludeMenus: string[] | any = config.excludeMenus
if (Array.isArray(excludeMenus) === false) excludeMenus = []
config.menus = config.menus.filter(key => excludeMenus.includes(key) === false)
config.menus.forEach(menuKey => {
const MenuConstructor = this.constructorList[menuKey] // 暂用 any ,后面再替换
if (MenuConstructor == null || typeof MenuConstructor !== 'function') {

View File

@ -16,3 +16,11 @@ test('菜单数量', () => {
})
// 各个菜单的配置,随后开发的时候再加
test('菜单 exclude', () => {
const editor = createEditor(document, 'div1', '', {
excludeMenus: ['bold'],
})
const menus = editor.config.menus
// 不包含bold
expect(menus).not.toContain('bold')
})