Browse Source

wip rendermime refactor

Steven Silvester 7 years ago
parent
commit
8f95ec35ed

+ 3 - 0
packages/application/package.json

@@ -15,6 +15,9 @@
   "dependencies": {
   "dependencies": {
     "@jupyterlab/apputils": "^0.7.0",
     "@jupyterlab/apputils": "^0.7.0",
     "@jupyterlab/coreutils": "^0.7.0",
     "@jupyterlab/coreutils": "^0.7.0",
+    "@jupyterlab/docregistry": "^0.7.0",
+    "@jupyterlab/rendermime": "^0.7.0",
+    "@jupyterlab/rendermime-interfaces": "^0.1.0",
     "@phosphor/algorithm": "^1.1.1",
     "@phosphor/algorithm": "^1.1.1",
     "@phosphor/application": "^1.3.0",
     "@phosphor/application": "^1.3.0",
     "@phosphor/coreutils": "^1.1.1",
     "@phosphor/coreutils": "^1.1.1",

+ 87 - 0
packages/application/src/index.ts

@@ -1,6 +1,16 @@
 // Copyright (c) Jupyter Development Team.
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
+import {
+  CommandLinker
+} from '@jupyterlab/apputils';
+
+import {
+  IRenderMime, RenderMime,
+  HTMLRenderer, LatexRenderer, ImageRenderer, TextRenderer,
+  JavaScriptRenderer, SVGRenderer, MarkdownRenderer, PDFRenderer
+} from '@jupyterlab/rendermime';
+
 import {
 import {
   Application, IPlugin
   Application, IPlugin
 } from '@phosphor/application';
 } from '@phosphor/application';
@@ -42,8 +52,27 @@ class JupyterLab extends Application<ApplicationShell> {
     if (options.devMode) {
     if (options.devMode) {
       this.shell.addClass('jp-mod-devMode');
       this.shell.addClass('jp-mod-devMode');
     }
     }
+    let linker = this.linker = new CommandLinker({ commands: this.commands });
+
+    let items = Private.getDefaultRendererItems();
+    let linkHandler = {
+      handleLink: (node: HTMLElement, path: string) => {
+        linker.connectNode(node, 'file-operations:open', { path });
+      }
+    };
+    this.rendermime = new RenderMime({ items, linkHandler });
   }
   }
 
 
+  /**
+   * The rendermime instance used by the application.
+   */
+  readonly rendermime: RenderMime;
+
+  /**
+   * The command linker used by the application.
+   */
+  readonly linker: CommandLinker;
+
   /**
   /**
    * The information about the application.
    * The information about the application.
    */
    */
@@ -87,6 +116,28 @@ class JupyterLab extends Application<ApplicationShell> {
     mods.forEach(mod => { this.registerPluginModule(mod); });
     mods.forEach(mod => { this.registerPluginModule(mod); });
   }
   }
 
 
+  /**
+   * Register a rendermime extension module.
+   */
+  registerMimeModule(mod: IRenderMime.IExtensionModule): void {
+    let data = mod.default;
+    // Handle commonjs exports.
+    if (!mod.hasOwnProperty('__esModule')) {
+      data = mod as any;
+    }
+    if (!Array.isArray(data)) {
+      data = [data];
+    }
+    let rendermime = this.rendermime;
+
+    data.forEach(item => {
+      rendermime.addRenderer({
+        mimeType: item.mimeType,
+        renderer: item.renderer
+      }, item.rendererIndex || 0);
+    });
+  }
+
   private _info: JupyterLab.IInfo;
   private _info: JupyterLab.IInfo;
 }
 }
 
 
@@ -186,3 +237,39 @@ namespace JupyterLab {
     default: JupyterLabPlugin<any> | JupyterLabPlugin<any>[];
     default: JupyterLabPlugin<any> | JupyterLabPlugin<any>[];
   }
   }
 }
 }
