@jupyterlab/ui-components 3.3.0-alpha.9 → 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 (52) 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 +10 -2
  10. package/lib/components/menu.js.map +1 -1
  11. package/lib/icon/iconimports.d.ts +1 -0
  12. package/lib/icon/iconimports.js +2 -0
  13. package/lib/icon/iconimports.js.map +1 -1
  14. package/lib/icon/labicon.d.ts +1 -1
  15. package/lib/icon/labicon.js +1 -2
  16. package/lib/icon/labicon.js.map +1 -1
  17. package/lib/index.d.ts +1 -0
  18. package/lib/index.js +1 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/style/icon.js +1 -1
  21. package/lib/style/icon.js.map +1 -1
  22. package/lib/utils.d.ts +1 -3
  23. package/lib/utils.js +1 -3
  24. package/lib/utils.js.map +1 -1
  25. package/package.json +5 -8
  26. package/style/base.css +0 -5
  27. package/style/deprecated.css +4 -0
  28. package/style/icons/toolbar/launch.svg +6 -0
  29. package/style/icons.css +0 -11
  30. package/lib/components/collapse.d.ts +0 -64
  31. package/lib/components/collapse.js +0 -145
  32. package/lib/components/collapse.js.map +0 -1
  33. package/lib/components/iframe.d.ts +0 -77
  34. package/lib/components/iframe.js +0 -89
  35. package/lib/components/iframe.js.map +0 -1
  36. package/lib/components/spinner.d.ts +0 -15
  37. package/lib/components/spinner.js +0 -28
  38. package/lib/components/spinner.js.map +0 -1
  39. package/lib/components/styling.d.ts +0 -27
  40. package/lib/components/styling.js +0 -100
  41. package/lib/components/styling.js.map +0 -1
  42. package/lib/components/toolbar.d.ts +0 -354
  43. package/lib/components/toolbar.js +0 -784
  44. package/lib/components/toolbar.js.map +0 -1
  45. package/lib/components/vdom.d.ts +0 -189
  46. package/lib/components/vdom.js +0 -203
  47. package/lib/components/vdom.js.map +0 -1
  48. package/style/collapse.css +0 -30
  49. package/style/iframe.css +0 -33
  50. package/style/spinner.css +0 -79
  51. package/style/styling.css +0 -89
  52. package/style/toolbar.css +0 -115
