diff --git a/packages/base/src/commands.ts b/packages/base/src/commands.ts index d593cdaa..9f1ed3c4 100644 --- a/packages/base/src/commands.ts +++ b/packages/base/src/commands.ts @@ -43,7 +43,6 @@ import { DocumentRegistry } from '@jupyterlab/docregistry'; import { PathExt } from '@jupyterlab/coreutils'; import { MainViewModel } from './3dview/mainviewmodel'; import { handleRemoveObject } from './panelview'; -import { syncEditor } from './widget'; export function newName(type: string, model: IJupyterCadModel): string { const sharedModel = model.sharedModel; @@ -684,7 +683,6 @@ export function addCommands( const trans = translator.load('jupyterlab'); const { commands } = app; Private.updateFormSchema(formSchemaRegistry); - syncEditor(tracker); commands.addCommand(CommandIDs.toggleConsole, { label: trans.__('Toggle console'), diff --git a/packages/base/src/widget.ts b/packages/base/src/widget.ts index 2124ab71..fe83830d 100644 --- a/packages/base/src/widget.ts +++ b/packages/base/src/widget.ts @@ -38,17 +38,6 @@ export class JupyterCadWidget }; } -export function syncEditor(tracker: WidgetTracker) { - tracker.currentChanged.connect(() => { - const currentWidget = tracker.currentWidget; - - if (currentWidget) { - const resizeEvent = new Event('resize'); - window.dispatchEvent(resizeEvent); - } - }); -} - export class JupyterCadPanel extends SplitPanel { constructor(options: JupyterCadPanel.IOptions) { super({ orientation: 'vertical', spacing: 0 }); @@ -57,6 +46,7 @@ export class JupyterCadPanel extends SplitPanel { this._initView(); this._consoleOption = consoleOption; this._consoleTracker = consoleTracker; + this._syncEditor(options.tracker); } _initModel(options: { @@ -79,6 +69,17 @@ export class JupyterCadPanel extends SplitPanel { SplitPanel.setStretch(this._jupyterCadMainViewPanel, 1); } + private _syncEditor(tracker: WidgetTracker) { + tracker.currentChanged.connect(() => { + const currentWidget = tracker.currentWidget; + + if (currentWidget) { + const resizeEvent = new Event('resize'); + window.dispatchEvent(resizeEvent); + } + }); + } + get jupyterCadMainViewPanel(): JupyterCadMainViewPanel { return this._jupyterCadMainViewPanel; } @@ -241,5 +242,6 @@ export namespace JupyterCadPanel { model: IJupyterCadModel; workerRegistry: IJCadWorkerRegistry; consoleTracker?: IConsoleTracker; + tracker: WidgetTracker; } } diff --git a/python/jupytercad_core/src/factory.ts b/python/jupytercad_core/src/factory.ts index 26e4f331..3075267b 100644 --- a/python/jupytercad_core/src/factory.ts +++ b/python/jupytercad_core/src/factory.ts @@ -1,7 +1,6 @@ import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console'; import { JupyterCadModel, - IJupyterCadTracker, IJCadWorkerRegistry, IJCadExternalCommandRegistry } from '@jupytercad/schema'; @@ -15,9 +14,10 @@ import { ToolbarWidget } from '@jupytercad/base'; import { ServiceManager } from '@jupyterlab/services'; - +import { WidgetTracker } from '@jupyterlab/apputils'; +import { IJupyterCadWidget } from '@jupytercad/schema'; interface IOptions extends DocumentRegistry.IWidgetFactoryOptions { - tracker: IJupyterCadTracker; + tracker: WidgetTracker; commands: CommandRegistry; workerRegistry: IJCadWorkerRegistry; externalCommandRegistry: IJCadExternalCommandRegistry; @@ -66,7 +66,8 @@ export class JupyterCadWidgetFactory extends ABCWidgetFactory< mimeTypeService: this.options.mimeTypeService, rendermime: this.options.rendermime, consoleTracker: this.options.consoleTracker, - commandRegistry: this.options.commands + commandRegistry: this.options.commands, + tracker: this.options.tracker }); const toolbar = new ToolbarWidget({ commands: this._commands, diff --git a/python/jupytercad_lab/src/notebookrenderer.ts b/python/jupytercad_lab/src/notebookrenderer.ts index 8c9b50df..b9d90b84 100644 --- a/python/jupytercad_lab/src/notebookrenderer.ts +++ b/python/jupytercad_lab/src/notebookrenderer.ts @@ -4,6 +4,7 @@ import { IJCadWorkerRegistry, IJCadWorkerRegistryToken, IJupyterCadDoc, + IJupyterCadWidget, JupyterCadModel } from '@jupytercad/schema'; @@ -20,7 +21,7 @@ import { IJupyterYWidgetManager, JupyterYModel } from 'yjs-widgets'; - +import { WidgetTracker } from '@jupyterlab/apputils'; export interface ICommMetadata { create_ydoc: boolean; path: string; @@ -39,6 +40,7 @@ export class YJupyterCADLuminoWidget extends Panel { constructor(options: { model: JupyterCadModel; workerRegistry: IJCadWorkerRegistry; + tracker: WidgetTracker; }) { super(); @@ -78,6 +80,10 @@ export const notebookRenderePlugin: JupyterFrontEndPlugin = { console.error('Missing ICollaborativeDrive token!'); return; } + + const tracker = new WidgetTracker({ + namespace: 'jupytercad' + }); class YJupyterCADModelFactory extends YJupyterCADModel { ydocFactory(commMetadata: ICommMetadata): Y.Doc { const { path, format, contentType } = commMetadata; @@ -105,7 +111,8 @@ export const notebookRenderePlugin: JupyterFrontEndPlugin = { const widget = new YJupyterCADLuminoWidget({ model: yModel.jupyterCADModel, - workerRegistry + workerRegistry, + tracker }); // Widget.attach(widget, node);