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