@jupyterlab/cells 4.0.0-alpha.8 → 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
  ******************************************************************************/
@@ -37,18 +37,45 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
37
37
  * The content factory used by the widget.
38
38
  */
39
39
  readonly contentFactory: Cell.IContentFactory;
40
+ /**
41
+ * Signal to indicate that widget has changed visibly (in size, in type, etc)
42
+ */
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);
40
59
  /**
41
60
  * Get the prompt node used by the cell.
42
61
  */
43
- get promptNode(): HTMLElement;
62
+ get promptNode(): HTMLElement | null;
44
63
  /**
45
64
  * Get the CodeEditorWrapper used by the cell.
46
65
  */
47
- get editorWidget(): CodeEditorWrapper;
66
+ get editorWidget(): CodeEditorWrapper | null;
48
67
  /**
49
68
  * Get the CodeEditor used by the cell.
50
69
  */
51
- 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[];
52
79
  /**
53
80
  * Get the model used by the cell.
54
81
  */
@@ -56,12 +83,20 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
56
83
  /**
57
84
  * Get the input area for the cell.
58
85
  */
59
- get inputArea(): InputArea;
86
+ get inputArea(): InputArea | null;
60
87
  /**
61
88
  * The read only state of the cell.
62
89
  */
63
90
  get readOnly(): boolean;
64
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;
65
100
  /**
66
101
  * Save view editable state to model
67
102
  */
@@ -118,6 +153,26 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
118
153
  * Dispose of the resources held by the widget.
119
154
  */
120
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;
121
176
  /**
122
177
  * Handle `after-attach` messages.
123
178
  */
@@ -127,9 +182,9 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
127
182
  */
128
183
  protected onActivateRequest(msg: Message): void;
129
184
  /**
130
- * Handle `fit-request` messages.
185
+ * Handle `resize` messages.
131
186
  */
132
- protected onFitRequest(msg: Message): void;
187
+ protected onResize(msg: Widget.ResizeMessage): void;
133
188
  /**
134
189
  * Handle `update-request` messages.
135
190
  */
@@ -137,14 +192,22 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
137
192
  /**
138
193
  * Handle changes in the metadata.
139
194
  */
140
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
195
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
196
+ protected prompt: string;
141
197
  protected translator: ITranslator;
142
- private _readOnly;
143
- private _model;
144
- private _inputHidden;
198
+ protected _displayChanged: Signal<this, void>;
199
+ private _editorConfig;
145
200
  private _input;
201
+ private _inputHidden;
146
202
  private _inputWrapper;
147
203
  private _inputPlaceholder;
204
+ private _inViewport;
205
+ private _inViewportChanged;
206
+ private _model;
207
+ private _placeholder;
208
+ private _readOnly;
209
+ private _ready;
210
+ private _resizeDebouncer;
148
211
  private _syncCollapse;
149
212
  private _syncEditable;
150
213
  }
@@ -163,19 +226,27 @@ export declare namespace Cell {
163
226
  /**
164
227
  * The factory object for customizable cell children.
165
228
  */
166
- contentFactory?: IContentFactory;
229
+ contentFactory: IContentFactory;
167
230
  /**
168
231
  * The configuration options for the text editor widget.
169
232
  */
170
- editorConfig?: Partial<CodeEditor.IConfig>;
233
+ editorConfig?: Record<string, any>;
234
+ /**
235
+ * Editor extensions to be added.
236
+ */
237
+ editorExtensions?: Extension[];
171
238
  /**
172
- * Whether to send an update request to the editor when it is shown.
239
+ * Cell widget layout.
173
240
  */
174
- updateEditorOnShow?: boolean;
241
+ layout?: PanelLayout;
175
242
  /**
176
243
  * The maximum number of output items to display in cell output.
177
244
  */
178
245
  maxNumberOutputs?: number;
246
+ /**
247
+ * Whether to split stdin line history by kernel session or keep globally accessible.
248
+ */
249
+ inputHistoryScope?: 'global' | 'session';
179
250
  /**
180
251
  * Whether this cell is a placeholder for future rendering.
181
252
  */
@@ -185,6 +256,40 @@ export declare namespace Cell {
185
256
  */
186
257
  translator?: ITranslator;
187
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
+ }
188
293
  /**
189
294
  * The factory object for customizable cell children.
190
295
  *
@@ -213,7 +318,7 @@ export declare namespace Cell {
213
318
  /**
214
319
  * Create a content factory for a cell.
215
320
  */
216
- constructor(options?: ContentFactory.IOptions);
321
+ constructor(options: ContentFactory.IOptions);
217
322
  /**
218
323
  * The readonly editor factory that create code editors
219
324
  */
@@ -250,21 +355,43 @@ export declare namespace Cell {
250
355
  interface IOptions {
251
356
  /**
252
357
  * The editor factory used by the content factory.
253
- *
254
- * If this is not passed, a default CodeMirror editor factory
255
- * will be used.
256
358
  */
257
- editorFactory?: CodeEditor.Factory;
359
+ editorFactory: CodeEditor.Factory;
258
360
  }
259
361
  }
260
- /**
261
- * The default content factory for cells.
262
- */
263
- const defaultContentFactory: ContentFactory;
264
362
  }
