import * as T from "./types" ; import { electron , readFile } from "./bridge" ; import { makeDefaultArtboards } from "./factories" ; function arrayToMap ( array ) { return new Map ( array . map ( ( item ) => { const { id , ... rest } = item ; return [ id , rest ] ; } ) ) ; } export function jsonToRefs ( fileName , isSaved , data ) { return { isSaved , fileName , uiState : data . uiState || { type : "typography" } , artboards : makeDefaultArtboards ( ) , components : arrayToMap ( data . components ) , fontSizes : arrayToMap ( data . fontSizes ) , fontFamilies : arrayToMap ( data . fontFamilies ) , breakpoints : arrayToMap ( data . breakpoints ) , colors : arrayToMap ( data . colors ) , } ; } export async function open ( ) { const path = electron . remote . dialog . showOpenDialog ( { } ) ; if ( ! path ) { return ; } try { const str = await readFile ( path [ 0 ] , "utf-8" ) ; const data = JSON . parse ( str ) ; return jsonToRefs ( path [ 0 ] , true , data ) ; } catch ( er ) { console . log ( er ) ; return ; } }