@lcap/nasl 3.2.0-beta.4 → 3.3.0-alpha

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