Преглед изворни кода

Rename RawCellWidget to RawCell.

Brian E. Granger пре 8 година
родитељ
комит
eca012ac46

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

@@ -776,7 +776,7 @@ namespace MarkdownCell {
  * A widget for a raw cell.
  */
 export
-class RawCellWidget extends Cell {
+class RawCell extends Cell {
   /**
    * Construct a raw cell widget.
    */
@@ -793,10 +793,10 @@ class RawCellWidget extends Cell {
 
 
 /**
- * The namespace for the `RawCellWidget` class statics.
+ * The namespace for the `RawCell` class statics.
  */
 export
-namespace RawCellWidget {
+namespace RawCell {
   /**
    * An options object for initializing a base cell widget.
    */

+ 40 - 123
packages/console/src/widget.ts

@@ -34,7 +34,7 @@ import {
 } from '@jupyterlab/codeeditor';
 
 import {
-  Cell, CodeCell, RawCellWidget,
+  Cell, CodeCell, RawCell,
   ICodeCellModel, IRawCellModel, CellModel,
   RawCellModel, CodeCellModel
 } from '@jupyterlab/cells';
@@ -137,7 +137,7 @@ class CodeConsole extends Widget {
     // Create the banner.
     let model = modelFactory.createRawCell({});
     model.value.text = '...';
-    let banner = this.banner = factory.createBanner({
+    let banner = this.banner = new RawCell({
       model,
       contentFactory: factory.rawCellContentFactory
     }, this);
@@ -146,13 +146,13 @@ class CodeConsole extends Widget {
     this._content.addWidget(banner);
 
     // Set up the foreign iopub handler.
-    this._foreignHandler = factory.createForeignHandler({
+    this._foreignHandler = new ForeignHandler({
       session: this.session,
       parent: this,
-      cellFactory: () => this._createForeignCell(),
+      cellFactory: () => this._createCodeCell(),
     });
 
-    this._history = factory.createConsoleHistory({
+    this._history = new ConsoleHistory({
       session: this.session
     });
 
@@ -197,7 +197,7 @@ class CodeConsole extends Widget {
   /**
    * The console banner widget.
    */
-  readonly banner: RawCellWidget;
+  readonly banner: RawCell;
 
   /**
    * The list of content cells in the console.
@@ -312,7 +312,7 @@ class CodeConsole extends Widget {
    * @returns A promise that indicates when the injected cell's execution ends.
    */
   inject(code: string): Promise<void> {
-    let cell = this._createForeignCell();
+    let cell = this._createCodeCell();
     cell.model.value.text = code;
     this.addCell(cell);
     return this._execute(cell);
@@ -496,7 +496,7 @@ class CodeConsole extends Widget {
    */
   private _handleInfo(info: KernelMessage.IInfoReply): void {
     let layout = this._content.layout as PanelLayout;
-    let banner = layout.widgets[0] as RawCellWidget;
+    let banner = layout.widgets[0] as RawCell;
     banner.model.value.text = info.banner;
     let lang = info.language_info as nbformat.ILanguageInfoMetadata;
     this._mimetype = this._mimeTypeService.getMimeTypeByLanguage(lang);
@@ -508,10 +508,10 @@ class CodeConsole extends Widget {
   /**
    * Create a new foreign cell.
    */
-  private _createForeignCell(): CodeCell {
+  private _createCodeCell(): CodeCell {
     let factory = this.contentFactory;
     let options = this._createCodeCellOptions();
-    let cell = factory.createForeignCell(options, this);
+    let cell = factory.createCodeCell(options, this);
     cell.readOnly = true;
     cell.model.mimeType = this._mimetype;
     cell.addClass(FOREIGN_CELL_CLASS);
@@ -643,148 +643,65 @@ namespace CodeConsole {
    * A content factory for console children.
    */
   export
-  interface IContentFactory {
-    /**
-     * The editor factory.
-     */
-    readonly editorFactory: CodeEditor.Factory;
-
-    /**
-     * The factory for code cell widget content.
-     */
-    readonly codeCellContentFactory: CodeCell.IContentFactory;
-
-    /**
-     * The factory for raw cell widget content.
-     */
-    readonly rawCellContentFactory: Cell.IContentFactory;
-
-    /**
-     * The history manager for a console widget.
+  interface IContentFactory extends Cell.IContentFactory {
+ 
+     /**
+     * Create a new code cell widget.
      */
-    createConsoleHistory(options: ConsoleHistory.IOptions): IConsoleHistory;
+    createCodeCell(options: CodeCell.IOptions): CodeCell;
 
     /**
-     * The foreign handler for a console widget.
+     * Create a new raw cell widget.
      */
-    createForeignHandler(options: ForeignHandler.IOptions): ForeignHandler;
+    createRawCell(options: RawCell.IOptions): RawCell;
 
     /**
      * Create a new banner widget.
      */
-    createBanner(options: RawCellWidget.IOptions, parent: CodeConsole): RawCellWidget;
-
-    /**
-     * Create a new prompt widget.
-     */
-    createPrompt(options: CodeCell.IOptions, parent: CodeConsole): CodeCell;
+    createBanner(options: RawCell.IOptions, parent: CodeConsole): RawCell;
 
-    /**
-     * Create a code cell whose input originated from a foreign session.
-     */
-    createForeignCell(options: CodeCell.IOptions, parent: CodeConsole): CodeCell;
   }
 
   /**
    * Default implementation of `IContentFactory`.
    */
   export
-  class ContentFactory implements IContentFactory {
-    /**
-     * Create a new content factory.
-     */
-    constructor(options: IContentFactoryOptions) {
-      let editorFactory = options.editorFactory;
-      let outputAreaContentFactory = (options.outputAreaContentFactory ||
-        OutputArea.defaultContentFactory
-      );
-      this.codeCellContentFactory = (options.codeCellContentFactory ||
-        new CodeCell.ContentFactory({
-          editorFactory,
-          outputAreaContentFactory
-        })
-      );
-      this.rawCellContentFactory = (options.rawCellContentFactory ||
-        new RawCellWidget.ContentFactory({ editorFactory })
-      );
-    }
-
-    /**
-     * The editor factory.
-     */
-    readonly editorFactory: CodeEditor.Factory;
-
-    /**
-     * The factory for code cell widget content.
-     */
-    readonly codeCellContentFactory: CodeCell.IContentFactory;
-
-    /**
-     * The factory for raw cell widget content.
-     */
-    readonly rawCellContentFactory: Cell.IContentFactory;
+  class ContentFactory extends Cell.ContentFactory implements IContentFactory {
 
     /**
-     * The history manager for a console widget.
+     * Create a new code cell widget.
+     * 
+     * #### Notes
+     * If no cell content factory is passed in with the options, the one on the
+     * notebook content factory is used.
      */
-    createConsoleHistory(options: ConsoleHistory.IOptions): IConsoleHistory {
-      return new ConsoleHistory(options);
-    }
-
-    /**
-     * The foreign handler for a console widget.
-     */
-    createForeignHandler(options: ForeignHandler.IOptions):
-    ForeignHandler {
-      return new ForeignHandler(options);
-    }
-    /**
-     * Create a new banner widget.
-     */
-    createBanner(options: RawCellWidget.IOptions, parent: CodeConsole): RawCellWidget {
-      return new RawCellWidget(options);
-    }
-
-    /**
-     * Create a new prompt widget.
-     */
-    createPrompt(options: CodeCell.IOptions, parent: CodeConsole): CodeCell {
+    createCodeCell(options: CodeCell.IOptions): CodeCell {
+      if (!options.contentFactory) {
+        options.contentFactory = this;
+      }
       return new CodeCell(options);
     }
 
     /**
-     * Create a new code cell widget for an input from a foreign session.
+     * Create a new raw cell widget.
+     * 
+     * #### Notes
+     * If no cell content factory is passed in with the options, the one on the
+     * notebook content factory is used.
      */
-    createForeignCell(options: CodeCell.IOptions, parent: CodeConsole): CodeCell {
-      return new CodeCell(options);
+    createRawCell(options: RawCell.IOptions): RawCell {
+      if (!options.contentFactory) {
+        options.contentFactory = this;
+      }
+      return new RawCell(options);
     }
   }
+
   /**
    * An initialize options for `ContentFactory`.
    */
   export
-  interface IContentFactoryOptions {
-    /**
-     * The editor factory.
-     */
-    editorFactory: CodeEditor.Factory;
-
-    /**
-     * The factory for output area content.
-     */
-    outputAreaContentFactory?: OutputArea.IContentFactory;
-
-    /**
-     * The factory for code cell widget content.  If given, this will
-     * take precedence over the `outputAreaContentFactory`.
-     */
-    codeCellContentFactory?: CodeCell.IContentFactory;
-
-    /**
-     * The factory for raw cell widget content.
-     */
-    rawCellContentFactory?: Cell.IContentFactory;
-  }
+  interface IContentFactoryOptions extends Cell.IContentFactory { }
 
   /**
    * A model factory for a console widget.

+ 5 - 5
packages/notebook/src/widget.ts

@@ -40,7 +40,7 @@ import {
 import {
   ICellModel, Cell, IMarkdownCellModel,
   CodeCell, MarkdownCell,
-  ICodeCellModel, RawCellWidget, IRawCellModel,
+  ICodeCellModel, RawCell, IRawCellModel,
 } from '@jupyterlab/cells';
 
 import {
@@ -412,7 +412,7 @@ class StaticNotebook extends Widget {
   /**
    * Create a raw cell widget from a raw cell model.
    */
-  private _createRawCell(model: IRawCellModel): RawCellWidget {
+  private _createRawCell(model: IRawCellModel): RawCell {
     let contentFactory = this.contentFactory;
     let options = { model, contentFactory };
     return this.contentFactory.createRawCell(options, this);
@@ -517,7 +517,7 @@ namespace StaticNotebook {
     /**
      * Create a new raw cell widget.
      */
-    createRawCell(options: RawCellWidget.IOptions, parent: StaticNotebook): RawCellWidget;
+    createRawCell(options: RawCell.IOptions, parent: StaticNotebook): RawCell;
   }
 
   /**
@@ -561,11 +561,11 @@ namespace StaticNotebook {
      * If no cell content factory is passed in with the options, the one on the
      * notebook content factory is used.
      */
-    createRawCell(options: RawCellWidget.IOptions, parent: StaticNotebook): RawCellWidget {
+    createRawCell(options: RawCell.IOptions, parent: StaticNotebook): RawCell {
       if (!options.contentFactory) {
         options.contentFactory = this;
       }
-      return new RawCellWidget(options);
+      return new RawCell(options);
     }
   }
 

+ 4 - 4
test/src/cells/widget.spec.ts

@@ -22,7 +22,7 @@ import {
 import {
   Cell, CellModel, InputArea,
   CodeCell, CodeCellModel, MarkdownCell,
-  RawCellWidget, RawCellModel, MarkdownCellModel
+  RawCell, RawCellModel, MarkdownCellModel
 } from '@jupyterlab/cells';
 
 import {
@@ -577,7 +577,7 @@ describe('cells/widget', () => {
 
   });
 
-  describe('RawCellWidget', () => {
+  describe('RawCell', () => {
 
     let contentFactory = createBaseCellFactory();
 
@@ -585,8 +585,8 @@ describe('cells/widget', () => {
 
       it('should create a raw cell widget', () => {
         let model = new RawCellModel({});
-        let widget = new RawCellWidget({ model, contentFactory });
-        expect(widget).to.be.a(RawCellWidget);
+        let widget = new RawCell({ model, contentFactory });
+        expect(widget).to.be.a(RawCell);
       });
 
     });

+ 2 - 2
test/src/console/widget.spec.ts

@@ -20,7 +20,7 @@ import {
 } from '@jupyterlab/console';
 
 import {
-  Cell, CodeCell, CodeCellModel, RawCellModel, RawCellWidget
+  Cell, CodeCell, CodeCellModel, RawCellModel, RawCell
 } from '@jupyterlab/cells';
 
 import {
@@ -422,7 +422,7 @@ describe('console/widget', () => {
             model,
             contentFactory: contentFactory.rawCellContentFactory
           }, widget);
-          expect(banner).to.be.a(RawCellWidget);
+          expect(banner).to.be.a(RawCell);
         });
 
       });

+ 4 - 4
test/src/notebook/actions.spec.ts

@@ -12,7 +12,7 @@ import {
 } from '@phosphor/algorithm';
 
 import {
-  CodeCell, MarkdownCell, RawCellWidget
+  CodeCell, MarkdownCell, RawCell
 } from '@jupyterlab/cells';
 
 import {
@@ -228,7 +228,7 @@ describe('@jupyterlab/notebook', () => {
       it('should preserve the cell type of the active cell', () => {
         NotebookActions.changeCellType(widget, 'raw');
         NotebookActions.mergeCells(widget);
-        expect(widget.activeCell).to.be.a(RawCellWidget);
+        expect(widget.activeCell).to.be.a(RawCell);
         expect(widget.mode).to.be('command');
       });
 
@@ -417,9 +417,9 @@ describe('@jupyterlab/notebook', () => {
         let next = widget.widgets[1];
         widget.select(next);
         NotebookActions.changeCellType(widget, 'raw');
-        expect(widget.activeCell).to.be.a(RawCellWidget);
+        expect(widget.activeCell).to.be.a(RawCell);
         next = widget.widgets[widget.activeCellIndex + 1];
-        expect(next).to.be.a(RawCellWidget);
+        expect(next).to.be.a(RawCell);
       });
 
       it('should be a no-op if there is no model', () => {

+ 3 - 3
test/src/notebook/widget.spec.ts

@@ -17,7 +17,7 @@ import {
 
 import {
   CodeCellModel, CodeCell, MarkdownCellModel, MarkdownCell,
-  RawCellModel, RawCellWidget, Cell
+  RawCellModel, RawCell, Cell
 } from '@jupyterlab/cells';
 
 import {
@@ -531,14 +531,14 @@ describe('notebook/widget', () => {
 
       describe('#createRawCell()', () => {
 
-        it('should create a `RawCellWidget`', () => {
+        it('should create a `RawCell`', () => {
           let factory = new StaticNotebook.ContentFactory({ editorFactory });
           let contentFactory = factory.rawCellContentFactory;
           let model = new RawCellModel({});
           let rawOptions = { model, contentFactory };
           let parent = new StaticNotebook(options);
           let widget = factory.createRawCell(rawOptions, parent);
-          expect(widget).to.be.a(RawCellWidget);
+          expect(widget).to.be.a(RawCell);
         });
 
       });