Adds a token on the notebook tree widget, in order to easily add widgets in it from external extension

This commit is contained in:
Nicolas Brichet 2022-08-01 17:27:26 +02:00
parent c6faa5c32d
commit 429e255abf
16 changed files with 229 additions and 81 deletions

View File

@ -19,6 +19,7 @@
"@jupyter-notebook/help-extension": "~7.0.0-alpha.5",
"@jupyter-notebook/notebook-extension": "~7.0.0-alpha.5",
"@jupyter-notebook/terminal-extension": "~7.0.0-alpha.5",
"@jupyter-notebook/tree": "~7.0.0-alpha.5",
"@jupyter-notebook/tree-extension": "~7.0.0-alpha.5",
"@jupyter-notebook/ui-components": "~7.0.0-alpha.5",
"@jupyterlab/application": "~4.0.0-alpha.10",
@ -104,6 +105,7 @@
"@jupyter-notebook/help-extension": "^7.0.0-alpha.5",
"@jupyter-notebook/notebook-extension": "^7.0.0-alpha.5",
"@jupyter-notebook/terminal-extension": "^7.0.0-alpha.5",
"@jupyter-notebook/tree": "^7.0.0-alpha.5",
"@jupyter-notebook/tree-extension": "^7.0.0-alpha.5",
"@jupyter-notebook/ui-components": "^7.0.0-alpha.5",
"@jupyterlab/application-extension": "^4.0.0-alpha.10",
@ -194,6 +196,7 @@
"@jupyterlab/user-extension"
],
"singletonPackages": [
"@jupyter-notebook/tree",
"@jupyterlab/application",
"@jupyterlab/apputils",
"@jupyterlab/cell-toolbar",

View File

@ -29,6 +29,7 @@
"@jupyter-notebook/lab-extension": "file:../lab-extension",
"@jupyter-notebook/notebook-extension": "file:../notebook-extension",
"@jupyter-notebook/terminal-extension": "file:../terminal-extension",
"@jupyter-notebook/tree": "file:../tree",
"@jupyter-notebook/tree-extension": "file:../tree-extension",
"@jupyter-notebook/ui-components": "file:../ui-components"
},

View File

@ -7,5 +7,6 @@ import '@jupyter-notebook/help-extension';
import '@jupyter-notebook/lab-extension';
import '@jupyter-notebook/notebook-extension';
import '@jupyter-notebook/terminal-extension';
import '@jupyter-notebook/tree';
import '@jupyter-notebook/tree-extension';
import '@jupyter-notebook/ui-components';

View File

