@jupyterlab/cells 4.7.0-alpha.1 → 4.7.0-beta.0

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/src/widget.ts CHANGED
@@ -369,6 +369,23 @@ export class Cell<T extends ICellModel = ICellModel> extends Widget {
369
369
  this.update();
370
370
  }
371
371
 
372
+ /**
373
+ * Whether the cell is being displayed in view-only mode.
374
+ *
375
+ * This state is transient and is not persisted to the notebook model.
376
+ */
377
+ get viewOnly(): boolean {
378
+ return this._viewOnly;
379
+ }
380
+
381
+ set viewOnly(value: boolean) {
382
+ if (this._viewOnly === value) {
383
+ return;
384
+ }
385
+ this._viewOnly = value;
386
+ this.update();
387
+ }
388
+
372
389
  /**
373
390
  * Whether the cell is a placeholder that defer rendering
374
391
  *
@@ -566,11 +583,16 @@ export class Cell<T extends ICellModel = ICellModel> extends Widget {
566
583
  return;
567
584
  }
568
585
  this._resizeDebouncer.dispose();
586
+ const input = this._input;
587
+ const inputPlaceholder = this._inputPlaceholder;
569
588
  this._input = null!;
570
589
  this._model = null!;
571
590
  this._inputWrapper = null!;
572
591
  this._inputPlaceholder = null!;
573
592
  super.dispose();
593
+ // Dispose the input widget that may have been swapped out of the layout.
594
+ input?.dispose();
595
+ inputPlaceholder?.dispose();
574
596
  }
575
597
 
576
598
  /**
@@ -637,7 +659,7 @@ export class Cell<T extends ICellModel = ICellModel> extends Widget {
637
659
  .getSource()
638
660
  .split('\n')?.[0];
639
661
  }
640
- });
662
+ }, this);
641
663
 
642
664
  if (this.inputHidden) {
643
665
  input.parent = null;
@@ -696,9 +718,12 @@ export class Cell<T extends ICellModel = ICellModel> extends Widget {
696
718
  if (!this._model) {
697
719
  return;
698
720
  }
699
- // Handle read only state.
700
- if (this.editor?.getOption('readOnly') !== this._readOnly) {
701
- this.editor?.setOption('readOnly', this._readOnly);
721
+
722
+ // Handle read-only and view-only states.
723
+ const readOnly = this._readOnly || this._viewOnly;
724
+
725
+ if (this.editor?.getOption('readOnly') !== readOnly) {
726
+ this.editor?.setOption('readOnly', readOnly);
702
727
  }
703
728
  }
704
729
 
@@ -776,6 +801,7 @@ export class Cell<T extends ICellModel = ICellModel> extends Widget {
776
801
  private _model: T;
777
802
  private _placeholder: boolean;
778
803
  private _readOnly = false;
804
+ private _viewOnly = false;
779
805
  private _ready = new PromiseDelegate<void>();
780
806
  private _resizeDebouncer = new Debouncer(() => {
781
807
  this._displayChanged.emit();
@@ -1490,20 +1516,20 @@ export class CodeCell extends Cell<ICodeCellModel> {
1490
1516
  overlay.firstChild?.remove();
1491
1517
  return;
1492
1518
  }
1519
+ const trans = this.translator.load('jupyterlab');
1493
1520
  let overlayTitle: string;
1494
1521
  if (this._outputsScrolled) {
1495
1522
  expandIcon.element({
1496
1523
  container: overlay
1497
1524
  });
1498
- overlayTitle = 'Expand Output';
1525
+ overlayTitle = trans.__('Expand Output');
1499
1526
  } else {
1500
1527
  collapseIcon.element({
1501
1528
  container: overlay
1502
1529
  });
1503
- overlayTitle = 'Collapse Output';
1530
+ overlayTitle = trans.__('Collapse Output');
1504
1531
  }
1505
- const trans = this.translator.load('jupyterlab');
1506
- overlay.title = trans.__(overlayTitle);
1532
+ overlay.title = overlayTitle;
1507
1533
  }
1508
1534
  /**
1509
1535
  * Save view collapse state to model
@@ -1614,11 +1640,16 @@ export class CodeCell extends Cell<ICodeCellModel> {
1614
1640
  'keydown',
1615
1641
  this._detectCaretMovementInOuput
1616
1642
  );
1643
+ const output = this._output;
1644
+ const outputPlaceholder = this._outputPlaceholder;
1617
1645
  this._rendermime = null!;
1618
1646
  this._output = null!;
1619
1647
  this._outputWrapper = null!;
1620
1648
  this._outputPlaceholder = null!;
1621
1649
  super.dispose();
1650
+ // Dispose the output widget that may have been swapped out of the layout.
1651
+ output.dispose();
1652
+ outputPlaceholder?.dispose();
1622
1653
  }
1623
1654
 
1624
1655
  /**
@@ -1695,7 +1726,7 @@ export class CodeCell extends Cell<ICodeCellModel> {
1695
1726
  if (this.model.executionState == 'running') {
1696
1727
  prompt = '*';
1697
1728
  } else {
1698
- prompt = `${this.model.executionCount || ''}`;
1729
+ prompt = `${this.model.executionCount ?? ''}`;
1699
1730
  }
1700
1731
  this._setPrompt(prompt);
1701
1732
  }