eoss 0.1.0-alpha.40 → 0.1.0-alpha.41

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 (250) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +59 -59
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +2 -2
  86. package/lib/autocomplete.js +56 -56
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +6 -6
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +37 -37
  95. package/lib/calendar.js +4 -4
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +36 -36
  98. package/lib/carousel.js +38 -38
  99. package/lib/cascader-panel.js +71 -71
  100. package/lib/cascader.js +220 -220
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +65 -65
  103. package/lib/checkbox.js +6 -6
  104. package/lib/code-editor.js +1134 -0
  105. package/lib/col.js +2 -2
  106. package/lib/collapse-item.js +76 -76
  107. package/lib/collapse.js +76 -76
  108. package/lib/color-picker.js +10 -10
  109. package/lib/container.js +2 -2
  110. package/lib/cron.js +20 -20
  111. package/lib/data-table.js +66 -66
  112. package/lib/date-picker.js +2419 -2419
  113. package/lib/descriptions-item.js +4 -4
  114. package/lib/descriptions.js +4 -4
  115. package/lib/dialog.js +42 -42
  116. package/lib/divider.js +2 -2
  117. package/lib/drawer.js +6 -6
  118. package/lib/dropdown-item.js +8 -8
  119. package/lib/dropdown-menu.js +20 -20
  120. package/lib/dropdown.js +40 -40
  121. package/lib/email-login.js +64 -64
  122. package/lib/empty.js +2 -2
  123. package/lib/eoss.common.js +23730 -5967
  124. package/lib/flip.js +2 -2
  125. package/lib/flow-group.js +55 -55
  126. package/lib/flow.js +171 -171
  127. package/lib/flows.js +77 -77
  128. package/lib/footer.js +2 -2
  129. package/lib/form-editor.js +12534 -0
  130. package/lib/form-item.js +57 -49
  131. package/lib/form.js +233 -174
  132. package/lib/guide.js +2 -2
  133. package/lib/header.js +2 -2
  134. package/lib/icon.js +38 -38
  135. package/lib/icons.js +11 -11
  136. package/lib/image-viewer.js +38 -38
  137. package/lib/image.js +6 -6
  138. package/lib/index.js +1 -1
  139. package/lib/infinite-scroll.js +4 -4
  140. package/lib/input-number.js +39 -39
  141. package/lib/input.js +60 -60
  142. package/lib/link.js +2 -2
  143. package/lib/loading.js +6 -6
  144. package/lib/login.js +193 -193
  145. package/lib/lowcode-view.js +824 -132
  146. package/lib/lowcode.js +27278 -16925
  147. package/lib/main.js +270 -257
  148. package/lib/marquee.js +38 -38
  149. package/lib/menu-item-group.js +14 -14
  150. package/lib/menu-item.js +10 -10
  151. package/lib/menu.js +129 -129
  152. package/lib/message-box.js +52 -52
  153. package/lib/message.js +62 -62
  154. package/lib/notification.js +40 -40
  155. package/lib/option-group.js +4 -4
  156. package/lib/option.js +36 -36
  157. package/lib/page-header.js +2 -2
  158. package/lib/pagination.js +37 -37
  159. package/lib/phone-login.js +58 -58
  160. package/lib/popconfirm.js +4 -4
  161. package/lib/popover.js +42 -42
  162. package/lib/process-config.js +65 -65
  163. package/lib/process-module.js +62 -62
  164. package/lib/process-rule.js +66 -66
  165. package/lib/progress.js +2 -2
  166. package/lib/qr-code.js +6 -6
  167. package/lib/qrcode-login.js +57 -57
  168. package/lib/radio-button.js +4 -4
  169. package/lib/radio-group.js +63 -63
  170. package/lib/radio.js +6 -6
  171. package/lib/rate.js +36 -36
  172. package/lib/retrial-auth.js +55 -55
  173. package/lib/row.js +2 -2
  174. package/lib/scrollbar.js +41 -41
  175. package/lib/select.js +95 -95
  176. package/lib/selector-panel.js +92 -91
  177. package/lib/selector.js +935 -935
  178. package/lib/slider.js +6 -6
  179. package/lib/step.js +35 -35
  180. package/lib/steps.js +82 -82
  181. package/lib/submenu.js +38 -38
  182. package/lib/switch.js +38 -38
  183. package/lib/tab-pane.js +4 -4
  184. package/lib/table-column.js +39 -39
  185. package/lib/table.js +653 -653
  186. package/lib/tabs.js +42 -42
  187. package/lib/tag.js +2 -2
  188. package/lib/theme-chalk/code-editor.css +1 -0
  189. package/lib/theme-chalk/form-editor.css +1 -0
  190. package/lib/theme-chalk/form.css +1 -1
  191. package/lib/theme-chalk/index.css +1 -1
  192. package/lib/theme-chalk/lowcode.css +1 -1
  193. package/lib/theme-chalk/selector.css +1 -1
  194. package/lib/time-picker.js +1276 -1276
  195. package/lib/time-select.js +21 -21
  196. package/lib/timeline-item.js +2 -2
  197. package/lib/timeline.js +2 -2
  198. package/lib/tips.js +59 -59
  199. package/lib/toolbar.js +6 -6
  200. package/lib/tooltip.js +44 -44
  201. package/lib/transfer.js +36 -36
  202. package/lib/tree-group.js +49 -49
  203. package/lib/tree.js +432 -432
  204. package/lib/update-history.js +2 -2
  205. package/lib/upload.js +942 -942
  206. package/lib/utils/source-generator.js +586 -0
  207. package/lib/utils/source-parser.js +581 -0
  208. package/lib/wujie.js +39 -39
  209. package/package.json +1 -1
  210. package/packages/code-editor/index.js +5 -0
  211. package/packages/{lowcode/src/editor.vue → code-editor/src/code-editor.vue} +14 -17
  212. package/packages/form/src/form-item-render.vue +25 -0
  213. package/packages/form/src/form-item.vue +10 -3
  214. package/packages/form-editor/index.js +5 -0
  215. package/packages/form-editor/src/components.js +6736 -0
  216. package/packages/form-editor/src/form-editor.vue +981 -0
  217. package/packages/form-editor/src/props-panel.vue +168 -0
  218. package/packages/lowcode/src/attribute/bind.vue +5 -5
  219. package/packages/lowcode/src/attribute/function.vue +24 -9
  220. package/packages/lowcode/src/attribute/javascript.vue +4 -4
  221. package/packages/lowcode/src/attribute/property.vue +1 -1
  222. package/packages/lowcode/src/attribute/props.vue +44 -29
  223. package/packages/lowcode/src/attribute/styles.vue +1 -1
  224. package/packages/lowcode/src/attribute.vue +4 -4
  225. package/packages/lowcode/src/canvas.vue +45 -100
  226. package/packages/lowcode/src/form-render.vue +25 -13
  227. package/packages/lowcode/src/json.vue +4 -4
  228. package/packages/lowcode/src/lowcode.vue +1 -1
  229. package/packages/lowcode/src/modules.vue +8 -1
  230. package/packages/lowcode/src/render.vue +14 -9
  231. package/packages/lowcode/src/source.vue +6 -6
  232. package/packages/lowcode/src/util/components.js +15646 -68
  233. package/packages/lowcode/src/util/form-controls.js +87 -0
  234. package/packages/lowcode/src/util/props-util.js +9 -8
  235. package/packages/lowcode-view/src/render.vue +13 -6
  236. package/packages/lowcode-view/src/view.vue +4 -1
  237. package/packages/main/src/components/user.vue +2 -0
  238. package/packages/main/src/components/userinfo.vue +22 -14
  239. package/packages/selector-panel/src/mixin.js +1 -0
  240. package/packages/theme-chalk/src/code-editor.scss +59 -0
  241. package/packages/theme-chalk/src/form-editor.scss +240 -0
  242. package/packages/theme-chalk/src/form.scss +10 -1
  243. package/packages/theme-chalk/src/index.scss +2 -0
  244. package/packages/theme-chalk/src/lowcode.scss +1 -42
  245. package/packages/theme-chalk/src/selector.scss +2 -0
  246. package/src/index.js +7 -1
  247. package/{packages/lowcode/src/util → src/utils}/source-generator.js +24 -15
  248. package/{packages/lowcode/src/util → src/utils}/source-parser.js +67 -23
  249. /package/packages/{lowcode → code-editor}/src/util/json-repair.js +0 -0
  250. /package/packages/{lowcode → code-editor}/src/util/monaco-vue-completions.js +0 -0
