@jupyterlab/cells 4.0.0-alpha.2 → 4.0.0-alpha.21

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.
Files changed (46) hide show
  1. package/lib/celldragutils.d.ts +1 -7
  2. package/lib/celldragutils.js +12 -13
  3. package/lib/celldragutils.js.map +1 -1
  4. package/lib/index.d.ts +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/inputarea.d.ts +9 -19
  8. package/lib/inputarea.js +16 -29
  9. package/lib/inputarea.js.map +1 -1
  10. package/lib/model.d.ts +121 -79
  11. package/lib/model.js +179 -392
  12. package/lib/model.js.map +1 -1
  13. package/lib/placeholder.d.ts +23 -19
  14. package/lib/placeholder.js +30 -35
  15. package/lib/placeholder.js.map +1 -1
  16. package/lib/resizeHandle.d.ts +0 -1
  17. package/lib/resizeHandle.js +9 -11
  18. package/lib/resizeHandle.js.map +1 -1
  19. package/lib/searchprovider.d.ts +31 -0
  20. package/lib/searchprovider.js +359 -0
  21. package/lib/searchprovider.js.map +1 -0
  22. package/lib/testutils.d.ts +22 -0
  23. package/lib/testutils.js +48 -0
  24. package/lib/testutils.js.map +1 -0
  25. package/lib/widget.d.ts +226 -42
  26. package/lib/widget.js +672 -270
  27. package/lib/widget.js.map +1 -1
  28. package/package.json +36 -33
  29. package/src/celldragutils.ts +214 -0
  30. package/src/collapser.tsx +150 -0
  31. package/src/headerfooter.ts +52 -0
  32. package/src/index.ts +17 -0
  33. package/src/inputarea.ts +292 -0
  34. package/src/model.ts +845 -0
  35. package/src/placeholder.ts +125 -0
  36. package/src/resizeHandle.ts +96 -0
  37. package/src/searchprovider.ts +436 -0
  38. package/src/testutils.ts +57 -0
  39. package/src/widget.ts +2290 -0
  40. package/style/collapser.css +5 -4
  41. package/style/headerfooter.css +3 -3
  42. package/style/index.css +4 -2
  43. package/style/index.js +4 -2
  44. package/style/inputarea.css +19 -17
  45. package/style/placeholder.css +1 -1
  46. package/style/widget.css +85 -7
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,15 +226,19 @@ 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>;
171
234
  /**
172
- * Whether to send an update request to the editor when it is shown.
235
+ * Editor extensions to be added.
173
236
  */
174
- updateEditorOnShow?: boolean;
237
+ editorExtensions?: Extension[];
238
+ /**
239
+ * Cell widget layout.
240
+ */
241
+ layout?: PanelLayout;
175
242
  /**
176
243
  * The maximum number of output items to display in cell output.
177
244
  */
@@ -185,6 +252,40 @@ export declare namespace Cell {
185
252
  */
186
253
  translator?: ITranslator;
187
254
  }
255
+ /**
256
+ * Cell heading
257
+ */
258
+ interface IHeading {
259
+ /**
260
+ * Heading text.
261
+ */
262
+ text: string;
263
+ /**
264
+ * HTML heading level.
265
+ */
266
+ level: number;
267
+ /**
268
+ * Index of the output containing the heading
269
+ */
270
+ outputIndex?: number;
271
+ /**
272
+ * Type of heading
273
+ */
274
+ type: HeadingType;
275
+ }
276
+ /**
277
+ * Type of headings
278
+ */
279
+ enum HeadingType {
280
+ /**
281
+ * Heading from HTML output
282
+ */
283
+ HTML = 0,
284
+ /**
285
+ * Heading from Markdown cell or Markdown output
286
+ */
287
+ Markdown = 1
288
+ }
188
289
  /**
189
290
  * The factory object for customizable cell children.
190
291
  *
@@ -213,7 +314,7 @@ export declare namespace Cell {
213
314
  /**
214
315
  * Create a content factory for a cell.
215
316
  */
216
- constructor(options?: ContentFactory.IOptions);
317
+ constructor(options: ContentFactory.IOptions);
217
318
  /**
218
319
  * The readonly editor factory that create code editors
219
320
  */
