@lcap/nasl 3.5.0-alpha.1 → 3.5.0-beta.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 (571) 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/generator/CallbackNode.js +15 -0
  7. package/out/breakpoint/generator/CallbackNode.js.map +1 -1
  8. package/out/breakpoint/shared/constants.js +1 -0
  9. package/out/breakpoint/shared/constants.js.map +1 -1
  10. package/out/breakpoint/shared/utils.js +12 -6
  11. package/out/breakpoint/shared/utils.js.map +1 -1
  12. package/out/common/BaseNode.d.ts +1 -0
  13. package/out/common/BaseNode.js +23 -34
  14. package/out/common/BaseNode.js.map +1 -1
  15. package/out/concepts/App__.d.ts +51 -51
  16. package/out/concepts/App__.js +87 -92
  17. package/out/concepts/App__.js.map +1 -1
  18. package/out/concepts/BackendVariable__.js +10 -2
  19. package/out/concepts/BackendVariable__.js.map +1 -1
  20. package/out/concepts/BinaryExpression__.d.ts +2 -0
  21. package/out/concepts/BinaryExpression__.js +4 -0
  22. package/out/concepts/BinaryExpression__.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 +38 -13
  30. package/out/concepts/BindEvent__.js.map +1 -1
  31. package/out/concepts/BusinessComponent__.d.ts +637 -0
  32. package/out/concepts/BusinessComponent__.js +1892 -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 +97 -0
  38. package/out/concepts/CallEvent__.js +263 -0
  39. package/out/concepts/CallEvent__.js.map +1 -0
  40. package/out/concepts/CallFunction__.d.ts +2 -0
  41. package/out/concepts/CallFunction__.js +14 -2
  42. package/out/concepts/CallFunction__.js.map +1 -1
  43. package/out/concepts/CallInterface__.d.ts +2 -0
  44. package/out/concepts/CallInterface__.js +5 -1
  45. package/out/concepts/CallInterface__.js.map +1 -1
  46. package/out/concepts/CallLogic__.d.ts +5 -2
  47. package/out/concepts/CallLogic__.js +43 -50
  48. package/out/concepts/CallLogic__.js.map +1 -1
  49. package/out/concepts/Constant__.js +7 -6
  50. package/out/concepts/Constant__.js.map +1 -1
  51. package/out/concepts/Destination__.js +2 -2
  52. package/out/concepts/Destination__.js.map +1 -1
  53. package/out/concepts/End__.js +2 -1
  54. package/out/concepts/End__.js.map +1 -1
  55. package/out/concepts/Event__.d.ts +10 -0
  56. package/out/concepts/Event__.js +49 -0
  57. package/out/concepts/Event__.js.map +1 -1
  58. package/out/concepts/FrontendType__.d.ts +308 -0
  59. package/out/concepts/FrontendType__.js +605 -0
  60. package/out/concepts/FrontendType__.js.map +1 -0
  61. package/out/concepts/Frontend__.d.ts +0 -88
  62. package/out/concepts/Frontend__.js +1 -143
  63. package/out/concepts/Frontend__.js.map +1 -1
  64. package/out/concepts/Identifier__.d.ts +5 -0
  65. package/out/concepts/Identifier__.js +19 -9
  66. package/out/concepts/Identifier__.js.map +1 -1
  67. package/out/concepts/LogicItem__.d.ts +1 -1
  68. package/out/concepts/LogicItem__.js.map +1 -1
  69. package/out/concepts/Logic__.d.ts +3 -1
  70. package/out/concepts/Logic__.js +16 -13
  71. package/out/concepts/Logic__.js.map +1 -1
  72. package/out/concepts/MemberExpression__.d.ts +1 -1
  73. package/out/concepts/MemberExpression__.js +3 -3
  74. package/out/concepts/MemberExpression__.js.map +1 -1
  75. package/out/concepts/NewComposite__.d.ts +2 -0
  76. package/out/concepts/NewComposite__.js +4 -0
  77. package/out/concepts/NewComposite__.js.map +1 -1
  78. package/out/concepts/NewList__.d.ts +2 -0
  79. package/out/concepts/NewList__.js +4 -0
  80. package/out/concepts/NewList__.js.map +1 -1
  81. package/out/concepts/NewMap__.d.ts +2 -0
  82. package/out/concepts/NewMap__.js +4 -0
  83. package/out/concepts/NewMap__.js.map +1 -1
  84. package/out/concepts/ParamWithGroup__.d.ts +39 -0
  85. package/out/concepts/ParamWithGroup__.js +85 -0
  86. package/out/concepts/ParamWithGroup__.js.map +1 -0
  87. package/out/concepts/Param__.js +11 -3
  88. package/out/concepts/Param__.js.map +1 -1
  89. package/out/concepts/Return__.js +17 -9
  90. package/out/concepts/Return__.js.map +1 -1
  91. package/out/concepts/TypeAnnotation__.js.map +1 -1
  92. package/out/concepts/Variable__.js +17 -8
  93. package/out/concepts/Variable__.js.map +1 -1
  94. package/out/concepts/ViewElement__.d.ts +17 -1
  95. package/out/concepts/ViewElement__.js +141 -15
  96. package/out/concepts/ViewElement__.js.map +1 -1
  97. package/out/concepts/View__.js +4 -4
  98. package/out/concepts/View__.js.map +1 -1
  99. package/out/concepts/index__.d.ts +5 -0
  100. package/out/concepts/index__.js +5 -0
  101. package/out/concepts/index__.js.map +1 -1
  102. package/out/concepts/utils/asserts.d.ts +258 -3
  103. package/out/concepts/utils/asserts.js +351 -13
  104. package/out/concepts/utils/asserts.js.map +1 -1
  105. package/out/concepts/utils/quick-info.d.ts +13 -0
  106. package/out/concepts/utils/quick-info.js +51 -0
  107. package/out/concepts/utils/quick-info.js.map +1 -0
  108. package/out/concepts/utils/types.d.ts +20 -3
  109. package/out/generator/genBundleFiles.js +25 -11
  110. package/out/generator/genBundleFiles.js.map +1 -1
  111. package/out/generator/genReleaseBody.js +12 -3
  112. package/out/generator/genReleaseBody.js.map +1 -1
  113. package/out/generator/permission.js +3 -3
  114. package/out/generator/permission.js.map +1 -1
  115. package/out/server/extendBaseNode.js +6 -4
  116. package/out/server/extendBaseNode.js.map +1 -1
  117. package/out/server/getLogics.js +62 -27
  118. package/out/server/getLogics.js.map +1 -1
  119. package/out/server/getMemberIdentifier.js +6 -1
  120. package/out/server/getMemberIdentifier.js.map +1 -1
  121. package/out/server/naslServer.js +26 -59
  122. package/out/server/naslServer.js.map +1 -1
  123. package/out/server/translator.js +6 -1
  124. package/out/server/translator.js.map +1 -1
  125. package/out/service/storage/init.js +1 -2
  126. package/out/service/storage/init.js.map +1 -1
  127. package/out/templator/genCreateBlock.js +6 -6
  128. package/out/templator/genCreateBlock.js.map +1 -1
  129. package/out/templator/genCurdEditMultipleKeyBlock.js +16 -16
  130. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  131. package/out/templator/genCurdMultipleKeyBlock.js +36 -36
  132. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  133. package/out/templator/genGetBlock.js +4 -4
  134. package/out/templator/genGetBlock.js.map +1 -1
  135. package/out/templator/genGridViewBlock.js +12 -12
  136. package/out/templator/genGridViewBlock.js.map +1 -1
  137. package/out/templator/genListViewBlock.js +4 -4
  138. package/out/templator/genListViewBlock.js.map +1 -1
  139. package/out/templator/genSelectBlock.js +3 -3
  140. package/out/templator/genSelectBlock.js.map +1 -1
  141. package/out/templator/genTableBlock.js +10 -10
  142. package/out/templator/genTableBlock.js.map +1 -1
  143. package/out/templator/genUpdateBlock.js +8 -8
  144. package/out/templator/genUpdateBlock.js.map +1 -1
  145. package/out/templator/utils.d.ts +2 -2
  146. package/out/templator/utils.js.map +1 -1
  147. package/out/translator/utils.d.ts +2 -2
  148. package/out/translator/utils.js +0 -18
  149. package/out/translator/utils.js.map +1 -1
  150. package/out/utils/i18nInfo.js +7 -2
  151. package/out/utils/i18nInfo.js.map +1 -1
  152. package/package.json +1 -1
  153. package/src/bak/translator.js +121 -43
  154. package/src/breakpoint/generator/BreakpointNode.ts +12 -0
  155. package/src/breakpoint/generator/CallbackNode.ts +17 -0
  156. package/src/breakpoint/shared/constants.ts +1 -0
  157. package/src/breakpoint/shared/utils.ts +13 -8
  158. package/src/common/BaseNode.ts +22 -34
  159. package/src/concepts/App__.ts +140 -146
  160. package/src/concepts/BackendVariable__.ts +10 -2
  161. package/src/concepts/BinaryExpression__.ts +5 -1
  162. package/src/concepts/BindAttribute__.ts +15 -6
  163. package/src/concepts/BindDirective__.ts +19 -4
  164. package/src/concepts/BindEvent__.ts +40 -12
  165. package/src/concepts/BusinessComponent__.ts +2659 -0
  166. package/src/concepts/BusinessLogic__.ts +376 -0
  167. package/src/concepts/CallEvent__.ts +334 -0
  168. package/src/concepts/CallFunction__.ts +15 -2
  169. package/src/concepts/CallInterface__.ts +6 -1
  170. package/src/concepts/CallLogic__.ts +50 -58
  171. package/src/concepts/Constant__.ts +5 -7
  172. package/src/concepts/Destination__.ts +2 -2
  173. package/src/concepts/End__.ts +1 -0
  174. package/src/concepts/Event__.ts +57 -0
  175. package/src/concepts/FrontendType__.ts +919 -0
  176. package/src/concepts/Frontend__.ts +3 -251
  177. package/src/concepts/Identifier__.ts +29 -13
  178. package/src/concepts/LogicItem__.ts +1 -0
  179. package/src/concepts/Logic__.ts +21 -14
  180. package/src/concepts/MemberExpression__.ts +3 -3
  181. package/src/concepts/NewComposite__.ts +5 -5
  182. package/src/concepts/NewList__.ts +6 -2
  183. package/src/concepts/NewMap__.ts +6 -3
  184. package/src/concepts/ParamWithGroup__.ts +101 -0
  185. package/src/concepts/Param__.ts +11 -3
  186. package/src/concepts/Return__.ts +15 -12
  187. package/src/concepts/TypeAnnotation__.ts +1 -1
  188. package/src/concepts/Variable__.ts +17 -9
  189. package/src/concepts/ViewElement__.ts +164 -31
  190. package/src/concepts/View__.ts +6 -4
  191. package/src/concepts/index__.ts +5 -0
  192. package/src/concepts/utils/asserts.ts +367 -4
  193. package/src/concepts/utils/quick-info.ts +64 -0
  194. package/src/concepts/utils/types.ts +28 -0
  195. package/src/generator/genBundleFiles.ts +33 -15
  196. package/src/generator/genReleaseBody.ts +14 -3
  197. package/src/generator/permission.ts +8 -6
  198. package/src/server/extendBaseNode.ts +22 -20
  199. package/src/server/getLogics.ts +79 -41
  200. package/src/server/getMemberIdentifier.ts +7 -1
  201. package/src/server/naslServer.ts +28 -57
  202. package/src/server/translator.ts +7 -1
  203. package/src/service/storage/init.ts +1 -2
  204. package/src/templator/genCreateBlock.ts +6 -6
  205. package/src/templator/genCurdEditMultipleKeyBlock.ts +16 -16
  206. package/src/templator/genCurdMultipleKeyBlock.ts +36 -36
  207. package/src/templator/genGetBlock.ts +4 -4
  208. package/src/templator/genGridViewBlock.ts +12 -12
  209. package/src/templator/genListViewBlock.ts +4 -4
  210. package/src/templator/genSelectBlock.ts +3 -3
  211. package/src/templator/genTableBlock.ts +10 -10
  212. package/src/templator/genUpdateBlock.ts +8 -8
  213. package/src/templator/utils.ts +2 -2
  214. package/src/translator/utils.ts +2 -22
  215. package/src/utils/i18nInfo.ts +7 -2
  216. package/test/concepts/binary-expression/__snapshots__/getQuickInfoOffset.spec.ts.snap +25 -0
  217. package/test/concepts/binary-expression/getQuickInfoOffset.spec.ts +19 -0
  218. package/test/concepts/call-function/__snapshots__/getQuickInfoOffset.spec.ts.snap +41 -0
  219. package/test/concepts/call-function/fixtures/from-string.json +68 -59
  220. package/test/concepts/call-function/fixtures/to-string-global-tz.json +67 -58
  221. package/test/concepts/call-function/fixtures/to-string-no-tz.json +57 -48
  222. package/test/concepts/call-function/fixtures/to-string-user-tz.json +69 -60
  223. package/test/concepts/call-function/fixtures/to-string-utc-tz.json +69 -60
  224. package/test/concepts/call-function/getQuickInfoOffset.spec.ts +19 -0
  225. package/test/concepts/call-interface/__snapshots__/getQuickInfoOffset.spec.ts.snap +86 -0
  226. package/test/concepts/call-interface/__snapshots__/toEmbeddedTS.spec.ts.snap +3 -3
  227. package/test/concepts/call-interface/fixtures/only-interface.json +81 -72
  228. package/test/concepts/call-interface/fixtures/with-body-complex-argument.json +223 -214
  229. package/test/concepts/call-interface/fixtures/with-body-no-argument.json +85 -76
  230. package/test/concepts/call-interface/fixtures/with-body-simple-argument.json +100 -91
  231. package/test/concepts/call-interface/fixtures/with-headers-no-argument.json +88 -79
  232. package/test/concepts/call-interface/fixtures/with-headers.json +90 -81
  233. package/test/concepts/call-interface/fixtures/with-query-no-argument.json +88 -79
  234. package/test/concepts/call-interface/fixtures/with-query.json +90 -81
  235. package/test/concepts/call-interface/getQuickInfoOffset.spec.ts +19 -0
  236. package/test/concepts/call-logic/__snapshots__/getQuickInfoOffset.spec.ts.snap +4 -2
  237. package/test/concepts/call-logic/fixtures/entries-get-with-arguments.json +104 -95
  238. package/test/concepts/call-logic/fixtures/entries-update-with-arguments.json +209 -200
  239. package/test/concepts/call-logic/fixtures/global-logic-argument-no-expression.json +97 -88
  240. package/test/concepts/call-logic/fixtures/global-logic-argument-some-expression.json +124 -115
  241. package/test/concepts/call-logic/fixtures/json-deserialize.json +120 -111
  242. package/test/concepts/call-logic/fixtures/json-serialize-with-string.json +124 -115
  243. package/test/concepts/call-logic/fixtures/json-serialize.json +124 -115
  244. package/test/concepts/call-logic/fixtures/view-buildin-logic-with-argument.json +91 -82
  245. package/test/concepts/call-logic/fixtures/view-component-logic-no-argument.json +88 -79
  246. package/test/concepts/call-logic/fixtures/view-component-with-validation.json +144 -135
  247. package/test/concepts/call-logic/getQuickInfoOffset.spec.ts +2 -7
  248. package/test/concepts/identifier/fixtures/view-variable.json +145 -136
  249. package/test/concepts/new-composite/__snapshots__/getQuickInfoOffset.spec.ts.snap +104 -0
  250. package/test/concepts/new-composite/__snapshots__/toEmbeddedTS.spec.ts.snap +97 -0
  251. package/test/concepts/new-composite/__snapshots__/toJS.spec.ts.snap +43 -0
  252. package/test/concepts/new-composite/constant.ts +5 -0
  253. package/test/concepts/new-composite/fixtures/nested-transform.json +241 -0
  254. package/test/concepts/new-composite/fixtures/nested.json +146 -0
  255. package/test/concepts/new-composite/fixtures/normal.json +63 -0
  256. package/test/concepts/new-composite/getQuickInfoOffset.spec.ts +19 -0
  257. package/test/concepts/new-composite/toEmbeddedTS.spec.ts +15 -0
  258. package/test/concepts/new-composite/toJS.spec.ts +14 -0
  259. package/test/concepts/new-list/__snapshots__/getQuickInfoOffset.spec.ts.snap +165 -0
  260. package/test/concepts/new-list/__snapshots__/toEmbeddedTS.spec.ts.snap +207 -0
  261. package/test/concepts/new-list/__snapshots__/toJS.spec.ts.snap +63 -0
  262. package/test/concepts/new-list/constant.ts +5 -0
  263. package/test/concepts/new-list/fixtures/nested-map.json +117 -0
  264. package/test/concepts/new-list/fixtures/nested-tranform.json +140 -0
  265. package/test/concepts/new-list/fixtures/nested.json +107 -0
  266. package/test/concepts/new-list/fixtures/normal.json +95 -0
  267. package/test/concepts/new-list/getQuickInfoOffset.spec.ts +19 -0
  268. package/test/concepts/new-list/toEmbeddedTS.spec.ts +15 -0
  269. package/test/concepts/new-list/toJS.spec.ts +14 -0
  270. package/test/concepts/new-map/__snapshots__/getQuickInfoOffset.spec.ts.snap +115 -0
  271. package/test/concepts/new-map/__snapshots__/toEmbeddedTS.spec.ts.snap +192 -0
  272. package/test/concepts/new-map/__snapshots__/toJS.spec.ts.snap +54 -0
  273. package/test/concepts/new-map/constant.ts +5 -0
  274. package/test/concepts/new-map/fixtures/nested-transform.json +169 -0
  275. package/test/concepts/new-map/fixtures/nested.json +141 -0
  276. package/test/concepts/new-map/fixtures/normal.json +101 -0
  277. package/test/concepts/new-map/getQuickInfoOffset.spec.ts +19 -0
  278. package/test/concepts/new-map/toEmbeddedTS.spec.ts +15 -0
  279. package/test/concepts/new-map/toJS.spec.ts +14 -0
  280. package/test/concepts/utils.ts +17 -0
  281. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +1 -1
  282. package/test/concepts/view-element/fixtures/default-login.json +221 -212
  283. package/test/concepts/view-element/fixtures/default-not-found.json +183 -174
  284. package/test/concepts/view-element/fixtures/with-role-auth.json +91 -82
  285. package/test/concepts/view-element/fixtures/with-table.json +1894 -1885
  286. package/test/concepts/view-element/toVue.spec.ts +1 -0
  287. package/.nyc_output/b920244d-8d01-4e76-be5a-95132217c5a1.json +0 -1
  288. package/.nyc_output/processinfo/b920244d-8d01-4e76-be5a-95132217c5a1.json +0 -1
  289. package/.nyc_output/processinfo/index.json +0 -1
  290. package/coverage/base.css +0 -224
  291. package/coverage/block-navigation.js +0 -87
  292. package/coverage/favicon.png +0 -0
  293. package/coverage/index.html +0 -461
  294. package/coverage/prettify.css +0 -1
  295. package/coverage/prettify.js +0 -2
  296. package/coverage/sort-arrow-sprite.png +0 -0
  297. package/coverage/sorter.js +0 -196
  298. package/coverage/src/automate/engine/index.html +0 -116
  299. package/coverage/src/automate/engine/utils.js.html +0 -1414
  300. package/coverage/src/bak/index.html +0 -116
  301. package/coverage/src/bak/translator.js.html +0 -631
  302. package/coverage/src/breakpoint/generator/AfterStartNode.ts.html +0 -175
  303. package/coverage/src/breakpoint/generator/BeforeEndNode.ts.html +0 -169
  304. package/coverage/src/breakpoint/generator/BreakpointNode.ts.html +0 -1246
  305. package/coverage/src/breakpoint/generator/CallbackNode.ts.html +0 -145
  306. package/coverage/src/breakpoint/generator/index.html +0 -176
  307. package/coverage/src/breakpoint/generator/index.ts.html +0 -508
  308. package/coverage/src/breakpoint/index.html +0 -116
  309. package/coverage/src/breakpoint/index.ts.html +0 -94
  310. package/coverage/src/breakpoint/shared/constants.ts.html +0 -436
  311. package/coverage/src/breakpoint/shared/index.html +0 -176
  312. package/coverage/src/breakpoint/shared/index.ts.html +0 -94
  313. package/coverage/src/breakpoint/shared/operations.ts.html +0 -160
  314. package/coverage/src/breakpoint/shared/socket.ts.html +0 -1297
  315. package/coverage/src/breakpoint/shared/utils.ts.html +0 -1087
  316. package/coverage/src/breakpoint/store/core.ts.html +0 -1600
  317. package/coverage/src/breakpoint/store/dock.ts.html +0 -733
  318. package/coverage/src/breakpoint/store/index.html +0 -146
  319. package/coverage/src/breakpoint/store/index.ts.html +0 -91
  320. package/coverage/src/common/BaseNode.ts.html +0 -4081
  321. package/coverage/src/common/Command.ts.html +0 -310
  322. package/coverage/src/common/EventEmitter.ts.html +0 -373
  323. package/coverage/src/common/Messager.ts.html +0 -820
  324. package/coverage/src/common/asyncFuncMap.ts.html +0 -127
  325. package/coverage/src/common/index.html +0 -191
  326. package/coverage/src/common/index.ts.html +0 -94
  327. package/coverage/src/concepts/Abort__.ts.html +0 -331
  328. package/coverage/src/concepts/Anchor__.ts.html +0 -667
  329. package/coverage/src/concepts/AnonymousFunction__.ts.html +0 -2092
  330. package/coverage/src/concepts/App__.ts.html +0 -13651
  331. package/coverage/src/concepts/Argument__.ts.html +0 -907
  332. package/coverage/src/concepts/Assignee__.ts.html +0 -2317
  333. package/coverage/src/concepts/AssignmentLine__.ts.html +0 -430
  334. package/coverage/src/concepts/Assignment__.ts.html +0 -1174
  335. package/coverage/src/concepts/Attribute__.ts.html +0 -919
  336. package/coverage/src/concepts/AuthInterface__.ts.html +0 -370
  337. package/coverage/src/concepts/AuthLogicForCallInterface__.ts.html +0 -2011
  338. package/coverage/src/concepts/AuthLogic__.ts.html +0 -793
  339. package/coverage/src/concepts/BackendVariable__.ts.html +0 -1690
  340. package/coverage/src/concepts/Backend__.ts.html +0 -1192
  341. package/coverage/src/concepts/BatchAssignment__.ts.html +0 -3376
  342. package/coverage/src/concepts/BinaryExpression__.ts.html +0 -1468
  343. package/coverage/src/concepts/BindAttribute__.ts.html +0 -3931
  344. package/coverage/src/concepts/BindDirective__.ts.html +0 -2002
  345. package/coverage/src/concepts/BindEvent__.ts.html +0 -3487
  346. package/coverage/src/concepts/BindStyle__.ts.html +0 -1645
  347. package/coverage/src/concepts/BooleanLiteral__.ts.html +0 -421
  348. package/coverage/src/concepts/CallAuthInterface__.ts.html +0 -1642
  349. package/coverage/src/concepts/CallConnector__.ts.html +0 -925
  350. package/coverage/src/concepts/CallFunction__.ts.html +0 -2164
  351. package/coverage/src/concepts/CallInterface__.ts.html +0 -2776
  352. package/coverage/src/concepts/CallLogic__.ts.html +0 -4693
  353. package/coverage/src/concepts/CallQueryComponent__.ts.html +0 -5419
  354. package/coverage/src/concepts/Comment__.ts.html +0 -397
  355. package/coverage/src/concepts/CompletionProperty__.ts.html +0 -946
  356. package/coverage/src/concepts/ConfigGroup__.ts.html +0 -1132
  357. package/coverage/src/concepts/ConfigPropertyValue__.ts.html +0 -427
  358. package/coverage/src/concepts/ConfigProperty__.ts.html +0 -1375
  359. package/coverage/src/concepts/Configuration__.ts.html +0 -1054
  360. package/coverage/src/concepts/Connection__.ts.html +0 -1387
  361. package/coverage/src/concepts/ConnectorTrigger__.ts.html +0 -598
  362. package/coverage/src/concepts/Connector__.ts.html +0 -4390
  363. package/coverage/src/concepts/Constant__.ts.html +0 -1123
  364. package/coverage/src/concepts/DataSource__.ts.html +0 -1798
  365. package/coverage/src/concepts/DatabaseTypeAnnotation__.ts.html +0 -334
  366. package/coverage/src/concepts/DefaultValue__.ts.html +0 -946
  367. package/coverage/src/concepts/Destination__.ts.html +0 -2761
  368. package/coverage/src/concepts/End__.ts.html +0 -436
  369. package/coverage/src/concepts/EntityIndex__.ts.html +0 -799
  370. package/coverage/src/concepts/EntityProperty__.ts.html +0 -2866
  371. package/coverage/src/concepts/Entity__.ts.html +0 -3070
  372. package/coverage/src/concepts/EnumItem__.ts.html +0 -553
  373. package/coverage/src/concepts/Enum__.ts.html +0 -1258
  374. package/coverage/src/concepts/Event__.ts.html +0 -1111
  375. package/coverage/src/concepts/ExternalDestination__.ts.html +0 -1060
  376. package/coverage/src/concepts/ForEachStatement__.ts.html +0 -2023
  377. package/coverage/src/concepts/FrontendLibrary__.ts.html +0 -1762
  378. package/coverage/src/concepts/FrontendVariable__.ts.html +0 -292
  379. package/coverage/src/concepts/Frontend__.ts.html +0 -4078
  380. package/coverage/src/concepts/Function__.ts.html +0 -3718
  381. package/coverage/src/concepts/Identifier__.ts.html +0 -1060
  382. package/coverage/src/concepts/IfStatement__.ts.html +0 -1636
  383. package/coverage/src/concepts/Integration__.ts.html +0 -1273
  384. package/coverage/src/concepts/InterfaceParam__.ts.html +0 -1258
  385. package/coverage/src/concepts/Interface__.ts.html +0 -3463
  386. package/coverage/src/concepts/JSBlock__.ts.html +0 -424
  387. package/coverage/src/concepts/JavaLogic__.ts.html +0 -463
  388. package/coverage/src/concepts/LogicItem__.ts.html +0 -1174
  389. package/coverage/src/concepts/Logic__.ts.html +0 -7732
  390. package/coverage/src/concepts/MatchCase__.ts.html +0 -2974
  391. package/coverage/src/concepts/Match__.ts.html +0 -2494
  392. package/coverage/src/concepts/MemberExpression__.ts.html +0 -1744
  393. package/coverage/src/concepts/MicroApp__.ts.html +0 -439
  394. package/coverage/src/concepts/Module__.ts.html +0 -9385
  395. package/coverage/src/concepts/MsgTriggerEvent__.ts.html +0 -1072
  396. package/coverage/src/concepts/MsgTriggerLauncher__.ts.html +0 -1045
  397. package/coverage/src/concepts/Namespace__.ts.html +0 -8221
  398. package/coverage/src/concepts/NewComposite__.ts.html +0 -4765
  399. package/coverage/src/concepts/NewList__.ts.html +0 -1702
  400. package/coverage/src/concepts/NewMap__.ts.html +0 -2470
  401. package/coverage/src/concepts/New__.ts.html +0 -289
  402. package/coverage/src/concepts/NullLiteral__.ts.html +0 -352
  403. package/coverage/src/concepts/NumericLiteral__.ts.html +0 -697
  404. package/coverage/src/concepts/OqlQueryComponent__.ts.html +0 -1237
  405. package/coverage/src/concepts/OverriddenLogic__.ts.html +0 -6970
  406. package/coverage/src/concepts/Param__.ts.html +0 -1798
  407. package/coverage/src/concepts/Point__.ts.html +0 -334
  408. package/coverage/src/concepts/ProcessComponent__.ts.html +0 -1717
  409. package/coverage/src/concepts/ProcessElement__.ts.html +0 -6187
  410. package/coverage/src/concepts/ProcessOutcome__.ts.html +0 -355
  411. package/coverage/src/concepts/ProcessOutcomes__.ts.html +0 -355
  412. package/coverage/src/concepts/Process__.ts.html +0 -5071
  413. package/coverage/src/concepts/QueryAggregateExpression__.ts.html +0 -589
  414. package/coverage/src/concepts/QueryFieldExpression__.ts.html +0 -586
  415. package/coverage/src/concepts/QueryFromExpression__.ts.html +0 -937
  416. package/coverage/src/concepts/QueryGroupByExpression__.ts.html +0 -580
  417. package/coverage/src/concepts/QueryJoinExpression__.ts.html +0 -1606
  418. package/coverage/src/concepts/QueryLimitExpression__.ts.html +0 -664
  419. package/coverage/src/concepts/QueryOrderByExpression__.ts.html +0 -706
  420. package/coverage/src/concepts/QuerySelectExpression__.ts.html +0 -1741
  421. package/coverage/src/concepts/Rect__.ts.html +0 -376
  422. package/coverage/src/concepts/Return__.ts.html +0 -1471
  423. package/coverage/src/concepts/Role__.ts.html +0 -604
  424. package/coverage/src/concepts/SelectMembers__.ts.html +0 -1279
  425. package/coverage/src/concepts/Slot__.ts.html +0 -649
  426. package/coverage/src/concepts/SqlQueryComponent__.ts.html +0 -1003
  427. package/coverage/src/concepts/Start__.ts.html +0 -307
  428. package/coverage/src/concepts/StringInterpolation__.ts.html +0 -1156
  429. package/coverage/src/concepts/StringLiteral__.ts.html +0 -508
  430. package/coverage/src/concepts/StructureProperty__.ts.html +0 -1300
  431. package/coverage/src/concepts/Structure__.ts.html +0 -2182
  432. package/coverage/src/concepts/SwitchCase__.ts.html +0 -1204
  433. package/coverage/src/concepts/SwitchStatement__.ts.html +0 -904
  434. package/coverage/src/concepts/Theme__.ts.html +0 -361
  435. package/coverage/src/concepts/Transactional__.ts.html +0 -631
  436. package/coverage/src/concepts/TriggerEvent__.ts.html +0 -1039
  437. package/coverage/src/concepts/TriggerLauncher__.ts.html +0 -778
  438. package/coverage/src/concepts/TypeAnnotation__.ts.html +0 -3832
  439. package/coverage/src/concepts/TypeParam__.ts.html +0 -322
  440. package/coverage/src/concepts/UnaryExpression__.ts.html +0 -730
  441. package/coverage/src/concepts/Unparsed__.ts.html +0 -397
  442. package/coverage/src/concepts/UseComponent__.ts.html +0 -334
  443. package/coverage/src/concepts/ValidationRule__.ts.html +0 -1876
  444. package/coverage/src/concepts/Variable__.ts.html +0 -1705
  445. package/coverage/src/concepts/ViewBlock__.ts.html +0 -355
  446. package/coverage/src/concepts/ViewComponent__.ts.html +0 -4327
  447. package/coverage/src/concepts/ViewElement__.ts.html +0 -8992
  448. package/coverage/src/concepts/View__.ts.html +0 -9019
  449. package/coverage/src/concepts/WhileStatement__.ts.html +0 -1105
  450. package/coverage/src/concepts/basics/stdlib/index.html +0 -356
  451. package/coverage/src/concepts/basics/stdlib/index.ts.html +0 -208
  452. package/coverage/src/concepts/basics/stdlib/nasl.auth.ts.html +0 -565
  453. package/coverage/src/concepts/basics/stdlib/nasl.browser.ts.html +0 -517
  454. package/coverage/src/concepts/basics/stdlib/nasl.collection.ts.html +0 -226
  455. package/coverage/src/concepts/basics/stdlib/nasl.configuration.ts.html +0 -172
  456. package/coverage/src/concepts/basics/stdlib/nasl.core.ts.html +0 -214
  457. package/coverage/src/concepts/basics/stdlib/nasl.event.ts.html +0 -145
  458. package/coverage/src/concepts/basics/stdlib/nasl.http.ts.html +0 -589
  459. package/coverage/src/concepts/basics/stdlib/nasl.interface.ts.html +0 -214
  460. package/coverage/src/concepts/basics/stdlib/nasl.io.ts.html +0 -229
  461. package/coverage/src/concepts/basics/stdlib/nasl.logging.ts.html +0 -268
  462. package/coverage/src/concepts/basics/stdlib/nasl.process.ts.html +0 -1999
  463. package/coverage/src/concepts/basics/stdlib/nasl.ui.ts.html +0 -3259
  464. package/coverage/src/concepts/basics/stdlib/nasl.util.ts.html +0 -6955
  465. package/coverage/src/concepts/basics/stdlib/nasl.validation.ts.html +0 -1768
  466. package/coverage/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts.html +0 -163
  467. package/coverage/src/concepts/basics/stdlib/timeZone.ts.html +0 -664
  468. package/coverage/src/concepts/basics/types/coreTypeList.ts.html +0 -121
  469. package/coverage/src/concepts/basics/types/index.html +0 -131
  470. package/coverage/src/concepts/basics/types/index.ts.html +0 -160
  471. package/coverage/src/concepts/index.html +0 -1976
  472. package/coverage/src/concepts/index.ts.html +0 -103
  473. package/coverage/src/concepts/index__.ts.html +0 -454
  474. package/coverage/src/config.ts.html +0 -325
  475. package/coverage/src/decorators/index.html +0 -131
  476. package/coverage/src/decorators/index.ts.html +0 -583
  477. package/coverage/src/decorators/promise.ts.html +0 -169
  478. package/coverage/src/eventBus.ts.html +0 -100
  479. package/coverage/src/generator/compileComponent.ts.html +0 -142
  480. package/coverage/src/generator/genBundleFiles.ts.html +0 -1828
  481. package/coverage/src/generator/genHash.ts.html +0 -124
  482. package/coverage/src/generator/genMetaData.ts.html +0 -1084
  483. package/coverage/src/generator/genReleaseBody.ts.html +0 -1282
  484. package/coverage/src/generator/icestark.ts.html +0 -220
  485. package/coverage/src/generator/index.html +0 -266
  486. package/coverage/src/generator/index.ts.html +0 -106
  487. package/coverage/src/generator/microApp.ts.html +0 -172
  488. package/coverage/src/generator/permission.ts.html +0 -1036
  489. package/coverage/src/generator/qiankun.ts.html +0 -232
  490. package/coverage/src/generator/styleReplacer.ts.html +0 -199
  491. package/coverage/src/index.html +0 -146
  492. package/coverage/src/index.ts.html +0 -124
  493. package/coverage/src/manager/diagnostic.ts.html +0 -442
  494. package/coverage/src/manager/index.html +0 -131
  495. package/coverage/src/manager/stepRecorder.ts.html +0 -457
  496. package/coverage/src/natural/genNaturalTS.ts.html +0 -355
  497. package/coverage/src/natural/index.html +0 -161
  498. package/coverage/src/natural/index.ts.html +0 -91
  499. package/coverage/src/natural/naslStdlibMap.ts.html +0 -157
  500. package/coverage/src/natural/transformTSCode.ts.html +0 -2707
  501. package/coverage/src/sentry/index.html +0 -116
  502. package/coverage/src/sentry/index.ts.html +0 -676
  503. package/coverage/src/server/createUiTs.ts.html +0 -919
  504. package/coverage/src/server/entity2LogicNamespace.ts.html +0 -1294
  505. package/coverage/src/server/event.js.html +0 -526
  506. package/coverage/src/server/extendBaseNode.ts.html +0 -1762
  507. package/coverage/src/server/formatTsUtils.ts.html +0 -2689
  508. package/coverage/src/server/getConnector.ts.html +0 -316
  509. package/coverage/src/server/getExtensionModules.ts.html +0 -178
  510. package/coverage/src/server/getFunctions.ts.html +0 -133
  511. package/coverage/src/server/getInterfaces.ts.html +0 -229
  512. package/coverage/src/server/getLogging.ts.html +0 -100
  513. package/coverage/src/server/getLogics.ts.html +0 -1363
  514. package/coverage/src/server/getMemberIdentifier.ts.html +0 -1606
  515. package/coverage/src/server/getProcessComponents.ts.html +0 -112
  516. package/coverage/src/server/getProcesses.ts.html +0 -2023
  517. package/coverage/src/server/getValidates.ts.html +0 -115
  518. package/coverage/src/server/index.html +0 -401
  519. package/coverage/src/server/index.ts.html +0 -229
  520. package/coverage/src/server/naslServer.ts.html +0 -14356
  521. package/coverage/src/server/naslStdlibMap.ts.html +0 -241
  522. package/coverage/src/server/process2LogicNamespace.ts.html +0 -454
  523. package/coverage/src/server/translator.ts.html +0 -2566
  524. package/coverage/src/service/creator/add.configs.js.html +0 -397
  525. package/coverage/src/service/creator/errHandles.js.html +0 -304
  526. package/coverage/src/service/creator/index.html +0 -146
  527. package/coverage/src/service/creator/index.js.html +0 -352
  528. package/coverage/src/service/datasource/api.js.html +0 -118
  529. package/coverage/src/service/datasource/index.html +0 -131
  530. package/coverage/src/service/datasource/index.js.html +0 -103
  531. package/coverage/src/service/logic/api.js.html +0 -109
  532. package/coverage/src/service/logic/index.html +0 -131
  533. package/coverage/src/service/logic/index.js.html +0 -103
  534. package/coverage/src/service/storage/api.js.html +0 -202
  535. package/coverage/src/service/storage/index.html +0 -206
  536. package/coverage/src/service/storage/index.ts.html +0 -103
  537. package/coverage/src/service/storage/init.ts.html +0 -3721
  538. package/coverage/src/service/storage/jsoner.ts.html +0 -502
  539. package/coverage/src/service/storage/map.ts.html +0 -256
  540. package/coverage/src/service/storage/service.ts.html +0 -331
  541. package/coverage/src/service/storage/storagePoint.ts.html +0 -304
  542. package/coverage/src/templator/genCallComponentLogic.ts.html +0 -163
  543. package/coverage/src/templator/genCreateBlock.ts.html +0 -1093
  544. package/coverage/src/templator/genCurdEditMultipleKeyBlock.ts.html +0 -1609
  545. package/coverage/src/templator/genCurdMultipleKeyBlock.ts.html +0 -2254
  546. package/coverage/src/templator/genEditTableBlock.ts.html +0 -1021
  547. package/coverage/src/templator/genEnumSelectBlock.ts.html +0 -178
  548. package/coverage/src/templator/genGetBlock.ts.html +0 -451
  549. package/coverage/src/templator/genGridViewBlock.ts.html +0 -1114
  550. package/coverage/src/templator/genListViewBlock.ts.html +0 -475
  551. package/coverage/src/templator/genQueryComponent.ts.html +0 -1207
  552. package/coverage/src/templator/genSelectBlock.ts.html +0 -1243
  553. package/coverage/src/templator/genTableBlock.ts.html +0 -973
  554. package/coverage/src/templator/genUpdateBlock.ts.html +0 -1192
  555. package/coverage/src/templator/index.html +0 -326
  556. package/coverage/src/templator/index.ts.html +0 -154
  557. package/coverage/src/templator/utils.ts.html +0 -1861
  558. package/coverage/src/translator/constant.ts.html +0 -106
  559. package/coverage/src/translator/index.html +0 -146
  560. package/coverage/src/translator/index.ts.html +0 -94
  561. package/coverage/src/translator/utils.ts.html +0 -436
  562. package/coverage/src/utils/cookie.ts.html +0 -265
  563. package/coverage/src/utils/env.ts.html +0 -91
  564. package/coverage/src/utils/index.html +0 -236
  565. package/coverage/src/utils/index.ts.html +0 -694
  566. package/coverage/src/utils/logger.ts.html +0 -145
  567. package/coverage/src/utils/sortTsString.ts.html +0 -187
  568. package/coverage/src/utils/string.ts.html +0 -400
  569. package/coverage/src/utils/time-slicing.ts.html +0 -418
  570. package/coverage/src/utils/traverse.ts.html +0 -568
  571. package/coverage/src/utils/window.ts.html +0 -112
