UNPKG

7.62 kBTypeScriptView Raw
1import { Cell } from '@jupyterlab/cells';
2import { CodeEditor, JSONEditor } from '@jupyterlab/codeeditor';
3import { ObservableJSON } from '@jupyterlab/observables';
4import { ITranslator } from '@jupyterlab/translation';
5import { ReadonlyPartialJSONValue } from '@lumino/coreutils';
6import { ConflatableMessage, Message } from '@lumino/messaging';
7import { Widget } from '@lumino/widgets';
8import { NotebookPanel } from './panel';
9import { INotebookTools, INotebookTracker } from './tokens';
10declare class RankedPanel<T extends Widget = Widget> extends Widget {
11 constructor();
12 addWidget(widget: Widget, rank: number): void;
13 /**
14 * Handle the removal of a child
15 *
16 */
17 protected onChildRemoved(msg: Widget.ChildMessage): void;
18 private _items;
19}
20/**
21 * A widget that provides metadata tools.
22 */
23export declare class NotebookTools extends Widget implements INotebookTools {
24 /**
25 * Construct a new NotebookTools object.
26 */
27 constructor(options: NotebookTools.IOptions);
28 /**
29 * The active cell widget.
30 */
31 get activeCell(): Cell | null;
32 /**
33 * The currently selected cells.
34 */
35 get selectedCells(): Cell[];
36 /**
37 * The current notebook.
38 */
39 get activeNotebookPanel(): NotebookPanel | null;
40 /**
41 * Add a cell tool item.
42 */
43 addItem(options: NotebookTools.IAddOptions): void;
44 addSection(options: NotebookTools.IAddSectionOptions): void;
45 /**
46 * Handle a change to the notebook panel.
47 */
48 private _onActiveNotebookPanelChanged;
49 /**
50 * Handle a change to the active cell.
51 */
52 private _onActiveCellChanged;
53 /**
54 * Handle a change in the selection.
55 */
56 private _onSelectionChanged;
57 /**
58 * Handle a change in the active cell metadata.
59 */
60 private _onActiveNotebookPanelMetadataChanged;
61 /**
62 * Handle a change in the notebook model metadata.
63 */
64 private _onActiveCellMetadataChanged;
65 private _toolChildren;
66 translator: ITranslator;
67 private _tools;
68 private _tracker;
69 private _prevActiveCell;
70 private _prevActiveNotebookModel;
71}
72/**
73 * The namespace for NotebookTools class statics.
74 */
75export declare namespace NotebookTools {
76 /**
77 * A type alias for a readonly partial JSON tuples `[option, value]`.
78 * `option` should be localized.
79 *
80 * Note: Partial here means that JSON object attributes can be `undefined`.
81 */
82 type ReadonlyPartialJSONOptionValueArray = [
83 ReadonlyPartialJSONValue | undefined,
84 ReadonlyPartialJSONValue
85 ][];
86 /**
87 * Interface for an extended panel section.
88 */
89 interface IToolPanel {
90 /**
91 * The name of the section.
92 */
93 section: string;
94 /**
95 * The associated panel, only one for a section.
96 */
97 panel: RankedPanel<NotebookTools.Tool>;
98 /**
99 * The rank of the section on the notebooktools panel.
100 */
101 rank?: number | null;
102 }
103 /**
104 * The options used to create a NotebookTools object.
105 */
106 interface IOptions {
107 /**
108 * The notebook tracker used by the notebook tools.
109 */
110 tracker: INotebookTracker;
111 /**
112 * Language translator.
113 */
114 translator?: ITranslator;
115 }
116 /**
117 * The options used to add an item to the notebook tools.
118 */
119 interface IAddOptions {
120 /**
121 * The tool to add to the notebook tools area.
122 */
123 tool: INotebookTools.ITool;
124 /**
125 * The section to which the tool should be added.
126 */
127 section: string;
128 /**
129 * The rank order of the widget among its siblings.
130 */
131 rank?: number;
132 }
133 /**
134 * The options used to add a section to the notebook tools.
135 */
136 interface IAddSectionOptions {
137 /**
138 * The name of the new section.
139 */
140 sectionName: string;
141 /**
142 * The tool to add to the notebook tools area.
143 */
144 tool?: INotebookTools.ITool;
145 /**
146 * The label of the new section.
147 */
148 label?: string;
149 /**
150 * The rank order of the section among its siblings.
151 */
152 rank?: number;
153 }
154 /**
155 * A singleton conflatable `'activenotebookpanel-changed'` message.
156 */
157 const ActiveNotebookPanelMessage: ConflatableMessage;
158 /**
159 * A singleton conflatable `'activecell-changed'` message.
160 */
161 const ActiveCellMessage: ConflatableMessage;
162 /**
163 * A singleton conflatable `'selection-changed'` message.
164 */
165 const SelectionMessage: ConflatableMessage;
166 /**
167 * The base notebook tool, meant to be subclassed.
168 */
169 class Tool extends Widget implements INotebookTools.ITool {
170 /**
171 * The notebook tools object.
172 */
173 notebookTools: INotebookTools;
174 dispose(): void;
175 /**
176 * Process a message sent to the widget.
177 *
178 * @param msg - The message sent to the widget.
179 */
180 processMessage(msg: Message): void;
181 /**
182 * Handle a change to the notebook panel.
183 *
184 * #### Notes
185 * The default implementation is a no-op.
186 */
187 protected onActiveNotebookPanelChanged(msg: Message): void;
188 /**
189 * Handle a change to the active cell.
190 *
191 * #### Notes
192 * The default implementation is a no-op.
193 */
194 protected onActiveCellChanged(msg: Message): void;
195 /**
196 * Handle a change to the selection.
197 *
198 * #### Notes
199 * The default implementation is a no-op.
200 */
201 protected onSelectionChanged(msg: Message): void;
202 /**
203 * Handle a change to the metadata of the active cell.
204 *
205 * #### Notes
206 * The default implementation is a no-op.
207 */
208 protected onActiveCellMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
209 /**
210 * Handle a change to the metadata of the active cell.
211 *
212 * #### Notes
213 * The default implementation is a no-op.
214 */
215 protected onActiveNotebookPanelMetadataChanged(msg: ObservableJSON.ChangeMessage): void;
216 }
217 /**
218 * A raw metadata editor.
219 */
220 class MetadataEditorTool extends Tool {
221 /**
222 * Construct a new raw metadata tool.
223 */
224 constructor(options: MetadataEditorTool.IOptions);
225 /**
226 * The editor used by the tool.
227 */
228 get editor(): JSONEditor;
229 /**
230 * Handle a change to the notebook.
231 */
232 protected onActiveNotebookPanelChanged(msg: Message): void;
233 protected createEditor(): void;
234 private _editor;
235 private _editorLabel;
236 private _editorFactory;
237 }
238 /**
239 * The namespace for `MetadataEditorTool` static data.
240 */
241 namespace MetadataEditorTool {
242 /**
243 * The options used to initialize a metadata editor tool.
244 */
245 interface IOptions {
246 /**
247 * The editor factory used by the tool.
248 */
249 editorFactory: CodeEditor.Factory;
250 /**
251 * The label for the JSON editor
252 */
253 label?: string;
254 /**
255 * Initial collapse state, defaults to true.
256 */
257 collapsed?: boolean;
258 /**
259 * Language translator.
260 */
261 translator?: ITranslator;
262 }
263 }
264}
265export {};