Skip to content

Commit 6c214f8

Browse files
committed
Merge branch 'develop'
2 parents d8f817b + de5ba3b commit 6c214f8

File tree

5 files changed

+81
-52
lines changed

5 files changed

+81
-52
lines changed

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Changelog
2+
3+
### Current
4+
- Fix collapse all button (thank to matthieu-crouzet)
5+
- Add scroll direcly on the current file opened (thank to matthieu-crouzet)
6+
7+
### 18.3.0
8+
- Make change current file reactive (thank to matthieu-crouzet)
9+
10+
### 18.2.0
11+
- Update dependencies
12+
13+
### 18.1.0
14+
- Upgrade to Angular 18
15+
16+
### 17.5.0
17+
- Add default value (thank to matthieu-crouzet)
18+
19+
### 17.3.0
20+
- Bug fix publish directory (thank to DustdevDM)
21+
22+
### 17.1.0
23+
- Migrate to Angular 17
24+
- Add color to files
25+
- Add highlight on selected file or folder
26+
- Add buttons to create file or folder, and collapse all folders
27+
- Drag & Drop
28+
29+
### 15.2.0
30+
- Migrate from yarn to pnpm
31+
- Create a project with Angular 17 to test the compatibility
32+
- Passing to standalone components
33+
- CI/CD with Github Actions
34+
35+
### 15.1.1
36+
- Add demo on stackblitz in README
37+
38+
### 15.1.0
39+
- Fix theme in context menu
40+
41+
### 15.0.0
42+
- Upgrade to Angular 15
43+
44+
### 14.0.0
45+
- Upgrade to Angular 14

projects/ngx-monaco-tree-test/src/app/app.component.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {CommonModule} from "@angular/common";
55
import {NgxMonacoTreeComponent} from "../../../ngx-monaco-tree/src/lib/ngx-monaco-tree.component";
66
import {DragAndDropEvent} from "../../../ngx-monaco-tree/src/lib/monaco-tree-file/monaco-tree-file.type";
77