@@ -250,21 +351,43 @@ export declare namespace Cell {
250
351
  interface IOptions {
251
352
  /**
252
353
  * 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
354
  */
257
- editorFactory?: CodeEditor.Factory;
355
+ editorFactory: CodeEditor.Factory;
258
356
  }
259
357
  }
260
- /**
261
- * The default content factory for cells.
262
- */
263
- const defaultContentFactory: ContentFactory;
264
358
  }
265
359
  /** ****************************************************************************
266
360
  * CodeCell
267
361
  ******************************************************************************/
362
+ /**
363
+ * Code cell layout
364
+ *
365
+ * It will not detached the output area when the cell is detached.
366
+ */
367
+ export declare class CodeCellLayout extends PanelLayout {
368
+ /**
369
+ * A message handler invoked on a `'before-attach'` message.
370
+ *
371
+ * #### Notes
372
+ * The default implementation of this method forwards the message
373
+ * to all widgets. It assumes all widget nodes are attached to the
374
+ * parent widget node.
375
+ *
376
+ * This may be reimplemented by subclasses as needed.
377
+ */
378
+ protected onBeforeAttach(msg: Message): void;
379
+ /**
380
+ * A message handler invoked on an `'after-detach'` message.
381
+ *
382
+ * #### Notes
383
+ * The default implementation of this method forwards the message
384
+ * to all widgets. It assumes all widget nodes are attached to the
385
+ * parent widget node.
386
+ *
387
+ * This may be reimplemented by subclasses as needed.
388
+ */
389
+ protected onAfterDetach(msg: Message): void;
390
+ }
268
391
  /**
269
392
  * A widget for a code cell.
270
393
  */
@@ -273,6 +396,14 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
273
396
  * Construct a code cell widget.
274
397
  */
275
398
  constructor(options: CodeCell.IOptions);
399
+ /**
400
+ * Maximum number of outputs to display.
401
+ */
402
+ protected maxNumberOutputs: number | undefined;
403
+ /**
404
+ * Create children widgets.
405
+ */
406
+ protected initializeDOM(): void;
276
407
  /**
277
408
  * Initialize view state from model.
278
409
  *
@@ -281,6 +412,7 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
281
412
  * can be chained in the construction, like `new Foo().initializeState();`
282
413
  */
283
414
  initializeState(): this;
415
+ get headings(): Cell.IHeading[];
284
416
  /**
285
417
  * Get the output area for the cell.
286
418
  */
@@ -344,14 +476,19 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
344
476
  * Handle changes in the model.
345
477
  */
346
478
  protected onStateChanged(model: ICellModel, args: IChangedArgs<any>): void;
479
+ /**
480
+ * Callback on output changes
481
+ */
482
+ protected onOutputChanged(): void;
347
483
  /**
348
484
  * Handle changes in the metadata.
349
485
  */
350
- protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<JSONValue>): void;
486
+ protected onMetadataChanged(model: CellModel, args: IMapChange): void;
351
487
  /**
352
488
  * Handle changes in the number of outputs in the output area.
353
489
  */
354
490
  private _outputLengthHandler;
491
+ private _headingsCache;
355
492
  private _rendermime;
356
493
  private _outputHidden;
357
494
  private _outputsScrolled;
@@ -359,7 +496,6 @@ export declare class CodeCell extends Cell<ICodeCellModel> {
359
496
  private _outputPlaceholder;
360
497
  private _output;
361
498
  private _syncScrolled;
362
- private _savingMetadata;
363
499
  }
364
500
  /**
365
501
  * The namespace for the `CodeCell` class statics.
@@ -369,6 +505,10 @@ export declare namespace CodeCell {
369
505
  * An options object for initializing a base cell widget.
370
506
  */
