UNPKG

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