@jupyterlab/cells 4.0.0-alpha.13 → 4.0.0-alpha.15

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/lib/model.js CHANGED
@@ -2,24 +2,13 @@
2
2
  | Copyright (c) Jupyter Development Team.
3
3
  | Distributed under the terms of the Modified BSD License.
4
4
  |----------------------------------------------------------------------------*/
5
- var __rest = (this && this.__rest) || function (s, e) {
6
- var t = {};
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
8
- t[p] = s[p];
9
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
10
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
12
- t[p[i]] = s[p[i]];
13
- }
14
- return t;
15
- };
16
- import { JSONExt } from '@lumino/coreutils';
17
5
  import { Signal } from '@lumino/signaling';
18
6
  import { AttachmentsModel } from '@jupyterlab/attachments';
19
7
  import { CodeEditor } from '@jupyterlab/codeeditor';
20
8
  import * as models from '@jupyterlab/shared-models';
21
- import { UUID } from '@lumino/coreutils';
9
+ import { JSONExt } from '@lumino/coreutils';
22
10
  import { OutputAreaModel } from '@jupyterlab/outputarea';
11
+ import { createStandaloneCell } from '@jupyterlab/shared-models';
23
12
  const globalModelDBMutex = models.createMutex();
24
13
  export function isCodeCellModel(model) {
25
14
  return model.type === 'code';
@@ -34,15 +23,8 @@ export function isRawCellModel(model) {
34
23
  * An implementation of the cell model.
35
24
  */
36
25
  export class CellModel extends CodeEditor.Model {
37
- /**
38
- * Construct a cell model from optional cell content.
39
- */
40
- constructor(options) {
41
- var _a;
42
- super({
43
- modelDB: options.modelDB,
44
- id: options.id || ((_a = options.cell) === null || _a === void 0 ? void 0 : _a.id) || UUID.uuid4()
45
- });
26
+ constructor(options = {}) {
27
+ super(options);
46
28
  /**
47
29
  * A signal emitted when the state of the model changes.
48
30
  */
@@ -51,41 +33,19 @@ export class CellModel extends CodeEditor.Model {
51
33
  * A signal emitted when a model state changes.
52
34
  */
53
35
  this.stateChanged = new Signal(this);
54
- this.value.changed.connect(this.onGenericChange, this);
55
- const cellType = this.modelDB.createValue('type');
56
- cellType.set(this.type);
36
+ this.sharedModel.changed.connect(this.onGenericChange, this);
37
+ this.sharedModel.changed.connect(this.onSharedModelChanged, this);
57
38
  const observableMetadata = this.modelDB.createMap('metadata');
58
- observableMetadata.changed.connect(this.onModelDBMetadataChange, this);
59
- observableMetadata.changed.connect(this.onGenericChange, this);
60
- const cell = options.cell;
39
+ const metadata = JSONExt.deepCopy(this.sharedModel.getMetadata());
61
40
  const trusted = this.modelDB.createValue('trusted');
62
- trusted.changed.connect(this.onTrustedChanged, this);
63
- if (!cell) {
64
- trusted.set(false);
65
- return;
66
- }
67
- trusted.set(!!cell.metadata['trusted']);
68
- delete cell.metadata['trusted'];
69
- // Set the text value, normalizing line endings to \n
70
- if (Array.isArray(cell.source)) {
71
- this.value.text = cell.source
72
- .map(s => s.replace(/\r\n/g, '\n').replace(/\r/g, '\n'))
73
- .join('');
74
- }
75
- else {
76
- this.value.text = cell.source.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
77
- }
78
- const metadata = JSONExt.deepCopy(cell.metadata);
79
- if (this.type !== 'raw') {
80
- delete metadata['format'];
81
- }
82
- if (this.type !== 'code') {
83
- delete metadata['collapsed'];
84
- delete metadata['scrolled'];
85
- }
41
+ const cellType = this.modelDB.createValue('type');
42
+ cellType.set(this.type);
86
43
  for (const key in metadata) {
87
44
  observableMetadata.set(key, metadata[key]);
88
45
  }
46
+ observableMetadata.changed.connect(this.onModelDBMetadataChange, this);
47
+ trusted.changed.connect(this.onTrustedChanged, this);
48
+ trusted.set(!!metadata.trusted || !!options.trusted);
89
49
  }
90
50
  /**
91
51
  * The type of cell.
@@ -123,24 +83,6 @@ export class CellModel extends CodeEditor.Model {
123
83
  }
124
84
  this.modelDB.setValue('trusted', newValue);
125
85
  }
126
- /**
127
- * Serialize the model to JSON.
128
- */
129
- toJSON() {
130
- const metadata = Object.create(null);
131
- for (const key of this.metadata.keys()) {
132
- const value = JSON.parse(JSON.stringify(this.metadata.get(key)));
133
- metadata[key] = value;
134
- }
135
- if (this.trusted) {
136
- metadata['trusted'] = true;
137
- }
138
- return {
139
- cell_type: this.type,
140
- source: this.value.text,
141
- metadata
142
- };
143
- }
144
86
  /**
145
87
  * Handle a change to the trusted state.
146
88
  *
@@ -150,42 +92,62 @@ export class CellModel extends CodeEditor.Model {
150
92
  /* no-op */
151
93
  }
152
94
  /**
153
- * When we initialize a cell model, we create a standalone model that cannot be shared in a YNotebook.
154
- * Call this function to re-initialize the local representation based on a fresh shared model (e.g. models.YFile or models.YCodeCell).
155
- *
156
- * @param sharedModel
157
- * @param reinitialize Whether to reinitialize the shared model.
158
- */
159
- switchSharedModel(sharedModel, reinitialize) {
160
- if (reinitialize) {
161
- const newValue = sharedModel.getMetadata();
162
- if (newValue) {
163
- this._updateModelDBMetadata(newValue);
164
- }
165
- }
166
- super.switchSharedModel(sharedModel, reinitialize);
95
+ * Serialize the model to JSON.
96
+ */
97
+ toJSON() {
98
+ return this.sharedModel.toJSON();
99
+ }
100
+ /**
101
+ * Handle a change to the observable value.
102
+ */
103
+ onGenericChange() {
104
+ this.contentChanged.emit(void 0);
167
105
  }
168
106
  /**
169
107
  * Handle a change to the cell metadata modelDB and reflect it in the shared model.
170
108
  */
171
109
  onModelDBMetadataChange(sender, event) {
172
110
  const metadata = this.sharedModel.getMetadata();
173
- globalModelDBMutex(() => {
174
- switch (event.type) {
175
- case 'add':
176
- this._changeCellMetadata(metadata, event);
177
- break;
178
- case 'change':
179
- this._changeCellMetadata(metadata, event);
180
- break;
181
- case 'remove':
182
- delete metadata[event.key];
183
- break;
184
- default:
185
- throw new Error(`Invalid event type: ${event.type}`);
111
+ switch (event.type) {
112
+ case 'add':
113
+ this._changeCellMetadata(metadata, event);
114
+ break;
115
+ case 'change':
116
+ this._changeCellMetadata(metadata, event);
117
+ break;
118
+ case 'remove':
119
+ delete metadata[event.key];
120
+ if (event.key === 'collapsed' && metadata.jupyter) {
121
+ delete metadata.jupyter.outputs_hidden;
122
+ if (Object.keys(metadata.jupyter).length === 0) {
123
+ delete metadata.jupyter;
124
+ }
125
+ }
126
+ if (event.key === 'jupyter') {
127
+ delete metadata.collapsed;
128
+ }
129
+ break;
130
+ default:
131
+ throw new Error(`Invalid event type: ${event.type}`);
132
+ }
133
+ this.sharedModel.setMetadata(metadata);
134
+ }
135
+ onSharedModelChanged(sender, change) {
136
+ if (change.metadataChange) {
137
+ const newValue = change.metadataChange.newValue || {};
138
+ const oldValue = change.metadataChange.oldValue || {};
139
+ for (const key in newValue) {
140
+ if (oldValue[key] === undefined ||
141
+ !JSONExt.deepEqual(newValue[key], oldValue[key])) {
142
+ this.metadata.set(key, newValue[key]);
143
+ }
186
144
  }
187
- this.sharedModel.setMetadata(metadata);
188
- });
145
+ this.metadata.keys().forEach(key => {
146
+ if (newValue[key] === undefined) {
147
+ this.metadata.delete(key);
148
+ }
149
+ });
150
+ }
189
151
  }
190
152
  /**
191
153
  * Change the cell metadata for a given event.
@@ -194,9 +156,16 @@ export class CellModel extends CodeEditor.Model {
194
156
  * @param event The event to handle.
195
157
  */
196
158
  _changeCellMetadata(metadata, event) {
159
+ var _a;
197
160
  switch (event.key) {
198
161
  case 'jupyter':
199
162
  metadata.jupyter = event.newValue;
163
+ if (((_a = metadata.jupyter) === null || _a === void 0 ? void 0 : _a.outputs_hidden) != null) {
164
+ metadata.collapsed = metadata.jupyter.outputs_hidden;
165
+ }
166
+ else {
167
+ delete metadata.collapsed;
168
+ }
200
169
  break;
201
170
  case 'collapsed':
202
171
  metadata.collapsed = event.newValue;
@@ -220,62 +189,6 @@ export class CellModel extends CodeEditor.Model {
220
189
  metadata[event.key] = event.newValue;
221
190
  }
222
191
  }
223
- /**
224
- * Handle a change to the cell shared model and reflect it in modelDB.
225
- * We update the modeldb metadata when the shared model changes.
226
- *
227
- * This method overrides the CodeEditor protected _onSharedModelChanged
228
- * so we first call super._onSharedModelChanged
229
- *
230
- * @override CodeEditor._onSharedModelChanged
231
- */
232
- _onSharedModelChanged(sender, change) {
233
- super._onSharedModelChanged(sender, change);
234
- globalModelDBMutex(() => {
235
- var _a;
236
- if (change.metadataChange) {
237
- const newValue = (_a = change.metadataChange) === null || _a === void 0 ? void 0 : _a.newValue;
238
- if (newValue) {
239
- this._updateModelDBMetadata(newValue);
240
- }
241
- }
242
- });
243
- }
244
- _updateModelDBMetadata(metadata) {
245
- Object.keys(metadata).map(key => {
246
- switch (key) {
247
- case 'collapsed':
248
- this.metadata.set('collapsed', metadata.jupyter);
249
- break;
250
- case 'jupyter':
251
- this.metadata.set('jupyter', metadata.jupyter);
252
- break;
253
- case 'name':
254
- this.metadata.set('name', metadata.name);
255
- break;
256
- case 'scrolled':
257
- this.metadata.set('scrolled', metadata.scrolled);
258
- break;
259
- case 'tags':
260
- this.metadata.set('tags', metadata.tags);
261
- break;
262
- case 'trusted':
263
- this.metadata.set('trusted', metadata.trusted);
264
- break;
265
- default:
266
- // The default is applied for custom metadata that are not
267
- // defined in the official nbformat but which are defined
268
- // by the user.
269
- this.metadata.set(key, metadata[key]);
270
- }
271
- });
272
- }
273
- /**
274
- * Handle a change to the observable value.
275
- */
276
- onGenericChange() {
277
- this.contentChanged.emit(void 0);
278
- }
279
192
  }
280
193
  /**
281
194
  * A base implementation for cell models with attachments.
@@ -287,15 +200,8 @@ export class AttachmentsCellModel extends CellModel {
287
200
  constructor(options) {
288
201
  super(options);
289
202
  const factory = options.contentFactory || AttachmentsCellModel.defaultContentFactory;
290
- let attachments;
291
- const cell = options.cell;
292
- if (cell && (cell.cell_type === 'raw' || cell.cell_type === 'markdown')) {
293
- attachments = cell
294
- .attachments;
295
- }
296
203
  this._attachments = factory.createAttachmentsModel({
297
- values: attachments,
298
- modelDB: this.modelDB
204
+ sharedModel: this.sharedModel
299
205
  });
300
206
  this._attachments.stateChanged.connect(this.onGenericChange, this);
301
207
  }
@@ -309,11 +215,7 @@ export class AttachmentsCellModel extends CellModel {
309
215
  * Serialize the model to JSON.
310
216
  */
311
217
  toJSON() {
312
- const cell = super.toJSON();
313
- if (this.attachments.length) {
314
- cell.attachments = this.attachments.toJSON();
315
- }
316
- return cell;
218
+ return super.toJSON();
317
219
  }
318
220
  }
319
221
  /**
@@ -341,6 +243,19 @@ export class AttachmentsCellModel extends CellModel {
341
243
  * An implementation of a raw cell model.
342
244
  */
343
245
  export class RawCellModel extends AttachmentsCellModel {
246
+ /**
247
+ * Construct a raw cell model from optional shared model.
248
+ */
249
+ constructor(options = {}) {
250
+ super({
251
+ ...options,
252
+ sharedModel: (options === null || options === void 0 ? void 0 : options.sharedModel) ||
253
+ createStandaloneCell({
254
+ cell_type: 'raw',
255
+ id: options.id
256
+ })
257
+ });
258
+ }
344
259
  /**
345
260
  * The type of the cell.
346
261
  */
@@ -351,9 +266,7 @@ export class RawCellModel extends AttachmentsCellModel {
351
266
  * Serialize the model to JSON.
352
267
  */
353
268
  toJSON() {
354
- const cell = super.toJSON();
355
- cell.id = this.id;
356
- return cell;
269
+ return super.toJSON();
357
270
  }
358
271
  }
359
272
  /**
@@ -361,10 +274,17 @@ export class RawCellModel extends AttachmentsCellModel {
361
274
  */
362
275
  export class MarkdownCellModel extends AttachmentsCellModel {
363
276
  /**
364
- * Construct a markdown cell model from optional cell content.
277
+ * Construct a markdown cell model from optional shared model.
365
278
  */
366
- constructor(options) {
367
- super(options);
279
+ constructor(options = {}) {
280
+ super({
281
+ ...options,
282
+ sharedModel: (options === null || options === void 0 ? void 0 : options.sharedModel) ||
283
+ createStandaloneCell({
284
+ cell_type: 'markdown',
285
+ id: options.id
286
+ })
287
+ });
368
288
  // Use the Github-flavored markdown mode.
369
289
  this.mimeType = 'text/x-ipythongfm';
370
290
  }
@@ -378,9 +298,7 @@ export class MarkdownCellModel extends AttachmentsCellModel {
378
298
  * Serialize the model to JSON.
379
299
  */
380
300
  toJSON() {
381
- const cell = super.toJSON();
382
- cell.id = this.id;
383
- return cell;
301
+ return super.toJSON();
384
302
  }
385
303
  }
386
304
  /**
@@ -390,77 +308,21 @@ export class CodeCellModel extends CellModel {
390
308
  /**
391
309
  * Construct a new code cell with optional original cell content.
392
310
  */
393
- constructor(options) {
394
- var _a;
395
- super(options);
311
+ constructor(options = {}) {
312
+ super({
313
+ ...options,
314
+ sharedModel: (options === null || options === void 0 ? void 0 : options.sharedModel) ||
315
+ createStandaloneCell({ cell_type: 'code', id: options.id })
316
+ });
396
317
  this._executedCode = '';
397
318
  this._isDirty = false;
398
- const factory = options.contentFactory || CodeCellModel.defaultContentFactory;
319
+ const factory = (options === null || options === void 0 ? void 0 : options.contentFactory) || CodeCellModel.defaultContentFactory;
399
320
  const trusted = this.trusted;
400
- const cell = options.cell;
401
- let outputs = [];
402
- const executionCount = this.modelDB.createValue('executionCount');
403
- if (cell && cell.cell_type === 'code') {
404
- // Initialize from disk
405
- executionCount.set(cell.execution_count || null);
406
- outputs = (_a = cell.outputs) !== null && _a !== void 0 ? _a : [];
407
- // Add content loaded from disk to sharedModel
408
- globalModelDBMutex(() => {
409
- this.sharedModel.execution_count = cell.execution_count;
410
- this.sharedModel.setOutputs(outputs);
411
- });
412
- // If execution count is not null presume the input code was the latest executed
413
- // TODO load from the notebook file when the dirty state is stored in it
414
- if (cell.execution_count !== null) {
415
- // True if execution_count is null or undefined
416
- this._executedCode = this.value.text.trim();
417
- }
418
- }
419
- else {
420
- // Initialize from other clients
421
- executionCount.set(this.sharedModel.execution_count);
422
- outputs = this.sharedModel.getOutputs();
423
- }
424
- this.value.changed.connect(this._onValueChanged, this);
425
- executionCount.changed.connect(this._onExecutionCountChanged, this);
321
+ let outputs = this.sharedModel.getOutputs();
322
+ this.sharedModel.changed.connect(this._onValueChanged, this);
426
323
  this._outputs = factory.createOutputArea({ trusted, values: outputs });
427
324
  this._outputs.changed.connect(this.onGenericChange, this);
428
325
  this._outputs.changed.connect(this.onModelDBOutputsChange, this);
429
- // We keep `collapsed` and `jupyter.outputs_hidden` metadata in sync, since
430
- // they are redundant in nbformat 4.4. See
431
- // https://github.com/jupyter/nbformat/issues/137
432
- this.metadata.changed.connect(Private.collapseChanged, this);
433
- // Sync `collapsed` and `jupyter.outputs_hidden` for the first time, giving
434
- // preference to `collapsed`.
435
- if (this.metadata.has('collapsed')) {
436
- const collapsed = this.metadata.get('collapsed');
437
- Private.collapseChanged(this.metadata, {
438
- type: 'change',
439
- key: 'collapsed',
440
- oldValue: collapsed,
441
- newValue: collapsed
442
- });
443
- }
444
- else if (this.metadata.has('jupyter')) {
445
- const jupyter = this.metadata.get('jupyter');
446
- if (jupyter.hasOwnProperty('outputs_hidden')) {
447
- Private.collapseChanged(this.metadata, {
448
- type: 'change',
449
- key: 'jupyter',
450
- oldValue: jupyter,
451
- newValue: jupyter
452
- });
453
- }
454
- }
455
- }
456
- switchSharedModel(sharedModel, reinitialize) {
457
- if (reinitialize) {
458
- this.executionCount = sharedModel.execution_count;
459
- this.outputs.clear();
460
- sharedModel.getOutputs().forEach(output => this._outputs.add(output));
461
- }
462
- super.switchSharedModel(sharedModel, reinitialize);
463
- this._setDirty(false);
464
326
  }
465
327
  /**
466
328
  * The type of the cell.
@@ -472,16 +334,10 @@ export class CodeCellModel extends CellModel {
472
334
  * The execution count of the cell.
473
335
  */
474
336
  get executionCount() {
475
- return this.modelDB.has('executionCount')
476
- ? this.modelDB.getValue('executionCount')
477
- : null;
337
+ return this.sharedModel.execution_count || null;
478
338
  }
479
339
  set executionCount(newValue) {
480
- const oldValue = this.executionCount;
481
- if (newValue === oldValue) {
482
- return;
483
- }
484
- this.modelDB.setValue('executionCount', newValue || null);
340
+ this.sharedModel.execution_count = newValue || null;
485
341
  }
486
342
  /**
487
343
  * Whether the cell is dirty or not.
@@ -495,32 +351,18 @@ export class CodeCellModel extends CellModel {
495
351
  return this._isDirty;
496
352
  }
497
353
  /**
498
- * Set whether the cell is dirty or not.
354
+ * The cell outputs.
499
355
  */
500
- _setDirty(v) {
501
- if (v !== this._isDirty) {
502
- if (!v) {
503
- this._executedCode = this.value.text.trim();
504
- }
505
- this._isDirty = v;
506
- this.stateChanged.emit({
507
- name: 'isDirty',
508
- oldValue: !v,
509
- newValue: v
510
- });
511
- }
356
+ get outputs() {
357
+ return this._outputs;
512
358
  }
513
359
  clearExecution() {
514
360
  this.outputs.clear();
515
361
  this.executionCount = null;
516
362
  this._setDirty(false);
517
- this.metadata.delete('execution');
518
- }
519
- /**
520
- * The cell outputs.
521
- */
522
- get outputs() {
523
- return this._outputs;
363
+ const metadata = this.sharedModel.getMetadata();
364
+ delete metadata.execution;
365
+ this.sharedModel.setMetadata(metadata);
524
366
  }
525
367
  /**
526
368
  * Dispose of the resources held by the model.
@@ -533,16 +375,6 @@ export class CodeCellModel extends CellModel {
533
375
  this._outputs = null;
534
376
  super.dispose();
535
377
  }
536
- /**
537
- * Serialize the model to JSON.
538
- */
539
- toJSON() {
540
- const cell = super.toJSON();
541
- cell.execution_count = this.executionCount || null;
542
- cell.outputs = this.outputs.toJSON();
543
- cell.id = this.id;
544
- return cell;
545
- }
546
378
  /**
547
379
  * Handle a change to the trusted state.
548
380
  */
@@ -556,6 +388,12 @@ export class CodeCellModel extends CellModel {
556
388
  newValue: args.newValue
557
389
  });
558
390
  }
391
+ /**
392
+ * Serialize the model to JSON.
393
+ */
394
+ toJSON() {
395
+ return super.toJSON();
396
+ }
559
397
  /**
560
398
  * Handle a change to the cell outputs modelDB and reflect it in the shared model.
561
399
  */
@@ -565,7 +403,7 @@ export class CodeCellModel extends CellModel {
565
403
  switch (event.type) {
566
404
  case 'add': {
567
405
  const outputs = event.newValues.map(output => output.toJSON());
568
- codeCell.updateOutputs(event.newIndex, event.newIndex + outputs.length, outputs);
406
+ codeCell.updateOutputs(event.newIndex, event.newIndex, outputs);
569
407
  break;
570
408
  }
571
409
  case 'set': {
@@ -581,14 +419,6 @@ export class CodeCellModel extends CellModel {
581
419
  }
582
420
  });
583
421
  }
584
- /**
585
- * Handle a change to the code cell value.
586
- */
587
- _onValueChanged() {
588
- if (this.executionCount !== null) {
589
- this._setDirty(this._executedCode !== this.value.text.trim());
590
- }
591
- }
592
422
  /**
593
423
  * Handle a change to the output shared model and reflect it in modelDB.
594
424
  * We update the modeldb metadata when the nbcell changes.
@@ -598,38 +428,48 @@ export class CodeCellModel extends CellModel {
598
428
  *
599
429
  * @override CellModel._onSharedModelChanged
600
430
  */
601
- _onSharedModelChanged(sender, change) {
602
- super._onSharedModelChanged(sender, change);
431
+ onSharedModelChanged(sender, change) {
432
+ super.onSharedModelChanged(sender, change);
603
433
  globalModelDBMutex(() => {
604
434
  if (change.outputsChange) {
605
435
  this.clearExecution();
606
436
  sender.getOutputs().forEach(output => this._outputs.add(output));
607
437
  }
608
- if (change.executionCountChange) {
609
- this.executionCount = change.executionCountChange.newValue
610
- ? change.executionCountChange.newValue
611
- : null;
612
- }
613
438
  });
614
439
  }
615
440
  /**
616
- * Handle a change to the execution count.
441
+ * Handle a change to the code cell value.
617
442
  */
618
- _onExecutionCountChanged(count, args) {
619
- const codeCell = this.sharedModel;
620
- globalModelDBMutex(() => {
621
- codeCell.execution_count = args.newValue
622
- ? args.newValue
623
- : null;
624
- });
625
- this.contentChanged.emit(void 0);
626
- this.stateChanged.emit({
627
- name: 'executionCount',
628
- oldValue: args.oldValue,
629
- newValue: args.newValue
630
- });
631
- if (args.newValue && this.isDirty) {
632
- this._setDirty(false);
443
+ _onValueChanged(slot, change) {
444
+ if (change.executionCountChange) {
445
+ if (change.executionCountChange.newValue &&
446
+ (this.isDirty || !change.executionCountChange.oldValue)) {
447
+ this._setDirty(false);
448
+ }
449
+ this.stateChanged.emit({
450
+ name: 'executionCount',
451
+ oldValue: change.executionCountChange.oldValue,
452
+ newValue: change.executionCountChange.newValue
453
+ });
454
+ }
455
+ if (change.sourceChange && this.executionCount !== null) {
456
+ this._setDirty(this._executedCode !== this.sharedModel.getSource().trim());
457
+ }
458
+ }
459
+ /**
460
+ * Set whether the cell is dirty or not.
461
+ */
462
+ _setDirty(v) {
463
+ if (!v) {
464
+ this._executedCode = this.sharedModel.getSource().trim();
465
+ }
466
+ if (v !== this._isDirty) {
467
+ this._isDirty = v;
468
+ this.stateChanged.emit({
469
+ name: 'isDirty',
470
+ oldValue: !v,
471
+ newValue: v
472
+ });
633
473
  }
634
474
  }
635
475
  }
@@ -654,34 +494,4 @@ export class CodeCellModel extends CellModel {
654
494
  */
655
495
  CodeCellModel.defaultContentFactory = new ContentFactory();
656
496
  })(CodeCellModel || (CodeCellModel = {}));
657
- var Private;
658
- (function (Private) {
659
- function collapseChanged(metadata, args) {
660
- if (args.key === 'collapsed') {
661
- const jupyter = (metadata.get('jupyter') || {});
662
- const { outputs_hidden } = jupyter, newJupyter = __rest(jupyter, ["outputs_hidden"]);
663
- if (outputs_hidden !== args.newValue) {
664
- if (args.newValue !== undefined) {
665
- newJupyter['outputs_hidden'] = args.newValue;
666
- }
667
- if (Object.keys(newJupyter).length === 0) {
668
- metadata.delete('jupyter');
669
- }
670
- else {
671
- metadata.set('jupyter', newJupyter);
672
- }
673
- }
674
- }
675
- else if (args.key === 'jupyter') {
676
- const jupyter = (args.newValue || {});
677
- if (jupyter.hasOwnProperty('outputs_hidden')) {
678
- metadata.set('collapsed', jupyter.outputs_hidden);
679
- }
680
- else {
681
- metadata.delete('collapsed');
682
- }
683
- }
684
- }
685
- Private.collapseChanged = collapseChanged;
686
- })(Private || (Private = {}));
687
497
  //# sourceMappingURL=model.js.map