-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
161 lines (141 loc) · 3.63 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { createApp } from "vue";
function data_handler(value) {
const view = $$(this.webixId);
if (typeof value === "object") {
if (this.copyData) value = webix.copy(value);
if (view.setValues) view.setValues(value);
else if (view.parse) {
view.clearAll();
view.parse(value);
}
} else if (view.setValue) view.setValue(value);
const subs = view.queryView(sub => {
return sub.hasEvent && sub.hasEvent("onValue");
}, "all");
if (subs.length) {
subs.forEach(sub => {
sub.callEvent("onValue", [value]);
});
}
}
export function registerWebixUIComponent(app) {
app.component("webix-ui", {
props: ["config", "modelValue", "copyData"],
watch: {
modelValue: {
handler: data_handler,
},
},
template: "<div></div>",
mounted() {
const config = webix.copy(this.config);
config.$scope = this;
this.webixId = webix.ui(config, this.$el);
if (this.modelValue) data_handler.call(this, this.modelValue);
},
destroyed() {
webix.$$(this.webixId).destructor();
},
});
}
const controls = [
"text",
"search",
"slider",
"checkbox",
"colorpicker",
"datepicker",
"counter",
"richtext",
"textarea",
"tabbar",
"segmented",
"combo",
"richselect",
"multicombo",
"select",
"button",
"radio",
];
const props = ["label", "labelWidth", "options", "labelPosition"];
const props_handler = function(name) {
return function(value) {
const self = webix.$$(this.webixId);
self.config[name] = value;
self.render();
};
};
function add_input(app, name) {
const handlers = {
modelValue: {
handler(value) {
const self = webix.$$(this.webixId);
self.setValue(value);
},
},
};
for (let i = 0; i < props.length; i++)
handlers[props[i]] = props_handler(props[i]);
app.component("webix-" + name, {
props: ["modelValue", "label", "labelWidth", "options", "labelPosition", "id"],
template: "<div></div>",
watch: handlers,
mounted() {
const config = {
view: name,
value: this.modelValue,
};
if (this.label) config.label = this.label;
if (this.labelWidth) config.labelWidth = this.labelWidth;
if (this.labelPosition) config.labelPosition = this.labelPosition;
if (this.options) config.options = webix.copy(this.options);
this.webixId = webix.ui(config, this.$el);
const context = this;
$$(this.webixId).attachEvent("onChange", function() {
const value = this.getValue();
if (context.modelValue != value)
context.$emit("update:modelValue", value);
});
},
destroyed() {
webix.$$(this.webixId).destructor();
},
});
}
export function registerWebixControls(app) {
for (let i = 0; i < controls.length; i++) add_input(app, controls[i]);
}
webix.protoUI(
{
name: "vue",
$init(config) {
const vtm = config.template;
const id = "vue_" + webix.uid();
this.$vueData = config.data;
delete config.data;
config.template = "<div id='" + id + "'></div>";
this.attachEvent("onAfterRender", function() {
this.$vue = createApp({
template: vtm,
methods: this.config.methods || {},
watch: this.config.watch,
data: () => {
return this.$vueData;
},
}).mount("#" + id);
});
},
getVue() {
return this.$vue;
},
setValues(value) {
if (this.$vue)
for (const key in value) {
if (typeof this.$vueData[key] !== "undefined")
this.$vue[key] = value[key];
}
else this.$vueData = value;
},
},
webix.ui.template
);