@kizmann/nano-ui 0.9.3 → 0.9.5

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