@jupyterlab/apputils 3.3.0-alpha.13 → 3.3.0-alpha.17

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 (60) hide show
  1. package/lib/collapse.d.ts +64 -0
  2. package/lib/collapse.js +145 -0
  3. package/lib/collapse.js.map +1 -0
  4. package/lib/commandpalette.d.ts +32 -0
  5. package/lib/commandpalette.js +7 -1
  6. package/lib/commandpalette.js.map +1 -1
  7. package/lib/dialog.d.ts +8 -10
  8. package/lib/dialog.js +23 -2
  9. package/lib/dialog.js.map +1 -1
  10. package/lib/iframe.d.ts +77 -0
  11. package/lib/iframe.js +89 -0
  12. package/lib/iframe.js.map +1 -0
  13. package/lib/index.d.ts +7 -26
  14. package/lib/index.js +7 -26
  15. package/lib/index.js.map +1 -1
  16. package/lib/inputdialog.js +1 -1
  17. package/lib/inputdialog.js.map +1 -1
  18. package/lib/mainareawidget.d.ts +2 -2
  19. package/lib/mainareawidget.js +2 -1
  20. package/lib/mainareawidget.js.map +1 -1
  21. package/lib/printing.js +1 -1
  22. package/lib/printing.js.map +1 -1
  23. package/lib/sanitizer.js +0 -1
  24. package/lib/sanitizer.js.map +1 -1
  25. package/lib/sessioncontext.d.ts +4 -0
  26. package/lib/sessioncontext.js +37 -7
  27. package/lib/sessioncontext.js.map +1 -1
  28. package/lib/spinner.d.ts +15 -0
  29. package/lib/spinner.js +28 -0
  30. package/lib/spinner.js.map +1 -0
  31. package/lib/splash.d.ts +19 -0
  32. package/lib/splash.js +9 -0
  33. package/lib/splash.js.map +1 -0
  34. package/lib/styling.d.ts +27 -0
  35. package/lib/styling.js +100 -0
  36. package/lib/styling.js.map +1 -0
  37. package/lib/thememanager.d.ts +2 -1
  38. package/lib/thememanager.js.map +1 -1
  39. package/lib/tokens.d.ts +1 -61
  40. package/lib/tokens.js +0 -15
  41. package/lib/tokens.js.map +1 -1
  42. package/lib/toolbar/registry.js +2 -1
  43. package/lib/toolbar/registry.js.map +1 -1
  44. package/lib/toolbar/widget.d.ts +412 -0
  45. package/lib/toolbar/widget.js +864 -3
  46. package/lib/toolbar/widget.js.map +1 -1
  47. package/lib/vdom.d.ts +189 -0
  48. package/lib/vdom.js +203 -0
  49. package/lib/vdom.js.map +1 -0
  50. package/lib/windowresolver.d.ts +14 -1
  51. package/lib/windowresolver.js +6 -1
  52. package/lib/windowresolver.js.map +1 -1
  53. package/package.json +15 -11
  54. package/style/base.css +5 -0
  55. package/style/collapse.css +30 -0
  56. package/style/dialog.css +24 -2
  57. package/style/iframe.css +33 -0
  58. package/style/spinner.css +79 -0
  59. package/style/styling.css +101 -0
  60. package/style/toolbar.css +115 -0
@@ -1,22 +1,493 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  import { nullTranslator } from '@jupyterlab/translation';
4
- import { circleEmptyIcon, circleIcon, LabIcon, offlineBoltIcon, ReactWidget, refreshIcon, stopIcon, ToolbarButton, ToolbarButtonComponent, UseSignal } from '@jupyterlab/ui-components';
5
- import { Widget } from '@lumino/widgets';
4
+ import { Button, circleEmptyIcon, circleIcon, classes, ellipsesIcon, LabIcon, offlineBoltIcon, refreshIcon, stopIcon } from '@jupyterlab/ui-components';
5
+ import { find, map, some } from '@lumino/algorithm';
6
+ import { CommandRegistry } from '@lumino/commands';
7
+ import { MessageLoop } from '@lumino/messaging';
8
+ import { AttachedProperty } from '@lumino/properties';
9
+ import { PanelLayout, Widget } from '@lumino/widgets';
6
10
  import * as React from 'react';
7
11
  import { sessionContextDialogs } from '../sessioncontext';
