@jupyterlab/ui-components 4.3.0-alpha.0 → 4.3.0-alpha.2

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.
@@ -640,14 +640,14 @@ export class ReactiveToolbar extends Toolbar<Widget> {
640
640
  openerWidth: number
641
641
  ) {
642
642
  const opener = this.popupOpener;
643
- const layout = this.layout as ToolbarLayout;
644
- const toIndex = layout.widgets.length - 1;
643
+ const widgets = [...(this.layout as ToolbarLayout).widgets];
644
+ const toIndex = widgets.length - 1;
645
645
 
646
646
  const widgetsToRemove = [];
647
647
 
648
648
  let index = 0;
649
649
  while (index < toIndex) {
650
- const widget = layout.widgets[index];
650
+ const widget = widgets[index];
651
651
  const name = Private.nameProperty.get(widget);
652
652
  // Compute the widget size only if
653
653
  // - the zoom has changed.
@@ -863,7 +863,7 @@ export function ToolbarButtonComponent(
863
863
  onMouseDown={handleMouseDown}
864
864
  onKeyDown={handleKeyDown}
865
865
  title={title}
866
- minimal
866
+ scale="xsmall"
867
867
  >
868
868
  {(props.icon || props.iconClass) && (
869
869
  <LabIcon.resolveReact
@@ -1114,6 +1114,7 @@ class ToolbarPopup extends Widget {
1114
1114
  super({ node: document.createElement('jp-toolbar') });
1115
1115
  this.addClass('jp-Toolbar');
1116
1116
  this.addClass('jp-Toolbar-responsive-popup');
1117
+ this.addClass('jp-ThemedContainer');
1117
1118
  this.layout = new PanelLayout();
1118
1119
  Widget.attach(this, document.body);
1119
1120
  this.hide();
@@ -792,6 +792,13 @@ export class WindowedList<
792
792
  const scrollbarElement = node.appendChild(document.createElement('div'));
793
793
  scrollbarElement.classList.add('jp-WindowedPanel-scrollbar');
794
794
 
795
+ const indicator = scrollbarElement.appendChild(
796
+ renderer.createScrollbarViewportIndicator
797
+ ? renderer.createScrollbarViewportIndicator()
798
+ : WindowedList.defaultRenderer.createScrollbarViewportIndicator()
799
+ );
800
+ indicator.classList.add('jp-WindowedPanel-scrollbar-viewportIndicator');
801
+
795
802
  const list = scrollbarElement.appendChild(renderer.createScrollbar());
796
803
  list.classList.add('jp-WindowedPanel-scrollbar-content');
797
804
 
@@ -810,6 +817,7 @@ export class WindowedList<
810
817
  super.layout = options.layout ?? new WindowedLayout();
811
818
  this.renderer = renderer;
812
819
 
820
+ this._viewportIndicator = indicator;
813
821
  this._innerElement = innerElement;
814
822
  this._isScrolling = null;
815
823
  this._outerElement = outerElement;
@@ -828,6 +836,7 @@ export class WindowedList<
828
836
 
829
837
  this.viewModel.stateChanged.connect(this.onStateChanged, this);
830
838
  }
839
+ private _viewportIndicator: HTMLElement;
831
840
 
832
841
  /**
833
842
  * Whether the parent is hidden or not.
@@ -1033,8 +1042,10 @@ export class WindowedList<
1033
1042
  }
1034
1043
  this._addListeners();
1035
1044
  this.viewModel.height = this.node.getBoundingClientRect().height;
1036
- const style = window.getComputedStyle(this._viewport);
1037
- this.viewModel.paddingTop = parseFloat(style.paddingTop);
1045
+ const viewportStyle = window.getComputedStyle(this._viewport);
1046
+ this.viewModel.paddingTop = parseFloat(viewportStyle.paddingTop);
1047
+ this._viewportPaddingTop = this.viewModel.paddingTop;
1048
+ this._viewportPaddingBottom = parseFloat(viewportStyle.paddingBottom);
1038
1049
  this._scrollbarElement.addEventListener('pointerdown', this);
1039
1050
  }
1040
1051
 
@@ -1134,9 +1145,6 @@ export class WindowedList<
1134
1145
  * The default implementation of this handler is a no-op.
1135
1146
  */
1136
1147
  protected onUpdateRequest(msg: Message): void {
1137
- if (this.scrollbar) {
1138
- this._renderScrollbar();
1139
- }
1140
1148
  if (this.viewModel.windowingActive) {
1141
1149
  // Throttle update request
1142
1150
  if (this._scrollRepaint === null) {
@@ -1194,7 +1202,7 @@ export class WindowedList<
1194
1202
  } else {
1195
1203
  // Reset all styles that may have been touched.
1196
1204
  outer.style.width = '100%';
1197
- this._innerElement.style.marginRight = '0';
1205
+ this._innerElement.style.marginRight = '';
1198
1206
  outer.style.paddingRight = '0';
1199
1207
  outer.style.boxSizing = '';
1200
1208
  }
@@ -1239,6 +1247,7 @@ export class WindowedList<
1239
1247
  private _applyNoWindowingStyles() {
1240
1248
  this._viewport.style.position = 'relative';
1241
1249
  this._viewport.style.top = '0px';
1250
+ this._innerElement.style.height = '';
1242
1251
  }
1243
1252
  /**
1244
1253
  * Turn on windowing related styles in the viewport.
@@ -1271,7 +1280,18 @@ export class WindowedList<
1271
1280
  const newWindowIndex = this.viewModel.getRangeToRender();
1272
1281
 
1273
1282
  if (newWindowIndex !== null) {
1274
- const [startIndex, stopIndex] = newWindowIndex;
1283
+ const [startIndex, stopIndex, firstVisibleIndex, lastVisibleIndex] =
1284
+ newWindowIndex;
1285
+
1286
+ if (this.scrollbar) {
1287
+ const scrollbarItems = this._renderScrollbar();
1288
+ const first = scrollbarItems[firstVisibleIndex];
1289
+ const last = scrollbarItems[lastVisibleIndex];
1290
+ this._viewportIndicator.style.top = first.offsetTop - 1 + 'px';
1291
+ this._viewportIndicator.style.height =
1292
+ last.offsetTop - first.offsetTop + last.offsetHeight + 'px';
1293
+ }
1294
+
1275
1295
  const toAdd: Widget[] = [];
1276
1296
  if (stopIndex >= 0) {
1277
1297
  for (let index = startIndex; index <= stopIndex; index++) {
@@ -1438,24 +1458,67 @@ export class WindowedList<
1438
1458
  /**
1439
1459
  * Render virtual scrollbar.
1440
1460
  */
1441
- private _renderScrollbar(): void {
1461
+ private _renderScrollbar(): HTMLElement[] {
1442
1462
  const { node, renderer, viewModel } = this;
1443
1463
  const content = node.querySelector('.jp-WindowedPanel-scrollbar-content')!;
1444
1464
 
1445
- while (content.firstChild) {
1446
- content.removeChild(content.firstChild);
1447
- }
1465
+ const elements: HTMLElement[] = [];
1466
+
1467
+ const getElement = (
1468
+ item: ReturnType<WindowedList.IRenderer['createScrollbarItem']>,
1469
+ index: number
1470
+ ) => {
1471
+ if (item instanceof HTMLElement) {
1472
+ return item;
1473
+ } else {
1474
+ visitedKeys.add(item.key);
1475
+ const props = { index };
1476
+ const cachedItem = this._scrollbarItems[item.key];
1477
+ if (cachedItem && !cachedItem.isDisposed) {
1478
+ return cachedItem.render(props);
1479
+ } else {
1480
+ this._scrollbarItems[item.key] = item;
1481
+ const element = item.render(props);
1482
+ return element;
1483
+ }
1484
+ }
1485
+ };
1448
1486
 
1449
1487
  const list = viewModel.itemsList;
1450
1488
  const count = list?.length ?? viewModel.widgetCount;
1489
+ const visitedKeys = new Set<string>();
1451
1490
  for (let index = 0; index < count; index += 1) {
1452
- const item = list?.get?.(index);
1453
- const element = renderer.createScrollbarItem(this, index, item);
1491
+ const model = list?.get?.(index);
1492
+ const item = renderer.createScrollbarItem(this, index, model);
1493
+ const element: HTMLElement = getElement(item, index);
1454
1494
  element.classList.add('jp-WindowedPanel-scrollbar-item');
1455
1495
  element.dataset.index = `${index}`;
1456
- content.appendChild(element);
1496
+ elements.push(element);
1497
+ }
1498
+
1499
+ // dispose of any elements which are no longer in the scrollbar
1500
+ const keysNotSeen = Object.keys(this._scrollbarItems).filter(
1501
+ key => !visitedKeys.has(key)
1502
+ );
1503
+ for (const key of keysNotSeen) {
1504
+ this._scrollbarItems[key].dispose();
1505
+ delete this._scrollbarItems[key];
1506
+ }
1507
+
1508
+ const oldNodes = [...content.childNodes];
1509
+ if (
1510
+ oldNodes.length !== elements.length ||
1511
+ !oldNodes.every((node, index) => elements[index] === node)
1512
+ ) {
1513
+ content.replaceChildren(...elements);
1457
1514
  }
1515
+
1516
+ return elements;
1458
1517
  }
1518
+ private _scrollbarItems: Record<
1519
+ string,
1520
+ WindowedList.IRenderer.IScrollbarItem
1521
+ > = {};
1459
1522
 
1460
1523
  /**
1461
1524
  * Handle `pointerdown` events on the virtual scrollbar.
@@ -1480,13 +1543,18 @@ export class WindowedList<
1480
1543
  private _updateTotalSize(): void {
1481
1544
  if (this.viewModel.windowingActive) {
1482
1545
  const estimatedTotalHeight = this.viewModel.getEstimatedTotalSize();
1483
-
1546
+ const heightWithPadding =
1547
+ estimatedTotalHeight +
1548
+ this._viewportPaddingTop +
1549
+ this._viewportPaddingBottom;
1484
1550
  // Update inner container height
1485
- this._innerElement.style.height = `${estimatedTotalHeight}px`;
1551
+ this._innerElement.style.height = `${heightWithPadding}px`;
1486
1552
  }
1487
1553
  }
1488
1554
 
1489
1555
  protected _viewModel: T;
1556
+ private _viewportPaddingTop: number = 0;
1557
+ private _viewportPaddingBottom: number = 0;
1490
1558
  private _innerElement: HTMLElement;
1491
1559
  private _isParentHidden: boolean;
1492
1560
  private _isScrolling: PromiseDelegate<void> | null;
@@ -1682,6 +1750,13 @@ export namespace WindowedList {
1682
1750
  return document.createElement('ol');
1683
1751
  }
1684
1752
 
1753
+ /**
1754
+ * Create the virtual scrollbar viewport indicator.
1755
+ */
1756
+ createScrollbarViewportIndicator(): HTMLElement {
1757
+ return document.createElement('div');
1758
+ }
1759
+
1685
1760
  /**
1686
1761
  * Create an individual item rendered in the scrollbar.
1687
1762
  */
@@ -1943,6 +2018,11 @@ export namespace WindowedList {
1943
2018
  */
1944
2019
  createScrollbar(): HTMLElement;
1945
2020
 
2021
+ /**
2022
+ * Create the virtual scrollbar viewport indicator.
2023
+ */
2024
+ createScrollbarViewportIndicator?(): HTMLElement;
2025
+
1946
2026
  /**
1947
2027
  * Create an individual item rendered in the scrollbar.
1948
2028
  */
@@ -1950,7 +2030,7 @@ export namespace WindowedList {
1950
2030
  list: WindowedList,
1951
2031
  index: number,
1952
2032
  item: T | undefined
1953
- ): HTMLElement;
2033
+ ): HTMLElement | IRenderer.IScrollbarItem;
1954
2034
 
1955
2035
  /**
1956
2036
  * Create the viewport element into which virtualized children are added.
@@ -1958,6 +2038,26 @@ export namespace WindowedList {
1958
2038
  createViewport(): HTMLElement;
1959
2039
  }
1960
2040
 
2041
+ /**
2042
+ * Renderer statics.
2043
+ */
2044
+ export namespace IRenderer {
2045
+ /**
2046
+ * Scrollbar item.
2047
+ */
2048
+ export interface IScrollbarItem extends IDisposable {
2049
+ /**
2050
+ * Render the scrollbar item as an HTML element.
2051
+ */
2052
+ render: (props: { index: number }) => HTMLElement;
2053
+
2054
+ /**
2055
+ * Unique item key used for caching.
2056
+ */
2057
+ key: string;
2058
+ }
2059
+ }
2060
+
1961
2061
  /**
1962
2062
  * Item list metadata
1963
2063
  */
@@ -102,6 +102,7 @@ export class MenuSvg extends Menu {
102
102
  constructor(options: Menu.IOptions) {
103
103
  options.renderer = options.renderer || MenuSvg.defaultRenderer;
104
104
  super(options);
105
+ this.addClass('jp-ThemedContainer');
105
106
  }
106
107
 
107
108
  /**
package/style/base.css CHANGED
@@ -22,18 +22,23 @@
22
22
  @import './toolbar.css';
23
23
  @import './windowedlist.css';
24
24
 
25
- body {
25
+ :root {
26
+ /* Increase default density for Jupyter toolkit components */
27
+ --density: -4;
28
+ }
29
+
30
+ .jp-ThemedContainer {
26
31
  color: var(--jp-ui-font-color1);
27
32
  font-size: var(--jp-ui-font-size1);
28
33
  }
29
34
 
30
35
  /* Disable native link decoration styles everywhere outside of dialog boxes */
31
- a {
36
+ .jp-ThemedContainer a {
32
37
  text-decoration: unset;
33
38
  color: unset;
34
39
  }
35
40
 
36
- a:hover {
41
+ .jp-ThemedContainer a:hover {
37
42
  text-decoration: unset;
38
43
  color: unset;
39
44
  }
@@ -105,7 +110,7 @@ a:hover {
105
110
  .jp-InputGroup input {
106
111
  box-sizing: border-box;
107
112
  border: none;
108
- border-radius: 0;
113
+ border-radius: var(--jp-border-radius);
109
114
  background-color: transparent;
110
115
  color: var(--jp-ui-font-color0);
111
116
  box-shadow: inset 0 0 0 var(--jp-border-width) var(--jp-input-border-color);
@@ -145,7 +150,7 @@ a:hover {
145
150
  }
146
151
 
147
152
  .jp-InputGroup input::placeholder,
148
- input::placeholder {
153
+ .jp-ThemedContainer input::placeholder {
149
154
  color: var(--jp-ui-font-color2);
150
155
  }
151
156
 
@@ -156,6 +161,11 @@ input::placeholder {
156
161
  padding: 6px;
157
162
  }
158
163
 
164
+ .jp-HTMLSelect.jp-DefaultStyle {
165
+ /* Leave space for the focus outline */
166
+ padding: 0 2px;
167
+ }
168
+
159
169
  .jp-HTMLSelect.jp-DefaultStyle select {
160
170
  background-color: initial;
161
171
  border: none;
@@ -184,6 +194,10 @@ input::placeholder {
184
194
  cursor: not-allowed;
185
195
  }
186
196
 
197
+ .jp-HTMLSelect.jp-DefaultStyle select:focus-visible {
198
+ outline: 2px solid var(--accent-fill-focus, var(--jp-brand-color1));
199
+ }
200
+
187
201
  /* Use our own theme for hover and option styles */
188
202
  /* stylelint-disable-next-line selector-max-type */
189
203
  .jp-HTMLSelect.jp-DefaultStyle select:hover,
@@ -192,6 +206,6 @@ input::placeholder {
192
206
  color: var(--jp-ui-font-color0);
193
207
  }
194
208
 
195
- select {
209
+ .jp-ThemedContainer select {
196
210
  box-sizing: border-box;
197
211
  }
@@ -37,7 +37,7 @@
37
37
  </g>
38
38
  </g>
39
39
 
40
- <g class="jp-icon-warn0" fill="#F37726">
40
+ <g class="jp-jupyter-icon-color" fill="#F37726">
41
41
  <path d="M1352.3,326.2h37V28h-37V326.2z M1604.8,326.2c-2.5-13.9-3.4-31.1-3.4-48.7v-76 c0-40.7-15.1-83.1-77.3-83.1c-25.6,0-50,7.1-66.8,18.1l8.4,24.4c14.3-9.2,34-15.1,53-15.1c41.6,0,46.2,30.2,46.2,47v4.2 c-78.6-0.4-122.3,26.5-122.3,75.6c0,29.4,21,58.4,62.2,58.4c29,0,50.9-14.3,62.2-30.2h1.3l2.9,25.6H1604.8z M1565.7,257.7 c0,3.8-0.8,8-2.1,11.8c-5.9,17.2-22.7,34-49.2,34c-18.9,0-34.9-11.3-34.9-35.3c0-39.5,45.8-46.6,86.2-45.8V257.7z M1698.5,326.2 l1.7-33.6h1.3c15.1,26.9,38.7,38.2,68.1,38.2c45.4,0,91.2-36.1,91.2-108.8c0.4-61.7-35.3-103.7-85.7-103.7 c-32.8,0-56.3,14.7-69.3,37.4h-0.8V28h-36.6v245.7c0,18.1-0.8,38.6-1.7,52.5H1698.5z M1704.8,208.2c0-5.9,1.3-10.9,2.1-15.1 c7.6-28.1,31.1-45.4,56.3-45.4c39.5,0,60.5,34.9,60.5,75.6c0,46.6-23.1,78.1-61.8,78.1c-26.9,0-48.3-17.6-55.5-43.3 c-0.8-4.2-1.7-8.8-1.7-13.4V208.2z"/>
42
42
  </g>
43
43
  </svg>
@@ -57,9 +57,9 @@
57
57
  .jp-FormGroup-content fieldset input:focus,
58
58
  .jp-FormGroup-content fieldset select:focus {
59
59
  -moz-outline-radius: unset;
60
- outline: var(--jp-border-width) solid var(--md-blue-500, #2196f3);
60
+ outline: var(--jp-border-width) solid var(--jp-input-active-border-color);
61
61
  outline-offset: -1px;
62
- box-shadow: inset 0 0 4px var(--md-blue-300, #64b5f6);
62
+ box-shadow: var(--jp-input-box-shadow);
63
63
  }
64
64
 
65
65
  .jp-FormGroup-content fieldset input:hover:not(:focus),
@@ -46,6 +46,9 @@
46
46
  box-sizing: border-box;
47
47
  line-height: 25px;
48
48
  margin: 0;
49
+
50
+ /* padding to allow for focus outline */
51
+ padding: 2px;
49
52
  display: flex;
50
53
  align-items: center;
51
54
  background: var(--jp-layout-color1);
@@ -56,8 +59,9 @@
56
59
  }
57
60
 
58
61
  .lm-AccordionPanel .jp-AccordionPanel-title:focus-visible {
59
- outline: 4px solid var(--jp-accept-color-active, var(--jp-brand-color1));
60
- outline-offset: -1px;
62
+ /* --accent-fill-focus is computed by the jp toolkit to ensure accessibility */
63
+ outline: 2px solid var(--accent-fill-focus, var(--jp-brand-color1));
64
+ outline-offset: -2px;
61
65
  }
62
66
 
63
67
  .jp-AccordionPanel-title {
package/style/styling.css CHANGED
@@ -24,6 +24,7 @@ input.jp-mod-styled {
24
24
  height: 28px;
25
25
  box-sizing: border-box;
26
26
  border: var(--jp-border-width) solid var(--jp-border-color1);
27
+ border-radius: var(--jp-border-radius);
27
28
  padding-left: 7px;
28
29
  padding-right: 7px;
29
30
  font-size: var(--jp-ui-font-size2);
@@ -42,8 +43,8 @@ input[type='checkbox'].jp-mod-styled {
42
43
  }
43
44
 
44
45
  input.jp-mod-styled:focus {
45
- border: var(--jp-border-width) solid var(--md-blue-500, #2196f3);
46
- box-shadow: inset 0 0 4px var(--md-blue-300, #64b5f6);
46
+ border: var(--jp-border-width) solid var(--jp-input-active-border-color);
47
+ box-shadow: var(--jp-input-box-shadow);
47
48
  }
48
49
 
49
50
  input[type='checkbox'].jp-mod-styled:focus-visible {
@@ -86,7 +87,7 @@ select.jp-mod-styled {
86
87
  color: var(--jp-ui-font-color0);
87
88
  padding: 0 25px 0 8px;
88
89
  border: var(--jp-border-width) solid var(--jp-input-border-color);
89
- border-radius: 0;
90
+ border-radius: var(--jp-border-radius);
90
91
  outline: none;
91
92
  appearance: none;
92
93
  -webkit-appearance: none;
package/style/toolbar.css CHANGED
@@ -23,7 +23,7 @@
23
23
  box-shadow: var(--jp-toolbar-box-shadow);
24
24
  background: var(--jp-toolbar-background);
25
25
  min-height: var(--jp-toolbar-micro-height);
26
- padding: 2px;
26
+ padding: 0 2px;
27
27
  z-index: 8;
28
28
  }
29
29
 
@@ -34,9 +34,6 @@
34
34
  height: 100%;
35
35
  display: flex;
36
36
  align-items: center;
37
-
38
- /* Increase density for toolbar items */
39
- --density: -4;
40
37
  }
41
38
 
42
39
  .jp-Toolbar::part(positioning-region) {
@@ -22,6 +22,7 @@
22
22
 
23
23
  .jp-WindowedPanel-scrollbar {
24
24
  display: none;
25
+ position: relative;
25
26
  }
26
27
 
27
28
  .jp-WindowedPanel.jp-mod-virtual-scrollbar > .jp-WindowedPanel-scrollbar {
@@ -30,6 +31,7 @@
30
31
  display: block;
31
32
  position: fixed;
32
33
  overflow-y: auto;
34
+ overflow-x: hidden;
33
35
  top: 0;
34
36
  bottom: 0;
35
37
  right: 0;
@@ -38,19 +40,33 @@
38
40
  }
39
41
 
40
42
  .jp-WindowedPanel-scrollbar-content {
41
- background-color: var(--jp-layout-color1);
43
+ background-color: transparent;
42
44
  list-style-type: none;
43
45
  margin: 0;
44
46
  padding: 0;
47
+ position: relative;
48
+ z-index: 3;
45
49
  }
46
50
 
47
51
  .jp-WindowedPanel-scrollbar-content > .jp-WindowedPanel-scrollbar-item {
48
52
  border-bottom: 1px solid var(--jp-layout-color3);
53
+ background-color: rgb(from var(--jp-layout-color1) r g b / 50%);
49
54
  padding: 2px;
50
55
  text-align: left;
56
+ margin: 0 2px;
51
57
  }
52
58
 
53
59
  .jp-WindowedPanel-scrollbar-content > .jp-WindowedPanel-scrollbar-item:hover {
54
60
  cursor: pointer;
55
- background-color: var(--jp-layout-color2);
61
+ background-color: var(--jp-layout-color3);
62
+ }
63
+
64
+ .jp-WindowedPanel-scrollbar-viewportIndicator {
65
+ position: absolute;
66
+ background: var(--jp-layout-color2);
67
+ border: 1px solid var(--jp-layout-color4);
68
+ width: 100%;
69
+ z-index: 2;
70
+ border-radius: 2px;
71
+ box-sizing: border-box;
56
72
  }