import type { ModeSpec } from 'codemirror' ; import { useObjectRef } from '@cloudbeaver/core-blocks' ; export function useAutoFormat ( mode ) { let modeName = 'sql' ; if ( typeof mode === 'string' ) { modeName = mode ; } else if ( typeof mode === 'object' ) { modeName = mode . name ; } return useObjectRef ( ( ) => ( { format ( value ) { try { switch ( this . mode ) { case 'application/json' : return JSON . stringify ( JSON . parse ( value ) , null , 2 ) ; case 'text/xml' : case 'text/html' : return value ; default : return value ; } } catch { return value ; } } , } ) , { mode : modeName } ) ; }