import * as T from "./types" ; import { valuesAsArray } from "./helpers/immutable-map" ; import { layerTreeToArray } from "./layerUtils" ; export function filterComponentsWhenLayer ( refs , layerPredicate ) { return valuesAsArray ( refs . components ) . filter ( ( component ) => layerTreeToArray ( component . layout ) . some ( layerPredicate ) ) ; } export function refsToJson ( current ) { return JSON . stringify ( { uiState : current . uiState , colors : mapToArray ( current . colors ) , fontSizes : mapToArray ( current . fontSizes ) , fontFamilies : mapToArray ( current . fontFamilies ) , breakpoints : mapToArray ( current . breakpoints ) , components : mapToArray ( current . components ) , } , null , 2 ) ; } function mapToArray ( map ) { return Array . from ( map . entries ( ) ) . map ( ( entry ) => ( { id : entry [ 0 ] , ... entry [ 1 ] , } ) ) ; } export function uiStateComponentOrThrow ( refs ) { if ( refs . uiState . type !== "component" ) { throw new Error ( `Expected uiState.type to be "component" but got ${ refs . uiState . type }` ) ; } return refs . uiState ; }