@jupyterlab/cells 4.0.0-alpha.9 → 4.0.0-beta.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/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
  */
@@ -142,20 +189,28 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
142
189
  * Handle `update-request` messages.
143
190
  */
144
191
  protected onUpdateRequest(msg: Message): void;
192
+ protected onContentChanged(): void;
145
193
  /**
146
194
  * Handle changes in the metadata.
147
195
  */
148
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
196
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
197
+ protected prompt: string;
149
198
  protected translator: ITranslator;
150
- private _readOnly;
151
- private _model;
152
- private _inputHidden;
199
+ protected _displayChanged: Signal<this, void>;
200
+ private _editorConfig;
153
201
  private _input;
202
+ private _inputHidden;
154
203
  private _inputWrapper;
155
204
  private _inputPlaceholder;
205
+ private _inViewport;
206
+ private _inViewportChanged;
207
+ private _model;
208
+ private _placeholder;
209
+ private _readOnly;
210
+ private _ready;
211
+ private _resizeDebouncer;
156
212
  private _syncCollapse;
157
213
  private _syncEditable;
158
- private _resizeDebouncer;
159
214
  }
160
215
  /**
161
216
  * The namespace for the `Cell` class statics.
@@ -172,19 +227,27 @@ export declare namespace Cell {
172
227
  /**
173
228
  * The factory object for customizable cell children.
174
229
  */
175
- contentFactory?: IContentFactory;
230
+ contentFactory: IContentFactory;
176
231
  /**
177
232
  * The configuration options for the text editor widget.
178
233
  */
179
- editorConfig?: Partial<CodeEditor.IConfig>;
234
+ editorConfig?: Record<string, any>;
235
+ /**
236
+ * Editor extensions to be added.
237
+ */
238
+ editorExtensions?: Extension[];
180
239
  /**
181
- * Whether to send an update request to the editor when it is shown.
240
+ * Cell widget layout.
182
241
  */
183
- updateEditorOnShow?: boolean;
242
+ layout?: PanelLayout;
184
243
  /**
185
244
  * The maximum number of output items to display in cell output.
186
245
  */
187
246
  maxNumberOutputs?: number;
247
+ /**
248
+ * Whether to split stdin line history by kernel session or keep globally accessible.
249
+ */
250
+ inputHistoryScope?: 'global' | 'session';
188
251
  /**
189
252
  * Whether this cell is a placeholder for future rendering.
190
253
  */
@@ -194,6 +257,40 @@ export declare namespace Cell {
194
257
  */
195
258
  translator?: ITranslator;
196
259
  }
260
+ /**
261
+ * Cell heading
262
+ */
263
+ interface IHeading {
264
+ /**
265
+ * Heading text.
266
+ */
267
+ text: string;
268
+ /**
269
+ * HTML heading level.
270
+ */
271
+ level: number;
272
+ /**
273
+ * Index of the output containing the heading
274
+ */
275
+ outputIndex?: number;
276
+ /**
277
+ * Type of heading
278
+ */
279
+ type: HeadingType;
280
+ }
281
+ /**
282
+ * Type of headings
283
+ */
284
+ enum HeadingType {
285
+ /**
286
+ * Heading from HTML output
287
+ */
288
+ HTML = 0,
289
+ /**
290
+ * Heading from Markdown cell or Markdown output
291
+ */
292
+ Markdown = 1
293
+ }
197
294
  /**
198
295
  * The factory object for customizable cell children.
199
296
  *
@@ -222,7 +319,7 @@ export declare namespace Cell {
222
319
  /**
223
320
  * Create a content factory for a cell.
224
321
  */
225
- constructor(options?: ContentFactory.IOptions);
322
+ constructor(options: ContentFactory.IOptions);
226
323
  /**
227
324
  * The readonly editor factory that create code editors
228
325
  */
@@ -259,21 +356,43 @@ export declare namespace Cell {
259
356
  interface IOptions {
260
357
  /**
261
358
  * 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
359
  */
266
- editorFactory?: CodeEditor.Factory;
360
+ editorFactory: CodeEditor.Factory;
267
361
  }
268
362
  }
269
- /**
270
- * The default content factory for cells.
271
- */
272
- const defaultContentFactory: ContentFactory;
273
363
  }
274
364
  /** ****************************************************************************
275
365
  * CodeCell
276
366
  ******************************************************************************/
367
+ /**
368
+ * Code cell layout
369
+ *
370
+ * It will not detached the output area when the cell is detached.
371
+ */
372
+ export declare class CodeCellLayout extends PanelLayout {
373
+ /**
374
+ * A message handler invoked on a `'before-attach'` message.
375
+ *
376
+ * #### Notes
377
+ * The default implementation of this method forwards the message
378
+ * to all widgets. It assumes all widget nodes are attached to the
379
+ * parent widget node.
380
+ *
381
+ * This may be reimplemented by subclasses as needed.
382
+ */
383
+ protected onBeforeAttach(msg: Message): void;
384
+ /**
385
+ * A message handler invoked on an `'after-detach'` message.
386
+ *
387
+ * #### Notes
388
+ * The default implementation of this method forwards the message
389
+ * to all widgets. It assumes all widget nodes are attached to the
390
+ * parent widget node.
391
+ *
392
+ * This may be reimplemented by subclasses as needed.
393
+ */
394
+ protected onAfterDetach(msg: Message): void;
395
+ }
277
396
  /**
278
397
  * A widget for a code cell.
279
398
  */
@@ -282,6 +401,15 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
282
401
  * Construct a code cell widget.
