import { FormEditor } from "./formEditor" ; import { DevToolsExtensionContext } from "../devToolsExtensionContext" ; export class JsonFormEditor extends FormEditor { fieldsOrder : string [ ] | undefined ; undefFields : string [ ] | undefined ; constructor ( devToolsContext , title ) { super ( devToolsContext , title ) ; this . fieldsOrder = undefined ; this . undefFields = undefined ; } protected getViewType ( ) { return 'azALDevTools.JsonFormEditor' ; } protected onDataChanged ( data ) { if ( ! data ) data = { } ; if ( this . fieldsOrder ) { let sorted = { } ; for ( let i = 0 ; i < this . fieldsOrder . length ; i ++ ) { let val = data [ this . fieldsOrder [ i ] ] ; if ( val ) sorted [ this . fieldsOrder [ i ] ] = val ; } if ( this . undefFields ) { for ( let i = 0 ; i < this . undefFields . length ; i ++ ) { let val = data [ this . undefFields [ i ] ] ; if ( val ) sorted [ this . undefFields [ i ] ] = val ; } } data = sorted ; } this . updateTextDocumentFromJson ( data ) ; } protected onBeforeDataSave ( data ) { } protected getDocumentData ( ) { let data = this . getTextDocumentAsJson ( ) ; this . undefFields = undefined ; if ( ( this . fieldsOrder ) && ( data ) ) { this . undefFields = [ ] ; for ( let key in data ) { if ( this . fieldsOrder . indexOf ( key ) < 0 ) this . undefFields . push ( key ) ; } } return data ; } }