Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jupyter-js-notebook

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jupyter-js-notebook - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

lib/utils/latex.d.ts

141

lib/cells/model.d.ts

@@ -1,23 +0,11 @@

import { IInputAreaModel, IInputAreaOptions } from '../input-area';
import { IOutputAreaModel } from '../output-area';
import { IObservableList } from 'phosphor-observablelist';
import { IChangedArgs } from 'phosphor-properties';
import { ISignal } from 'phosphor-signaling';
import { IInputAreaModel } from '../input-area';
import { CellType } from '../notebook/nbformat';
import { IOutputAreaModel } from '../output-area';
/**
* A type which describes the type of cell.
* The interactivity modes for a cell.
*/
export declare type CellType = "code" | "markdown" | "raw";
export declare type CellMode = 'command' | 'edit';
/**
* An object which is serializable.
*/
export interface ISerializable {
toJSON(): any;
fromJSON(data: any): void;
}
/**
* The options for creating a cell.
*/
export interface ICellOptions extends IInputAreaOptions {
}
/**
* The definition of a model object for a base cell.

@@ -31,6 +19,10 @@ */

/**
* Tags applied to the cell.
* The cell's name. If present, must be a non-empty string.
*/
tags?: IObservableList<string>;
name?: string;
/**
* The cell's tags. Tags must be unique, and must not contain commas.
*/
tags?: string[];
/**
* A signal emitted when state of the cell changes.

@@ -40,8 +32,9 @@ */

/**
* A signal emitted when the cell is selected.
* Whether the cell is selected.
*/
selected: ISignal<IBaseCellModel, void>;
selected: boolean;
/**
* Get namespaced metadata about the cell.
* The mode of the cell.
*/
mode: CellMode;
/**

@@ -63,5 +56,5 @@ * The input area of the cell.

/**
* Select the cell model.
* Whether the cell is marked for applying commands.
*/
select(): void;
marked: boolean;
}

@@ -72,4 +65,18 @@ /**

export interface ICodeCellModel extends IBaseCellModel {
/**
* Execution, display, or stream outputs.
*/
output: IOutputAreaModel;
/**
* The code cell's prompt number. Will be null if the cell has not been run.
*/
executionCount: number;
/**
* Whether the cell is collapsed/expanded.
*/
collapsed?: boolean;
/**
* Whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
scrolled?: boolean | 'auto';
}

@@ -81,3 +88,3 @@ /**

/**
* The raw cell format.
* Raw cell metadata format for nbconvert.
*/

@@ -91,3 +98,3 @@ format?: string;

/**
* Whether a cell is rendered.
* Whether the cell is rendered.
*/

@@ -107,3 +114,3 @@ rendered: boolean;

*/
constructor(options?: ICellOptions);
constructor(input: IInputAreaModel);
/**

@@ -114,6 +121,29 @@ * A signal emitted when the state of the model changes.

/**
* A signal emitted when the cell is selected.
* Get whether the cell is selected.
*/
selected: ISignal<IBaseCellModel, void>;
/**
* Set whether the cell is selected.
*/
selected: boolean;
/**
* Get mode of the cell.
*
* #### Notes
* This is a delegate to the focused state of the input's editor.
*/
/**
* Set mode of the cell.
*
* #### Notes
* This is a delegate to the focused state of the input's editor.
*/
mode: CellMode;
/**
* Get whether the cell is marked.
*/
/**
* Set whether the cell is marked.
*/
marked: boolean;
/**
* Get the input area model.

@@ -149,6 +179,16 @@ */

/**
* Select the cell model.
* Get the name of the cell.
*/
select(): void;
/**
* Set the name of the cell.
*/
name: string;
/**
* Get the tags for the cell.
*/
/**
* Set the tags for the cell.
*/
tags: string[];
/**
* The type of cell.

@@ -158,5 +198,10 @@ */

/**
* Re-emit changes to the input dirty state.
* Handle changes to the input model.
*/
private _inputChanged(input, args);
protected onInputChanged(input: IInputAreaModel, args: IChangedArgs<any>): void;
/**
* Handle changes to the editor model.
*/
private onEditorChanged(editor, args);
private _input;
}

@@ -170,3 +215,3 @@ /**

*/
constructor(options?: ICellOptions);
constructor(input: IInputAreaModel, output: IOutputAreaModel);
/**

@@ -183,3 +228,18 @@ * Get the output area model.

executionCount: number;
/**
* Get whether the cell is collapsed/expanded.
*/
/**
* Set whether the cell is collapsed/expanded.
*/
collapsed: boolean;
/**
* Get whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
/**
* Set whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
scrolled: boolean | 'auto';
type: CellType;
private _output;
}

@@ -197,6 +257,15 @@ /**

rendered: boolean;
type: CellType;
}
/**
* An implementation of a Raw cell Model.
*/
export declare class RawCellModel extends BaseCellModel implements IRawCellModel {
/**
* Select the cell model.
* Get the raw cell metadata format for nbconvert.
*/
select(): void;
/**
* Get the raw cell metadata format for nbconvert.
*/
format: string;
type: CellType;

@@ -203,0 +272,0 @@ }

@@ -9,4 +9,2 @@ // Copyright (c) Jupyter Development Team.

};
var input_area_1 = require('../input-area');
var output_area_1 = require('../output-area');
var phosphor_properties_1 = require('phosphor-properties');

@@ -21,6 +19,7 @@ var phosphor_signaling_1 = require('phosphor-signaling');

