Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Migrate the MonacoEditorModule to standalone components #9407

Merged
merged 30 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5902a58
Make Monaco standalone
pzdr7 Sep 22, 2024
f6e0e26
Use inject function
pzdr7 Sep 22, 2024
1c4cbfc
Add monaco editor service
pzdr7 Sep 22, 2024
4ea9f24
Use input and output signals
pzdr7 Sep 22, 2024
dc16948
Use input and output signals, part 2
pzdr7 Sep 22, 2024
89cf3fd
Reorganize attributes
pzdr7 Sep 22, 2024
aaf368c
Reorganize attributes, part 2
pzdr7 Sep 22, 2024
5380595
Fix aeolus tests
pzdr7 Sep 22, 2024
e5fe810
Fix monaco tests
pzdr7 Sep 22, 2024
b3a6e45
Fix build error
pzdr7 Sep 22, 2024
5c04869
Delete MonacoEditorModule
pzdr7 Sep 22, 2024
da4ea63
WIP themes
pzdr7 Sep 25, 2024
d378c63
Revert "WIP themes"
pzdr7 Oct 1, 2024
badfb0f
Merge branch 'develop' into chore/programming-exercises/monaco-themes
pzdr7 Oct 1, 2024
2ec48ba
Move theme apply to service
pzdr7 Oct 1, 2024
b44d1c0
Replace runInInjectionContext
pzdr7 Oct 1, 2024
984cbcf
Adapt change detection strategy
pzdr7 Oct 1, 2024
ab1eb8f
Use signals for theme adjustment
pzdr7 Oct 2, 2024
f380128
Remove obsolete theme tests
pzdr7 Oct 2, 2024
ee18ea8
Rework service tests
pzdr7 Oct 2, 2024
6124064
Refactor
pzdr7 Oct 2, 2024
c17be72
Refactor
pzdr7 Oct 2, 2024
a804014
Fix tests
pzdr7 Oct 2, 2024
bacddd6
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 2, 2024
4296f8a
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 3, 2024
c7ac041
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 3, 2024
7785e49
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 3, 2024
075a008
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 4, 2024
c157920
Merge branch 'develop' into chore/programming-exercises/monaco-standa…
pzdr7 Oct 6, 2024
713dffb
Update src/main/webapp/app/shared/monaco-editor/monaco-diff-editor.co…
pzdr7 Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { GitDiffFileComponent } from 'app/exercises/programming/hestia/git-diff-
import { GitDiffReportModalComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component';
import { GitDiffFilePanelComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component';
import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { GitDiffFilePanelTitleComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component';
import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module';
import { MonacoDiffEditorComponent } from 'app/shared/monaco-editor/monaco-diff-editor.component';

@NgModule({
imports: [ArtemisSharedModule, NgbAccordionModule, MonacoEditorModule, ArtemisSharedComponentModule],
imports: [ArtemisSharedModule, NgbAccordionModule, MonacoDiffEditorComponent, ArtemisSharedComponentModule],
declarations: [GitDiffFilePanelComponent, GitDiffFilePanelTitleComponent, GitDiffReportComponent, GitDiffFileComponent, GitDiffReportModalComponent, GitDiffLineStatComponent],
exports: [GitDiffReportComponent, GitDiffReportModalComponent, GitDiffLineStatComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { TestwiseCoverageReportModalComponent } from 'app/exercises/programming/
import { TestwiseCoverageReportComponent } from 'app/exercises/programming/hestia/testwise-coverage-report/testwise-coverage-report.component';
import { TestwiseCoverageFileComponent } from 'app/exercises/programming/hestia/testwise-coverage-report/testwise-coverage-file.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [ArtemisSharedModule, MatExpansionModule, MonacoEditorModule],
imports: [ArtemisSharedModule, MatExpansionModule, MonacoEditorComponent],
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
declarations: [TestwiseCoverageFileComponent, TestwiseCoverageReportComponent, TestwiseCoverageReportModalComponent],
exports: [TestwiseCoverageFileComponent, TestwiseCoverageReportModalComponent, TestwiseCoverageReportComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ArtemisCodeEditorModule } from 'app/exercises/programming/shared/code-e
import { DetailModule } from 'app/detail-overview-list/detail.module';
import { IrisModule } from 'app/iris/iris.module';
import { ArtemisExerciseModule } from 'app/exercises/shared/exercise/exercise.module';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -56,7 +56,7 @@ import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.modul
ArtemisExerciseModule,
DetailModule,
IrisModule,
MonacoEditorModule,
MonacoEditorComponent,
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
],
declarations: [
ProgrammingExerciseDetailComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { FormsModule } from 'app/forms/forms.module';
import { ProgrammingExerciseBuildPlanCheckoutDirectoriesComponent } from 'app/exercises/programming/shared/build-details/programming-exercise-build-plan-checkout-directories.component';
import { ProgrammingExerciseRepositoryAndBuildPlanDetailsComponent } from 'app/exercises/programming/shared/build-details/programming-exercise-repository-and-build-plan-details.component';
import { ProgrammingExerciseTheiaComponent } from 'app/exercises/programming/manage/update/update-components/theia/programming-exercise-theia.component';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [
Expand All @@ -57,7 +57,7 @@ import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.modul
FormsModule,
ProgrammingExerciseBuildPlanCheckoutDirectoriesComponent,
ProgrammingExerciseRepositoryAndBuildPlanDetailsComponent,
MonacoEditorModule,
MonacoEditorComponent,
ProgrammingExerciseTheiaComponent,
],
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TreeviewModule } from 'app/exercises/programming/shared/code-editor/treeview/treeview.module';
import { CodeEditorHeaderComponent } from 'app/exercises/programming/shared/code-editor/header/code-editor-header.component';
import { CodeEditorFileBrowserBadgeComponent } from 'app/exercises/programming/shared/code-editor/file-browser/code-editor-file-browser-badge.component';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { CodeEditorMonacoComponent } from 'app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component';
import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [
Expand All @@ -33,7 +33,7 @@ import { ArtemisSharedComponentModule } from 'app/shared/components/shared-compo
TreeviewModule.forRoot(),
ArtemisProgrammingExerciseInstructionsEditorModule,
ArtemisProgrammingManualAssessmentModule,
MonacoEditorModule,
MonacoEditorComponent,
ArtemisSharedComponentModule,
],
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { CastToCodeHintPipe } from 'app/exercises/shared/exercise-hint/services/
import { SolutionEntryComponent } from 'app/exercises/shared/exercise-hint/shared/solution-entry.component';
import { CodeHintContainerComponent } from 'app/exercises/shared/exercise-hint/shared/code-hint-container.component';
import { ArtemisMarkdownModule } from 'app/shared/markdown.module';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [ArtemisSharedModule, ArtemisMarkdownModule, MonacoEditorModule],
imports: [ArtemisSharedModule, ArtemisMarkdownModule, MonacoEditorComponent],
declarations: [SolutionEntryComponent, CodeHintContainerComponent, CastToCodeHintPipe],
exports: [SolutionEntryComponent, CodeHintContainerComponent, CastToCodeHintPipe],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { ArtemisSharedModule } from 'app/shared/shared.module';
import { MatMenuModule } from '@angular/material/menu';
import { MatButtonModule } from '@angular/material/button';
import { MarkdownEditorMonacoComponent } from 'app/shared/markdown-editor/monaco/markdown-editor-monaco.component';
import { MonacoEditorModule } from 'app/shared/monaco-editor/monaco-editor.module';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { MonacoEditorComponent } from 'app/shared/monaco-editor/monaco-editor.component';

@NgModule({
imports: [ArtemisSharedModule, MonacoEditorModule, FormsModule, ArtemisColorSelectorModule, MatMenuModule, MatButtonModule, DragDropModule],
imports: [ArtemisSharedModule, MonacoEditorComponent, FormsModule, ArtemisColorSelectorModule, MatMenuModule, MatButtonModule, DragDropModule],
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
declarations: [MarkdownEditorMonacoComponent],
exports: [MarkdownEditorMonacoComponent],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,65 @@
import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, Renderer2, ViewEncapsulation } from '@angular/core';
import { Theme, ThemeService } from 'app/core/theme/theme.service';
import { ChangeDetectionStrategy, Component, ElementRef, OnDestroy, OnInit, Renderer2, ViewEncapsulation, effect, inject, input, output } from '@angular/core';

import * as monaco from 'monaco-editor';
import { Subscription } from 'rxjs';
import { Disposable } from 'app/shared/monaco-editor/model/actions/monaco-editor.util';
import { MonacoEditorService } from './monaco-editor.service';

export type MonacoEditorDiffText = { original: string; modified: string };
@Component({
selector: 'jhi-monaco-diff-editor',
template: '',
standalone: true,
styleUrls: ['monaco-diff-editor.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
})
export class MonacoDiffEditorComponent implements OnInit, OnDestroy {
private _editor: monaco.editor.IStandaloneDiffEditor;
monacoDiffEditorContainerElement: HTMLElement;
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
themeSubscription?: Subscription;

allowSplitView = input<boolean>(true);
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved
onReadyForDisplayChange = output<boolean>();

/*
* Subscriptions and listeners that need to be disposed of when this component is destroyed.
*/
listeners: Disposable[] = [];
resizeObserver?: ResizeObserver;

@Input()
set allowSplitView(value: boolean) {
this._editor.updateOptions({
renderSideBySide: value,
});
}

@Output()
onReadyForDisplayChange = new EventEmitter<boolean>();
/*
* Injected services and elements.
*/
private readonly elementRef = inject(ElementRef);
private readonly renderer = inject(Renderer2);
private readonly monacoEditorService = inject(MonacoEditorService);

constructor(
private themeService: ThemeService,
elementRef: ElementRef,
renderer: Renderer2,
) {
constructor() {
/*
* The constructor injects the editor along with its container into the empty template of this component.
* This makes the editor available immediately (not just after ngOnInit), preventing errors when the methods
* of this component are called.
*/
this.monacoDiffEditorContainerElement = renderer.createElement('div');
this._editor = monaco.editor.createDiffEditor(this.monacoDiffEditorContainerElement, {
glyphMargin: true,
minimap: { enabled: false },
readOnly: true,
renderSideBySide: true,
scrollBeyondLastLine: false,
stickyScroll: {
enabled: false,
},
renderOverviewRuler: false,
scrollbar: {
vertical: 'hidden',
handleMouseWheel: true,
alwaysConsumeMouseWheel: false,
},
hideUnchangedRegions: {
enabled: true,
},
fontSize: 12,
});
renderer.appendChild(elementRef.nativeElement, this.monacoDiffEditorContainerElement);
this.monacoDiffEditorContainerElement = this.renderer.createElement('div');
this._editor = this.monacoEditorService.createStandaloneDiffEditor(this.monacoDiffEditorContainerElement);
this.renderer.appendChild(this.elementRef.nativeElement, this.monacoDiffEditorContainerElement);
this.setupDiffListener();
this.setupContentHeightListeners();

effect(() => {
this._editor.updateOptions({
renderSideBySide: this.allowSplitView(),
});
});
}
pzdr7 marked this conversation as resolved.
Show resolved Hide resolved

ngOnInit(): void {
this.resizeObserver = new ResizeObserver(() => {
this.layout();
});
this.resizeObserver.observe(this.monacoDiffEditorContainerElement);
this.themeSubscription = this.themeService.getCurrentThemeObservable().subscribe((theme) => this.changeTheme(theme));
}

ngOnDestroy(): void {
this.themeSubscription?.unsubscribe();
this.resizeObserver?.disconnect();
this.listeners.forEach((listener) => {
listener.dispose();
Expand Down Expand Up @@ -137,15 +122,6 @@ export class MonacoDiffEditorComponent implements OnInit, OnDestroy {
this._editor.layout({ width, height });
}

/**
* Sets the theme of all Monaco editors according to the Artemis theme.
* As of now, it is not possible to have two editors with different themes.
* @param artemisTheme The active Artemis theme.
*/
changeTheme(artemisTheme: Theme): void {
monaco.editor.setTheme(artemisTheme === Theme.DARK ? 'vs-dark' : 'vs-light');
}

/**
* Updates the files displayed in this editor. When this happens, {@link onReadyForDisplayChange} will signal that the editor is not
* ready to display the diff (as it must be computed first). This will later be change by the appropriate listener.
Expand Down
Loading
Loading