@lcap/nasl 3.5.0-beta.4 → 3.6.0-alpha.1

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 (238) hide show
  1. package/out/bak/translator.js +39 -119
  2. package/out/bak/translator.js.map +1 -1
  3. package/out/breakpoint/generator/BreakpointNode.d.ts +0 -3
  4. package/out/breakpoint/generator/BreakpointNode.js +0 -9
  5. package/out/breakpoint/generator/BreakpointNode.js.map +1 -1
  6. package/out/breakpoint/shared/constants.js +0 -1
  7. package/out/breakpoint/shared/constants.js.map +1 -1
  8. package/out/breakpoint/shared/utils.js +7 -31
  9. package/out/breakpoint/shared/utils.js.map +1 -1
  10. package/out/common/BaseNode.d.ts +13 -1
  11. package/out/common/BaseNode.js +52 -23
  12. package/out/common/BaseNode.js.map +1 -1
  13. package/out/common/Command.js +1 -0
  14. package/out/common/Command.js.map +1 -1
  15. package/out/common/EventEmitter.d.ts +1 -1
  16. package/out/common/EventEmitter.js +0 -4
  17. package/out/common/EventEmitter.js.map +1 -1
  18. package/out/concepts/App__.d.ts +76 -51
  19. package/out/concepts/App__.js +190 -87
  20. package/out/concepts/App__.js.map +1 -1
  21. package/out/concepts/BackendVariable__.js +2 -10
  22. package/out/concepts/BackendVariable__.js.map +1 -1
  23. package/out/concepts/BindAttribute__.js +6 -16
  24. package/out/concepts/BindAttribute__.js.map +1 -1
  25. package/out/concepts/BindDirective__.d.ts +0 -1
  26. package/out/concepts/BindDirective__.js +4 -19
  27. package/out/concepts/BindDirective__.js.map +1 -1
  28. package/out/concepts/BindEvent__.d.ts +1 -3
  29. package/out/concepts/BindEvent__.js +13 -38
  30. package/out/concepts/BindEvent__.js.map +1 -1
  31. package/out/concepts/CallFunction__.js +2 -10
  32. package/out/concepts/CallFunction__.js.map +1 -1
  33. package/out/concepts/CallLogic__.d.ts +0 -2
  34. package/out/concepts/CallLogic__.js +27 -38
  35. package/out/concepts/CallLogic__.js.map +1 -1
  36. package/out/concepts/Constant__.js +6 -7
  37. package/out/concepts/Constant__.js.map +1 -1
  38. package/out/concepts/Destination__.d.ts +1 -1
  39. package/out/concepts/Destination__.js +4 -6
  40. package/out/concepts/Destination__.js.map +1 -1
  41. package/out/concepts/End__.js +1 -2
  42. package/out/concepts/End__.js.map +1 -1
  43. package/out/concepts/Entity__.d.ts +1 -1
  44. package/out/concepts/Entity__.js +2 -0
  45. package/out/concepts/Entity__.js.map +1 -1
  46. package/out/concepts/Event__.d.ts +0 -14
  47. package/out/concepts/Event__.js +0 -61
  48. package/out/concepts/Event__.js.map +1 -1
  49. package/out/concepts/Frontend__.d.ts +88 -0
  50. package/out/concepts/Frontend__.js +143 -1
  51. package/out/concepts/Frontend__.js.map +1 -1
  52. package/out/concepts/Identifier__.d.ts +0 -5
  53. package/out/concepts/Identifier__.js +9 -19
  54. package/out/concepts/Identifier__.js.map +1 -1
  55. package/out/concepts/LogicItem__.d.ts +1 -1
  56. package/out/concepts/LogicItem__.js.map +1 -1
  57. package/out/concepts/Logic__.d.ts +1 -3
  58. package/out/concepts/Logic__.js +13 -16
  59. package/out/concepts/Logic__.js.map +1 -1
  60. package/out/concepts/MemberExpression__.d.ts +1 -1
  61. package/out/concepts/MemberExpression__.js +3 -3
  62. package/out/concepts/MemberExpression__.js.map +1 -1
  63. package/out/concepts/NewComposite__.js.map +1 -1
  64. package/out/concepts/Param__.js +3 -11
  65. package/out/concepts/Param__.js.map +1 -1
  66. package/out/concepts/ProcessElement__.js +1 -9
  67. package/out/concepts/ProcessElement__.js.map +1 -1
  68. package/out/concepts/Return__.js +9 -17
  69. package/out/concepts/Return__.js.map +1 -1
  70. package/out/concepts/Variable__.js +8 -17
  71. package/out/concepts/Variable__.js.map +1 -1
  72. package/out/concepts/ViewElement__.d.ts +2 -17
  73. package/out/concepts/ViewElement__.js +31 -143
  74. package/out/concepts/ViewElement__.js.map +1 -1
  75. package/out/concepts/View__.js +6 -6
  76. package/out/concepts/View__.js.map +1 -1
  77. package/out/concepts/index__.d.ts +0 -5
  78. package/out/concepts/index__.js +0 -5
  79. package/out/concepts/index__.js.map +1 -1
  80. package/out/concepts/utils/asserts.d.ts +3 -258
  81. package/out/concepts/utils/asserts.js +13 -351
  82. package/out/concepts/utils/asserts.js.map +1 -1
  83. package/out/concepts/utils/types.d.ts +3 -20
  84. package/out/generator/genBundleFiles.js +11 -25
  85. package/out/generator/genBundleFiles.js.map +1 -1
  86. package/out/generator/genReleaseBody.js +3 -12
  87. package/out/generator/genReleaseBody.js.map +1 -1
  88. package/out/generator/permission.js +3 -3
  89. package/out/generator/permission.js.map +1 -1
  90. package/out/natural/transformTSCode.js +1 -1
  91. package/out/natural/transformTSCode.js.map +1 -1
  92. package/out/server/extendBaseNode.js +22 -6
  93. package/out/server/extendBaseNode.js.map +1 -1
  94. package/out/server/getLogics.js +27 -62
  95. package/out/server/getLogics.js.map +1 -1
  96. package/out/server/getMemberIdentifier.js +1 -6
  97. package/out/server/getMemberIdentifier.js.map +1 -1
  98. package/out/server/naslServer.js +11 -28
  99. package/out/server/naslServer.js.map +1 -1
  100. package/out/server/translator.js +1 -6
  101. package/out/server/translator.js.map +1 -1
  102. package/out/service/storage/init.js +26 -2
  103. package/out/service/storage/init.js.map +1 -1
  104. package/out/templator/genCreateBlock.js +6 -6
  105. package/out/templator/genCreateBlock.js.map +1 -1
  106. package/out/templator/genCurdEditMultipleKeyBlock.js +16 -16
  107. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  108. package/out/templator/genCurdMultipleKeyBlock.d.ts +27 -0
  109. package/out/templator/genCurdMultipleKeyBlock.js +709 -37
  110. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  111. package/out/templator/genGetBlock.js +4 -4
  112. package/out/templator/genGetBlock.js.map +1 -1
  113. package/out/templator/genGridViewBlock.js +12 -12
  114. package/out/templator/genGridViewBlock.js.map +1 -1
  115. package/out/templator/genListViewBlock.js +4 -4
  116. package/out/templator/genListViewBlock.js.map +1 -1
  117. package/out/templator/genSelectBlock.js +3 -3
  118. package/out/templator/genSelectBlock.js.map +1 -1
  119. package/out/templator/genTableBlock.d.ts +2 -0
  120. package/out/templator/genTableBlock.js +124 -11
  121. package/out/templator/genTableBlock.js.map +1 -1
  122. package/out/templator/genUpdateBlock.js +8 -8
  123. package/out/templator/genUpdateBlock.js.map +1 -1
  124. package/out/templator/utils.d.ts +2 -2
  125. package/out/templator/utils.js.map +1 -1
  126. package/out/translator/utils.js +18 -0
  127. package/out/translator/utils.js.map +1 -1
  128. package/out/utils/i18nInfo.js +2 -7
  129. package/out/utils/i18nInfo.js.map +1 -1
  130. package/package.json +2 -2
  131. package/src/bak/translator.js +43 -121
  132. package/src/breakpoint/generator/BreakpointNode.ts +0 -12
  133. package/src/breakpoint/shared/constants.ts +0 -1
  134. package/src/breakpoint/shared/utils.ts +10 -37
  135. package/src/common/BaseNode.ts +60 -22
  136. package/src/common/Command.ts +1 -0
  137. package/src/common/EventEmitter.ts +1 -6
  138. package/src/concepts/App__.ts +251 -139
  139. package/src/concepts/BackendVariable__.ts +2 -10
  140. package/src/concepts/BindAttribute__.ts +6 -15
  141. package/src/concepts/BindDirective__.ts +4 -19
  142. package/src/concepts/BindEvent__.ts +12 -40
  143. package/src/concepts/CallFunction__.ts +2 -10
  144. package/src/concepts/CallLogic__.ts +32 -45
  145. package/src/concepts/Constant__.ts +7 -5
  146. package/src/concepts/Destination__.ts +4 -6
  147. package/src/concepts/End__.ts +0 -1
  148. package/src/concepts/Entity__.ts +3 -1
  149. package/src/concepts/Event__.ts +0 -70
  150. package/src/concepts/Frontend__.ts +251 -3
  151. package/src/concepts/Identifier__.ts +13 -29
  152. package/src/concepts/LogicItem__.ts +0 -1
  153. package/src/concepts/Logic__.ts +14 -21
  154. package/src/concepts/MemberExpression__.ts +3 -3
  155. package/src/concepts/NewComposite__.ts +6 -4
  156. package/src/concepts/Param__.ts +3 -11
  157. package/src/concepts/ProcessElement__.ts +1 -8
  158. package/src/concepts/Return__.ts +12 -15
  159. package/src/concepts/Variable__.ts +9 -17
  160. package/src/concepts/ViewElement__.ts +54 -166
  161. package/src/concepts/View__.ts +6 -8
  162. package/src/concepts/index__.ts +0 -5
  163. package/src/concepts/utils/asserts.ts +4 -367
  164. package/src/concepts/utils/types.ts +0 -28
  165. package/src/generator/genBundleFiles.ts +15 -33
  166. package/src/generator/genReleaseBody.ts +3 -14
  167. package/src/generator/permission.ts +6 -8
  168. package/src/natural/transformTSCode.ts +1 -1
  169. package/src/server/extendBaseNode.ts +41 -22
  170. package/src/server/getLogics.ts +41 -79
  171. package/src/server/getMemberIdentifier.ts +1 -7
  172. package/src/server/naslServer.ts +12 -30
  173. package/src/server/translator.ts +1 -7
  174. package/src/service/storage/init.ts +33 -2
  175. package/src/templator/genCreateBlock.ts +6 -6
  176. package/src/templator/genCurdEditMultipleKeyBlock.ts +16 -16
  177. package/src/templator/genCurdMultipleKeyBlock.ts +817 -93
  178. package/src/templator/genGetBlock.ts +4 -4
  179. package/src/templator/genGridViewBlock.ts +12 -12
  180. package/src/templator/genListViewBlock.ts +4 -4
  181. package/src/templator/genSelectBlock.ts +3 -3
  182. package/src/templator/genTableBlock.ts +137 -12
  183. package/src/templator/genUpdateBlock.ts +8 -8
  184. package/src/templator/utils.ts +2 -2
  185. package/src/translator/utils.ts +20 -0
  186. package/src/utils/i18nInfo.ts +2 -7
  187. package/test/concepts/call-function/fixtures/from-string.json +59 -68
  188. package/test/concepts/call-function/fixtures/to-string-global-tz.json +58 -67
  189. package/test/concepts/call-function/fixtures/to-string-no-tz.json +48 -57
  190. package/test/concepts/call-function/fixtures/to-string-user-tz.json +60 -69
  191. package/test/concepts/call-function/fixtures/to-string-utc-tz.json +60 -69
  192. package/test/concepts/call-interface/fixtures/only-interface.json +72 -81
  193. package/test/concepts/call-interface/fixtures/with-body-complex-argument.json +214 -223
  194. package/test/concepts/call-interface/fixtures/with-body-no-argument.json +76 -85
  195. package/test/concepts/call-interface/fixtures/with-body-simple-argument.json +91 -100
  196. package/test/concepts/call-interface/fixtures/with-headers-no-argument.json +79 -88
  197. package/test/concepts/call-interface/fixtures/with-headers.json +81 -90
  198. package/test/concepts/call-interface/fixtures/with-query-no-argument.json +79 -88
  199. package/test/concepts/call-interface/fixtures/with-query.json +81 -90
  200. package/test/concepts/call-logic/__snapshots__/getQuickInfoOffset.spec.ts.snap +2 -4
  201. package/test/concepts/call-logic/fixtures/entries-get-with-arguments.json +95 -104
  202. package/test/concepts/call-logic/fixtures/entries-update-with-arguments.json +200 -209
  203. package/test/concepts/call-logic/fixtures/global-logic-argument-no-expression.json +88 -97
  204. package/test/concepts/call-logic/fixtures/global-logic-argument-some-expression.json +115 -124
  205. package/test/concepts/call-logic/fixtures/json-deserialize.json +111 -120
  206. package/test/concepts/call-logic/fixtures/json-serialize-with-string.json +115 -124
  207. package/test/concepts/call-logic/fixtures/json-serialize.json +115 -124
  208. package/test/concepts/call-logic/fixtures/view-buildin-logic-with-argument.json +82 -91
  209. package/test/concepts/call-logic/fixtures/view-component-logic-no-argument.json +79 -88
  210. package/test/concepts/call-logic/fixtures/view-component-with-validation.json +135 -144
  211. package/test/concepts/identifier/fixtures/view-variable.json +136 -145
  212. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +1 -1
  213. package/test/concepts/view-element/fixtures/default-login.json +212 -221
  214. package/test/concepts/view-element/fixtures/default-not-found.json +174 -183
  215. package/test/concepts/view-element/fixtures/with-role-auth.json +82 -91
  216. package/test/concepts/view-element/fixtures/with-table.json +1834 -1843
  217. package/test/concepts/view-element/toVue.spec.ts +0 -1
  218. package/ts-worker/package.json +1 -1
  219. package/out/concepts/BusinessComponent__.d.ts +0 -641
  220. package/out/concepts/BusinessComponent__.js +0 -1901
  221. package/out/concepts/BusinessComponent__.js.map +0 -1
  222. package/out/concepts/BusinessLogic__.d.ts +0 -38
  223. package/out/concepts/BusinessLogic__.js +0 -358
  224. package/out/concepts/BusinessLogic__.js.map +0 -1
  225. package/out/concepts/CallEvent__.d.ts +0 -97
  226. package/out/concepts/CallEvent__.js +0 -263
  227. package/out/concepts/CallEvent__.js.map +0 -1
  228. package/out/concepts/FrontendType__.d.ts +0 -308
  229. package/out/concepts/FrontendType__.js +0 -605
  230. package/out/concepts/FrontendType__.js.map +0 -1
  231. package/out/concepts/ParamWithGroup__.d.ts +0 -39
  232. package/out/concepts/ParamWithGroup__.js +0 -85
  233. package/out/concepts/ParamWithGroup__.js.map +0 -1
  234. package/src/concepts/BusinessComponent__.ts +0 -2669
  235. package/src/concepts/BusinessLogic__.ts +0 -376
  236. package/src/concepts/CallEvent__.ts +0 -334
  237. package/src/concepts/FrontendType__.ts +0 -919
  238. package/src/concepts/ParamWithGroup__.ts +0 -101
