Browse Source

Simplify content factories further.

Ian Rose 8 years ago
parent
commit
e7f2103879

+ 6 - 61
packages/chatbox/src/widget.ts → packages/chatbox/src/chatbox.ts

@@ -30,7 +30,6 @@ import {
 
 
 import {
 import {
   BaseCellWidget,
   BaseCellWidget,
-  CellModel, IMarkdownCellModel,
   MarkdownCellModel, MarkdownCellWidget
   MarkdownCellModel, MarkdownCellWidget
 } from '@jupyterlab/cells';
 } from '@jupyterlab/cells';
 
 
@@ -87,9 +86,6 @@ class Chatbox extends Widget {
     this._log = new ObservableVector<Chatbox.IChatEntry>();
     this._log = new ObservableVector<Chatbox.IChatEntry>();
 
 
     this.contentFactory = options.contentFactory;
     this.contentFactory = options.contentFactory;
-    this.modelFactory = (
-      options.modelFactory || Chatbox.defaultModelFactory
-    );
     this.rendermime = options.rendermime;
     this.rendermime = options.rendermime;
     this._mimeTypeService = options.mimeTypeService;
     this._mimeTypeService = options.mimeTypeService;
 
 
@@ -107,11 +103,6 @@ class Chatbox extends Widget {
    */
    */
   readonly contentFactory: Chatbox.IContentFactory;
   readonly contentFactory: Chatbox.IContentFactory;
 
 
-  /**
-   * The model factory for the chatbox widget.
-   */
-  readonly modelFactory: Chatbox.IModelFactory;
-
   /**
   /**
    * The rendermime instance used by the chatbox.
    * The rendermime instance used by the chatbox.
    */
    */
@@ -148,7 +139,7 @@ class Chatbox extends Widget {
         }
         }
         each(this._log, entry => {
         each(this._log, entry => {
           let options = this._createMarkdownCellOptions(entry.text);
           let options = this._createMarkdownCellOptions(entry.text);
-          let cellWidget = this.contentFactory.createPrompt(options, this);
+          let cellWidget = this.contentFactory.createCell(options);
           cellWidget.readOnly = true;
           cellWidget.readOnly = true;
           cellWidget.rendered = true;
           cellWidget.rendered = true;
           this.addCell(cellWidget);
           this.addCell(cellWidget);
@@ -300,7 +291,7 @@ class Chatbox extends Widget {
     // Create the new prompt.
     // Create the new prompt.
     let factory = this.contentFactory;
     let factory = this.contentFactory;
     let options = this._createMarkdownCellOptions();
     let options = this._createMarkdownCellOptions();
-    prompt = factory.createPrompt(options, this);
+    prompt = factory.createCell(options);
     prompt.model.mimeType = this._mimetype;
     prompt.model.mimeType = this._mimetype;
     prompt.addClass(PROMPT_CLASS);
     prompt.addClass(PROMPT_CLASS);
     prompt.rendered = false;
     prompt.rendered = false;
@@ -343,8 +334,7 @@ class Chatbox extends Widget {
    */
    */
   private _createMarkdownCellOptions(text: string = ''): MarkdownCellWidget.IOptions {
   private _createMarkdownCellOptions(text: string = ''): MarkdownCellWidget.IOptions {
     let contentFactory = this.contentFactory.markdownCellContentFactory;
     let contentFactory = this.contentFactory.markdownCellContentFactory;
-    let modelFactory = this.modelFactory;
-    let model = modelFactory.createMarkdownCell({ });
+    let model = new MarkdownCellModel({ });
     let rendermime = this.rendermime;
     let rendermime = this.rendermime;
     model.value.text = text || '';
     model.value.text = text || '';
     return { model, rendermime, contentFactory };
     return { model, rendermime, contentFactory };
@@ -374,11 +364,6 @@ namespace Chatbox {
      */
      */
     contentFactory: IContentFactory;
     contentFactory: IContentFactory;
 
 
-    /**
-     * The model factory for the chatbox widget.
-     */
-    modelFactory?: IModelFactory;
-
     /**
     /**
      * The mime renderer for the chatbox widget.
      * The mime renderer for the chatbox widget.
      */
      */
@@ -406,9 +391,9 @@ namespace Chatbox {
     readonly markdownCellContentFactory: BaseCellWidget.IContentFactory;
     readonly markdownCellContentFactory: BaseCellWidget.IContentFactory;
 
 
     /**
     /**
-     * Create a new prompt widget.
+     * Create a new cell widget.
      */
      */
-    createPrompt(options: MarkdownCellWidget.IOptions, parent: Chatbox): MarkdownCellWidget;
+    createCell(options: MarkdownCellWidget.IOptions): MarkdownCellWidget;
 
 
   }
   }
 
 
@@ -457,7 +442,7 @@ namespace Chatbox {
     /**
     /**
      * Create a new prompt widget.
      * Create a new prompt widget.
      */
      */
-    createPrompt(options: MarkdownCellWidget.IOptions, parent: Chatbox): MarkdownCellWidget {
+    createCell(options: MarkdownCellWidget.IOptions): MarkdownCellWidget {
       return new MarkdownCellWidget(options);
       return new MarkdownCellWidget(options);
     }
     }
   }
   }
@@ -471,46 +456,6 @@ namespace Chatbox {
      */
      */
     editorFactory: CodeEditor.Factory;
     editorFactory: CodeEditor.Factory;
   }
   }
-
-  /**
-   * A model factory for a chatbox widget.
-   */
-  export
-  interface IModelFactory {
-    /**
-     * Create a new markdown cell.
-     *
-     * @param options - The options used to create the cell.
-     *
-     * @returns A new code cell. If a source cell is provided, the
-     *   new cell will be intialized with the data from the source.
-     */
-    createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel;
-  }
-
-  /**
-   * The default implementation of an `IModelFactory`.
-   */
-  export
-  class ModelFactory {
-    /**
-     * Create a new markdown cell.
-     *
-     * @param source - The data to use for the original source data.
-     *
-     * @returns A new markdown cell. If a source cell is provided, the
-     *   new cell will be intialized with the data from the source.
-     */
-    createMarkdownCell(options: CellModel.IOptions): IMarkdownCellModel {
-      return new MarkdownCellModel(options);
-    }
-  }
-
-  /**
-   * The default `ModelFactory` instance.
-   */
-  export
-  const defaultModelFactory = new ModelFactory();
 }
 }
 
 
 
 

+ 1 - 1
packages/chatbox/src/index.ts

@@ -2,5 +2,5 @@
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
 export * from './panel';
 export * from './panel';
-export * from './widget';
+export * from './chatbox';
 
 

+ 4 - 21
packages/chatbox/src/panel.ts

@@ -23,7 +23,7 @@ import {
 
 
 import {
 import {
   Chatbox
   Chatbox
-} from './widget';
+} from './chatbox';
 
 
 
 
 /**
 /**
@@ -44,7 +44,7 @@ class ChatboxPanel extends Panel {
     super();
     super();
     this.addClass(PANEL_CLASS);
     this.addClass(PANEL_CLASS);
     let {
     let {
-      rendermime, mimeTypeService, path, basePath, modelFactory
+      rendermime, mimeTypeService, path, basePath
     } = options;
     } = options;
     let factory = options.contentFactory;
     let factory = options.contentFactory;
     let contentFactory = factory.chatboxContentFactory;
     let contentFactory = factory.chatboxContentFactory;
@@ -53,8 +53,8 @@ class ChatboxPanel extends Panel {
       path = `${basePath || ''}/chatbox-${count}-${uuid()}`;
       path = `${basePath || ''}/chatbox-${count}-${uuid()}`;
     }
     }
 
 
-    this.chatbox = factory.createChatbox({
-      rendermime, mimeTypeService, contentFactory, modelFactory
+    this.chatbox = new Chatbox({
+      rendermime, mimeTypeService, contentFactory
     });
     });
     this.addWidget(this.chatbox);
     this.addWidget(this.chatbox);
 
 
@@ -128,11 +128,6 @@ namespace ChatboxPanel {
      */
      */
     name?: string;
     name?: string;
 
 
-    /**
-     * The model factory for the chatbox widget.
-     */
-    modelFactory?: Chatbox.IModelFactory;
-
     /**
     /**
      * The service used to look up mime types.
      * The service used to look up mime types.
      */
      */
@@ -153,11 +148,6 @@ namespace ChatboxPanel {
      * The factory for code chatbox content.
      * The factory for code chatbox content.
      */
      */
     readonly chatboxContentFactory: Chatbox.IContentFactory;
     readonly chatboxContentFactory: Chatbox.IContentFactory;
-
-    /**
-     * Create a new chatbox panel.
-     */
-    createChatbox(options: Chatbox.IOptions): Chatbox;
   }
   }
 
 
   /**
   /**
@@ -186,13 +176,6 @@ namespace ChatboxPanel {
      * The factory for code chatbox content.
      * The factory for code chatbox content.
      */
      */
     readonly chatboxContentFactory: Chatbox.IContentFactory;
     readonly chatboxContentFactory: Chatbox.IContentFactory;
-
-    /**
-     * Create a new chatbox panel.
-     */
-    createChatbox(options: Chatbox.IOptions): Chatbox {
-      return new Chatbox(options);
-    }
   }
   }
 
 
   /**
   /**

+ 5 - 1
packages/chatbox/style/index.css

@@ -55,6 +55,10 @@
   display: none;
   display: none;
 }
 }
 
 
+.jp-Chatbox .jp-InputArea {
+  background-color: pink;
+}
+
 .jp-Chatbox-content .jp-InputArea-editor.jp-CellEditor {
 .jp-Chatbox-content .jp-InputArea-editor.jp-CellEditor {
   background: transparent;
   background: transparent;
   border-color: transparent;
   border-color: transparent;
@@ -63,7 +67,7 @@
 
 
 /* TODO: we should be able to use notebook styles for this */
 /* TODO: we should be able to use notebook styles for this */
 .jp-Chatbox-input .jp-Chatbox-prompt.jp-Cell {
 .jp-Chatbox-input .jp-Chatbox-prompt.jp-Cell {
-  background: linear-gradient(to right, #66BB6A -40px, #66BB6A 5px, transparent 5px, transparent 100%);
+  background: transparent;
   border-color: #66BB6A;
   border-color: #66BB6A;
   border-left-width: var(--jp-border-width);
   border-left-width: var(--jp-border-width);
 }
 }