import { App } from '@vue/devtools-api' ; import { BackendContext , CustomInspector } from '@vue-devtools/app-backend-api' ; import { BridgeEvents , parse , stringify } from '@vue-devtools/shared-utils' ; export function getInspector ( inspectorId , app , ctx ) { return ctx . customInspectors . find ( i => i . id === inspectorId && i . appRecord . options . app === app ) ; } export async function getInspectorWithAppId ( inspectorId , appId , ctx ) { for ( const i of ctx . customInspectors ) { if ( i . id === inspectorId && i . appRecord . id === appId ) { return i ; } } return null ; } export async function sendInspectorTree ( inspector , ctx ) { const rootNodes = await inspector . appRecord . backend . api . getInspectorTree ( inspector . id , inspector . appRecord . options . app , inspector . treeFilter ) ; ctx . bridge . send ( BridgeEvents . TO_FRONT_CUSTOM_INSPECTOR_TREE , { appId : inspector . appRecord . id , inspectorId : inspector . id , rootNodes , } ) ; } export async function sendInspectorState ( inspector , ctx ) { const state = inspector . selectedNodeId ? await inspector . appRecord . backend . api . getInspectorState ( inspector . id , inspector . appRecord . options . app , inspector . selectedNodeId ) : null ; ctx . bridge . send ( BridgeEvents . TO_FRONT_CUSTOM_INSPECTOR_STATE , { appId : inspector . appRecord . id , inspectorId : inspector . id , state : stringify ( state ) , } ) ; } export async function editInspectorState ( inspector , nodeId , dotPath , type , state , ctx ) { await inspector . appRecord . backend . api . editInspectorState ( inspector . id , inspector . appRecord . options . app , nodeId , dotPath , type , { ... state , value : state . value != null ? parse ( state . value , true ) : state . value , } ) ; } export async function sendCustomInspectors ( ctx ) { const inspectors = [ ] ; for ( const i of ctx . customInspectors ) { inspectors . push ( { id : i . id , appId : i . appRecord . id , pluginId : i . plugin . descriptor . id , label : i . label , icon : i . icon , treeFilterPlaceholder : i . treeFilterPlaceholder , stateFilterPlaceholder : i . stateFilterPlaceholder , noSelectionText : i . noSelectionText , actions : i . actions ?. map ( a => ( { icon : a . icon , tooltip : a . tooltip , } ) ) , } ) ; } ctx . bridge . send ( BridgeEvents . TO_FRONT_CUSTOM_INSPECTOR_LIST , { inspectors , } ) ; } export async function selectInspectorNode ( inspector , nodeId , ctx ) { ctx . bridge . send ( BridgeEvents . TO_FRONT_CUSTOM_INSPECTOR_SELECT_NODE , { appId : inspector . appRecord . id , inspectorId : inspector . id , nodeId , } ) ; }