@ -40,6 +40,7 @@
},
"dependencies": {
"@jupyter-notebook/application": "^7.0.0-alpha.5",
"@jupyter-notebook/tree": "^7.0.0-alpha.5",
"@jupyterlab/application": "^4.0.0-alpha.10",
"@jupyterlab/apputils": "^4.0.0-alpha.10",
"@jupyterlab/coreutils": "^6.0.0-alpha.10",

View File

@ -27,11 +27,13 @@ import { ITranslator } from '@jupyterlab/translation';
import {
caretDownIcon,
folderIcon,
runningIcon,
TabBarSvg
runningIcon
} from '@jupyterlab/ui-components';
import { Menu, MenuBar, TabPanel } from '@lumino/widgets';
import { Menu, MenuBar } from '@lumino/widgets';
import { NotebookTreeWidget } from '@jupyter-notebook/tree';
import { INotebookTree } from '@jupyter-notebook/tree';
/**
* The file browser factory.
@ -93,10 +95,87 @@ const createNew: JupyterFrontEndPlugin<void> = {
}
};
function activateNotebookTreeWidget(
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
translator: ITranslator,
settingRegistry: ISettingRegistry,
toolbarRegistry: IToolbarWidgetRegistry,
manager: IRunningSessionManagers | null
): INotebookTree {
const notebookTreeWidget = new NotebookTreeWidget();
// const tabPanel = new TabPanel({
// tabPlacement: 'top',
// tabsMovable: true,
// renderer: TabBarSvg.defaultRenderer
// });
// tabPanel.addClass('jp-TreePanel');
const trans = translator.load('notebook');
const { defaultBrowser: browser } = factory;
browser.title.label = trans.__('Files');
browser.node.setAttribute('role', 'region');
browser.node.setAttribute('aria-label', trans.__('File Browser Section'));
browser.title.icon = folderIcon;
notebookTreeWidget.addWidget(browser);
notebookTreeWidget.tabBar.addTab(browser.title);
// Toolbar
toolbarRegistry.addFactory(
FILE_BROWSER_FACTORY,
'uploader',
(browser: FileBrowser) =>
new Uploader({
model: browser.model,
translator,
label: trans.__('Upload')
})
);
setToolbar(
browser,
createToolbarFactory(
toolbarRegistry,
settingRegistry,
FILE_BROWSER_FACTORY,
notebookTreeWidget.id,
translator
)
);
if (manager) {
const running = new RunningSessions(manager, translator);
running.id = 'jp-running-sessions';
running.title.label = trans.__('Running');
running.title.icon = runningIcon;
notebookTreeWidget.addWidget(running);
notebookTreeWidget.tabBar.addTab(running.title);
}
// show checkboxes by default if there is no user setting override
const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID);
Promise.all([settings, app.restored])
.then(([settings]) => {
if (settings.user.showFileCheckboxes !== undefined) {
return;
}
void settings.set('showFileCheckboxes', true);
})
.catch((reason: Error) => {
console.error(reason.message);
});
app.shell.add(notebookTreeWidget, 'main', { rank: 100 });
return notebookTreeWidget;
}
/**
* A plugin to add the file browser widget to an ILabShell
* A plugin to add the file browser widget to an INotebookShell
*/
const browserWidget: JupyterFrontEndPlugin<void> = {
const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
id: '@jupyter-notebook/tree-extension:widget',
requires: [
IFileBrowserFactory,
@ -106,83 +185,12 @@ const browserWidget: JupyterFrontEndPlugin<void> = {
],
optional: [IRunningSessionManagers],
autoStart: true,
activate: (
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
translator: ITranslator,
settingRegistry: ISettingRegistry,
toolbarRegistry: IToolbarWidgetRegistry,
manager: IRunningSessionManagers | null
): void => {
const tabPanel = new TabPanel({
tabPlacement: 'top',
tabsMovable: true,
renderer: TabBarSvg.defaultRenderer
});
tabPanel.addClass('jp-TreePanel');
const trans = translator.load('notebook');
const { defaultBrowser: browser } = factory;
browser.title.label = trans.__('Files');
browser.node.setAttribute('role', 'region');
browser.node.setAttribute('aria-label', trans.__('File Browser Section'));
browser.title.icon = folderIcon;
tabPanel.addWidget(browser);
tabPanel.tabBar.addTab(browser.title);
// Toolbar
toolbarRegistry.addFactory(
FILE_BROWSER_FACTORY,
'uploader',
(browser: FileBrowser) =>
new Uploader({
model: browser.model,
translator,
label: trans.__('Upload')
})
);
setToolbar(
browser,
createToolbarFactory(
toolbarRegistry,
settingRegistry,
FILE_BROWSER_FACTORY,
browserWidget.id,
translator
)
);
if (manager) {
const running = new RunningSessions(manager, translator);
running.id = 'jp-running-sessions';
running.title.label = trans.__('Running');
running.title.icon = runningIcon;
tabPanel.addWidget(running);
tabPanel.tabBar.addTab(running.title);
}
// show checkboxes by default if there is no user setting override
const settings = settingRegistry.load(FILE_BROWSER_PLUGIN_ID);
Promise.all([settings, app.restored])
.then(([settings]) => {
if (settings.user.showFileCheckboxes !== undefined) {
return;
}
void settings.set('showFileCheckboxes', true);
})
.catch((reason: Error) => {
console.error(reason.message);
});
app.shell.add(tabPanel, 'main', { rank: 100 });
}
provides: INotebookTree,
activate: activateNotebookTreeWidget
};
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, browserWidget];
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, notebookTreeWidget];
export default plugins;

View File

@ -1,3 +1,3 @@
@import url('~@jupyterlab/filebrowser/style/index.css');
@import url('./base.css');
@import url('~@jupyter-notebook/tree/style/index.css');

View File

@ -1,3 +1,3 @@
import '@jupyterlab/filebrowser/style/index.js';
import './base.css';
import '@jupyter-notebook/tree/style/index.js';

View File

