@jupyterlab/ui-components 3.3.0-alpha.6 → 3.3.0-beta.0

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 (54) hide show
  1. package/lib/FormComponentRegistry.d.ts +56 -0
  2. package/lib/FormComponentRegistry.js +44 -0
  3. package/lib/FormComponentRegistry.js.map +1 -0
  4. package/lib/blueprint.js +1 -1
  5. package/lib/blueprint.js.map +1 -1
  6. package/lib/components/index.d.ts +0 -6
  7. package/lib/components/index.js +0 -6
  8. package/lib/components/index.js.map +1 -1
  9. package/lib/components/menu.d.ts +19 -6
  10. package/lib/components/menu.js +138 -3
  11. package/lib/components/menu.js.map +1 -1
  12. package/lib/icon/iconimports.d.ts +2 -0
  13. package/lib/icon/iconimports.js +4 -0
  14. package/lib/icon/iconimports.js.map +1 -1
  15. package/lib/icon/labicon.d.ts +1 -1
  16. package/lib/icon/labicon.js +1 -2
  17. package/lib/icon/labicon.js.map +1 -1
  18. package/lib/index.d.ts +1 -0
  19. package/lib/index.js +1 -0
  20. package/lib/index.js.map +1 -1
  21. package/lib/style/icon.js +1 -2
  22. package/lib/style/icon.js.map +1 -1
  23. package/lib/utils.d.ts +1 -3
  24. package/lib/utils.js +1 -3
  25. package/lib/utils.js.map +1 -1
  26. package/package.json +5 -8
  27. package/style/base.css +0 -5
  28. package/style/deprecated.css +8 -0
  29. package/style/icons/toolbar/bug-dot.svg +6 -0
  30. package/style/icons/toolbar/launch.svg +6 -0
  31. package/style/icons.css +0 -11
  32. package/lib/components/collapse.d.ts +0 -64
  33. package/lib/components/collapse.js +0 -145
  34. package/lib/components/collapse.js.map +0 -1
  35. package/lib/components/iframe.d.ts +0 -77
  36. package/lib/components/iframe.js +0 -89
  37. package/lib/components/iframe.js.map +0 -1
  38. package/lib/components/spinner.d.ts +0 -15
  39. package/lib/components/spinner.js +0 -28
  40. package/lib/components/spinner.js.map +0 -1
  41. package/lib/components/styling.d.ts +0 -27
  42. package/lib/components/styling.js +0 -100
  43. package/lib/components/styling.js.map +0 -1
  44. package/lib/components/toolbar.d.ts +0 -320
  45. package/lib/components/toolbar.js +0 -718
  46. package/lib/components/toolbar.js.map +0 -1
  47. package/lib/components/vdom.d.ts +0 -189
  48. package/lib/components/vdom.js +0 -203
  49. package/lib/components/vdom.js.map +0 -1
  50. package/style/collapse.css +0 -30
  51. package/style/iframe.css +0 -33
  52. package/style/spinner.css +0 -79
  53. package/style/styling.css +0 -89
  54. package/style/toolbar.css +0 -115
