1- // need to Fix something in ember-statechart-component
2- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3- // @ts-nocheck
41import { assert } from ' @ember/debug' ;
5- import { fn , hash } from ' @ember/helper' ;
2+ import { fn } from ' @ember/helper' ;
63
74import { modifier } from ' ember-modifier' ;
85
@@ -11,17 +8,21 @@ import { EditorContainer, OutputContainer } from './containers';
118import { Controls } from ' ./controls' ;
129import { Orientation } from ' ./orientation' ;
1310import { ResizeHandle } from ' ./resize-handle' ;
14- import State , { isHorizontalSplit , setupResizeObserver } from ' ./state' ;
11+ import { isHorizontalSplit , LayoutState , setupResizeObserver } from ' ./state' ;
1512
1613import 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' ;
1815
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 ]) => {
2019 assert (` Element is not resizable ` , element instanceof HTMLElement );
2120
2221 let observer = setupResizeObserver (() => send (' RESIZE' ));
2322
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' ,
2526 container: element ,
2627 observer ,
2728 maximize : () => send (' MAXIMIZE' ),
@@ -37,46 +38,58 @@ const effect = (fn: (...args: unknown[]) => void) => {
3738 fn ();
3839};
3940
40- const isResizable = (state : StateFor < typeof State > ) => {
41+ const isResizable = (state : ReactiveActor ) => {
4142 return ! (state .matches (' hasContainer.minimized' ) || state .matches (' hasContainer.maximized' ));
4243};
4344
4445/**
4546 * true for horizontally split
4647 * false for vertically split
4748 */
48- const containerDirection = (state : StateFor < typeof State > ) => {
49+ const containerDirection = (state : ReactiveActor ) => {
4950 if (state .matches (' hasContainer.default.horizontallySplit' )) {
5051 return true ;
5152 }
5253
53- return isHorizontalSplit (state .context );
54+ return isHorizontalSplit (state .snapshot );
5455};
5556
57+ function updateOrientation(isVertical : boolean ) {
58+ return {
59+ type: ' ORIENTATION' ,
60+ isVertical ,
61+ };
62+ }
63+
5664export const Layout: TOC <{
5765 Blocks: {
5866 editor: [];
5967 output: [];
6068 };
6169}> = <template >
62- <State as | state send | >
70+ <LayoutState as | state | >
6371 {{#let ( containerDirection state ) as | horizontallySplit | }}
6472 <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 ) ) }}
6679
6780 <div
6881 {{! row = left to right, col = top to bottom }}
6982 class =" {{if horizontallySplit ' flex-col' ' flex-row' }} flex overflow-hidden"
7083 >
7184
72- <EditorContainer @ splitHorizontally ={{horizontallySplit }} {{setupState send }} >
85+ <EditorContainer @ splitHorizontally ={{horizontallySplit }} {{setupState state. send}} >
7386 <Save />
7487 <Controls
7588 @ isMinimized ={{state.matches " hasContainer.minimized" }}
7689 @ isMaximized ={{state.matches " hasContainer.maximized" }}
77- @ needsControls ={{toBoolean state.context.container }}
90+ @ needsControls ={{toBoolean state.snapshot. context.container }}
7891 @ splitHorizontally ={{horizontallySplit }}
79- @ send ={{send }}
92+ @ send ={{state. send }}
8093 />
8194
8295 {{yield to =" editor" }}
@@ -100,7 +113,7 @@ export const Layout: TOC<{
100113 </div >
101114 </Orientation >
102115 {{/let }}
103- </State >
116+ </LayoutState >
104117</template >;
105118
106119export default Layout ;
0 commit comments