11import { CodeEditor , DiffEditor , Orientation , RevertControls , Setup } from '@acrodata/code-editor' ;
2- import { Component } from '@angular/core' ;
2+ import { Component , linkedSignal , signal } from '@angular/core' ;
33import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
44import { unifiedMergeView } from '@codemirror/merge' ;
55
@@ -10,36 +10,72 @@ import { unifiedMergeView } from '@codemirror/merge';
1010 styleUrl : './diff.scss' ,
1111} )
1212export class Diff {
13- doc = `one
13+ doc = signal ( `one
1414two
1515three
1616four
17- five` ;
17+ five` ) ;
1818
19- doc2 = this . doc . replace ( / t / g, 'T' ) + '\nSix' ;
19+ doc2 = signal ( this . doc ( ) . replace ( / t / g, 'T' ) + '\nSix' ) ;
2020
21- value = {
22- original : this . doc ,
23- modified : this . doc2 ,
24- } ;
21+ value = linkedSignal ( ( ) => ( {
22+ original : this . doc ( ) ,
23+ modified : this . doc2 ( ) ,
24+ } ) ) ;
2525
2626 control = new FormControl ( { value : this . value , disabled : true } ) ;
2727
2828 unifiedExts = [
2929 unifiedMergeView ( {
30- original : this . doc ,
30+ original : this . doc ( ) ,
3131 gutter : true ,
3232 } ) ,
3333 ] ;
3434
3535 setup : Setup = 'minimal' ;
36- orientation : Orientation = 'a-b' ;
37- revertControls : RevertControls = 'a-to-b' ;
38- highlightChanges = true ;
39- gutter = true ;
40- disabled = false ;
36+ orientation = signal < Orientation > ( 'a-b' ) ;
37+ revertControls = signal < RevertControls > ( 'a-to-b' ) ;
38+ highlightChanges = signal ( true ) ;
39+ gutter = signal ( true ) ;
40+ disabled = signal ( false ) ;
4141
4242 log ( e : any ) {
4343 console . log ( e ) ;
4444 }
45+
46+ setOriginalValue ( ) {
47+ this . doc . set ( '123' ) ;
48+ }
49+
50+ setModifiedValue ( ) {
51+ this . doc2 . set ( '13\n456' ) ;
52+ }
53+
54+ setOrientation ( ) {
55+ if ( this . orientation ( ) === 'a-b' ) {
56+ this . orientation . set ( 'b-a' ) ;
57+ } else {
58+ this . orientation . set ( 'a-b' ) ;
59+ }
60+ }
61+
62+ setRevertControls ( ) {
63+ if ( this . revertControls ( ) === 'a-to-b' ) {
64+ this . revertControls . set ( 'b-to-a' ) ;
65+ } else {
66+ this . revertControls . set ( 'a-to-b' ) ;
67+ }
68+ }
69+
70+ setHighlightChanges ( ) {
71+ this . highlightChanges . update ( v => ! v ) ;
72+ }
73+
74+ setGutter ( ) {
75+ this . gutter . update ( v => ! v ) ;
76+ }
77+
78+ setDisabled ( ) {
79+ this . disabled . update ( v => ! v ) ;
80+ }
4581}
0 commit comments