UNPKG

23 kBTypeScriptView Raw
1import { ISessionContext, ISessionContextDialogs } from '@jupyterlab/apputils';
2import { Cell } from '@jupyterlab/cells';
3import * as nbformat from '@jupyterlab/nbformat';
4import { KernelMessage } from '@jupyterlab/services';
5import { ITranslator } from '@jupyterlab/translation';
6import { ISignal } from '@lumino/signaling';
7import { Notebook, StaticNotebook } from './widget';
8export declare class KernelError extends Error {
9 /**
10 * Exception name
11 */
12 readonly errorName: string;
13 /**
14 * Exception value
15 */
16 readonly errorValue: string;
17 /**
18 * Traceback
19 */
20 readonly traceback: string[];
21 /**
22 * Construct the kernel error.
23 */
24 constructor(content: KernelMessage.IExecuteReplyMsg['content']);
25}
26/**
27 * A collection of actions that run against notebooks.
28 *
29 * #### Notes
30 * All of the actions are a no-op if there is no model on the notebook.
31 * The actions set the widget `mode` to `'command'` unless otherwise specified.
32 * The actions will preserve the selection on the notebook widget unless
33 * otherwise specified.
34 */
35export declare class NotebookActions {
36 /**
37 * A signal that emits whenever a cell completes execution.
38 */
39 static get executed(): ISignal<any, {
40 notebook: Notebook;
41 cell: Cell;
42 success: boolean;
43 error?: KernelError | null;
44 }>;
45 /**
46 * A signal that emits whenever a cell execution is scheduled.
47 */
48 static get executionScheduled(): ISignal<any, {
49 notebook: Notebook;
50 cell: Cell;
51 }>;
52 /**
53 * A signal that emits when one notebook's cells are all executed.
54 */
55 static get selectionExecuted(): ISignal<any, {
56 notebook: Notebook;
57 lastCell: Cell;
58 }>;
59 /**
60 * A private constructor for the `NotebookActions` class.
61 *
62 * #### Notes
63 * This class can never be instantiated. Its static member `executed` will be
64 * merged with the `NotebookActions` namespace. The reason it exists as a
65 * standalone class is because at run time, the `Private.executed` variable
66 * does not yet exist, so it needs to be referenced via a getter.
67 */
68 private constructor();
69}
70/**
71 * A namespace for `NotebookActions` static methods.
72 */
73export declare namespace NotebookActions {
74 /**
75 * Split the active cell into two or more cells.
76 *
77 * @param notebook The target notebook widget.
78 *
79 * #### Notes
80 * It will preserve the existing mode.
81 * The last cell will be activated if no selection is found.
82 * If text was selected, the cell containing the selection will
83 * be activated.
84 * The existing selection will be cleared.
85 * The activated cell will have focus and the cursor will
86 * remain in the initial position.
87 * The leading whitespace in the second cell will be removed.
88 * If there is no content, two empty cells will be created.
89 * Both cells will have the same type as the original cell.
90 * This action can be undone.
91 */
92 function splitCell(notebook: Notebook): void;
93 /**
94 * Merge the selected cells.
95 *
96 * @param notebook - The target notebook widget.
97 *
98 * @param mergeAbove - If only one cell is selected, indicates whether to merge it
99 * with the cell above (true) or below (false, default).
100 *
101 * #### Notes
102 * The widget mode will be preserved.
103 * If only one cell is selected and `mergeAbove` is true, the above cell will be selected.
104 * If only one cell is selected and `mergeAbove` is false, the below cell will be selected.
105 * If the active cell is a code cell, its outputs will be cleared.
106 * This action can be undone.
107 * The final cell will have the same type as the active cell.
108 * If the active cell is a markdown cell, it will be unrendered.
109 */
110 function mergeCells(notebook: Notebook, mergeAbove?: boolean): void;
111 /**
112 * Delete the selected cells.
113 *
114 * @param notebook - The target notebook widget.
115 *
116 * #### Notes
117 * The cell after the last selected cell will be activated.
118 * It will add a code cell if all cells are deleted.
119 * This action can be undone.
120 */
121 function deleteCells(notebook: Notebook): void;
122 /**
123 * Insert a new code cell above the active cell or in index 0 if the notebook is empty.
124 *
125 * @param notebook - The target notebook widget.
126 *
127 * #### Notes
128 * The widget mode will be preserved.
129 * This action can be undone.
130 * The existing selection will be cleared.
131 * The new cell will the active cell.
132 */
133 function insertAbove(notebook: Notebook): void;
134 /**
135 * Insert a new code cell below the active cell or in index 0 if the notebook is empty.
136 *
137 * @param notebook - The target notebook widget.
138 *
139 * #### Notes
140 * The widget mode will be preserved.
141 * This action can be undone.
142 * The existing selection will be cleared.
143 * The new cell will be the active cell.
144 */
145 function insertBelow(notebook: Notebook): void;
146 /**
147 * Move the selected cell(s) down.
148 *
149 * @param notebook = The target notebook widget.
150 */
151 function moveDown(notebook: Notebook): void;
152 /**
153 * Move the selected cell(s) up.
154 *
155 * @param notebook - The target notebook widget.
156 */
157 function moveUp(notebook: Notebook): void;
158 /**
159 * Change the selected cell type(s).
160 *
161 * @param notebook - The target notebook widget.
162 *
163 * @param value - The target cell type.
164 *
165 * #### Notes
166 * It should preserve the widget mode.
167 * This action can be undone.
168 * The existing selection will be cleared.
169 * Any cells converted to markdown will be unrendered.
170 */
171 function changeCellType(notebook: Notebook, value: nbformat.CellType): void;
172 /**
173 * Run the selected cell(s).
174 *
175 * @param notebook - The target notebook widget.
176 * @param sessionContext - The client session object.
177 * @param sessionDialogs - The session dialogs.
178 * @param translator - The application translator.
179 *
180 * #### Notes
181 * The last selected cell will be activated, but not scrolled into view.
182 * The existing selection will be cleared.
183 * An execution error will prevent the remaining code cells from executing.
184 * All markdown cells will be rendered.
185 */
186 function run(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
187 /**
188 * Run the selected cell(s) and advance to the next cell.
189 *
190 * @param notebook - The target notebook widget.
191 * @param sessionContext - The client session object.
192 * @param sessionDialogs - The session dialogs.
193 * @param translator - The application translator.
194 *
195 * #### Notes
196 * The existing selection will be cleared.
197 * The cell after the last selected cell will be activated and scrolled into view.
198 * An execution error will prevent the remaining code cells from executing.
199 * All markdown cells will be rendered.
200 * If the last selected cell is the last cell, a new code cell
201 * will be created in `'edit'` mode. The new cell creation can be undone.
202 */
203 function runAndAdvance(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
204 /**
205 * Run the selected cell(s) and insert a new code cell.
206 *
207 * @param notebook - The target notebook widget.
208 * @param sessionContext - The client session object.
209 * @param sessionDialogs - The session dialogs.
210 * @param translator - The application translator.
211 *
212 * #### Notes
213 * An execution error will prevent the remaining code cells from executing.
214 * All markdown cells will be rendered.
215 * The widget mode will be set to `'edit'` after running.
216 * The existing selection will be cleared.
217 * The cell insert can be undone.
218 * The new cell will be scrolled into view.
219 */
220 function runAndInsert(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
221 /**
222 * Run all of the cells in the notebook.
223 *
224 * @param notebook - The target notebook widget.
225 * @param sessionContext - The client session object.
226 * @param sessionDialogs - The session dialogs.
227 * @param translator - The application translator.
228 *
229 * #### Notes
230 * The existing selection will be cleared.
231 * An execution error will prevent the remaining code cells from executing.
232 * All markdown cells will be rendered.
233 * The last cell in the notebook will be activated and scrolled into view.
234 */
235 function runAll(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
236 function renderAllMarkdown(notebook: Notebook): Promise<boolean>;
237 /**
238 * Run all of the cells before the currently active cell (exclusive).
239 *
240 * @param notebook - The target notebook widget.
241 * @param sessionContext - The client session object.
242 * @param sessionDialogs - The session dialogs.
243 * @param translator - The application translator.
244 *
245 * #### Notes
246 * The existing selection will be cleared.
247 * An execution error will prevent the remaining code cells from executing.
248 * All markdown cells will be rendered.
249 * The currently active cell will remain selected.
250 */
251 function runAllAbove(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
252 /**
253 * Run all of the cells after the currently active cell (inclusive).
254 *
255 * @param notebook - The target notebook widget.
256 * @param sessionContext - The client session object.
257 * @param sessionDialogs - The session dialogs.
258 * @param translator - The application translator.
259 *
260 * #### Notes
261 * The existing selection will be cleared.
262 * An execution error will prevent the remaining code cells from executing.
263 * All markdown cells will be rendered.
264 * The last cell in the notebook will be activated and scrolled into view.
265 */
266 function runAllBelow(notebook: Notebook, sessionContext?: ISessionContext, sessionDialogs?: ISessionContextDialogs, translator?: ITranslator): Promise<boolean>;
267 /**
268 * Replaces the selection in the active cell of the notebook.
269 *
270 * @param notebook - The target notebook widget.
271 * @param text - The text to replace the selection.
272 */
273 function replaceSelection(notebook: Notebook, text: string): void;
274 /**
275 * Select the above the active cell.
276 *
277 * @param notebook - The target notebook widget.
278 *
279 * #### Notes
280 * The widget mode will be preserved.
281 * This is a no-op if the first cell is the active cell.
282 * This will skip any collapsed cells.
283 * The existing selection will be cleared.
284 */
285 function selectAbove(notebook: Notebook): void;
286 /**
287 * Select the cell below the active cell.
288 *
289 * @param notebook - The target notebook widget.
290 *
291 * #### Notes
292 * The widget mode will be preserved.
293 * This is a no-op if the last cell is the active cell.
294 * This will skip any collapsed cells.
295 * The existing selection will be cleared.
296 */
297 function selectBelow(notebook: Notebook): void;
298 /** Insert new heading of same level above active cell.
299 *
300 * @param notebook - The target notebook widget
301 */
302 function insertSameLevelHeadingAbove(notebook: Notebook): Promise<void>;
303 /** Insert new heading of same level at end of current section.
304 *
305 * @param notebook - The target notebook widget
306 */
307 function insertSameLevelHeadingBelow(notebook: Notebook): Promise<void>;
308 /**
309 * Select the heading above the active cell or, if already at heading, collapse it.
310 *
311 * @param notebook - The target notebook widget.
312 *
313 * #### Notes
314 * The widget mode will be preserved.
315 * This is a no-op if the active cell is the topmost heading in collapsed state
316 * The existing selection will be cleared.
317 */
318 function selectHeadingAboveOrCollapseHeading(notebook: Notebook): void;
319 /**
320 * Select the heading below the active cell or, if already at heading, expand it.
321 *
322 * @param notebook - The target notebook widget.
323 *
324 * #### Notes
325 * The widget mode will be preserved.
326 * This is a no-op if the active cell is the last heading in expanded state
327 * The existing selection will be cleared.
328 */
329 function selectHeadingBelowOrExpandHeading(notebook: Notebook): void;
330 /**
331 * Extend the selection to the cell above.
332 *
333 * @param notebook - The target notebook widget.
334 * @param toTop - If true, denotes selection to extend to the top.
335 *
336 * #### Notes
337 * This is a no-op if the first cell is the active cell.
338 * The new cell will be activated.
339 */
340 function extendSelectionAbove(notebook: Notebook, toTop?: boolean): void;
341 /**
342 * Extend the selection to the cell below.
343 *
344 * @param notebook - The target notebook widget.
345 * @param toBottom - If true, denotes selection to extend to the bottom.
346 *
347 * #### Notes
348 * This is a no-op if the last cell is the active cell.
349 * The new cell will be activated.
350 */
351 function extendSelectionBelow(notebook: Notebook, toBottom?: boolean): void;
352 /**
353 * Select all of the cells of the notebook.
354 *
355 * @param notebook - the target notebook widget.
356 */
357 function selectAll(notebook: Notebook): void;
358 /**
359 * Deselect all of the cells of the notebook.
360 *
361 * @param notebook - the target notebook widget.
362 */
363 function deselectAll(notebook: Notebook): void;
364 /**
365 * Copy the selected cell(s) data to a clipboard.
366 *
367 * @param notebook - The target notebook widget.
368 */
369 function copy(notebook: Notebook): void;
370 /**
371 * Cut the selected cell data to a clipboard.
372 *
373 * @param notebook - The target notebook widget.
374 *
375 * #### Notes
376 * This action can be undone.
377 * A new code cell is added if all cells are cut.
378 */
379 function cut(notebook: Notebook): void;
380 /**
381 * Paste cells from the application clipboard.
382 *
383 * @param notebook - The target notebook widget.
384 *
385 * @param mode - the mode of adding cells:
386 * 'below' (default) adds cells below the active cell,
387 * 'belowSelected' adds cells below all selected cells,
388 * 'above' adds cells above the active cell, and
389 * 'replace' removes the currently selected cells and adds cells in their place.
390 *
391 * #### Notes
392 * The last pasted cell becomes the active cell.
393 * This is a no-op if there is no cell data on the clipboard.
394 * This action can be undone.
395 */
396 function paste(notebook: Notebook, mode?: 'below' | 'belowSelected' | 'above' | 'replace'): void;
397 /**
398 * Duplicate selected cells in the notebook without using the application clipboard.
399 *
400 * @param notebook - The target notebook widget.
401 *
402 * @param mode - the mode of adding cells:
403 * 'below' (default) adds cells below the active cell,
404 * 'belowSelected' adds cells below all selected cells,
405 * 'above' adds cells above the active cell, and
406 * 'replace' removes the currently selected cells and adds cells in their place.
407 *
408 * #### Notes
409 * The last pasted cell becomes the active cell.
410 * This is a no-op if there is no cell data on the clipboard.
411 * This action can be undone.
412 */
413 function duplicate(notebook: Notebook, mode?: 'below' | 'belowSelected' | 'above' | 'replace'): void;
414 /**
415 * Undo a cell action.
416 *
417 * @param notebook - The target notebook widget.
418 *
419 * #### Notes
420 * This is a no-op if there are no cell actions to undo.
421 */
422 function undo(notebook: Notebook): void;
423 /**
424 * Redo a cell action.
425 *
426 * @param notebook - The target notebook widget.
427 *
428 * #### Notes
429 * This is a no-op if there are no cell actions to redo.
430 */
431 function redo(notebook: Notebook): void;
432 /**
433 * Toggle the line number of all cells.
434 *
435 * @param notebook - The target notebook widget.
436 *
437 * #### Notes
438 * The original state is based on the state of the active cell.
439 * The `mode` of the widget will be preserved.
440 */
441 function toggleAllLineNumbers(notebook: Notebook): void;
442 /**
443 * Clear the code outputs of the selected cells.
444 *
445 * @param notebook - The target notebook widget.
446 *
447 * #### Notes
448 * The widget `mode` will be preserved.
449 */
450 function clearOutputs(notebook: Notebook): void;
451 /**
452 * Clear all the code outputs on the widget.
453 *
454 * @param notebook - The target notebook widget.
455 *
456 * #### Notes
457 * The widget `mode` will be preserved.
458 */
459 function clearAllOutputs(notebook: Notebook): void;
460 /**
461 * Hide the code on selected code cells.
462 *
463 * @param notebook - The target notebook widget.
464 */
465 function hideCode(notebook: Notebook): void;
466 /**
467 * Show the code on selected code cells.
468 *
469 * @param notebook - The target notebook widget.
470 */
471 function showCode(notebook: Notebook): void;
472 /**
473 * Hide the code on all code cells.
474 *
475 * @param notebook - The target notebook widget.
476 */
477 function hideAllCode(notebook: Notebook): void;
478 /**
479 * Show the code on all code cells.
480 *
481 * @param widget - The target notebook widget.
482 */
483 function showAllCode(notebook: Notebook): void;
484 /**
485 * Hide the output on selected code cells.
486 *
487 * @param notebook - The target notebook widget.
488 */
489 function hideOutput(notebook: Notebook): void;
490 /**
491 * Show the output on selected code cells.
492 *
493 * @param notebook - The target notebook widget.
494 */
495 function showOutput(notebook: Notebook): void;
496 /**
497 * Hide the output on all code cells.
498 *
499 * @param notebook - The target notebook widget.
500 */
501 function hideAllOutputs(notebook: Notebook): void;
502 /**
503 * Render side-by-side.
504 *
505 * @param notebook - The target notebook widget.
506 */
507 function renderSideBySide(notebook: Notebook): void;
508 /**
509 * Render not side-by-side.
510 *
511 * @param notebook - The target notebook widget.
512 */
513 function renderDefault(notebook: Notebook): void;
514 /**
515 * Show the output on all code cells.
516 *
517 * @param notebook - The target notebook widget.
518 */
519 function showAllOutputs(notebook: Notebook): void;
520 /**
521 * Enable output scrolling for all selected cells.
522 *
523 * @param notebook - The target notebook widget.
524 */
525 function enableOutputScrolling(notebook: Notebook): void;
526 /**
527 * Disable output scrolling for all selected cells.
528 *
529 * @param notebook - The target notebook widget.
530 */
531 function disableOutputScrolling(notebook: Notebook): void;
532 /**
533 * Go to the last cell that is run or current if it is running.
534 *
535 * Note: This requires execution timing to be toggled on or this will have
536 * no effect.
537 *
538 * @param notebook - The target notebook widget.
539 */
540 function selectLastRunCell(notebook: Notebook): void;
541 /**
542 * Set the markdown header level.
543 *
544 * @param notebook - The target notebook widget.
545 *
546 * @param level - The header level.
547 *
548 * #### Notes
549 * All selected cells will be switched to markdown.
550 * The level will be clamped between 1 and 6.
551 * If there is an existing header, it will be replaced.
552 * There will always be one blank space after the header.
553 * The cells will be unrendered.
554 */
555 function setMarkdownHeader(notebook: Notebook, level: number): void;
556 /**
557 * Collapse all cells in given notebook.
558 *
559 * @param notebook - The target notebook widget.
560 */
561 function collapseAllHeadings(notebook: Notebook): any;
562 /**
563 * Un-collapse all cells in given notebook.
564 *
565 * @param notebook - The target notebook widget.
566 */
567 function expandAllHeadings(notebook: Notebook): any;
568 /**
569 * Finds the "parent" heading of the given cell and expands.
570 * Used for the case that a cell becomes active that is within a collapsed heading.
571 * @param cell - "Child" cell that has become the active cell
572 * @param notebook - The target notebook widget.
573 */
574 function expandParent(cell: Cell, notebook: Notebook): void;
575 /**
576 * Finds the next heading that isn't a child of the given markdown heading.
577 * @param cell - "Child" cell that has become the active cell
578 * @param notebook - The target notebook widget.
579 */
580 function findNextParentHeading(cell: Cell, notebook: Notebook): number;
581 /**
582 * Set the given cell and ** all "child" cells **
583 * to the given collapse / expand if cell is
584 * a markdown header.
585 *
586 * @param cell - The cell
587 * @param collapsing - Whether to collapse or expand the cell
588 * @param notebook - The target notebook widget.
589 */
590 function setHeadingCollapse(cell: Cell, collapsing: boolean, notebook: StaticNotebook): number;
591 /**
592 * Toggles the collapse state of the active cell of the given notebook
593 * and ** all of its "child" cells ** if the cell is a heading.
594 *
595 * @param notebook - The target notebook widget.
596 */
597 function toggleCurrentHeadingCollapse(notebook: Notebook): any;
598 /**
599 * If cell is a markdown heading, sets the headingCollapsed field,
600 * and otherwise hides the cell.
601 *
602 * @param cell - The cell to collapse / expand
603 * @param collapsing - Whether to collapse or expand the given cell
604 */
605 function setCellCollapse(cell: Cell, collapsing: boolean): any;
606 /**
607 * If given cell is a markdown heading, returns the heading level.
608 * If given cell is not markdown, returns 7 (there are only 6 levels of markdown headings)
609 *
610 * @param cell - The target cell widget.
611 */
612 function getHeadingInfo(cell: Cell): {
613 isHeading: boolean;
614 headingLevel: number;
615 collapsed?: boolean;
616 };
617 /**
618 * Trust the notebook after prompting the user.
619 *
620 * @param notebook - The target notebook widget.
621 *
622 * @returns a promise that resolves when the transaction is finished.
623 *
624 * #### Notes
625 * No dialog will be presented if the notebook is already trusted.
626 */
627 function trust(notebook: Notebook, translator?: ITranslator): Promise<void>;
628}