@@ -11,7 +11,7 @@ import { WorkspaceBottomPanelDockLayout } from "layouts/panel/workspace-bottom-p
1111import { CodeEditor } from "components/code-editor" ;
1212import { ClearRemoteDesignSessionCache } from "components/clear-remote-design-session-cache" ;
1313import { WidgetTree } from "components/visualization/json-visualization/json-tree" ;
14- import { EditorAppbarFragments , EditorSidebar } from "components/editor" ;
14+ import { EditorSidebar } from "components/editor" ;
1515import { useEditorState , useWorkspaceState } from "core/states" ;
1616import { designToCode , Result } from "@designto/code" ;
1717import { RemoteImageRepositories } from "@design-sdk/figma-remote/lib/asset-repository/image-repository" ;
@@ -22,9 +22,15 @@ import {
2222} from "@design-sdk/core/assets-repository" ;
2323import { personal } from "@design-sdk/figma-auth-store" ;
2424import { useFigmaAccessToken } from "hooks" ;
25- import { ReflectSceneNode } from "@design-sdk/figma-node" ;
2625import { get_framework_config } from "query/to-code-options-from-query" ;
2726import { CodeOptionsControl } from "components/codeui-code-options-control" ;
27+ import { DesignInput } from "@designto/config/input" ;
28+ import { Canvas } from "scaffolds/canvas" ;
29+ import {
30+ find_node_by_id_under_entry ,
31+ find_node_by_id_under_inpage_nodes ,
32+ } from "utils/design-query" ;
33+ import { vanilla_presets } from "@grida/builder-config-preset" ;
2834
2935export function Editor ( ) {
3036 const router = useRouter ( ) ;
@@ -38,17 +44,26 @@ export function Editor() {
3844 const [ framework_config , set_framework_config ] = useState (
3945 wstate . preferences . framework_config
4046 ) ;
41- const preview_runner_framework =
42- wstate . preferences . preview_runner_framework_config ;
47+
4348 const enable_components =
4449 wstate . preferences . enable_preview_feature_components_support ;
45- const design = state . design ?. input ;
46- const focusid =
50+
51+ const thisPageNodes = state . selectedPage
52+ ? state . design . pages . find ( ( p ) => p . id == state . selectedPage ) . children
53+ : null ;
54+
55+ const targetId =
4756 state ?. selectedNodes ?. length === 1 ? state . selectedNodes [ 0 ] : null ;
48- const focused =
49- find_node_by_id_under_entry ( focusid , design ?. entry ) ?? design ?. entry ;
5057
51- // const focusdesign = design?.nodes.find((n) => n.id === focusid);
58+ const container_of_target =
59+ find_node_by_id_under_inpage_nodes ( targetId , thisPageNodes ) || null ;
60+
61+ const root = thisPageNodes
62+ ? container_of_target && DesignInput . fromDesign ( container_of_target )
63+ : state . design ?. input ;
64+
65+ const targetted =
66+ find_node_by_id_under_entry ( targetId , root ?. entry ) ?? root ?. entry ;
5267
5368 useEffect ( ( ) => {
5469 // ------------------------------------------------------------
@@ -75,77 +90,77 @@ export function Editor() {
7590 } , [ state . design ?. key , fat ] ) ;
7691
7792 useEffect ( ( ) => {
78- if ( focused && framework_config ) {
79- const input = {
80- id : focused . id ,
81- name : focused . name ,
82- entry : focused ,
83- repository : design . repository ,
93+ if ( targetted && framework_config ) {
94+ const _input = {
95+ id : targetted . id ,
96+ name : targetted . name ,
97+ entry : targetted ,
98+ repository : root . repository ,
8499 } ;
85100 const build_config = {
86101 ...config . default_build_configuration ,
87102 disable_components : ! enable_components ,
88103 } ;
89104
90105 const on_result = ( result : Result ) => {
91- setResult ( result ) ;
92- if ( framework_config . framework == preview_runner_framework . framework ) {
93- setPreview ( result ) ;
106+ if ( result . id == targetted . id ) {
107+ setResult ( result ) ;
94108 }
95109 } ;
96110
97111 // build code without assets fetch
98112 designToCode ( {
99- input : input ,
113+ input : _input ,
100114 framework : framework_config ,
101115 asset_config : { skip_asset_replacement : true } ,
102116 build_config : build_config ,
103117 } ) . then ( on_result ) ;
104118
105119 // build final code with asset fetch
106120 designToCode ( {
107- input : input ,
121+ input : root ,
108122 framework : framework_config ,
109123 asset_config : { asset_repository : MainImageRepository . instance } ,
110124 build_config : build_config ,
111125 } ) . then ( on_result ) ;
112126 }
113- } , [ focused ?. id , framework_config ?. framework ] ) ;
127+ } , [ targetted ?. id , framework_config ?. framework ] ) ;
114128
115129 useEffect ( ( ) => {
116- if ( design ) {
117- const { id, name } = design . entry ;
118- const input = {
130+ if ( root ) {
131+ const { id, name } = root . entry ;
132+ const _input = {
119133 id : id ,
120134 name : name ,
121- entry : design . entry ,
135+ entry : root . entry ,
122136 } ;
123137 const build_config = {
124138 ...config . default_build_configuration ,
125139 disable_components : true ,
126140 } ;
127- // ----- for preview -----
128- if ( framework_config ?. framework !== preview_runner_framework . framework ) {
129- designToCode ( {
130- input : input ,
131- build_config : build_config ,
132- framework : preview_runner_framework ,
133- asset_config : { skip_asset_replacement : true } ,
134- } ) . then ( ( result ) => {
135- setPreview ( result ) ;
136- } ) ;
137141
138- designToCode ( {
139- input : input ,
140- build_config : build_config ,
141- framework : preview_runner_framework ,
142- asset_config : { asset_repository : MainImageRepository . instance } ,
143- } ) . then ( ( result ) => {
142+ const on_preview_result = ( result : Result ) => {
143+ if ( result . id == targetId ) {
144144 setPreview ( result ) ;
145- } ) ;
146- }
145+ }
146+ } ;
147+
148+ // ----- for preview -----
149+ designToCode ( {
150+ input : _input ,
151+ build_config : build_config ,
152+ framework : vanilla_presets . vanilla_default ,
153+ asset_config : { skip_asset_replacement : true } ,
154+ } ) . then ( on_preview_result ) ;
155+
156+ designToCode ( {
157+ input : root ,
158+ build_config : build_config ,
159+ framework : vanilla_presets . vanilla_default ,
160+ asset_config : { asset_repository : MainImageRepository . instance } ,
161+ } ) . then ( on_preview_result ) ;
147162 }
148- } , [ design ?. id ] ) ;
163+ } , [ root ?. id ] ) ;
149164
150165 const { code, scaffold, name : componentName } = result ?? { } ;
151166
@@ -156,29 +171,15 @@ export function Editor() {
156171 >
157172 < WorkspaceContentPanelGridLayout >
158173 < WorkspaceContentPanel >
159- < >
160- < EditorAppbarFragments . Canvas />
161- { preview ? (
162- < PreviewAndRunPanel
163- // key={_key_for_preview}
164- config = { {
165- src : preview . scaffold . raw ,
166- platform : preview_runner_framework . framework ,
167- componentName : componentName ,
168- sceneSize : {
169- w : design . entry ?. width ,
170- h : design . entry ?. height ,
171- } ,
172- initialMode : "run" ,
173- fileid : state . design . key ,
174- sceneid : design . id ,
175- hideModeChangeControls : true ,
176- } }
177- />
178- ) : (
179- < EditorCanvasSkeleton />
180- ) }
181- </ >
174+ < Canvas
175+ preview = { preview }
176+ fileid = { state ?. design ?. key }
177+ sceneid = { root ?. id }
178+ originsize = { {
179+ width : root ?. entry ?. width ,
180+ height : root ?. entry ?. height ,
181+ } }
182+ />
182183 </ WorkspaceContentPanel >
183184 < WorkspaceContentPanel backgroundColor = { "rgba(30, 30, 30, 1)" } >
184185 < CodeEditorContainer >
@@ -228,13 +229,13 @@ export function Editor() {
228229 >
229230 < div style = { { flex : 1 } } >
230231 < ClearRemoteDesignSessionCache
231- key = { design . id }
232+ key = { root . id }
232233 file = { state . design . key }
233- node = { design . id }
234+ node = { root . id }
234235 />
235236 < br />
236- { ( design . entry . origin === "INSTANCE" ||
237- design . entry . origin === "COMPONENT" ) && (
237+ { ( root . entry . origin === "INSTANCE" ||
238+ root . entry . origin === "COMPONENT" ) && (
238239 < button
239240 onClick = { ( ) => {
240241 router . push ( {
@@ -249,7 +250,7 @@ export function Editor() {
249250 </ div >
250251
251252 < div style = { { flex : 2 } } >
252- < WidgetTree data = { design . entry } />
253+ < WidgetTree data = { root . entry } />
253254 </ div >
254255 < div style = { { flex : 2 } } >
255256 < WidgetTree data = { result . widget } />
@@ -263,45 +264,8 @@ export function Editor() {
263264 ) ;
264265}
265266
266- const EditorCanvasSkeleton = ( ) => {
267- return (
268- < PreviewAndRunPanel
269- // key={_key_for_preview}
270- config = { {
271- src : "" ,
272- platform : "vanilla" ,
273- componentName : "loading" ,
274- sceneSize : {
275- w : 375 ,
276- h : 812 ,
277- } ,
278- initialMode : "run" ,
279- fileid : "loading" ,
280- sceneid : "loading" ,
281- hideModeChangeControls : true ,
282- } }
283- />
284- ) ;
285- } ;
286-
287267const CodeEditorContainer = styled . div `
288268 display: flex;
289269 flex-direction: column;
290270 align-items: stretch;
291271` ;
292-
293- const find_node_by_id_under_entry = ( id : string , entry : ReflectSceneNode ) => {
294- if ( ! entry ) return null ;
295- if ( entry . id === id ) {
296- return entry ;
297- }
298- if ( entry . children ) {
299- for ( const child of entry . children ) {
300- const found = find_node_by_id_under_entry ( id , child ) ;
301- if ( found ) {
302- return found ;
303- }
304- }
305- }
306- return null ;
307- } ;
0 commit comments