283
402
  */
284
403
  constructor(options: CodeCell.IOptions);
404
+ /**
405
+ * Maximum number of outputs to display.
406
+ */
407
+ protected maxNumberOutputs: number | undefined;
408
+ /**
409
+ * Create children widgets.
410
+ */
411
+ protected initializeDOM(): void;
412
+ protected getOutputPlaceholderText(): string | undefined;
285
413
  /**
286
414
  * Initialize view state from model.
287
415
  *
@@ -290,6 +418,7 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
290
418
  * can be chained in the construction, like `new Foo().initializeState();`
291
419
  */
292
420
  initializeState(): this;
421
+ get headings(): Cell.IHeading[];
293
422
  /**
294
423
  * Get the output area for the cell.
295
424
  */
@@ -353,14 +482,19 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
353
482
  * Handle changes in the model.
354
483
  */
355
484
  protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
485
+ /**
486
+ * Callback on output changes
487
+ */
488
+ protected onOutputChanged(): void;
356
489
  /**
357
490
  * Handle changes in the metadata.
358
491
  */
359
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<JSONValue>): void;
492
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
360
493
  /**
361
494
  * Handle changes in the number of outputs in the output area.
362
495
  */
363
496
  private _outputLengthHandler;
497
+ private _headingsCache;
364
498
  private _rendermime;
365
499
  private _outputHidden;
366
500
  private _outputsScrolled;
@@ -368,7 +502,6 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
368
502
  private _outputPlaceholder;
369
503
  private _output;
370
504
  private _syncScrolled;
371
- private _savingMetadata;
372
505
  }
373
506
  /**
374
507
  * The namespace for the `CodeCell` class statics.
@@ -378,6 +511,10 @@ export declare namespace CodeCell {
378
511
  * An options object for initializing a base cell widget.
379
512
  */
380
513
  interface IOptions extends Cell.IOptions<ICodeCellModel> {
514
+ /**
515
+ * Code cell layout.
516
+ */
517
+ layout?: CodeCellLayout;
381
518
  /**
382
519
  * The mime renderer for the cell widget.
383
520
  */
@@ -404,6 +541,12 @@ export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> e
404
541
  * not be called directly by user code.
405
542
  */
406
543
  handleEvent(event: Event): void;
544
+ /**
545
+ * Get the editor options at initialization.
546
+ *
547
+ * @returns Editor options
548
+ */
549
+ protected getEditorOptions(): InputArea.IOptions['editorOptions'];
407
550
  /**
408
551
  * Modify the cell source to include a reference to the attachment.
409
552
  */
@@ -464,35 +607,61 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
464
607
  */
465
608
  constructor(options: MarkdownCell.IOptions);
466
609
  /**
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.
610
+ * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
472
611
  * Returns empty string if not a heading.
473
612
  */
474
613
  get headingInfo(): {
475
614
  text: string;
476
615
  level: number;
477
616
  };
617
+ get headings(): Cell.IHeading[];
618
+ /**
619
+ * Whether the heading is collapsed or not.
620
+ */
478
621
  get headingCollapsed(): boolean;
479
622
  set headingCollapsed(value: boolean);
623
+ /**
624
+ * Number of collapsed sub cells.
625
+ */
480
626
  get numberChildNodes(): number;
481
627
  set numberChildNodes(value: number);
482
- get toggleCollapsedSignal(): Signal<this, boolean>;
628
+ /**
629
+ * Signal emitted when the cell collapsed state changes.
630
+ */
631
+ get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
483
632
  /**
484
633
  * Whether the cell is rendered.
485
634
  */
486
635
  get rendered(): boolean;
487
636
  set rendered(value: boolean);
637
+ /**
638
+ * Signal emitted when the markdown cell rendered state changes
639
+ */
640
+ get renderedChanged(): ISignal<MarkdownCell, boolean>;
488
641
  get showEditorForReadOnly(): boolean;
489
642
  set showEditorForReadOnly(value: boolean);
643
+ /**
644
+ * Renderer
645
+ */
646
+ get renderer(): IRenderMime.IRenderer;
647
+ /**
648
+ * Dispose of the resources held by the widget.
649
+ */
650
+ dispose(): void;
651
+ /**
652
+ * Create children widgets.
653
+ */
654
+ protected initializeDOM(): void;
490
655
  protected maybeCreateCollapseButton(): void;
491
656
  /**
492
657
  * Create, update or remove the hidden cells button.
493
658
  * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
494
659
  */
495
660
  protected maybeCreateOrUpdateExpandButton(): void;
661
+ /**
662
+ * Callback on content changed
663
+ */
664
+ protected onContentChanged(): void;
496
665
  /**
497
666
  * Render the collapse button for heading cells,
498
667
  * and for collapsed heading cells render the "expand hidden cells"
@@ -524,15 +693,16 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
524
693
  * Clone the cell, using the same model.
525
694
  */
526
695
  clone(): MarkdownCell;
696
+ private _headingsCache;
697
+ private _headingCollapsed;
698
+ private _headingCollapsedChanged;
527
699
  private _monitor;
528
700
  private _numberChildNodes;
529
- private _headingCollapsed;
530
- private _toggleCollapsedSignal;
701
+ private _prevText;
531
702
  private _renderer;
532
703
  private _rendermime;
533
704
  private _rendered;
534
- private _prevText;
535
- private _ready;
705
+ private _renderedChanged;
536
706
  private _showEditorForReadOnlyMarkdown;
537
707
  }
538
708
  /**