This repository was archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add an initial cell model #2
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,180 @@ | ||
// 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 { | ||
ISignal | ||
} from 'phosphor-signaling'; | ||
|
||
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 | ||
} | ||
|
||
|
||
/** | ||
* The arguments object emitted with the `stateChanged` signal. | ||
*/ | ||
export | ||
interface ICellChangedArgs<T> { | ||
name: string, | ||
oldValue: T; | ||
newValue: T; | ||
} | ||
|
||
|
||
/** | ||
* An object which is serializable. | ||
*/ | ||
export | ||
interface ISerializable { | ||
toJSON(): any; | ||
fromJSON(data: any): void; | ||
} | ||
|
||
|
||
/** | ||
* The definition of a model object for a base cell. | ||
*/ | ||
interface IBaseCellViewModel { | ||
|
||
/** | ||
* The type of cell. | ||
*/ | ||
type: CellType; | ||
|
||
/** | ||
* Tags applied to the cell. | ||
*/ | ||
tags?: IObservableList<string>; | ||
|
||
/** | ||
* Get namespaced metadata about the cell. | ||
*/ | ||
getMetadata(namespace: string) : IObservableMap<string, ISerializable>; | ||
|
||
/** | ||
* 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<ICodeCellViewModel, ICellChangedArgs<any>>; | ||
|
||
output: IOutputAreaViewModel; | ||
} | ||
|
||
|
||
/** | ||
* The definition of a raw cell. | ||
*/ | ||
export | ||
interface IRawCellViewModel extends IBaseCellViewModel { | ||
|
||
/** | ||
* A signal emitted when state of the cell changes. | ||
*/ | ||
stateChanged: ISignal<IRawCellViewModel, ICellChangedArgs<any>>; | ||
|
||
/** | ||
* 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<IMarkdownCellViewModel, ICellChangedArgs<any>>; | ||
} | ||
|
||
|
||
|
||
/** | ||
* A model consisting of any valid cell type. | ||
*/ | ||
export | ||
type ICellViewModel = ( | ||
IRawCellViewModel | IMarkdownCellViewModel | ICodeCellViewModel | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we restrict string to a subset with reg-exes in typescript ? I think if so we should restrict to
A-Za-z-
(same for name). I think the restriction was already discussed and is informally agreed upon fro extension as each tag might be added as a class on the dom element of the cell.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would need to be asserted dynamically at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i.e. not possible with the type system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course for checking values at runtime. But I was more wondering if there was a syntax in the interface just for documentation purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I confusing with JSON schema paternProperties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with
type
.For the metadat stuff, what about making the values be something like this:
That at least encodes the fact that we expect the data to be serializable
to/from JSON?
On Tue, Nov 3, 2015 at 10:20 PM, Matthias Bussonnier <
[email protected]> wrote:
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the javascript JSON.stringify function looks for a toJSON() function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior.