@kizmann/nano-ui 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/demos/builder.html +401 -0
  2. package/demos/overview.html +1 -1
  3. package/dist/nano-ui.css +1 -1
  4. package/dist/nano-ui.js +3 -3
  5. package/dist/nano-ui.js.map +1 -1
  6. package/dist/themes/light.css +1 -1
  7. package/package.json +2 -2
  8. package/src/config/index.js +6 -0
  9. package/src/config/index.scss +3 -0
  10. package/src/config/src/builder/builder.js +866 -0
  11. package/src/config/src/builder/builder.scss +272 -0
  12. package/src/config/src/builder/prototypes/button/n-button-group.js +11 -0
  13. package/src/config/src/builder/prototypes/button/n-button.js +37 -0
  14. package/src/config/src/builder/prototypes/cascader/n-cascader.js +11 -0
  15. package/src/config/src/builder/prototypes/checkbox/n-checkbox-group.js +11 -0
  16. package/src/config/src/builder/prototypes/checkbox/n-checkbox.js +11 -0
  17. package/src/config/src/builder/prototypes/confirm/n-confirm.js +11 -0
  18. package/src/config/src/builder/prototypes/datepicker/n-datepicker.js +11 -0
  19. package/src/config/src/builder/prototypes/datetimepicker/n-datetimepicker.js +11 -0
  20. package/src/config/src/builder/prototypes/durationpicker/n-durationpicker.js +11 -0
  21. package/src/config/src/builder/prototypes/empty/n-empty.js +11 -0
  22. package/src/config/src/builder/prototypes/form/n-form-group.js +13 -0
  23. package/src/config/src/builder/prototypes/form/n-form-item.js +13 -0
  24. package/src/config/src/builder/prototypes/form/n-form.js +11 -0
  25. package/src/config/src/builder/prototypes/html/div.js +13 -0
  26. package/src/config/src/builder/prototypes/html/nano.js +11 -0
  27. package/src/config/src/builder/prototypes/html/span.js +11 -0
  28. package/src/config/src/builder/prototypes/info/n-info-column.js +11 -0
  29. package/src/config/src/builder/prototypes/info/n-info.js +11 -0
  30. package/src/config/src/builder/prototypes/input/n-input.js +40 -0
  31. package/src/config/src/builder/prototypes/input-number/n-input-number.js +49 -0
  32. package/src/config/src/builder/prototypes/loader/n-loader.js +11 -0
  33. package/src/config/src/builder/prototypes/modal/n-modal.js +11 -0
  34. package/src/config/src/builder/prototypes/popover/n-popover-group.js +11 -0
  35. package/src/config/src/builder/prototypes/popover/n-popover-item.js +11 -0
  36. package/src/config/src/builder/prototypes/popover/n-popover.js +11 -0
  37. package/src/config/src/builder/prototypes/radio/n-radio-group.js +11 -0
  38. package/src/config/src/builder/prototypes/radio/n-radio.js +11 -0
  39. package/src/config/src/builder/prototypes/rating/n-rating.js +11 -0
  40. package/src/config/src/builder/prototypes/select/n-select.js +11 -0
  41. package/src/config/src/builder/prototypes/slider/n-slider.js +11 -0
  42. package/src/config/src/builder/prototypes/switch/n-switch.js +31 -0
  43. package/src/config/src/builder/prototypes/table/n-table-column.js +11 -0
  44. package/src/config/src/builder/prototypes/table/n-table.js +11 -0
  45. package/src/config/src/builder/prototypes/tabs/n-tabs-item.js +11 -0
  46. package/src/config/src/builder/prototypes/tabs/n-tabs.js +11 -0
  47. package/src/config/src/builder/prototypes/tags/n-tags-item.js +11 -0
  48. package/src/config/src/builder/prototypes/tags/n-tags.js +11 -0
  49. package/src/config/src/builder/prototypes/textarea/n-textarea.js +11 -0
  50. package/src/config/src/builder/prototypes/timepicker/n-timepicker.js +11 -0
  51. package/src/config/src/builder/prototypes/transfer/n-transfer.js +11 -0
  52. package/src/config/src/reference-panel/reference-panel.js +196 -0
  53. package/src/config/src/reference-panel/reference-panel.scss +194 -0
  54. package/src/config/src/reference-picker/reference-picker.js +146 -0
  55. package/src/config/src/reference-picker/reference-picker.scss +3 -0
  56. package/src/form/src/form-group/form-group.js +5 -1
  57. package/src/index.scss +1 -0
  58. package/src/input/src/input/input.js +2 -0
  59. package/src/popover/src/popover/popover.scss +3 -3
  60. package/src/root/vars.scss +23 -0
  61. package/webservy.json +3 -1
  62. package/servy.json +0 -6
