From ea62d44f4c77fb4423fdd6dad9da34296473264f Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Thu, 9 May 2019 10:14:31 +0100 Subject: [PATCH 01/10] Docstring cleanup --- packages/application/src/shell.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index 9c7eead2548e..c27c848c8d2f 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -61,7 +61,7 @@ const ACTIVITY_CLASS = 'jp-Activity'; /* tslint:disable */ /** - * The layout restorer token. + * The JupyterLab application shell token. */ export const ILabShell = new Token( '@jupyterlab/application:ILabShell' @@ -69,7 +69,7 @@ export const ILabShell = new Token( /* tslint:enable */ /** - * The JupyterLab application shell. + * The JupyterLab application shell interface. */ export interface ILabShell extends LabShell {} From 559fca0852d3cc83acf5bf5e7973f75463b16065 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:44:25 +0100 Subject: [PATCH 02/10] Simple token refactors --- packages/codeeditor/src/index.ts | 31 +-- packages/codeeditor/src/tokens.ts | 32 +++ packages/codemirror-extension/src/index.ts | 5 +- packages/codemirror/src/index.ts | 2 +- packages/completer-extension/src/index.ts | 4 +- packages/completer/src/index.ts | 67 +---- packages/completer/src/tokens.ts | 69 ++++++ packages/console-extension/src/index.ts | 4 +- packages/console/src/index.ts | 3 +- .../console/src/{tracker.ts => tokens.ts} | 0 packages/csvviewer-extension/src/index.ts | 2 +- packages/docmanager/src/index.ts | 1 + packages/docmanager/src/manager.ts | 20 +- packages/docmanager/src/pathstatus.tsx | 2 +- packages/docmanager/src/savingstatus.tsx | 2 +- packages/docmanager/src/tokens.ts | 231 ++++++++++++++++++ packages/documentsearch/src/index.ts | 1 + .../src/searchproviderregistry.ts | 36 +-- packages/documentsearch/src/tokens.ts | 41 ++++ packages/filebrowser-extension/src/index.ts | 2 +- packages/filebrowser/src/browser.ts | 4 +- packages/filebrowser/src/index.ts | 2 +- .../filebrowser/src/{factory.ts => tokens.ts} | 0 packages/fileeditor-extension/src/index.ts | 8 +- packages/fileeditor/src/index.ts | 27 +- packages/fileeditor/src/tokens.ts | 25 ++ packages/imageviewer/src/index.ts | 24 +- packages/imageviewer/src/tokens.ts | 25 ++ packages/inspector-extension/src/index.ts | 2 +- packages/inspector/src/handler.ts | 2 +- packages/inspector/src/index.ts | 1 + packages/inspector/src/inspector.ts | 74 +----- packages/inspector/src/tokens.ts | 76 ++++++ packages/mainmenu-extension/src/index.ts | 2 +- packages/markdownviewer/src/index.ts | 20 +- packages/markdownviewer/src/tokens.ts | 21 ++ packages/notebook-extension/src/index.ts | 8 +- packages/rendermime-extension/src/index.ts | 4 +- packages/rendermime/src/index.ts | 1 + packages/rendermime/src/registry.ts | 53 +--- packages/rendermime/src/tokens.ts | 187 ++++++++++++++ packages/settingeditor-extension/src/index.ts | 2 +- packages/settingeditor/src/index.ts | 22 +- packages/settingeditor/src/tokens.ts | 23 ++ packages/statusbar-extension/src/index.ts | 11 +- packages/statusbar/src/index.ts | 1 + packages/statusbar/src/statusbar.ts | 64 +---- packages/statusbar/src/tokens.ts | 70 ++++++ packages/terminal-extension/src/index.ts | 5 +- packages/terminal/src/index.ts | 4 +- .../terminal/src/{constants.ts => tokens.ts} | 2 - packages/tooltip-extension/src/index.ts | 4 +- packages/tooltip/src/index.ts | 60 +---- packages/tooltip/src/tokens.ts | 61 +++++ 54 files changed, 930 insertions(+), 520 deletions(-) create mode 100644 packages/codeeditor/src/tokens.ts create mode 100644 packages/completer/src/tokens.ts rename packages/console/src/{tracker.ts => tokens.ts} (100%) create mode 100644 packages/docmanager/src/tokens.ts create mode 100644 packages/documentsearch/src/tokens.ts rename packages/filebrowser/src/{factory.ts => tokens.ts} (100%) create mode 100644 packages/fileeditor/src/tokens.ts create mode 100644 packages/imageviewer/src/tokens.ts create mode 100644 packages/inspector/src/tokens.ts create mode 100644 packages/markdownviewer/src/tokens.ts create mode 100644 packages/rendermime/src/tokens.ts create mode 100644 packages/settingeditor/src/tokens.ts create mode 100644 packages/statusbar/src/tokens.ts rename packages/terminal/src/{constants.ts => tokens.ts} (98%) create mode 100644 packages/tooltip/src/tokens.ts diff --git a/packages/codeeditor/src/index.ts b/packages/codeeditor/src/index.ts index 548fd96c463b..9856e4dd637d 100644 --- a/packages/codeeditor/src/index.ts +++ b/packages/codeeditor/src/index.ts @@ -1,12 +1,6 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { Token } from '@phosphor/coreutils'; - -import { IEditorFactoryService } from './factory'; - -import { IEditorMimeTypeService } from './mimetype'; - import '../style/index.css'; export * from './editor'; @@ -14,27 +8,4 @@ export * from './jsoneditor'; export * from './widget'; export * from './factory'; export * from './mimetype'; - -/* tslint:disable */ -/** - * Code editor services token. - */ -export const IEditorServices = new Token( - '@jupyterlab/codeeditor:IEditorServices' -); -/* tslint:enable */ - -/** - * Code editor services. - */ -export interface IEditorServices { - /** - * The code editor factory. - */ - readonly factoryService: IEditorFactoryService; - - /** - * The editor mime type service. - */ - readonly mimeTypeService: IEditorMimeTypeService; -} +export * from './tokens'; diff --git a/packages/codeeditor/src/tokens.ts b/packages/codeeditor/src/tokens.ts new file mode 100644 index 000000000000..a80e991fe7df --- /dev/null +++ b/packages/codeeditor/src/tokens.ts @@ -0,0 +1,32 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; + +import { IEditorFactoryService } from './factory'; + +import { IEditorMimeTypeService } from './mimetype'; + +/* tslint:disable */ +/** + * Code editor services token. + */ +export const IEditorServices = new Token( + '@jupyterlab/codeeditor:IEditorServices' +); +/* tslint:enable */ + +/** + * Code editor services. + */ +export interface IEditorServices { + /** + * The code editor factory. + */ + readonly factoryService: IEditorFactoryService; + + /** + * The editor mime type service. + */ + readonly mimeTypeService: IEditorMimeTypeService; +} diff --git a/packages/codemirror-extension/src/index.ts b/packages/codemirror-extension/src/index.ts index 5a89de742162..d3bdee579886 100644 --- a/packages/codemirror-extension/src/index.ts +++ b/packages/codemirror-extension/src/index.ts @@ -13,7 +13,7 @@ import { import { IMainMenu, IEditMenu } from '@jupyterlab/mainmenu'; -import { IEditorServices } from '@jupyterlab/codeeditor'; +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; import { editorServices, @@ -26,7 +26,8 @@ import { ISettingRegistry } from '@jupyterlab/coreutils'; import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { IEditorTracker, FileEditor } from '@jupyterlab/fileeditor'; +import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; +import { FileEditor } from '@jupyterlab/fileeditor'; import { IStatusBar } from '@jupyterlab/statusbar'; diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts index c2ac7d3faf79..7194fc92caba 100644 --- a/packages/codemirror/src/index.ts +++ b/packages/codemirror/src/index.ts @@ -1,7 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IEditorServices } from '@jupyterlab/codeeditor'; +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; import { CodeMirrorEditorFactory } from './factory'; diff --git a/packages/completer-extension/src/index.ts b/packages/completer-extension/src/index.ts index f29b4b41c138..46d9b8fcb654 100644 --- a/packages/completer-extension/src/index.ts +++ b/packages/completer-extension/src/index.ts @@ -15,9 +15,9 @@ import { ICompletionManager } from '@jupyterlab/completer'; -import { IConsoleTracker } from '@jupyterlab/console'; +import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; -import { IEditorTracker } from '@jupyterlab/fileeditor'; +import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; import { INotebookTracker } from '@jupyterlab/notebook'; diff --git a/packages/completer/src/index.ts b/packages/completer/src/index.ts index 886f42d71da1..40361219eba4 100644 --- a/packages/completer/src/index.ts +++ b/packages/completer/src/index.ts @@ -1,16 +1,6 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { CodeEditor } from '@jupyterlab/codeeditor'; - -import { IDataConnector } from '@jupyterlab/coreutils'; - -import { Token } from '@phosphor/coreutils'; - -import { Widget } from '@phosphor/widgets'; - -import { CompletionHandler } from './handler'; - import '../style/index.css'; export * from './handler'; @@ -20,59 +10,4 @@ export * from './connector'; export * from './model'; export * from './widget'; -/* tslint:disable */ -/** - * The completion manager token. - */ -export const ICompletionManager = new Token( - '@jupyterlab/completer:ICompletionManager' -); -/* tslint:enable */ - -/** - * A manager to register completers with parent widgets. - */ -export interface ICompletionManager { - /** - * Register a completable object with the completion manager. - * - * @returns A completable object whose attributes can be updated as necessary. - */ - register( - completable: ICompletionManager.ICompletable - ): ICompletionManager.ICompletableAttributes; -} - -/** - * A namespace for `ICompletionManager` interface specifications. - */ -export namespace ICompletionManager { - /** - * The attributes of a completable object that can change and sync at runtime. - */ - export interface ICompletableAttributes { - /** - * The host editor for the completer. - */ - editor: CodeEditor.IEditor | null; - - /** - * The data connector used to populate the completer. - */ - connector: IDataConnector< - CompletionHandler.IReply, - void, - CompletionHandler.IRequest - >; - } - - /** - * An interface for completer-compatible objects. - */ - export interface ICompletable extends ICompletableAttributes { - /** - * The parent of the completer; the completer resources dispose with parent. - */ - readonly parent: Widget; - } -} +export * from './tokens'; diff --git a/packages/completer/src/tokens.ts b/packages/completer/src/tokens.ts new file mode 100644 index 000000000000..9d3e9f79f86e --- /dev/null +++ b/packages/completer/src/tokens.ts @@ -0,0 +1,69 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { CodeEditor } from '@jupyterlab/codeeditor'; + +import { IDataConnector } from '@jupyterlab/coreutils'; + +import { Token } from '@phosphor/coreutils'; + +import { Widget } from '@phosphor/widgets'; + +import { CompletionHandler } from './handler'; + +/* tslint:disable */ +/** + * The completion manager token. + */ +export const ICompletionManager = new Token( + '@jupyterlab/completer:ICompletionManager' +); +/* tslint:enable */ + +/** + * A manager to register completers with parent widgets. + */ +export interface ICompletionManager { + /** + * Register a completable object with the completion manager. + * + * @returns A completable object whose attributes can be updated as necessary. + */ + register( + completable: ICompletionManager.ICompletable + ): ICompletionManager.ICompletableAttributes; +} + +/** + * A namespace for `ICompletionManager` interface specifications. + */ +export namespace ICompletionManager { + /** + * The attributes of a completable object that can change and sync at runtime. + */ + export interface ICompletableAttributes { + /** + * The host editor for the completer. + */ + editor: CodeEditor.IEditor | null; + + /** + * The data connector used to populate the completer. + */ + connector: IDataConnector< + CompletionHandler.IReply, + void, + CompletionHandler.IRequest + >; + } + + /** + * An interface for completer-compatible objects. + */ + export interface ICompletable extends ICompletableAttributes { + /** + * The parent of the completer; the completer resources dispose with parent. + */ + readonly parent: Widget; + } +} diff --git a/packages/console-extension/src/index.ts b/packages/console-extension/src/index.ts index 07852e9050d1..64b0e56d5f66 100644 --- a/packages/console-extension/src/index.ts +++ b/packages/console-extension/src/index.ts @@ -16,13 +16,13 @@ import { showDialog } from '@jupyterlab/apputils'; -import { IEditorServices } from '@jupyterlab/codeeditor'; +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console'; import { ISettingRegistry, PageConfig } from '@jupyterlab/coreutils'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; import { ILauncher } from '@jupyterlab/launcher'; diff --git a/packages/console/src/index.ts b/packages/console/src/index.ts index c2a761778c11..b49c8dd92863 100644 --- a/packages/console/src/index.ts +++ b/packages/console/src/index.ts @@ -6,5 +6,6 @@ import '../style/index.css'; export * from './foreign'; export * from './history'; export * from './panel'; -export * from './tracker'; export * from './widget'; + +export * from './tokens'; diff --git a/packages/console/src/tracker.ts b/packages/console/src/tokens.ts similarity index 100% rename from packages/console/src/tracker.ts rename to packages/console/src/tokens.ts diff --git a/packages/csvviewer-extension/src/index.ts b/packages/csvviewer-extension/src/index.ts index 5af7e932f9e0..8d97ce9b53c5 100644 --- a/packages/csvviewer-extension/src/index.ts +++ b/packages/csvviewer-extension/src/index.ts @@ -9,7 +9,7 @@ import { import { InstanceTracker, IThemeManager, Dialog } from '@jupyterlab/apputils'; -import { ISearchProviderRegistry } from '@jupyterlab/documentsearch'; +import { ISearchProviderRegistry } from '@jupyterlab/documentsearch/lib/tokens'; import { CSVViewer, diff --git a/packages/docmanager/src/index.ts b/packages/docmanager/src/index.ts index 8ca8c4044e55..40445eba2e55 100644 --- a/packages/docmanager/src/index.ts +++ b/packages/docmanager/src/index.ts @@ -2,6 +2,7 @@ // Distributed under the terms of the Modified BSD License. export * from './dialogs'; +export * from './tokens'; export * from './manager'; export * from './savehandler'; export * from './savingstatus'; diff --git a/packages/docmanager/src/manager.ts b/packages/docmanager/src/manager.ts index 82d47fbde02e..b34f6de43939 100644 --- a/packages/docmanager/src/manager.ts +++ b/packages/docmanager/src/manager.ts @@ -17,8 +17,6 @@ import { Contents, Kernel, ServiceManager } from '@jupyterlab/services'; import { ArrayExt, find } from '@phosphor/algorithm'; -import { Token } from '@phosphor/coreutils'; - import { IDisposable } from '@phosphor/disposable'; import { AttachedProperty } from '@phosphor/properties'; @@ -29,21 +27,9 @@ import { Widget } from '@phosphor/widgets'; import { SaveHandler } from './savehandler'; -import { DocumentWidgetManager } from './widgetmanager'; - -/* tslint:disable */ -/** - * The document registry token. - */ -export const IDocumentManager = new Token( - '@jupyterlab/docmanager:IDocumentManager' -); -/* tslint:enable */ +import { IDocumentManager } from './tokens'; -/** - * The interface for a document manager. - */ -export interface IDocumentManager extends DocumentManager {} +import { DocumentWidgetManager } from './widgetmanager'; /** * The document manager. @@ -55,7 +41,7 @@ export interface IDocumentManager extends DocumentManager {} * open, and a list of widgets for each context. The document manager is in * control of the proper closing and disposal of the widgets and contexts. */ -export class DocumentManager implements IDisposable { +export class DocumentManager implements IDocumentManager { /** * Construct a new document manager. */ diff --git a/packages/docmanager/src/pathstatus.tsx b/packages/docmanager/src/pathstatus.tsx index 4c0c7e7f9603..9be33563ef07 100644 --- a/packages/docmanager/src/pathstatus.tsx +++ b/packages/docmanager/src/pathstatus.tsx @@ -7,7 +7,7 @@ import { VDomModel, VDomRenderer } from '@jupyterlab/apputils'; import { PathExt } from '@jupyterlab/coreutils'; -import { IDocumentManager } from './manager'; +import { IDocumentManager } from './tokens'; import { DocumentRegistry } from '@jupyterlab/docregistry'; diff --git a/packages/docmanager/src/savingstatus.tsx b/packages/docmanager/src/savingstatus.tsx index e62a952bbc08..bb78be4d7da0 100644 --- a/packages/docmanager/src/savingstatus.tsx +++ b/packages/docmanager/src/savingstatus.tsx @@ -5,7 +5,7 @@ import React from 'react'; import { VDomModel, VDomRenderer } from '@jupyterlab/apputils'; -import { IDocumentManager } from './manager'; +import { IDocumentManager } from './tokens'; import { DocumentRegistry } from '@jupyterlab/docregistry'; diff --git a/packages/docmanager/src/tokens.ts b/packages/docmanager/src/tokens.ts new file mode 100644 index 000000000000..cbeebf0a23e6 --- /dev/null +++ b/packages/docmanager/src/tokens.ts @@ -0,0 +1,231 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; + +import { IDisposable } from '@phosphor/disposable'; + +import { ISignal } from '@phosphor/signaling'; + +import { Widget } from '@phosphor/widgets'; + +import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; + +import { Contents, Kernel, ServiceManager } from '@jupyterlab/services'; + +/* tslint:disable */ +/** + * The document registry token. + */ +export const IDocumentManager = new Token( + '@jupyterlab/docmanager:IDocumentManager' +); +/* tslint:enable */ + +/** + * The interface for a document manager. + */ +export interface IDocumentManager extends IDisposable { + /** + * The registry used by the manager. + */ + readonly registry: DocumentRegistry; + + /** + * The service manager used by the manager. + */ + readonly services: ServiceManager.IManager; + + /** + * A signal emitted when one of the documents is activated. + */ + readonly activateRequested: ISignal; + + /** + * Whether to autosave documents. + */ + autosave: boolean; + + /** + * Determines the time interval for autosave in seconds. + */ + autosaveInterval: number; + + /** + * Clone a widget. + * + * @param widget - The source widget. + * + * @returns A new widget or `undefined`. + * + * #### Notes + * Uses the same widget factory and context as the source, or returns + * `undefined` if the source widget is not managed by this manager. + */ + cloneWidget(widget: Widget): IDocumentWidget | undefined; + + /** + * Close all of the open documents. + * + * @returns A promise resolving when the widgets are closed. + */ + closeAll(): Promise; + + /** + * Close the widgets associated with a given path. + * + * @param path - The target path. + * + * @returns A promise resolving when the widgets are closed. + */ + closeFile(path: string): Promise; + + /** + * Get the document context for a widget. + * + * @param widget - The widget of interest. + * + * @returns The context associated with the widget, or `undefined` if no such + * context exists. + */ + contextForWidget(widget: Widget): DocumentRegistry.Context | undefined; + + /** + * Copy a file. + * + * @param fromFile - The full path of the original file. + * + * @param toDir - The full path to the target directory. + * + * @returns A promise which resolves to the contents of the file. + */ + copy(fromFile: string, toDir: string): Promise; + + /** + * Create a new file and return the widget used to view it. + * + * @param path - The file path to create. + * + * @param widgetName - The name of the widget factory to use. 'default' will use the default widget. + * + * @param kernel - An optional kernel name/id to override the default. + * + * @returns The created widget, or `undefined`. + * + * #### Notes + * This function will return `undefined` if a valid widget factory + * cannot be found. + */ + createNew( + path: string, + widgetName?: string, + kernel?: Partial + ): Widget; + + /** + * Delete a file. + * + * @param path - The full path to the file to be deleted. + * + * @returns A promise which resolves when the file is deleted. + * + * #### Notes + * If there is a running session associated with the file and no other + * sessions are using the kernel, the session will be shut down. + */ + deleteFile(path: string): Promise; + + /** + * See if a widget already exists for the given path and widget name. + * + * @param path - The file path to use. + * + * @param widgetName - The name of the widget factory to use. 'default' will use the default widget. + * + * @returns The found widget, or `undefined`. + * + * #### Notes + * This can be used to find an existing widget instead of opening + * a new widget. + */ + findWidget( + path: string, + widgetName?: string | null + ): IDocumentWidget | undefined; + + /** + * Create a new untitled file. + * + * @param options - The file content creation options. + */ + newUntitled(options: Contents.ICreateOptions): Promise; + + /** + * Open a file and return the widget used to view it. + * + * @param path - The file path to open. + * + * @param widgetName - The name of the widget factory to use. 'default' will use the default widget. + * + * @param kernel - An optional kernel name/id to override the default. + * + * @returns The created widget, or `undefined`. + * + * #### Notes + * This function will return `undefined` if a valid widget factory + * cannot be found. + */ + open( + path: string, + widgetName?: string, + kernel?: Partial, + options?: DocumentRegistry.IOpenOptions + ): IDocumentWidget | undefined; + + /** + * Open a file and return the widget used to view it. + * Reveals an already existing editor. + * + * @param path - The file path to open. + * + * @param widgetName - The name of the widget factory to use. 'default' will use the default widget. + * + * @param kernel - An optional kernel name/id to override the default. + * + * @returns The created widget, or `undefined`. + * + * #### Notes + * This function will return `undefined` if a valid widget factory + * cannot be found. + */ + openOrReveal( + path: string, + widgetName?: string, + kernel?: Partial, + options?: DocumentRegistry.IOpenOptions + ): IDocumentWidget | undefined; + + /** + * Overwrite a file. + * + * @param oldPath - The full path to the original file. + * + * @param newPath - The full path to the new file. + * + * @returns A promise containing the new file contents model. + */ + overwrite(oldPath: string, newPath: string): Promise; + + /** + * Rename a file or directory. + * + * @param oldPath - The full path to the original file. + * + * @param newPath - The full path to the new file. + * + * @returns A promise containing the new file contents model. The promise + * will reject if the newPath already exists. Use [[overwrite]] to overwrite + * a file. + */ + rename(oldPath: string, newPath: string): Promise; +} diff --git a/packages/documentsearch/src/index.ts b/packages/documentsearch/src/index.ts index bf11d9c094e1..781f987cf155 100644 --- a/packages/documentsearch/src/index.ts +++ b/packages/documentsearch/src/index.ts @@ -6,5 +6,6 @@ import '../style/index.css'; export * from './interfaces'; export * from './searchinstance'; export * from './searchproviderregistry'; +export * from './tokens'; export * from './providers/codemirrorsearchprovider'; export * from './providers/notebooksearchprovider'; diff --git a/packages/documentsearch/src/searchproviderregistry.ts b/packages/documentsearch/src/searchproviderregistry.ts index e35c24798781..a770080873b7 100644 --- a/packages/documentsearch/src/searchproviderregistry.ts +++ b/packages/documentsearch/src/searchproviderregistry.ts @@ -1,45 +1,13 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. + import { ISearchProvider, ISearchProviderConstructor } from './interfaces'; +import { ISearchProviderRegistry } from './tokens'; -import { Token } from '@phosphor/coreutils'; import { Widget } from '@phosphor/widgets'; import { IDisposable, DisposableDelegate } from '@phosphor/disposable'; import { ISignal, Signal } from '@phosphor/signaling'; -/* tslint:disable */ -/** - * The search provider registry token. - */ -export const ISearchProviderRegistry = new Token( - '@jupyterlab/documentsearch:ISearchProviderRegistry' -); -/* tslint:enable */ - -export interface ISearchProviderRegistry { - /** - * Add a provider to the registry. - * - * @param key - The provider key. - * @returns A disposable delegate that, when disposed, deregisters the given search provider - */ - register(key: string, provider: ISearchProviderConstructor): IDisposable; - - /** - * Returns a matching provider for the widget. - * - * @param widget - The widget to search over. - * @returns the search provider, or undefined if none exists. - */ - getProviderForWidget(widget: any): ISearchProvider | undefined; - - /** - * Signal that emits when a new search provider has been registered - * or removed. - */ - changed: ISignal; -} - export class SearchProviderRegistry implements ISearchProviderRegistry { /** * Add a provider to the registry. diff --git a/packages/documentsearch/src/tokens.ts b/packages/documentsearch/src/tokens.ts new file mode 100644 index 000000000000..71d1a9e96c2e --- /dev/null +++ b/packages/documentsearch/src/tokens.ts @@ -0,0 +1,41 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; +import { IDisposable } from '@phosphor/disposable'; +import { ISignal } from '@phosphor/signaling'; + +import { ISearchProvider, ISearchProviderConstructor } from './interfaces'; + +/* tslint:disable */ +/** + * The search provider registry token. + */ +export const ISearchProviderRegistry = new Token( + '@jupyterlab/documentsearch:ISearchProviderRegistry' +); +/* tslint:enable */ + +export interface ISearchProviderRegistry { + /** + * Add a provider to the registry. + * + * @param key - The provider key. + * @returns A disposable delegate that, when disposed, deregisters the given search provider + */ + register(key: string, provider: ISearchProviderConstructor): IDisposable; + + /** + * Returns a matching provider for the widget. + * + * @param widget - The widget to search over. + * @returns the search provider, or undefined if none exists. + */ + getProviderForWidget(widget: any): ISearchProvider | undefined; + + /** + * Signal that emits when a new search provider has been registered + * or removed. + */ + changed: ISignal; +} diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index 0e90fdac8bf8..e4fc3087c424 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -24,7 +24,7 @@ import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { IDocumentManager } from '@jupyterlab/docmanager'; +import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; import { FileBrowserModel, diff --git a/packages/filebrowser/src/browser.ts b/packages/filebrowser/src/browser.ts index 63937b87e07b..a67b2455ff79 100644 --- a/packages/filebrowser/src/browser.ts +++ b/packages/filebrowser/src/browser.ts @@ -3,7 +3,7 @@ import { showErrorMessage, Toolbar, ToolbarButton } from '@jupyterlab/apputils'; -import { DocumentManager } from '@jupyterlab/docmanager'; +import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; import { Contents, ServerConnection } from '@jupyterlab/services'; @@ -272,7 +272,7 @@ export class FileBrowser extends Widget { private _crumbs: BreadCrumbs; private _listing: DirListing; - private _manager: DocumentManager; + private _manager: IDocumentManager; private _showingError = false; private _directoryPending: boolean; } diff --git a/packages/filebrowser/src/index.ts b/packages/filebrowser/src/index.ts index 135873305c05..665fc67300e5 100644 --- a/packages/filebrowser/src/index.ts +++ b/packages/filebrowser/src/index.ts @@ -5,7 +5,7 @@ import '../style/index.css'; export * from './browser'; export * from './crumbs'; -export * from './factory'; +export * from './tokens'; export * from './listing'; export * from './model'; export * from './upload'; diff --git a/packages/filebrowser/src/factory.ts b/packages/filebrowser/src/tokens.ts similarity index 100% rename from packages/filebrowser/src/factory.ts rename to packages/filebrowser/src/tokens.ts diff --git a/packages/fileeditor-extension/src/index.ts b/packages/fileeditor-extension/src/index.ts index a2e49021fa94..24eeee47e19c 100644 --- a/packages/fileeditor-extension/src/index.ts +++ b/packages/fileeditor-extension/src/index.ts @@ -9,9 +9,11 @@ import { import { ICommandPalette, InstanceTracker } from '@jupyterlab/apputils'; -import { CodeEditor, IEditorServices } from '@jupyterlab/codeeditor'; +import { CodeEditor } from '@jupyterlab/codeeditor/lib/editor'; -import { IConsoleTracker } from '@jupyterlab/console'; +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; + +import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; import { ISettingRegistry, @@ -21,7 +23,7 @@ import { import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; import { FileEditor, diff --git a/packages/fileeditor/src/index.ts b/packages/fileeditor/src/index.ts index b3a7530c7e10..c5d9ad3c742c 100644 --- a/packages/fileeditor/src/index.ts +++ b/packages/fileeditor/src/index.ts @@ -1,31 +1,8 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IInstanceTracker } from '@jupyterlab/apputils'; - -import { IDocumentWidget } from '@jupyterlab/docregistry'; - -import { Token } from '@phosphor/coreutils'; - -import { FileEditor } from './widget'; - import '../style/index.css'; -export * from './widget'; - +export * from './tokens'; export * from './tabspacestatus'; - -/** - * A class that tracks editor widgets. - */ -export interface IEditorTracker - extends IInstanceTracker> {} - -/* tslint:disable */ -/** - * The editor tracker token. - */ -export const IEditorTracker = new Token( - '@jupyterlab/fileeditor:IEditorTracker' -); -/* tslint:enable */ +export * from './widget'; diff --git a/packages/fileeditor/src/tokens.ts b/packages/fileeditor/src/tokens.ts new file mode 100644 index 000000000000..a494160af1ad --- /dev/null +++ b/packages/fileeditor/src/tokens.ts @@ -0,0 +1,25 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { IInstanceTracker } from '@jupyterlab/apputils'; + +import { IDocumentWidget } from '@jupyterlab/docregistry'; + +import { Token } from '@phosphor/coreutils'; + +import { FileEditor } from './widget'; + +/** + * A class that tracks editor widgets. + */ +export interface IEditorTracker + extends IInstanceTracker> {} + +/* tslint:disable */ +/** + * The editor tracker token. + */ +export const IEditorTracker = new Token( + '@jupyterlab/fileeditor:IEditorTracker' +); +/* tslint:enable */ diff --git a/packages/imageviewer/src/index.ts b/packages/imageviewer/src/index.ts index f35847223d1e..dfc065d72e56 100644 --- a/packages/imageviewer/src/index.ts +++ b/packages/imageviewer/src/index.ts @@ -1,29 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IInstanceTracker } from '@jupyterlab/apputils'; - -import { IDocumentWidget } from '@jupyterlab/docregistry'; - -import { Token } from '@phosphor/coreutils'; - -import { ImageViewer } from './widget'; - import '../style/index.css'; +export * from './tokens'; export * from './widget'; - -/** - * A class that tracks editor widgets. - */ -export interface IImageTracker - extends IInstanceTracker> {} - -/* tslint:disable */ -/** - * The editor tracker token. - */ -export const IImageTracker = new Token( - '@jupyterlab/imageviewer:IImageTracker' -); -/* tslint:enable */ diff --git a/packages/imageviewer/src/tokens.ts b/packages/imageviewer/src/tokens.ts new file mode 100644 index 000000000000..00c0005e854d --- /dev/null +++ b/packages/imageviewer/src/tokens.ts @@ -0,0 +1,25 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { IInstanceTracker } from '@jupyterlab/apputils'; + +import { IDocumentWidget } from '@jupyterlab/docregistry'; + +import { Token } from '@phosphor/coreutils'; + +import { ImageViewer } from './widget'; + +/** + * A class that tracks editor widgets. + */ +export interface IImageTracker + extends IInstanceTracker> {} + +/* tslint:disable */ +/** + * The editor tracker token. + */ +export const IImageTracker = new Token( + '@jupyterlab/imageviewer:IImageTracker' +); +/* tslint:enable */ diff --git a/packages/inspector-extension/src/index.ts b/packages/inspector-extension/src/index.ts index 9b92a574ceab..a6f31723f114 100644 --- a/packages/inspector-extension/src/index.ts +++ b/packages/inspector-extension/src/index.ts @@ -14,7 +14,7 @@ import { MainAreaWidget } from '@jupyterlab/apputils'; -import { IConsoleTracker } from '@jupyterlab/console'; +import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; import { IInspector, diff --git a/packages/inspector/src/handler.ts b/packages/inspector/src/handler.ts index 0f01fdf9c865..e23ab435fd9e 100644 --- a/packages/inspector/src/handler.ts +++ b/packages/inspector/src/handler.ts @@ -13,7 +13,7 @@ import { IDisposable } from '@phosphor/disposable'; import { ISignal, Signal } from '@phosphor/signaling'; -import { IInspector } from './inspector'; +import { IInspector } from './tokens'; /** * An object that handles code inspection. diff --git a/packages/inspector/src/index.ts b/packages/inspector/src/index.ts index e427547f8f10..03bfe131b722 100644 --- a/packages/inspector/src/index.ts +++ b/packages/inspector/src/index.ts @@ -6,3 +6,4 @@ import '../style/index.css'; export * from './handler'; export * from './inspector'; export * from './kernelconnector'; +export * from './tokens'; diff --git a/packages/inspector/src/inspector.ts b/packages/inspector/src/inspector.ts index 70a7ebffd6ac..37008f9099ba 100644 --- a/packages/inspector/src/inspector.ts +++ b/packages/inspector/src/inspector.ts @@ -3,12 +3,10 @@ import { Printing } from '@jupyterlab/apputils'; -import { Token } from '@phosphor/coreutils'; - -import { ISignal } from '@phosphor/signaling'; - import { Panel, PanelLayout, Widget } from '@phosphor/widgets'; +import { IInspector } from './tokens'; + /** * The class name added to inspector panels. */ @@ -19,74 +17,6 @@ const PANEL_CLASS = 'jp-Inspector'; */ const CONTENT_CLASS = 'jp-Inspector-content'; -/* tslint:disable */ -/** - * The inspector panel token. - */ -export const IInspector = new Token( - '@jupyterlab/inspector:IInspector' -); -/* tslint:enable */ - -/** - * An interface for an inspector. - */ -export interface IInspector { - /** - * The source of events the inspector listens for. - */ - source: IInspector.IInspectable | null; -} - -/** - * A namespace for inspector interfaces. - */ -export namespace IInspector { - /** - * The definition of an inspectable source. - */ - export interface IInspectable { - /** - * A signal emitted when the inspector should clear all items. - */ - cleared: ISignal; - - /** - * A signal emitted when the inspectable is disposed. - */ - disposed: ISignal; - - /** - * A signal emitted when an inspector value is generated. - */ - inspected: ISignal; - - /** - * Test whether the inspectable has been disposed. - */ - isDisposed: boolean; - - /** - * Indicates whether the inspectable source emits signals. - * - * #### Notes - * The use case for this attribute is to limit the API traffic when no - * inspector is visible. It can be modified by the consumer of the source. - */ - standby: boolean; - } - - /** - * An update value for code inspectors. - */ - export interface IInspectorUpdate { - /** - * The content being sent to the inspector for display. - */ - content: Widget | null; - } -} - /** * A panel which contains a set of inspectors. */ diff --git a/packages/inspector/src/tokens.ts b/packages/inspector/src/tokens.ts new file mode 100644 index 000000000000..fe77a226762b --- /dev/null +++ b/packages/inspector/src/tokens.ts @@ -0,0 +1,76 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; + +import { ISignal } from '@phosphor/signaling'; + +import { Widget } from '@phosphor/widgets'; + +/* tslint:disable */ +/** + * The inspector panel token. + */ +export const IInspector = new Token( + '@jupyterlab/inspector:IInspector' +); +/* tslint:enable */ + +/** + * An interface for an inspector. + */ +export interface IInspector { + /** + * The source of events the inspector listens for. + */ + source: IInspector.IInspectable | null; +} + +/** + * A namespace for inspector interfaces. + */ +export namespace IInspector { + /** + * The definition of an inspectable source. + */ + export interface IInspectable { + /** + * A signal emitted when the inspector should clear all items. + */ + cleared: ISignal; + + /** + * A signal emitted when the inspectable is disposed. + */ + disposed: ISignal; + + /** + * A signal emitted when an inspector value is generated. + */ + inspected: ISignal; + + /** + * Test whether the inspectable has been disposed. + */ + isDisposed: boolean; + + /** + * Indicates whether the inspectable source emits signals. + * + * #### Notes + * The use case for this attribute is to limit the API traffic when no + * inspector is visible. It can be modified by the consumer of the source. + */ + standby: boolean; + } + + /** + * An update value for code inspectors. + */ + export interface IInspectorUpdate { + /** + * The content being sent to the inspector for display. + */ + content: Widget | null; + } +} diff --git a/packages/mainmenu-extension/src/index.ts b/packages/mainmenu-extension/src/index.ts index 34fef724b4c0..8443b275875f 100644 --- a/packages/mainmenu-extension/src/index.ts +++ b/packages/mainmenu-extension/src/index.ts @@ -18,7 +18,7 @@ import { ICommandPalette, showDialog, Dialog } from '@jupyterlab/apputils'; import { PageConfig, URLExt } from '@jupyterlab/coreutils'; -import { IInspector } from '@jupyterlab/inspector'; +import { IInspector } from '@jupyterlab/inspector/lib/tokens'; import { IMainMenu, diff --git a/packages/markdownviewer/src/index.ts b/packages/markdownviewer/src/index.ts index cd18f6f1dd56..dfc065d72e56 100644 --- a/packages/markdownviewer/src/index.ts +++ b/packages/markdownviewer/src/index.ts @@ -1,25 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IInstanceTracker } from '@jupyterlab/apputils'; - -import { Token } from '@phosphor/coreutils'; - -import { MarkdownDocument } from './widget'; - import '../style/index.css'; +export * from './tokens'; export * from './widget'; - -/** - * A class that tracks markdown viewer widgets. - */ -export interface IMarkdownViewerTracker - extends IInstanceTracker {} - -/** - * The markdownviewer tracker token. - */ -export const IMarkdownViewerTracker = new Token( - '@jupyterlab/markdownviewer:IMarkdownViewerTracker' -); diff --git a/packages/markdownviewer/src/tokens.ts b/packages/markdownviewer/src/tokens.ts new file mode 100644 index 000000000000..50d1f3f4f11c --- /dev/null +++ b/packages/markdownviewer/src/tokens.ts @@ -0,0 +1,21 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { IInstanceTracker } from '@jupyterlab/apputils'; + +import { Token } from '@phosphor/coreutils'; + +import { MarkdownDocument } from './widget'; + +/** + * The markdownviewer tracker token. + */ +export const IMarkdownViewerTracker = new Token( + '@jupyterlab/markdownviewer:IMarkdownViewerTracker' +); + +/** + * A class that tracks markdown viewer widgets. + */ +export interface IMarkdownViewerTracker + extends IInstanceTracker {} diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 700a839ddb0e..08d9bf1d7ebb 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -18,7 +18,9 @@ import { import { CodeCell } from '@jupyterlab/cells'; -import { CodeEditor, IEditorServices } from '@jupyterlab/codeeditor'; +import { CodeEditor } from '@jupyterlab/codeeditor/lib/editor'; + +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; import { ISettingRegistry, @@ -27,7 +29,7 @@ import { PageConfig } from '@jupyterlab/coreutils'; -import { IDocumentManager } from '@jupyterlab/docmanager'; +import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; import { ArrayExt } from '@phosphor/algorithm'; @@ -35,7 +37,7 @@ import { UUID } from '@phosphor/coreutils'; import { DisposableSet } from '@phosphor/disposable'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; import { ILauncher } from '@jupyterlab/launcher'; diff --git a/packages/rendermime-extension/src/index.ts b/packages/rendermime-extension/src/index.ts index 130f428fa77a..b4dc6a4a5367 100644 --- a/packages/rendermime-extension/src/index.ts +++ b/packages/rendermime-extension/src/index.ts @@ -8,7 +8,7 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IDocumentManager } from '@jupyterlab/docmanager'; +import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; import { ILatexTypesetter, @@ -24,7 +24,7 @@ namespace CommandIDs { /** * A plugin providing a rendermime registry. */ -const plugin: JupyterFrontEndPlugin = { +const plugin: JupyterFrontEndPlugin = { id: '@jupyterlab/rendermime-extension:plugin', requires: [IDocumentManager], optional: [ILatexTypesetter], diff --git a/packages/rendermime/src/index.ts b/packages/rendermime/src/index.ts index b6d683c17c5e..02aa990475d7 100644 --- a/packages/rendermime/src/index.ts +++ b/packages/rendermime/src/index.ts @@ -12,4 +12,5 @@ export * from './mimemodel'; export * from './outputmodel'; export * from './registry'; export * from './renderers'; +export * from './tokens'; export * from './widgets'; diff --git a/packages/rendermime/src/registry.ts b/packages/rendermime/src/registry.ts index cc9f34bee059..454ba2599b18 100644 --- a/packages/rendermime/src/registry.ts +++ b/packages/rendermime/src/registry.ts @@ -14,31 +14,11 @@ import { defaultSanitizer } from '@jupyterlab/apputils'; -import { ReadonlyJSONObject, Token } from '@phosphor/coreutils'; +import { ReadonlyJSONObject } from '@phosphor/coreutils'; import { MimeModel } from './mimemodel'; -/* tslint:disable */ -/** - * The rendermime token. - */ -export const IRenderMimeRegistry = new Token( - '@jupyterlab/rendermime:IRenderMimeRegistry' -); - -export interface IRenderMimeRegistry extends RenderMimeRegistry {} -/* tslint:enable */ - -/* tslint:disable */ -/** - * The latex typesetter token. - */ -export const ILatexTypesetter = new Token( - '@jupyterlab/rendermime:ILatexTypesetter' -); - -export interface ILatexTypesetter extends IRenderMime.ILatexTypesetter {} -/* tslint:enable */ +import { IRenderMimeRegistry } from './tokens'; /** * An object which manages mime renderer factories. @@ -50,7 +30,7 @@ export interface ILatexTypesetter extends IRenderMime.ILatexTypesetter {} * #### Notes * This class is not intended to be subclassed. */ -export class RenderMimeRegistry { +export class RenderMimeRegistry implements IRenderMimeRegistry { /** * Construct a new rendermime. * @@ -180,7 +160,7 @@ export class RenderMimeRegistry { * * @returns A new independent clone of the rendermime. */ - clone(options: RenderMimeRegistry.ICloneOptions = {}): RenderMimeRegistry { + clone(options: IRenderMimeRegistry.ICloneOptions = {}): RenderMimeRegistry { // Create the clone. let clone = new RenderMimeRegistry({ resolver: options.resolver || this.resolver || undefined, @@ -323,31 +303,6 @@ export namespace RenderMimeRegistry { latexTypesetter?: IRenderMime.ILatexTypesetter; } - /** - * The options used to clone a rendermime instance. - */ - export interface ICloneOptions { - /** - * The new sanitizer used to sanitize untrusted html inputs. - */ - sanitizer?: IRenderMime.ISanitizer; - - /** - * The new resolver object. - */ - resolver?: IRenderMime.IResolver; - - /** - * The new path handler. - */ - linkHandler?: IRenderMime.ILinkHandler; - - /** - * The new LaTeX typesetter. - */ - latexTypesetter?: IRenderMime.ILatexTypesetter; - } - /** * A default resolver that uses a session and a contents manager. */ diff --git a/packages/rendermime/src/tokens.ts b/packages/rendermime/src/tokens.ts new file mode 100644 index 000000000000..a002dd19236a --- /dev/null +++ b/packages/rendermime/src/tokens.ts @@ -0,0 +1,187 @@ +/*----------------------------------------------------------------------------- +| Copyright (c) Jupyter Development Team. +| Distributed under the terms of the Modified BSD License. +|----------------------------------------------------------------------------*/ + +import { Token, ReadonlyJSONObject } from '@phosphor/coreutils'; + +import { ISanitizer } from '@jupyterlab/apputils'; + +import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; + +import { MimeModel } from './mimemodel'; + +/* tslint:disable */ +/** + * The rendermime token. + */ +export const IRenderMimeRegistry = new Token( + '@jupyterlab/rendermime:IRenderMimeRegistry' +); + +export interface IRenderMimeRegistry { + /** + * The sanitizer used by the rendermime instance. + */ + readonly sanitizer: ISanitizer; + + /** + * The object used to resolve relative urls for the rendermime instance. + */ + readonly resolver: IRenderMime.IResolver | null; + + /** + * The object used to handle path opening links. + */ + readonly linkHandler: IRenderMime.ILinkHandler | null; + + /** + * The LaTeX typesetter for the rendermime. + */ + readonly latexTypesetter: IRenderMime.ILatexTypesetter | null; + + /** + * The ordered list of mimeTypes. + */ + readonly mimeTypes: ReadonlyArray; + + /** + * Find the preferred mime type for a mime bundle. + * + * @param bundle - The bundle of mime data. + * + * @param safe - How to consider safe/unsafe factories. If 'ensure', + * it will only consider safe factories. If 'any', any factory will be + * considered. If 'prefer', unsafe factories will be considered, but + * only after the safe options have been exhausted. + * + * @returns The preferred mime type from the available factories, + * or `undefined` if the mime type cannot be rendered. + */ + preferredMimeType( + bundle: ReadonlyJSONObject, + safe?: 'ensure' | 'prefer' | 'any' + ): string | undefined; + + /** + * Create a renderer for a mime type. + * + * @param mimeType - The mime type of interest. + * + * @returns A new renderer for the given mime type. + * + * @throws An error if no factory exists for the mime type. + */ + createRenderer(mimeType: string): IRenderMime.IRenderer; + + /** + * Create a new mime model. This is a convenience method. + * + * @options - The options used to create the model. + * + * @returns A new mime model. + */ + createModel(options?: MimeModel.IOptions): MimeModel; + + /** + * Create a clone of this rendermime instance. + * + * @param options - The options for configuring the clone. + * + * @returns A new independent clone of the rendermime. + */ + clone(options?: IRenderMimeRegistry.ICloneOptions): IRenderMimeRegistry; + + /** + * Get the renderer factory registered for a mime type. + * + * @param mimeType - The mime type of interest. + * + * @returns The factory for the mime type, or `undefined`. + */ + getFactory(mimeType: string): IRenderMime.IRendererFactory | undefined; + + /** + * Add a renderer factory to the rendermime. + * + * @param factory - The renderer factory of interest. + * + * @param rank - The rank of the renderer. A lower rank indicates + * a higher priority for rendering. If not given, the rank will + * defer to the `defaultRank` of the factory. If no `defaultRank` + * is given, it will default to 100. + * + * #### Notes + * The renderer will replace an existing renderer for the given + * mimeType. + */ + addFactory(factory: IRenderMime.IRendererFactory, rank?: number): void; + + /** + * Remove a mime type. + * + * @param mimeType - The mime type of interest. + */ + removeMimeType(mimeType: string): void; + + /** + * Get the rank for a given mime type. + * + * @param mimeType - The mime type of interest. + * + * @returns The rank of the mime type or undefined. + */ + getRank(mimeType: string): number | undefined; + + /** + * Set the rank of a given mime type. + * + * @param mimeType - The mime type of interest. + * + * @param rank - The new rank to assign. + * + * #### Notes + * This is a no-op if the mime type is not registered. + */ + setRank(mimeType: string, rank: number): void; +} + +export namespace IRenderMimeRegistry { + /** + * The options used to clone a rendermime instance. + */ + export interface ICloneOptions { + /** + * The new sanitizer used to sanitize untrusted html inputs. + */ + sanitizer?: IRenderMime.ISanitizer; + + /** + * The new resolver object. + */ + resolver?: IRenderMime.IResolver; + + /** + * The new path handler. + */ + linkHandler?: IRenderMime.ILinkHandler; + + /** + * The new LaTeX typesetter. + */ + latexTypesetter?: IRenderMime.ILatexTypesetter; + } +} + +/* tslint:enable */ + +/* tslint:disable */ +/** + * The latex typesetter token. + */ +export const ILatexTypesetter = new Token( + '@jupyterlab/rendermime:ILatexTypesetter' +); + +export interface ILatexTypesetter extends IRenderMime.ILatexTypesetter {} +/* tslint:enable */ diff --git a/packages/settingeditor-extension/src/index.ts b/packages/settingeditor-extension/src/index.ts index d3477e58b759..d91b337d31ed 100644 --- a/packages/settingeditor-extension/src/index.ts +++ b/packages/settingeditor-extension/src/index.ts @@ -15,7 +15,7 @@ import { MainAreaWidget } from '@jupyterlab/apputils'; -import { IEditorServices } from '@jupyterlab/codeeditor'; +import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; import { ISettingRegistry, IStateDB } from '@jupyterlab/coreutils'; diff --git a/packages/settingeditor/src/index.ts b/packages/settingeditor/src/index.ts index be32230df0d9..2acac92d063a 100644 --- a/packages/settingeditor/src/index.ts +++ b/packages/settingeditor/src/index.ts @@ -1,27 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IInstanceTracker, MainAreaWidget } from '@jupyterlab/apputils'; - -import { Token } from '@phosphor/coreutils'; - -import { SettingEditor } from './settingeditor'; - import '../style/settingeditor.css'; export * from './settingeditor'; - -/* tslint:disable */ -/** - * The setting editor tracker token. - */ -export const ISettingEditorTracker = new Token( - '@jupyterlab/settingeditor:ISettingEditorTracker' -); -/* tslint:enable */ - -/** - * A class that tracks the setting editor. - */ -export interface ISettingEditorTracker - extends IInstanceTracker> {} +export * from './tokens'; diff --git a/packages/settingeditor/src/tokens.ts b/packages/settingeditor/src/tokens.ts new file mode 100644 index 000000000000..524fa8627bbd --- /dev/null +++ b/packages/settingeditor/src/tokens.ts @@ -0,0 +1,23 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { IInstanceTracker, MainAreaWidget } from '@jupyterlab/apputils'; + +import { Token } from '@phosphor/coreutils'; + +import { SettingEditor } from './settingeditor'; + +/* tslint:disable */ +/** + * The setting editor tracker token. + */ +export const ISettingEditorTracker = new Token( + '@jupyterlab/settingeditor:ISettingEditorTracker' +); +/* tslint:enable */ + +/** + * A class that tracks the setting editor. + */ +export interface ISettingEditorTracker + extends IInstanceTracker> {} diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index 229fbaf3f3fa..beffef5b3fe6 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -11,15 +11,14 @@ import { IClientSession, ICommandPalette } from '@jupyterlab/apputils'; import { Cell, CodeCell } from '@jupyterlab/cells'; -import { - CodeConsole, - ConsolePanel, - IConsoleTracker -} from '@jupyterlab/console'; +import { CodeConsole, ConsolePanel } from '@jupyterlab/console'; + +import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { FileEditor, IEditorTracker } from '@jupyterlab/fileeditor'; +import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; +import { FileEditor } from '@jupyterlab/fileeditor'; import { INotebookTracker, diff --git a/packages/statusbar/src/index.ts b/packages/statusbar/src/index.ts index ac477a9a88f2..4455c9b240cc 100644 --- a/packages/statusbar/src/index.ts +++ b/packages/statusbar/src/index.ts @@ -7,3 +7,4 @@ export * from './statusbar'; export * from './style/statusbar'; export * from './components'; export * from './defaults'; +export * from './tokens'; diff --git a/packages/statusbar/src/statusbar.ts b/packages/statusbar/src/statusbar.ts index cc860aedc88d..89585ebad2ab 100644 --- a/packages/statusbar/src/statusbar.ts +++ b/packages/statusbar/src/statusbar.ts @@ -3,10 +3,6 @@ import { ArrayExt } from '@phosphor/algorithm'; -import { ISignal } from '@phosphor/signaling'; - -import { Token } from '@phosphor/coreutils'; - import { DisposableDelegate, DisposableSet, @@ -25,65 +21,7 @@ import { rightSide as rightSideStyle } from './style/statusbar'; -// tslint:disable-next-line:variable-name -export const IStatusBar = new Token( - '@jupyterlab/statusbar:IStatusBar' -); - -/** - * Main status bar object which contains all widgets. - */ -export interface IStatusBar { - /** - * Register a new status item. - * - * @param id - a unique id for the status item. - * - * @param options - The options for how to add the status item. - * - * @returns an `IDisposable` that can be disposed to remove the item. - */ - registerStatusItem(id: string, statusItem: IStatusBar.IItem): IDisposable; -} - -/** - * A namespace for status bar statics. - */ -export namespace IStatusBar { - export type Alignment = 'right' | 'left' | 'middle'; - - /** - * Options for status bar items. - */ - export interface IItem { - /** - * The item to add to the status bar. - */ - item: Widget; - - /** - * Which side to place item. - * Permanent items are intended for the right and left side, - * with more transient items in the middle. - */ - align?: Alignment; - - /** - * Ordering of Items -- higher rank items are closer to the middle. - */ - rank?: number; - - /** - * Whether the item is shown or hidden. - */ - isActive?: () => boolean; - - /** - * A signal that is fired when the item active state changes. - */ - activeStateChanged?: ISignal; - } -} +import { IStatusBar } from './tokens'; /** * Main status bar object which contains all items. diff --git a/packages/statusbar/src/tokens.ts b/packages/statusbar/src/tokens.ts new file mode 100644 index 000000000000..896b1b97083d --- /dev/null +++ b/packages/statusbar/src/tokens.ts @@ -0,0 +1,70 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { ISignal } from '@phosphor/signaling'; + +import { Token } from '@phosphor/coreutils'; + +import { IDisposable } from '@phosphor/disposable'; + +import { Widget } from '@phosphor/widgets'; + +// tslint:disable-next-line:variable-name +export const IStatusBar = new Token( + '@jupyterlab/statusbar:IStatusBar' +); + +/** + * Main status bar object which contains all widgets. + */ +export interface IStatusBar { + /** + * Register a new status item. + * + * @param id - a unique id for the status item. + * + * @param options - The options for how to add the status item. + * + * @returns an `IDisposable` that can be disposed to remove the item. + */ + registerStatusItem(id: string, statusItem: IStatusBar.IItem): IDisposable; +} + +/** + * A namespace for status bar statics. + */ +export namespace IStatusBar { + export type Alignment = 'right' | 'left' | 'middle'; + + /** + * Options for status bar items. + */ + export interface IItem { + /** + * The item to add to the status bar. + */ + item: Widget; + + /** + * Which side to place item. + * Permanent items are intended for the right and left side, + * with more transient items in the middle. + */ + align?: Alignment; + + /** + * Ordering of Items -- higher rank items are closer to the middle. + */ + rank?: number; + + /** + * Whether the item is shown or hidden. + */ + isActive?: () => boolean; + + /** + * A signal that is fired when the item active state changes. + */ + activeStateChanged?: ISignal; + } +} diff --git a/packages/terminal-extension/src/index.ts b/packages/terminal-extension/src/index.ts index 070d3c6e744e..db831be3401c 100644 --- a/packages/terminal-extension/src/index.ts +++ b/packages/terminal-extension/src/index.ts @@ -20,10 +20,7 @@ import { ILauncher } from '@jupyterlab/launcher'; import { IMainMenu } from '@jupyterlab/mainmenu'; -import { - ITerminalTracker, - ITerminal -} from '@jupyterlab/terminal/lib/constants'; +import { ITerminalTracker, ITerminal } from '@jupyterlab/terminal/lib/tokens'; // Name-only import so as to not trigger inclusion in main bundle import * as WidgetModuleType from '@jupyterlab/terminal/lib/widget'; diff --git a/packages/terminal/src/index.ts b/packages/terminal/src/index.ts index 955aa19e46f9..dfc065d72e56 100644 --- a/packages/terminal/src/index.ts +++ b/packages/terminal/src/index.ts @@ -1,5 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -export * from './constants'; +import '../style/index.css'; + +export * from './tokens'; export * from './widget'; diff --git a/packages/terminal/src/constants.ts b/packages/terminal/src/tokens.ts similarity index 98% rename from packages/terminal/src/constants.ts rename to packages/terminal/src/tokens.ts index d7a9218c64b7..8ec72d3da249 100644 --- a/packages/terminal/src/constants.ts +++ b/packages/terminal/src/tokens.ts @@ -9,8 +9,6 @@ import { IInstanceTracker, MainAreaWidget } from '@jupyterlab/apputils'; import { TerminalSession } from '@jupyterlab/services'; -import '../style/index.css'; - /** * A class that tracks editor widgets. */ diff --git a/packages/tooltip-extension/src/index.ts b/packages/tooltip-extension/src/index.ts index 8d214b27dc1d..c828070575a2 100644 --- a/packages/tooltip-extension/src/index.ts +++ b/packages/tooltip-extension/src/index.ts @@ -18,9 +18,9 @@ import { import { CodeEditor } from '@jupyterlab/codeeditor'; -import { IConsoleTracker } from '@jupyterlab/console'; +import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; -import { IEditorTracker } from '@jupyterlab/fileeditor'; +import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; import { INotebookTracker } from '@jupyterlab/notebook'; diff --git a/packages/tooltip/src/index.ts b/packages/tooltip/src/index.ts index e0130d8791a0..dfc065d72e56 100644 --- a/packages/tooltip/src/index.ts +++ b/packages/tooltip/src/index.ts @@ -1,65 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { Kernel } from '@jupyterlab/services'; - -import { Token } from '@phosphor/coreutils'; - -import { Widget } from '@phosphor/widgets'; - -import { CodeEditor } from '@jupyterlab/codeeditor'; - -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; - import '../style/index.css'; +export * from './tokens'; export * from './widget'; - -/* tslint:disable */ -/** - * The tooltip manager token. - */ -export const ITooltipManager = new Token( - '@jupyterlab/tooltip:ITooltipManager' -); -/* tslint:enable */ - -/** - * A manager to register tooltips with parent widgets. - */ -export interface ITooltipManager { - /** - * Invoke a tooltip. - */ - invoke(options: ITooltipManager.IOptions): void; -} - -/** - * A namespace for `ICompletionManager` interface specifications. - */ -export namespace ITooltipManager { - /** - * An interface for tooltip-compatible objects. - */ - export interface IOptions { - /** - * The referent anchor the tooltip follows. - */ - readonly anchor: Widget; - - /** - * The referent editor for the tooltip. - */ - readonly editor: CodeEditor.IEditor; - - /** - * The kernel the tooltip communicates with to populate itself. - */ - readonly kernel: Kernel.IKernelConnection; - - /** - * The renderer the tooltip uses to render API responses. - */ - readonly rendermime: RenderMimeRegistry; - } -} diff --git a/packages/tooltip/src/tokens.ts b/packages/tooltip/src/tokens.ts new file mode 100644 index 000000000000..b7582f317d8a --- /dev/null +++ b/packages/tooltip/src/tokens.ts @@ -0,0 +1,61 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Kernel } from '@jupyterlab/services'; + +import { Token } from '@phosphor/coreutils'; + +import { Widget } from '@phosphor/widgets'; + +import { CodeEditor } from '@jupyterlab/codeeditor'; + +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; + +/* tslint:disable */ +/** + * The tooltip manager token. + */ +export const ITooltipManager = new Token( + '@jupyterlab/tooltip:ITooltipManager' +); +/* tslint:enable */ + +/** + * A manager to register tooltips with parent widgets. + */ +export interface ITooltipManager { + /** + * Invoke a tooltip. + */ + invoke(options: ITooltipManager.IOptions): void; +} + +/** + * A namespace for `ICompletionManager` interface specifications. + */ +export namespace ITooltipManager { + /** + * An interface for tooltip-compatible objects. + */ + export interface IOptions { + /** + * The referent anchor the tooltip follows. + */ + readonly anchor: Widget; + + /** + * The referent editor for the tooltip. + */ + readonly editor: CodeEditor.IEditor; + + /** + * The kernel the tooltip communicates with to populate itself. + */ + readonly kernel: Kernel.IKernelConnection; + + /** + * The renderer the tooltip uses to render API responses. + */ + readonly rendermime: IRenderMimeRegistry; + } +} From 7410ceb411d2a6fb5a8024ff34f1ef379842e71b Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:03:45 +0100 Subject: [PATCH 03/10] IRenderMimeRegistry typing --- packages/cells/src/widget.ts | 10 +++++----- packages/console/src/panel.ts | 7 +++++-- packages/console/src/widget.ts | 6 +++--- packages/docregistry/src/mimedocument.ts | 6 +++--- packages/inspector/src/handler.ts | 6 +++--- packages/markdownviewer/src/widget.ts | 6 +++--- packages/notebook/src/panel.ts | 4 ++-- packages/notebook/src/widget.ts | 6 +++--- packages/notebook/src/widgetfactory.ts | 6 +++--- packages/outputarea/src/widget.ts | 6 +++--- packages/settingeditor/src/inspector.ts | 3 ++- packages/settingeditor/src/plugineditor.ts | 4 ++-- packages/settingeditor/src/raweditor.ts | 4 ++-- packages/settingeditor/src/settingeditor.tsx | 4 ++-- packages/tooltip/src/widget.ts | 6 +++--- 15 files changed, 44 insertions(+), 40 deletions(-) diff --git a/packages/cells/src/widget.ts b/packages/cells/src/widget.ts index f1a1d1cde4c6..d1d6c1062fc8 100644 --- a/packages/cells/src/widget.ts +++ b/packages/cells/src/widget.ts @@ -25,7 +25,7 @@ import { import { IRenderMime, MimeModel, - RenderMimeRegistry + IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { KernelMessage } from '@jupyterlab/services'; @@ -974,7 +974,7 @@ export class CodeCell extends Cell { this.toggleClass(NO_OUTPUTS_CLASS, force); } - private _rendermime: RenderMimeRegistry = null; + private _rendermime: IRenderMimeRegistry = null; private _outputHidden = false; private _outputsScrolled: boolean; private _outputWrapper: Widget = null; @@ -1000,7 +1000,7 @@ export namespace CodeCell { /** * The mime renderer for the cell widget. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } /** @@ -1189,7 +1189,7 @@ export class MarkdownCell extends Cell { private _monitor: ActivityMonitor = null; private _renderer: IRenderMime.IRenderer = null; - private _rendermime: RenderMimeRegistry; + private _rendermime: IRenderMimeRegistry; private _rendered = true; private _prevText = ''; private _ready = new PromiseDelegate(); @@ -1211,7 +1211,7 @@ export namespace MarkdownCell { /** * The mime renderer for the cell widget. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } } diff --git a/packages/console/src/panel.ts b/packages/console/src/panel.ts index cbaca4f70cb6..a3e8f34fc725 100644 --- a/packages/console/src/panel.ts +++ b/packages/console/src/panel.ts @@ -9,7 +9,10 @@ import { PathExt, Time } from '@jupyterlab/coreutils'; import { UUID } from '@phosphor/coreutils'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { + IRenderMimeRegistry, + RenderMimeRegistry +} from '@jupyterlab/rendermime'; import { ServiceManager } from '@jupyterlab/services'; @@ -169,7 +172,7 @@ export namespace ConsolePanel { /** * The rendermime instance used by the panel. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; /** * The content factory for the panel. diff --git a/packages/console/src/widget.ts b/packages/console/src/widget.ts index 90b2d4847b5d..65c07b07101a 100644 --- a/packages/console/src/widget.ts +++ b/packages/console/src/widget.ts @@ -22,7 +22,7 @@ import { nbformat } from '@jupyterlab/coreutils'; import { IObservableList, ObservableList } from '@jupyterlab/observables'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { KernelMessage } from '@jupyterlab/services'; @@ -165,7 +165,7 @@ export class CodeConsole extends Widget { /** * The rendermime instance used by the console. */ - readonly rendermime: RenderMimeRegistry; + readonly rendermime: IRenderMimeRegistry; /** * The client session used by the console. @@ -837,7 +837,7 @@ export namespace CodeConsole { /** * The mime renderer for the console widget. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; /** * The client session for the console widget. diff --git a/packages/docregistry/src/mimedocument.ts b/packages/docregistry/src/mimedocument.ts index 65555f4a8ecb..b8225dd095c3 100644 --- a/packages/docregistry/src/mimedocument.ts +++ b/packages/docregistry/src/mimedocument.ts @@ -7,7 +7,7 @@ import { ActivityMonitor } from '@jupyterlab/coreutils'; import { IRenderMime, - RenderMimeRegistry, + IRenderMimeRegistry, MimeModel } from '@jupyterlab/rendermime'; @@ -293,7 +293,7 @@ export class MimeDocumentFactory extends ABCWidgetFactory { return widget; } - private _rendermime: RenderMimeRegistry; + private _rendermime: IRenderMimeRegistry; private _renderTimeout: number; private _dataType: 'string' | 'json'; private _fileType: DocumentRegistry.IFileType; @@ -316,7 +316,7 @@ export namespace MimeDocumentFactory { /** * The rendermime instance. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; /** * The render timeout. diff --git a/packages/inspector/src/handler.ts b/packages/inspector/src/handler.ts index e23ab435fd9e..96e91c88ae06 100644 --- a/packages/inspector/src/handler.ts +++ b/packages/inspector/src/handler.ts @@ -5,7 +5,7 @@ import { CodeEditor } from '@jupyterlab/codeeditor'; import { IDataConnector, Text, ActivityMonitor } from '@jupyterlab/coreutils'; -import { MimeModel, RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { MimeModel, IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { ReadonlyJSONObject } from '@phosphor/coreutils'; @@ -183,7 +183,7 @@ export class InspectionHandler implements IDisposable, IInspector.IInspectable { private _inspected = new Signal(this); private _isDisposed = false; private _pending = 0; - private _rendermime: RenderMimeRegistry; + private _rendermime: IRenderMimeRegistry; private _standby = true; private _monitors: ActivityMonitor[]; } @@ -209,7 +209,7 @@ export namespace InspectionHandler { /** * The mime renderer for the inspection handler. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } /** diff --git a/packages/markdownviewer/src/widget.ts b/packages/markdownviewer/src/widget.ts index 2e2a650bfa6f..5388a831ac18 100644 --- a/packages/markdownviewer/src/widget.ts +++ b/packages/markdownviewer/src/widget.ts @@ -13,7 +13,7 @@ import { import { IRenderMime, - RenderMimeRegistry, + IRenderMimeRegistry, MimeModel } from '@jupyterlab/rendermime'; @@ -315,7 +315,7 @@ export class MarkdownViewerFactory extends ABCWidgetFactory { } private _fileType: DocumentRegistry.IFileType; - private _rendermime: RenderMimeRegistry; + private _rendermime: IRenderMimeRegistry; } /** @@ -334,7 +334,7 @@ export namespace MarkdownViewerFactory { /** * The rendermime instance. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } } diff --git a/packages/notebook/src/panel.ts b/packages/notebook/src/panel.ts index cc309fdf9cf7..b3f924660a80 100644 --- a/packages/notebook/src/panel.ts +++ b/packages/notebook/src/panel.ts @@ -18,7 +18,7 @@ import { import { DocumentWidget } from '@jupyterlab/docregistry'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { INotebookModel } from './model'; @@ -102,7 +102,7 @@ export class NotebookPanel extends DocumentWidget { * TODO: deprecate this in favor of the .content attribute * */ - get rendermime(): RenderMimeRegistry { + get rendermime(): IRenderMimeRegistry { return this.content.rendermime; } diff --git a/packages/notebook/src/widget.ts b/packages/notebook/src/widget.ts index a90886434c8a..47d4346a25c1 100644 --- a/packages/notebook/src/widget.ts +++ b/packages/notebook/src/widget.ts @@ -36,7 +36,7 @@ import { IChangedArgs, nbformat } from '@jupyterlab/coreutils'; import { IObservableMap, IObservableList } from '@jupyterlab/observables'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { INotebookModel } from './model'; @@ -199,7 +199,7 @@ export class StaticNotebook extends Widget { /** * The Rendermime instance used by the widget. */ - readonly rendermime: RenderMimeRegistry; + readonly rendermime: IRenderMimeRegistry; /** * The model for the widget. @@ -645,7 +645,7 @@ export namespace StaticNotebook { /** * The rendermime instance used by the widget. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; /** * The language preference for the model. diff --git a/packages/notebook/src/widgetfactory.ts b/packages/notebook/src/widgetfactory.ts index a36c3b45193b..1ef22a0dd74d 100644 --- a/packages/notebook/src/widgetfactory.ts +++ b/packages/notebook/src/widgetfactory.ts @@ -5,7 +5,7 @@ import { IEditorMimeTypeService } from '@jupyterlab/codeeditor'; import { ABCWidgetFactory, DocumentRegistry } from '@jupyterlab/docregistry'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { ToolbarItems } from './default-toolbar'; @@ -42,7 +42,7 @@ export class NotebookWidgetFactory extends ABCWidgetFactory< /* * The rendermime instance. */ - readonly rendermime: RenderMimeRegistry; + readonly rendermime: IRenderMimeRegistry; /** * The content factory used by the widget factory. @@ -122,7 +122,7 @@ export namespace NotebookWidgetFactory { /* * A rendermime instance. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; /** * A notebook panel content factory. diff --git a/packages/outputarea/src/widget.ts b/packages/outputarea/src/widget.ts index 79aa0ea5296c..0b04ae2b185f 100644 --- a/packages/outputarea/src/widget.ts +++ b/packages/outputarea/src/widget.ts @@ -19,7 +19,7 @@ import { IClientSession } from '@jupyterlab/apputils'; import { nbformat } from '@jupyterlab/coreutils'; -import { IOutputModel, RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IOutputModel, IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; @@ -123,7 +123,7 @@ export class OutputArea extends Widget { /** * The rendermime instance used by the widget. */ - readonly rendermime: RenderMimeRegistry; + readonly rendermime: IRenderMimeRegistry; /** * A read-only sequence of the chidren widgets in the output area. @@ -522,7 +522,7 @@ export namespace OutputArea { /** * The rendermime instance used by the widget. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } /** diff --git a/packages/settingeditor/src/inspector.ts b/packages/settingeditor/src/inspector.ts index 1fc05dd60191..fea298d02d42 100644 --- a/packages/settingeditor/src/inspector.ts +++ b/packages/settingeditor/src/inspector.ts @@ -8,6 +8,7 @@ import { DataConnector, ISchemaValidator } from '@jupyterlab/coreutils'; import { InspectionHandler, InspectorPanel } from '@jupyterlab/inspector'; import { + IRenderMimeRegistry, RenderMimeRegistry, standardRendererFactories } from '@jupyterlab/rendermime'; @@ -21,7 +22,7 @@ import { RawEditor } from './raweditor'; */ export function createInspector( editor: RawEditor, - rendermime?: RenderMimeRegistry + rendermime?: IRenderMimeRegistry ): InspectorPanel { const connector = new InspectorConnector(editor); const inspector = new InspectorPanel(); diff --git a/packages/settingeditor/src/plugineditor.ts b/packages/settingeditor/src/plugineditor.ts index 1c3572cc6a69..4943f32de0c9 100644 --- a/packages/settingeditor/src/plugineditor.ts +++ b/packages/settingeditor/src/plugineditor.ts @@ -9,7 +9,7 @@ import { CodeEditor } from '@jupyterlab/codeeditor'; import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { CommandRegistry } from '@phosphor/commands'; @@ -243,7 +243,7 @@ export namespace PluginEditor { /** * The optional MIME renderer to use for rendering debug messages. */ - rendermime?: RenderMimeRegistry; + rendermime?: IRenderMimeRegistry; } } diff --git a/packages/settingeditor/src/raweditor.ts b/packages/settingeditor/src/raweditor.ts index 3eebd1d9a88e..006938ae689f 100644 --- a/packages/settingeditor/src/raweditor.ts +++ b/packages/settingeditor/src/raweditor.ts @@ -7,7 +7,7 @@ import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor'; import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { CommandRegistry } from '@phosphor/commands'; @@ -388,7 +388,7 @@ export namespace RawEditor { /** * The optional MIME renderer to use for rendering debug messages. */ - rendermime?: RenderMimeRegistry; + rendermime?: IRenderMimeRegistry; } } diff --git a/packages/settingeditor/src/settingeditor.tsx b/packages/settingeditor/src/settingeditor.tsx index e7a11ac3529f..03f5e2e46989 100644 --- a/packages/settingeditor/src/settingeditor.tsx +++ b/packages/settingeditor/src/settingeditor.tsx @@ -7,7 +7,7 @@ import { CodeEditor } from '@jupyterlab/codeeditor'; import { ISettingRegistry, IStateDB } from '@jupyterlab/coreutils'; -import { RenderMimeRegistry } from '@jupyterlab/rendermime'; +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { CommandRegistry } from '@phosphor/commands'; @@ -402,7 +402,7 @@ export namespace SettingEditor { /** * The optional MIME renderer to use for rendering debug messages. */ - rendermime?: RenderMimeRegistry; + rendermime?: IRenderMimeRegistry; /** * The state database used to store layout. diff --git a/packages/tooltip/src/widget.ts b/packages/tooltip/src/widget.ts index e9efbdc78ecf..afb78fc22693 100644 --- a/packages/tooltip/src/widget.ts +++ b/packages/tooltip/src/widget.ts @@ -15,7 +15,7 @@ import { HoverBox } from '@jupyterlab/apputils'; import { IRenderMime, - RenderMimeRegistry, + IRenderMimeRegistry, MimeModel } from '@jupyterlab/rendermime'; @@ -232,7 +232,7 @@ export class Tooltip extends Widget { private _content: IRenderMime.IRenderer | null = null; private _editor: CodeEditor.IEditor; - private _rendermime: RenderMimeRegistry; + private _rendermime: IRenderMimeRegistry; } /** @@ -261,6 +261,6 @@ export namespace Tooltip { /** * The rendermime instance used by the tooltip model. */ - rendermime: RenderMimeRegistry; + rendermime: IRenderMimeRegistry; } } From b5571de355e46c0d216a5a9d6c7aed9c55f8c071 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:25:12 +0100 Subject: [PATCH 04/10] Token refactor ThemeManager Might not make sense, since all uses also import other things from apputils. --- packages/apputils/src/thememanager.ts | 62 +------------- packages/apputils/src/tokens.ts | 113 ++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 58 deletions(-) create mode 100644 packages/apputils/src/tokens.ts diff --git a/packages/apputils/src/thememanager.ts b/packages/apputils/src/thememanager.ts index 2669d0e5916e..1e03f66f882b 100644 --- a/packages/apputils/src/thememanager.ts +++ b/packages/apputils/src/thememanager.ts @@ -5,8 +5,6 @@ import { IChangedArgs, ISettingRegistry, URLExt } from '@jupyterlab/coreutils'; import { each } from '@phosphor/algorithm'; -import { Token } from '@phosphor/coreutils'; - import { DisposableDelegate, IDisposable } from '@phosphor/disposable'; import { Widget } from '@phosphor/widgets'; @@ -17,19 +15,7 @@ import { Dialog, showDialog } from './dialog'; import { ISplashScreen } from './splash'; -/* tslint:disable */ -/** - * The theme manager token. - */ -export const IThemeManager = new Token( - '@jupyterlab/apputils:IThemeManager' -); -/* tslint:enable */ - -/** - * An interface for a theme manager. - */ -export interface IThemeManager extends ThemeManager {} +import { IThemeManager } from './tokens'; /** * The number of milliseconds between theme loading attempts. @@ -44,7 +30,7 @@ const REQUEST_THRESHOLD = 20; /** * A class that provides theme management. */ -export class ThemeManager { +export class ThemeManager implements IThemeManager { /** * Construct a new theme manager. */ @@ -119,7 +105,7 @@ export class ThemeManager { * * @returns A disposable that can be used to unregister the theme. */ - register(theme: ThemeManager.ITheme): IDisposable { + register(theme: IThemeManager.ITheme): IDisposable { const { name } = theme; const themes = this._themes; @@ -297,13 +283,10 @@ export class ThemeManager { private _requests: { [theme: string]: number } = {}; private _settings: ISettingRegistry.ISettings; private _splash: ISplashScreen | null; - private _themes: { [key: string]: ThemeManager.ITheme } = {}; + private _themes: { [key: string]: IThemeManager.ITheme } = {}; private _themeChanged = new Signal>(this); } -/** - * A namespace for `ThemeManager` statics. - */ export namespace ThemeManager { /** * The options used to create a theme manager. @@ -334,43 +317,6 @@ export namespace ThemeManager { */ url: string; } - - /** - * An interface for a theme. - */ - export interface ITheme { - /** - * The display name of the theme. - */ - name: string; - - /** - * Whether the theme is light or dark. Downstream authors - * of extensions can use this information to customize their - * UI depending upon the current theme. - */ - isLight: boolean; - - /** - * Whether the theme includes styling for the scrollbar. - * If set to false, this theme will leave the native scrollbar untouched. - */ - themeScrollbars?: boolean; - - /** - * Load the theme. - * - * @returns A promise that resolves when the theme has loaded. - */ - load(): Promise; - - /** - * Unload the theme. - * - * @returns A promise that resolves when the theme has unloaded. - */ - unload(): Promise; - } } /** diff --git a/packages/apputils/src/tokens.ts b/packages/apputils/src/tokens.ts new file mode 100644 index 000000000000..718bf38667d7 --- /dev/null +++ b/packages/apputils/src/tokens.ts @@ -0,0 +1,113 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { IChangedArgs } from '@jupyterlab/coreutils'; + +import { Token } from '@phosphor/coreutils'; + +import { IDisposable } from '@phosphor/disposable'; + +import { ISignal } from '@phosphor/signaling'; + +/* tslint:disable */ +/** + * The theme manager token. + */ +export const IThemeManager = new Token( + '@jupyterlab/apputils:IThemeManager' +); +/* tslint:enable */ + +/** + * An interface for a theme manager. + */ +export interface IThemeManager { + /** + * Get the name of the current theme. + */ + readonly theme: string | null; + + /** + * The names of the registered themes. + */ + readonly themes: ReadonlyArray; + + /** + * A signal fired when the application theme changes. + */ + readonly themeChanged: ISignal>; + + /** + * Load a theme CSS file by path. + * + * @param path - The path of the file to load. + */ + loadCSS(path: string): Promise; + + /** + * Register a theme with the theme manager. + * + * @param theme - The theme to register. + * + * @returns A disposable that can be used to unregister the theme. + */ + register(theme: IThemeManager.ITheme): IDisposable; + + /** + * Set the current theme. + */ + setTheme(name: string): Promise; + + /** + * Test whether a given theme is light. + */ + isLight(name: string): boolean; + + /** + * Test whether a given theme styles scrollbars, + * and if the user has scrollbar styling enabled. + */ + themeScrollbars(name: string): boolean; +} + +/** + * A namespace for the `IThemeManager` sub-types. + */ +export namespace IThemeManager { + /** + * An interface for a theme. + */ + export interface ITheme { + /** + * The display name of the theme. + */ + name: string; + + /** + * Whether the theme is light or dark. Downstream authors + * of extensions can use this information to customize their + * UI depending upon the current theme. + */ + isLight: boolean; + + /** + * Whether the theme includes styling for the scrollbar. + * If set to false, this theme will leave the native scrollbar untouched. + */ + themeScrollbars?: boolean; + + /** + * Load the theme. + * + * @returns A promise that resolves when the theme has loaded. + */ + load(): Promise; + + /** + * Unload the theme. + * + * @returns A promise that resolves when the theme has unloaded. + */ + unload(): Promise; + } +} From d09109cc291cd56d65b61b199f4eb73327983fe3 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:48:54 +0100 Subject: [PATCH 05/10] Refactor mainmenu token --- packages/apputils-extension/src/index.ts | 2 +- packages/codemirror-extension/src/index.ts | 3 +- packages/console-extension/src/index.ts | 3 +- packages/csvviewer-extension/src/index.ts | 3 +- packages/docmanager-extension/src/index.ts | 2 +- .../documentsearch-extension/src/index.ts | 2 +- packages/fileeditor-extension/src/index.ts | 3 +- packages/mainmenu/src/index.ts | 1 + packages/mainmenu/src/mainmenu.ts | 90 ++---------------- packages/mainmenu/src/tokens.ts | 94 +++++++++++++++++++ packages/notebook-extension/src/index.ts | 3 +- packages/statusbar-extension/src/index.ts | 2 +- packages/terminal-extension/src/index.ts | 2 +- 13 files changed, 119 insertions(+), 91 deletions(-) create mode 100644 packages/mainmenu/src/tokens.ts diff --git a/packages/apputils-extension/src/index.ts b/packages/apputils-extension/src/index.ts index 86fae3d1680d..92dc734a6abf 100644 --- a/packages/apputils-extension/src/index.ts +++ b/packages/apputils-extension/src/index.ts @@ -29,7 +29,7 @@ import { URLExt } from '@jupyterlab/coreutils'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { CommandRegistry } from '@phosphor/commands'; diff --git a/packages/codemirror-extension/src/index.ts b/packages/codemirror-extension/src/index.ts index d3bdee579886..5cf9d3d0b41e 100644 --- a/packages/codemirror-extension/src/index.ts +++ b/packages/codemirror-extension/src/index.ts @@ -11,7 +11,8 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IMainMenu, IEditMenu } from '@jupyterlab/mainmenu'; +import { IEditMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; diff --git a/packages/console-extension/src/index.ts b/packages/console-extension/src/index.ts index 64b0e56d5f66..c8a4d8a6f3ed 100644 --- a/packages/console-extension/src/index.ts +++ b/packages/console-extension/src/index.ts @@ -31,10 +31,11 @@ import { IFileMenu, IHelpMenu, IKernelMenu, - IMainMenu, IRunMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; + import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { find } from '@phosphor/algorithm'; diff --git a/packages/csvviewer-extension/src/index.ts b/packages/csvviewer-extension/src/index.ts index 8d97ce9b53c5..e64bff29832e 100644 --- a/packages/csvviewer-extension/src/index.ts +++ b/packages/csvviewer-extension/src/index.ts @@ -22,7 +22,8 @@ import { IDocumentWidget } from '@jupyterlab/docregistry'; import { DataGrid } from '@phosphor/datagrid'; -import { IMainMenu, IEditMenu } from '@jupyterlab/mainmenu'; +import { IEditMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { CSVSearchProvider } from './searchprovider'; /** diff --git a/packages/docmanager-extension/src/index.ts b/packages/docmanager-extension/src/index.ts index b06d77308d18..30f7583cd482 100644 --- a/packages/docmanager-extension/src/index.ts +++ b/packages/docmanager-extension/src/index.ts @@ -32,7 +32,7 @@ import { import { DocumentRegistry } from '@jupyterlab/docregistry'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { Contents, Kernel } from '@jupyterlab/services'; diff --git a/packages/documentsearch-extension/src/index.ts b/packages/documentsearch-extension/src/index.ts index 3655cce2f5b2..7c6316b10fd1 100644 --- a/packages/documentsearch-extension/src/index.ts +++ b/packages/documentsearch-extension/src/index.ts @@ -17,7 +17,7 @@ import { NotebookSearchProvider } from '@jupyterlab/documentsearch'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { Widget } from '@phosphor/widgets'; const SEARCHABLE_CLASS = 'jp-mod-searchable'; diff --git a/packages/fileeditor-extension/src/index.ts b/packages/fileeditor-extension/src/index.ts index 24eeee47e19c..aeb3f29f87ff 100644 --- a/packages/fileeditor-extension/src/index.ts +++ b/packages/fileeditor-extension/src/index.ts @@ -37,11 +37,12 @@ import { ILauncher } from '@jupyterlab/launcher'; import { IEditMenu, IFileMenu, - IMainMenu, IRunMenu, IViewMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; + import { IStatusBar } from '@jupyterlab/statusbar'; import { JSONObject, ReadonlyJSONObject } from '@phosphor/coreutils'; diff --git a/packages/mainmenu/src/index.ts b/packages/mainmenu/src/index.ts index 5875bcc56ef2..8a04bf65720b 100644 --- a/packages/mainmenu/src/index.ts +++ b/packages/mainmenu/src/index.ts @@ -11,3 +11,4 @@ export * from './run'; export * from './settings'; export * from './view'; export * from './tabs'; +export * from './tokens'; diff --git a/packages/mainmenu/src/mainmenu.ts b/packages/mainmenu/src/mainmenu.ts index 79c31343999a..187276ee5d81 100644 --- a/packages/mainmenu/src/mainmenu.ts +++ b/packages/mainmenu/src/mainmenu.ts @@ -5,97 +5,25 @@ import { ArrayExt } from '@phosphor/algorithm'; import { CommandRegistry } from '@phosphor/commands'; -import { Token } from '@phosphor/coreutils'; - import { Menu, MenuBar } from '@phosphor/widgets'; -import { IFileMenu, FileMenu } from './file'; - -import { IEditMenu, EditMenu } from './edit'; - -import { IHelpMenu, HelpMenu } from './help'; - -import { IKernelMenu, KernelMenu } from './kernel'; +import { FileMenu } from './file'; -import { IRunMenu, RunMenu } from './run'; +import { EditMenu } from './edit'; -import { ISettingsMenu, SettingsMenu } from './settings'; +import { HelpMenu } from './help'; -import { IViewMenu, ViewMenu } from './view'; - -import { ITabsMenu, TabsMenu } from './tabs'; - -/* tslint:disable */ -/** - * The main menu token. - */ -export const IMainMenu = new Token('@jupyterlab/mainmenu:IMainMenu'); -/* tslint:enable */ - -/** - * The main menu interface. - */ -export interface IMainMenu { - /** - * Add a new menu to the main menu bar. - */ - addMenu(menu: Menu, options?: IMainMenu.IAddOptions): void; +import { KernelMenu } from './kernel'; - /** - * The application "File" menu. - */ - readonly fileMenu: IFileMenu; +import { RunMenu } from './run'; - /** - * The application "Edit" menu. - */ - readonly editMenu: IEditMenu; +import { SettingsMenu } from './settings'; - /** - * The application "View" menu. - */ - readonly viewMenu: IViewMenu; +import { ViewMenu } from './view'; - /** - * The application "Help" menu. - */ - readonly helpMenu: IHelpMenu; +import { TabsMenu } from './tabs'; - /** - * The application "Kernel" menu. - */ - readonly kernelMenu: IKernelMenu; - - /** - * The application "Run" menu. - */ - readonly runMenu: IRunMenu; - - /** - * The application "Settings" menu. - */ - readonly settingsMenu: ISettingsMenu; - - /** - * The application "Tabs" menu. - */ - readonly tabsMenu: ITabsMenu; -} - -/** - * The namespace for IMainMenu attached interfaces. - */ -export namespace IMainMenu { - /** - * The options used to add a menu to the main menu. - */ - export interface IAddOptions { - /** - * The rank order of the menu among its siblings. - */ - rank?: number; - } -} +import { IMainMenu } from './tokens'; /** * The main menu class. It is intended to be used as a singleton. diff --git a/packages/mainmenu/src/tokens.ts b/packages/mainmenu/src/tokens.ts new file mode 100644 index 000000000000..110342e10b89 --- /dev/null +++ b/packages/mainmenu/src/tokens.ts @@ -0,0 +1,94 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; + +import { Menu } from '@phosphor/widgets'; + +import { IFileMenu } from './file'; + +import { IEditMenu } from './edit'; + +import { IHelpMenu } from './help'; + +import { IKernelMenu } from './kernel'; + +import { IRunMenu } from './run'; + +import { ISettingsMenu } from './settings'; + +import { IViewMenu } from './view'; + +import { ITabsMenu } from './tabs'; + +/* tslint:disable */ +/** + * The main menu token. + */ +export const IMainMenu = new Token('@jupyterlab/mainmenu:IMainMenu'); +/* tslint:enable */ + +/** + * The main menu interface. + */ +export interface IMainMenu { + /** + * Add a new menu to the main menu bar. + */ + addMenu(menu: Menu, options?: IMainMenu.IAddOptions): void; + + /** + * The application "File" menu. + */ + readonly fileMenu: IFileMenu; + + /** + * The application "Edit" menu. + */ + readonly editMenu: IEditMenu; + + /** + * The application "View" menu. + */ + readonly viewMenu: IViewMenu; + + /** + * The application "Help" menu. + */ + readonly helpMenu: IHelpMenu; + + /** + * The application "Kernel" menu. + */ + readonly kernelMenu: IKernelMenu; + + /** + * The application "Run" menu. + */ + readonly runMenu: IRunMenu; + + /** + * The application "Settings" menu. + */ + readonly settingsMenu: ISettingsMenu; + + /** + * The application "Tabs" menu. + */ + readonly tabsMenu: ITabsMenu; +} + +/** + * The namespace for IMainMenu attached interfaces. + */ +export namespace IMainMenu { + /** + * The options used to add a menu to the main menu. + */ + export interface IAddOptions { + /** + * The rank order of the menu among its siblings. + */ + rank?: number; + } +} diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 08d9bf1d7ebb..b5db29259c50 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -42,7 +42,6 @@ import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; import { ILauncher } from '@jupyterlab/launcher'; import { - IMainMenu, IEditMenu, IFileMenu, IHelpMenu, @@ -51,6 +50,8 @@ import { IViewMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; + import { NotebookTools, INotebookTools, diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index beffef5b3fe6..79aee6c63b15 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -37,7 +37,7 @@ import { import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { Title, Widget } from '@phosphor/widgets'; diff --git a/packages/terminal-extension/src/index.ts b/packages/terminal-extension/src/index.ts index db831be3401c..362aeb152c9c 100644 --- a/packages/terminal-extension/src/index.ts +++ b/packages/terminal-extension/src/index.ts @@ -18,7 +18,7 @@ import { import { ILauncher } from '@jupyterlab/launcher'; -import { IMainMenu } from '@jupyterlab/mainmenu'; +import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; import { ITerminalTracker, ITerminal } from '@jupyterlab/terminal/lib/tokens'; From 88f5dcd179d51994a16d7fe92c1d113e62685f72 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:33:04 +0100 Subject: [PATCH 06/10] Refactor coreutils token Might not make sense, given the prevalence of coreutils imports --- packages/codemirror-extension/src/index.ts | 2 +- packages/coreutils/src/index.ts | 1 + packages/coreutils/src/settingregistry.ts | 323 +------------- packages/coreutils/src/statedb.ts | 44 +- packages/coreutils/src/tokens.ts | 487 +++++++++++++++++++++ 5 files changed, 497 insertions(+), 360 deletions(-) create mode 100644 packages/coreutils/src/tokens.ts diff --git a/packages/codemirror-extension/src/index.ts b/packages/codemirror-extension/src/index.ts index 5cf9d3d0b41e..06c5a9ac038b 100644 --- a/packages/codemirror-extension/src/index.ts +++ b/packages/codemirror-extension/src/index.ts @@ -23,7 +23,7 @@ import { Mode } from '@jupyterlab/codemirror'; -import { ISettingRegistry } from '@jupyterlab/coreutils'; +import { ISettingRegistry } from '@jupyterlab/coreutils/lib/tokens'; import { IDocumentWidget } from '@jupyterlab/docregistry'; diff --git a/packages/coreutils/src/index.ts b/packages/coreutils/src/index.ts index 7b52f64f5f9a..35e0bb48f2be 100644 --- a/packages/coreutils/src/index.ts +++ b/packages/coreutils/src/index.ts @@ -13,4 +13,5 @@ export * from './settingregistry'; export * from './statedb'; export * from './text'; export * from './time'; +export * from './tokens'; export * from './url'; diff --git a/packages/coreutils/src/settingregistry.ts b/packages/coreutils/src/settingregistry.ts index a9a0a56ee286..f03bb5ffed4c 100644 --- a/packages/coreutils/src/settingregistry.ts +++ b/packages/coreutils/src/settingregistry.ts @@ -10,8 +10,7 @@ import { JSONObject, JSONValue, ReadonlyJSONObject, - ReadonlyJSONValue, - Token + ReadonlyJSONValue } from '@phosphor/coreutils'; import { DisposableDelegate, IDisposable } from '@phosphor/disposable'; @@ -20,6 +19,8 @@ import { ISignal, Signal } from '@phosphor/signaling'; import { IDataConnector } from './interfaces'; +import { ISettingRegistry } from './tokens'; + import SCHEMA from './plugin-schema.json'; /** @@ -96,318 +97,6 @@ export namespace ISchemaValidator { } } -/* tslint:disable */ -/** - * The setting registry token. - */ -export const ISettingRegistry = new Token( - '@jupyterlab/coreutils:ISettingRegistry' -); -/* tslint:enable */ - -/** - * A namespace for setting registry interfaces. - */ -export namespace ISettingRegistry { - /** - * The primitive types available in a JSON schema. - */ - export type Primitive = - | 'array' - | 'boolean' - | 'null' - | 'number' - | 'object' - | 'string'; - - /** - * The settings for a specific plugin. - */ - export interface IPlugin extends JSONObject { - /** - * The name of the plugin. - */ - id: string; - - /** - * The collection of values for a specified plugin. - */ - data: ISettingBundle; - - /** - * The raw user settings data as a string containing JSON with comments. - */ - raw: string; - - /** - * The JSON schema for the plugin. - */ - schema: ISchema; - - /** - * The published version of the NPM package containing the plugin. - */ - version: string; - } - - /** - * A namespace for plugin functionality. - */ - export namespace IPlugin { - /** - * A function that transforms a plugin object before it is consumed by the - * setting registry. - */ - export type Transform = (plugin: IPlugin) => IPlugin; - - /** - * The phases during which a transformation may be applied to a plugin. - */ - export type Phase = 'compose' | 'fetch'; - } - - /** - * A minimal subset of the formal JSON Schema that describes a property. - */ - export interface IProperty extends JSONObject { - /** - * The default value, if any. - */ - default?: any; - - /** - * The schema description. - */ - description?: string; - - /** - * The schema's child properties. - */ - properties?: { [property: string]: IProperty }; - - /** - * The title of a property. - */ - title?: string; - - /** - * The type or types of the data. - */ - type?: Primitive | Primitive[]; - } - - /** - * A schema type that is a minimal subset of the formal JSON Schema along with - * optional JupyterLab rendering hints. - */ - export interface ISchema extends IProperty { - /** - * Whether the schema is deprecated. - * - * #### Notes - * This flag can be used by functionality that loads this plugin's settings - * from the registry. For example, the setting editor does not display a - * plugin's settings if it is set to `true`. - */ - 'jupyter.lab.setting-deprecated'?: boolean; - - /** - * The JupyterLab icon class hint. - */ - 'jupyter.lab.setting-icon-class'?: string; - - /** - * The JupyterLab icon label hint. - */ - 'jupyter.lab.setting-icon-label'?: string; - - /** - * A flag that indicates plugin should be transformed before being used by - * the setting registry. - * - * #### Notes - * If this value is set to `true`, the setting registry will wait until a - * transformation has been registered (by calling the `transform()` method - * of the registry) for the plugin ID before resolving `load()` promises. - * This means that if the attribute is set to `true` but no transformation - * is registered in time, calls to `load()` a plugin will eventually time - * out and reject. - */ - 'jupyter.lab.transform'?: boolean; - - /** - * The JupyterLab shortcuts that are creaed by a plugin's schema. - */ - 'jupyter.lab.shortcuts'?: IShortcut[]; - - /** - * The root schema is always an object. - */ - type: 'object'; - } - - /** - * The setting values for a plugin. - */ - export interface ISettingBundle extends JSONObject { - /** - * A composite of the user setting values and the plugin schema defaults. - * - * #### Notes - * The `composite` values will always be a superset of the `user` values. - */ - composite: JSONObject; - - /** - * The user setting values. - */ - user: JSONObject; - } - - /** - * An interface for manipulating the settings of a specific plugin. - */ - export interface ISettings extends IDisposable { - /** - * A signal that emits when the plugin's settings have changed. - */ - readonly changed: ISignal; - - /** - * The composite of user settings and extension defaults. - */ - readonly composite: ReadonlyJSONObject; - - /** - * The plugin's ID. - */ - readonly id: string; - - /* - * The underlying plugin. - */ - readonly plugin: ISettingRegistry.IPlugin; - - /** - * The plugin settings raw text value. - */ - readonly raw: string; - - /** - * The plugin's schema. - */ - readonly schema: ISettingRegistry.ISchema; - - /** - * The user settings. - */ - readonly user: ReadonlyJSONObject; - - /** - * The published version of the NPM package containing these settings. - */ - readonly version: string; - - /** - * Return the defaults in a commented JSON format. - */ - annotatedDefaults(): string; - - /** - * Calculate the default value of a setting by iterating through the schema. - * - * @param key - The name of the setting whose default value is calculated. - * - * @returns A calculated default JSON value for a specific setting. - */ - default(key: string): JSONValue | undefined; - - /** - * Get an individual setting. - * - * @param key - The name of the setting being retrieved. - * - * @returns The setting value. - */ - get(key: string): { composite: ReadonlyJSONValue; user: ReadonlyJSONValue }; - - /** - * Remove a single setting. - * - * @param key - The name of the setting being removed. - * - * @returns A promise that resolves when the setting is removed. - * - * #### Notes - * This function is asynchronous because it writes to the setting registry. - */ - remove(key: string): Promise; - - /** - * Save all of the plugin's user settings at once. - */ - save(raw: string): Promise; - - /** - * Set a single setting. - * - * @param key - The name of the setting being set. - * - * @param value - The value of the setting. - * - * @returns A promise that resolves when the setting has been saved. - * - * #### Notes - * This function is asynchronous because it writes to the setting registry. - */ - set(key: string, value: JSONValue): Promise; - - /** - * Validates raw settings with comments. - * - * @param raw - The JSON with comments string being validated. - * - * @returns A list of errors or `null` if valid. - */ - validate(raw: string): ISchemaValidator.IError[] | null; - } - - /** - * An interface describing a JupyterLab keyboard shortcut. - */ - export interface IShortcut extends JSONObject { - /** - * The optional arguments passed into the shortcut's command. - */ - args?: JSONObject; - - /** - * The command invoked by the shortcut. - */ - command: string; - - /** - * Whether a keyboard shortcut is disabled. `False` by default. - */ - disabled?: boolean; - - /** - * The key combination of the shortcut. - */ - keys: string[]; - - /** - * The CSS selector applicable to the shortcut. - */ - selector: string; - } -} - -/** - * An implementation of a setting registry. - */ -export interface ISettingRegistry extends SettingRegistry {} - /** * The default implementation of a schema validator. */ @@ -553,7 +242,7 @@ export class DefaultSchemaValidator implements ISchemaValidator { /** * The default concrete implementation of a setting registry. */ -export class SettingRegistry { +export class SettingRegistry implements ISettingRegistry { /** * Create a new setting registry. */ @@ -967,7 +656,7 @@ export class Settings implements ISettingRegistry.ISettings { /** * The setting registry instance used as a back-end for these settings. */ - readonly registry: SettingRegistry; + readonly registry: ISettingRegistry; /** * A signal that emits when the plugin's settings have changed. @@ -1262,7 +951,7 @@ export namespace Settings { /** * The system registry instance used by the settings manager. */ - registry: SettingRegistry; + registry: ISettingRegistry; } } diff --git a/packages/coreutils/src/statedb.ts b/packages/coreutils/src/statedb.ts index 4e035212303e..973031ef116b 100644 --- a/packages/coreutils/src/statedb.ts +++ b/packages/coreutils/src/statedb.ts @@ -1,51 +1,11 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { - ReadonlyJSONObject, - ReadonlyJSONValue, - Token -} from '@phosphor/coreutils'; +import { ReadonlyJSONObject, ReadonlyJSONValue } from '@phosphor/coreutils'; import { ISignal, Signal } from '@phosphor/signaling'; -import { IDataConnector } from './interfaces'; - -/* tslint:disable */ -/** - * The default state database token. - */ -export const IStateDB = new Token('@jupyterlab/coreutils:IStateDB'); -/* tslint:enable */ - -/** - * The description of a state database. - */ -export interface IStateDB - extends IDataConnector { - /** - * The maximum allowed length of the data after it has been serialized. - */ - readonly maxLength: number; - - /** - * The namespace prefix for all state database entries. - * - * #### Notes - * This value should be set at instantiation and will only be used - * internally by a state database. That means, for example, that an - * app could have multiple, mutually exclusive state databases. - */ - readonly namespace: string; - - /** - * Return a serialized copy of the state database's entire contents. - * - * @returns A promise that bears the database contents as JSON. - */ - toJSON(): Promise<{ [id: string]: T }>; -} - +import { IStateDB } from './tokens'; /** * The default concrete implementation of a state database. */ diff --git a/packages/coreutils/src/tokens.ts b/packages/coreutils/src/tokens.ts new file mode 100644 index 000000000000..e23b2baf3e93 --- /dev/null +++ b/packages/coreutils/src/tokens.ts @@ -0,0 +1,487 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { + JSONObject, + JSONValue, + ReadonlyJSONObject, + ReadonlyJSONValue, + Token +} from '@phosphor/coreutils'; + +import { IDisposable } from '@phosphor/disposable'; + +import { ISignal } from '@phosphor/signaling'; + +import { ISchemaValidator } from './settingregistry'; + +import { IDataConnector } from './interfaces'; + +/* tslint:disable */ +/** + * The setting registry token. + */ +export const ISettingRegistry = new Token( + '@jupyterlab/coreutils:ISettingRegistry' +); +/* tslint:enable */ + +/** + * The settings registry interface. + */ +export interface ISettingRegistry { + /** + * The data connector used by the setting registry. + */ + readonly connector: IDataConnector; + + /** + * The schema of the setting registry. + */ + readonly schema: ISettingRegistry.ISchema; + + /** + * The schema validator used by the setting registry. + */ + readonly validator: ISchemaValidator; + + /** + * A signal that emits the name of a plugin when its settings change. + */ + readonly pluginChanged: ISignal; + + /** + * The collection of setting registry plugins. + */ + readonly plugins: { + [name: string]: ISettingRegistry.IPlugin; + }; + + /** + * Get an individual setting. + * + * @param plugin - The name of the plugin whose settings are being retrieved. + * + * @param key - The name of the setting being retrieved. + * + * @returns A promise that resolves when the setting is retrieved. + */ + get( + plugin: string, + key: string + ): Promise<{ composite: JSONValue; user: JSONValue }>; + + /** + * Load a plugin's settings into the setting registry. + * + * @param plugin - The name of the plugin whose settings are being loaded. + * + * @returns A promise that resolves with a plugin settings object or rejects + * if the plugin is not found. + */ + load(plugin: string): Promise; + + /** + * Reload a plugin's settings into the registry even if they already exist. + * + * @param plugin - The name of the plugin whose settings are being reloaded. + * + * @returns A promise that resolves with a plugin settings object or rejects + * with a list of `ISchemaValidator.IError` objects if it fails. + */ + reload(plugin: string): Promise; + + /** + * Remove a single setting in the registry. + * + * @param plugin - The name of the plugin whose setting is being removed. + * + * @param key - The name of the setting being removed. + * + * @returns A promise that resolves when the setting is removed. + */ + remove(plugin: string, key: string): Promise; + + /** + * Set a single setting in the registry. + * + * @param plugin - The name of the plugin whose setting is being set. + * + * @param key - The name of the setting being set. + * + * @param value - The value of the setting being set. + * + * @returns A promise that resolves when the setting has been saved. + * + */ + set(plugin: string, key: string, value: JSONValue): Promise; + + /** + * Register a plugin transform function to act on a specific plugin. + * + * @param plugin - The name of the plugin whose settings are transformed. + * + * @param transforms - The transform functions applied to the plugin. + * + * @returns A disposable that removes the transforms from the registry. + * + * #### Notes + * - `compose` transformations: The registry automatically overwrites a + * plugin's default values with user overrides, but a plugin may instead wish + * to merge values. This behavior can be accomplished in a `compose` + * transformation. + * - `fetch` transformations: The registry uses the plugin data that is + * fetched from its connector. If a plugin wants to override, e.g. to update + * its schema with dynamic defaults, a `fetch` transformation can be applied. + */ + transform( + plugin: string, + transforms: { + [phase in ISettingRegistry.IPlugin.Phase]?: ISettingRegistry.IPlugin.Transform + } + ): IDisposable; + + /** + * Upload a plugin's settings. + * + * @param plugin - The name of the plugin whose settings are being set. + * + * @param raw - The raw plugin settings being uploaded. + * + * @returns A promise that resolves when the settings have been saved. + */ + upload(plugin: string, raw: string): Promise; +} + +/** + * A namespace for setting registry interfaces. + */ +export namespace ISettingRegistry { + /** + * The primitive types available in a JSON schema. + */ + export type Primitive = + | 'array' + | 'boolean' + | 'null' + | 'number' + | 'object' + | 'string'; + + /** + * The settings for a specific plugin. + */ + export interface IPlugin extends JSONObject { + /** + * The name of the plugin. + */ + id: string; + + /** + * The collection of values for a specified plugin. + */ + data: ISettingBundle; + + /** + * The raw user settings data as a string containing JSON with comments. + */ + raw: string; + + /** + * The JSON schema for the plugin. + */ + schema: ISchema; + + /** + * The published version of the NPM package containing the plugin. + */ + version: string; + } + + /** + * A namespace for plugin functionality. + */ + export namespace IPlugin { + /** + * A function that transforms a plugin object before it is consumed by the + * setting registry. + */ + export type Transform = (plugin: IPlugin) => IPlugin; + + /** + * The phases during which a transformation may be applied to a plugin. + */ + export type Phase = 'compose' | 'fetch'; + } + + /** + * A minimal subset of the formal JSON Schema that describes a property. + */ + export interface IProperty extends JSONObject { + /** + * The default value, if any. + */ + default?: any; + + /** + * The schema description. + */ + description?: string; + + /** + * The schema's child properties. + */ + properties?: { [property: string]: IProperty }; + + /** + * The title of a property. + */ + title?: string; + + /** + * The type or types of the data. + */ + type?: Primitive | Primitive[]; + } + + /** + * A schema type that is a minimal subset of the formal JSON Schema along with + * optional JupyterLab rendering hints. + */ + export interface ISchema extends IProperty { + /** + * Whether the schema is deprecated. + * + * #### Notes + * This flag can be used by functionality that loads this plugin's settings + * from the registry. For example, the setting editor does not display a + * plugin's settings if it is set to `true`. + */ + 'jupyter.lab.setting-deprecated'?: boolean; + + /** + * The JupyterLab icon class hint. + */ + 'jupyter.lab.setting-icon-class'?: string; + + /** + * The JupyterLab icon label hint. + */ + 'jupyter.lab.setting-icon-label'?: string; + + /** + * A flag that indicates plugin should be transformed before being used by + * the setting registry. + * + * #### Notes + * If this value is set to `true`, the setting registry will wait until a + * transformation has been registered (by calling the `transform()` method + * of the registry) for the plugin ID before resolving `load()` promises. + * This means that if the attribute is set to `true` but no transformation + * is registered in time, calls to `load()` a plugin will eventually time + * out and reject. + */ + 'jupyter.lab.transform'?: boolean; + + /** + * The JupyterLab shortcuts that are creaed by a plugin's schema. + */ + 'jupyter.lab.shortcuts'?: IShortcut[]; + + /** + * The root schema is always an object. + */ + type: 'object'; + } + + /** + * The setting values for a plugin. + */ + export interface ISettingBundle extends JSONObject { + /** + * A composite of the user setting values and the plugin schema defaults. + * + * #### Notes + * The `composite` values will always be a superset of the `user` values. + */ + composite: JSONObject; + + /** + * The user setting values. + */ + user: JSONObject; + } + + /** + * An interface for manipulating the settings of a specific plugin. + */ + export interface ISettings extends IDisposable { + /** + * A signal that emits when the plugin's settings have changed. + */ + readonly changed: ISignal; + + /** + * The composite of user settings and extension defaults. + */ + readonly composite: ReadonlyJSONObject; + + /** + * The plugin's ID. + */ + readonly id: string; + + /* + * The underlying plugin. + */ + readonly plugin: ISettingRegistry.IPlugin; + + /** + * The plugin settings raw text value. + */ + readonly raw: string; + + /** + * The plugin's schema. + */ + readonly schema: ISettingRegistry.ISchema; + + /** + * The user settings. + */ + readonly user: ReadonlyJSONObject; + + /** + * The published version of the NPM package containing these settings. + */ + readonly version: string; + + /** + * Return the defaults in a commented JSON format. + */ + annotatedDefaults(): string; + + /** + * Calculate the default value of a setting by iterating through the schema. + * + * @param key - The name of the setting whose default value is calculated. + * + * @returns A calculated default JSON value for a specific setting. + */ + default(key: string): JSONValue | undefined; + + /** + * Get an individual setting. + * + * @param key - The name of the setting being retrieved. + * + * @returns The setting value. + */ + get(key: string): { composite: ReadonlyJSONValue; user: ReadonlyJSONValue }; + + /** + * Remove a single setting. + * + * @param key - The name of the setting being removed. + * + * @returns A promise that resolves when the setting is removed. + * + * #### Notes + * This function is asynchronous because it writes to the setting registry. + */ + remove(key: string): Promise; + + /** + * Save all of the plugin's user settings at once. + */ + save(raw: string): Promise; + + /** + * Set a single setting. + * + * @param key - The name of the setting being set. + * + * @param value - The value of the setting. + * + * @returns A promise that resolves when the setting has been saved. + * + * #### Notes + * This function is asynchronous because it writes to the setting registry. + */ + set(key: string, value: JSONValue): Promise; + + /** + * Validates raw settings with comments. + * + * @param raw - The JSON with comments string being validated. + * + * @returns A list of errors or `null` if valid. + */ + validate(raw: string): ISchemaValidator.IError[] | null; + } + + /** + * An interface describing a JupyterLab keyboard shortcut. + */ + export interface IShortcut extends JSONObject { + /** + * The optional arguments passed into the shortcut's command. + */ + args?: JSONObject; + + /** + * The command invoked by the shortcut. + */ + command: string; + + /** + * Whether a keyboard shortcut is disabled. `False` by default. + */ + disabled?: boolean; + + /** + * The key combination of the shortcut. + */ + keys: string[]; + + /** + * The CSS selector applicable to the shortcut. + */ + selector: string; + } +} + +/* tslint:disable */ +/** + * The default state database token. + */ +export const IStateDB = new Token('@jupyterlab/coreutils:IStateDB'); +/* tslint:enable */ + +/** + * The description of a state database. + */ +export interface IStateDB + extends IDataConnector { + /** + * The maximum allowed length of the data after it has been serialized. + */ + readonly maxLength: number; + + /** + * The namespace prefix for all state database entries. + * + * #### Notes + * This value should be set at instantiation and will only be used + * internally by a state database. That means, for example, that an + * app could have multiple, mutually exclusive state databases. + */ + readonly namespace: string; + + /** + * Return a serialized copy of the state database's entire contents. + * + * @returns A promise that bears the database contents as JSON. + */ + toJSON(): Promise<{ [id: string]: T }>; +} From 4b19bde9384bf3c522b07013d50fca7f1e0192e5 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 10 May 2019 16:33:30 +0100 Subject: [PATCH 07/10] Refactor notebook tokens --- packages/notebook/src/index.ts | 1 + packages/notebook/src/notebooktools.ts | 25 +------ packages/notebook/src/tokens.ts | 98 ++++++++++++++++++++++++++ packages/notebook/src/tracker.ts | 39 +--------- 4 files changed, 104 insertions(+), 59 deletions(-) create mode 100644 packages/notebook/src/tokens.ts diff --git a/packages/notebook/src/index.ts b/packages/notebook/src/index.ts index e068dbbf8c8f..2b9977093df7 100644 --- a/packages/notebook/src/index.ts +++ b/packages/notebook/src/index.ts @@ -14,3 +14,4 @@ export * from './widget'; export * from './widgetfactory'; export * from './modestatus'; export * from './truststatus'; +export * from './tokens'; diff --git a/packages/notebook/src/notebooktools.ts b/packages/notebook/src/notebooktools.ts index 8b9619a2032e..421166e002b1 100644 --- a/packages/notebook/src/notebooktools.ts +++ b/packages/notebook/src/notebooktools.ts @@ -3,7 +3,7 @@ import { ArrayExt, each, chain } from '@phosphor/algorithm'; -import { JSONObject, JSONValue, Token } from '@phosphor/coreutils'; +import { JSONObject, JSONValue } from '@phosphor/coreutils'; import { ConflatableMessage, Message, MessageLoop } from '@phosphor/messaging'; @@ -25,28 +25,9 @@ import { nbformat } from '@jupyterlab/coreutils'; import { IObservableMap, ObservableJSON } from '@jupyterlab/observables'; -import { INotebookTracker } from './'; import { NotebookPanel } from './panel'; import { INotebookModel } from './model'; - -/* tslint:disable */ -/** - * The notebook tools token. - */ -export const INotebookTools = new Token( - '@jupyterlab/notebook:INotebookTools' -); -/* tslint:enable */ - -/** - * The interface for notebook metadata tools. - */ -export interface INotebookTools extends Widget { - activeNotebookPanel: NotebookPanel | null; - activeCell: Cell | null; - selectedCells: Cell[]; - addItem(options: NotebookTools.IAddOptions): void; -} +import { INotebookTools, INotebookTracker } from './tokens'; class RankedPanel extends Widget { constructor() { @@ -321,7 +302,7 @@ export namespace NotebookTools { /** * The base notebook tool, meant to be subclassed. */ - export class Tool extends Widget { + export class Tool extends Widget implements INotebookTools.ITool { /** * The notebook tools object. */ diff --git a/packages/notebook/src/tokens.ts b/packages/notebook/src/tokens.ts new file mode 100644 index 000000000000..853b1fa1a08b --- /dev/null +++ b/packages/notebook/src/tokens.ts @@ -0,0 +1,98 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +import { Token } from '@phosphor/coreutils'; +import { ISignal } from '@phosphor/signaling'; +import { Widget } from '@phosphor/widgets'; + +import { IInstanceTracker } from '@jupyterlab/apputils'; +import { Cell } from '@jupyterlab/cells'; + +import { NotebookPanel } from './panel'; +import { NotebookTools } from './notebooktools'; + +/* tslint:disable */ +/** + * The notebook tools token. + */ +export const INotebookTools = new Token( + '@jupyterlab/notebook:INotebookTools' +); +/* tslint:enable */ + +/** + * The interface for notebook metadata tools. + */ +export interface INotebookTools extends Widget { + activeNotebookPanel: NotebookPanel | null; + activeCell: Cell | null; + selectedCells: Cell[]; + addItem(options: NotebookTools.IAddOptions): void; +} + +/** + * The namespace for NotebookTools class statics. + */ +export namespace INotebookTools { + /** + * The options used to add an item to the notebook tools. + */ + export interface IAddOptions { + /** + * The tool to add to the notebook tools area. + */ + tool: ITool; + + /** + * The section to which the tool should be added. + */ + section?: 'common' | 'advanced'; + + /** + * The rank order of the widget among its siblings. + */ + rank?: number; + } + + export interface ITool extends Widget { + /** + * The notebook tools object. + */ + notebookTools: INotebookTools; + } +} + +/* tslint:disable */ +/** + * The notebook tracker token. + */ +export const INotebookTracker = new Token( + '@jupyterlab/notebook:INotebookTracker' +); +/* tslint:enable */ + +/** + * An object that tracks notebook widgets. + */ +export interface INotebookTracker extends IInstanceTracker { + /** + * The currently focused cell. + * + * #### Notes + * If there is no cell with the focus, then this value is `null`. + */ + readonly activeCell: Cell; + + /** + * A signal emitted when the current active cell changes. + * + * #### Notes + * If there is no cell with the focus, then `null` will be emitted. + */ + readonly activeCellChanged: ISignal; + + /** + * A signal emitted when the selection state changes. + */ + readonly selectionChanged: ISignal; +} diff --git a/packages/notebook/src/tracker.ts b/packages/notebook/src/tracker.ts index f6489a7e4366..f0faa1756289 100644 --- a/packages/notebook/src/tracker.ts +++ b/packages/notebook/src/tracker.ts @@ -1,50 +1,15 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IInstanceTracker, InstanceTracker } from '@jupyterlab/apputils'; +import { InstanceTracker } from '@jupyterlab/apputils'; import { Cell } from '@jupyterlab/cells'; -import { Token } from '@phosphor/coreutils'; import { ISignal, Signal } from '@phosphor/signaling'; +import { INotebookTracker } from './tokens'; import { NotebookPanel } from './panel'; import { Notebook } from './widget'; -/** - * An object that tracks notebook widgets. - */ -export interface INotebookTracker extends IInstanceTracker { - /** - * The currently focused cell. - * - * #### Notes - * If there is no cell with the focus, then this value is `null`. - */ - readonly activeCell: Cell; - - /** - * A signal emitted when the current active cell changes. - * - * #### Notes - * If there is no cell with the focus, then `null` will be emitted. - */ - readonly activeCellChanged: ISignal; - - /** - * A signal emitted when the selection state changes. - */ - readonly selectionChanged: ISignal; -} - -/* tslint:disable */ -/** - * The notebook tracker token. - */ -export const INotebookTracker = new Token( - '@jupyterlab/notebook:INotebookTracker' -); -/* tslint:enable */ - export class NotebookTracker extends InstanceTracker implements INotebookTracker { /** From 8705749b2725c9d67b31cc28080c8ffc2b8b0dc6 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Mon, 13 May 2019 14:29:45 +0100 Subject: [PATCH 08/10] Remove lib/editor submodule import --- packages/fileeditor-extension/src/index.ts | 2 +- packages/notebook-extension/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fileeditor-extension/src/index.ts b/packages/fileeditor-extension/src/index.ts index aeb3f29f87ff..3a2cdd8bba62 100644 --- a/packages/fileeditor-extension/src/index.ts +++ b/packages/fileeditor-extension/src/index.ts @@ -9,7 +9,7 @@ import { import { ICommandPalette, InstanceTracker } from '@jupyterlab/apputils'; -import { CodeEditor } from '@jupyterlab/codeeditor/lib/editor'; +import { CodeEditor } from '@jupyterlab/codeeditor'; import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index b5db29259c50..fd1c21b25f62 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -18,7 +18,7 @@ import { import { CodeCell } from '@jupyterlab/cells'; -import { CodeEditor } from '@jupyterlab/codeeditor/lib/editor'; +import { CodeEditor } from '@jupyterlab/codeeditor'; import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; From 468801e4ebfe636095d637e3290dcfa74383f9f6 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Mon, 13 May 2019 14:52:25 +0100 Subject: [PATCH 09/10] Fix missing export of IThemeManager token --- packages/apputils/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/apputils/src/index.ts b/packages/apputils/src/index.ts index b8c5d22a02be..8eebc4bc978f 100644 --- a/packages/apputils/src/index.ts +++ b/packages/apputils/src/index.ts @@ -21,6 +21,7 @@ export * from './spinner'; export * from './splash'; export * from './styling'; export * from './thememanager'; +export * from './tokens'; export * from './toolbar'; export * from './vdom'; export * from './windowresolver'; From 9a70889bbf04e4a96fa626952ec7143255813347 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Wed, 22 May 2019 16:48:33 -0400 Subject: [PATCH 10/10] Revert from internal /lib/X imports The plan is to instead make index.ts side effect free, and push/pray for dependencies to use sideEffects flag + ES6 modules as well. --- packages/apputils-extension/src/index.ts | 2 +- packages/codemirror-extension/src/index.ts | 10 ++++------ packages/codemirror/src/index.ts | 2 +- packages/completer-extension/src/index.ts | 4 ++-- packages/console-extension/src/index.ts | 7 +++---- packages/csvviewer-extension/src/index.ts | 5 ++--- packages/docmanager-extension/src/index.ts | 2 +- packages/documentsearch-extension/src/index.ts | 2 +- packages/filebrowser-extension/src/index.ts | 2 +- packages/filebrowser/src/browser.ts | 2 +- packages/fileeditor-extension/src/index.ts | 11 ++++------- packages/inspector-extension/src/index.ts | 2 +- packages/mainmenu-extension/src/index.ts | 2 +- packages/notebook-extension/src/index.ts | 11 ++++------- packages/rendermime-extension/src/index.ts | 2 +- packages/settingeditor-extension/src/index.ts | 2 +- packages/statusbar-extension/src/index.ts | 13 +++++++------ packages/terminal-extension/src/index.ts | 4 ++-- packages/tooltip-extension/src/index.ts | 4 ++-- 19 files changed, 40 insertions(+), 49 deletions(-) diff --git a/packages/apputils-extension/src/index.ts b/packages/apputils-extension/src/index.ts index 92dc734a6abf..86fae3d1680d 100644 --- a/packages/apputils-extension/src/index.ts +++ b/packages/apputils-extension/src/index.ts @@ -29,7 +29,7 @@ import { URLExt } from '@jupyterlab/coreutils'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IMainMenu } from '@jupyterlab/mainmenu'; import { CommandRegistry } from '@phosphor/commands'; diff --git a/packages/codemirror-extension/src/index.ts b/packages/codemirror-extension/src/index.ts index 06c5a9ac038b..492cad2b8f70 100644 --- a/packages/codemirror-extension/src/index.ts +++ b/packages/codemirror-extension/src/index.ts @@ -11,10 +11,9 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IEditMenu } from '@jupyterlab/mainmenu'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IEditMenu, IMainMenu } from '@jupyterlab/mainmenu'; -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; +import { IEditorServices } from '@jupyterlab/codeeditor'; import { editorServices, @@ -23,12 +22,11 @@ import { Mode } from '@jupyterlab/codemirror'; -import { ISettingRegistry } from '@jupyterlab/coreutils/lib/tokens'; +import { ISettingRegistry } from '@jupyterlab/coreutils'; import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; -import { FileEditor } from '@jupyterlab/fileeditor'; +import { IEditorTracker, FileEditor } from '@jupyterlab/fileeditor'; import { IStatusBar } from '@jupyterlab/statusbar'; diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts index 7194fc92caba..c2ac7d3faf79 100644 --- a/packages/codemirror/src/index.ts +++ b/packages/codemirror/src/index.ts @@ -1,7 +1,7 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; +import { IEditorServices } from '@jupyterlab/codeeditor'; import { CodeMirrorEditorFactory } from './factory'; diff --git a/packages/completer-extension/src/index.ts b/packages/completer-extension/src/index.ts index 46d9b8fcb654..f29b4b41c138 100644 --- a/packages/completer-extension/src/index.ts +++ b/packages/completer-extension/src/index.ts @@ -15,9 +15,9 @@ import { ICompletionManager } from '@jupyterlab/completer'; -import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; +import { IConsoleTracker } from '@jupyterlab/console'; -import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; +import { IEditorTracker } from '@jupyterlab/fileeditor'; import { INotebookTracker } from '@jupyterlab/notebook'; diff --git a/packages/console-extension/src/index.ts b/packages/console-extension/src/index.ts index c8a4d8a6f3ed..07852e9050d1 100644 --- a/packages/console-extension/src/index.ts +++ b/packages/console-extension/src/index.ts @@ -16,13 +16,13 @@ import { showDialog } from '@jupyterlab/apputils'; -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; +import { IEditorServices } from '@jupyterlab/codeeditor'; import { ConsolePanel, IConsoleTracker } from '@jupyterlab/console'; import { ISettingRegistry, PageConfig } from '@jupyterlab/coreutils'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; import { ILauncher } from '@jupyterlab/launcher'; @@ -31,11 +31,10 @@ import { IFileMenu, IHelpMenu, IKernelMenu, + IMainMenu, IRunMenu } from '@jupyterlab/mainmenu'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; - import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { find } from '@phosphor/algorithm'; diff --git a/packages/csvviewer-extension/src/index.ts b/packages/csvviewer-extension/src/index.ts index e64bff29832e..1fb63c1985e7 100644 --- a/packages/csvviewer-extension/src/index.ts +++ b/packages/csvviewer-extension/src/index.ts @@ -9,7 +9,7 @@ import { import { InstanceTracker, IThemeManager, Dialog } from '@jupyterlab/apputils'; -import { ISearchProviderRegistry } from '@jupyterlab/documentsearch/lib/tokens'; +import { ISearchProviderRegistry } from '@jupyterlab/documentsearch'; import { CSVViewer, @@ -22,8 +22,7 @@ import { IDocumentWidget } from '@jupyterlab/docregistry'; import { DataGrid } from '@phosphor/datagrid'; -import { IEditMenu } from '@jupyterlab/mainmenu'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IEditMenu, IMainMenu } from '@jupyterlab/mainmenu'; import { CSVSearchProvider } from './searchprovider'; /** diff --git a/packages/docmanager-extension/src/index.ts b/packages/docmanager-extension/src/index.ts index 30f7583cd482..b06d77308d18 100644 --- a/packages/docmanager-extension/src/index.ts +++ b/packages/docmanager-extension/src/index.ts @@ -32,7 +32,7 @@ import { import { DocumentRegistry } from '@jupyterlab/docregistry'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IMainMenu } from '@jupyterlab/mainmenu'; import { Contents, Kernel } from '@jupyterlab/services'; diff --git a/packages/documentsearch-extension/src/index.ts b/packages/documentsearch-extension/src/index.ts index 7c6316b10fd1..3655cce2f5b2 100644 --- a/packages/documentsearch-extension/src/index.ts +++ b/packages/documentsearch-extension/src/index.ts @@ -17,7 +17,7 @@ import { NotebookSearchProvider } from '@jupyterlab/documentsearch'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IMainMenu } from '@jupyterlab/mainmenu'; import { Widget } from '@phosphor/widgets'; const SEARCHABLE_CLASS = 'jp-mod-searchable'; diff --git a/packages/filebrowser-extension/src/index.ts b/packages/filebrowser-extension/src/index.ts index e4fc3087c424..0e90fdac8bf8 100644 --- a/packages/filebrowser-extension/src/index.ts +++ b/packages/filebrowser-extension/src/index.ts @@ -24,7 +24,7 @@ import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; +import { IDocumentManager } from '@jupyterlab/docmanager'; import { FileBrowserModel, diff --git a/packages/filebrowser/src/browser.ts b/packages/filebrowser/src/browser.ts index a67b2455ff79..7ce79de8f0bb 100644 --- a/packages/filebrowser/src/browser.ts +++ b/packages/filebrowser/src/browser.ts @@ -3,7 +3,7 @@ import { showErrorMessage, Toolbar, ToolbarButton } from '@jupyterlab/apputils'; -import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; +import { IDocumentManager } from '@jupyterlab/docmanager'; import { Contents, ServerConnection } from '@jupyterlab/services'; diff --git a/packages/fileeditor-extension/src/index.ts b/packages/fileeditor-extension/src/index.ts index 3a2cdd8bba62..a2e49021fa94 100644 --- a/packages/fileeditor-extension/src/index.ts +++ b/packages/fileeditor-extension/src/index.ts @@ -9,11 +9,9 @@ import { import { ICommandPalette, InstanceTracker } from '@jupyterlab/apputils'; -import { CodeEditor } from '@jupyterlab/codeeditor'; +import { CodeEditor, IEditorServices } from '@jupyterlab/codeeditor'; -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; - -import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; +import { IConsoleTracker } from '@jupyterlab/console'; import { ISettingRegistry, @@ -23,7 +21,7 @@ import { import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; import { FileEditor, @@ -37,12 +35,11 @@ import { ILauncher } from '@jupyterlab/launcher'; import { IEditMenu, IFileMenu, + IMainMenu, IRunMenu, IViewMenu } from '@jupyterlab/mainmenu'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; - import { IStatusBar } from '@jupyterlab/statusbar'; import { JSONObject, ReadonlyJSONObject } from '@phosphor/coreutils'; diff --git a/packages/inspector-extension/src/index.ts b/packages/inspector-extension/src/index.ts index a6f31723f114..9b92a574ceab 100644 --- a/packages/inspector-extension/src/index.ts +++ b/packages/inspector-extension/src/index.ts @@ -14,7 +14,7 @@ import { MainAreaWidget } from '@jupyterlab/apputils'; -import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; +import { IConsoleTracker } from '@jupyterlab/console'; import { IInspector, diff --git a/packages/mainmenu-extension/src/index.ts b/packages/mainmenu-extension/src/index.ts index 8443b275875f..34fef724b4c0 100644 --- a/packages/mainmenu-extension/src/index.ts +++ b/packages/mainmenu-extension/src/index.ts @@ -18,7 +18,7 @@ import { ICommandPalette, showDialog, Dialog } from '@jupyterlab/apputils'; import { PageConfig, URLExt } from '@jupyterlab/coreutils'; -import { IInspector } from '@jupyterlab/inspector/lib/tokens'; +import { IInspector } from '@jupyterlab/inspector'; import { IMainMenu, diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index fd1c21b25f62..e1b127da5ddb 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -18,9 +18,7 @@ import { import { CodeCell } from '@jupyterlab/cells'; -import { CodeEditor } from '@jupyterlab/codeeditor'; - -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; +import { CodeEditor, IEditorServices } from '@jupyterlab/codeeditor'; import { ISettingRegistry, @@ -29,7 +27,7 @@ import { PageConfig } from '@jupyterlab/coreutils'; -import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; +import { IDocumentManager } from '@jupyterlab/docmanager'; import { ArrayExt } from '@phosphor/algorithm'; @@ -37,7 +35,7 @@ import { UUID } from '@phosphor/coreutils'; import { DisposableSet } from '@phosphor/disposable'; -import { IFileBrowserFactory } from '@jupyterlab/filebrowser/lib/tokens'; +import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; import { ILauncher } from '@jupyterlab/launcher'; @@ -46,12 +44,11 @@ import { IFileMenu, IHelpMenu, IKernelMenu, + IMainMenu, IRunMenu, IViewMenu } from '@jupyterlab/mainmenu'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; - import { NotebookTools, INotebookTools, diff --git a/packages/rendermime-extension/src/index.ts b/packages/rendermime-extension/src/index.ts index b4dc6a4a5367..abb205600cb8 100644 --- a/packages/rendermime-extension/src/index.ts +++ b/packages/rendermime-extension/src/index.ts @@ -8,7 +8,7 @@ import { JupyterFrontEndPlugin } from '@jupyterlab/application'; -import { IDocumentManager } from '@jupyterlab/docmanager/lib/tokens'; +import { IDocumentManager } from '@jupyterlab/docmanager'; import { ILatexTypesetter, diff --git a/packages/settingeditor-extension/src/index.ts b/packages/settingeditor-extension/src/index.ts index d91b337d31ed..d3477e58b759 100644 --- a/packages/settingeditor-extension/src/index.ts +++ b/packages/settingeditor-extension/src/index.ts @@ -15,7 +15,7 @@ import { MainAreaWidget } from '@jupyterlab/apputils'; -import { IEditorServices } from '@jupyterlab/codeeditor/lib/tokens'; +import { IEditorServices } from '@jupyterlab/codeeditor'; import { ISettingRegistry, IStateDB } from '@jupyterlab/coreutils'; diff --git a/packages/statusbar-extension/src/index.ts b/packages/statusbar-extension/src/index.ts index 79aee6c63b15..229fbaf3f3fa 100644 --- a/packages/statusbar-extension/src/index.ts +++ b/packages/statusbar-extension/src/index.ts @@ -11,14 +11,15 @@ import { IClientSession, ICommandPalette } from '@jupyterlab/apputils'; import { Cell, CodeCell } from '@jupyterlab/cells'; -import { CodeConsole, ConsolePanel } from '@jupyterlab/console'; - -import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; +import { + CodeConsole, + ConsolePanel, + IConsoleTracker +} from '@jupyterlab/console'; import { IDocumentWidget } from '@jupyterlab/docregistry'; -import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; -import { FileEditor } from '@jupyterlab/fileeditor'; +import { FileEditor, IEditorTracker } from '@jupyterlab/fileeditor'; import { INotebookTracker, @@ -37,7 +38,7 @@ import { import { ISettingRegistry } from '@jupyterlab/coreutils'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IMainMenu } from '@jupyterlab/mainmenu'; import { Title, Widget } from '@phosphor/widgets'; diff --git a/packages/terminal-extension/src/index.ts b/packages/terminal-extension/src/index.ts index 362aeb152c9c..498c8f1486e2 100644 --- a/packages/terminal-extension/src/index.ts +++ b/packages/terminal-extension/src/index.ts @@ -18,9 +18,9 @@ import { import { ILauncher } from '@jupyterlab/launcher'; -import { IMainMenu } from '@jupyterlab/mainmenu/lib/tokens'; +import { IMainMenu } from '@jupyterlab/mainmenu'; -import { ITerminalTracker, ITerminal } from '@jupyterlab/terminal/lib/tokens'; +import { ITerminalTracker, ITerminal } from '@jupyterlab/terminal'; // Name-only import so as to not trigger inclusion in main bundle import * as WidgetModuleType from '@jupyterlab/terminal/lib/widget'; diff --git a/packages/tooltip-extension/src/index.ts b/packages/tooltip-extension/src/index.ts index c828070575a2..8d214b27dc1d 100644 --- a/packages/tooltip-extension/src/index.ts +++ b/packages/tooltip-extension/src/index.ts @@ -18,9 +18,9 @@ import { import { CodeEditor } from '@jupyterlab/codeeditor'; -import { IConsoleTracker } from '@jupyterlab/console/lib/tokens'; +import { IConsoleTracker } from '@jupyterlab/console'; -import { IEditorTracker } from '@jupyterlab/fileeditor/lib/tokens'; +import { IEditorTracker } from '@jupyterlab/fileeditor'; import { INotebookTracker } from '@jupyterlab/notebook';