From d08e6dba5d42913fccd4ca67b2e00eea3d5ecfd6 Mon Sep 17 00:00:00 2001 From: Vladyslav Prykhodko Date: Tue, 28 Sep 2021 08:41:39 +0300 Subject: [PATCH 1/2] UI: Added global scope variables in javascript functions --- ui-ngx/src/app/core/http/widget.service.ts | 5 ++++- ...custom-action-pretty-editor.component.html | 1 + .../custom-action-pretty-editor.component.ts | 7 ++++++- ...ction-pretty-resources-tabs.component.html | 1 + ...-action-pretty-resources-tabs.component.ts | 5 +++++ .../mobile-action-editor.component.html | 8 ++++++++ .../action/mobile-action-editor.component.ts | 19 +++++++++++++------ .../widget-action-dialog.component.html | 1 + .../action/widget-action-dialog.component.ts | 5 +++++ .../widget/data-key-config.component.html | 2 ++ .../widget/data-key-config.component.ts | 5 +++++ .../shared/components/js-func.component.ts | 7 +++++++ 12 files changed, 58 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/core/http/widget.service.ts b/ui-ngx/src/app/core/http/widget.service.ts index 41bf604177..d6de011133 100644 --- a/ui-ngx/src/app/core/http/widget.service.ts +++ b/ui-ngx/src/app/core/http/widget.service.ts @@ -68,6 +68,10 @@ export class WidgetService { ); } + public getWidgetScopeVariables(): string[] { + return ['tinycolor', 'cssjs', 'moment', '$', 'jQuery']; + } + public getAllWidgetsBundles(config?: RequestConfig): Observable> { return this.loadWidgetsBundleCache(config).pipe( map(() => this.allWidgetsBundles) @@ -311,5 +315,4 @@ export class WidgetService { this.loadWidgetsBundleCacheSubject = undefined; this.widgetTypeInfosCache.clear(); } - } diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html index c3f0b81850..21ae07c1f6 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html @@ -44,6 +44,7 @@ (ngModelChange)="onActionUpdated()" [fillHeight]="true" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter"> diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts index 60b28b32da..c98ee36259 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts @@ -36,6 +36,7 @@ import { AppState } from '@core/core.state'; import { combineLatest } from 'rxjs'; import { CustomActionDescriptor } from '@shared/models/widget.models'; import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; +import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-custom-action-pretty-editor', @@ -58,6 +59,8 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements fullscreen = false; + functionScopeVariables: string[]; + @ViewChildren('leftPanel') leftPanelElmRef: QueryList>; @@ -68,8 +71,10 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements private propagateChange = (_: any) => {}; - constructor(protected store: Store) { + constructor(protected store: Store, + private widgetService: WidgetService) { super(store); + this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } ngOnInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html index 6aa835cf84..3bbed25940 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html @@ -94,6 +94,7 @@ [(ngModel)]="action.customFunction" (ngModelChange)="notifyActionUpdated()" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter"> diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts index 1022668fd1..5c08fb04fe 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts @@ -41,6 +41,7 @@ import { forkJoin, from } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { getAce } from '@shared/models/ace/ace.models'; import { beautifyCss, beautifyHtml } from '@shared/models/beautify.models'; +import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-custom-action-pretty-resources-tabs', @@ -75,12 +76,16 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl cssEditor: Ace.Editor; setValuesPending = false; + functionScopeVariables: string[]; + customPrettyActionEditorCompleter = CustomPrettyActionEditorCompleter; constructor(protected store: Store, private translate: TranslateService, + private widgetService: WidgetService, private raf: RafService) { super(store); + this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } ngOnInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html index cdb4615068..401dfb8bd7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.html @@ -35,6 +35,7 @@ formControlName="getLocationFunction" functionName="getLocation" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -43,6 +44,7 @@ formControlName="getPhoneNumberFunction" functionName="getPhoneNumber" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -54,6 +56,7 @@ formControlName="processImageFunction" functionName="processImage" [functionArgs]="['imageUrl', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -62,6 +65,7 @@ formControlName="processQrCodeFunction" functionName="processQrCode" [functionArgs]="['code', 'format', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -70,6 +74,7 @@ formControlName="processLocationFunction" functionName="processLocation" [functionArgs]="['latitude', 'longitude', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -81,6 +86,7 @@ formControlName="processLaunchResultFunction" functionName="processLaunchResult" [functionArgs]="['launched', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > @@ -89,12 +95,14 @@ formControlName="handleEmptyResultFunction" functionName="handleEmptyResult" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel']" + [globalVariables]="functionScopeVariables" [editorCompleter]="customActionEditorCompleter" > diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts index 966268faa3..ac6b6d9577 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts @@ -14,26 +14,29 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core'; +import { Component, forwardRef, Input, OnInit, QueryList, ViewChildren } from '@angular/core'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import { Store } from '@ngrx/store'; import { AppState } from '@app/core/core.state'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; -import { deepClone } from '@core/utils'; import { WidgetMobileActionDescriptor, - WidgetMobileActionType, widgetMobileActionTypeTranslationMap + WidgetMobileActionType, + widgetMobileActionTypeTranslationMap } from '@shared/models/widget.models'; import { CustomActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; import { JsFuncComponent } from '@shared/components/js-func.component'; import { - getDefaultGetLocationFunction, getDefaultGetPhoneNumberFunction, + getDefaultGetLocationFunction, + getDefaultGetPhoneNumberFunction, getDefaultHandleEmptyResultFunction, getDefaultHandleErrorFunction, getDefaultProcessImageFunction, - getDefaultProcessLaunchResultFunction, getDefaultProcessLocationFunction, + getDefaultProcessLaunchResultFunction, + getDefaultProcessLocationFunction, getDefaultProcessQrCodeFunction } from '@home/components/widget/action/mobile-action-editor.models'; +import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-mobile-action-editor', @@ -58,6 +61,8 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit mobileActionFormGroup: FormGroup; mobileActionTypeFormGroup: FormGroup; + functionScopeVariables: string[]; + private requiredValue: boolean; get required(): boolean { return this.requiredValue; @@ -73,7 +78,9 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit private propagateChange = (v: any) => { }; constructor(private store: Store, - private fb: FormBuilder) { + private fb: FormBuilder, + private widgetService: WidgetService) { + this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } registerOnChange(fn: any): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html index 2c7b826200..ec475e1c3e 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.html @@ -171,6 +171,7 @@ diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts index 8930456636..7a70c50b0e 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts @@ -47,6 +47,7 @@ import { CustomActionEditorCompleter } from '@home/components/widget/action/cust import { isDefinedAndNotNull } from '@core/utils'; import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component'; import { widgetType } from '@shared/models/widget.models'; +import { WidgetService } from "@core/http/widget.service"; export interface WidgetActionDialogData { isAdd: boolean; @@ -88,11 +89,14 @@ export class WidgetActionDialogComponent extends DialogComponent, protected router: Router, private utils: UtilsService, private dashboardService: DashboardService, private dashboardUtils: DashboardUtilsService, + private widgetService: WidgetService, @Inject(MAT_DIALOG_DATA) public data: WidgetActionDialogData, @SkipSelf() private errorStateMatcher: ErrorStateMatcher, public dialogRef: MatDialogRef, @@ -109,6 +113,7 @@ export class WidgetActionDialogComponent extends DialogComponent @@ -78,6 +79,7 @@ diff --git a/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts index 5d1eabc4e4..23aced69c7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts @@ -40,6 +40,7 @@ import { map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators'; import { alarmFields } from '@shared/models/alarm.models'; import { JsFuncComponent } from '@shared/components/js-func.component'; import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models'; +import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-data-key-config', @@ -99,13 +100,17 @@ export class DataKeyConfigComponent extends PageComponent implements OnInit, Con keySearchText = ''; + functionScopeVariables: string[]; + constructor(protected store: Store, private utils: UtilsService, private entityService: EntityService, private dialog: MatDialog, private translate: TranslateService, + private widgetService: WidgetService, private fb: FormBuilder) { super(store); + this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } ngOnInit(): void { diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index a068068991..abc0bc0d21 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -83,6 +83,8 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, @Input() editorCompleter: TbEditorCompleter; + @Input() globalVariables: Array; + private noValidateValue: boolean; get noValidate(): boolean { return this.noValidateValue; @@ -190,6 +192,11 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, jsWorkerOptions.globals[arg] = false; }); } + if (this.globalVariables) { + this.globalVariables.forEach(arg => { + jsWorkerOptions.globals[arg] = false; + }); + } // @ts-ignore this.jsEditor.session.$worker.send('changeOptions', [jsWorkerOptions]); } From b29e208b95e7f1f33ceece344d2970cc237a7e99 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 28 Sep 2021 10:33:31 +0300 Subject: [PATCH 2/2] UI: Added global scope variables in javascript functions - refactoring --- ...custom-action-pretty-editor.component.html | 2 +- .../custom-action-pretty-editor.component.ts | 7 +--- ...ction-pretty-resources-tabs.component.html | 2 +- ...-action-pretty-resources-tabs.component.ts | 5 --- .../action/mobile-action-editor.component.ts | 2 +- .../action/widget-action-dialog.component.ts | 2 +- .../widget/data-key-config.component.ts | 2 +- .../shared/components/js-func.component.ts | 34 +++++++++++-------- 8 files changed, 25 insertions(+), 31 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html index 21ae07c1f6..642f739f8e 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html @@ -44,7 +44,7 @@ (ngModelChange)="onActionUpdated()" [fillHeight]="true" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']" - [globalVariables]="functionScopeVariables" + [disableUndefinedCheck]="true" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter"> diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts index c98ee36259..60b28b32da 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.ts @@ -36,7 +36,6 @@ import { AppState } from '@core/core.state'; import { combineLatest } from 'rxjs'; import { CustomActionDescriptor } from '@shared/models/widget.models'; import { CustomPrettyActionEditorCompleter } from '@home/components/widget/action/custom-action.models'; -import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-custom-action-pretty-editor', @@ -59,8 +58,6 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements fullscreen = false; - functionScopeVariables: string[]; - @ViewChildren('leftPanel') leftPanelElmRef: QueryList>; @@ -71,10 +68,8 @@ export class CustomActionPrettyEditorComponent extends PageComponent implements private propagateChange = (_: any) => {}; - constructor(protected store: Store, - private widgetService: WidgetService) { + constructor(protected store: Store) { super(store); - this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } ngOnInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html index 3bbed25940..d5893c47ab 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html @@ -94,7 +94,7 @@ [(ngModel)]="action.customFunction" (ngModelChange)="notifyActionUpdated()" [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']" - [globalVariables]="functionScopeVariables" + [disableUndefinedCheck]="true" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter"> diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts index 5c08fb04fe..1022668fd1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.ts @@ -41,7 +41,6 @@ import { forkJoin, from } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { getAce } from '@shared/models/ace/ace.models'; import { beautifyCss, beautifyHtml } from '@shared/models/beautify.models'; -import { WidgetService } from "@core/http/widget.service"; @Component({ selector: 'tb-custom-action-pretty-resources-tabs', @@ -76,16 +75,12 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl cssEditor: Ace.Editor; setValuesPending = false; - functionScopeVariables: string[]; - customPrettyActionEditorCompleter = CustomPrettyActionEditorCompleter; constructor(protected store: Store, private translate: TranslateService, - private widgetService: WidgetService, private raf: RafService) { super(store); - this.functionScopeVariables = this.widgetService.getWidgetScopeVariables(); } ngOnInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts index ac6b6d9577..75c42e7375 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/mobile-action-editor.component.ts @@ -36,7 +36,7 @@ import { getDefaultProcessLocationFunction, getDefaultProcessQrCodeFunction } from '@home/components/widget/action/mobile-action-editor.models'; -import { WidgetService } from "@core/http/widget.service"; +import { WidgetService } from '@core/http/widget.service'; @Component({ selector: 'tb-mobile-action-editor', diff --git a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts index 7a70c50b0e..d8633c9aff 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/action/widget-action-dialog.component.ts @@ -47,7 +47,7 @@ import { CustomActionEditorCompleter } from '@home/components/widget/action/cust import { isDefinedAndNotNull } from '@core/utils'; import { MobileActionEditorComponent } from '@home/components/widget/action/mobile-action-editor.component'; import { widgetType } from '@shared/models/widget.models'; -import { WidgetService } from "@core/http/widget.service"; +import { WidgetService } from '@core/http/widget.service'; export interface WidgetActionDialogData { isAdd: boolean; diff --git a/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts index 23aced69c7..db40968a1c 100644 --- a/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/data-key-config.component.ts @@ -40,7 +40,7 @@ import { map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators'; import { alarmFields } from '@shared/models/alarm.models'; import { JsFuncComponent } from '@shared/components/js-func.component'; import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models'; -import { WidgetService } from "@core/http/widget.service"; +import { WidgetService } from '@core/http/widget.service'; @Component({ selector: 'tb-data-key-config', diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index abc0bc0d21..9ba2428e44 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -85,6 +85,8 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, @Input() globalVariables: Array; + @Input() disableUndefinedCheck = false; + private noValidateValue: boolean; get noValidate(): boolean { return this.noValidateValue; @@ -167,32 +169,34 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, this.updateView(); } }); - // @ts-ignore - this.jsEditor.session.on('changeAnnotation', () => { - const annotations = this.jsEditor.session.getAnnotations(); - annotations.filter(annotation => annotation.text.includes('is not defined')).forEach(annotation => { - annotation.type = 'error'; + if (!this.disableUndefinedCheck) { + // @ts-ignore + this.jsEditor.session.on('changeAnnotation', () => { + const annotations = this.jsEditor.session.getAnnotations(); + annotations.filter(annotation => annotation.text.includes('is not defined')).forEach(annotation => { + annotation.type = 'error'; + }); + this.jsEditor.renderer.setAnnotations(annotations); + const hasErrors = annotations.filter(annotation => annotation.type === 'error').length > 0; + if (this.hasErrors !== hasErrors) { + this.hasErrors = hasErrors; + this.propagateChange(this.modelValue); + } }); - this.jsEditor.renderer.setAnnotations(annotations); - const hasErrors = annotations.filter(annotation => annotation.type === 'error').length > 0; - if (this.hasErrors !== hasErrors) { - this.hasErrors = hasErrors; - this.propagateChange(this.modelValue); - } - }); + } // @ts-ignore if (!!this.jsEditor.session.$worker) { const jsWorkerOptions = { - undef: true, + undef: !this.disableUndefinedCheck, unused: true, globals: {} }; - if (this.functionArgs) { + if (!this.disableUndefinedCheck && this.functionArgs) { this.functionArgs.forEach(arg => { jsWorkerOptions.globals[arg] = false; }); } - if (this.globalVariables) { + if (!this.disableUndefinedCheck && this.globalVariables) { this.globalVariables.forEach(arg => { jsWorkerOptions.globals[arg] = false; });