@jupyterlab/ui-components 4.0.0-alpha.34 → 4.0.0-alpha.35

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.
Files changed (45) hide show
  1. package/lib/components/form.js +1 -1
  2. package/lib/components/form.js.map +1 -1
  3. package/lib/components/vdom.d.ts +1 -1
  4. package/lib/components/windowedlist.js +2 -1
  5. package/lib/components/windowedlist.js.map +1 -1
  6. package/lib/hoverbox.d.ts +1 -1
  7. package/lib/icon/labicon.js +49 -48
  8. package/lib/icon/labicon.js.map +1 -1
  9. package/lib/icon/widgets/tabbarsvg.js +2 -1
  10. package/lib/icon/widgets/tabbarsvg.js.map +1 -1
  11. package/package.json +20 -19
  12. package/src/FormRendererRegistry.tsx +60 -0
  13. package/src/components/accordiontoolbar.ts +252 -0
  14. package/src/components/button.tsx +45 -0
  15. package/src/components/collapser.ts +176 -0
  16. package/src/components/form.tsx +678 -0
  17. package/src/components/htmlselect.tsx +99 -0
  18. package/src/components/iframe.ts +153 -0
  19. package/src/components/index.ts +20 -0
  20. package/src/components/inputgroup.tsx +51 -0
  21. package/src/components/interface.ts +9 -0
  22. package/src/components/menu.ts +442 -0
  23. package/src/components/panelwithtoolbar.ts +41 -0
  24. package/src/components/search.tsx +216 -0
  25. package/src/components/sidepanel.ts +168 -0
  26. package/src/components/spinner.ts +31 -0
  27. package/src/components/styling.ts +114 -0
  28. package/src/components/switch.ts +103 -0
  29. package/src/components/toolbar.tsx +1119 -0
  30. package/src/components/vdom.ts +324 -0
  31. package/src/components/windowedlist.ts +1422 -0
  32. package/src/hoverbox.ts +401 -0
  33. package/src/icon/iconimports.ts +206 -0
  34. package/src/icon/index.ts +6 -0
  35. package/src/icon/labicon.tsx +955 -0
  36. package/src/icon/widgets/commandpalettesvg.ts +78 -0
  37. package/src/icon/widgets/index.ts +6 -0
  38. package/src/icon/widgets/menusvg.ts +218 -0
  39. package/src/icon/widgets/tabbarsvg.ts +122 -0
  40. package/src/index.ts +13 -0
  41. package/src/style/icon.ts +581 -0
  42. package/src/style/index.ts +4 -0
  43. package/src/svg.d.ts +58 -0
  44. package/src/tokens.ts +68 -0
  45. package/src/utils.ts +90 -0