*/
function BaseCellModel(options) {
var input = new input_area_1.InputAreaModel(options);
Private.inputProperty.set(this, input);
input.stateChanged.connect(this._inputChanged, this);
function BaseCellModel(input) {
this._input = null;
this._input = input;
input.stateChanged.connect(this.onInputChanged, this);
input.textEditor.stateChanged.connect(this.onEditorChanged, this);
}

@@ -39,10 +38,59 @@ Object.defineProperty(BaseCellModel.prototype, "stateChanged", {

/**
* A signal emitted when the cell is selected.
* Get whether the cell is selected.
*/
get: function () {
return Private.selectedSignal.bind(this);
return Private.selectedProperty.get(this);
},
/**
* Set whether the cell is selected.
*/
set: function (value) {
Private.selectedProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BaseCellModel.prototype, "mode", {
/**
* Get mode of the cell.
*
* #### Notes
* This is a delegate to the focused state of the input's editor.
*/
get: function () {
if (this.input.textEditor.focused) {
return 'edit';
}
else {
return 'command';
}
},
/**
* Set mode of the cell.
*
* #### Notes
* This is a delegate to the focused state of the input's editor.
*/
set: function (value) {
this.input.textEditor.focused = value === 'edit';
},
enumerable: true,
configurable: true
});
Object.defineProperty(BaseCellModel.prototype, "marked", {
/**
* Get whether the cell is marked.
*/
get: function () {
return Private.markedProperty.get(this);
},
/**
* Set whether the cell is marked.
*/
set: function (value) {
Private.markedProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BaseCellModel.prototype, "input", {

@@ -53,3 +101,3 @@ /**

get: function () {
return Private.inputProperty.get(this);
return this._input;
},

@@ -103,15 +151,63 @@ enumerable: true,

});
Object.defineProperty(BaseCellModel.prototype, "name", {
/**
* Get the name of the cell.
*/
get: function () {
return Private.nameProperty.get(this);
},
/**
* Set the name of the cell.
*/
set: function (value) {
Private.nameProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BaseCellModel.prototype, "tags", {
/**
* Get the tags for the cell.
*/
get: function () {
return Private.tagsProperty.get(this);
},
/**
* Set the tags for the cell.
*/
set: function (value) {
Private.tagsProperty.set(this, value);
},
enumerable: true,
configurable: true
});
/**
* Select the cell model.
* Handle changes to the input model.
*/
BaseCellModel.prototype.select = function () {
this.selected.emit(void 0);
this.input.textEditor.select();
BaseCellModel.prototype.onInputChanged = function (input, args) {
// Re-emit changes to input dirty and readOnly states.
if (args.name === 'dirty' || args.name === 'readOnly') {
this.stateChanged.emit(args);
}
};
/**
* Re-emit changes to the input dirty state.
* Handle changes to the editor model.
*/
BaseCellModel.prototype._inputChanged = function (input, args) {
if (args.name === 'dirty' || args.name === 'readOnly') {
this.stateChanged.emit(args);
BaseCellModel.prototype.onEditorChanged = function (editor, args) {
// Handle changes to the focused state of the editor.
if (args.name === 'focused') {
if (args.newValue) {
this.stateChanged.emit({
name: 'mode',
newValue: 'edit',
oldValue: 'command'
});
}
else {
this.stateChanged.emit({
name: 'mode',
newValue: 'command',
oldValue: 'edit'
});
}
}

@@ -130,6 +226,8 @@ };

*/
function CodeCellModel(options) {
_super.call(this, options);
function CodeCellModel(input, output) {
_super.call(this, input);
this.type = "code";
Private.outputProperty.set(this, new output_area_1.OutputAreaModel());
this._output = null;
this._output = output;
this.input.prompt = 'In [ ]:';
}

@@ -141,3 +239,3 @@ Object.defineProperty(CodeCellModel.prototype, "output", {

get: function () {
return Private.outputProperty.get(this);
return this._output;
},

@@ -159,2 +257,3 @@ enumerable: true,

Private.executionCountProperty.set(this, value);
this.input.prompt = "In [" + (value === null ? ' ' : value) + "]:";
},

@@ -164,2 +263,34 @@ enumerable: true,

});
Object.defineProperty(CodeCellModel.prototype, "collapsed", {
/**
* Get whether the cell is collapsed/expanded.
*/
get: function () {
return Private.collapsedProperty.get(this);
},
/**
* Set whether the cell is collapsed/expanded.
*/
set: function (value) {
Private.collapsedProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeCellModel.prototype, "scrolled", {
/**
* Get whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
get: function () {
return Private.scrolledProperty.get(this);
},
/**
* Set whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
set: function (value) {
Private.scrolledProperty.set(this, value);
},
enumerable: true,
configurable: true
});
return CodeCellModel;

@@ -193,10 +324,2 @@ }(BaseCellModel));

});
/**
* Select the cell model.
*/
MarkdownCellModel.prototype.select = function () {
this.selected.emit(void 0);
if (!this.rendered)
this.input.textEditor.select();
};
return MarkdownCellModel;

@@ -206,2 +329,30 @@ }(BaseCellModel));

/**
* An implementation of a Raw cell Model.
*/
var RawCellModel = (function (_super) {
__extends(RawCellModel, _super);
function RawCellModel() {
_super.apply(this, arguments);
this.type = "raw";
}
Object.defineProperty(RawCellModel.prototype, "format", {
/**
* Get the raw cell metadata format for nbconvert.
*/
get: function () {
return Private.formatProperty.get(this);
},
/**
* Get the raw cell metadata format for nbconvert.
*/
set: function (value) {
Private.formatProperty.set(this, value);
},
enumerable: true,
configurable: true
});
return RawCellModel;
}(BaseCellModel));
exports.RawCellModel = RawCellModel;
/**
* A type guard for testing if a cell model is a markdown cell.

@@ -237,20 +388,39 @@ */

/**
* A signal emitted when a cell model is selected.
* A property descriptor for the selected state of the cell.
*/
Private.selectedSignal = new phosphor_signaling_1.Signal();
Private.selectedProperty = new phosphor_properties_1.Property({
name: 'selected',
notify: Private.stateChangedSignal,
});
/**
* A property descriptor for the input area model.
* A property descriptor for the marked state of the cell.
*/
Private.inputProperty = new phosphor_properties_1.Property({
name: 'input',
Private.markedProperty = new phosphor_properties_1.Property({
name: 'marked',
notify: Private.stateChangedSignal,
});
/**
* A property descriptor holding the output area model.
* A property descriptor for the name of a cell.
*/
Private.outputProperty = new phosphor_properties_1.Property({
name: 'output',
Private.nameProperty = new phosphor_properties_1.Property({
name: 'name',
value: null,
notify: Private.stateChangedSignal,
});
/**
* A property descriptor for the tags of a cell.
*/
Private.tagsProperty = new phosphor_properties_1.Property({
name: 'tags',
value: null,
notify: Private.stateChangedSignal,
});
/**
* A property descriptor holding the format of a raw cell.
*/
Private.formatProperty = new phosphor_properties_1.Property({
name: 'format',
notify: Private.stateChangedSignal,
});
/**
* A property descriptor which determines whether the input area should be rendered.

@@ -260,2 +430,3 @@ */

name: 'rendered',
value: true,
notify: Private.stateChangedSignal,

@@ -271,2 +442,16 @@ });

});
/**
* A property descriptor for the collapsed state of a code cell.
*/
Private.collapsedProperty = new phosphor_properties_1.Property({
name: 'collapsed',
notify: Private.stateChangedSignal,
});
/**
* A property descriptor for the scrolled state of a code cell.
*/
Private.scrolledProperty = new phosphor_properties_1.Property({
name: 'scrolled',
notify: Private.stateChangedSignal,
});
})(Private || (Private = {}));

@@ -0,12 +1,39 @@

import { Message } from 'phosphor-messaging';
import { IChangedArgs } from 'phosphor-properties';
import { Widget } from 'phosphor-widget';
import { ICodeCellModel, IMarkdownCellModel, ICellModel } from './model';
import { InputAreaWidget, IInputAreaModel } from '../input-area';
import { OutputAreaWidget, IOutputAreaModel } from '../output-area';
import { InputAreaWidget } from '../input-area';
import { OutputAreaWidget } from '../output-area';
import { ICodeCellModel, IMarkdownCellModel, ICellModel, IRawCellModel } from './model';
/**
* A base cell widget.
*/
export declare abstract class CellWidget extends Widget {
constructor();
protected _model: ICellModel;
export declare class BaseCellWidget extends Widget {
/**
* Construct a new base cell widget.
*/
constructor(model: ICellModel);
/**
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
model: ICellModel;
/**
* Get the input widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
input: InputAreaWidget;
/**
* Handle `update_request` messages.
*/
protected onUpdateRequest(message: Message): void;
/**
* Handle changes to the model state.
*/
protected onModelChanged(sender: ICellModel, args: IChangedArgs<any>): void;
private _input;
private _model;
}

@@ -16,3 +43,3 @@ /**

*/
export declare class CodeCellWidget extends CellWidget {
export declare class CodeCellWidget extends BaseCellWidget {
/**

@@ -23,18 +50,9 @@ * Construct a code cell widget.

/**
* Update the input area, creating a new input area
* widget and detaching the old one.
* Get the output widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
protected updateInputArea(input: IInputAreaModel): void;
/**
* Update the output area, creating a new output area
* widget and detaching the old one.
*/
protected updateOutputArea(output: IOutputAreaModel): void;
/**
* Change handler for model updates.
*/
protected modelStateChanged(sender: ICodeCellModel, args: IChangedArgs<any>): void;
protected input: InputAreaWidget;
protected output: OutputAreaWidget;
protected _model: ICodeCellModel;
output: OutputAreaWidget;
private _output;
}

@@ -50,3 +68,3 @@ /**

*/
export declare class MarkdownCellWidget extends CellWidget {
export declare class MarkdownCellWidget extends BaseCellWidget {
/**

@@ -57,38 +75,27 @@ * Construct a Markdown cell widget.

/**
* Process the input and display the rendered Markdown.
* Get the rendering widget used by the widget.
*
* #### Notes
* This will remove the input widget.
* Call [[editInput]] to restore the editor.
* This is a read-only property.
*/
renderInput(): void;
rendered: Widget;
/**
* Edit the Markdown source.
*
* #### Notes
* This will remove the rendered widget.
* Call [[renderInput]] to render the source.
* Handle `update_request` messages.
*/
editInput(): void;
protected onUpdateRequest(message: Message): void;
/**
* Update the input area, creating a new input area
* widget and detaching the old one.
*/
protected updateInputArea(input: IInputAreaModel): void;
/**
* Update the input area, creating a new input area
* widget and detaching the old one.
*/
protected updateRendered(rendered: boolean): void;
/**
* Change handler for model updates.
*/
protected modelStateChanged(sender: IMarkdownCellModel, args: IChangedArgs<any>): void;
protected onModelChanged(sender: ICellModel, args: IChangedArgs<any>): void;
private _rendered;
private _dirty;
}
/**
* A widget for a raw cell.
*/
export declare class RawCellWidget extends BaseCellWidget {
/**
* A selection handler for the model.
* Construct a raw cell widget.
*/
private _onModelSelected();
protected input: InputAreaWidget;
protected rendered: Widget;
protected _model: IMarkdownCellModel;
constructor(model: IRawCellModel);
}

@@ -9,22 +9,132 @@ // Copyright (c) Jupyter Development Team.

};
var marked = require('marked');
var phosphor_panel_1 = require('phosphor-panel');
var phosphor_widget_1 = require('phosphor-widget');
var phosphor_panel_1 = require('phosphor-panel');
var input_area_1 = require('../input-area');
var output_area_1 = require('../output-area');
var marked = require('marked');
var latex_1 = require('../utils/latex');
/**
* The class name added to cell widgets.
*/
var CELL_CLASS = 'jp-Cell';
/**
* The class name added to selected widgets.
*/
var SELECTED_CLASS = 'jp-mod-selected';
/**
* The class name added to marked widgets.
*/
var MARKED_CLASS = 'jp-mod-marked';
/**
* The class name added to code cells.
*/
var CODE_CELL_CLASS = 'jp-CodeCell';
/**
* The class name added to markdown cells.
*/
var MARKDOWN_CELL_CLASS = 'jp-MarkdownCell';
/**
* The class name added to the markdown cell renderer widget.
*/
var RENDERER_CLASS = 'jp-MarkdownCell-renderer';
/**
* The class name added to raw cells.
*/
var RAW_CELL_CLASS = 'jp-RawCell';
/**
* The class name added to a rendered markdown cell.
*/
var RENDERED_CLASS = 'jp-mod-rendered';
/**
* The class name added to a cell in edit mode.
*/
var EDIT_CLASS = 'jp-mod-editMode';
/**
* The class name added to a cell in command mode.
*/
var COMMAND_CLASS = 'jp-mod-commandMode';
/**
* The text applied to an empty markdown cell.
*/
var DEFAULT_MARKDOWN_TEXT = 'Type Markdown and LaTeX: $ α^2 $';
/**
* A base cell widget.
*/
var CellWidget = (function (_super) {
__extends(CellWidget, _super);
function CellWidget() {
var BaseCellWidget = (function (_super) {
__extends(BaseCellWidget, _super);
/**
* Construct a new base cell widget.
*/
function BaseCellWidget(model) {
_super.call(this);
this.addClass('jp-Cell');
// we make the cell focusable by setting the tabIndex
this.addClass(CELL_CLASS);
// Make the cell focusable by setting the tabIndex.
this.node.tabIndex = -1;
this._model = model;
this._input = new input_area_1.InputAreaWidget(model.input);
this.layout = new phosphor_panel_1.PanelLayout();
this.layout.addChild(this._input);
model.stateChanged.connect(this.onModelChanged, this);
}
return CellWidget;
Object.defineProperty(BaseCellWidget.prototype, "model", {
/**
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BaseCellWidget.prototype, "input", {
/**
* Get the input widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._input;
},
enumerable: true,
configurable: true
});
/**
* Handle `update_request` messages.
*/
BaseCellWidget.prototype.onUpdateRequest = function (message) {
_super.prototype.onUpdateRequest.call(this, message);
if (this.model.selected) {
this.addClass(SELECTED_CLASS);
}
else {
this.removeClass(SELECTED_CLASS);
}
if (this.model.marked) {
this.addClass(MARKED_CLASS);
}
else {
this.removeClass(MARKED_CLASS);
}
if (this.model.mode === 'edit') {
this.addClass(EDIT_CLASS);
this.removeClass(COMMAND_CLASS);
}
else {
this.addClass(COMMAND_CLASS);
this.removeClass(EDIT_CLASS);
}
};
/**
* Handle changes to the model state.
*/
BaseCellWidget.prototype.onModelChanged = function (sender, args) {
this.update();
};
return BaseCellWidget;
}(phosphor_widget_1.Widget));
exports.CellWidget = CellWidget;
exports.BaseCellWidget = BaseCellWidget;
/**

@@ -39,44 +149,22 @@ * A widget for a code cell.

function CodeCellWidget(model) {
_super.call(this);
this.addClass('jp-CodeCell');
this._model = model;
this.input = new input_area_1.InputAreaWidget(model.input);
this.output = new output_area_1.OutputAreaWidget(model.output);
this.layout.addChild(this.input);
this.layout.addChild(this.output);
model.stateChanged.connect(this.modelStateChanged, this);
_super.call(this, model);
this.addClass(CODE_CELL_CLASS);
this._output = new output_area_1.OutputAreaWidget(model.output);
this.layout.addChild(this._output);
}
/**
* Update the input area, creating a new input area
* widget and detaching the old one.
*/
CodeCellWidget.prototype.updateInputArea = function (input) {
this.input.dispose(); // removes from children
this.input = new input_area_1.InputAreaWidget(input);
this.layout.insertChild(0, this.input);
};
/**
* Update the output area, creating a new output area
* widget and detaching the old one.
*/
CodeCellWidget.prototype.updateOutputArea = function (output) {
this.output.dispose();
this.output = new output_area_1.OutputAreaWidget(output);
this.layout.insertChild(1, this.output);
};
/**
* Change handler for model updates.
*/
CodeCellWidget.prototype.modelStateChanged = function (sender, args) {
switch (args.name) {
case 'input':
this.updateInputArea(args.newValue);
break;
case 'output':
this.updateOutputArea(args.newValue);
break;
}
};
Object.defineProperty(CodeCellWidget.prototype, "output", {
/**
* Get the output widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._output;
},
enumerable: true,
configurable: true
});
return CodeCellWidget;
}(CellWidget));
}(BaseCellWidget));
exports.CodeCellWidget = CodeCellWidget;

@@ -98,90 +186,79 @@ /**

function MarkdownCellWidget(model) {
_super.call(this);
this.addClass('jp-MarkdownCell');
this._model = model;
// Insist on the Github-flavored markdown mode
_super.call(this, model);
this._dirty = true;
this.addClass(MARKDOWN_CELL_CLASS);
// Insist on the Github-flavored markdown mode.
model.input.textEditor.mimetype = 'text/x-ipythongfm';
this.input = new input_area_1.InputAreaWidget(model.input);
this.rendered = new phosphor_widget_1.Widget();
if (model.rendered) {
this.renderInput();
}
else {
this.editInput();
}
model.stateChanged.connect(this.modelStateChanged, this);
model.selected.connect(this._onModelSelected, this);
this._rendered = new phosphor_widget_1.Widget();
this._rendered.addClass(RENDERER_CLASS);
this.layout.addChild(this._rendered);
this.update();
}
Object.defineProperty(MarkdownCellWidget.prototype, "rendered", {
/**
* Get the rendering widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._rendered;
},
enumerable: true,
configurable: true
});
/**
* Process the input and display the rendered Markdown.
*
* #### Notes
* This will remove the input widget.
* Call [[editInput]] to restore the editor.
* Handle `update_request` messages.
*/
MarkdownCellWidget.prototype.renderInput = function () {
this.rendered.node.innerHTML = marked(this._model.input.textEditor.text);
this.input.parent = null;
this.layout.addChild(this.rendered);
};
/**
* Edit the Markdown source.
*
* #### Notes
* This will remove the rendered widget.
* Call [[renderInput]] to render the source.
*/
MarkdownCellWidget.prototype.editInput = function () {
this.rendered.parent = null;
this.layout.addChild(this.input);
};
/**
* Update the input area, creating a new input area
* widget and detaching the old one.
*/
MarkdownCellWidget.prototype.updateInputArea = function (input) {
this.input.dispose();
this.input = new input_area_1.InputAreaWidget(input);
if (this._model.rendered) {
this.renderInput();
MarkdownCellWidget.prototype.onUpdateRequest = function (message) {
var model = this.model;
if (model.rendered) {
if (this._dirty) {
var text = model.input.textEditor.text || DEFAULT_MARKDOWN_TEXT;
var data = latex_1.removeMath(text);
var html = marked(data['text']);
this.rendered.node.innerHTML = latex_1.replaceMath(html, data['math']);
latex_1.typeset(this.rendered.node);
}
this._rendered.show();
this.input.hide();
this.addClass(RENDERED_CLASS);
}
else {
this.editInput();
this._rendered.hide();
this.input.show();
this.removeClass(RENDERED_CLASS);
}
this._dirty = false;
_super.prototype.onUpdateRequest.call(this, message);
};
/**
* Update the input area, creating a new input area
* widget and detaching the old one.
*/
MarkdownCellWidget.prototype.updateRendered = function (rendered) {
if (rendered) {
this.renderInput();
}
else {
this.editInput();
}
};
/**
* Change handler for model updates.
*/
MarkdownCellWidget.prototype.modelStateChanged = function (sender, args) {
MarkdownCellWidget.prototype.onModelChanged = function (sender, args) {
_super.prototype.onModelChanged.call(this, sender, args);
switch (args.name) {
case 'input':
this.updateInputArea(args.newValue);
break;
case 'rendered':
this.updateRendered(args.newValue);
this._dirty = true;
this.update();
break;
}
};
return MarkdownCellWidget;
}(BaseCellWidget));
exports.MarkdownCellWidget = MarkdownCellWidget;
/**
* A widget for a raw cell.
*/
var RawCellWidget = (function (_super) {
__extends(RawCellWidget, _super);
/**
* A selection handler for the model.
* Construct a raw cell widget.
*/
MarkdownCellWidget.prototype._onModelSelected = function () {
if (this._model.rendered) {
this.node.focus();
}
};
return MarkdownCellWidget;
}(CellWidget));
exports.MarkdownCellWidget = MarkdownCellWidget;
function RawCellWidget(model) {
_super.call(this, model);
this.addClass(RAW_CELL_CLASS);
}
return RawCellWidget;
}(BaseCellWidget));
exports.RawCellWidget = RawCellWidget;
import { IChangedArgs } from 'phosphor-properties';
import { ISignal } from 'phosphor-signaling';
import { IEditorModel } from './widget';
/**

@@ -46,3 +47,3 @@ * Interface that must be implemented to set defaults on an EditorModel.

*/
export declare class EditorModel {
export declare class EditorModel implements IEditorModel {
/**

@@ -53,6 +54,2 @@ * Construct an Editor Model.

/**
* A signal emitted when the editor is selected.
*/
selected: ISignal<EditorModel, void>;
/**
* A signal emitted when the editor model state changes.

@@ -104,2 +101,9 @@ */

/**
* Get whether the editor is focused for editing.
*/
/**
* Set whether the editor is focused for editing.
*/
focused: boolean;
/**
* Get the tabSize number for the editor model.

@@ -118,6 +122,2 @@ */

text: string;
/**
* Select the editor model.
*/
select(): void;
}

@@ -17,12 +17,2 @@ // Copyright (c) Jupyter Development Team.

}
Object.defineProperty(EditorModel.prototype, "selected", {
/**
* A signal emitted when the editor is selected.
*/
get: function () {
return EditorModelPrivate.selectedSignal.bind(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(EditorModel.prototype, "stateChanged", {

@@ -134,2 +124,18 @@ /**

});
Object.defineProperty(EditorModel.prototype, "focused", {
/**
* Get whether the editor is focused for editing.
*/
get: function () {
return EditorModelPrivate.focusedProperty.get(this);
},
/**
* Set whether the editor is focused for editing.
*/
set: function (value) {
EditorModelPrivate.focusedProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(EditorModel.prototype, "tabSize", {

@@ -167,8 +173,2 @@ /**

});
/**
* Select the editor model.
*/
EditorModel.prototype.select = function () {
this.selected.emit(void 0);
};
return EditorModel;

@@ -187,6 +187,2 @@ }());

/**
* A signal emitted when the editor is selected.
*/
EditorModelPrivate.selectedSignal = new phosphor_signaling_1.Signal();
/**
* The property descriptor for the editor mimetype.

@@ -232,2 +228,10 @@ */

/**
* The property descriptor for the editor focused property.
*/
EditorModelPrivate.focusedProperty = new phosphor_properties_1.Property({
name: 'focused',
value: false,
notify: EditorModelPrivate.stateChangedSignal
});
/**
* The property descriptor for the editor text.

@@ -234,0 +238,0 @@ */

@@ -16,6 +16,2 @@ import 'codemirror/mode/meta';

/**
* A signal emitted when the editor model is selected.
*/
selected: ISignal<IEditorModel, void>;
/**
* The text in the text editor.

@@ -36,2 +32,6 @@ */

/**
* Whether the editor is focused.
*/
focused: boolean;
/**
* Whether the text editor has a fixed maximum height.

@@ -60,6 +60,2 @@ *

dirty: boolean;
/**
* Select the editor model.
*/
select(): void;
}

@@ -78,3 +74,3 @@ /**

*/
export declare class CodeMirrorWidget extends Widget {
export declare class CodeMirrorWidget extends Widget implements IEditorWidget {
/**

@@ -86,8 +82,5 @@ * Construct a CodeMirror widget.

* Get the editor model.
*/
/**
* Set the editor model.
*
* #### Notes
* This is a no-op if the value is `null` or the existing model.
* This is a read-only property.
*/

@@ -101,7 +94,2 @@ model: IEditorModel;

* Update the text in the widget.
*
* #### Notes
* This function attempts to restore the cursor to the correct
* place by using the bitap algorithm to find the corresponding
* position of the cursor in the new text.
*/

@@ -108,0 +96,0 @@ protected updateText(text: string): void;

@@ -35,2 +35,3 @@ // Copyright (c) Jupyter Development Team.

function CodeMirrorWidget(model) {
var _this = this;
_super.call(this);

@@ -42,3 +43,21 @@ this._editor = null;

this._editor = CodeMirror(this.node);
this.model = model;
this._model = model;
this.updateMimetype(model.mimetype);
this.updateFilename(model.filename);
this.updateReadOnly(model.readOnly);
this.updateTabSize(model.tabSize);
this.updateLineNumbers(model.lineNumbers);
this.updateFixedHeight(model.fixedHeight);
this.updateText(model.text);
CodeMirror.on(this._editor.getDoc(), 'change', function (instance, change) {
_this._model.text = instance.getValue();
_this._model.dirty = true;
});
this._editor.on('focus', function () {
_this._model.focused = true;
});
this._editor.on('blur', function () {
_this._model.focused = false;
});
model.stateChanged.connect(this.onModelStateChanged, this);
}

@@ -48,2 +67,5 @@ Object.defineProperty(CodeMirrorWidget.prototype, "model", {

* Get the editor model.
*
* #### Notes
* This is a read-only property.
*/

@@ -53,34 +75,2 @@ get: function () {

},
/**
* Set the editor model.
*
* #### Notes
* This is a no-op if the value is `null` or the existing model.
*/
set: function (value) {
var _this = this;
if (value === null || value === this._model) {
return;
}
if (this._model !== null) {
this._model.stateChanged.disconnect(this.onModelStateChanged, this);
this._model.selected.connect(function () {
if (!_this.model.readOnly)
_this._editor.focus();
});
}
this._model = value;
this.updateMimetype(value.mimetype);
this.updateFilename(value.filename);
this.updateReadOnly(value.readOnly);
this.updateTabSize(value.tabSize);
this.updateLineNumbers(value.lineNumbers);
this.updateFixedHeight(value.fixedHeight);
this.updateText(value.text);
CodeMirror.on(this._editor.getDoc(), 'change', function (instance, change) {
_this._model.text = instance.getValue();
_this._model.dirty = true;
});
value.stateChanged.connect(this.onModelStateChanged, this);
},
enumerable: true,

@@ -97,7 +87,2 @@ configurable: true

* Update the text in the widget.
*
* #### Notes
* This function attempts to restore the cursor to the correct
* place by using the bitap algorithm to find the corresponding
* position of the cursor in the new text.
*/

@@ -241,2 +226,6 @@ CodeMirrorWidget.prototype.updateText = function (text) {

break;
case 'focused':
if (args.newValue) {
this._editor.focus();
}
}

@@ -243,0 +232,0 @@ };

import { IChangedArgs } from 'phosphor-properties';
import { ISignal } from 'phosphor-signaling';
import { IEditorModel, IEditorOptions, EditorModel } from '../editor';
import { IEditorModel } from '../editor';
/**

@@ -18,15 +18,9 @@ * The model for an input area.

* Whether the input area should be collapsed (hidden) or expanded.
*
* // TODO: this should probably be a property on the cell, not the input area.
*/
collapsed: boolean;
/**
* The prompt number to display for the input area.
* The prompt text to display for the input area.
*/
promptNumber: number;
prompt: string;
/**
* The execution count.
*/
executionCount: number;
/**
* The dirty state of the input cell.

@@ -41,7 +35,2 @@ */

/**
* The options for creating an input area.
*/
export interface IInputAreaOptions extends IEditorOptions {
}
/**
* An implementation of an input area model.

@@ -53,3 +42,3 @@ */

*/
constructor(options?: IInputAreaOptions);
constructor(editor: IEditorModel);
/**

@@ -67,16 +56,9 @@ * A signal emitted when the state of the model changes.

/**
* Get the prompt number.
* Get the prompt text.
*/
/**
* Set the prompt number.
* Set the prompt text.
*/
promptNumber: number;
prompt: string;
/**
* Get the execution count of the input area.
*/
/**
* Set the execution count of the input area.
*/
executionCount: number;
/**
* Get the text editor Model.

@@ -87,3 +69,3 @@ *

*/
textEditor: EditorModel;
textEditor: IEditorModel;
/**

@@ -93,3 +75,3 @@ * Get the dirty state.

* #### Notest
* This is a pure delegate to the dirty state of the [textEditor].
* This is a delegate to the dirty state of the [textEditor].
*/

@@ -100,3 +82,3 @@ /**

* #### Notest
* This is a pure delegate to the dirty state of the [textEditor].
* This is a delegate to the dirty state of the [textEditor].
*/

@@ -112,5 +94,6 @@ dirty: boolean;

/**
* Re-emit changes to the text editor dirty state.
* Handle changes to the editor state.
*/
private _textEditorChanged(editor, args);
protected onEditorChanged(editor: IEditorModel, args: IChangedArgs<any>): void;
private _editor;
}

@@ -6,3 +6,2 @@ // Copyright (c) Jupyter Development Team.

var phosphor_signaling_1 = require('phosphor-signaling');
var editor_1 = require('../editor');
/**

@@ -15,6 +14,6 @@ * An implementation of an input area model.

*/
function InputAreaModel(options) {
var editor = new editor_1.EditorModel(options);
InputAreaModelPrivate.textEditorProperty.set(this, editor);
editor.stateChanged.connect(this._textEditorChanged, this);
function InputAreaModel(editor) {
this._editor = null;
this._editor = editor;
editor.stateChanged.connect(this.onEditorChanged, this);
}

@@ -47,14 +46,14 @@ Object.defineProperty(InputAreaModel.prototype, "stateChanged", {

});
Object.defineProperty(InputAreaModel.prototype, "promptNumber", {
Object.defineProperty(InputAreaModel.prototype, "prompt", {
/**
* Get the prompt number.
* Get the prompt text.
*/
get: function () {
return InputAreaModelPrivate.promptNumberProperty.get(this);
return InputAreaModelPrivate.promptProperty.get(this);
},
/**
* Set the prompt number.
* Set the prompt text.
*/
set: function (value) {
InputAreaModelPrivate.promptNumberProperty.set(this, value);
InputAreaModelPrivate.promptProperty.set(this, value);
},

@@ -64,18 +63,2 @@ enumerable: true,

});
Object.defineProperty(InputAreaModel.prototype, "executionCount", {
/**
* Get the execution count of the input area.
*/
get: function () {
return InputAreaModelPrivate.executionCountProperty.get(this);
},
/**
* Set the execution count of the input area.
*/
set: function (value) {
InputAreaModelPrivate.executionCountProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(InputAreaModel.prototype, "textEditor", {

@@ -89,3 +72,3 @@ /**

get: function () {
return InputAreaModelPrivate.textEditorProperty.get(this);
return this._editor;
},

@@ -100,3 +83,3 @@ enumerable: true,

* #### Notest
* This is a pure delegate to the dirty state of the [textEditor].
* This is a delegate to the dirty state of the [textEditor].
*/

@@ -110,3 +93,3 @@ get: function () {

* #### Notest
* This is a pure delegate to the dirty state of the [textEditor].
* This is a delegate to the dirty state of the [textEditor].
*/

@@ -136,6 +119,7 @@ set: function (value) {

/**
* Re-emit changes to the text editor dirty state.
* Handle changes to the editor state.
*/
InputAreaModel.prototype._textEditorChanged = function (editor, args) {
if (editor === this.textEditor && args.name === 'dirty') {
InputAreaModel.prototype.onEditorChanged = function (editor, args) {
if (args.name === 'dirty') {
// Re-emit dirty state changes from the editor.
this.stateChanged.emit(args);

@@ -164,22 +148,8 @@ }

/**
* A property descriptor containing the prompt number.
* A property descriptor containing the prompt.
*/
InputAreaModelPrivate.promptNumberProperty = new phosphor_properties_1.Property({
name: 'promptNumber',
InputAreaModelPrivate.promptProperty = new phosphor_properties_1.Property({
name: 'prompt',
notify: InputAreaModelPrivate.stateChangedSignal,
});
/**
* A property descriptor containing the execution count of the input area.
*/
InputAreaModelPrivate.executionCountProperty = new phosphor_properties_1.Property({
name: 'executionCount',
notify: InputAreaModelPrivate.stateChangedSignal,
});
/**
* A property descriptor containing the text editor Model.
*/
InputAreaModelPrivate.textEditorProperty = new phosphor_properties_1.Property({
name: 'textEditor',
notify: InputAreaModelPrivate.stateChangedSignal,
});
})(InputAreaModelPrivate || (InputAreaModelPrivate = {}));

@@ -0,3 +1,4 @@

import { IChangedArgs } from 'phosphor-properties';
import { Widget } from 'phosphor-widget';
import { IEditorModel } from '../editor';
import { CodeMirrorWidget } from '../editor';
import { IInputAreaModel } from './model';

@@ -13,11 +14,29 @@ /**

/**
* Update the text editor model, creating a new text editor
* widget and detaching the old one.
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
updateTextEditor(editor: IEditorModel): void;
model: IInputAreaModel;
/**
* Get the editor widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
editor: CodeMirrorWidget;
/**
* Get the prompt widget for the input area.
*
* #### Notes
* This is a read-only property.
*/
prompt: Widget;
/**
* Change handler for model updates.
*/
private _modelUpdate(sender, args);
protected onModelUpdated(sender: IInputAreaModel, args: IChangedArgs<any>): void;
private _model;
private _editor;
private _prompt;
}

@@ -13,2 +13,26 @@ // Copyright (c) Jupyter Development Team.

/**
* The class name added to input area widgets.
*/
var INPUT_CLASS = 'jp-InputArea';
/**
* The class name added to the prompt area of the input area.
*/
var PROMPT_CLASS = 'jp-InputArea-prompt';
/**
* The class name added to the editor area of the input area.
*/
var EDITOR_CLASS = 'jp-InputArea-editor';
/**
* The class name added to the input area when collapsed.
*/
var COLLAPSED_CLASS = 'jp-mod-collapsed';
/**
* The class name added to to the input area when dirty.
*/
var DIRTY_CLASS = 'jp-mod-dirty';
/**
* The class name added to to the input area when readonly.
*/
var READONLY_CLASS = 'jp-mod-readOnly';
/**
* An input area widget, which hosts an editor widget.

@@ -23,33 +47,89 @@ */

_super.call(this);
this.addClass('jp-InputArea');
this._model = null;
this._editor = null;
this._prompt = null;
this.addClass(INPUT_CLASS);
this._model = model;
this.layout = new phosphor_panel_1.PanelLayout();
this.updateTextEditor(model.textEditor);
model.stateChanged.connect(this._modelUpdate, this);
this._prompt = new phosphor_widget_1.Widget();
this._prompt.addClass(PROMPT_CLASS);
this._prompt.node.textContent = model.prompt;
this._editor = new editor_1.CodeMirrorWidget(model.textEditor);
this._editor.addClass(EDITOR_CLASS);
var layout = this.layout;
layout.addChild(this._prompt);
layout.addChild(this._editor);
model.stateChanged.connect(this.onModelUpdated, this);
}
Object.defineProperty(InputAreaWidget.prototype, "model", {
/**
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
Object.defineProperty(InputAreaWidget.prototype, "editor", {
/**
* Get the editor widget used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._editor;
},
enumerable: true,
configurable: true
});
Object.defineProperty(InputAreaWidget.prototype, "prompt", {
/**
* Get the prompt widget for the input area.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._prompt;
},
enumerable: true,
configurable: true
});
/**
* Update the text editor model, creating a new text editor
* widget and detaching the old one.
*/
InputAreaWidget.prototype.updateTextEditor = function (editor) {
var layout = this.layout;
if (layout.childCount() > 0) {
layout.childAt(0).dispose();
}
layout.addChild(new editor_1.CodeMirrorWidget(editor));
};
/**
* Change handler for model updates.
*/
InputAreaWidget.prototype._modelUpdate = function (sender, args) {
InputAreaWidget.prototype.onModelUpdated = function (sender, args) {
switch (args.name) {
case 'textEditor':
this.updateTextEditor(args.newValue);
break;
case 'collapsed':
if (args.newValue) {
this.addClass(COLLAPSED_CLASS);
}
else {
this.removeClass(COLLAPSED_CLASS);
}
break;
case 'promptNumber':
case 'dirty':
if (args.newValue) {
this.addClass(DIRTY_CLASS);
}
else {
this.removeClass(DIRTY_CLASS);
}
break;
case 'executionCount':
case 'readOnly':
if (args.newValue) {
this.addClass(READONLY_CLASS);
}
else {
this.removeClass(READONLY_CLASS);
}
break;
case 'prompt':
this.prompt.node.textContent = args.newValue;
break;
}

@@ -56,0 +136,0 @@ };

export * from './model';
export * from './nbformat';
export * from './serialize';
export * from './widget';
export * from './serialize';
export * from './nbformat';

@@ -8,4 +8,4 @@ // Copyright (c) Jupyter Development Team.

__export(require('./model'));
__export(require('./nbformat'));
__export(require('./serialize'));
__export(require('./widget'));
__export(require('./serialize'));
__export(require('./nbformat'));

@@ -5,9 +5,8 @@ import { INotebookSession } from 'jupyter-js-services';

import { ISignal } from 'phosphor-signaling';
import { ICellModel, ICodeCellModel, CodeCellModel, IMarkdownCellModel } from '../cells';
import { NotebookMetadata } from './nbformat';
import { IEditorModel, IEditorOptions } from '../editor';
import { IInputAreaModel } from '../input-area';
import { IOutputAreaModel } from '../output-area';
import { ICellModel, ICodeCellModel, CodeCellModel, IMarkdownCellModel, IRawCellModel } from '../cells';
import { INotebookMetadata } from './nbformat';
/**
* The interactivity modes for a notebook.
*/
export declare type NotebookMode = "command" | "edit";
/**
* The definition of a model object for a notebook widget.

@@ -42,6 +41,2 @@ */

/**
* The current interactivity mode of the notebook.
*/
mode: NotebookMode;
/**
* The list of cells in the notebook.

@@ -59,16 +54,5 @@ *

* The currently selected cell.
*
* #### Notes
* Changing this property will deselect the previous cell.
*/
selectedCellIndex: number;
/**
* Select the next cell in the notebook.
*/
selectNextCell(): void;
/**
* Select the previous cell in the notebook.
*/
selectPreviousCell(): void;
/**
* A factory for creating a new code cell.

@@ -103,2 +87,3 @@ *

*/
createRawCell(source?: ICellModel): IRawCellModel;
/**

@@ -111,3 +96,3 @@ * Run the selected cell, taking the appropriate action.

*/
metadata: NotebookMetadata;
metadata: INotebookMetadata;
}

@@ -119,2 +104,14 @@ /**

/**
* Create an editor model.
*/
static createEditor(options?: IEditorOptions): IEditorModel;
/**
* Create an input area model.
*/
static createInput(editor: IEditorModel): IInputAreaModel;
/**
* Create an output area model.
*/
static createOutputArea(): IOutputAreaModel;
/**
* Construct a new notebook model.

@@ -142,9 +139,2 @@ */

/**
* Get the mode of the notebook.
*/
/**
* Set the mode of the notebook.
*/
mode: NotebookMode;
/**
* Get the read-only status of the notebook.

@@ -169,3 +159,3 @@ */

*/
metadata: NotebookMetadata;
metadata: INotebookMetadata;
/**

@@ -186,10 +176,2 @@ * Get the selected cell index.

/**
* Select the next cell in the notebook.
*/
selectNextCell(): void;
/**
* Select the previous cell in the notebook.
*/
selectPreviousCell(): void;
/**
* Create a code cell model.

@@ -203,2 +185,6 @@ */

/**
* Create a raw cell model.
*/
createRawCell(source?: ICellModel): IRawCellModel;
/**
* Run the selected cell, taking the appropriate action.

@@ -205,0 +191,0 @@ */

@@ -5,4 +5,6 @@ "use strict";

var phosphor_signaling_1 = require('phosphor-signaling');
var editor_1 = require('../editor');
var input_area_1 = require('../input-area');
var output_area_1 = require('../output-area');
var cells_1 = require('../cells');
var serialize_1 = require('./serialize');
/**

@@ -19,2 +21,20 @@ * An implementation of a notebook Model.

}
/**
* Create an editor model.
*/
NotebookModel.createEditor = function (options) {
return new editor_1.EditorModel(options);
};
/**
* Create an input area model.
*/
NotebookModel.createInput = function (editor) {
return new input_area_1.InputAreaModel(editor);
};
/**
* Create an output area model.
*/
NotebookModel.createOutputArea = function () {
return new output_area_1.OutputAreaModel();
};
Object.defineProperty(NotebookModel.prototype, "stateChanged", {

@@ -59,18 +79,2 @@ /**

});
Object.defineProperty(NotebookModel.prototype, "mode", {
/**
* Get the mode of the notebook.
*/
get: function () {
return NotebookModelPrivate.modeProperty.get(this);
},
/**
* Set the mode of the notebook.
*/
set: function (value) {
NotebookModelPrivate.modeProperty.set(this, value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(NotebookModel.prototype, "readOnly", {

@@ -140,5 +144,7 @@ /**

NotebookModelPrivate.selectedCellIndexProperty.set(this, value);
var cell = this.cells.get(value);
if (cell)
cell.select();
var cells = this.cells;
for (var i = 0; i < cells.length; i++) {
var cell = cells.get(i);
cell.selected = value === i;
}
},

@@ -173,25 +179,27 @@ enumerable: true,

/**
* Select the next cell in the notebook.
*/
NotebookModel.prototype.selectNextCell = function () {
if (this.selectedCellIndex < this.cells.length - 1) {
this.selectedCellIndex += 1;
}
};
/**
* Select the previous cell in the notebook.
*/
NotebookModel.prototype.selectPreviousCell = function () {
if (this.selectedCellIndex > 0) {
this.selectedCellIndex -= 1;
}
};
/**
* Create a code cell model.
*/
NotebookModel.prototype.createCodeCell = function (source) {
return new cells_1.CodeCellModel({
mimetype: this.defaultMimetype,
var mimetype = this.defaultMimetype;
if (source) {
mimetype = source.input.textEditor.mimetype;
}
var constructor = this.constructor;
var editor = constructor.createEditor({
mimetype: mimetype,
readOnly: this.readOnly
});
var input = constructor.createInput(editor);
var output = constructor.createOutputArea();
var cell = new cells_1.CodeCellModel(input, output);
if (source) {
cell.input.textEditor.text = source.input.textEditor.text;
cell.dirty = source.dirty;
cell.tags = source.tags;
if (cells_1.isCodeCellModel(source)) {
cell.collapsed = source.collapsed;
cell.scrolled = source.scrolled;
}
}
return cell;
};

@@ -202,8 +210,40 @@ /**

NotebookModel.prototype.createMarkdownCell = function (source) {
return new cells_1.MarkdownCellModel({
var constructor = this.constructor;
var editor = constructor.createEditor({
mimetype: 'text/x-ipythongfm',
readOnly: this.readOnly
});
var input = constructor.createInput(editor);
var cell = new cells_1.MarkdownCellModel(input);
if (source) {
cell.input.textEditor.text = source.input.textEditor.text;
cell.dirty = source.dirty;
cell.tags = source.tags;
if (cells_1.isMarkdownCellModel(source)) {
cell.rendered = source.rendered;
}
}
return cell;
};
/**
* Create a raw cell model.
*/
NotebookModel.prototype.createRawCell = function (source) {
var constructor = this.constructor;
var editor = constructor.createEditor({
readOnly: this.readOnly
});
var input = constructor.createInput(editor);
var cell = new cells_1.RawCellModel(input);
if (source) {
cell.input.textEditor.text = source.input.textEditor.text;
cell.dirty = source.dirty;
cell.tags = source.tags;
if (cells_1.isRawCellModel(source)) {
cell.format = source.format;
}
}
return cell;
};
/**
* Run the selected cell, taking the appropriate action.

@@ -228,4 +268,7 @@ */

this.cells.add(cell_1);
cell_1.mode = 'edit'; // This already sets the new index.
}
this.selectNextCell();
else {
this.selectedCellIndex += 1;
}
};

@@ -239,2 +282,7 @@ /**

}
var text = cell.input.textEditor.text.trim();
if (!text) {
cell.input.prompt = 'In [ ]:';
return;
}
var session = this.session;

@@ -244,2 +292,3 @@ if (!session) {

}
cell.input.prompt = 'In [*]:';
var exRequest = {

@@ -256,7 +305,11 @@ code: cell.input.textEditor.text,

ex.onIOPub = (function (msg) {
var model = serialize_1.messageToModel(msg);
var model = msg.content;
if (model !== void 0) {
model.output_type = msg.header.msg_type;
output.add(model);
}
});
ex.onReply = (function (msg) {
cell.executionCount = msg.content.execution_count;
});
};

@@ -279,2 +332,10 @@ /**

}
if (change.name === 'mode' && change.newValue === 'edit') {
var cells = this.cells;
for (var i = 0; i < cells.length; i++) {
if (cells.get(i) === cell) {
this.selectedCellIndex = i;
}
}
}
};

@@ -302,9 +363,2 @@ return NotebookModel;

/**
* A property descriptor which holds the mode of the notebook.
*/
NotebookModelPrivate.modeProperty = new phosphor_properties_1.Property({
name: 'mode',
notify: NotebookModelPrivate.stateChangedSignal,
});
/**
* A property descriptor which holds the read only status of the notebook.

@@ -311,0 +365,0 @@ */

@@ -1,4 +0,1 @@

import { MimeBundle, OutputType } from '../output-area';
import { CellType } from '../cells';
export declare type multilineString = string;
/**

@@ -12,64 +9,6 @@ * The major version of the notebook format.

export declare const MINOR_VERSION: number;
export interface BaseOutput {
output_type: OutputType;
}
export interface DisplayData extends BaseOutput {
output_type: "display_data";
data: MimeBundle;
metadata: {};
}
export interface ExecuteResult extends BaseOutput {
output_type: "execute_result";
execution_count: number;
data: MimeBundle;
metadata: {};
}
export interface Stream extends BaseOutput {
output_type: "stream";
name: string;
text: multilineString;
}
export interface JupyterError extends BaseOutput {
output_type: "error";
ename: string;
evalue: string;
traceback: string[];
}
export declare type Output = ExecuteResult | DisplayData | Stream | JupyterError;
export declare function isExecuteResult(d: BaseOutput): d is ExecuteResult;
export declare function isDisplayData(d: BaseOutput): d is DisplayData;
export declare function isStream(d: BaseOutput): d is Stream;
export declare function isJupyterError(d: BaseOutput): d is JupyterError;
export declare type Cell = BaseCell | RawCell | MarkdownCell | CodeCell;
export interface BaseCell {
cell_type: CellType;
source: multilineString;
metadata: {
name?: string;
tags?: string[];
};
}
export interface RawCell extends BaseCell {
cell_type: "raw";
metadata: {
format?: string;
};
}
export interface MarkdownCell extends BaseCell {
cell_type: "markdown";
}
export interface CodeCell extends BaseCell {
cell_type: "code";
metadata: {
name?: string;
tags?: string[];
collapsed?: boolean;
scrolled?: boolean | string;
};
outputs: Output[];
execution_count: number;
}
export declare function isMarkdownCell(d: BaseCell): d is MarkdownCell;
export declare function isCodeCell(d: BaseCell): d is CodeCell;
export interface NotebookMetadata {
/**
* The notebook metadata.
*/
export interface INotebookMetadata {
kernelspec: {

@@ -81,3 +20,3 @@ name: string;

name: string;
codemirror_mode?: string | {};
codemirror_mode?: any;
file_extension?: string;

@@ -89,7 +28,249 @@ mimetype?: string;

}
export interface NotebookContent {
metadata: NotebookMetadata;
/**
* The notebook content.
*/
export interface INotebookContent {
metadata: INotebookMetadata;
nbformat_minor: number;
nbformat: number;
cells: Cell[];
cells: ICell[];
}
/**
* A type alias for a multiline string.
*/
export declare type multilineString = string | string[];
/**
* A mime-type keyed dictionary of data.
*/
export interface MimeBundle {
[key: string]: multilineString;
'application/json'?: any;
}
/**
* A type which describes the type of cell.
*/
export declare type CellType = 'code' | 'markdown' | 'raw';
/**
* Cell-level metadata.
*/
export interface IBaseCellMetadata {
/**
* The cell's name. If present, must be a non-empty string.
*/
name?: string;
/**
* The cell's tags. Tags must be unique, and must not contain commas.
*/
tags?: string[];
}
/**
* The base cell interface.
*/
export interface IBaseCell {
/**
* String identifying the type of cell.
*/
cell_type: CellType;
/**
* Contents of the cell, represented as an array of lines.
*/
source: multilineString;
/**
* Cell-level metadata.
*/
metadata: ICellMetadata;
}
/**
* Metadata for the raw cell.
*/
export interface IRawCellMetadata extends IBaseCellMetadata {
/**
* Raw cell metadata format for nbconvert.
*/
format?: string;
}
/**
* A raw cell.
*/
export interface IRawCell extends IBaseCell {
/**
* String identifying the type of cell.
*/
cell_type: 'raw';
/**
* Cell-level metadata.
*/
metadata: IRawCellMetadata;
}
/**
* A markdown cell.
*/
export interface IMarkdownCell extends IBaseCell {
/**
* String identifying the type of cell.
*/
cell_type: 'markdown';
}
/**
* Metadata for a code cell.
*/
export interface ICodeCellMetadata extends IBaseCellMetadata {
/**
* Whether the cell is collapsed/expanded.
*/
collapsed?: boolean;
/**
* Whether the cell's output is scrolled, unscrolled, or autoscrolled.
*/
scrolled?: boolean | 'auto';
}
/**
* A code cell.
*/
export interface ICodeCell extends IBaseCell {
/**
* String identifying the type of cell.
*/
cell_type: 'code';
/**
* Cell-level metadata.
*/
metadata: ICodeCellMetadata;
/**
* Execution, display, or stream outputs.
*/
outputs: IOutput[];
/**
* The code cell's prompt number. Will be null if the cell has not been run.
*/
execution_count: number;
}
/**
* A cell union type.
*/
export declare type ICell = IBaseCell | IRawCell | IMarkdownCell | ICodeCell;
/**
* A union metadata type.
*/
export declare type ICellMetadata = IBaseCellMetadata | IRawCellMetadata | ICodeCellMetadata;
/**
* Check if cell is of markdown type.
*/
export declare function isMarkdownCell(d: IBaseCell): d is IMarkdownCell;
/**
* Check if cell is of code type.
*/
export declare function isCodeCell(d: IBaseCell): d is ICodeCell;
/**
* Check if cell is of raw type.
*/
export declare function isRawCell(d: IBaseCell): d is IRawCell;
/**
* The valid output types.
*/
export declare type OutputType = 'execute_result' | 'display_data' | 'stream' | 'error';
/**
* The base output type.
*/
export interface IBaseOutput {
/**
* Type of cell output.
*/
output_type: OutputType;
}
/**
* Result of executing a code cell.
*/
export interface IExecuteResult extends IBaseOutput {
/**
* Type of cell output.
*/
output_type: 'execute_result';
/**
* A result's prompt number.
*/
execution_count: number;
/**
* A mime-type keyed dictionary of data.
*/
data: MimeBundle;
/**
* Cell output metadata.
*/
metadata: {};
}
/**
* Data displayed as a result of code cell execution.
*/
export interface IDisplayData extends IBaseOutput {
/**
* Type of cell output.
*/
output_type: 'display_data';
/**
* A mime-type keyed dictionary of data.
*/
data: MimeBundle;
/**
* Cell output metadata.
*/
metadata: {};
}
/**
* Stream output from a code cell.
*/
export interface IStream extends IBaseOutput {
/**
* Type of cell output.
*/
output_type: 'stream';
/**
* The name of the stream.
*/
name: 'stdout' | 'stderr';
/**
* The stream's text output.
*/
text: multilineString;
}
/**
* Output of an error that occurred during code cell execution.
*/
export interface IError extends IBaseOutput {
/**
* Type of cell output.
*/
output_type: 'error';
/**
* The name of the error.
*/
ename: string;
/**
* The value, or message, of the error.
*/
evalue: string;
/**
* The error's traceback.
*/
traceback: string[];
}
/**
* An output union type.
*/
export declare type IOutput = IExecuteResult | IDisplayData | IStream | IError;
/**
* Check if output is an `execute_result`.
*/
export declare function isExecuteResult(d: IBaseOutput): d is IExecuteResult;
/**
* Check if output is a `display_data`.
*/
export declare function isDisplayData(d: IBaseOutput): d is IDisplayData;
/**
* Check if output is `stream`.
*/
export declare function isStream(d: IBaseOutput): d is IStream;
/**
* Check if output is `error`.
*/
export declare function isError(d: IBaseOutput): d is IError;

@@ -13,25 +13,50 @@ // Notebook format interfaces

exports.MINOR_VERSION = 0;
/**
* Check if cell is of markdown type.
*/
function isMarkdownCell(d) {
return d.cell_type === 'markdown';
}
exports.isMarkdownCell = isMarkdownCell;
/**
* Check if cell is of code type.
*/
function isCodeCell(d) {
return d.cell_type === 'code';
}
exports.isCodeCell = isCodeCell;
/**
* Check if cell is of raw type.
*/
function isRawCell(d) {
return d.cell_type === 'raw';
}
exports.isRawCell = isRawCell;
/**
* Check if output is an `execute_result`.
*/
function isExecuteResult(d) {
return d.output_type === "execute_result";
return d.output_type === 'execute_result';
}
exports.isExecuteResult = isExecuteResult;
/**
* Check if output is a `display_data`.
*/
function isDisplayData(d) {
return d.output_type === "display_data";
return d.output_type === 'display_data';
}
exports.isDisplayData = isDisplayData;
/**
* Check if output is `stream`.
*/
function isStream(d) {
return d.output_type === "stream";
return d.output_type === 'stream';
}
exports.isStream = isStream;
function isJupyterError(d) {
return d.output_type === "error";
/**
* Check if output is `error`.
*/
function isError(d) {
return d.output_type === 'error';
}
exports.isJupyterError = isJupyterError;
function isMarkdownCell(d) {
return d.cell_type === "markdown";
}
exports.isMarkdownCell = isMarkdownCell;
function isCodeCell(d) {
return d.cell_type === "code";
}
exports.isCodeCell = isCodeCell;
exports.isError = isError;

@@ -1,20 +0,10 @@

import { IKernelMessage } from 'jupyter-js-services';
import { INotebookContent } from './nbformat';
import { INotebookModel } from './model';
import { DisplayDataModel, ExecuteResultModel, ExecuteErrorModel, StreamModel, OutputModel } from '../output-area';
import { NotebookContent, Output } from './nbformat';
/**
* Build a complete notebook model from the notebook data.
* Serialize a notebook model.
*/
export declare function populateNotebookModel(nb: INotebookModel, data: NotebookContent): void;
export declare function serialize(nb: INotebookModel): INotebookContent;
/**
* Build an output model from output message data.
* Deserialize notebook content into a model.
*/
export declare function buildOutputModel(out: Output): OutputModel;
/**
* Convert a kernel message to an output model.
*/
export declare function messageToModel(msg: IKernelMessage): ExecuteResultModel | DisplayDataModel | StreamModel | ExecuteErrorModel;
/**
* Get the current notebook content.
*/
export declare function getNotebookContent(nb: INotebookModel): NotebookContent;
export declare function deserialize(data: INotebookContent, model: INotebookModel): void;

@@ -5,79 +5,14 @@ // Copyright (c) Jupyter Development Team.

var cells_1 = require('../cells');
var output_area_1 = require('../output-area');
var nbformat_1 = require('./nbformat');
/**
* Build a complete notebook model from the notebook data.
* Serialize a notebook model.
*/
function populateNotebookModel(nb, data) {
nb.cells.clear();
// Iterate through the cell data, creating cell models.
data.cells.forEach(function (c) {
if (nbformat_1.isMarkdownCell(c)) {
var cell = nb.createMarkdownCell();
cell.input.textEditor.text = c.source;
cell.rendered = true;
nb.cells.add(cell);
}
else if (nbformat_1.isCodeCell(c)) {
var cell = nb.createCodeCell();
cell.input.textEditor.text = c.source;
for (var i = 0; i < c.outputs.length; i++) {
cell.output.add(buildOutputModel(c.outputs[i]));
}
nb.cells.add(cell);
}
});
if (nb.cells.length) {
nb.selectedCellIndex = 0;
function serialize(nb) {
var cells = [];
for (var i = 0; i < nb.cells.length; i++) {
var cell = nb.cells.get(i);
cells.push(serializeCell(cell));
}
nb.metadata = data.metadata;
}
exports.populateNotebookModel = populateNotebookModel;
/**
* Build an output model from output message data.
*/
function buildOutputModel(out) {
if (nbformat_1.isDisplayData(out)) {
var outmodel = new output_area_1.DisplayDataModel();
outmodel.data = out.data;
outmodel.metadata = out.metadata;
return outmodel;
}
if (nbformat_1.isStream(out)) {
var outmodel = new output_area_1.StreamModel();
outmodel.name = out.name;
outmodel.text = out.text;
return outmodel;
}
if (nbformat_1.isJupyterError(out)) {
var outmodel = new output_area_1.ExecuteErrorModel();
outmodel.ename = out.ename;
outmodel.evalue = out.evalue;
outmodel.traceback = out.traceback.join('\n');
return outmodel;
}
if (nbformat_1.isExecuteResult(out)) {
var outmodel = new output_area_1.ExecuteResultModel();
outmodel.data = out.data;
outmodel.executionCount = out.execution_count;
outmodel.metadata = out.metadata;
return outmodel;
}
}
exports.buildOutputModel = buildOutputModel;
/**
* Convert a kernel message to an output model.
*/
function messageToModel(msg) {
var m = msg.content;
m.output_type = msg.header.msg_type;
return buildOutputModel(m);
}
exports.messageToModel = messageToModel;
/**
* Get the current notebook content.
*/
function getNotebookContent(nb) {
return {
cells: getNotebookCells(nb),
cells: cells,
metadata: nb.metadata,

@@ -88,75 +23,80 @@ nbformat: nbformat_1.MAJOR_VERSION,

}
exports.getNotebookContent = getNotebookContent;
exports.serialize = serialize;
/**
* Get the cell data for a given notebook.
* Deserialize notebook content into a model.
*/
function getNotebookCells(nb) {
var cells = [];
for (var i = 0; i < nb.cells.length; i++) {
var cell = nb.cells.get(i);
var text = cell.input.textEditor.text;
var tags = [];
if (cell.tags) {
for (var i_1 = 0; i_1 < cell.tags.length; i_1++) {
tags.push(cell.tags.get(i_1));
}
function deserialize(data, model) {
model.cells.clear();
// Iterate through the cell data, creating cell models.
data.cells.forEach(function (c) {
var cell;
if (nbformat_1.isMarkdownCell(c)) {
cell = model.createMarkdownCell();
}
if (cells_1.isCodeCellModel(cell)) {
cells.push({
source: text,
cell_type: 'code',
metadata: { tags: tags },
outputs: getOutputData(cell),
execution_count: cell.executionCount
});
else if (nbformat_1.isCodeCell(c)) {
cell = model.createCodeCell();
}
else if (cells_1.isMarkdownCellModel(cell)) {
cells.push({
cell_type: 'markdown',
source: text,
metadata: { tags: tags },
});
else if (nbformat_1.isRawCell(c)) {
cell = model.createRawCell();
}
deserializeCell(c, cell);
model.cells.add(cell);
});
if (model.cells.length) {
model.selectedCellIndex = 0;
}
return cells;
model.metadata = data.metadata;
}
exports.deserialize = deserialize;
/**
* Get the output data for a given cell.
* Serialize a cell model.
*/
function getOutputData(cell) {
var outputs = [];
for (var i = 0; i < cell.output.outputs.length; i++) {
var output = cell.output.outputs.get(i);
if (output instanceof output_area_1.ExecuteResultModel) {
outputs.push({
output_type: 'execute_result',
execution_count: cell.executionCount,
data: output.data,
metadata: output.metadata
});
function serializeCell(cell) {
var output = {
source: cell.input.textEditor.text,
cell_type: cell.type,
metadata: {
tags: cell.tags,
name: cell.name
}
else if (output instanceof output_area_1.StreamModel) {
outputs.push({
output_type: 'stream',
name: output.name,
text: output.text
});
};
if (cells_1.isRawCellModel(cell)) {
output.metadata.format = cell.format;
}
else if (cells_1.isCodeCellModel(cell)) {
var out = output;
out.metadata.scrolled = cell.scrolled;
out.metadata.collapsed = cell.collapsed;
out.outputs = [];
for (var i = 0; i < cell.output.outputs.length; i++) {
out.outputs.push(cell.output.outputs.get(i));
}
else if (output instanceof output_area_1.DisplayDataModel) {
outputs.push({
output_type: 'display_data',
data: output.data,
metadata: output.metadata
});
out.execution_count = cell.executionCount;
}
return output;
}
/**
* Deserialize cell data.
*/
function deserializeCell(data, model) {
var source = data.source;
if (Array.isArray(data.source)) {
source = data.source.join('\n');
}
model.input.textEditor.text = source;
model.tags = data.metadata.tags;
model.name = data.metadata.name;
if (cells_1.isCodeCellModel(model)) {
var value = data;
model.collapsed = value.metadata.collapsed;
model.scrolled = value.metadata.scrolled;
model.executionCount = value.execution_count;
for (var i = 0; i < value.outputs.length; i++) {
model.output.add(value.outputs[i]);
}
else if (output instanceof output_area_1.ExecuteErrorModel) {
outputs.push({
output_type: 'error',
ename: output.ename,
evalue: output.evalue,
traceback: output.traceback.split('\n')
});
}
}
return outputs;
else if (cells_1.isRawCellModel(model)) {
model.format = data.metadata.format;
;
}
}

@@ -0,4 +1,5 @@

import { Message } from 'phosphor-messaging';
import { IChangedArgs } from 'phosphor-properties';
import { IObservableList, IListChangedArgs } from 'phosphor-observablelist';
import { Panel } from 'phosphor-panel';
import { Widget } from 'phosphor-widget';
import { INotebookModel } from './model';

@@ -11,8 +12,42 @@ import { ICellModel } from '../cells';

*/
export declare class NotebookWidget extends Panel {
export declare class NotebookWidget extends Widget {
/**
* Construct a code cell widget.
* Construct a notebook widget.
*/
constructor(model: INotebookModel);
/**
* Get the model for the widget.
*
* #### Notes
* This is a read-only property.
*/
model: INotebookModel;
/**
* Dispose of the resources held by the widget.
*/
dispose(): void;
/**
* Handle the DOM events for the widget.
*
* @param event - The DOM event sent to the widget.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the dock panel's node. It should
* not be called directly by user code.
*/
handleEvent(event: Event): void;
/**
* Handle `after_attach` messages for the widget.
*/
protected onAfterAttach(msg: Message): void;
/**
* Handle `before_detach` messages for the widget.
*/
protected onBeforeDetach(msg: Message): void;
/**
* Create a new cell widget given a cell model.
*/
protected createCell(cell: ICellModel): Widget;
/**
* Find the cell index containing the target html element.

@@ -23,25 +58,24 @@ *

*/
findCell(node: HTMLElement): number;
protected findCell(node: HTMLElement): number;
/**
* Handle a change cells event.
* Handle a selected index change.
*/
protected cellsChanged(sender: IObservableList<ICellModel>, args: IListChangedArgs<ICellModel>): void;
protected updateSelectedCell(newIndex: number, oldIndex?: number): void;
/**
* Handle a selection change event.
* Change handler for model updates.
*/
updateSelectedCell(newIndex: number, oldIndex?: number): void;
protected onModelChanged(sender: INotebookModel, args: IChangedArgs<any>): void;
/**
* Change handler for model updates.
* Handle a change cells event.
*/
protected modelStateChanged(sender: INotebookModel, args: IChangedArgs<any>): void;
protected onCellsChanged(sender: IObservableList<ICellModel>, args: IListChangedArgs<ICellModel>): void;
/**
* Dispose this model.
* Handle `click` events for the widget.
*/
dispose(): void;
private _evtClick(event);
/**
* Get the model for the widget
* Handle `dblclick` events for the widget.
*/
model: INotebookModel;
private _evtDblClick(event);
private _model;
private _listdispose;
}

@@ -48,0 +82,0 @@ /**

@@ -13,3 +13,2 @@ // Copyright (c) Jupyter Development Team.

var cells_1 = require('../cells');
var phosphor_disposable_1 = require('phosphor-disposable');
require('./codemirror-ipython');

@@ -35,52 +34,97 @@ require('./codemirror-ipythongfm');

/**
* Construct a code cell widget.
* Construct a notebook widget.
*/
function NotebookWidget(model) {
var _this = this;
_super.call(this);
this.addClass(NB_CLASS);
this._model = model;
this._listdispose = follow(model.cells, this, function (c) {
var w;
switch (c.type) {
case "code":
w = new cells_1.CodeCellWidget(c);
break;
case "markdown":
w = new cells_1.MarkdownCellWidget(c);
break;
default:
// if there are any issues, just return a blank placeholder
// widget so the lists stay in sync
w = new phosphor_widget_1.Widget();
}
w.addClass(NB_CELL_CLASS);
return w;
});
this.updateSelectedCell(model.selectedCellIndex);
// bind events that can select the cell
// see https://github.com/jupyter/notebook/blob/203ccd3d4496cc22e6a1c5e6ece9f5a7d791472a/notebook/static/notebook/js/cell.js#L178
this.node.addEventListener('click', function (ev) {
if (!_this._model.readOnly) {
_this._model.selectedCellIndex = _this.findCell(ev.target);
}
});
this.node.addEventListener('dblclick', function (ev) {
if (_this._model.readOnly) {
return;
}
var i = _this.findCell(ev.target);
if (i === void 0) {
return;
}
var cell = _this._model.cells.get(i);
if (cells_1.isMarkdownCellModel(cell) && cell.rendered) {
cell.rendered = false;
cell.input.textEditor.select();
}
});
model.stateChanged.connect(this.modelStateChanged, this);
model.cells.changed.connect(this.cellsChanged, this);
this.layout = new phosphor_panel_1.PanelLayout();
var layout = this.layout;
for (var i = 0; i < model.cells.length; i++) {
layout.addChild(this.createCell(model.cells.get(i)));
}
this.updateSelectedCell(this.model.selectedCellIndex);
model.stateChanged.connect(this.onModelChanged, this);
model.cells.changed.connect(this.onCellsChanged, this);
}
Object.defineProperty(NotebookWidget.prototype, "model", {
/**
* Get the model for the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
/**
* Dispose of the resources held by the widget.
*/
NotebookWidget.prototype.dispose = function () {
this._model.stateChanged.disconnect(this.onModelChanged);
this._model.cells.changed.disconnect(this.onCellsChanged);
this._model = null;
_super.prototype.dispose.call(this);
};
/**
* Handle the DOM events for the widget.
*
* @param event - The DOM event sent to the widget.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the dock panel's node. It should
* not be called directly by user code.
*/
NotebookWidget.prototype.handleEvent = function (event) {
switch (event.type) {
case 'click':
this._evtClick(event);
break;
case 'dblclick':
this._evtDblClick(event);
break;
}
};
/**
* Handle `after_attach` messages for the widget.
*/
NotebookWidget.prototype.onAfterAttach = function (msg) {
this.node.addEventListener('click', this);
this.node.addEventListener('dblclick', this);
};
/**
* Handle `before_detach` messages for the widget.
*/
NotebookWidget.prototype.onBeforeDetach = function (msg) {
this.node.removeEventListener('click', this);
this.node.removeEventListener('dblclick', this);
};
/**
* Create a new cell widget given a cell model.
*/
NotebookWidget.prototype.createCell = function (cell) {
var widget;
switch (cell.type) {
case 'code':
widget = new cells_1.CodeCellWidget(cell);
break;
case 'markdown':
widget = new cells_1.MarkdownCellWidget(cell);
break;
case 'raw':
widget = new cells_1.RawCellWidget(cell);
break;
default:
// If there are any issues, just return a blank placeholder
// widget so the lists stay in sync.
widget = new phosphor_widget_1.Widget();
}
widget.addClass(NB_CELL_CLASS);
return widget;
};
/**
* Find the cell index containing the target html element.

@@ -92,8 +136,9 @@ *

NotebookWidget.prototype.findCell = function (node) {
// Trace up the DOM hierarchy to find the root cell node
// then find the corresponding child and select it
// Trace up the DOM hierarchy to find the root cell node.
// Then find the corresponding child and select it.
var layout = this.layout;
while (node && node !== this.node) {
if (node.classList.contains(NB_CELL_CLASS)) {
for (var i = 0; i < this.childCount(); i++) {
if (this.childAt(i).node === node) {
for (var i = 0; i < layout.childCount(); i++) {
if (layout.childAt(i).node === node) {
return i;

@@ -106,19 +151,14 @@ }

}
return void 0;
return -1;
};
/**
* Handle a change cells event.
* Handle a selected index change.
*/
NotebookWidget.prototype.cellsChanged = function (sender, args) {
console.log(args);
};
/**
* Handle a selection change event.
*/
NotebookWidget.prototype.updateSelectedCell = function (newIndex, oldIndex) {
var layout = this.layout;
if (oldIndex !== void 0) {
this.childAt(oldIndex).removeClass(NB_SELECTED_CLASS);
layout.childAt(oldIndex).removeClass(NB_SELECTED_CLASS);
}
if (newIndex !== void 0) {
var newCell = this.childAt(newIndex);
var newCell = layout.childAt(newIndex);
newCell.addClass(NB_SELECTED_CLASS);

@@ -131,74 +171,84 @@ scrollIfNeeded(this.node, newCell.node);

*/
NotebookWidget.prototype.modelStateChanged = function (sender, args) {
NotebookWidget.prototype.onModelChanged = function (sender, args) {
switch (args.name) {
case 'defaultMimetype': break;
case 'mode': break;
case 'mode':
this.update();
break;
case 'selectedCellIndex':
this.updateSelectedCell(args.newValue, args.oldValue);
break;
}
};
/**
* Dispose this model.
* Handle a change cells event.
*/
NotebookWidget.prototype.dispose = function () {
this._listdispose.dispose();
_super.prototype.dispose.call(this);
};
Object.defineProperty(NotebookWidget.prototype, "model", {
/**
* Get the model for the widget
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
return NotebookWidget;
}(phosphor_panel_1.Panel));
exports.NotebookWidget = NotebookWidget;
/**
* Make a panel mirror changes to an observable list.
*
* @param source - The observable list.
* @param sink - The Panel.
* @param factory - A function which takes an item from the list and constructs a widget.
*/
function follow(source, sink, factory) {
for (var i = sink.childCount() - 1; i >= 0; i--) {
sink.childAt(i).dispose();
}
for (var i = 0; i < source.length; i++) {
sink.addChild(factory(source.get(i)));
}
function callback(sender, args) {
NotebookWidget.prototype.onCellsChanged = function (sender, args) {
var layout = this.layout;
var factory = this.createCell;
var widget;
switch (args.type) {
case phosphor_observablelist_1.ListChangeType.Add:
sink.insertChild(args.newIndex, factory(args.newValue));
layout.insertChild(args.newIndex, factory(args.newValue));
break;
case phosphor_observablelist_1.ListChangeType.Move:
sink.insertChild(args.newIndex, sink.childAt(args.oldIndex));
layout.insertChild(args.newIndex, layout.childAt(args.oldIndex));
break;
case phosphor_observablelist_1.ListChangeType.Remove:
sink.childAt(args.oldIndex).dispose();
widget = layout.childAt(args.oldIndex);
layout.removeChild(widget);
widget.dispose();
break;
case phosphor_observablelist_1.ListChangeType.Replace:
for (var i = args.oldValue.length; i > 0; i--) {
sink.childAt(args.oldIndex).dispose();
widget = layout.childAt(i);
layout.removeChild(widget);
widget.dispose();
}
for (var i = args.newValue.length; i > 0; i--) {
sink.insertChild(args.newIndex, factory(args.newValue[i]));
var newValues = args.newValue;
for (var i = 0; i < newValues.length; i++) {
layout.addChild(factory(newValues[i]));
}
break;
case phosphor_observablelist_1.ListChangeType.Set:
sink.childAt(args.newIndex).dispose();
sink.insertChild(args.newIndex, factory(args.newValue));
widget = layout.childAt(args.newIndex);
layout.removeChild(widget);
widget.dispose();
layout.insertChild(args.newIndex, factory(args.newValue));
break;
}
}
source.changed.connect(callback);
return new phosphor_disposable_1.DisposableDelegate(function () {
source.changed.disconnect(callback);
});
}
};
/**
* Handle `click` events for the widget.
*/
NotebookWidget.prototype._evtClick = function (event) {
var model = this.model;
if (!model.readOnly) {
var i = this.findCell(event.target);
if (i === -1) {
return;
}
model.selectedCellIndex = i;
}
};
/**
* Handle `dblclick` events for the widget.
*/
NotebookWidget.prototype._evtDblClick = function (event) {
var model = this._model;
if (model.readOnly) {
return;
}
var i = this.findCell(event.target);
if (i === -1) {
return;
}
var cell = model.cells.get(i);
if (cells_1.isMarkdownCellModel(cell) && cell.rendered) {
cell.rendered = false;
cell.mode = 'edit';
}
};
return NotebookWidget;
}(phosphor_widget_1.Widget));
exports.NotebookWidget = NotebookWidget;
/**

@@ -205,0 +255,0 @@ * Scroll an element into view if needed.

@@ -1,151 +0,37 @@

import { IChangedArgs, Property } from 'phosphor-properties';
import { ISignal, Signal } from 'phosphor-signaling';
import { ObservableList } from 'phosphor-observablelist';
import { IChangedArgs } from 'phosphor-properties';
import { ISignal } from 'phosphor-signaling';
import { IOutput, IStream, IExecuteResult, IDisplayData, IError } from '../notebook/nbformat';
/**
* A Mime bundle of data.
*/
export interface MimeBundle {
[key: string]: string;
'application/json'?: any;
}
/**
* The valid output type strings.
* The model for an output area.
*/
export declare type OutputType = "execute_result" | "display_data" | "stream" | "error";
/**
* The valid stream type strings.
*/
export declare type StreamType = "stdout" | "stderr";
/**
* The base interface for an output model.
*/
export declare class OutputBaseModel {
export interface IOutputAreaModel {
/**
* A signal emitted when state of the output changes.
* A signal emitted when state of the output area changes.
*/
stateChanged: ISignal<OutputBaseModel, IChangedArgs<any>>;
stateChanged: ISignal<IOutputAreaModel, IChangedArgs<any>>;
/**
* The output type.
* Whether the output is collapsed.
*/
outputType: OutputType;
}
/**
* An output model for display data.
*/
export declare class DisplayDataModel extends OutputBaseModel {
collapsed: boolean;
/**
* The output type.
* Whether the output has a fixed maximum height.
*/
outputType: OutputType;
fixedHeight: boolean;
/**
* The raw data for the output.
* The actual outputs.
*/
data: MimeBundle;
outputs: ObservableList<IOutput>;
/**
* Metadata about the output.
* A convenience method to add an output to the end of the outputs list,
* combining outputs if necessary.
*/
metadata: any;
}
/**
* An output model for an execute result.
*/
export declare class ExecuteResultModel extends OutputBaseModel {
add(output: IOutput): void;
/**
* The output type.
* Clear all of the output.
*/
outputType: OutputType;
/**
* The raw data for the output.
*/
data: MimeBundle;
/**
* Metadata about the output.
*/
metadata: any;
/**
* The current execution count.
*/
executionCount: number;
}
/**
* An output model for stream data.
*/
export declare class StreamModel extends OutputBaseModel {
/**
* The output type.
*/
outputType: OutputType;
/**
* The type of stream.
*/
name: StreamType;
/**
* The text from the stream.
*/
text: string;
}
/**
* An output model for an execute error.
*/
export declare class ExecuteErrorModel extends OutputBaseModel {
/**
* The output type.
*/
outputType: OutputType;
/**
* The name of the error.
*/
ename: string;
/**
* The value of the error.
*/
evalue: string;
/**
* The traceback for the error.
*
* #### Notes
* This is an array of strings that has been concatenated to a single string.
*/
traceback: string;
}
/**
* An output model that is one of the valid output types.
*/
export declare type OutputModel = (ExecuteResultModel | DisplayDataModel | StreamModel | ExecuteErrorModel);
/**
* The model for an output area.
*/
export interface IOutputAreaModel {
/**
* A signal emitted when state of the output area changes.
*/
stateChanged: ISignal<IOutputAreaModel, IChangedArgs<any>>;
/**
* Whether the output is collapsed.
*/
collapsed: boolean;
/**
* Whether the output has a fixed maximum height.
*/
fixedHeight: boolean;
/**
* The output prompt.
*/
prompt: string;
/**
* The actual outputs.
*/
outputs: ObservableList<OutputModel>;
/**
* A convenience method to add an output to the end of the outputs list,
* combining outputs if necessary.
*/
add(output: OutputModel): void;
/**
* Clear all of the output.
*/
clear(wait: boolean): void;
}
/**
* An implementation of an input area model.
* An implementation of an output area model.
*/

@@ -155,49 +41,9 @@ export declare class OutputAreaModel implements IOutputAreaModel {

* A signal emitted when the state of the model changes.
*
* #### Notes
* This will not trigger on changes to the output list. For output change handlers,
* listen to [[outputs]] events directly.
*
* **See also:** [[stateChanged]]
*/
static stateChangedSignal: Signal<OutputAreaModel, IChangedArgs<any>>;
/**
* A property descriptor which determines whether the output has a maximum fixed height.
*
* **See also:** [[fixedHeight]]
*/
static fixedHeightProperty: Property<OutputAreaModel, boolean>;
/**
* A property descriptor which determines whether the input area is collapsed or displayed.
*
* **See also:** [[collapsed]]
*/
static collapsedProperty: Property<OutputAreaModel, boolean>;
/**
* A property descriptor containing the prompt.
*
* **See also:** [[prompt]]
*/
static promptProperty: Property<OutputAreaModel, string>;
/**
* A signal emitted when the state of the model changes.
*
* #### Notes
* This will not trigger on changes to the output list. For output change handlers,
* listen to [[outputs]] events directly.
*
* This is a pure delegate to the [[stateChangedSignal]].
*/
stateChanged: ISignal<OutputAreaModel, IChangedArgs<any>>;
/**
* Get whether the output has a maximum fixed height.
*
* #### Notes
* This is a pure delegate to the [[fixedHeightProperty]].
*/
/**
* Set whether the output has a maximum fixed height.
*
* #### Notes
* This is a pure delegate to the [[fixedHeightProperty]].
*/

@@ -207,42 +53,23 @@ fixedHeight: boolean;

* Get whether the input area should be collapsed or displayed.
*
* #### Notes
* This is a pure delegate to the [[collapsedProperty]].
*/
/**
* Set whether the input area should be collapsed or displayed.
*
* #### Notes
* This is a pure delegate to the [[collapsedProperty]].
*/
collapsed: boolean;
/**
* Get the prompt.
*
* #### Notes
* This is a pure delegate to the [[promptProperty]].
* Add an output, which may be combined with previous output
* (e.g. for streams).
*/
add(output: IOutput): void;
/**
* Set the prompt.
* Clear all of the output.
*
* #### Notes
* This is a pure delegate to the [[promptProperty]].
* @param wait Delay clearing the output until the next message is added.
*/
prompt: string;
/**
* Add an output, which may be combined with previous output
* (e.g. for streams).
*/
add(output: OutputModel): void;
/**
* Clear all of the output.
*
* @param wait Delay clearing the output until the next message is added.
*/
clear(wait?: boolean): void;
outputs: ObservableList<ExecuteResultModel | DisplayDataModel | StreamModel | ExecuteErrorModel>;
/**
* Whether to clear on the next message add.
* Execution, display, or stream outputs.
*/
outputs: ObservableList<IExecuteResult | IDisplayData | IStream | IError>;
private _clearNext;
}
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
'use strict';
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var phosphor_observablelist_1 = require('phosphor-observablelist');
var phosphor_properties_1 = require('phosphor-properties');
var phosphor_signaling_1 = require('phosphor-signaling');
var phosphor_observablelist_1 = require('phosphor-observablelist');
var nbformat_1 = require('../notebook/nbformat');
/**
* The base interface for an output model.
* An implementation of an output area model.
*/
var OutputBaseModel = (function () {
function OutputBaseModel() {
}
return OutputBaseModel;
}());
exports.OutputBaseModel = OutputBaseModel;
/**
* An output model for display data.
*/
var DisplayDataModel = (function (_super) {
__extends(DisplayDataModel, _super);
function DisplayDataModel() {
_super.apply(this, arguments);
/**
* The output type.
*/
this.outputType = "display_data";
}
return DisplayDataModel;
}(OutputBaseModel));
exports.DisplayDataModel = DisplayDataModel;
/**
* An output model for an execute result.
*/
var ExecuteResultModel = (function (_super) {
__extends(ExecuteResultModel, _super);
function ExecuteResultModel() {
_super.apply(this, arguments);
/**
* The output type.
*/
this.outputType = "execute_result";
}
return ExecuteResultModel;
}(OutputBaseModel));
exports.ExecuteResultModel = ExecuteResultModel;
/**
* An output model for stream data.
*/
var StreamModel = (function (_super) {
__extends(StreamModel, _super);
function StreamModel() {
_super.apply(this, arguments);
/**
* The output type.
*/
this.outputType = "stream";
}
return StreamModel;
}(OutputBaseModel));
exports.StreamModel = StreamModel;
function isStreamModel(model) {
return model.outputType === "stream";
}
/**
* An output model for an execute error.
*/
var ExecuteErrorModel = (function (_super) {
__extends(ExecuteErrorModel, _super);
function ExecuteErrorModel() {
_super.apply(this, arguments);
/**
* The output type.
*/
this.outputType = "error";
}
return ExecuteErrorModel;
}(OutputBaseModel));
exports.ExecuteErrorModel = ExecuteErrorModel;
/**
* An implementation of an input area model.
*/
var OutputAreaModel = (function () {
function OutputAreaModel() {
this.outputs = new phosphor_observablelist_1.ObservableList();
/**
* Whether to clear on the next message add.
* Execution, display, or stream outputs.
*/
this.outputs = new phosphor_observablelist_1.ObservableList();
this._clearNext = false;

@@ -98,11 +22,5 @@ }

* A signal emitted when the state of the model changes.
*
* #### Notes
* This will not trigger on changes to the output list. For output change handlers,
* listen to [[outputs]] events directly.
*
* This is a pure delegate to the [[stateChangedSignal]].
*/
get: function () {
return OutputAreaModel.stateChangedSignal.bind(this);
return Private.stateChangedSignal.bind(this);
},

@@ -115,17 +33,11 @@ enumerable: true,

* Get whether the output has a maximum fixed height.
*
* #### Notes
* This is a pure delegate to the [[fixedHeightProperty]].
*/
get: function () {
return OutputAreaModel.fixedHeightProperty.get(this);
return Private.fixedHeightProperty.get(this);
},
/**
* Set whether the output has a maximum fixed height.
*
* #### Notes
* This is a pure delegate to the [[fixedHeightProperty]].
*/
set: function (value) {
OutputAreaModel.fixedHeightProperty.set(this, value);
Private.fixedHeightProperty.set(this, value);
},

@@ -138,17 +50,11 @@ enumerable: true,

* Get whether the input area should be collapsed or displayed.
*
* #### Notes
* This is a pure delegate to the [[collapsedProperty]].
*/
get: function () {
return OutputAreaModel.collapsedProperty.get(this);
return Private.collapsedProperty.get(this);
},
/**
* Set whether the input area should be collapsed or displayed.
*
* #### Notes
* This is a pure delegate to the [[collapsedProperty]].
*/
set: function (value) {
OutputAreaModel.collapsedProperty.set(this, value);
Private.collapsedProperty.set(this, value);
},

@@ -158,24 +64,2 @@ enumerable: true,

});
Object.defineProperty(OutputAreaModel.prototype, "prompt", {
/**
* Get the prompt.
*
* #### Notes
* This is a pure delegate to the [[promptProperty]].
*/
get: function () {
return OutputAreaModel.promptProperty.get(this);
},
/**
* Set the prompt.
*
* #### Notes
* This is a pure delegate to the [[promptProperty]].
*/
set: function (value) {
OutputAreaModel.promptProperty.set(this, value);
},
enumerable: true,
configurable: true
});
/**

@@ -186,3 +70,3 @@ * Add an output, which may be combined with previous output

OutputAreaModel.prototype.add = function (output) {
// if we received a delayed clear message, then clear now
// If we received a delayed clear message, then clear now.
if (this._clearNext) {

@@ -192,6 +76,6 @@ this.clear();

}
// Consolidate outputs if they are stream outputs of the same kind
// Consolidate outputs if they are stream outputs of the same kind.
var lastOutput = this.outputs.get(-1);
if (isStreamModel(output)
&& lastOutput && isStreamModel(lastOutput)
if (nbformat_1.isStream(output)
&& lastOutput && nbformat_1.isStream(lastOutput)
&& output.name === lastOutput.name) {

@@ -201,3 +85,7 @@ // In order to get a list change event, we add the previous

// This also replaces the metadata of the last item.
output.text = lastOutput.text + output.text;
var text = output.text;
if (Array.isArray(output.text)) {
text = output.text.join('\n');
}
output.text = lastOutput.text + text;
this.outputs.set(-1, output);

@@ -210,6 +98,6 @@ }

/**
* Clear all of the output.
*
* @param wait Delay clearing the output until the next message is added.
*/
* Clear all of the output.
*
* @param wait Delay clearing the output until the next message is added.
*/
OutputAreaModel.prototype.clear = function (wait) {

@@ -224,41 +112,28 @@ if (wait === void 0) { wait = false; }

};
return OutputAreaModel;
}());
exports.OutputAreaModel = OutputAreaModel;
/**
* A private namespace for output area model data.
*/
var Private;
(function (Private) {
/**
* A signal emitted when the state of the model changes.
*
* #### Notes
* This will not trigger on changes to the output list. For output change handlers,
* listen to [[outputs]] events directly.
*
* **See also:** [[stateChanged]]
*/
OutputAreaModel.stateChangedSignal = new phosphor_signaling_1.Signal();
Private.stateChangedSignal = new phosphor_signaling_1.Signal();
/**
* A property descriptor which determines whether the output has a maximum fixed height.
*
* **See also:** [[fixedHeight]]
*/
OutputAreaModel.fixedHeightProperty = new phosphor_properties_1.Property({
* The property descriptor for whether the output has a fixed maximum height.
*/
Private.fixedHeightProperty = new phosphor_properties_1.Property({
name: 'fixedHeight',
notify: OutputAreaModel.stateChangedSignal,
notify: Private.stateChangedSignal,
});
/**
* A property descriptor which determines whether the input area is collapsed or displayed.
*
* **See also:** [[collapsed]]
*/
OutputAreaModel.collapsedProperty = new phosphor_properties_1.Property({
* The property descriptor for whether the output is collapsed.
*/
Private.collapsedProperty = new phosphor_properties_1.Property({
name: 'collapsed',
notify: OutputAreaModel.stateChangedSignal,
notify: Private.stateChangedSignal,
});
/**
* A property descriptor containing the prompt.
*
* **See also:** [[prompt]]
*/
OutputAreaModel.promptProperty = new phosphor_properties_1.Property({
name: 'prompt',
notify: OutputAreaModel.stateChangedSignal,
});
return OutputAreaModel;
}());
exports.OutputAreaModel = OutputAreaModel;
})(Private || (Private = {}));

@@ -0,9 +1,11 @@

import { IListChangedArgs, ObservableList } from 'phosphor-observablelist';
import { Message } from 'phosphor-messaging';
import { IChangedArgs } from 'phosphor-properties';
import { Widget } from 'phosphor-widget';
import { Panel } from 'phosphor-panel';
import { IOutputAreaModel, OutputModel } from './model';
import { IOutput } from '../notebook/nbformat';
import { IOutputAreaModel } from './model';
/**
* An output area widget.
*/
export declare class OutputAreaWidget extends Panel {
export declare class OutputAreaWidget extends Widget {
/**

@@ -14,15 +16,29 @@ * Construct an output area widget.

/**
* Render an item using the transformime library.
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
renderItem(widget: Widget, output: OutputModel): Promise<void>;
model: IOutputAreaModel;
/**
* Dispose of the resources held by the widget.
*/
dispose(): void;
/**
* Create an output node from an output model.
*/
protected createOutput(output: IOutput): Widget;
/**
* Follow changes to the outputs list.
*/
protected outputsChanged(sender: ObservableList<IOutput>, args: IListChangedArgs<IOutput>): void;
/**
* Handle `update_request` messages.
*/
protected onUpdateRequest(msg: Message): void;
/**
* Change handler for model state changes.
*/
protected modelStateChanged(sender: IOutputAreaModel, args: IChangedArgs<any>): void;
/**
* Dispose the object and its data attributes.
*/
dispose(): void;
private _model;
private _listdispose;
}

@@ -10,8 +10,47 @@ // Copyright (c) Jupyter Development Team.

var phosphor_observablelist_1 = require('phosphor-observablelist');
var phosphor_panel_1 = require('phosphor-panel');
var phosphor_widget_1 = require('phosphor-widget');
var phosphor_panel_1 = require('phosphor-panel');
var transformime_1 = require("transformime");
var transformime_jupyter_transformers_1 = require("transformime-jupyter-transformers");
var phosphor_disposable_1 = require('phosphor-disposable');
var transformime_1 = require('transformime');
var transformime_jupyter_transformers_1 = require('transformime-jupyter-transformers');
/**
* The class name added to an output area widget.
*/
var OUTPUT_AREA_CLASS = 'jp-OutputArea';
/**
* The class name added to an output area output.
*/
var OUTPUT_CLASS = 'jp-OutputArea-output';
/**
* The class name added to an execute result.
*/
var EXECUTE_CLASS = 'jp-OutputArea-executeResult';
/**
* The class name added to display data.
*/
var DISPLAY_CLASS = 'jp-OutputArea-displayData';
/**
* The class name added to stdout data.
*/
var STDOUT_CLASS = 'jp-OutputArea-stdout';
/**
* The class name added to stderr data.
*/
var STDERR_CLASS = 'jp-OutputArea-stderr';
/**
* The class anme added to error data.
*/
var ERROR_CLASS = 'jp-Output-error';
/**
* The class name added to fixed height output areas.
*/
var FIXED_HEIGHT_CLASS = 'jp-mod-fixedHeight';
/**
The class name added to collaped output areas.
*/
var COLLAPSED_CLASS = 'jp-mod-collapsed';
/**
* The class name added to output area prompts.
*/
var PROMPT_CLASS = 'jp-OutputArea-prompt';
/**
* A list of transformers used to render outputs

@@ -35,3 +74,3 @@ *

/**
* A global transformime object to render all outputs.
* The global transformime transformer.
*/

@@ -48,27 +87,56 @@ var transform = new transformime_1.Transformime(transformers);

function OutputAreaWidget(model) {
var _this = this;
_super.call(this);
this.addClass('jp-OutputArea');
this.addClass(OUTPUT_AREA_CLASS);
this._model = model;
this.layout = new phosphor_panel_1.PanelLayout();
model.stateChanged.connect(this.modelStateChanged, this);
this._listdispose = follow(model.outputs, this, function (out) {
var w = new phosphor_widget_1.Widget();
_this.renderItem(w, out);
return w;
});
var outputs = model.outputs;
for (var i = 0; i < outputs.length; i++) {
var widget = this.createOutput(outputs.get(i));
this.layout.addChild(widget);
}
model.outputs.changed.connect(this.outputsChanged, this);
}
Object.defineProperty(OutputAreaWidget.prototype, "model", {
/**
* Get the model used by the widget.
*
* #### Notes
* This is a read-only property.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
/**
* Render an item using the transformime library.
* Dispose of the resources held by the widget.
*/
OutputAreaWidget.prototype.renderItem = function (widget, output) {
OutputAreaWidget.prototype.dispose = function () {
this._model.stateChanged.disconnect(this.modelStateChanged);
this._model.outputs.changed.disconnect(this.outputsChanged);
this._model = null;
_super.prototype.dispose.call(this);
};
/**
* Create an output node from an output model.
*/
OutputAreaWidget.prototype.createOutput = function (output) {
var widget = new phosphor_widget_1.Widget();
widget.addClass(OUTPUT_CLASS);
var bundle;
widget.addClass('jp-OutputArea-Output');
switch (output.outputType) {
switch (output.output_type) {
case "execute_result":
bundle = output.data;
widget.addClass('jp-OutputArea-ExecuteResult');
widget.addClass(EXECUTE_CLASS);
var prompt_1 = document.createElement('div');
prompt_1.className = PROMPT_CLASS;
var count = output.execution_count;
prompt_1.textContent = "Out [" + (count === null ? ' ' : count) + "]:";
widget.node.appendChild(prompt_1);
break;
case "display_data":
bundle = output.data;
widget.addClass('jp-OutputArea-DisplayData');
widget.addClass(DISPLAY_CLASS);
break;

@@ -78,6 +146,6 @@ case "stream":

if (output.name == 'stdout') {
widget.addClass('jp-OutputArea-Stdout');
widget.addClass(STDOUT_CLASS);
}
else {
widget.addClass('jp-OutputArea-Stderr');
widget.addClass(STDERR_CLASS);
}

@@ -87,79 +155,87 @@ break;

var out = output;
bundle = { 'jupyter/console-text': out.traceback || out.ename + ": " + out.evalue };
widget.addClass('jp-OutputArea-Error');
var traceback = out.traceback.join('\n');
bundle = { 'jupyter/console-text': traceback || out.ename + ": " + out.evalue };
widget.addClass(ERROR_CLASS);
break;
default:
console.error("Unrecognized output type: " + output.outputType);
console.error("Unrecognized output type: " + output.output_type);
bundle = {};
}
return (transform.transform(bundle, document).then(function (result) {
transform.transform(bundle, document).then(function (result) {
widget.node.appendChild(result.el);
}));
});
return widget;
};
/**
* Change handler for model state changes.
* Follow changes to the outputs list.
*/
OutputAreaWidget.prototype.modelStateChanged = function (sender, args) {
switch (args.name) {
case 'collapsed':
break;
case 'fixedHeight':
break;
case 'prompt':
break;
}
};
/**
* Dispose the object and its data attributes.
*/
OutputAreaWidget.prototype.dispose = function () {
this._listdispose.dispose();
_super.prototype.dispose.call(this);
};
return OutputAreaWidget;
}(phosphor_panel_1.Panel));
exports.OutputAreaWidget = OutputAreaWidget;
/**
* Make a panel mirror changes to an observable list.
*
* @param source - The observable list.
* @param sink - The Panel.
* @param factory - A function which takes an item from the list and constructs a widget.
*/
function follow(source, sink, factory) {
for (var i = sink.childCount() - 1; i >= 0; i--) {
sink.childAt(i).dispose();
}
for (var i = 0; i < source.length; i++) {
sink.addChild(factory(source.get(i)));
}
function callback(sender, args) {
OutputAreaWidget.prototype.outputsChanged = function (sender, args) {
var layout = this.layout;
var widget;
switch (args.type) {
case phosphor_observablelist_1.ListChangeType.Add:
sink.insertChild(args.newIndex, factory(args.newValue));
var value = args.newValue;
layout.insertChild(args.newIndex, this.createOutput(value));
break;
case phosphor_observablelist_1.ListChangeType.Move:
sink.insertChild(args.newIndex, sink.childAt(args.oldIndex));
layout.insertChild(args.newIndex, layout.childAt(args.oldIndex));
break;
case phosphor_observablelist_1.ListChangeType.Remove:
sink.childAt(args.oldIndex).dispose();
widget = layout.childAt(args.oldIndex);
layout.removeChild(widget);
widget.dispose();
break;
case phosphor_observablelist_1.ListChangeType.Replace:
for (var i = args.oldValue.length; i > 0; i--) {
sink.childAt(args.oldIndex).dispose();
for (var i = layout.childCount(); i > 0; i--) {
widget = layout.childAt(i - 1);
layout.removeChild(widget);
widget.dispose();
}
for (var i = args.newValue.length; i > 0; i--) {
sink.insertChild(args.newIndex, factory(args.newValue[i]));
var newValue = args.newValue;
for (var i = newValue.length; i > 0; i--) {
layout.insertChild(args.newIndex, this.createOutput(newValue[i]));
}
break;
case phosphor_observablelist_1.ListChangeType.Set:
sink.childAt(args.newIndex).dispose();
sink.insertChild(args.newIndex, factory(args.newValue));
widget = layout.childAt(args.newIndex);
layout.removeChild(widget);
widget.dispose();
widget = this.createOutput(args.newValue);
layout.insertChild(args.newIndex, widget);
break;
}
}
source.changed.connect(callback);
return new phosphor_disposable_1.DisposableDelegate(function () {
source.changed.disconnect(callback);
});
}
};
/**
* Handle `update_request` messages.
*/
OutputAreaWidget.prototype.onUpdateRequest = function (msg) {
_super.prototype.onUpdateRequest.call(this, msg);
if (this.model.collapsed) {
this.addClass(COLLAPSED_CLASS);
}
else {
this.removeClass(COLLAPSED_CLASS);
}
if (this.model.fixedHeight) {
this.addClass(FIXED_HEIGHT_CLASS);
}
else {
this.removeClass(FIXED_HEIGHT_CLASS);
}
};
/**
* Change handler for model state changes.
*/
OutputAreaWidget.prototype.modelStateChanged = function (sender, args) {
switch (args.name) {
case 'collapsed':
this.update();
break;
case 'fixedHeight':
this.update();
break;
}
};
return OutputAreaWidget;
}(phosphor_widget_1.Widget));
exports.OutputAreaWidget = OutputAreaWidget;
{
"name": "jupyter-js-notebook",
"version": "0.10.0",
"version": "0.11.0",
"description": "Notebook widget for Jupyter",

@@ -18,4 +18,4 @@ "main": "lib/index.js",

"phosphor-widget": "^1.0.0-rc.1",
"transformime": "^2.1.1",
"transformime-jupyter-transformers": "^0.3.0"
"transformime": "^2.1.2",
"transformime-jupyter-transformers": "^0.4.0"
},

@@ -22,0 +22,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc