@jupyterlab/ui-components 4.1.0-alpha.2 → 4.1.0-alpha.4

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.
@@ -16,6 +16,7 @@ import { ArrayExt } from '@lumino/algorithm';
16
16
  import { PromiseDelegate } from '@lumino/coreutils';
17
17
  import { IDisposable } from '@lumino/disposable';
18
18
  import { Message, MessageLoop } from '@lumino/messaging';
19
+ import { Throttler } from '@lumino/polling';
19
20
  import { ISignal, Signal } from '@lumino/signaling';
20
21
  import { PanelLayout, Widget } from '@lumino/widgets';
21
22
 
@@ -89,6 +90,32 @@ export abstract class WindowedListModel implements WindowedList.IModel {
89
90
  */
90
91
  abstract widgetRenderer: (index: number) => Widget;
91
92
 
93
+ /**
94
+ * The overlap threshold used to decide whether to scroll down to an item
95
+ * below the viewport (smart mode). If the item overlap with the viewport
96
+ * is greater or equal this threshold the item is considered sufficiently
97
+ * visible and will not be scrolled to. The value is the number of pixels
98
+ * in overlap if greater than one, or otherwise a fraction of item height.
99
+ * By default the item is scrolled to if not full visible in the viewport.
100
+ */
101
+ readonly scrollDownThreshold: number = 1;
102
+
103
+ /**
104
+ * The underlap threshold used to decide whether to scroll up to an item
105
+ * above the viewport (smart mode). If the item part outside the viewport
106
+ * (underlap) is greater than this threshold then the item is considered
107
+ * not sufficiently visible and will be scrolled to.
108
+ * The value is the number of pixels in underlap if greater than one, or
109
+ * otherwise a fraction of the item height.
110
+ * By default the item is scrolled to if not full visible in the viewport.
111
+ */
112
+ readonly scrollUpThreshold: number = 0;
113
+
114
+ /**
115
+ * Top padding of the the outer window node.
116
+ */
117
+ paddingTop: number = 0;
118
+
92
119
  /**
93
120
  * List widget height
94
121
  */
@@ -265,29 +292,41 @@ export abstract class WindowedListModel implements WindowedList.IModel {
265
292
  /**
266
293
  * Get the scroll offset to display an item in the viewport.
267
294
  *
268
- * By default, the list will scroll as little as possible to ensure the item is visible. You can control the alignment of the item though by specifying a second alignment parameter. Acceptable values are:
295
+ * By default, the list will scroll as little as possible to ensure the item is fully visible. You can control the alignment of the item though by specifying a second alignment parameter. Acceptable values are:
269
296
  *
270
- * auto (default) - Scroll as little as possible to ensure the item is visible. (If the item is already visible, it won't scroll at all.)
271
- * smart - If the item is already visible (including the margin), don't scroll at all. If it is less than one viewport away, scroll so that it becomes visible (including the margin). If it is more than one viewport away, scroll so that it is centered within the list.
297
+ * auto (default) - Automatically align with the top or bottom minimising the amount scrolled; if item is smaller than the viewport and fully visible, do not scroll at all.
298
+ * smart - If the item is significantly visible, don't scroll at all (regardless of whether it fits in the viewport). If it is less than one viewport away or exceeds viewport in height, scroll so that it becomes visible. If it is more than one viewport away and fits the viewport, scroll so that it is centered within the viewport.
272
299
  * center - Center align the item within the list.
273
300
  * end - Align the item to the end of the list
274
301
  * start - Align the item to the beginning of the list
275
302
  *
303
+ * An item is considered significantly visible if:
304
+ * - it overlaps with the viewport by the amount specified by `scrollDownThreshold` when below the viewport
305
+ * - it exceeds the viewport by the amount less than specified by `scrollUpThreshold` when above the viewport.
306
+ *
276
307
  * @param index Item index
277
308
  * @param align Where to align the item in the viewport
278
- * @param margin In 'smart' mode the viewport proportion to add
309
+ * @param margin The proportion of viewport to add when aligning with the top/bottom of the list.
279
310
  * @returns The needed scroll offset
280
311
  */
281
312
  getOffsetForIndexAndAlignment(
282
313
  index: number,
283
314
  align: WindowedList.ScrollToAlign = 'auto',
284
- margin: number = 0.25
315
+ margin: number = 0
285
316
  ): number {
286
- const boundedMargin =
287
- align === 'smart' ? Math.min(Math.max(0.0, margin), 1.0) : 0.0;
317
+ const boundedMargin = Math.min(Math.max(0.0, margin), 1.0);
288
318
  const size = this._height;
289
319
  const itemMetadata = this._getItemMetadata(index);
290
320
 
321
+ const scrollDownThreshold =
322
+ this.scrollDownThreshold <= 1
323
+ ? itemMetadata.size * this.scrollDownThreshold
324
+ : this.scrollDownThreshold;
325
+ const scrollUpThreshold =
326
+ this.scrollUpThreshold <= 1
327
+ ? itemMetadata.size * this.scrollUpThreshold
328
+ : this.scrollUpThreshold;
329
+
291
330
  // Get estimated total size after ItemMetadata is computed,
292
331
  // To ensure it reflects actual measurements instead of just estimates.
293
332
  const estimatedTotalSize = this.getEstimatedTotalSize();
@@ -300,37 +339,62 @@ export abstract class WindowedListModel implements WindowedList.IModel {
300
339
  0,
301
340
  itemMetadata.offset - size + itemMetadata.size
302
341
  );
303
-
342
+ const currentOffset = this._scrollOffset;
343
+
344
+ const itemTop = itemMetadata.offset;
345
+ const itemBottom = itemMetadata.offset + itemMetadata.size;
346
+ const bottomEdge = currentOffset - this.paddingTop + size;
347
+ const topEdge = currentOffset - this.paddingTop;
348
+ const crossingBottomEdge = bottomEdge > itemTop && bottomEdge < itemBottom;
349
+ const crossingTopEdge = topEdge > itemTop && topEdge < itemBottom;
304
350
  if (align === 'smart') {
351
+ const edgeLessThanOneViewportAway =
352
+ currentOffset >= bottomOffset - size &&
353
+ currentOffset <= topOffset + size;
354
+
355
+ const visiblePartBottom = bottomEdge - itemTop;
356
+ const hiddenPartTop = topEdge - itemTop;
357
+
305
358
  if (
306
- this._scrollOffset >= bottomOffset - size &&
307
- this._scrollOffset <= topOffset + size
359
+ (crossingBottomEdge && visiblePartBottom >= scrollDownThreshold) ||
360
+ (crossingTopEdge && hiddenPartTop < scrollUpThreshold)
308
361
  ) {
362
+ return this._scrollOffset;
363
+ } else if (edgeLessThanOneViewportAway) {
364
+ // Possibly less than one viewport away, scroll so that it becomes visible (including the margin)
309
365
  align = 'auto';
310
366
  } else {
311
- align = 'center';
367
+ // More than one viewport away, scroll so that it is centered within the list,
368
+ // unless the widget is larger than the viewport, in which case only scroll to
369
+ // align with the top or bottom edge (automatically)
370
+ if (itemMetadata.size > size) {
371
+ align = 'auto';
372
+ } else {
373
+ align = 'center';
374
+ }
375
+ }
376
+ }
377
+
378
+ if (align === 'auto') {
379
+ if (bottomEdge > itemBottom && topEdge < itemTop) {
380
+ // No need to change the position, return the current offset.
381
+ return this._scrollOffset;
382
+ } else if (crossingBottomEdge || bottomEdge <= itemBottom) {
383
+ align = 'end';
384
+ } else {
385
+ align = 'start';
312
386
  }
313
387
  }
314
388
 
315
389
  switch (align) {
316
390
  case 'start':
317
- return topOffset;
391
+ // Align to the top edge.
392
+ return Math.max(0, topOffset - boundedMargin * size) + this.paddingTop;
318
393
  case 'end':
319
- return bottomOffset;
394
+ // Align to the bottom edge.
395
+ return bottomOffset + boundedMargin * size + this.paddingTop;
320
396
  case 'center':
321
397
  return Math.round(bottomOffset + (topOffset - bottomOffset) / 2);
322
- case 'auto':
323
- default:
324
- if (
325
- this._scrollOffset >= bottomOffset &&
326
- this._scrollOffset <= itemMetadata.offset
327
- ) {
328
- return this._scrollOffset;
329
- } else if (this._scrollOffset < bottomOffset) {
330
- return bottomOffset + boundedMargin * size;
331
- } else {
332
- return Math.max(0, topOffset - boundedMargin * size);
333
- }
334
398
  }
335
399
  }
336
400
 
@@ -688,6 +752,7 @@ export class WindowedList<
688
752
  this._scrollToItem = null;
689
753
  this._scrollRepaint = null;
690
754
  this._scrollUpdateWasRequested = false;
755
+ this._updater = new Throttler(() => this.update(), 50);
691
756
  this._resizeObserver = null;
692
757
 
693
758
  this._viewModel.stateChanged.connect(this.onStateChanged, this);
@@ -727,6 +792,14 @@ export class WindowedList<
727
792
  return this._viewModel;
728
793
  }
729
794
 
795
+ /**
796
+ * Dispose the windowed list.
797
+ */
798
+ dispose(): void {
799
+ this._updater.dispose();
800
+ super.dispose();
801
+ }
802
+
730
803
  /**
731
804
  * Callback on event.
732
805
  *
@@ -832,6 +905,8 @@ export class WindowedList<
832
905
  this._applyNoWindowingStyles();
833
906
  }
834
907
  this.viewModel.height = this.node.getBoundingClientRect().height;
908
+ const style = window.getComputedStyle(this.node);
909
+ this.viewModel.paddingTop = parseFloat(style.paddingTop);
835
910
  }
836
911
 
837
912
  /**
@@ -880,8 +955,12 @@ export class WindowedList<
880
955
  * A message handler invoked on an `'resize-request'` message.
881
956
  */
882
957
  protected onResize(msg: Widget.ResizeMessage): void {
958
+ const previousHeight = this.viewModel.height;
883
959
  this.viewModel.height =
884
960
  msg.height >= 0 ? msg.height : this.node.getBoundingClientRect().height;
961
+ if (this.viewModel.height !== previousHeight) {
962
+ void this._updater.invoke();
963
+ }
885
964
  super.onResize(msg);
886
965
  }
887
966
 
@@ -1114,6 +1193,7 @@ export class WindowedList<
1114
1193
  private _scrollRepaint: number | null;
1115
1194
  private _scrollToItem: [number, WindowedList.ScrollToAlign] | null;
1116
1195
  private _scrollUpdateWasRequested: boolean;
1196
+ private _updater: Throttler;
1117
1197
  }
