forked from baianat/vuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styler.js
30 lines (27 loc) · 934 Bytes
/
styler.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
import Styler from './components/VuseStyler.vue';
import { getTypeFromTagName, getTypeFromSchema } from './util';
function installStyler ({ builder, Vue }) {
const StylerInstance = Vue.extend(Styler).extend({
beforeCreate () {
this.$builder = builder;
}
});
builder.styler = {
inserted (el, binding, vnode) {
const newNode = document.createElement('div');
const section = vnode.context.$section;
const rootApp = vnode.context.$root.$el;
rootApp.appendChild(newNode);
el.classList.add('is-editable');
section.stylers.push(new StylerInstance({
propsData: {
el,
section: section,
type: binding.arg || getTypeFromSchema(binding.expression, section.schema) || getTypeFromTagName(el.tagName),
name: binding.expression
}
}).$mount(newNode));
}
};
};
export default installStyler;