Skip to content

Commit

Permalink
Improve type of defaultOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas committed Feb 10, 2025
1 parent 17b5c21 commit 1be5c5d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const monacoConfig: NgxMonacoEditorConfig = {
baseUrl: 'app-name/assets', // configure base path for monaco editor. Starting with version 8.0.0 it defaults to './assets'. Previous releases default to '/assets'
defaultOptions: { scrollBeyondLastLine: false }, // pass default options to be used
onMonacoLoad: () => { console.log((<any>window).monaco); } // here monaco object will be available as window.monaco use this function to extend monaco editor functionalities.
requireConfig: { preferScriptTags: true } // allows to oweride configuration passed to monacos loader
requireConfig: { preferScriptTags: true } // allows to override configuration passed to monacos loader
monacoRequire: (<any>window).monacoRequire // pass here monacos require function if you loaded monacos loader (loader.js) yourself
};

Expand Down
4 changes: 2 additions & 2 deletions projects/editor/src/lib/base-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
inject
} from '@angular/core';
import { Subscription } from 'rxjs';
import { NGX_MONACO_EDITOR_CONFIG, NgxMonacoEditorConfig } from './config';
import { MonacoOpts, NGX_MONACO_EDITOR_CONFIG, NgxMonacoEditorConfig } from './config';

let loadedMonaco = false;
let loadPromise: Promise<void>;
Expand Down Expand Up @@ -38,7 +38,7 @@ export abstract class BaseEditor implements AfterViewInit, OnDestroy {
@ViewChild('editorContainer', { static: true }) _editorContainer: ElementRef;
@Output() onInit = new EventEmitter<any>();
protected _editor: any;
protected _options: any;
protected _options: MonacoOpts;
protected _windowResizeSubscription: Subscription;
private _insideNg: boolean = false;

Expand Down
7 changes: 6 additions & 1 deletion projects/editor/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { InjectionToken } from '@angular/core';
import type MonacoNamespace from 'monaco-editor';

export const NGX_MONACO_EDITOR_CONFIG = new InjectionToken('NGX_MONACO_EDITOR_CONFIG');

export type MonacoOpts = MonacoNamespace.editor.IEditorOptions &
MonacoNamespace.editor.IGlobalEditorOptions &
MonacoNamespace.editor.ITextModelUpdateOptions;

export interface NgxMonacoEditorConfig {
baseUrl?: string;
requireConfig?: { [key: string]: any; };
defaultOptions?: { [key: string]: any; };
defaultOptions?: MonacoOpts;
monacoRequire?: Function;
onMonacoLoad?: Function;
}
3 changes: 2 additions & 1 deletion projects/editor/src/lib/diff-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fromEvent } from 'rxjs';

import { BaseEditor } from './base-editor';
import { DiffEditorModel } from './types';
import { MonacoOpts } from './config';

declare var monaco: any;

Expand Down Expand Up @@ -30,7 +31,7 @@ export class DiffEditorComponent extends BaseEditor {
_modifiedModel: DiffEditorModel;

@Input('options')
set options(options: any) {
set options(options: MonacoOpts) {
this._options = Object.assign({}, this.config.defaultOptions, options);
if (this._editor) {
this._editor.dispose();
Expand Down
3 changes: 2 additions & 1 deletion projects/editor/src/lib/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fromEvent } from 'rxjs';

import { BaseEditor } from './base-editor';
import { NgxEditorModel } from './types';
import { MonacoOpts } from './config';

declare var monaco: any;

Expand Down Expand Up @@ -37,7 +38,7 @@ export class EditorComponent extends BaseEditor implements ControlValueAccessor
onTouched = () => {};

@Input('options')
set options(options: any) {
set options(options: MonacoOpts) {
this._options = Object.assign({}, this.config.defaultOptions, options);
if (this._editor) {
this._editor.dispose();
Expand Down

0 comments on commit 1be5c5d

Please sign in to comment.