1- import React , { useEffect , useState } from "react" ;
1+ import React , { useCallback } from "react" ;
22import styled from "@emotion/styled" ;
33import { Canvas } from "@code-editor/canvas" ;
44import { useEditorState , useWorkspace } from "core/states" ;
@@ -7,57 +7,62 @@ import useMeasure from "react-use-measure";
77import { useDispatch } from "core/dispatch" ;
88import { FrameTitleRenderer } from "./render/frame-title" ;
99import { IsolateModeCanvas } from "./isolate-mode" ;
10- import { useRouter } from "next/router" ;
11-
12- type ViewMode = "full" | "isolate" ;
13- const _editor_path_name = "/files/[key]/" ;
10+ import { Dialog } from "@material-ui/core" ;
11+ import { FullScreenPreview } from "scaffolds/preview-full-screen" ;
1412
1513/**
1614 * Statefull canvas segment that contains canvas as a child, with state-data connected.
1715 */
1816export function VisualContentArea ( ) {
1917 const [ state ] = useEditorState ( ) ;
20- const router = useRouter ( ) ;
21- const { mode : q_mode } = router . query ;
22-
23- // this hook is used for focusing the node on the first load with the initial selection is provided externally.
24- useEffect ( ( ) => {
25- // if the initial selection is available, and not empty &&
26- if ( state . selectedNodesInitial ?. length && q_mode == "isolate" ) {
27- // trigger isolation mode once.
28- setMode ( "isolate" ) ;
29-
30- // TODO: set explicit canvas initial transform.
31- // make the canvas fit to the initial target even when the isolation mode is complete by the user.
32- }
33- } , [ state . selectedNodesInitial ] ) ;
34-
3518 const [ canvasSizingRef , canvasBounds ] = useMeasure ( ) ;
3619
3720 const { highlightedLayer, highlightLayer } = useWorkspace ( ) ;
3821 const dispatch = useDispatch ( ) ;
3922
40- const { selectedPage, design, selectedNodes } = state ;
23+ const { selectedPage, design, selectedNodes, canvasMode } = state ;
4124
4225 const thisPageNodes = selectedPage
43- ? state . design . pages
44- . find ( ( p ) => p . id == selectedPage )
45- . children . filter ( Boolean )
26+ ? design . pages . find ( ( p ) => p . id == selectedPage ) . children . filter ( Boolean )
4627 : [ ] ;
4728
4829 const isEmptyPage = thisPageNodes ?. length === 0 ;
4930
50- const [ mode , _setMode ] = useState < ViewMode > ( "full" ) ;
31+ const startIsolatedViewMode = useCallback (
32+ ( ) =>
33+ dispatch ( {
34+ type : "canvas-mode-switch" ,
35+ mode : "isolated-view" ,
36+ } ) ,
37+ [ dispatch ]
38+ ) ;
39+
40+ const startFullscreenPreviewMode = useCallback (
41+ ( ) =>
42+ dispatch ( {
43+ type : "canvas-mode-switch" ,
44+ mode : "fullscreen-preview" ,
45+ } ) ,
46+ [ dispatch ]
47+ ) ;
5148
52- const setMode = ( m : ViewMode ) => {
53- _setMode ( m ) ;
49+ const endIsolatedViewMode = useCallback (
50+ ( ) =>
51+ dispatch ( {
52+ type : "canvas-mode-switch" ,
53+ mode : "free" ,
54+ } ) ,
55+ [ dispatch ]
56+ ) ;
5457
55- // update the router
56- router . push ( {
57- pathname : _editor_path_name ,
58- query : { ...router . query , mode : m } ,
59- } ) ;
60- } ;
58+ const exitFullscreenPreview = useCallback (
59+ ( ) =>
60+ dispatch ( {
61+ type : "canvas-mode-goback" ,
62+ fallback : "isolated-view" ,
63+ } ) ,
64+ [ dispatch ]
65+ ) ;
6166
6267 return (
6368 < CanvasContainer ref = { canvasSizingRef } id = "canvas" >
@@ -67,16 +72,19 @@ export function VisualContentArea() {
6772 < > </ >
6873 ) : (
6974 < >
70- { mode == "isolate" && (
75+ < FullScreenPreviewContainer
76+ show = { canvasMode == "fullscreen-preview" }
77+ onExit = { exitFullscreenPreview }
78+ />
79+ { canvasMode == "isolated-view" && (
7180 < IsolateModeCanvas
72- onClose = { ( ) => {
73- setMode ( "full" ) ;
74- } }
81+ onClose = { endIsolatedViewMode }
82+ onEnterFullscreen = { startFullscreenPreviewMode }
7583 />
7684 ) }
7785 < div
7886 style = { {
79- display : mode == "full" ? undefined : "none" ,
87+ display : canvasMode ! == "free" && "none" ,
8088 } }
8189 >
8290 < Canvas
@@ -112,9 +120,7 @@ export function VisualContentArea() {
112120 < FrameTitleRenderer
113121 key = { p . id }
114122 { ...p }
115- onRunClick = { ( ) => {
116- setMode ( "isolate" ) ;
117- } }
123+ onRunClick = { startIsolatedViewMode }
118124 />
119125 ) }
120126 />
@@ -125,6 +131,20 @@ export function VisualContentArea() {
125131 ) ;
126132}
127133
134+ function FullScreenPreviewContainer ( {
135+ onExit,
136+ show,
137+ } : {
138+ onExit : ( ) => void ;
139+ show : boolean ;
140+ } ) {
141+ return (
142+ < Dialog fullScreen onClose = { onExit } open = { show } >
143+ < FullScreenPreview onClose = { onExit } />
144+ </ Dialog >
145+ ) ;
146+ }
147+
128148const CanvasContainer = styled . div `
129149 display: flex;
130150 flex-direction: column;
0 commit comments