@opensumi/ide-components 2.12.1-next-079c1930

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 (360) hide show
  1. package/README.md +65 -0
  2. package/dist/index.css +1 -0
  3. package/dist/index.js +26330 -0
  4. package/lib/badge/index.d.ts +4 -0
  5. package/lib/badge/index.d.ts.map +1 -0
  6. package/lib/badge/index.js +13 -0
  7. package/lib/badge/index.js.map +1 -0
  8. package/lib/badge/styles.less +17 -0
  9. package/lib/button/index.d.ts +54 -0
  10. package/lib/button/index.d.ts.map +1 -0
  11. package/lib/button/index.js +68 -0
  12. package/lib/button/index.js.map +1 -0
  13. package/lib/button/style.less +251 -0
  14. package/lib/checkbox/index.d.ts +9 -0
  15. package/lib/checkbox/index.d.ts.map +1 -0
  16. package/lib/checkbox/index.js +27 -0
  17. package/lib/checkbox/index.js.map +1 -0
  18. package/lib/checkbox/style.less +80 -0
  19. package/lib/common.d.ts +7 -0
  20. package/lib/common.d.ts.map +1 -0
  21. package/lib/common.js +11 -0
  22. package/lib/common.js.map +1 -0
  23. package/lib/dialog/index.d.ts +26 -0
  24. package/lib/dialog/index.d.ts.map +1 -0
  25. package/lib/dialog/index.js +28 -0
  26. package/lib/dialog/index.js.map +1 -0
  27. package/lib/dialog/styles.less +85 -0
  28. package/lib/dropdown/dropdown.d.ts +48 -0
  29. package/lib/dropdown/dropdown.d.ts.map +1 -0
  30. package/lib/dropdown/dropdown.js +80 -0
  31. package/lib/dropdown/dropdown.js.map +1 -0
  32. package/lib/dropdown/index.d.ts +5 -0
  33. package/lib/dropdown/index.d.ts.map +1 -0
  34. package/lib/dropdown/index.js +8 -0
  35. package/lib/dropdown/index.js.map +1 -0
  36. package/lib/dropdown/style.less +254 -0
  37. package/lib/icon/icon.d.ts +33 -0
  38. package/lib/icon/icon.d.ts.map +1 -0
  39. package/lib/icon/icon.js +71 -0
  40. package/lib/icon/icon.js.map +1 -0
  41. package/lib/icon/iconfont/iconManager.d.ts +187 -0
  42. package/lib/icon/iconfont/iconManager.d.ts.map +1 -0
  43. package/lib/icon/iconfont/iconManager.js +67 -0
  44. package/lib/icon/iconfont/iconManager.js.map +1 -0
  45. package/lib/icon/iconfont/iconMap.d.ts +160 -0
  46. package/lib/icon/iconfont/iconMap.d.ts.map +1 -0
  47. package/lib/icon/iconfont/iconMap.js +165 -0
  48. package/lib/icon/iconfont/iconMap.js.map +1 -0
  49. package/lib/icon/iconfont/iconfont.css +646 -0
  50. package/lib/icon/iconfont/iconfont.eot +0 -0
  51. package/lib/icon/iconfont/iconfont.html +1522 -0
  52. package/lib/icon/iconfont/iconfont.svg +333 -0
  53. package/lib/icon/iconfont/iconfont.ttf +0 -0
  54. package/lib/icon/iconfont/iconfont.woff +0 -0
  55. package/lib/icon/iconfont/iconfont.woff2 +0 -0
  56. package/lib/icon/iconfont-cn.d.ts +15 -0
  57. package/lib/icon/iconfont-cn.d.ts.map +1 -0
  58. package/lib/icon/iconfont-cn.js +78 -0
  59. package/lib/icon/iconfont-cn.js.map +1 -0
  60. package/lib/icon/index.d.ts +4 -0
  61. package/lib/icon/index.d.ts.map +1 -0
  62. package/lib/icon/index.js +9 -0
  63. package/lib/icon/index.js.map +1 -0
  64. package/lib/icon/styles.less +105 -0
  65. package/lib/icon/util.d.ts +29 -0
  66. package/lib/icon/util.d.ts.map +1 -0
  67. package/lib/icon/util.js +53 -0
  68. package/lib/icon/util.js.map +1 -0
  69. package/lib/index.d.ts +20 -0
  70. package/lib/index.d.ts.map +1 -0
  71. package/lib/index.js +23 -0
  72. package/lib/index.js.map +1 -0
  73. package/lib/input/HistoryInputBox.d.ts +38 -0
  74. package/lib/input/HistoryInputBox.d.ts.map +1 -0
  75. package/lib/input/HistoryInputBox.js +114 -0
  76. package/lib/input/HistoryInputBox.js.map +1 -0
  77. package/lib/input/Input.d.ts +43 -0
  78. package/lib/input/Input.d.ts.map +1 -0
  79. package/lib/input/Input.js +124 -0
  80. package/lib/input/Input.js.map +1 -0
  81. package/lib/input/ProxiedInput.d.ts +8 -0
  82. package/lib/input/ProxiedInput.d.ts.map +1 -0
  83. package/lib/input/ProxiedInput.js +67 -0
  84. package/lib/input/ProxiedInput.js.map +1 -0
  85. package/lib/input/TextArea.d.ts +6 -0
  86. package/lib/input/TextArea.d.ts.map +1 -0
  87. package/lib/input/TextArea.js +11 -0
  88. package/lib/input/TextArea.js.map +1 -0
  89. package/lib/input/ValidateInput.d.ts +20 -0
  90. package/lib/input/ValidateInput.d.ts.map +1 -0
  91. package/lib/input/ValidateInput.js +59 -0
  92. package/lib/input/ValidateInput.js.map +1 -0
  93. package/lib/input/index.d.ts +5 -0
  94. package/lib/input/index.d.ts.map +1 -0
  95. package/lib/input/index.js +8 -0
  96. package/lib/input/index.js.map +1 -0
  97. package/lib/input/input.less +83 -0
  98. package/lib/input/validate-input.less +88 -0
  99. package/lib/locale-context-provider.d.ts +16 -0
  100. package/lib/locale-context-provider.d.ts.map +1 -0
  101. package/lib/locale-context-provider.js +26 -0
  102. package/lib/locale-context-provider.js.map +1 -0
  103. package/lib/menu/MenuContext.d.ts +8 -0
  104. package/lib/menu/MenuContext.d.ts.map +1 -0
  105. package/lib/menu/MenuContext.js +8 -0
  106. package/lib/menu/MenuContext.js.map +1 -0
  107. package/lib/menu/MenuItem.d.ts +29 -0
  108. package/lib/menu/MenuItem.d.ts.map +1 -0
  109. package/lib/menu/MenuItem.js +32 -0
  110. package/lib/menu/MenuItem.js.map +1 -0
  111. package/lib/menu/SubMenu.d.ts +30 -0
  112. package/lib/menu/SubMenu.d.ts.map +1 -0
  113. package/lib/menu/SubMenu.js +28 -0
  114. package/lib/menu/SubMenu.js.map +1 -0
  115. package/lib/menu/index.d.ts +64 -0
  116. package/lib/menu/index.d.ts.map +1 -0
  117. package/lib/menu/index.js +203 -0
  118. package/lib/menu/index.js.map +1 -0
  119. package/lib/menu/style.less +513 -0
  120. package/lib/message/index.d.ts +10 -0
  121. package/lib/message/index.d.ts.map +1 -0
  122. package/lib/message/index.js +21 -0
  123. package/lib/message/index.js.map +1 -0
  124. package/lib/message/message.d.ts +42 -0
  125. package/lib/message/message.d.ts.map +1 -0
  126. package/lib/message/message.js +128 -0
  127. package/lib/message/message.js.map +1 -0
  128. package/lib/message/style.less +76 -0
  129. package/lib/modal/Modal.d.ts +127 -0
  130. package/lib/modal/Modal.d.ts.map +1 -0
  131. package/lib/modal/Modal.js +87 -0
  132. package/lib/modal/Modal.js.map +1 -0
  133. package/lib/modal/index.d.ts +5 -0
  134. package/lib/modal/index.d.ts.map +1 -0
  135. package/lib/modal/index.js +8 -0
  136. package/lib/modal/index.js.map +1 -0
  137. package/lib/modal/locale.d.ts +8 -0
  138. package/lib/modal/locale.d.ts.map +1 -0
  139. package/lib/modal/locale.js +23 -0
  140. package/lib/modal/locale.js.map +1 -0
  141. package/lib/modal/style.less +168 -0
  142. package/lib/notification/index.d.ts +8 -0
  143. package/lib/notification/index.d.ts.map +1 -0
  144. package/lib/notification/index.js +80 -0
  145. package/lib/notification/index.js.map +1 -0
  146. package/lib/notification/notification.d.ts +44 -0
  147. package/lib/notification/notification.d.ts.map +1 -0
  148. package/lib/notification/notification.js +156 -0
  149. package/lib/notification/notification.js.map +1 -0
  150. package/lib/notification/notification.less +231 -0
  151. package/lib/overlay/index.d.ts +19 -0
  152. package/lib/overlay/index.d.ts.map +1 -0
  153. package/lib/overlay/index.js +13 -0
  154. package/lib/overlay/index.js.map +1 -0
  155. package/lib/overlay/styles.less +44 -0
  156. package/lib/popover/index.d.ts +28 -0
  157. package/lib/popover/index.d.ts.map +1 -0
  158. package/lib/popover/index.js +127 -0
  159. package/lib/popover/index.js.map +1 -0
  160. package/lib/popover/styles.less +135 -0
  161. package/lib/recycle-list/RecycleList.d.ts +105 -0
  162. package/lib/recycle-list/RecycleList.d.ts.map +1 -0
  163. package/lib/recycle-list/RecycleList.js +253 -0
  164. package/lib/recycle-list/RecycleList.js.map +1 -0
  165. package/lib/recycle-list/index.d.ts +2 -0
  166. package/lib/recycle-list/index.d.ts.map +1 -0
  167. package/lib/recycle-list/index.js +5 -0
  168. package/lib/recycle-list/index.js.map +1 -0
  169. package/lib/recycle-tree/RecycleTree.d.ts +254 -0
  170. package/lib/recycle-tree/RecycleTree.d.ts.map +1 -0
  171. package/lib/recycle-tree/RecycleTree.js +635 -0
  172. package/lib/recycle-tree/RecycleTree.js.map +1 -0
  173. package/lib/recycle-tree/TreeNodeRendererWrap.d.ts +37 -0
  174. package/lib/recycle-tree/TreeNodeRendererWrap.d.ts.map +1 -0
  175. package/lib/recycle-tree/TreeNodeRendererWrap.js +18 -0
  176. package/lib/recycle-tree/TreeNodeRendererWrap.js.map +1 -0
  177. package/lib/recycle-tree/decorators/Adaptive/index.d.ts +10 -0
  178. package/lib/recycle-tree/decorators/Adaptive/index.d.ts.map +1 -0
  179. package/lib/recycle-tree/decorators/Adaptive/index.js +97 -0
  180. package/lib/recycle-tree/decorators/Adaptive/index.js.map +1 -0
  181. package/lib/recycle-tree/decorators/Filter/filter.less +11 -0
  182. package/lib/recycle-tree/decorators/Filter/index.d.ts +26 -0
  183. package/lib/recycle-tree/decorators/Filter/index.d.ts.map +1 -0
  184. package/lib/recycle-tree/decorators/Filter/index.js +53 -0
  185. package/lib/recycle-tree/decorators/Filter/index.js.map +1 -0
  186. package/lib/recycle-tree/decorators/index.d.ts +3 -0
  187. package/lib/recycle-tree/decorators/index.d.ts.map +1 -0
  188. package/lib/recycle-tree/decorators/index.js +6 -0
  189. package/lib/recycle-tree/decorators/index.js.map +1 -0
  190. package/lib/recycle-tree/index.d.ts +7 -0
  191. package/lib/recycle-tree/index.d.ts.map +1 -0
  192. package/lib/recycle-tree/index.js +10 -0
  193. package/lib/recycle-tree/index.js.map +1 -0
  194. package/lib/recycle-tree/prompt/NewPromptHandle.d.ts +12 -0
  195. package/lib/recycle-tree/prompt/NewPromptHandle.d.ts.map +1 -0
  196. package/lib/recycle-tree/prompt/NewPromptHandle.js +21 -0
  197. package/lib/recycle-tree/prompt/NewPromptHandle.js.map +1 -0
  198. package/lib/recycle-tree/prompt/PromptHandle.d.ts +59 -0
  199. package/lib/recycle-tree/prompt/PromptHandle.d.ts.map +1 -0
  200. package/lib/recycle-tree/prompt/PromptHandle.js +200 -0
  201. package/lib/recycle-tree/prompt/PromptHandle.js.map +1 -0
  202. package/lib/recycle-tree/prompt/RenamePromptHandle.d.ts +10 -0
  203. package/lib/recycle-tree/prompt/RenamePromptHandle.d.ts.map +1 -0
  204. package/lib/recycle-tree/prompt/RenamePromptHandle.js +21 -0
  205. package/lib/recycle-tree/prompt/RenamePromptHandle.js.map +1 -0
  206. package/lib/recycle-tree/prompt/index.d.ts +4 -0
  207. package/lib/recycle-tree/prompt/index.d.ts.map +1 -0
  208. package/lib/recycle-tree/prompt/index.js +7 -0
  209. package/lib/recycle-tree/prompt/index.js.map +1 -0
  210. package/lib/recycle-tree/tree/Tree.d.ts +20 -0
  211. package/lib/recycle-tree/tree/Tree.d.ts.map +1 -0
  212. package/lib/recycle-tree/tree/Tree.js +43 -0
  213. package/lib/recycle-tree/tree/Tree.js.map +1 -0
  214. package/lib/recycle-tree/tree/TreeNode.d.ts +222 -0
  215. package/lib/recycle-tree/tree/TreeNode.d.ts.map +1 -0
  216. package/lib/recycle-tree/tree/TreeNode.js +1099 -0
  217. package/lib/recycle-tree/tree/TreeNode.js.map +1 -0
  218. package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts +60 -0
  219. package/lib/recycle-tree/tree/decoration/CompositeDecoration.d.ts.map +1 -0
  220. package/lib/recycle-tree/tree/decoration/CompositeDecoration.js +328 -0
  221. package/lib/recycle-tree/tree/decoration/CompositeDecoration.js.map +1 -0
  222. package/lib/recycle-tree/tree/decoration/Decoration.d.ts +79 -0
  223. package/lib/recycle-tree/tree/decoration/Decoration.d.ts.map +1 -0
  224. package/lib/recycle-tree/tree/decoration/Decoration.js +183 -0
  225. package/lib/recycle-tree/tree/decoration/Decoration.js.map +1 -0
  226. package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts +34 -0
  227. package/lib/recycle-tree/tree/decoration/DecorationManager.d.ts.map +1 -0
  228. package/lib/recycle-tree/tree/decoration/DecorationManager.js +166 -0
  229. package/lib/recycle-tree/tree/decoration/DecorationManager.js.map +1 -0
  230. package/lib/recycle-tree/tree/decoration/index.d.ts +4 -0
  231. package/lib/recycle-tree/tree/decoration/index.d.ts.map +1 -0
  232. package/lib/recycle-tree/tree/decoration/index.js +7 -0
  233. package/lib/recycle-tree/tree/decoration/index.js.map +1 -0
  234. package/lib/recycle-tree/tree/index.d.ts +5 -0
  235. package/lib/recycle-tree/tree/index.d.ts.map +1 -0
  236. package/lib/recycle-tree/tree/index.js +8 -0
  237. package/lib/recycle-tree/tree/index.js.map +1 -0
  238. package/lib/recycle-tree/tree/model/TreeModel.d.ts +50 -0
  239. package/lib/recycle-tree/tree/model/TreeModel.d.ts.map +1 -0
  240. package/lib/recycle-tree/tree/model/TreeModel.js +81 -0
  241. package/lib/recycle-tree/tree/model/TreeModel.js.map +1 -0
  242. package/lib/recycle-tree/tree/model/index.d.ts +2 -0
  243. package/lib/recycle-tree/tree/model/index.d.ts.map +1 -0
  244. package/lib/recycle-tree/tree/model/index.js +5 -0
  245. package/lib/recycle-tree/tree/model/index.js.map +1 -0
  246. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts +65 -0
  247. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.d.ts.map +1 -0
  248. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js +191 -0
  249. package/lib/recycle-tree/tree/model/treeState/TreeStateManager.js.map +1 -0
  250. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts +15 -0
  251. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.d.ts.map +1 -0
  252. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js +104 -0
  253. package/lib/recycle-tree/tree/model/treeState/TreeStateWatcher.js.map +1 -0
  254. package/lib/recycle-tree/tree/model/treeState/index.d.ts +4 -0
  255. package/lib/recycle-tree/tree/model/treeState/index.d.ts.map +1 -0
  256. package/lib/recycle-tree/tree/model/treeState/index.js +8 -0
  257. package/lib/recycle-tree/tree/model/treeState/index.js.map +1 -0
  258. package/lib/recycle-tree/tree/model/treeState/types.d.ts +21 -0
  259. package/lib/recycle-tree/tree/model/treeState/types.d.ts.map +1 -0
  260. package/lib/recycle-tree/tree/model/treeState/types.js +18 -0
  261. package/lib/recycle-tree/tree/model/treeState/types.js.map +1 -0
  262. package/lib/recycle-tree/types/index.d.ts +4 -0
  263. package/lib/recycle-tree/types/index.d.ts.map +1 -0
  264. package/lib/recycle-tree/types/index.js +7 -0
  265. package/lib/recycle-tree/types/index.js.map +1 -0
  266. package/lib/recycle-tree/types/tree-node.d.ts +70 -0
  267. package/lib/recycle-tree/types/tree-node.d.ts.map +1 -0
  268. package/lib/recycle-tree/types/tree-node.js +11 -0
  269. package/lib/recycle-tree/types/tree-node.js.map +1 -0
  270. package/lib/recycle-tree/types/tree.d.ts +8 -0
  271. package/lib/recycle-tree/types/tree.d.ts.map +1 -0
  272. package/lib/recycle-tree/types/tree.js +3 -0
  273. package/lib/recycle-tree/types/tree.js.map +1 -0
  274. package/lib/recycle-tree/types/watcher.d.ts +114 -0
  275. package/lib/recycle-tree/types/watcher.d.ts.map +1 -0
  276. package/lib/recycle-tree/types/watcher.js +46 -0
  277. package/lib/recycle-tree/types/watcher.js.map +1 -0
  278. package/lib/scrollbars/index.d.ts +14 -0
  279. package/lib/scrollbars/index.d.ts.map +1 -0
  280. package/lib/scrollbars/index.js +52 -0
  281. package/lib/scrollbars/index.js.map +1 -0
  282. package/lib/scrollbars/styles.less +46 -0
  283. package/lib/select/index.d.ts +119 -0
  284. package/lib/select/index.d.ts.map +1 -0
  285. package/lib/select/index.js +327 -0
  286. package/lib/select/index.js.map +1 -0
  287. package/lib/select/style.less +224 -0
  288. package/lib/style/base.less +542 -0
  289. package/lib/style/index.less +14 -0
  290. package/lib/style/mixins.less +135 -0
  291. package/lib/style/motion/fade.less +31 -0
  292. package/lib/style/motion/move.less +120 -0
  293. package/lib/style/motion/other.less +45 -0
  294. package/lib/style/motion/slide.less +120 -0
  295. package/lib/style/motion/swing.less +34 -0
  296. package/lib/style/motion/zoom.less +162 -0
  297. package/lib/style/variable.less +204 -0
  298. package/lib/tabs/index.d.ts +12 -0
  299. package/lib/tabs/index.d.ts.map +1 -0
  300. package/lib/tabs/index.js +24 -0
  301. package/lib/tabs/index.js.map +1 -0
  302. package/lib/tabs/style.less +34 -0
  303. package/lib/tooltip/index.d.ts +7 -0
  304. package/lib/tooltip/index.d.ts.map +1 -0
  305. package/lib/tooltip/index.js +58 -0
  306. package/lib/tooltip/index.js.map +1 -0
  307. package/lib/tooltip/style.less +41 -0
  308. package/lib/utils/deprecated.d.ts +3 -0
  309. package/lib/utils/deprecated.d.ts.map +1 -0
  310. package/lib/utils/deprecated.js +18 -0
  311. package/lib/utils/deprecated.js.map +1 -0
  312. package/lib/utils/disposable.d.ts +37 -0
  313. package/lib/utils/disposable.d.ts.map +1 -0
  314. package/lib/utils/disposable.js +140 -0
  315. package/lib/utils/disposable.js.map +1 -0
  316. package/lib/utils/event.d.ts +189 -0
  317. package/lib/utils/event.d.ts.map +1 -0
  318. package/lib/utils/event.js +569 -0
  319. package/lib/utils/event.js.map +1 -0
  320. package/lib/utils/index.d.ts +10 -0
  321. package/lib/utils/index.d.ts.map +1 -0
  322. package/lib/utils/index.js +13 -0
  323. package/lib/utils/index.js.map +1 -0
  324. package/lib/utils/iterator.d.ts +14 -0
  325. package/lib/utils/iterator.d.ts.map +1 -0
  326. package/lib/utils/iterator.js +9 -0
  327. package/lib/utils/iterator.js.map +1 -0
  328. package/lib/utils/linkedList.d.ts +18 -0
  329. package/lib/utils/linkedList.d.ts.map +1 -0
  330. package/lib/utils/linkedList.js +139 -0
  331. package/lib/utils/linkedList.js.map +1 -0
  332. package/lib/utils/motion.d.ts +24 -0
  333. package/lib/utils/motion.d.ts.map +1 -0
  334. package/lib/utils/motion.js +17 -0
  335. package/lib/utils/motion.js.map +1 -0
  336. package/lib/utils/os.d.ts +4 -0
  337. package/lib/utils/os.d.ts.map +1 -0
  338. package/lib/utils/os.js +22 -0
  339. package/lib/utils/os.js.map +1 -0
  340. package/lib/utils/path.d.ts +92 -0
  341. package/lib/utils/path.d.ts.map +1 -0
  342. package/lib/utils/path.js +1712 -0
  343. package/lib/utils/path.js.map +1 -0
  344. package/lib/utils/process.d.ts +6 -0
  345. package/lib/utils/process.d.ts.map +1 -0
  346. package/lib/utils/process.js +17 -0
  347. package/lib/utils/process.js.map +1 -0
  348. package/lib/utils/raf.d.ts +10 -0
  349. package/lib/utils/raf.d.ts.map +1 -0
  350. package/lib/utils/raf.js +33 -0
  351. package/lib/utils/raf.js.map +1 -0
  352. package/lib/utils/type.d.ts +4 -0
  353. package/lib/utils/type.d.ts.map +1 -0
  354. package/lib/utils/type.js +9 -0
  355. package/lib/utils/type.js.map +1 -0
  356. package/lib/utils/warning.d.ts +8 -0
  357. package/lib/utils/warning.d.ts.map +1 -0
  358. package/lib/utils/warning.js +40 -0
  359. package/lib/utils/warning.js.map +1 -0
  360. package/package.json +36 -0
