@@ -3,6 +3,7 @@ import * as ace from "ace-builds";
3
3
import { Ace } from "ace-builds" ;
4
4
import { MatFormFieldControl } from "@angular/material/form-field" ;
5
5
import { Subject } from "rxjs" ;
6
+ import { BooleanInput , coerceBooleanProperty } from "@angular/cdk/coercion" ;
6
7
import Editor = Ace . Editor ;
7
8
8
9
@Component ( {
@@ -26,7 +27,6 @@ export class AceEditorComponent implements MatFormFieldControl<string>, OnInit {
26
27
focused : boolean = false ;
27
28
empty : boolean = false ;
28
29
shouldLabelFloat : boolean = true ;
29
- disabled : boolean = false ;
30
30
errorState : boolean = false ;
31
31
controlType ?: string | undefined = "app-ace-editor" ;
32
32
autofilled ?: boolean | undefined ;
@@ -44,22 +44,45 @@ export class AceEditorComponent implements MatFormFieldControl<string>, OnInit {
44
44
private _required = false ;
45
45
46
46
@Input ( )
47
- get required ( ) {
47
+ get required ( ) : boolean {
48
48
return this . _required ;
49
49
}
50
50
51
- set required ( req : boolean ) {
52
- this . _required = req ;
51
+ set required ( req : BooleanInput ) {
52
+ this . _required = coerceBooleanProperty ( req ) ;
53
53
this . stateChanges . next ( ) ;
54
54
}
55
55
56
+ private _disabled = false ;
57
+
58
+ @Input ( )
59
+ get disabled ( ) : boolean {
60
+ return this . _disabled ;
61
+ }
62
+
63
+ set disabled ( value : BooleanInput ) {
64
+ this . _disabled = coerceBooleanProperty ( value ) ;
65
+ this . stateChanges . next ( ) ;
66
+ }
56
67
57
68
ngOnInit ( ) {
58
69
if ( this . ruleScriptEdit ) {
59
- this . editor = ace . edit ( this . ruleScriptEdit . nativeElement ) ;
60
- this . editor . session . setMode ( "ace/mode/javascript" ) ;
70
+ this . editor = ace . edit ( this . ruleScriptEdit . nativeElement , {
71
+ value : this . value ,
72
+ mode : "ace/mode/javascript" ,
73
+ minLines : 2 ,
74
+ maxLines : 15
75
+ } ) ;
76
+
77
+ if ( this . disabled ) {
78
+ this . editor . setReadOnly ( true ) ;
79
+ this . editor . setHighlightActiveLine ( false ) ;
80
+ this . editor . setHighlightGutterLine ( false ) ;
81
+ // hide the cursor
82
+ // @ts -ignore
83
+ this . editor . renderer . $cursorLayer . element . style . display = "none"
84
+ }
61
85
62
- this . editor . setValue ( this . value ) ;
63
86
this . editor . on ( "input" , ( ) => {
64
87
this . valueChange . emit ( this . editor ?. getValue ( ) ) ;
65
88
this . stateChanges . next ( ) ;
0 commit comments