virtua 0.51.3 → 0.52.1
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.
- package/README.md +37 -13
- package/lib/angular/VGrid.d.ts +249 -0
- package/lib/angular/VList.d.ts +3 -3
- package/lib/angular/Virtualizer.d.ts +3 -3
- package/lib/angular/WindowVirtualizer.d.ts +3 -3
- package/lib/angular/index.d.ts +2 -0
- package/lib/angular/index.js +1152 -327
- package/lib/angular/index.js.map +1 -1
- package/lib/core/grid.d.ts +30 -0
- package/lib/core/index.cjs +481 -265
- package/lib/core/index.cjs.map +1 -1
- package/lib/core/index.d.ts +5 -3
- package/lib/core/index.js +464 -249
- package/lib/core/index.js.map +1 -1
- package/lib/core/layouts/grid.d.ts +23 -0
- package/lib/core/scroll-to.d.ts +50 -1
- package/lib/core/types.d.ts +0 -25
- package/lib/index.cjs +763 -558
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +732 -509
- package/lib/index.js.map +1 -1
- package/lib/react/VGrid.d.ts +105 -80
- package/lib/react/index.d.ts +3 -2
- package/lib/solid/VGrid.d.ts +193 -0
- package/lib/solid/index.cjs +819 -288
- package/lib/solid/index.cjs.map +1 -1
- package/lib/solid/index.d.ts +3 -0
- package/lib/solid/index.js +788 -270
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.jsx +741 -124
- package/lib/solid/index.jsx.map +1 -1
- package/lib/svelte/GridCell.svelte +44 -0
- package/lib/svelte/GridRow.svelte +42 -0
- package/lib/svelte/GridRowGroup.svelte +42 -0
- package/lib/svelte/VGrid.svelte +238 -0
- package/lib/svelte/VGrid.type.d.ts +185 -0
- package/lib/svelte/index.d.ts +3 -0
- package/lib/svelte/index.js +2 -1
- package/lib/vue/VGrid.d.ts +194 -0
- package/lib/vue/index.cjs +888 -376
- package/lib/vue/index.cjs.map +1 -1
- package/lib/vue/index.d.ts +3 -0
- package/lib/vue/index.js +860 -349
- package/lib/vue/index.js.map +1 -1
- package/package.json +4 -3
package/lib/solid/index.jsx
CHANGED
|
@@ -3,10 +3,11 @@ import { Dynamic, isServer } from "solid-js/web";
|
|
|
3
3
|
|
|
4
4
|
//#region src/core/utils.ts
|
|
5
5
|
var NULL = null;
|
|
6
|
+
var EMPTY = [];
|
|
6
7
|
var { min, max, abs, floor } = Math;
|
|
7
8
|
var clamp = (value, minValue, maxValue) => min(maxValue, max(minValue, value));
|
|
8
9
|
var sort = (arr) => {
|
|
9
|
-
return
|
|
10
|
+
return arr.sort((a, b) => a - b);
|
|
10
11
|
};
|
|
11
12
|
var timeout = setTimeout;
|
|
12
13
|
var cancelTimeout = clearTimeout;
|
|
@@ -51,6 +52,7 @@ var ACTION_ITEMS_LENGTH_CHANGE = 5;
|
|
|
51
52
|
var ACTION_START_OFFSET_CHANGE = 6;
|
|
52
53
|
var ACTION_MANUAL_SCROLL = 7;
|
|
53
54
|
var ACTION_BEFORE_MANUAL_SMOOTH_SCROLL = 8;
|
|
55
|
+
var ACTION_RELAYOUT = 9;
|
|
54
56
|
var UPDATE_VIRTUAL_STATE = 1;
|
|
55
57
|
var UPDATE_SIZE_EVENT = 2;
|
|
56
58
|
var UPDATE_SCROLL_EVENT = 4;
|
|
@@ -250,6 +252,11 @@ var createVirtualStore = ({ $getRange: getRange, $findIndex: findIndex, $getItem
|
|
|
250
252
|
_scrollMode = SCROLL_BY_MANUAL_SCROLL;
|
|
251
253
|
break;
|
|
252
254
|
}
|
|
255
|
+
case 9: {
|
|
256
|
+
applyJump(payload);
|
|
257
|
+
mutated = 1 + 2;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
253
260
|
case 8: {
|
|
254
261
|
_frozenRange = getRange(payload, payload + viewportSize);
|
|
255
262
|
mutated = 1;
|
|
@@ -382,10 +389,10 @@ var createListLayout = (length, itemSize, snapshot) => {
|
|
|
382
389
|
}
|
|
383
390
|
});
|
|
384
391
|
computedOffsetIndex = -1;
|
|
385
|
-
|
|
386
|
-
const len =
|
|
392
|
+
sort(measuredSizes);
|
|
393
|
+
const len = measuredSizes.length;
|
|
387
394
|
const mid = len / 2 | 0;
|
|
388
|
-
const median = len % 2 === 0 ? (
|
|
395
|
+
const median = len % 2 === 0 ? (measuredSizes[mid - 1] + measuredSizes[mid]) / 2 : measuredSizes[mid];
|
|
389
396
|
const prevDefaultItemSize = defaultItemSize;
|
|
390
397
|
return ((defaultItemSize = median) - prevDefaultItemSize) * max(startIndex - measuredCountBeforeStart, 0);
|
|
391
398
|
},
|
|
@@ -393,6 +400,457 @@ var createListLayout = (length, itemSize, snapshot) => {
|
|
|
393
400
|
};
|
|
394
401
|
};
|
|
395
402
|
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/core/layouts/grid.ts
|
|
405
|
+
var getAxisLength = (axis) => typeof axis === "number" ? axis : axis.length;
|
|
406
|
+
var getAxisItem = (axis, index) => typeof axis === "number" ? index : axis[index];
|
|
407
|
+
var createGridLayout = (axis, size, gap = 0) => {
|
|
408
|
+
if (typeof size === "number") {
|
|
409
|
+
let length = getAxisLength(axis);
|
|
410
|
+
let itemSize = size;
|
|
411
|
+
const findIndex = (offset) => itemSize + gap ? clamp(floor(offset / (itemSize + gap)), 0, length - 1) : 0;
|
|
412
|
+
return {
|
|
413
|
+
$getRange: (startOffset, endOffset) => [findIndex(startOffset), findIndex(endOffset)],
|
|
414
|
+
$findIndex: findIndex,
|
|
415
|
+
$getItemOffset: (index) => index * (itemSize + gap),
|
|
416
|
+
$getItemSize: () => itemSize,
|
|
417
|
+
$setItemSize: () => false,
|
|
418
|
+
$isSizeEqual: () => false,
|
|
419
|
+
$getTotalSize: () => length ? length * (itemSize + gap) - gap : 0,
|
|
420
|
+
$getLength: () => length,
|
|
421
|
+
$setLength: (nextLength) => {
|
|
422
|
+
length = nextLength;
|
|
423
|
+
return 0;
|
|
424
|
+
},
|
|
425
|
+
$isMeasurable: () => false,
|
|
426
|
+
$setAxis: (_axis, nextSize, scrollOffset) => {
|
|
427
|
+
if (typeof nextSize !== "number" || nextSize === itemSize) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
const jump = findIndex(scrollOffset) * (nextSize - itemSize);
|
|
431
|
+
itemSize = nextSize;
|
|
432
|
+
return jump;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
const isAuto = size === "auto";
|
|
437
|
+
let currentAxis;
|
|
438
|
+
let currentSize = size;
|
|
439
|
+
const length = getAxisLength(axis);
|
|
440
|
+
const autos = [];
|
|
441
|
+
const inner = createListLayout(length, undefined, [[], 40 + gap]);
|
|
442
|
+
const isMeasurable = (index) => isAuto || !!autos[index];
|
|
443
|
+
const layout = {
|
|
444
|
+
$getRange: inner.$getRange,
|
|
445
|
+
$findIndex: inner.$findIndex,
|
|
446
|
+
$getItemOffset: inner.$getItemOffset,
|
|
447
|
+
$getItemSize: (index) => inner.$getItemSize(index) - gap,
|
|
448
|
+
$setItemSize: (index, s) => isMeasurable(index) && inner.$setItemSize(index, s + gap),
|
|
449
|
+
$isSizeEqual: (index, s) => inner.$isSizeEqual(index, s + gap),
|
|
450
|
+
$getTotalSize: () => inner.$getLength() ? inner.$getTotalSize() - gap : 0,
|
|
451
|
+
$getLength: inner.$getLength,
|
|
452
|
+
$setLength: inner.$setLength,
|
|
453
|
+
$estimateDefaultSize: isAuto ? inner.$estimateDefaultSize : undefined,
|
|
454
|
+
$isMeasurable: isMeasurable,
|
|
455
|
+
$setAxis: (nextAxis, requestedSize, scrollOffset, mutable) => {
|
|
456
|
+
if (isAuto) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const nextSize = typeof requestedSize === "number" || requestedSize === "auto" ? currentSize : requestedSize;
|
|
460
|
+
const length = inner.$getLength();
|
|
461
|
+
if (!mutable && nextAxis === currentAxis && nextSize === currentSize && length === autos.length) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
currentAxis = nextAxis;
|
|
465
|
+
currentSize = nextSize;
|
|
466
|
+
autos.length = length;
|
|
467
|
+
const anchorIndex = inner.$findIndex(scrollOffset);
|
|
468
|
+
const prevOffset = inner.$getItemOffset(anchorIndex);
|
|
469
|
+
let changed;
|
|
470
|
+
for (let i = 0; i < length; i++) {
|
|
471
|
+
const item = nextAxis[i];
|
|
472
|
+
const itemSize = item !== null && typeof item === "object" ? item[nextSize] : null;
|
|
473
|
+
const isAutoItem = typeof itemSize !== "number";
|
|
474
|
+
if (!isAutoItem || !autos[i]) {
|
|
475
|
+
autos[i] = isAutoItem;
|
|
476
|
+
const target = isAutoItem ? -1 : itemSize + gap;
|
|
477
|
+
if (!inner.$isSizeEqual(i, target)) {
|
|
478
|
+
inner.$setItemSize(i, target);
|
|
479
|
+
changed = true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (!changed) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
return inner.$getItemOffset(anchorIndex) - prevOffset;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
layout.$setAxis(axis, size, 0);
|
|
490
|
+
return layout;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/core/grid.ts
|
|
495
|
+
var updateGridAxis = (store, layout, axis, size, mutable) => {
|
|
496
|
+
const length = getAxisLength(axis);
|
|
497
|
+
if (length !== store.$getItemsLength()) {
|
|
498
|
+
store.$update(5, [length]);
|
|
499
|
+
}
|
|
500
|
+
const jump = layout.$setAxis(axis, size, store.$getScrollOffset() - store.$getItemOffset(0), mutable);
|
|
501
|
+
if (jump != null) {
|
|
502
|
+
store.$update(9, jump);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
var rowStatesCache = /*#__PURE__*/ new WeakMap();
|
|
506
|
+
var hasTrackIn = (extras, from, to, pinnedStart, start, end, trailStart) => {
|
|
507
|
+
if (from < pinnedStart || max(from, start) < min(to, end + 1) || trailStart < to) {
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
for (const i of extras) {
|
|
511
|
+
if (i >= from && i < to) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return false;
|
|
516
|
+
};
|
|
517
|
+
var getSectionStarts = (sectionRows, pinnedStart, trailStart) => {
|
|
518
|
+
const starts = [];
|
|
519
|
+
for (const rowIndex of sectionRows) {
|
|
520
|
+
if (rowIndex >= pinnedStart && rowIndex < trailStart) {
|
|
521
|
+
starts.push(rowIndex);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return sort(starts);
|
|
525
|
+
};
|
|
526
|
+
var getSection = (starts, rowIndex, trailStart) => {
|
|
527
|
+
if (rowIndex >= trailStart) {
|
|
528
|
+
return -1;
|
|
529
|
+
}
|
|
530
|
+
let lo = 0;
|
|
531
|
+
let hi = starts.length;
|
|
532
|
+
while (lo < hi) {
|
|
533
|
+
const mid = lo + hi >> 1;
|
|
534
|
+
if (starts[mid] <= rowIndex) {
|
|
535
|
+
lo = mid + 1;
|
|
536
|
+
} else {
|
|
537
|
+
hi = mid;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return lo - 1;
|
|
541
|
+
};
|
|
542
|
+
var addSectionHeader = (extras, sectionStarts, rowIndex, trailStart) => {
|
|
543
|
+
const section = getSection(sectionStarts, rowIndex, trailStart);
|
|
544
|
+
if (section >= 0) {
|
|
545
|
+
extras.push(sectionStarts[section]);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
var getTrackIndexes = (extras, count, pinnedStart, start, end, trailStart) => {
|
|
549
|
+
const indexes = [];
|
|
550
|
+
for (let i = 0; i < pinnedStart; i++) {
|
|
551
|
+
indexes.push(i);
|
|
552
|
+
}
|
|
553
|
+
const extrasLength = extras.length;
|
|
554
|
+
let e = 0;
|
|
555
|
+
let last = pinnedStart - 1;
|
|
556
|
+
for (; e < extrasLength && extras[e] < start; e++) {
|
|
557
|
+
const i = extras[e];
|
|
558
|
+
if (i > last) {
|
|
559
|
+
indexes.push(i);
|
|
560
|
+
last = i;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
for (let i = start; i <= end; i++) {
|
|
564
|
+
indexes.push(i);
|
|
565
|
+
}
|
|
566
|
+
last = end;
|
|
567
|
+
for (; e < extrasLength && extras[e] < trailStart; e++) {
|
|
568
|
+
const i = extras[e];
|
|
569
|
+
if (i > last) {
|
|
570
|
+
indexes.push(i);
|
|
571
|
+
last = i;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
for (let i = trailStart; i < count; i++) {
|
|
575
|
+
indexes.push(i);
|
|
576
|
+
}
|
|
577
|
+
return indexes;
|
|
578
|
+
};
|
|
579
|
+
var getSpanRowEnd = (span, rowCount) => min(span.rowIndex + (span.rowSpan || 1), rowCount);
|
|
580
|
+
var getSpanColEnd = (span, colCount) => min(span.colIndex + (span.colSpan || 1), colCount);
|
|
581
|
+
var getTemplate = (layout, indexes, measured, sortedCuts, measuredSize, count) => {
|
|
582
|
+
const indexesLength = indexes.length;
|
|
583
|
+
const cutsLength = sortedCuts.length;
|
|
584
|
+
let template = "[l0]";
|
|
585
|
+
let line = 0;
|
|
586
|
+
let i = 0;
|
|
587
|
+
let c = 0;
|
|
588
|
+
while (i < indexesLength || c < cutsLength) {
|
|
589
|
+
const index = i < indexesLength ? indexes[i] : count;
|
|
590
|
+
const cut = c < cutsLength ? sortedCuts[c] : count;
|
|
591
|
+
if (cut <= line) {
|
|
592
|
+
c++;
|
|
593
|
+
} else {
|
|
594
|
+
let to;
|
|
595
|
+
let size;
|
|
596
|
+
if (index === line) {
|
|
597
|
+
to = line + 1;
|
|
598
|
+
const m = measured[i];
|
|
599
|
+
size = m == null ? layout.$getItemSize(line) + "px" : m ? measuredSize : "minmax(" + layout.$getItemSize(line) + "px,auto)";
|
|
600
|
+
i++;
|
|
601
|
+
} else {
|
|
602
|
+
to = min(index, cut);
|
|
603
|
+
size = "minmax(" + (layout.$getItemOffset(to - 1) + layout.$getItemSize(to - 1) - layout.$getItemOffset(line)) + "px,auto)";
|
|
604
|
+
}
|
|
605
|
+
template += " " + size + " [l" + to + "]";
|
|
606
|
+
line = to;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (line < count) {
|
|
610
|
+
template += " minmax(" + (layout.$getTotalSize() - layout.$getItemOffset(line)) + "px,auto) [l" + count + "]";
|
|
611
|
+
}
|
|
612
|
+
return template;
|
|
613
|
+
};
|
|
614
|
+
var gridStyleToString = (style) => {
|
|
615
|
+
let css = "";
|
|
616
|
+
for (const key in style) {
|
|
617
|
+
css += key.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase()) + ":" + style[key] + ";";
|
|
618
|
+
}
|
|
619
|
+
return css;
|
|
620
|
+
};
|
|
621
|
+
var createGridPlan = (rowLayout, colLayout, rowRange, colRange, headerRows = 0, sectionRows = EMPTY, footerRows = 0, headerCols = 0, footerCols = 0, spans = EMPTY, kept = EMPTY, sortedCell) => {
|
|
622
|
+
const rowCount = rowLayout.$getLength();
|
|
623
|
+
const colCount = colLayout.$getLength();
|
|
624
|
+
const rowPinnedStart = min(headerRows, rowCount);
|
|
625
|
+
const rowTrailStart = max(rowCount - footerRows, rowPinnedStart);
|
|
626
|
+
const colPinnedStart = min(headerCols, colCount);
|
|
627
|
+
const colTrailStart = max(colCount - footerCols, colPinnedStart);
|
|
628
|
+
const rowRangeStart = clamp(rowRange[0], rowPinnedStart, rowTrailStart);
|
|
629
|
+
const rowRangeEnd = min(rowRange[1], rowTrailStart - 1);
|
|
630
|
+
const colRangeStart = clamp(colRange[0], colPinnedStart, colTrailStart);
|
|
631
|
+
const colRangeEnd = min(colRange[1], colTrailStart - 1);
|
|
632
|
+
const sectionStarts = getSectionStarts(sectionRows, rowPinnedStart, rowTrailStart);
|
|
633
|
+
const rowHeaderCol = max(colPinnedStart - 1, 0);
|
|
634
|
+
const extraRows = [];
|
|
635
|
+
const extraCols = [];
|
|
636
|
+
const extraCells = [];
|
|
637
|
+
for (const cell of kept) {
|
|
638
|
+
if (cell.rowIndex < rowCount && cell.colIndex < colCount) {
|
|
639
|
+
extraCells.push(cell);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const sectionLength = sectionStarts.length;
|
|
643
|
+
if (sectionLength) {
|
|
644
|
+
addSectionHeader(extraRows, sectionStarts, rowRangeStart, rowTrailStart);
|
|
645
|
+
extraCols.push(rowHeaderCol);
|
|
646
|
+
}
|
|
647
|
+
let waiting = spans;
|
|
648
|
+
let l = 0;
|
|
649
|
+
do {
|
|
650
|
+
for (; l < extraCells.length; l++) {
|
|
651
|
+
const { rowIndex, colIndex } = extraCells[l];
|
|
652
|
+
extraRows.push(rowIndex);
|
|
653
|
+
addSectionHeader(extraRows, sectionStarts, rowIndex, rowTrailStart);
|
|
654
|
+
extraCols.push(colIndex);
|
|
655
|
+
}
|
|
656
|
+
const rest = [];
|
|
657
|
+
for (const span of waiting) {
|
|
658
|
+
const row = span.rowIndex;
|
|
659
|
+
const col = span.colIndex;
|
|
660
|
+
const rowTo = getSpanRowEnd(span, rowCount);
|
|
661
|
+
const colTo = getSpanColEnd(span, colCount);
|
|
662
|
+
if (row < rowCount && col < colCount && (rowTo - row > 1 || colTo - col > 1)) {
|
|
663
|
+
if (hasTrackIn(extraRows, row, rowTo, rowPinnedStart, rowRangeStart, rowRangeEnd, rowTrailStart)) {
|
|
664
|
+
if (hasTrackIn(extraCols, col, colTo, colPinnedStart, colRangeStart, colRangeEnd, colTrailStart)) {
|
|
665
|
+
extraCells.push(span);
|
|
666
|
+
} else {
|
|
667
|
+
const section = getSection(sectionStarts, rowTo - 1, rowTrailStart);
|
|
668
|
+
if (row < rowPinnedStart || section >= 0 && sectionStarts[section] >= row) {
|
|
669
|
+
rest.push(span);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
} else if (col < colPinnedStart) {
|
|
673
|
+
rest.push(span);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
waiting = rest;
|
|
678
|
+
} while (l < extraCells.length);
|
|
679
|
+
sort(extraRows);
|
|
680
|
+
sort(extraCols);
|
|
681
|
+
const rowIndexes = getTrackIndexes(extraRows, rowCount, rowPinnedStart, rowRangeStart, rowRangeEnd, rowTrailStart);
|
|
682
|
+
const cols = getTrackIndexes(extraCols, colCount, colPinnedStart, colRangeStart, colRangeEnd, colTrailStart);
|
|
683
|
+
const rowLength = rowIndexes.length;
|
|
684
|
+
const colLength = cols.length;
|
|
685
|
+
const spanCells = new Map();
|
|
686
|
+
const rowCuts = [];
|
|
687
|
+
const colCuts = [];
|
|
688
|
+
for (const span of extraCells) {
|
|
689
|
+
const rowTo = getSpanRowEnd(span, rowCount);
|
|
690
|
+
const colTo = getSpanColEnd(span, colCount);
|
|
691
|
+
rowCuts.push(rowTo);
|
|
692
|
+
colCuts.push(colTo);
|
|
693
|
+
const colStart = cols.indexOf(span.colIndex);
|
|
694
|
+
for (let i = rowIndexes.indexOf(span.rowIndex); i < rowLength && rowIndexes[i] < rowTo; i++) {
|
|
695
|
+
const rowKey = rowIndexes[i] * colCount;
|
|
696
|
+
for (let j = colStart; j < colLength && cols[j] < colTo; j++) {
|
|
697
|
+
spanCells.set(rowKey + cols[j], span);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
const measuredCols = [];
|
|
702
|
+
for (const colIndex of cols) {
|
|
703
|
+
measuredCols.push(colLayout.$isMeasurable(colIndex) ? false : null);
|
|
704
|
+
}
|
|
705
|
+
const measuredRows = [];
|
|
706
|
+
const stickyTop = rowLayout.$getItemOffset(rowPinnedStart);
|
|
707
|
+
const groups = [];
|
|
708
|
+
let groupRows = groups;
|
|
709
|
+
const prev = rowStatesCache.get(rowLayout);
|
|
710
|
+
const rowStates = new Map();
|
|
711
|
+
for (const rowIndex of rowIndexes) {
|
|
712
|
+
const pinnedTop = rowIndex < rowPinnedStart;
|
|
713
|
+
const pinnedBottom = rowIndex >= rowTrailStart;
|
|
714
|
+
const rowInRangeOrPinnedToEnd = pinnedBottom || rowIndex >= rowRangeStart && rowIndex <= rowRangeEnd;
|
|
715
|
+
const section = getSection(sectionStarts, rowIndex, rowTrailStart);
|
|
716
|
+
const groupStart = pinnedTop ? 0 : pinnedBottom ? rowTrailStart : section < 0 ? -1 : sectionStarts[section];
|
|
717
|
+
if (rowIndex === groupStart) {
|
|
718
|
+
const groupEnd = pinnedTop ? rowPinnedStart : pinnedBottom ? rowCount : section + 1 < sectionLength ? sectionStarts[section + 1] : rowTrailStart;
|
|
719
|
+
rowCuts.push(groupEnd);
|
|
720
|
+
const rows = [];
|
|
721
|
+
groups.push({
|
|
722
|
+
$key: pinnedTop ? -1 : pinnedBottom ? -2 : -3 - groupStart,
|
|
723
|
+
$rows: rows,
|
|
724
|
+
$style: getBoxStyle(groupStart, groupEnd, pinnedTop || pinnedBottom ? 0 : null, pinnedBottom ? "bottom" : "top", 4)
|
|
725
|
+
});
|
|
726
|
+
groupRows = rows;
|
|
727
|
+
} else if (groupStart < 0) {
|
|
728
|
+
groupRows = groups;
|
|
729
|
+
}
|
|
730
|
+
const isSectionHeaderRow = section >= 0 && rowIndex === groupStart;
|
|
731
|
+
const rowTop = isSectionHeaderRow ? stickyTop : null;
|
|
732
|
+
const rowKey = rowIndex * colCount;
|
|
733
|
+
const prevRow = prev && prev.get(rowIndex);
|
|
734
|
+
const prevCells = prevRow && prevRow.$cells;
|
|
735
|
+
const rowCells = [];
|
|
736
|
+
let p = 0;
|
|
737
|
+
let measuredRow = rowLayout.$isMeasurable(rowIndex) ? false : null;
|
|
738
|
+
let rowEnd = rowIndex + 1;
|
|
739
|
+
let changed = false;
|
|
740
|
+
for (let i = 0; i < colLength; i++) {
|
|
741
|
+
const colIndex = cols[i];
|
|
742
|
+
const startPinned = colIndex < colPinnedStart;
|
|
743
|
+
const endPinned = colIndex >= colTrailStart;
|
|
744
|
+
const colInRangeOrPinnedToEnd = endPinned || colIndex >= colRangeStart && colIndex <= colRangeEnd;
|
|
745
|
+
const span = spanCells.get(rowKey + colIndex);
|
|
746
|
+
if (span ? span.rowIndex === rowIndex && span.colIndex === colIndex : rowInRangeOrPinnedToEnd && colInRangeOrPinnedToEnd || pinnedTop || isSectionHeaderRow || startPinned) {
|
|
747
|
+
const rowTo = span ? getSpanRowEnd(span, rowCount) : rowIndex + 1;
|
|
748
|
+
const colTo = span ? getSpanColEnd(span, colCount) : colIndex + 1;
|
|
749
|
+
const spansRows = rowTo - rowIndex > 1;
|
|
750
|
+
const spansCols = colTo - colIndex > 1;
|
|
751
|
+
const spanning = spansRows || spansCols;
|
|
752
|
+
const rowSpan = spanning ? rowTo - rowIndex : undefined;
|
|
753
|
+
const colSpan = spanning ? colTo - colIndex : undefined;
|
|
754
|
+
let measureRowIndex;
|
|
755
|
+
let measureColIndex;
|
|
756
|
+
rowEnd = max(rowEnd, rowTo);
|
|
757
|
+
const stickyStart = startPinned ? colLayout.$getItemOffset(colIndex) : null;
|
|
758
|
+
const stickyEnd = endPinned ? colLayout.$getTotalSize() - colLayout.$getItemOffset(colTo - 1) - colLayout.$getItemSize(colTo - 1) : null;
|
|
759
|
+
if (measuredRow === false && !spansRows) {
|
|
760
|
+
measureRowIndex = rowIndex;
|
|
761
|
+
measuredRow = true;
|
|
762
|
+
}
|
|
763
|
+
if (measuredCols[i] === false && !spansCols) {
|
|
764
|
+
measureColIndex = colIndex;
|
|
765
|
+
measuredCols[i] = true;
|
|
766
|
+
}
|
|
767
|
+
const role = pinnedTop ? "columnheader" : colIndex === rowHeaderCol && (startPinned || isSectionHeaderRow) ? "rowheader" : "cell";
|
|
768
|
+
const sortOrder = role !== "cell" && sortedCell && sortedCell.rowIndex === rowIndex && sortedCell.colIndex === colIndex ? sortedCell.order : undefined;
|
|
769
|
+
let cell;
|
|
770
|
+
if (prevCells) {
|
|
771
|
+
while (p < prevCells.length && prevCells[p].$col < colIndex) {
|
|
772
|
+
p++;
|
|
773
|
+
}
|
|
774
|
+
if (p < prevCells.length) {
|
|
775
|
+
cell = prevCells[p];
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (!cell || cell.$col !== colIndex || cell.$rowSpan !== rowSpan || cell.$colSpan !== colSpan || cell.$start !== stickyStart || cell.$end !== stickyEnd || cell.$measureRow !== measureRowIndex || cell.$measureCol !== measureColIndex || cell.$role !== role || cell.$sort !== sortOrder) {
|
|
779
|
+
const style = {
|
|
780
|
+
contain: "layout style",
|
|
781
|
+
display: "grid",
|
|
782
|
+
gridArea: spanning ? "1/l" + colIndex + "/l" + rowTo + "/l" + colTo : "1/l" + colIndex
|
|
783
|
+
};
|
|
784
|
+
if (spansRows) {
|
|
785
|
+
style["height"] = "0px";
|
|
786
|
+
style["minHeight"] = "100%";
|
|
787
|
+
style["zIndex"] = 1;
|
|
788
|
+
}
|
|
789
|
+
if (spansCols) {
|
|
790
|
+
style["width"] = "0px";
|
|
791
|
+
style["minWidth"] = "100%";
|
|
792
|
+
}
|
|
793
|
+
if (startPinned || endPinned) {
|
|
794
|
+
if (startPinned) {
|
|
795
|
+
style["insetInlineStart"] = stickyStart + "px";
|
|
796
|
+
} else {
|
|
797
|
+
style["insetInlineEnd"] = stickyEnd + "px";
|
|
798
|
+
}
|
|
799
|
+
style["position"] = "sticky";
|
|
800
|
+
style["zIndex"] = 2;
|
|
801
|
+
}
|
|
802
|
+
cell = {
|
|
803
|
+
$col: colIndex,
|
|
804
|
+
$rowSpan: rowSpan,
|
|
805
|
+
$colSpan: colSpan,
|
|
806
|
+
$measureRow: measureRowIndex,
|
|
807
|
+
$measureCol: measureColIndex,
|
|
808
|
+
$role: role,
|
|
809
|
+
$sort: sortOrder,
|
|
810
|
+
$style: style,
|
|
811
|
+
$start: stickyStart,
|
|
812
|
+
$end: stickyEnd
|
|
813
|
+
};
|
|
814
|
+
changed = true;
|
|
815
|
+
}
|
|
816
|
+
rowCells.push(cell);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
measuredRows.push(measuredRow);
|
|
820
|
+
if (rowCells.length) {
|
|
821
|
+
const row = prevRow && !changed && prevRow.$cells.length === rowCells.length && prevRow.$top === rowTop ? prevRow : {
|
|
822
|
+
$row: rowIndex,
|
|
823
|
+
$cells: rowCells,
|
|
824
|
+
$style: getBoxStyle(rowIndex, rowEnd, rowTop, "top", 3),
|
|
825
|
+
$top: rowTop
|
|
826
|
+
};
|
|
827
|
+
rowStates.set(rowIndex, row);
|
|
828
|
+
groupRows.push(row);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
rowStatesCache.set(rowLayout, rowStates);
|
|
832
|
+
return {
|
|
833
|
+
$rowTemplate: getTemplate(rowLayout, rowIndexes, measuredRows, sort(rowCuts), "max-content", rowCount),
|
|
834
|
+
$colTemplate: getTemplate(colLayout, cols, measuredCols, sort(colCuts), "minmax(max-content,auto)", colCount),
|
|
835
|
+
$groups: groups
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
var getBoxStyle = (from, to, inset, edge, zIndex) => {
|
|
839
|
+
const style = {
|
|
840
|
+
display: "grid",
|
|
841
|
+
gridTemplateRows: "subgrid",
|
|
842
|
+
gridTemplateColumns: "subgrid",
|
|
843
|
+
gridColumn: "1/-1",
|
|
844
|
+
gridRow: "l" + from + "/l" + to
|
|
845
|
+
};
|
|
846
|
+
if (inset != null) {
|
|
847
|
+
style["position"] = "sticky";
|
|
848
|
+
style[edge] = inset + "px";
|
|
849
|
+
style["zIndex"] = zIndex;
|
|
850
|
+
}
|
|
851
|
+
return style;
|
|
852
|
+
};
|
|
853
|
+
|
|
396
854
|
//#endregion
|
|
397
855
|
//#region src/core/observer.ts
|
|
398
856
|
var createResizeObserver = (cb) => {
|
|
@@ -716,14 +1174,11 @@ var createContainerGridDriver = (rowStore, colStore) => {
|
|
|
716
1174
|
let rowScrollObserver;
|
|
717
1175
|
let colScrollObserver;
|
|
718
1176
|
let initialized = createPromise();
|
|
719
|
-
const
|
|
720
|
-
const
|
|
721
|
-
const maybeCachedColIndexes = new Set();
|
|
722
|
-
const sizeCache = new Map();
|
|
723
|
-
const getKey = (rowIndex, colIndex) => `${rowIndex}-${colIndex}`;
|
|
1177
|
+
const mountedRowIndexes = new WeakMap();
|
|
1178
|
+
const mountedColIndexes = new WeakMap();
|
|
724
1179
|
const resizeObserver = createResizeObserver((entries) => {
|
|
725
|
-
const
|
|
726
|
-
const
|
|
1180
|
+
const rowResizes = [];
|
|
1181
|
+
const colResizes = [];
|
|
727
1182
|
for (const { target, contentRect: { width, height } } of entries) {
|
|
728
1183
|
if (target === viewportElement) {
|
|
729
1184
|
if (width || height) {
|
|
@@ -731,82 +1186,43 @@ var createContainerGridDriver = (rowStore, colStore) => {
|
|
|
731
1186
|
colStore.$update(4, width);
|
|
732
1187
|
}
|
|
733
1188
|
} else if (target.offsetParent) {
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
if (!prevSize) {
|
|
742
|
-
rowResized = colResized = true;
|
|
743
|
-
} else {
|
|
744
|
-
if (prevSize[0] !== height) {
|
|
745
|
-
rowResized = true;
|
|
746
|
-
}
|
|
747
|
-
if (prevSize[1] !== width) {
|
|
748
|
-
colResized = true;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (rowResized) {
|
|
752
|
-
resizedRows.add(rowIndex);
|
|
753
|
-
}
|
|
754
|
-
if (colResized) {
|
|
755
|
-
resizedCols.add(colIndex);
|
|
756
|
-
}
|
|
757
|
-
if (rowResized || colResized) {
|
|
758
|
-
sizeCache.set(key, [height, width]);
|
|
759
|
-
}
|
|
1189
|
+
const rowIndex = mountedRowIndexes.get(target);
|
|
1190
|
+
const colIndex = mountedColIndexes.get(target);
|
|
1191
|
+
if (rowIndex != null) {
|
|
1192
|
+
rowResizes.push([rowIndex, height]);
|
|
1193
|
+
}
|
|
1194
|
+
if (colIndex != null) {
|
|
1195
|
+
colResizes.push([colIndex, width]);
|
|
760
1196
|
}
|
|
761
1197
|
}
|
|
762
1198
|
}
|
|
763
|
-
if (
|
|
764
|
-
|
|
765
|
-
resizedRows.forEach((rowIndex) => {
|
|
766
|
-
let maxHeight = 0;
|
|
767
|
-
maybeCachedColIndexes.forEach((colIndex) => {
|
|
768
|
-
const size = sizeCache.get(getKey(rowIndex, colIndex));
|
|
769
|
-
if (size) {
|
|
770
|
-
maxHeight = max(maxHeight, size[0]);
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
if (maxHeight) {
|
|
774
|
-
heightResizes.push([rowIndex, maxHeight]);
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
rowStore.$update(3, heightResizes);
|
|
1199
|
+
if (rowResizes.length) {
|
|
1200
|
+
rowStore.$update(3, rowResizes);
|
|
778
1201
|
}
|
|
779
|
-
if (
|
|
780
|
-
|
|
781
|
-
resizedCols.forEach((colIndex) => {
|
|
782
|
-
let maxWidth = 0;
|
|
783
|
-
maybeCachedRowIndexes.forEach((rowIndex) => {
|
|
784
|
-
const size = sizeCache.get(getKey(rowIndex, colIndex));
|
|
785
|
-
if (size) {
|
|
786
|
-
maxWidth = max(maxWidth, size[1]);
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
if (maxWidth) {
|
|
790
|
-
widthResizes.push([colIndex, maxWidth]);
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
colStore.$update(3, widthResizes);
|
|
1202
|
+
if (colResizes.length) {
|
|
1203
|
+
colStore.$update(3, colResizes);
|
|
794
1204
|
}
|
|
795
1205
|
});
|
|
796
1206
|
return {
|
|
797
|
-
$
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1207
|
+
async $scroll(isHorizontal, getTargetOffset) {
|
|
1208
|
+
if (await initialized[0]) {
|
|
1209
|
+
(isHorizontal ? colScrollObserver : rowScrollObserver)._scroll(getTargetOffset);
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
$observe(containerElement) {
|
|
1213
|
+
const viewport = viewportElement = containerElement.parentElement;
|
|
1214
|
+
resizeObserver._observe(viewport);
|
|
1215
|
+
const observe = (store, isHorizontal) => createScrollObserver(store, viewport, viewport, isHorizontal, isHorizontal && getComputedStyle(viewport).direction === "rtl", () => {
|
|
1216
|
+
const overflowKey = isHorizontal ? "overflowX" : "overflowY";
|
|
801
1217
|
const style = viewport.style;
|
|
802
1218
|
const prev = style[overflowKey];
|
|
803
1219
|
style[overflowKey] = "hidden";
|
|
804
1220
|
timeout(() => {
|
|
805
1221
|
style[overflowKey] = prev;
|
|
806
1222
|
});
|
|
807
|
-
};
|
|
808
|
-
rowScrollObserver =
|
|
809
|
-
colScrollObserver =
|
|
1223
|
+
});
|
|
1224
|
+
rowScrollObserver = observe(rowStore, false);
|
|
1225
|
+
colScrollObserver = observe(colStore, true);
|
|
810
1226
|
initialized[1](true);
|
|
811
1227
|
},
|
|
812
1228
|
$dispose() {
|
|
@@ -817,41 +1233,19 @@ var createContainerGridDriver = (rowStore, colStore) => {
|
|
|
817
1233
|
initialized = createPromise();
|
|
818
1234
|
},
|
|
819
1235
|
$observeItem(el, rowIndex, colIndex) {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1236
|
+
if (rowIndex != null) {
|
|
1237
|
+
mountedRowIndexes.set(el, rowIndex);
|
|
1238
|
+
}
|
|
1239
|
+
if (colIndex != null) {
|
|
1240
|
+
mountedColIndexes.set(el, colIndex);
|
|
1241
|
+
}
|
|
823
1242
|
resizeObserver._observe(el);
|
|
824
1243
|
return () => {
|
|
825
|
-
|
|
1244
|
+
mountedRowIndexes.delete(el);
|
|
1245
|
+
mountedColIndexes.delete(el);
|
|
826
1246
|
resizeObserver._unobserve(el);
|
|
827
1247
|
};
|
|
828
1248
|
},
|
|
829
|
-
$resizeRows(rows) {
|
|
830
|
-
for (const [r] of rows) {
|
|
831
|
-
for (let c = 0; c < colStore.$getItemsLength(); c++) {
|
|
832
|
-
sizeCache.delete(getKey(r, c));
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
rowStore.$update(3, rows);
|
|
836
|
-
},
|
|
837
|
-
$resizeCols(cols) {
|
|
838
|
-
for (const [c] of cols) {
|
|
839
|
-
for (let r = 0; r < rowStore.$getItemsLength(); r++) {
|
|
840
|
-
sizeCache.delete(getKey(r, c));
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
colStore.$update(3, cols);
|
|
844
|
-
},
|
|
845
|
-
async $scrollX(getTargetOffset, smooth) {
|
|
846
|
-
if (await initialized[0]) {
|
|
847
|
-
colScrollObserver._scroll(getTargetOffset, smooth);
|
|
848
|
-
}
|
|
849
|
-
},
|
|
850
|
-
async $scrollY(getTargetOffset, smooth) {
|
|
851
|
-
if (await initialized[0]) {
|
|
852
|
-
rowScrollObserver._scroll(getTargetOffset, smooth);
|
|
853
|
-
}
|
|
854
|
-
},
|
|
855
1249
|
$effect() {
|
|
856
1250
|
rowScrollObserver && rowScrollObserver._fixScrollJump();
|
|
857
1251
|
colScrollObserver && colScrollObserver._fixScrollJump();
|
|
@@ -884,32 +1278,65 @@ var scrollToIndex = (driver, store, index, { align, smooth, offset = 0 } = {}) =
|
|
|
884
1278
|
return offset + driver.$getBaseOffset() + store.$getItemOffset(index) + (align === "end" ? store.$getItemSize(index) - store.$getViewportSize() : align === "center" ? (store.$getItemSize(index) - store.$getViewportSize()) / 2 : 0);
|
|
885
1279
|
}, smooth);
|
|
886
1280
|
};
|
|
887
|
-
var gridScrollTo = (driver,
|
|
888
|
-
if (
|
|
889
|
-
driver.$
|
|
1281
|
+
var gridScrollTo = (driver, vertical, horizontal) => {
|
|
1282
|
+
if (vertical != null) {
|
|
1283
|
+
driver.$scroll(false, () => vertical);
|
|
890
1284
|
}
|
|
891
|
-
if (
|
|
892
|
-
driver.$
|
|
1285
|
+
if (horizontal != null) {
|
|
1286
|
+
driver.$scroll(true, () => horizontal);
|
|
893
1287
|
}
|
|
894
1288
|
};
|
|
895
|
-
var gridScrollBy = (driver, rowStore, colStore,
|
|
896
|
-
if (
|
|
897
|
-
const
|
|
898
|
-
driver.$
|
|
1289
|
+
var gridScrollBy = (driver, rowStore, colStore, vertical, horizontal) => {
|
|
1290
|
+
if (vertical != null) {
|
|
1291
|
+
const offset = vertical + rowStore.$getScrollOffset();
|
|
1292
|
+
driver.$scroll(false, () => offset);
|
|
1293
|
+
}
|
|
1294
|
+
if (horizontal != null) {
|
|
1295
|
+
const offset = horizontal + colStore.$getScrollOffset();
|
|
1296
|
+
driver.$scroll(true, () => offset);
|
|
899
1297
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1298
|
+
};
|
|
1299
|
+
var scrollGridAxisToIndex = (driver, store, header, sections, footer, index, align, isHorizontal) => {
|
|
1300
|
+
const count = store.$getItemsLength();
|
|
1301
|
+
const pinnedStart = min(header, count);
|
|
1302
|
+
const trailStart = max(count - footer, pinnedStart);
|
|
1303
|
+
index = clamp(index, 0, count - 1);
|
|
1304
|
+
const starts = getSectionStarts(sections, pinnedStart, trailStart);
|
|
1305
|
+
const section = getSection(starts, index, trailStart);
|
|
1306
|
+
const sectionHeader = section < 0 ? -1 : starts[section];
|
|
1307
|
+
const getInsets = () => [store.$getItemOffset(pinnedStart) - store.$getItemOffset(0) + (sectionHeader < 0 || sectionHeader === index ? 0 : store.$getItemOffset(sectionHeader + 1) - store.$getItemOffset(sectionHeader)), store.$getItemOffset(count) - store.$getItemOffset(trailStart)];
|
|
1308
|
+
if (align === "nearest") {
|
|
1309
|
+
if (index < pinnedStart || index >= trailStart) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
const [insetStart, insetEnd] = getInsets();
|
|
1313
|
+
const scrollOffset = store.$getScrollOffset();
|
|
1314
|
+
const itemSize = store.$getItemSize(index);
|
|
1315
|
+
let itemOffset = store.$getItemOffset(index);
|
|
1316
|
+
if (sectionHeader === index) {
|
|
1317
|
+
const lastIndex = (section + 1 < starts.length ? starts[section + 1] : trailStart) - 1;
|
|
1318
|
+
itemOffset = max(itemOffset, min(scrollOffset + insetStart, store.$getItemOffset(lastIndex) + store.$getItemSize(lastIndex) - itemSize));
|
|
1319
|
+
}
|
|
1320
|
+
if (itemOffset < scrollOffset + insetStart) {
|
|
1321
|
+
align = "start";
|
|
1322
|
+
} else if (itemOffset + itemSize > scrollOffset + store.$getViewportSize() - insetEnd) {
|
|
1323
|
+
align = "end";
|
|
1324
|
+
} else {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
903
1327
|
}
|
|
1328
|
+
driver.$scroll(isHorizontal, () => {
|
|
1329
|
+
const [insetStart, insetEnd] = getInsets();
|
|
1330
|
+
const rest = store.$getItemSize(index) - store.$getViewportSize();
|
|
1331
|
+
return store.$getItemOffset(index) + (align === "end" ? rest + insetEnd : align === "center" ? (rest + insetEnd - insetStart) / 2 : -insetStart);
|
|
1332
|
+
});
|
|
904
1333
|
};
|
|
905
|
-
var gridScrollToIndex = (driver, rowStore, colStore,
|
|
906
|
-
if (
|
|
907
|
-
|
|
908
|
-
driver.$scrollY(() => rowStore.$getItemOffset(index));
|
|
1334
|
+
var gridScrollToIndex = (driver, rowStore, colStore, headerRows = 0, sectionRows = EMPTY, footerRows = 0, headerCols = 0, footerCols = 0, { rowIndex, colIndex, rowAlign, colAlign }) => {
|
|
1335
|
+
if (rowIndex != null) {
|
|
1336
|
+
scrollGridAxisToIndex(driver, rowStore, headerRows, sectionRows, footerRows, rowIndex, rowAlign, false);
|
|
909
1337
|
}
|
|
910
|
-
if (
|
|
911
|
-
|
|
912
|
-
driver.$scrollX(() => colStore.$getItemOffset(index));
|
|
1338
|
+
if (colIndex != null) {
|
|
1339
|
+
scrollGridAxisToIndex(driver, colStore, headerCols, EMPTY, footerCols, colIndex, colAlign, true);
|
|
913
1340
|
}
|
|
914
1341
|
};
|
|
915
1342
|
|
|
@@ -1218,5 +1645,195 @@ var WindowVirtualizer = (props) => {
|
|
|
1218
1645
|
};
|
|
1219
1646
|
|
|
1220
1647
|
//#endregion
|
|
1221
|
-
|
|
1648
|
+
//#region src/solid/VGrid.tsx
|
|
1649
|
+
var GridCell = (props) => {
|
|
1650
|
+
let elementRef;
|
|
1651
|
+
const [state, setState] = createSignal(undefined);
|
|
1652
|
+
createComputed(() => setState(props._state));
|
|
1653
|
+
const measureRowIndex = createMemo(() => state().$measureRow);
|
|
1654
|
+
const measureColIndex = createMemo(() => state().$measureCol);
|
|
1655
|
+
const row = createMemo(() => props._row);
|
|
1656
|
+
const col = createMemo(() => props._col);
|
|
1657
|
+
const children = createMemo(() => {
|
|
1658
|
+
const r = row();
|
|
1659
|
+
const c = col();
|
|
1660
|
+
return untrack(() => props._children(r, c, {
|
|
1661
|
+
rowIndex: props._rowIndex,
|
|
1662
|
+
colIndex: state().$col
|
|
1663
|
+
}));
|
|
1664
|
+
});
|
|
1665
|
+
createEffect(on([measureRowIndex, measureColIndex], ([rowIndex, colIndex]) => {
|
|
1666
|
+
if (!elementRef || rowIndex == null && colIndex == null) return;
|
|
1667
|
+
onCleanup(props._resizer(elementRef, rowIndex, colIndex));
|
|
1668
|
+
}));
|
|
1669
|
+
const style = createMemo(() => gridStyleToString(state().$style));
|
|
1670
|
+
return <div ref={elementRef} role={state().$role} aria-colindex={state().$col + 1} aria-rowspan={state().$rowSpan} aria-colspan={state().$colSpan} aria-sort={state().$sort} style={style()}>
|
|
1671
|
+
{children()}
|
|
1672
|
+
</div>;
|
|
1673
|
+
};
|
|
1674
|
+
var GridRow = (props) => {
|
|
1675
|
+
const state = createMemo(() => props._state);
|
|
1676
|
+
const cols = createMemo(() => state().$cells.map((cell) => cell.$col));
|
|
1677
|
+
const style = createMemo(() => gridStyleToString(state().$style));
|
|
1678
|
+
return <div role="row" aria-rowindex={state().$row + 1} style={style()}>
|
|
1679
|
+
<For each={cols()}>
|
|
1680
|
+
{(colIndex, i) => <GridCell _state={state().$cells[i()]} _children={props._children} _row={props._row} _col={getAxisItem(props._cols, colIndex)} _rowIndex={state().$row} _resizer={props._resizer} />}
|
|
1681
|
+
</For>
|
|
1682
|
+
</div>;
|
|
1683
|
+
};
|
|
1684
|
+
var GridRowGroup = (props) => {
|
|
1685
|
+
const rows = createMemo(() => props._state.$rows.map((row) => row.$row));
|
|
1686
|
+
const style = createMemo(() => gridStyleToString(props._state.$style));
|
|
1687
|
+
return <div role="rowgroup" style={style()}>
|
|
1688
|
+
<For each={rows()}>
|
|
1689
|
+
{(rowIndex, i) => <GridRow _state={props._state.$rows[i()]} _children={props._children} _row={getAxisItem(props._rows, rowIndex)} _cols={props._cols} _resizer={props._resizer} />}
|
|
1690
|
+
</For>
|
|
1691
|
+
</div>;
|
|
1692
|
+
};
|
|
1693
|
+
var VGrid = (props) => {
|
|
1694
|
+
let containerRef;
|
|
1695
|
+
const withDefaults = mergeProps({ gap: 0 }, props);
|
|
1696
|
+
const { rows, cols, rowHeight, colWidth, gap } = withDefaults;
|
|
1697
|
+
const [, others] = splitProps(props, [
|
|
1698
|
+
"ref",
|
|
1699
|
+
"children",
|
|
1700
|
+
"rows",
|
|
1701
|
+
"cols",
|
|
1702
|
+
"rowHeight",
|
|
1703
|
+
"colWidth",
|
|
1704
|
+
"headerRows",
|
|
1705
|
+
"sectionRows",
|
|
1706
|
+
"footerRows",
|
|
1707
|
+
"headerCols",
|
|
1708
|
+
"footerCols",
|
|
1709
|
+
"spans",
|
|
1710
|
+
"keepMounted",
|
|
1711
|
+
"bufferSize",
|
|
1712
|
+
"gap",
|
|
1713
|
+
"ariaSort",
|
|
1714
|
+
"onVerticalScroll",
|
|
1715
|
+
"onHorizontalScroll",
|
|
1716
|
+
"onScrollEnd",
|
|
1717
|
+
"style"
|
|
1718
|
+
]);
|
|
1719
|
+
const rowLayout = createGridLayout(rows, rowHeight, gap);
|
|
1720
|
+
const colLayout = createGridLayout(cols, colWidth, gap);
|
|
1721
|
+
const rowStore = createVirtualStore(rowLayout);
|
|
1722
|
+
const colStore = createVirtualStore(colLayout);
|
|
1723
|
+
const driver = createContainerGridDriver(rowStore, colStore);
|
|
1724
|
+
const getStateVersion = () => rowStore.$getStateVersion() + colStore.$getStateVersion();
|
|
1725
|
+
const [stateVersion, setRerender] = createSignal(getStateVersion());
|
|
1726
|
+
const rerender = () => setRerender(getStateVersion());
|
|
1727
|
+
rowStore.$subscribe(1, rerender);
|
|
1728
|
+
colStore.$subscribe(1, rerender);
|
|
1729
|
+
let scrolled = false;
|
|
1730
|
+
rowStore.$subscribe(4, () => {
|
|
1731
|
+
scrolled = true;
|
|
1732
|
+
props.onVerticalScroll && props.onVerticalScroll(rowStore.$getScrollOffset());
|
|
1733
|
+
});
|
|
1734
|
+
colStore.$subscribe(4, () => {
|
|
1735
|
+
scrolled = true;
|
|
1736
|
+
props.onHorizontalScroll && props.onHorizontalScroll(colStore.$getScrollOffset());
|
|
1737
|
+
});
|
|
1738
|
+
const notifyScrollEnd = () => {
|
|
1739
|
+
if (scrolled && !rowStore.$isScrolling() && !colStore.$isScrolling()) {
|
|
1740
|
+
scrolled = false;
|
|
1741
|
+
props.onScrollEnd && props.onScrollEnd();
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
rowStore.$subscribe(8, notifyScrollEnd);
|
|
1745
|
+
colStore.$subscribe(8, notifyScrollEnd);
|
|
1746
|
+
createComputed(() => {
|
|
1747
|
+
updateGridAxis(rowStore, rowLayout, props.rows, props.rowHeight, true);
|
|
1748
|
+
});
|
|
1749
|
+
createComputed(() => {
|
|
1750
|
+
updateGridAxis(colStore, colLayout, props.cols, props.colWidth, true);
|
|
1751
|
+
});
|
|
1752
|
+
const rowCount = createMemo(() => stateVersion() && rowStore.$getItemsLength());
|
|
1753
|
+
const colCount = createMemo(() => stateVersion() && colStore.$getItemsLength());
|
|
1754
|
+
const plan = createMemo(() => {
|
|
1755
|
+
stateVersion();
|
|
1756
|
+
return createGridPlan(rowLayout, colLayout, rowStore.$getRange(props.bufferSize), colStore.$getRange(props.bufferSize), props.headerRows, props.sectionRows, props.footerRows, props.headerCols, props.footerCols, props.spans, props.keepMounted, props.ariaSort);
|
|
1757
|
+
});
|
|
1758
|
+
const keys = createMemo(() => plan().$groups.map((state) => "$rows" in state ? state.$key : state.$row));
|
|
1759
|
+
const isScrolling = createMemo(() => stateVersion() && (rowStore.$isScrolling() || colStore.$isScrolling()));
|
|
1760
|
+
const containerStyle = createMemo(() => {
|
|
1761
|
+
const { $rowTemplate, $colTemplate } = plan();
|
|
1762
|
+
const marginTop = rowStore.$getItemOffset(0);
|
|
1763
|
+
const marginInlineStart = colStore.$getItemOffset(0);
|
|
1764
|
+
return {
|
|
1765
|
+
contain: "size style",
|
|
1766
|
+
"overflow-anchor": "none",
|
|
1767
|
+
flex: "none",
|
|
1768
|
+
display: "grid",
|
|
1769
|
+
"grid-template-rows": $rowTemplate,
|
|
1770
|
+
"grid-template-columns": $colTemplate,
|
|
1771
|
+
gap: withDefaults.gap + "px",
|
|
1772
|
+
"margin-top": marginTop + "px",
|
|
1773
|
+
"margin-inline-start": marginInlineStart + "px",
|
|
1774
|
+
height: getScrollSize(rowStore) - marginTop + "px",
|
|
1775
|
+
"pointer-events": isScrolling() ? "none" : undefined
|
|
1776
|
+
};
|
|
1777
|
+
});
|
|
1778
|
+
const ref = props.ref;
|
|
1779
|
+
if (!isServer && ref) {
|
|
1780
|
+
ref({
|
|
1781
|
+
get verticalScrollOffset() {
|
|
1782
|
+
return rowStore.$getScrollOffset();
|
|
1783
|
+
},
|
|
1784
|
+
get horizontalScrollOffset() {
|
|
1785
|
+
return colStore.$getScrollOffset();
|
|
1786
|
+
},
|
|
1787
|
+
get scrollHeight() {
|
|
1788
|
+
return getScrollSize(rowStore);
|
|
1789
|
+
},
|
|
1790
|
+
get scrollWidth() {
|
|
1791
|
+
return getScrollSize(colStore);
|
|
1792
|
+
},
|
|
1793
|
+
get viewportHeight() {
|
|
1794
|
+
return rowStore.$getViewportSize();
|
|
1795
|
+
},
|
|
1796
|
+
get viewportWidth() {
|
|
1797
|
+
return colStore.$getViewportSize();
|
|
1798
|
+
},
|
|
1799
|
+
findRowIndex: rowStore.$findItemIndex,
|
|
1800
|
+
findColIndex: colStore.$findItemIndex,
|
|
1801
|
+
getRowOffset: rowStore.$getItemOffset,
|
|
1802
|
+
getColOffset: colStore.$getItemOffset,
|
|
1803
|
+
getRowSize: rowStore.$getItemSize,
|
|
1804
|
+
getColSize: colStore.$getItemSize,
|
|
1805
|
+
scrollToIndex: (opts) => gridScrollToIndex(driver, rowStore, colStore, props.headerRows, props.sectionRows, props.footerRows, props.headerCols, props.footerCols, opts),
|
|
1806
|
+
scrollTo: ({ vertical, horizontal }) => gridScrollTo(driver, vertical, horizontal),
|
|
1807
|
+
scrollBy: ({ vertical, horizontal }) => gridScrollBy(driver, rowStore, colStore, vertical, horizontal)
|
|
1808
|
+
});
|
|
1809
|
+
onCleanup(() => ref());
|
|
1810
|
+
}
|
|
1811
|
+
onMount(() => {
|
|
1812
|
+
driver.$observe(containerRef);
|
|
1813
|
+
onCleanup(() => {
|
|
1814
|
+
rowStore.$dispose();
|
|
1815
|
+
colStore.$dispose();
|
|
1816
|
+
driver.$dispose();
|
|
1817
|
+
});
|
|
1818
|
+
});
|
|
1819
|
+
createEffect(on(stateVersion, () => {
|
|
1820
|
+
driver.$effect();
|
|
1821
|
+
}));
|
|
1822
|
+
return <div role="table" aria-rowcount={rowCount()} aria-colcount={colCount()} {...others} style={{
|
|
1823
|
+
overflow: "auto",
|
|
1824
|
+
contain: "strict",
|
|
1825
|
+
width: "100%",
|
|
1826
|
+
height: "100%",
|
|
1827
|
+
...props.style
|
|
1828
|
+
}}>
|
|
1829
|
+
<div ref={containerRef} style={containerStyle()}>
|
|
1830
|
+
<For each={keys()}>
|
|
1831
|
+
{(key, i) => key < 0 ? <GridRowGroup _state={plan().$groups[i()]} _children={props.children} _rows={props.rows} _cols={props.cols} _resizer={driver.$observeItem} /> : <GridRow _state={plan().$groups[i()]} _children={props.children} _row={getAxisItem(props.rows, key)} _cols={props.cols} _resizer={driver.$observeItem} />}
|
|
1832
|
+
</For>
|
|
1833
|
+
</div>
|
|
1834
|
+
</div>;
|
|
1835
|
+
};
|
|
1836
|
+
|
|
1837
|
+
//#endregion
|
|
1838
|
+
export { VGrid, VList, Virtualizer, WindowVirtualizer };
|
|
1222
1839
|
//# sourceMappingURL=index.jsx.map
|