@jupyterlab/ui-components 4.7.0-beta.0 → 4.7.0-beta.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.
@@ -327,6 +327,10 @@ export class Toolbar<T extends Widget = Widget> extends Widget {
327
327
  */
328
328
  handleEvent(event: Event): void {
329
329
  switch (event.type) {
330
+ case 'pointerdown':
331
+ case 'keydown':
332
+ this._focusBeforeClick = document.activeElement;
333
+ break;
330
334
  case 'click':
331
335
  this.handleClick(event);
332
336
  break;
@@ -342,6 +346,9 @@ export class Toolbar<T extends Widget = Widget> extends Widget {
342
346
  // Stop propagating the click outside the toolbar
343
347
  event.stopPropagation();
344
348
 
349
+ const focusBeforeClick = this._focusBeforeClick;
350
+ this._focusBeforeClick = null;
351
+
345
352
  // Clicking a label focuses the corresponding control
346
353
  // that is linked with `for` attribute, so let it be.
347
354
  if (event.target instanceof HTMLLabelElement) {
@@ -356,6 +363,16 @@ export class Toolbar<T extends Widget = Widget> extends Widget {
356
363
  return;
357
364
  }
358
365
 
366
+ // If this click moved the focus out of the toolbar, for example to a menu,
367
+ // let it be. The focus is on the body when the click did not focus anything.
368
+ if (
369
+ focusBeforeClick !== null &&
370
+ document.activeElement !== focusBeforeClick &&
371
+ document.activeElement !== document.body
372
+ ) {
373
+ return;
374
+ }
375
+
359
376
  // Otherwise, activate the parent widget, which may take focus if desired.
360
377
  if (this.parent) {
361
378
  this.parent.activate();
@@ -367,6 +384,8 @@ export class Toolbar<T extends Widget = Widget> extends Widget {
367
384
  */
368
385
  protected onAfterAttach(msg: Message): void {
369
386
  this.node.addEventListener('click', this);
387
+ this.node.addEventListener('pointerdown', this);
388
+ this.node.addEventListener('keydown', this);
370
389
  }
371
390
 
372
391
  /**
@@ -374,9 +393,12 @@ export class Toolbar<T extends Widget = Widget> extends Widget {
374
393
  */
375
394
  protected onBeforeDetach(msg: Message): void {
376
395
  this.node.removeEventListener('click', this);
396
+ this.node.removeEventListener('pointerdown', this);
397
+ this.node.removeEventListener('keydown', this);
377
398
  }
378
399
 
379
400
  noFocusOnClick: boolean;
401
+ private _focusBeforeClick: Element | null = null;
380
402
  }
381
403
 
382
404
  /**
@@ -1118,7 +1140,15 @@ export function CommandToolbarButtonComponent(
1118
1140
  >
1119
1141
  {() =>
1120
1142
  props.commands.listCommands().includes(props.id) ? (
1121
- <ToolbarButtonComponent {...Private.propsFromCommand(props)} />
1143
+ // Use a memoized component so that signal emissions which do not
1144
+ // actually change the rendered output (e.g. the bulk command
1145
+ // notifications fired when switching tabs) do not trigger a costly
1146
+ // re-render of the button subtree. See `Private.arePropsEqual`.
1147
+ <Private.MemoizedToolbarButtonComponent
1148
+ {...Private.propsFromCommand(props)}
1149
+ commands={props.commands}
1150
+ commandArgs={props.args}
1151
+ />
1122
1152
  ) : null
1123
1153
  }
1124
1154
  </UseSignal>
@@ -1461,6 +1491,113 @@ namespace Private {
1461
1491
  };
1462
1492
  }
1463
1493
 
1494
+ /**
1495
+ * Props of the memoized toolbar button.
1496
+ *
1497
+ * It carries the command registry (`commands`) and the command `args`
1498
+ * (`commandArgs`) in addition to the rendered button props: a change of
1499
+ * either can affect only the click handler, and must still re-render the
1500
+ * button. `ToolbarButtonComponent` ignores these two fields.
1501
+ */
1502
+ interface IMemoizedButtonProps extends ToolbarButtonComponent.IProps {
1503
+ commands?: CommandRegistry;
1504
+ commandArgs?: ReadonlyJSONObject;
1505
+ }
1506
+
1507
+ /**
1508
+ * Props which are recreated on every call to `propsFromCommand` and therefore
1509
+ * cannot be compared by identity:
1510
+ * - `onClick` is a fresh closure but is semantically stable - what it
1511
+ * dispatches depends only on the command registry, the command id and
1512
+ * `args` (compared through `commands`, `dataset` and `commandArgs`) - so
1513
+ * it is skipped entirely.
1514
+ * - `dataset` is a fresh object and is compared by value instead.
1515
+ */
1516
+ const NON_IDENTITY_PROPS: {
1517
+ [key in keyof IMemoizedButtonProps]?: 'skip' | 'dataset';
1518
+ } = {
1519
+ onClick: 'skip',
1520
+ dataset: 'dataset'
1521
+ };
1522
+
1523
+ /**
1524
+ * Compare two sets of toolbar button props for rendering equality.
1525
+ *
1526
+ * Used as the equality function of a `React.memo` wrapper so that command
1527
+ * change notifications which do not affect the button (the common case when
1528
+ * switching tabs, where every notebook command is notified but most buttons
1529
+ * are unaffected) do not re-render the button.
1530
+ *
1531
+ * #### Notes
1532
+ * This compares *every* prop generically (rather than an explicit allow-list)
1533
+ * so that the optimization stays correct when a new prop is added to
1534
+ * `ToolbarButtonComponent.IProps`: an unhandled prop is compared by identity,
1535
+ * which at worst forces a re-render but can never leave the button stale.
1536
+ * Only the props that are recreated on every render
1537
+ * (see {@link NON_IDENTITY_PROPS}) need explicit handling here.
1538
+ *
1539
+ * `propsFromCommand` always returns the same set of keys, so iterating the
1540
+ * keys of `a` is sufficient. We use `for...in` rather than `Object.keys`/a
1541
+ * `Set` to avoid allocating on every call: this runs for every toolbar button
1542
+ * on every command notification, so the per-call cost must stay minimal.
1543
+ */
1544
+ export function arePropsEqual(
1545
+ a: IMemoizedButtonProps,
1546
+ b: IMemoizedButtonProps
1547
+ ): boolean {
1548
+ const aRecord = a as Record<string, unknown>;
1549
+ const bRecord = b as Record<string, unknown>;
1550
+ for (const key in aRecord) {
1551
+ const handling = NON_IDENTITY_PROPS[key as keyof IMemoizedButtonProps];
1552
+ if (handling === 'skip') {
1553
+ continue;
1554
+ }
1555
+ if (handling === 'dataset') {
1556
+ if (!shallowEqualDataset(a.dataset, b.dataset)) {
1557
+ return false;
1558
+ }
1559
+ continue;
1560
+ }
1561
+ if (aRecord[key] !== bRecord[key]) {
1562
+ return false;
1563
+ }
1564
+ }
1565
+ return true;
1566
+ }
1567
+
1568
+ /**
1569
+ * Shallow comparison of two `dataset` objects (key/value equality).
1570
+ */
1571
+ function shallowEqualDataset(a?: DOMStringMap, b?: DOMStringMap): boolean {
1572
+ if (a === b) {
1573
+ return true;
1574
+ }
1575
+ if (!a || !b) {
1576
+ return false;
1577
+ }
1578
+ const aKeys = Object.keys(a);
1579
+ const bKeys = Object.keys(b);
1580
+ if (aKeys.length !== bKeys.length) {
1581
+ return false;
1582
+ }
1583
+ return aKeys.every(key => a[key] === b[key]);
1584
+ }
1585
+
1586
+ /**
1587
+ * A memoized version of `ToolbarButtonComponent` which skips re-rendering
1588
+ * when the derived props are unchanged (see `arePropsEqual`).
1589
+ */
1590
+ export const MemoizedToolbarButtonComponent = React.memo(
1591
+ (props: IMemoizedButtonProps): JSX.Element => {
1592
+ // `commands` and `commandArgs` are only used by `arePropsEqual`; the
1593
+ // remaining fields are the actual button props (the button ignores the
1594
+ // extra fields).
1595
+ const buttonProps: ToolbarButtonComponent.IProps = props;
1596
+ return <ToolbarButtonComponent {...buttonProps} />;
1597
+ },
1598
+ arePropsEqual
1599
+ );
1600
+
1464
1601
  /**
1465
1602
  * An attached property for the name of a toolbar item.
1466
1603
  */
@@ -1302,6 +1302,24 @@ export class WindowedList<
1302
1302
  const { clientHeight, scrollHeight, scrollTop } =
1303
1303
  event.currentTarget as HTMLDivElement;
1304
1304
 
1305
+ // A scroll that the list did not request, such as one with the mouse
1306
+ // wheel, stops the list from scrolling back to the last requested
1307
+ // item. The type check excludes the synthetic onScroll call made
1308
+ // when windowing is toggled, which carries no event type.
1309
+ // When the list requests an offset past the end (such as the last
1310
+ // item plus a margin), the browser scrolls only to the end, so the
1311
+ // comparison limits the offset to the end.
1312
+ if (
1313
+ event.type === 'scroll' &&
1314
+ !this._scrollUpdateWasRequested &&
1315
+ Math.abs(
1316
+ Math.min(this.viewModel.scrollOffset, scrollHeight - clientHeight) -
1317
+ scrollTop
1318
+ ) > 1
1319
+ ) {
1320
+ this._scrollToItem = null;
1321
+ }
1322
+
1305
1323
  // TBC Firefox is emitting two events one with 1px diff then the _real_ scroll
1306
1324
  if (
1307
1325
  !this._scrollUpdateWasRequested &&
package/src/tokens.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
+ import type { ReadonlyPartialJSONObject } from '@lumino/coreutils';
4
5
  import { Token } from '@lumino/coreutils';
5
6
  import type { Field, Widget } from '@rjsf/utils';
6
7
 
@@ -17,6 +18,14 @@ export interface IFormRenderer {
17
18
  * A React component with properties WidgetProps.
18
19
  */
19
20
  widgetRenderer?: Widget;
21
+
22
+ /**
23
+ * Returns the schema of the sub-properties displayed by the renderer.
24
+ *
25
+ * Use it when the renderer shows properties that are not in the plugin
26
+ * schema, so that the settings editor search can find them.
27
+ */
28
+ getSchemaProperties?: () => ReadonlyPartialJSONObject;
20
29
  }
21
30
 
22
31
  /**
package/style/base.css CHANGED
@@ -69,6 +69,48 @@
69
69
  --density: 0;
70
70
  }
71
71
 
72
+ .jp-FilterBox-wrapper {
73
+ position: relative;
74
+ }
75
+
76
+ .jp-FilterBox-wrapper > .jp-FilterBox {
77
+ width: 100%;
78
+ }
79
+
80
+ .jp-FilterBox-wrapper > .jp-FilterBox-suggestions {
81
+ position: absolute;
82
+ top: 100%;
83
+ bottom: auto;
84
+ left: 0;
85
+ right: 0;
86
+ z-index: 1;
87
+ max-height: 200px;
88
+ overflow-y: auto;
89
+ margin: 2px 0 0;
90
+ padding: 2px 0;
91
+ list-style: none;
92
+ background: var(--jp-layout-color1);
93
+ border: var(--jp-border-width) solid var(--jp-border-color1);
94
+ box-shadow: var(--jp-elevation-z4);
95
+ }
96
+
97
+ .jp-FilterBox-suggestion {
98
+ padding: 4px 8px;
99
+ cursor: pointer;
100
+ color: var(--jp-ui-font-color1);
101
+ font-size: var(--jp-ui-font-size1);
102
+ }
103
+
104
+ .jp-FilterBox-suggestion:hover,
105
+ .jp-FilterBox-suggestion:focus {
106
+ background: var(--jp-layout-color2);
107
+ }
108
+
109
+ .jp-FilterBox-suggestion:focus-visible {
110
+ outline: 1px solid var(--jp-brand-color1);
111
+ outline-offset: -1px;
112
+ }
113
+
72
114
  .jp-Button {
73
115
  color: var(--jp-ui-font-color2);
74
116
  border-radius: var(--jp-border-radius);
@@ -1,3 +1,3 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
2
- <path fill="#616161" d="M5 2h10l5 5v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-6h1v2l4-3-4-3v2H3V4a2 2 0 0 1 2-2m7 16h4v-2h-4zm0-4h6v-2h-6zm0-4h6V8h-6zm-2 4a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-7-2v2H1v-2z" class="jp-icon3"/>
2
+ <path fill="#616161" d="M5 2h10l5 5v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-6h1v2l4-3-4-3v2H3V4a2 2 0 0 1 2-2m7 16h4v-2h-4zm0-4h6v-2h-6zm0-4h6V8h-6zm-2 4a1 1 0 1 0 0-2 1 1 0 0 0 0 2m-7-2v2H1v-2z" class="jp-icon3 jp-icon-selectable"/>
3
3
  </svg>
@@ -112,3 +112,46 @@
112
112
  text-overflow: ellipsis;
113
113
  white-space: nowrap;
114
114
  }
115
+
116
+ .jp-AccordionPanel-dragHandle {
117
+ display: none;
118
+ touch-action: none;
119
+ align-items: center;
120
+ flex-shrink: 0;
121
+ padding: 0 4px;
122
+ opacity: 0.5;
123
+ cursor: grab;
124
+ }
125
+
126
+ .jp-AccordionPanel-dragHandle::before {
127
+ content: '⠿';
128
+ font-size: var(--jp-ui-font-size1);
129
+ line-height: 1;
130
+ color: var(--jp-ui-font-color1);
131
+ }
132
+
133
+ .jp-mod-dragging .jp-AccordionPanel-dragHandle {
134
+ cursor: grabbing;
135
+ }
136
+
137
+ .jp-AccordionPanel-dropIndicator {
138
+ position: absolute;
139
+ left: 0;
140
+ right: 0;
141
+ height: 2px;
142
+ background-color: var(--jp-brand-color1);
143
+ pointer-events: none;
144
+ z-index: 10;
145
+ }
146
+
147
+ .jp-mod-reorderable > .lm-AccordionPanel-title > .jp-AccordionPanel-dragHandle {
148
+ display: inline-flex;
149
+ }
150
+
151
+ .lm-AccordionPanel[data-orientation='horizontal']
152
+ > .jp-AccordionPanel-dropIndicator {
153
+ top: 0;
154
+ bottom: 0;
155
+ width: 2px;
156
+ height: auto;
157
+ }