Const globalsEditorPlugin
globalsEditorPlugin: IPlugin<Application<Widget>, void> = {id: "@mavenomics/dashboard-devtools:globals-editor",autoStart: true,requires: [IDashboardTracker],activate: (app, tracker: IDashboardTracker) => {const { commands, contextMenu } = app;commands.addCommand(GlobalsEditorCommands.OpenGlobals, {label: "Open Globals Editor",iconClass: "fa fa-globe",isEnabled: () => tracker.getCurrentDashboard() != null,execute: async () => {let dashboard = tracker.getCurrentDashboard();if (dashboard == null) {return;}let globals = dashboard.globals;let serializedGlobals = serializeGlobals(globals);const hover = new class extends ReactWrapperWidget {private context: TypeEditorHost.IContext = {portalHostNode: void 0,owner: this,};protected render() {return React.createElement(TypeEditorHost.Context.Provider,{ value: this.context },React.createElement(OptionsEditor, {arguments: serializedGlobals,onArgsChanged: (newArgs) => {serializedGlobals = newArgs;}} as OptionsEditor.IProps)) as React.ReactElement<unknown>;}protected onAfterChangeDocumentOwner() {this.context = {portalHostNode: this.node.ownerDocument!.body,owner: this};this.update();}};await HoverManager.GetManager().launchEditorDialog(hover,dashboard,700,500,"Globals Editor",() => {// TODO: Globals#mergeGlobals()const unvisitedGlobals = new Set(IterTools.map(globals, i => i.name));const visitedGlobals = new Set<string>();for (const global of serializedGlobals) {if (!unvisitedGlobals.has(global.name)) {globals.addGlobal(global.name,Types.findType(global.typeAnnotation) || Types.Any,Converters.deserialize(global.defaultValue));continue;}unvisitedGlobals.delete(global.name);visitedGlobals.add(global.name);}for (const toDelete of unvisitedGlobals.values()) {globals.removeGlobal(toDelete);}for (const toChange of visitedGlobals.values()) {const global = serializedGlobals.find(i => i.name === toChange)!;globals.changeType(toChange, Types.findType(global.typeAnnotation) || Types.Any);globals.set(toChange, Converters.deserialize(global.defaultValue));}});}});commands.addKeyBinding({command: GlobalsEditorCommands.OpenGlobals,keys: ["Accel G"],selector: ".jp-Notebook.jp-mod-commandMode:not(.p-mod-hidden)"});contextMenu.addItem({command: GlobalsEditorCommands.OpenGlobals,selector: ".jp-Notebook:not(.p-mod-hidden)"});commands.addKeyBinding({command: GlobalsEditorCommands.OpenGlobals,keys: ["Accel G"],selector: ".m-DashboardEditor:not(.p-mod-hidden)"});contextMenu.addItem({command: GlobalsEditorCommands.OpenGlobals,selector: ".m-DashboardEditor:not(.p-mod-hidden)"});}} as IPlugin<Application<Widget>, void>
A set of routines to perform actions on dashboards.
This is meant as a stand-in for real Phosphor commands, since due to the current architechture we need to duplicate some work here. Until we can factor out the dashboards into an independent plugin, this will have to do for now.