@@ -0,0 +1,442 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ /* global WeakRef */
5
+
6
+ import { ArrayExt } from '@lumino/algorithm';
7
+ import { CommandRegistry } from '@lumino/commands';
8
+ import { ReadonlyJSONObject } from '@lumino/coreutils';
9
+ import { DisposableDelegate, IDisposable } from '@lumino/disposable';
10
+ import { Signal } from '@lumino/signaling';
11
+ import { VirtualElement } from '@lumino/virtualdom';
12
+ import { Menu } from '@lumino/widgets';
13
+
14
+ /**
15
+ * Interface for disposable item menu
16
+ */
17
+ export interface IDisposableMenuItem extends IDisposable, Menu.IItem {}
18
+
19
+ /**
20
+ * A common interface for extensible JupyterLab application menus.
21
+ *
22
+ * Plugins are still free to define their own menus in any way
23
+ * they like. However, JupyterLab defines a few top-level
24
+ * application menus that may be extended by plugins as well,
25
+ * such as "Edit" and "View"
26
+ */
27
+ export interface IRankedMenu extends IDisposable {
28
+ /**
29
+ * Add a group of menu items specific to a particular
30
+ * plugin.
31
+ *
32
+ * The rank can be set for all items in the group using the
33
+ * function argument or per item.
34
+ *
35
+ * @param items - the list of menu items to add.
36
+ * @param rank - the default rank in the menu in which to insert the group.
37
+ * @returns Disposable of the group
38
+ */
39
+ addGroup(items: Menu.IItemOptions[], rank?: number): IDisposable;
40
+
41
+ /**
42
+ * Add a menu item to the end of the menu.
43
+ *
44
+ * @param options - The options for creating the menu item.
45
+ *
46
+ * @returns The disposable menu item added to the menu.
47
+ */
48
+ addItem(options: IRankedMenu.IItemOptions): IDisposable;
49
+
50
+ /**
51
+ * A read-only array of the menu items in the menu.
52
+ */
53
+ readonly items: ReadonlyArray<Menu.IItem>;
54
+
55
+ /**
56
+ * Menu rank
57
+ */
58
+ readonly rank?: number;
59
+ }
60
+
61
+ /**
62
+ * Namespace for JupyterLabMenu interfaces
63
+ */
64
+ export namespace IRankedMenu {
65
+ /**
66
+ * Default menu item rank
67
+ */
68
+ export const DEFAULT_RANK = 100;
69
+
70
+ /**
71
+ * An options object for creating a menu item.
72
+ */
73
+ export interface IItemOptions extends Menu.IItemOptions {
74
+ /**
75
+ * Menu item rank
76
+ */
77
+ rank?: number;
78
+ }
79
+
80
+ /**
81
+ * An options object for creating a JupyterLab menu.
82
+ */
83
+ export interface IOptions extends Menu.IOptions {
84
+ /**
85
+ * Whether to include separators between the
86
+ * groups that are added to the menu.
87
+ *
88
+ * Default: true
89
+ */
90
+ includeSeparators?: boolean;
91
+ /**
92
+ * Menu rank
93
+ */
94
+ rank?: number;
95
+ }
96
+ }
97
+
98
+ /**
99
+ * An extensible menu for JupyterLab application menus.
100
+ */
101
+ export class RankedMenu extends Menu implements IRankedMenu {
102
+ /**
103
+ * Construct a new menu.
104
+ *
105
+ * @param options - Options for the lumino menu.
106
+ */
107
+ constructor(options: IRankedMenu.IOptions) {
108
+ super(options);
109
+ this._rank = options.rank;
110
+ this._includeSeparators = options.includeSeparators ?? true;
111
+ }
112
+
113
+ /**
114
+ * The underlying Lumino menu.
115
+ *
116
+ * @deprecated since v3.1
117
+ * RankMenu inherits from Menu since v3.1
118
+ */
119
+ get menu(): Menu {
120
+ return this;
121
+ }
122
+
123
+ /**
124
+ * Menu rank.
125
+ */
126
+ get rank(): number | undefined {
127
+ return this._rank;
128
+ }
129
+
130
+ /**
131
+ * Add a group of menu items specific to a particular
132
+ * plugin.
133
+ *
134
+ * The rank can be set for all items in the group using the
135
+ * function argument or per item.
136
+ *
137
+ * @param items - the list of menu items to add.
138
+ * @param rank - the default rank in the menu in which to insert the group.
139
+ * @returns Disposable of the group
140
+ */
141
+ addGroup(items: IRankedMenu.IItemOptions[], rank?: number): IDisposable {
142
+ if (items.length === 0) {
143
+ return new DisposableDelegate(() => void 0);
144
+ }
145
+ const defaultRank = rank ?? IRankedMenu.DEFAULT_RANK;
146
+
147
+ const sortedItems = items
148
+ .map(item => {
149
+ return { ...item, rank: item.rank ?? defaultRank };
150
+ })
151
+ .sort((a, b) => a.rank - b.rank);
152
+
153
+ // Insert the plugin group into the menu.
154
+ let insertIndex = this._ranks.findIndex(rank => sortedItems[0].rank < rank);
155
+ if (insertIndex < 0) {
156
+ insertIndex = this._ranks.length; // Insert at the end of the menu
157
+ }
158
+
159
+ // Keep an array of the menu items that have been created.
160
+ const added: IDisposableMenuItem[] = [];
161
+
162
+ // Insert a separator before the group.
163
+ // Lumino takes care of superfluous leading,
164
+ // trailing, and duplicate separators.
165
+ if (this._includeSeparators) {
166
+ added.push(
167
+ this.insertItem(insertIndex++, { type: 'separator', rank: defaultRank })
168
+ );
169
+ }
170
+ // Insert the group.
171
+ added.push(
172
+ ...sortedItems.map(item => {
173
+ return this.insertItem(insertIndex++, item);
174
+ })
175
+ );
176
+
177
+ // Insert a separator after the group.
178
+ if (this._includeSeparators) {
179
+ added.push(
180
+ this.insertItem(insertIndex++, { type: 'separator', rank: defaultRank })
181
+ );
182
+ }
183
+
184
+ return new DisposableDelegate(() => {
185
+ added.forEach(i => i.dispose());
186
+ });
187
+ }
188
+
189
+ /**
190
+ * Add a menu item to the end of the menu.
191
+ *
192
+ * @param options - The options for creating the menu item.
193
+ *
194
+ * @returns The menu item added to the menu.
195
+ */
196
+ addItem(options: IRankedMenu.IItemOptions): IDisposableMenuItem {
197
+ let insertIndex = -1;
198
+
199
+ if (options.rank) {
200
+ insertIndex = this._ranks.findIndex(rank => options.rank! < rank);
201
+ }
202
+ if (insertIndex < 0) {
203
+ insertIndex = this._ranks.length; // Insert at the end of the menu
204
+ }
205
+
206
+ return this.insertItem(insertIndex, options);
207
+ }
208
+
209
+ /**
210
+ * Remove all menu items from the menu.
211
+ */
212
+ clearItems(): void {
213
+ this._ranks.length = 0;
214
+ super.clearItems();
215
+ }
216
+
217
+ /**
218
+ * Dispose of the resources held by the menu.
219
+ */
220
+ dispose(): void {
221
+ this._ranks.length = 0;
222
+ super.dispose();
223
+ }
224
+
225
+ /**
226
+ * Get the rank of the item at index.
227
+ *
228
+ * @param index Item index.
229
+ * @returns Rank of the item.
230
+ */
231
+ getRankAt(index: number): number {
232
+ return this._ranks[index];
233
+ }
234
+
235
+ /**
236
+ * Insert a menu item into the menu at the specified index.
237
+ *
238
+ * @param index - The index at which to insert the item.
239
+ *
240
+ * @param options - The options for creating the menu item.
241
+ *
242
+ * @returns The menu item added to the menu.
243
+ *
244
+ * #### Notes
245
+ * The index will be clamped to the bounds of the items.
246
+ */
247
+ insertItem(
248
+ index: number,
249
+ options: IRankedMenu.IItemOptions
250
+ ): IDisposableMenuItem {
251
+ const clampedIndex = Math.max(0, Math.min(index, this._ranks.length));
252
+ ArrayExt.insert(
253
+ this._ranks,
254
+ clampedIndex,
255
+ options.rank ??
256
+ Math.max(
257
+ IRankedMenu.DEFAULT_RANK,
258
+ this._ranks[this._ranks.length - 1] ?? IRankedMenu.DEFAULT_RANK
259
+ )
260
+ );
261
+ const item = super.insertItem(clampedIndex, options);
262
+ return new DisposableMenuItem(item, this);
263
+ }
264
+
265
+ /**
266
+ * Remove the item at a given index from the menu.
267
+ *
268
+ * @param index - The index of the item to remove.
269
+ *
270
+ * #### Notes
271
+ * This is a no-op if the index is out of range.
272
+ */
273
+ removeItemAt(index: number): void {
274
+ ArrayExt.removeAt(this._ranks, index);
275
+ super.removeItemAt(index);
276
+ }
277
+
278
+ private _includeSeparators: boolean;
279
+ private _rank: number | undefined;
280
+ private _ranks: number[] = [];
281
+ }
282
+
283
+ /**
284
+ * Disposable Menu Item
285
+ */
286
+ class DisposableMenuItem implements IDisposableMenuItem {
287
+ /**
288
+ * Create a disposable menu item from an item and the menu it belongs to
289
+ *
290
+ * @param item Menu item
291
+ * @param menu Menu
292
+ */
293
+ constructor(item: Menu.IItem, menu: Menu) {
294
+ this._item = new WeakRef(item);
295
+ this._menu = menu;
296
+
297
+ // dispose this item if the parent menu is disposed
298
+ const dispose = (menu: Menu): void => {
299
+ menu.disposed.disconnect(dispose, this);
300
+ this.dispose();
301
+ };
302
+ this._menu.disposed.connect(dispose, this);
303
+ }
304
+
305
+ /**
306
+ * Whether the menu item is disposed or not.
307
+ */
308
+ get isDisposed(): boolean {
309
+ return this._isDisposed;
310
+ }
311
+
312
+ /**
313
+ * The type of the menu item.
314
+ */
315
+ get type(): Menu.ItemType {
316
+ return this._item.deref()!.type;
317
+ }
318
+
319
+ /**
320
+ * The command to execute when the item is triggered.
321
+ */
322
+ get command(): string {
323
+ return this._item.deref()!.command;
324
+ }
325
+
326
+ /**
327
+ * The arguments for the command.
328
+ */
329
+ get args(): ReadonlyJSONObject {
330
+ return this._item.deref()!.args;
331
+ }
332
+
333
+ /**
334
+ * The submenu for a `'submenu'` type item.
335
+ */
336
+ get submenu(): Menu | null {
337
+ return this._item.deref()!.submenu;
338
+ }
339
+
340
+ /**
341
+ * The display label for the menu item.
342
+ */
343
+ get label(): string {
344
+ return this._item.deref()!.label;
345
+ }
346
+
347
+ /**
348
+ * The mnemonic index for the menu item.
349
+ */
350
+ get mnemonic(): number {
351
+ return this._item.deref()!.mnemonic;
352
+ }
353
+
354
+ /**
355
+ * The icon renderer for the menu item.
356
+ */
357
+ get icon(): VirtualElement.IRenderer | undefined {
358
+ return this._item.deref()!.icon;
359
+ }
360
+
361
+ /**
362
+ * The icon class for the menu item.
363
+ */
364
+ get iconClass(): string {
365
+ return this._item.deref()!.iconClass;
366
+ }
367
+
368
+ /**
369
+ * The icon label for the menu item.
370
+ */
371
+ get iconLabel(): string {
372
+ return this._item.deref()!.iconLabel;
373
+ }
374
+
375
+ /**
376
+ * The display caption for the menu item.
377
+ */
378
+ get caption(): string {
379
+ return this._item.deref()!.caption;
380
+ }
381
+
382
+ /**
383
+ * The extra class name for the menu item.
384
+ */
385
+ get className(): string {
386
+ return this._item.deref()!.className;
387
+ }
388
+
389
+ /**
390
+ * The dataset for the menu item.
391
+ */
392
+ get dataset(): CommandRegistry.Dataset {
393
+ return this._item.deref()!.dataset;
394
+ }
395
+
396
+ /**
397
+ * Whether the menu item is enabled.
398
+ */
399
+ get isEnabled(): boolean {
400
+ return this._item.deref()!.isEnabled;
401
+ }
402
+
403
+ /**
404
+ * Whether the menu item is toggled.
405
+ */
406
+ get isToggled(): boolean {
407
+ return this._item.deref()!.isToggled;
408
+ }
409
+
410
+ /**
411
+ * Whether the menu item is visible.
412
+ */
413
+ get isVisible(): boolean {
414
+ return this._item.deref()!.isVisible;
415
+ }
416
+
417
+ /**
418
+ * The key binding for the menu item.
419
+ */
420
+ get keyBinding(): CommandRegistry.IKeyBinding | null {
421
+ return this._item.deref()!.keyBinding;
422
+ }
423
+
424
+ /**
425
+ * Dispose the menu item by removing it from its menu.
426
+ */
427
+ dispose(): void {
428
+ if (this._isDisposed) {
429
+ return;
430
+ }
431
+ this._isDisposed = true;
432
+ const item = this._item.deref();
433
+ if (item && !this._menu.isDisposed) {
434
+ this._menu.removeItem(item);
435
+ }
436
+ Signal.clearData(this);
437
+ }
438
+
439
+ private _isDisposed: boolean;
440
+ private _item: WeakRef<Menu.IItem>;
441
+ private _menu: Menu;
442
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import { Panel } from '@lumino/widgets';
7
+ import { Toolbar } from './toolbar';
8
+
9
+ /**
10
+ * A base class for panel widget with toolbar.
11
+ */
12
+ export class PanelWithToolbar extends Panel implements Toolbar.IWidgetToolbar {
13
+ constructor(options: PanelWithToolbar.IOptions = {}) {
14
+ super(options);
15
+ this._toolbar = new Toolbar();
16
+ }
17
+
18
+ /**
19
+ * Widget toolbar
20
+ */
21
+ get toolbar(): Toolbar {
22
+ return this._toolbar;
23
+ }
24
+
25
+ protected _toolbar: Toolbar;
26
+ }
27
+
28
+ /**
29
+ * Namespace for panel with toolbar
30
+ */
31
+ export namespace PanelWithToolbar {
32
+ /**
33
+ * An options object for creating a panel with toolbar widget.
34
+ */
35
+ export interface IOptions extends Panel.IOptions {
36
+ /**
37
+ * Custom toolbar
38
+ */
39
+ toolbar?: Toolbar;
40
+ }
41
+ }
@@ -0,0 +1,216 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { InputGroup } from './inputgroup';
5
+ import { ReactWidget } from './vdom';
6
+ import { StringExt } from '@lumino/algorithm';
7
+ import React, { useEffect, useState } from 'react';
8
+
9
+ /**
10
+ * The class name added to the filebrowser crumbs node.
11
+ */
12
+ export interface IFilterBoxProps {
13
+ /**
14
+ * Whether to use case-sensitive search
15
+ */
16
+ caseSensitive?: boolean;
17
+
18
+ /**
19
+ * Whether the search box is disabled or not.
20
+ */
21
+ disabled?: boolean;
22
+
23
+ /**
24
+ * Whether to force a refresh.
25
+ */
26
+ forceRefresh?: boolean;
27
+
28
+ /**
29
+ * An optional initial search value.
30
+ */
31
+ initialQuery?: string;
32
+
33
+ /**
34
+ * Pass a ref to the input element
35
+ */
36
+ inputRef?: React.RefObject<HTMLInputElement>;
37
+
38
+ /**
39
+ * Optional placeholder for the search box.
40
+ */
41
+ placeholder?: string;
42
+
43
+ /**
44
+ * A function to callback when filter is updated.
45
+ */
46
+ updateFilter: (
47
+ filterFn: (item: string) => Partial<IScore> | null,
48
+ query?: string
49
+ ) => void;
50
+
51
+ /**
52
+ * Whether to use the fuzzy filter.
53
+ */
54
+ useFuzzyFilter: boolean;
55
+ }
56
+
57
+ /**
58
+ * A text match score with associated content item.
59
+ */
60
+ export interface IScore {
61
+ /**
62
+ * The numerical score for the text match.
63
+ */
64
+ score: number;
65
+
66
+ /**
67
+ * The indices of the text matches.
68
+ */
69
+ indices: number[] | null;
70
+ }
71
+
72
+ /**
73
+ * Perform a fuzzy search on a single item.
74
+ */
75
+ export function fuzzySearch(source: string, query: string): IScore | null {
76
+ // Set up the match score and indices array.
77
+ let score = Infinity;
78
+ let indices: number[] | null = null;
79
+
80
+ // The regex for search word boundaries
81
+ const rgx = /\b\w/g;
82
+
83
+ let continueSearch = true;
84
+
85
+ // Search the source by word boundary.
86
+ while (continueSearch) {
87
+ // Find the next word boundary in the source.
88
+ let rgxMatch = rgx.exec(source);
89
+
90
+ // Break if there is no more source context.
91
+ if (!rgxMatch) {
92
+ break;
93
+ }
94
+
95
+ // Run the string match on the relevant substring.
96
+ let match = StringExt.matchSumOfDeltas(source, query, rgxMatch.index);
97
+
98
+ // Break if there is no match.
99
+ if (!match) {
100
+ break;
101
+ }
102
+
103
+ // Update the match if the score is better.
104
+ if (match && match.score <= score) {
105
+ score = match.score;
106
+ indices = match.indices;
107
+ }
108
+ }
109
+
110
+ // Bail if there was no match.
111
+ if (!indices || score === Infinity) {
112
+ return null;
113
+ }
114
+
115
+ // Handle a split match.
116
+ return {
117
+ score,
118
+ indices
119
+ };
120
+ }
121
+
122
+ export const updateFilterFunction = (
123
+ value: string,
124
+ useFuzzyFilter: boolean,
125
+ caseSensitive?: boolean
126
+ ) => {
127
+ return (item: string): Partial<IScore> | null => {
128
+ if (useFuzzyFilter) {
129
+ // Run the fuzzy search for the item and query.
130
+ const query = value.toLowerCase();
131
+ // Ignore the item if it is not a match.
132
+ return fuzzySearch(item, query);
133
+ }
134
+ if (!caseSensitive) {
135
+ item = item.toLocaleLowerCase();
136
+ value = value.toLocaleLowerCase();
137
+ }
138
+ const i = item.indexOf(value);
139
+ if (i === -1) {
140
+ return null;
141
+ }
142
+ return {
143
+ indices: [...Array(item.length).keys()].map(x => x + 1)
144
+ };
145
+ };
146
+ };
147
+
148
+ export const FilterBox = (props: IFilterBoxProps): JSX.Element => {
149
+ const [filter, setFilter] = useState(props.initialQuery ?? '');
150
+
151
+ if (props.forceRefresh) {
152
+ useEffect(() => {
153
+ props.updateFilter((item: string) => {
154
+ return {};
155
+ });
156
+ }, []);
157
+ }
158
+
159
+ useEffect(() => {
160
+ // If there is an initial search value, pass the parent the initial filter function for that value.
161
+ if (props.initialQuery !== undefined) {
162
+ props.updateFilter(
163
+ updateFilterFunction(
164
+ props.initialQuery,
165
+ props.useFuzzyFilter,
166
+ props.caseSensitive
167
+ ),
168
+ props.initialQuery
169
+ );
170
+ }
171
+ }, []);
172
+
173
+ /**
174
+ * Handler for search input changes.
175
+ */
176
+ const handleChange = (e: React.FormEvent<HTMLElement>) => {
177
+ const target = e.target as HTMLInputElement;
178
+ setFilter(target.value);
179
+ props.updateFilter(
180
+ updateFilterFunction(
181
+ target.value,
182
+ props.useFuzzyFilter,
183
+ props.caseSensitive
184
+ ),
185
+ target.value
186
+ );
187
+ };
188
+
189
+ return (
190
+ <InputGroup
191
+ className="jp-FilterBox"
192
+ inputRef={props.inputRef}
193
+ type="text"
194
+ disabled={props.disabled}
195
+ rightIcon="ui-components:search"
196
+ placeholder={props.placeholder}
197
+ onChange={handleChange}
198
+ value={filter}
199
+ />
200
+ );
201
+ };
202
+
203
+ /**
204
+ * A widget which hosts a input textbox to filter on file names.
205
+ */
206
+ export const FilenameSearcher = (props: IFilterBoxProps): ReactWidget => {
207
+ return ReactWidget.create(
208
+ <FilterBox
209
+ updateFilter={props.updateFilter}
210
+ useFuzzyFilter={props.useFuzzyFilter}
211
+ placeholder={props.placeholder}
212
+ forceRefresh={props.forceRefresh}
213
+ caseSensitive={props.caseSensitive}
214
+ />
215
+ );
216
+ };