@@ -0,0 +1,866 @@
1
+ import { Arr, Dom, Any, Locale, Obj, UUID, Num } from "@kizmann/pico-js";
2
+
3
+ global.NanoBuilderPropType = {
4
+ 'root': Locale.trans('Root'),
5
+ 'binds': Locale.trans('Bind'),
6
+ 'props': Locale.trans('Property'),
7
+ 'attrs': Locale.trans('Attribute'),
8
+ 'on': Locale.trans('Event'),
9
+ };
10
+
11
+ global.NanoBuilderPropCode = {
12
+ 'string': Locale.trans('String'),
13
+ 'number': Locale.trans('Number'),
14
+ 'boolean': Locale.trans('Boolean'),
15
+ 'object': Locale.trans('Object'),
16
+ 'function': Locale.trans('Function'),
17
+ };
18
+
19
+ global.NanoBuilderProps = {
20
+ classList: {
21
+ for: ['root', 'attrs', 'props'], type: 'String'
22
+ },
23
+ vIf: {
24
+ for: ['root'], type: 'String'
25
+ },
26
+ vShow: {
27
+ for: ['root'], type: 'String'
28
+ },
29
+ };
30
+
31
+ global.NanoBuilderTypes = {
32
+ //
33
+ };
34
+
35
+ global.NanoBuilderIndexies = {
36
+ //
37
+ };
38
+
39
+ // DOM elements
40
+ require('./prototypes/html/nano');
41
+ require('./prototypes/html/div');
42
+ require('./prototypes/html/span');
43
+
44
+ // Nano elements
45
+ require('./prototypes/button/n-button');
46
+ require('./prototypes/button/n-button-group');
47
+ require('./prototypes/cascader/n-cascader');
48
+ require('./prototypes/checkbox/n-checkbox');
49
+ require('./prototypes/checkbox/n-checkbox-group');
50
+ require('./prototypes/confirm/n-confirm');
51
+ require('./prototypes/datepicker/n-datepicker');
52
+ require('./prototypes/datetimepicker/n-datetimepicker');
53
+ require('./prototypes/durationpicker/n-durationpicker');
54
+ require('./prototypes/empty/n-empty');
55
+ require('./prototypes/form/n-form');
56
+ require('./prototypes/form/n-form-group');
57
+ require('./prototypes/form/n-form-item');
58
+ require('./prototypes/input/n-input');
59
+ require('./prototypes/input-number/n-input-number');
60
+ require('./prototypes/loader/n-loader');
61
+ require('./prototypes/modal/n-modal');
62
+ require('./prototypes/radio/n-radio');
63
+ require('./prototypes/radio/n-radio-group');
64
+ require('./prototypes/rating/n-rating');
65
+ require('./prototypes/select/n-select');
66
+ require('./prototypes/slider/n-slider');
67
+ require('./prototypes/switch/n-switch');
68
+ require('./prototypes/table/n-table');
69
+ require('./prototypes/table/n-table-column');
70
+ require('./prototypes/tabs/n-tabs');
71
+ require('./prototypes/tabs/n-tabs-item');
72
+ require('./prototypes/tags/n-tags');
73
+ require('./prototypes/tags/n-tags-item');
74
+ require('./prototypes/timepicker/n-timepicker');
75
+ require('./prototypes/transfer/n-transfer');
76
+
77
+ export default {
78
+
79
+ name: 'NBuilder',
80
+
81
+ props: {
82
+
83
+ modelValue: {
84
+ default()
85
+ {
86
+ return {};
87
+ },
88
+ type: [Object]
89
+ },
90
+
91
+ scope: {
92
+ default()
93
+ {
94
+ return {};
95
+ },
96
+ type: [Object]
97
+ },
98
+
99
+ model: {
100
+ default()
101
+ {
102
+ return {};
103
+ },
104
+ type: [Object]
105
+ },
106
+
107
+ renderDemo: {
108
+ default()
109
+ {
110
+ return true;
111
+ },
112
+ type: [Boolean]
113
+ },
114
+
115
+ renderExport: {
116
+ default()
117
+ {
118
+ return true;
119
+ },
120
+ type: [Boolean]
121
+ },
122
+
123
+ },
124
+
125
+ data()
126
+ {
127
+ return {
128
+ init: false, demo: false, collapse: [], safevar: this.normalizeModel(this.modelValue)
129
+ };
130
+ },
131
+
132
+ watch: {
133
+ modelValue: function () {
134
+ this.safevar = this.normalizeModel(this.modelValue)
135
+ }
136
+ },
137
+
138
+ mounted()
139
+ {
140
+ this.init = true;
141
+ },
142
+
143
+ methods: {
144
+
145
+ exportJson(value)
146
+ {
147
+ return JSON.stringify(Obj.clone(value), null, 4).replace(/"!FUNC:(.*?):FUNC!"/g, (matches) => {
148
+ return matches.replace(/^"!FUNC:/, '').replace(/:FUNC!"$/, '').replace(/\\"/, '"').replace(/\\n/g, "\n");
149
+ });
150
+ },
151
+
152
+ exportExecutable(value)
153
+ {
154
+ return new Function(`return ${this.exportJson(value)};`)();
155
+ },
156
+
157
+ normalizeModel(model)
158
+ {
159
+ let result = {};
160
+
161
+ Obj.each(model, (value, key) => {
162
+ result[key] = Obj.assign(this.normalizeChild(value), {
163
+ order: (Any.vals(result).length + 1) * 100
164
+ });
165
+ });
166
+
167
+ return result;
168
+ },
169
+
170
+ normalizeChild(child)
171
+ {
172
+ let result = this.applyProps(null, {
173
+ ...Obj.except(child, ['content']), content: {}, builder: this.buildProps(child),
174
+ });
175
+
176
+ Obj.each(child.content || {}, (value, key) => {
177
+
178
+ if ( ! key.match(':') ) {
179
+ key += ':' + UUID();
180
+ }
181
+
182
+ result['content'][key] = Obj.assign(this.normalizeChild(value), {
183
+ order: (Any.vals(result['content']).length + 1) * 100
184
+ });
185
+ });
186
+
187
+ return result;
188
+ },
189
+
190
+ getOriginalValue(prop)
191
+ {
192
+ let safevalue = prop.value;
193
+
194
+ if ( typeof prop.value === 'function' ) {
195
+ safevalue = btoa("!FUNC:" + prop.value.toString() + ":FUNC!");
196
+ }
197
+
198
+ return safevalue;
199
+ },
200
+
201
+ getSafeValue(prop)
202
+ {
203
+ let safevalue = '';
204
+
205
+ if ( typeof prop.value === 'string' ) {
206
+ safevalue = Any.string(prop.value);
207
+ }
208
+
209
+ if ( typeof prop.value === 'boolean' ) {
210
+ safevalue = Any.string(prop.value);
211
+ }
212
+
213
+ if ( typeof prop.value === 'number' ) {
214
+ safevalue = Any.string(prop.value);
215
+ }
216
+
217
+ if ( typeof prop.value === 'object' ) {
218
+ safevalue = JSON.stringify(prop.value);
219
+ }
220
+
221
+ if ( typeof prop.value === 'function' ) {
222
+ safevalue = btoa("!FUNC:" + prop.value.toString() + ":FUNC!");
223
+ }
224
+
225
+ return safevalue;
226
+ },
227
+
228
+ getRealValue(prop)
229
+ {
230
+ let realvalue = '';
231
+
232
+ if ( prop.code === 'string' ) {
233
+ realvalue = Any.string(prop.value);
234
+ }
235
+
236
+ if ( prop.code === 'boolean' ) {
237
+ realvalue = Any.boolean(prop.value);
238
+ }
239
+
240
+ if ( prop.code === 'number' ) {
241
+ realvalue = Any.number(prop.value, 0);
242
+ console.log('num', prop.value, realvalue)
243
+ }
244
+
245
+ if ( prop.code === 'object' ) {
246
+ realvalue = JSON.parse(prop.value);
247
+ }
248
+
249
+ if ( prop.code === 'function' ) {
250
+ realvalue = atob(prop.original);
251
+ }
252
+
253
+ return realvalue;
254
+ },
255
+
256
+ changeElement(key, update)
257
+ {
258
+ if ( Any.isEmpty(update) ) {
259
+ return;
260
+ }
261
+
262
+ let newKey = key.replace(/^(.*?)([^\.]+):([^\.]+)$/, `$1${update}:$3`);
263
+
264
+ let value = Obj.get(this, key, {});
265
+
266
+ Obj.unset(this, key);
267
+ Obj.set(this, newKey, value);
268
+
269
+ this.collapse = Arr.each(this.collapse, (k) => {
270
+ return k.replace(key, newKey);
271
+ });
272
+ },
273
+
274
+ changeAlias(key, update)
275
+ {
276
+ if ( Any.isEmpty(update) ) {
277
+ return;
278
+ }
279
+
280
+ let newKey = key.replace(/^(.*?)([^\.]+):([^\.]+)$/, `$1$2:${update}`);
281
+
282
+ let value = Obj.get(this, key, {});
283
+
284
+ Obj.unset(this, key);
285
+ Obj.set(this, newKey, value);
286
+
287
+ this.collapse = Arr.each(this.collapse, (k) => {
288
+ return k.replace(key, newKey);
289
+ });
290
+ },
291
+
292
+ applyProps(key = null, value = {})
293
+ {
294
+ if ( ! Any.isEmpty(key) ) {
295
+ value = Obj.get(this, key, {});
296
+ }
297
+
298
+ let reset = [
299
+ 'vIf', 'vShow', 'classList', 'vLocale', 'binds', 'attrs', 'props', 'on',
300
+ ];
301
+
302
+ Obj.each(reset, (prop) => {
303
+ Obj.unset(value, prop);
304
+ });
305
+
306
+ Obj.each(value.builder || {}, (val) => {
307
+
308
+ if ( Any.isEmpty(val.key) ) {
309
+ return;
310
+ }
311
+
312
+ let bindValue = {
313
+ value: val.value, fallback: null
314
+ };
315
+
316
+ if ( val.code === 'string' ) {
317
+ bindValue.fallback = Any.string(val.fallback || '');
318
+ }
319
+
320
+ if ( val.code === 'boolean' ) {
321
+ bindValue.fallback = Any.boolean(val.fallback || 'false');
322
+ }
323
+
324
+ if ( val.code === 'object' ) {
325
+ bindValue.fallback = JSON.parse(val.fallback || '{}');
326
+ }
327
+
328
+ if ( val.type === 'binds' ) {
329
+ return Obj.set(value, [val.type, val.key], bindValue);
330
+ }
331
+
332
+ let realvalue = '';
333
+
334
+ try {
335
+ realvalue = this.getRealValue(val);
336
+ } catch (e) {
337
+ if ( ! Any.isEmpty(val.value) ) {
338
+ console.error('Invalid JSON: ' + val.value);
339
+ }
340
+ }
341
+
342
+ if ( val.type === 'root' ) {
343
+ return Obj.set(value, val.key, realvalue);
344
+ }
345
+
346
+ if ( val.type === 'attrs' ) {
347
+ return Obj.set(value, [val.type, val.key], realvalue);
348
+ }
349
+
350
+ if ( val.type === 'props' ) {
351
+ return Obj.set(value, [val.type, val.key], realvalue);
352
+ }
353
+
354
+ if ( val.type === 'on' ) {
355
+ return Obj.set(value, [val.type, val.key], realvalue);
356
+ }
357
+
358
+ });
359
+
360
+ if ( Any.isEmpty(key) ) {
361
+ return value;
362
+ }
363
+
364
+ return Obj.set(this, key, value);
365
+ },
366
+
367
+ buildProps(el, key = null)
368
+ {
369
+ let builder = {};
370
+
371
+ Obj.each(Obj.only(el, ['vIf', 'vShow', 'classList']), (value, sey) => {
372
+ builder[UUID()] = {
373
+ type: 'root', code: typeof value, key: sey, value: this.getSafeValue({ value }), fallback: null, original: this.getOriginalValue({ value })
374
+ };
375
+ });
376
+
377
+ Obj.each(Obj.get(el, `binds`, {}), (value, sey) => {
378
+
379
+ let result = {
380
+ type: 'binds', code: typeof value, key: sey, fallback: null, original: this.getOriginalValue({ value })
381
+ }
382
+
383
+ if ( Any.isString(value) ) {
384
+ result.value = this.getSafeValue({ value });
385
+ }
386
+
387
+ if ( Any.isObject(value) ) {
388
+ Obj.assign(result, { value: this.getSafeValue(value), fallback: Obj.get(value, 'fallback', null) })
389
+ }
390
+
391
+ builder[UUID()] = result;
392
+ });
393
+
394
+ Obj.each(Obj.get(el, `props`, {}), (value, sey) => {
395
+ builder[UUID()] = { type: 'props', code: typeof value, key: sey, value: this.getSafeValue({ value }), fallback: null, original: this.getOriginalValue({ value }) };
396
+ });
397
+
398
+ Obj.each(Obj.get(el, `attrs`, {}), (value, sey) => {
399
+ builder[UUID()] = { type: 'attrs', code: typeof value, key: sey, value: this.getSafeValue({ value }), fallback: null, original: this.getOriginalValue({ value }) };
400
+ });
401
+
402
+ Obj.each(Obj.get(el, `on`, {}), (value, sey) => {
403
+ builder[UUID()] = { type: 'on', code: typeof value, key: sey, value: this.getSafeValue({ value }), fallback: null, original: this.getOriginalValue({ value }) };
404
+ });
405
+
406
+ if ( Any.isEmpty(key) ) {
407
+ return builder;
408
+ }
409
+
410
+ this.$nextTick(() => {
411
+ Obj.set(this, `${key}.builder`, builder);
412
+ });
413
+
414
+ return builder;
415
+ },
416
+
417
+ addProp(key)
418
+ {
419
+ let value = Obj.get(this, `${key}.builder`, {});
420
+
421
+ Obj.set(value, UUID(), {
422
+ type: 'props', code: 'string', key: '', value: '', fallback: null
423
+ });
424
+
425
+ Obj.set(this, `${key}.builder`, value);
426
+ },
427
+
428
+ removeProp(key, prop)
429
+ {
430
+ Obj.unset(this, `${key}.builder.${prop}`);
431
+
432
+ this.applyProps(key);
433
+ },
434
+
435
+ collapseElement(key)
436
+ {
437
+ Arr.toggle(this.collapse, key);
438
+ },
439
+
440
+ addElement(key)
441
+ {
442
+ let value = Obj.get(this, key, {});
443
+
444
+ Obj.set(value, 'div:' + UUID(), {
445
+ order: (Any.vals(value).length + 1) * 100, props: { modelValue: '$scope.list' }, content: {}
446
+ });
447
+
448
+ Obj.assign(this, key, value);
449
+ },
450
+
451
+ removeElement(key)
452
+ {
453
+ Obj.unset(this, key);
454
+ },
455
+
456
+ moveupElement(key)
457
+ {
458
+ let [el, childs] = [
459
+ Obj.get(this, key), Obj.get(this, key.replace(/\.[^.]+$/, ''))
460
+ ];
461
+
462
+ let close = Number.MIN_VALUE;
463
+
464
+ Arr.each(childs, (sub) => {
465
+ if ( sub.order < el.order ) close = Math.max(close, sub.order);
466
+ });
467
+
468
+ if ( close === Number.MIN_VALUE ) {
469
+ return;
470
+ }
471
+
472
+ let replacement = Arr.find(childs, {
473
+ order: close
474
+ });
475
+
476
+ Obj.assign(replacement, {
477
+ order: el.order
478
+ });
479
+
480
+ Obj.assign(el, { order: close });
481
+ },
482
+
483
+ movedownElement(key)
484
+ {
485
+ let [el, childs] = [
486
+ Obj.get(this, key), Obj.get(this, key.replace(/\.[^.]+$/, ''))
487
+ ];
488
+
489
+ let close = Number.MAX_VALUE;
490
+
491
+ Arr.each(childs, (sub) => {
492
+ if ( sub.order > el.order ) close = Math.min(close, sub.order);
493
+ });
494
+
495
+ if ( close === Number.MAX_VALUE ) {
496
+ return;
497
+ }
498
+
499
+ let replacement = Arr.find(childs, {
500
+ order: close
501
+ });
502
+
503
+ Obj.assign(replacement, {
504
+ order: el.order
505
+ });
506
+
507
+ Obj.assign(el, { order: close });
508
+ },
509
+
510
+ },
511
+
512
+ renderTools(el, value, key)
513
+ {
514
+ let rootProps = {
515
+ //
516
+ };
517
+
518
+ rootProps['onDblclick'] = () => {
519
+ this.collapseElement(key);
520
+ };
521
+
522
+ let collapseProps = {
523
+ href: 'javascript:void(0)',
524
+ };
525
+
526
+ collapseProps['onClick'] = () => {
527
+ this.collapseElement(key);
528
+ };
529
+
530
+ let addProps = {
531
+ href: 'javascript:void(0)',
532
+ };
533
+
534
+ addProps['onClick'] = () => {
535
+ this.addElement(`${key}.content`);
536
+ };
537
+
538
+ let removeProps = {
539
+ href: 'javascript:void(0)',
540
+ };
541
+
542
+ removeProps['onClick'] = () => {
543
+ this.removeElement(key);
544
+ };
545
+
546
+ let moveupProps = {
547
+ href: 'javascript:void(0)',
548
+ };
549
+
550
+ moveupProps['onClick'] = () => {
551
+ this.moveupElement(key);
552
+ };
553
+
554
+ let movedownProps = {
555
+ href: 'javascript:void(0)',
556
+ };
557
+
558
+ movedownProps['onClick'] = () => {
559
+ this.movedownElement(key);
560
+ };
561
+
562
+
563
+ return (
564
+ <div class="n-builder__tools" {...rootProps}>
565
+ <div class="n-builder__collapse">
566
+ <a {...collapseProps}><i class="fa fa-bars"></i></a>
567
+ </div>
568
+ <div class="n-builder__name">
569
+ {key.replace(/^.*?([^\.:]+):([^\.:]+)$/, '$1')}<span>{key.replace(/^.*?([^\.:]+):([^\.:]+)$/, '$2')}</span>
570
+ </div>
571
+ <div class="n-builder__move">
572
+ <a {...moveupProps}><i class="fa fa-angle-up"></i></a>
573
+ <a {...movedownProps}><i class="fa fa-angle-down"></i></a>
574
+ </div>
575
+ <div class="n-builder__add">
576
+ <a {...addProps}><i class="fa fa-plus"></i></a>
577
+ </div>
578
+ <div class="n-builder__remove">
579
+ <a {...removeProps}><i class="fa fa-trash"></i></a>
580
+ </div>
581
+ </div>
582
+ );
583
+ },
584
+
585
+ renderProp(el, sub, key)
586
+ {
587
+ let group = key.replace(/^.*?([^\.]+):([^\.]+)$/, '$1')
588
+ let value = Obj.get(this.$data, `${key}.builder.${sub}`, {});
589
+
590
+ let props = Obj.clone(Obj.get(global.NanoBuilderIndexies, `${group}.props`, {}));
591
+
592
+ props = Obj.assign({}, global.NanoBuilderProps, props);
593
+
594
+ Obj.each(props, (prop, index) => {
595
+ console.log(prop.for, index, value.type)
596
+ if ( ! Any.isEmpty(prop.for) && ! Arr.has(prop.for, value.type) ) {
597
+ props = Obj.unset(props, index);
598
+ }
599
+ });
600
+
601
+ console.log(props);
602
+
603
+ let typeProps = {
604
+ size: 'sm', options: global.NanoBuilderPropType
605
+ };
606
+
607
+ typeProps['onUpdate:modelValue'] = () => {
608
+ this.applyProps(key);
609
+ };
610
+
611
+ let keyProps = {
612
+ size: 'sm', allowCreate: true, options: props, optionsLabel: '$index'
613
+ };
614
+
615
+ keyProps['onUpdate:modelValue'] = () => {
616
+ this.$nextTick(() => this.applyProps(key));
617
+ };
618
+
619
+ let codeProps = {
620
+ size: 'sm', options: global.NanoBuilderPropCode
621
+ };
622
+
623
+ codeProps['onUpdate:modelValue'] = () => {
624
+ this.$nextTick(() => this.applyProps(key));
625
+ };
626
+
627
+ let values = Obj.get(props, `${value.key}.options`, []);
628
+
629
+ let valueInputProps = {
630
+ size: 'sm', model: this.model, scope: this.scope
631
+ };
632
+
633
+ valueInputProps['onUpdate:modelValue'] = () => {
634
+ this.$nextTick(() => this.applyProps(key));
635
+ };
636
+
637
+ let valueHtml = (
638
+ <NReferencePicker vModel={value.value} {...valueInputProps} />
639
+ );
640
+
641
+ let fallbackProps = {
642
+ size: 'sm', minRows: 1, autoRows: true
643
+ };
644
+
645
+ fallbackProps['onUpdate:modelValue'] = () => {
646
+ this.$nextTick(() => this.applyProps(key));
647
+ };
648
+
649
+ let tooltipHtml = (
650
+ <div class="n-builder_prop-text">
651
+ <p>{Obj.get(props, `${value.key}.desc`, '')}</p>
652
+ </div>
653
+ );
654
+
655
+ return (
656
+ <div class="n-builder_prop">
657
+ <div class="n-builder_prop-type">
658
+ <NSelect vModel={value.type} {...typeProps} />
659
+ </div>
660
+ <div class="n-builder_prop-key">
661
+ <NSelect vModel={value.key} {...keyProps} />
662
+ </div>
663
+ <div class="n-builder_prop-func">
664
+ <NSelect vModel={value.code} {...codeProps} />
665
+ </div>
666
+ <div class="n-builder_prop-value">
667
+ {valueHtml}
668
+ </div>
669
+ <div class="n-builder_prop-fallback">
670
+ <NInput vModel={value.fallback} {...fallbackProps} />
671
+ </div>
672
+ <div class="n-builder_prop-button">
673
+ <NButton size="sm" type="danger" onClick={() => this.removeProp(key, sub)}>Remove</NButton>
674
+ </div>
675
+ </div>
676
+ );
677
+ },
678
+
679
+ renderProps(el, value, key)
680
+ {
681
+ if ( !Arr.has(this.collapse, key) ) {
682
+ return null;
683
+ }
684
+
685
+ let elementProps = {
686
+ options: global.NanoBuilderTypes, allowCreate: true, modelValue: key.replace(/^.*?([^\.]+):([^\.]+)$/, '$1'),
687
+ };
688
+
689
+ elementProps['onUpdate:modelValue'] = (value) => {
690
+ this.changeElement(key, value);
691
+ };
692
+
693
+ let aliasProps = {
694
+ modelValue: key.replace(/^.*?([^\.]+):([^\.]+)$/, '$2'),
695
+ };
696
+
697
+ aliasProps['onBlur'] = (e) => {
698
+ this.changeAlias(key, e.target.value);
699
+ };
700
+
701
+ let addProps = {
702
+ type: 'primary', size: 'sm', link: true
703
+ };
704
+
705
+ addProps['onClick'] = () => {
706
+ this.addProp(key, value);
707
+ };
708
+
709
+ let props = Obj.get(value, `builder`);
710
+
711
+ if ( ! Obj.has(value, 'builder') ) {
712
+ props = this.buildProps(el, key, value);
713
+ }
714
+
715
+ return (
716
+ <NForm class="n-builder__props">
717
+ <NFormItem class="n-builder__element-type" label={this.trans('Type')}>
718
+ <NSelect {...elementProps} />
719
+ </NFormItem>
720
+ <NFormItem class="n-builder__element-alias" label={this.trans('Alias')}>
721
+ <NInput {...aliasProps} />
722
+ </NFormItem>
723
+ <div class="n-builder__element-prop">
724
+ <NButton {...addProps}>Add property</NButton>
725
+ </div>
726
+ <div class="n-builder__element-list">
727
+ {Arr.each(props, (prop, sub) => this.ctor('renderProp')(el, sub, key))}
728
+ </div>
729
+ </NForm>
730
+ );
731
+ },
732
+
733
+ renderElement(el, value, key)
734
+ {
735
+ let classList = [
736
+ 'n-builder__element'
737
+ ];
738
+
739
+ if ( Arr.has(this.collapse, key) ) {
740
+ classList.push('is-open');
741
+ }
742
+
743
+ return (
744
+ <div class={classList}>
745
+ {this.ctor('renderTools')(el, value, key)}
746
+ {this.ctor('renderProps')(el, value, key)}
747
+ {this.ctor('renderBuilder')(value.content || {}, `${key}.content`)}
748
+ </div>
749
+ );
750
+ },
751
+
752
+ renderBuilder(el, key)
753
+ {
754
+ if ( Any.isEmpty(el) ) {
755
+ return null;
756
+ }
757
+
758
+ return (
759
+ <div class="n-builder__frame">
760
+ {Arr.each(Obj.sort(Obj.clone(el), 'order'), (v) => this.ctor('renderElement')(Obj.get(this.$data, key, {}), Obj.get(this.$data, [key, v._key], {}), `${key}.${v._key}`))}
761
+ </div>
762
+ );
763
+ },
764
+
765
+ renderBody()
766
+ {
767
+ return (
768
+ <div class="n-builder__body">
769
+ {this.ctor('renderBuilder')(this.safevar, 'safevar')}
770
+ </div>
771
+ );
772
+ },
773
+
774
+ renderHead()
775
+ {
776
+ let addProps = {
777
+ type: 'primary'
778
+ };
779
+
780
+ addProps['onClick'] = () => {
781
+ this.addElement('safevar');
782
+ };
783
+
784
+ let addHtml = (
785
+ <div class="n-builder__head-add">
786
+ <NButton {...addProps}>{this.trans('Add root element')}</NButton>
787
+ </div>
788
+ );
789
+
790
+ let demoProps = {
791
+ type: 'primary'
792
+ };
793
+
794
+ demoProps['onClick'] = () => {
795
+ this.demo = true;
796
+ };
797
+
798
+ let demoHtml = (
799
+ <div class="n-builder__head-demo">
800
+ <NButton {...demoProps}>{this.trans('Render demo')}</NButton>
801
+ </div>
802
+ );
803
+
804
+ return (
805
+ <div class="n-builder__head">
806
+ {[addHtml, demoHtml]}
807
+ </div>
808
+ );
809
+ },
810
+
811
+ renderOutput()
812
+ {
813
+ return (
814
+ <div class="n-builder__output">
815
+ <pre>{this.exportJson(this.safevar)}</pre>
816
+ </div>
817
+ );
818
+ },
819
+
820
+ renderDemo()
821
+ {
822
+ if ( ! this.renderDemo || ! this.demo ) {
823
+ return null;
824
+ }
825
+
826
+ let renderFunction = this.$slots.default;
827
+
828
+ if ( Any.isEmpty(renderFunction) ) {
829
+ renderFunction = ({ render }) => render();
830
+ }
831
+
832
+ let modalProps = {
833
+ width: '100%',
834
+ height: '100%'
835
+ };
836
+
837
+ let configProps = {
838
+ modelValue: this.model, scope: this.scope, config: this.exportExecutable(this.safevar)
839
+ };
840
+
841
+ let renderContent = () => {
842
+ return ( <NConfigNext {...configProps} />);
843
+ };
844
+
845
+ return (
846
+ <NModal vModel={this.demo} {...modalProps}>
847
+ {renderFunction({ render: renderContent })}
848
+ </NModal>
849
+ );
850
+ },
851
+
852
+ render()
853
+ {
854
+ let classList = [
855
+ 'n-builder',
856
+ ];
857
+
858
+ return (
859
+ <div class={classList}>
860
+ {[
861
+ this.ctor('renderBody')(), this.ctor('renderHead')(), this.ctor('renderOutput')(), this.ctor('renderDemo')(),
862
+ ]}
863
+ </div>
864
+ );
865
+ }
866
+ }