renusify 1.0.4 → 1.0.5

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.
Files changed (41) hide show
  1. package/components/app/index.vue +14 -14
  2. package/components/{notify → app/notify}/index.vue +1 -1
  3. package/components/{notify → app/notify}/notification.vue +0 -0
  4. package/components/{notify → app/notify}/notify.js +0 -0
  5. package/components/app/style.scss +0 -1
  6. package/components/{toast → app/toast}/index.vue +0 -0
  7. package/components/{toast → app/toast}/style.scss +1 -1
  8. package/components/{toast → app/toast}/toast.js +0 -0
  9. package/components/{toast → app/toast}/toast.vue +0 -0
  10. package/components/breadcrumb/bredcrumbItem.vue +11 -11
  11. package/components/breadcrumb/index.vue +6 -5
  12. package/components/chart/chart.vue +3 -0
  13. package/components/chat/chatInput.vue +139 -135
  14. package/components/codeEditor/index.vue +412 -443
  15. package/components/codeEditor/run.vue +76 -80
  16. package/components/content/style.scss +0 -1
  17. package/components/form/address.vue +109 -109
  18. package/components/form/address_ir.vue +106 -0
  19. package/components/form/colorPicker/Alpha.vue +3 -0
  20. package/components/form/colorPicker/Preview.vue +3 -0
  21. package/components/form/group-input.vue +2 -1
  22. package/components/form/number.vue +1 -1
  23. package/components/iframe/index.vue +1 -1
  24. package/components/index.js +178 -88
  25. package/components/infinite/index.vue +0 -2
  26. package/components/menu/index.vue +159 -127
  27. package/components/modal/index.vue +85 -90
  28. package/components/modal/style.scss +0 -1
  29. package/components/table/crud/index.vue +12 -13
  30. package/directive/clickOutSide/index.js +2 -3
  31. package/directive/drag/index.js +1 -2
  32. package/directive/intersect/index.js +3 -3
  33. package/directive/resize/index.js +3 -4
  34. package/directive/ripple/index.js +4 -6
  35. package/directive/scroll/index.js +3 -4
  36. package/directive/sortable/index.js +1 -2
  37. package/directive/title/index.js +2 -3
  38. package/directive/touch/index.js +1 -2
  39. package/index.js +3 -4
  40. package/package.json +1 -1
  41. package/plugins/trans/Translate.js +9 -14
@@ -1,472 +1,441 @@
1
1
  <template>
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" :script="script" :style="style"></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">&lt;template&gt;</span>
24
- <div ref="codeViewTemplate" :contenteditable="runnable" @input="rebuild" class="code-template"></div>
25
- <span class="color-green" v-if="runnable">&lt;/template&gt;</span>
26
- <br>
27
- </div>
28
- <div v-show="script">
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">&lt;template&gt;</span>
24
+ <div ref="codeViewTemplate" :contenteditable="runnable" @input="rebuildHtml" class="code-template"></div>
25
+ <span class="color-green" v-if="runnable">&lt;/template&gt;</span>
26
+ <br>
27
+ </div>
28
+ <div v-show="script">
29
29
  <span class="color-orange" v-if="runnable">&lt;script&gt;
30
30
  <br>
31
31
  export default {</span>
32
- <div ref="codeViewScript" :contenteditable="runnable" @input="rebuild" class="code-script"></div>
33
- <span class="color-orange" v-if="runnable">}<br>&lt;script&gt;</span>
34
- </div>
35
- <div v-show="style">
36
- <span class="color-orange" v-if="runnable">&lt;style&gt;</span>
37
- <div ref="codeViewStyle" :contenteditable="runnable" @input="rebuild" class="code-style"></div>
38
- <span class="color-orange" v-if="runnable">&lt;/style&gt;</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>&lt;script&gt;</span>
34
+ </div>
41
35
  </div>
36
+ </div>
42
37
  </template>
43
38
  <script>