8+
const TOO_MANY_FILES_IN_FOLDER = 200;
9+
810
@Component({
911
selector: 'app-root',
1012
standalone: true,
@@ -44,6 +46,10 @@ export class AppComponent {
4446
{ name: 'environment.ts' },
4547
],
4648
},
49+
{
50+
name: 'folder-with-too-many-files',
51+
content: Array.from({ length: TOO_MANY_FILES_IN_FOLDER }).map((_, index) => ({ name: `file_${index + 1}.ts`}))
52+
},
4753
{
4854
name: 'favicon.ico',
4955
},
@@ -76,9 +82,9 @@ export class AppComponent {
7682
];
7783

7884
changeCurrentFile() {
79-
this.currentFile = this.currentFile === 'src/environments/environment.ts'
85+
this.currentFile = this.currentFile === `src/folder-with-too-many-files/file_${TOO_MANY_FILES_IN_FOLDER}.ts`
8086
? 'src/app/app.component.html'
81-
: 'src/environments/environment.ts';
87+
: `src/folder-with-too-many-files/file_${TOO_MANY_FILES_IN_FOLDER}.ts`;
8288
}
8389

8490
handleContextMenu(action: ContextMenuAction) {
@@ -140,9 +146,9 @@ export class AppComponent {
140146
path: string,
141147
localTree: MonacoTreeElement[]
142148
) {
143-
const spited = path.split('/');
149+
const splitted = path.split('/');
144150
if (!filename) return;
145-
if (spited.length === 1) {
151+
if (splitted.length === 1) {
146152
const file = localTree.find((el) => el.name == path);
147153
if (!file) return;
148154
else if (file.content === undefined) {
@@ -157,9 +163,9 @@ export class AppComponent {
157163
});
158164
}
159165
} else {
160-
const file = localTree.find((el) => el.name == spited[0]);
166+
const file = localTree.find((el) => el.name == splitted[0]);
161167
if (!file || !file.content) return;
162-
this.create(type, filename, spited.slice(1).join('/'), file?.content);
168+
this.create(type, filename, splitted.slice(1).join('/'), file?.content);
163169
}
164170
}
165171

projects/ngx-monaco-tree/README.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,7 @@ This is a Tree view based on [monaco-editor](https://github.com/microsoft/monaco
99
<img width="387" alt="Screenshot 2022-02-06 at 21 57 31" src="https://user-images.githubusercontent.com/44646690/152701329-f53622ee-d28e-4019-ac70-ae551d36560f.png">
1010

1111
## Changelog
12-
13-
### Current
14-
- Update dependencies
15-
16-
### 18.1.0
17-
- Upgrade to Angular 18
18-
19-
### 17.5.0
20-
- Add default value (thank to matthieu-crouzet)
21-
22-
### 17.3.0
23-
- Bug fix publish directory (thank to DustdevDM)
24-
25-
### 17.1.0
26-
- Migrate to Angular 17
27-
- Add color to files
28-
- Add highlight on selected file or folder
29-
- Add buttons to create file or folder, and collapse all folders
30-
- Drag & Drop
31-
32-
### 15.2.0
33-
- Migrate from yarn to pnpm
34-
- Create a project with Angular 17 to test the compatibility
35-
- Passing to standalone components
36-
- CI/CD with Github Actions
37-
38-
### 15.1.1
39-
- Add demo on stackblitz in README
40-
41-
### 15.1.0
42-
- Fix theme in context menu
43-
44-
### 15.0.0
45-
- Upgrade to Angular 15
46-
47-
### 14.0.0
48-
- Upgrade to Angular 14
49-
12+
See CHANGELOG.md
5013

5114
## Features
5215

projects/ngx-monaco-tree/src/lib/monaco-tree-file/monaco-tree-file.component.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ElementRef, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges} from '@angular/core';
1+
import {Component, ElementRef, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges, viewChildren} from '@angular/core';
22
import { extensions } from '../../utils/extension-icon';
33
import { files } from '../../utils/file-icon';
44
import { folders } from '../../utils/folder-icon';
@@ -12,7 +12,6 @@ import {MonacoTreeContextMenuComponent} from "../monaco-tree-context-menu/monaco
1212
import {NgForOf, NgIf, NgStyle} from "@angular/common";
1313
import {DragDropModule, CdkDragDrop, CdkDrag, CdkDropList} from '@angular/cdk/drag-drop';
1414

15-
1615
function getAbsolutePosition(element: any) {
1716
const r = { x: element.offsetLeft, y: element.offsetTop };
1817
if (element.offsetParent) {
@@ -44,6 +43,8 @@ export class MonacoTreeFileComponent implements OnChanges {
4443
@Output() contextMenuClick = new EventEmitter<ContextMenuAction>();
4544
@Output() dragDropFile = new EventEmitter<DragAndDropEvent>();
4645

46+
private children = viewChildren(MonacoTreeFileComponent);
47+
4748
open = false;
4849
position: [number, number]|undefined = undefined;
4950

@@ -56,10 +57,18 @@ export class MonacoTreeFileComponent implements OnChanges {
5657
changes['current']
5758
&& !!this.current
5859
&& this.current.startsWith(this.path)
59-
&& !this.open
60-
&& this.current !== this.path
6160
) {
62-
this.toggle(false);
61+
if (!this.open && this.current !== this.path) {
62+
this.toggle(false);
63+
}
64+
if (this.current === this.path) {
65+
// Needed as `scrollIntoViewIfNeeded` is not supported on Firefox
66+
if (this.eRef.nativeElement.scrollIntoViewIfNeeded) {
67+
this.eRef.nativeElement.scrollIntoViewIfNeeded();
68+
} else {
69+
this.eRef.nativeElement.scrollIntoView();
70+
}
71+
}
6372
}
6473
}
6574

@@ -147,6 +156,11 @@ export class MonacoTreeFileComponent implements OnChanges {
147156
this.contextMenuClick.emit([event[0], this.name + '/' + event[1]]);
148157
}
149158

159+
collapseAll() {
160+
this.children().forEach((child) => child.collapseAll());
161+
this.open = false;
162+
}
163+
150164
@HostListener('document:contextmenu', ['$event'])
151165
clickOut(event: MouseEvent) {
152166
if(!this.eRef.nativeElement.contains(event.target)) {

projects/ngx-monaco-tree/src/lib/ngx-monaco-tree.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, OnInit, Output, viewChildren } from '@angular/core';
22
import { MonacoTreeElement } from './ngx-monaco-tree.type';
33
import {ContextMenuAction, DragAndDropEvent} from "./monaco-tree-file/monaco-tree-file.type";
44
import {MonacoTreeFileComponent} from "./monaco-tree-file/monaco-tree-file.component";
@@ -32,6 +32,8 @@ export class NgxMonacoTreeComponent {
3232

3333
@Input() currentFile: string|null = null;
3434

35+
private children = viewChildren(MonacoTreeFileComponent);
36+
3537
handleClickFile(path: string) {
3638
this.clickFile.emit(path);
3739
this.currentFile = path;
@@ -54,7 +56,6 @@ export class NgxMonacoTreeComponent {
5456
}
5557

5658
handleCollapseAll() {
57-
const tree = JSON.parse(JSON.stringify(this.tree));
58-
this.tree = tree;
59+
this.children().forEach((child) => child.collapseAll());
5960
}
6061
}

0 commit comments

Comments
 (0)