265
363
  /** ****************************************************************************
266
364
  * CodeCell
267
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
+ }
268
395
  /**
269
396
  * A widget for a code cell.
270
397
  */
@@ -273,6 +400,14 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
273
400
  * Construct a code cell widget.
274
401
  */
275
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;
276
411
  /**
277
412
  * Initialize view state from model.
278
413
  *
@@ -281,6 +416,7 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
281
416
  * can be chained in the construction, like `new Foo().initializeState();`
282
417
  */
283
418
  initializeState(): this;
419
+ get headings(): Cell.IHeading[];
284
420
  /**
285
421
  * Get the output area for the cell.
286
422
  */
@@ -344,14 +480,19 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
344
480
  * Handle changes in the model.
345
481
  */
346
482
  protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
483
+ /**
484
+ * Callback on output changes
485
+ */
486
+ protected onOutputChanged(): void;
347
487
  /**
348
488
  * Handle changes in the metadata.
349
489
  */
350
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<JSONValue>): void;
490
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
351
491
  /**
352
492
  * Handle changes in the number of outputs in the output area.
353
493
  */
354
494
  private _outputLengthHandler;
495
+ private _headingsCache;
355
496
  private _rendermime;
356
497
  private _outputHidden;
357
498
  private _outputsScrolled;
@@ -359,7 +500,6 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
359
500
  private _outputPlaceholder;
360
501
  private _output;
361
502
  private _syncScrolled;
362
- private _savingMetadata;
363
503
  }
364
504
  /**
365
505
  * The namespace for the `CodeCell` class statics.
@@ -369,6 +509,10 @@ export declare namespace CodeCell {
369
509
  * An options object for initializing a base cell widget.
370
510
  */
371
511
  interface IOptions extends Cell.IOptions<ICodeCellModel> {
512
+ /**
513
+ * Code cell layout.
514
+ */
515
+ layout?: CodeCellLayout;
372
516
  /**
373
517
  * The mime renderer for the cell widget.
374
518
  */
@@ -395,6 +539,12 @@ export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> e
395
539
  * not be called directly by user code.
396
540
  */
397
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'];
398
548
  /**
399
549
  * Modify the cell source to include a reference to the attachment.
400
550
  */
@@ -455,35 +605,61 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
455
605
  */
456
606
  constructor(options: MarkdownCell.IOptions);
457
607
  /**
458
- * A promise that resolves when the widget renders for the first time.
459
- */
460
- get ready(): Promise<void>;
461
- /**
462
- * 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.
463
609
  * Returns empty string if not a heading.
464
610
  */
465
611
  get headingInfo(): {
466
612
  text: string;
467
613
  level: number;
468
614
  };
615
+ get headings(): Cell.IHeading[];
616
+ /**
617
+ * Whether the heading is collapsed or not.
618
+ */
469
619
  get headingCollapsed(): boolean;
470
620
  set headingCollapsed(value: boolean);
621
+ /**
622
+ * Number of collapsed sub cells.
623
+ */
471
624
  get numberChildNodes(): number;
472
625
  set numberChildNodes(value: number);
473
- get toggleCollapsedSignal(): Signal<this, boolean>;
626
+ /**
627
+ * Signal emitted when the cell collapsed state changes.
628
+ */
629
+ get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
474
630
  /**
475
631
  * Whether the cell is rendered.
476
632
  */
477
633
  get rendered(): boolean;
478
634
  set rendered(value: boolean);
635
+ /**
636
+ * Signal emitted when the markdown cell rendered state changes
637
+ */
638
+ get renderedChanged(): ISignal<MarkdownCell, boolean>;
479
639
  get showEditorForReadOnly(): boolean;
480
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;
481
653
  protected maybeCreateCollapseButton(): void;
482
654
  /**
483
655
  * Create, update or remove the hidden cells button.
484
656
  * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
485
657
  */
486
658
  protected maybeCreateOrUpdateExpandButton(): void;
659
+ /**
660
+ * Callback on content changed
661
+ */
662
+ protected onContentChanged(): void;
487
663
  /**
488
664
  * Render the collapse button for heading cells,
489
665
  * and for collapsed heading cells render the "expand hidden cells"
@@ -515,15 +691,16 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
515
691
  * Clone the cell, using the same model.
516
692
  */
517
693
  clone(): MarkdownCell;
694
+ private _headingsCache;
695
+ private _headingCollapsed;
696
+ private _headingCollapsedChanged;
518
697
  private _monitor;
519
698
  private _numberChildNodes;
520
- private _headingCollapsed;
521
- private _toggleCollapsedSignal;
699
+ private _prevText;
522
700
  private _renderer;
523
701
  private _rendermime;
524
702
  private _rendered;
525
- private _prevText;
526
- private _ready;
703
+ private _renderedChanged;
527
704
  private _showEditorForReadOnlyMarkdown;
528
705
  }
529
706
  /**