@ -0,0 +1,66 @@
{
"name": "@jupyter-notebook/tree",
"version": "7.0.0-alpha.5",
"description": "Jupyter Notebook - Tree ",
"homepage": "https://github.com/jupyter/notebook",
"bugs": {
"url": "https://github.com/jupyter/notebook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyter/notebook.git"
},
"license": "BSD-3-Clause",
"author": "Project Jupyter",
"sideEffects": [
"style/**/*.css",
"style/index.js"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"directories": {
"lib": "lib/"
},
"files": [
"lib/*.d.ts",
"lib/*.js.map",
"lib/*.js",
"schema/*.json",
"style/**/*.css",
"style/index.js"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"prepublishOnly": "npm run build",
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyter-notebook/application": "^7.0.0-alpha.5",
"@jupyterlab/application": "^4.0.0-alpha.10",
"@jupyterlab/apputils": "^4.0.0-alpha.10",
"@jupyterlab/coreutils": "^6.0.0-alpha.10",
"@jupyterlab/docmanager": "^4.0.0-alpha.10",
"@jupyterlab/filebrowser": "^4.0.0-alpha.10",
"@jupyterlab/mainmenu": "^4.0.0-alpha.10",
"@jupyterlab/services": "^7.0.0-alpha.10",
"@jupyterlab/settingregistry": "^4.0.0-alpha.10",
"@jupyterlab/statedb": "^4.0.0-alpha.10",
"@jupyterlab/translation": "^4.0.0-alpha.10",
"@jupyterlab/ui-components": "^4.0.0-alpha.25",
"@lumino/algorithm": "^1.9.1",
"@lumino/commands": "^1.20.0",
"@lumino/widgets": "^1.32.0"
},
"devDependencies": {
"rimraf": "~3.0.0",
"typescript": "~4.6.3"
},
"publishConfig": {
"access": "public"
},
"styleModule": "style/index.js"
}

View File

@ -0,0 +1,2 @@
export * from './notebook-tree';
export * from './token';

View File

@ -0,0 +1,16 @@
import { TabBarSvg } from '@jupyterlab/ui-components';
import { TabPanel } from '@lumino/widgets';
import { INotebookTree } from './token';
export class NotebookTreeWidget extends TabPanel implements INotebookTree {
constructor() {
super({
tabPlacement: 'top',
tabsMovable: true,
renderer: TabBarSvg.defaultRenderer
});
this.addClass('jp-TreePanel');
}
}

View File

@ -0,0 +1,11 @@
import { Token } from '@lumino/coreutils';
import { TabPanel } from '@lumino/widgets';
export interface INotebookTree extends TabPanel {}
/**
* The INotebookTree token.
*/
export const INotebookTree = new Token<INotebookTree>(
'@jupyter-notebook/tree:INotebookTree'
);

View File

@ -0,0 +1,3 @@
@import url('~@jupyterlab/filebrowser/style/index.css');
@import url('./base.css');

View File

@ -0,0 +1,3 @@
import '@jupyterlab/filebrowser/style/index.js';
import './base.css';

View File

@ -0,0 +1,13 @@
{
"extends": "../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"],
"references": [
{
"path": "../application"
}
]
}

View File

@ -1388,6 +1388,26 @@
"@lumino/algorithm" "^1.9.1"
"@jupyter-notebook/tree-extension@file:packages/tree-extension":
version "7.0.0-alpha.5"
dependencies:
"@jupyter-notebook/application" "^7.0.0-alpha.5"
"@jupyter-notebook/tree" "^7.0.0-alpha.5"
"@jupyterlab/application" "^4.0.0-alpha.10"
"@jupyterlab/apputils" "^4.0.0-alpha.10"
"@jupyterlab/coreutils" "^6.0.0-alpha.10"
"@jupyterlab/docmanager" "^4.0.0-alpha.10"
"@jupyterlab/filebrowser" "^4.0.0-alpha.10"
"@jupyterlab/mainmenu" "^4.0.0-alpha.10"
"@jupyterlab/services" "^7.0.0-alpha.10"
"@jupyterlab/settingregistry" "^4.0.0-alpha.10"
"@jupyterlab/statedb" "^4.0.0-alpha.10"
"@jupyterlab/translation" "^4.0.0-alpha.10"
"@jupyterlab/ui-components" "^4.0.0-alpha.25"
"@lumino/algorithm" "^1.9.1"
"@lumino/commands" "^1.20.0"
"@lumino/widgets" "^1.32.0"
"@jupyter-notebook/tree@file:packages/tree":
version "7.0.0-alpha.5"
dependencies:
"@jupyter-notebook/application" "^7.0.0-alpha.5"