From 429e255abf17d96167f1f0acd42f73c14dc9bb00 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Mon, 1 Aug 2022 17:27:26 +0200 Subject: [PATCH 1/5] Adds a token on the notebook tree widget, in order to easily add widgets in it from external extension --- app/package.json | 3 + packages/_metapackage/package.json | 1 + packages/_metapackage/src/index.ts | 1 + packages/tree-extension/package.json | 1 + packages/tree-extension/src/index.ts | 166 +++++++++--------- packages/tree-extension/style/index.css | 2 +- packages/tree-extension/style/index.js | 2 +- packages/tree/package.json | 66 +++++++ packages/tree/src/index.ts | 2 + packages/tree/src/notebook-tree.ts | 16 ++ packages/tree/src/token.ts | 11 ++ .../{tree-extension => tree}/style/base.css | 0 packages/tree/style/index.css | 3 + packages/tree/style/index.js | 3 + packages/tree/tsconfig.json | 13 ++ yarn.lock | 20 +++ 16 files changed, 229 insertions(+), 81 deletions(-) create mode 100644 packages/tree/package.json create mode 100644 packages/tree/src/index.ts create mode 100644 packages/tree/src/notebook-tree.ts create mode 100644 packages/tree/src/token.ts rename packages/{tree-extension => tree}/style/base.css (100%) create mode 100644 packages/tree/style/index.css create mode 100644 packages/tree/style/index.js create mode 100644 packages/tree/tsconfig.json diff --git a/app/package.json b/app/package.json index 46c7bd354f..e27b1a4f8a 100644 --- a/app/package.json +++ b/app/package.json @@ -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", diff --git a/packages/_metapackage/package.json b/packages/_metapackage/package.json index 02693ac6f1..205c89adb2 100644 --- a/packages/_metapackage/package.json +++ b/packages/_metapackage/package.json @@ -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" }, diff --git a/packages/_metapackage/src/index.ts b/packages/_metapackage/src/index.ts index e0ba7372bc..c41bc6c855 100644 --- a/packages/_metapackage/src/index.ts +++ b/packages/_metapackage/src/index.ts @@ -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'; diff --git a/packages/tree-extension/package.json b/packages/tree-extension/package.json index 2187b0e209..fec081e678 100644 --- a/packages/tree-extension/package.json +++ b/packages/tree-extension/package.json @@ -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", diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index d9b842f7ac..4320e814b0 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -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 = { } }; +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 = { +const notebookTreeWidget: JupyterFrontEndPlugin = { id: '@jupyter-notebook/tree-extension:widget', requires: [ IFileBrowserFactory, @@ -106,83 +185,12 @@ const browserWidget: JupyterFrontEndPlugin = { ], 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[] = [createNew, browserWidget]; +const plugins: JupyterFrontEndPlugin[] = [createNew, notebookTreeWidget]; export default plugins; diff --git a/packages/tree-extension/style/index.css b/packages/tree-extension/style/index.css index c6a335ca57..078667ad6e 100644 --- a/packages/tree-extension/style/index.css +++ b/packages/tree-extension/style/index.css @@ -1,3 +1,3 @@ @import url('~@jupyterlab/filebrowser/style/index.css'); -@import url('./base.css'); +@import url('~@jupyter-notebook/tree/style/index.css'); diff --git a/packages/tree-extension/style/index.js b/packages/tree-extension/style/index.js index 334392b2dc..406d1565af 100644 --- a/packages/tree-extension/style/index.js +++ b/packages/tree-extension/style/index.js @@ -1,3 +1,3 @@ import '@jupyterlab/filebrowser/style/index.js'; -import './base.css'; +import '@jupyter-notebook/tree/style/index.js'; diff --git a/packages/tree/package.json b/packages/tree/package.json new file mode 100644 index 0000000000..94298d3c1d --- /dev/null +++ b/packages/tree/package.json @@ -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" +} diff --git a/packages/tree/src/index.ts b/packages/tree/src/index.ts new file mode 100644 index 0000000000..dd239a6187 --- /dev/null +++ b/packages/tree/src/index.ts @@ -0,0 +1,2 @@ +export * from './notebook-tree'; +export * from './token'; diff --git a/packages/tree/src/notebook-tree.ts b/packages/tree/src/notebook-tree.ts new file mode 100644 index 0000000000..85fd387c3a --- /dev/null +++ b/packages/tree/src/notebook-tree.ts @@ -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'); + } +} diff --git a/packages/tree/src/token.ts b/packages/tree/src/token.ts new file mode 100644 index 0000000000..7ae940953a --- /dev/null +++ b/packages/tree/src/token.ts @@ -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( + '@jupyter-notebook/tree:INotebookTree' +); diff --git a/packages/tree-extension/style/base.css b/packages/tree/style/base.css similarity index 100% rename from packages/tree-extension/style/base.css rename to packages/tree/style/base.css diff --git a/packages/tree/style/index.css b/packages/tree/style/index.css new file mode 100644 index 0000000000..c6a335ca57 --- /dev/null +++ b/packages/tree/style/index.css @@ -0,0 +1,3 @@ +@import url('~@jupyterlab/filebrowser/style/index.css'); + +@import url('./base.css'); diff --git a/packages/tree/style/index.js b/packages/tree/style/index.js new file mode 100644 index 0000000000..334392b2dc --- /dev/null +++ b/packages/tree/style/index.js @@ -0,0 +1,3 @@ +import '@jupyterlab/filebrowser/style/index.js'; + +import './base.css'; diff --git a/packages/tree/tsconfig.json b/packages/tree/tsconfig.json new file mode 100644 index 0000000000..b223e1a1b8 --- /dev/null +++ b/packages/tree/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfigbase", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" + }, + "include": ["src/**/*"], + "references": [ + { + "path": "../application" + } + ] +} diff --git a/yarn.lock b/yarn.lock index 9e13785786..5a5af46fa9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From 5d6fdef55e110cf8c8d85db564af51526af1b4fa Mon Sep 17 00:00:00 2001 From: Nicolas Brichet <32258950+brichet@users.noreply.github.com> Date: Tue, 2 Aug 2022 10:25:09 +0200 Subject: [PATCH 2/5] Update packages/tree/package.json Remove trailing whitespace Co-authored-by: Jeremy Tuloup --- packages/tree/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tree/package.json b/packages/tree/package.json index 94298d3c1d..06419fb253 100644 --- a/packages/tree/package.json +++ b/packages/tree/package.json @@ -1,7 +1,7 @@ { "name": "@jupyter-notebook/tree", "version": "7.0.0-alpha.5", - "description": "Jupyter Notebook - Tree ", + "description": "Jupyter Notebook - Tree", "homepage": "https://github.com/jupyter/notebook", "bugs": { "url": "https://github.com/jupyter/notebook/issues" From 5a77a22207181526f0ffb925fdcf76f1f459f2f8 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Thu, 4 Aug 2022 13:48:54 +0200 Subject: [PATCH 3/5] Add some docstring --- packages/tree-extension/src/index.ts | 3 +-- packages/tree/src/notebook-tree.ts | 6 ++++++ packages/tree/src/token.ts | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index 4320e814b0..f9bcb80401 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -32,8 +32,7 @@ import { import { Menu, MenuBar } from '@lumino/widgets'; -import { NotebookTreeWidget } from '@jupyter-notebook/tree'; -import { INotebookTree } from '@jupyter-notebook/tree'; +import { NotebookTreeWidget, INotebookTree } from '@jupyter-notebook/tree'; /** * The file browser factory. diff --git a/packages/tree/src/notebook-tree.ts b/packages/tree/src/notebook-tree.ts index 85fd387c3a..28dad32c55 100644 --- a/packages/tree/src/notebook-tree.ts +++ b/packages/tree/src/notebook-tree.ts @@ -4,7 +4,13 @@ import { TabPanel } from '@lumino/widgets'; import { INotebookTree } from './token'; +/** + * The widget added in main area of the tree view. + */ export class NotebookTreeWidget extends TabPanel implements INotebookTree { + /** + * Constructor of the NotebookTreeWidget. + */ constructor() { super({ tabPlacement: 'top', diff --git a/packages/tree/src/token.ts b/packages/tree/src/token.ts index 7ae940953a..70342c9e7d 100644 --- a/packages/tree/src/token.ts +++ b/packages/tree/src/token.ts @@ -1,6 +1,9 @@ import { Token } from '@lumino/coreutils'; import { TabPanel } from '@lumino/widgets'; +/** + * The INotebookTree interface. + */ export interface INotebookTree extends TabPanel {} /** From 8feaee8afc93d993524a9fc0797d603c559a636c Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Thu, 4 Aug 2022 15:44:44 +0200 Subject: [PATCH 4/5] Fix toolbar not displayed in tree view --- packages/tree-extension/src/index.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index f9bcb80401..77d28ffe23 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -102,13 +102,7 @@ function activateNotebookTreeWidget( 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 nbTreeWidget = new NotebookTreeWidget(); const trans = translator.load('notebook'); @@ -118,8 +112,8 @@ function activateNotebookTreeWidget( browser.node.setAttribute('aria-label', trans.__('File Browser Section')); browser.title.icon = folderIcon; - notebookTreeWidget.addWidget(browser); - notebookTreeWidget.tabBar.addTab(browser.title); + nbTreeWidget.addWidget(browser); + nbTreeWidget.tabBar.addTab(browser.title); // Toolbar toolbarRegistry.addFactory( @@ -149,8 +143,8 @@ function activateNotebookTreeWidget( running.id = 'jp-running-sessions'; running.title.label = trans.__('Running'); running.title.icon = runningIcon; - notebookTreeWidget.addWidget(running); - notebookTreeWidget.tabBar.addTab(running.title); + nbTreeWidget.addWidget(running); + nbTreeWidget.tabBar.addTab(running.title); } // show checkboxes by default if there is no user setting override @@ -166,9 +160,9 @@ function activateNotebookTreeWidget( console.error(reason.message); }); - app.shell.add(notebookTreeWidget, 'main', { rank: 100 }); + app.shell.add(nbTreeWidget, 'main', { rank: 100 }); - return notebookTreeWidget; + return nbTreeWidget; } /** From 9ac98a6ddd6916d21a3e55f1bb1884d150dbed4f Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Thu, 4 Aug 2022 15:58:16 +0200 Subject: [PATCH 5/5] Code refctoring --- packages/tree-extension/src/index.ts | 142 +++++++++++++-------------- 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index 77d28ffe23..3c3aafd5ff 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -94,77 +94,6 @@ const createNew: JupyterFrontEndPlugin = { } }; -function activateNotebookTreeWidget( - app: JupyterFrontEnd, - factory: IFileBrowserFactory, - translator: ITranslator, - settingRegistry: ISettingRegistry, - toolbarRegistry: IToolbarWidgetRegistry, - manager: IRunningSessionManagers | null -): INotebookTree { - const nbTreeWidget = new NotebookTreeWidget(); - - 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; - - nbTreeWidget.addWidget(browser); - nbTreeWidget.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; - nbTreeWidget.addWidget(running); - nbTreeWidget.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(nbTreeWidget, 'main', { rank: 100 }); - - return nbTreeWidget; -} - /** * A plugin to add the file browser widget to an INotebookShell */ @@ -179,7 +108,76 @@ const notebookTreeWidget: JupyterFrontEndPlugin = { optional: [IRunningSessionManagers], autoStart: true, provides: INotebookTree, - activate: activateNotebookTreeWidget + activate: ( + app: JupyterFrontEnd, + factory: IFileBrowserFactory, + translator: ITranslator, + settingRegistry: ISettingRegistry, + toolbarRegistry: IToolbarWidgetRegistry, + manager: IRunningSessionManagers | null + ): INotebookTree => { + const nbTreeWidget = new NotebookTreeWidget(); + + 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; + + nbTreeWidget.addWidget(browser); + nbTreeWidget.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; + nbTreeWidget.addWidget(running); + nbTreeWidget.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(nbTreeWidget, 'main', { rank: 100 }); + + return nbTreeWidget; + } }; /**