371
507
  interface IOptions extends Cell.IOptions<ICodeCellModel> {
508
+ /**
509
+ * Code cell layout.
510
+ */
511
+ layout?: CodeCellLayout;
372
512
  /**
373
513
  * The mime renderer for the cell widget.
374
514
  */
@@ -395,6 +535,12 @@ export declare abstract class AttachmentsCell<T extends IAttachmentsCellModel> e
395
535
  * not be called directly by user code.
396
536
  */
397
537
  handleEvent(event: Event): void;
538
+ /**
539
+ * Get the editor options at initialization.
540
+ *
541
+ * @returns Editor options
542
+ */
543
+ protected getEditorOptions(): InputArea.IOptions['editorOptions'];
398
544
  /**
399
545
  * Modify the cell source to include a reference to the attachment.
400
546
  */
@@ -455,33 +601,61 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
455
601
  */
456
602
  constructor(options: MarkdownCell.IOptions);
457
603
  /**
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.
604
+ * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
463
605
  * Returns empty string if not a heading.
464
606
  */
465
607
  get headingInfo(): {
466
608
  text: string;
467
609
  level: number;
468
610
  };
611
+ get headings(): Cell.IHeading[];
612
+ /**
613
+ * Whether the heading is collapsed or not.
614
+ */
469
615
  get headingCollapsed(): boolean;
470
616
  set headingCollapsed(value: boolean);
617
+ /**
618
+ * Number of collapsed sub cells.
619
+ */
471
620
  get numberChildNodes(): number;
472
621
  set numberChildNodes(value: number);
473
- get toggleCollapsedSignal(): Signal<this, boolean>;
622
+ /**
623
+ * Signal emitted when the cell collapsed state changes.
624
+ */
625
+ get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
474
626
  /**
475
627
  * Whether the cell is rendered.
476
628
  */
477
629
  get rendered(): boolean;
478
630
  set rendered(value: boolean);
631
+ /**
632
+ * Signal emitted when the markdown cell rendered state changes
633
+ */
634
+ get renderedChanged(): ISignal<MarkdownCell, boolean>;
635
+ get showEditorForReadOnly(): boolean;
636
+ set showEditorForReadOnly(value: boolean);
637
+ /**
638
+ * Renderer
639
+ */
640
+ get renderer(): IRenderMime.IRenderer;
641
+ /**
642
+ * Dispose of the resources held by the widget.
643
+ */
644
+ dispose(): void;
645
+ /**
646
+ * Create children widgets.
647
+ */
648
+ protected initializeDOM(): void;
479
649
  protected maybeCreateCollapseButton(): void;
480
650
  /**
481
651
  * Create, update or remove the hidden cells button.
482
652
  * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
483
653
  */
484
654
  protected maybeCreateOrUpdateExpandButton(): void;
655
+ /**
656
+ * Callback on content changed
657
+ */
658
+ protected onContentChanged(): void;
485
659
  /**
486
660
  * Render the collapse button for heading cells,
487
661
  * and for collapsed heading cells render the "expand hidden cells"
@@ -513,15 +687,17 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
513
687
  * Clone the cell, using the same model.
514
688
  */
515
689
  clone(): MarkdownCell;
690
+ private _headingsCache;
691
+ private _headingCollapsed;
692
+ private _headingCollapsedChanged;
516
693
  private _monitor;
517
694
  private _numberChildNodes;
518
- private _headingCollapsed;
519
- private _toggleCollapsedSignal;
695
+ private _prevText;
520
696
  private _renderer;
521
697
  private _rendermime;
522
698
  private _rendered;
523
- private _prevText;
524
- private _ready;
699
+ private _renderedChanged;
700
+ private _showEditorForReadOnlyMarkdown;
525
701
  }
526
702
  /**
527
703
  * The namespace for the `CodeCell` class statics.
@@ -535,7 +711,15 @@ export declare namespace MarkdownCell {
535
711
  * The mime renderer for the cell widget.
536
712
  */
537
713
  rendermime: IRenderMimeRegistry;
714
+ /**
715
+ * Show editor for read-only Markdown cells.
716
+ */
717
+ showEditorForReadOnlyMarkdown?: boolean;
538
718
  }
719
+ /**
720
+ * Default value for showEditorForReadOnlyMarkdown.
721
+ */
722
+ const defaultShowEditorForReadOnlyMarkdown = true;
539
723
  }
540
724
  /** ****************************************************************************
541
725
  * RawCell