1118
1198
 
1119
1199
  /**
@@ -1331,6 +1411,11 @@ export namespace WindowedList {
1331
1411
  */
1332
1412
  height: number;
1333
1413
 
1414
+ /**
1415
+ * Top padding of the the outer window node.
1416
+ */
1417
+ paddingTop?: number;
1418
+
1334
1419
  /**
1335
1420
  * Items list to be rendered
1336
1421
  */
@@ -53,6 +53,7 @@ import filterListSvgstr from '../../style/icons/toolbar/filter-list.svg';
53
53
  import filterSvgstr from '../../style/icons/search/filter.svg';
54
54
  import folderFavoriteSvgstr from '../../style/icons/filetype/folder-favorite.svg';
55
55
  import folderSvgstr from '../../style/icons/filetype/folder.svg';
56
+ import historySvgstr from '../../style/icons/history.svg';
56
57
  import homeSvgstr from '../../style/icons/filetype/home.svg';
57
58
  import html5Svgstr from '../../style/icons/filetype/html5.svg';
58
59
  import imageSvgstr from '../../style/icons/filetype/image.svg';
@@ -158,6 +159,7 @@ export const filterIcon = new LabIcon({ name: 'ui-components:filter', svgstr: fi
158
159
  export const filterListIcon = new LabIcon({ name: 'ui-components:filter-list', svgstr: filterListSvgstr });
159
160
  export const folderFavoriteIcon = new LabIcon({ name: 'ui-components:folder-favorite', svgstr: folderFavoriteSvgstr });
160
161
  export const folderIcon = new LabIcon({ name: 'ui-components:folder', svgstr: folderSvgstr });
162
+ export const historyIcon = new LabIcon({ name: 'ui-components:history', svgstr: historySvgstr });
161
163
  export const homeIcon = new LabIcon({ name: 'ui-components:home', svgstr: homeSvgstr });
162
164
  export const html5Icon = new LabIcon({ name: 'ui-components:html5', svgstr: html5Svgstr });
163
165
  export const imageIcon = new LabIcon({ name: 'ui-components:image', svgstr: imageSvgstr });
@@ -332,28 +332,39 @@ export class LabIcon implements LabIcon.ILabIcon, VirtualElement.IRenderer {
332
332
  return document.createElement('div');
333
333
  }
334
334
 
335
- let returnSvgElement = true;
336
335
  if (container) {
337
336
  // take ownership by removing any existing children
338
337
  while (container.firstChild) {
339
338
  container.firstChild.remove();
340
339
  }
341
- } else {
340
+ } else if (tag) {
342
341
  // create a container if needed
343
342
  container = document.createElement(tag);
343
+ }
344
344
 
345
- returnSvgElement = false;
345
+ const svgElement = this.svgElement.cloneNode(true) as HTMLElement;
346
+ if (!container) {
347
+ if (label) {
348
+ console.warn();
349
+ }
350
+ return svgElement;
346
351
  }
352
+
347
353
  if (label != null) {
348
354
  container.textContent = label;
349
355
  }
350
- Private.initContainer({ container, className, styleProps, title });
356
+
357
+ Private.initContainer({
358
+ container: container!,
359
+ className,
360
+ styleProps,
361
+ title
362
+ });
351
363
 
352
364
  // add the svg node to the container
353
- const svgElement = this.svgElement.cloneNode(true) as HTMLElement;
354
365
  container.appendChild(svgElement);
355
366
 
356
- return returnSvgElement ? svgElement : container;
367
+ return container;
357
368
  }
358
369
 
359
370
  render(container: HTMLElement, options?: LabIcon.IRendererOptions): void {
@@ -468,7 +479,7 @@ export class LabIcon implements LabIcon.ILabIcon, VirtualElement.IRenderer {
468
479
  });
469
480
 
470
481
  // make it so that tag can be used as a jsx component
471
- const Tag = tag;
482
+ const Tag = tag ?? React.Fragment;
472
483
 
473
484
  // ensure that svg html is valid
474
485
  if (!(this.svgInnerHTML && this.svgReactAttrs)) {
@@ -494,15 +505,18 @@ export class LabIcon implements LabIcon.ILabIcon, VirtualElement.IRenderer {
494
505
  </React.Fragment>
495
506
  );
496
507
  } else {
497
- return (
498
- <Tag
499
- className={
508
+ let attributes = {};
509
+ if (Tag !== React.Fragment) {
510
+ attributes = {
511
+ className:
500
512
  className || styleProps
501
513
  ? classes(className, LabIconStyle.styleClass(styleProps))
502
- : undefined
503
- }
504
- title={title}
505
- >
514
+ : undefined,
515
+ title: title
516
+ };
517
+ }
518
+ return (
519
+ <Tag {...attributes}>
506
520
  {svgComponent}
507
521
  {label}
508
522
  </Tag>
@@ -670,8 +684,12 @@ export namespace LabIcon {
670
684
  /**
671
685
  * HTML element tag used to create the icon's outermost container node,
672
686
  * if no container is passed in
687
+ *
688
+ * #### Notes
689
+ * If `null` is provided and no container is defined, the icon SVG will return directly
690
+ * ignoring all other attributes (label, title,...)
673
691
  */
674
- tag?: 'div' | 'span';
692
+ tag?: 'div' | 'span' | null;
675
693
 
676
694
  /**
677
695
  * Optional title that will be set on the icon's outermost container node
@@ -741,7 +759,7 @@ namespace Private {
741
759
  }
742
760
  } else {
743
761
  // create a container if needed
744
- container = document.createElement(tag);
762
+ container = document.createElement(tag ?? 'div');
745
763
  }
746
764
  if (label != null) {
747
765
  container.textContent = label;
@@ -764,7 +782,7 @@ namespace Private {
764
782
  ref: LabIcon.IReactRef
765
783
  ) => {
766
784
  // make it so that tag can be used as a jsx component
767
- const Tag = tag;
785
+ const Tag = tag ?? 'div';
768
786
 
769
787
  if (container) {
770
788
  initContainer({ container, className, styleProps, title });
@@ -57,6 +57,7 @@
57
57
  --jp-icon-filter: url('icons/search/filter.svg');
58
58
  --jp-icon-folder-favorite: url('icons/filetype/folder-favorite.svg');
59
59
  --jp-icon-folder: url('icons/filetype/folder.svg');
60
+ --jp-icon-history: url('icons/history.svg');
60
61
  --jp-icon-home: url('icons/filetype/home.svg');
61
62
  --jp-icon-html5: url('icons/filetype/html5.svg');
62
63
  --jp-icon-image: url('icons/filetype/image.svg');
@@ -299,6 +300,10 @@
299
300
  background-image: var(--jp-icon-folder);
300
301
  }
301
302
 
303
+ .jp-HistoryIcon {
304
+ background-image: var(--jp-icon-history);
305
+ }
306
+
302
307
  .jp-HomeIcon {
303
308
  background-image: var(--jp-icon-home);
304
309
  }
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" viewBox="0 0 24 24">
2
+ <g class="jp-icon3" fill="#616161"><path d="M13.5,8H12V13L16.28,15.54L17,14.33L13.5,12.25V8M13,3A9,9 0 0,0 4,12H1L4.96,16.03L9,12H6A7,7 0 0,1 13,5A7,7 0 0,1 20,12A7,7 0 0,1 13,19C11.07,19 9.32,18.21 8.06,16.94L6.64,18.36C8.27,20 10.5,21 13,21A9,9 0 0,0 22,12A9,9 0 0,0 13,3" /></g>
3
+ </svg>
package/style/toolbar.css CHANGED
@@ -5,67 +5,48 @@
5
5
 
6
6
  :root {
7
7
  --jp-private-toolbar-height: calc(
8
- 28px + var(--jp-border-width)
8
+ 31px + var(--jp-border-width)
9
9
  ); /* leave 28px for content */
10
10
  }
11
11
 
12
+ .jp-MainAreaWidget > .jp-Toolbar {
13
+ border-radius: 0;
14
+ }
15
+
12
16
  .jp-Toolbar {
17
+ /* Increase density for toolbar */
18
+ --design-unit: 3.5;
19
+ --toolbar-item-gap: 0;
20
+
13
21
  color: var(--jp-ui-font-color1);
14
- flex: 0 0 auto;
15
- display: flex;
16
- flex-direction: row;
17
22
  border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
18
23
  box-shadow: var(--jp-toolbar-box-shadow);
19
24
  background: var(--jp-toolbar-background);
20
25
  min-height: var(--jp-toolbar-micro-height);
21
26
  padding: 2px;
22
27
  z-index: 8;
23
- overflow-x: hidden;
24
28
  }
25
29
 
26
30
  /* Toolbar items */
27
31
 
28
- .jp-Toolbar > .jp-Toolbar-item.jp-Toolbar-spacer {
29
- flex-grow: 1;
30
- flex-shrink: 1;
31
- }
32
-
33
- .jp-Toolbar-item.jp-Toolbar-kernelStatus {
34
- display: inline-block;
35
- width: 32px;
36
- background-repeat: no-repeat;
37
- background-position: center;
38
- background-size: 16px;
39
- }
40
-
41
32
  .jp-Toolbar > .jp-Toolbar-item {
42
- flex: 0 0 auto;
43
- display: flex;
44
- padding-left: 1px;
45
- padding-right: 1px;
46
- font-size: var(--jp-ui-font-size1);
47
- line-height: var(--jp-private-toolbar-height);
33
+ /* Center the items in toolbar */
48
34
  height: 100%;
49
- }
35
+ display: flex;
36
+ align-items: center;
50
37
 
51
- /* Toolbar buttons */
38
+ /* Increase density for toolbar items */
39
+ --density: -4;
40
+ }
52
41
 
53
- /* This is the div we use to wrap the react component into a Widget */
54
- div.jp-ToolbarButton {
55
- color: transparent;
56
- border: none;
57
- box-sizing: border-box;
58
- outline: none;
59
- appearance: none;
60
- -webkit-appearance: none;
61
- -moz-appearance: none;
62
- padding: 0;
63
- margin: 0;
42
+ .jp-Toolbar::part(positioning-region) {
43
+ align-items: center;
64
44
  }
65
45
 
66
- button.jp-ToolbarButtonComponent,
67
46
  .jp-ToolbarLabelComponent {
68
47
  background: var(--jp-layout-color1);
48
+ background-color: var(--jp-brand-color1);
49
+ color: var(--jp-ui-inverse-font-color1);
69
50
  border: none;
70
51
  box-sizing: border-box;
71
52
  outline: none;
@@ -79,18 +60,10 @@ button.jp-ToolbarButtonComponent,
79
60
  display: flex;
80
61
  align-items: center;
81
62
  text-align: center;
82
- font-size: 14px;
63
+ font-size: var(--jp-ui-font-size0);
83
64
  min-width: unset;
84
65
  min-height: unset;
85
- }
86
-
87
- button.jp-ToolbarButtonComponent:disabled {
88
- opacity: 0.4;
89
- }
90
-
91
- button.jp-ToolbarButtonComponent > span {
92
- padding: 0;
93
- flex: 0 0 auto;
66
+ user-select: none;
94
67
  }
95
68
 
96
69
  button.jp-ToolbarButtonComponent .jp-ToolbarButtonComponent-label {
@@ -101,11 +74,25 @@ button.jp-ToolbarButtonComponent .jp-ToolbarButtonComponent-label {
101
74
  font-family: var(--jp-ui-font-family);
102
75
  }
103
76
 
104
- .jp-ToolbarLabelComponent {
105
- background-color: var(--jp-brand-color1);
106
- color: var(--jp-ui-inverse-font-color1);
107
- font-size: var(--jp-ui-font-size0);
108
- user-select: none;
77
+ .jp-ToolbarButtonComponent::part(content) {
78
+ display: flex;
79
+ align-items: center;
80
+ }
81
+
82
+ .jp-Toolbar > .jp-Toolbar-item.jp-Toolbar-spacer {
83
+ flex-grow: 1;
84
+ flex-shrink: 1;
85
+ }
86
+
87
+ .jp-Toolbar-responsive-popup {
88
+ position: absolute;
89
+ height: fit-content;
90
+ border-bottom: var(--jp-border-width) solid var(--jp-toolbar-border-color);
91
+ box-shadow: var(--jp-toolbar-box-shadow);
92
+ background: var(--jp-toolbar-background);
93
+ z-index: 1;
94
+ right: 0;
95
+ top: 0;
109
96
  }
110
97
 
111
98
  #jp-main-dock-panel[data-mode='single-document']