@@ -1,718 +0,0 @@
1
- // Copyright (c) Jupyter Development Team.
2
- // Distributed under the terms of the Modified BSD License.
3
- import { find, map, some } from '@lumino/algorithm';
4
- import { CommandRegistry } from '@lumino/commands';
5
- import { MessageLoop } from '@lumino/messaging';
6
- import { AttachedProperty } from '@lumino/properties';
7
- import { PanelLayout, Widget } from '@lumino/widgets';
8
- import { Throttler } from '@lumino/polling';
9
- import * as React from 'react';
10
- import { Button } from '../blueprint';
11
- import { ellipsesIcon, LabIcon } from '../icon';
12
- import { classes } from '../utils';
13
- import { ReactWidget, UseSignal } from './vdom';
14
- /**
15
- * The class name added to toolbars.
16
- */
17
- const TOOLBAR_CLASS = 'jp-Toolbar';
18
- /**
19
- * The class name added to toolbar items.
20
- */
21
- const TOOLBAR_ITEM_CLASS = 'jp-Toolbar-item';
22
- /**
23
- * The class name added to toolbar spacer.
24
- */
25
- const TOOLBAR_SPACER_CLASS = 'jp-Toolbar-spacer';
26
- /**
27
- * A layout for toolbars.
28
- *
29
- * #### Notes
30
- * This layout automatically collapses its height if there are no visible
31
- * toolbar widgets, and expands to the standard toolbar height if there are
32
- * visible toolbar widgets.
33
- */
34
- class ToolbarLayout extends PanelLayout {
35
- constructor() {
36
- super(...arguments);
37
- this._dirty = false;
38
- }
39
- /**
40
- * A message handler invoked on a `'fit-request'` message.
41
- *
42
- * If any child widget is visible, expand the toolbar height to the normal
43
- * toolbar height.
44
- */
45
- onFitRequest(msg) {
46
- super.onFitRequest(msg);
47
- if (this.parent.isAttached) {
48
- // If there are any widgets not explicitly hidden, expand the toolbar to
49
- // accommodate them.
50
- if (some(this.widgets, w => !w.isHidden)) {
51
- this.parent.node.style.minHeight = 'var(--jp-private-toolbar-height)';
52
- this.parent.removeClass('jp-Toolbar-micro');
53
- }
54
- else {
55
- this.parent.node.style.minHeight = '';
56
- this.parent.addClass('jp-Toolbar-micro');
57
- }
58
- }
59
- // Set the dirty flag to ensure only a single update occurs.
60
- this._dirty = true;
61
- // Notify the ancestor that it should fit immediately. This may
62
- // cause a resize of the parent, fulfilling the required update.
63
- if (this.parent.parent) {
64
- MessageLoop.sendMessage(this.parent.parent, Widget.Msg.FitRequest);
65
- }
66
- // If the dirty flag is still set, the parent was not resized.
67
- // Trigger the required update on the parent widget immediately.
68
- if (this._dirty) {
69
- MessageLoop.sendMessage(this.parent, Widget.Msg.UpdateRequest);
70
- }
71
- }
72
- /**
73
- * A message handler invoked on an `'update-request'` message.
74
- */
75
- onUpdateRequest(msg) {
76
- super.onUpdateRequest(msg);
77
- if (this.parent.isVisible) {
78
- this._dirty = false;
79
- }
80
- }
81
- /**
82
- * A message handler invoked on a `'child-shown'` message.
83
- */
84
- onChildShown(msg) {
85
- super.onChildShown(msg);
86
- // Post a fit request for the parent widget.
87
- this.parent.fit();
88
- }
89
- /**
90
- * A message handler invoked on a `'child-hidden'` message.
91
- */
92
- onChildHidden(msg) {
93
- super.onChildHidden(msg);
94
- // Post a fit request for the parent widget.
95
- this.parent.fit();
96
- }
97
- /**
98
- * A message handler invoked on a `'before-attach'` message.
99
- */
100
- onBeforeAttach(msg) {
101
- super.onBeforeAttach(msg);
102
- // Post a fit request for the parent widget.
103
- this.parent.fit();
104
- }
105
- /**
106
- * Attach a widget to the parent's DOM node.
107
- *
108
- * @param index - The current index of the widget in the layout.
109
- *
110
- * @param widget - The widget to attach to the parent.
111
- *
112
- * #### Notes
113
- * This is a reimplementation of the superclass method.
114
- */
115
- attachWidget(index, widget) {
116
- super.attachWidget(index, widget);
117
- // Post a fit request for the parent widget.
118
- this.parent.fit();
119
- }
120
- /**
121
- * Detach a widget from the parent's DOM node.
122
- *
123
- * @param index - The previous index of the widget in the layout.
124
- *
125
- * @param widget - The widget to detach from the parent.
126
- *
127
- * #### Notes
128
- * This is a reimplementation of the superclass method.
129
- */
130
- detachWidget(index, widget) {
131
- super.detachWidget(index, widget);
132
- // Post a fit request for the parent widget.
133
- this.parent.fit();
134
- }
135
- }
136
- /**
137
- * A class which provides a toolbar widget.
138
- */
139
- export class Toolbar extends Widget {
140
- /**
141
- * Construct a new toolbar widget.
142
- */
143
- constructor() {
144
- super();
145
- this.popupOpener = new ToolbarPopupOpener();
146
- this._widgetWidths = {};
147
- this.addClass(TOOLBAR_CLASS);
148
- this.layout = new ToolbarLayout();
149
- this.insertItem(0, 'toolbar-popup-opener', this.popupOpener);
150
- this.popupOpener.hide();
151
- this._resizer = new Throttler(this._onResize.bind(this), 500);
152
- }
153
- /**
154
- * Get an iterator over the ordered toolbar item names.
155
- *
156
- * @returns An iterator over the toolbar item names.
157
- */
158
- names() {
159
- const layout = this.layout;
160
- return map(layout.widgets, widget => {
161
- return Private.nameProperty.get(widget);
162
- });
163
- }
164
- /**
165
- * Add an item to the end of the toolbar.
166
- *
167
- * @param name - The name of the widget to add to the toolbar.
168
- *
169
- * @param widget - The widget to add to the toolbar.
170
- *
171
- * @param index - The optional name of the item to insert after.
172
- *
173
- * @returns Whether the item was added to toolbar. Returns false if
174
- * an item of the same name is already in the toolbar.
175
- *
176
- * #### Notes
177
- * The item can be removed from the toolbar by setting its parent to `null`.
178
- */
179
- addItem(name, widget) {
180
- const layout = this.layout;
181
- return this.insertItem(layout.widgets.length - 1, name, widget);
182
- }
183
- /**
184
- * Dispose of the widget and its descendant widgets.
185
- */
186
- dispose() {
187
- if (this.isDisposed) {
188
- return;
189
- }
190
- if (this._resizer) {
191
- this._resizer.dispose();
192
- }
193
- super.dispose();
194
- }
195
- /**
196
- * Insert an item into the toolbar at the specified index.
197
- *
198
- * @param index - The index at which to insert the item.
199
- *
200
- * @param name - The name of the item.
201
- *
202
- * @param widget - The widget to add.
203
- *
204
- * @returns Whether the item was added to the toolbar. Returns false if
205
- * an item of the same name is already in the toolbar.
206
- *
207
- * #### Notes
208
- * The index will be clamped to the bounds of the items.
209
- * The item can be removed from the toolbar by setting its parent to `null`.
210
- */
211
- insertItem(index, name, widget) {
212
- const existing = find(this.names(), value => value === name);
213
- if (existing) {
214
- return false;
215
- }
216
- widget.addClass(TOOLBAR_ITEM_CLASS);
217
- const layout = this.layout;
218
- if (widget instanceof ToolbarPopupOpener) {
219
- layout.insertWidget(index, widget);
220
- }
221
- else {
222
- const j = Math.max(0, Math.min(index, layout.widgets.length - 1));
223
- layout.insertWidget(j, widget);
224
- }
225
- Private.nameProperty.set(widget, name);
226
- return true;
227
- }
228
- /**
229
- * Insert an item into the toolbar at the after a target item.
230
- *
231
- * @param at - The target item to insert after.
232
- *
233
- * @param name - The name of the item.
234
- *
235
- * @param widget - The widget to add.
236
- *
237
- * @returns Whether the item was added to the toolbar. Returns false if
238
- * an item of the same name is already in the toolbar.
239
- *
240
- * #### Notes
241
- * The index will be clamped to the bounds of the items.
242
- * The item can be removed from the toolbar by setting its parent to `null`.
243
- */
244
- insertAfter(at, name, widget) {
245
- return this._insertRelative(at, 1, name, widget);
246
- }
247
- /**
248
- * Insert an item into the toolbar at the before a target item.
249
- *
250
- * @param at - The target item to insert before.
251
- *
252
- * @param name - The name of the item.
253
- *
254
- * @param widget - The widget to add.
255
- *
256
- * @returns Whether the item was added to the toolbar. Returns false if
257
- * an item of the same name is already in the toolbar.
258
- *
259
- * #### Notes
260
- * The index will be clamped to the bounds of the items.
261
- * The item can be removed from the toolbar by setting its parent to `null`.
262
- */
263
- insertBefore(at, name, widget) {
264
- return this._insertRelative(at, 0, name, widget);
265
- }
266
- _insertRelative(at, offset, name, widget) {
267
- const nameWithIndex = map(this.names(), (name, i) => {
268
- return { name: name, index: i };
269
- });
270
- const target = find(nameWithIndex, x => x.name === at);
271
- if (target && !(target instanceof ToolbarPopupOpener)) {
272
- return this.insertItem(target.index + offset, name, widget);
273
- }
274
- return false;
275
- }
276
- /**
277
- * Handle the DOM events for the widget.
278
- *
279
- * @param event - The DOM event sent to the widget.
280
- *
281
- * #### Notes
282
- * This method implements the DOM `EventListener` interface and is
283
- * called in response to events on the dock panel's node. It should
284
- * not be called directly by user code.
285
- */
286
- handleEvent(event) {
287
- switch (event.type) {
288
- case 'click':
289
- this.handleClick(event);
290
- break;
291
- default:
292
- break;
293
- }
294
- }
295
- /**
296
- * Handle a DOM click event.
297
- */
298
- handleClick(event) {
299
- // Clicking a label focuses the corresponding control
300
- // that is linked with `for` attribute, so let it be.
301
- if (event.target instanceof HTMLLabelElement) {
302
- const forId = event.target.getAttribute('for');
303
- if (forId && this.node.querySelector(`#${forId}`)) {
304
- return;
305
- }
306
- }
307
- // If this click already focused a control, let it be.
308
- if (this.node.contains(document.activeElement)) {
309
- return;
310
- }
311
- // Otherwise, activate the parent widget, which may take focus if desired.
312
- if (this.parent) {
313
- this.parent.activate();
314
- }
315
- }
316
- /**
317
- * Handle `after-attach` messages for the widget.
318
- */
319
- onAfterAttach(msg) {
320
- this.node.addEventListener('click', this);
321
- }
322
- /**
323
- * Handle `before-detach` messages for the widget.
324
- */
325
- onBeforeDetach(msg) {
326
- this.node.removeEventListener('click', this);
327
- }
328
- onResize(msg) {
329
- super.onResize(msg);
330
- if (msg.width > 0 && this._resizer) {
331
- void this._resizer.invoke();
332
- }
333
- }
334
- _onResize() {
335
- if (this.parent && this.parent.isAttached) {
336
- const toolbarWidth = this.node.clientWidth;
337
- const opener = this.popupOpener;
338
- const openerWidth = 30;
339
- const toolbarPadding = 2;
340
- const layout = this.layout;
341
- let width = opener.isHidden
342
- ? toolbarPadding
343
- : toolbarPadding + openerWidth;
344
- let index = 0;
345
- const widgetsToRemove = [];
346
- const toIndex = layout.widgets.length - 1;
347
- while (index < toIndex) {
348
- const widget = layout.widgets[index];
349
- this._saveWidgetWidth(widget);
350
- width += this._getWidgetWidth(widget);
351
- if (widgetsToRemove.length === 0 &&
352
- opener.isHidden &&
353
- width + openerWidth > toolbarWidth) {
354
- width += openerWidth;
355
- }
356
- if (width > toolbarWidth) {
357
- widgetsToRemove.push(widget);
358
- }
359
- index++;
360
- }
361
- while (widgetsToRemove.length > 0) {
362
- const widget = widgetsToRemove.pop();
363
- width -= this._getWidgetWidth(widget);
364
- opener.addWidget(widget);
365
- }
366
- if (opener.widgetCount() > 0) {
367
- const widgetsToAdd = [];
368
- let index = 0;
369
- let widget = opener.widgetAt(index);
370
- const widgetCount = opener.widgetCount();
371
- width += this._getWidgetWidth(widget);
372
- if (widgetCount === 1 && width - openerWidth <= toolbarWidth) {
373
- width -= openerWidth;
374
- }
375
- while (width < toolbarWidth && index < widgetCount) {
376
- widgetsToAdd.push(widget);
377
- index++;
378
- widget = opener.widgetAt(index);
379
- if (widget) {
380
- width += this._getWidgetWidth(widget);
381
- }
382
- else {
383
- break;
384
- }
385
- }
386
- while (widgetsToAdd.length > 0) {
387
- const widget = widgetsToAdd.shift();
388
- this.addItem(Private.nameProperty.get(widget), widget);
389
- }
390
- }
391
- if (opener.widgetCount() > 0) {
392
- opener.updatePopup();
393
- opener.show();
394
- }
395
- else {
396
- opener.hide();
397
- }
398
- }
399
- }
400
- _saveWidgetWidth(widget) {
401
- const widgetName = Private.nameProperty.get(widget);
402
- this._widgetWidths[widgetName] = widget.hasClass(TOOLBAR_SPACER_CLASS)
403
- ? 2
404
- : widget.node.clientWidth;
405
- }
406
- _getWidgetWidth(widget) {
407
- const widgetName = Private.nameProperty.get(widget);
408
- return this._widgetWidths[widgetName];
409
- }
410
- }
411
- /**
412
- * The namespace for Toolbar class statics.
413
- */
414
- (function (Toolbar) {
415
- /**
416
- * Create a toolbar spacer item.
417
- *
418
- * #### Notes
419
- * It is a flex spacer that separates the left toolbar items
420
- * from the right toolbar items.
421
- */
422
- function createSpacerItem() {
423
- return new Private.Spacer();
424
- }
425
- Toolbar.createSpacerItem = createSpacerItem;
426
- })(Toolbar || (Toolbar = {}));
427
- /**
428
- * React component for a toolbar button.
429
- *
430
- * @param props - The props for ToolbarButtonComponent.
431
- */
432
- export function ToolbarButtonComponent(props) {
433
- var _a, _b;
434
- // In some browsers, a button click event moves the focus from the main
435
- // content to the button (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus).
436
- // We avoid a click event by calling preventDefault in mousedown, and
437
- // we bind the button action to `mousedown`.
438
- const handleMouseDown = (event) => {
439
- var _a;
440
- // Fire action only when left button is pressed.
441
- if (event.button === 0) {
442
- event.preventDefault();
443
- (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
444
- }
445
- };
446
- const handleKeyDown = (event) => {
447
- var _a;
448
- const { key } = event;
449
- if (key === 'Enter' || key === ' ') {
450
- (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
451
- }
452
- };
453
- const handleClick = (event) => {
454
- var _a;
455
- if (event.button === 0) {
456
- (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);
457
- }
458
- };
459
- return (React.createElement(Button, { className: props.className
460
- ? props.className + ' jp-ToolbarButtonComponent'
461
- : 'jp-ToolbarButtonComponent', 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: props.tooltip || props.iconLabel, minimal: true },
462
- (props.icon || props.iconClass) && (React.createElement(LabIcon.resolveReact, { icon: props.icon, iconClass:
463
- // add some extra classes for proper support of icons-as-css-background
464
- classes(props.iconClass, 'jp-Icon'), className: "jp-ToolbarButtonComponent-icon", tag: "span", stylesheet: "toolbarButton" })),
465
- props.label && (React.createElement("span", { className: "jp-ToolbarButtonComponent-label" }, props.label))));
466
- }
467
- /**
468
- * Adds the toolbar button class to the toolbar widget.
469
- * @param w Toolbar button widget.
470
- */
471
- export function addToolbarButtonClass(w) {
472
- w.addClass('jp-ToolbarButton');
473
- return w;
474
- }
475
- /**
476
- * Phosphor Widget version of static ToolbarButtonComponent.
477
- */
478
- export class ToolbarButton extends ReactWidget {
479
- /**
480
- * Creates a toolbar button
481
- * @param props props for underlying `ToolbarButton` component
482
- */
483
- constructor(props = {}) {
484
- super();
485
- this.props = props;
486
- addToolbarButtonClass(this);
487
- }
488
- render() {
489
- return React.createElement(ToolbarButtonComponent, Object.assign({}, this.props));
490
- }
491
- }
492
- /**
493
- * React component for a toolbar button that wraps a command.
494
- *
495
- * This wraps the ToolbarButtonComponent and watches the command registry
496
- * for changes to the command.
497
- */
498
- export function CommandToolbarButtonComponent(props) {
499
- return (React.createElement(UseSignal, { signal: props.commands.commandChanged, shouldUpdate: (sender, args) => (args.id === props.id && args.type === 'changed') ||
500
- args.type === 'many-changed' }, () => React.createElement(ToolbarButtonComponent, Object.assign({}, Private.propsFromCommand(props)))));
501
- }
502
- /*
503
- * Adds the command toolbar button class to the command toolbar widget.
504
- * @param w Command toolbar button widget.
505
- */
506
- export function addCommandToolbarButtonClass(w) {
507
- w.addClass('jp-CommandToolbarButton');
508
- return w;
509
- }
510
- /**
511
- * Phosphor Widget version of CommandToolbarButtonComponent.
512
- */
513
- export class CommandToolbarButton extends ReactWidget {
514
- /**
515
- * Creates a command toolbar button
516
- * @param props props for underlying `CommandToolbarButtonComponent` component
517
- */
518
- constructor(props) {
519
- super();
520
- this.props = props;
521
- addCommandToolbarButtonClass(this);
522
- }
523
- render() {
524
- return React.createElement(CommandToolbarButtonComponent, Object.assign({}, this.props));
525
- }
526
- }
527
- /**
528
- * A class which provides a toolbar popup
529
- * used to store widgets that don't fit
530
- * in the toolbar when it is resized
531
- */
532
- class ToolbarPopup extends Widget {
533
- /**
534
- * Construct a new ToolbarPopup
535
- */
536
- constructor() {
537
- super();
538
- this.width = 0;
539
- this.addClass('jp-Toolbar-responsive-popup');
540
- this.layout = new PanelLayout();
541
- Widget.attach(this, document.body);
542
- this.hide();
543
- }
544
- /**
545
- * Updates the width of the popup, this
546
- * should match with the toolbar width
547
- *
548
- * @param width - The width to resize to
549
- * @protected
550
- */
551
- updateWidth(width) {
552
- if (width > 0) {
553
- this.width = width;
554
- this.node.style.width = `${width}px`;
555
- }
556
- }
557
- /**
558
- * Aligns the popup to left bottom of widget
559
- *
560
- * @param widget the widget to align to
561
- * @private
562
- */
563
- alignTo(widget) {
564
- const { height: widgetHeight, width: widgetWidth, x: widgetX, y: widgetY } = widget.node.getBoundingClientRect();
565
- const width = this.width;
566
- this.node.style.left = `${widgetX + widgetWidth - width + 1}px`;
567
- this.node.style.top = `${widgetY + widgetHeight + 1}px`;
568
- }
569
- /**
570
- * Inserts the widget at specified index
571
- * @param index the index
572
- * @param widget widget to add
573
- */
574
- insertWidget(index, widget) {
575
- this.layout.insertWidget(0, widget);
576
- }
577
- /**
578
- * Total number of widgets in the popup
579
- */
580
- widgetCount() {
581
- return this.layout.widgets.length;
582
- }
583
- /**
584
- * Returns the widget at index
585
- * @param index the index
586
- */
587
- widgetAt(index) {
588
- return this.layout.widgets[index];
589
- }
590
- }
591
- /**
592
- * A class that provides a ToolbarPopupOpener,
593
- * which is a button added to toolbar when
594
- * the toolbar items overflow toolbar width
595
- */
596
- class ToolbarPopupOpener extends ToolbarButton {
597
- /**
598
- * Create a new popup opener
599
- */
600
- constructor() {
601
- super({
602
- icon: ellipsesIcon,
603
- onClick: () => {
604
- this.handleClick();
605
- }
606
- });
607
- this.addClass('jp-Toolbar-responsive-opener');
608
- this._popup = new ToolbarPopup();
609
- }
610
- handleClick() {
611
- const popup = this._popup;
612
- popup.updateWidth(this.parent.node.clientWidth);
613
- popup.alignTo(this.parent);
614
- popup.setHidden(!popup.isHidden);
615
- }
616
- /**
617
- * Updates width and position of the popup
618
- * to align with the toolbar
619
- */
620
- updatePopup() {
621
- this._popup.updateWidth(this.parent.node.clientWidth);
622
- this._popup.alignTo(this.parent);
623
- }
624
- /**
625
- * Add widget to the popup, prepends widgets
626
- * @param widget the widget to add
627
- */
628
- addWidget(widget) {
629
- this._popup.insertWidget(0, widget);
630
- }
631
- /**
632
- * Returns total no of widgets in the popup
633
- */
634
- widgetCount() {
635
- return this._popup.widgetCount();
636
- }
637
- /**
638
- * Returns widget at index in the popup
639
- * @param index
640
- */
641
- widgetAt(index) {
642
- return this._popup.widgetAt(index);
643
- }
644
- /**
645
- * Hides the opener and the popup
646
- */
647
- hide() {
648
- super.hide();
649
- this._popup.hide();
650
- }
651
- }
652
- /**
653
- * A namespace for private data.
654
- */
655
- var Private;
656
- (function (Private) {
657
- function propsFromCommand(options) {
658
- var _a, _b;
659
- const { commands, id, args } = options;
660
- const iconClass = commands.iconClass(id, args);
661
- const iconLabel = commands.iconLabel(id, args);
662
- // DEPRECATED: remove _icon when lumino 2.0 is adopted
663
- // if icon is aliasing iconClass, don't use it
664
- const _icon = (_a = options.icon) !== null && _a !== void 0 ? _a : commands.icon(id, args);
665
- const icon = _icon === iconClass ? undefined : _icon;
666
- const label = commands.label(id, args);
667
- let className = commands.className(id, args);
668
- // Add the boolean state classes.
669
- if (commands.isToggled(id, args)) {
670
- className += ' lm-mod-toggled';
671
- }
672
- if (!commands.isVisible(id, args)) {
673
- className += ' lm-mod-hidden';
674
- }
675
- let tooltip = commands.caption(id, args) || options.label || label || iconLabel;
676
- // Shows hot keys in tooltips
677
- const binding = commands.keyBindings.find(b => b.command === id);
678
- if (binding) {
679
- const ks = CommandRegistry.formatKeystroke(binding.keys.join(' '));
680
- tooltip = `${tooltip} (${ks})`;
681
- }
682
- const onClick = () => {
683
- void commands.execute(id, args);
684
- };
685
- const enabled = commands.isEnabled(id, args);
686
- return {
687
- className,
688
- icon,
689
- iconClass,
690
- tooltip,
691
- onClick,
692
- enabled,
693
- label: (_b = options.label) !== null && _b !== void 0 ? _b : label
694
- };
695
- }
696
- Private.propsFromCommand = propsFromCommand;
697
- /**
698
- * An attached property for the name of a toolbar item.
699
- */
700
- Private.nameProperty = new AttachedProperty({
701
- name: 'name',
702
- create: () => ''
703
- });
704
- /**
705
- * A spacer widget.
706
- */
707
- class Spacer extends Widget {
708
- /**
709
- * Construct a new spacer widget.
710
- */
711
- constructor() {
712
- super();
713
- this.addClass(TOOLBAR_SPACER_CLASS);
714
- }
715
- }
716
- Private.Spacer = Spacer;
717
- })(Private || (Private = {}));
718
- //# sourceMappingURL=toolbar.js.map