Skip to content

Commit

Permalink
Add interface to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Dec 13, 2024
1 parent f8596a0 commit 4781c0b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
5 changes: 2 additions & 3 deletions demo/src/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/quotes */
/* eslint-disable no-undef */
import { CommandBridge } from 'jupyter-iframe-commands-host';
import { createBridge } from 'jupyter-iframe-commands-host';

const commandBridge = new CommandBridge({ iframeId: 'jupyterlab' })
.commandBridge;
const commandBridge = createBridge({ iframeId: 'jupyterlab' });

// Create and append dialogs to the document
const instructionsDialog = document.createElement('dialog');
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
},
"dependencies": {
"@jupyterlab/application": "^4.3.2",
"@jupyterlab/settingregistry": "^4.3.2"
"@jupyterlab/settingregistry": "^4.3.2",
"@lumino/coreutils": "^2.2.0"
},
"devDependencies": {
"@jupyterlab/builder": "^4.3.2"
Expand Down
4 changes: 3 additions & 1 deletion packages/extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
import { expose, windowEndpoint } from 'comlink';
import { ICommandBridgeRemote } from './interface';

/**
* A plugin to expose an API for interacting with JupyterLab from a parent page.
Expand Down Expand Up @@ -42,7 +43,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
}

const api = {
const api: ICommandBridgeRemote = {
execute(command: string, args: ReadonlyPartialJSONObject) {
commands.execute(command, args);
},
Expand All @@ -57,3 +58,4 @@ const plugin: JupyterFrontEndPlugin<void> = {
};

export default plugin;
export * from './interface';
6 changes: 6 additions & 0 deletions packages/extension/src/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';

export interface ICommandBridgeRemote {
execute(command: string, args: ReadonlyPartialJSONObject): void;
listCommands(): string[];
}
5 changes: 2 additions & 3 deletions packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@lumino/commands": "^2.3.1",
"@lumino/coreutils": "^2.2.0",
"comlink": "^4.4.2"
"comlink": "^4.4.2",
"jupyter-iframe-commands": "0.0.1"
}
}
14 changes: 11 additions & 3 deletions packages/host/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) TileDB, Inc.
// Distributed under the terms of the Modified BSD License.
import { Endpoint, Remote, windowEndpoint, wrap } from 'comlink';

import { ICommandBridgeRemote } from 'jupyter-iframe-commands';
/**
* A bridge to expose actions on JupyterLab commands.
*/
Expand All @@ -22,13 +22,21 @@ export class CommandBridge {
}

this._endpoint = windowEndpoint(this._childWindow);
this.commandBridge = wrap(this._endpoint);
this._commandBridge = wrap(this._endpoint);
}

get commandBridge() {
return this._commandBridge;
}

private _iframe: HTMLIFrameElement | null;
private _childWindow: Window | undefined | null;
private _endpoint: Endpoint | undefined;
commandBridge: Remote<unknown> | undefined;
private _commandBridge: Remote<ICommandBridgeRemote> | undefined;
}

export function createBridge({ iframeId }: CommandBridge.IOptions) {
return new CommandBridge({ iframeId }).commandBridge;
}

export namespace CommandBridge {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5885,9 +5885,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "jupyter-iframe-commands-host@workspace:packages/host"
dependencies:
"@lumino/commands": ^2.3.1
"@lumino/coreutils": ^2.2.0
comlink: ^4.4.2
jupyter-iframe-commands: 0.0.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -5921,13 +5920,14 @@ __metadata:
languageName: unknown
linkType: soft

"jupyter-iframe-commands@workspace:packages/extension":
"jupyter-iframe-commands@0.0.1, jupyter-iframe-commands@workspace:packages/extension":
version: 0.0.0-use.local
resolution: "jupyter-iframe-commands@workspace:packages/extension"
dependencies:
"@jupyterlab/application": ^4.3.2
"@jupyterlab/builder": ^4.3.2
"@jupyterlab/settingregistry": ^4.3.2
"@lumino/coreutils": ^2.2.0
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 4781c0b

Please sign in to comment.