@jupyterlab/cells 4.0.0-alpha.9 → 4.0.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/lib/widget.d.ts CHANGED
@@ -1,19 +1,19 @@
1
+ import { Extension } from '@codemirror/state';
1
2
  import { ISessionContext } from '@jupyterlab/apputils';
2
3
  import { IChangedArgs } from '@jupyterlab/coreutils';
3
4
  import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
4
- import { IObservableJSON, IObservableMap } from '@jupyterlab/observables';
5
5
  import { IOutputPrompt, IStdin, OutputArea, Stdin } from '@jupyterlab/outputarea';
6
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
6
+ import { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
7
7
  import { KernelMessage } from '@jupyterlab/services';
8
+ import { IMapChange } from '@jupyter/ydoc';
8
9
  import { ITranslator } from '@jupyterlab/translation';
9
- import { JSONObject, JSONValue, PartialJSONValue } from '@lumino/coreutils';
10
+ import { JSONObject } from '@lumino/coreutils';
10
11
  import { Message } from '@lumino/messaging';
11
- import { Widget } from '@lumino/widgets';
12
+ import { ISignal, Signal } from '@lumino/signaling';
13
+ import { PanelLayout, Widget } from '@lumino/widgets';
12
14
  import { ICellFooter, ICellHeader } from './headerfooter';
13
15
  import { IInputPrompt, InputArea } from './inputarea';
14
- import { IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
15
- import { Signal } from '@lumino/signaling';
16
- export declare const MARKDOWN_HEADING_COLLAPSED = "jp-MarkdownHeadingCollapsed";
16
+ import { CellModel, IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
17
17
  /** ****************************************************************************
18
18
  * Cell
19
19
  ******************************************************************************/
@@ -40,19 +40,42 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
40
40
  /**
41
41
  * Signal to indicate that widget has changed visibly (in size, in type, etc)
42
42
  */
43
- readonly displayChanged: Signal<this, void>;
43
+ get displayChanged(): ISignal<this, void>;
44
+ /**
45
+ * Whether the cell is in viewport or not.
46
+ */
47
+ get inViewport(): boolean;
48
+ set inViewport(v: boolean);
49
+ /**
50
+ * Will emit true just after the node is attached to the DOM
51
+ * Will emit false just before the node is detached of the DOM
52
+ */
53
+ get inViewportChanged(): ISignal<Cell, boolean>;
54
+ /**
55
+ * Whether the cell is a placeholder not yet fully rendered or not.
56
+ */
57
+ protected get placeholder(): boolean;
58
+ protected set placeholder(v: boolean);
44
59
  /**
45
60
  * Get the prompt node used by the cell.
46
61
  */
47
- get promptNode(): HTMLElement;
62
+ get promptNode(): HTMLElement | null;
48
63
  /**
49
64
  * Get the CodeEditorWrapper used by the cell.
50
65
  */
51
- get editorWidget(): CodeEditorWrapper;
66
+ get editorWidget(): CodeEditorWrapper | null;
52
67
  /**
53
68
  * Get the CodeEditor used by the cell.
54
69
  */
55
- get editor(): CodeEditor.IEditor;
70
+ get editor(): CodeEditor.IEditor | null;
71
+ /**
72
+ * Editor configuration
73
+ */
74
+ get editorConfig(): Record<string, any>;
75
+ /**
76
+ * Cell headings
77
+ */
78
+ get headings(): Cell.IHeading[];
56
79
  /**
57
80
  * Get the model used by the cell.
58
81
  */
@@ -60,12 +83,20 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
60
83
  /**
61
84
  * Get the input area for the cell.
62
85
  */
63
- get inputArea(): InputArea;
86
+ get inputArea(): InputArea | null;
64
87
  /**
65
88
  * The read only state of the cell.
66
89
  */
67
90
  get readOnly(): boolean;
68
91
  set readOnly(value: boolean);
92
+ /**
93
+ * Whether the cell is a placeholder that defer rendering
94
+ *
95
+ * #### Notes
96
+ * You can wait for the promise `Cell.ready` to wait for the
97
+ * cell to be rendered.
98
+ */
99
+ isPlaceholder(): boolean;
69
100
  /**
70
101
  * Save view editable state to model
71
102
  */
@@ -122,6 +153,26 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
122
153
  * Dispose of the resources held by the widget.
123
154
  */
124
155
  dispose(): void;
156
+ /**
157
+ * Update the editor configuration with the partial provided dictionary.
158
+ *
159
+ * @param v Partial editor configuration
160
+ */
161
+ updateEditorConfig(v: Record<string, any>): void;
162
+ /**
163
+ * Create children widgets.
164
+ */
165
+ protected initializeDOM(): void;
166
+ /**
167
+ * Get the editor options at initialization.
168
+ *
169
+ * @returns Editor options
170
+ */
171
+ protected getEditorOptions(): InputArea.IOptions['editorOptions'];
172
+ /**
173
+ * Handle `before-attach` messages.
174
+ */
175
+ protected onBeforeAttach(msg: Message): void;
125
176
  /**
126
177
  * Handle `after-attach` messages.
127
178
  */
@@ -130,10 +181,6 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
130
181
  * Handle `'activate-request'` messages.
131
182
  */
132
183
  protected onActivateRequest(msg: Message): void;
133
- /**
134
- * Handle `fit-request` messages.
135
- */
136
- protected onFitRequest(msg: Message): void;
137
184
  /**
138
185
  * Handle `resize` messages.
139
186
  */
@@ -145,17 +192,24 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
145
192
  /**
146
193
  * Handle changes in the metadata.
147
194
  */
148
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
195
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
196
+ protected prompt: string;
149
197
  protected translator: ITranslator;
150
- private _readOnly;
151
- private _model;
152
- private _inputHidden;
198
+ protected _displayChanged: Signal<this, void>;
199
+ private _editorConfig;
153
200
  private _input;
201
+ private _inputHidden;
154
202
  private _inputWrapper;
155
203
  private _inputPlaceholder;
204
+ private _inViewport;
205
+ private _inViewportChanged;
206
+ private _model;
207
+ private _placeholder;
208
+ private _readOnly;
209
+ private _ready;
210
+ private _resizeDebouncer;
156
211
  private _syncCollapse;
157
212
  private _syncEditable;
158
- private _resizeDebouncer;
159
213
  }
160
214
  /**
161
215
  * The namespace for the `Cell` class statics.
@@ -172,19 +226,27 @@ export declare namespace Cell {
172
226
  /**
173
227
  * The factory object for customizable cell children.
174
228
  */
175
- contentFactory?: IContentFactory;
229
+ contentFactory: IContentFactory;
176
230
  /**
177
231
  * The configuration options for the text editor widget.
178
232
  */
179
- editorConfig?: Partial<CodeEditor.IConfig>;
233
+ editorConfig?: Record<string, any>;
234
+ /**
235
+ * Editor extensions to be added.
236
+ */
237
+ editorExtensions?: Extension[];
180
238
  /**
181
- * Whether to send an update request to the editor when it is shown.
239
+ * Cell widget layout.
182
240
  */
183
- updateEditorOnShow?: boolean;
241
+ layout?: PanelLayout;
184
242
  /**
185
243
  * The maximum number of output items to display in cell output.
186
244
  */
187
245
  maxNumberOutputs?: number;
246
+ /**
247
+ * Whether to split stdin line history by kernel session or keep globally accessible.
248
+ */
249
+ inputHistoryScope?: 'global' | 'session';
188
250
  /**
189
251
  * Whether this cell is a placeholder for future rendering.
190
252
  */
@@ -194,6 +256,40 @@ export declare namespace Cell {
194
256
  */
195
257
  translator?: ITranslator;
196
258
  }
259
+ /**
260
+ * Cell heading
261
+ */
262
+ interface IHeading {
263
+ /**
264
+ * Heading text.
265
+ */
266
+ text: string;
267
+ /**
268
+ * HTML heading level.
269
+ */
270
+ level: number;
271
+ /**
272
+ * Index of the output containing the heading
273
+ */
274
+ outputIndex?: number;
275
+ /**
276
+ * Type of heading
277
+ */
278
+ type: HeadingType;
279
+ }
280
+ /**
281
+ * Type of headings
282
+ */
283
+ enum HeadingType {
284
+ /**
285
+ * Heading from HTML output
286
+ */
287
+ HTML = 0,
288
+ /**
289
+ * Heading from Markdown cell or Markdown output
290
+ */
291
+ Markdown = 1
292
+ }
197
293
  /**
198
294
  * The factory object for customizable cell children.
199
295
  *
@@ -222,7 +318,7 @@ export declare namespace Cell {
222
318
  /**
223
319
  * Create a content factory for a cell.
224
320
  */
225
- constructor(options?: ContentFactory.IOptions);
321
+ constructor(options: ContentFactory.IOptions);
226
322
  /**
227
323
  * The readonly editor factory that create code editors
228
324
  */
@@ -259,21 +355,43 @@ export declare namespace Cell {
259
355
  interface IOptions {
260
356
  /**
261
357
  * The editor factory used by the content factory.
262
- *
263
- * If this is not passed, a default CodeMirror editor factory
264
- * will be used.
265
358
  */
266
- editorFactory?: CodeEditor.Factory;
359
+ editorFactory: CodeEditor.Factory;
267
360
  }
268
361
  }
269
- /**
270
- * The default content factory for cells.
271
- */
272
- const defaultContentFactory: ContentFactory;
273
362
  }
274
363
  /** ****************************************************************************
275
364
  * CodeCell
276
365
  ******************************************************************************/
366
+ /**
367
+ * Code cell layout
368
+ *
369
+ * It will not detached the output area when the cell is detached.
370
+ */
371
+ export declare class CodeCellLayout extends PanelLayout {
372
+ /**
373
+ * A message handler invoked on a `'before-attach'` message.
374
+ *
375
+ * #### Notes
376
+ * The default implementation of this method forwards the message
377
+ * to all widgets. It assumes all widget nodes are attached to the
378
+ * parent widget node.
379
+ *
380
+ * This may be reimplemented by subclasses as needed.
381
+ */
382
+ protected onBeforeAttach(msg: Message): void;
383
+ /**
384
+ * A message handler invoked on an `'after-detach'` message.
385
+ *
386
+ * #### Notes
387
+ * The default implementation of this method forwards the message
388
+ * to all widgets. It assumes all widget nodes are attached to the
389
+ * parent widget node.
390
+ *
391
+ * This may be reimplemented by subclasses as needed.
392
+ */
393
+ protected onAfterDetach(msg: Message): void;
394
+ }
277
395
  /**
278
396
  * A widget for a code cell.
279
397
  */
@@ -282,6 +400,14 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
282
400
  * Construct a code cell widget.
283
401
  */
284
402
  constructor(options: CodeCell.IOptions);
403
+ /**
404
+ * Maximum number of outputs to display.
405
+ */
406
+ protected maxNumberOutputs: number | undefined;
407
+ /**
408
+ * Create children widgets.
409
+ */
410
+ protected initializeDOM(): void;
285
411
  /**
286
412
  * Initialize view state from model.
287
413
  *
@@ -290,6 +416,7 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
290
416
  * can be chained in the construction, like `new Foo().initializeState();`
291
417
  */
292
418
  initializeState(): this;
419
+ get headings(): Cell.IHeading[];
293
420
  /**
294
421
  * Get the output area for the cell.
295
422
  */
@@ -353,14 +480,19 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
353
480
  * Handle changes in the model.
354
481
  */
355
482
  protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
483
+ /**
484
+ * Callback on output changes
485
+ */
486
+ protected onOutputChanged(): void;
356
487
  /**
357
488
  * Handle changes in the metadata.
358
489
  */
359
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<JSONValue>): void;
490
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
360
491
  /**
361
492
  * Handle changes in the number of outputs in the output area.
362
493
  */