@@ -0,0 +1,2659 @@
1
+ import {
2
+ wrapForEachToGenerator as wrapForEach,
3
+ wrapIteratorToGenerator as wrapIterator,
4
+ returnOrigin,
5
+ } from '../utils/time-slicing';
6
+ import type { EmbeddedTSFileGenerator } from '../utils';
7
+ import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator } from '../translator';
8
+ import type Assignment from './Assignment__';
9
+ import type BatchAssignment from './BatchAssignment__';
10
+ import type Interface from './Interface__';
11
+ import type App from './App__';
12
+ import type FrontendType from './FrontendType__';
13
+ import type Match from './Match__';
14
+ import { ElementToVueOptions } from './ViewElement__';
15
+ import translator from '../bak/translator';
16
+
17
+ type AttrObject = {
18
+ value: string;
19
+ label: string;
20
+ };
21
+
22
+ const PAGE_COMPONENT_INCLUDE_TAG_MAP: Record<string, Record<string, AttrObject>> = {
23
+ 'u-list-view': {
24
+ 'page-size': {
25
+ value: 'size',
26
+ label: '分页大小',
27
+ },
28
+ 'page-number': {
29
+ value: 'page',
30
+ label: '当前页数',
31
+ },
32
+ 'data-source': {
33
+ value: 'data',
34
+ label: '数据',
35
+ },
36
+ },
37
+ 'u-grid-view': {
38
+ 'page-size': {
39
+ value: 'size',
40
+ label: '分页大小',
41
+ },
42
+ 'page-number': {
43
+ value: 'page',
44
+ label: '当前页数',
45
+ },
46
+ 'data-source': {
47
+ value: 'data',
48
+ label: '数据',
49
+ },
50
+ },
51
+ 'u-list-components': {
52
+ 'data-source': {
53
+ value: 'data',
54
+ label: '数据',
55
+ },
56
+ },
57
+ 'u-table-view': {
58
+ 'page-size': {
59
+ value: 'size',
60
+ label: '分页大小',
61
+ },
62
+ 'page-number': {
63
+ value: 'page',
64
+ label: '当前页数',
65
+ },
66
+ sorting: {
67
+ value: 'sort',
68
+ label: '排序属性',
69
+ },
70
+ value: {
71
+ value: 'value',
72
+ label: '单选选中值',
73
+ },
74
+ values: {
75
+ value: 'values',
76
+ label: '多选选中值',
77
+ },
78
+ 'data-source': {
79
+ value: 'data',
80
+ label: '数据',
81
+ },
82
+ },
83
+ 'u-radios': {
84
+ value: {
85
+ value: 'value',
86
+ label: '选中值',
87
+ },
88
+ 'data-source': {
89
+ value: 'data',
90
+ label: '数据',
91
+ },
92
+ },
93
+ 'u-checkboxes': {
94
+ value: {
95
+ value: 'value',
96
+ label: '选中值',
97
+ },
98
+ 'data-source': {
99
+ value: 'data',
100
+ label: '数据',
101
+ },
102
+ },
103
+ 'u-select': {
104
+ value: {
105
+ value: 'value',
106
+ label: '选中值',
107
+ },
108
+ 'data-source': {
109
+ value: 'data',
110
+ label: '数据',
111
+ },
112
+ opened: {
113
+ value: 'opened',
114
+ label: '弹出状态',
115
+ },
116
+ 'page-size': {
117
+ value: 'size',
118
+ label: '分页大小',
119
+ },
120
+ 'page-number': {
121
+ value: 'page',
122
+ label: '当前页数',
123
+ },
124
+ },
125
+ 'u-cascader': {
126
+ value: {
127
+ value: 'value',
128
+ label: '选中值',
129
+ },
130
+ 'data-source': {
131
+ value: 'data',
132
+ label: '数据',
133
+ },
134
+ },
135
+ 'u-tree-select-new': {
136
+ value: {
137
+ value: 'value',
138
+ label: '选中值',
139
+ },
140
+ 'data-source': {
141
+ value: 'data',
142
+ label: '数据',
143
+ },
144
+ },
145
+ 'van-radio-group': {
146
+ value: {
147
+ value: 'value',
148
+ label: '选中值',
149
+ },
150
+ 'data-source': {
151
+ value: 'data',
152
+ label: '数据',
153
+ },
154
+ },
155
+ 'van-checkbox-group': {
156
+ value: {
157
+ value: 'value',
158
+ label: '选中值',
159
+ },
160
+ 'data-source': {
161
+ value: 'data',
162
+ label: '数据',
163
+ },
164
+ },
165
+ 'van-pickerson': {
166
+ pvalue: {
167
+ value: 'value',
168
+ label: '选中值',
169
+ },
170
+ 'data-source': {
171
+ value: 'data',
172
+ label: '数据',
173
+ },
174
+ 'page-size': {
175
+ value: 'size',
176
+ label: '分页大小',
177
+ },
178
+ 'page-number': {
179
+ value: 'page',
180
+ label: '当前页数',
181
+ },
182
+ },
183
+ 'van-cascader': {
184
+ value: {
185
+ value: 'value',
186
+ label: '选中值',
187
+ },
188
+ 'data-source': {
189
+ value: 'data',
190
+ label: '数据',
191
+ },
192
+ },
193
+ 'van-list-view': {
194
+ 'page-size': {
195
+ value: 'size',
196
+ label: '分页大小',
197
+ },
198
+ 'page-number': {
199
+ value: 'page',
200
+ label: '当前页数',
201
+ },
202
+ 'data-source': {
203
+ value: 'data',
204
+ label: '数据',
205
+ },
206
+ },
207
+ 'van-grid-view': {
208
+ 'page-size': {
209
+ value: 'size',
210
+ label: '分页大小',
211
+ },
212
+ 'page-number': {
213
+ value: 'page',
214
+ label: '当前页数',
215
+ },
216
+ 'data-source': {
217
+ value: 'data',
218
+ label: '数据',
219
+ },
220
+ },
221
+ 'van-for-components': {
222
+ 'data-source': {
223
+ value: 'data',
224
+ label: '数据',
225
+ },
226
+ },
227
+ };
228
+
229
+ const getBranchCopyUniCode = () => (window as any)?.BranchCopyUniCode;
230
+ const removedViewElementCache: {
231
+ [key: string]: number | bigint;
232
+ } = {}; // 临时记录删除的页面元素计数的最大值
233
+
234
+ //================================================================================
235
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
236
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
237
+ //================================================================================
238
+ import { EventPayload, Params } from '../common/EventEmitter';
239
+ import { concept, excludedInJSON, property, getConceptConstructor, getBaseNode } from '../decorators';
240
+
241
+ import * as utils from '../utils';
242
+ import * as types from './utils/types';
243
+ import * as asserts from './utils/asserts';
244
+ import { v4 as uuidv4 } from 'uuid';
245
+ import BaseNode from '../common/BaseNode';
246
+ import type Event from './Event__';
247
+ import type ParamWithGroup from './ParamWithGroup__';
248
+ import type Variable from './Variable__';
249
+ import type BindEvent from './BindEvent__';
250
+ import type BusinessLogic from './BusinessLogic__';
251
+ import type ViewElement from './ViewElement__';
252
+ import type Param from './Param__';
253
+ import type Logic from './Logic__';
254
+
255
+ /**
256
+ * 业务组件
257
+ */
258
+ @concept('业务组件')
259
+ export class BusinessComponent extends BaseNode {
260
+ /** 类名 */
261
+ static readonly ConceptName: string = 'BusinessComponent';
262
+
263
+ /** 继承链 */
264
+ static readonly inheritanceChain: string[] = ['BaseNode'];
265
+
266
+ /**
267
+ * 产品概念
268
+ */
269
+ @property('concept')
270
+ // @ts-ignore
271
+ readonly concept!: 'BusinessComponent';
272
+
273
+ /**
274
+ * 业务组件名称
275
+ */
276
+ @property()
277
+ name!: string;
278
+
279
+ /**
280
+ * 业务组件标题
281
+ */
282
+ @property()
283
+ title!: string;
284
+
285
+ /**
286
+ * 业务组件描述
287
+ */
288
+ @property()
289
+ description!: string;
290
+
291
+ /**
292
+ * 组件事件列表
293
+ */
294
+ @property({
295
+ objectRef: 'Event',
296
+ isArray: true,
297
+ defaultValue: [],
298
+ })
299
+ events: Array<Event> = [];
300
+
301
+ /**
302
+ * 参数分组列表
303
+ */
304
+ @property({
305
+ objectRef: 'ParamWithGroup',
306
+ isArray: true,
307
+ defaultValue: [],
308
+ })
309
+ params: Array<ParamWithGroup> = [];
310
+
311
+ /**
312
+ * 变量列表
313
+ */
314
+ @property({
315
+ objectRef: 'Variable',
316
+ isArray: true,
317
+ defaultValue: [],
318
+ })
319
+ variables: Array<Variable> = [];
320
+
321
+ /**
322
+ * 元素绑定事件列表
323
+ */
324
+ @property({
325
+ objectRef: 'BindEvent',
326
+ isArray: true,
327
+ defaultValue: [],
328
+ })
329
+ bindEvents: Array<BindEvent> = [];
330
+
331
+ /**
332
+ * 业务组件逻辑列表
333
+ */
334
+ @property({
335
+ objectRef: 'BusinessLogic',
336
+ isArray: true,
337
+ defaultValue: [],
338
+ })
339
+ logics: Array<BusinessLogic> = [];
340
+
341
+ /**
342
+ * 页面元素列表
343
+ */
344
+ @property({
345
+ objectRef: 'ViewElement',
346
+ isArray: true,
347
+ defaultValue: [],
348
+ })
349
+ elements: Array<ViewElement> = [];
350
+
351
+ /**
352
+ * icon
353
+ */
354
+ @property()
355
+ icon!: string;
356
+
357
+ /**
358
+ * @param source 需要合并的部分参数
359
+ */
360
+ constructor(source?: Partial<BusinessComponent>) {
361
+ source = Object.assign({}, BusinessComponent.getDefaultOptions(), source);
362
+ super(source);
363
+ super.subConstructor(source);
364
+ }
365
+
366
+ static from(source: any, parentNode?: any, parentKey?: string): BusinessComponent {
367
+ return super.from(source, parentNode, parentKey) as BusinessComponent;
368
+ }
369
+
370
+ /**
371
+ * 从父级删除该节点
372
+ * @internal
373
+ */
374
+ _delete() {
375
+ let params: Params = null;
376
+ if (this.parentNode) {
377
+ params = (this.parentNode as any)?.__removeBusinessComponent?.(this);
378
+ }
379
+ return params;
380
+ }
381
+ /**
382
+ * 设置业务组件名称
383
+ */
384
+ setName(name: string) {
385
+ const object = {
386
+ name,
387
+ };
388
+ this.update({
389
+ ...object,
390
+ field: 'name',
391
+ });
392
+ }
393
+
394
+ /**
395
+ * 设置业务组件标题
396
+ */
397
+ setTitle(title: string) {
398
+ const object = {
399
+ title,
400
+ };
401
+ this.update({
402
+ ...object,
403
+ });
404
+ }
405
+
406
+ /**
407
+ * 设置业务组件描述
408
+ */
409
+ setDescription(description: string) {
410
+ const object = {
411
+ description,
412
+ };
413
+ this.update({
414
+ ...object,
415
+ });
416
+ }
417
+
418
+ /**
419
+ * 设置icon
420
+ */
421
+ setIcon(icon: string) {
422
+ const object = {
423
+ icon,
424
+ };
425
+ this.update({
426
+ ...object,
427
+ });
428
+ }
429
+
430
+ getEventExistingNames(excludedList: Array<Event> = []) {
431
+ const excludedSet = new Set(excludedList);
432
+ return ((this.events as Event[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
433
+ }
434
+ getEventUniqueName(name = 'event1') {
435
+ return utils.unique(name, this.getEventExistingNames(), undefined, false);
436
+ }
437
+
438
+ /**
439
+ * 插入组件事件
440
+ * @internal
441
+ * @param name 组件事件名称,如果不填会自动生成一个唯一名称
442
+ */
443
+ _insertEventAt(name: string, index: number): Event;
444
+
445
+ /**
446
+ * 插入组件事件
447
+ * @internal
448
+ * @param eventOptions 组件事件参数
449
+ */
450
+ _insertEventAt(eventOptions: Partial<Event>, index: number): Event;
451
+
452
+ /**
453
+ * 插入组件事件
454
+ * @internal
455
+ * @param event 已有的组件事件实例
456
+ */
457
+ _insertEventAt(event: Event, index: number): Event;
458
+
459
+ _insertEventAt(options: string | Partial<Event> | Event, index: number) {
460
+ const eventOptions: any = {};
461
+ const relationOptions = { parentNode: this, parentKey: 'events' };
462
+ const Event = getConceptConstructor('Event');
463
+ let event: Event;
464
+ if (!options) {
465
+ event = Event.from(
466
+ {
467
+ ...eventOptions,
468
+ name: this.getEventUniqueName(),
469
+ },
470
+ this,
471
+ 'events',
472
+ );
473
+ } else if (typeof options === 'string') {
474
+ event = Event.from(
475
+ {
476
+ ...eventOptions,
477
+ name: options,
478
+ },
479
+ this,
480
+ 'events',
481
+ );
482
+ } else if (asserts.isEvent(options)) {
483
+ options.ensureDelete(); // 同一实例不支持多处存在
484
+ event = options;
485
+ Object.assign(event, relationOptions);
486
+ } else {
487
+ event = Event.from(
488
+ {
489
+ ...eventOptions,
490
+ ...options,
491
+ },
492
+ this,
493
+ 'events',
494
+ );
495
+ }
496
+ this.events.splice(index, 0, event);
497
+ return event;
498
+ }
499
+
500
+ /**
501
+ * 插入组件事件
502
+ * @param name 组件事件名称,如果不填会自动生成一个唯一名称
503
+ */
504
+ insertEventAt(name: string, index: number): Event;
505
+
506
+ /**
507
+ * 插入组件事件
508
+ * @param eventOptions 组件事件参数
509
+ */
510
+ insertEventAt(eventOptions: Partial<Event>, index: number): Event;
511
+
512
+ /**
513
+ * 插入组件事件
514
+ * @param event 已有的组件事件实例
515
+ */
516
+ insertEventAt(event: Event, index: number): Event;
517
+
518
+ insertEventAt(options: string | Partial<Event> | Event, index: number) {
519
+ const node = this._insertEventAt(options as any, index);
520
+ node.create({
521
+ index,
522
+ parentNode: this,
523
+ parentKey: 'events',
524
+ });
525
+ return node;
526
+ }
527
+
528
+ /**
529
+ * 添加组件事件
530
+ * @internal
531
+ * @param name 组件事件名称,如果不填会自动生成一个唯一名称
532
+ */
533
+ _addEvent(name?: string): Event;
534
+
535
+ /**
536
+ * 添加组件事件
537
+ * @internal
538
+ * @param eventOptions 组件事件参数
539
+ */
540
+ _addEvent(eventOptions: Partial<Event>): Event;
541
+
542
+ /**
543
+ * 添加组件事件
544
+ * @internal
545
+ * @param event 已有的组件事件实例
546
+ */
547
+ _addEvent(event: Event): Event;
548
+
549
+ _addEvent(options?: string | Partial<Event> | Event) {
550
+ const index = this.events.length;
551
+ return this._insertEventAt(options as any, index);
552
+ }
553
+
554
+ /**
555
+ * 添加组件事件
556
+ * @internal
557
+ * @param name 组件事件名称,如果不填会自动生成一个唯一名称
558
+ */
559
+ addEvent(name?: string): Event;
560
+
561
+ /**
562
+ * 添加组件事件
563
+ * @param eventOptions 组件事件参数
564
+ */
565
+ addEvent(eventOptions: Partial<Event>): Event;
566
+
567
+ /**
568
+ * 添加组件事件
569
+ * @param event 已有的组件事件实例
570
+ */
571
+ addEvent(event: Event): Event;
572
+
573
+ addEvent(options?: string | Partial<Event> | Event) {
574
+ const node = this._addEvent(options as any);
575
+ const index = this.events.indexOf(node);
576
+ node.create({
577
+ index,
578
+ parentNode: this,
579
+ parentKey: 'events',
580
+ });
581
+ return node;
582
+ }
583
+
584
+ getParamUniqueName(name = 'param1') {
585
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
586
+ }
587
+
588
+ /**
589
+ * 插入参数分组
590
+ * @internal
591
+ * @param name 参数分组名称,如果不填会自动生成一个唯一名称
592
+ */
593
+ _insertParamAt(name: string, index: number): ParamWithGroup;
594
+
595
+ /**
596
+ * 插入参数分组
597
+ * @internal
598
+ * @param paramOptions 参数分组参数
599
+ */
600
+ _insertParamAt(paramOptions: Partial<ParamWithGroup>, index: number): ParamWithGroup;
601
+
602
+ /**
603
+ * 插入参数分组
604
+ * @internal
605
+ * @param param 已有的参数分组实例
606
+ */
607
+ _insertParamAt(param: ParamWithGroup, index: number): ParamWithGroup;
608
+
609
+ _insertParamAt(options: string | Partial<ParamWithGroup> | ParamWithGroup, index: number) {
610
+ const paramOptions: any = {};
611
+ const relationOptions = { parentNode: this, parentKey: 'params' };
612
+ const ParamWithGroup = getConceptConstructor('ParamWithGroup');
613
+ let param: ParamWithGroup;
614
+ if (!options) {
615
+ param = ParamWithGroup.from(
616
+ {
617
+ ...paramOptions,
618
+ name: this.getParamUniqueName(),
619
+ },
620
+ this,
621
+ 'params',
622
+ );
623
+ } else if (typeof options === 'string') {
624
+ param = ParamWithGroup.from(
625
+ {
626
+ ...paramOptions,
627
+ name: options,
628
+ },
629
+ this,
630
+ 'params',
631
+ );
632
+ } else if (asserts.isParamWithGroup(options)) {
633
+ options.ensureDelete(); // 同一实例不支持多处存在
634
+ param = options;
635
+ Object.assign(param, relationOptions);
636
+ } else {
637
+ param = ParamWithGroup.from(
638
+ {
639
+ ...paramOptions,
640
+ ...options,
641
+ },
642
+ this,
643
+ 'params',
644
+ );
645
+ }
646
+ this.params.splice(index, 0, param);
647
+ return param;
648
+ }
649
+
650
+ /**
651
+ * 插入参数分组
652
+ * @param name 参数分组名称,如果不填会自动生成一个唯一名称
653
+ */
654
+ insertParamAt(name: string, index: number): ParamWithGroup;
655
+
656
+ /**
657
+ * 插入参数分组
658
+ * @param paramOptions 参数分组参数
659
+ */
660
+ insertParamAt(paramOptions: Partial<ParamWithGroup>, index: number): ParamWithGroup;
661
+
662
+ /**
663
+ * 插入参数分组
664
+ * @param param 已有的参数分组实例
665
+ */
666
+ insertParamAt(param: ParamWithGroup, index: number): ParamWithGroup;
667
+
668
+ insertParamAt(options: string | Partial<ParamWithGroup> | ParamWithGroup, index: number) {
669
+ const node = this._insertParamAt(options as any, index);
670
+ node.create({
671
+ index,
672
+ parentNode: this,
673
+ parentKey: 'params',
674
+ });
675
+ return node;
676
+ }
677
+
678
+ /**
679
+ * 添加参数分组
680
+ * @internal
681
+ * @param name 参数分组名称,如果不填会自动生成一个唯一名称
682
+ */
683
+ _addParam(name?: string): ParamWithGroup;
684
+
685
+ /**
686
+ * 添加参数分组
687
+ * @internal
688
+ * @param paramOptions 参数分组参数
689
+ */
690
+ _addParam(paramOptions: Partial<ParamWithGroup>): ParamWithGroup;
691
+
692
+ /**
693
+ * 添加参数分组
694
+ * @internal
695
+ * @param param 已有的参数分组实例
696
+ */
697
+ _addParam(param: ParamWithGroup): ParamWithGroup;
698
+
699
+ _addParam(options?: string | Partial<ParamWithGroup> | ParamWithGroup) {
700
+ const index = this.params.length;
701
+ return this._insertParamAt(options as any, index);
702
+ }
703
+
704
+ /**
705
+ * 添加参数分组
706
+ * @internal
707
+ * @param name 参数分组名称,如果不填会自动生成一个唯一名称
708
+ */
709
+ addParam(name?: string): ParamWithGroup;
710
+
711
+ /**
712
+ * 添加参数分组
713
+ * @param paramOptions 参数分组参数
714
+ */
715
+ addParam(paramOptions: Partial<ParamWithGroup>): ParamWithGroup;
716
+
717
+ /**
718
+ * 添加参数分组
719
+ * @param param 已有的参数分组实例
720
+ */
721
+ addParam(param: ParamWithGroup): ParamWithGroup;
722
+
723
+ addParam(options?: string | Partial<ParamWithGroup> | ParamWithGroup) {
724
+ const node = this._addParam(options as any);
725
+ const index = this.params.indexOf(node);
726
+ node.create({
727
+ index,
728
+ parentNode: this,
729
+ parentKey: 'params',
730
+ });
731
+ return node;
732
+ }
733
+
734
+ getVariableUniqueName(name = 'variable1') {
735
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
736
+ }
737
+
738
+ /**
739
+ * 插入变量
740
+ * @internal
741
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
742
+ */
743
+ _insertVariableAt(name: string, index: number): Variable;
744
+
745
+ /**
746
+ * 插入变量
747
+ * @internal
748
+ * @param variableOptions 变量参数
749
+ */
750
+ _insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
751
+
752
+ /**
753
+ * 插入变量
754
+ * @internal
755
+ * @param variable 已有的变量实例
756
+ */
757
+ _insertVariableAt(variable: Variable, index: number): Variable;
758
+
759
+ _insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
760
+ const variableOptions: any = {};
761
+ const relationOptions = { parentNode: this, parentKey: 'variables' };
762
+ const Variable = getConceptConstructor('Variable');
763
+ let variable: Variable;
764
+ if (!options) {
765
+ variable = Variable.from(
766
+ {
767
+ ...variableOptions,
768
+ name: this.getVariableUniqueName(),
769
+ },
770
+ this,
771
+ 'variables',
772
+ );
773
+ } else if (typeof options === 'string') {
774
+ variable = Variable.from(
775
+ {
776
+ ...variableOptions,
777
+ name: options,
778
+ },
779
+ this,
780
+ 'variables',
781
+ );
782
+ } else if (asserts.isVariable(options)) {
783
+ options.ensureDelete(); // 同一实例不支持多处存在
784
+ variable = options;
785
+ Object.assign(variable, relationOptions);
786
+ } else {
787
+ variable = Variable.from(
788
+ {
789
+ ...variableOptions,
790
+ ...options,
791
+ },
792
+ this,
793
+ 'variables',
794
+ );
795
+ }
796
+ this.variables.splice(index, 0, variable);
797
+ return variable;
798
+ }
799
+
800
+ /**
801
+ * 插入变量
802
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
803
+ */
804
+ insertVariableAt(name: string, index: number): Variable;
805
+
806
+ /**
807
+ * 插入变量
808
+ * @param variableOptions 变量参数
809
+ */
810
+ insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
811
+
812
+ /**
813
+ * 插入变量
814
+ * @param variable 已有的变量实例
815
+ */
816
+ insertVariableAt(variable: Variable, index: number): Variable;
817
+
818
+ insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
819
+ const node = this._insertVariableAt(options as any, index);
820
+ node.create({
821
+ index,
822
+ parentNode: this,
823
+ parentKey: 'variables',
824
+ });
825
+ return node;
826
+ }
827
+
828
+ /**
829
+ * 添加变量
830
+ * @internal
831
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
832
+ */
833
+ _addVariable(name?: string): Variable;
834
+
835
+ /**
836
+ * 添加变量
837
+ * @internal
838
+ * @param variableOptions 变量参数
839
+ */
840
+ _addVariable(variableOptions: Partial<Variable>): Variable;
841
+
842
+ /**
843
+ * 添加变量
844
+ * @internal
845
+ * @param variable 已有的变量实例
846
+ */
847
+ _addVariable(variable: Variable): Variable;
848
+
849
+ _addVariable(options?: string | Partial<Variable> | Variable) {
850
+ const index = this.variables.length;
851
+ return this._insertVariableAt(options as any, index);
852
+ }
853
+
854
+ /**
855
+ * 添加变量
856
+ * @internal
857
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
858
+ */
859
+ addVariable(name?: string): Variable;
860
+
861
+ /**
862
+ * 添加变量
863
+ * @param variableOptions 变量参数
864
+ */
865
+ addVariable(variableOptions: Partial<Variable>): Variable;
866
+
867
+ /**
868
+ * 添加变量
869
+ * @param variable 已有的变量实例
870
+ */
871
+ addVariable(variable: Variable): Variable;
872
+
873
+ addVariable(options?: string | Partial<Variable> | Variable) {
874
+ const node = this._addVariable(options as any);
875
+ const index = this.variables.indexOf(node);
876
+ node.create({
877
+ index,
878
+ parentNode: this,
879
+ parentKey: 'variables',
880
+ });
881
+ return node;
882
+ }
883
+
884
+ getBindEventExistingNames(excludedList: Array<BindEvent> = []) {
885
+ const excludedSet = new Set(excludedList);
886
+ return ((this.bindEvents as BindEvent[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
887
+ }
888
+ getBindEventUniqueName(name = 'bindEvent1') {
889
+ return utils.unique(name, this.getBindEventExistingNames(), undefined, false);
890
+ }
891
+
892
+ /**
893
+ * 插入元素绑定事件
894
+ * @internal
895
+ * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
896
+ */
897
+ _insertBindEventAt(name: string, index: number): BindEvent;
898
+
899
+ /**
900
+ * 插入元素绑定事件
901
+ * @internal
902
+ * @param bindEventOptions 元素绑定事件参数
903
+ */
904
+ _insertBindEventAt(bindEventOptions: Partial<BindEvent>, index: number): BindEvent;
905
+
906
+ /**
907
+ * 插入元素绑定事件
908
+ * @internal
909
+ * @param bindEvent 已有的元素绑定事件实例
910
+ */
911
+ _insertBindEventAt(bindEvent: BindEvent, index: number): BindEvent;
912
+
913
+ _insertBindEventAt(options: string | Partial<BindEvent> | BindEvent, index: number) {
914
+ const bindEventOptions: any = {};
915
+ const relationOptions = { parentNode: this, parentKey: 'bindEvents' };
916
+ const BindEvent = getConceptConstructor('BindEvent');
917
+ let bindEvent: BindEvent;
918
+ if (!options) {
919
+ bindEvent = BindEvent.from(
920
+ {
921
+ ...bindEventOptions,
922
+ name: this.getBindEventUniqueName(),
923
+ },
924
+ this,
925
+ 'bindEvents',
926
+ );
927
+ } else if (typeof options === 'string') {
928
+ bindEvent = BindEvent.from(
929
+ {
930
+ ...bindEventOptions,
931
+ name: options,
932
+ },
933
+ this,
934
+ 'bindEvents',
935
+ );
936
+ } else if (asserts.isBindEvent(options)) {
937
+ options.ensureDelete(); // 同一实例不支持多处存在
938
+ bindEvent = options;
939
+ Object.assign(bindEvent, relationOptions);
940
+ } else {
941
+ bindEvent = BindEvent.from(
942
+ {
943
+ ...bindEventOptions,
944
+ ...options,
945
+ },
946
+ this,
947
+ 'bindEvents',
948
+ );
949
+ }
950
+ this.bindEvents.splice(index, 0, bindEvent);
951
+ return bindEvent;
952
+ }
953
+
954
+ /**
955
+ * 插入元素绑定事件
956
+ * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
957
+ */
958
+ insertBindEventAt(name: string, index: number): BindEvent;
959
+
960
+ /**
961
+ * 插入元素绑定事件
962
+ * @param bindEventOptions 元素绑定事件参数
963
+ */
964
+ insertBindEventAt(bindEventOptions: Partial<BindEvent>, index: number): BindEvent;
965
+
966
+ /**
967
+ * 插入元素绑定事件
968
+ * @param bindEvent 已有的元素绑定事件实例
969
+ */
970
+ insertBindEventAt(bindEvent: BindEvent, index: number): BindEvent;
971
+
972
+ insertBindEventAt(options: string | Partial<BindEvent> | BindEvent, index: number) {
973
+ const node = this._insertBindEventAt(options as any, index);
974
+ node.create({
975
+ index,
976
+ parentNode: this,
977
+ parentKey: 'bindEvents',
978
+ });
979
+ return node;
980
+ }
981
+
982
+ /**
983
+ * 添加元素绑定事件
984
+ * @internal
985
+ * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
986
+ */
987
+ _addBindEvent(name?: string): BindEvent;
988
+
989
+ /**
990
+ * 添加元素绑定事件
991
+ * @internal
992
+ * @param bindEventOptions 元素绑定事件参数
993
+ */
994
+ _addBindEvent(bindEventOptions: Partial<BindEvent>): BindEvent;
995
+
996
+ /**
997
+ * 添加元素绑定事件
998
+ * @internal
999
+ * @param bindEvent 已有的元素绑定事件实例
1000
+ */
1001
+ _addBindEvent(bindEvent: BindEvent): BindEvent;
1002
+
1003
+ _addBindEvent(options?: string | Partial<BindEvent> | BindEvent) {
1004
+ const index = this.bindEvents.length;
1005
+ return this._insertBindEventAt(options as any, index);
1006
+ }
1007
+
1008
+ /**
1009
+ * 添加元素绑定事件
1010
+ * @internal
1011
+ * @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
1012
+ */
1013
+ addBindEvent(name?: string): BindEvent;
1014
+
1015
+ /**
1016
+ * 添加元素绑定事件
1017
+ * @param bindEventOptions 元素绑定事件参数
1018
+ */
1019
+ addBindEvent(bindEventOptions: Partial<BindEvent>): BindEvent;
1020
+
1021
+ /**
1022
+ * 添加元素绑定事件
1023
+ * @param bindEvent 已有的元素绑定事件实例
1024
+ */
1025
+ addBindEvent(bindEvent: BindEvent): BindEvent;
1026
+
1027
+ addBindEvent(options?: string | Partial<BindEvent> | BindEvent) {
1028
+ const node = this._addBindEvent(options as any);
1029
+ const index = this.bindEvents.indexOf(node);
1030
+ node.create({
1031
+ index,
1032
+ parentNode: this,
1033
+ parentKey: 'bindEvents',
1034
+ });
1035
+ return node;
1036
+ }
1037
+
1038
+ getLogicExistingNames(excludedList: Array<BusinessLogic> = []) {
1039
+ const excludedSet = new Set(excludedList);
1040
+ return ((this.logics as BusinessLogic[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
1041
+ }
1042
+ getLogicUniqueName(name = 'logic1') {
1043
+ return utils.unique(name, this.getLogicExistingNames(), undefined, false);
1044
+ }
1045
+
1046
+ /**
1047
+ * 插入业务组件逻辑
1048
+ * @internal
1049
+ * @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
1050
+ */
1051
+ _insertLogicAt(name: string, index: number): BusinessLogic;
1052
+
1053
+ /**
1054
+ * 插入业务组件逻辑
1055
+ * @internal
1056
+ * @param logicOptions 业务组件逻辑参数
1057
+ */
1058
+ _insertLogicAt(logicOptions: Partial<BusinessLogic>, index: number): BusinessLogic;
1059
+
1060
+ /**
1061
+ * 插入业务组件逻辑
1062
+ * @internal
1063
+ * @param logic 已有的业务组件逻辑实例
1064
+ */
1065
+ _insertLogicAt(logic: BusinessLogic, index: number): BusinessLogic;
1066
+
1067
+ _insertLogicAt(options: string | Partial<BusinessLogic> | BusinessLogic, index: number) {
1068
+ const logicOptions: any = {};
1069
+ const relationOptions = { parentNode: this, parentKey: 'logics' };
1070
+ const BusinessLogic = getConceptConstructor('BusinessLogic');
1071
+ let logic: BusinessLogic;
1072
+ if (!options) {
1073
+ logic = BusinessLogic.from(
1074
+ {
1075
+ ...logicOptions,
1076
+ name: this.getLogicUniqueName(),
1077
+ },
1078
+ this,
1079
+ 'logics',
1080
+ );
1081
+ } else if (typeof options === 'string') {
1082
+ logic = BusinessLogic.from(
1083
+ {
1084
+ ...logicOptions,
1085
+ name: options,
1086
+ },
1087
+ this,
1088
+ 'logics',
1089
+ );
1090
+ } else if (asserts.isBusinessLogic(options)) {
1091
+ options.ensureDelete(); // 同一实例不支持多处存在
1092
+ logic = options;
1093
+ Object.assign(logic, relationOptions);
1094
+ } else {
1095
+ logic = BusinessLogic.from(
1096
+ {
1097
+ ...logicOptions,
1098
+ ...options,
1099
+ },
1100
+ this,
1101
+ 'logics',
1102
+ );
1103
+ }
1104
+ this.logics.splice(index, 0, logic);
1105
+ return logic;
1106
+ }
1107
+
1108
+ /**
1109
+ * 插入业务组件逻辑
1110
+ * @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
1111
+ */
1112
+ insertLogicAt(name: string, index: number): BusinessLogic;
1113
+
1114
+ /**
1115
+ * 插入业务组件逻辑
1116
+ * @param logicOptions 业务组件逻辑参数
1117
+ */
1118
+ insertLogicAt(logicOptions: Partial<BusinessLogic>, index: number): BusinessLogic;
1119
+
1120
+ /**
1121
+ * 插入业务组件逻辑
1122
+ * @param logic 已有的业务组件逻辑实例
1123
+ */
1124
+ insertLogicAt(logic: BusinessLogic, index: number): BusinessLogic;
1125
+
1126
+ insertLogicAt(options: string | Partial<BusinessLogic> | BusinessLogic, index: number) {
1127
+ const node = this._insertLogicAt(options as any, index);
1128
+ node.create({
1129
+ index,
1130
+ parentNode: this,
1131
+ parentKey: 'logics',
1132
+ });
1133
+ return node;
1134
+ }
1135
+
1136
+ /**
1137
+ * 添加业务组件逻辑
1138
+ * @internal
1139
+ * @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
1140
+ */
1141
+ _addLogic(name?: string): BusinessLogic;
1142
+
1143
+ /**
1144
+ * 添加业务组件逻辑
1145
+ * @internal
1146
+ * @param logicOptions 业务组件逻辑参数
1147
+ */
1148
+ _addLogic(logicOptions: Partial<BusinessLogic>): BusinessLogic;
1149
+
1150
+ /**
1151
+ * 添加业务组件逻辑
1152
+ * @internal
1153
+ * @param logic 已有的业务组件逻辑实例
1154
+ */
1155
+ _addLogic(logic: BusinessLogic): BusinessLogic;
1156
+
1157
+ _addLogic(options?: string | Partial<BusinessLogic> | BusinessLogic) {
1158
+ const index = this.logics.length;
1159
+ return this._insertLogicAt(options as any, index);
1160
+ }
1161
+
1162
+ /**
1163
+ * 添加业务组件逻辑
1164
+ * @internal
1165
+ * @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
1166
+ */
1167
+ addLogic(name?: string): BusinessLogic;
1168
+
1169
+ /**
1170
+ * 添加业务组件逻辑
1171
+ * @param logicOptions 业务组件逻辑参数
1172
+ */
1173
+ addLogic(logicOptions: Partial<BusinessLogic>): BusinessLogic;
1174
+
1175
+ /**
1176
+ * 添加业务组件逻辑
1177
+ * @param logic 已有的业务组件逻辑实例
1178
+ */
1179
+ addLogic(logic: BusinessLogic): BusinessLogic;
1180
+
1181
+ addLogic(options?: string | Partial<BusinessLogic> | BusinessLogic) {
1182
+ const node = this._addLogic(options as any);
1183
+ const index = this.logics.indexOf(node);
1184
+ node.create({
1185
+ index,
1186
+ parentNode: this,
1187
+ parentKey: 'logics',
1188
+ });
1189
+ return node;
1190
+ }
1191
+
1192
+ /**
1193
+ * 插入页面元素
1194
+ * @internal
1195
+ * @param name 页面元素名称,如果不填会自动生成一个唯一名称
1196
+ */
1197
+ _insertViewElementAt(name: string, index: number): ViewElement;
1198
+
1199
+ /**
1200
+ * 插入页面元素
1201
+ * @internal
1202
+ * @param viewElementOptions 页面元素参数
1203
+ */
1204
+ _insertViewElementAt(viewElementOptions: Partial<ViewElement>, index: number): ViewElement;
1205
+
1206
+ /**
1207
+ * 插入页面元素
1208
+ * @internal
1209
+ * @param viewElement 已有的页面元素实例
1210
+ */
1211
+ _insertViewElementAt(viewElement: ViewElement, index: number): ViewElement;
1212
+
1213
+ _insertViewElementAt(options: string | Partial<ViewElement> | ViewElement, index: number) {
1214
+ const viewElementOptions: any = {};
1215
+ const relationOptions = { parentNode: this, parentKey: 'elements' };
1216
+ const ViewElement = getConceptConstructor('ViewElement');
1217
+ let viewElement: ViewElement;
1218
+ if (!options) {
1219
+ viewElement = ViewElement.from(
1220
+ {
1221
+ ...viewElementOptions,
1222
+ name: this.getViewElementUniqueName(),
1223
+ },
1224
+ this,
1225
+ 'elements',
1226
+ );
1227
+ } else if (typeof options === 'string') {
1228
+ viewElement = ViewElement.from(
1229
+ {
1230
+ ...viewElementOptions,
1231
+ name: options,
1232
+ },
1233
+ this,
1234
+ 'elements',
1235
+ );
1236
+ } else if (asserts.isViewElement(options)) {
1237
+ options.ensureDelete(); // 同一实例不支持多处存在
1238
+ viewElement = options;
1239
+ Object.assign(viewElement, relationOptions);
1240
+ } else {
1241
+ viewElement = ViewElement.from(
1242
+ {
1243
+ ...viewElementOptions,
1244
+ ...options,
1245
+ },
1246
+ this,
1247
+ 'elements',
1248
+ );
1249
+ }
1250
+ this.elements.splice(index, 0, viewElement);
1251
+ return viewElement;
1252
+ }
1253
+
1254
+ /**
1255
+ * 插入页面元素
1256
+ * @param name 页面元素名称,如果不填会自动生成一个唯一名称
1257
+ */
1258
+ insertViewElementAt(name: string, index: number): ViewElement;
1259
+
1260
+ /**
1261
+ * 插入页面元素
1262
+ * @param viewElementOptions 页面元素参数
1263
+ */
1264
+ insertViewElementAt(viewElementOptions: Partial<ViewElement>, index: number): ViewElement;
1265
+
1266
+ /**
1267
+ * 插入页面元素
1268
+ * @param viewElement 已有的页面元素实例
1269
+ */
1270
+ insertViewElementAt(viewElement: ViewElement, index: number): ViewElement;
1271
+
1272
+ insertViewElementAt(options: string | Partial<ViewElement> | ViewElement, index: number) {
1273
+ const node = this._insertViewElementAt(options as any, index);
1274
+ node.create({
1275
+ index,
1276
+ parentNode: this,
1277
+ parentKey: 'elements',
1278
+ });
1279
+ return node;
1280
+ }
1281
+
1282
+ /**
1283
+ * 添加页面元素
1284
+ * @internal
1285
+ * @param name 页面元素名称,如果不填会自动生成一个唯一名称
1286
+ */
1287
+ _addViewElement(name?: string): ViewElement;
1288
+
1289
+ /**
1290
+ * 添加页面元素
1291
+ * @internal
1292
+ * @param viewElementOptions 页面元素参数
1293
+ */
1294
+ _addViewElement(viewElementOptions: Partial<ViewElement>): ViewElement;
1295
+
1296
+ /**
1297
+ * 添加页面元素
1298
+ * @internal
1299
+ * @param viewElement 已有的页面元素实例
1300
+ */
1301
+ _addViewElement(viewElement: ViewElement): ViewElement;
1302
+
1303
+ _addViewElement(options?: string | Partial<ViewElement> | ViewElement) {
1304
+ const index = this.elements.length;
1305
+ return this._insertViewElementAt(options as any, index);
1306
+ }
1307
+
1308
+ /**
1309
+ * 添加页面元素
1310
+ * @internal
1311
+ * @param name 页面元素名称,如果不填会自动生成一个唯一名称
1312
+ */
1313
+ addViewElement(name?: string): ViewElement;
1314
+
1315
+ /**
1316
+ * 添加页面元素
1317
+ * @param viewElementOptions 页面元素参数
1318
+ */
1319
+ addViewElement(viewElementOptions: Partial<ViewElement>): ViewElement;
1320
+
1321
+ /**
1322
+ * 添加页面元素
1323
+ * @param viewElement 已有的页面元素实例
1324
+ */
1325
+ addViewElement(viewElement: ViewElement): ViewElement;
1326
+
1327
+ addViewElement(options?: string | Partial<ViewElement> | ViewElement) {
1328
+ const node = this._addViewElement(options as any);
1329
+ const index = this.elements.indexOf(node);
1330
+ node.create({
1331
+ index,
1332
+ parentNode: this,
1333
+ parentKey: 'elements',
1334
+ });
1335
+ return node;
1336
+ }
1337
+
1338
+ /**
1339
+ * 删除组件事件
1340
+ * @param name 组件事件名称
1341
+ */
1342
+ removeEvent(name: string): void;
1343
+
1344
+ /**
1345
+ * 删除组件事件
1346
+ * @param event 已有的组件事件实例
1347
+ */
1348
+ removeEvent(event: Event): void;
1349
+
1350
+ removeEvent(options: string | Event) {
1351
+ let event: Event;
1352
+ if (typeof options === 'string') {
1353
+ event = (this.events as Event[]).find((item) => item.name === options);
1354
+ if (!event) {
1355
+ throw new Error('找不到组件事件 ' + options);
1356
+ }
1357
+ } else {
1358
+ event = options;
1359
+ }
1360
+ return event.delete();
1361
+ }
1362
+
1363
+ __removeEvent(event: Event) {
1364
+ const parentKey = event.parentKey;
1365
+ const params: Params = {
1366
+ parentNode: this,
1367
+ parentKey,
1368
+ index: -1,
1369
+ object: null,
1370
+ oldObject: event,
1371
+ };
1372
+ if (parentKey) {
1373
+ params.parentKey = parentKey;
1374
+ // @ts-ignore
1375
+ const t = this.__v_raw || this;
1376
+ // @ts-ignore
1377
+ const n = event.__v_raw || event;
1378
+ if (Array.isArray((t as any)[parentKey])) {
1379
+ // @ts-ignore
1380
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1381
+ ~index && (this as any)[parentKey].splice(index, 1);
1382
+ params.index = index;
1383
+ } else {
1384
+ const q = (t as any)[parentKey];
1385
+ if ((q.__v_raw || q) === n) {
1386
+ params.index = 0;
1387
+ (this as any)[parentKey] = undefined;
1388
+ }
1389
+ }
1390
+ }
1391
+ return params;
1392
+ }
1393
+
1394
+ /**
1395
+ * 删除参数分组
1396
+ * @param name 参数分组名称
1397
+ */
1398
+ removeParam(name: string): void;
1399
+
1400
+ /**
1401
+ * 删除参数分组
1402
+ * @param param 已有的参数分组实例
1403
+ */
1404
+ removeParam(param: ParamWithGroup): void;
1405
+
1406
+ removeParam(options: string | ParamWithGroup) {
1407
+ let param: ParamWithGroup;
1408
+ if (typeof options === 'string') {
1409
+ param = (this.params as ParamWithGroup[]).find((item) => item.name === options);
1410
+ if (!param) {
1411
+ throw new Error('找不到参数分组 ' + options);
1412
+ }
1413
+ } else {
1414
+ param = options;
1415
+ }
1416
+ return param.delete();
1417
+ }
1418
+
1419
+ __removeParam(param: Param) {
1420
+ const parentKey = param.parentKey;
1421
+ const params: Params = {
1422
+ parentNode: this,
1423
+ parentKey,
1424
+ index: -1,
1425
+ object: null,
1426
+ oldObject: param,
1427
+ };
1428
+ if (parentKey) {
1429
+ params.parentKey = parentKey;
1430
+ // @ts-ignore
1431
+ const t = this.__v_raw || this;
1432
+ // @ts-ignore
1433
+ const n = param.__v_raw || param;
1434
+ if (Array.isArray((t as any)[parentKey])) {
1435
+ // @ts-ignore
1436
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1437
+ ~index && (this as any)[parentKey].splice(index, 1);
1438
+ params.index = index;
1439
+ } else {
1440
+ const q = (t as any)[parentKey];
1441
+ if ((q.__v_raw || q) === n) {
1442
+ params.index = 0;
1443
+ (this as any)[parentKey] = undefined;
1444
+ }
1445
+ }
1446
+ }
1447
+ return params;
1448
+ }
1449
+
1450
+ /**
1451
+ * 删除变量
1452
+ * @param name 变量名称
1453
+ */
1454
+ removeVariable(name: string): void;
1455
+
1456
+ /**
1457
+ * 删除变量
1458
+ * @param variable 已有的变量实例
1459
+ */
1460
+ removeVariable(variable: Variable): void;
1461
+
1462
+ removeVariable(options: string | Variable) {
1463
+ let variable: Variable;
1464
+ if (typeof options === 'string') {
1465
+ variable = (this.variables as Variable[]).find((item) => item.name === options);
1466
+ if (!variable) {
1467
+ throw new Error('找不到变量 ' + options);
1468
+ }
1469
+ } else {
1470
+ variable = options;
1471
+ }
1472
+ return variable.delete();
1473
+ }
1474
+
1475
+ __removeVariable(variable: Variable) {
1476
+ const parentKey = variable.parentKey;
1477
+ const params: Params = {
1478
+ parentNode: this,
1479
+ parentKey,
1480
+ index: -1,
1481
+ object: null,
1482
+ oldObject: variable,
1483
+ };
1484
+ if (parentKey) {
1485
+ params.parentKey = parentKey;
1486
+ // @ts-ignore
1487
+ const t = this.__v_raw || this;
1488
+ // @ts-ignore
1489
+ const n = variable.__v_raw || variable;
1490
+ if (Array.isArray((t as any)[parentKey])) {
1491
+ // @ts-ignore
1492
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1493
+ ~index && (this as any)[parentKey].splice(index, 1);
1494
+ params.index = index;
1495
+ } else {
1496
+ const q = (t as any)[parentKey];
1497
+ if ((q.__v_raw || q) === n) {
1498
+ params.index = 0;
1499
+ (this as any)[parentKey] = undefined;
1500
+ }
1501
+ }
1502
+ }
1503
+ return params;
1504
+ }
1505
+
1506
+ /**
1507
+ * 删除元素绑定事件
1508
+ * @param name 元素绑定事件名称
1509
+ */
1510
+ removeBindEvent(name: string): void;
1511
+
1512
+ /**
1513
+ * 删除元素绑定事件
1514
+ * @param bindEvent 已有的元素绑定事件实例
1515
+ */
1516
+ removeBindEvent(bindEvent: BindEvent): void;
1517
+
1518
+ removeBindEvent(options: string | BindEvent) {
1519
+ let bindEvent: BindEvent;
1520
+ if (typeof options === 'string') {
1521
+ bindEvent = (this.bindEvents as BindEvent[]).find((item) => item.name === options);
1522
+ if (!bindEvent) {
1523
+ throw new Error('找不到元素绑定事件 ' + options);
1524
+ }
1525
+ } else {
1526
+ bindEvent = options;
1527
+ }
1528
+ return bindEvent.delete();
1529
+ }
1530
+
1531
+ __removeBindEvent(bindEvent: BindEvent) {
1532
+ const parentKey = bindEvent.parentKey;
1533
+ const params: Params = {
1534
+ parentNode: this,
1535
+ parentKey,
1536
+ index: -1,
1537
+ object: null,
1538
+ oldObject: bindEvent,
1539
+ };
1540
+ if (parentKey) {
1541
+ params.parentKey = parentKey;
1542
+ // @ts-ignore
1543
+ const t = this.__v_raw || this;
1544
+ // @ts-ignore
1545
+ const n = bindEvent.__v_raw || bindEvent;
1546
+ if (Array.isArray((t as any)[parentKey])) {
1547
+ // @ts-ignore
1548
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1549
+ ~index && (this as any)[parentKey].splice(index, 1);
1550
+ params.index = index;
1551
+ } else {
1552
+ const q = (t as any)[parentKey];
1553
+ if ((q.__v_raw || q) === n) {
1554
+ params.index = 0;
1555
+ (this as any)[parentKey] = undefined;
1556
+ }
1557
+ }
1558
+ }
1559
+ return params;
1560
+ }
1561
+
1562
+ /**
1563
+ * 删除业务组件逻辑
1564
+ * @param name 业务组件逻辑名称
1565
+ */
1566
+ removeLogic(name: string): void;
1567
+
1568
+ /**
1569
+ * 删除业务组件逻辑
1570
+ * @param logic 已有的业务组件逻辑实例
1571
+ */
1572
+ removeLogic(logic: BusinessLogic): void;
1573
+
1574
+ removeLogic(options: string | BusinessLogic) {
1575
+ let logic: BusinessLogic;
1576
+ if (typeof options === 'string') {
1577
+ logic = (this.logics as BusinessLogic[]).find((item) => item.name === options);
1578
+ if (!logic) {
1579
+ throw new Error('找不到业务组件逻辑 ' + options);
1580
+ }
1581
+ } else {
1582
+ logic = options;
1583
+ }
1584
+ return logic.delete();
1585
+ }
1586
+
1587
+ __removeLogic(logic: Logic) {
1588
+ const parentKey = logic.parentKey;
1589
+ const params: Params = {
1590
+ parentNode: this,
1591
+ parentKey,
1592
+ index: -1,
1593
+ object: null,
1594
+ oldObject: logic,
1595
+ };
1596
+ if (parentKey) {
1597
+ params.parentKey = parentKey;
1598
+ // @ts-ignore
1599
+ const t = this.__v_raw || this;
1600
+ // @ts-ignore
1601
+ const n = logic.__v_raw || logic;
1602
+ if (Array.isArray((t as any)[parentKey])) {
1603
+ // @ts-ignore
1604
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1605
+ ~index && (this as any)[parentKey].splice(index, 1);
1606
+ params.index = index;
1607
+ } else {
1608
+ const q = (t as any)[parentKey];
1609
+ if ((q.__v_raw || q) === n) {
1610
+ params.index = 0;
1611
+ (this as any)[parentKey] = undefined;
1612
+ }
1613
+ }
1614
+ }
1615
+ return params;
1616
+ }
1617
+
1618
+ /**
1619
+ * 删除页面元素
1620
+ * @param name 页面元素名称
1621
+ */
1622
+ removeViewElement(name: string): void;
1623
+
1624
+ /**
1625
+ * 删除页面元素
1626
+ * @param viewElement 已有的页面元素实例
1627
+ */
1628
+ removeViewElement(viewElement: ViewElement): void;
1629
+
1630
+ removeViewElement(options: string | ViewElement) {
1631
+ let viewElement: ViewElement;
1632
+ if (typeof options === 'string') {
1633
+ viewElement = (this.elements as ViewElement[]).find((item) => item.name === options);
1634
+ if (!viewElement) {
1635
+ throw new Error('找不到页面元素 ' + options);
1636
+ }
1637
+ } else {
1638
+ viewElement = options;
1639
+ }
1640
+ return viewElement.delete();
1641
+ }
1642
+
1643
+ __removeViewElement(viewElement: ViewElement) {
1644
+ const parentKey = viewElement.parentKey;
1645
+ const params: Params = {
1646
+ parentNode: this,
1647
+ parentKey,
1648
+ index: -1,
1649
+ object: null,
1650
+ oldObject: viewElement,
1651
+ };
1652
+ if (parentKey) {
1653
+ params.parentKey = parentKey;
1654
+ // @ts-ignore
1655
+ const t = this.__v_raw || this;
1656
+ // @ts-ignore
1657
+ const n = viewElement.__v_raw || viewElement;
1658
+ if (Array.isArray((t as any)[parentKey])) {
1659
+ // @ts-ignore
1660
+ const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
1661
+ ~index && (this as any)[parentKey].splice(index, 1);
1662
+ params.index = index;
1663
+ } else {
1664
+ const q = (t as any)[parentKey];
1665
+ if ((q.__v_raw || q) === n) {
1666
+ params.index = 0;
1667
+ (this as any)[parentKey] = undefined;
1668
+ }
1669
+ }
1670
+ }
1671
+ return params;
1672
+ }
1673
+
1674
+ //================================================================================
1675
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1676
+ // 自动生成的代码已结束。下面可以手动编写。
1677
+ //================================================================================
1678
+ static getDefaultOptions() {
1679
+ return {
1680
+ title: '业务组件',
1681
+ };
1682
+ }
1683
+
1684
+ getNamespace(): string {
1685
+ if (this.parentNode && (this.parentNode as FrontendType).getNamespace) {
1686
+ const parentNamespace = (this.parentNode as FrontendType).getNamespace();
1687
+ const parentName = this.parentNode.name;
1688
+ const arr = [parentNamespace];
1689
+ if (this.parentNode.concept !== 'App' && parentName) {
1690
+ arr.push(parentName);
1691
+ }
1692
+ return `${arr.join('.')}.businessComponents`;
1693
+ }
1694
+ throw new Error('无法获取命名空间,请设置 parentNode!');
1695
+ }
1696
+
1697
+ getTsNamespace() {
1698
+ const parentNodeNamespace = this.getNamespace();
1699
+ let tsCalleeNamespace = parentNodeNamespace.replace(/\.[0-9]/g, (m) => m.replace('.', '.$'));
1700
+ tsCalleeNamespace = tsCalleeNamespace.replace(/-/g, '_');
1701
+ return tsCalleeNamespace;
1702
+ }
1703
+
1704
+ /**
1705
+ * 获取当前业务组件下所有elements上bindEvents下的logic
1706
+ */
1707
+ elementLogicRoot: any[] = [];
1708
+
1709
+ getElementLogicRoot() {
1710
+ const Param = getConceptConstructor('Param');
1711
+ const logics: Array<Logic> = [];
1712
+ // 页面上的绑定的事件
1713
+ this.bindEvents.forEach((bindEvent) => {
1714
+ bindEvent.logics.forEach((logic) => {
1715
+ // 键盘事件
1716
+ if (['keydown', 'keyup'].includes(bindEvent.name)) {
1717
+ logic.virtualParams = [
1718
+ Param.from(
1719
+ {
1720
+ name: 'event',
1721
+ typeAnnotation: null,
1722
+ },
1723
+ logic,
1724
+ 'virtualParams',
1725
+ ),
1726
+ ];
1727
+ }
1728
+ // 生命周期没有event
1729
+ logics.push(logic);
1730
+ });
1731
+ });
1732
+ this.elements.forEach((item) => {
1733
+ utils.traverse(
1734
+ (current) => {
1735
+ current.node.bindEvents.forEach((bindEvent) => {
1736
+ bindEvent.logics.forEach((logic) => {
1737
+ if (logic.name.startsWith('__')) {
1738
+ return;
1739
+ }
1740
+ // 绑定参数才有 event 的 current
1741
+ logic.virtualParams = bindEvent.getContextRenderLogicParams(logic);
1742
+ logics.push(logic);
1743
+ });
1744
+ });
1745
+ },
1746
+ { node: item },
1747
+ );
1748
+ });
1749
+ if (logics.length) {
1750
+ const expanded = (this.elementLogicRoot.length && this.elementLogicRoot[0].expanded) || false;
1751
+ this.elementLogicRoot = [
1752
+ {
1753
+ concept: 'elementLogicRoot',
1754
+ expanded,
1755
+ children: logics,
1756
+ },
1757
+ ];
1758
+ } else {
1759
+ this.elementLogicRoot = [];
1760
+ }
1761
+ }
1762
+
1763
+ getVarExistingNames(excludedList: Array<Param | Variable> = []) {
1764
+ const excludedSet = new Set(excludedList);
1765
+ const varList: any[] = [];
1766
+ if (Array.isArray(this.params)) {
1767
+ varList.push(...this.params);
1768
+ }
1769
+ if (Array.isArray(this.variables)) {
1770
+ varList.push(...this.variables);
1771
+ }
1772
+ if (Array.isArray(this.logics)) {
1773
+ this.logics.forEach((logic) => {
1774
+ varList.push(logic);
1775
+ if (Array.isArray(logic.params)) {
1776
+ varList.push(...logic.params);
1777
+ }
1778
+ if (Array.isArray(logic.returns)) {
1779
+ varList.push(...logic.returns);
1780
+ }
1781
+ if (Array.isArray(logic.variables)) {
1782
+ varList.push(...logic.variables);
1783
+ }
1784
+ });
1785
+ }
1786
+ // 事件逻辑的变量不允许和页面逻辑下的重复
1787
+ if (Array.isArray(this.elementLogicRoot) && this.elementLogicRoot.length) {
1788
+ this.elementLogicRoot[0]?.children.forEach((logic: Logic) => {
1789
+ if (Array.isArray(logic.variables)) {
1790
+ varList.push(...logic.variables);
1791
+ }
1792
+ });
1793
+ }
1794
+ return varList.filter((item) => !excludedSet.has(item)).map((item) => item.name);
1795
+ }
1796
+
1797
+ existingViewElement: Set<string> = new Set<string>();
1798
+
1799
+ // 收集已经存在的ViewElement
1800
+ collectExistingViewElementName(excludedList: Array<ViewElement> = []) {
1801
+ const excludedSet = new Set(excludedList);
1802
+ this.elements.forEach((element) => {
1803
+ utils.traverse(
1804
+ ({ node }) => {
1805
+ if (!excludedSet.has(node)) {
1806
+ this.existingViewElement.add(node.name);
1807
+ }
1808
+ },
1809
+ {
1810
+ node: element,
1811
+ },
1812
+ );
1813
+ });
1814
+ }
1815
+
1816
+ // 获取当前业务组件的所有组件的名字
1817
+ getViewElementExistingNames(excludedList: Array<ViewElement> = []) {
1818
+ if (!this.existingViewElement.size) {
1819
+ this.collectExistingViewElementName();
1820
+ }
1821
+ return Array.from(this.existingViewElement);
1822
+ }
1823
+
1824
+ getViewElementUniqueNameOld(name = 'viewElement1') {
1825
+ this.collectExistingViewElementName();
1826
+ const viewElementUniqueName = utils.unique(name, this.existingViewElement);
1827
+ this.existingViewElement.add(viewElementUniqueName);
1828
+ return viewElementUniqueName;
1829
+ }
1830
+
1831
+ getViewElementUniqueName(name = 'viewElement_1') {
1832
+ this.collectExistingViewElementName();
1833
+ const BranchCopyUniCode = getBranchCopyUniCode();
1834
+ let newName = name;
1835
+ const prefix = name.replace(/\d*$/, '');
1836
+ if (BranchCopyUniCode && prefix.indexOf(`_${BranchCopyUniCode}_`) === -1) {
1837
+ newName = name.replace(/\d*$/, (m) => `_${BranchCopyUniCode}_${m}`);
1838
+ }
1839
+ // 主分支无 BranchCopyUniCode
1840
+ if (!BranchCopyUniCode && prefix.at(-1) !== '_') {
1841
+ newName = name.replace(/\d*$/, (m) => `_${m}`);
1842
+ }
1843
+ const newPrefix = newName.replace(/\d*$/, '');
1844
+ const newPrefixNum = removedViewElementCache?.[newPrefix] ? removedViewElementCache[newPrefix] : 1;
1845
+ const startNum =
1846
+ newPrefixNum < Number.MAX_SAFE_INTEGER ? (newPrefixNum as number) + 1 : BigInt(newPrefixNum) + BigInt(1);
1847
+ const viewElementUniqueName = utils.uniqueMax(
1848
+ newName,
1849
+ this.existingViewElement,
1850
+ removedViewElementCache?.[newPrefix] ? startNum : newPrefixNum,
1851
+ );
1852
+ this.existingViewElement.add(viewElementUniqueName);
1853
+ return viewElementUniqueName;
1854
+ }
1855
+
1856
+ // 获取当前element,铺平
1857
+ elementsMethods(elements: Array<ViewElement>, allMethods: Array<ViewElement>, parentNodeNames: Array<string>) {
1858
+ if (elements) {
1859
+ elements.forEach((item: ViewElement) => {
1860
+ const { bindAttrs = [], name } = item;
1861
+ const isDataSource = bindAttrs.some((attr) => attr.name === 'data-source');
1862
+ const isInclude = parentNodeNames.includes(name);
1863
+
1864
+ allMethods.push(item);
1865
+ if (item.children) {
1866
+ if (isDataSource) {
1867
+ if (isInclude) {
1868
+ this.elementsMethods(item.children, allMethods, parentNodeNames);
1869
+ }
1870
+ } else {
1871
+ this.elementsMethods(item.children, allMethods, parentNodeNames);
1872
+ }
1873
+ }
1874
+ });
1875
+ }
1876
+ }
1877
+
1878
+ mergeBlock({ code, nodePath, position, cb }: { code: string; nodePath: string; position: string; cb?: Function }) {
1879
+ const ViewElement = getConceptConstructor('ViewElement');
1880
+ const Logic = getConceptConstructor('Logic');
1881
+ const ParamWithGroup = getConceptConstructor('ParamWithGroup');
1882
+ const Variable = getConceptConstructor('Variable');
1883
+ const BindEvent = getConceptConstructor('BindEvent');
1884
+ const Structure = getConceptConstructor('Structure');
1885
+ const template = utils.sliceTagContent(code, 'template');
1886
+ let targetNode = (this.getAncestor('App') as App)?.findNodeByPath(nodePath);
1887
+ let parentNode = position === 'append' ? targetNode : targetNode.parentNode;
1888
+ const definitionStr = utils.sliceTagContent(code, 'definition') || '{}';
1889
+ const definition: any = JSON.parse(definitionStr);
1890
+ let node = null;
1891
+ if (template) {
1892
+ node = ViewElement.fromHTML(template, {
1893
+ view: this,
1894
+ definition,
1895
+ });
1896
+ if (!parentNode) {
1897
+ return;
1898
+ }
1899
+ if (position === 'append') {
1900
+ parentNode.addViewElement(node);
1901
+ cb && cb(parentNode, node);
1902
+ } else {
1903
+ const index = targetNode.getIndexOfParent();
1904
+ if (position === 'insertBefore') {
1905
+ parentNode.insertViewElementAt(node, index);
1906
+ } else if (position === 'insertAfter') {
1907
+ parentNode.insertViewElementAt(node, index + 1);
1908
+ }
1909
+ }
1910
+ }
1911
+
1912
+ // 服务端逻辑
1913
+ if (Array.isArray(definition.logics)) {
1914
+ definition.logics.forEach((logicOption: any) => {
1915
+ const logic = Logic.from(
1916
+ {
1917
+ ...logicOption,
1918
+ },
1919
+ this.rootNode,
1920
+ 'logics',
1921
+ );
1922
+ (this.rootNode as App).addLogic(logic);
1923
+ });
1924
+ }
1925
+
1926
+ // 全局结构体
1927
+ if (Array.isArray(definition.structures)) {
1928
+ definition.structures.forEach((structureOption: any) => {
1929
+ const structure = Structure.from(
1930
+ {
1931
+ ...structureOption,
1932
+ },
1933
+ this.rootNode,
1934
+ 'structures',
1935
+ );
1936
+ (this.rootNode as App).addStructure(structure);
1937
+ });
1938
+ }
1939
+
1940
+ // 页面入参
1941
+ if (Array.isArray(definition.viewParams)) {
1942
+ definition.viewParams.forEach((paramsOption: any) => {
1943
+ const param = ParamWithGroup.from(
1944
+ {
1945
+ ...paramsOption,
1946
+ },
1947
+ this,
1948
+ 'params',
1949
+ );
1950
+ this._addParam(param);
1951
+ param.addParamsPrepare();
1952
+ });
1953
+ }
1954
+ // 页面变量
1955
+ if (Array.isArray(definition.viewVariables)) {
1956
+ definition.viewVariables.forEach((variableOption: any) => {
1957
+ const variable = Variable.from(
1958
+ {
1959
+ ...variableOption,
1960
+ },
1961
+ this,
1962
+ 'variables',
1963
+ );
1964
+ this.addVariable(variable);
1965
+ });
1966
+ }
1967
+
1968
+ // 页面事件
1969
+ if (Array.isArray(definition.viewBindEvents)) {
1970
+ definition.viewBindEvents.forEach((eventOption: any) => {
1971
+ const newLogic = definition.viewLogics.find((logic: Logic) => eventOption.calleeName === logic.name);
1972
+ const bindEvent = this.bindEvents.find((currentEventItem) => currentEventItem.name === eventOption.name);
1973
+
1974
+ // 如果没有event对象就先新增一个,如果已经有了就在内部添加logic
1975
+ if (!bindEvent) {
1976
+ const event = BindEvent.from(
1977
+ {
1978
+ ...eventOption,
1979
+ calleeName: '',
1980
+ logics: [newLogic],
1981
+ },
1982
+ this,
1983
+ 'events',
1984
+ );
1985
+ this.addBindEvent(event);
1986
+ } else {
1987
+ bindEvent.addLogic(newLogic);
1988
+ }
1989
+ });
1990
+ }
1991
+ return node;
1992
+ }
1993
+
1994
+ onChange($event?: EventPayload): void {
1995
+ this.emit('change', $event);
1996
+ }
1997
+
1998
+ /**
1999
+ * 转换成设计器中使用的 Vue template 内容
2000
+ * @param options
2001
+ */
2002
+ genDesignerVueTemplate(options?: { asCompontent?: boolean }) {
2003
+ return this.elements
2004
+ .map(
2005
+ (element) =>
2006
+ `${element.toDesignerVue({
2007
+ isRoot: true,
2008
+ asCompontent: options?.asCompontent,
2009
+ })}\n`,
2010
+ )
2011
+ .join('');
2012
+ }
2013
+
2014
+ get frontendType() {
2015
+ return this.getAncestor('FrontendType') as FrontendType;
2016
+ }
2017
+
2018
+ get path() {
2019
+ return `/${this.frontendType?.kind}/${this.name}`;
2020
+ }
2021
+
2022
+ get slotElems() {
2023
+ const slotElems: ViewElement[] = [];
2024
+ this.elements.forEach((element) => {
2025
+ utils.traverse(
2026
+ ({ node }) => {
2027
+ if (node.tag === 'slot') {
2028
+ slotElems.push(node);
2029
+ }
2030
+ },
2031
+ {
2032
+ node: element,
2033
+ },
2034
+ );
2035
+ });
2036
+ return slotElems;
2037
+ }
2038
+
2039
+ /**
2040
+ * 生成宿主语言的文件路径
2041
+ * @param name 一般不用传,用于 rename
2042
+ */
2043
+ getEmbeddedFilePath(name = this.name) {
2044
+ return `/embedded/${this.rootNode?.name || this.parentNode.name}/frontendTypes/${this.getAncestor('FrontendType')?.name
2045
+ }/${name}.ts`;
2046
+ }
2047
+
2048
+ *toEmbeddedTSFile(): EmbeddedTSFileGenerator {
2049
+ let code = `namespace ${this.getTsNamespace()} {\n`;
2050
+ const state = createCompilerState(code, {
2051
+ tabSize: 1,
2052
+ });
2053
+
2054
+ try {
2055
+ code += yield* this.toEmbeddedTS(state);
2056
+ } catch (err) {
2057
+ code += '';
2058
+ console.log(err);
2059
+ }
2060
+
2061
+ code += '}\n';
2062
+
2063
+ return {
2064
+ code,
2065
+ filePath: this.getEmbeddedFilePath(),
2066
+ sourceMap: state.sourceMap,
2067
+ };
2068
+ }
2069
+
2070
+ getAncestorViewElementsWithDataSource(logic: Logic): ViewElement[] {
2071
+ let element: types.SyntaxNode = logic;
2072
+ const viewElements: ViewElement[] = [];
2073
+ while (element) {
2074
+ if (
2075
+ element.concept &&
2076
+ element.concept === 'ViewElement' &&
2077
+ (element as ViewElement).bindAttrs.find((bAttr) => bAttr.name === 'data-source')
2078
+ ) {
2079
+ viewElements.push(element as ViewElement);
2080
+ }
2081
+ element = element.parentNode;
2082
+ }
2083
+ return viewElements;
2084
+ }
2085
+
2086
+ *handleCurrentItemCode(code: string, logic: Logic) {
2087
+ const viewElementsWithDataSource: ViewElement[] = this.getAncestorViewElementsWithDataSource(logic);
2088
+ yield* wrapForEach(viewElementsWithDataSource, function* wrapForEach(viewElement, index) {
2089
+ const currentIndex = viewElementsWithDataSource.length - 1 - index;
2090
+ const currentItemCode = `current${currentIndex === 0 ? '' : currentIndex}.item`;
2091
+ if (code.includes(currentItemCode)) {
2092
+ const dataSource = viewElement.bindAttrs.find((bAttr) => bAttr.name === 'data-source');
2093
+ if (dataSource) {
2094
+ const businessComponent = viewElement.getAncestor('BusinessComponent') as BusinessComponent;
2095
+ const dataSourceTS = yield* dataSource.expression.toEmbeddedTS();
2096
+ const logic = businessComponent.logics.find((logic) => logic.name === dataSourceTS);
2097
+ if (logic) {
2098
+ code = code.replaceAll(
2099
+ currentItemCode,
2100
+ `nasl.ui.getCurrentItemType(${dataSourceTS}(${logic.params.map(() => 'null').join(',')}))`,
2101
+ );
2102
+ } else {
2103
+ const variable = businessComponent.variables.find((variable) => variable.name === dataSourceTS);
2104
+ code = code.replaceAll(
2105
+ currentItemCode,
2106
+ `nasl.ui.getCurrentItemType(${variable ? variable.name : dataSourceTS})`,
2107
+ );
2108
+ }
2109
+ }
2110
+ }
2111
+ });
2112
+ return code;
2113
+ }
2114
+
2115
+ removeExistingViewElement(viewElement: ViewElement) {
2116
+ if (this.existingViewElement.has(viewElement.name)) {
2117
+ this.existingViewElement.delete(viewElement.name);
2118
+ }
2119
+
2120
+ const prefix = viewElement?.name.replace(/\d*$/, '');
2121
+ let lastDigit = viewElement?.name.match(/\d+$/)?.[0];
2122
+ if (lastDigit === undefined) return;
2123
+
2124
+ //@ts-ignore
2125
+ lastDigit = lastDigit < Number.MAX_SAFE_INTEGER ? parseInt(lastDigit) : BigInt(lastDigit);
2126
+
2127
+ if (removedViewElementCache?.[prefix]) {
2128
+ //@ts-ignore
2129
+ if (lastDigit > removedViewElementCache[prefix])
2130
+ //@ts-ignore
2131
+ removedViewElementCache[prefix] = lastDigit;
2132
+ } else {
2133
+ //@ts-ignore
2134
+ removedViewElementCache[prefix] = lastDigit;
2135
+ }
2136
+ }
2137
+
2138
+ *getRightCode(code: string, assignment: Assignment | BatchAssignment, rightNode: any) {
2139
+ code = code.replaceAll('\n', ' ');
2140
+ const logic = assignment.logic;
2141
+ const logicRtn = logic?.returns[0];
2142
+ // 调用接口,参数替换成 null
2143
+ if (asserts.isCallInterface(rightNode)) {
2144
+ const { _interface } = rightNode.getModuleInterface();
2145
+ return _interface
2146
+ ? `${rightNode.tsCalleeKey}(${(_interface as Interface).params.map(() => 'null').join(',')})`
2147
+ : null;
2148
+ }
2149
+
2150
+ // 调用服务端逻辑,参数替换成 null
2151
+ if (asserts.isCallLogic(rightNode) && rightNode.calleeNamespace === 'app.logics') {
2152
+ const calleeName = rightNode?.calleeName;
2153
+ const calleeLogic = (this.getAncestor('App') as App).logics.find((l) => l.name === calleeName);
2154
+ return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
2155
+ }
2156
+
2157
+ // view 局部变量,申明提升前增加判断,使用 logic 内的 result 直接替换成对应 logic,logic 内部变量替换成 null
2158
+ if (logicRtn && code.includes(logicRtn.name)) {
2159
+ if (code === logicRtn.name) return `${logic.name}(${logic.params.map(() => 'null').join(',')})`;
2160
+
2161
+ code = this.handleReplaceCode(code, logicRtn.name, `${logic.name}(${logic.params.map(() => 'null').join(',')})`);
2162
+ logic.params.forEach((param) => {
2163
+ if (code.includes(param.name)) code = this.handleReplaceCode(code, param.name, 'null');
2164
+ });
2165
+ logic.variables.forEach((variable) => {
2166
+ if (code.includes(variable.name)) code = this.handleReplaceCode(code, variable.name, 'null');
2167
+ });
2168
+ return code;
2169
+ }
2170
+
2171
+ // 处理 current.item、current1.item 等数据
2172
+ if (/current(\d)*\.item/.test(code)) {
2173
+ code = yield* this.handleCurrentItemCode(code, logic);
2174
+ return code;
2175
+ }
2176
+
2177
+ // 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
2178
+ const useLogicVar =
2179
+ logic.params.find((param) => code.includes(param.name)) ||
2180
+ logic.variables.find((variable) => code.includes(variable.name));
2181
+ return useLogicVar ? 'null' : code;
2182
+ }
2183
+
2184
+ handleReplaceCode(code: string, variable: string, replaceCode: string) {
2185
+ return code.replace(/\S+/g, ($1) => {
2186
+ if ($1 === `${variable},`) return `${replaceCode},`;
2187
+ if ($1 === variable) return replaceCode;
2188
+
2189
+ let fnCode = $1;
2190
+ if ($1.startsWith(`${variable}.`)) fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
2191
+ if ($1.startsWith(`${variable},`)) fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
2192
+ if ($1.includes(`(${variable},`)) fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
2193
+ if ($1.includes(`(${variable}.`)) fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
2194
+ if ($1.includes(`(${variable})`)) fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
2195
+ if ($1.includes(`,${variable},`)) fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
2196
+ if ($1.includes(`,${variable}.`)) fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
2197
+ if ($1.includes(`,${variable})`)) fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
2198
+ return fnCode;
2199
+ });
2200
+ }
2201
+
2202
+ // 获取当前element,铺平
2203
+ elementsAttrs(elements: Array<ViewElement>, componentList: Array<ViewElement>) {
2204
+ if (elements) {
2205
+ elements.forEach((item: ViewElement) => {
2206
+ if (PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
2207
+ componentList.push(item);
2208
+ }
2209
+ if (item.children.length > 0) {
2210
+ this.elementsAttrs(item.children, componentList);
2211
+ }
2212
+ });
2213
+ }
2214
+ }
2215
+
2216
+ elementsAttrsAll(elements: Array<ViewElement>, componentListExtra: Array<ViewElement>) {
2217
+ if (elements) {
2218
+ elements.forEach((item: ViewElement) => {
2219
+ if (!PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
2220
+ componentListExtra.push(item);
2221
+ }
2222
+ if (item.children.length > 0) {
2223
+ this.elementsAttrsAll(item.children, componentListExtra);
2224
+ }
2225
+ });
2226
+ }
2227
+ }
2228
+
2229
+ @withSourceMapGenerator
2230
+ *toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
2231
+ const self = this;
2232
+ // 获取虚拟logic的参数和内容
2233
+ // 用作展示和tots查找引用
2234
+ self.getElementLogicRoot();
2235
+ let code = `export class ${self.tsName} extends nasl.ui.VueComponent {\n`;
2236
+ // 需要类型推导的局部变量/返回值需要调整申明顺序
2237
+ code += `constructor(
2238
+ options?: {
2239
+ [propname: string]: any,
2240
+ bindAttr?: {
2241
+ __NASLIF?: nasl.core.Boolean,
2242
+ `;
2243
+ if (Array.isArray(self.params)) {
2244
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2245
+ code += `${param.name}?: `;
2246
+ code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2247
+ code += ',\n';
2248
+ });
2249
+ }
2250
+ code += `
2251
+ },
2252
+ slotDefault?: () => Array<any>,
2253
+ }) {
2254
+ super();\n`;
2255
+
2256
+ // 绑定事件
2257
+ if (Array.isArray(self.bindEvents)) {
2258
+ yield* wrapForEach(self.bindEvents, function* warpForEachGenerator(event) {
2259
+ code += yield* event.toEmbeddedTS(
2260
+ shiftState(state, code, {
2261
+ tabSize: state?.tabSize || 0,
2262
+ }),
2263
+ true,
2264
+ );
2265
+ code += '\n';
2266
+ });
2267
+ }
2268
+ code += `\n}`;
2269
+ // 自定义事件的定义
2270
+ if (Array.isArray(self.events) && self.events.length) {
2271
+ code += indent((state?.tabSize || 0) + 1);
2272
+ yield* wrapForEach(self.events, function* warpForEachGenerator(event) {
2273
+ code += yield* event.toEmbeddedTS(
2274
+ shiftState(state, code, {
2275
+ tabSize: (state?.tabSize || 0) + 2,
2276
+ }),
2277
+ );
2278
+ code += '\n';
2279
+ });
2280
+ code += indent((state?.tabSize || 0) + 1);
2281
+ }
2282
+ // 逻辑
2283
+ if (Array.isArray(self.logics) && self.logics.length) {
2284
+ code += indent((state?.tabSize || 0) + 1);
2285
+ yield* wrapForEach(self.logics, function* warpForEachGenerator(logic) {
2286
+ code += yield* logic.toEmbeddedTS(
2287
+ shiftState(state, code, {
2288
+ tabSize: (state?.tabSize || 0) + 2,
2289
+ }),
2290
+ 'noExport',
2291
+ );
2292
+ code += '\n';
2293
+ });
2294
+ code += indent((state?.tabSize || 0) + 1);
2295
+ }
2296
+ // render函数
2297
+ code += `\n${indent((state?.tabSize || 0) + 1)}`;
2298
+ code += `__render(`;
2299
+ code += `){\n`;
2300
+ code += indent(state?.tabSize || 0);
2301
+ // elements 元素
2302
+ if (Array.isArray(self.elements)) {
2303
+ // 生成嵌套式的内容
2304
+ yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
2305
+ code += yield* element.toEmbeddedTS(
2306
+ shiftState(state, code, {
2307
+ tabSize: (state?.tabSize || 0) + 3,
2308
+ }),
2309
+ );
2310
+ code += '\n';
2311
+ });
2312
+ }
2313
+ code += `\n${indent((state?.tabSize || 0) + 1)}}\n`;
2314
+ if (Array.isArray(self.params)) {
2315
+ code += `${indent((state?.tabSize || 0) + 1)}$destination(options: {`;
2316
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2317
+ code += `${param.name}?: `;
2318
+ code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2319
+ code += ', ';
2320
+ });
2321
+ // 锚点
2322
+ code += `_anchor?: nasl.core.String`;
2323
+ code += '}){}\n';
2324
+ }
2325
+ code += `${indent(state?.tabSize || 0)}}\n`;
2326
+
2327
+ // elements类型声明定义
2328
+ code += `interface __elements {\n`;
2329
+ // 生成所有的name和类型定义
2330
+ yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
2331
+ code += yield* element.toEmbeddedTSDefinition(
2332
+ shiftState(state, code, {
2333
+ tabSize: (state?.tabSize || 0) + 1,
2334
+ }),
2335
+ );
2336
+ });
2337
+ code += `${indent((state?.tabSize || 0) + 1)}}\n`;
2338
+ code += `let __elements: __elements;\n`;
2339
+
2340
+ if (Array.isArray(self.elements)) {
2341
+ code += `${indent((state?.tabSize || 0) + 1)}interface `;
2342
+ code += `__elements_completionProperty {\n`;
2343
+ const componentList: Array<ViewElement> = [];
2344
+ self.elementsAttrs(self.elements, componentList);
2345
+ const variableList: string[] = [];
2346
+ yield* wrapForEach(self.elements, function* warpForEachGenerator(item) {
2347
+ code += yield* item.toEmbeddedTSVariableDefinition(shiftState(state, code, { inline: true }), variableList);
2348
+ });
2349
+ code += indent((state?.tabSize || 0) + 1) + `}\n`;
2350
+ code += indent((state?.tabSize || 0) + 1);
2351
+ code += `let __elements_completionProperty: __elements_completionProperty;\n`;
2352
+ code += indent((state?.tabSize || 0) + 1);
2353
+ code += `let __elements_variable_function = {\n`;
2354
+ yield* wrapForEach(self.elements, function* warpForEachGenerator(item) {
2355
+ code += yield* item.toEmbeddedTSVariableFunctionDefinition(shiftState(state, code, { inline: true }));
2356
+ });
2357
+ code += indent((state?.tabSize || 0) + 1) + `}\n`;
2358
+ code += indent((state?.tabSize || 0) + 1);
2359
+ code += `let __elements_stashFunctionVariable = {\n`;
2360
+ yield* wrapForEach(variableList, function* warpForEachGenerator(item) {
2361
+ code += indent((state?.tabSize || 0) + 2);
2362
+ code += `${item}`;
2363
+ });
2364
+ code += indent((state?.tabSize || 0) + 1) + `}\n`;
2365
+ }
2366
+
2367
+ const advanceMap: Map<Variable, Assignment | BatchAssignment> = new Map();
2368
+ yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
2369
+ if (el && (asserts.isBatchAssignment(el) || (asserts.isAssignment(el) && el.left?.name))) {
2370
+ if (asserts.isAssignment(el)) {
2371
+ const advanceVar = self.variables?.find(
2372
+ (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
2373
+ );
2374
+ if (advanceVar && !advanceMap.get(advanceVar)) {
2375
+ advanceMap.set(advanceVar, el);
2376
+ }
2377
+ } else if (asserts.isBatchAssignment(el)) {
2378
+ yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
2379
+ const leftCode =
2380
+ leftIndex.length === 1
2381
+ ? yield* el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2382
+ returnOrigin('')
2383
+ : yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2384
+ returnOrigin('');
2385
+ const advanceVar = self.variables?.find(
2386
+ (variable) => !variable.typeAnnotation && leftCode === variable.name,
2387
+ );
2388
+ if (advanceVar && !advanceMap.get(advanceVar)) {
2389
+ advanceMap.set(advanceVar, el);
2390
+ }
2391
+ });
2392
+ }
2393
+ }
2394
+ });
2395
+
2396
+ // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
2397
+ const IDENTIFIERMAP = new Set<Variable>();
2398
+ if (Array.isArray(self.params)) {
2399
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param) {
2400
+ code += `let ${indent((state?.tabSize || 0) + 1)}`;
2401
+ code += yield* param.toEmbeddedTS(shiftState(state, code, { inline: true }));
2402
+ code += ';\n';
2403
+ });
2404
+ }
2405
+ if (Array.isArray(self.variables)) {
2406
+ yield* wrapForEach(self.variables, function* warpForEachGenerator(variable) {
2407
+ const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? returnOrigin('');
2408
+ if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
2409
+ IDENTIFIERMAP.add(variable);
2410
+ }
2411
+ if (!advanceMap.get(variable)) {
2412
+ code += `let ${indent((state?.tabSize || 0) + 1)}`;
2413
+ code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
2414
+ code += ';\n';
2415
+ }
2416
+ });
2417
+ }
2418
+ yield* wrapIterator(advanceMap.entries(), function* warpForEachGenerator([variable, assignment]) {
2419
+ // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
2420
+ if (variable.defaultValue?.expression && !IDENTIFIERMAP.has(variable)) {
2421
+ code += `let ${indent((state?.tabSize || 0) + 1)}`;
2422
+ code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
2423
+ return;
2424
+ }
2425
+ code += `${indent((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
2426
+ code += `let ${indent((state?.tabSize || 0) + 1)}`;
2427
+ code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
2428
+ code += ' = ';
2429
+ if (asserts.isBatchAssignment(assignment)) {
2430
+ yield* wrapForEach(assignment.assignmentLines, function* warpForEachGenerator({ leftIndex, rightIndex }) {
2431
+ const leftCode =
2432
+ leftIndex.length === 1
2433
+ ? yield* assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
2434
+ : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2435
+ returnOrigin('');
2436
+ if (leftCode === variable.name) {
2437
+ const rightNode =
2438
+ rightIndex.length === 1
2439
+ ? assignment.rights[rightIndex[0]]?.expression
2440
+ : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
2441
+ const rightCode = yield* rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2442
+ returnOrigin('');
2443
+ code += yield* self.getRightCode(rightCode, assignment, rightNode);
2444
+ }
2445
+ });
2446
+ } else {
2447
+ let rightCode = '';
2448
+ // 因为右侧枚举要赋值就得new 一下;
2449
+ if (
2450
+ assignment.right &&
2451
+ asserts.isIdentifier(assignment.right) &&
2452
+ assignment.right.namespace &&
2453
+ assignment.right.namespace.endsWith('enums')
2454
+ ) {
2455
+ rightCode += 'new ';
2456
+ }
2457
+ rightCode +=
2458
+ assignment.right && assignment.right.toEmbeddedTS
2459
+ ? yield* assignment.right.toEmbeddedTS(shiftState(state, code, { inline: true }))
2460
+ : '__RIGHT__';
2461
+ code += yield* self.getRightCode(rightCode, assignment, assignment.right);
2462
+ }
2463
+ code += ';\n';
2464
+ });
2465
+
2466
+ /* 默认值草稿区 ---------------------------*/
2467
+ code += `${indent((state?.tabSize || 0) + 1)}function __playground(){\n`;
2468
+
2469
+ /* 参数的默认值是__IDENTIFIER__或者__IDENTIFIER__()时不赋默认值,但是需要ts翻译出来进行报错校验 */
2470
+ for (const node of IDENTIFIERMAP.values()) {
2471
+ code += `${indent((state?.tabSize || 0) + 2)}`;
2472
+ code += yield* node.defaultValue.toEmbeddedTS(shiftState(state, code, { inline: true }));
2473
+ code += '; ';
2474
+ }
2475
+
2476
+ code += '\n';
2477
+ code += `${indent((state?.tabSize || 0) + 2)}return\n`;
2478
+
2479
+ function* setPlaygroundCode(arr: Variable[] | ParamWithGroup[], name: string) {
2480
+ if (arr.length) {
2481
+ code += `${indent((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
2482
+ }
2483
+
2484
+ for (const item1 of arr) {
2485
+ for (const item of item1.defaultValue?.playground ?? []) {
2486
+ code += yield* item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
2487
+ code += ';\n';
2488
+ }
2489
+ }
2490
+ }
2491
+ yield* setPlaygroundCode(self.variables, 'variables');
2492
+ yield* setPlaygroundCode(self.params, 'params');
2493
+
2494
+ code += `${indent((state?.tabSize || 0) + 1)}}\n`;
2495
+ return code;
2496
+ }
2497
+
2498
+ /**
2499
+ * 转换成 VueOptions
2500
+ * @TODO 后面 template 可以优化成 render 函数
2501
+ */
2502
+ toVueOptions(options?: ElementToVueOptions) {
2503
+ return {
2504
+ template: this.genVueTemplate(options),
2505
+ script: this.genScript(),
2506
+ };
2507
+ }
2508
+
2509
+ genVueTemplate(options?: ElementToVueOptions) {
2510
+ return this.elements?.map((element) => `${element?.toVue(options)}\n`).join('');
2511
+ }
2512
+
2513
+ getViewBindEvents() {
2514
+ const bindEvents: Array<BindEvent> = [];
2515
+ // 页面上的绑定的事件
2516
+ this.bindEvents.forEach((bindEvent) => {
2517
+ bindEvents.push(bindEvent);
2518
+ });
2519
+ this.elements.forEach((item) => {
2520
+ utils.traverse(
2521
+ (current) => {
2522
+ current.node.bindEvents.forEach((bindEvent) => {
2523
+ bindEvents.push(bindEvent);
2524
+ });
2525
+ },
2526
+ { node: item },
2527
+ );
2528
+ });
2529
+ return bindEvents;
2530
+ }
2531
+
2532
+ // 获取页面上需要替换的表达式
2533
+ getViewExpressions() {
2534
+ const bindExpressions: any[] = [];
2535
+ this.elements.forEach((item) => {
2536
+ utils.traverse(
2537
+ (current) => {
2538
+ const { node } = current as any;
2539
+ const playgroundNodePath = (node?.nodePath || '').split('.').find((nodePathNode: string) => {
2540
+ return nodePathNode.match(/(.+)\[.+\]/)?.[1] === 'playground';
2541
+ });
2542
+ if (!playgroundNodePath) {
2543
+ //// 处理三种情况
2544
+ //if (
2545
+ // ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
2546
+ // && node.needReplaceWithIdentifier
2547
+ //) {
2548
+ // bindExpressions.push(node);
2549
+ //}
2550
+ if (node?.concept === 'Match') {
2551
+ bindExpressions.push(node as Match);
2552
+ }
2553
+ }
2554
+ },
2555
+ {
2556
+ node: item,
2557
+ },
2558
+ {
2559
+ mode: 'anyObject',
2560
+ depthFirst: true,
2561
+ excludedKeySet: new Set([
2562
+ 'bindEvents',
2563
+ 'parentNode',
2564
+ 'sourceMap',
2565
+ 'storageJSON',
2566
+ 'tsErrorDetail',
2567
+ 'NaslAnnotatedJSON',
2568
+ 'calledFrom',
2569
+ '_events',
2570
+ '_collectingList',
2571
+ '_historyList',
2572
+ ]),
2573
+ },
2574
+ );
2575
+ });
2576
+ return bindExpressions;
2577
+ }
2578
+
2579
+ /**
2580
+ * 生成 Vue 中需要的 JS 代码
2581
+ * @TODO 这一版先做成 componentOptions 式的,后面再美化
2582
+ */
2583
+ genScript() {
2584
+ const componentList: Array<ViewElement> = [];
2585
+ const componentListExtra: Array<ViewElement> = [];
2586
+ this.elementsAttrs(this.elements, componentList);
2587
+ this.elementsAttrsAll(this.elements, componentListExtra);
2588
+ const definition = {
2589
+ params: this.params,
2590
+ variables: this.variables,
2591
+ logics: this.logics,
2592
+ events: this.bindEvents,
2593
+ title: this.title,
2594
+ viewBindEvents: this.getViewBindEvents(),
2595
+ viewExpressions: this.getViewExpressions(),
2596
+ elements: componentList,
2597
+ elementsAll: componentListExtra,
2598
+ };
2599
+ let code = '';
2600
+ const keyboardEventMixinCode = `const keyboardEventMixin = {
2601
+ mounted() {
2602
+ document.addEventListener('keydown', this.onKeyDown);
2603
+ document.addEventListener('keyup', this.onKeyUp);
2604
+ },
2605
+ beforeDestory() {
2606
+ document.removeEventListener('keydown', this.onKeyDown);
2607
+ document.removeEventListener('keyup', this.onKeyUp);
2608
+ },
2609
+ methods: {
2610
+ async onKeyDown(e) {
2611
+ ${this.bindEvents
2612
+ .filter((event) => ['keydown'].includes(event.name))
2613
+ .map((event) => `await this.${event.view.name}_${event.name}(e);`)
2614
+ .join('\n')}
2615
+ },
2616
+ async onKeyUp(e) {
2617
+ ${this.bindEvents
2618
+ .filter((event) => ['keyup'].includes(event.name))
2619
+ .map((event) => `await this.${event.view.name}_${event.name}(e);`)
2620
+ .join('\n')}
2621
+ }
2622
+ }
2623
+ };\n`;
2624
+ code += keyboardEventMixinCode;
2625
+ code += 'export default {\n';
2626
+ code += 'mixins: [';
2627
+ const mixins = [];
2628
+ // 键盘事件mixin
2629
+ mixins.push('keyboardEventMixin');
2630
+ code += mixins.join(',');
2631
+ code += '],';
2632
+ code += translator(definition, this);
2633
+ code += '};\n';
2634
+ return code;
2635
+ }
2636
+
2637
+ // 生成预览的模板
2638
+ genPreviewTemplate() {
2639
+ return `<template>
2640
+ <bs-${this.name}>
2641
+ ${this.slotElems.map((slotElem) => {
2642
+ const slotName = slotElem.name;
2643
+ return `<template #${slotName}></template>`;
2644
+ }).join('')}
2645
+ </bs-${this.name}>
2646
+ </template>`;
2647
+ }
2648
+
2649
+ //================================================================================
2650
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
2651
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
2652
+ //================================================================================
2653
+ }
2654
+
2655
+ export default BusinessComponent;
2656
+ //================================================================================
2657
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
2658
+ // 自动生成的代码已结束。下面可以手动编写。
2659
+ //================================================================================