@@ -17,7 +17,7 @@ import {
1717import { WorkspaceAction } from "core/actions" ;
1818import { createInitialWorkspaceState } from "core/states" ;
1919import { workspaceReducer } from "core/reducers" ;
20- import { useDesign , useDesignFile } from "hooks" ;
20+ import { P_DESIGN , useDesign , useDesignFile } from "hooks" ;
2121import {
2222 get_enable_components_config_from_query ,
2323 get_framework_config_from_query ,
@@ -27,6 +27,7 @@ import { PendingState } from "core/utility-types";
2727import { DesignInput } from "@designto/config/input" ;
2828import { convert } from "@design-sdk/figma-node-conversion" ;
2929import { mapper } from "@design-sdk/figma-remote" ;
30+ import { analyze , parseFileAndNodeId } from "@design-sdk/figma-url" ;
3031
3132const pending_workspace_state = createPendingWorkspaceState ( ) ;
3233//
@@ -104,39 +105,62 @@ export default function Page() {
104105 } , [ design , router ] ) ;
105106
106107 // background whole file fetching
107- const file = useDesignFile ( { file : design ?. file } ) ;
108+ const designparam : string = router . query [ P_DESIGN ] as string ;
109+ const targetnodeconfig = parseFileAndNodeId ( designparam ) ;
110+ const file = useDesignFile ( { file : targetnodeconfig ?. file } ) ;
108111 const prevstate =
109112 initialState . type == "success" && initialState . value . history . present ;
110113 const selectedPage = useMemo ( ( ) => {
111- if ( prevstate . selectedNodes && file ?. document ?. children ) {
114+ if ( prevstate . selectedPage ) {
115+ return prevstate . selectedPage ;
116+ }
117+
118+ if ( prevstate ?. selectedNodes && file ?. document ?. children ) {
112119 return prevstate . selectedNodes . length > 0
113120 ? file . document . children . find ( ( page ) => {
114121 return isChildrenOf ( prevstate . selectedNodes [ 0 ] , page ) ;
115122 } ) ?. id ?? null
116123 : // find page of current selection.
117124 null ;
118125 }
119- return null ;
126+
127+ return file ?. document ?. children ?. [ 0 ] . id ?? null ; // otherwise, return first page.
120128 } , [ file ?. document ?. children ] ) ;
121129
122130 useEffect ( ( ) => {
123- if ( file && prevstate ) {
124- const val : EditorSnapshot = {
125- ...prevstate ,
126- design : {
127- ...prevstate . design ,
128- pages : file . document . children . map ( ( page ) => ( {
129- id : page . id ,
130- name : page . name ,
131- children : page [ "children" ] ?. map ( ( child ) => {
132- const _mapped = mapper . mapFigmaRemoteToFigma ( child ) ;
133- return convert . intoReflectNode ( _mapped ) ;
134- } ) ,
135- type : "design" ,
136- } ) ) ,
137- } ,
138- selectedPage : selectedPage ,
139- } ;
131+ if ( file ) {
132+ let val : EditorSnapshot ;
133+
134+ const pages = file . document . children . map ( ( page ) => ( {
135+ id : page . id ,
136+ name : page . name ,
137+ children : page [ "children" ] ?. map ( ( child ) => {
138+ const _mapped = mapper . mapFigmaRemoteToFigma ( child ) ;
139+ return convert . intoReflectNode ( _mapped ) ;
140+ } ) ,
141+ type : "design" ,
142+ } ) ) ;
143+ if ( prevstate ) {
144+ val = {
145+ ...prevstate ,
146+ design : {
147+ ...prevstate . design ,
148+ pages : pages ,
149+ } ,
150+ selectedPage : selectedPage ,
151+ } ;
152+ } else {
153+ val = {
154+ selectedNodes : [ ] ,
155+ selectedLayersOnPreview : [ ] ,
156+ design : {
157+ input : null ,
158+ key : file . document . id , //?
159+ pages : pages ,
160+ } ,
161+ selectedPage : selectedPage ,
162+ } ;
163+ }
140164
141165 initialDispatcher ( {
142166 type : "set" ,
0 commit comments