renusify 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/app/index.vue +14 -14
- package/components/{notify → app/notify}/index.vue +1 -1
- package/components/{notify → app/notify}/notification.vue +0 -0
- package/components/{notify → app/notify}/notify.js +0 -0
- package/components/app/style.scss +0 -1
- package/components/{toast → app/toast}/index.vue +0 -0
- package/components/{toast → app/toast}/style.scss +1 -1
- package/components/{toast → app/toast}/toast.js +0 -0
- package/components/{toast → app/toast}/toast.vue +0 -0
- package/components/breadcrumb/bredcrumbItem.vue +11 -11
- package/components/breadcrumb/index.vue +6 -5
- package/components/chart/chart.vue +3 -0
- package/components/chat/chatInput.vue +139 -135
- package/components/codeEditor/index.vue +432 -449
- package/components/codeEditor/run.vue +76 -80
- package/components/content/style.scss +0 -1
- package/components/form/address.vue +109 -109
- package/components/form/address_ir.vue +106 -0
- package/components/form/colorPicker/Alpha.vue +3 -0
- package/components/form/colorPicker/Preview.vue +3 -0
- package/components/form/group-input.vue +2 -1
- package/components/form/number.vue +1 -1
- package/components/iframe/index.vue +1 -1
- package/components/index.js +178 -88
- package/components/infinite/index.vue +0 -2
- package/components/menu/index.vue +173 -125
- package/components/modal/index.vue +85 -90
- package/components/modal/style.scss +0 -1
- package/components/table/crud/index.vue +12 -13
- package/directive/clickOutSide/index.js +2 -3
- package/directive/drag/index.js +1 -2
- package/directive/intersect/index.js +3 -3
- package/directive/resize/index.js +3 -4
- package/directive/ripple/index.js +4 -6
- package/directive/scroll/index.js +3 -4
- package/directive/sortable/index.js +1 -2
- package/directive/title/index.js +2 -3
- package/directive/touch/index.js +1 -2
- package/index.js +4 -5
- package/package.json +1 -1
- package/plugins/trans/Translate.js +12 -14
|
@@ -1,472 +1,455 @@
|
|
|
1
1
|
<template>
|
|
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
|
-
|
|
2
|
+
<div :class="`${$r.prefix}code-editor`">
|
|
3
|
+
<div class="code-action text-right">
|
|
4
|
+
<r-btn text @click.prevent="$helper.copy($refs.codeView.innerText)" class="image-copy" icon>
|
|
5
|
+
<r-icon v-html="$r.icons.copy"></r-icon>
|
|
6
|
+
</r-btn>
|
|
7
|
+
<r-btn v-if="show==='code'&&runnable" text @click="show='run'">
|
|
8
|
+
run
|
|
9
|
+
<r-icon v-html="$r.icons.play" exact></r-icon>
|
|
10
|
+
</r-btn>
|
|
11
|
+
<r-btn v-if="show==='run'" text @click="show='code'">
|
|
12
|
+
<r-icon v-html="$r.icons.code_tags" exact></r-icon>
|
|
13
|
+
</r-btn>
|
|
14
|
+
</div>
|
|
15
|
+
<div v-show="false" ref="codeSlot">
|
|
16
|
+
<slot></slot>
|
|
17
|
+
</div>
|
|
18
|
+
<div v-if="show==='run'&&runnable" class="code-compile">
|
|
19
|
+
<r-code-editor-run :template="template.outerHTML" :script="script"></r-code-editor-run>
|
|
20
|
+
</div>
|
|
21
|
+
<div v-show="show!=='run'" ref="codeView" class="code-wrapper">
|
|
22
|
+
<div v-show="template">
|
|
23
|
+
<span class="color-green" v-if="runnable"><template></span>
|
|
24
|
+
<div ref="codeViewTemplate" :contenteditable="runnable" @input="rebuildHtml" class="code-template"></div>
|
|
25
|
+
<span class="color-green" v-if="runnable"></template></span>
|
|
26
|
+
<br>
|
|
27
|
+
</div>
|
|
28
|
+
<div v-show="script">
|
|
29
29
|
<span class="color-orange" v-if="runnable"><script>
|
|
30
30
|
<br>
|
|
31
31
|
export default {</span>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<div v-show="style">
|
|
36
|
-
<span class="color-orange" v-if="runnable"><style></span>
|
|
37
|
-
<div ref="codeViewStyle" :contenteditable="runnable" @input="rebuild" class="code-style"></div>
|
|
38
|
-
<span class="color-orange" v-if="runnable"></style></span>
|
|
39
|
-
</div>
|
|
40
|
-
</div>
|
|
32
|
+
<div ref="codeViewScript" :contenteditable="runnable" @input="rebuild" class="code-script"></div>
|
|
33
|
+
<span class="color-orange" v-if="runnable">}<br><script></span>
|
|
34
|
+
</div>
|
|
41
35
|
</div>
|
|
36
|
+
</div>
|
|
42
37
|
</template>
|
|
43
38
|
<script>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
style: null,
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
created(){
|
|
63
|
-
if(!this.$r.icons.play){
|
|
64
|
-
this.$r.icons.play = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="M8 5.14v14l11-7l-11-7Z"/></svg>'
|
|
65
|
-
}
|
|
66
|
-
if(!this.$r.icons.code_tags){
|
|
67
|
-
this.$r.icons.code_tags = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="m14.6 16.6l4.6-4.6l-4.6-4.6L16 6l6 6l-6 6l-1.4-1.4m-5.2 0L4.8 12l4.6-4.6L8 6l-6 6l6 6l1.4-1.4Z"/></svg>'
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
mounted() {
|
|
71
|
-
this.get_code('codeSlot', this.runnable)
|
|
72
|
-
},
|
|
73
|
-
beforeUpdate() {
|
|
74
|
-
if (this.show === 'code' && !this.edited) {
|
|
75
|
-
this.get_code('codeSlot', this.runnable)
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
methods: {
|
|
79
|
-
node_walk(node, func) {
|
|
80
|
-
let result = func(node);
|
|
81
|
-
for (node = node.firstChild; result !== false && node; node = node.nextSibling)
|
|
82
|
-
result = this.node_walk(node, func);
|
|
83
|
-
return result;
|
|
84
|
-
},
|
|
85
|
-
getCaretPosition(elem) {
|
|
86
|
-
var sel = window.getSelection();
|
|
87
|
-
var cum_length = [0, 0];
|
|
88
|
-
|
|
89
|
-
if (sel.anchorNode == elem)
|
|
90
|
-
cum_length = [sel.anchorOffset, sel.extentOffset];
|
|
91
|
-
else {
|
|
92
|
-
var nodes_to_find = [sel.anchorNode, sel.extentNode];
|
|
93
|
-
if (!elem.contains(sel.anchorNode) || !elem.contains(sel.extentNode))
|
|
94
|
-
return undefined;
|
|
95
|
-
else {
|
|
96
|
-
var found = [0, 0];
|
|
97
|
-
var i;
|
|
98
|
-
this.node_walk(elem, function (node) {
|
|
99
|
-
for (i = 0; i < 2; i++) {
|
|
100
|
-
if (node == nodes_to_find[i]) {
|
|
101
|
-
found[i] = true;
|
|
102
|
-
if (found[i == 0 ? 1 : 0])
|
|
103
|
-
return false; // all done
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (node.textContent && !node.firstChild) {
|
|
108
|
-
for (i = 0; i < 2; i++) {
|
|
109
|
-
if (!found[i])
|
|
110
|
-
cum_length[i] += node.textContent.length;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
cum_length[0] += sel.anchorOffset;
|
|
115
|
-
cum_length[1] += sel.extentOffset;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (cum_length[0] <= cum_length[1])
|
|
119
|
-
return cum_length;
|
|
120
|
-
return [cum_length[1], cum_length[0]];
|
|
121
|
-
},
|
|
122
|
-
createRange(node, chars, range) {
|
|
123
|
-
if (!range) {
|
|
124
|
-
range = document.createRange()
|
|
125
|
-
range.selectNode(node);
|
|
126
|
-
range.setStart(node, 0);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (chars.count === 0) {
|
|
130
|
-
range.setEnd(node, chars.count);
|
|
131
|
-
} else if (node && chars.count > 0) {
|
|
132
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
133
|
-
if (node.textContent.length < chars.count) {
|
|
134
|
-
chars.count -= node.textContent.length;
|
|
135
|
-
} else {
|
|
136
|
-
range.setEnd(node, chars.count);
|
|
137
|
-
chars.count = 0;
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
const lng=node.childNodes.length
|
|
141
|
-
for (var lp = 0; lp < lng; lp++) {
|
|
142
|
-
range = this.createRange(node.childNodes[lp], chars, range);
|
|
143
|
-
|
|
144
|
-
if (chars.count === 0) {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return range;
|
|
152
|
-
},
|
|
153
|
-
rebuild(e) {
|
|
154
|
-
this.edited = true
|
|
155
|
-
const pos = this.getCaretPosition(this.$refs.codeView)
|
|
156
|
-
let spans = this.$refs.codeView.querySelectorAll('.code-editor-span')
|
|
157
|
-
if (spans) {
|
|
158
|
-
const lng=spans.length
|
|
159
|
-
for (let i = lng - 1; i >= 0; i--) {
|
|
160
|
-
let b = document.createDocumentFragment();
|
|
161
|
-
let res = this.$helper.replacer(spans[i].innerHTML, '<', '<')
|
|
162
|
-
res = this.$helper.replacer(res, '>', '>')
|
|
163
|
-
b.append(res)
|
|
164
|
-
spans[i].parentNode.replaceChild(b, spans[i]);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
this.get_code('codeView')
|
|
168
|
-
var selection = window.getSelection();
|
|
169
|
-
let range = this.createRange(this.$refs.codeView, {count: pos[0] + (e.inputType === 'insertParagraph' ? 1 : 0)});
|
|
170
|
-
if (range) {
|
|
171
|
-
range.collapse(false);
|
|
172
|
-
selection.removeAllRanges();
|
|
173
|
-
selection.addRange(range);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
toHTML(htmlString) {
|
|
178
|
-
var div = document.createElement('div');
|
|
179
|
-
div.innerHTML = htmlString.trim();
|
|
180
|
-
return div
|
|
181
|
-
},
|
|
182
|
-
get_code(slot = 'codeSlot') {
|
|
183
|
-
if (!this.$refs[slot]) {
|
|
184
|
-
setTimeout(() => {
|
|
185
|
-
this.get_code(slot)
|
|
186
|
-
}, 100)
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
this.code = this.toHTML(this.$refs[slot].innerHTML)
|
|
191
|
-
this.template = this.code.querySelector('.code-template')
|
|
192
|
-
if (this.template) {
|
|
193
|
-
this.template = this.template.innerHTML
|
|
194
|
-
}
|
|
195
|
-
this.script = this.code.querySelector('.code-script')
|
|
196
|
-
if (this.script) {
|
|
197
|
-
this.script = this.script.innerText.trim()
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.style = this.code.querySelector('.code-style')
|
|
201
|
-
if (this.style) {
|
|
202
|
-
this.style = this.style.innerText
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (this.template || this.script || this.style) {
|
|
206
|
-
this.$refs.codeViewTemplate.innerHTML = this.buildHtml()
|
|
207
|
-
this.$refs.codeViewScript.innerHTML = this.buildScript()
|
|
208
|
-
this.$refs.codeViewStyle.innerHTML = this.buildStyle()
|
|
209
|
-
} else {
|
|
210
|
-
this.$refs.codeView.innerHTML = this.$refs[slot].innerHTML
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
strToObj(str) {
|
|
214
|
-
str = this.$helper.replacer(str, ' ', '')
|
|
215
|
-
str = this.$helper.replacer(str, "\n", '')
|
|
216
|
-
str = this.$helper.replacer(str, "\r", '')
|
|
217
|
-
let open = 0
|
|
218
|
-
let pre = 0
|
|
219
|
-
let to = 0
|
|
220
|
-
let items = []
|
|
221
|
-
const s = str
|
|
222
|
-
s.split('').forEach((c, i) => {
|
|
223
|
-
to++
|
|
224
|
-
if (c === '{') {
|
|
225
|
-
open++
|
|
226
|
-
}
|
|
227
|
-
if (c === '}') {
|
|
228
|
-
open--
|
|
229
|
-
}
|
|
230
|
-
if (open === 0 && c === ',') {
|
|
231
|
-
let new_str = str.substr(pre, to - 1)
|
|
232
|
-
const o = new_str.indexOf(':')
|
|
233
|
-
const f = new_str.indexOf('(')
|
|
234
|
-
if ((f > 0 && f < o) || o < 0) {
|
|
235
|
-
new_str = new_str.substr(0, f)
|
|
236
|
-
} else {
|
|
237
|
-
new_str = new_str.substr(0, o)
|
|
238
|
-
}
|
|
239
|
-
items.push(new_str)
|
|
240
|
-
pre = i + 1
|
|
241
|
-
to = 0
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
let new_str = str.substr(pre, str.length)
|
|
245
|
-
const o = new_str.indexOf(':')
|
|
246
|
-
const f = new_str.indexOf('(')
|
|
247
|
-
if ((f > 0 && f < o) || o < 0) {
|
|
248
|
-
new_str = new_str.substr(0, f)
|
|
249
|
-
} else {
|
|
250
|
-
new_str = new_str.substr(0, o)
|
|
251
|
-
}
|
|
252
|
-
items.push(new_str)
|
|
253
|
-
return items
|
|
254
|
-
},
|
|
255
|
-
buildStyle() {
|
|
256
|
-
if (!this.style) {
|
|
257
|
-
return ''
|
|
258
|
-
}
|
|
259
|
-
let data = this.style.split('')
|
|
260
|
-
let res = ''
|
|
261
|
-
let in_quta = false
|
|
262
|
-
data.forEach((c, i) => {
|
|
263
|
-
if (c === '=') {
|
|
264
|
-
res += '<span class="color-blue code-editor-span">=</span>'
|
|
265
|
-
} else if ((c === '"' || c === "'") && !in_quta) {
|
|
266
|
-
in_quta = c
|
|
267
|
-
res += '<span class="color-green code-editor-span">' + c
|
|
268
|
-
} else if (c === in_quta) {
|
|
269
|
-
in_quta = false
|
|
270
|
-
res += c + '</span>'
|
|
271
|
-
} else {
|
|
272
|
-
res += c
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
let regex = /[\s]([.]|[#]|[:])[a-zA-Z0-9_-]+/g
|
|
276
|
-
let matched = res.matchAll(regex)
|
|
277
|
-
for (const match of matched) {
|
|
278
|
-
res = this.$helper.replacer(res, match[0], '<span class="color-orange code-editor-span">' + match[0] + '</span>')
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
regex = /:(.*?)+;/g
|
|
282
|
-
matched = res.matchAll(regex)
|
|
283
|
-
for (const match of matched) {
|
|
284
|
-
res = this.$helper.replacer(res, match[0], '<span class="color-blue code-editor-span">' + match[0] + '</span>')
|
|
285
|
-
}
|
|
286
|
-
res = this.$helper.replacer(res, '!important', '<span class="color-orange code-editor-span">!important</span>')
|
|
287
|
-
res = this.re_comment(res)
|
|
288
|
-
res = this.re_func(res)
|
|
289
|
-
|
|
290
|
-
return res
|
|
291
|
-
},
|
|
292
|
-
buildHtml() {
|
|
293
|
-
if (!this.template) {
|
|
294
|
-
return ''
|
|
295
|
-
}
|
|
296
|
-
let data = this.template.split('')
|
|
297
|
-
let res = ''
|
|
298
|
-
let in_quta = false
|
|
299
|
-
data.forEach((c, i) => {
|
|
300
|
-
if (c === '=') {
|
|
301
|
-
res += '<span class="color-blue code-editor-span">=</span>'
|
|
302
|
-
} else if ((c === '"' || c === "'") && !in_quta) {
|
|
303
|
-
in_quta = c
|
|
304
|
-
res += '<span class="color-green code-editor-span">' + c
|
|
305
|
-
} else if (c === in_quta) {
|
|
306
|
-
in_quta = false
|
|
307
|
-
res += c + '</span>'
|
|
308
|
-
} else {
|
|
309
|
-
res += c
|
|
310
|
-
}
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
res = this.$helper.replacer(res, '(!', '<span class="color-orange code-editor-span"><')
|
|
314
|
-
res = this.$helper.replacer(res, '!)', '></span>')
|
|
315
|
-
res = this.$helper.replacer(res, '[!', '<span class="color-blue code-editor-span">{{')
|
|
316
|
-
res = this.$helper.replacer(res, '!]', '}}</span>')
|
|
317
|
-
let regex = /\+(.*?)\+/g
|
|
318
|
-
let matched = res.matchAll(regex)
|
|
319
|
-
for (const match of matched) {
|
|
320
|
-
res = this.$helper.replacer(res, match[0], '<span class="color-blue code-editor-span">' + match[0] + '</span>')
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
res = this.re_words(res)
|
|
324
|
-
res = this.re_comment(res)
|
|
325
|
-
res = this.re_func(res)
|
|
326
|
-
|
|
327
|
-
return res
|
|
328
|
-
},
|
|
329
|
-
buildScript() {
|
|
330
|
-
if (!this.script) {
|
|
331
|
-
return ''
|
|
332
|
-
}
|
|
333
|
-
let data = this.script.split('')
|
|
334
|
-
let str = this.script.trim()
|
|
335
|
-
if (str.substr(0, 1) === '{') {
|
|
336
|
-
str = str.substr(1, str.length - 2)
|
|
337
|
-
}
|
|
338
|
-
let res = ''
|
|
339
|
-
|
|
340
|
-
let in_quta = false
|
|
341
|
-
data.forEach((c, i) => {
|
|
342
|
-
if (['=', '&', '{', '}', '<', '>'].includes(c)) {
|
|
343
|
-
res += '<span class="color-blue code-editor-span">' + c + '</span>'
|
|
344
|
-
} else if ([',', ';', ':'].includes(c)) {
|
|
345
|
-
res += '<span class="color-orange code-editor-span">' + c + '</span>'
|
|
346
|
-
} else if (parseInt(c) > -1) {
|
|
347
|
-
res += '<span class="color-number code-editor-span">' + c + '</span>'
|
|
348
|
-
} else if ((c === '"' || c === "'" || c === "`") && !in_quta) {
|
|
349
|
-
in_quta = c
|
|
350
|
-
res += '<span class="color-green code-editor-span">' + c
|
|
351
|
-
} else if (c === in_quta) {
|
|
352
|
-
in_quta = false
|
|
353
|
-
res += c + '</span>'
|
|
354
|
-
} else {
|
|
355
|
-
res += c
|
|
356
|
-
}
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
res = this.re_words(res)
|
|
360
|
-
res = this.re_comment(res)
|
|
361
|
-
res = this.re_func(res)
|
|
362
|
-
|
|
363
|
-
// main function vuejs methods created ,...
|
|
364
|
-
this.strToObj(str).forEach((item) => {
|
|
365
|
-
res = this.$helper.replacer(res, item, ' <span class="color-func code-editor-span">' + item + '</span>')
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
return res
|
|
369
|
-
},
|
|
370
|
-
re_words(res) {
|
|
371
|
-
res = this.$helper.replacer(res, 'import ', '<span class="color-orange code-editor-span">import</span> ')
|
|
372
|
-
res = this.$helper.replacer(res, ' from ', ' <span class="color-orange code-editor-span">from</span> ')
|
|
373
|
-
res = this.$helper.replacer(res, ' window.', ' <span class="color-orange code-editor-span">window</span>.')
|
|
374
|
-
res = this.$helper.replacer(res, ' new ', ' <span class="color-orange code-editor-span">new</span> ')
|
|
375
|
-
res = this.$helper.replacer(res, ' var ', ' <span class="color-orange code-editor-span">var</span> ')
|
|
376
|
-
res = this.$helper.replacer(res, ' let ', ' <span class="color-orange code-editor-span">let</span> ')
|
|
377
|
-
res = this.$helper.replacer(res, ' const ', ' <span class="color-orange code-editor-span">const</span> ')
|
|
378
|
-
res = this.$helper.replacer(res, ' return ', ' <span class="color-orange code-editor-span">return</span> ')
|
|
379
|
-
res = this.$helper.replacer(res, ' this.', ' <span class="color-orange code-editor-span">this</span>.')
|
|
380
|
-
|
|
381
|
-
return res
|
|
382
|
-
},
|
|
383
|
-
re_comment(res) {
|
|
384
|
-
let regex = /(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/g
|
|
385
|
-
let matched = res.matchAll(regex)
|
|
386
|
-
for (const match of matched) {
|
|
387
|
-
res = this.$helper.replacer(res, match[0], '<span class="color-comment code-editor-span">' + match[0] + '</span>')
|
|
388
|
-
}
|
|
389
|
-
return res
|
|
390
|
-
},
|
|
391
|
-
re_func(res) {
|
|
392
|
-
//function like Date()
|
|
393
|
-
let regex = /([a-zA-Z_{1}][a-zA-Z0-9_]+)[ ]{0,1}(?=\()/g
|
|
394
|
-
let matched = res.matchAll(regex)
|
|
395
|
-
for (const match of matched) {
|
|
396
|
-
res = this.$helper.replacer(res, match[0], '<span class="color-func2 code-editor-span">' + match[0] + '</span>')
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
//function like $r $d()
|
|
400
|
-
regex = /(\$([a-zA-z0-9]*)[.|(])/g
|
|
401
|
-
matched = res.matchAll(regex)
|
|
402
|
-
for (const match of matched) {
|
|
403
|
-
res = this.$helper.replacer(res, match[0].substr(0, match[0].length - 1), '<span class="color-func code-editor-span">' + match[0].substr(0, match[0].length - 1) + '</span>')
|
|
404
|
-
}
|
|
405
|
-
res = this.$helper.replacer(res, '(', '<span class="color-func2 code-editor-span">(</span>')
|
|
406
|
-
res = this.$helper.replacer(res, ')', '<span class="color-func2 code-editor-span">)</span>')
|
|
407
|
-
return res
|
|
408
|
-
}
|
|
409
|
-
}
|
|
39
|
+
import RCodeEditorRun from "./run";
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
name: 'r-code-editor',
|
|
43
|
+
components: {RCodeEditorRun},
|
|
44
|
+
props: {
|
|
45
|
+
runnable: Boolean
|
|
46
|
+
},
|
|
47
|
+
data() {
|
|
48
|
+
return {
|
|
49
|
+
show: 'code',
|
|
50
|
+
code: '',
|
|
51
|
+
edited: false,
|
|
52
|
+
template: null,
|
|
53
|
+
script: null
|
|
410
54
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
55
|
+
},
|
|
56
|
+
created() {
|
|
57
|
+
if (!this.$r.icons.play) {
|
|
58
|
+
this.$r.icons.play = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="M8 5.14v14l11-7l-11-7Z"/></svg>'
|
|
59
|
+
}
|
|
60
|
+
if (!this.$r.icons.code_tags) {
|
|
61
|
+
this.$r.icons.code_tags = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path fill="currentColor" d="m14.6 16.6l4.6-4.6l-4.6-4.6L16 6l6 6l-6 6l-1.4-1.4m-5.2 0L4.8 12l4.6-4.6L8 6l-6 6l6 6l1.4-1.4Z"/></svg>'
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
mounted() {
|
|
65
|
+
this.get_code('codeSlot')
|
|
66
|
+
},
|
|
67
|
+
beforeUpdate() {
|
|
68
|
+
if (this.show === 'code' && !this.edited) {
|
|
69
|
+
this.get_code('codeSlot')
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
methods: {
|
|
73
|
+
node_walk(node, func) {
|
|
74
|
+
let result = func(node);
|
|
75
|
+
for (node = node.firstChild; result !== false && node; node = node.nextSibling)
|
|
76
|
+
result = this.node_walk(node, func);
|
|
77
|
+
return result;
|
|
78
|
+
},
|
|
79
|
+
getCaretPosition(elem) {
|
|
80
|
+
let sel = window.getSelection();
|
|
81
|
+
let cum_length = [0, 0];
|
|
82
|
+
|
|
83
|
+
if (sel.anchorNode == elem)
|
|
84
|
+
cum_length = [sel.anchorOffset, sel.extentOffset];
|
|
85
|
+
else {
|
|
86
|
+
let nodes_to_find = [sel.anchorNode, sel.extentNode];
|
|
87
|
+
if (!elem.contains(sel.anchorNode) || !elem.contains(sel.extentNode))
|
|
88
|
+
return undefined;
|
|
89
|
+
else {
|
|
90
|
+
let found = [0, 0];
|
|
91
|
+
let i;
|
|
92
|
+
this.node_walk(elem, function (node) {
|
|
93
|
+
for (i = 0; i < 2; i++) {
|
|
94
|
+
if (node == nodes_to_find[i]) {
|
|
95
|
+
found[i] = true;
|
|
96
|
+
if (found[i == 0 ? 1 : 0])
|
|
97
|
+
return false; // all done
|
|
98
|
+
}
|
|
99
|
+
}
|
|
419
100
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
101
|
+
if (node.textContent && !node.firstChild) {
|
|
102
|
+
for (i = 0; i < 2; i++) {
|
|
103
|
+
if (!found[i])
|
|
104
|
+
cum_length[i] += node.textContent.length;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
cum_length[0] += sel.anchorOffset;
|
|
109
|
+
cum_length[1] += sel.extentOffset;
|
|
423
110
|
}
|
|
111
|
+
}
|
|
112
|
+
if (cum_length[0] <= cum_length[1])
|
|
113
|
+
return cum_length;
|
|
114
|
+
return [cum_length[1], cum_length[0]];
|
|
115
|
+
},
|
|
116
|
+
createRange(node, chars, range) {
|
|
117
|
+
if (!range) {
|
|
118
|
+
range = document.createRange()
|
|
119
|
+
range.selectNode(node);
|
|
120
|
+
range.setStart(node, 0);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (chars.count === 0) {
|
|
124
|
+
range.setEnd(node, chars.count);
|
|
125
|
+
} else if (node && chars.count > 0) {
|
|
126
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
127
|
+
if (node.textContent.length < chars.count) {
|
|
128
|
+
chars.count -= node.textContent.length;
|
|
129
|
+
} else {
|
|
130
|
+
range.setEnd(node, chars.count);
|
|
131
|
+
chars.count = 0;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
const lng = node.childNodes.length
|
|
135
|
+
for (let lp = 0; lp < lng; lp++) {
|
|
136
|
+
range = this.createRange(node.childNodes[lp], chars, range);
|
|
424
137
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
color: #ffffff;
|
|
430
|
-
padding: 10px;
|
|
138
|
+
if (chars.count === 0) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
431
142
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return range;
|
|
146
|
+
},
|
|
147
|
+
rebuild(e) {
|
|
148
|
+
this.edited = true
|
|
149
|
+
const pos = this.getCaretPosition(this.$refs.codeViewScript)
|
|
150
|
+
this.script = this.$refs.codeViewScript.innerText
|
|
151
|
+
let selection = window.getSelection();
|
|
152
|
+
this.$refs.codeViewScript.innerHTML = this.buildScript(this.script)
|
|
153
|
+
let range = this.createRange(this.$refs.codeViewScript, {count: pos[0] + (e.inputType === 'insertParagraph' ? 1 : 0)});
|
|
154
|
+
if (range) {
|
|
155
|
+
range.collapse(false);
|
|
156
|
+
selection.removeAllRanges();
|
|
157
|
+
selection.addRange(range);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
},
|
|
161
|
+
rebuildHtml(e) {
|
|
162
|
+
this.edited = true
|
|
163
|
+
const pos = this.getCaretPosition(this.$refs.codeViewTemplate)
|
|
164
|
+
this.template = this.toHTML(this.$refs.codeViewTemplate.innerText)
|
|
165
|
+
let selection = window.getSelection();
|
|
166
|
+
this.$refs.codeViewTemplate.innerHTML = this.buildHtml(this.template.children[0])
|
|
167
|
+
let range = this.createRange(this.$refs.codeViewTemplate, {count: pos[0] + (e.inputType === 'insertParagraph' ? 1 : 0)});
|
|
168
|
+
|
|
169
|
+
if (range) {
|
|
170
|
+
range.collapse(false);
|
|
171
|
+
selection.removeAllRanges();
|
|
172
|
+
selection.addRange(range);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
},
|
|
176
|
+
toHTML(htmlString) {
|
|
177
|
+
let div = document.createElement('div');
|
|
178
|
+
div.innerHTML = htmlString;
|
|
179
|
+
return div
|
|
180
|
+
},
|
|
181
|
+
get_code(slot = 'codeSlot') {
|
|
182
|
+
if (!this.$refs[slot]) {
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
this.get_code(slot)
|
|
185
|
+
}, 100)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.code = this.toHTML(this.$refs[slot].innerHTML)
|
|
190
|
+
let temp = this.code.querySelector('.code-template')
|
|
191
|
+
|
|
192
|
+
if (temp && temp.childNodes.length > 0) {
|
|
193
|
+
for (let i = 0; i < temp.childNodes.length; i++) {
|
|
194
|
+
if (temp.childNodes[i].nodeName === "#comment") {
|
|
195
|
+
this.template = this.toHTML(temp.childNodes[i].nodeValue).children[0]
|
|
196
|
+
break
|
|
197
|
+
}
|
|
436
198
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let script = this.code.querySelector('.code-script')
|
|
202
|
+
if (script && script.childNodes.length > 0) {
|
|
203
|
+
for (let i = 0; i < script.childNodes.length; i++) {
|
|
204
|
+
if (script.childNodes[i].nodeName === "#comment") {
|
|
205
|
+
this.script = script.childNodes[i].nodeValue
|
|
206
|
+
break
|
|
207
|
+
}
|
|
440
208
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if (this.template || this.script) {
|
|
213
|
+
this.$refs.codeViewTemplate.innerHTML = this.buildHtml(this.template)
|
|
214
|
+
this.$refs.codeViewScript.innerHTML = this.buildScript(this.script)
|
|
215
|
+
} else {
|
|
216
|
+
this.$refs.codeView.innerHTML = this.$refs[slot].innerHTML
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
strToObj(str) {
|
|
220
|
+
str = this.$helper.replacer(str, ' ', '')
|
|
221
|
+
str = this.$helper.replacer(str, "\n", '')
|
|
222
|
+
str = this.$helper.replacer(str, "\r", '')
|
|
223
|
+
let open = 0
|
|
224
|
+
let pre = 0
|
|
225
|
+
let to = 0
|
|
226
|
+
let items = []
|
|
227
|
+
const s = str
|
|
228
|
+
s.split('').forEach((c, i) => {
|
|
229
|
+
to++
|
|
230
|
+
if (c === '{') {
|
|
231
|
+
open++
|
|
444
232
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
color: orange;
|
|
233
|
+
if (c === '}') {
|
|
234
|
+
open--
|
|
448
235
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
236
|
+
if (open === 0 && c === ',') {
|
|
237
|
+
let new_str = str.substr(pre, to - 1)
|
|
238
|
+
const o = new_str.indexOf(':')
|
|
239
|
+
const f = new_str.indexOf('(')
|
|
240
|
+
if ((f > 0 && f < o) || o < 0) {
|
|
241
|
+
new_str = new_str.substr(0, f)
|
|
242
|
+
} else {
|
|
243
|
+
new_str = new_str.substr(0, o)
|
|
244
|
+
}
|
|
245
|
+
items.push(new_str)
|
|
246
|
+
pre = i + 1
|
|
247
|
+
to = 0
|
|
453
248
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
249
|
+
})
|
|
250
|
+
let new_str = str.substr(pre, str.length)
|
|
251
|
+
const o = new_str.indexOf(':')
|
|
252
|
+
const f = new_str.indexOf('(')
|
|
253
|
+
if ((f > 0 && f < o) || o < 0) {
|
|
254
|
+
new_str = new_str.substr(0, f)
|
|
255
|
+
} else {
|
|
256
|
+
new_str = new_str.substr(0, o)
|
|
257
|
+
}
|
|
258
|
+
items.push(new_str)
|
|
259
|
+
return items
|
|
260
|
+
},
|
|
261
|
+
buildHtml(template) {
|
|
262
|
+
if (!template) {
|
|
263
|
+
return ''
|
|
264
|
+
}
|
|
265
|
+
let data = template.outerHTML
|
|
266
|
+
data = this.$helper.replacer(data, '<', '<')
|
|
267
|
+
data = this.$helper.replacer(data, '>', '>')
|
|
268
|
+
data = data.split('')
|
|
269
|
+
let res = ''
|
|
270
|
+
let in_quta = false
|
|
271
|
+
data.forEach((c, i) => {
|
|
272
|
+
if (c === '=') {
|
|
273
|
+
res += '<span class="color-blue code-editor-span">=</span>'
|
|
274
|
+
} else if ((c === '"' || c === "'") && !in_quta) {
|
|
275
|
+
in_quta = c
|
|
276
|
+
res += '<span class="color-green code-editor-span">' + c
|
|
277
|
+
} else if (c === in_quta) {
|
|
278
|
+
in_quta = false
|
|
279
|
+
res += c + '</span>'
|
|
280
|
+
} else {
|
|
281
|
+
res += c
|
|
458
282
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
res = this.$helper.replacer(res, '<', '<span class="color-orange code-editor-span"><')
|
|
286
|
+
res = this.$helper.replacer(res, '>', '></span>')
|
|
287
|
+
res = this.$helper.replacer(res, '{{', '<span class="color-blue code-editor-span">{{')
|
|
288
|
+
res = this.$helper.replacer(res, '}}', '}}</span>')
|
|
289
|
+
|
|
290
|
+
let regex = /\+(.*?)\+/g
|
|
291
|
+
let matched = res.matchAll(regex)
|
|
292
|
+
for (const match of matched) {
|
|
293
|
+
res = this.$helper.replacer(res, match[0], '<span class="color-blue code-editor-span">' + match[0] + '</span>')
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
res = this.re_words(res)
|
|
297
|
+
res = this.re_comment(res)
|
|
298
|
+
res = this.re_func(res)
|
|
299
|
+
|
|
300
|
+
return res
|
|
301
|
+
},
|
|
302
|
+
buildScript() {
|
|
303
|
+
if (!this.script) {
|
|
304
|
+
return ''
|
|
305
|
+
}
|
|
306
|
+
let data = this.script.split('')
|
|
307
|
+
let str = this.script.trim()
|
|
308
|
+
|
|
309
|
+
if (str.substr(0, 1) === '{') {
|
|
310
|
+
str = str.substr(1, str.length - 2)
|
|
311
|
+
}
|
|
312
|
+
let res = ''
|
|
313
|
+
|
|
314
|
+
let in_quta = false
|
|
315
|
+
data.forEach((c, i) => {
|
|
316
|
+
if (['=', '&', '{', '}', '<', '>'].includes(c)) {
|
|
317
|
+
res += '<span class="color-blue code-editor-span">' + c + '</span>'
|
|
318
|
+
} else if ([',', ';', ':'].includes(c)) {
|
|
319
|
+
res += '<span class="color-orange code-editor-span">' + c + '</span>'
|
|
320
|
+
} else if (parseInt(c) > -1) {
|
|
321
|
+
res += '<span class="color-number code-editor-span">' + c + '</span>'
|
|
322
|
+
} else if ((c === '"' || c === "'" || c === "`") && !in_quta) {
|
|
323
|
+
in_quta = c
|
|
324
|
+
res += '<span class="color-green code-editor-span">' + c
|
|
325
|
+
} else if (c === in_quta) {
|
|
326
|
+
in_quta = false
|
|
327
|
+
res += c + '</span>'
|
|
328
|
+
} else {
|
|
329
|
+
res += c
|
|
462
330
|
}
|
|
331
|
+
})
|
|
463
332
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
333
|
+
res = this.re_words(res)
|
|
334
|
+
res = this.re_comment(res)
|
|
335
|
+
res = this.re_func(res)
|
|
467
336
|
|
|
468
|
-
|
|
469
|
-
|
|
337
|
+
// main function vuejs methods created ,...
|
|
338
|
+
this.strToObj(str).forEach((item) => {
|
|
339
|
+
if (item) {
|
|
340
|
+
res = this.$helper.replacer(res, item, '<span class="color-func code-editor-span">' + item + '</span>')
|
|
470
341
|
}
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
return res
|
|
345
|
+
},
|
|
346
|
+
re_words(res) {
|
|
347
|
+
res = this.$helper.replacer(res, 'import ', '<span class="color-orange code-editor-span">import</span> ')
|
|
348
|
+
res = this.$helper.replacer(res, ' from ', ' <span class="color-orange code-editor-span">from</span> ')
|
|
349
|
+
res = this.$helper.replacer(res, ' window.', ' <span class="color-orange code-editor-span">window</span>.')
|
|
350
|
+
res = this.$helper.replacer(res, ' new ', ' <span class="color-orange code-editor-span">new</span> ')
|
|
351
|
+
res = this.$helper.replacer(res, ' var ', ' <span class="color-orange code-editor-span">var</span> ')
|
|
352
|
+
res = this.$helper.replacer(res, ' let ', ' <span class="color-orange code-editor-span">let</span> ')
|
|
353
|
+
res = this.$helper.replacer(res, ' const ', ' <span class="color-orange code-editor-span">const</span> ')
|
|
354
|
+
res = this.$helper.replacer(res, ' return ', ' <span class="color-orange code-editor-span">return</span> ')
|
|
355
|
+
res = this.$helper.replacer(res, ' true', ' <span class="color-orange code-editor-span">true</span>')
|
|
356
|
+
res = this.$helper.replacer(res, ' false', ' <span class="color-orange code-editor-span">false</span>')
|
|
357
|
+
res = this.$helper.replacer(res, ' this.', ' <span class="color-orange code-editor-span">this</span>.')
|
|
358
|
+
|
|
359
|
+
return res
|
|
360
|
+
},
|
|
361
|
+
re_comment(res) {
|
|
362
|
+
let regex = /(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/g
|
|
363
|
+
let matched = res.matchAll(regex)
|
|
364
|
+
for (const match of matched) {
|
|
365
|
+
res = this.$helper.replacer(res, match[0], '<span class="color-comment code-editor-span">' + match[0] + '</span>')
|
|
366
|
+
}
|
|
367
|
+
return res
|
|
368
|
+
},
|
|
369
|
+
re_func(res) {
|
|
370
|
+
//function like Date()
|
|
371
|
+
let regex = /([a-zA-Z_{1}][a-zA-Z0-9_]+)[ ]{0,1}(?=\()/g
|
|
372
|
+
let matched = res.matchAll(regex)
|
|
373
|
+
for (const match of matched) {
|
|
374
|
+
res = this.$helper.replacer(res, match[0], '<span class="color-func2 code-editor-span">' + match[0] + '</span>')
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
//function like $r $d()
|
|
378
|
+
regex = /(\$([a-zA-z0-9]*)[.|(])/g
|
|
379
|
+
matched = res.matchAll(regex)
|
|
380
|
+
for (const match of matched) {
|
|
381
|
+
res = this.$helper.replacer(res, match[0].substr(0, match[0].length - 1), '<span class="color-func code-editor-span">' + match[0].substr(0, match[0].length - 1) + '</span>')
|
|
382
|
+
}
|
|
383
|
+
res = this.$helper.replacer(res, '(', '<span class="color-func2 code-editor-span">(</span>')
|
|
384
|
+
res = this.$helper.replacer(res, ')', '<span class="color-func2 code-editor-span">)</span>')
|
|
385
|
+
return res
|
|
471
386
|
}
|
|
472
|
-
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
</script>
|
|
390
|
+
<style lang="scss">
|
|
391
|
+
@import "../../style/include";
|
|
392
|
+
|
|
393
|
+
.#{$prefix}code-editor {
|
|
394
|
+
direction: ltr;
|
|
395
|
+
text-align: left;
|
|
396
|
+
position: relative;
|
|
397
|
+
white-space: break-spaces;
|
|
398
|
+
caret-color: white;
|
|
399
|
+
background-color: #15212e;
|
|
400
|
+
color: #fff;
|
|
401
|
+
padding: 10px;
|
|
402
|
+
|
|
403
|
+
.code-script, .code-template {
|
|
404
|
+
padding: 0 20px;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.code-wrapper {
|
|
408
|
+
direction: ltr;
|
|
409
|
+
text-align: left;
|
|
410
|
+
padding: 10px;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.code-compile {
|
|
414
|
+
background-color: #fafafa;
|
|
415
|
+
min-height: 300px;
|
|
416
|
+
padding: 10px;
|
|
417
|
+
margin: 0 -10px -10px -10px;
|
|
418
|
+
color: black;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
.color-func {
|
|
422
|
+
color: #db92e3;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
.color-func2 {
|
|
426
|
+
color: #deca10;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
.color-orange {
|
|
430
|
+
color: orange;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
.color-green {
|
|
435
|
+
color: #0cde27;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
.color-blue {
|
|
440
|
+
color: #3bb7ee;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.color-number {
|
|
444
|
+
color: #7ad5ff;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.color-purple {
|
|
448
|
+
color: #d2a8ee;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.color-comment {
|
|
452
|
+
color: #898d8c;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
</style>
|