UNPKG

12.1 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 current editor value.
189 */
190 private _onValueChanged;
191 /**
192 * Handle a change to the current editor mimetype.
193 */
194 private _onMimeTypeChanged;
195 private _model;
196 private _cellModel;
197 }
198 /**
199 * A raw metadata editor.
200 */
201 class MetadataEditorTool extends Tool {
202 /**
203 * Construct a new raw metadata tool.
204 */
205 constructor(options: MetadataEditorTool.IOptions);
206 /**
207 * The editor used by the tool.
208 */
209 readonly editor: JSONEditor;
210 }
211 /**
212 * The namespace for `MetadataEditorTool` static data.
213 */
214 namespace MetadataEditorTool {
215 /**
216 * The options used to initialize a metadata editor tool.
217 */
218 interface IOptions {
219 /**
220 * The editor factory used by the tool.
221 */
222 editorFactory: CodeEditor.Factory;
223 /**
224 * The label for the JSON editor
225 */
226 label?: string;
227 /**
228 * Initial collapse state, defaults to true.
229 */
230 collapsed?: boolean;
231 /**
232 * Language translator.
233 */
234 translator?: ITranslator;
235 }
236 }
237 /**
238 * A notebook metadata editor
239 */
240 class NotebookMetadataEditorTool extends MetadataEditorTool {
241 constructor(options: MetadataEditorTool.IOptions);
242 /**
243 * Handle a change to the notebook.
244 */
245 protected onActiveNotebookPanelChanged(msg: Message): void;
246 /**
247 * Handle a change to the notebook metadata.
248 */
249 protected onActiveNotebookPanelMetadataChanged(msg: Message): void;
250 private _update;
251 }
252 /**
253 * A cell metadata editor
254 */
255 class CellMetadataEditorTool extends MetadataEditorTool {
256 constructor(options: MetadataEditorTool.IOptions);
257 /**
258 * Handle a change to the active cell.
259 */
260 protected onActiveCellChanged(msg: Message): void;
261 /**
262 * Handle a change to the active cell metadata.
263 */
264 protected onActiveCellMetadataChanged(msg: Message): void;
265 private _update;
266 }
267 /**
268 * A cell tool that provides a selection for a given metadata key.
269 */
270 class KeySelector extends Tool {
271 /**
272 * Construct a new KeySelector.
273 */
274 constructor(options: KeySelector.IOptions);
275 /**
276 * The metadata key used by the selector.
277 */
278 readonly key: string;
279 /**
280 * The select node for the widget.
281 */
282 get selectNode(): HTMLSelectElement;
283 /**
284 * Handle the DOM events for the widget.
285 *
286 * @param event - The DOM event sent to the widget.
287 *
288 * #### Notes
289 * This method implements the DOM `EventListener` interface and is
290 * called in response to events on the notebook panel's node. It should
291 * not be called directly by user code.
292 */
293 handleEvent(event: Event): void;
294 /**
295 * Handle `after-attach` messages for the widget.
296 */
297 protected onAfterAttach(msg: Message): void;
298 /**
299 * Handle `before-detach` messages for the widget.
300 */
301 protected onBeforeDetach(msg: Message): void;
302 /**
303 * Handle a change to the active cell.
304 */
305 protected onActiveCellChanged(msg: Message): void;
306 /**
307 * Handle a change to the metadata of the active cell.
308 */
309 protected onActiveCellMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
310 /**
311 * Handle a change to the value.
312 */
313 protected onValueChanged(): void;
314 /**
315 * Get the value for the data.
316 */
317 private _getValue;
318 /**
319 * Set the value for the data.
320 */
321 private _setValue;
322 private _changeGuard;
323 private _validCellTypes;
324 private _getter;
325 private _setter;
326 private _default;
327 }
328 /**
329 * The namespace for `KeySelector` static data.
330 */
331 namespace KeySelector {
332 /**
333 * The options used to initialize a keyselector.
334 */
335 interface IOptions {
336 /**
337 * The metadata key of interest.
338 */
339 key: string;
340 /**
341 * The map of values to options.
342 *
343 * Value corresponds to the unique identifier.
344 * Option corresponds to the localizable value to display.
345 *
346 * See: `<option value="volvo">Volvo</option>`
347 *
348 * #### Notes
349 * If a value equals the default, choosing it may erase the key from the
350 * metadata.
351 */
352 optionValueArray: ReadonlyPartialJSONOptionValueArray;
353 /**
354 * The optional title of the selector - defaults to capitalized `key`.
355 */
356 title: string;
357 /**
358 * The optional valid cell types - defaults to all valid types.
359 */
360 validCellTypes?: nbformat.CellType[];
361 /**
362 * An optional value getter for the selector.
363 *
364 * @param cell - The currently active cell.
365 *
366 * @returns The appropriate value for the selector.
367 */
368 getter?: (cell: Cell) => ReadonlyPartialJSONValue | undefined;
369 /**
370 * An optional value setter for the selector.
371 *
372 * @param cell - The currently active cell.
373 *
374 * @param value - The value of the selector.
375 *
376 * #### Notes
377 * The setter should set the appropriate metadata value given the value of
378 * the selector.
379 */
380 setter?: (cell: Cell, value: ReadonlyPartialJSONValue | undefined) => void;
381 /**
382 * Default value for default setters and getters if value is not found.
383 */
384 default?: ReadonlyPartialJSONValue;
385 }
386 }
387 /**
388 * Create a slideshow selector.
389 */
390 function createSlideShowSelector(translator?: ITranslator): KeySelector;
391 /**
392 * Create an nbconvert selector.
393 */
394 function createNBConvertSelector(optionValueArray: ReadonlyPartialJSONOptionValueArray, translator?: ITranslator): KeySelector;
395}