12
+ import { ReactWidget, UseSignal } from '../vdom';
13
+ import { Throttler } from '@lumino/polling';
14
+ /**
15
+ * The class name added to toolbars.
16
+ */
17
+ const TOOLBAR_CLASS = 'jp-Toolbar';
18
+ /**
19
+ * Toolbar pop-up opener button name
20
+ */
21
+ const TOOLBAR_OPENER_NAME = 'toolbar-popup-opener';
22
+ /**
23
+ * The class name added to toolbar items.
24
+ */
25
+ const TOOLBAR_ITEM_CLASS = 'jp-Toolbar-item';
8
26
  /**
9
27
  * The class name added to toolbar kernel name text.
10
28
  */
11
29
  const TOOLBAR_KERNEL_NAME_CLASS = 'jp-Toolbar-kernelName';
30
+ /**
31
+ * The class name added to toolbar spacer.
32
+ */
33
+ const TOOLBAR_SPACER_CLASS = 'jp-Toolbar-spacer';
12
34
  /**
13
35
  * The class name added to toolbar kernel status icon.
14
36
  */
15
37
  const TOOLBAR_KERNEL_STATUS_CLASS = 'jp-Toolbar-kernelStatus';
38
+ /**
39
+ * A layout for toolbars.
40
+ *
41
+ * #### Notes
42
+ * This layout automatically collapses its height if there are no visible
43
+ * toolbar widgets, and expands to the standard toolbar height if there are
44
+ * visible toolbar widgets.
45
+ */
46
+ class ToolbarLayout extends PanelLayout {
47
+ constructor() {
48
+ super(...arguments);
49
+ this._dirty = false;
50
+ }
51
+ /**
52
+ * A message handler invoked on a `'fit-request'` message.
53
+ *
54
+ * If any child widget is visible, expand the toolbar height to the normal
55
+ * toolbar height.
56
+ */
57
+ onFitRequest(msg) {
58
+ super.onFitRequest(msg);
59
+ if (this.parent.isAttached) {
60
+ // If there are any widgets not explicitly hidden, expand the toolbar to
61
+ // accommodate them.
62
+ if (some(this.widgets, w => !w.isHidden)) {
63
+ this.parent.node.style.minHeight = 'var(--jp-private-toolbar-height)';
64
+ this.parent.removeClass('jp-Toolbar-micro');
65
+ }
66
+ else {
67
+ this.parent.node.style.minHeight = '';
68
+ this.parent.addClass('jp-Toolbar-micro');
69
+ }
70
+ }
71
+ // Set the dirty flag to ensure only a single update occurs.
72
+ this._dirty = true;
73
+ // Notify the ancestor that it should fit immediately. This may
74
+ // cause a resize of the parent, fulfilling the required update.
75
+ if (this.parent.parent) {
76
+ MessageLoop.sendMessage(this.parent.parent, Widget.Msg.FitRequest);
77
+ }
78
+ // If the dirty flag is still set, the parent was not resized.
79
+ // Trigger the required update on the parent widget immediately.
80
+ if (this._dirty) {
81
+ MessageLoop.sendMessage(this.parent, Widget.Msg.UpdateRequest);
82
+ }
83
+ }
84
+ /**
85
+ * A message handler invoked on an `'update-request'` message.
86
+ */
87
+ onUpdateRequest(msg) {
88
+ super.onUpdateRequest(msg);
89
+ if (this.parent.isVisible) {
90
+ this._dirty = false;
91
+ }
92
+ }
93
+ /**
94
+ * A message handler invoked on a `'child-shown'` message.
95
+ */
96
+ onChildShown(msg) {
97
+ super.onChildShown(msg);
98
+ // Post a fit request for the parent widget.
99
+ this.parent.fit();
100
+ }
101
+ /**
102
+ * A message handler invoked on a `'child-hidden'` message.
103
+ */
104
+ onChildHidden(msg) {
105
+ super.onChildHidden(msg);
106
+ // Post a fit request for the parent widget.
107
+ this.parent.fit();
108
+ }
109
+ /**
110
+ * A message handler invoked on a `'before-attach'` message.
111
+ */
112
+ onBeforeAttach(msg) {
113
+ super.onBeforeAttach(msg);
114
+ // Post a fit request for the parent widget.
115
+ this.parent.fit();
116
+ }
117
+ /**
118
+ * Attach a widget to the parent's DOM node.
119
+ *
120
+ * @param index - The current index of the widget in the layout.
121
+ *
122
+ * @param widget - The widget to attach to the parent.
123
+ *
124
+ * #### Notes
125
+ * This is a reimplementation of the superclass method.
126
+ */
127
+ attachWidget(index, widget) {
128
+ super.attachWidget(index, widget);
129
+ // Post a fit request for the parent widget.
130
+ this.parent.fit();
131
+ }
132
+ /**
133
+ * Detach a widget from the parent's DOM node.
134
+ *
135
+ * @param index - The previous index of the widget in the layout.
136
+ *
137
+ * @param widget - The widget to detach from the parent.
138
+ *
139
+ * #### Notes
140
+ * This is a reimplementation of the superclass method.
141
+ */
142
+ detachWidget(index, widget) {
143
+ super.detachWidget(index, widget);
144
+ // Post a fit request for the parent widget.
145
+ this.parent.fit();
146
+ }
147
+ }
148
+ /**
149
+ * A class which provides a toolbar widget.
150
+ */
151
+ export class Toolbar extends Widget {
152
+ /**
153
+ * Construct a new toolbar widget.
154
+ */
155
+ constructor() {
156
+ super();
157
+ this.addClass(TOOLBAR_CLASS);
158
+ this.layout = new ToolbarLayout();
159
+ }
160
+ /**
161
+ * Get an iterator over the ordered toolbar item names.
162
+ *
163
+ * @returns An iterator over the toolbar item names.
164
+ */
165
+ names() {
166
+ const layout = this.layout;
167
+ return map(layout.widgets, widget => {
168
+ return Private.nameProperty.get(widget);
169
+ });
170
+ }
171
+ /**
172
+ * Add an item to the end of the toolbar.
173
+ *
174
+ * @param name - The name of the widget to add to the toolbar.
175
+ *
176
+ * @param widget - The widget to add to the toolbar.
177
+ *
178
+ * @param index - The optional name of the item to insert after.
179
+ *
180
+ * @returns Whether the item was added to toolbar. Returns false if
181
+ * an item of the same name is already in the toolbar.
182
+ *
183
+ * #### Notes
184
+ * The item can be removed from the toolbar by setting its parent to `null`.
185
+ */
186
+ addItem(name, widget) {
187
+ const layout = this.layout;
188
+ return this.insertItem(layout.widgets.length, name, widget);
189
+ }
190
+ /**
191
+ * Insert an item into the toolbar at the specified index.
192
+ *
193
+ * @param index - The index at which to insert the item.
194
+ *
195
+ * @param name - The name of the item.
196
+ *
197
+ * @param widget - The widget to add.
198
+ *
199
+ * @returns Whether the item was added to the toolbar. Returns false if
200
+ * an item of the same name is already in the toolbar.
201
+ *
202
+ * #### Notes
203
+ * The index will be clamped to the bounds of the items.
204
+ * The item can be removed from the toolbar by setting its parent to `null`.
205
+ */
206
+ insertItem(index, name, widget) {
207
+ const existing = find(this.names(), value => value === name);
208
+ if (existing) {
209
+ return false;
210
+ }
211
+ widget.addClass(TOOLBAR_ITEM_CLASS);
212
+ const layout = this.layout;
213
+ const j = Math.max(0, Math.min(index, layout.widgets.length));
214
+ layout.insertWidget(j, widget);
215
+ Private.nameProperty.set(widget, name);
216
+ return true;
217
+ }
218
+ /**
219
+ * Insert an item into the toolbar at the after a target item.
220
+ *
221
+ * @param at - The target item to insert after.
222
+ *
223
+ * @param name - The name of the item.
224
+ *
225
+ * @param widget - The widget to add.
226
+ *
227
+ * @returns Whether the item was added to the toolbar. Returns false if
228
+ * an item of the same name is already in the toolbar.
229
+ *
230
+ * #### Notes
231
+ * The index will be clamped to the bounds of the items.
232
+ * The item can be removed from the toolbar by setting its parent to `null`.
233
+ */
234
+ insertAfter(at, name, widget) {
235
+ return this._insertRelative(at, 1, name, widget);
236
+ }
237
+ /**
238
+ * Insert an item into the toolbar at the before a target item.
239
+ *
240
+ * @param at - The target item to insert before.
241
+ *
242
+ * @param name - The name of the item.
243
+ *
244
+ * @param widget - The widget to add.
245
+ *
246
+ * @returns Whether the item was added to the toolbar. Returns false if
247
+ * an item of the same name is already in the toolbar.
248
+ *
249
+ * #### Notes
250
+ * The index will be clamped to the bounds of the items.
251
+ * The item can be removed from the toolbar by setting its parent to `null`.
252
+ */
253
+ insertBefore(at, name, widget) {
254
+ return this._insertRelative(at, 0, name, widget);
255
+ }
256
+ _insertRelative(at, offset, name, widget) {
257
+ const nameWithIndex = map(this.names(), (name, i) => {
258
+ return { name: name, index: i };
259
+ });
260
+ const target = find(nameWithIndex, x => x.name === at);
261
+ if (target) {
262
+ return this.insertItem(target.index + offset, name, widget);
263
+ }
264
+ return false;
265
+ }
266
+ /**
267
+ * Handle the DOM events for the widget.
268
+ *
269
+ * @param event - The DOM event sent to the widget.
270
+ *
271
+ * #### Notes
272
+ * This method implements the DOM `EventListener` interface and is
273
+ * called in response to events on the dock panel's node. It should
274
+ * not be called directly by user code.
275
+ */
276
+ handleEvent(event) {
277
+ switch (event.type) {
278
+ case 'click':
279
+ this.handleClick(event);
280
+ break;
281
+ default:
282
+ break;
283
+ }
284
+ }
285
+ /**
286
+ * Handle a DOM click event.
287
+ */
288
+ handleClick(event) {
289
+ // Stop propagating the click outside the toolbar
290
+ event.stopPropagation();
291
+ // Clicking a label focuses the corresponding control
292
+ // that is linked with `for` attribute, so let it be.
293
+ if (event.target instanceof HTMLLabelElement) {
294
+ const forId = event.target.getAttribute('for');
295
+ if (forId && this.node.querySelector(`#${forId}`)) {
296
+ return;
297
+ }
298
+ }
299
+ // If this click already focused a control, let it be.
300
+ if (this.node.contains(document.activeElement)) {
301
+ return;
302
+ }
303
+ // Otherwise, activate the parent widget, which may take focus if desired.
304
+ if (this.parent) {
305
+ this.parent.activate();
306
+ }
307
+ }
308
+ /**
309
+ * Handle `after-attach` messages for the widget.
310
+ */
311
+ onAfterAttach(msg) {
312
+ this.node.addEventListener('click', this);
313
+ }
314
+ /**
315
+ * Handle `before-detach` messages for the widget.
316
+ */
317
+ onBeforeDetach(msg) {
318
+ this.node.removeEventListener('click', this);
319
+ }
320
+ }
321
+ /**
322
+ * A class which provides a toolbar widget.
323
+ */
324
+ export class ReactiveToolbar extends Toolbar {
325
+ /**
326
+ * Construct a new toolbar widget.
327
+ */
328
+ constructor() {
329
+ super();
330
+ this.popupOpener = new ToolbarPopupOpener();
331
+ this._widgetWidths = {};
332
+ this.insertItem(0, TOOLBAR_OPENER_NAME, this.popupOpener);
333
+ this.popupOpener.hide();
334
+ this._resizer = new Throttler(this._onResize.bind(this), 500);
335
+ }
336
+ /**
337
+ * Dispose of the widget and its descendant widgets.
338
+ */
339
+ dispose() {
340
+ if (this.isDisposed) {
341
+ return;
342
+ }
343
+ if (this._resizer) {
344
+ this._resizer.dispose();
345
+ }
346
+ super.dispose();
347
+ }
348
+ /**
349
+ * Insert an item into the toolbar at the after a target item.
350
+ *
351
+ * @param at - The target item to insert after.
352
+ *
353
+ * @param name - The name of the item.
354
+ *
355
+ * @param widget - The widget to add.
356
+ *
357
+ * @returns Whether the item was added to the toolbar. Returns false if
358
+ * an item of the same name is already in the toolbar or if the target
359
+ * is the toolbar pop-up opener.
360
+ *
361
+ * #### Notes
362
+ * The index will be clamped to the bounds of the items.
363
+ * The item can be removed from the toolbar by setting its parent to `null`.
364
+ */
365
+ insertAfter(at, name, widget) {
366
+ if (at === TOOLBAR_OPENER_NAME) {
367
+ return false;
368
+ }
369
+ return super.insertAfter(at, name, widget);
370
+ }
371
+ /**
372
+ * Insert an item into the toolbar at the specified index.
373
+ *
374
+ * @param index - The index at which to insert the item.
375
+ *
376
+ * @param name - The name of the item.
377
+ *
378
+ * @param widget - The widget to add.
379
+ *
380
+ * @returns Whether the item was added to the toolbar. Returns false if
381
+ * an item of the same name is already in the toolbar.
382
+ *
383
+ * #### Notes
384
+ * The index will be clamped to the bounds of the items.
385
+ * The item can be removed from the toolbar by setting its parent to `null`.
386
+ */
387
+ insertItem(index, name, widget) {
388
+ if (widget instanceof ToolbarPopupOpener) {
389
+ return super.insertItem(index, name, widget);
390
+ }
391
+ else {
392
+ const j = Math.max(0, Math.min(index, this.layout.widgets.length - 1));
393
+ return super.insertItem(j, name, widget);
394
+ }
395
+ }
396
+ /**
397
+ * A message handler invoked on a `'before-hide'` message.
398
+ *
399
+ * It will hide the pop-up panel
400
+ */
401
+ onBeforeHide(msg) {
402
+ this.popupOpener.hidePopup();
403
+ super.onBeforeHide(msg);
404
+ }
405
+ onResize(msg) {
406
+ super.onResize(msg);
407
+ if (msg.width > 0 && this._resizer) {
408
+ void this._resizer.invoke();
409
+ }
410
+ }
411
+ _onResize() {
412
+ if (this.parent && this.parent.isAttached) {
413
+ const toolbarWidth = this.node.clientWidth;
414
+ const opener = this.popupOpener;
415
+ const openerWidth = 30;
416
+ const toolbarPadding = 2;
417
+ const layout = this.layout;
418
+ let width = opener.isHidden
419
+ ? toolbarPadding
420
+ : toolbarPadding + openerWidth;
421
+ let index = 0;
422
+ const widgetsToRemove = [];
423
+ const toIndex = layout.widgets.length - 1;
424
+ while (index < toIndex) {
425
+ const widget = layout.widgets[index];
426
+ this._saveWidgetWidth(widget);
427
+ width += this._getWidgetWidth(widget);
428
+ if (widgetsToRemove.length === 0 &&
429
+ opener.isHidden &&
430
+ width + openerWidth > toolbarWidth) {
431
+ width += openerWidth;
432
+ }
433
+ if (width > toolbarWidth) {
434
+ widgetsToRemove.push(widget);
435
+ }
436
+ index++;
437
+ }
438
+ while (widgetsToRemove.length > 0) {
439
+ const widget = widgetsToRemove.pop();
440
+ width -= this._getWidgetWidth(widget);
441
+ opener.addWidget(widget);
442
+ }
443
+ if (opener.widgetCount() > 0) {
444
+ const widgetsToAdd = [];
445
+ let index = 0;
446
+ let widget = opener.widgetAt(index);
447
+ const widgetCount = opener.widgetCount();
448
+ width += this._getWidgetWidth(widget);
449
+ if (widgetCount === 1 && width - openerWidth <= toolbarWidth) {
450
+ width -= openerWidth;
451
+ }
452
+ while (width < toolbarWidth && index < widgetCount) {
453
+ widgetsToAdd.push(widget);
454
+ index++;
455
+ widget = opener.widgetAt(index);
456
+ if (widget) {
457
+ width += this._getWidgetWidth(widget);
458
+ }
459
+ else {
460
+ break;
461
+ }
462
+ }
463
+ while (widgetsToAdd.length > 0) {
464
+ const widget = widgetsToAdd.shift();
465
+ this.addItem(Private.nameProperty.get(widget), widget);
466
+ }
467
+ }
468
+ if (opener.widgetCount() > 0) {
469
+ opener.updatePopup();
470
+ opener.show();
471
+ }
472
+ else {
473
+ opener.hide();
474
+ }
475
+ }
476
+ }
477
+ _saveWidgetWidth(widget) {
478
+ const widgetName = Private.nameProperty.get(widget);
479
+ this._widgetWidths[widgetName] = widget.hasClass(TOOLBAR_SPACER_CLASS)
480
+ ? 2
481
+ : widget.node.clientWidth;
482
+ }
483
+ _getWidgetWidth(widget) {
484
+ const widgetName = Private.nameProperty.get(widget);
485
+ return this._widgetWidths[widgetName];
486
+ }
487
+ }
16
488
  /**
17
489
  * The namespace for Toolbar class statics.
18
490
  */