363
494
  private _outputLengthHandler;
495
+ private _headingsCache;
364
496
  private _rendermime;
365
497
  private _outputHidden;
366
498
  private _outputsScrolled;
@@ -368,7 +500,6 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
368
500
  private _outputPlaceholder;
369
501
  private _output;
370
502
  private _syncScrolled;
371
- private _savingMetadata;
372
503
  }
373
504
  /**
374
505
  * The namespace for the `CodeCell` class statics.
@@ -378,6 +509,10 @@ export declare namespace CodeCell {
378
509
  * An options object for initializing a base cell widget.
379
510
  */
380
511
  interface IOptions extends Cell.IOptions<ICodeCellModel> {
512
+ /**
513
+ * Code cell layout.
514
+ */
515
+ layout?: CodeCellLayout;
381
516
  /**
382
517
  * The mime renderer for the cell widget.
383
518
  */
@@ -404,6 +539,12 @@ export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> e
404
539
  * not be called directly by user code.
405
540
  */
406
541
  handleEvent(event: Event): void;
542
+ /**
543
+ * Get the editor options at initialization.
544
+ *
545
+ * @returns Editor options
546
+ */
547
+ protected getEditorOptions(): InputArea.IOptions['editorOptions'];
407
548
  /**
408
549
  * Modify the cell source to include a reference to the attachment.
409
550
  */
@@ -464,35 +605,61 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
464
605
  */
465
606
  constructor(options: MarkdownCell.IOptions);
466
607
  /**
467
- * A promise that resolves when the widget renders for the first time.
468
- */
469
- get ready(): Promise<void>;
470
- /**
471
- * Text that represents the heading if cell is a heading.
608
+ * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
472
609
  * Returns empty string if not a heading.
473
610
  */
474
611
  get headingInfo(): {
475
612
  text: string;
476
613
  level: number;
477
614
  };
615
+ get headings(): Cell.IHeading[];
616
+ /**
617
+ * Whether the heading is collapsed or not.
618
+ */
478
619
  get headingCollapsed(): boolean;
479
620
  set headingCollapsed(value: boolean);
621
+ /**
622
+ * Number of collapsed sub cells.
623
+ */
480
624
  get numberChildNodes(): number;
481
625
  set numberChildNodes(value: number);
482
- get toggleCollapsedSignal(): Signal<this, boolean>;
626
+ /**
627
+ * Signal emitted when the cell collapsed state changes.
628
+ */
629
+ get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
483
630
  /**
484
631
  * Whether the cell is rendered.
485
632
  */
486
633
  get rendered(): boolean;
487
634
  set rendered(value: boolean);
635
+ /**
636
+ * Signal emitted when the markdown cell rendered state changes
637
+ */
638
+ get renderedChanged(): ISignal<MarkdownCell, boolean>;
488
639
  get showEditorForReadOnly(): boolean;
489
640
  set showEditorForReadOnly(value: boolean);
641
+ /**
642
+ * Renderer
643
+ */
644
+ get renderer(): IRenderMime.IRenderer;
645
+ /**
646
+ * Dispose of the resources held by the widget.
647
+ */
648
+ dispose(): void;
649
+ /**
650
+ * Create children widgets.
651
+ */
652
+ protected initializeDOM(): void;
490
653
  protected maybeCreateCollapseButton(): void;
491
654
  /**
492
655
  * Create, update or remove the hidden cells button.
493
656
  * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
494
657
  */
495
658
  protected maybeCreateOrUpdateExpandButton(): void;
659
+ /**
660
+ * Callback on content changed
661
+ */
662
+ protected onContentChanged(): void;
496
663
  /**
497
664
  * Render the collapse button for heading cells,
498
665
  * and for collapsed heading cells render the "expand hidden cells"
@@ -524,15 +691,16 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
524
691
  * Clone the cell, using the same model.
525
692
  */
526
693
  clone(): MarkdownCell;
694
+ private _headingsCache;
695
+ private _headingCollapsed;
696
+ private _headingCollapsedChanged;
527
697
  private _monitor;
528
698
  private _numberChildNodes;
529
- private _headingCollapsed;
530
- private _toggleCollapsedSignal;
699
+ private _prevText;
531
700
  private _renderer;
532
701
  private _rendermime;
533
702
  private _rendered;
534
- private _prevText;
535
- private _ready;
703
+ private _renderedChanged;
536
704
  private _showEditorForReadOnlyMarkdown;
537
705
  }
538
706
  /**