44
- import RCodeEditorRun from "./run";
45
-
46
- export default {
47
- name: 'r-code-editor',
48
- components: {RCodeEditorRun},
49
- props: {
50
- runnable: Boolean
51
- },
52
- data() {
53
- return {
54
- show: 'code',
55
- code: '',
56
- edited: false,
57
- template: null,
58
- script: null,
59
- style: null,
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
54
+ }
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', this.runnable)
66
+ },
67
+ beforeUpdate() {
68
+ if (this.show === 'code' && !this.edited) {
69
+ this.get_code('codeSlot', this.runnable)
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
+ }
60
99
  }
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)
100
+
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
+ }
76
106
  }
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, '&lt;', '<')
162
- res = this.$helper.replacer(res, '&gt;', '>')
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">&lt;')
314
- res = this.$helper.replacer(res, '!)', '&gt;</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
107
+ });
108
+ cum_length[0] += sel.anchorOffset;
109
+ cum_length[1] += sel.extentOffset;
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);
137
+
138
+ if (chars.count === 0) {
139
+ break;
408
140
  }
141
+ }
142
+ }
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
+ this.template = this.toHTML(temp.childNodes[0].nodeValue).children[0]
194
+ }
195
+
196
+ let script = this.code.querySelector('.code-script')
197
+ if (script && script.childNodes.length > 0) {
198
+ this.script = script.childNodes[0].nodeValue
199
+ }
200
+
201
+ if (this.template || this.script) {
202
+ this.$refs.codeViewTemplate.innerHTML = this.buildHtml(this.template)
203
+ this.$refs.codeViewScript.innerHTML = this.buildScript(this.script)
204
+ } else {
205
+ this.$refs.codeView.innerHTML = this.$refs[slot].innerHTML
206
+ }
207
+ },
208
+ strToObj(str) {
209
+ str = this.$helper.replacer(str, ' ', '')
210
+ str = this.$helper.replacer(str, "\n", '')
211
+ str = this.$helper.replacer(str, "\r", '')
212
+ let open = 0
213
+ let pre = 0
214
+ let to = 0
215
+ let items = []
216
+ const s = str
217
+ s.split('').forEach((c, i) => {
218
+ to++
219
+ if (c === '{') {
220
+ open++
221
+ }
222
+ if (c === '}') {
223
+ open--
224
+ }
225
+ if (open === 0 && c === ',') {
226
+ let new_str = str.substr(pre, to - 1)
227
+ const o = new_str.indexOf(':')
228
+ const f = new_str.indexOf('(')
229
+ if ((f > 0 && f < o) || o < 0) {
230
+ new_str = new_str.substr(0, f)
231
+ } else {
232
+ new_str = new_str.substr(0, o)
233
+ }
234
+ items.push(new_str)
235
+ pre = i + 1
236
+ to = 0
409
237
  }
238
+ })
239
+ let new_str = str.substr(pre, str.length)
240
+ const o = new_str.indexOf(':')
241
+ const f = new_str.indexOf('(')
242
+ if ((f > 0 && f < o) || o < 0) {
243
+ new_str = new_str.substr(0, f)
244
+ } else {
245
+ new_str = new_str.substr(0, o)
246
+ }
247
+ items.push(new_str)
248
+ return items
249
+ },
250
+ buildHtml(template) {
251
+ if (!template) {
252
+ return ''
253
+ }
254
+ let data = template.outerHTML
255
+ data = this.$helper.replacer(data, '<', '&lt;')
256
+ data = this.$helper.replacer(data, '>', '&gt;')
257
+ data = data.split('')
258
+ let res = ''
259
+ let in_quta = false
260
+ data.forEach((c, i) => {
261
+ if (c === '=') {
262
+ res += '<span class="color-blue code-editor-span">=</span>'
263
+ } else if ((c === '"' || c === "'") && !in_quta) {
264
+ in_quta = c
265
+ res += '<span class="color-green code-editor-span">' + c
266
+ } else if (c === in_quta) {
267
+ in_quta = false
268
+ res += c + '</span>'
269
+ } else {
270
+ res += c
271
+ }
272
+ })
273
+
274
+ res = this.$helper.replacer(res, '&lt;', '<span class="color-orange code-editor-span">&lt;')
275
+ res = this.$helper.replacer(res, '&gt;', '&gt;</span>')
276
+ res = this.$helper.replacer(res, '{{', '<span class="color-blue code-editor-span">{{')
277
+ res = this.$helper.replacer(res, '}}', '}}</span>')
278
+
279
+ let regex = /\+(.*?)\+/g
280
+ let matched = res.matchAll(regex)
281
+ for (const match of matched) {
282
+ res = this.$helper.replacer(res, match[0], '<span class="color-blue code-editor-span">' + match[0] + '</span>')
283
+ }
284
+
285
+ res = this.re_words(res)
286
+ res = this.re_comment(res)
287
+ res = this.re_func(res)
288
+
289
+ return res
290
+ },
291
+ buildScript() {
292
+ if (!this.script) {
293
+ return ''
294
+ }
295
+ let data = this.script.split('')
296
+ let str = this.script.trim()
297
+
298
+ if (str.substr(0, 1) === '{') {
299
+ str = str.substr(1, str.length - 2)
300
+ }
301
+ let res = ''
302
+
303
+ let in_quta = false
304
+ data.forEach((c, i) => {
305
+ if (['=', '&', '{', '}', '<', '>'].includes(c)) {
306
+ res += '<span class="color-blue code-editor-span">' + c + '</span>'
307
+ } else if ([',', ';', ':'].includes(c)) {
308
+ res += '<span class="color-orange code-editor-span">' + c + '</span>'
309
+ } else if (parseInt(c) > -1) {
310
+ res += '<span class="color-number code-editor-span">' + c + '</span>'
311
+ } else if ((c === '"' || c === "'" || c === "`") && !in_quta) {
312
+ in_quta = c
313
+ res += '<span class="color-green code-editor-span">' + c
314
+ } else if (c === in_quta) {
315
+ in_quta = false
316
+ res += c + '</span>'
317
+ } else {
318
+ res += c
319
+ }
320
+ })
321
+
322
+ res = this.re_words(res)
323
+ res = this.re_comment(res)
324
+ res = this.re_func(res)
325
+
326
+ // main function vuejs methods created ,...
327
+ this.strToObj(str).forEach((item) => {
328
+ if (item) {
329
+ res = this.$helper.replacer(res, item, '<span class="color-func code-editor-span">' + item + '</span>')
330
+ }
331
+ })
332
+
333
+ return res
334
+ },
335
+ re_words(res) {
336
+ res = this.$helper.replacer(res, 'import ', '<span class="color-orange code-editor-span">import</span> ')
337
+ res = this.$helper.replacer(res, ' from ', ' <span class="color-orange code-editor-span">from</span> ')
338
+ res = this.$helper.replacer(res, ' window.', ' <span class="color-orange code-editor-span">window</span>.')
339
+ res = this.$helper.replacer(res, ' new ', ' <span class="color-orange code-editor-span">new</span> ')
340
+ res = this.$helper.replacer(res, ' var ', ' <span class="color-orange code-editor-span">var</span> ')
341
+ res = this.$helper.replacer(res, ' let ', ' <span class="color-orange code-editor-span">let</span> ')
342
+ res = this.$helper.replacer(res, ' const ', ' <span class="color-orange code-editor-span">const</span> ')
343
+ res = this.$helper.replacer(res, ' return ', ' <span class="color-orange code-editor-span">return</span> ')
344
+ res = this.$helper.replacer(res, ' this.', ' <span class="color-orange code-editor-span">this</span>.')
345
+
346
+ return res
347
+ },
348
+ re_comment(res) {
349
+ let regex = /(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/g
350
+ let matched = res.matchAll(regex)
351
+ for (const match of matched) {
352
+ res = this.$helper.replacer(res, match[0], '<span class="color-comment code-editor-span">' + match[0] + '</span>')
353
+ }
354
+ return res
355
+ },
356
+ re_func(res) {
357
+ //function like Date()
358
+ let regex = /([a-zA-Z_{1}][a-zA-Z0-9_]+)[ ]{0,1}(?=\()/g
359
+ let matched = res.matchAll(regex)
360
+ for (const match of matched) {
361
+ res = this.$helper.replacer(res, match[0], '<span class="color-func2 code-editor-span">' + match[0] + '</span>')
362
+ }
363
+
364
+ //function like $r $d()
365
+ regex = /(\$([a-zA-z0-9]*)[.|(])/g
366
+ matched = res.matchAll(regex)
367
+ for (const match of matched) {
368
+ 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>')
369
+ }
370
+ res = this.$helper.replacer(res, '(', '<span class="color-func2 code-editor-span">(</span>')
371
+ res = this.$helper.replacer(res, ')', '<span class="color-func2 code-editor-span">)</span>')
372
+ return res
410
373
  }
374
+ }
375
+ }
411
376
  </script>
412
377
  <style lang="scss">
413
- @import "../../style/include";
378
+ @import "../../style/include";
414
379
 
415
- .#{$prefix}code-editor {
416
- position: relative;
417
- white-space: break-spaces;
418
- caret-color: white !important;
380
+ .#{$prefix}code-editor {
381
+ position: relative;
382
+ white-space: break-spaces;
383
+ caret-color: white !important;
419
384
 
420
- .code-action {
421
- color: #ffffff;
422
- background: #283739;
423
- }
385
+ .code-script, .code-template {
386
+ padding: 10px;
387
+ }
424
388
 
425
- .code-wrapper {
426
- direction: ltr;
427
- text-align: left;
428
- background: #283739;
429
- color: #ffffff;
430
- padding: 10px;
431
- }
389
+ .code-action {
390
+ color: #ffffff;
391
+ background: #283739;
392
+ }
432
393
 
433
- .code-compile {
434
- border: 1px solid #444444;
435
- min-height: 300px;
436
- }
394
+ .code-wrapper {
395
+ direction: ltr;
396
+ text-align: left;
397
+ background: #283739;
398
+ color: #ffffff;
399
+ padding: 10px;
400
+ }
437
401
 
438
- .color-func {
439
- color: #db92e3;
440
- }
402
+ .code-compile {
403
+ border: 1px solid #444444;
404
+ min-height: 300px;
405
+ }
441
406
 
442
- .color-func2 {
443
- color: #deca10;
444
- }
407
+ .color-func {
408
+ color: #db92e3;
409
+ }
445
410
 
446
- .color-orange {
447
- color: orange;
448
- }
411
+ .color-func2 {
412
+ color: #deca10;
413
+ }
449
414
 
415
+ .color-orange {
416
+ color: orange;
417
+ }
450
418
 
451
- .color-green {
452
- color: #0cde27;
453
- }
454
419
 
420
+ .color-green {
421
+ color: #0cde27;
422
+ }
455
423
 
456
- .color-blue {
457
- color: #3bb7ee;
458
- }
459
424
 
460
- .color-number {
461
- color: #7ad5ff;
462
- }
425
+ .color-blue {
426
+ color: #3bb7ee;
427
+ }
463
428
 
464
- .color-purple {
465
- color: #d2a8ee;
466
- }
429
+ .color-number {
430
+ color: #7ad5ff;
431
+ }
467
432
 
468
- .color-comment {
469
- color: #898d8c;
470
- }
471
- }
433
+ .color-purple {
434
+ color: #d2a8ee;
435
+ }
436
+
437
+ .color-comment {
438
+ color: #898d8c;
439
+ }
440
+ }
472
441
  </style>