UNPKG

10.4 kBPlain TextView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3
4import { IChangedArgs } from '@jupyterlab/coreutils';
5import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
6import { ISettingRegistry } from '@jupyterlab/settingregistry';
7import { Token } from '@lumino/coreutils';
8import { IDisposable } from '@lumino/disposable';
9import { ISignal } from '@lumino/signaling';
10import { CommandPalette, Widget } from '@lumino/widgets';
11import { ISessionContext } from './sessioncontext';
12
13/**
14 * The command palette token.
15 */
16export const ICommandPalette = new Token<ICommandPalette>(
17 '@jupyterlab/apputils:ICommandPalette',
18 `A service for the application command palette
19 in the left panel. Use this to add commands to the palette.`
20);
21
22/**
23 * The options for creating a command palette item.
24 */
25export interface IPaletteItem extends CommandPalette.IItemOptions {}
26
27/**
28 * The interface for a Jupyter Lab command palette.
29 */
30export interface ICommandPalette {
31 /**
32 * The placeholder text of the command palette's search input.
33 */
34 placeholder: string;
35
36 /**
37 * Activate the command palette for user input.
38 */
39 activate(): void;
40
41 /**
42 * Add a command item to the command palette.
43 *
44 * @param options - The options for creating the command item.
45 *
46 * @returns A disposable that will remove the item from the palette.
47 */
48 addItem(options: IPaletteItem): IDisposable;
49}
50
51/**
52 * The kernel status indicator model.
53 */
54export const IKernelStatusModel = new Token<IKernelStatusModel>(
55 '@jupyterlab/apputils:IKernelStatusModel',
56 'A service to register kernel session provider to the kernel status indicator.'
57);
58
59/**
60 * Kernel status indicator model.
61 */
62export interface IKernelStatusModel {
63 /**
64 * Add a session context provider.
65 *
66 * A provider will receive the currently active widget and must return the
67 * associated session context if it can or null otherwise.
68 */
69 addSessionProvider: (
70 provider: (widget: Widget | null) => ISessionContext | null
71 ) => void;
72}
73
74/**
75 * An interface for the session context dialogs.
76 */
77export interface ISessionContextDialogs extends ISessionContext.IDialogs {}
78
79/**
80 * The session context dialogs token.
81 */
82export const ISessionContextDialogs = new Token<ISessionContext.IDialogs>(
83 '@jupyterlab/apputils:ISessionContextDialogs',
84 'A service for handling the session dialogs.'
85);
86
87/**
88 * The theme manager token.
89 */
90export const IThemeManager = new Token<IThemeManager>(
91 '@jupyterlab/apputils:IThemeManager',
92 'A service for the theme manager for the application. This is used primarily in theme extensions to register new themes.'
93);
94
95/**
96 * An interface for a theme manager.
97 */
98export interface IThemeManager {
99 /**
100 * Get the name of the current theme.
101 */
102 readonly theme: string | null;
103
104 /**
105 * Get the name of the preferred light theme.
106 */
107 readonly preferredLightTheme?: string | undefined;
108
109 /**
110 * Get the name of the preferred dark theme.
111 */
112 readonly preferredDarkTheme?: string | undefined;
113
114 /**
115 * Get the name of the preferred theme.
116 */
117 readonly preferredTheme?: string | null | undefined;
118
119 /**
120 * The names of the registered themes.
121 */
122 readonly themes: ReadonlyArray<string>;
123
124 /**
125 * Get the names of the registered light themes.
126 */
127 readonly lightThemes?: ReadonlyArray<string> | undefined;
128
129 /**
130 * Get the names of the registered dark themes.
131 */
132 readonly darkThemes?: ReadonlyArray<string> | undefined;
133
134 /**
135 * A signal fired when the application theme changes.
136 */
137 readonly themeChanged: ISignal<this, IChangedArgs<string, string | null>>;
138
139 /**
140 * Load a theme CSS file by path.
141 *
142 * @param path - The path of the file to load.
143 */
144 loadCSS(path: string): Promise<void>;
145
146 /**
147 * Register a theme with the theme manager.
148 *
149 * @param theme - The theme to register.
150 *
151 * @returns A disposable that can be used to unregister the theme.
152 */
153 register(theme: IThemeManager.ITheme): IDisposable;
154
155 /**
156 * Set the current theme.
157 */
158 setTheme(name: string): Promise<void>;
159
160 /**
161 * Test whether a given theme is light.
162 */
163 isLight(name: string): boolean;
164
165 /**
166 * Test whether a given theme styles scrollbars,
167 * and if the user has scrollbar styling enabled.
168 */
169 themeScrollbars(name: string): boolean;
170
171 /**
172 * Get display name for theme.
173 */
174 getDisplayName(name: string): string;
175}
176
177/**
178 * A namespace for the `IThemeManager` sub-types.
179 */
180export namespace IThemeManager {
181 /**
182 * An interface for a theme.
183 */
184 export interface ITheme {
185 /**
186 * The unique identifier name of the theme.
187 */
188 name: string;
189
190 /**
191 * The display name of the theme.
192 */
193 displayName?: string;
194
195 /**
196 * Whether the theme is light or dark. Downstream authors
197 * of extensions can use this information to customize their
198 * UI depending upon the current theme.
199 */
200 isLight: boolean;
201
202 /**
203 * Whether the theme includes styling for the scrollbar.
204 * If set to false, this theme will leave the native scrollbar untouched.
205 */
206 themeScrollbars?: boolean;
207
208 /**
209 * Load the theme.
210 *
211 * @returns A promise that resolves when the theme has loaded.
212 */
213 load(): Promise<void>;
214
215 /**
216 * Unload the theme.
217 *
218 * @returns A promise that resolves when the theme has unloaded.
219 */
220 unload(): Promise<void>;
221 }
222}
223
224/**
225 * The sanitizer token.
226 */
227export const ISanitizer = new Token<IRenderMime.ISanitizer>(
228 '@jupyterlab/apputils:ISanitizer',
229 'A service for sanitizing HTML strings.'
230);
231
232/**
233 * @deprecated since v4 use {@link IRenderMime.ISanitizer}
234 */
235export type ISanitizer = IRenderMime.ISanitizer;
236
237/**
238 * The namespace for `ISanitizer` related interfaces.
239 */
240export namespace ISanitizer {
241 /**
242 * The options used to sanitize.
243 *
244 * @deprecated in v4 use {@link IRenderMime.ISanitizerOptions}
245 */
246 export type IOptions = IRenderMime.ISanitizerOptions;
247}
248
249/**
250 * The main menu token.
251 */
252export const ISplashScreen = new Token<ISplashScreen>(
253 '@jupyterlab/apputils:ISplashScreen',
254 `A service for the splash screen for the application.
255 Use this if you want to show the splash screen for your own purposes.`
256);
257
258/**
259 * The interface for an application splash screen.
260 */
261export interface ISplashScreen {
262 /**
263 * Show the application splash screen.
264 *
265 * @param light - Whether to show the light splash screen or the dark one.
266 *
267 * @returns A disposable used to clear the splash screen.
268 */
269 show(light?: boolean): IDisposable;
270}
271
272/**
273 * The default window resolver token.
274 */
275export const IWindowResolver = new Token<IWindowResolver>(
276 '@jupyterlab/apputils:IWindowResolver',
277 `A service for a window resolver for the
278 application. JupyterLab workspaces are given a name, which are determined using
279 the window resolver. Require this if you want to use the name of the current workspace.`
280);
281
282/**
283 * The description of a window name resolver.
284 */
285export interface IWindowResolver {
286 /**
287 * A window name to use as a handle among shared resources.
288 */
289 readonly name: string;
290}
291
292/**
293 * The namespace for `IToolbarWidgetRegistry` related interfaces
294 */
295export namespace ToolbarRegistry {
296 /**
297 * Interface of item to be inserted in a toolbar
298 */
299 export interface IToolbarItem extends IRenderMime.IToolbarItem {}
300
301 /**
302 * Interface describing a toolbar item widget
303 */
304 export interface IWidget extends ISettingRegistry.IToolbarItem {}
305
306 /**
307 * Options to set up the toolbar widget registry
308 */
309 export interface IOptions {
310 /**
311 * Default toolbar widget factory
312 *
313 * The factory is receiving 3 arguments:
314 * @param widgetFactory The widget factory name that creates the toolbar
315 * @param widget The newly widget containing the toolbar
316 * @param toolbarItem The toolbar item definition
317 * @returns The widget to be inserted in the toolbar.
318 */
319 defaultFactory: (
320 widgetFactory: string,
321 widget: Widget,
322 toolbarItem: IWidget
323 ) => Widget;
324 }
325}
326
327/**
328 * Toolbar widget registry interface
329 */
330export interface IToolbarWidgetRegistry {
331 /**
332 * Add a new toolbar item factory
333 *
334 * @param widgetFactory The widget factory name that creates the toolbar
335 * @param toolbarItemName The unique toolbar item
336 * @param factory The factory function that receives the widget containing the toolbar and returns the toolbar widget.
337 * @returns The previously defined factory
338 */
339 addFactory<T extends Widget = Widget>(
340 widgetFactory: string,
341 toolbarItemName: string,
342 factory: (main: T) => Widget
343 ): ((main: T) => Widget) | undefined;
344
345 /**
346 * Default toolbar item factory
347 */
348 defaultFactory: (
349 widgetFactory: string,
350 widget: Widget,
351 toolbarItem: ToolbarRegistry.IWidget
352 ) => Widget;
353
354 /**
355 * Create a toolbar item widget
356 *
357 * @param widgetFactory The widget factory name that creates the toolbar
358 * @param widget The newly widget containing the toolbar
359 * @param toolbarItem The toolbar item definition
360 * @returns The widget to be inserted in the toolbar.
361 */
362 createWidget(
363 widgetFactory: string,
364 widget: Widget,
365 toolbarItem: ToolbarRegistry.IWidget
366 ): Widget;
367
368 /**
369 * Register a new toolbar item factory
370 *
371 * @param widgetFactory The widget factory name that creates the toolbar
372 * @param toolbarItemName The unique toolbar item
373 * @param factory The factory function that receives the widget containing the toolbar and returns the toolbar widget.
374 * @returns The previously defined factory
375 *
376 * @deprecated since v4 use `addFactory` instead
377 */
378 registerFactory<T extends Widget = Widget>(
379 widgetFactory: string,
380 toolbarItemName: string,
381 factory: (main: T) => Widget
382 ): ((main: T) => Widget) | undefined;
383
384 /**
385 * A signal emitted when a factory widget has been added.
386 */
387 readonly factoryAdded: ISignal<this, string>;
388}
389
390/**
391 * The toolbar registry token.
392 */
393export const IToolbarWidgetRegistry = new Token<IToolbarWidgetRegistry>(
394 '@jupyterlab/apputils:IToolbarWidgetRegistry',
395 `A registry for toolbar widgets. Require this
396 if you want to build the toolbar dynamically from a data definition (stored in settings for example).`
397);
398
\No newline at end of file