1
1
import { BaseElement , html , element , property } from './base-element.js' ;
2
2
import { flexStyles } from './flex-styles.js' ;
3
+ import { UndoableOp , Op } from './ops.js' ;
4
+ import { UndoRedoElement } from './components/undo-redo.js' ;
5
+ import { DesignSection } from './designer/design-section' ;
3
6
import './components/dac-tab-bar' ;
4
7
import './components/dac-tab' ;
5
8
import './components/dac-icon' ;
6
9
import './designer/design-section' ;
10
+ import './components/undo-redo.js' ;
7
11
8
12
@element ( 'main-app' )
9
13
export class MainApp extends BaseElement {
@@ -54,11 +58,11 @@ export class MainApp extends BaseElement {
54
58
< div id ="toolbar " class ="horizontal layout center ">
55
59
< div class ="flex "> Draw A Component</ div >
56
60
< div id ="appControls ">
57
- < button id ="undoBtn " disabled title ="Undo ">
61
+ < button id ="undoBtn " disabled title ="Undo " @click =" ${ ( ) => this . ur . undo ( ) } " >
58
62
< dac-icon icon ="undo "> </ dac-icon >
59
63
< div > Undo</ div >
60
64
</ button >
61
- < button id ="redoBtn " disabled title ="Undo ">
65
+ < button id ="redoBtn " disabled title ="Redo " @click =" ${ ( ) => this . ur . redo ( ) } ">
62
66
< dac-icon icon ="redo "> </ dac-icon >
63
67
< div > Redo</ div >
64
68
</ button >
@@ -75,15 +79,44 @@ export class MainApp extends BaseElement {
75
79
</ dac-tab-bar >
76
80
</ div >
77
81
< main class ="flex horizontal layout ">
78
- < design-section class ="flex " style ="${ this . selectedTab === 'design' ? '' : 'display: none;' } "> </ design-section >
82
+ < design-section class ="flex " style ="${ this . selectedTab === 'design' ? '' : 'display: none;' } " @op =" ${ this . onOp } " > </ design-section >
79
83
< div class ="flex " style ="${ this . selectedTab === 'preview' ? '' : 'display: none;' } ">
80
84
< p > Preview goes here</ p >
81
85
</ div >
82
86
</ div >
87
+ < undo-redo @do-op ="${ this . doOp } " @undo-state-change ="${ this . updateUndoState } "> </ undo-redo >
83
88
` ;
84
89
}
85
90
91
+ private get ur ( ) : UndoRedoElement {
92
+ return this . $$ ( 'undo-redo' ) as UndoRedoElement ;
93
+ }
94
+
95
+ private get designSection ( ) : DesignSection {
96
+ return this . $$ ( 'design-section' ) as DesignSection ;
97
+ }
98
+
86
99
private tabClick ( e : Event ) {
87
100
this . selectedTab = ( e . currentTarget as HTMLElement ) . getAttribute ( 'name' ) || 'design' ;
88
101
}
102
+
103
+ private onOp ( e : CustomEvent ) {
104
+ const uop = e . detail as UndoableOp ;
105
+ if ( uop ) {
106
+ this . ur . push ( uop ) ;
107
+ }
108
+ }
109
+
110
+ private doOp ( e : CustomEvent ) {
111
+ const op = e . detail as Op ;
112
+ if ( op ) {
113
+ this . designSection . doOp ( op ) ;
114
+ }
115
+ }
116
+
117
+ private updateUndoState ( e : CustomEvent ) {
118
+ const detail = e . detail ;
119
+ ( this . $ ( 'undoBtn' ) as HTMLButtonElement ) . disabled = ! detail . canUndo ;
120
+ ( this . $ ( 'redoBtn' ) as HTMLButtonElement ) . disabled = ! detail . canRedo ;
121
+ }
89
122
}
0 commit comments