@jupyterlab/rendermime 0.19.1-alpha.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +34 -0
- package/lib/attachmentmodel.d.ts +94 -94
- package/lib/attachmentmodel.js +166 -166
- package/lib/factories.d.ts +33 -33
- package/lib/factories.js +89 -89
- package/lib/index.d.ts +10 -10
- package/lib/index.js +18 -18
- package/lib/latex.d.ts +16 -16
- package/lib/latex.js +184 -184
- package/lib/mimemodel.d.ts +60 -60
- package/lib/mimemodel.js +54 -54
- package/lib/outputmodel.d.ts +131 -131
- package/lib/outputmodel.js +238 -238
- package/lib/registry.d.ts +245 -245
- package/lib/registry.js +295 -295
- package/lib/renderers.d.ts +242 -242
- package/lib/renderers.js +537 -537
- package/lib/widgets.d.ts +210 -210
- package/lib/widgets.js +311 -311
- package/package.json +13 -10
package/lib/outputmodel.js
CHANGED
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/*-----------------------------------------------------------------------------
|
|
4
|
-
| Copyright (c) Jupyter Development Team.
|
|
5
|
-
| Distributed under the terms of the Modified BSD License.
|
|
6
|
-
|----------------------------------------------------------------------------*/
|
|
7
|
-
const coreutils_1 = require("@phosphor/coreutils");
|
|
8
|
-
const signaling_1 = require("@phosphor/signaling");
|
|
9
|
-
const coreutils_2 = require("@jupyterlab/coreutils");
|
|
10
|
-
const observables_1 = require("@jupyterlab/observables");
|
|
11
|
-
/**
|
|
12
|
-
* The default implementation of a notebook output model.
|
|
13
|
-
*/
|
|
14
|
-
class OutputModel {
|
|
15
|
-
/**
|
|
16
|
-
* Construct a new output model.
|
|
17
|
-
*/
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this._changed = new signaling_1.Signal(this);
|
|
20
|
-
this._raw = {};
|
|
21
|
-
let { data, metadata, trusted } = Private.getBundleOptions(options);
|
|
22
|
-
this._data = new observables_1.ObservableJSON({ values: data });
|
|
23
|
-
this._rawData = data;
|
|
24
|
-
this._metadata = new observables_1.ObservableJSON({ values: metadata });
|
|
25
|
-
this._rawMetadata = metadata;
|
|
26
|
-
this.trusted = trusted;
|
|
27
|
-
// Make a copy of the data.
|
|
28
|
-
let value = options.value;
|
|
29
|
-
for (let key in value) {
|
|
30
|
-
// Ignore data and metadata that were stripped.
|
|
31
|
-
switch (key) {
|
|
32
|
-
case 'data':
|
|
33
|
-
case 'metadata':
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
this._raw[key] = Private.extract(value, key);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
this.type = value.output_type;
|
|
40
|
-
if (coreutils_2.nbformat.isExecuteResult(value)) {
|
|
41
|
-
this.executionCount = value.execution_count;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
this.executionCount = null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* A signal emitted when the output model changes.
|
|
49
|
-
*/
|
|
50
|
-
get changed() {
|
|
51
|
-
return this._changed;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Dispose of the resources used by the output model.
|
|
55
|
-
*/
|
|
56
|
-
dispose() {
|
|
57
|
-
this._data.dispose();
|
|
58
|
-
this._metadata.dispose();
|
|
59
|
-
signaling_1.Signal.clearData(this);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The data associated with the model.
|
|
63
|
-
*/
|
|
64
|
-
get data() {
|
|
65
|
-
return this._rawData;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* The metadata associated with the model.
|
|
69
|
-
*/
|
|
70
|
-
get metadata() {
|
|
71
|
-
return this._rawMetadata;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Set the data associated with the model.
|
|
75
|
-
*
|
|
76
|
-
* #### Notes
|
|
77
|
-
* Depending on the implementation of the mime model,
|
|
78
|
-
* this call may or may not have deferred effects,
|
|
79
|
-
*/
|
|
80
|
-
setData(options) {
|
|
81
|
-
if (options.data) {
|
|
82
|
-
this._updateObservable(this._data, options.data);
|
|
83
|
-
this._rawData = options.data;
|
|
84
|
-
}
|
|
85
|
-
if (options.metadata) {
|
|
86
|
-
this._updateObservable(this._metadata, options.metadata);
|
|
87
|
-
this._rawMetadata = options.metadata;
|
|
88
|
-
}
|
|
89
|
-
this._changed.emit(void 0);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Serialize the model to JSON.
|
|
93
|
-
*/
|
|
94
|
-
toJSON() {
|
|
95
|
-
let output = {};
|
|
96
|
-
for (let key in this._raw) {
|
|
97
|
-
output[key] = Private.extract(this._raw, key);
|
|
98
|
-
}
|
|
99
|
-
switch (this.type) {
|
|
100
|
-
case 'display_data':
|
|
101
|
-
case 'execute_result':
|
|
102
|
-
case 'update_display_data':
|
|
103
|
-
output['data'] = this.data;
|
|
104
|
-
output['metadata'] = this.metadata;
|
|
105
|
-
break;
|
|
106
|
-
default:
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
// Remove transient data.
|
|
110
|
-
delete output['transient'];
|
|
111
|
-
return output;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Update an observable JSON object using a readonly JSON object.
|
|
115
|
-
*/
|
|
116
|
-
_updateObservable(observable, data) {
|
|
117
|
-
let oldKeys = observable.keys();
|
|
118
|
-
let newKeys = Object.keys(data);
|
|
119
|
-
// Handle removed keys.
|
|
120
|
-
for (let key of oldKeys) {
|
|
121
|
-
if (newKeys.indexOf(key) === -1) {
|
|
122
|
-
observable.delete(key);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// Handle changed data.
|
|
126
|
-
for (let key of newKeys) {
|
|
127
|
-
let oldValue = observable.get(key);
|
|
128
|
-
let newValue = data[key];
|
|
129
|
-
if (oldValue !== newValue) {
|
|
130
|
-
observable.set(key, newValue);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.OutputModel = OutputModel;
|
|
136
|
-
/**
|
|
137
|
-
* The namespace for OutputModel statics.
|
|
138
|
-
*/
|
|
139
|
-
(function (OutputModel) {
|
|
140
|
-
/**
|
|
141
|
-
* Get the data for an output.
|
|
142
|
-
*
|
|
143
|
-
* @params output - A kernel output message payload.
|
|
144
|
-
*
|
|
145
|
-
* @returns - The data for the payload.
|
|
146
|
-
*/
|
|
147
|
-
function getData(output) {
|
|
148
|
-
return Private.getData(output);
|
|
149
|
-
}
|
|
150
|
-
OutputModel.getData = getData;
|
|
151
|
-
/**
|
|
152
|
-
* Get the metadata from an output message.
|
|
153
|
-
*
|
|
154
|
-
* @params output - A kernel output message payload.
|
|
155
|
-
*
|
|
156
|
-
* @returns - The metadata for the payload.
|
|
157
|
-
*/
|
|
158
|
-
function getMetadata(output) {
|
|
159
|
-
return Private.getMetadata(output);
|
|
160
|
-
}
|
|
161
|
-
OutputModel.getMetadata = getMetadata;
|
|
162
|
-
})(OutputModel = exports.OutputModel || (exports.OutputModel = {}));
|
|
163
|
-
/**
|
|
164
|
-
* The namespace for module private data.
|
|
165
|
-
*/
|
|
166
|
-
var Private;
|
|
167
|
-
(function (Private) {
|
|
168
|
-
/**
|
|
169
|
-
* Get the data from a notebook output.
|
|
170
|
-
*/
|
|
171
|
-
function getData(output) {
|
|
172
|
-
let bundle = {};
|
|
173
|
-
if (coreutils_2.nbformat.isExecuteResult(output) ||
|
|
174
|
-
coreutils_2.nbformat.isDisplayData(output) ||
|
|
175
|
-
coreutils_2.nbformat.isDisplayUpdate(output)) {
|
|
176
|
-
bundle = output.data;
|
|
177
|
-
}
|
|
178
|
-
else if (coreutils_2.nbformat.isStream(output)) {
|
|
179
|
-
if (output.name === 'stderr') {
|
|
180
|
-
bundle['application/vnd.jupyter.stderr'] = output.text;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
bundle['application/vnd.jupyter.stdout'] = output.text;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
else if (coreutils_2.nbformat.isError(output)) {
|
|
187
|
-
let traceback = output.traceback.join('\n');
|
|
188
|
-
bundle['application/vnd.jupyter.stderr'] =
|
|
189
|
-
traceback || `${output.ename}: ${output.evalue}`;
|
|
190
|
-
}
|
|
191
|
-
return convertBundle(bundle);
|
|
192
|
-
}
|
|
193
|
-
Private.getData = getData;
|
|
194
|
-
/**
|
|
195
|
-
* Get the metadata from an output message.
|
|
196
|
-
*/
|
|
197
|
-
function getMetadata(output) {
|
|
198
|
-
let value = Object.create(null);
|
|
199
|
-
if (coreutils_2.nbformat.isExecuteResult(output) || coreutils_2.nbformat.isDisplayData(output)) {
|
|
200
|
-
for (let key in output.metadata) {
|
|
201
|
-
value[key] = extract(output.metadata, key);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return value;
|
|
205
|
-
}
|
|
206
|
-
Private.getMetadata = getMetadata;
|
|
207
|
-
/**
|
|
208
|
-
* Get the bundle options given output model options.
|
|
209
|
-
*/
|
|
210
|
-
function getBundleOptions(options) {
|
|
211
|
-
let data = getData(options.value);
|
|
212
|
-
let metadata = getMetadata(options.value);
|
|
213
|
-
let trusted = !!options.trusted;
|
|
214
|
-
return { data, metadata, trusted };
|
|
215
|
-
}
|
|
216
|
-
Private.getBundleOptions = getBundleOptions;
|
|
217
|
-
/**
|
|
218
|
-
* Extract a value from a JSONObject.
|
|
219
|
-
*/
|
|
220
|
-
function extract(value, key) {
|
|
221
|
-
let item = value[key];
|
|
222
|
-
if (coreutils_1.JSONExt.isPrimitive(item)) {
|
|
223
|
-
return item;
|
|
224
|
-
}
|
|
225
|
-
return JSON.parse(JSON.stringify(item));
|
|
226
|
-
}
|
|
227
|
-
Private.extract = extract;
|
|
228
|
-
/**
|
|
229
|
-
* Convert a mime bundle to mime data.
|
|
230
|
-
*/
|
|
231
|
-
function convertBundle(bundle) {
|
|
232
|
-
let map = Object.create(null);
|
|
233
|
-
for (let mimeType in bundle) {
|
|
234
|
-
map[mimeType] = extract(bundle, mimeType);
|
|
235
|
-
}
|
|
236
|
-
return map;
|
|
237
|
-
}
|
|
238
|
-
})(Private || (Private = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/*-----------------------------------------------------------------------------
|
|
4
|
+
| Copyright (c) Jupyter Development Team.
|
|
5
|
+
| Distributed under the terms of the Modified BSD License.
|
|
6
|
+
|----------------------------------------------------------------------------*/
|
|
7
|
+
const coreutils_1 = require("@phosphor/coreutils");
|
|
8
|
+
const signaling_1 = require("@phosphor/signaling");
|
|
9
|
+
const coreutils_2 = require("@jupyterlab/coreutils");
|
|
10
|
+
const observables_1 = require("@jupyterlab/observables");
|
|
11
|
+
/**
|
|
12
|
+
* The default implementation of a notebook output model.
|
|
13
|
+
*/
|
|
14
|
+
class OutputModel {
|
|
15
|
+
/**
|
|
16
|
+
* Construct a new output model.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this._changed = new signaling_1.Signal(this);
|
|
20
|
+
this._raw = {};
|
|
21
|
+
let { data, metadata, trusted } = Private.getBundleOptions(options);
|
|
22
|
+
this._data = new observables_1.ObservableJSON({ values: data });
|
|
23
|
+
this._rawData = data;
|
|
24
|
+
this._metadata = new observables_1.ObservableJSON({ values: metadata });
|
|
25
|
+
this._rawMetadata = metadata;
|
|
26
|
+
this.trusted = trusted;
|
|
27
|
+
// Make a copy of the data.
|
|
28
|
+
let value = options.value;
|
|
29
|
+
for (let key in value) {
|
|
30
|
+
// Ignore data and metadata that were stripped.
|
|
31
|
+
switch (key) {
|
|
32
|
+
case 'data':
|
|
33
|
+
case 'metadata':
|
|
34
|
+
break;
|
|
35
|
+
default:
|
|
36
|
+
this._raw[key] = Private.extract(value, key);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this.type = value.output_type;
|
|
40
|
+
if (coreutils_2.nbformat.isExecuteResult(value)) {
|
|
41
|
+
this.executionCount = value.execution_count;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.executionCount = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A signal emitted when the output model changes.
|
|
49
|
+
*/
|
|
50
|
+
get changed() {
|
|
51
|
+
return this._changed;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Dispose of the resources used by the output model.
|
|
55
|
+
*/
|
|
56
|
+
dispose() {
|
|
57
|
+
this._data.dispose();
|
|
58
|
+
this._metadata.dispose();
|
|
59
|
+
signaling_1.Signal.clearData(this);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The data associated with the model.
|
|
63
|
+
*/
|
|
64
|
+
get data() {
|
|
65
|
+
return this._rawData;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The metadata associated with the model.
|
|
69
|
+
*/
|
|
70
|
+
get metadata() {
|
|
71
|
+
return this._rawMetadata;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set the data associated with the model.
|
|
75
|
+
*
|
|
76
|
+
* #### Notes
|
|
77
|
+
* Depending on the implementation of the mime model,
|
|
78
|
+
* this call may or may not have deferred effects,
|
|
79
|
+
*/
|
|
80
|
+
setData(options) {
|
|
81
|
+
if (options.data) {
|
|
82
|
+
this._updateObservable(this._data, options.data);
|
|
83
|
+
this._rawData = options.data;
|
|
84
|
+
}
|
|
85
|
+
if (options.metadata) {
|
|
86
|
+
this._updateObservable(this._metadata, options.metadata);
|
|
87
|
+
this._rawMetadata = options.metadata;
|
|
88
|
+
}
|
|
89
|
+
this._changed.emit(void 0);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Serialize the model to JSON.
|
|
93
|
+
*/
|
|
94
|
+
toJSON() {
|
|
95
|
+
let output = {};
|
|
96
|
+
for (let key in this._raw) {
|
|
97
|
+
output[key] = Private.extract(this._raw, key);
|
|
98
|
+
}
|
|
99
|
+
switch (this.type) {
|
|
100
|
+
case 'display_data':
|
|
101
|
+
case 'execute_result':
|
|
102
|
+
case 'update_display_data':
|
|
103
|
+
output['data'] = this.data;
|
|
104
|
+
output['metadata'] = this.metadata;
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
// Remove transient data.
|
|
110
|
+
delete output['transient'];
|
|
111
|
+
return output;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Update an observable JSON object using a readonly JSON object.
|
|
115
|
+
*/
|
|
116
|
+
_updateObservable(observable, data) {
|
|
117
|
+
let oldKeys = observable.keys();
|
|
118
|
+
let newKeys = Object.keys(data);
|
|
119
|
+
// Handle removed keys.
|
|
120
|
+
for (let key of oldKeys) {
|
|
121
|
+
if (newKeys.indexOf(key) === -1) {
|
|
122
|
+
observable.delete(key);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Handle changed data.
|
|
126
|
+
for (let key of newKeys) {
|
|
127
|
+
let oldValue = observable.get(key);
|
|
128
|
+
let newValue = data[key];
|
|
129
|
+
if (oldValue !== newValue) {
|
|
130
|
+
observable.set(key, newValue);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.OutputModel = OutputModel;
|
|
136
|
+
/**
|
|
137
|
+
* The namespace for OutputModel statics.
|
|
138
|
+
*/
|
|
139
|
+
(function (OutputModel) {
|
|
140
|
+
/**
|
|
141
|
+
* Get the data for an output.
|
|
142
|
+
*
|
|
143
|
+
* @params output - A kernel output message payload.
|
|
144
|
+
*
|
|
145
|
+
* @returns - The data for the payload.
|
|
146
|
+
*/
|
|
147
|
+
function getData(output) {
|
|
148
|
+
return Private.getData(output);
|
|
149
|
+
}
|
|
150
|
+
OutputModel.getData = getData;
|
|
151
|
+
/**
|
|
152
|
+
* Get the metadata from an output message.
|
|
153
|
+
*
|
|
154
|
+
* @params output - A kernel output message payload.
|
|
155
|
+
*
|
|
156
|
+
* @returns - The metadata for the payload.
|
|
157
|
+
*/
|
|
158
|
+
function getMetadata(output) {
|
|
159
|
+
return Private.getMetadata(output);
|
|
160
|
+
}
|
|
161
|
+
OutputModel.getMetadata = getMetadata;
|
|
162
|
+
})(OutputModel = exports.OutputModel || (exports.OutputModel = {}));
|
|
163
|
+
/**
|
|
164
|
+
* The namespace for module private data.
|
|
165
|
+
*/
|
|
166
|
+
var Private;
|
|
167
|
+
(function (Private) {
|
|
168
|
+
/**
|
|
169
|
+
* Get the data from a notebook output.
|
|
170
|
+
*/
|
|
171
|
+
function getData(output) {
|
|
172
|
+
let bundle = {};
|
|
173
|
+
if (coreutils_2.nbformat.isExecuteResult(output) ||
|
|
174
|
+
coreutils_2.nbformat.isDisplayData(output) ||
|
|
175
|
+
coreutils_2.nbformat.isDisplayUpdate(output)) {
|
|
176
|
+
bundle = output.data;
|
|
177
|
+
}
|
|
178
|
+
else if (coreutils_2.nbformat.isStream(output)) {
|
|
179
|
+
if (output.name === 'stderr') {
|
|
180
|
+
bundle['application/vnd.jupyter.stderr'] = output.text;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
bundle['application/vnd.jupyter.stdout'] = output.text;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (coreutils_2.nbformat.isError(output)) {
|
|
187
|
+
let traceback = output.traceback.join('\n');
|
|
188
|
+
bundle['application/vnd.jupyter.stderr'] =
|
|
189
|
+
traceback || `${output.ename}: ${output.evalue}`;
|
|
190
|
+
}
|
|
191
|
+
return convertBundle(bundle);
|
|
192
|
+
}
|
|
193
|
+
Private.getData = getData;
|
|
194
|
+
/**
|
|
195
|
+
* Get the metadata from an output message.
|
|
196
|
+
*/
|
|
197
|
+
function getMetadata(output) {
|
|
198
|
+
let value = Object.create(null);
|
|
199
|
+
if (coreutils_2.nbformat.isExecuteResult(output) || coreutils_2.nbformat.isDisplayData(output)) {
|
|
200
|
+
for (let key in output.metadata) {
|
|
201
|
+
value[key] = extract(output.metadata, key);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
Private.getMetadata = getMetadata;
|
|
207
|
+
/**
|
|
208
|
+
* Get the bundle options given output model options.
|
|
209
|
+
*/
|
|
210
|
+
function getBundleOptions(options) {
|
|
211
|
+
let data = getData(options.value);
|
|
212
|
+
let metadata = getMetadata(options.value);
|
|
213
|
+
let trusted = !!options.trusted;
|
|
214
|
+
return { data, metadata, trusted };
|
|
215
|
+
}
|
|
216
|
+
Private.getBundleOptions = getBundleOptions;
|
|
217
|
+
/**
|
|
218
|
+
* Extract a value from a JSONObject.
|
|
219
|
+
*/
|
|
220
|
+
function extract(value, key) {
|
|
221
|
+
let item = value[key];
|
|
222
|
+
if (coreutils_1.JSONExt.isPrimitive(item)) {
|
|
223
|
+
return item;
|
|
224
|
+
}
|
|
225
|
+
return JSON.parse(JSON.stringify(item));
|
|
226
|
+
}
|
|
227
|
+
Private.extract = extract;
|
|
228
|
+
/**
|
|
229
|
+
* Convert a mime bundle to mime data.
|
|
230
|
+
*/
|
|
231
|
+
function convertBundle(bundle) {
|
|
232
|
+
let map = Object.create(null);
|
|
233
|
+
for (let mimeType in bundle) {
|
|
234
|
+
map[mimeType] = extract(bundle, mimeType);
|
|
235
|
+
}
|
|
236
|
+
return map;
|
|
237
|
+
}
|
|
238
|
+
})(Private || (Private = {}));
|