@@ -1,1901 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __importDefault = (this && this.__importDefault) || function (mod) {
32
- return (mod && mod.__esModule) ? mod : { "default": mod };
33
- };
34
- var BusinessComponent_1;
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.BusinessComponent = void 0;
37
- const time_slicing_1 = require("../utils/time-slicing");
38
- const translator_1 = require("../translator");
39
- const translator_2 = __importDefault(require("../bak/translator"));
40
- const PAGE_COMPONENT_INCLUDE_TAG_MAP = {
41
- 'u-list-view': {
42
- 'page-size': {
43
- value: 'size',
44
- label: '分页大小',
45
- },
46
- 'page-number': {
47
- value: 'page',
48
- label: '当前页数',
49
- },
50
- 'data-source': {
51
- value: 'data',
52
- label: '数据',
53
- },
54
- },
55
- 'u-grid-view': {
56
- 'page-size': {
57
- value: 'size',
58
- label: '分页大小',
59
- },
60
- 'page-number': {
61
- value: 'page',
62
- label: '当前页数',
63
- },
64
- 'data-source': {
65
- value: 'data',
66
- label: '数据',
67
- },
68
- },
69
- 'u-list-components': {
70
- 'data-source': {
71
- value: 'data',
72
- label: '数据',
73
- },
74
- },
75
- 'u-table-view': {
76
- 'page-size': {
77
- value: 'size',
78
- label: '分页大小',
79
- },
80
- 'page-number': {
81
- value: 'page',
82
- label: '当前页数',
83
- },
84
- sorting: {
85
- value: 'sort',
86
- label: '排序属性',
87
- },
88
- value: {
89
- value: 'value',
90
- label: '单选选中值',
91
- },
92
- values: {
93
- value: 'values',
94
- label: '多选选中值',
95
- },
96
- 'data-source': {
97
- value: 'data',
98
- label: '数据',
99
- },
100
- },
101
- 'u-radios': {
102
- value: {
103
- value: 'value',
104
- label: '选中值',
105
- },
106
- 'data-source': {
107
- value: 'data',
108
- label: '数据',
109
- },
110
- },
111
- 'u-checkboxes': {
112
- value: {
113
- value: 'value',
114
- label: '选中值',
115
- },
116
- 'data-source': {
117
- value: 'data',
118
- label: '数据',
119
- },
120
- },
121
- 'u-select': {
122
- value: {
123
- value: 'value',
124
- label: '选中值',
125
- },
126
- 'data-source': {
127
- value: 'data',
128
- label: '数据',
129
- },
130
- opened: {
131
- value: 'opened',
132
- label: '弹出状态',
133
- },
134
- 'page-size': {
135
- value: 'size',
136
- label: '分页大小',
137
- },
138
- 'page-number': {
139
- value: 'page',
140
- label: '当前页数',
141
- },
142
- },
143
- 'u-cascader': {
144
- value: {
145
- value: 'value',
146
- label: '选中值',
147
- },
148
- 'data-source': {
149
- value: 'data',
150
- label: '数据',
151
- },
152
- },
153
- 'u-tree-select-new': {
154
- value: {
155
- value: 'value',
156
- label: '选中值',
157
- },
158
- 'data-source': {
159
- value: 'data',
160
- label: '数据',
161
- },
162
- },
163
- 'van-radio-group': {
164
- value: {
165
- value: 'value',
166
- label: '选中值',
167
- },
168
- 'data-source': {
169
- value: 'data',
170
- label: '数据',
171
- },
172
- },
173
- 'van-checkbox-group': {
174
- value: {
175
- value: 'value',
176
- label: '选中值',
177
- },
178
- 'data-source': {
179
- value: 'data',
180
- label: '数据',
181
- },
182
- },
183
- 'van-pickerson': {
184
- pvalue: {
185
- value: 'value',
186
- label: '选中值',
187
- },
188
- 'data-source': {
189
- value: 'data',
190
- label: '数据',
191
- },
192
- 'page-size': {
193
- value: 'size',
194
- label: '分页大小',
195
- },
196
- 'page-number': {
197
- value: 'page',
198
- label: '当前页数',
199
- },
200
- },
201
- 'van-cascader': {
202
- value: {
203
- value: 'value',
204
- label: '选中值',
205
- },
206
- 'data-source': {
207
- value: 'data',
208
- label: '数据',
209
- },
210
- },
211
- 'van-list-view': {
212
- 'page-size': {
213
- value: 'size',
214
- label: '分页大小',
215
- },
216
- 'page-number': {
217
- value: 'page',
218
- label: '当前页数',
219
- },
220
- 'data-source': {
221
- value: 'data',
222
- label: '数据',
223
- },
224
- },
225
- 'van-grid-view': {
226
- 'page-size': {
227
- value: 'size',
228
- label: '分页大小',
229
- },
230
- 'page-number': {
231
- value: 'page',
232
- label: '当前页数',
233
- },
234
- 'data-source': {
235
- value: 'data',
236
- label: '数据',
237
- },
238
- },
239
- 'van-for-components': {
240
- 'data-source': {
241
- value: 'data',
242
- label: '数据',
243
- },
244
- },
245
- };
246
- const getBranchCopyUniCode = () => window?.BranchCopyUniCode;
247
- const removedViewElementCache = {}; // 临时记录删除的页面元素计数的最大值
248
- const decorators_1 = require("../decorators");
249
- const utils = __importStar(require("../utils"));
250
- const asserts = __importStar(require("./utils/asserts"));
251
- const BaseNode_1 = __importDefault(require("../common/BaseNode"));
252
- /**
253
- * 业务组件
254
- */
255
- let BusinessComponent = BusinessComponent_1 = class BusinessComponent extends BaseNode_1.default {
256
- /**
257
- * @param source 需要合并的部分参数
258
- */
259
- constructor(source) {
260
- source = Object.assign({}, BusinessComponent_1.getDefaultOptions(), source);
261
- super(source);
262
- /**
263
- * 组件事件列表
264
- */
265
- this.events = [];
266
- /**
267
- * 参数分组列表
268
- */
269
- this.params = [];
270
- /**
271
- * 变量列表
272
- */
273
- this.variables = [];
274
- /**
275
- * 元素绑定事件列表
276
- */
277
- this.bindEvents = [];
278
- /**
279
- * 业务组件逻辑列表
280
- */
281
- this.logics = [];
282
- /**
283
- * 页面元素列表
284
- */
285
- this.elements = [];
286
- /**
287
- * 获取当前业务组件下所有elements上bindEvents下的logic
288
- */
289
- this.elementLogicRoot = [];
290
- this.existingViewElement = new Set();
291
- super.subConstructor(source);
292
- }
293
- static from(source, parentNode, parentKey) {
294
- return super.from(source, parentNode, parentKey);
295
- }
296
- /**
297
- * 从父级删除该节点
298
- * @internal
299
- */
300
- _delete() {
301
- let params = null;
302
- if (this.parentNode) {
303
- params = this.parentNode?.__removeBusinessComponent?.(this);
304
- }
305
- return params;
306
- }
307
- /**
308
- * 设置业务组件名称
309
- */
310
- setName(name) {
311
- const object = {
312
- name,
313
- };
314
- this.update({
315
- ...object,
316
- field: 'name',
317
- });
318
- }
319
- /**
320
- * 设置业务组件标题
321
- */
322
- setTitle(title) {
323
- const object = {
324
- title,
325
- };
326
- this.update({
327
- ...object,
328
- });
329
- }
330
- /**
331
- * 设置业务组件描述
332
- */
333
- setDescription(description) {
334
- const object = {
335
- description,
336
- };
337
- this.update({
338
- ...object,
339
- });
340
- }
341
- /**
342
- * 设置icon
343
- */
344
- setIcon(icon) {
345
- const object = {
346
- icon,
347
- };
348
- this.update({
349
- ...object,
350
- });
351
- }
352
- getEventExistingNames(excludedList = []) {
353
- const excludedSet = new Set(excludedList);
354
- return (this.events || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
355
- }
356
- getEventUniqueName(name = 'event1') {
357
- return utils.unique(name, this.getEventExistingNames(), undefined, false);
358
- }
359
- _insertEventAt(options, index) {
360
- const eventOptions = {};
361
- const relationOptions = { parentNode: this, parentKey: 'events' };
362
- const Event = (0, decorators_1.getConceptConstructor)('Event');
363
- let event;
364
- if (!options) {
365
- event = Event.from({
366
- ...eventOptions,
367
- name: this.getEventUniqueName(),
368
- }, this, 'events');
369
- }
370
- else if (typeof options === 'string') {
371
- event = Event.from({
372
- ...eventOptions,
373
- name: options,
374
- }, this, 'events');
375
- }
376
- else if (asserts.isEvent(options)) {
377
- options.ensureDelete(); // 同一实例不支持多处存在
378
- event = options;
379
- Object.assign(event, relationOptions);
380
- }
381
- else {
382
- event = Event.from({
383
- ...eventOptions,
384
- ...options,
385
- }, this, 'events');
386
- }
387
- this.events.splice(index, 0, event);
388
- return event;
389
- }
390
- insertEventAt(options, index) {
391
- const node = this._insertEventAt(options, index);
392
- node.create({
393
- index,
394
- parentNode: this,
395
- parentKey: 'events',
396
- });
397
- return node;
398
- }
399
- _addEvent(options) {
400
- const index = this.events.length;
401
- return this._insertEventAt(options, index);
402
- }
403
- addEvent(options) {
404
- const node = this._addEvent(options);
405
- const index = this.events.indexOf(node);
406
- node.create({
407
- index,
408
- parentNode: this,
409
- parentKey: 'events',
410
- });
411
- return node;
412
- }
413
- getParamUniqueName(name = 'param1') {
414
- return utils.unique(name, this.getVarExistingNames(), undefined, false);
415
- }
416
- _insertParamAt(options, index) {
417
- const paramOptions = {};
418
- const relationOptions = { parentNode: this, parentKey: 'params' };
419
- const ParamWithGroup = (0, decorators_1.getConceptConstructor)('ParamWithGroup');
420
- let param;
421
- if (!options) {
422
- param = ParamWithGroup.from({
423
- ...paramOptions,
424
- name: this.getParamUniqueName(),
425
- }, this, 'params');
426
- }
427
- else if (typeof options === 'string') {
428
- param = ParamWithGroup.from({
429
- ...paramOptions,
430
- name: options,
431
- }, this, 'params');
432
- }
433
- else if (asserts.isParamWithGroup(options)) {
434
- options.ensureDelete(); // 同一实例不支持多处存在
435
- param = options;
436
- Object.assign(param, relationOptions);
437
- }
438
- else {
439
- param = ParamWithGroup.from({
440
- ...paramOptions,
441
- ...options,
442
- }, this, 'params');
443
- }
444
- this.params.splice(index, 0, param);
445
- return param;
446
- }
447
- insertParamAt(options, index) {
448
- const node = this._insertParamAt(options, index);
449
- node.create({
450
- index,
451
- parentNode: this,
452
- parentKey: 'params',
453
- });
454
- return node;
455
- }
456
- _addParam(options) {
457
- const index = this.params.length;
458
- return this._insertParamAt(options, index);
459
- }
460
- addParam(options) {
461
- const node = this._addParam(options);
462
- const index = this.params.indexOf(node);
463
- node.create({
464
- index,
465
- parentNode: this,
466
- parentKey: 'params',
467
- });
468
- return node;
469
- }
470
- getVariableUniqueName(name = 'variable1') {
471
- return utils.unique(name, this.getVarExistingNames(), undefined, false);
472
- }
473
- _insertVariableAt(options, index) {
474
- const variableOptions = {};
475
- const relationOptions = { parentNode: this, parentKey: 'variables' };
476
- const Variable = (0, decorators_1.getConceptConstructor)('Variable');
477
- let variable;
478
- if (!options) {
479
- variable = Variable.from({
480
- ...variableOptions,
481
- name: this.getVariableUniqueName(),
482
- }, this, 'variables');
483
- }
484
- else if (typeof options === 'string') {
485
- variable = Variable.from({
486
- ...variableOptions,
487
- name: options,
488
- }, this, 'variables');
489
- }
490
- else if (asserts.isVariable(options)) {
491
- options.ensureDelete(); // 同一实例不支持多处存在
492
- variable = options;
493
- Object.assign(variable, relationOptions);
494
- }
495
- else {
496
- variable = Variable.from({
497
- ...variableOptions,
498
- ...options,
499
- }, this, 'variables');
500
- }
501
- this.variables.splice(index, 0, variable);
502
- return variable;
503
- }
504
- insertVariableAt(options, index) {
505
- const node = this._insertVariableAt(options, index);
506
- node.create({
507
- index,
508
- parentNode: this,
509
- parentKey: 'variables',
510
- });
511
- return node;
512
- }
513
- _addVariable(options) {
514
- const index = this.variables.length;
515
- return this._insertVariableAt(options, index);
516
- }
517
- addVariable(options) {
518
- const node = this._addVariable(options);
519
- const index = this.variables.indexOf(node);
520
- node.create({
521
- index,
522
- parentNode: this,
523
- parentKey: 'variables',
524
- });
525
- return node;
526
- }
527
- getBindEventExistingNames(excludedList = []) {
528
- const excludedSet = new Set(excludedList);
529
- return (this.bindEvents || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
530
- }
531
- getBindEventUniqueName(name = 'bindEvent1') {
532
- return utils.unique(name, this.getBindEventExistingNames(), undefined, false);
533
- }
534
- _insertBindEventAt(options, index) {
535
- const bindEventOptions = {};
536
- const relationOptions = { parentNode: this, parentKey: 'bindEvents' };
537
- const BindEvent = (0, decorators_1.getConceptConstructor)('BindEvent');
538
- let bindEvent;
539
- if (!options) {
540
- bindEvent = BindEvent.from({
541
- ...bindEventOptions,
542
- name: this.getBindEventUniqueName(),
543
- }, this, 'bindEvents');
544
- }
545
- else if (typeof options === 'string') {
546
- bindEvent = BindEvent.from({
547
- ...bindEventOptions,
548
- name: options,
549
- }, this, 'bindEvents');
550
- }
551
- else if (asserts.isBindEvent(options)) {
552
- options.ensureDelete(); // 同一实例不支持多处存在
553
- bindEvent = options;
554
- Object.assign(bindEvent, relationOptions);
555
- }
556
- else {
557
- bindEvent = BindEvent.from({
558
- ...bindEventOptions,
559
- ...options,
560
- }, this, 'bindEvents');
561
- }
562
- this.bindEvents.splice(index, 0, bindEvent);
563
- return bindEvent;
564
- }
565
- insertBindEventAt(options, index) {
566
- const node = this._insertBindEventAt(options, index);
567
- node.create({
568
- index,
569
- parentNode: this,
570
- parentKey: 'bindEvents',
571
- });
572
- return node;
573
- }
574
- _addBindEvent(options) {
575
- const index = this.bindEvents.length;
576
- return this._insertBindEventAt(options, index);
577
- }
578
- addBindEvent(options) {
579
- const node = this._addBindEvent(options);
580
- const index = this.bindEvents.indexOf(node);
581
- node.create({
582
- index,
583
- parentNode: this,
584
- parentKey: 'bindEvents',
585
- });
586
- return node;
587
- }
588
- getLogicExistingNames(excludedList = []) {
589
- const excludedSet = new Set(excludedList);
590
- return (this.logics || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
591
- }
592
- getLogicUniqueName(name = 'logic1') {
593
- return utils.unique(name, this.getLogicExistingNames(), undefined, false);
594
- }
595
- _insertLogicAt(options, index) {
596
- const logicOptions = {};
597
- const relationOptions = { parentNode: this, parentKey: 'logics' };
598
- const BusinessLogic = (0, decorators_1.getConceptConstructor)('BusinessLogic');
599
- let logic;
600
- if (!options) {
601
- logic = BusinessLogic.from({
602
- ...logicOptions,
603
- name: this.getLogicUniqueName(),
604
- }, this, 'logics');
605
- }
606
- else if (typeof options === 'string') {
607
- logic = BusinessLogic.from({
608
- ...logicOptions,
609
- name: options,
610
- }, this, 'logics');
611
- }
612
- else if (asserts.isBusinessLogic(options)) {
613
- options.ensureDelete(); // 同一实例不支持多处存在
614
- logic = options;
615
- Object.assign(logic, relationOptions);
616
- }
617
- else {
618
- logic = BusinessLogic.from({
619
- ...logicOptions,
620
- ...options,
621
- }, this, 'logics');
622
- }
623
- this.logics.splice(index, 0, logic);
624
- return logic;
625
- }
626
- insertLogicAt(options, index) {
627
- const node = this._insertLogicAt(options, index);
628
- node.create({
629
- index,
630
- parentNode: this,
631
- parentKey: 'logics',
632
- });
633
- return node;
634
- }
635
- _addLogic(options) {
636
- const index = this.logics.length;
637
- return this._insertLogicAt(options, index);
638
- }
639
- addLogic(options) {
640
- const node = this._addLogic(options);
641
- const index = this.logics.indexOf(node);
642
- node.create({
643
- index,
644
- parentNode: this,
645
- parentKey: 'logics',
646
- });
647
- return node;
648
- }
649
- _insertViewElementAt(options, index) {
650
- const viewElementOptions = {};
651
- const relationOptions = { parentNode: this, parentKey: 'elements' };
652
- const ViewElement = (0, decorators_1.getConceptConstructor)('ViewElement');
653
- let viewElement;
654
- if (!options) {
655
- viewElement = ViewElement.from({
656
- ...viewElementOptions,
657
- name: this.getViewElementUniqueName(),
658
- }, this, 'elements');
659
- }
660
- else if (typeof options === 'string') {
661
- viewElement = ViewElement.from({
662
- ...viewElementOptions,
663
- name: options,
664
- }, this, 'elements');
665
- }
666
- else if (asserts.isViewElement(options)) {
667
- options.ensureDelete(); // 同一实例不支持多处存在
668
- viewElement = options;
669
- Object.assign(viewElement, relationOptions);
670
- }
671
- else {
672
- viewElement = ViewElement.from({
673
- ...viewElementOptions,
674
- ...options,
675
- }, this, 'elements');
676
- }
677
- this.elements.splice(index, 0, viewElement);
678
- return viewElement;
679
- }
680
- insertViewElementAt(options, index) {
681
- const node = this._insertViewElementAt(options, index);
682
- node.create({
683
- index,
684
- parentNode: this,
685
- parentKey: 'elements',
686
- });
687
- return node;
688
- }
689
- _addViewElement(options) {
690
- const index = this.elements.length;
691
- return this._insertViewElementAt(options, index);
692
- }
693
- addViewElement(options) {
694
- const node = this._addViewElement(options);
695
- const index = this.elements.indexOf(node);
696
- node.create({
697
- index,
698
- parentNode: this,
699
- parentKey: 'elements',
700
- });
701
- return node;
702
- }
703
- removeEvent(options) {
704
- let event;
705
- if (typeof options === 'string') {
706
- event = this.events.find((item) => item.name === options);
707
- if (!event) {
708
- throw new Error('找不到组件事件 ' + options);
709
- }
710
- }
711
- else {
712
- event = options;
713
- }
714
- return event.delete();
715
- }
716
- __removeEvent(event) {
717
- const parentKey = event.parentKey;
718
- const params = {
719
- parentNode: this,
720
- parentKey,
721
- index: -1,
722
- object: null,
723
- oldObject: event,
724
- };
725
- if (parentKey) {
726
- params.parentKey = parentKey;
727
- // @ts-ignore
728
- const t = this.__v_raw || this;
729
- // @ts-ignore
730
- const n = event.__v_raw || event;
731
- if (Array.isArray(t[parentKey])) {
732
- // @ts-ignore
733
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
734
- ~index && this[parentKey].splice(index, 1);
735
- params.index = index;
736
- }
737
- else {
738
- const q = t[parentKey];
739
- if ((q.__v_raw || q) === n) {
740
- params.index = 0;
741
- this[parentKey] = undefined;
742
- }
743
- }
744
- }
745
- return params;
746
- }
747
- removeParam(options) {
748
- let param;
749
- if (typeof options === 'string') {
750
- param = this.params.find((item) => item.name === options);
751
- if (!param) {
752
- throw new Error('找不到参数分组 ' + options);
753
- }
754
- }
755
- else {
756
- param = options;
757
- }
758
- return param.delete();
759
- }
760
- __removeParam(param) {
761
- const parentKey = param.parentKey;
762
- const params = {
763
- parentNode: this,
764
- parentKey,
765
- index: -1,
766
- object: null,
767
- oldObject: param,
768
- };
769
- if (parentKey) {
770
- params.parentKey = parentKey;
771
- // @ts-ignore
772
- const t = this.__v_raw || this;
773
- // @ts-ignore
774
- const n = param.__v_raw || param;
775
- if (Array.isArray(t[parentKey])) {
776
- // @ts-ignore
777
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
778
- ~index && this[parentKey].splice(index, 1);
779
- params.index = index;
780
- }
781
- else {
782
- const q = t[parentKey];
783
- if ((q.__v_raw || q) === n) {
784
- params.index = 0;
785
- this[parentKey] = undefined;
786
- }
787
- }
788
- }
789
- return params;
790
- }
791
- removeVariable(options) {
792
- let variable;
793
- if (typeof options === 'string') {
794
- variable = this.variables.find((item) => item.name === options);
795
- if (!variable) {
796
- throw new Error('找不到变量 ' + options);
797
- }
798
- }
799
- else {
800
- variable = options;
801
- }
802
- return variable.delete();
803
- }
804
- __removeVariable(variable) {
805
- const parentKey = variable.parentKey;
806
- const params = {
807
- parentNode: this,
808
- parentKey,
809
- index: -1,
810
- object: null,
811
- oldObject: variable,
812
- };
813
- if (parentKey) {
814
- params.parentKey = parentKey;
815
- // @ts-ignore
816
- const t = this.__v_raw || this;
817
- // @ts-ignore
818
- const n = variable.__v_raw || variable;
819
- if (Array.isArray(t[parentKey])) {
820
- // @ts-ignore
821
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
822
- ~index && this[parentKey].splice(index, 1);
823
- params.index = index;
824
- }
825
- else {
826
- const q = t[parentKey];
827
- if ((q.__v_raw || q) === n) {
828
- params.index = 0;
829
- this[parentKey] = undefined;
830
- }
831
- }
832
- }
833
- return params;
834
- }
835
- removeBindEvent(options) {
836
- let bindEvent;
837
- if (typeof options === 'string') {
838
- bindEvent = this.bindEvents.find((item) => item.name === options);
839
- if (!bindEvent) {
840
- throw new Error('找不到元素绑定事件 ' + options);
841
- }
842
- }
843
- else {
844
- bindEvent = options;
845
- }
846
- return bindEvent.delete();
847
- }
848
- __removeBindEvent(bindEvent) {
849
- const parentKey = bindEvent.parentKey;
850
- const params = {
851
- parentNode: this,
852
- parentKey,
853
- index: -1,
854
- object: null,
855
- oldObject: bindEvent,
856
- };
857
- if (parentKey) {
858
- params.parentKey = parentKey;
859
- // @ts-ignore
860
- const t = this.__v_raw || this;
861
- // @ts-ignore
862
- const n = bindEvent.__v_raw || bindEvent;
863
- if (Array.isArray(t[parentKey])) {
864
- // @ts-ignore
865
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
866
- ~index && this[parentKey].splice(index, 1);
867
- params.index = index;
868
- }
869
- else {
870
- const q = t[parentKey];
871
- if ((q.__v_raw || q) === n) {
872
- params.index = 0;
873
- this[parentKey] = undefined;
874
- }
875
- }
876
- }
877
- return params;
878
- }
879
- removeLogic(options) {
880
- let logic;
881
- if (typeof options === 'string') {
882
- logic = this.logics.find((item) => item.name === options);
883
- if (!logic) {
884
- throw new Error('找不到业务组件逻辑 ' + options);
885
- }
886
- }
887
- else {
888
- logic = options;
889
- }
890
- return logic.delete();
891
- }
892
- __removeLogic(logic) {
893
- const parentKey = logic.parentKey;
894
- const params = {
895
- parentNode: this,
896
- parentKey,
897
- index: -1,
898
- object: null,
899
- oldObject: logic,
900
- };
901
- if (parentKey) {
902
- params.parentKey = parentKey;
903
- // @ts-ignore
904
- const t = this.__v_raw || this;
905
- // @ts-ignore
906
- const n = logic.__v_raw || logic;
907
- if (Array.isArray(t[parentKey])) {
908
- // @ts-ignore
909
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
910
- ~index && this[parentKey].splice(index, 1);
911
- params.index = index;
912
- }
913
- else {
914
- const q = t[parentKey];
915
- if ((q.__v_raw || q) === n) {
916
- params.index = 0;
917
- this[parentKey] = undefined;
918
- }
919
- }
920
- }
921
- return params;
922
- }
923
- removeViewElement(options) {
924
- let viewElement;
925
- if (typeof options === 'string') {
926
- viewElement = this.elements.find((item) => item.name === options);
927
- if (!viewElement) {
928
- throw new Error('找不到页面元素 ' + options);
929
- }
930
- }
931
- else {
932
- viewElement = options;
933
- }
934
- return viewElement.delete();
935
- }
936
- __removeViewElement(viewElement) {
937
- const parentKey = viewElement.parentKey;
938
- const params = {
939
- parentNode: this,
940
- parentKey,
941
- index: -1,
942
- object: null,
943
- oldObject: viewElement,
944
- };
945
- if (parentKey) {
946
- params.parentKey = parentKey;
947
- // @ts-ignore
948
- const t = this.__v_raw || this;
949
- // @ts-ignore
950
- const n = viewElement.__v_raw || viewElement;
951
- if (Array.isArray(t[parentKey])) {
952
- // @ts-ignore
953
- const index = t[parentKey].findIndex((el) => (el.__v_raw || el) === n);
954
- ~index && this[parentKey].splice(index, 1);
955
- params.index = index;
956
- }
957
- else {
958
- const q = t[parentKey];
959
- if ((q.__v_raw || q) === n) {
960
- params.index = 0;
961
- this[parentKey] = undefined;
962
- }
963
- }
964
- }
965
- return params;
966
- }
967
- //================================================================================
968
- // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
969
- // 自动生成的代码已结束。下面可以手动编写。
970
- //================================================================================
971
- static getDefaultOptions() {
972
- return {
973
- title: '业务组件',
974
- };
975
- }
976
- getNamespace() {
977
- if (this.parentNode && this.parentNode.getNamespace) {
978
- const parentNamespace = this.parentNode.getNamespace();
979
- const parentName = this.parentNode.name;
980
- const arr = [parentNamespace];
981
- if (this.parentNode.concept !== 'App' && parentName) {
982
- arr.push(parentName);
983
- }
984
- return `${arr.join('.')}.businessComponents`;
985
- }
986
- throw new Error('无法获取命名空间,请设置 parentNode!');
987
- }
988
- getTsNamespace() {
989
- const parentNodeNamespace = this.getNamespace();
990
- let tsCalleeNamespace = parentNodeNamespace.replace(/\.[0-9]/g, (m) => m.replace('.', '.$'));
991
- tsCalleeNamespace = tsCalleeNamespace.replace(/-/g, '_');
992
- return tsCalleeNamespace;
993
- }
994
- getElementLogicRoot() {
995
- const Param = (0, decorators_1.getConceptConstructor)('Param');
996
- const logics = [];
997
- // 页面上的绑定的事件
998
- this.bindEvents.forEach((bindEvent) => {
999
- bindEvent.logics.forEach((logic) => {
1000
- // 键盘事件
1001
- if (['keydown', 'keyup'].includes(bindEvent.name)) {
1002
- logic.virtualParams = [
1003
- Param.from({
1004
- name: 'event',
1005
- typeAnnotation: null,
1006
- }, logic, 'virtualParams'),
1007
- ];
1008
- }
1009
- // 生命周期没有event
1010
- logics.push(logic);
1011
- });
1012
- });
1013
- this.elements.forEach((item) => {
1014
- utils.traverse((current) => {
1015
- current.node.bindEvents.forEach((bindEvent) => {
1016
- bindEvent.logics.forEach((logic) => {
1017
- if (logic.name.startsWith('__')) {
1018
- return;
1019
- }
1020
- // 绑定参数才有 event 的 current
1021
- logic.virtualParams = bindEvent.getContextRenderLogicParams(logic);
1022
- logics.push(logic);
1023
- });
1024
- });
1025
- }, { node: item });
1026
- });
1027
- if (logics.length) {
1028
- const expanded = (this.elementLogicRoot.length && this.elementLogicRoot[0].expanded) || false;
1029
- this.elementLogicRoot = [
1030
- {
1031
- concept: 'elementLogicRoot',
1032
- expanded,
1033
- children: logics,
1034
- },
1035
- ];
1036
- }
1037
- else {
1038
- this.elementLogicRoot = [];
1039
- }
1040
- }
1041
- getVarExistingNames(excludedList = []) {
1042
- const excludedSet = new Set(excludedList);
1043
- const varList = [];
1044
- if (Array.isArray(this.params)) {
1045
- varList.push(...this.params);
1046
- }
1047
- if (Array.isArray(this.variables)) {
1048
- varList.push(...this.variables);
1049
- }
1050
- if (Array.isArray(this.logics)) {
1051
- this.logics.forEach((logic) => {
1052
- varList.push(logic);
1053
- if (Array.isArray(logic.params)) {
1054
- varList.push(...logic.params);
1055
- }
1056
- if (Array.isArray(logic.returns)) {
1057
- varList.push(...logic.returns);
1058
- }
1059
- if (Array.isArray(logic.variables)) {
1060
- varList.push(...logic.variables);
1061
- }
1062
- });
1063
- }
1064
- // 事件逻辑的变量不允许和页面逻辑下的重复
1065
- if (Array.isArray(this.elementLogicRoot) && this.elementLogicRoot.length) {
1066
- this.elementLogicRoot[0]?.children.forEach((logic) => {
1067
- if (Array.isArray(logic.variables)) {
1068
- varList.push(...logic.variables);
1069
- }
1070
- });
1071
- }
1072
- return varList.filter((item) => !excludedSet.has(item)).map((item) => item.name);
1073
- }
1074
- // 收集已经存在的ViewElement
1075
- collectExistingViewElementName(excludedList = []) {
1076
- const excludedSet = new Set(excludedList);
1077
- this.elements.forEach((element) => {
1078
- utils.traverse(({ node }) => {
1079
- if (!excludedSet.has(node)) {
1080
- this.existingViewElement.add(node.name);
1081
- }
1082
- }, {
1083
- node: element,
1084
- });
1085
- });
1086
- }
1087
- // 获取当前业务组件的所有组件的名字
1088
- getViewElementExistingNames(excludedList = []) {
1089
- if (!this.existingViewElement.size) {
1090
- this.collectExistingViewElementName();
1091
- }
1092
- return Array.from(this.existingViewElement);
1093
- }
1094
- getViewElementUniqueNameOld(name = 'viewElement1') {
1095
- this.collectExistingViewElementName();
1096
- const viewElementUniqueName = utils.unique(name, this.existingViewElement);
1097
- this.existingViewElement.add(viewElementUniqueName);
1098
- return viewElementUniqueName;
1099
- }
1100
- getViewElementUniqueName(name = 'viewElement_1') {
1101
- this.collectExistingViewElementName();
1102
- const BranchCopyUniCode = getBranchCopyUniCode();
1103
- let newName = name;
1104
- const prefix = name.replace(/\d*$/, '');
1105
- if (BranchCopyUniCode && prefix.indexOf(`_${BranchCopyUniCode}_`) === -1) {
1106
- newName = name.replace(/\d*$/, (m) => `_${BranchCopyUniCode}_${m}`);
1107
- }
1108
- // 主分支无 BranchCopyUniCode
1109
- if (!BranchCopyUniCode && prefix.at(-1) !== '_') {
1110
- newName = name.replace(/\d*$/, (m) => `_${m}`);
1111
- }
1112
- const newPrefix = newName.replace(/\d*$/, '');
1113
- const newPrefixNum = removedViewElementCache?.[newPrefix] ? removedViewElementCache[newPrefix] : 1;
1114
- const startNum = newPrefixNum < Number.MAX_SAFE_INTEGER ? newPrefixNum + 1 : BigInt(newPrefixNum) + BigInt(1);
1115
- const viewElementUniqueName = utils.uniqueMax(newName, this.existingViewElement, removedViewElementCache?.[newPrefix] ? startNum : newPrefixNum);
1116
- this.existingViewElement.add(viewElementUniqueName);
1117
- return viewElementUniqueName;
1118
- }
1119
- // 获取当前element,铺平
1120
- elementsMethods(elements, allMethods, parentNodeNames) {
1121
- if (elements) {
1122
- elements.forEach((item) => {
1123
- const { bindAttrs = [], name } = item;
1124
- const isDataSource = bindAttrs.some((attr) => attr.name === 'data-source');
1125
- const isInclude = parentNodeNames.includes(name);
1126
- allMethods.push(item);
1127
- if (item.children) {
1128
- if (isDataSource) {
1129
- if (isInclude) {
1130
- this.elementsMethods(item.children, allMethods, parentNodeNames);
1131
- }
1132
- }
1133
- else {
1134
- this.elementsMethods(item.children, allMethods, parentNodeNames);
1135
- }
1136
- }
1137
- });
1138
- }
1139
- }
1140
- mergeBlock({ code, nodePath, position, cb }) {
1141
- const ViewElement = (0, decorators_1.getConceptConstructor)('ViewElement');
1142
- const Logic = (0, decorators_1.getConceptConstructor)('Logic');
1143
- const ParamWithGroup = (0, decorators_1.getConceptConstructor)('ParamWithGroup');
1144
- const Variable = (0, decorators_1.getConceptConstructor)('Variable');
1145
- const BindEvent = (0, decorators_1.getConceptConstructor)('BindEvent');
1146
- const Structure = (0, decorators_1.getConceptConstructor)('Structure');
1147
- const template = utils.sliceTagContent(code, 'template');
1148
- let targetNode = this.getAncestor('App')?.findNodeByPath(nodePath);
1149
- let parentNode = position === 'append' ? targetNode : targetNode.parentNode;
1150
- const definitionStr = utils.sliceTagContent(code, 'definition') || '{}';
1151
- const definition = JSON.parse(definitionStr);
1152
- let node = null;
1153
- if (template) {
1154
- node = ViewElement.fromHTML(template, {
1155
- view: this,
1156
- definition,
1157
- });
1158
- if (!parentNode) {
1159
- return;
1160
- }
1161
- if (position === 'append') {
1162
- parentNode.addViewElement(node);
1163
- cb && cb(parentNode, node);
1164
- }
1165
- else {
1166
- const index = targetNode.getIndexOfParent();
1167
- if (position === 'insertBefore') {
1168
- parentNode.insertViewElementAt(node, index);
1169
- }
1170
- else if (position === 'insertAfter') {
1171
- parentNode.insertViewElementAt(node, index + 1);
1172
- }
1173
- }
1174
- }
1175
- // 服务端逻辑
1176
- if (Array.isArray(definition.logics)) {
1177
- definition.logics.forEach((logicOption) => {
1178
- const logic = Logic.from({
1179
- ...logicOption,
1180
- }, this.rootNode, 'logics');
1181
- this.rootNode.addLogic(logic);
1182
- });
1183
- }
1184
- // 全局结构体
1185
- if (Array.isArray(definition.structures)) {
1186
- definition.structures.forEach((structureOption) => {
1187
- const structure = Structure.from({
1188
- ...structureOption,
1189
- }, this.rootNode, 'structures');
1190
- this.rootNode.addStructure(structure);
1191
- });
1192
- }
1193
- // 页面入参
1194
- if (Array.isArray(definition.viewParams)) {
1195
- definition.viewParams.forEach((paramsOption) => {
1196
- const param = ParamWithGroup.from({
1197
- ...paramsOption,
1198
- }, this, 'params');
1199
- this._addParam(param);
1200
- param.addParamsPrepare();
1201
- });
1202
- }
1203
- // 页面变量
1204
- if (Array.isArray(definition.viewVariables)) {
1205
- definition.viewVariables.forEach((variableOption) => {
1206
- const variable = Variable.from({
1207
- ...variableOption,
1208
- }, this, 'variables');
1209
- this.addVariable(variable);
1210
- });
1211
- }
1212
- // 页面事件
1213
- if (Array.isArray(definition.viewBindEvents)) {
1214
- definition.viewBindEvents.forEach((eventOption) => {
1215
- const newLogic = definition.viewLogics.find((logic) => eventOption.calleeName === logic.name);
1216
- const bindEvent = this.bindEvents.find((currentEventItem) => currentEventItem.name === eventOption.name);
1217
- // 如果没有event对象就先新增一个,如果已经有了就在内部添加logic
1218
- if (!bindEvent) {
1219
- const event = BindEvent.from({
1220
- ...eventOption,
1221
- calleeName: '',
1222
- logics: [newLogic],
1223
- }, this, 'events');
1224
- this.addBindEvent(event);
1225
- }
1226
- else {
1227
- bindEvent.addLogic(newLogic);
1228
- }
1229
- });
1230
- }
1231
- return node;
1232
- }
1233
- onChange($event) {
1234
- this.emit('change', $event);
1235
- }
1236
- /**
1237
- * 转换成设计器中使用的 Vue template 内容
1238
- * @param options
1239
- */
1240
- genDesignerVueTemplate(options) {
1241
- return this.elements
1242
- .map((element) => `${element.toDesignerVue({
1243
- isRoot: true,
1244
- asCompontent: options?.asCompontent,
1245
- })}\n`)
1246
- .join('');
1247
- }
1248
- get frontendType() {
1249
- return this.getAncestor('FrontendType');
1250
- }
1251
- get path() {
1252
- return `/${this.frontendType?.kind}/${this.name}`;
1253
- }
1254
- get slotElems() {
1255
- const slotElems = [];
1256
- this.elements.forEach((element) => {
1257
- utils.traverse(({ node }) => {
1258
- if (node.tag === 'slot') {
1259
- slotElems.push(node);
1260
- }
1261
- }, {
1262
- node: element,
1263
- });
1264
- });
1265
- return slotElems;
1266
- }
1267
- /**
1268
- * 转换成 Vue 文件
1269
- */
1270
- toVue(options) {
1271
- let result = '';
1272
- result += `<template>\n${this.genVueTemplate(options)}\n</template>\n`;
1273
- result += `<script>\n${this.genScript()}\n</script>\n`;
1274
- return result;
1275
- }
1276
- /**
1277
- * 生成宿主语言的文件路径
1278
- * @param name 一般不用传,用于 rename
1279
- */
1280
- getEmbeddedFilePath(name = this.name) {
1281
- return `/embedded/${this.rootNode?.name || this.parentNode.name}/frontendTypes/${this.getAncestor('FrontendType')?.name}/${name}.ts`;
1282
- }
1283
- *toEmbeddedTSFile() {
1284
- let code = `namespace ${this.getTsNamespace()} {\n`;
1285
- const state = (0, translator_1.createCompilerState)(code, {
1286
- tabSize: 1,
1287
- });
1288
- try {
1289
- code += yield* this.toEmbeddedTS(state);
1290
- }
1291
- catch (err) {
1292
- code += '';
1293
- console.log(err);
1294
- }
1295
- code += '}\n';
1296
- return {
1297
- code,
1298
- filePath: this.getEmbeddedFilePath(),
1299
- sourceMap: state.sourceMap,
1300
- };
1301
- }
1302
- getAncestorViewElementsWithDataSource(logic) {
1303
- let element = logic;
1304
- const viewElements = [];
1305
- while (element) {
1306
- if (element.concept &&
1307
- element.concept === 'ViewElement' &&
1308
- element.bindAttrs.find((bAttr) => bAttr.name === 'data-source')) {
1309
- viewElements.push(element);
1310
- }
1311
- element = element.parentNode;
1312
- }
1313
- return viewElements;
1314
- }
1315
- *handleCurrentItemCode(code, logic) {
1316
- const viewElementsWithDataSource = this.getAncestorViewElementsWithDataSource(logic);
1317
- yield* (0, time_slicing_1.wrapForEachToGenerator)(viewElementsWithDataSource, function* wrapForEach(viewElement, index) {
1318
- const currentIndex = viewElementsWithDataSource.length - 1 - index;
1319
- const currentItemCode = `current${currentIndex === 0 ? '' : currentIndex}.item`;
1320
- if (code.includes(currentItemCode)) {
1321
- const dataSource = viewElement.bindAttrs.find((bAttr) => bAttr.name === 'data-source');
1322
- if (dataSource) {
1323
- const businessComponent = viewElement.getAncestor('BusinessComponent');
1324
- const dataSourceTS = yield* dataSource.expression.toEmbeddedTS();
1325
- const logic = businessComponent.logics.find((logic) => logic.name === dataSourceTS);
1326
- if (logic) {
1327
- code = code.replaceAll(currentItemCode, `nasl.ui.getCurrentItemType(${dataSourceTS}(${logic.params.map(() => 'null').join(',')}))`);
1328
- }
1329
- else {
1330
- const variable = businessComponent.variables.find((variable) => variable.name === dataSourceTS);
1331
- code = code.replaceAll(currentItemCode, `nasl.ui.getCurrentItemType(${variable ? variable.name : dataSourceTS})`);
1332
- }
1333
- }
1334
- }
1335
- });
1336
- return code;
1337
- }
1338
- removeExistingViewElement(viewElement) {
1339
- if (this.existingViewElement.has(viewElement.name)) {
1340
- this.existingViewElement.delete(viewElement.name);
1341
- }
1342
- const prefix = viewElement?.name.replace(/\d*$/, '');
1343
- let lastDigit = viewElement?.name.match(/\d+$/)?.[0];
1344
- if (lastDigit === undefined)
1345
- return;
1346
- //@ts-ignore
1347
- lastDigit = lastDigit < Number.MAX_SAFE_INTEGER ? parseInt(lastDigit) : BigInt(lastDigit);
1348
- if (removedViewElementCache?.[prefix]) {
1349
- //@ts-ignore
1350
- if (lastDigit > removedViewElementCache[prefix])
1351
- //@ts-ignore
1352
- removedViewElementCache[prefix] = lastDigit;
1353
- }
1354
- else {
1355
- //@ts-ignore
1356
- removedViewElementCache[prefix] = lastDigit;
1357
- }
1358
- }
1359
- *getRightCode(code, assignment, rightNode) {
1360
- code = code.replaceAll('\n', ' ');
1361
- const logic = assignment.logic;
1362
- const logicRtn = logic?.returns[0];
1363
- // 调用接口,参数替换成 null
1364
- if (asserts.isCallInterface(rightNode)) {
1365
- const { _interface } = rightNode.getModuleInterface();
1366
- return _interface
1367
- ? `${rightNode.tsCalleeKey}(${_interface.params.map(() => 'null').join(',')})`
1368
- : null;
1369
- }
1370
- // 调用服务端逻辑,参数替换成 null
1371
- if (asserts.isCallLogic(rightNode) && rightNode.calleeNamespace === 'app.logics') {
1372
- const calleeName = rightNode?.calleeName;
1373
- const calleeLogic = this.getAncestor('App').logics.find((l) => l.name === calleeName);
1374
- return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
1375
- }
1376
- // view 局部变量,申明提升前增加判断,使用 logic 内的 result 直接替换成对应 logic,logic 内部变量替换成 null
1377
- if (logicRtn && code.includes(logicRtn.name)) {
1378
- if (code === logicRtn.name)
1379
- return `${logic.name}(${logic.params.map(() => 'null').join(',')})`;
1380
- code = this.handleReplaceCode(code, logicRtn.name, `${logic.name}(${logic.params.map(() => 'null').join(',')})`);
1381
- logic.params.forEach((param) => {
1382
- if (code.includes(param.name))
1383
- code = this.handleReplaceCode(code, param.name, 'null');
1384
- });
1385
- logic.variables.forEach((variable) => {
1386
- if (code.includes(variable.name))
1387
- code = this.handleReplaceCode(code, variable.name, 'null');
1388
- });
1389
- return code;
1390
- }
1391
- // 处理 current.item、current1.item 等数据
1392
- if (/current(\d)*\.item/.test(code)) {
1393
- code = yield* this.handleCurrentItemCode(code, logic);
1394
- return code;
1395
- }
1396
- // 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
1397
- const useLogicVar = logic.params.find((param) => code.includes(param.name)) ||
1398
- logic.variables.find((variable) => code.includes(variable.name));
1399
- return useLogicVar ? 'null' : code;
1400
- }
1401
- handleReplaceCode(code, variable, replaceCode) {
1402
- return code.replace(/\S+/g, ($1) => {
1403
- if ($1 === `${variable},`)
1404
- return `${replaceCode},`;
1405
- if ($1 === variable)
1406
- return replaceCode;
1407
- let fnCode = $1;
1408
- if ($1.startsWith(`${variable}.`))
1409
- fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
1410
- if ($1.startsWith(`${variable},`))
1411
- fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
1412
- if ($1.includes(`(${variable},`))
1413
- fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
1414
- if ($1.includes(`(${variable}.`))
1415
- fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
1416
- if ($1.includes(`(${variable})`))
1417
- fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
1418
- if ($1.includes(`,${variable},`))
1419
- fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
1420
- if ($1.includes(`,${variable}.`))
1421
- fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
1422
- if ($1.includes(`,${variable})`))
1423
- fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
1424
- return fnCode;
1425
- });
1426
- }
1427
- // 获取当前element,铺平
1428
- elementsAttrs(elements, componentList) {
1429
- if (elements) {
1430
- elements.forEach((item) => {
1431
- if (PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
1432
- componentList.push(item);
1433
- }
1434
- if (item.children.length > 0) {
1435
- this.elementsAttrs(item.children, componentList);
1436
- }
1437
- });
1438
- }
1439
- }
1440
- elementsAttrsAll(elements, componentListExtra) {
1441
- if (elements) {
1442
- elements.forEach((item) => {
1443
- if (!PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
1444
- componentListExtra.push(item);
1445
- }
1446
- if (item.children.length > 0) {
1447
- this.elementsAttrsAll(item.children, componentListExtra);
1448
- }
1449
- });
1450
- }
1451
- }
1452
- *toEmbeddedTS(state = (0, translator_1.createCompilerState)()) {
1453
- const self = this;
1454
- // 获取虚拟logic的参数和内容
1455
- // 用作展示和tots查找引用
1456
- self.getElementLogicRoot();
1457
- let code = `export class ${self.tsName} extends nasl.ui.VueComponent {\n`;
1458
- // 需要类型推导的局部变量/返回值需要调整申明顺序
1459
- code += `constructor(
1460
- options?: {
1461
- [propname: string]: any,
1462
- bindAttr?: {
1463
- __NASLIF?: nasl.core.Boolean,
1464
- `;
1465
- if (Array.isArray(self.params)) {
1466
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.params, function* warpForEachGenerator(param, index) {
1467
- code += `${param.name}?: `;
1468
- code += yield* param.typeAnnotation.toEmbeddedTS((0, translator_1.shiftState)(state, code));
1469
- code += ',\n';
1470
- });
1471
- }
1472
- code += `
1473
- },
1474
- slotDefault?: () => Array<any>,
1475
- }) {
1476
- super();\n`;
1477
- // 绑定事件
1478
- if (Array.isArray(self.bindEvents)) {
1479
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.bindEvents, function* warpForEachGenerator(event) {
1480
- code += yield* event.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1481
- tabSize: state?.tabSize || 0,
1482
- }), true);
1483
- code += '\n';
1484
- });
1485
- }
1486
- code += `\n}`;
1487
- // 自定义事件的定义
1488
- if (Array.isArray(self.events) && self.events.length) {
1489
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1490
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.events, function* warpForEachGenerator(event) {
1491
- code += yield* event.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1492
- tabSize: (state?.tabSize || 0) + 2,
1493
- }));
1494
- code += '\n';
1495
- });
1496
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1497
- }
1498
- // 逻辑
1499
- if (Array.isArray(self.logics) && self.logics.length) {
1500
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1501
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.logics, function* warpForEachGenerator(logic) {
1502
- code += yield* logic.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1503
- tabSize: (state?.tabSize || 0) + 2,
1504
- }), 'noExport');
1505
- code += '\n';
1506
- });
1507
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1508
- }
1509
- // render函数
1510
- code += `\n${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
1511
- code += `__render(`;
1512
- code += `){\n`;
1513
- code += (0, translator_1.indent)(state?.tabSize || 0);
1514
- // elements 元素
1515
- if (Array.isArray(self.elements)) {
1516
- // 生成嵌套式的内容
1517
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.elements, function* warpForEachGenerator(element) {
1518
- code += yield* element.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1519
- tabSize: (state?.tabSize || 0) + 3,
1520
- }));
1521
- code += '\n';
1522
- });
1523
- }
1524
- code += `\n${(0, translator_1.indent)((state?.tabSize || 0) + 1)}}\n`;
1525
- if (Array.isArray(self.params)) {
1526
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}$destination(options: {`;
1527
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.params, function* warpForEachGenerator(param, index) {
1528
- code += `${param.name}?: `;
1529
- code += yield* param.typeAnnotation.toEmbeddedTS((0, translator_1.shiftState)(state, code));
1530
- code += ', ';
1531
- });
1532
- // 锚点
1533
- code += `_anchor?: nasl.core.String`;
1534
- code += '}){}\n';
1535
- }
1536
- code += `${(0, translator_1.indent)(state?.tabSize || 0)}}\n`;
1537
- // elements类型声明定义
1538
- code += `interface __elements {\n`;
1539
- // 生成所有的name和类型定义
1540
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.elements, function* warpForEachGenerator(element) {
1541
- code += yield* element.toEmbeddedTSDefinition((0, translator_1.shiftState)(state, code, {
1542
- tabSize: (state?.tabSize || 0) + 1,
1543
- }));
1544
- });
1545
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}}\n`;
1546
- code += `let __elements: __elements;\n`;
1547
- if (Array.isArray(self.elements)) {
1548
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}interface `;
1549
- code += `__elements_completionProperty {\n`;
1550
- const componentList = [];
1551
- self.elementsAttrs(self.elements, componentList);
1552
- const variableList = [];
1553
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.elements, function* warpForEachGenerator(item) {
1554
- code += yield* item.toEmbeddedTSVariableDefinition((0, translator_1.shiftState)(state, code, { inline: true }), variableList);
1555
- });
1556
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + `}\n`;
1557
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1558
- code += `let __elements_completionProperty: __elements_completionProperty;\n`;
1559
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1560
- code += `let __elements_variable_function = {\n`;
1561
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.elements, function* warpForEachGenerator(item) {
1562
- code += yield* item.toEmbeddedTSVariableFunctionDefinition((0, translator_1.shiftState)(state, code, { inline: true }));
1563
- });
1564
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + `}\n`;
1565
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1566
- code += `let __elements_stashFunctionVariable = {\n`;
1567
- yield* (0, time_slicing_1.wrapForEachToGenerator)(variableList, function* warpForEachGenerator(item) {
1568
- code += (0, translator_1.indent)((state?.tabSize || 0) + 2);
1569
- code += `${item}`;
1570
- });
1571
- code += (0, translator_1.indent)((state?.tabSize || 0) + 1) + `}\n`;
1572
- }
1573
- const advanceMap = new Map();
1574
- yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
1575
- if (el && (asserts.isBatchAssignment(el) || (asserts.isAssignment(el) && el.left?.name))) {
1576
- if (asserts.isAssignment(el)) {
1577
- const advanceVar = self.variables?.find((variable) => !variable.typeAnnotation && el.left?.name === variable.name);
1578
- if (advanceVar && !advanceMap.get(advanceVar)) {
1579
- advanceMap.set(advanceVar, el);
1580
- }
1581
- }
1582
- else if (asserts.isBatchAssignment(el)) {
1583
- yield* (0, time_slicing_1.wrapForEachToGenerator)(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
1584
- const leftCode = leftIndex.length === 1
1585
- ? yield* el.left?.expression?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
1586
- (0, time_slicing_1.returnOrigin)('')
1587
- : yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
1588
- (0, time_slicing_1.returnOrigin)('');
1589
- const advanceVar = self.variables?.find((variable) => !variable.typeAnnotation && leftCode === variable.name);
1590
- if (advanceVar && !advanceMap.get(advanceVar)) {
1591
- advanceMap.set(advanceVar, el);
1592
- }
1593
- });
1594
- }
1595
- }
1596
- });
1597
- // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
1598
- const IDENTIFIERMAP = new Set();
1599
- if (Array.isArray(self.params)) {
1600
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.params, function* warpForEachGenerator(param) {
1601
- code += `let ${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
1602
- code += yield* param.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
1603
- code += ';\n';
1604
- });
1605
- }
1606
- if (Array.isArray(self.variables)) {
1607
- yield* (0, time_slicing_1.wrapForEachToGenerator)(self.variables, function* warpForEachGenerator(variable) {
1608
- const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? (0, time_slicing_1.returnOrigin)('');
1609
- if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
1610
- IDENTIFIERMAP.add(variable);
1611
- }
1612
- if (!advanceMap.get(variable)) {
1613
- code += `let ${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
1614
- code += yield* variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
1615
- code += ';\n';
1616
- }
1617
- });
1618
- }
1619
- yield* (0, time_slicing_1.wrapIteratorToGenerator)(advanceMap.entries(), function* warpForEachGenerator([variable, assignment]) {
1620
- // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
1621
- if (variable.defaultValue?.expression && !IDENTIFIERMAP.has(variable)) {
1622
- code += `let ${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
1623
- code += yield* variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
1624
- return;
1625
- }
1626
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
1627
- code += `let ${(0, translator_1.indent)((state?.tabSize || 0) + 1)}`;
1628
- code += yield* variable.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
1629
- code += ' = ';
1630
- if (asserts.isBatchAssignment(assignment)) {
1631
- yield* (0, time_slicing_1.wrapForEachToGenerator)(assignment.assignmentLines, function* warpForEachGenerator({ leftIndex, rightIndex }) {
1632
- const leftCode = leftIndex.length === 1
1633
- ? yield* assignment.left.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))
1634
- : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
1635
- (0, time_slicing_1.returnOrigin)('');
1636
- if (leftCode === variable.name) {
1637
- const rightNode = rightIndex.length === 1
1638
- ? assignment.rights[rightIndex[0]]?.expression
1639
- : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
1640
- const rightCode = yield* rightNode?.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true })) ??
1641
- (0, time_slicing_1.returnOrigin)('');
1642
- code += yield* self.getRightCode(rightCode, assignment, rightNode);
1643
- }
1644
- });
1645
- }
1646
- else {
1647
- let rightCode = '';
1648
- // 因为右侧枚举要赋值就得new 一下;
1649
- if (assignment.right &&
1650
- asserts.isIdentifier(assignment.right) &&
1651
- assignment.right.namespace &&
1652
- assignment.right.namespace.endsWith('enums')) {
1653
- rightCode += 'new ';
1654
- }
1655
- rightCode +=
1656
- assignment.right && assignment.right.toEmbeddedTS
1657
- ? yield* assignment.right.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }))
1658
- : '__RIGHT__';
1659
- code += yield* self.getRightCode(rightCode, assignment, assignment.right);
1660
- }
1661
- code += ';\n';
1662
- });
1663
- /* 默认值草稿区 ---------------------------*/
1664
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}function __playground(){\n`;
1665
- /* 参数的默认值是__IDENTIFIER__或者__IDENTIFIER__()时不赋默认值,但是需要ts翻译出来进行报错校验 */
1666
- for (const node of IDENTIFIERMAP.values()) {
1667
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 2)}`;
1668
- code += yield* node.defaultValue.toEmbeddedTS((0, translator_1.shiftState)(state, code, { inline: true }));
1669
- code += '; ';
1670
- }
1671
- code += '\n';
1672
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 2)}return\n`;
1673
- function* setPlaygroundCode(arr, name) {
1674
- if (arr.length) {
1675
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
1676
- }
1677
- for (const item1 of arr) {
1678
- for (const item of item1.defaultValue?.playground ?? []) {
1679
- code += yield* item.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1680
- code += ';\n';
1681
- }
1682
- }
1683
- }
1684
- yield* setPlaygroundCode(self.variables, 'variables');
1685
- yield* setPlaygroundCode(self.params, 'params');
1686
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 1)}}\n`;
1687
- return code;
1688
- }
1689
- /**
1690
- * 转换成 VueOptions
1691
- * @TODO 后面 template 可以优化成 render 函数
1692
- */
1693
- toVueOptions(options) {
1694
- return {
1695
- template: this.genVueTemplate(options),
1696
- script: this.genScript(),
1697
- };
1698
- }
1699
- genVueTemplate(options) {
1700
- return this.elements?.map((element) => `${element?.toVue(options)}\n`).join('');
1701
- }
1702
- getViewBindEvents() {
1703
- const bindEvents = [];
1704
- // 页面上的绑定的事件
1705
- this.bindEvents.forEach((bindEvent) => {
1706
- bindEvents.push(bindEvent);
1707
- });
1708
- this.elements.forEach((item) => {
1709
- utils.traverse((current) => {
1710
- current.node.bindEvents.forEach((bindEvent) => {
1711
- bindEvents.push(bindEvent);
1712
- });
1713
- }, { node: item });
1714
- });
1715
- return bindEvents;
1716
- }
1717
- // 获取页面上需要替换的表达式
1718
- getViewExpressions() {
1719
- const bindExpressions = [];
1720
- this.elements.forEach((item) => {
1721
- utils.traverse((current) => {
1722
- const { node } = current;
1723
- const playgroundNodePath = (node?.nodePath || '').split('.').find((nodePathNode) => {
1724
- return nodePathNode.match(/(.+)\[.+\]/)?.[1] === 'playground';
1725
- });
1726
- if (!playgroundNodePath) {
1727
- //// 处理三种情况
1728
- //if (
1729
- // ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
1730
- // && node.needReplaceWithIdentifier
1731
- //) {
1732
- // bindExpressions.push(node);
1733
- //}
1734
- if (node?.concept === 'Match') {
1735
- bindExpressions.push(node);
1736
- }
1737
- }
1738
- }, {
1739
- node: item,
1740
- }, {
1741
- mode: 'anyObject',
1742
- depthFirst: true,
1743
- excludedKeySet: new Set([
1744
- 'bindEvents',
1745
- 'parentNode',
1746
- 'sourceMap',
1747
- 'storageJSON',
1748
- 'tsErrorDetail',
1749
- 'NaslAnnotatedJSON',
1750
- 'calledFrom',
1751
- '_events',
1752
- '_collectingList',
1753
- '_historyList',
1754
- ]),
1755
- });
1756
- });
1757
- return bindExpressions;
1758
- }
1759
- /**
1760
- * 生成 Vue 中需要的 JS 代码
1761
- * @TODO 这一版先做成 componentOptions 式的,后面再美化
1762
- */
1763
- genScript() {
1764
- const componentList = [];
1765
- const componentListExtra = [];
1766
- this.elementsAttrs(this.elements, componentList);
1767
- this.elementsAttrsAll(this.elements, componentListExtra);
1768
- const definition = {
1769
- params: this.params,
1770
- variables: this.variables,
1771
- logics: this.logics,
1772
- events: this.bindEvents,
1773
- title: this.title,
1774
- viewBindEvents: this.getViewBindEvents(),
1775
- viewExpressions: this.getViewExpressions(),
1776
- elements: componentList,
1777
- elementsAll: componentListExtra,
1778
- };
1779
- let code = '';
1780
- const keyboardEventMixinCode = `const keyboardEventMixin = {
1781
- mounted() {
1782
- document.addEventListener('keydown', this.onKeyDown);
1783
- document.addEventListener('keyup', this.onKeyUp);
1784
- },
1785
- beforeDestory() {
1786
- document.removeEventListener('keydown', this.onKeyDown);
1787
- document.removeEventListener('keyup', this.onKeyUp);
1788
- },
1789
- methods: {
1790
- async onKeyDown(e) {
1791
- ${this.bindEvents
1792
- .filter((event) => ['keydown'].includes(event.name))
1793
- .map((event) => `await this.${event.view.name}_${event.name}(e);`)
1794
- .join('\n')}
1795
- },
1796
- async onKeyUp(e) {
1797
- ${this.bindEvents
1798
- .filter((event) => ['keyup'].includes(event.name))
1799
- .map((event) => `await this.${event.view.name}_${event.name}(e);`)
1800
- .join('\n')}
1801
- }
1802
- }
1803
- };\n`;
1804
- code += keyboardEventMixinCode;
1805
- code += 'export default {\n';
1806
- code += 'mixins: [';
1807
- const mixins = [];
1808
- // 键盘事件mixin
1809
- mixins.push('keyboardEventMixin');
1810
- code += mixins.join(',');
1811
- code += '],';
1812
- code += (0, translator_2.default)(definition, this);
1813
- code += '};\n';
1814
- return code;
1815
- }
1816
- // 生成预览的模板
1817
- genPreviewTemplate() {
1818
- return `<template>
1819
- <bs-${this.name}>
1820
- ${this.slotElems.map((slotElem) => {
1821
- const slotName = slotElem.name;
1822
- return `<template #${slotName}></template>`;
1823
- }).join('')}
1824
- </bs-${this.name}>
1825
- </template>`;
1826
- }
1827
- };
1828
- /** 类名 */
1829
- BusinessComponent.ConceptName = 'BusinessComponent';
1830
- /** 继承链 */
1831
- BusinessComponent.inheritanceChain = ['BaseNode'];
1832
- __decorate([
1833
- (0, decorators_1.property)('concept')
1834
- ], BusinessComponent.prototype, "concept", void 0);
1835
- __decorate([
1836
- (0, decorators_1.property)()
1837
- ], BusinessComponent.prototype, "name", void 0);
1838
- __decorate([
1839
- (0, decorators_1.property)()
1840
- ], BusinessComponent.prototype, "title", void 0);
1841
- __decorate([
1842
- (0, decorators_1.property)()
1843
- ], BusinessComponent.prototype, "description", void 0);
1844
- __decorate([
1845
- (0, decorators_1.property)({
1846
- objectRef: 'Event',
1847
- isArray: true,
1848
- defaultValue: [],
1849
- })
1850
- ], BusinessComponent.prototype, "events", void 0);
1851
- __decorate([
1852
- (0, decorators_1.property)({
1853
- objectRef: 'ParamWithGroup',
1854
- isArray: true,
1855
- defaultValue: [],
1856
- })
1857
- ], BusinessComponent.prototype, "params", void 0);
1858
- __decorate([
1859
- (0, decorators_1.property)({
1860
- objectRef: 'Variable',
1861
- isArray: true,
1862
- defaultValue: [],
1863
- })
1864
- ], BusinessComponent.prototype, "variables", void 0);
1865
- __decorate([
1866
- (0, decorators_1.property)({
1867
- objectRef: 'BindEvent',
1868
- isArray: true,
1869
- defaultValue: [],
1870
- })
1871
- ], BusinessComponent.prototype, "bindEvents", void 0);
1872
- __decorate([
1873
- (0, decorators_1.property)({
1874
- objectRef: 'BusinessLogic',
1875
- isArray: true,
1876
- defaultValue: [],
1877
- })
1878
- ], BusinessComponent.prototype, "logics", void 0);
1879
- __decorate([
1880
- (0, decorators_1.property)({
1881
- objectRef: 'ViewElement',
1882
- isArray: true,
1883
- defaultValue: [],
1884
- })
1885
- ], BusinessComponent.prototype, "elements", void 0);
1886
- __decorate([
1887
- (0, decorators_1.property)()
1888
- ], BusinessComponent.prototype, "icon", void 0);
1889
- __decorate([
1890
- translator_1.withSourceMapGenerator
1891
- ], BusinessComponent.prototype, "toEmbeddedTS", null);
1892
- BusinessComponent = BusinessComponent_1 = __decorate([
1893
- (0, decorators_1.concept)('业务组件')
1894
- ], BusinessComponent);
1895
- exports.BusinessComponent = BusinessComponent;
1896
- exports.default = BusinessComponent;
1897
- //================================================================================
1898
- // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1899
- // 自动生成的代码已结束。下面可以手动编写。
1900
- //================================================================================
1901
- //# sourceMappingURL=BusinessComponent__.js.map