19
- export var Toolbar;
20
491
  (function (Toolbar) {
21
492
  /**
22
493
  * Create an interrupt toolbar item.
@@ -55,6 +526,17 @@ export var Toolbar;
55
526
  });
56
527
  }
57
528
  Toolbar.createRestartButton = createRestartButton;
529
+ /**
530
+ * Create a toolbar spacer item.
531
+ *
532
+ * #### Notes
533
+ * It is a flex spacer that separates the left toolbar items
534
+ * from the right toolbar items.
535
+ */
536
+ function createSpacerItem() {
537
+ return new Private.Spacer();
538
+ }
539
+ Toolbar.createSpacerItem = createSpacerItem;
58
540
  /**
59
541
  * Create a kernel name indicator item.
60
542
  *
@@ -81,11 +563,390 @@ export var Toolbar;
81
563
  }
82
564
  Toolbar.createKernelStatusItem = createKernelStatusItem;
83
565
  })(Toolbar || (Toolbar = {}));
566
+ /**
567
+ * React component for a toolbar button.
568
+ *
569
+ * @param props - The props for ToolbarButtonComponent.
570
+ */
571
+ export function ToolbarButtonComponent(props) {
572
+ var _a, _b;
573
+ // In some browsers, a button click event moves the focus from the main
574
+ // content to the button (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus).
575
+ // We avoid a click event by calling preventDefault in mousedown, and
576
+ // we bind the button action to `mousedown`.
577
+ const handleMouseDown = (event) => {
578
+ var _a;
579
+ // Fire action only when left button is pressed.
580
+ if (event.button === 0) {
581
+ event.preventDefault();
582
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
583
+ }
584
+ };
585
+ const handleKeyDown = (event) => {
586
+ var _a;
587
+ const { key } = event;
588
+ if (key === 'Enter' || key === ' ') {
589
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
590
+ }
591
+ };
592
+ const handleClick = (event) => {
593
+ var _a;
594
+ if (event.button === 0) {
595
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
596
+ }
597
+ };
598
+ const getTooltip = () => {
599
+ if (props.enabled === false && props.disabledTooltip) {
600
+ return props.disabledTooltip;
601
+ }
602
+ else if (props.pressed && props.pressedTooltip) {
603
+ return props.pressedTooltip;
604
+ }
605
+ else {
606
+ return props.tooltip || props.iconLabel;
607
+ }
608
+ };
609
+ return (React.createElement(Button, { className: props.className
610
+ ? props.className + ' jp-ToolbarButtonComponent'
611
+ : 'jp-ToolbarButtonComponent', "aria-pressed": props.pressed, "aria-disabled": props.enabled === false, disabled: props.enabled === false, onClick: ((_a = props.actualOnClick) !== null && _a !== void 0 ? _a : false) ? handleClick : undefined, onMouseDown: !((_b = props.actualOnClick) !== null && _b !== void 0 ? _b : false) ? handleMouseDown : undefined, onKeyDown: handleKeyDown, title: getTooltip(), minimal: true },
612
+ (props.icon || props.iconClass) && (React.createElement(LabIcon.resolveReact, { icon: props.pressed ? props.pressedIcon : props.icon, iconClass:
613
+ // add some extra classes for proper support of icons-as-css-background
614
+ classes(props.iconClass, 'jp-Icon'), className: "jp-ToolbarButtonComponent-icon", tag: "span", stylesheet: "toolbarButton" })),
615
+ props.label && (React.createElement("span", { className: "jp-ToolbarButtonComponent-label" }, props.label))));
616
+ }
617
+ /**
618
+ * Adds the toolbar button class to the toolbar widget.
619
+ * @param w Toolbar button widget.
620
+ */
621
+ export function addToolbarButtonClass(w) {
622
+ w.addClass('jp-ToolbarButton');
623
+ return w;
624
+ }
625
+ /**
626
+ * Phosphor Widget version of static ToolbarButtonComponent.
627
+ */
628
+ export class ToolbarButton extends ReactWidget {
629
+ /**
630
+ * Creates a toolbar button
631
+ * @param props props for underlying `ToolbarButton` component
632
+ */
633
+ constructor(props = {}) {
634
+ var _a, _b;
635
+ super();
636
+ this.props = props;
637
+ addToolbarButtonClass(this);
638
+ this._enabled = (_a = props.enabled) !== null && _a !== void 0 ? _a : true;
639
+ this._pressed = this._enabled && ((_b = props.pressed) !== null && _b !== void 0 ? _b : false);
640
+ this._onClick = props.onClick;
641
+ }
642
+ /**
643
+ * Sets the pressed state for the button
644
+ * @param value true if button is pressed, false otherwise
645
+ */
646
+ set pressed(value) {
647
+ if (this.enabled && value !== this._pressed) {
648
+ this._pressed = value;
649
+ this.update();
650
+ }
651
+ }
652
+ /**
653
+ * Returns true if button is pressed, false otherwise
654
+ */
655
+ get pressed() {
656
+ return this._pressed;
657
+ }
658
+ /**
659
+ * Sets the enabled state for the button
660
+ * @param value true to enable the button, false otherwise
661
+ */
662
+ set enabled(value) {
663
+ if (value != this._enabled) {
664
+ this._enabled = value;
665
+ if (!this._enabled) {
666
+ this._pressed = false;
667
+ }
668
+ this.update();
669
+ }
670
+ }
671
+ /**
672
+ * Returns true if button is enabled, false otherwise
673
+ */
674
+ get enabled() {
675
+ return this._enabled;
676
+ }
677
+ /**
678
+ * Sets the click handler for the button
679
+ * @param value click handler
680
+ */
681
+ set onClick(value) {
682
+ if (value !== this._onClick) {
683
+ this._onClick = value;
684
+ this.update();
685
+ }
686
+ }
687
+ /**
688
+ * Returns the click handler for the button
689
+ */
690
+ get onClick() {
691
+ return this._onClick;
692
+ }
693
+ render() {
694
+ return (React.createElement(ToolbarButtonComponent, Object.assign({}, this.props, { pressed: this.pressed, enabled: this.enabled, onClick: this.onClick })));
695
+ }
696
+ }
697
+ /**
698
+ * React component for a toolbar button that wraps a command.
699
+ *
700
+ * This wraps the ToolbarButtonComponent and watches the command registry
701
+ * for changes to the command.
702
+ */
703
+ export function CommandToolbarButtonComponent(props) {
704
+ return (React.createElement(UseSignal, { signal: props.commands.commandChanged, shouldUpdate: (sender, args) => (args.id === props.id && args.type === 'changed') ||
705
+ args.type === 'many-changed' }, () => React.createElement(ToolbarButtonComponent, Object.assign({}, Private.propsFromCommand(props)))));
706
+ }
707
+ /*
708
+ * Adds the command toolbar button class to the command toolbar widget.
709
+ * @param w Command toolbar button widget.
710
+ */
711
+ export function addCommandToolbarButtonClass(w) {
712
+ w.addClass('jp-CommandToolbarButton');
713
+ return w;
714
+ }
715
+ /**
716
+ * Phosphor Widget version of CommandToolbarButtonComponent.
717
+ */
718
+ export class CommandToolbarButton extends ReactWidget {
719
+ /**
720
+ * Creates a command toolbar button
721
+ * @param props props for underlying `CommandToolbarButtonComponent` component
722
+ */
723
+ constructor(props) {
724
+ super();
725
+ this.props = props;
726
+ addCommandToolbarButtonClass(this);
727
+ }
728
+ render() {
729
+ return React.createElement(CommandToolbarButtonComponent, Object.assign({}, this.props));
730
+ }
731
+ }
732
+ /**
733
+ * A class which provides a toolbar popup
734
+ * used to store widgets that don't fit
735
+ * in the toolbar when it is resized
736
+ */
737
+ class ToolbarPopup extends Widget {
738
+ /**
739
+ * Construct a new ToolbarPopup
740
+ */
741
+ constructor() {
742
+ super();
743
+ this.width = 0;
744
+ this.addClass('jp-Toolbar-responsive-popup');
745
+ this.layout = new PanelLayout();
746
+ Widget.attach(this, document.body);
747
+ this.hide();
748
+ }
749
+ /**
750
+ * Updates the width of the popup, this
751
+ * should match with the toolbar width
752
+ *
753
+ * @param width - The width to resize to
754
+ * @protected
755
+ */
756
+ updateWidth(width) {
757
+ if (width > 0) {
758
+ this.width = width;
759
+ this.node.style.width = `${width}px`;
760
+ }
761
+ }
762
+ /**
763
+ * Aligns the popup to left bottom of widget
764
+ *
765
+ * @param widget the widget to align to
766
+ * @private
767
+ */
768
+ alignTo(widget) {
769
+ const { height: widgetHeight, width: widgetWidth, x: widgetX, y: widgetY } = widget.node.getBoundingClientRect();
770
+ const width = this.width;
771
+ this.node.style.left = `${widgetX + widgetWidth - width + 1}px`;
772
+ this.node.style.top = `${widgetY + widgetHeight + 1}px`;
773
+ }
774
+ /**
775
+ * Inserts the widget at specified index
776
+ * @param index the index
777
+ * @param widget widget to add
778
+ */
779
+ insertWidget(index, widget) {
780
+ this.layout.insertWidget(0, widget);
781
+ }
782
+ /**
783
+ * Total number of widgets in the popup
784
+ */
785
+ widgetCount() {
786
+ return this.layout.widgets.length;
787
+ }
788
+ /**
789
+ * Returns the widget at index
790
+ * @param index the index
791
+ */
792
+ widgetAt(index) {
793
+ return this.layout.widgets[index];
794
+ }
795
+ }
796
+ /**
797
+ * A class that provides a ToolbarPopupOpener,
798
+ * which is a button added to toolbar when
799
+ * the toolbar items overflow toolbar width
800
+ */
801
+ class ToolbarPopupOpener extends ToolbarButton {
802
+ /**
803
+ * Create a new popup opener
804
+ */
805
+ constructor() {
806
+ super({
807
+ icon: ellipsesIcon,
808
+ onClick: () => {
809
+ this.handleClick();
810
+ }
811
+ });
812
+ this.addClass('jp-Toolbar-responsive-opener');
813
+ this.popup = new ToolbarPopup();
814
+ }
815
+ /**
816
+ * Add widget to the popup, prepends widgets
817
+ * @param widget the widget to add
818
+ */
819
+ addWidget(widget) {
820
+ this.popup.insertWidget(0, widget);
821
+ }
822
+ /**
823
+ * Dispose of the widget and its descendant widgets.
824
+ *
825
+ * #### Notes
826
+ * It is unsafe to use the widget after it has been disposed.
827
+ *
828
+ * All calls made to this method after the first are a no-op.
829
+ */
830
+ dispose() {
831
+ if (this.isDisposed) {
832
+ return;
833
+ }
834
+ this.popup.dispose();
835
+ super.dispose();
836
+ }
837
+ /**
838
+ * Hides the opener and the popup
839
+ */
840
+ hide() {
841
+ super.hide();
842
+ this.hidePopup();
843
+ }
844
+ /**
845
+ * Hides the popup
846
+ */
847
+ hidePopup() {
848
+ this.popup.hide();
849
+ }
850
+ /**
851
+ * Updates width and position of the popup
852
+ * to align with the toolbar
853
+ */
854
+ updatePopup() {
855
+ this.popup.updateWidth(this.parent.node.clientWidth);
856
+ this.popup.alignTo(this.parent);
857
+ }
858
+ /**
859
+ * Returns widget at index in the popup
860
+ * @param index
861
+ */
862
+ widgetAt(index) {
863
+ return this.popup.widgetAt(index);
864
+ }
865
+ /**
866
+ * Returns total number of widgets in the popup
867
+ *
868
+ * @returns Number of widgets
869
+ */
870
+ widgetCount() {
871
+ return this.popup.widgetCount();
872
+ }
873
+ handleClick() {
874
+ this.updatePopup();
875
+ this.popup.setHidden(!this.popup.isHidden);
876
+ }
877
+ }
84
878
  /**
85
879
  * A namespace for private data.
86
880
  */
87
881
  var Private;
88
882
  (function (Private) {
883
+ function propsFromCommand(options) {
884
+ var _a, _b;
885
+ const { commands, id, args } = options;
886
+ const iconClass = commands.iconClass(id, args);
887
+ const iconLabel = commands.iconLabel(id, args);
888
+ // DEPRECATED: remove _icon when lumino 2.0 is adopted
889
+ // if icon is aliasing iconClass, don't use it
890
+ const _icon = (_a = options.icon) !== null && _a !== void 0 ? _a : commands.icon(id, args);
891
+ const icon = _icon === iconClass ? undefined : _icon;
892
+ const label = commands.label(id, args);
893
+ let className = commands.className(id, args);
894
+ // Add the boolean state classes.
895
+ if (commands.isToggled(id, args)) {
896
+ className += ' lm-mod-toggled';
897
+ }
898
+ if (!commands.isVisible(id, args)) {
899
+ className += ' lm-mod-hidden';
900
+ }
901
+ let tooltip = commands.caption(id, args) || options.label || label || iconLabel;
902
+ // Shows hot keys in tooltips
903
+ const binding = commands.keyBindings.find(b => b.command === id);
904
+ if (binding) {
905
+ const ks = CommandRegistry.formatKeystroke(binding.keys.join(' '));
906
+ tooltip = `${tooltip} (${ks})`;
907
+ }
908
+ const onClick = () => {
909
+ void commands.execute(id, args);
910
+ };
911
+ const enabled = commands.isEnabled(id, args);
912
+ return {
913
+ className,
914
+ icon,
915
+ iconClass,
916
+ tooltip,
917
+ onClick,
918
+ enabled,
919
+ label: (_b = options.label) !== null && _b !== void 0 ? _b : label
920
+ };
921
+ }
922
+ Private.propsFromCommand = propsFromCommand;
923
+ /**
924
+ * An attached property for the name of a toolbar item.
925
+ */
926
+ Private.nameProperty = new AttachedProperty({
927
+ name: 'name',
928
+ create: () => ''
929
+ });
930
+ /**
931
+ * A no-op function.
932
+ */
933
+ function noOp() {
934
+ /* no-op */
935
+ }
936
+ Private.noOp = noOp;
937
+ /**
938
+ * A spacer widget.
939
+ */
940
+ class Spacer extends Widget {
941
+ /**
942
+ * Construct a new spacer widget.
943
+ */
944
+ constructor() {
945
+ super();
946
+ this.addClass(TOOLBAR_SPACER_CLASS);
947
+ }
948
+ }
949
+ Private.Spacer = Spacer;
89
950
  /**
90
951
  * React component for a kernel name button.
91
952
  *