@@ -1,784 +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
- const getTooltip = () => {
460
- if (props.enabled === false && props.disabledTooltip) {
461
- return props.disabledTooltip;
462
- }
463
- else if (props.pressed && props.pressedTooltip) {
464
- return props.pressedTooltip;
465
- }
466
- else {
467
- return props.tooltip || props.iconLabel;
468
- }
469
- };
470
- return (React.createElement(Button, { className: props.className
471
- ? props.className + ' jp-ToolbarButtonComponent'
472
- : '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 },
473
- (props.icon || props.iconClass) && (React.createElement(LabIcon.resolveReact, { icon: props.pressed ? props.pressedIcon : props.icon, iconClass:
474
- // add some extra classes for proper support of icons-as-css-background
475
- classes(props.iconClass, 'jp-Icon'), className: "jp-ToolbarButtonComponent-icon", tag: "span", stylesheet: "toolbarButton" })),
476
- props.label && (React.createElement("span", { className: "jp-ToolbarButtonComponent-label" }, props.label))));
477
- }
478
- /**
479
- * Adds the toolbar button class to the toolbar widget.
480
- * @param w Toolbar button widget.
481
- */
482
- export function addToolbarButtonClass(w) {
483
- w.addClass('jp-ToolbarButton');
484
- return w;
485
- }
486
- /**
487
- * Phosphor Widget version of static ToolbarButtonComponent.
488
- */
489
- export class ToolbarButton extends ReactWidget {
490
- /**
491
- * Creates a toolbar button
492
- * @param props props for underlying `ToolbarButton` component
493
- */
494
- constructor(props = {}) {
495
- var _a, _b;
496
- super();
497
- this.props = props;
498
- addToolbarButtonClass(this);
499
- this._enabled = (_a = props.enabled) !== null && _a !== void 0 ? _a : true;
500
- this._pressed = this._enabled && ((_b = props.pressed) !== null && _b !== void 0 ? _b : false);
501
- this._onClick = props.onClick;
502
- }
503
- /**
504
- * Sets the pressed state for the button
505
- * @param value true if button is pressed, false otherwise
506
- */
507
- set pressed(value) {
508
- if (this.enabled && value !== this._pressed) {
509
- this._pressed = value;
510
- this.update();
511
- }
512
- }
513
- /**
514
- * Returns true if button is pressed, false otherwise
515
- */
516
- get pressed() {
517
- return this._pressed;
518
- }
519
- /**
520
- * Sets the enabled state for the button
521
- * @param value true to enable the button, false otherwise
522
- */
523
- set enabled(value) {
524
- if (value != this._enabled) {
525
- this._enabled = value;
526
- if (!this._enabled) {
527
- this._pressed = false;
528
- }
529
- this.update();
530
- }
531
- }
532
- /**
533
- * Returns true if button is enabled, false otherwise
534
- */
535
- get enabled() {
536
- return this._enabled;
537
- }
538
- /**
539
- * Sets the click handler for the button
540
- * @param value click handler
541
- */
542
- set onClick(value) {
543
- if (value !== this._onClick) {
544
- this._onClick = value;
545
- this.update();
546
- }
547
- }
548
- /**
549
- * Returns the click handler for the button
550
- */
551
- get onClick() {
552
- return this._onClick;
553
- }
554
- render() {
555
- return (React.createElement(ToolbarButtonComponent, Object.assign({}, this.props, { pressed: this.pressed, enabled: this.enabled, onClick: this.onClick })));
556
- }
557
- }
558
- /**
559
- * React component for a toolbar button that wraps a command.
560
- *
561
- * This wraps the ToolbarButtonComponent and watches the command registry
562
- * for changes to the command.
563
- */
564
- export function CommandToolbarButtonComponent(props) {
565
- return (React.createElement(UseSignal, { signal: props.commands.commandChanged, shouldUpdate: (sender, args) => (args.id === props.id && args.type === 'changed') ||
566
- args.type === 'many-changed' }, () => React.createElement(ToolbarButtonComponent, Object.assign({}, Private.propsFromCommand(props)))));
567
- }
568
- /*
569
- * Adds the command toolbar button class to the command toolbar widget.
570
- * @param w Command toolbar button widget.
571
- */
572
- export function addCommandToolbarButtonClass(w) {
573
- w.addClass('jp-CommandToolbarButton');
574
- return w;
575
- }
576
- /**
577
- * Phosphor Widget version of CommandToolbarButtonComponent.
578
- */
579
- export class CommandToolbarButton extends ReactWidget {
580
- /**
581
- * Creates a command toolbar button
582
- * @param props props for underlying `CommandToolbarButtonComponent` component
583
- */
584
- constructor(props) {
585
- super();
586
- this.props = props;
587
- addCommandToolbarButtonClass(this);
588
- }
589
- render() {
590
- return React.createElement(CommandToolbarButtonComponent, Object.assign({}, this.props));
591
- }
592
- }
593
- /**
594
- * A class which provides a toolbar popup
595
- * used to store widgets that don't fit
596
- * in the toolbar when it is resized
597
- */
598
- class ToolbarPopup extends Widget {
599
- /**
600
- * Construct a new ToolbarPopup
601
- */
602
- constructor() {
603
- super();
604
- this.width = 0;
605
- this.addClass('jp-Toolbar-responsive-popup');
606
- this.layout = new PanelLayout();
607
- Widget.attach(this, document.body);
608
- this.hide();
609
- }
610
- /**
611
- * Updates the width of the popup, this
612
- * should match with the toolbar width
613
- *
614
- * @param width - The width to resize to
615
- * @protected
616
- */
617
- updateWidth(width) {
618
- if (width > 0) {
619
- this.width = width;
620
- this.node.style.width = `${width}px`;
621
- }
622
- }
623
- /**
624
- * Aligns the popup to left bottom of widget
625
- *
626
- * @param widget the widget to align to
627
- * @private
628
- */
629
- alignTo(widget) {
630
- const { height: widgetHeight, width: widgetWidth, x: widgetX, y: widgetY } = widget.node.getBoundingClientRect();
631
- const width = this.width;
632
- this.node.style.left = `${widgetX + widgetWidth - width + 1}px`;
633
- this.node.style.top = `${widgetY + widgetHeight + 1}px`;
634
- }
635
- /**
636
- * Inserts the widget at specified index
637
- * @param index the index
638
- * @param widget widget to add
639
- */
640
- insertWidget(index, widget) {
641
- this.layout.insertWidget(0, widget);
642
- }
643
- /**
644
- * Total number of widgets in the popup
645
- */
646
- widgetCount() {
647
- return this.layout.widgets.length;
648
- }
649
- /**
650
- * Returns the widget at index
651
- * @param index the index
652
- */
653
- widgetAt(index) {
654
- return this.layout.widgets[index];
655
- }
656
- }
657
- /**
658
- * A class that provides a ToolbarPopupOpener,
659
- * which is a button added to toolbar when
660
- * the toolbar items overflow toolbar width
661
- */
662
- class ToolbarPopupOpener extends ToolbarButton {
663
- /**
664
- * Create a new popup opener
665
- */
666
- constructor() {
667
- super({
668
- icon: ellipsesIcon,
669
- onClick: () => {
670
- this.handleClick();
671
- }
672
- });
673
- this.addClass('jp-Toolbar-responsive-opener');
674
- this._popup = new ToolbarPopup();
675
- }
676
- handleClick() {
677
- const popup = this._popup;
678
- popup.updateWidth(this.parent.node.clientWidth);
679
- popup.alignTo(this.parent);
680
- popup.setHidden(!popup.isHidden);
681
- }
682
- /**
683
- * Updates width and position of the popup
684
- * to align with the toolbar
685
- */
686
- updatePopup() {
687
- this._popup.updateWidth(this.parent.node.clientWidth);
688
- this._popup.alignTo(this.parent);
689
- }
690
- /**
691
- * Add widget to the popup, prepends widgets
692
- * @param widget the widget to add
693
- */
694
- addWidget(widget) {
695
- this._popup.insertWidget(0, widget);
696
- }
697
- /**
698
- * Returns total no of widgets in the popup
699
- */
700
- widgetCount() {
701
- return this._popup.widgetCount();
702
- }
703
- /**
704
- * Returns widget at index in the popup
705
- * @param index
706
- */
707
- widgetAt(index) {
708
- return this._popup.widgetAt(index);
709
- }
710
- /**
711
- * Hides the opener and the popup
712
- */
713
- hide() {
714
- super.hide();
715
- this._popup.hide();
716
- }
717
- }
718
- /**
719
- * A namespace for private data.
720
- */
721
- var Private;
722
- (function (Private) {
723
- function propsFromCommand(options) {
724
- var _a, _b;
725
- const { commands, id, args } = options;
726
- const iconClass = commands.iconClass(id, args);
727
- const iconLabel = commands.iconLabel(id, args);
728
- // DEPRECATED: remove _icon when lumino 2.0 is adopted
729
- // if icon is aliasing iconClass, don't use it
730
- const _icon = (_a = options.icon) !== null && _a !== void 0 ? _a : commands.icon(id, args);
731
- const icon = _icon === iconClass ? undefined : _icon;
732
- const label = commands.label(id, args);
733
- let className = commands.className(id, args);
734
- // Add the boolean state classes.
735
- if (commands.isToggled(id, args)) {
736
- className += ' lm-mod-toggled';
737
- }
738
- if (!commands.isVisible(id, args)) {
739
- className += ' lm-mod-hidden';
740
- }
741
- let tooltip = commands.caption(id, args) || options.label || label || iconLabel;
742
- // Shows hot keys in tooltips
743
- const binding = commands.keyBindings.find(b => b.command === id);
744
- if (binding) {
745
- const ks = CommandRegistry.formatKeystroke(binding.keys.join(' '));
746
- tooltip = `${tooltip} (${ks})`;
747
- }
748
- const onClick = () => {
749
- void commands.execute(id, args);
750
- };
751
- const enabled = commands.isEnabled(id, args);
752
- return {
753
- className,
754
- icon,
755
- iconClass,
756
- tooltip,
757
- onClick,
758
- enabled,
759
- label: (_b = options.label) !== null && _b !== void 0 ? _b : label
760
- };
761
- }
762
- Private.propsFromCommand = propsFromCommand;
763
- /**
764
- * An attached property for the name of a toolbar item.
765
- */
766
- Private.nameProperty = new AttachedProperty({
767
- name: 'name',
768
- create: () => ''
769
- });
770
- /**
771
- * A spacer widget.
772
- */
773
- class Spacer extends Widget {
774
- /**
775
- * Construct a new spacer widget.
776
- */
777
- constructor() {
778
- super();
779
- this.addClass(TOOLBAR_SPACER_CLASS);
780
- }
781
- }
782
- Private.Spacer = Spacer;
783
- })(Private || (Private = {}));
784
- //# sourceMappingURL=toolbar.js.map