@lcap/nasl 3.6.0-alpha.1 → 3.6.0-alpha.2

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