+
+
+/**
+ * The namespace for module private data.
+ */
+export
+namespace Private {
+  /**
+   * Get an array of the default renderer items.
+   */
+  export
+  function getDefaultRendererItems(): RenderMime.IRendererItem[] {
+    let renderers = [
+    new JavaScriptRenderer(),
+    new HTMLRenderer(),
+    new MarkdownRenderer(),
+    new LatexRenderer(),
+    new SVGRenderer(),
+    new ImageRenderer(),
+    new PDFRenderer(),
+    new TextRenderer()
+    ];
+    let items: RenderMime.IRendererItem[] = [];
+    let mimes: { [key: string]: boolean } = {};
+    for (let renderer of renderers) {
+      for (let mime of renderer.mimeTypes) {
+        if (mime in mimes) {
+          continue;
+        }
+        mimes[mime] = true;
+        items.push({ mimeType: mime, renderer });
+      }
+    }
+    return items;
+  }
+}

+ 67 - 2
packages/application/src/layoutrestorer.ts

@@ -27,6 +27,10 @@ import {
   IStateDB
   IStateDB
 } from '@jupyterlab/coreutils';
 } from '@jupyterlab/coreutils';
 
 
+import {
+  DocumentRegistry
+} from '@jupyterlab/docregistry';
+
 import {
 import {
   ApplicationShell
   ApplicationShell
 } from '.';
 } from '.';
@@ -64,7 +68,14 @@ interface ILayoutRestorer {
    *
    *
    * @param options - The restoration options.
    * @param options - The restoration options.
    */
    */
-  restore(tracker: InstanceTracker<any>, options: ILayoutRestorer.IRestoreOptions<any>): void;
+  restoreTracker(tracker: InstanceTracker<any>, options: ILayoutRestorer.IRestoreOptions<any>): void;
+
+  /**
+   * Restore the widgets of a particular widget factory.
+   *
+   * @param factory - The factory whose widgets will be restored.
+   */
+  restoreWidgetFactory(factory: DocumentRegistry.IWidgetFactory): void;
 }
 }
 
 
 
 
