@jupyterlab/ui-components 4.0.0-alpha.34 → 4.0.0-alpha.35

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 (45) hide show
  1. package/lib/components/form.js +1 -1
  2. package/lib/components/form.js.map +1 -1
  3. package/lib/components/vdom.d.ts +1 -1
  4. package/lib/components/windowedlist.js +2 -1
  5. package/lib/components/windowedlist.js.map +1 -1
  6. package/lib/hoverbox.d.ts +1 -1
  7. package/lib/icon/labicon.js +49 -48
  8. package/lib/icon/labicon.js.map +1 -1
  9. package/lib/icon/widgets/tabbarsvg.js +2 -1
  10. package/lib/icon/widgets/tabbarsvg.js.map +1 -1
  11. package/package.json +20 -19
  12. package/src/FormRendererRegistry.tsx +60 -0
  13. package/src/components/accordiontoolbar.ts +252 -0
  14. package/src/components/button.tsx +45 -0
  15. package/src/components/collapser.ts +176 -0
  16. package/src/components/form.tsx +678 -0
  17. package/src/components/htmlselect.tsx +99 -0
  18. package/src/components/iframe.ts +153 -0
  19. package/src/components/index.ts +20 -0
  20. package/src/components/inputgroup.tsx +51 -0
  21. package/src/components/interface.ts +9 -0
  22. package/src/components/menu.ts +442 -0
  23. package/src/components/panelwithtoolbar.ts +41 -0
  24. package/src/components/search.tsx +216 -0
  25. package/src/components/sidepanel.ts +168 -0
  26. package/src/components/spinner.ts +31 -0
  27. package/src/components/styling.ts +114 -0
  28. package/src/components/switch.ts +103 -0
  29. package/src/components/toolbar.tsx +1119 -0
  30. package/src/components/vdom.ts +324 -0
  31. package/src/components/windowedlist.ts +1422 -0
  32. package/src/hoverbox.ts +401 -0
  33. package/src/icon/iconimports.ts +206 -0
  34. package/src/icon/index.ts +6 -0
  35. package/src/icon/labicon.tsx +955 -0
  36. package/src/icon/widgets/commandpalettesvg.ts +78 -0
  37. package/src/icon/widgets/index.ts +6 -0
  38. package/src/icon/widgets/menusvg.ts +218 -0
  39. package/src/icon/widgets/tabbarsvg.ts +122 -0
  40. package/src/index.ts +13 -0
  41. package/src/style/icon.ts +581 -0
  42. package/src/style/index.ts +4 -0
  43. package/src/svg.d.ts +58 -0
  44. package/src/tokens.ts +68 -0
  45. package/src/utils.ts +90 -0