@@ -0,0 +1,586 @@
1
+ exports.__esModule = true;
2
+
3
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4
+
5
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
6
+ * 低代码页面 JSON → Vue 单文件源码生成器
7
+ * 将 page 对象(含 children 节点树)转换为可直接运行的 .vue 源码字符串
8
+ */
9
+
10
+
11
+ exports.genNode = genNode;
12
+ exports.generateVueSource = generateVueSource;
13
+
14
+ var _formControls = require('eoss/packages/lowcode/src/util/form-controls.js');
15
+
16
+ var INDENT = ' ';
17
+
18
+ /** 判断值是否是需要原样输出的表达式(绑定语法) */
19
+ function isExpression(val) {
20
+ return typeof val === 'string' && /^[{[]/.test(val.trim());
21
+ }
22
+
23
+ /** 判断是否是"函数体"约定结构:{ body: '...' } */
24
+ function isFunctionBody(val) {
25
+ return val && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object' && typeof val.body === 'string';
26
+ }
27
+
28
+ /**
29
+ * 序列化值为源码文本
30
+ * 对象/数组换行展开,函数体对象直接输出 body
31
+ */
32
+ function serialize(val, indent) {
33
+ var pad = new Array(indent + 1).join(INDENT);
34
+ var padChild = pad + INDENT;
35
+ if (val === null || val === undefined) {
36
+ return 'null';
37
+ }
38
+ if (typeof val === 'function') {
39
+ return val.toString();
40
+ }
41
+ if (typeof val === 'string') {
42
+ return JSON.stringify(val);
43
+ }
44
+ if ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) !== 'object') {
45
+ return String(val);
46
+ }
47
+ if (isFunctionBody(val)) {
48
+ return val.body;
49
+ }
50
+ if (Array.isArray(val)) {
51
+ if (!val.length) {
52
+ return '[]';
53
+ }
54
+ var _items = val.map(function (item) {
55
+ return padChild + serialize(item, indent + 1);
56
+ }).join(',\n');
57
+ return '[\n' + _items + '\n' + pad + ']';
58
+ }
59
+ var keys = Object.keys(val);
60
+ if (!keys.length) {
61
+ return '{}';
62
+ }
63
+ var items = keys.map(function (key) {
64
+ return padChild + key + ': ' + serialize(val[key], indent + 1);
65
+ }).join(',\n');
66
+ return '{\n' + items + '\n' + pad + '}';
67
+ }
68
+
69
+ /** 生成节点的 :style 绑定字符串(对象字面量形式,可读性更好) */
70
+ function genStyle(node) {
71
+ var style = node.style;
72
+ if (!style || !Object.keys(style).length) {
73
+ return '';
74
+ }
75
+ var parts = Object.keys(style).map(function (key) {
76
+ var val = style[key];
77
+ if (isExpression(val)) {
78
+ // 绑定表达式直接嵌入
79
+ return key + ': ' + val;
80
+ }
81
+ return key + ': ' + JSON.stringify(val);
82
+ });
83
+ return " :style='{ " + parts.join(', ') + " }'";
84
+ }
85
+
86
+ /** 属性值转义:& 与 " 转实体,解析端统一解码 */
87
+ function escapeAttr(val) {
88
+ return String(val).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
89
+ }
90
+
91
+ /** 单个 prop 属性串:{{var}} 整体匹配输出绑定表达式,其余按类型输出 */
92
+ function genPropAttr(key, val) {
93
+ if (typeof val === 'string') {
94
+ var full = /^\{\{([\s\S]+)\}\}$/.exec(val);
95
+ if (full) {
96
+ return ' :' + key + '="' + full[1].trim() + '"';
97
+ }
98
+ return ' ' + key + '="' + val + '"';
99
+ }
100
+ if (typeof val === 'boolean' || typeof val === 'number') {
101
+ return ' :' + key + '="' + val + '"';
102
+ }
103
+ // 复杂值用绑定语法输出:单引号属性 + 紧凑 JSON
104
+ return ' :' + key + "='" + JSON.stringify(val).replace(/'/g, '&#39;') + "'";
105
+ }
106
+
107
+ /** 生成节点的 props 属性串 */
108
+ function genProps(node) {
109
+ var props = node.props;
110
+ if (!props) {
111
+ return '';
112
+ }
113
+ // 定义数组形态:仅输出值被改动过的条目(value 字段)
114
+ if (Array.isArray(props)) {
115
+ return props.reduce(function (attrs, item) {
116
+ if (!item || !item.name || item.value === undefined) {
117
+ return attrs;
118
+ }
119
+ return attrs + genPropAttr(item.name, item.value);
120
+ }, '');
121
+ }
122
+ return Object.keys(props).reduce(function (attrs, key) {
123
+ var val = props[key];
124
+ if (val === undefined) {
125
+ return attrs;
126
+ }
127
+ // 跳过组件定义的 props(值是函数类型,如 String、Number、Boolean 等)
128
+ // 这些是组件声明接受的属性,不是使用时传入的值
129
+ if (typeof val === 'function') {
130
+ return attrs;
131
+ }
132
+ // 指令统一存在 directives 字段,这里跳过历史数据中混入 props 的 v- 键
133
+ if (key.startsWith('v-')) {
134
+ return attrs;
135
+ }
136
+ // 字符串:{{var}} 整体匹配输出绑定表达式(与数组形态 genPropAttr 对称);
137
+ // 以 { 或 [ 开头的历史表达式原样绑定;其余按字面量输出
138
+ if (typeof val === 'string') {
139
+ var full = /^\{\{([\s\S]+)\}\}$/.exec(val);
140
+ if (full) {
141
+ return attrs + ' :' + key + '="' + full[1].trim() + '"';
142
+ }
143
+ if (isExpression(val)) {
144
+ return attrs + ' :' + key + '="' + val + '"';
145
+ }
146
+ return attrs + ' ' + key + '="' + val + '"';
147
+ }
148
+ if (typeof val === 'boolean') {
149
+ return attrs + ' :' + key + '="' + val + '"';
150
+ }
151
+ if (typeof val === 'number') {
152
+ return attrs + ' :' + key + '="' + val + '"';
153
+ }
154
+ // 复杂值用绑定语法输出:单引号属性 + 紧凑 JSON(不转实体、不换行),
155
+ // 解析端据此还原为真实数组/对象;值内单引号转 &#39; 避免截断属性
156
+ return attrs + ' :' + key + "='" + JSON.stringify(val).replace(/'/g, '&#39;') + "'";
157
+ }, '');
158
+ }
159
+
160
+ /** 生成节点的 Vue 指令串(键存储时不含 v- 前缀,输出时统一补上;text 除外) */
161
+ function genDirectives(node) {
162
+ var directives = node.directives;
163
+ if (!directives) {
164
+ return '';
165
+ }
166
+ return Object.keys(directives).reduce(function (attrs, key) {
167
+ var val = directives[key];
168
+ if (val === undefined || val === null || val === '') {
169
+ return attrs;
170
+ }
171
+ var dirName = key.startsWith('v-') ? key : 'v-' + key;
172
+ // text 转换为 {{xxx}} 形式输出到标签内容中,不作为属性输出
173
+ if (dirName === 'v-text') {
174
+ return attrs;
175
+ }
176
+ return attrs + ' ' + dirName + '="' + val + '"';
177
+ }, '');
178
+ }
179
+
180
+ /** 生成节点的 events 属性串 */
181
+ function genEvents(node) {
182
+ var events = node.events;
183
+ if (!events) {
184
+ return '';
185
+ }
186
+ return Object.keys(events).reduce(function (attrs, key) {
187
+ var val = events[key];
188
+ if (val === undefined || val === null) {
189
+ return attrs;
190
+ }
191
+ // 函数体约定结构,输出方法名引用
192
+ if (isFunctionBody(val)) {
193
+ return attrs + ' @' + key + '="' + key + '"';
194
+ }
195
+ if (typeof val === 'string') {
196
+ return attrs + ' @' + key + '="' + val + '"';
197
+ }
198
+ return attrs + ' @' + key + '="' + key + '"';
199
+ }, '');
200
+ }
201
+
202
+ /** 取节点的子节点列表(页面结构树统一存在 children) */
203
+ function getChildren(node) {
204
+ if (!node || !node.children) {
205
+ return [];
206
+ }
207
+ if (!Array.isArray(node.children)) {
208
+ return [];
209
+ }
210
+ return node.children;
211
+ }
212
+
213
+ /** es-button → EsButton 形式的组件标识 */
214
+ function componentName(name) {
215
+ return String(name).replace(/(^|-)(\w)/g, function (m, sep, c) {
216
+ return c.toUpperCase();
217
+ });
218
+ }
219
+
220
+ /** EsButton → es-button 形式的模板标签名(html 小写标签保持不变) */
221
+ function tagName(name) {
222
+ return String(name).replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
223
+ }
224
+
225
+ /** 递归收集节点树中的所有脚本依赖 */
226
+ function collectScripts(node, scripts) {
227
+ if (!node) return;
228
+ // 收集当前节点的脚本(数组格式)
229
+ if (Array.isArray(node.script)) {
230
+ node.script.forEach(function (src) {
231
+ if (src && !scripts.includes(src)) {
232
+ scripts.push(src);
233
+ }
234
+ });
235
+ }
236
+ // 递归收集子节点
237
+ if (node.children && Array.isArray(node.children) && node.children.length) {
238
+ node.children.forEach(function (child) {
239
+ return collectScripts(child, scripts);
240
+ });
241
+ }
242
+ }
243
+
244
+ /** 生成节点的 HTML 属性串(id、ref、class、slot 等普通属性) */
245
+ function genAttrs(node) {
246
+ var attrs = node.attrs;
247
+ if (!attrs) {
248
+ return '';
249
+ }
250
+ return Object.keys(attrs).reduce(function (str, key) {
251
+ var val = attrs[key];
252
+ if (val === undefined || val === null || val === '') {
253
+ return str;
254
+ }
255
+ if (typeof val === 'boolean') {
256
+ return val ? str + ' ' + key : str;
257
+ }
258
+ return str + ' ' + key + '="' + val + '"';
259
+ }, '');
260
+ }
261
+
262
+ /** 递归生成模板节点(html 元素、组件库组件、自封装组件一视同仁,按 name 渲染) */
263
+ function genNode(node, indent) {
264
+ if (!node) {
265
+ return '';
266
+ }
267
+ var pad = new Array(indent + 1).join(INDENT);
268
+ var tag = tagName(node.nodeName || 'div');
269
+
270
+ // 节点 id 以 data-id 输出,源码编辑后能原样解析回来
271
+ var idAttr = node.id ? ' data-id="' + node.id + '"' : '';
272
+ // description 是编辑器标签(元信息),以属性承载,不作为插槽文本渲染;
273
+ // 解析端对 description 属性单独识别,旧源码的文本写法仍兼容
274
+ var descAttr = node.description ? ' description="' + escapeAttr(node.description) + '"' : '';
275
+ // 输出顺序:HTML 属性 + 组件 props + 指令 + 事件 + 样式
276
+ var attrStr = idAttr + descAttr + genAttrs(node) + genProps(node) + genDirectives(node) + genEvents(node) + genStyle(node);
277
+ var children = getChildren(node);
278
+ var lines = [];
279
+
280
+ // 检查是否有 text 指令
281
+ var vText = node.directives && node.directives['text'];
282
+
283
+ if (!children.length && !vText) {
284
+ lines.push(pad + '<' + tag + attrStr + '></' + tag + '>');
285
+ return lines.join('\n');
286
+ }
287
+ lines.push(pad + '<' + tag + attrStr + '>');
288
+ if (vText) {
289
+ // v-text 属性转换为 {{xxx}} 形式
290
+ lines.push(pad + INDENT + '{{' + vText + '}}');
291
+ }
292
+ // 子节点继续递归下钻;仅 es-form 内的表单控件子节点输出时包 es-form-item
293
+ // (JSON 不存包裹节点,源码与真实应用结构一一对应);es-form 外的控件裸输出
294
+ children.forEach(function (child) {
295
+ lines.push(genChildNode(child, indent + 1, node));
296
+ });
297
+ lines.push(pad + '</' + tag + '>');
298
+ return lines.join('\n');
299
+ }
300
+
301
+ /** 生成子节点:仅 es-form 内的表单控件(form-controls 清单命中)包 es-form-item 包裹层,其余直接生成 */
302
+ function genChildNode(child, indent, parent) {
303
+ if (!child) {
304
+ return '';
305
+ }
306
+ if (!(0, _formControls.isFormControlNode)(child) || (0, _formControls.toPascal)(parent && parent.nodeName || '') !== 'EsForm') {
307
+ return genNode(child, indent);
308
+ }
309
+ var pad = new Array(indent + 1).join(INDENT);
310
+ var label = child.label || '';
311
+ var prop = child.name || '';
312
+ // 宽度输出在包裹层:form-item 是列布局单元,拖宽占多列才能在真实应用生效;
313
+ // 内层控件不重复携带 width(画布上宽度同样作用于 es-form-item 根)
314
+ var width = child.style && child.style.width;
315
+ var styleAttr = width ? genStyle({ style: { width: width } }) : '';
316
+ var inner = child;
317
+ if (width) {
318
+ inner = _extends({}, child, { style: _extends({}, child.style) });
319
+ delete inner.style.width;
320
+ }
321
+ return pad + '<es-form-item label="' + escapeAttr(label) + '" prop="' + escapeAttr(prop) + '"' + styleAttr + '>\n' + genNode(inner, indent + 1) + '\n' + pad + '</es-form-item>';
322
+ }
323
+
324
+ /**
325
+ * 生成 methods/computed/watch 等选项块
326
+ * @param {string} name 选项名,如 computed 会生成计算属性 getter
327
+ * @param {Object} obj 选项对象
328
+ * @param {string} params 函数体对象的形参,如 methods 用 '...args'
329
+ */
330
+ function genOption(name, obj, params) {
331
+ if (!obj || !Object.keys(obj).length) {
332
+ return '';
333
+ }
334
+ var isComputed = name === 'computed';
335
+ var items = Object.keys(obj).map(function (key) {
336
+ var val = obj[key];
337
+ if (isFunctionBody(val)) {
338
+ // 函数体缩进:普通方法在第 3 级,computed 也在第 3 级(不再包 IIFE)
339
+ var level = 3;
340
+ var bodyPad = new Array(level + 1).join(INDENT);
341
+ var body = val.body.split('\n').map(function (l) {
342
+ return bodyPad + l;
343
+ }).join('\n');
344
+ // computed 无参数,其他使用 params
345
+ var paramsStr = isComputed ? '' : params || '';
346
+ return INDENT + INDENT + key + '(' + paramsStr + ') {\n' + body + '\n' + INDENT + INDENT + '}';
347
+ }
348
+ // 如果是函数对象,提取函数体和参数生成简写语法
349
+ if (typeof val === 'function') {
350
+ var funcStr = val.toString();
351
+ // 检测是否是原生函数(如 String, Number, Boolean 等)
352
+ if (funcStr.includes('[native code]')) {
353
+ // 提取函数名
354
+ var nameMatch = funcStr.match(/function\s+(\w+)/);
355
+ var funcName = nameMatch ? nameMatch[1] : key;
356
+ return INDENT + INDENT + key + ': ' + funcName;
357
+ }
358
+ // 匹配 function name(params) { body } 或 (params) => { body }
359
+ var match = funcStr.match(/(?:function\s+\w+|\(.*?\)|\w+)\s*(?:=>)?\s*\{([\s\S]*)\}/);
360
+ if (match) {
361
+ var _body = match[1].trim();
362
+ // 提取参数部分
363
+ var _paramsStr = '';
364
+ var paramMatch = funcStr.match(/function\s+\w+\(([^)]*)\)/);
365
+ if (paramMatch) {
366
+ _paramsStr = paramMatch[1];
367
+ } else {
368
+ var arrowParamMatch = funcStr.match(/\(([^)]*)\)\s*=>/);
369
+ if (arrowParamMatch) {
370
+ _paramsStr = arrowParamMatch[1];
371
+ }
372
+ }
373
+ var _level = isComputed ? 4 : 3;
374
+ var _bodyPad = new Array(_level + 1).join(INDENT);
375
+ var formattedBody = _body.split('\n').map(function (l) {
376
+ return _bodyPad + l;
377
+ }).join('\n');
378
+ // computed 直接输出函数体,不包 IIFE
379
+ if (isComputed) {
380
+ return INDENT + INDENT + key + '() {\n' + formattedBody + '\n' + INDENT + INDENT + '}';
381
+ }
382
+ return INDENT + INDENT + key + '(' + _paramsStr + ') {\n' + formattedBody + '\n' + INDENT + INDENT + '}';
383
+ }
384
+ }
385
+ // methods 中的字符串值视为函数体
386
+ if (name === 'methods' && typeof val === 'string') {
387
+ var _level2 = 3;
388
+ var _bodyPad2 = new Array(_level2 + 1).join(INDENT);
389
+ var _paramsStr2 = params || '';
390
+ var _body2 = val ? val.split('\n').map(function (l) {
391
+ return _bodyPad2 + l;
392
+ }).join('\n') : _bodyPad2;
393
+ return INDENT + INDENT + key + '(' + _paramsStr2 + ') {\n' + _body2 + '\n' + INDENT + INDENT + '}';
394
+ }
395
+ return INDENT + INDENT + key + ': ' + serialize(val, 1);
396
+ });
397
+ return INDENT + name + ': {\n' + items.join(',\n') + '\n' + INDENT + '},';
398
+ }
399
+
400
+ /** data 选项:固定生成为函数形式,对象键在第 3 级、闭合括号对齐 return */
401
+ function genData(obj) {
402
+ // 如果 obj 不存在或不是对象,返回空
403
+ if (!obj || (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
404
+ return '';
405
+ }
406
+ // 只要有 data 字段就生成 data() 函数,即使为空对象
407
+ var keys = Object.keys(obj);
408
+ if (!keys.length) {
409
+ return INDENT + 'data() {\n' + INDENT + INDENT + 'return {};\n' + INDENT + '},';
410
+ }
411
+ return INDENT + 'data() {\n' + INDENT + INDENT + 'return ' + serialize(obj, 2) + ';\n' + INDENT + '},';
412
+ }
413
+
414
+ /** inject / provide 选项:支持对象、数组、字符串三种格式 */
415
+ function genInjectProvide(name, obj) {
416
+ if (obj == null) return '';
417
+ // 数组格式:['foo', 'bar']
418
+ if (Array.isArray(obj)) {
419
+ if (!obj.length) return '';
420
+ return INDENT + name + ': ' + JSON.stringify(obj) + ',';
421
+ }
422
+ // 对象格式:{ foo: 'bar' }
423
+ if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
424
+ return genOption(name, obj);
425
+ }
426
+ // 字符串格式:直接输出原始代码
427
+ if (typeof obj === 'string' && obj.trim()) {
428
+ return INDENT + name + ': ' + obj.trim() + ',';
429
+ }
430
+ return '';
431
+ }
432
+
433
+ /** 生命周期钩子:created/mounted/destroyed 等 */
434
+ function genHook(name, hook) {
435
+ if (!hook || !isFunctionBody(hook)) {
436
+ return '';
437
+ }
438
+ return INDENT + name + '() {\n' + hook.body.split('\n').map(function (l) {
439
+ return INDENT + INDENT + l;
440
+ }).join('\n') + '\n' + INDENT + '},';
441
+ }
442
+
443
+ /**
444
+ * 将页面 JSON 转换为 Vue 单文件源码
445
+ * @param {Object} page 页面对象(含 children 节点树)
446
+ * @returns {string} .vue 源码字符串
447
+ */
448
+ function generateVueSource(page) {
449
+ if (!page) {
450
+ return '';
451
+ }
452
+
453
+ // ---------- template ----------
454
+ // 区分本地 css 和 CDN css
455
+ var cssItems = Array.isArray(page.css) ? page.css : [];
456
+ var localCss = [];
457
+ var cdnCss = [];
458
+ cssItems.forEach(function (path) {
459
+ if (/^https?:\/\//.test(path)) {
460
+ cdnCss.push(path);
461
+ } else {
462
+ localCss.push(path);
463
+ }
464
+ });
465
+
466
+ // 优先使用用户编辑的 template,否则从 children 生成
467
+ var template = void 0;
468
+ if (page.template) {
469
+ // 用户编辑的模板,直接使用
470
+ template = page.template + '\n';
471
+ } else {
472
+ // 页面对象本身就是根节点(含 style/children),但它的 name 是页面名不是标签名,
473
+ // 根标签固定为 div;子节点递归下钻,支持 html 元素 / 组件库组件 / 自封装组件
474
+ var root = {};
475
+ Object.keys(page).forEach(function (key) {
476
+ root[key] = page[key];
477
+ });
478
+ root.nodeName = 'div';
479
+ // 子节点
480
+ var children = Array.isArray(page.children) ? page.children : [];
481
+ // 过滤掉旧格式的导入注册数据(含 path 字段的对象)
482
+ var validChildren = children.filter(function (c) {
483
+ return c && c.id && !c.path;
484
+ });
485
+ root.children = validChildren;
486
+ var body = genNode(root, 1);
487
+ template = body ? '<template>\n' + body + '\n</template>\n' : '<template>\n <div></div>\n</template>\n';
488
+ }
489
+
490
+ // ---------- script ----------
491
+ var scriptLines = ['<script>'];
492
+
493
+ // 处理 imports(所有 import 都作为组件处理)
494
+ var importsArr = page.imports || [];
495
+ var allImports = importsArr.filter(function (item) {
496
+ return item && item.name;
497
+ });
498
+
499
+ // 生成 import 语句(default import)
500
+ allImports.forEach(function (item) {
501
+ if (item.path) {
502
+ scriptLines.push('import ' + componentName(item.name) + " from '" + item.path + "';");
503
+ }
504
+ });
505
+ if (allImports.length) {
506
+ scriptLines.push('');
507
+ }
508
+
509
+ scriptLines.push('export default {');
510
+ if (page.name) {
511
+ scriptLines.push(INDENT + 'name: ' + JSON.stringify(page.name) + ',');
512
+ }
513
+ // 生成 components 注册
514
+ if (allImports.length) {
515
+ var names = allImports.map(function (item) {
516
+ return componentName(item.name);
517
+ });
518
+ scriptLines.push(INDENT + 'components: { ' + names.join(', ') + ' },');
519
+ }
520
+ var props = genOption('props', page.props);
521
+ var inject = genInjectProvide('inject', page.inject);
522
+ var provide = genInjectProvide('provide', page.provide);
523
+ var data = genData(page.data);
524
+ var computed = genOption('computed', page.computed);
525
+ var watch = genOption('watch', page.watch, 'newVal, oldVal');
526
+ var methods = genOption('methods', page.methods);
527
+
528
+ // 收集组件级脚本依赖并生成 created 钩子
529
+ var scripts = [];
530
+ collectScripts(page, scripts);
531
+
532
+ // 生成 created 钩子:合并 CDN css、脚本注入和用户定义的 created
533
+ var createdCode = '';
534
+ if (cdnCss.length > 0 || scripts.length > 0) {
535
+ createdCode += INDENT + 'created() {\n';
536
+ // CDN css 动态加载
537
+ cdnCss.forEach(function (href) {
538
+ createdCode += INDENT + INDENT + '// 加载 ' + href + '\n';
539
+ createdCode += INDENT + INDENT + 'if (typeof window !== "undefined") {\n';
540
+ createdCode += INDENT + INDENT + INDENT + 'const link = document.createElement("link");\n';
541
+ createdCode += INDENT + INDENT + INDENT + 'link.rel = "stylesheet";\n';
542
+ createdCode += INDENT + INDENT + INDENT + 'link.href = "' + href + '";\n';
543
+ createdCode += INDENT + INDENT + INDENT + 'document.head.appendChild(link);\n';
544
+ createdCode += INDENT + INDENT + '}\n';
545
+ });
546
+ // 脚本动态加载
547
+ scripts.forEach(function (src) {
548
+ createdCode += INDENT + INDENT + '// 加载 ' + src + '\n';
549
+ createdCode += INDENT + INDENT + 'if (typeof window !== "undefined") {\n';
550
+ createdCode += INDENT + INDENT + INDENT + 'const s = document.createElement("script");\n';
551
+ createdCode += INDENT + INDENT + INDENT + 's.src = "' + src + '";\n';
552
+ createdCode += INDENT + INDENT + INDENT + 'document.head.appendChild(s);\n';
553
+ createdCode += INDENT + INDENT + '}\n';
554
+ });
555
+ // 如果有页面级 created 钩子,追加其内容
556
+ if (page.created && page.created.body) {
557
+ createdCode += INDENT + INDENT + '// 用户定义的 created 逻辑\n';
558
+ createdCode += INDENT + INDENT + page.created.body + '\n';
559
+ }
560
+ createdCode += INDENT + '},';
561
+ } else {
562
+ createdCode = genHook('created', page.created);
563
+ }
564
+
565
+ var mounted = genHook('mounted', page.mounted);
566
+ var destroyed = genHook('destroyed', page.destroyed);
567
+ [props, inject, provide, data, computed, watch, methods, createdCode, mounted, destroyed].forEach(function (block) {
568
+ if (block) {
569
+ scriptLines.push(block);
570
+ }
571
+ });
572
+ scriptLines.push('};', '</script>');
573
+ var script = scriptLines.join('\n');
574
+
575
+ // ---------- style ----------
576
+ var style = '';
577
+ if (localCss.length > 0) {
578
+ var imports = localCss.map(function (path) {
579
+ return '@import \'' + path + '\';';
580
+ }).join('\n');
581
+ style = '<style lang="scss" scoped>\n' + imports + '\n</style>\n';
582
+ }
583
+
584
+ var result = template + '\n' + script + '\n' + style;
585
+ return result;
586
+ }