This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
/
index.js
109 lines (97 loc) · 3.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import polyfill from './polyfill-ie'
import buildInModules from './modules/index'
import editor from './editor'
import i18nZhCn from './i18n/zh-cn'
import i18nEnUs from './i18n/en-us'
import mixin from './util/mixin'
polyfill()
/**
* Vue html5 Editor
* @param Vue {Vue}
* @param options {Object}
*/
class VueHtml5Editor {
/**
* build an editor component
*/
constructor(options = {}) {
let modules = [...buildInModules]
const components = {}
// extended modules
if (Array.isArray(options.modules)) {
options.modules.forEach((module) => {
if (module.name) {
modules.push(module)
}
})
}
// hidden modules
if (Array.isArray(options.hiddenModules)) {
modules = (() => {
const arr = []
modules.forEach((m) => {
if (!options.hiddenModules.includes(m.name)) {
arr.push(m)
}
})
return arr
})()
}
// visible modules
if (Array.isArray(options.visibleModules)) {
modules = (() => {
const arr = []
modules.forEach((module) => {
if (options.visibleModules.includes(module.name)) {
arr.push(module)
}
})
return arr
})()
}
modules.forEach((module) => {
// specify the config for each module in options by name
const config = options[module.name]
module.config = mixin(module.config, config)
if (module.dashboard) {
// $options.module
module.dashboard.module = module
components[`dashboard-${module.name}`] = module.dashboard
}
if (options.icons && options.icons[module.name]) {
module.icon = options.icons[module.name]
}
module.hasDashboard = !!module.dashboard
// prevent vue sync
module.dashboard = null
})
// i18n
const i18n = {'zh-cn': i18nZhCn, 'en-us': i18nEnUs}
const customI18n = options.i18n || {}
Object.keys(customI18n).forEach((key) => {
i18n[key] = i18n[key] ? mixin(i18n[key], customI18n[key]) : customI18n[key]
})
const language = options.language || 'en-us'
const locale = i18n[language]
// showModuleName
const defaultShowModuleName = !!options.showModuleName
// ######################################
const compo = mixin(editor, {
data() {
return {modules, locale, defaultShowModuleName}
},
components
})
mixin(this, compo)
}
/**
* global install
*
* @param Vue
* @param options
*/
static install(Vue, options = {}) {
Vue.component(options.name || 'vue-html5-editor', new VueHtml5Editor(options))
}
}
export default VueHtml5Editor