UNPKG

12.6 kBTypeScriptView Raw
1import { Cell } from '@jupyterlab/cells';
2import { CodeEditor, JSONEditor } from '@jupyterlab/codeeditor';
3import * as nbformat from '@jupyterlab/nbformat';
4import { ObservableJSON } from '@jupyterlab/observables';
5import { ITranslator } from '@jupyterlab/translation';
6import { ReadonlyPartialJSONValue } from '@lumino/coreutils';
7import { ConflatableMessage, Message } from '@lumino/messaging';
8import { Widget } from '@lumino/widgets';
9import { NotebookPanel } from './panel';
10import { INotebookTools, INotebookTracker } from './tokens';
11/**
12 * A widget that provides metadata tools.
13 */
14export declare class NotebookTools extends Widget implements INotebookTools {
15 /**
16 * Construct a new NotebookTools object.
17 */
18 constructor(options: NotebookTools.IOptions);
19 /**
20 * The active cell widget.
21 */
22 get activeCell(): Cell | null;
23 /**
24 * The currently selected cells.
25 */
26 get selectedCells(): Cell[];
27 /**
28 * The current notebook.
29 */
30 get activeNotebookPanel(): NotebookPanel | null;
31 /**
32 * Add a cell tool item.
33 */
34 addItem(options: NotebookTools.IAddOptions): void;
35 /**
36 * Handle a change to the notebook panel.
37 */
38 private _onActiveNotebookPanelChanged;
39 /**
40 * Handle a change to the active cell.
41 */
42 private _onActiveCellChanged;
43 /**
44 * Handle a change in the selection.
45 */
46 private _onSelectionChanged;
47 /**
48 * Handle a change in the active cell metadata.
49 */
50 private _onActiveNotebookPanelMetadataChanged;
51 /**
52 * Handle a change in the notebook model metadata.
53 */
54 private _onActiveCellMetadataChanged;
55 private _toolChildren;
56 translator: ITranslator;
57 private _trans;
58 private _commonTools;
59 private _advancedTools;
60 private _tracker;
61 private _prevActiveCell;
62 private _prevActiveNotebookModel;
63}
64/**
65 * The namespace for NotebookTools class statics.
66 */
67export declare namespace NotebookTools {
68 /**
69 * A type alias for a readonly partial JSON tuples `[option, value]`.
70 * `option` should be localized.
71 *
72 * Note: Partial here means that JSON object attributes can be `undefined`.
73 */
74 type ReadonlyPartialJSONOptionValueArray = [
75 ReadonlyPartialJSONValue | undefined,
76 ReadonlyPartialJSONValue
77 ][];
78 /**
79 * The options used to create a NotebookTools object.
80 */
81 interface IOptions {
82 /**
83 * The notebook tracker used by the notebook tools.
84 */
85 tracker: INotebookTracker;
86 /**
87 * Language translator.
88 */
89 translator?: ITranslator;
90 }
91 /**
92 * The options used to add an item to the notebook tools.
93 */
94 interface IAddOptions {
95 /**
96 * The tool to add to the notebook tools area.
97 */
98 tool: Tool;
99 /**
100 * The section to which the tool should be added.
101 */
102 section?: 'common' | 'advanced';
103 /**
104 * The rank order of the widget among its siblings.
105 */
106 rank?: number;
107 }
108 /**
109 * A singleton conflatable `'activenotebookpanel-changed'` message.
110 */
111 const ActiveNotebookPanelMessage: ConflatableMessage;
112 /**
113 * A singleton conflatable `'activecell-changed'` message.
114 */
115 const ActiveCellMessage: ConflatableMessage;
116 /**
117 * A singleton conflatable `'selection-changed'` message.
118 */
119 const SelectionMessage: ConflatableMessage;
120 /**
121 * The base notebook tool, meant to be subclassed.
122 */
123 class Tool extends Widget implements INotebookTools.ITool {
124 /**
125 * The notebook tools object.
126 */
127 notebookTools: INotebookTools;
128 dispose(): void;
129 /**
130 * Process a message sent to the widget.
131 *
132 * @param msg - The message sent to the widget.
133 */
134 processMessage(msg: Message): void;
135 /**
136 * Handle a change to the notebook panel.
137 *
138 * #### Notes
139 * The default implementation is a no-op.
140 */
141 protected onActiveNotebookPanelChanged(msg: Message): void;
142 /**
143 * Handle a change to the active cell.
144 *
145 * #### Notes
146 * The default implementation is a no-op.
147 */
148 protected onActiveCellChanged(msg: Message): void;
149 /**
150 * Handle a change to the selection.
151 *
152 * #### Notes
153 * The default implementation is a no-op.
154 */
155 protected onSelectionChanged(msg: Message): void;
156 /**
157 * Handle a change to the metadata of the active cell.
158 *
159 * #### Notes
160 * The default implementation is a no-op.
161 */
162 protected onActiveCellMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
163 /**
164 * Handle a change to the metadata of the active cell.
165 *
166 * #### Notes
167 * The default implementation is a no-op.
168 */
169 protected onActiveNotebookPanelMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
170 }
171 /**
172 * A cell tool displaying the active cell contents.
173 */
174 class ActiveCellTool extends Tool {
175 /**
176 * Construct a new active cell tool.
177 */
178 constructor();
179 /**
180 * Dispose of the resources used by the tool.
181 */
182 dispose(): void;
183 /**
184 * Handle a change to the active cell.
185 */
186 protected onActiveCellChanged(): void;
187 /**
188 * Handle a change to the notebook panel.
189 *
190 * #### Notes
191 * The default implementation is a no-op.
192 */
193 protected onActiveNotebookPanelChanged(msg: Message): void;
194 /**
195 * Handle a change to the current editor value.
196 */
197 private _onValueChanged;
198 /**
199 * Handle a change to the current editor mimetype.
200 */
201 private _onMimeTypeChanged;
202 private _model;
203 private _cellModel;
204 }
205 /**
206 * A raw metadata editor.
207 */
208 class MetadataEditorTool extends Tool {
209 /**
210 * Construct a new raw metadata tool.
211 */
212 constructor(options: MetadataEditorTool.IOptions);
213 /**
214 * The editor used by the tool.
215 */
216 get editor(): JSONEditor;
217 /**
218 * Handle a change to the notebook.
219 */
220 protected onActiveNotebookPanelChanged(msg: Message): void;
221 protected createEditor(): void;
222 private _editor;
223 private _editorLabel;
224 private _editorFactory;
225 }
226 /**
227 * The namespace for `MetadataEditorTool` static data.
228 */
229 namespace MetadataEditorTool {
230 /**
231 * The options used to initialize a metadata editor tool.
232 */
233 interface IOptions {
234 /**
235 * The editor factory used by the tool.
236 */
237 editorFactory: CodeEditor.Factory;
238 /**
239 * The label for the JSON editor
240 */
241 label?: string;
242 /**
243 * Initial collapse state, defaults to true.
244 */
245 collapsed?: boolean;
246 /**
247 * Language translator.
248 */
249 translator?: ITranslator;
250 }
251 }
252 /**
253 * A notebook metadata editor
254 */
255 class NotebookMetadataEditorTool extends MetadataEditorTool {
256 constructor(options: MetadataEditorTool.IOptions);
257 /**
258 * Handle a change to the notebook.
259 */
260 protected onActiveNotebookPanelChanged(msg: Message): void;
261 /**
262 * Handle a change to the notebook metadata.
263 */
264 protected onActiveNotebookPanelMetadataChanged(msg: Message): void;
265 private _update;
266 }
267 /**
268 * A cell metadata editor
269 */
270 class CellMetadataEditorTool extends MetadataEditorTool {
271 constructor(options: MetadataEditorTool.IOptions);
272 /**
273 * Handle a change to the active cell.
274 */
275 protected onActiveCellChanged(msg: Message): void;
276 /**
277 * Handle a change to the active cell metadata.
278 */
279 protected onActiveCellMetadataChanged(msg: Message): void;
280 private _update;
281 }
282 /**
283 * A cell tool that provides a selection for a given metadata key.
284 */
285 class KeySelector extends Tool {
286 /**
287 * Construct a new KeySelector.
288 */
289 constructor(options: KeySelector.IOptions);
290 /**
291 * The metadata key used by the selector.
292 */
293 readonly key: string;
294 /**
295 * The select node for the widget.
296 */
297 get selectNode(): HTMLSelectElement;
298 /**
299 * Handle the DOM events for the widget.
300 *
301 * @param event - The DOM event sent to the widget.
302 *
303 * #### Notes
304 * This method implements the DOM `EventListener` interface and is
305 * called in response to events on the notebook panel's node. It should
306 * not be called directly by user code.
307 */
308 handleEvent(event: Event): void;
309 /**
310 * Handle `after-attach` messages for the widget.
311 */
312 protected onAfterAttach(msg: Message): void;
313 /**
314 * Handle `before-detach` messages for the widget.
315 */
316 protected onBeforeDetach(msg: Message): void;
317 /**
318 * Handle a change to the active cell.
319 */
320 protected onActiveCellChanged(msg: Message): void;
321 /**
322 * Handle a change to the metadata of the active cell.
323 */
324 protected onActiveCellMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
325 /**
326 * Handle a change to the value.
327 */
328 protected onValueChanged(): void;
329 /**
330 * Get the value for the data.
331 */
332 private _getValue;
333 /**
334 * Set the value for the data.
335 */
336 private _setValue;
337 private _changeGuard;
338 private _validCellTypes;
339 private _getter;
340 private _setter;
341 private _default;
342 }
343 /**
344 * The namespace for `KeySelector` static data.
345 */
346 namespace KeySelector {
347 /**
348 * The options used to initialize a keyselector.
349 */
350 interface IOptions {
351 /**
352 * The metadata key of interest.
353 */
354 key: string;
355 /**
356 * The map of values to options.
357 *
358 * Value corresponds to the unique identifier.
359 * Option corresponds to the localizable value to display.
360 *
361 * See: `<option value="volvo">Volvo</option>`
362 *
363 * #### Notes
364 * If a value equals the default, choosing it may erase the key from the
365 * metadata.
366 */
367 optionValueArray: ReadonlyPartialJSONOptionValueArray;
368 /**
369 * The optional title of the selector - defaults to capitalized `key`.
370 */
371 title: string;
372 /**
373 * The optional valid cell types - defaults to all valid types.
374 */
375 validCellTypes?: nbformat.CellType[];
376 /**
377 * An optional value getter for the selector.
378 *
379 * @param cell - The currently active cell.
380 *
381 * @returns The appropriate value for the selector.
382 */
383 getter?: (cell: Cell) => ReadonlyPartialJSONValue | undefined;
384 /**
385 * An optional value setter for the selector.
386 *
387 * @param cell - The currently active cell.
388 *
389 * @param value - The value of the selector.
390 *
391 * #### Notes
392 * The setter should set the appropriate metadata value given the value of
393 * the selector.
394 */
395 setter?: (cell: Cell, value: ReadonlyPartialJSONValue | undefined) => void;
396 /**
397 * Default value for default setters and getters if value is not found.
398 */
399 default?: ReadonlyPartialJSONValue;
400 }
401 }
402 /**
403 * Create a slideshow selector.
404 */
405 function createSlideShowSelector(translator?: ITranslator): KeySelector;
406 /**
407 * Create an nbconvert selector.
408 */
409 function createNBConvertSelector(optionValueArray: ReadonlyPartialJSONOptionValueArray, translator?: ITranslator): KeySelector;
410}