@jupyterlab/apputils 4.0.0-alpha.19 → 4.0.0-alpha.20

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