import { InputAction } from "tiny-undo" ; /**
 * Define storage data type
 */ interface StorageData { editorContentCache : string ; shouldSplitMemoWord : boolean ; shouldHideImageUrl : boolean ; shouldUseMarkdownParser : boolean ; useTinyUndoHistoryCache : boolean ; tinyUndoActionsCache : InputAction [ ] ; tinyUndoIndexCache : number ; } type StorageKey = keyof StorageData ; /**
 * storage helper
 */ export namespace storage { export function get ( keys ) { const data = { } ; for ( const key of keys ) { try { const stringifyValue = localStorage . getItem ( key ) ; if ( stringifyValue !== null ) { const val = JSON . parse ( stringifyValue ) ; data [ key ] = val ; } } catch ( error ) { console . error ( "Get storage failed in " , key , error ) ; } } return data ; } export function set ( data ) { for ( const key in data ) { try { const stringifyValue = JSON . stringify ( data [ key as StorageKey ] ) ; localStorage . setItem ( key , stringifyValue ) ; } catch ( error ) { console . error ( "Save storage failed in " , key , error ) ; } } } export function remove ( keys ) { for ( const key of keys ) { try { localStorage . removeItem ( key ) ; } catch ( error ) { console . error ( "Remove storage failed in " , key , error ) ; } } } export function emitStorageChangedEvent ( ) { const iframeEl = document . createElement ( "iframe" ) ; iframeEl . style . display = "none" ; document . body . appendChild ( iframeEl ) ; iframeEl . contentWindow ?. localStorage . setItem ( "t" , Date . now ( ) . toString ( ) ) ; iframeEl . remove ( ) ; } }