From 36d63656ae55e97becfb1abdc3d234b3e015c7db Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 3 Nov 2015 18:48:59 -0600 Subject: [PATCH 1/3] Add an initial cell model --- src/index.ts | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/src/index.ts b/src/index.ts index 9efd726..f55acf0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,182 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. 'use-strict'; + +import { + IInputAreaViewModel +} from 'jupyter-js-input-area'; + +import { + IOutputAreaViewModel +} from 'jupyter-js-output-area'; + +import { + IObservableList +} from 'phosphor-observablelist'; + +import { + Widget +} from 'phosphor-widget'; + +import './index.css'; + + +/** + * An enum which describes the type of cell. + */ +enum CellType { + /** + * The cell contains code input. + */ + Code, + + /** + * The cell contains markdown. + */ + Markdown, + + /** + * The cell contains raw text. + */ + Raw +} + + +/** + * An enum which describes which interface property has changed. + */ +export +enum CellProperty { + CellType, + Tags, + Deletable, + Mergable, + Splittable, + Rendered, + Marked, + Format +} + + +/** + * The arguments object emitted with the `stateChanged` signal. + */ +export +interface ICellChangedArgs { + which: CellProperty, + oldValue: T; + newValue: T; +} + + +/** + * The definition of a model object for a base cell. + */ +interface IBaseCellViewModel { + + /** + * The type of cell. + */ + cellType: CellType; + + /** + * Tags applied to the cell. + */ + tags?: IObservableList; + + /** + * Get namespaced metadata about the cell. + */ + getMetadata(namespace: string) : IObservableMap; + + /** + * The input area of the cell. + */ + input: IInputAreaViewModel; + + /** + * Whether a cell is deletable. + */ + deleteable: boolean; + + /** + * Whether a cell is mergable. + */ + mergeable: boolean; + + /** + * Whether a cell is splittable. + */ + splittable: boolean; + + /** + * Whether a cell is rendered. + */ + rendered: boolean; + + /** + * Whether the cell is marked for applying commands + */ + marked: boolean; + + /** + * Run the cell. + */ + run(): void; +} + + +/** + * The definition of a code cell. + */ +export +interface ICodeCellViewModel extends IBaseCellViewModel { + + /** + * A signal emitted when state of the cell changes. + */ + stateChanged: ISignal>; + + output: IOutputAreaViewModel; +} + + +/** + * The definition of a raw cell. + */ +export +interface IRawCellViewModel extends IBaseCellViewModel { + + /** + * A signal emitted when state of the cell changes. + */ + stateChanged: ISignal>; + + /** + * The raw cell format. + */ + format?: string; +} + + +/** + * The definition of a markdown cell. + */ +export +interface IMarkdownCellViewModel extends IBaseCellViewModel { + + /** + * A signal emitted when state of the cell changes. + */ + stateChanged: ISignal>; +} + + + +/** + * A model consisting of any valid cell type. + */ +export +type ICellViewModel = ( + IRawCellViewModel | IMarkdownCellViewModel | ICodeCellViewModel +); From 1c4f4451ffa5cb01f3e5a3af4fdf4c932cee08b9 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 3 Nov 2015 19:24:03 -0600 Subject: [PATCH 2/3] Update the changed interface --- src/index.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index f55acf0..fc8d917 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,28 +42,12 @@ enum CellType { } -/** - * An enum which describes which interface property has changed. - */ -export -enum CellProperty { - CellType, - Tags, - Deletable, - Mergable, - Splittable, - Rendered, - Marked, - Format -} - - /** * The arguments object emitted with the `stateChanged` signal. */ export interface ICellChangedArgs { - which: CellProperty, + name: string, oldValue: T; newValue: T; } From 5c814bac03d2b3eb00d738c70ffa3aa193098829 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Nov 2015 15:04:40 -0600 Subject: [PATCH 3/3] Updates to interfaces --- package.json | 1 + src/index.ts | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5b0d568..52bbef0 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "typings": "lib/index.d.ts", "dependencies": { "phosphor-observablelist": "^0.9.2", + "phosphor-signaling": "^1.1.2", "phosphor-widget": "^0.9.13" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index fc8d917..f40b9a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,10 @@ import { IObservableList } from 'phosphor-observablelist'; +import { + ISignal +} from 'phosphor-signaling'; + import { Widget } from 'phosphor-widget'; @@ -53,6 +57,16 @@ interface ICellChangedArgs { } +/** + * An object which is serializable. + */ +export +interface ISerializable { + toJSON(): any; + fromJSON(data: any): void; +} + + /** * The definition of a model object for a base cell. */ @@ -61,7 +75,7 @@ interface IBaseCellViewModel { /** * The type of cell. */ - cellType: CellType; + type: CellType; /** * Tags applied to the cell. @@ -71,7 +85,7 @@ interface IBaseCellViewModel { /** * Get namespaced metadata about the cell. */ - getMetadata(namespace: string) : IObservableMap; + getMetadata(namespace: string) : IObservableMap; /** * The input area of the cell. @@ -128,7 +142,7 @@ interface ICodeCellViewModel extends IBaseCellViewModel { /** * The definition of a raw cell. */ -export +export interface IRawCellViewModel extends IBaseCellViewModel { /** @@ -146,7 +160,7 @@ interface IRawCellViewModel extends IBaseCellViewModel { /** * The definition of a markdown cell. */ -export +export interface IMarkdownCellViewModel extends IBaseCellViewModel { /** @@ -160,7 +174,7 @@ interface IMarkdownCellViewModel extends IBaseCellViewModel { /** * A model consisting of any valid cell type. */ -export +export type ICellViewModel = ( IRawCellViewModel | IMarkdownCellViewModel | ICodeCellViewModel );