@@ -0,0 +1,1422 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ /*
7
+ * This code is inspired by
8
+ * - react-window https://github.com/bvaughn/react-window
9
+ * That library is licensed under MIT License (MIT) Copyright (c) 2018 Brian Vaughn
10
+ * - https://github.com/WICG/virtual-scroller/
11
+ * Licensed by Contributors under the [W3C Software and Document License](http://www.w3.org/Consortium/Legal/2015/copyright-software-and-document)
12
+ */
13
+ import { IChangedArgs } from '@jupyterlab/coreutils';
14
+ import { IObservableList } from '@jupyterlab/observables';
15
+ import { ArrayExt } from '@lumino/algorithm';
16
+ import { PromiseDelegate } from '@lumino/coreutils';
17
+ import { IDisposable } from '@lumino/disposable';
18
+ import { Message, MessageLoop } from '@lumino/messaging';
19
+ import { ISignal, Signal } from '@lumino/signaling';
20
+ import { PanelLayout, Widget } from '@lumino/widgets';
21
+
22
+ /**
23
+ * Maximal remaining time for idle callback
24
+ *
25
+ * Ref: https://developer.mozilla.org/en-US/docs/Web/API/Background_Tasks_API#getting_the_most_out_of_idle_callbacks
26
+ */
27
+ const MAXIMUM_TIME_REMAINING = 50;
28
+
29
+ /*
30
+ * Feature detection
31
+ *
32
+ * Ref: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners
33
+ */
34
+ let passiveIfSupported: boolean | { passive: boolean } = false;
35
+
36
+ try {
37
+ // @ts-expect-error unknown signature
38
+ window.addEventListener(
39
+ 'test',
40
+ null,
41
+ Object.defineProperty({}, 'passive', {
42
+ get: function () {
43
+ passiveIfSupported = { passive: true };
44
+ }
45
+ })
46
+ );
47
+ } catch (err) {
48
+ // pass no-op
49
+ }
50
+
51
+ /**
52
+ * Windowed list abstract model.
53
+ */
54
+ export abstract class WindowedListModel implements WindowedList.IModel {
55
+ /**
56
+ * Constructor
57
+ *
58
+ * @param options Constructor options
59
+ */
60
+ constructor(options: WindowedList.IModelOptions = {}) {
61
+ this._widgetCount = options.itemsList?.length ?? options.count ?? 0;
62
+ this._overscanCount = options.overscanCount ?? 1;
63
+ this._windowingActive = options.windowingActive ?? true;
64
+ this.itemsList = options.itemsList ?? null;
65
+ }
66
+
67
+ /**
68
+ * Provide a best guess for the widget size at position index
69
+ *
70
+ * #### Notes
71
+ *
72
+ * This function should be very light to compute especially when
73
+ * returning the default size.
74
+ * The default value should be constant (i.e. two calls with `null` should
75
+ * return the same value). But it can change for a given `index`.
76
+ *
77
+ * @param index Widget position
78
+ * @returns Estimated widget size
79
+ */
80
+ abstract estimateWidgetSize: (index: number) => number;
81
+
82
+ /**
83
+ * Widget factory for the list items.
84
+ *
85
+ * Caching the resulting widgets should be done by the callee.
86
+ *
87
+ * @param index List index
88
+ * @returns The widget at the given position
89
+ */
90
+ abstract widgetRenderer: (index: number) => Widget;
91
+
92
+ /**
93
+ * List widget height
94
+ */
95
+ get height(): number {
96
+ return this._height;
97
+ }
98
+ set height(h: number) {
99
+ this._height = h;
100
+ }
101
+
102
+ /**
103
+ * Test whether the model is disposed.
104
+ */
105
+ get isDisposed(): boolean {
106
+ return this._isDisposed;
107
+ }
108
+
109
+ /**
110
+ * Items list to be rendered
111
+ */
112
+ get itemsList(): IObservableList<any> | null {
113
+ return this._itemsList;
114
+ }
115
+ set itemsList(v: IObservableList<any> | null) {
116
+ if (this._itemsList !== v) {
117
+ if (this._itemsList) {
118
+ this._itemsList.changed.disconnect(this.onListChanged, this);
119
+ }
120
+ const oldValue = this._itemsList;
121
+ this._itemsList = v;
122
+ if (this._itemsList) {
123
+ this._itemsList.changed.connect(this.onListChanged, this);
124
+ } else {
125
+ this._widgetCount = 0;
126
+ }
127
+ this._stateChanged.emit({
128
+ name: 'list',
129
+ newValue: this._itemsList,
130
+ oldValue
131
+ });
132
+ this._stateChanged.emit({
133
+ name: 'count',
134
+ newValue: this._itemsList?.length ?? 0,
135
+ oldValue: oldValue?.length ?? 0
136
+ });
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Number of widgets to render in addition to those
142
+ * visible in the viewport.
143
+ */
144
+ get overscanCount(): number {
145
+ return this._overscanCount;
146
+ }
147
+ set overscanCount(newValue: number) {
148
+ if (newValue >= 1) {
149
+ if (this._overscanCount !== newValue) {
150
+ const oldValue = this._overscanCount;
151
+ this._overscanCount = newValue;
152
+ this._stateChanged.emit({ name: 'overscanCount', newValue, oldValue });
153
+ }
154
+ } else {
155
+ console.error(`Forbidden non-positive overscan count: got ${newValue}`);
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Viewport scroll offset.
161
+ */
162
+ get scrollOffset(): number {
163
+ return this._scrollOffset;
164
+ }
165
+ set scrollOffset(offset: number) {
166
+ this._scrollOffset = offset;
167
+ }
168
+
169
+ /**
170
+ * Total number of widgets in the list
171
+ */
172
+ get widgetCount(): number {
173
+ return this._itemsList ? this._itemsList.length : this._widgetCount;
174
+ }
175
+ set widgetCount(newValue: number) {
176
+ if (this.itemsList) {
177
+ console.error(
178
+ 'It is not allow to change the widgets count of a windowed list if a items list is used.'
179
+ );
180
+ return;
181
+ }
182
+
183
+ if (newValue >= 0) {
184
+ if (this._widgetCount !== newValue) {
185
+ const oldValue = this._widgetCount;
186
+ this._widgetCount = newValue;
187
+ this._stateChanged.emit({ name: 'count', newValue, oldValue });
188
+ }
189
+ } else {
190
+ console.error(`Forbidden negative widget count: got ${newValue}`);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Whether windowing is active or not.
196
+ *
197
+ * This is true by default.
198
+ */
199
+ get windowingActive(): boolean {
200
+ return this._windowingActive;
201
+ }
202
+ set windowingActive(newValue: boolean) {
203
+ if (newValue !== this._windowingActive) {
204
+ const oldValue = this._windowingActive;
205
+ this._windowingActive = newValue;
206
+
207
+ this._currentWindow = [-1, -1, -1, -1];
208
+ this._lastMeasuredIndex = -1;
209
+ this._widgetSizers = [];
210
+
211
+ this._stateChanged.emit({ name: 'windowingActive', newValue, oldValue });
212
+ }
213
+ }
214
+
215
+ /**
216
+ * A signal emitted when any model state changes.
217
+ */
218
+ get stateChanged(): ISignal<
219
+ WindowedListModel,
220
+ IChangedArgs<
221
+ any,
222
+ any,
223
+ 'count' | 'index' | 'list' | 'overscanCount' | 'windowingActive'
224
+ >
225
+ > {
226
+ return this._stateChanged;
227
+ }
228
+
229
+ /**
230
+ * Dispose the model.
231
+ */
232
+ dispose(): void {
233
+ if (this.isDisposed) {
234
+ return;
235
+ }
236
+ this._isDisposed = true;
237
+ Signal.clearData(this);
238
+ }
239
+
240
+ /**
241
+ * Get the total list size.
242
+ *
243
+ * @returns Total estimated size
244
+ */
245
+ getEstimatedTotalSize(): number {
246
+ let totalSizeOfMeasuredItems = 0;
247
+
248
+ if (this._lastMeasuredIndex >= this.widgetCount) {
249
+ this._lastMeasuredIndex = this.widgetCount - 1;
250
+ }
251
+
252
+ if (this._lastMeasuredIndex >= 0) {
253
+ const itemMetadata = this._widgetSizers[this._lastMeasuredIndex];
254
+ totalSizeOfMeasuredItems = itemMetadata.offset + itemMetadata.size;
255
+ }
256
+
257
+ // We can do better than this
258
+ const numUnmeasuredItems = this.widgetCount - this._lastMeasuredIndex - 1;
259
+ const totalSizeOfUnmeasuredItems =
260
+ numUnmeasuredItems * this._estimatedWidgetSize;
261
+
262
+ return totalSizeOfMeasuredItems + totalSizeOfUnmeasuredItems;
263
+ }
264
+
265
+ /**
266
+ * Get the scroll offset to display an item in the viewport.
267
+ *
268
+ * @param index Item index
269
+ * @param align Where to align the item in the viewport
270
+ * @returns The needed scroll offset
271
+ */
272
+ getOffsetForIndexAndAlignment(
273
+ index: number,
274
+ align: WindowedList.ScrollToAlign = 'auto'
275
+ ): number {
276
+ const size = this._height;
277
+ const itemMetadata = this._getItemMetadata(index);
278
+
279
+ // Get estimated total size after ItemMetadata is computed,
280
+ // To ensure it reflects actual measurements instead of just estimates.
281
+ const estimatedTotalSize = this.getEstimatedTotalSize();
282
+
283
+ const maxOffset = Math.max(
284
+ 0,
285
+ Math.min(estimatedTotalSize - size, itemMetadata.offset)
286
+ );
287
+ const minOffset = Math.max(
288
+ 0,
289
+ itemMetadata.offset - size + itemMetadata.size
290
+ );
291
+
292
+ if (align === 'smart') {
293
+ if (
294
+ this._scrollOffset >= minOffset - size &&
295
+ this._scrollOffset <= maxOffset + size
296
+ ) {
297
+ align = 'auto';
298
+ } else {
299
+ align = 'center';
300
+ }
301
+ }
302
+
303
+ switch (align) {
304
+ case 'start':
305
+ return maxOffset;
306
+ case 'end':
307
+ return minOffset;
308
+ case 'center':
309
+ return Math.round(minOffset + (maxOffset - minOffset) / 2);
310
+ case 'auto':
311
+ default:
312
+ if (
313
+ this._scrollOffset >= minOffset &&
314
+ this._scrollOffset <= maxOffset
315
+ ) {
316
+ return this._scrollOffset;
317
+ } else if (this._scrollOffset < minOffset) {
318
+ return minOffset;
319
+ } else {
320
+ return maxOffset;
321
+ }
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Compute the items range to display.
327
+ *
328
+ * It returns ``null`` if the range does not need to be updated.
329
+ *
330
+ * @returns The current items range to display
331
+ */
332
+ getRangeToRender(): WindowedList.WindowIndex | null {
333
+ let newWindowIndex: [number, number, number, number] = [
334
+ 0,
335
+ Math.max(this.widgetCount - 1, -1),
336
+ 0,
337
+ Math.max(this.widgetCount - 1, -1)
338
+ ];
339
+
340
+ const previousLastMeasuredIndex = this._lastMeasuredIndex;
341
+ if (this.windowingActive) {
342
+ newWindowIndex = this._getRangeToRender();
343
+ }
344
+ const [startIndex, stopIndex] = newWindowIndex;
345
+
346
+ if (
347
+ previousLastMeasuredIndex <= stopIndex ||
348
+ this._currentWindow[0] !== startIndex ||
349
+ this._currentWindow[1] !== stopIndex
350
+ ) {
351
+ this._currentWindow = newWindowIndex;
352
+ return newWindowIndex;
353
+ }
354
+
355
+ return null;
356
+ }
357
+
358
+ /**
359
+ * Return the viewport top position and height for range spanning from
360
+ * ``startIndex`` to ``stopIndex``.
361
+ *
362
+ * @param startIndex First item in viewport index
363
+ * @param stopIndex Last item in viewport index
364
+ * @returns The viewport top position and its height
365
+ */
366
+ getSpan(startIndex: number, stopIndex: number): [number, number] {
367
+ const startSize = this._getItemMetadata(startIndex);
368
+ const top = startSize.offset;
369
+ const stopSize = this._getItemMetadata(stopIndex);
370
+ const height = stopSize.offset - startSize.offset + stopSize.size;
371
+ return [top, height];
372
+ }
373
+
374
+ /**
375
+ * WindowedListModel caches offsets and measurements for each index for performance purposes.
376
+ * This method clears that cached data for all items after (and including) the specified index.
377
+ *
378
+ * The list will automatically re-render after the index is reset.
379
+ *
380
+ * @param index
381
+ */
382
+ resetAfterIndex(index: number): void {
383
+ const oldValue = this._lastMeasuredIndex;
384
+ this._lastMeasuredIndex = Math.min(index, this._lastMeasuredIndex);
385
+ if (this._lastMeasuredIndex !== oldValue) {
386
+ this._stateChanged.emit({ name: 'index', newValue: index, oldValue });
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Update item sizes.
392
+ *
393
+ * This should be called when the real item sizes has been
394
+ * measured.
395
+ *
396
+ * @param sizes New sizes per item index
397
+ * @returns Whether some sizes changed or not
398
+ */
399
+ setWidgetSize(sizes: { index: number; size: number }[]): boolean {
400
+ if (this._currentWindow[0] >= 0) {
401
+ let minIndex = Infinity;
402
+ for (const item of sizes) {
403
+ const key = item.index;
404
+ const size = item.size;
405
+
406
+ if (this._widgetSizers[key].size != size) {
407
+ this._widgetSizers[key].size = size;
408
+ minIndex = Math.min(minIndex, key);
409
+ }
410
+ // Always set the flag in case the size estimator provides perfect result
411
+ this._widgetSizers[key].measured = true;
412
+ }
413
+
414
+ // If some sizes changed
415
+ if (minIndex != Infinity) {
416
+ // Invalid follow-up index
417
+ this._lastMeasuredIndex = Math.min(this._lastMeasuredIndex, minIndex);
418
+ return true;
419
+ }
420
+ }
421
+
422
+ return false;
423
+ }
424
+
425
+ /**
426
+ * Callback on list changes
427
+ *
428
+ * @param list List items
429
+ * @param changes List change
430
+ */
431
+ protected onListChanged(
432
+ list: IObservableList<Widget>,
433
+ changes: IObservableList.IChangedArgs<Widget>
434
+ ): void {
435
+ switch (changes.type) {
436
+ case 'add':
437
+ this._widgetSizers.splice(
438
+ changes.newIndex,
439
+ 0,
440
+ ...new Array(changes.newValues.length).map(() => {
441
+ return { offset: 0, size: this._estimatedWidgetSize };
442
+ })
443
+ );
444
+ this.resetAfterIndex(changes.newIndex - 1);
445
+ break;
446
+ case 'move':
447
+ ArrayExt.move(this._widgetSizers, changes.oldIndex, changes.newIndex);
448
+ this.resetAfterIndex(Math.min(changes.newIndex, changes.oldIndex) - 1);
449
+ break;
450
+ case 'remove':
451
+ this._widgetSizers.splice(changes.oldIndex, changes.oldValues.length);
452
+ this.resetAfterIndex(changes.oldIndex - 1);
453
+ break;
454
+ case 'set':
455
+ this.resetAfterIndex(changes.newIndex - 1);
456
+ break;
457
+ }
458
+ }
459
+
460
+ private _getItemMetadata(index: number): WindowedList.ItemMetadata {
461
+ if (index > this._lastMeasuredIndex) {
462
+ let offset = 0;
463
+ if (this._lastMeasuredIndex >= 0) {
464
+ const itemMetadata = this._widgetSizers[this._lastMeasuredIndex];
465
+ offset = itemMetadata.offset + itemMetadata.size;
466
+ }
467
+
468
+ for (let i = this._lastMeasuredIndex + 1; i <= index; i++) {
469
+ let size = this._widgetSizers[i]?.measured
470
+ ? this._widgetSizers[i].size
471
+ : this.estimateWidgetSize(i);
472
+
473
+ this._widgetSizers[i] = {
474
+ offset,
475
+ size,
476
+ measured: this._widgetSizers[i]?.measured
477
+ };
478
+
479
+ offset += size;
480
+ }
481
+
482
+ this._lastMeasuredIndex = index;
483
+ }
484
+
485
+ for (let i = 0; i <= this._lastMeasuredIndex; i++) {
486
+ const sizer = this._widgetSizers[i];
487
+ if (i === 0) {
488
+ if (sizer.offset !== 0) {
489
+ throw new Error('First offset is not null');
490
+ }
491
+ } else {
492
+ const previous = this._widgetSizers[i - 1];
493
+ if (sizer.offset !== previous.offset + previous.size) {
494
+ throw new Error(`Sizer ${i} has incorrect offset.`);
495
+ }
496
+ }
497
+ }
498
+
499
+ return this._widgetSizers[index];
500
+ }
501
+
502
+ private _findNearestItem(offset: number): number {
503
+ const lastMeasuredItemOffset =
504
+ this._lastMeasuredIndex > 0
505
+ ? this._widgetSizers[this._lastMeasuredIndex].offset
506
+ : 0;
507
+
508
+ if (lastMeasuredItemOffset >= offset) {
509
+ // If we've already measured items within this range just use a binary search as it's faster.
510
+ return this._findNearestItemBinarySearch(
511
+ this._lastMeasuredIndex,
512
+ 0,
513
+ offset
514
+ );
515
+ } else {
516
+ // If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
517
+ // The exponential search avoids pre-computing sizes for the full set of items as a binary search would.
518
+ // The overall complexity for this approach is O(log n).
519
+ return this._findNearestItemExponentialSearch(
520
+ Math.max(0, this._lastMeasuredIndex),
521
+ offset
522
+ );
523
+ }
524
+ }
525
+
526
+ private _findNearestItemBinarySearch(
527
+ high: number,
528
+ low: number,
529
+ offset: number
530
+ ): number {
531
+ while (low <= high) {
532
+ const middle = low + Math.floor((high - low) / 2);
533
+ const currentOffset = this._getItemMetadata(middle).offset;
534
+
535
+ if (currentOffset === offset) {
536
+ return middle;
537
+ } else if (currentOffset < offset) {
538
+ low = middle + 1;
539
+ } else if (currentOffset > offset) {
540
+ high = middle - 1;
541
+ }
542
+ }
543
+
544
+ if (low > 0) {
545
+ return low - 1;
546
+ } else {
547
+ return 0;
548
+ }
549
+ }
550
+
551
+ private _findNearestItemExponentialSearch(
552
+ index: number,
553
+ offset: number
554
+ ): number {
555
+ let interval = 1;
556
+
557
+ while (
558
+ index < this.widgetCount &&
559
+ this._getItemMetadata(index).offset < offset
560
+ ) {
561
+ index += interval;
562
+ interval *= 2;
563
+ }
564
+
565
+ return this._findNearestItemBinarySearch(
566
+ Math.min(index, this.widgetCount - 1),
567
+ Math.floor(index / 2),
568
+ offset
569
+ );
570
+ }
571
+
572
+ private _getRangeToRender(): WindowedList.WindowIndex {
573
+ const widgetCount = this.widgetCount;
574
+
575
+ if (widgetCount === 0) {
576
+ return [-1, -1, -1, -1];
577
+ }
578
+
579
+ const startIndex = this._getStartIndexForOffset(this._scrollOffset);
580
+ const stopIndex = this._getStopIndexForStartIndex(
581
+ startIndex,
582
+ this._scrollOffset
583
+ );
584
+
585
+ const overscanBackward = Math.max(1, this.overscanCount);
586
+ const overscanForward = Math.max(1, this.overscanCount);
587
+
588
+ return [
589
+ Math.max(0, startIndex - overscanBackward),
590
+ Math.max(0, Math.min(widgetCount - 1, stopIndex + overscanForward)),
591
+ startIndex,
592
+ stopIndex
593
+ ];
594
+ }
595
+
596
+ private _getStartIndexForOffset(offset: number): number {
597
+ return this._findNearestItem(offset);
598
+ }
599
+
600
+ private _getStopIndexForStartIndex(
601
+ startIndex: number,
602
+ scrollOffset: number
603
+ ): number {
604
+ const size = this._height;
605
+ const itemMetadata = this._getItemMetadata(startIndex);
606
+ const maxOffset = scrollOffset + size;
607
+
608
+ let offset = itemMetadata.offset + itemMetadata.size;
609
+ let stopIndex = startIndex;
610
+
611
+ while (stopIndex < this.widgetCount - 1 && offset < maxOffset) {
612
+ stopIndex++;
613
+ offset += this._getItemMetadata(stopIndex).size;
614
+ }
615
+
616
+ return stopIndex;
617
+ }
618
+
619
+ /**
620
+ * Default widget size estimation
621
+ */
622
+ protected _estimatedWidgetSize: number = WindowedList.DEFAULT_WIDGET_SIZE;
623
+ protected _stateChanged = new Signal<
624
+ WindowedListModel,
625
+ IChangedArgs<
626
+ any,
627
+ any,
628
+ 'count' | 'index' | 'list' | 'overscanCount' | 'windowingActive'
629
+ >
630
+ >(this);
631
+
632
+ private _currentWindow: WindowedList.WindowIndex = [-1, -1, -1, -1];
633
+ private _height: number = 0;
634
+ private _isDisposed = false;
635
+ private _itemsList: IObservableList<any> | null = null;
636
+ private _lastMeasuredIndex: number = -1;
637
+ private _overscanCount = 1;
638
+ private _scrollOffset: number = 0;
639
+ private _widgetCount = 0;
640
+ private _widgetSizers: WindowedList.ItemMetadata[] = [];
641
+ private _windowingActive = true;
642
+ }
643
+
644
+ /**
645
+ * Windowed list widget
646
+ */
647
+ export class WindowedList<
648
+ T extends WindowedList.IModel = WindowedList.IModel
649
+ > extends Widget {
650
+ /**
651
+ * Default widget size
652
+ */
653
+ static readonly DEFAULT_WIDGET_SIZE = 50;
654
+
655
+ /**
656
+ * Constructor
657
+ *
658
+ * @param options Constructor options
659
+ */
660
+ constructor(options: WindowedList.IOptions<T>) {
661
+ // TODO probably needs to be able to customize outer HTML tag (could be ul / ol / table, ...)
662
+ const node = document.createElement('div');
663
+ node.className = 'jp-WindowedPanel-outer';
664
+ const innerElement = node.appendChild(document.createElement('div'));
665
+ innerElement.className = 'jp-WindowedPanel-inner';
666
+ const windowContainer = innerElement.appendChild(
667
+ document.createElement('div')
668
+ );
669
+ windowContainer.className = 'jp-WindowedPanel-window';
670
+ super({ node });
671
+ super.layout = options.layout ?? new WindowedLayout();
672
+ this._viewModel = options.model;
673
+ this._innerElement = innerElement;
674
+ this._isScrolling = null;
675
+ this._windowElement = windowContainer;
676
+ this._scrollToItem = null;
677
+ this._scrollRepaint = null;
678
+ this._scrollUpdateWasRequested = false;
679
+ this._resizeObserver = null;
680
+
681
+ this._viewModel.stateChanged.connect(this.onStateChanged, this);
682
+ }
683
+
684
+ /**
685
+ * Widget layout
686
+ */
687
+ get layout(): WindowedLayout {
688
+ return super.layout as WindowedLayout;
689
+ }
690
+
691
+ /**
692
+ * Viewport
693
+ */
694
+ get viewportNode(): HTMLDivElement {
695
+ return this._windowElement;
696
+ }
697
+
698
+ /**
699
+ * Windowed list view model
700
+ */
701
+ protected get viewModel(): T {
702
+ return this._viewModel;
703
+ }
704
+
705
+ /**
706
+ * Callback on event.
707
+ *
708
+ * @param event Event
709
+ */
710
+ handleEvent(event: Event): void {
711
+ switch (event.type) {
712
+ case 'scroll':
713
+ this.onScroll(event);
714
+ break;
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Scroll to the specified offset `scrollTop`.
720
+ *
721
+ * @param scrollOffset Offset to scroll
722
+ *
723
+ * @deprecated This is an internal helper. Prefer calling `scrollToItem`.
724
+ */
725
+ scrollTo(scrollOffset: number): void {
726
+ if (!this.viewModel.windowingActive) {
727
+ this.node.scrollTo({ top: scrollOffset });
728
+ return;
729
+ }
730
+
731
+ scrollOffset = Math.max(0, scrollOffset);
732
+
733
+ if (scrollOffset !== this.viewModel.scrollOffset) {
734
+ this.viewModel.scrollOffset = scrollOffset;
735
+ this._scrollUpdateWasRequested = true;
736
+
737
+ this.update();
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Scroll to the specified item.
743
+ *
744
+ * 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:
745
+ *
746
+ * 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.)
747
+ * smart - If the item is already visible, don't scroll at all. If it is less than one viewport away, scroll as little as possible so that it becomes visible. If it is more than one viewport away, scroll so that it is centered within the list.
748
+ * center - Center align the item within the list.
749
+ * end - Align the item to the end of the list
750
+ * start - Align the item to the beginning of the list
751
+ *
752
+ * @param index Item index to scroll to
753
+ * @param align Type of alignment
754
+ */
755
+ scrollToItem(
756
+ index: number,
757
+ align: WindowedList.ScrollToAlign = 'auto'
758
+ ): Promise<void> {
759
+ if (!this.viewModel.windowingActive) {
760
+ const widget = this.layout.widgets[index];
761
+ if (widget?.node.scrollIntoView) {
762
+ widget.node.scrollIntoView({
763
+ block: ['auto', 'smart'].includes(align)
764
+ ? 'nearest'
765
+ : (align as ScrollLogicalPosition)
766
+ });
767
+ }
768
+ return Promise.resolve();
769
+ }
770
+
771
+ if (
772
+ !this._isScrolling ||
773
+ this._scrollToItem === null ||
774
+ this._scrollToItem[0] !== index ||
775
+ this._scrollToItem[1] !== align
776
+ ) {
777
+ if (this._isScrolling) {
778
+ this._isScrolling.reject('Scrolling to a new item is requested.');
779
+ }
780
+
781
+ this._isScrolling = new PromiseDelegate<void>();
782
+ }
783
+
784
+ this._scrollToItem = [index, align];
785
+ this._resetScrollToItem();
786
+ this.scrollTo(
787
+ this.viewModel.getOffsetForIndexAndAlignment(
788
+ Math.max(0, Math.min(index, this._viewModel.widgetCount - 1)),
789
+ align
790
+ )
791
+ );
792
+
793
+ return this._isScrolling.promise;
794
+ }
795
+
796
+ /**
797
+ * A message handler invoked on an `'after-attach'` message.
798
+ */
799
+ protected onAfterAttach(msg: Message): void {
800
+ super.onAfterAttach(msg);
801
+ if (this._viewModel.windowingActive) {
802
+ this._addListeners();
803
+ }
804
+ this.viewModel.height = this.node.getBoundingClientRect().height;
805
+ }
806
+
807
+ /**
808
+ * A message handler invoked on an `'before-detach'` message.
809
+ */
810
+ protected onBeforeDetach(msg: Message): void {
811
+ if (this._viewModel.windowingActive) {
812
+ this._removeListeners();
813
+ }
814
+ }
815
+
816
+ /**
817
+ * Callback on scroll event
818
+ *
819
+ * @param event Scroll event
820
+ */
821
+ protected onScroll(event: Event): void {
822
+ const { clientHeight, scrollHeight, scrollTop } =
823
+ event.currentTarget as HTMLDivElement;
824
+
825
+ // TBC Firefox is emitting two events one with 1px diff then the _real_ scroll
826
+ if (
827
+ !this._scrollUpdateWasRequested &&
828
+ Math.abs(this.viewModel.scrollOffset - scrollTop) > 1
829
+ ) {
830
+ // Test if the scroll event is jumping to the list bottom
831
+ // if (Math.abs(scrollHeight - clientHeight - scrollTop) < 1) {
832
+ // // FIXME Does not work because it happens in multiple segments in between which the sizing is changing
833
+ // // due to widget resizing. A possible fix would be to keep track of the "old" scrollHeight - clientHeight
834
+ // // up to some quiet activity.
835
+ // this.scrollToItem(this.widgetCount, 'end');
836
+ // } else {
837
+ const scrollOffset = Math.max(
838
+ 0,
839
+ Math.min(scrollTop, scrollHeight - clientHeight)
840
+ );
841
+ this.viewModel.scrollOffset = scrollOffset;
842
+ this._scrollUpdateWasRequested = false;
843
+
844
+ this.update();
845
+ // }
846
+ }
847
+ }
848
+
849
+ /**
850
+ * A message handler invoked on an `'resize-request'` message.
851
+ */
852
+ protected onResize(msg: Widget.ResizeMessage): void {
853
+ this.viewModel.height =
854
+ msg.height >= 0 ? msg.height : this.node.getBoundingClientRect().height;
855
+ super.onResize(msg);
856
+ }
857
+
858
+ /**
859
+ * Callback on view model change
860
+ *
861
+ * @param model Windowed list model
862
+ * @param changes Change
863
+ */
864
+ protected onStateChanged(
865
+ model: WindowedList.IModel,
866
+ changes: IChangedArgs<number | boolean, number | boolean, string>
867
+ ): void {
868
+ switch (changes.name) {
869
+ case 'windowingActive':
870
+ if (this.viewModel.windowingActive) {
871
+ this._addListeners();
872
+ this.onScroll({ currentTarget: this.node } as any);
873
+ // Bail as onScroll will trigger update
874
+ return;
875
+ } else {
876
+ this._removeListeners();
877
+ }
878
+ break;
879
+ }
880
+ this.update();
881
+ }
882
+
883
+ /**
884
+ * A message handler invoked on an `'update-request'` message.
885
+ *
886
+ * #### Notes
887
+ * The default implementation of this handler is a no-op.
888
+ */
889
+ protected onUpdateRequest(msg: Message): void {
890
+ if (this.viewModel.windowingActive) {
891
+ // Throttle update request
892
+ if (this._scrollRepaint === null) {
893
+ this._scrollRepaint = window.requestAnimationFrame(() => {
894
+ this._scrollRepaint = null;
895
+ this._update();
896
+ });
897
+ }
898
+ } else {
899
+ this._update();
900
+ }
901
+ }
902
+
903
+ private _addListeners() {
904
+ if (!this._resizeObserver) {
905
+ this._resizeObserver = new ResizeObserver(
906
+ this._onWidgetResize.bind(this)
907
+ );
908
+ }
909
+ for (const widget of this.layout.widgets) {
910
+ this._resizeObserver.observe(widget.node);
911
+ widget.disposed.connect(() =>
912
+ this._resizeObserver?.unobserve(widget.node)
913
+ );
914
+ }
915
+ this.node.addEventListener('scroll', this, passiveIfSupported);
916
+ this._windowElement.style.position = 'absolute';
917
+ }
918
+
919
+ private _removeListeners() {
920
+ this.node.removeEventListener('scroll', this);
921
+ this._resizeObserver?.disconnect();
922
+ this._resizeObserver = null;
923
+ this._innerElement.style.height = '100%';
924
+ this._windowElement.style.position = 'relative';
925
+ this._windowElement.style.top = '0px';
926
+ }
927
+
928
+ private _update(): void {
929
+ if (this.isDisposed || !this.layout) {
930
+ return;
931
+ }
932
+
933
+ const newWindowIndex = this.viewModel.getRangeToRender();
934
+
935
+ if (newWindowIndex !== null) {
936
+ const [startIndex, stopIndex] = newWindowIndex;
937
+ const toAdd: Widget[] = [];
938
+ if (stopIndex >= 0) {
939
+ for (let index = startIndex; index <= stopIndex; index++) {
940
+ const widget = this.viewModel.widgetRenderer(index);
941
+ widget.dataset.windowedListIndex = `${index}`;
942
+ toAdd.push(widget);
943
+ }
944
+ }
945
+ const nWidgets = this.layout.widgets.length;
946
+ // Remove not needed widgets
947
+ for (let itemIdx = nWidgets - 1; itemIdx >= 0; itemIdx--) {
948
+ if (!toAdd.includes(this.layout.widgets[itemIdx])) {
949
+ this._resizeObserver?.unobserve(this.layout.widgets[itemIdx].node);
950
+ this.layout.removeWidget(this.layout.widgets[itemIdx]);
951
+ }
952
+ }
953
+
954
+ for (let index = 0; index < toAdd.length; index++) {
955
+ const item = toAdd[index];
956
+ if (this._resizeObserver && !this.layout.widgets.includes(item)) {
957
+ this._resizeObserver.observe(item.node);
958
+ item.disposed.connect(() =>
959
+ this._resizeObserver?.unobserve(item.node)
960
+ );
961
+ }
962
+
963
+ // The widget may have moved due to drag-and-drop
964
+ this.layout.insertWidget(index, item);
965
+ }
966
+
967
+ if (this.viewModel.windowingActive) {
968
+ if (stopIndex >= 0) {
969
+ // Read this value after creating the cells.
970
+ // So their actual sizes are taken into account
971
+ const estimatedTotalHeight = this.viewModel.getEstimatedTotalSize();
972
+
973
+ // Update inner container height
974
+ this._innerElement.style.height = `${estimatedTotalHeight}px`;
975
+
976
+ // Update position of window container
977
+ const [top, minHeight] = this.viewModel.getSpan(
978
+ startIndex,
979
+ stopIndex
980
+ );
981
+ this._windowElement.style.top = `${top}px`;
982
+ this._windowElement.style.minHeight = `${minHeight}px`;
983
+ } else {
984
+ // Update inner container height
985
+ this._innerElement.style.height = `0px`;
986
+
987
+ // Update position of window container
988
+ this._windowElement.style.top = `0px`;
989
+ this._windowElement.style.minHeight = `0px`;
990
+ }
991
+
992
+ // Update scroll
993
+ if (this._scrollUpdateWasRequested) {
994
+ this.node.scrollTop = this.viewModel.scrollOffset;
995
+ this._scrollUpdateWasRequested = false;
996
+ }
997
+ }
998
+ }
999
+
1000
+ let index2 = -1;
1001
+ for (const w of this.viewportNode.children) {
1002
+ const currentIdx = parseInt(
1003
+ (w as HTMLElement).dataset.windowedListIndex!,
1004
+ 10
1005
+ );
1006
+ if (currentIdx < index2) {
1007
+ throw new Error('Inconsistent dataset index');
1008
+ } else {
1009
+ index2 = currentIdx;
1010
+ }
1011
+ }
1012
+ }
1013
+
1014
+ private _onWidgetResize(entries: ResizeObserverEntry[]): void {
1015
+ this._resetScrollToItem();
1016
+
1017
+ const newSizes: { index: number; size: number }[] = [];
1018
+ for (let entry of entries) {
1019
+ // Update size only if item is attached to the DOM
1020
+ if (entry.target.isConnected) {
1021
+ // Rely on the data attribute as some nodes may be hidden instead of detach
1022
+ // to preserve state.
1023
+ newSizes.push({
1024
+ index: parseInt(
1025
+ (entry.target as HTMLElement).dataset.windowedListIndex!,
1026
+ 10
1027
+ ),
1028
+ size: entry.borderBoxSize[0].blockSize
1029
+ });
1030
+ }
1031
+ }
1032
+
1033
+ // If some sizes changed
1034
+ if (this.viewModel.setWidgetSize(newSizes)) {
1035
+ // Update the list
1036
+ if (this._scrollToItem) {
1037
+ this.scrollToItem(...this._scrollToItem).catch(reason => {
1038
+ console.log(reason);
1039
+ });
1040
+ } else {
1041
+ this.update();
1042
+ }
1043
+ }
1044
+ }
1045
+
1046
+ private _resetScrollToItem(): void {
1047
+ if (this._resetScrollToItemTimeout) {
1048
+ clearTimeout(this._resetScrollToItemTimeout);
1049
+ }
1050
+
1051
+ if (this._scrollToItem) {
1052
+ this._resetScrollToItemTimeout = window.setTimeout(() => {
1053
+ this._scrollToItem = null;
1054
+ if (this._isScrolling) {
1055
+ this._isScrolling.resolve();
1056
+ this._isScrolling = null;
1057
+ }
1058
+ }, MAXIMUM_TIME_REMAINING);
1059
+ }
1060
+ }
1061
+
1062
+ protected _viewModel: T;
1063
+ private _innerElement: HTMLDivElement;
1064
+ private _isScrolling: PromiseDelegate<void> | null;
1065
+ private _windowElement: HTMLDivElement;
1066
+ private _resetScrollToItemTimeout: number | null;
1067
+ private _resizeObserver: ResizeObserver | null;
1068
+ private _scrollRepaint: number | null;
1069
+ private _scrollToItem: [number, WindowedList.ScrollToAlign] | null;
1070
+ private _scrollUpdateWasRequested: boolean;
1071
+ }
1072
+
1073
+ /**
1074
+ * Customized layout for windowed list container.
1075
+ */
1076
+ export class WindowedLayout extends PanelLayout {
1077
+ /**
1078
+ * Constructor
1079
+ */
1080
+ constructor() {
1081
+ super({ fitPolicy: 'set-no-constraint' });
1082
+ }
1083
+
1084
+ /**
1085
+ * Specialized parent type definition
1086
+ */
1087
+ get parent(): WindowedList | null {
1088
+ return super.parent as WindowedList | null;
1089
+ }
1090
+ set parent(value: WindowedList | null) {
1091
+ super.parent = value;
1092
+ }
1093
+
1094
+ /**
1095
+ * Attach a widget to the parent's DOM node.
1096
+ *
1097
+ * @param index - The current index of the widget in the layout.
1098
+ *
1099
+ * @param widget - The widget to attach to the parent.
1100
+ *
1101
+ * #### Notes
1102
+ * This method is called automatically by the panel layout at the
1103
+ * appropriate time. It should not be called directly by user code.
1104
+ *
1105
+ * The default implementation adds the widgets's node to the parent's
1106
+ * node at the proper location, and sends the appropriate attach
1107
+ * messages to the widget if the parent is attached to the DOM.
1108
+ *
1109
+ * Subclasses may reimplement this method to control how the widget's
1110
+ * node is added to the parent's node.
1111
+ */
1112
+ protected attachWidget(index: number, widget: Widget): void {
1113
+ // Look up the next sibling reference node.
1114
+ let ref = this.parent!.viewportNode.children[index];
1115
+
1116
+ // Send a `'before-attach'` message if the parent is attached.
1117
+ if (this.parent!.isAttached) {
1118
+ MessageLoop.sendMessage(widget, Widget.Msg.BeforeAttach);
1119
+ }
1120
+
1121
+ // Insert the widget's node before the sibling.
1122
+ this.parent!.viewportNode.insertBefore(widget.node, ref);
1123
+
1124
+ // Send an `'after-attach'` message if the parent is attached.
1125
+ if (this.parent!.isAttached) {
1126
+ MessageLoop.sendMessage(widget, Widget.Msg.AfterAttach);
1127
+ }
1128
+ }
1129
+
1130
+ /**
1131
+ * Detach a widget from the parent's DOM node.
1132
+ *
1133
+ * @param index - The previous index of the widget in the layout.
1134
+ *
1135
+ * @param widget - The widget to detach from the parent.
1136
+ *
1137
+ * #### Notes
1138
+ * This method is called automatically by the panel layout at the
1139
+ * appropriate time. It should not be called directly by user code.
1140
+ *
1141
+ * The default implementation removes the widget's node from the
1142
+ * parent's node, and sends the appropriate detach messages to the
1143
+ * widget if the parent is attached to the DOM.
1144
+ *
1145
+ * Subclasses may reimplement this method to control how the widget's
1146
+ * node is removed from the parent's node.
1147
+ */
1148
+ protected detachWidget(index: number, widget: Widget): void {
1149
+ // Send a `'before-detach'` message if the parent is attached.
1150
+ if (this.parent!.isAttached) {
1151
+ MessageLoop.sendMessage(widget, Widget.Msg.BeforeDetach);
1152
+ }
1153
+
1154
+ // Remove the widget's node from the parent.
1155
+ this.parent!.viewportNode.removeChild(widget.node);
1156
+
1157
+ // Send an `'after-detach'` message if the parent is attached.
1158
+ if (this.parent!.isAttached) {
1159
+ MessageLoop.sendMessage(widget, Widget.Msg.AfterDetach);
1160
+ }
1161
+ }
1162
+
1163
+ /**
1164
+ * Move a widget in the parent's DOM node.
1165
+ *
1166
+ * @param fromIndex - The previous index of the widget in the layout.
1167
+ *
1168
+ * @param toIndex - The current index of the widget in the layout.
1169
+ *
1170
+ * @param widget - The widget to move in the parent.
1171
+ *
1172
+ * #### Notes
1173
+ * This method is called automatically by the panel layout at the
1174
+ * appropriate time. It should not be called directly by user code.
1175
+ *
1176
+ * The default implementation moves the widget's node to the proper
1177
+ * location in the parent's node and sends the appropriate attach and
1178
+ * detach messages to the widget if the parent is attached to the DOM.
1179
+ *
1180
+ * Subclasses may reimplement this method to control how the widget's
1181
+ * node is moved in the parent's node.
1182
+ */
1183
+ protected moveWidget(
1184
+ fromIndex: number,
1185
+ toIndex: number,
1186
+ widget: Widget
1187
+ ): void {
1188
+ // Optimize move without de-/attaching as motion appends with parent attached
1189
+
1190
+ // Case fromIndex === toIndex, already checked in PanelLayout.insertWidget
1191
+
1192
+ // Look up the next sibling reference node.
1193
+ let ref = this.parent!.viewportNode.children[toIndex];
1194
+ if (fromIndex < toIndex) {
1195
+ ref.insertAdjacentElement('afterend', widget.node);
1196
+ } else {
1197
+ ref.insertAdjacentElement('beforebegin', widget.node);
1198
+ }
1199
+ }
1200
+
1201
+ /**
1202
+ * A message handler invoked on an `'update-request'` message.
1203
+ *
1204
+ * #### Notes
1205
+ * This is a reimplementation of the base class method,
1206
+ * and is a no-op.
1207
+ */
1208
+ protected onUpdateRequest(msg: Message): void {
1209
+ // This is a no-op.
1210
+ }
1211
+ }
1212
+
1213
+ /**
1214
+ * A namespace for windowed list
1215
+ */
1216
+ export namespace WindowedList {
1217
+ /**
1218
+ * Windowed list model interface
1219
+ */
1220
+ export interface IModel extends IDisposable {
1221
+ /**
1222
+ * Provide a best guess for the widget size at position index
1223
+ *
1224
+ * #### Notes
1225
+ *
1226
+ * This function should be very light to compute especially when
1227
+ * returning the default size.
1228
+ * The default value should be constant (i.e. two calls with `null` should
1229
+ * return the same value). But it can change for a given `index`.
1230
+ *
1231
+ * @param index Widget position
1232
+ * @returns Estimated widget size
1233
+ */
1234
+ estimateWidgetSize: (index: number) => number;
1235
+
1236
+ /**
1237
+ * Get the total list size.
1238
+ *
1239
+ * @returns Total estimated size
1240
+ */
1241
+ getEstimatedTotalSize(): number;
1242
+
1243
+ /**
1244
+ * Get the scroll offset to display an item in the viewport.
1245
+ *
1246
+ * @param index Item index
1247
+ * @param align Where to align the item in the viewport
1248
+ * @returns The needed scroll offset
1249
+ */
1250
+ getOffsetForIndexAndAlignment(index: number, align: ScrollToAlign): number;
1251
+ /**
1252
+ * Compute the items range to display.
1253
+ *
1254
+ * It returns ``null`` if the range does not need to be updated.
1255
+ *
1256
+ * @returns The current items range to display
1257
+ */
1258
+ getRangeToRender(): WindowIndex | null;
1259
+
1260
+ /**
1261
+ * Return the viewport top position and height for range spanning from
1262
+ * ``startIndex`` to ``stopIndex``.
1263
+ *
1264
+ * @param start First item in viewport index
1265
+ * @param stop Last item in viewport index
1266
+ * @returns The viewport top position and its height
1267
+ */
1268
+ getSpan(start: number, stop: number): [number, number];
1269
+
1270
+ /**
1271
+ * List widget height
1272
+ */
1273
+ height: number;
1274
+
1275
+ /**
1276
+ * Items list to be rendered
1277
+ */
1278
+ itemsList: {
1279
+ length: number;
1280
+ changed: ISignal<any, IObservableList.IChangedArgs<any>>;
1281
+ } | null;
1282
+
1283
+ /**
1284
+ * Number of widgets to render in addition to those
1285
+ * visible in the viewport.
1286
+ */
1287
+ overscanCount: number;
1288
+
1289
+ /**
1290
+ * WindowedListModel caches offsets and measurements for each index for performance purposes.
1291
+ * This method clears that cached data for all items after (and including) the specified index.
1292
+ *
1293
+ * The list will automatically re-render after the index is reset.
1294
+ *
1295
+ * @param index
1296
+ */
1297
+ resetAfterIndex(index: number): void;
1298
+
1299
+ /**
1300
+ * Viewport scroll offset.
1301
+ */
1302
+ scrollOffset: number;
1303
+
1304
+ /**
1305
+ * Update item sizes.
1306
+ *
1307
+ * This should be called when the real item sizes has been
1308
+ * measured.
1309
+ *
1310
+ * @param sizes New sizes per item index
1311
+ * @returns Whether some sizes changed or not
1312
+ */
1313
+ setWidgetSize(sizes: { index: number; size: number }[]): boolean;
1314
+
1315
+ /**
1316
+ * A signal emitted when any model state changes.
1317
+ */
1318
+ readonly stateChanged: ISignal<
1319
+ IModel,
1320
+ IChangedArgs<
1321
+ any,
1322
+ any,
1323
+ 'count' | 'index' | 'list' | 'overscanCount' | 'windowingActive'
1324
+ >
1325
+ >;
1326
+
1327
+ /**
1328
+ * Total number of widgets in the list
1329
+ */
1330
+ widgetCount: number;
1331
+
1332
+ /**
1333
+ * Whether windowing is active or not.
1334
+ */
1335
+ windowingActive: boolean;
1336
+
1337
+ /**
1338
+ * Widget factory for the list items.
1339
+ *
1340
+ * Caching the resulting widgets should be done by the callee.
1341
+ *
1342
+ * @param index List index
1343
+ * @returns The widget at the given position
1344
+ */
1345
+ widgetRenderer: (index: number) => Widget;
1346
+ }
1347
+
1348
+ /**
1349
+ * Windowed list model constructor options
1350
+ */
1351
+ export interface IModelOptions {
1352
+ /**
1353
+ * Total number of widgets in the list.
1354
+ *
1355
+ * #### Notes
1356
+ * If an observable list is provided this will be ignored.
1357
+ */
1358
+ count?: number;
1359
+
1360
+ /**
1361
+ * Dynamic list of items
1362
+ */
1363
+ itemsList?: IObservableList<any>;
1364
+
1365
+ /**
1366
+ * Number of widgets to render in addition to those
1367
+ * visible in the viewport.
1368
+ */
1369
+ overscanCount?: number;
1370
+
1371
+ /**
1372
+ * Whether windowing is active or not.
1373
+ *
1374
+ * This is true by default.
1375
+ */
1376
+ windowingActive?: boolean;
1377
+ }
1378
+
1379
+ /**
1380
+ * Windowed list view constructor options
1381
+ */
1382
+ export interface IOptions<
1383
+ T extends WindowedList.IModel = WindowedList.IModel
1384
+ > {
1385
+ /**
1386
+ * Windowed list model to display
1387
+ */
1388
+ model: T;
1389
+ /**
1390
+ * Windowed list layout
1391
+ */
1392
+ layout?: WindowedLayout;
1393
+ }
1394
+
1395
+ /**
1396
+ * Item list metadata
1397
+ */
1398
+ export type ItemMetadata = {
1399
+ /**
1400
+ * Item vertical offset in the container
1401
+ */
1402
+ offset: number;
1403
+ /**
1404
+ * Item height
1405
+ */
1406
+ size: number;
1407
+ /**
1408
+ * Whether the size is an estimation or a measurement.
1409
+ */
1410
+ measured?: boolean;
1411
+ };
1412
+
1413
+ /**
1414
+ * Type of scroll
1415
+ */
1416
+ export type ScrollToAlign = 'auto' | 'smart' | 'center' | 'start' | 'end';
1417
+
1418
+ /**
1419
+ * Widget range in view port
1420
+ */
1421
+ export type WindowIndex = [number, number, number, number];
1422
+ }