@@ -0,0 +1,1099 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompositeTreeNode = exports.TreeNode = exports.spliceArray = void 0;
4
+ const types_1 = require("../types");
5
+ const utils_1 = require("../../utils");
6
+ /**
7
+ * 裁剪数组
8
+ *
9
+ * @param arr 裁剪数组
10
+ * @param start 起始位置
11
+ * @param deleteCount 删除或替换位置
12
+ * @param items 插入的数组
13
+ */
14
+ function spliceArray(arr, start, deleteCount = 0, items) {
15
+ const a = arr.slice(0);
16
+ a.splice(start, deleteCount, ...(items || []));
17
+ return a;
18
+ }
19
+ exports.spliceArray = spliceArray;
20
+ class TreeNode {
21
+ constructor(tree, parent, watcher, optionalMetadata, options) {
22
+ this._uid = TreeNode.nextId();
23
+ this._parent = parent;
24
+ this._tree = tree;
25
+ this._disposed = false;
26
+ this._visible = true;
27
+ this._metadata = Object.assign({}, (optionalMetadata || {}));
28
+ this._depth = parent ? parent.depth + 1 : 0;
29
+ if (watcher) {
30
+ this._watcher = watcher;
31
+ }
32
+ else if (parent) {
33
+ this._watcher = parent.watcher;
34
+ }
35
+ if (!(options && options.disableCache)) {
36
+ TreeNode.setTreeNode(this._uid, this.path, this);
37
+ }
38
+ }
39
+ static is(node) {
40
+ return !!node && 'depth' in node && 'name' in node && 'path' in node && 'id' in node;
41
+ }
42
+ static getTreeNodeById(id) {
43
+ return TreeNode.idToTreeNode.get(id);
44
+ }
45
+ static getTreeNodeByPath(path) {
46
+ return TreeNode.pathToTreeNode.get(path);
47
+ }
48
+ static setTreeNode(id, path, node) {
49
+ TreeNode.idToTreeNode.set(id, node);
50
+ TreeNode.pathToTreeNode.set(path, node);
51
+ }
52
+ static removeTreeNode(id, path) {
53
+ TreeNode.idToTreeNode.delete(id);
54
+ TreeNode.pathToTreeNode.delete(path);
55
+ }
56
+ get disposed() {
57
+ return this._disposed;
58
+ }
59
+ /**
60
+ * 获取基础信息
61
+ */
62
+ get depth() {
63
+ return this._depth;
64
+ }
65
+ get parent() {
66
+ return this._parent;
67
+ }
68
+ set parent(node) {
69
+ this._parent = node;
70
+ }
71
+ get whenReady() {
72
+ // 保障节点是否完成的标识位
73
+ return (async () => { })();
74
+ }
75
+ get type() {
76
+ return types_1.TreeNodeType.TreeNode;
77
+ }
78
+ get id() {
79
+ return this._uid;
80
+ }
81
+ get name() {
82
+ // 根节点保证路径不重复
83
+ if (!this.parent) {
84
+ return `root_${this._uid}`;
85
+ }
86
+ return this.getMetadata('name');
87
+ }
88
+ set name(name) {
89
+ this.addMetadata('name', name);
90
+ }
91
+ // 节点绝对路径
92
+ get path() {
93
+ if (!this.parent) {
94
+ return new utils_1.Path(`/${this.name}`).toString();
95
+ }
96
+ return new utils_1.Path(this.parent.path).join(this.name).toString();
97
+ }
98
+ get accessibilityInformation() {
99
+ return {
100
+ label: this.name,
101
+ role: 'treeitem',
102
+ };
103
+ }
104
+ getMetadata(withKey) {
105
+ return this._metadata[withKey];
106
+ }
107
+ addMetadata(withKey, value) {
108
+ if (!(withKey in this._metadata)) {
109
+ this._metadata[withKey] = value;
110
+ this._watcher.notifyDidChangeMetadata(this, { type: types_1.MetadataChangeType.Added, key: withKey, prevValue: void 0, value });
111
+ }
112
+ else {
113
+ const prevValue = this._metadata[withKey];
114
+ this._metadata[withKey] = value;
115
+ this._watcher.notifyDidChangeMetadata(this, { type: types_1.MetadataChangeType.Updated, key: withKey, prevValue, value });
116
+ }
117
+ }
118
+ removeMetadata(withKey) {
119
+ if (withKey in this._metadata) {
120
+ const prevValue = this._metadata[withKey];
121
+ delete this._metadata[withKey];
122
+ this._watcher.notifyDidChangeMetadata(this, { type: types_1.MetadataChangeType.Removed, key: withKey, prevValue, value: void 0 });
123
+ }
124
+ }
125
+ /**
126
+ * 这里的move操作可能为移动,也可能为重命名
127
+ *
128
+ * @param {ICompositeTreeNode} to
129
+ * @param {string} [name=this.name]
130
+ * @returns
131
+ * @memberof TreeNode
132
+ */
133
+ mv(to, name = this.name) {
134
+ // 一个普通节点必含有父节点,根节点不允许任何操作
135
+ const prevParent = this._parent;
136
+ if (to === null || !CompositeTreeNode.is(to)) {
137
+ this._parent = undefined;
138
+ this.dispose();
139
+ return;
140
+ }
141
+ const didChangeParent = prevParent !== to;
142
+ const prevPath = this.path;
143
+ this._depth = to.depth + 1;
144
+ if (didChangeParent || name !== this.name) {
145
+ this.addMetadata('name', name);
146
+ if (didChangeParent) {
147
+ this._watcher.notifyWillChangeParent(this, prevParent, to);
148
+ }
149
+ if (this.parent) {
150
+ this.parent.unlinkItem(this, true);
151
+ this._parent = to;
152
+ this.parent.insertItem(this);
153
+ }
154
+ if (didChangeParent) {
155
+ this._watcher.notifyDidChangeParent(this, prevParent, to);
156
+ }
157
+ }
158
+ if (this.path !== prevPath) {
159
+ this._watcher.notifyDidChangePath(this);
160
+ }
161
+ }
162
+ get visible() {
163
+ return this._visible;
164
+ }
165
+ setVisible(b) {
166
+ this._visible = b;
167
+ return this;
168
+ }
169
+ dispose() {
170
+ if (this._disposed) {
171
+ return;
172
+ }
173
+ this._watcher.notifyWillDispose(this);
174
+ TreeNode.removeTreeNode(this._uid, this.path);
175
+ this._watcher.notifyDidDispose(this);
176
+ this._disposed = true;
177
+ }
178
+ }
179
+ exports.TreeNode = TreeNode;
180
+ TreeNode.nextId = (() => {
181
+ let id = 0;
182
+ return () => id++;
183
+ })();
184
+ TreeNode.idToTreeNode = new Map();
185
+ TreeNode.pathToTreeNode = new Map();
186
+ class CompositeTreeNode extends TreeNode {
187
+ // parent 为undefined即表示该节点为根节点
188
+ constructor(tree, parent, watcher, optionalMetadata, options) {
189
+ super(tree, parent, watcher, optionalMetadata, options);
190
+ this._children = null;
191
+ this.refreshTasks = [];
192
+ /**
193
+ * 处理Watch事件,同时可通过外部手动调 g用节点更新函数进行节点替换,这里为通用的事件管理
194
+ * 如: transferItem,insertItem, unlinkItem等
195
+ * @private
196
+ * @memberof CompositeTreeNode
197
+ */
198
+ this.handleWatchEvent = async (event) => {
199
+ this.watcher.notifyWillProcessWatchEvent(this, event);
200
+ if (event.type === types_1.WatchEvent.Moved) {
201
+ const { oldPath, newPath } = event;
202
+ if (typeof oldPath !== 'string') {
203
+ throw new TypeError(`Expected oldPath to be a string`);
204
+ }
205
+ if (typeof newPath !== 'string') {
206
+ throw new TypeError(`Expected newPath to be a string`);
207
+ }
208
+ if (utils_1.Path.isRelative(oldPath)) {
209
+ throw new TypeError(`oldPath must be absolute`);
210
+ }
211
+ if (utils_1.Path.isRelative(newPath)) {
212
+ throw new TypeError(`newPath must be absolute`);
213
+ }
214
+ this.transferItem(oldPath, newPath);
215
+ }
216
+ else if (event.type === types_1.WatchEvent.Added) {
217
+ const { node } = event;
218
+ if (!TreeNode.is(node)) {
219
+ throw new TypeError(`Expected node to be a TreeNode`);
220
+ }
221
+ this.insertItem(node);
222
+ }
223
+ else if (event.type === types_1.WatchEvent.Removed) {
224
+ const { path } = event;
225
+ const pathObject = new utils_1.Path(path);
226
+ const dirName = pathObject.dir.toString();
227
+ const name = pathObject.base.toString();
228
+ if (dirName === this.path && !!this.children) {
229
+ const item = this.children.find((c) => c.name === name);
230
+ if (item) {
231
+ this.unlinkItem(item);
232
+ }
233
+ }
234
+ }
235
+ else {
236
+ // 预存展开目录
237
+ const expandedPaths = this.getAllExpandedNodePath();
238
+ // Changed事件,表示节点有较多的变化时,重新更新当前Tree节点
239
+ if (!!this.children) {
240
+ for (const child of this.children) {
241
+ child.dispose();
242
+ }
243
+ }
244
+ // 如果当前变化的节点已在数据视图(并非滚动到不可见区域)中不可见,则将该节点折叠,待下次更新即可,
245
+ if (!this.isItemVisibleAtRootSurface(this)) {
246
+ this.isExpanded = false;
247
+ this._children = null;
248
+ }
249
+ else {
250
+ // needReload --- 判断根目录是否需要进行一次刷新,部分情况,如压缩目录下的文件创建后不应该刷新
251
+ await this.refresh(expandedPaths);
252
+ }
253
+ }
254
+ this.watcher.notifyDidProcessWatchEvent(this, event);
255
+ };
256
+ this.isExpanded = !!parent ? false : true;
257
+ this._branchSize = 0;
258
+ if (!parent) {
259
+ this.watchEvents = new Map();
260
+ // 为根节点创建监听器
261
+ this._watcher = this.generatorWatcher();
262
+ }
263
+ else {
264
+ this._watcher = parent.watcher;
265
+ }
266
+ }
267
+ static defaultSortComparator(a, b) {
268
+ if (a.constructor === b.constructor) {
269
+ return a.name > b.name ? 1
270
+ : a.name < b.name ? -1
271
+ : 0;
272
+ }
273
+ return CompositeTreeNode.is(a) ? -1
274
+ : CompositeTreeNode.is(b) ? 1
275
+ : 0;
276
+ }
277
+ static is(node) {
278
+ return !!node && 'children' in node;
279
+ }
280
+ static isRoot(node) {
281
+ return CompositeTreeNode.is(node) && !node.parent;
282
+ }
283
+ generatorWatcher() {
284
+ const emitter = new utils_1.Emitter();
285
+ const onEventChanges = emitter.event;
286
+ const disposeCollection = new utils_1.DisposableCollection();
287
+ const terminateWatch = (path) => {
288
+ this.watchEvents.delete(path);
289
+ };
290
+ const watcher = {
291
+ notifyWillProcessWatchEvent: (target, event) => {
292
+ emitter.fire({ type: types_1.TreeNodeEvent.WillProcessWatchEvent, args: [target, event] });
293
+ },
294
+ notifyWillChangeParent: (target, prevParent, newParent) => {
295
+ emitter.fire({ type: types_1.TreeNodeEvent.WillChangeParent, args: [target, prevParent, newParent] });
296
+ },
297
+ notifyDidChangeParent: (target, prevParent, newParent) => {
298
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangeParent, args: [target, prevParent, newParent] });
299
+ },
300
+ notifyWillDispose: (target) => {
301
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangeParent, args: [target] });
302
+ },
303
+ notifyDidDispose: (target) => {
304
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangeParent, args: [target] });
305
+ },
306
+ notifyDidProcessWatchEvent: (target, event) => {
307
+ emitter.fire({ type: types_1.TreeNodeEvent.DidProcessWatchEvent, args: [target, event] });
308
+ },
309
+ notifyDidChangePath: (target) => {
310
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangePath, args: [target] });
311
+ },
312
+ notifyWillChangeExpansionState: (target, nowExpanded) => {
313
+ const isVisible = this.isItemVisibleAtSurface(target);
314
+ emitter.fire({ type: types_1.TreeNodeEvent.WillChangeExpansionState, args: [target, nowExpanded, isVisible] });
315
+ },
316
+ notifyDidChangeExpansionState: (target, nowExpanded) => {
317
+ const isVisible = this.isItemVisibleAtSurface(target);
318
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangeExpansionState, args: [target, nowExpanded, isVisible] });
319
+ },
320
+ notifyDidChangeMetadata: (target, change) => {
321
+ emitter.fire({ type: types_1.TreeNodeEvent.DidChangeMetadata, args: [target, change] });
322
+ },
323
+ notifyDidUpdateBranch: () => {
324
+ emitter.fire({ type: types_1.TreeNodeEvent.BranchDidUpdate, args: [] });
325
+ },
326
+ notifyWillResolveChildren: (target, nowExpanded) => {
327
+ emitter.fire({ type: types_1.TreeNodeEvent.WillResolveChildren, args: [target, nowExpanded] });
328
+ },
329
+ notifyDidResolveChildren: (target, nowExpanded) => {
330
+ emitter.fire({ type: types_1.TreeNodeEvent.DidResolveChildren, args: [target, nowExpanded] });
331
+ },
332
+ // 监听所有事件
333
+ on: (event, callback) => {
334
+ const dispose = onEventChanges((data) => {
335
+ if (data.type === event) {
336
+ callback(...data.args);
337
+ }
338
+ });
339
+ disposeCollection.push(dispose);
340
+ return dispose;
341
+ },
342
+ // 监听Watch事件变化
343
+ onWatchEvent: (path, callback) => {
344
+ const terminator = terminateWatch;
345
+ this.watchEvents.set(path, { terminator, callback });
346
+ return terminator;
347
+ },
348
+ dispose: disposeCollection,
349
+ };
350
+ return watcher;
351
+ }
352
+ // 重载 name 的 getter/setter,路径改变时需要重新监听文件节点变化
353
+ set name(name) {
354
+ const prevPath = this.path;
355
+ if (!CompositeTreeNode.isRoot(this) && typeof this.watchTerminator === 'function') {
356
+ this.watchTerminator(prevPath);
357
+ this.addMetadata('name', name);
358
+ this.watchTerminator = this.watcher.onWatchEvent(this.path, this.handleWatchEvent);
359
+ }
360
+ else {
361
+ this.addMetadata('name', name);
362
+ }
363
+ }
364
+ get name() {
365
+ // 根节点保证路径不重复
366
+ if (!this.parent) {
367
+ return `root_${this._uid}`;
368
+ }
369
+ return this.getMetadata('name');
370
+ }
371
+ // 作为根节点唯一的watcher需要在生成新节点的时候传入
372
+ get watcher() {
373
+ return this._watcher;
374
+ }
375
+ get type() {
376
+ return types_1.TreeNodeType.CompositeTreeNode;
377
+ }
378
+ get children() {
379
+ return this._children;
380
+ }
381
+ get expanded() {
382
+ return this.isExpanded;
383
+ }
384
+ /**
385
+ * 当前可见的分支数量
386
+ *
387
+ * 当节点为展开状态时,其整个分支(递归展平)由上一级的分支(根(位于数据层可见)或处于折叠状态的分支)拥有
388
+ * 当节点为折叠状态时,其整个分支(递归展平)由其上一级父目录展开该节点
389
+ *
390
+ * @readonly
391
+ * @memberof CompositeTreeNode
392
+ */
393
+ get branchSize() {
394
+ return this._branchSize;
395
+ }
396
+ /**
397
+ * 获取当前节点的分支数,一般为顶层节点,如Root上获取
398
+ *
399
+ * @readonly
400
+ * @memberof CompositeTreeNode
401
+ */
402
+ get flattenedBranch() {
403
+ return this._flattenedBranch;
404
+ }
405
+ /**
406
+ * 确保此“目录”的子级已加载(不影响“展开”状态)
407
+ * 如果子级已经加载,则返回的Promise将立即解决
408
+ * 否则,将发出重新加载请求并返回Promise
409
+ * 一旦返回的Promise.resolve,“CompositeTreeNode#children” 便可以访问到对于节点
410
+ */
411
+ async ensureLoaded() {
412
+ if (this._children) {
413
+ return;
414
+ }
415
+ return this.hardReloadChildren();
416
+ }
417
+ // 展开节点
418
+ async setExpanded(ensureVisible = true, quiet = false) {
419
+ // 根节点不可折叠
420
+ if (CompositeTreeNode.isRoot(this)) {
421
+ return;
422
+ }
423
+ if (this.isExpanded) {
424
+ return;
425
+ }
426
+ this.isExpanded = true;
427
+ if (this._children === null) {
428
+ !quiet && this._watcher.notifyWillResolveChildren(this, this.isExpanded);
429
+ await this.hardReloadChildren();
430
+ !quiet && this._watcher.notifyDidResolveChildren(this, this.isExpanded);
431
+ // 检查其是否展开;可能同时执行了setCollapsed方法
432
+ if (!this.isExpanded) {
433
+ return;
434
+ }
435
+ }
436
+ if (ensureVisible && this.parent && CompositeTreeNode.is(this.parent)) {
437
+ await this.parent.setExpanded(true, !quiet);
438
+ }
439
+ if (this.isExpanded) {
440
+ !quiet && this._watcher.notifyWillChangeExpansionState(this, true);
441
+ // 与根节点合并分支
442
+ this.expandBranch(this, quiet);
443
+ !quiet && this._watcher.notifyDidChangeExpansionState(this, true);
444
+ }
445
+ }
446
+ // 获取当前节点下所有展开的节点路径
447
+ getAllExpandedNodePath() {
448
+ let paths = [];
449
+ if (!!this.children) {
450
+ for (const child of this.children) {
451
+ if (child.isExpanded) {
452
+ paths.push(child.path);
453
+ paths = paths.concat(child.getAllExpandedNodePath());
454
+ }
455
+ }
456
+ return paths;
457
+ }
458
+ else {
459
+ return paths;
460
+ }
461
+ }
462
+ // 获取当前节点下所有折叠的节点路径
463
+ getAllCollapsedNodePath() {
464
+ let paths = [];
465
+ if (!!this.children) {
466
+ for (const child of this.children) {
467
+ if (!CompositeTreeNode.is(child)) {
468
+ continue;
469
+ }
470
+ if (child.isExpanded) {
471
+ paths = paths.concat(child.getAllCollapsedNodePath());
472
+ }
473
+ else {
474
+ paths.push(child.path);
475
+ }
476
+ }
477
+ return paths;
478
+ }
479
+ else {
480
+ return paths;
481
+ }
482
+ }
483
+ // 静默刷新子节点, 即不触发分支更新事件
484
+ async forceReloadChildrenQuiet(expandedPaths = this.getAllExpandedNodePath(), needReload = true) {
485
+ let forceLoadPath;
486
+ if (this.isExpanded) {
487
+ if (needReload) {
488
+ await this.hardReloadChildren(true);
489
+ }
490
+ while (forceLoadPath = expandedPaths.shift()) {
491
+ const relativePath = new utils_1.Path(this.path).relative(new utils_1.Path(forceLoadPath));
492
+ if (!relativePath) {
493
+ break;
494
+ }
495
+ const child = TreeNode.getTreeNodeByPath(forceLoadPath);
496
+ if (!child) {
497
+ if (!this.children) {
498
+ break;
499
+ }
500
+ for (const child of this.children) {
501
+ if (forceLoadPath.indexOf(child.path) === 0 && CompositeTreeNode.is(child)) {
502
+ // 包含压缩节点的情况
503
+ // 加载路径包含当前判断路径,尝试加载该节点再匹配
504
+ await child.hardReloadChildren(true);
505
+ if (child.isExpanded) {
506
+ // 说明此时节点初始化时已默认展开,不需要进一步处理
507
+ continue;
508
+ }
509
+ child.isExpanded = true;
510
+ if (expandedPaths.length > 0) {
511
+ // 不需要重新reload压缩节点的子节点内容
512
+ await child.forceReloadChildrenQuiet(expandedPaths, false);
513
+ }
514
+ else {
515
+ child.expandBranch(child, true);
516
+ }
517
+ break;
518
+ }
519
+ }
520
+ }
521
+ else if (CompositeTreeNode.is(child)) {
522
+ if (child.whenReady) {
523
+ await child.whenReady;
524
+ }
525
+ if (child.isExpanded) {
526
+ // 说明此时节点初始化时已默认展开,不需要进一步处理
527
+ continue;
528
+ }
529
+ child.isExpanded = true;
530
+ if (expandedPaths.length > 0) {
531
+ await child.forceReloadChildrenQuiet(expandedPaths);
532
+ }
533
+ else {
534
+ await child.hardReloadChildren(true);
535
+ child.expandBranch(child, true);
536
+ }
537
+ }
538
+ }
539
+ if (forceLoadPath) {
540
+ expandedPaths.unshift(forceLoadPath);
541
+ this.expandBranch(this, true);
542
+ }
543
+ else if (CompositeTreeNode.isRoot(this)) {
544
+ // 通知分支树已更新
545
+ this.watcher.notifyDidUpdateBranch();
546
+ }
547
+ else {
548
+ // 这种情况一般为非根节点刷新后需同步到父节点,更新分支树
549
+ this.expandBranch(this);
550
+ }
551
+ }
552
+ else {
553
+ // 仅需处理存在子节点的情况,否则将会影响刷新后的节点长度
554
+ if (!!this.children) {
555
+ // 清理子节点,等待下次展开时更新
556
+ if (!!this.children && this.parent) {
557
+ for (const child of this.children) {
558
+ child.dispose();
559
+ }
560
+ this._children = null;
561
+ }
562
+ }
563
+ return;
564
+ }
565
+ }
566
+ async expandedAll(collapsedPaths = this.getAllCollapsedNodePath()) {
567
+ // 仅根节点使用
568
+ if (!CompositeTreeNode.isRoot(this)) {
569
+ return;
570
+ }
571
+ collapsedPaths = collapsedPaths.sort((a, b) => {
572
+ return utils_1.Path.pathDepth(a) - utils_1.Path.pathDepth(b);
573
+ });
574
+ let path;
575
+ while (collapsedPaths.length > 0) {
576
+ path = collapsedPaths.pop();
577
+ const item = TreeNode.getTreeNodeByPath(path);
578
+ if (CompositeTreeNode.is(item)) {
579
+ await item.setExpanded(false, true);
580
+ }
581
+ }
582
+ // 通知分支树已更新
583
+ this.watcher.notifyDidUpdateBranch();
584
+ }
585
+ async collapsedAll(expandedPaths = this.getAllExpandedNodePath()) {
586
+ // 仅根节点使用
587
+ if (!CompositeTreeNode.isRoot(this)) {
588
+ return;
589
+ }
590
+ expandedPaths = expandedPaths.sort((a, b) => {
591
+ return utils_1.Path.pathDepth(a) - utils_1.Path.pathDepth(b);
592
+ });
593
+ let path;
594
+ while (expandedPaths.length > 0) {
595
+ path = expandedPaths.pop();
596
+ const item = TreeNode.getTreeNodeByPath(path);
597
+ if (CompositeTreeNode.is(item)) {
598
+ await item.setCollapsed(true);
599
+ }
600
+ }
601
+ // 通知分支树已更新
602
+ this.watcher.notifyDidUpdateBranch();
603
+ }
604
+ // 折叠节点
605
+ setCollapsed(quiet = false) {
606
+ // 根节点不可折叠
607
+ if (CompositeTreeNode.isRoot(this)) {
608
+ return;
609
+ }
610
+ if (!this.isExpanded) {
611
+ return;
612
+ }
613
+ if (this._children && this.parent) {
614
+ !quiet && this._watcher.notifyWillChangeExpansionState(this, false);
615
+ // 从根节点裁剪分支
616
+ this.shrinkBranch(this, quiet);
617
+ }
618
+ this.isExpanded = false;
619
+ !quiet && this._watcher.notifyDidChangeExpansionState(this, false);
620
+ }
621
+ mv(to, name = this.name) {
622
+ const prevPath = this.path;
623
+ super.mv(to, name);
624
+ if (typeof this.watchTerminator === 'function') {
625
+ this.watchTerminator(prevPath);
626
+ this.watchTerminator = this.watcher.onWatchEvent(this.path, this.handleWatchEvent);
627
+ }
628
+ // 同时移动过子节点
629
+ if (this.children) {
630
+ for (const child of this.children) {
631
+ child.mv(child.parent, child.name);
632
+ }
633
+ }
634
+ }
635
+ /**
636
+ * 在节点中插入新的节点
637
+ *
638
+ * 直接调用此方法将不会触发onWillHandleWatchEvent和onDidHandleWatchEvent事件
639
+ */
640
+ insertItem(item) {
641
+ if (item.parent !== this) {
642
+ item.mv(this, item.name);
643
+ return;
644
+ }
645
+ if (this.children) {
646
+ for (let i = 0; i < this.children.length; i++) {
647
+ // path / id 是节点唯一标识
648
+ if (this.children[i].path === item.path) {
649
+ this.children[i] = item;
650
+ return;
651
+ }
652
+ }
653
+ }
654
+ const branchSizeIncrease = 1 + ((item instanceof CompositeTreeNode && item.expanded) ? item._branchSize : 0);
655
+ if (this._children) {
656
+ this._children.push(item);
657
+ this._children.sort(this._tree.sortComparator || CompositeTreeNode.defaultSortComparator);
658
+ }
659
+ this._branchSize += branchSizeIncrease;
660
+ let master = this;
661
+ // 如果该节点无叶子节点,则继续往上查找合适的插入位置
662
+ while (!master._flattenedBranch) {
663
+ if (master.parent) {
664
+ master = master.parent;
665
+ master._branchSize += branchSizeIncrease;
666
+ }
667
+ }
668
+ if (!this._children) {
669
+ return;
670
+ }
671
+ let relativeInsertionIndex = this._children.indexOf(item);
672
+ let absInsertionIndex;
673
+ const leadingSibling = this._children[relativeInsertionIndex - 1];
674
+ if (leadingSibling) {
675
+ const siblingIdx = master._flattenedBranch.indexOf(leadingSibling.id);
676
+ relativeInsertionIndex = siblingIdx + ((leadingSibling instanceof CompositeTreeNode && leadingSibling.expanded) ? leadingSibling._branchSize : 0);
677
+ }
678
+ else {
679
+ relativeInsertionIndex = master._flattenedBranch.indexOf(this.id);
680
+ }
681
+ if (relativeInsertionIndex === -1) {
682
+ if (this._branchSize === 1) {
683
+ // 在空Tree中插入节点时,相对插入位置为0
684
+ relativeInsertionIndex = 0;
685
+ }
686
+ }
687
+ // 非空Tree情况下需要+1,为了容纳自身节点位置,在插入节点下方插入新增节点
688
+ absInsertionIndex = relativeInsertionIndex + 1;
689
+ // 空 Tree 情况下需要重置为 0,避免设置 Uint32Array 时超出范围
690
+ if (master._flattenedBranch.length === 0) {
691
+ absInsertionIndex = 0;
692
+ }
693
+ let branch = [item.id];
694
+ if (item instanceof CompositeTreeNode && item.expanded && item._flattenedBranch) {
695
+ branch = branch.concat(item._flattenedBranch);
696
+ item.setFlattenedBranch(null);
697
+ }
698
+ master.setFlattenedBranch(spliceArray(master._flattenedBranch, absInsertionIndex, 0, branch));
699
+ }
700
+ /**
701
+ * 从父节点中移除节点
702
+ *
703
+ * 直接调用此方法将不会触发onWillHandleWatchEvent和onDidHandleWatchEvent事件
704
+ */
705
+ unlinkItem(item, reparenting) {
706
+ if (!this._children) {
707
+ return;
708
+ }
709
+ const idx = this._children.indexOf(item);
710
+ if (idx === -1) {
711
+ return;
712
+ }
713
+ // 当删除时父节点已不存在界面上时,跳过插入操作
714
+ if (!this.isItemVisibleAtRootSurface(this)) {
715
+ return;
716
+ }
717
+ this._children.splice(idx, 1);
718
+ const branchSizeDecrease = 1 + ((item instanceof CompositeTreeNode && item.expanded) ? item._branchSize : 0);
719
+ this._branchSize -= branchSizeDecrease;
720
+ // 逐级往上查找节点的父节点,并沿途裁剪分支数
721
+ let master = this;
722
+ while (!master._flattenedBranch) {
723
+ if (master.parent) {
724
+ master = master.parent;
725
+ master._branchSize -= branchSizeDecrease;
726
+ }
727
+ }
728
+ const removalBeginIdx = master._flattenedBranch.indexOf(item.id);
729
+ if (removalBeginIdx === -1) {
730
+ return;
731
+ }
732
+ if (item instanceof CompositeTreeNode && item.expanded) {
733
+ item.setFlattenedBranch(master._flattenedBranch.slice(removalBeginIdx + 1, removalBeginIdx + branchSizeDecrease));
734
+ }
735
+ master.setFlattenedBranch(spliceArray(master._flattenedBranch, removalBeginIdx, branchSizeDecrease));
736
+ if (!reparenting && item.parent === this) {
737
+ item.mv(null);
738
+ }
739
+ }
740
+ /**
741
+ * 转换节点路径
742
+ */
743
+ transferItem(oldPath, newPath) {
744
+ const oldP = new utils_1.Path(oldPath);
745
+ const from = oldP.dir.toString();
746
+ if (from !== this.path) {
747
+ return;
748
+ }
749
+ const name = oldP.base.toString();
750
+ const item = this._children.find((c) => c.name === name);
751
+ if (!item) {
752
+ return;
753
+ }
754
+ const newP = new utils_1.Path(newPath);
755
+ const to = newP.dir.toString();
756
+ const destDir = to === from ? this : TreeNode.getTreeNodeByPath(to);
757
+ if (!(CompositeTreeNode.is(destDir))) {
758
+ this.unlinkItem(item);
759
+ return;
760
+ }
761
+ item.mv(destDir, newP.base.toString());
762
+ }
763
+ dispose() {
764
+ // 如果存在对应文件路径下的监听,同样需要清理掉
765
+ if (this.watchEvents) {
766
+ const watcher = this.watchEvents.get(this.path);
767
+ if (watcher) {
768
+ watcher.terminator();
769
+ }
770
+ this.watchEvents.clear();
771
+ }
772
+ if (this._children) {
773
+ // 移除后应该折叠,因为下次初始化默认值为折叠,否则将会导致下次插入异常
774
+ this.isExpanded = false;
775
+ this._children.forEach((child) => {
776
+ child.dispose();
777
+ });
778
+ this._children = null;
779
+ this._flattenedBranch = null;
780
+ }
781
+ super.dispose();
782
+ }
783
+ /**
784
+ * 设置扁平化的分支信息
785
+ */
786
+ setFlattenedBranch(leaves, withoutNotify) {
787
+ this._flattenedBranch = leaves;
788
+ // Root节点才通知更新
789
+ if (CompositeTreeNode.isRoot(this) && !withoutNotify) {
790
+ this.watcher.notifyDidUpdateBranch();
791
+ }
792
+ }
793
+ /**
794
+ * 展开分支节点
795
+ * @param branch 分支节点
796
+ */
797
+ expandBranch(branch, withoutNotify) {
798
+ if (this !== branch) {
799
+ // 但节点为展开状态时进行裁剪
800
+ this._branchSize += branch._branchSize;
801
+ }
802
+ // 当前节点为折叠状态,更新分支信息
803
+ if (this !== branch && this._flattenedBranch) {
804
+ const injectionStartIdx = this._flattenedBranch.indexOf(branch.id) + 1;
805
+ if (injectionStartIdx === 0) {
806
+ // 中途发生了branch更新事件,此时的_flattenedBranch可能已被更新,即查找不到branch.id
807
+ // 这种情况在父节点发生了多路径目录的创建定位动作下更易复现
808
+ // 例:文件树在执行a/b/c定位操作时需要请求三次数据,而更新操作可能只需要一次
809
+ // 导致就算更新操作后置执行,也可能比定位操作先执行完,同时将_flattenedBranch更新
810
+ // 最终导致此处查询不到对应节点,下面的shrinkBranch同样可能有相同问题,如点击折叠全部功能时
811
+ return;
812
+ }
813
+ this.setFlattenedBranch(spliceArray(this._flattenedBranch, injectionStartIdx, 0, branch._flattenedBranch), withoutNotify);
814
+ // 取消展开分支对于分支的所有权,即最终只会有顶部Root拥有所有分支信息
815
+ branch.setFlattenedBranch(null, withoutNotify);
816
+ }
817
+ else if (this.parent) {
818
+ this.parent.expandBranch(branch, withoutNotify);
819
+ }
820
+ }
821
+ /**
822
+ * 清理分支节点
823
+ * @param branch 分支节点
824
+ */
825
+ shrinkBranch(branch, withoutNotify) {
826
+ if (this !== branch) {
827
+ // 这里的`this`实际上为父节点
828
+ // `this`的分支大小没有改变,仍然具有相同数量的叶子,但是从父级参照系(即根节点)来看,其分支缩小了
829
+ this._branchSize -= branch._branchSize;
830
+ }
831
+ if (this !== branch && this._flattenedBranch) {
832
+ const removalStartIdx = this._flattenedBranch.indexOf(branch.id) + 1;
833
+ if (removalStartIdx === 0) {
834
+ // 中途发生了branch更新事件,此时的_flattenedBranch可能已被更新,即查找不到branch.id
835
+ return;
836
+ }
837
+ // 返回分支对于分支信息所有权,即将折叠的节点信息再次存储于折叠了的节点中
838
+ branch.setFlattenedBranch(this._flattenedBranch.slice(removalStartIdx, removalStartIdx + branch._branchSize), withoutNotify);
839
+ this.setFlattenedBranch(spliceArray(this._flattenedBranch, removalStartIdx, branch._flattenedBranch ? branch._flattenedBranch.length : 0), withoutNotify);
840
+ }
841
+ else if (this.parent) {
842
+ this.parent.shrinkBranch(branch, withoutNotify);
843
+ }
844
+ }
845
+ /**
846
+ * 加载节点信息
847
+ * @memberof CompositeTreeNode
848
+ */
849
+ async hardReloadChildren(quiet) {
850
+ if (this.hardReloadPromise) {
851
+ return this.hardReloadPromise;
852
+ }
853
+ this.hardReloadPromise = new Promise((res) => this.hardReloadPResolver = res);
854
+ this.hardReloadPromise.then(() => {
855
+ this.hardReloadPromise = null;
856
+ this.hardReloadPResolver = null;
857
+ });
858
+ const rawItems = await this._tree.resolveChildren(this) || [];
859
+ if (this._children) {
860
+ // 重置节点分支
861
+ this.shrinkBranch(this, quiet);
862
+ }
863
+ const flatTree = new Array(rawItems.length);
864
+ this._children = Array(rawItems.length);
865
+ for (let i = 0; i < rawItems.length; i++) {
866
+ const child = rawItems[i];
867
+ this._children[i] = child;
868
+ }
869
+ this._children.sort(this._tree.sortComparator || CompositeTreeNode.defaultSortComparator);
870
+ for (let i = 0; i < rawItems.length; i++) {
871
+ flatTree[i] = this._children[i].id;
872
+ }
873
+ this._branchSize = flatTree.length;
874
+ this.setFlattenedBranch(flatTree, quiet);
875
+ // 清理上一次监听函数
876
+ if (typeof this.watchTerminator === 'function') {
877
+ this.watchTerminator(this.path);
878
+ }
879
+ this.watchTerminator = this.watcher.onWatchEvent(this.path, this.handleWatchEvent);
880
+ if (this.hardReloadPResolver) {
881
+ this.hardReloadPResolver();
882
+ }
883
+ }
884
+ async refresh(paths = this.getAllExpandedNodePath()) {
885
+ this.refreshTasks.push(paths);
886
+ return await this.queue(this.doRefresh.bind(this));
887
+ }
888
+ async queue(promiseFactory) {
889
+ if (this.activeRefreshPromise) {
890
+ this.queuedRefreshPromiseFactory = promiseFactory;
891
+ if (!this.queuedRefreshPromise) {
892
+ const onComplete = () => {
893
+ this.queuedRefreshPromise = null;
894
+ const result = this.queue(this.queuedRefreshPromiseFactory);
895
+ this.queuedRefreshPromiseFactory = null;
896
+ return result;
897
+ };
898
+ this.queuedRefreshPromise = new Promise((resolve) => {
899
+ this.activeRefreshPromise.then(onComplete, onComplete).then(resolve);
900
+ });
901
+ }
902
+ return new Promise((c, e) => {
903
+ this.queuedRefreshPromise.then(c, e);
904
+ });
905
+ }
906
+ this.activeRefreshPromise = promiseFactory();
907
+ return new Promise((c, e) => {
908
+ this.activeRefreshPromise.then((result) => {
909
+ this.activeRefreshPromise = null;
910
+ c(result);
911
+ }, (err) => {
912
+ this.activeRefreshPromise = null;
913
+ e(err);
914
+ });
915
+ });
916
+ }
917
+ async doRefresh() {
918
+ const tasks = this.refreshTasks.slice(0);
919
+ const paths = this.mergeExpandedPaths(tasks);
920
+ return await this.forceReloadChildrenQuiet(paths);
921
+ }
922
+ mergeExpandedPaths(paths) {
923
+ // 返回最长的刷新路径即可
924
+ let result;
925
+ for (const path of paths) {
926
+ if (!result) {
927
+ result = path;
928
+ continue;
929
+ }
930
+ else {
931
+ if (path.length > result.length) {
932
+ result = path;
933
+ }
934
+ }
935
+ }
936
+ return result;
937
+ }
938
+ isItemVisibleAtRootSurface(node) {
939
+ let parent = node;
940
+ while (parent.parent) {
941
+ parent = parent.parent;
942
+ }
943
+ return parent.isItemVisibleAtSurface(node);
944
+ }
945
+ /**
946
+ * 检查节点是否可见,而不是被隐藏在节点中
947
+ *
948
+ * 这里的可见并不表示节点在当前视图中可见,而是在用户滚动到特定位置便可看见
949
+ *
950
+ * 隐藏在节点中可能的原因为其父节点中有一个以上处于折叠状态
951
+ */
952
+ isItemVisibleAtSurface(item) {
953
+ if (item === this) {
954
+ return true;
955
+ }
956
+ return !!this._flattenedBranch && this._flattenedBranch.indexOf(item.id) > -1;
957
+ }
958
+ transformToRelativePath(path) {
959
+ const { splitPath } = utils_1.Path;
960
+ const pathFlag = splitPath(path);
961
+ pathFlag.shift();
962
+ return pathFlag;
963
+ }
964
+ /**
965
+ * 根据路径展开节点树
966
+ * @memberof CompositeTreeNode
967
+ */
968
+ async forceLoadTreeNodeAtPath(path) {
969
+ const { splitPath, isRelative } = utils_1.Path;
970
+ const pathFlag = isRelative(path) ? splitPath(path) : this.transformToRelativePath(path);
971
+ if (pathFlag.length === 0) {
972
+ return this;
973
+ }
974
+ await this.ensureLoaded();
975
+ let next = this._children;
976
+ let preItem;
977
+ let preItemPath = '';
978
+ let name;
979
+ while (name = pathFlag.shift()) {
980
+ let item = next.find((c) => c.name.indexOf(name) === 0);
981
+ if (item && pathFlag.length === 0) {
982
+ return item;
983
+ }
984
+ // 可能展开后路径发生了变化, 需要重新处理一下当前加载路径
985
+ if (!item && preItem) {
986
+ const compactPath = splitPath(preItem.name).slice(1);
987
+ if (compactPath[0] === name) {
988
+ compactPath.shift();
989
+ while (compactPath.length > 0) {
990
+ if (compactPath[0] === pathFlag[0]) {
991
+ compactPath.shift();
992
+ pathFlag.shift();
993
+ }
994
+ else {
995
+ break;
996
+ }
997
+ }
998
+ name = pathFlag.shift();
999
+ item = next.find((c) => c.name.indexOf(name) === 0);
1000
+ }
1001
+ }
1002
+ // 最终加载到的路径节点
1003
+ if (!item || (!CompositeTreeNode.is(item) && pathFlag.length > 0)) {
1004
+ return preItem;
1005
+ }
1006
+ if (CompositeTreeNode.is(item)) {
1007
+ const isCompactName = item.name.indexOf(utils_1.Path.separator) > 0;
1008
+ if (isCompactName) {
1009
+ const compactPath = splitPath(item.name).slice(1);
1010
+ while (compactPath.length > 0) {
1011
+ if (compactPath[0] === pathFlag[0]) {
1012
+ compactPath.shift();
1013
+ pathFlag.shift();
1014
+ }
1015
+ else {
1016
+ break;
1017
+ }
1018
+ }
1019
+ }
1020
+ if (!item._children) {
1021
+ preItemPath = item.path;
1022
+ if (CompositeTreeNode.is(item)) {
1023
+ await item.setExpanded(true, true);
1024
+ }
1025
+ }
1026
+ if (item && pathFlag.length === 0) {
1027
+ return item;
1028
+ }
1029
+ else {
1030
+ if (!!preItemPath && preItemPath !== item.path) {
1031
+ // 说明此时已发生了路径压缩,如从 a -> a/b/c
1032
+ // 需要根据路径变化移除对应的展开路径, 这里只需考虑短变长场景
1033
+ const prePaths = utils_1.Path.splitPath(preItemPath);
1034
+ const nextPaths = utils_1.Path.splitPath(item.path);
1035
+ if (nextPaths.length > prePaths.length) {
1036
+ pathFlag.splice(0, nextPaths.length - prePaths.length);
1037
+ }
1038
+ }
1039
+ next = item._children;
1040
+ preItem = item;
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ /**
1046
+ * 根据节点获取节点ID下标位置
1047
+ * @param {number} id
1048
+ * @returns
1049
+ * @memberof CompositeTreeNode
1050
+ */
1051
+ getIndexAtTreeNodeId(id) {
1052
+ if (this._flattenedBranch) {
1053
+ return this._flattenedBranch.indexOf(id);
1054
+ }
1055
+ return -1;
1056
+ }
1057
+ /**
1058
+ * 根据节点获取节点下标位置
1059
+ * @param {ITreeNodeOrCompositeTreeNode} node
1060
+ * @returns
1061
+ * @memberof CompositeTreeNode
1062
+ */
1063
+ getIndexAtTreeNode(node) {
1064
+ if (this._flattenedBranch) {
1065
+ return this._flattenedBranch.indexOf(node.id);
1066
+ }
1067
+ return -1;
1068
+ }
1069
+ /**
1070
+ * 根据下标位置获取节点
1071
+ * @param {number} index
1072
+ * @returns
1073
+ * @memberof CompositeTreeNode
1074
+ */
1075
+ getTreeNodeAtIndex(index) {
1076
+ const id = this._flattenedBranch[index];
1077
+ return TreeNode.getTreeNodeById(id);
1078
+ }
1079
+ /**
1080
+ * 根据节点ID获取节点
1081
+ * @param {number} id
1082
+ * @returns
1083
+ * @memberof CompositeTreeNode
1084
+ */
1085
+ getTreeNodeById(id) {
1086
+ return TreeNode.getTreeNodeById(id);
1087
+ }
1088
+ /**
1089
+ * 根据节点路径获取节点
1090
+ * @param {string} path
1091
+ * @returns
1092
+ * @memberof CompositeTreeNode
1093
+ */
1094
+ getTreeNodeByPath(path) {
1095
+ return TreeNode.getTreeNodeByPath(path);
1096
+ }
1097
+ }
1098
+ exports.CompositeTreeNode = CompositeTreeNode;
1099
+ //# sourceMappingURL=TreeNode.js.map