UNPKG

9.15 kBTypeScriptView Raw
1import { CommandLinker } from '@jupyterlab/apputils';
2import { DocumentRegistry } from '@jupyterlab/docregistry';
3import { ServiceManager } from '@jupyterlab/services';
4import { ContextMenuSvg } from '@jupyterlab/ui-components';
5import { Application, IPlugin } from '@lumino/application';
6import { Token } from '@lumino/coreutils';
7import { ISignal } from '@lumino/signaling';
8import { 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 */
18export 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 */
30export 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 */
98export 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 * Returns an iterator for the widgets inside the application shell.
153 *
154 * @param area - Optional regions in the shell whose widgets are iterated.
155 */
156 widgets(area?: string): IterableIterator<Widget>;
157 }
158 /**
159 * Is JupyterLab in document mode?
160 *
161 * @param path - Full URL of JupyterLab
162 * @param paths - The current IPaths object hydrated from PageConfig.
163 */
164 function inDocMode(path: string, paths: IPaths): boolean;
165 /**
166 * The application paths dictionary token.
167 */
168 const IPaths: Token<IPaths>;
169 /**
170 * An interface for URL and directory paths used by a Jupyter front-end.
171 */
172 interface IPaths {
173 /**
174 * The urls used by the application.
175 */
176 readonly urls: {
177 readonly base: string;
178 readonly notFound?: string;
179 readonly app: string;
180 readonly doc: string;
181 readonly static: string;
182 readonly settings: string;
183 readonly themes: string;
184 readonly translations: string;
185 readonly hubPrefix?: string;
186 readonly hubHost?: string;
187 readonly hubUser?: string;
188 readonly hubServerName?: string;
189 };
190 /**
191 * The server directories used by the application, for user information
192 * only.
193 *
194 * #### Notes
195 * These are for user information and user interface hints only and should
196 * not be relied on in code. A server may set these to empty strings if it
197 * does not want to expose this information.
198 *
199 * Examples of appropriate use include displaying a help dialog for a user
200 * listing the paths, or a tooltip in a filebrowser displaying the server
201 * root. Examples of inappropriate use include using one of these paths in a
202 * terminal command, generating code using these paths, or using one of
203 * these paths in a request to the server (it would be better to write a
204 * server extension to handle these cases).
205 */
206 readonly directories: {
207 readonly appSettings: string;
208 readonly schemas: string;
209 readonly static: string;
210 readonly templates: string;
211 readonly themes: string;
212 readonly userSettings: string;
213 readonly serverRoot: string;
214 readonly workspaces: string;
215 };
216 }
217 /**
218 * The application tree resolver token.
219 *
220 * #### Notes
221 * Not all Jupyter front-end applications will have a tree resolver
222 * implemented on the client-side. This token should not be required as a
223 * dependency if it is possible to make it an optional dependency.
224 */
225 const ITreeResolver: Token<ITreeResolver>;
226 /**
227 * An interface for a front-end tree route resolver.
228 */
229 interface ITreeResolver {
230 /**
231 * A promise that resolves to the routed tree paths or null.
232 */
233 readonly paths: Promise<ITreeResolver.Paths>;
234 }
235 /**
236 * A namespace for tree resolver types.
237 */
238 namespace ITreeResolver {
239 /**
240 * The browser and file paths if the tree resolver encountered and handled
241 * a tree URL or `null` if not. Empty string paths should be ignored.
242 */
243 type Paths = {
244 browser: string;
245 file: string;
246 } | null;
247 }
248}
249/**
250 * A namespace for the context menu override.
251 */
252export declare namespace JupyterFrontEndContextMenu {
253 /**
254 * An id for a private context-menu-info ersatz command.
255 */
256 const contextMenu = "__internal:context-menu-info";
257}