import { SerializedDiagram , convertToSerializedDiagram } from '../src/ontodia/index' ; export function onPageLoad ( callback ) { document . addEventListener ( 'DOMContentLoaded' , ( ) => { const container = document . createElement ( 'div' ) ; container . id = 'root' ; document . body . appendChild ( container ) ; callback ( container ) ; } ) ; } export function tryLoadLayoutFromLocalStorage ( ) { if ( window . location . hash . length > 1 ) { try { const key = window . location . hash . substring ( 1 ) ; const unparsedLayout = localStorage . getItem ( key ) ; const entry = unparsedLayout && JSON . parse ( unparsedLayout ) ; if ( entry [ '@context' ] ) { return entry ; } else { return convertToSerializedDiagram ( { layoutData : entry , linkTypeOptions : [ ] } ) ; } } catch ( e ) { } } return undefined ; } export function saveLayoutToLocalStorage ( diagram ) { const randomKey = Math . floor ( ( 1 + Math . random ( ) ) * 0x10000000000 ) . toString ( 16 ) . substring ( 1 ) ; localStorage . setItem ( randomKey , JSON . stringify ( diagram ) ) ; return randomKey ; }