1
- // need to Fix something in ember-statechart-component
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
1
import { assert } from ' @ember/debug' ;
5
- import { fn , hash } from ' @ember/helper' ;
2
+ import { fn } from ' @ember/helper' ;
6
3
7
4
import { modifier } from ' ember-modifier' ;
8
5
@@ -11,17 +8,21 @@ import { EditorContainer, OutputContainer } from './containers';
11
8
import { Controls } from ' ./controls' ;
12
9
import { Orientation } from ' ./orientation' ;
13
10
import { ResizeHandle } from ' ./resize-handle' ;
14
- import State , { isHorizontalSplit , setupResizeObserver } from ' ./state' ;
11
+ import { isHorizontalSplit , LayoutState , setupResizeObserver } from ' ./state' ;
15
12
16
13
import type { TOC } from ' @ember/component/template-only' ;
17
- import type { Send , State as StateFor } from ' ember-statechart-component/glint ' ;
14
+ import type { ReactiveActorFrom } from ' ember-statechart-component' ;
18
15
19
- const setupState = modifier ((element : Element , [send ]: [Send <unknown >]) => {
16
+ type ReactiveActor = ReactiveActorFrom <typeof LayoutState >;
17
+
18
+ const setupState = modifier ((element : Element , [send ]: [(event : string ) => void ]) => {
20
19
assert (` Element is not resizable ` , element instanceof HTMLElement );
21
20
22
21
let observer = setupResizeObserver (() => send (' RESIZE' ));
23
22
24
- send (' CONTAINER_FOUND' , {
23
+ // @ts-expect-error need to fix the type of this for ember-statechart-component
24
+ send ({
25
+ type: ' CONTAINER_FOUND' ,
25
26
container: element ,
26
27
observer ,
27
28
maximize : () => send (' MAXIMIZE' ),
@@ -37,46 +38,58 @@ const effect = (fn: (...args: unknown[]) => void) => {
37
38
fn ();
38
39
};
39
40
40
- const isResizable = (state : StateFor < typeof State > ) => {
41
+ const isResizable = (state : ReactiveActor ) => {
41
42
return ! (state .matches (' hasContainer.minimized' ) || state .matches (' hasContainer.maximized' ));
42
43
};
43
44
44
45
/**
45
46
* true for horizontally split
46
47
* false for vertically split
47
48
*/
48
- const containerDirection = (state : StateFor < typeof State > ) => {
49
+ const containerDirection = (state : ReactiveActor ) => {
49
50
if (state .matches (' hasContainer.default.horizontallySplit' )) {
50
51
return true ;
51
52
}
52
53
53
- return isHorizontalSplit (state .context );
54
+ return isHorizontalSplit (state .snapshot );
54
55
};
55
56
57
+ function updateOrientation(isVertical : boolean ) {
58
+ return {
59
+ type: ' ORIENTATION' ,
60
+ isVertical ,
61
+ };
62
+ }
63
+
56
64
export const Layout: TOC <{
57
65
Blocks: {
58
66
editor: [];
59
67
output: [];
60
68
};
61
69
}> = <template >
62
- <State as | state send | >
70
+ <LayoutState as | state | >
63
71
{{#let ( containerDirection state ) as | horizontallySplit | }}
64
72
<Orientation as | isVertical | >
65
- {{effect ( fn send " ORIENTATION" ( hash isVertical =isVertical ) ) }}
73
+ {{! Normally we don't do effects in app code,
74
+ because we can derive all state.
75
+
76
+ But XState is an *evented* system, so we have to send events.
77
+ }}
78
+ {{effect ( fn state.send ( updateOrientation isVertical ) ) }}
66
79
67
80
<div
68
81
{{! row = left to right, col = top to bottom }}
69
82
class =" {{if horizontallySplit ' flex-col' ' flex-row' }} flex overflow-hidden"
70
83
>
71
84
72
- <EditorContainer @ splitHorizontally ={{horizontallySplit }} {{setupState send }} >
85
+ <EditorContainer @ splitHorizontally ={{horizontallySplit }} {{setupState state. send}} >
73
86
<Save />
74
87
<Controls
75
88
@ isMinimized ={{state.matches " hasContainer.minimized" }}
76
89
@ isMaximized ={{state.matches " hasContainer.maximized" }}
77
- @ needsControls ={{toBoolean state.context.container }}
90
+ @ needsControls ={{toBoolean state.snapshot. context.container }}
78
91
@ splitHorizontally ={{horizontallySplit }}
79
- @ send ={{send }}
92
+ @ send ={{state. send }}
80
93
/>
81
94
82
95
{{yield to =" editor" }}
@@ -100,7 +113,7 @@ export const Layout: TOC<{
100
113
</div >
101
114
</Orientation >
102
115
{{/let }}
103
- </State >
116
+ </LayoutState >
104
117
</template >;
105
118
106
119
export default Layout ;
0 commit comments