UNPKG

5.45 kBTypeScriptView Raw
1import { Cell, ICellModel } from '@jupyterlab/cells';
2import { IMarkdownParser, IRenderMime } from '@jupyterlab/rendermime';
3import { TableOfContents, TableOfContentsFactory, TableOfContentsModel } from '@jupyterlab/toc';
4import { NotebookPanel } from './panel';
5import { INotebookTracker } from './tokens';
6import { Notebook } from './widget';
7/**
8 * Cell running status
9 */
10export declare enum RunningStatus {
11 /**
12 * Cell is idle
13 */
14 Idle = -1,
15 /**
16 * Cell execution is scheduled
17 */
18 Scheduled = 0,
19 /**
20 * Cell is running
21 */
22 Running = 1
23}
24/**
25 * Interface describing a notebook cell heading.
26 */
27export interface INotebookHeading extends TableOfContents.IHeading {
28 /**
29 * Reference to a notebook cell.
30 */
31 cellRef: Cell;
32 /**
33 * Running status of the cells in the heading
34 */
35 isRunning: RunningStatus;
36 /**
37 * Index of the output containing the heading
38 */
39 outputIndex?: number;
40 /**
41 * Type of heading
42 */
43 type: Cell.HeadingType;
44}
45/**
46 * Table of content model for Notebook files.
47 */
48export declare class NotebookToCModel extends TableOfContentsModel<INotebookHeading, NotebookPanel> {
49 protected parser: IMarkdownParser | null;
50 protected sanitizer: IRenderMime.ISanitizer;
51 /**
52 * Constructor
53 *
54 * @param widget The widget to search in
55 * @param parser Markdown parser
56 * @param sanitizer Sanitizer
57 * @param configuration Default model configuration
58 */
59 constructor(widget: NotebookPanel, parser: IMarkdownParser | null, sanitizer: IRenderMime.ISanitizer, configuration?: TableOfContents.IConfig);
60 /**
61 * Type of document supported by the model.
62 *
63 * #### Notes
64 * A `data-document-type` attribute with this value will be set
65 * on the tree view `.jp-TableOfContents-content[data-document-type="..."]`
66 */
67 get documentType(): string;
68 /**
69 * Whether the model gets updated even if the table of contents panel
70 * is hidden or not.
71 */
72 protected get isAlwaysActive(): boolean;
73 /**
74 * List of configuration options supported by the model.
75 */
76 get supportedOptions(): (keyof TableOfContents.IConfig)[];
77 /**
78 * Get the headings of a given cell.
79 *
80 * @param cell Cell
81 * @returns The associated headings
82 */
83 getCellHeadings(cell: Cell): INotebookHeading[];
84 /**
85 * Dispose the object
86 */
87 dispose(): void;
88 /**
89 * Model configuration setter.
90 *
91 * @param c New configuration
92 */
93 setConfiguration(c: Partial<TableOfContents.IConfig>): void;
94 /**
95 * Callback on heading collapse.
96 *
97 * @param options.heading The heading to change state (all headings if not provided)
98 * @param options.collapsed The new collapsed status (toggle existing status if not provided)
99 */
100 toggleCollapse(options: {
101 heading?: INotebookHeading;
102 collapsed?: boolean;
103 }): void;
104 /**
105 * Produce the headings for a document.
106 *
107 * @returns The list of new headings or `null` if nothing needs to be updated.
108 */
109 protected getHeadings(): Promise<INotebookHeading[] | null>;
110 /**
111 * Read table of content configuration from notebook metadata.
112 *
113 * @returns ToC configuration from metadata
114 */
115 protected loadConfigurationFromMetadata(): Partial<TableOfContents.IConfig>;
116 protected onActiveCellChanged(notebook: Notebook, cell: Cell<ICellModel>): void;
117 protected onHeadingsChanged(): void;
118 protected onExecuted(_: unknown, args: {
119 notebook: Notebook;
120 cell: Cell;
121 }): void;
122 protected onExecutionScheduled(_: unknown, args: {
123 notebook: Notebook;
124 cell: Cell;
125 }): void;
126 protected onMetadataChanged(): void;
127 protected updateRunningStatus(headings: INotebookHeading[]): void;
128 /**
129 * Mapping between configuration options and notebook metadata.
130 *
131 * If it starts with `!`, the boolean value of the configuration option is
132 * opposite to the one stored in metadata.
133 * If it contains `/`, the metadata data is nested.
134 */
135 protected configMetadataMap: {
136 [k: keyof TableOfContents.IConfig]: string[];
137 };
138 private _runningCells;
139 private _cellToHeadingIndex;
140}
141/**
142 * Table of content model factory for Notebook files.
143 */
144export declare class NotebookToCFactory extends TableOfContentsFactory<NotebookPanel> {
145 protected parser: IMarkdownParser | null;
146 protected sanitizer: IRenderMime.ISanitizer;
147 /**
148 * Constructor
149 *
150 * @param tracker Widget tracker
151 * @param parser Markdown parser
152 * @param sanitizer Sanitizer
153 */
154 constructor(tracker: INotebookTracker, parser: IMarkdownParser | null, sanitizer: IRenderMime.ISanitizer);
155 /**
156 * Create a new table of contents model for the widget
157 *
158 * @param widget - widget
159 * @param configuration - Table of contents configuration
160 * @returns The table of contents model
161 */
162 protected _createNew(widget: NotebookPanel, configuration?: TableOfContents.IConfig): TableOfContentsModel<TableOfContents.IHeading, NotebookPanel>;
163}
164/**
165 * Get the element id for an heading
166 * @param heading Heading
167 * @param parser The markdownparser
168 * @returns The element id
169 */
170export declare function getIdForHeading(heading: INotebookHeading, parser: IRenderMime.IMarkdownParser): Promise<string | null>;