Skip to content

Commit 0dc1bee

Browse files
committed
Add btns map
1 parent fdb917f commit 0dc1bee

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/components/DefaultConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import KatexParser from './plugin/KatexParser'
2-
import {toolbarBtn} from './toolbar-button/toolbarBtn'
2+
import { defaultBtns, getBtns } from './toolbar-button/toolbarBtn'
33
import _ from 'lodash'
44

55
function set (obj, config) {
@@ -17,7 +17,7 @@ export let defaultConfig = {
1717
parsers: [
1818
KatexParser
1919
],
20-
toolbarConfig: toolbarBtn,
20+
toolbarConfig: defaultBtns,
2121
editorOption: {
2222
mode: 'markdown',
2323
lineNumbers: true,
@@ -26,5 +26,6 @@ export let defaultConfig = {
2626
}
2727

2828
export function getConfig (config) {
29+
if (config.toolbarConfig !== undefined) { config.toolbarConfig = getBtns(config.toolbarConfig) }
2930
return set(_.cloneDeep(defaultConfig), config)
3031
}

src/components/toolbar-button/btn-delete.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/components/toolbar-button/toolbarBtn.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import BtnUl from './btn-ul'
1010
import BtnOl from './btn-ol'
1111
import BtnHr from './btn-hr'
1212

13-
export let toolbarBtn = [
13+
export let defaultBtns = [
1414
BtnBold,
1515
BtnStrikeThrough,
1616
BtnItalic,
@@ -30,3 +30,20 @@ export let toolbarBtn = [
3030
BtnLink,
3131
BtnTable
3232
]
33+
34+
function getDefaultBtnsMap () {
35+
let btnsMap = {}
36+
defaultBtns.forEach(function (btn) {
37+
btnsMap[btn.name] = btn
38+
})
39+
return btnsMap
40+
}
41+
42+
export function getBtns (toolbarConfig) {
43+
let btnsMap = getDefaultBtnsMap()
44+
let btns = []
45+
toolbarConfig.forEach(function (btn) {
46+
if (typeof btn === 'object') { btns.push(btn) } else { btns.push(btnsMap[btn]) }
47+
})
48+
return btns
49+
}

0 commit comments

Comments
 (0)