Skip to content

Remove demo and css-extension #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ dmypy.json

# lite build for demo
demo/public/lite
demo-react/public/lite
.jupyterlite.doit.db

# nx cache files
Expand All @@ -137,3 +138,5 @@ Untitled*.ipynb

# Pixi environments
.pixi

.vscode/*
41 changes: 0 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,47 +128,6 @@ For further information please consult the Jupyter documentation:
- Creating an extension: https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html
- Adding commands to the command registry: https://jupyterlab.readthedocs.io/en/stable/extension/extension_points.html#commands

## Demos

### Local Demo

To run the demo on a local Jupyter Lab instance:

1. Follow the [development install instructions](#development-install)
2. `cd demo`
3. Start JupyterLab:

```bash
jlpm start:lab
```

4. In another terminal, start the demo app:

```bash
jlpm start:local
```

Open http://localhost:8080 in your browser.

### Lite Demo

To run the demo on a Jupyter Lite instance:

1. Follow the [development install instructions](#development-install)
2. `cd demo`
3. Build and start the demo app:

```bash
# Build the lite assets
jlpm build:lite

# Build the demo
jlpm build:ghpages

# Start the development server
jlpm start:lite
```

## Uninstall

To remove the extension, execute:
Expand Down
5 changes: 3 additions & 2 deletions demo/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, sans-serif;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
Arial, sans-serif;
color: var(--text-color);
background-color: var(--background-color);
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "QuantStack",
"workspaces": [
"packages/*",
"demo"
"demo/"
],
"scripts": {
"build": "lerna run build",
Expand Down
1 change: 1 addition & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"dependencies": {
"@jupyterlab/application": "^4.3.2",
"@jupyterlab/notebook": "^4.3.2",
"@jupyterlab/settingregistry": "^4.3.2",
"@lumino/coreutils": "^2.2.0"
},
Expand Down
32 changes: 30 additions & 2 deletions packages/extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Distributed under the terms of the Modified BSD License.

import {
ILabStatus,
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { INotebookTracker } from '@jupyterlab/notebook';
import { KernelAPI, SessionAPI, TerminalAPI } from '@jupyterlab/services';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
import { expose, windowEndpoint } from 'comlink';
import { expose, windowEndpoint, wrap } from 'comlink';
import { ICommandBridgeRemote } from './interface';

/**
Expand All @@ -18,9 +21,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
autoStart: true,
description:
'A plugin to expose an API for interacting with JupyterLab from a parent page.',
requires: [ILabStatus, INotebookTracker],
optional: [ISettingRegistry],
activate: async (
app: JupyterFrontEnd,
labStatus: ILabStatus,
tracker: INotebookTracker,
settingRegistry: ISettingRegistry | null
) => {
console.log('JupyterLab extension jupyter-iframe-commands is activated!');
Expand All @@ -47,13 +53,35 @@ const plugin: JupyterFrontEndPlugin<void> = {
async execute(command: string, args: ReadonlyPartialJSONObject) {
await commands.execute(command, args);
},
listCommands() {
async listCommands() {
return commands.listCommands();
},
async listRunning() {
// ? Move to command extension?
const terminals = await TerminalAPI.listRunning();
const sessions = await SessionAPI.listRunning();
const kernels = await KernelAPI.listRunning();

return { terminals, sessions, kernels };
}
};

labStatus.busySignal.connect(async () => {
const kernelSpec =
await tracker.currentWidget?.sessionContext?.session?.kernel?.spec;
const displayName = kernelSpec ? kernelSpec.display_name : 'Loading...';
await host.kernelStatus(displayName, labStatus.isBusy);
});

const endpoint = windowEndpoint(self.parent);
const host = wrap<any>(endpoint); // TODO: fix typings?

expose(api, endpoint);

//TODO targetOrigin should be host page
app.started.then(() => {
host.setReady(true);
});
}
};

Expand Down
9 changes: 8 additions & 1 deletion packages/extension/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { KernelAPI, Session, TerminalAPI } from '@jupyterlab/services';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';

/**
Expand All @@ -19,5 +20,11 @@ export interface ICommandBridgeRemote {
*
* @returns An array of strings representing the names of all available commands.
*/
listCommands(): string[];
listCommands(): Promise<string[]>;

listRunning(): Promise<{
terminals: TerminalAPI.IModel[];
sessions: Session.IModel[];
kernels: KernelAPI.IModel[];
}>;
}
64 changes: 63 additions & 1 deletion packages/host/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Copyright (c) TileDB, Inc.
// Distributed under the terms of the Modified BSD License.
import { windowEndpoint, wrap } from 'comlink';
import { expose, windowEndpoint, wrap } from 'comlink';
import { ICommandBridgeRemote } from 'jupyter-iframe-commands';

type Listener = () => void;
export interface IJupyterInfo {
isBridgeReady: boolean;
kernelInfo: {
kernelName: string;
isKernelBusy: boolean;
};
}

/**
* A bridge to expose actions on JupyterLab commands.
*/
Expand All @@ -22,3 +32,55 @@ export function createBridge({ iframeId }: { iframeId: string }) {

return wrap<ICommandBridgeRemote>(windowEndpoint(iframe.contentWindow));
}

/**
* Define host package api and expose it to Jupyter extension
*/
export function exposeApi({ iframeId }: { iframeId: string }) {
const iframe = document.getElementById(iframeId) as HTMLIFrameElement;

if (!iframe.contentWindow) {
return;
}
const endpoint = windowEndpoint(iframe.contentWindow);
const hostApi = {
async setReady(val: boolean) {
jupyterInfo.setState({ isBridgeReady: val });
},
async kernelStatus(displayName: string, stat: boolean) {
jupyterInfo.setState({
kernelInfo: { kernelName: displayName, isKernelBusy: stat }
});
}
};

expose(hostApi, endpoint);
}

// Create observable state for consuming app to subscribe to
let jupyterInfoState = {
isBridgeReady: false,
kernelInfo: {
kernelName: 'Loading...',
isKernelBusy: false
}
};

const listeners = new Set<Listener>();
export const jupyterInfo = {
getState() {
return jupyterInfoState;
},

setState(newState: Partial<IJupyterInfo>) {
const mergedState = { ...jupyterInfoState, ...newState };

jupyterInfoState = mergedState;
listeners.forEach(listener => listener());
},

subscribe(listener: Listener) {
listeners.add(listener);
return () => listeners.delete(listener);
}
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"target": "ES2018"
"target": "ES2018",
"skipLibCheck": true
}
}
3 changes: 1 addition & 2 deletions ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "JupyterLab jupyter-iframe-commands Integration Tests",
"private": true,
"scripts": {
"start:lab": "jupyter lab --config jupyter_server_test_config.py",
"start:server": "jlpm --cwd ../demo start:local",
"start": "jupyter lab --config jupyter_server_test_config.py",
"test": "jlpm playwright test",
"test:update": "jlpm playwright test --update-snapshots"
},
Expand Down
8 changes: 1 addition & 7 deletions ui-tests/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ module.exports = {
},
webServer: [
{
command: 'jlpm start:lab',
command: 'jlpm start',
url: 'http://localhost:8888/lab',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI
},
{
command: 'jlpm start:server',
url: 'http://localhost:8080',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI
}
]
};
104 changes: 0 additions & 104 deletions ui-tests/tests/hostpage-tests.spec.ts

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading
Loading