@@ -235,7 +246,7 @@ class LayoutRestorer implements ILayoutRestorer {
    *
    *
    * @param options - The restoration options.
    * @param options - The restoration options.
    */
    */
-  restore(tracker: InstanceTracker<Widget>, options: ILayoutRestorer.IRestoreOptions<Widget>): Promise<any> {
+  restoreTracker(tracker: InstanceTracker<Widget>, options: ILayoutRestorer.IRestoreOptions<Widget>): Promise<any> {
     if (!this._promises) {
     if (!this._promises) {
       const warning = 'restore() can only be called before `first` has resolved.';
       const warning = 'restore() can only be called before `first` has resolved.';
       console.warn(warning);
       console.warn(warning);
@@ -274,6 +285,60 @@ class LayoutRestorer implements ILayoutRestorer {
     return promise;
     return promise;
   }
   }
 
 
+  /**
+   * Restore the widgets of a particular widget factory.
+   *
+   * @param factory - The factory whose widgets will be restored.
+   */
+  restoreWidgetFactory(factory: DocumentRegistry.IWidgetFactory): void {
+    if (!this._promises) {
+      const warning = 'restore() can only be called before `first` has resolved.';
+      console.warn(warning);
+      return Promise.reject(warning);
+    }
+    let state = this._state;
+
+    // Whenever a new widget is added to the tracker, record its name.
+    factory.widgetCreated.connect((sender, widget) => {
+      let name = `${factory.name}:${widget.context.path}`;
+      let data = {
+        path: widget.context.path,
+        factory: factory.name;
+      };
+      this.add(widget, name);
+      state.save(name, { data });
+
+      // Update the widget name when the path changes.
+      widget.context.pathChanged.connect(() => {
+        let newName = `${factory.name}:${widget.context.path}`;
+        Private.nameProperty.set(widget, newName);
+        this._widgets.set(newName, widget);
+        state.remove(name);
+        data = {
+          path: widget.context.path,
+          factory: factory.name;
+        };
+        state.save(newName, { data });
+        name = newName;
+      }, this);
+    }, this);
+
+    let promises = [state.fetchNamespace(factory.name)];
+    let registry = this._registry;
+
+    return this._first.then(() = {
+      return Promise.all(promises);
+    }).then([saved] => {
+      return Promise.all(saved.map(item => {
+        let args = (item.value as any).data;
+        let command = 'file-operations: open';
+        // Execute the command and if it fails, delete the state restore data.
+        return registry.execute(command, args)
+          .catch(() => { state.remove(item.id); });
+      }));
+    });
+  }
+
   /**
   /**
    * Save the layout state for the application.
    * Save the layout state for the application.
    */
    */

+ 2 - 88
packages/apputils/src/commandlinker.ts

@@ -4,7 +4,7 @@
 |----------------------------------------------------------------------------*/
 |----------------------------------------------------------------------------*/
 
 
 import {
 import {
-  JSONObject, Token
+  JSONObject
 } from '@phosphor/coreutils';
 } from '@phosphor/coreutils';
 
 
 import {
 import {
@@ -31,98 +31,12 @@ const COMMAND_ATTR = 'commandlinker-command';
 const ARGS_ATTR = 'commandlinker-args';
 const ARGS_ATTR = 'commandlinker-args';
 
 
 
 
-/* tslint:disable */
-/**
- * The command linker token.
- */
-export
-const ICommandLinker = new Token<ICommandLinker>('jupyter.services.command-linker');
-/* tslint:enable */
-
-
-/**
- * A helper class to generate clickables that execute commands.
- */
-export
-interface ICommandLinker extends IDisposable {
-  /**
-   * Connect a command/argument pair to a given node so that when it is clicked,
-   * the command will execute.
-   *
-   * @param node - The node being connected.
-   *
-   * @param command - The command ID to execute upon click.
-   *
-   * @param args - The arguments with which to invoke the command.
-   *
-   * @returns The same node that was passed in, after it has been connected.
-   *
-   * #### Notes
-   * Only `click` events will execute the command on a connected node. So, there
-   * are two considerations that are relevant:
-   * 1. If a node is connected, the default click action will be prevented.
-   * 2. The `HTMLElement` passed in should be clickable.
-   */
-  connectNode(node: HTMLElement, command: string, args: JSONObject): HTMLElement;
-
-  /**
-   * Disconnect a node that has been connected to execute a command on click.
-   *
-   * @param node - The node being disconnected.
-   *
-   * @returns The same node that was passed in, after it has been disconnected.
-   *
-   * #### Notes
-   * This method is safe to call multiple times and is safe to call on nodes
-   * that were never connected.
-   *
-   * This method can be called on rendered virtual DOM nodes that were populated
-   * using the `populateVNodeDataset` method in order to disconnect them from
-   * executing their command/argument pair.
-   */
-  disconnectNode(node: HTMLElement): HTMLElement;
-
-  /**
-   * Populate the `dataset` attribute within the collection of attributes used
-   * to instantiate a virtual DOM node with the values necessary for its
-   * rendered DOM node to respond to clicks by executing a command/argument
-   * pair.
-   *
-   * @param command - The command ID to execute upon click.
-   *
-   * @param args - The arguments with which to invoke the command.
-   *
-   * @returns A `dataset` collection for use within virtual node attributes.
-   *
-   * #### Notes
-   * The return value can be used on its own as the value for the `dataset`
-   * attribute of a virtual element, or it can be added to an existing `dataset`
-   * as in the example below.
-   *
-   * #### Example
-   * ```typescript
-   * let command = 'some:command-id';
-   * let args = { alpha: 'beta' };
-   * let anchor = h.a({
-   *   className: 'some-class',
-   *   dataset: {
-   *     foo: '1',
-   *     bar: '2',
-   *     ../...linker.populateVNodeDataset(command, args)
-   *   }
-   * }, 'some text');
-   * ```
-   */
-  populateVNodeDataset(command: string, args: JSONObject): ElementDataset;
-}
-
-
 /**
 /**
  * A static class that provides helper methods to generate clickable nodes that
  * A static class that provides helper methods to generate clickable nodes that
  * execute registered commands with pre-populated arguments.
  * execute registered commands with pre-populated arguments.
  */
  */
 export
 export
-class CommandLinker implements ICommandLinker {
+class CommandLinker implements IDisposable {
   /**
   /**
    * Instantiate a new command linker.
    * Instantiate a new command linker.
    */
    */

+ 6 - 6
packages/cells/src/widget.ts

@@ -32,7 +32,7 @@ import {
 } from '@jupyterlab/codeeditor';
 } from '@jupyterlab/codeeditor';
 
 
 import {
 import {
-  MimeModel, IRenderMime
+  MimeModel, RenderMime
 } from '@jupyterlab/rendermime';
 } from '@jupyterlab/rendermime';
 
 
 import {
 import {
@@ -166,7 +166,7 @@ const RENDER_TIMEOUT = 1000;
  * A base cell widget.
  * A base cell widget.
  */
  */
 export
 export
-class Cell extends Widget implements IRenderMime.IReadyWidget {
+class Cell extends Widget implements RenderMime.IReadyWidget {
   /**
   /**
    * Construct a new base cell widget.
    * Construct a new base cell widget.
    */
    */
@@ -668,7 +668,7 @@ class CodeCell extends Cell {
     this.toggleClass(NO_OUTPUTS_CLASS, force);
     this.toggleClass(NO_OUTPUTS_CLASS, force);
   }
   }
 
 
-  private _rendermime: IRenderMime = null;
+  private _rendermime: RenderMime = null;
   private _outputHidden = false;
   private _outputHidden = false;
   private _outputWrapper: Widget = null;
   private _outputWrapper: Widget = null;
   private _outputCollapser: OutputCollapser = null;
   private _outputCollapser: OutputCollapser = null;
@@ -695,7 +695,7 @@ namespace CodeCell {
     /**
     /**
      * The mime renderer for the cell widget.
      * The mime renderer for the cell widget.
      */
      */
-    rendermime: IRenderMime;
+    rendermime: RenderMime;
   }
   }
 
 
   /**
   /**
@@ -861,7 +861,7 @@ class MarkdownCell extends Cell {
   }
   }
 
 
   private _monitor: ActivityMonitor<any, any> = null;
   private _monitor: ActivityMonitor<any, any> = null;
-  private _rendermime: IRenderMime = null;
+  private _rendermime: RenderMime = null;
   private _renderedInput: Widget = null;
   private _renderedInput: Widget = null;
   private _rendered = true;
   private _rendered = true;
   private _prevText = '';
   private _prevText = '';
@@ -889,7 +889,7 @@ namespace MarkdownCell {
     /**
     /**
      * The mime renderer for the cell widget.
      * The mime renderer for the cell widget.
      */
      */
-    rendermime: IRenderMime;
+    rendermime: RenderMime;
 
 
   }
   }
 }
 }

+ 3 - 3
packages/chatbox-extension/src/index.ts

@@ -22,7 +22,7 @@ import {
 } from '@jupyterlab/chatbox';
 } from '@jupyterlab/chatbox';
 
 
 import {
 import {
-  IRenderMime
+  RenderMime
 } from '@jupyterlab/rendermime';
 } from '@jupyterlab/rendermime';
 
 
 
 
@@ -47,7 +47,7 @@ namespace CommandIDs {
 export
 export
 const chatboxPlugin: JupyterLabPlugin<void> = {
 const chatboxPlugin: JupyterLabPlugin<void> = {
   id: 'jupyter.extensions.chatbox',
   id: 'jupyter.extensions.chatbox',
-  requires: [IRenderMime, ICommandPalette, IEditorServices, IDocumentManager, ILayoutRestorer],
+  requires: [RenderMime, ICommandPalette, IEditorServices, IDocumentManager, ILayoutRestorer],
   autoStart: true,
   autoStart: true,
   activate: activateChatbox
   activate: activateChatbox
 };
 };
@@ -62,7 +62,7 @@ export default chatboxPlugin;
 /**
 /**
  * Activate the chatbox extension.
  * Activate the chatbox extension.
  */
  */
-function activateChatbox(app: JupyterLab, rendermime: IRenderMime, palette: ICommandPalette, editorServices: IEditorServices, docManager: IDocumentManager, restorer: ILayoutRestorer): void {
+function activateChatbox(app: JupyterLab, rendermime: RenderMime, palette: ICommandPalette, editorServices: IEditorServices, docManager: IDocumentManager, restorer: ILayoutRestorer): void {
   const id = 'chatbox';
   const id = 'chatbox';
   let { commands, shell } = app;
   let { commands, shell } = app;
   let category = 'Chatbox';
   let category = 'Chatbox';

+ 2 - 3
packages/console-extension/src/index.ts

@@ -23,7 +23,7 @@ import {
 } from '@jupyterlab/launcher';
 } from '@jupyterlab/launcher';
 
 
 import {
 import {
-  IRenderMime
+  RenderMime
 } from '@jupyterlab/rendermime';
 } from '@jupyterlab/rendermime';
 
 
 import {
 import {
@@ -91,7 +91,6 @@ const trackerPlugin: JupyterLabPlugin<IConsoleTracker> = {
   provides: IConsoleTracker,
   provides: IConsoleTracker,
   requires: [
   requires: [
     IServiceManager,
     IServiceManager,
-    IRenderMime,
     IMainMenu,
     IMainMenu,
     ICommandPalette,
     ICommandPalette,
     ConsolePanel.IContentFactory,
     ConsolePanel.IContentFactory,
@@ -131,7 +130,7 @@ export default plugins;
 /**
 /**
  * Activate the console extension.
  * Activate the console extension.
  */
  */
-function activateConsole(app: JupyterLab, manager: IServiceManager, rendermime: IRenderMime, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: ConsolePanel.IContentFactory,  editorServices: IEditorServices, restorer: ILayoutRestorer, launcher: ILauncher | null): IConsoleTracker {
+function activateConsole(app: JupyterLab, manager: IServiceManager, rendermime: RenderMime, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: ConsolePanel.IContentFactory,  editorServices: IEditorServices, restorer: ILayoutRestorer, launcher: ILauncher | null): IConsoleTracker {
   let { commands, shell } = app;
   let { commands, shell } = app;
   let category = 'Console';
   let category = 'Console';
   let command: string;
   let command: string;

+ 7 - 7
packages/docregistry/src/default.ts

@@ -34,7 +34,7 @@ import {
 } from '@jupyterlab/coreutils';
 } from '@jupyterlab/coreutils';
 
 
 import {
 import {
-  IRenderMime, MimeModel
+  RenderMime, MimeModel
 } from '@jupyterlab/rendermime';
 } from '@jupyterlab/rendermime';
 
 
 import {
 import {
@@ -288,7 +288,7 @@ class Base64ModelFactory extends TextModelFactory {
  * The default implemetation of a widget factory.
  * The default implemetation of a widget factory.
  */
  */
 export
 export
-abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U extends DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
+abstract class ABCWidgetFactory<T extends DocumentRegistry.IDocumentWidget<U>, U extends DocumentRegistry.IModel> implements DocumentRegistry.IWidgetFactory<T, U> {
   /**
   /**
    * Construct a new `ABCWidgetFactory`.
    * Construct a new `ABCWidgetFactory`.
    */
    */
@@ -406,7 +406,7 @@ abstract class ABCWidgetFactory<T extends DocumentRegistry.IReadyWidget, U exten
  * A widget for rendered mimetype.
  * A widget for rendered mimetype.
  */
  */
 export
 export
-class MimeRenderer extends Widget implements IRenderMime.IReadyWidget {
+class MimeRenderer extends Widget implements DocumentRegistry.IDocumentWidget<DocumentRegistry.IModel> {
   /**
   /**
    * Construct a new markdown widget.
    * Construct a new markdown widget.
    */
    */
@@ -516,7 +516,7 @@ class MimeRenderer extends Widget implements IRenderMime.IReadyWidget {
 
 
   private _context: DocumentRegistry.Context = null;
   private _context: DocumentRegistry.Context = null;
   private _monitor: ActivityMonitor<any, any> = null;
   private _monitor: ActivityMonitor<any, any> = null;
-  private _rendermime: IRenderMime = null;
+  private _rendermime: RenderMime = null;
   private _mimeType: string;
   private _mimeType: string;
   private _ready = new PromiseDelegate<void>();
   private _ready = new PromiseDelegate<void>();
   private _dataType: 'string' | 'json';
   private _dataType: 'string' | 'json';
@@ -541,7 +541,7 @@ namespace MimeRenderer {
     /**
     /**
      * The rendermime instance.
      * The rendermime instance.
      */
      */
-    rendermime: IRenderMime;
+    rendermime: RenderMime;
 
 
     /**
     /**
      * The mime type.
      * The mime type.
@@ -595,7 +595,7 @@ class MimeRendererFactory extends ABCWidgetFactory<MimeRenderer, DocumentRegistr
     return widget;
     return widget;
   }
   }
 
 
-  private _rendermime: IRenderMime = null;
+  private _rendermime: RenderMime = null;
   private _mimeType: string;
   private _mimeType: string;
   private _renderTimeout: number;
   private _renderTimeout: number;
   private _dataType: 'string' | 'json';
   private _dataType: 'string' | 'json';
@@ -617,7 +617,7 @@ namespace MimeRendererFactory {
     /**
     /**
      * The rendermime instance.
      * The rendermime instance.
      */
      */
-    rendermime: IRenderMime;
+    rendermime: RenderMime;
 
 
     /**
     /**
      * The mime type.
      * The mime type.

+ 8 - 3
packages/docregistry/src/registry.ts

@@ -779,13 +779,18 @@ namespace DocumentRegistry {
    * A widget for a document.
    * A widget for a document.
    */
    */
   export
   export
-  interface IReadyWidget extends IRenderMime.IReadyWidget { }
+  interface IDocumentWidget<T extends IModel> extends IRenderMime.IReadyWidget {
+    /**
+     * The context associated with the widget.
+     */
+    context: IContext<T>;
+  }
 
 
   /**
   /**
    * The interface for a widget factory.
    * The interface for a widget factory.
    */
    */
   export
   export
-  interface IWidgetFactory<T extends IReadyWidget, U extends IModel> extends IDisposable, IWidgetFactoryOptions {
+  interface IWidgetFactory<T extends IDocumentWidget<U>, U extends IModel> extends IDisposable, IWidgetFactoryOptions {
     /**
     /**
      * A signal emitted when a widget is created.
      * A signal emitted when a widget is created.
      */
      */
@@ -804,7 +809,7 @@ namespace DocumentRegistry {
    * A type alias for a standard widget factory.
    * A type alias for a standard widget factory.
    */
    */
   export
   export
-  type WidgetFactory = IWidgetFactory<IReadyWidget, IModel>;
+  type WidgetFactory = IWidgetFactory<IDocumentWidget<IModel>, IModel>;
 
 
   /**
   /**
    * An interface for a widget extension.
    * An interface for a widget extension.

+ 0 - 1
packages/rendermime-interfaces/package.json

@@ -12,7 +12,6 @@
     "lib": "lib/"
     "lib": "lib/"
   },
   },
   "dependencies": {
   "dependencies": {
-    "@phosphor/algorithm": "^1.1.1",
     "@phosphor/coreutils": "^1.1.1",
     "@phosphor/coreutils": "^1.1.1",
     "@phosphor/widgets": "^1.3.0"
     "@phosphor/widgets": "^1.3.0"
   },
   },

+ 2 - 120
packages/rendermime-interfaces/src/index.ts

@@ -2,11 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
 import {
 import {
-  IIterable
-} from '@phosphor/algorithm';
-
-import {
-  JSONValue, Token
+  JSONValue
 } from '@phosphor/coreutils';
 } from '@phosphor/coreutils';
 
 
 import {
 import {
@@ -14,125 +10,11 @@ import {
 } from '@phosphor/widgets';
 } from '@phosphor/widgets';
 
 
 
 
-/* tslint:disable */
-/**
- * The rendermime token.
- */
-export
-const IRenderMime = new Token<IRenderMime>('jupyter.services.rendermime');
-/* tslint:enable */
-
-
-/**
- * The rendermime interface.
- */
-export
-interface IRenderMime {
-  /**
-   * The object used to resolve relative urls for the rendermime instance.
-   */
-  resolver: IRenderMime.IResolver;
-
-  /**
-   * The object used to handle path opening links.
-   */
-  linkHandler: IRenderMime.ILinkHandler;
-
-  /**
-   * Get an iterator over the ordered list of mimeTypes.
-   *
-   * #### Notes
-   * These mimeTypes are searched from beginning to end, and the first matching
-   * mimeType is used.
-   */
-  mimeTypes(): IIterable<string>;
-
-  /**
-   * Render a mime model.
-   *
-   * @param model - the mime model to render.
-   *
-   * #### Notes
-   * Renders the model using the preferred mime type.  See
-   * [[preferredMimeType]].
-   */
-  render(model: IRenderMime.IMimeModel): IRenderMime.IReadyWidget;
-
-  /**
-   * Find the preferred mimeType for a model.
-   *
-   * @param model - the mime model of interest.
-   *
-   * #### Notes
-   * The mimeTypes in the model are checked in preference order
-   * until a renderer returns `true` for `.canRender`.
-   */
-  preferredMimeType(model: IRenderMime.IMimeModel): string;
-
-  /**
-   * Clone the rendermime instance with shallow copies of data.
-   *
-   * #### Notes
-   * The resolver is explicitly not cloned in this operation.
-   */
-  clone(): IRenderMime;
-
-  /**
-   * Add a renderer by mimeType.
-   *
-   * @param item - A renderer item.
-   *
-   * @param index - The optional order index.
-   *
-   * ####Notes
-   * Negative indices count from the end, so -1 refers to the last index.
-   * Use the index of `.order.length` to add to the end of the render precedence list,
-   * which would make the new renderer the last choice.
-   * The renderer will replace an existing renderer for the given
-   * mimeType.
-   */
-  addRenderer(item: IRenderMime.IRendererItem, index?: number): void;
-
-  /**
-   * Remove a renderer by mimeType.
-   *
-   * @param mimeType - The mimeType of the renderer.
-   */
-  removeRenderer(mimeType: string): void;
-
-  /**
-   * Get a renderer by mimeType.
-   *
-   * @param mimeType - The mimeType of the renderer.
-   *
-   * @returns The renderer for the given mimeType, or undefined if the mimeType is unknown.
-   */
-  getRenderer(mimeType: string): IRenderMime.IRenderer;
-}
-
-
 /**
 /**
- * A namespace for IRenderMime associated interfaces.
+ * A namespace for rendermime associated interfaces.
  */
  */
 export
 export
 namespace IRenderMime {
 namespace IRenderMime {
-  /**
-   * A render item.
-   */
-  export
-  interface IRendererItem {
-    /**
-     * The mimeType to be renderered.
-     */
-    mimeType: string;
-
-    /**
-     * The renderer.
-     */
-    renderer: IRenderer;
-  }
-
-
   /**
   /**
    * A bundle for mime data.
    * A bundle for mime data.
    */
    */

+ 0 - 2
packages/rendermime/src/index.ts

@@ -10,5 +10,3 @@ export * from './outputmodel';
 export * from './rendermime';
 export * from './rendermime';
 export * from './renderers';
 export * from './renderers';
 export * from './widgets';
 export * from './widgets';
-
-

+ 17 - 84
packages/rendermime/src/rendermime.ts

@@ -6,7 +6,7 @@ import {
 } from '@jupyterlab/services';
 } from '@jupyterlab/services';
 
 
 import {
 import {
-  ArrayExt, ArrayIterator, IIterable, find, iter, map, toArray
+  ArrayExt, find, map, toArray
 } from '@phosphor/algorithm';
 } from '@phosphor/algorithm';
 
 
 import {
 import {
@@ -25,11 +25,6 @@ import {
   MimeModel
   MimeModel
 } from './mimemodel';
 } from './mimemodel';
 
 
-import {
-  HTMLRenderer, LatexRenderer, ImageRenderer, TextRenderer,
-  JavaScriptRenderer, SVGRenderer, MarkdownRenderer, PDFRenderer
-} from './renderers';
-
 import {
 import {
   RenderedText
   RenderedText
 } from './widgets';
 } from './widgets';
@@ -43,7 +38,7 @@ import {
  * render the model into a widget.
  * render the model into a widget.
  */
  */
 export
 export
-class RenderMime implements IRenderMime {
+class RenderMime {
   /**
   /**
    * Construct a renderer.
    * Construct a renderer.
    */
    */
@@ -80,14 +75,10 @@ class RenderMime implements IRenderMime {
   }
   }
 
 
   /**
   /**
-   * Get an iterator over the ordered list of mimeTypes.
-   *
-   * #### Notes
-   * These mimeTypes are searched from beginning to end, and the first matching
-   * mimeType is used.
+   * The ordered list of mimeTypes.
    */
    */
-  mimeTypes(): IIterable<string> {
-    return new ArrayIterator(this._order);
+  get mimeTypes(): ReadonlyArray<string> {
+    return this._order;
   }
   }
 
 
   /**
   /**
@@ -169,12 +160,10 @@ class RenderMime implements IRenderMime {
    *
    *
    * ####Notes
    * ####Notes
    * Negative indices count from the end, so -1 refers to the last index.
    * Negative indices count from the end, so -1 refers to the last index.
-   * Use the index of `.order.length` to add to the end of the render precedence list,
-   * which would make the new renderer the last choice.
    * The renderer will replace an existing renderer for the given
    * The renderer will replace an existing renderer for the given
    * mimeType.
    * mimeType.
    */
    */
-  addRenderer(item: IRenderMime.IRendererItem, index = 0): void {
+  addRenderer(item: RenderMime.IRendererItem, index = 0): void {
     let { mimeType, renderer } = item;
     let { mimeType, renderer } = item;
     let orig = ArrayExt.removeFirstOf(this._order, mimeType);
     let orig = ArrayExt.removeFirstOf(this._order, mimeType);
     if (orig !== -1 && orig < index) {
     if (orig !== -1 && orig < index) {
@@ -244,7 +233,7 @@ namespace RenderMime {
     /**
     /**
      * The intial renderer items.
      * The intial renderer items.
      */
      */
-    items?: IRenderMime.IRendererItem[];
+    items?: IRendererItem[];
 
 
     /**
     /**
      * The sanitizer used to sanitize untrusted html inputs.
      * The sanitizer used to sanitize untrusted html inputs.
@@ -267,47 +256,19 @@ namespace RenderMime {
   }
   }
 
 
   /**
   /**
-   * Get an array of the default renderer items.
-   */
-  export
-  function getDefaultItems(): IRenderMime.IRendererItem[] {
-    let renderers = Private.defaultRenderers;
-    let items: IRenderMime.IRendererItem[] = [];
-    let mimes: { [key: string]: boolean } = {};
-    for (let renderer of renderers) {
-      for (let mime of renderer.mimeTypes) {
-        if (mime in mimes) {
-          continue;
-        }
-        mimes[mime] = true;
-        items.push({ mimeType: mime, renderer });
-      }
-    }
-    return items;
-  }
-
-  /**
-   * Register a rendermime extension module.
+   * A render item.
    */
    */
   export
   export
-  function registerExtensionModule(mod: IRenderMime.IExtensionModule): void {
-    let data = mod.default;
-    // Handle commonjs exports.
-    if (!mod.hasOwnProperty('__esModule')) {
-      data = mod as any;
-    }
-    if (!Array.isArray(data)) {
-      data = [data];
-    }
-    data.forEach(item => { Private.registeredExtensions.push(item); });
-  }
+  interface IRendererItem {
+    /**
+     * The mimeType to be renderered.
+     */
+    mimeType: string;
 
 
-  /**
-   * Get the registered extensions.
-   */
-  export
-  function getExtensions(): IIterable<IRenderMime.IExtension> {
-    return iter(Private.registeredExtensions);
+    /**
+     * The renderer.
+     */
+    renderer: IRenderMime.IRenderer;
   }
   }
 
 
   /**
   /**
@@ -364,31 +325,3 @@ namespace RenderMime {
     contents: Contents.IManager;
     contents: Contents.IManager;
   }
   }
 }
 }
-
-
-/**
- * The namespace for private module data.
- */
-export
-namespace Private {
-  /**
-   * The registered extensions.
-   */
-  export
-  const registeredExtensions: IRenderMime.IExtension[] = [];
-
-  /**
-   * The default renderer instances.
-   */
-  export
-  const defaultRenderers = [
-    new JavaScriptRenderer(),
-    new HTMLRenderer(),
-    new MarkdownRenderer(),
-    new LatexRenderer(),
-    new SVGRenderer(),
-    new ImageRenderer(),
-    new PDFRenderer(),
-    new TextRenderer()
-  ];
-}