@opensumi/ide-components 2.21.13 → 2.22.0
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.
- package/dist/1.index.js +7994 -0
- package/dist/index.css +1 -1
- package/dist/index.js +2390 -10030
- package/lib/button/index.d.ts +4 -4
- package/lib/button/index.d.ts.map +1 -1
- package/lib/checkbox/style.less +1 -1
- package/lib/dialog/index.d.ts +1 -1
- package/lib/dialog/index.d.ts.map +1 -1
- package/lib/dropdown/dropdown.d.ts +2 -2
- package/lib/dropdown/dropdown.d.ts.map +1 -1
- package/lib/icon/icon.d.ts +3 -2
- package/lib/icon/icon.d.ts.map +1 -1
- package/lib/icon/icon.js +5 -2
- package/lib/icon/icon.js.map +1 -1
- package/lib/icon/iconfont/iconManager.d.ts +2 -0
- package/lib/icon/iconfont/iconManager.d.ts.map +1 -1
- package/lib/icon/iconfont/iconMap.d.ts +2 -0
- package/lib/icon/iconfont/iconMap.d.ts.map +1 -1
- package/lib/icon/iconfont/iconMap.js +2 -0
- package/lib/icon/iconfont/iconMap.js.map +1 -1
- package/lib/icon/iconfont/iconfont.css +27 -7
- package/lib/icon/iconfont/iconfont.eot +0 -0
- package/lib/icon/iconfont/iconfont.html +3 -3
- package/lib/icon/iconfont/iconfont.js +1 -1
- package/lib/icon/iconfont/iconfont.json +56 -21
- package/lib/icon/iconfont/iconfont.svg +4 -0
- package/lib/icon/iconfont/iconfont.ttf +0 -0
- package/lib/icon/iconfont/iconfont.woff +0 -0
- package/lib/icon/iconfont/iconfont.woff2 +0 -0
- package/lib/icon/iconfont/index.html +15 -0
- package/lib/icon/iconfont-cn.d.ts +1 -1
- package/lib/icon/iconfont-cn.d.ts.map +1 -1
- package/lib/icon/styles.less +2 -2
- package/lib/locale-context-provider.d.ts +2 -2
- package/lib/locale-context-provider.d.ts.map +1 -1
- package/lib/markdown/index.d.ts +15 -0
- package/lib/markdown/index.d.ts.map +1 -0
- package/lib/markdown/index.js +25 -0
- package/lib/markdown/index.js.map +1 -0
- package/lib/markdown/render.d.ts +11 -0
- package/lib/markdown/render.d.ts.map +1 -0
- package/lib/markdown/render.js +35 -0
- package/lib/markdown/render.js.map +1 -0
- package/lib/menu/MenuContext.d.ts +1 -1
- package/lib/menu/MenuContext.d.ts.map +1 -1
- package/lib/menu/index.d.ts +2 -2
- package/lib/menu/index.d.ts.map +1 -1
- package/lib/menu/index.js +26 -26
- package/lib/menu/index.js.map +1 -1
- package/lib/menu/style.less +0 -5
- package/lib/message/index.d.ts +5 -5
- package/lib/message/index.d.ts.map +1 -1
- package/lib/message/message.d.ts +6 -6
- package/lib/message/message.d.ts.map +1 -1
- package/lib/modal/Modal.d.ts +3 -3
- package/lib/modal/Modal.d.ts.map +1 -1
- package/lib/notification/notification.d.ts +2 -2
- package/lib/notification/notification.d.ts.map +1 -1
- package/lib/popover/index.d.ts.map +1 -1
- package/lib/popover/index.js +3 -1
- package/lib/popover/index.js.map +1 -1
- package/lib/popover/styles.less +1 -1
- package/lib/recycle-list/RecycleList.js +1 -1
- package/lib/recycle-list/RecycleList.js.map +1 -1
- package/lib/recycle-tree/RecycleTree.d.ts +2 -2
- package/lib/recycle-tree/RecycleTree.d.ts.map +1 -1
- package/lib/recycle-tree/TreeNodeRendererWrap.d.ts +2 -2
- package/lib/recycle-tree/TreeNodeRendererWrap.d.ts.map +1 -1
- package/lib/recycle-tree/basic/index.d.ts.map +1 -1
- package/lib/recycle-tree/basic/index.js +45 -21
- package/lib/recycle-tree/basic/index.js.map +1 -1
- package/lib/recycle-tree/basic/styles.less +3 -2
- package/lib/recycle-tree/basic/tree-node.define.d.ts +8 -4
- package/lib/recycle-tree/basic/tree-node.define.d.ts.map +1 -1
- package/lib/recycle-tree/basic/tree-node.define.js +12 -9
- package/lib/recycle-tree/basic/tree-node.define.js.map +1 -1
- package/lib/recycle-tree/basic/tree-node.js +4 -2
- package/lib/recycle-tree/basic/tree-node.js.map +1 -1
- package/lib/recycle-tree/basic/tree-service.d.ts +9 -1
- package/lib/recycle-tree/basic/tree-service.d.ts.map +1 -1
- package/lib/recycle-tree/basic/tree-service.js +28 -7
- package/lib/recycle-tree/basic/tree-service.js.map +1 -1
- package/lib/recycle-tree/basic/types.d.ts +28 -8
- package/lib/recycle-tree/basic/types.d.ts.map +1 -1
- package/lib/recycle-tree/basic/types.js.map +1 -1
- package/lib/recycle-tree/decorators/Adaptive/index.d.ts +1 -1
- package/lib/recycle-tree/decorators/Adaptive/index.d.ts.map +1 -1
- package/lib/recycle-tree/decorators/Filter/index.d.ts +1 -1
- package/lib/recycle-tree/decorators/Filter/index.d.ts.map +1 -1
- package/lib/recycle-tree/tree/TreeNode.d.ts +18 -5
- package/lib/recycle-tree/tree/TreeNode.d.ts.map +1 -1
- package/lib/recycle-tree/tree/TreeNode.js +236 -159
- package/lib/recycle-tree/tree/TreeNode.js.map +1 -1
- package/lib/recycle-tree/types/tree-node.d.ts +5 -1
- package/lib/recycle-tree/types/tree-node.d.ts.map +1 -1
- package/lib/recycle-tree/types/tree-node.js.map +1 -1
- package/lib/recycle-tree/types/tree.d.ts +2 -1
- package/lib/recycle-tree/types/tree.d.ts.map +1 -1
- package/lib/recycle-tree/types/watcher.d.ts +4 -4
- package/lib/recycle-tree/types/watcher.d.ts.map +1 -1
- package/lib/scrollbars/index.d.ts +4 -1
- package/lib/scrollbars/index.d.ts.map +1 -1
- package/lib/scrollbars/index.js +21 -4
- package/lib/scrollbars/index.js.map +1 -1
- package/lib/scrollbars/styles.less +5 -0
- package/lib/utils/deprecated.d.ts +1 -1
- package/lib/utils/deprecated.d.ts.map +1 -1
- package/lib/utils/deprecated.js.map +1 -1
- package/lib/utils/marked.d.ts +3 -2
- package/lib/utils/marked.d.ts.map +1 -1
- package/lib/utils/marked.js.map +1 -1
- package/lib/utils/motion.d.ts +1 -1
- package/lib/utils/motion.d.ts.map +1 -1
- package/lib/utils/type.d.ts +1 -1
- package/lib/utils/type.d.ts.map +1 -1
- package/lib/virtual-list/index.d.ts +4 -0
- package/lib/virtual-list/index.d.ts.map +1 -0
- package/lib/virtual-list/index.js +23 -0
- package/lib/virtual-list/index.js.map +1 -0
- package/lib/virtual-list/types.d.ts +30 -0
- package/lib/virtual-list/types.d.ts.map +1 -0
- package/lib/virtual-list/types.js +3 -0
- package/lib/virtual-list/types.js.map +1 -0
- package/package.json +10 -8
|
@@ -25,21 +25,6 @@ var BranchOperatorStatus;
|
|
|
25
25
|
BranchOperatorStatus[BranchOperatorStatus["SHRINKED"] = 2] = "SHRINKED";
|
|
26
26
|
})(BranchOperatorStatus = exports.BranchOperatorStatus || (exports.BranchOperatorStatus = {}));
|
|
27
27
|
class TreeNode {
|
|
28
|
-
constructor(tree, parent, watcher, optionalMetadata) {
|
|
29
|
-
this._uid = TreeNode.nextId();
|
|
30
|
-
this._parent = parent;
|
|
31
|
-
this._tree = tree;
|
|
32
|
-
this._disposed = false;
|
|
33
|
-
this._visible = true;
|
|
34
|
-
this._metadata = Object.assign({}, (optionalMetadata || {}));
|
|
35
|
-
this._depth = parent ? parent.depth + 1 : 0;
|
|
36
|
-
if (watcher) {
|
|
37
|
-
this._watcher = watcher;
|
|
38
|
-
}
|
|
39
|
-
else if (parent) {
|
|
40
|
-
this._watcher = parent.watcher;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
28
|
static is(node) {
|
|
44
29
|
return !!node && 'depth' in node && 'name' in node && 'path' in node && 'id' in node;
|
|
45
30
|
}
|
|
@@ -64,8 +49,7 @@ class TreeNode {
|
|
|
64
49
|
return TreeNode.pathToId.set(path, id);
|
|
65
50
|
}
|
|
66
51
|
static getGlobalTreeState(path) {
|
|
67
|
-
|
|
68
|
-
let state = TreeNode.pathToGlobalTreeState.get(root);
|
|
52
|
+
let state = TreeNode.pathToGlobalTreeState.get(path);
|
|
69
53
|
if (!state) {
|
|
70
54
|
state = {
|
|
71
55
|
isExpanding: false,
|
|
@@ -78,8 +62,7 @@ class TreeNode {
|
|
|
78
62
|
return state;
|
|
79
63
|
}
|
|
80
64
|
static setGlobalTreeState(path, updateState) {
|
|
81
|
-
|
|
82
|
-
let state = TreeNode.pathToGlobalTreeState.get(root);
|
|
65
|
+
let state = TreeNode.pathToGlobalTreeState.get(path);
|
|
83
66
|
if (!state) {
|
|
84
67
|
state = {
|
|
85
68
|
isExpanding: false,
|
|
@@ -90,9 +73,24 @@ class TreeNode {
|
|
|
90
73
|
};
|
|
91
74
|
}
|
|
92
75
|
state = Object.assign(Object.assign({}, state), updateState);
|
|
93
|
-
TreeNode.pathToGlobalTreeState.set(
|
|
76
|
+
TreeNode.pathToGlobalTreeState.set(path, state);
|
|
94
77
|
return state;
|
|
95
78
|
}
|
|
79
|
+
constructor(tree, parent, watcher, optionalMetadata) {
|
|
80
|
+
this._uid = TreeNode.nextId();
|
|
81
|
+
this._parent = parent;
|
|
82
|
+
this._tree = tree;
|
|
83
|
+
this._disposed = false;
|
|
84
|
+
this._visible = true;
|
|
85
|
+
this._metadata = Object.assign({}, (optionalMetadata || {}));
|
|
86
|
+
this._depth = parent ? parent.depth + 1 : 0;
|
|
87
|
+
if (watcher) {
|
|
88
|
+
this._watcher = watcher;
|
|
89
|
+
}
|
|
90
|
+
else if (parent) {
|
|
91
|
+
this._watcher = parent.watcher;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
96
94
|
get disposed() {
|
|
97
95
|
return this._disposed;
|
|
98
96
|
}
|
|
@@ -244,80 +242,6 @@ TreeNode.pathToId = new Map();
|
|
|
244
242
|
// 每颗树都只会在根节点上绑定一个可取消的对象,即同个时间点只能存在一个改变树数据结构的事情
|
|
245
243
|
TreeNode.pathToGlobalTreeState = new Map();
|
|
246
244
|
class CompositeTreeNode extends TreeNode {
|
|
247
|
-
// parent 为undefined即表示该节点为根节点
|
|
248
|
-
constructor(tree, parent, watcher, optionalMetadata) {
|
|
249
|
-
super(tree, parent, watcher, optionalMetadata);
|
|
250
|
-
this._children = null;
|
|
251
|
-
this.refreshThrottler = new ide_utils_1.Throttler();
|
|
252
|
-
this._lock = false;
|
|
253
|
-
/**
|
|
254
|
-
* 处理Watch事件,同时可通过外部手动调 g用节点更新函数进行节点替换,这里为通用的事件管理
|
|
255
|
-
* 如: transferItem,insertItem, unlinkItem等
|
|
256
|
-
* @private
|
|
257
|
-
* @memberof CompositeTreeNode
|
|
258
|
-
*/
|
|
259
|
-
this.handleWatchEvent = async (event) => {
|
|
260
|
-
this.watcher.notifyWillProcessWatchEvent(this, event);
|
|
261
|
-
if (event.type === types_1.WatchEvent.Moved) {
|
|
262
|
-
const { oldPath, newPath } = event;
|
|
263
|
-
if (typeof oldPath !== 'string') {
|
|
264
|
-
throw new TypeError('Expected oldPath to be a string');
|
|
265
|
-
}
|
|
266
|
-
if (typeof newPath !== 'string') {
|
|
267
|
-
throw new TypeError('Expected newPath to be a string');
|
|
268
|
-
}
|
|
269
|
-
if (Path.isRelative(oldPath)) {
|
|
270
|
-
throw new TypeError('oldPath must be absolute');
|
|
271
|
-
}
|
|
272
|
-
if (Path.isRelative(newPath)) {
|
|
273
|
-
throw new TypeError('newPath must be absolute');
|
|
274
|
-
}
|
|
275
|
-
this.transferItem(oldPath, newPath);
|
|
276
|
-
}
|
|
277
|
-
else if (event.type === types_1.WatchEvent.Added) {
|
|
278
|
-
const { node } = event;
|
|
279
|
-
if (!TreeNode.is(node)) {
|
|
280
|
-
throw new TypeError('Expected node to be a TreeNode');
|
|
281
|
-
}
|
|
282
|
-
this.insertItem(node);
|
|
283
|
-
}
|
|
284
|
-
else if (event.type === types_1.WatchEvent.Removed) {
|
|
285
|
-
const { path } = event;
|
|
286
|
-
const pathObject = new Path(path);
|
|
287
|
-
const dirName = pathObject.dir.toString();
|
|
288
|
-
const name = pathObject.base.toString();
|
|
289
|
-
if (dirName === this.path && !!this.children) {
|
|
290
|
-
const item = this.children.find((c) => c.name === name);
|
|
291
|
-
if (item) {
|
|
292
|
-
this.unlinkItem(item);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
// 如果当前变化的节点已在数据视图(并非滚动到不可见区域)中不可见,则将该节点折叠,待下次更新即可,
|
|
298
|
-
if (!this.isItemVisibleAtRootSurface(this)) {
|
|
299
|
-
this.isExpanded = false;
|
|
300
|
-
this._children = null;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
// needReload --- 判断根目录是否需要进行一次刷新,部分情况,如压缩目录下的文件创建后不应该刷新
|
|
304
|
-
await this.refresh();
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
this.watcher.notifyDidProcessWatchEvent(this, event);
|
|
308
|
-
};
|
|
309
|
-
this.isExpanded = parent ? false : true;
|
|
310
|
-
this._branchSize = 0;
|
|
311
|
-
if (!parent) {
|
|
312
|
-
this.watchEvents = new Map();
|
|
313
|
-
// 为根节点创建监听器
|
|
314
|
-
this._watcher = this.generatorWatcher();
|
|
315
|
-
TreeNode.setTreeNode(this.id, this.path, this);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
this._watcher = parent.watcher;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
245
|
static defaultSortComparator(a, b) {
|
|
322
246
|
if (a.constructor === b.constructor) {
|
|
323
247
|
return a.name > b.name ? 1 : a.name < b.name ? -1 : 0;
|
|
@@ -396,6 +320,81 @@ class CompositeTreeNode extends TreeNode {
|
|
|
396
320
|
};
|
|
397
321
|
return watcher;
|
|
398
322
|
}
|
|
323
|
+
// parent 为undefined即表示该节点为根节点
|
|
324
|
+
constructor(tree, parent, watcher, optionalMetadata) {
|
|
325
|
+
super(tree, parent, watcher, optionalMetadata);
|
|
326
|
+
this._children = null;
|
|
327
|
+
this._lock = false;
|
|
328
|
+
this.refreshThrottler = new ide_utils_1.ThrottledDelayer(CompositeTreeNode.REFRESH_DELAY);
|
|
329
|
+
this.toRefreshPathQueue = new Set();
|
|
330
|
+
/**
|
|
331
|
+
* 处理 Watch 事件,同时可通过外部手动调 g用节点更新函数进行节点替换,这里为通用的事件管理
|
|
332
|
+
* 如: transferItem,insertItem, unlinkItem等
|
|
333
|
+
* @private
|
|
334
|
+
* @memberof CompositeTreeNode
|
|
335
|
+
*/
|
|
336
|
+
this.handleWatchEvent = async (event) => {
|
|
337
|
+
this.watcher.notifyWillProcessWatchEvent(this, event);
|
|
338
|
+
if (event.type === types_1.WatchEvent.Moved) {
|
|
339
|
+
const { oldPath, newPath } = event;
|
|
340
|
+
if (typeof oldPath !== 'string') {
|
|
341
|
+
throw new TypeError('Expected oldPath to be a string');
|
|
342
|
+
}
|
|
343
|
+
if (typeof newPath !== 'string') {
|
|
344
|
+
throw new TypeError('Expected newPath to be a string');
|
|
345
|
+
}
|
|
346
|
+
if (Path.isRelative(oldPath)) {
|
|
347
|
+
throw new TypeError('oldPath must be absolute');
|
|
348
|
+
}
|
|
349
|
+
if (Path.isRelative(newPath)) {
|
|
350
|
+
throw new TypeError('newPath must be absolute');
|
|
351
|
+
}
|
|
352
|
+
this.transferItem(oldPath, newPath);
|
|
353
|
+
}
|
|
354
|
+
else if (event.type === types_1.WatchEvent.Added) {
|
|
355
|
+
const { node } = event;
|
|
356
|
+
if (!TreeNode.is(node)) {
|
|
357
|
+
throw new TypeError('Expected node to be a TreeNode');
|
|
358
|
+
}
|
|
359
|
+
this.insertItem(node);
|
|
360
|
+
}
|
|
361
|
+
else if (event.type === types_1.WatchEvent.Removed) {
|
|
362
|
+
const { path } = event;
|
|
363
|
+
const pathObject = new Path(path);
|
|
364
|
+
const dirName = pathObject.dir.toString();
|
|
365
|
+
const name = pathObject.base.toString();
|
|
366
|
+
if (dirName === this.path && !!this.children) {
|
|
367
|
+
const item = this.children.find((c) => c.name === name);
|
|
368
|
+
if (item) {
|
|
369
|
+
this.unlinkItem(item);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
// 如果当前变化的节点已在数据视图(并非滚动到不可见区域)中不可见,则将该节点折叠,待下次更新即可,
|
|
375
|
+
if (!this.isItemVisibleAtRootSurface(this)) {
|
|
376
|
+
this.isExpanded = false;
|
|
377
|
+
this._children = null;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
await this.refresh();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
this.watcher.notifyDidProcessWatchEvent(this, event);
|
|
384
|
+
};
|
|
385
|
+
this.isExpanded = parent ? false : true;
|
|
386
|
+
this._branchSize = 0;
|
|
387
|
+
if (!parent) {
|
|
388
|
+
this.watchEvents = new Map();
|
|
389
|
+
// 为根节点创建监听器
|
|
390
|
+
this._watcher = this.generatorWatcher();
|
|
391
|
+
this._root = this;
|
|
392
|
+
TreeNode.setTreeNode(this.id, this.path, this);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
this._watcher = parent.watcher;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
399
398
|
// 重载 name 的 getter/setter,路径改变时需要重新监听文件节点变化
|
|
400
399
|
set name(name) {
|
|
401
400
|
const prevPath = this.path;
|
|
@@ -452,6 +451,19 @@ class CompositeTreeNode extends TreeNode {
|
|
|
452
451
|
get lock() {
|
|
453
452
|
return this._lock;
|
|
454
453
|
}
|
|
454
|
+
get root() {
|
|
455
|
+
if ((0, ide_utils_1.isUndefined)(this._root)) {
|
|
456
|
+
this._root = this.getRoot() || null;
|
|
457
|
+
}
|
|
458
|
+
return this._root;
|
|
459
|
+
}
|
|
460
|
+
getRoot() {
|
|
461
|
+
let root = this.parent;
|
|
462
|
+
while (root && root.parent) {
|
|
463
|
+
root = root.parent;
|
|
464
|
+
}
|
|
465
|
+
return root;
|
|
466
|
+
}
|
|
455
467
|
/**
|
|
456
468
|
* 确保此“目录”的子级已加载(不影响“展开”状态)
|
|
457
469
|
* 如果子级已经加载,则返回的Promise将立即解决
|
|
@@ -528,14 +540,24 @@ class CompositeTreeNode extends TreeNode {
|
|
|
528
540
|
TreeNode.setTreeNode(this.id, this.path, this);
|
|
529
541
|
}
|
|
530
542
|
}
|
|
543
|
+
isCompactNode(node) {
|
|
544
|
+
return CompositeTreeNode.is(node) && node.name.includes(Path.separator);
|
|
545
|
+
}
|
|
531
546
|
// 获取当前节点下所有展开的节点路径
|
|
532
547
|
getAllExpandedNodePath() {
|
|
548
|
+
var _a;
|
|
533
549
|
let paths = [];
|
|
534
550
|
if (this.children) {
|
|
535
551
|
for (let i = 0; i < this.children.length; i++) {
|
|
536
552
|
const child = this.children[i];
|
|
537
553
|
if (CompositeTreeNode.is(child) && child.expanded) {
|
|
538
|
-
|
|
554
|
+
if (this.isCompactNode(child) && ((_a = child.parent) === null || _a === void 0 ? void 0 : _a.path)) {
|
|
555
|
+
// 当获取到的节点为压缩节点时,仅需要存储其根路径,便于后续展开更新节点状态
|
|
556
|
+
paths.push(new Path(child.parent.path).join(child.name.split(Path.separator)[0]).toString());
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
paths.push(child.path);
|
|
560
|
+
}
|
|
539
561
|
paths = paths.concat(child.getAllExpandedNodePath());
|
|
540
562
|
}
|
|
541
563
|
}
|
|
@@ -572,7 +594,7 @@ class CompositeTreeNode extends TreeNode {
|
|
|
572
594
|
* @param token CancellationToken
|
|
573
595
|
*/
|
|
574
596
|
async resolveChildrens(token) {
|
|
575
|
-
var _a;
|
|
597
|
+
var _a, _b, _c;
|
|
576
598
|
let childrens = this.children;
|
|
577
599
|
let expandedPaths = [];
|
|
578
600
|
try {
|
|
@@ -598,8 +620,8 @@ class CompositeTreeNode extends TreeNode {
|
|
|
598
620
|
flatTree[i] = this._children[i].id;
|
|
599
621
|
}
|
|
600
622
|
const expandedChilds = [];
|
|
601
|
-
for (let i = 0
|
|
602
|
-
const subChild = this.children[i];
|
|
623
|
+
for (let i = 0, len = ((_b = this.children) === null || _b === void 0 ? void 0 : _b.length) || 0; i < len; i++) {
|
|
624
|
+
const subChild = (_c = this.children) === null || _c === void 0 ? void 0 : _c[i];
|
|
603
625
|
if (CompositeTreeNode.is(subChild) && subChild.expanded) {
|
|
604
626
|
const paths = await subChild.resolveChildrens(token);
|
|
605
627
|
if (paths) {
|
|
@@ -629,16 +651,22 @@ class CompositeTreeNode extends TreeNode {
|
|
|
629
651
|
}
|
|
630
652
|
}
|
|
631
653
|
}
|
|
632
|
-
|
|
633
|
-
|
|
654
|
+
/**
|
|
655
|
+
* 静默刷新子节点, 即不触发分支更新事件
|
|
656
|
+
* @param toExpandPaths 待展开的路径
|
|
657
|
+
* @param token CancellationToken
|
|
658
|
+
* @param origin 当 this === origin 时,说明此节点为调用的源头节点
|
|
659
|
+
*/
|
|
660
|
+
async refreshTreeNodeByPaths(toExpandPaths = this.getAllExpandedNodePath(), token, origin) {
|
|
634
661
|
if (!CompositeTreeNode.is(this)) {
|
|
635
662
|
return;
|
|
636
663
|
}
|
|
637
664
|
// 如果某次刷新操作被取消,则下次刷新依旧使用上一次刷新的展开目录进行刷新
|
|
638
|
-
let
|
|
665
|
+
let toExpandPath;
|
|
666
|
+
const originChildren = this.children;
|
|
639
667
|
let childrens = this.children || [];
|
|
640
668
|
if (this.expanded) {
|
|
641
|
-
if (
|
|
669
|
+
if (this === origin) {
|
|
642
670
|
try {
|
|
643
671
|
childrens = (await this._tree.resolveChildren(this)) || [];
|
|
644
672
|
}
|
|
@@ -664,12 +692,15 @@ class CompositeTreeNode extends TreeNode {
|
|
|
664
692
|
return;
|
|
665
693
|
}
|
|
666
694
|
}
|
|
667
|
-
while ((
|
|
668
|
-
const isRelative =
|
|
695
|
+
while ((toExpandPath = toExpandPaths.shift())) {
|
|
696
|
+
const isRelative = toExpandPath.indexOf(`${this.path}${Path.separator}`) > -1;
|
|
669
697
|
if (!isRelative) {
|
|
698
|
+
if (toExpandPath === this.path) {
|
|
699
|
+
toExpandPath = undefined;
|
|
700
|
+
}
|
|
670
701
|
break;
|
|
671
702
|
}
|
|
672
|
-
const child = childrens === null || childrens === void 0 ? void 0 : childrens.find((child) => child.path ===
|
|
703
|
+
const child = childrens === null || childrens === void 0 ? void 0 : childrens.find((child) => child.path === toExpandPath);
|
|
673
704
|
// 对于压缩情况的路径需要额外处理一下
|
|
674
705
|
// 如果这里加载的路径是 a/b/c, 有可能目前只加载到 a/b
|
|
675
706
|
if (!child) {
|
|
@@ -678,33 +709,32 @@ class CompositeTreeNode extends TreeNode {
|
|
|
678
709
|
}
|
|
679
710
|
for (let i = 0; i < childrens.length; i++) {
|
|
680
711
|
const child = childrens[i];
|
|
681
|
-
if (
|
|
712
|
+
if (toExpandPath.indexOf(`${child.path}${Path.separator}`) === 0 && CompositeTreeNode.is(child)) {
|
|
682
713
|
// 包含压缩节点的情况
|
|
683
|
-
if (!CompositeTreeNode.is(child)
|
|
684
|
-
//
|
|
714
|
+
if (!CompositeTreeNode.is(child)) {
|
|
715
|
+
// 说明此节点为非折叠节点时不处理
|
|
685
716
|
continue;
|
|
686
717
|
}
|
|
687
718
|
child.isExpanded = true;
|
|
688
719
|
// 加载路径包含当前判断路径,尝试加载该节点再匹配
|
|
689
720
|
const extraExpandedPaths = await child.resolveChildrens(token);
|
|
690
|
-
if (extraExpandedPaths) {
|
|
691
|
-
expandedPaths = expandedPaths.filter((path) => !extraExpandedPaths.find((a) => a === path));
|
|
692
|
-
}
|
|
693
721
|
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) {
|
|
694
722
|
return;
|
|
695
723
|
}
|
|
696
|
-
if (
|
|
724
|
+
if (extraExpandedPaths) {
|
|
725
|
+
toExpandPaths = toExpandPaths.filter((path) => !extraExpandedPaths.find((a) => a === path));
|
|
726
|
+
}
|
|
727
|
+
if (child.path !== toExpandPath && !toExpandPath.includes(child.path)) {
|
|
728
|
+
toExpandPaths.unshift(toExpandPath);
|
|
729
|
+
}
|
|
730
|
+
if (toExpandPaths.length > 0) {
|
|
697
731
|
// 不需要重新reload压缩节点的子节点内容
|
|
698
|
-
|
|
732
|
+
toExpandPaths =
|
|
733
|
+
(await child.refreshTreeNodeByPaths([...toExpandPaths], token, origin)) || [];
|
|
699
734
|
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) {
|
|
700
735
|
return;
|
|
701
736
|
}
|
|
702
737
|
}
|
|
703
|
-
else {
|
|
704
|
-
if (child.parent !== root) {
|
|
705
|
-
child.expandBranch(child, true);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
738
|
break;
|
|
709
739
|
}
|
|
710
740
|
}
|
|
@@ -715,27 +745,31 @@ class CompositeTreeNode extends TreeNode {
|
|
|
715
745
|
child.isExpanded = true;
|
|
716
746
|
}
|
|
717
747
|
const extraExpandedPaths = await child.resolveChildrens(token);
|
|
718
|
-
if (extraExpandedPaths) {
|
|
719
|
-
expandedPaths = expandedPaths.filter((path) => !extraExpandedPaths.find((a) => a === path));
|
|
720
|
-
}
|
|
721
748
|
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) {
|
|
722
749
|
return;
|
|
723
750
|
}
|
|
724
|
-
if (
|
|
725
|
-
|
|
751
|
+
if (extraExpandedPaths) {
|
|
752
|
+
toExpandPaths = toExpandPaths.filter((path) => !extraExpandedPaths.find((a) => a === path));
|
|
753
|
+
}
|
|
754
|
+
if (toExpandPaths.length > 0 && !(token === null || token === void 0 ? void 0 : token.isCancellationRequested)) {
|
|
755
|
+
toExpandPaths =
|
|
756
|
+
(await child.refreshTreeNodeByPaths([...toExpandPaths], token, origin)) || [];
|
|
726
757
|
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) {
|
|
727
758
|
return;
|
|
728
759
|
}
|
|
729
760
|
}
|
|
730
761
|
}
|
|
731
762
|
}
|
|
732
|
-
if (
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
763
|
+
if (toExpandPath) {
|
|
764
|
+
// 仍然存在需要进一步处理的待展开路径
|
|
765
|
+
toExpandPaths.unshift(toExpandPath);
|
|
766
|
+
if (this === origin) {
|
|
767
|
+
// 说明待展开的路径已经不存在,直接处理子节点
|
|
768
|
+
if (originChildren) {
|
|
769
|
+
this.shrinkBranch(this, true);
|
|
770
|
+
for (let i = 0; i < originChildren.length; i++) {
|
|
771
|
+
const child = originChildren[i];
|
|
772
|
+
child === null || child === void 0 ? void 0 : child.dispose();
|
|
739
773
|
}
|
|
740
774
|
}
|
|
741
775
|
const expandedChilds = [];
|
|
@@ -756,24 +790,20 @@ class CompositeTreeNode extends TreeNode {
|
|
|
756
790
|
}
|
|
757
791
|
this._branchSize = flatTree.length;
|
|
758
792
|
this.setFlattenedBranch(flatTree, true);
|
|
793
|
+
this.watcher.notifyDidUpdateBranch();
|
|
759
794
|
}
|
|
760
|
-
if (this.parent !==
|
|
761
|
-
//
|
|
795
|
+
if (this.parent !== origin) {
|
|
796
|
+
// 将所有子节点合并至第二层 Children 上,减少后续递归拼接带来额外成本
|
|
762
797
|
this.expandBranch(this, true);
|
|
763
798
|
}
|
|
799
|
+
return toExpandPaths;
|
|
764
800
|
}
|
|
765
801
|
else if (CompositeTreeNode.isRoot(this)) {
|
|
766
|
-
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) {
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
802
|
if (this.children) {
|
|
770
|
-
// 重置旧的节点分支
|
|
771
803
|
this.shrinkBranch(this, true);
|
|
772
|
-
}
|
|
773
|
-
if (this.children) {
|
|
774
804
|
for (let i = 0; i < this.children.length; i++) {
|
|
775
805
|
const child = this.children[i];
|
|
776
|
-
child.dispose();
|
|
806
|
+
child === null || child === void 0 ? void 0 : child.dispose();
|
|
777
807
|
}
|
|
778
808
|
}
|
|
779
809
|
const expandedChilds = [];
|
|
@@ -822,26 +852,23 @@ class CompositeTreeNode extends TreeNode {
|
|
|
822
852
|
this.watcher.notifyDidUpdateBranch();
|
|
823
853
|
}
|
|
824
854
|
else {
|
|
825
|
-
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
855
|
+
// 非根节点刷新的情况
|
|
828
856
|
const expandedChilds = [];
|
|
829
|
-
if (
|
|
830
|
-
// 非根节点刷新的情况
|
|
857
|
+
if (this === origin) {
|
|
831
858
|
// 通知节点更新
|
|
832
859
|
if (this.children) {
|
|
833
860
|
// 重置旧的节点分支
|
|
834
861
|
this.shrinkBranch(this, true);
|
|
835
862
|
}
|
|
836
863
|
if (this.children) {
|
|
837
|
-
for (let i = 0
|
|
864
|
+
for (let i = 0, len = this.children.length; i < len; i++) {
|
|
838
865
|
const child = this.children[i];
|
|
839
866
|
child.dispose();
|
|
840
867
|
}
|
|
841
868
|
}
|
|
842
869
|
const flatTree = new Array(childrens.length);
|
|
843
870
|
this._children = Array(childrens.length);
|
|
844
|
-
for (let i = 0
|
|
871
|
+
for (let i = 0, len = childrens.length; i < len; i++) {
|
|
845
872
|
const child = childrens[i];
|
|
846
873
|
child.id = TreeNode.getIdByPath(child.path) || child.id;
|
|
847
874
|
this._children[i] = child;
|
|
@@ -874,12 +901,11 @@ class CompositeTreeNode extends TreeNode {
|
|
|
874
901
|
const child = expandedChilds[i];
|
|
875
902
|
child.expandBranch(child, true);
|
|
876
903
|
}
|
|
877
|
-
// 清理上一次监听函数
|
|
878
904
|
if (typeof this.watchTerminator === 'function') {
|
|
879
905
|
this.watchTerminator(this.path);
|
|
880
906
|
}
|
|
881
907
|
this.watchTerminator = this.watcher.onWatchEvent(this.path, this.handleWatchEvent);
|
|
882
|
-
if (
|
|
908
|
+
if (this === origin) {
|
|
883
909
|
this.expandBranch(this);
|
|
884
910
|
}
|
|
885
911
|
}
|
|
@@ -890,7 +916,7 @@ class CompositeTreeNode extends TreeNode {
|
|
|
890
916
|
// 清理子节点,等待下次展开时更新
|
|
891
917
|
if (!!this.children && this.parent) {
|
|
892
918
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
893
|
-
for (let i = 0
|
|
919
|
+
for (let i = 0, len = this.children.length; i < len; i++) {
|
|
894
920
|
const child = this.children[i];
|
|
895
921
|
child.dispose();
|
|
896
922
|
}
|
|
@@ -1049,6 +1075,7 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1049
1075
|
* 直接调用此方法将不会触发onWillHandleWatchEvent和onDidHandleWatchEvent事件
|
|
1050
1076
|
*/
|
|
1051
1077
|
unlinkItem(item, reparenting) {
|
|
1078
|
+
var _a;
|
|
1052
1079
|
if (!this._children) {
|
|
1053
1080
|
return;
|
|
1054
1081
|
}
|
|
@@ -1060,7 +1087,7 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1060
1087
|
if (!this.isItemVisibleAtRootSurface(this)) {
|
|
1061
1088
|
return;
|
|
1062
1089
|
}
|
|
1063
|
-
this._children.splice(idx, 1);
|
|
1090
|
+
(_a = this._children) === null || _a === void 0 ? void 0 : _a.splice(idx, 1);
|
|
1064
1091
|
const branchSizeDecrease = 1 + (item instanceof CompositeTreeNode && item.expanded ? item._branchSize : 0);
|
|
1065
1092
|
this._branchSize -= branchSizeDecrease;
|
|
1066
1093
|
// 逐级往上查找节点的父节点,并沿途裁剪分支数
|
|
@@ -1087,13 +1114,14 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1087
1114
|
* 转换节点路径
|
|
1088
1115
|
*/
|
|
1089
1116
|
transferItem(oldPath, newPath) {
|
|
1117
|
+
var _a;
|
|
1090
1118
|
const oldP = new Path(oldPath);
|
|
1091
1119
|
const from = oldP.dir.toString();
|
|
1092
1120
|
if (from !== this.path) {
|
|
1093
1121
|
return;
|
|
1094
1122
|
}
|
|
1095
1123
|
const name = oldP.base.toString();
|
|
1096
|
-
const item = this._children.find((c) => c.name === name);
|
|
1124
|
+
const item = (_a = this._children) === null || _a === void 0 ? void 0 : _a.find((c) => c.name === name);
|
|
1097
1125
|
if (!item) {
|
|
1098
1126
|
return;
|
|
1099
1127
|
}
|
|
@@ -1216,7 +1244,6 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1216
1244
|
const tempChildren = new Array(rawItems.length);
|
|
1217
1245
|
for (let i = 0; i < rawItems.length; i++) {
|
|
1218
1246
|
const child = rawItems[i];
|
|
1219
|
-
// 如果存在上一次缓存的节点,则使用缓存节点的 ID
|
|
1220
1247
|
child.id = TreeNode.getIdByPath(child.path) || child.id;
|
|
1221
1248
|
tempChildren[i] = child;
|
|
1222
1249
|
TreeNode.setIdByPath(child.path, child.id);
|
|
@@ -1235,13 +1262,13 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1235
1262
|
flatTree[i] = tempChildren[i].id;
|
|
1236
1263
|
}
|
|
1237
1264
|
if (this.children) {
|
|
1238
|
-
// 重置节点分支
|
|
1239
1265
|
this.shrinkBranch(this);
|
|
1240
1266
|
}
|
|
1241
1267
|
if (this.children) {
|
|
1242
1268
|
for (let i = 0; i < this.children.length; i++) {
|
|
1243
1269
|
const child = this.children[i];
|
|
1244
|
-
|
|
1270
|
+
// The Child maybe `undefined`.
|
|
1271
|
+
child === null || child === void 0 ? void 0 : child.dispose();
|
|
1245
1272
|
}
|
|
1246
1273
|
}
|
|
1247
1274
|
for (let i = 0; i < tempChildren.length; i++) {
|
|
@@ -1294,7 +1321,11 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1294
1321
|
}
|
|
1295
1322
|
}
|
|
1296
1323
|
// 当没有传入具体路径时,使用当前展开目录作为刷新路径
|
|
1297
|
-
async refresh(tokenSource) {
|
|
1324
|
+
async refresh(tokenSource, target) {
|
|
1325
|
+
if (!CompositeTreeNode.isRoot(this)) {
|
|
1326
|
+
// 刷新操作只能从根节点进行,便于对重复的刷新操作进行合并
|
|
1327
|
+
return await this.root.refresh(tokenSource, this);
|
|
1328
|
+
}
|
|
1298
1329
|
const state = TreeNode.getGlobalTreeState(this.path);
|
|
1299
1330
|
if (state.isLoadingPath || state.isExpanding) {
|
|
1300
1331
|
return;
|
|
@@ -1320,14 +1351,55 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1320
1351
|
token = state.refreshCancelToken.token;
|
|
1321
1352
|
}
|
|
1322
1353
|
}
|
|
1323
|
-
|
|
1354
|
+
this.toRefreshPathQueue.add((target || this).path);
|
|
1355
|
+
await this.refreshThrottler.trigger(() => this.doRefresh(token));
|
|
1324
1356
|
TreeNode.setGlobalTreeState(this.path, {
|
|
1325
1357
|
isRefreshing: false,
|
|
1326
1358
|
});
|
|
1327
1359
|
}
|
|
1328
1360
|
async doRefresh(token) {
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1361
|
+
const target = this.getRefreshNode() || this;
|
|
1362
|
+
if (!CompositeTreeNode.is(target)) {
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
const paths = target.getAllExpandedNodePath();
|
|
1366
|
+
await target.refreshTreeNodeByPaths(paths, token, target);
|
|
1367
|
+
}
|
|
1368
|
+
getRefreshNode() {
|
|
1369
|
+
let paths = Array.from(this.toRefreshPathQueue);
|
|
1370
|
+
this.toRefreshPathQueue.clear();
|
|
1371
|
+
if (!paths.length) {
|
|
1372
|
+
return this.root;
|
|
1373
|
+
}
|
|
1374
|
+
// 根据路径层级深度进行排序
|
|
1375
|
+
paths = paths.sort((a, b) => {
|
|
1376
|
+
const depthA = Path.pathDepth(a);
|
|
1377
|
+
const depthB = Path.pathDepth(b);
|
|
1378
|
+
return depthA - depthB;
|
|
1379
|
+
});
|
|
1380
|
+
if (paths.length === 1 || Path.pathDepth(paths[0]) === 1) {
|
|
1381
|
+
// 说明刷新队列中包含根节点,直接返回根节点进行刷新
|
|
1382
|
+
return TreeNode.getTreeNodeByPath(paths[0]);
|
|
1383
|
+
}
|
|
1384
|
+
const sortedPaths = paths.map((p) => new Path(p));
|
|
1385
|
+
let rootPath = sortedPaths[0];
|
|
1386
|
+
for (let i = 1, len = sortedPaths.length; i < len; i++) {
|
|
1387
|
+
if (rootPath.isEqualOrParent(sortedPaths[i])) {
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
else {
|
|
1391
|
+
while (!rootPath.isRoot) {
|
|
1392
|
+
rootPath = rootPath.dir;
|
|
1393
|
+
if (!rootPath || rootPath.isEqualOrParent(sortedPaths[i])) {
|
|
1394
|
+
break;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
if (rootPath) {
|
|
1400
|
+
return TreeNode.getTreeNodeByPath(rootPath.toString());
|
|
1401
|
+
}
|
|
1402
|
+
return this.root;
|
|
1331
1403
|
}
|
|
1332
1404
|
isItemVisibleAtRootSurface(node) {
|
|
1333
1405
|
let parent = node;
|
|
@@ -1571,7 +1643,11 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1571
1643
|
* @memberof CompositeTreeNode
|
|
1572
1644
|
*/
|
|
1573
1645
|
getTreeNodeAtIndex(index) {
|
|
1574
|
-
|
|
1646
|
+
var _a;
|
|
1647
|
+
const id = (_a = this._flattenedBranch) === null || _a === void 0 ? void 0 : _a[index];
|
|
1648
|
+
if (!id) {
|
|
1649
|
+
return undefined;
|
|
1650
|
+
}
|
|
1575
1651
|
return TreeNode.getTreeNodeById(id);
|
|
1576
1652
|
}
|
|
1577
1653
|
/**
|
|
@@ -1594,4 +1670,5 @@ class CompositeTreeNode extends TreeNode {
|
|
|
1594
1670
|
}
|
|
1595
1671
|
}
|
|
1596
1672
|
exports.CompositeTreeNode = CompositeTreeNode;
|
|
1673
|
+
CompositeTreeNode.REFRESH_DELAY = 200;
|
|
1597
1674
|
//# sourceMappingURL=TreeNode.js.map
|