-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
notebook.ts
123 lines (115 loc) · 3.31 KB
/
notebook.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Vendor modules
import {
CellId,
emptyNotebook,
ImmutableCell,
ImmutableNotebook
} from "@nteract/commutable";
import { NotebookV4 } from "@nteract/commutable/lib/v4";
import * as Immutable from "immutable";
// Local modules
import { InputRequestMessage, KernelRef } from "../..";
// The data model that `nteract/bookstore` accepts. For more info, see:
// https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#data-model
export interface BookstoreDataModel {
/**
* Basename of the entity.
*/
name: string | undefined;
/**
* Full (API-style)*def path to entity.
* def => https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#apipaths
*/
path: string;
/**
* The entity type. One of "notebook", "file", or "directory".
*/
type: "notebook";
/**
* Creation date of the entity.
*/
created: string | undefined | null;
/**
* Last modified date of the entity.
*/
last_modified: string | undefined | null;
/**
* The "content" of the entity.
* See: https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#filesystem-entities
*/
content: NotebookV4;
/**
* The mimetype of `content`, if any.
* See: https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#filesystem-entities
*/
mimetype: string | undefined | null;
/**
* The format of `content`, if any.
* See: https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#filesystem-entities
*/
format: "json";
}
export interface DocumentRecordProps {
type: "notebook";
notebook: ImmutableNotebook;
savedNotebook: ImmutableNotebook;
// has the keypaths for updating displays
transient: Immutable.Map<string, any>;
// transient should be more fully typed (be a record itself)
// right now it's keypaths and then it looks like it's able to handle any per
// cell transient data that will be deleted when the kernel is restarted
cellPagers: any;
cellPrompts: Immutable.Map<CellId, Immutable.List<InputRequestMessage>>;
editorFocused?: CellId | null;
cellFocused?: CellId | null;
copied: ImmutableCell | null;
kernelRef?: KernelRef | null;
}
export const makeDocumentRecord = Immutable.Record<DocumentRecordProps>({
type: "notebook",
notebook: emptyNotebook,
savedNotebook: emptyNotebook,
transient: Immutable.Map({
keyPathsForDisplays: Immutable.Map()
}),
cellPagers: Immutable.Map(),
cellPrompts: Immutable.Map(),
editorFocused: null,
cellFocused: null,
copied: null,
kernelRef: null
});
export type NotebookModel = Immutable.RecordOf<DocumentRecordProps>;
export interface NotebookContentRecordProps {
mimetype?: string | null;
created?: Date | null;
format: "json";
lastSaved?: Date | null;
model: NotebookModel;
filepath: string;
type: "notebook";
writable: boolean;
saving: boolean;
loading: boolean;
error?: object | null;
showHeaderEditor?: boolean;
}
export const makeNotebookContentRecord = Immutable.Record<
NotebookContentRecordProps
>({
mimetype: null,
created: null,
format: "json",
lastSaved: null,
model: makeDocumentRecord(),
filepath: "",
type: "notebook",
writable: true,
saving: false,
loading: false,
error: null,
showHeaderEditor: false
});
export type NotebookContentRecord = Immutable.RecordOf<
NotebookContentRecordProps
>;