1 | import { CommandLinker } from '@jupyterlab/apputils';
|
2 | import { DocumentRegistry } from '@jupyterlab/docregistry';
|
3 | import { ServiceManager } from '@jupyterlab/services';
|
4 | import { ContextMenuSvg } from '@jupyterlab/ui-components';
|
5 | import { Application, IPlugin } from '@lumino/application';
|
6 | import { Token } from '@lumino/coreutils';
|
7 | import { ISignal } from '@lumino/signaling';
|
8 | import { FocusTracker, Widget } from '@lumino/widgets';
|
9 | /**
|
10 | * The type for all JupyterFrontEnd application plugins.
|
11 | *
|
12 | * @typeparam T - The type that the plugin `provides` upon being activated.
|
13 | *
|
14 | * @typeparam U - The type of the application shell.
|
15 | *
|
16 | * @typeparam V - The type that defines the application formats.
|
17 | */
|
18 | export type JupyterFrontEndPlugin<T, U extends JupyterFrontEnd.IShell = JupyterFrontEnd.IShell, V extends string = 'desktop' | 'mobile'> = IPlugin<JupyterFrontEnd<U, V>, T>;
|
19 | /**
|
20 | * The base Jupyter front-end application class.
|
21 | *
|
22 | * @typeparam `T` - The `shell` type. Defaults to `JupyterFrontEnd.IShell`.
|
23 | *
|
24 | * @typeparam `U` - The type for supported format names. Defaults to `string`.
|
25 | *
|
26 | * #### Notes
|
27 | * This type is useful as a generic application against which front-end plugins
|
28 | * can be authored. It inherits from the Lumino `Application`.
|
29 | */
|
30 | export declare abstract class JupyterFrontEnd<T extends JupyterFrontEnd.IShell = JupyterFrontEnd.IShell, U extends string = 'desktop' | 'mobile'> extends Application<T> {
|
31 | /**
|
32 | * Construct a new JupyterFrontEnd object.
|
33 | */
|
34 | constructor(options: JupyterFrontEnd.IOptions<T>);
|
35 | /**
|
36 | * The name of this Jupyter front-end application.
|
37 | */
|
38 | abstract readonly name: string;
|
39 | /**
|
40 | * A namespace/prefix plugins may use to denote their provenance.
|
41 | */
|
42 | abstract readonly namespace: string;
|
43 | /**
|
44 | * The version of this Jupyter front-end application.
|
45 | */
|
46 | abstract readonly version: string;
|
47 | /**
|
48 | * The command linker used by the application.
|
49 | */
|
50 | readonly commandLinker: CommandLinker;
|
51 | /**
|
52 | * The application context menu.
|
53 | */
|
54 | readonly contextMenu: ContextMenuSvg;
|
55 | /**
|
56 | * The document registry instance used by the application.
|
57 | */
|
58 | readonly docRegistry: DocumentRegistry;
|
59 | /**
|
60 | * Promise that resolves when state is first restored.
|
61 | */
|
62 | readonly restored: Promise<void>;
|
63 | /**
|
64 | * The service manager used by the application.
|
65 | */
|
66 | readonly serviceManager: ServiceManager.IManager;
|
67 | /**
|
68 | * The application form factor, e.g., `desktop` or `mobile`.
|
69 | */
|
70 | get format(): U;
|
71 | set format(format: U);
|
72 | /**
|
73 | * A signal that emits when the application form factor changes.
|
74 | */
|
75 | get formatChanged(): ISignal<this, U>;
|
76 | /**
|
77 | * Walks up the DOM hierarchy of the target of the active `contextmenu`
|
78 | * event, testing each HTMLElement ancestor for a user-supplied function. This can
|
79 | * be used to find an HTMLElement on which to operate, given a context menu click.
|
80 | *
|
81 | * @param fn - a function that takes an `HTMLElement` and returns a
|
82 | * boolean for whether it is the element the requester is seeking.
|
83 | *
|
84 | * @returns an HTMLElement or undefined, if none is found.
|
85 | */
|
86 | contextMenuHitTest(fn: (node: HTMLElement) => boolean): HTMLElement | undefined;
|
87 | /**
|
88 | * A method invoked on a document `'contextmenu'` event.
|
89 | */
|
90 | protected evtContextMenu(event: MouseEvent): void;
|
91 | private _contextMenuEvent;
|
92 | private _format;
|
93 | private _formatChanged;
|
94 | }
|
95 | /**
|
96 | * The namespace for `JupyterFrontEnd` class statics.
|
97 | */
|
98 | export declare namespace JupyterFrontEnd {
|
99 | /**
|
100 | * The options used to initialize a JupyterFrontEnd.
|
101 | */
|
102 | interface IOptions<T extends IShell = IShell, U = any> extends Application.IOptions<T> {
|
103 | /**
|
104 | * The document registry instance used by the application.
|
105 | */
|
106 | docRegistry?: DocumentRegistry;
|
107 | /**
|
108 | * The command linker used by the application.
|
109 | */
|
110 | commandLinker?: CommandLinker;
|
111 | /**
|
112 | * The service manager used by the application.
|
113 | */
|
114 | serviceManager?: ServiceManager.IManager;
|
115 | /**
|
116 | * Promise that resolves when state is first restored, returning layout
|
117 | * description.
|
118 | */
|
119 | restored?: Promise<U>;
|
120 | }
|
121 | /**
|
122 | * A minimal shell type for Jupyter front-end applications.
|
123 | */
|
124 | interface IShell extends Widget {
|
125 | /**
|
126 | * Activates a widget inside the application shell.
|
127 | *
|
128 | * @param id - The ID of the widget being activated.
|
129 | */
|
130 | activateById(id: string): void;
|
131 | /**
|
132 | * Add a widget to the application shell.
|
133 | *
|
134 | * @param widget - The widget being added.
|
135 | *
|
136 | * @param area - Optional region in the shell into which the widget should
|
137 | * be added.
|
138 | *
|
139 | * @param options - Optional flags the shell might use when opening the
|
140 | * widget, as defined in the `DocumentRegistry`.
|
141 | */
|
142 | add(widget: Widget, area?: string, options?: DocumentRegistry.IOpenOptions): void;
|
143 | /**
|
144 | * The focused widget in the application shell.
|
145 | *
|
146 | * #### Notes
|
147 | * Different shell implementations have latitude to decide what "current"
|
148 | * or "focused" mean, depending on their user interface characteristics.
|
149 | */
|
150 | readonly currentWidget: Widget | null;
|
151 | /**
|
152 | * A signal emitted when the focused widget in the application shell changes.
|
153 | *
|
154 | * ### Notes
|
155 | * Shells may not always have a {@link currentWidget} or it may not change.
|
156 | * Therefore implementing this signal is only expected for shells with the ability
|
157 | * to switch between active widgets.
|
158 | *
|
159 | * Although the signal argument type references a focus tracker, the shell
|
160 | * current widget may not be the one focused as its definition is an implementation
|
161 | * detail.
|
162 | */
|
163 | readonly currentChanged?: ISignal<IShell, FocusTracker.IChangedArgs<Widget>>;
|
164 | /**
|
165 | * Returns an iterator for the widgets inside the application shell.
|
166 | *
|
167 | * @param area - Optional regions in the shell whose widgets are iterated.
|
168 | */
|
169 | widgets(area?: string): IterableIterator<Widget>;
|
170 | }
|
171 | /**
|
172 | * Is JupyterLab in document mode?
|
173 | *
|
174 | * @param path - Full URL of JupyterLab
|
175 | * @param paths - The current IPaths object hydrated from PageConfig.
|
176 | */
|
177 | function inDocMode(path: string, paths: IPaths): boolean;
|
178 | /**
|
179 | * The application paths dictionary token.
|
180 | */
|
181 | const IPaths: Token<IPaths>;
|
182 | /**
|
183 | * An interface for URL and directory paths used by a Jupyter front-end.
|
184 | */
|
185 | interface IPaths {
|
186 | /**
|
187 | * The urls used by the application.
|
188 | */
|
189 | readonly urls: {
|
190 | readonly base: string;
|
191 | readonly notFound?: string;
|
192 | readonly app: string;
|
193 | readonly doc: string;
|
194 | readonly static: string;
|
195 | readonly settings: string;
|
196 | readonly themes: string;
|
197 | readonly translations: string;
|
198 | readonly hubPrefix?: string;
|
199 | readonly hubHost?: string;
|
200 | readonly hubUser?: string;
|
201 | readonly hubServerName?: string;
|
202 | };
|
203 | /**
|
204 | * The server directories used by the application, for user information
|
205 | * only.
|
206 | *
|
207 | * #### Notes
|
208 | * These are for user information and user interface hints only and should
|
209 | * not be relied on in code. A server may set these to empty strings if it
|
210 | * does not want to expose this information.
|
211 | *
|
212 | * Examples of appropriate use include displaying a help dialog for a user
|
213 | * listing the paths, or a tooltip in a filebrowser displaying the server
|
214 | * root. Examples of inappropriate use include using one of these paths in a
|
215 | * terminal command, generating code using these paths, or using one of
|
216 | * these paths in a request to the server (it would be better to write a
|
217 | * server extension to handle these cases).
|
218 | */
|
219 | readonly directories: {
|
220 | readonly appSettings: string;
|
221 | readonly schemas: string;
|
222 | readonly static: string;
|
223 | readonly templates: string;
|
224 | readonly themes: string;
|
225 | readonly userSettings: string;
|
226 | readonly serverRoot: string;
|
227 | readonly workspaces: string;
|
228 | };
|
229 | }
|
230 | /**
|
231 | * The application tree resolver token.
|
232 | *
|
233 | * #### Notes
|
234 | * Not all Jupyter front-end applications will have a tree resolver
|
235 | * implemented on the client-side. This token should not be required as a
|
236 | * dependency if it is possible to make it an optional dependency.
|
237 | */
|
238 | const ITreeResolver: Token<ITreeResolver>;
|
239 | /**
|
240 | * An interface for a front-end tree route resolver.
|
241 | */
|
242 | interface ITreeResolver {
|
243 | /**
|
244 | * A promise that resolves to the routed tree paths or null.
|
245 | */
|
246 | readonly paths: Promise<ITreeResolver.Paths>;
|
247 | }
|
248 | /**
|
249 | * A namespace for tree resolver types.
|
250 | */
|
251 | namespace ITreeResolver {
|
252 | /**
|
253 | * The browser and file paths if the tree resolver encountered and handled
|
254 | * a tree URL or `null` if not. Empty string paths should be ignored.
|
255 | */
|
256 | type Paths = {
|
257 | browser: string;
|
258 | file: string;
|
259 | } | null;
|
260 | }
|
261 | }
|
262 | /**
|
263 | * A namespace for the context menu override.
|
264 | */
|
265 | export declare namespace JupyterFrontEndContextMenu {
|
266 | /**
|
267 | * An id for a private context-menu-info ersatz command.
|
268 | */
|
269 | const contextMenu = "__internal:context-menu-info";
|
270 | }
|