-
-
Notifications
You must be signed in to change notification settings - Fork 209
feat(angular): add angular wrapper #763
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
90f9538
feat(angular): add angular wrapper
ls-infra 133153a
fix(angular): fix ci
ls-infra 0e067b8
fix(angular): fix pr comments
ls-infra 4f9182c
feat(server): add mock code saver API
ls-infra fb274fe
feat(angular): update to Signal inputs to pass wrapperConfig into wra…
ls-infra d689600
feat(angular): add HttpClient to the host app to demo the saving of t…
ls-infra 9e131e8
fix(build): update package json back with cors
ls-infra 0e7faad
fix(build): add types/cors
ls-infra ad36a15
fix(ci): fix lint errors
ls-infra 3fec488
fix(angular): rm unneeded check
ls-infra 8769bec
fix(angular): update packages
ls-infra 2cae1e0
fix(angular): fix cors demo
ls-infra 1a6b500
feat(angular): add didModelContentChange to emitCodeChange
ls-infra 3dc9f8e
fix(angular): fix ci lint
ls-infra 7e4b18e
fix(angular): fix handleOnTextChanged lint issue
ls-infra 8349478
fix(angular): fix null check
ls-infra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,11 @@ | ||
| <h2>Monaco Language Client Angular Client Example</h2> | ||
| <div> | ||
| <div id="monaco-editor-root" class="monaco-editor"></div> | ||
| <h2>Angular Monaco Editor demo with saving code to a mock HTTP server </h2> | ||
| <div class="editor-container"> | ||
| <monaco-angular-wrapper | ||
| [wrapperConfig]="wrapperConfig()" | ||
| [monacoEditorId]="editorId" | ||
| [editorInlineStyle]="editorInlineStyle()" | ||
| (onTextChanged)="onTextChanged($event)" | ||
| ></monaco-angular-wrapper> | ||
|
|
||
| <button class="save-button" (click)="save()">Save</button> | ||
| </div> |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
verify/angular/src/monaco-angular-wrapper/monaco-angular-wrapper.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div> | ||
| <div [id]="monacoEditorId()" class='monaco-editor' [style]="editorInlineStyle()"></div> | ||
| </div> |
1 change: 1 addition & 0 deletions
1
verify/angular/src/monaco-angular-wrapper/monaco-angular-wrapper.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
95 changes: 95 additions & 0 deletions
95
verify/angular/src/monaco-angular-wrapper/monaco-angular-wrapper.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2024 TypeFox and others. | ||
| * Licensed under the MIT License. See LICENSE in the package root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| import { | ||
| Component, | ||
| effect, | ||
| EventEmitter, | ||
| input, | ||
| OnDestroy, | ||
| Output, | ||
| } from '@angular/core'; | ||
|
|
||
| import * as monaco from 'monaco-editor'; | ||
| import { | ||
| MonacoEditorLanguageClientWrapper, | ||
| TextChanges, | ||
| TextModels, | ||
| WrapperConfig , didModelContentChange | ||
| } from 'monaco-editor-wrapper'; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| selector: 'monaco-angular-wrapper', | ||
| templateUrl: './monaco-angular-wrapper.component.html', | ||
| styleUrls: ['./monaco-angular-wrapper.component.scss'], | ||
| }) | ||
| export class MonacoAngularWrapperComponent implements OnDestroy { | ||
| @Output() onTextChanged = new EventEmitter<string>(); | ||
| wrapperConfig = input<WrapperConfig>(); | ||
| monacoEditorId = input<string>(); | ||
| editorInlineStyle = input<string>(); | ||
| private wrapper: MonacoEditorLanguageClientWrapper = | ||
| new MonacoEditorLanguageClientWrapper(); | ||
| private _subscription: monaco.IDisposable | null = null; | ||
| private isRestarting?: Promise<void>; | ||
|
|
||
| constructor() { | ||
| effect(async () => { | ||
| try { | ||
| if (this.wrapperConfig() !== undefined) { | ||
| await this.wrapper.initAndStart( | ||
| this.wrapperConfig() as WrapperConfig | ||
| ); | ||
| this.handleOnTextChanged(); | ||
| } | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| protected async destroyMonaco(): Promise<void> { | ||
| if (this.isRestarting) { | ||
| await this.isRestarting; | ||
| } | ||
| try { | ||
| await this.wrapper.dispose(); | ||
| } catch { | ||
| // The language client may throw an error during disposal. | ||
| // This should not prevent us from continue working. | ||
| console.error('Error during disposal of the language client.'); | ||
| } | ||
| if (this._subscription) { | ||
| this._subscription.dispose(); | ||
| } | ||
| } | ||
|
|
||
| async ngOnDestroy() { | ||
| this.destroyMonaco(); | ||
| } | ||
|
|
||
| handleOnTextChanged() { | ||
| const wrapperConfig = this.wrapperConfig(); | ||
| const textModels = this.wrapper.getTextModels(); | ||
| if (textModels?.text !== undefined && wrapperConfig !== undefined) { | ||
| const newSubscriptions: monaco.IDisposable[] = []; | ||
| this.emitCodeChange(textModels, wrapperConfig); | ||
| newSubscriptions.push( | ||
| textModels.text.onDidChangeContent(() => { | ||
| this.emitCodeChange(textModels, wrapperConfig); | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| emitCodeChange(textModels: TextModels , wrapperConfig: WrapperConfig ) { | ||
| const onTextChanged = (textChanges: TextChanges) => { | ||
| this.onTextChanged.emit(textChanges.text); | ||
| }; | ||
| didModelContentChange(textModels, wrapperConfig.editorAppConfig.codeResources, onTextChanged); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2024 TypeFox and others. | ||
| * Licensed under the MIT License. See LICENSE in the package root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
|
|
||
| import { inject, Injectable } from '@angular/core'; | ||
| import { HttpClient } from '@angular/common/http'; | ||
| @Injectable({ providedIn: 'root' }) | ||
| export class SaveCodeService { | ||
| private http = inject(HttpClient); | ||
| saveCode(codeText: string) { | ||
| return this.http.post('http://localhost:3003/save-code', { code: codeText }); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.