-
Notifications
You must be signed in to change notification settings - Fork 96
/
GroupManager.ts
778 lines (658 loc) · 22.4 KB
/
GroupManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
import Grid, {
GetterSetter,
GridFunction, GridItem, GridOptions,
GridOutlines, MOUNT_STATE, Properties, PROPERTY_TYPE,
RenderOptions, UPDATE_STATE,
} from "@egjs/grid";
import { GROUP_TYPE, ITEM_TYPE, STATUS_TYPE } from "./consts";
import { InfiniteGridItem, InfiniteGridItemStatus } from "./InfiniteGridItem";
import { LoadingGrid, LOADING_GROUP_KEY } from "./LoadingGrid";
import { CategorizedGroup, InfiniteGridGroup, InfiniteGridItemInfo } from "./types";
import {
categorize, filterVirtuals, findIndex, findLastIndex,
flat,
flatGroups, getItemInfo, isNumber, makeKey,
range,
setPlaceholder,
splitGridOptions, splitOptions, splitVirtualGroups,
} from "./utils";
export interface InfiniteGridGroupStatus {
type: GROUP_TYPE;
groupKey: string | number;
items: InfiniteGridItemStatus[];
outlines: GridOutlines;
}
export interface GroupManagerOptions extends GridOptions {
appliedItemChecker?: (item: InfiniteGridItem, grid: Grid) => boolean;
gridConstructor: GridFunction | null;
gridOptions: Record<string, any>;
}
export interface GroupManagerStatus {
cursors: [number, number];
orgCursors: [number, number];
itemCursors: [number, number];
startGroupKey: number | string;
endGroupKey: number | string;
groups: InfiniteGridGroupStatus[];
outlines: GridOutlines;
}
@GetterSetter
export class GroupManager extends Grid<GroupManagerOptions> {
public static defaultOptions: Required<GroupManagerOptions> = {
...Grid.defaultOptions,
appliedItemChecker: () => false,
gridConstructor: null,
gridOptions: {},
};
public static propertyTypes = {
...Grid.propertyTypes,
gridConstructor: PROPERTY_TYPE.PROPERTY,
gridOptions: PROPERTY_TYPE.PROPERTY,
} as const;
protected items: InfiniteGridItem[];
protected groupItems: InfiniteGridItem[] = [];
protected groups: InfiniteGridGroup[] = [];
protected itemKeys: Record<string | number, InfiniteGridItem> = {};
protected groupKeys: Record<string | number, InfiniteGridGroup> = {};
protected startCursor = 0;
protected endCursor = 0;
private _placeholder: Partial<InfiniteGridItemStatus> | null = null;
private _loadingGrid!: LoadingGrid;
private _mainGrid!: Grid;
constructor(container: HTMLElement, options: GroupManagerOptions) {
super(container, splitOptions(options));
this._loadingGrid = new LoadingGrid(container, {
externalContainerManager: this.containerManager,
useFit: false,
autoResize: false,
renderOnPropertyChange: false,
gap: this.gap,
});
this._mainGrid = this._makeGrid();
}
public set gridOptions(options: Record<string, any>) {
const {
gridOptions,
...otherOptions
} = splitGridOptions(options);
const shouldRender = this._checkShouldRender(options);
this.options.gridOptions = {
...this.options.gridOptions,
...gridOptions,
};
[this._mainGrid, ...this.groups.map(({ grid }) => grid)].forEach((grid) => {
for (const name in options) {
(grid as any)[name] = options[name];
}
});
for (const name in otherOptions) {
this[name] = otherOptions[name];
}
this._loadingGrid.gap = this.gap;
if (shouldRender) {
this.scheduleRender();
}
}
public getItemByKey(key: string | number): InfiniteGridItem | null {
return this.itemKeys[key] || null;
}
public getGroupItems(includePlaceholders?: boolean) {
return filterVirtuals(this.groupItems, includePlaceholders);
}
public getVisibleItems(includePlaceholders?: boolean) {
return filterVirtuals(this.items, includePlaceholders);
}
public getRenderingItems() {
if (this.hasPlaceholder()) {
return this.items;
} else {
return this.items.filter((item) => item.type !== ITEM_TYPE.VIRTUAL);
}
}
public getGroups(includePlaceholders?: boolean): InfiniteGridGroup[] {
return filterVirtuals(this.groups, includePlaceholders);
}
public hasVisibleVirtualGroups() {
return this.getVisibleGroups(true).some((group) => group.type === GROUP_TYPE.VIRTUAL);
}
public hasPlaceholder() {
return !!this._placeholder;
}
public hasLoadingItem() {
return !!this._getLoadingItem();
}
public updateItems(items = this.groupItems, options?: RenderOptions) {
return super.updateItems(items, options);
}
public setPlaceholder(placeholder: Partial<InfiniteGridItemStatus> | null) {
this._placeholder = placeholder;
this._updatePlaceholder();
}
public getLoadingType() {
return this._loadingGrid.type;
}
public startLoading(type: "start" | "end") {
this._loadingGrid.type = type;
this.items = this._getRenderingItems();
return true;
}
public endLoading() {
const prevType = this._loadingGrid.type;
this._loadingGrid.type = "";
this.items = this._getRenderingItems();
return !!prevType;
}
public setLoading(loading: Partial<InfiniteGridItemStatus> | null) {
this._loadingGrid.setLoadingItem(loading);
this.items = this._getRenderingItems();
}
public getVisibleGroups(includePlaceholders?: boolean): InfiniteGridGroup[] {
const groups = this.groups.slice(this.startCursor, this.endCursor + 1);
return filterVirtuals(groups, includePlaceholders);
}
public getComputedOutlineLength(items = this.items) {
return this._mainGrid.getComputedOutlineLength(items);
}
public getComputedOutlineSize(items = this.items) {
return this._mainGrid.getComputedOutlineSize(items);
}
public applyGrid(items: InfiniteGridItem[], direction: "end" | "start", outline: number[]): GridOutlines {
const renderingGroups = this.groups.slice();
if (!renderingGroups.length) {
return {
start: [],
end: [],
};
}
const loadingGrid = this._loadingGrid;
if (loadingGrid.getLoadingItem()) {
if (loadingGrid.type === "start") {
renderingGroups.unshift(this._getLoadingGroup());
} else if (loadingGrid.type === "end") {
renderingGroups.push(this._getLoadingGroup());
}
}
const groups = renderingGroups.slice();
let nextOutline = outline;
if (direction === "start") {
groups.reverse();
}
const appliedItemChecker = this.options.appliedItemChecker;
const groupItems = this.groupItems;
const outlineLength = this.getComputedOutlineLength(groupItems);
const outlineSize = this.getComputedOutlineSize(groupItems);
const itemRenderer = this.itemRenderer;
groups.forEach((group) => {
const grid = group.grid;
const gridItems = grid.getItems() as InfiniteGridItem[];
const isVirtual = group.type === GROUP_TYPE.VIRTUAL && !gridItems[0];
grid.outlineLength = outlineLength;
grid.outlineSize = outlineSize;
const appliedItems = gridItems.filter((item) => {
if (item.mountState === MOUNT_STATE.UNCHECKED || !item.rect.width) {
itemRenderer.updateItem(item, true);
}
return (item.orgRect.width && item.rect.width) || appliedItemChecker(item, grid);
});
let gridOutlines: GridOutlines;
if (isVirtual) {
gridOutlines = this._applyVirtualGrid(grid, direction, nextOutline);
} else if (appliedItems.length) {
gridOutlines = grid.applyGrid(appliedItems, direction, nextOutline);
} else {
gridOutlines = {
start: [...nextOutline],
end: [...nextOutline],
};
}
grid.setOutlines(gridOutlines);
nextOutline = gridOutlines[direction];
});
return {
start: renderingGroups[0].grid.getOutlines().start,
end: renderingGroups[renderingGroups.length - 1].grid.getOutlines().end,
};
}
public syncItems(nextItemInfos: InfiniteGridItemInfo[]) {
const prevItemKeys = this.itemKeys;
this.itemKeys = {};
const nextItems = this._syncItemInfos(nextItemInfos.map((info) => getItemInfo(info)), prevItemKeys);
const prevGroupKeys = this.groupKeys;
let nextManagerGroups = categorize(nextItems);
const startVirtualGroups = this._splitVirtualGroups("start", nextManagerGroups);
const endVirtualGroups = this._splitVirtualGroups("end", nextManagerGroups);
nextManagerGroups = [...startVirtualGroups, ...this._mergeVirtualGroups(nextManagerGroups), ...endVirtualGroups];
const nextGroups: InfiniteGridGroup[] = nextManagerGroups.map(({ groupKey, items }) => {
const isVirtual = !items[0] || items[0].type === ITEM_TYPE.VIRTUAL;
const grid = prevGroupKeys[groupKey]?.grid ?? this._makeGrid();
const gridItems = isVirtual ? items : items.filter(({ type }) => type === ITEM_TYPE.NORMAL);
grid.setItems(gridItems);
return {
type: isVirtual ? GROUP_TYPE.VIRTUAL : GROUP_TYPE.NORMAL,
groupKey,
grid,
items: gridItems,
renderItems: items,
};
});
this._registerGroups(nextGroups);
}
public renderItems(options: RenderOptions = {}) {
if (options.useResize) {
this.groupItems.forEach((item) => {
item.updateState = UPDATE_STATE.NEED_UPDATE;
});
const loadingItem = this._getLoadingItem();
if (loadingItem) {
loadingItem.updateState = UPDATE_STATE.NEED_UPDATE;
}
}
return super.renderItems(options);
}
public setCursors(startCursor: number, endCursor: number) {
this.startCursor = startCursor;
this.endCursor = endCursor;
this.items = this._getRenderingItems();
}
public getStartCursor() {
return this.startCursor;
}
public getEndCursor() {
return this.endCursor;
}
public getGroupStatus(type?: STATUS_TYPE, includePlaceholders?: boolean): GroupManagerStatus {
const orgStartCursor = this.startCursor;
const orgEndCursor = this.endCursor;
const orgGroups = this.groups;
const startGroup = orgGroups[orgStartCursor];
const endGroup = orgGroups[orgEndCursor];
let startCursor = orgStartCursor;
let endCursor = orgEndCursor;
const isMinimizeItems = type === STATUS_TYPE.MINIMIZE_INVISIBLE_ITEMS;
const isMinimizeGroups = type === STATUS_TYPE.MINIMIZE_INVISIBLE_GROUPS;
let groups: InfiniteGridGroup[];
if (type === STATUS_TYPE.REMOVE_INVISIBLE_GROUPS) {
groups = this.getVisibleGroups(includePlaceholders);
endCursor = groups.length - 1;
startCursor = 0;
} else {
groups = this.getGroups(includePlaceholders);
if (!includePlaceholders) {
startCursor = -1;
endCursor = -1;
for (let orgIndex = orgStartCursor; orgIndex <= orgEndCursor; ++orgIndex) {
const orgGroup = orgGroups[orgIndex];
if (orgGroup && orgGroup.type !== GROUP_TYPE.VIRTUAL) {
startCursor = groups.indexOf(orgGroup);
break;
}
}
for (let orgIndex = orgEndCursor; orgIndex >= orgStartCursor; --orgIndex) {
const orgGroup = orgGroups[orgIndex];
if (orgGroup && orgGroup.type !== GROUP_TYPE.VIRTUAL) {
endCursor = groups.lastIndexOf(orgGroup);
break;
}
}
}
}
const groupStatus: InfiniteGridGroupStatus[] = groups.map(({ grid, groupKey }, i) => {
const isOutsideCursor = i < startCursor || endCursor < i;
const isVirtualItems = isMinimizeItems && isOutsideCursor;
const isVirtualGroup = isMinimizeGroups && isOutsideCursor;
const gridItems = grid.getItems() as InfiniteGridItem[];
const items = isVirtualGroup
? []
: gridItems.map((item) => isVirtualItems ? item.getVirtualStatus() : item.getMinimizedStatus());
return {
type: isVirtualGroup || isVirtualItems ? GROUP_TYPE.VIRTUAL : GROUP_TYPE.NORMAL,
groupKey: groupKey,
outlines: grid.getOutlines(),
items,
};
});
const totalItems = this.getGroupItems();
const itemStartCursor = totalItems.indexOf(startGroup?.items[0]);
const itemEndCursor = totalItems.indexOf(endGroup?.items.slice().reverse()[0]);
return {
cursors: [startCursor, endCursor],
orgCursors: [orgStartCursor, orgEndCursor],
itemCursors: [itemStartCursor, itemEndCursor],
startGroupKey: startGroup?.groupKey,
endGroupKey: endGroup?.groupKey,
groups: groupStatus,
outlines: this.outlines,
};
}
protected fitOutlines(useFit = this.useFit) {
const groups = this.groups;
const firstGroup = groups[0];
if (!firstGroup) {
return;
}
const outlines = firstGroup.grid.getOutlines();
const startOutline = outlines.start;
const outlineOffset = startOutline.length ? Math.min(...startOutline) : 0;
// If the outline is less than 0, a fit occurs forcibly.
if (!useFit && outlineOffset > 0) {
return;
}
groups.forEach(({ grid }) => {
const { start, end } = grid.getOutlines();
grid.setOutlines({
start: start.map((point) => point - outlineOffset),
end: end.map((point) => point - outlineOffset),
});
});
this.groupItems.forEach((item) => {
const contentPos = item.cssContentPos;
if (!isNumber(contentPos)) {
return;
}
item.cssContentPos = contentPos - outlineOffset;
});
}
public setGroupStatus(status: GroupManagerStatus) {
this.itemKeys = {};
this.groupItems = [];
this.items = [];
const prevGroupKeys = this.groupKeys;
const nextGroups: InfiniteGridGroup[] = status.groups.map(({
type,
groupKey,
items,
outlines,
}) => {
const nextItems = this._syncItemInfos(items);
const grid = prevGroupKeys[groupKey]?.grid ?? this._makeGrid();
grid.setOutlines(outlines);
grid.setItems(nextItems);
return {
type,
groupKey,
grid,
items: nextItems,
renderItems: nextItems,
};
});
this.setOutlines(status.outlines);
this._registerGroups(nextGroups);
this._updatePlaceholder();
this.setCursors(status.cursors[0], status.cursors[1]);
}
public appendPlaceholders(items: number | InfiniteGridItemStatus[], groupKey?: string | number) {
return this.insertPlaceholders("end", items, groupKey);
}
public prependPlaceholders(items: number | InfiniteGridItemStatus[], groupKey?: string | number) {
return this.insertPlaceholders("start", items, groupKey);
}
public removePlaceholders(type: "start" | "end" | { groupKey: string | number }) {
const groups = this.groups;
const length = groups.length;
if (type === "start") {
const index = findIndex(groups, (group) => group.type === GROUP_TYPE.NORMAL);
groups.splice(0, index);
} else if (type === "end") {
const index = findLastIndex(groups, (group) => group.type === GROUP_TYPE.NORMAL);
groups.splice(index + 1, length - index - 1);
} else {
const groupKey = type.groupKey;
const index = findIndex(groups, (group) => group.groupKey === groupKey);
if (index > -1) {
groups.splice(index, 1);
}
}
this.syncItems(flatGroups(this.getGroups()));
}
public insertPlaceholders(
direction: "start" | "end",
items: number | InfiniteGridItemStatus[],
groupKey: string | number = makeKey(this.groupKeys, "virtual_"),
) {
let infos: InfiniteGridItemInfo[] = [];
if (isNumber(items)) {
infos = range(items).map(() => ({ type: ITEM_TYPE.VIRTUAL, groupKey }));
} else if (Array.isArray(items)) {
infos = items.map((status) => ({
groupKey,
...status,
type: ITEM_TYPE.VIRTUAL,
}));
}
const grid = this._makeGrid();
const nextItems = this._syncItemInfos(infos, this.itemKeys);
this._updatePlaceholder(nextItems);
grid.setItems(nextItems);
const group = {
type: GROUP_TYPE.VIRTUAL,
groupKey,
grid,
items: nextItems,
renderItems: nextItems,
};
this.groupKeys[groupKey] = group;
if (direction === "end") {
this.groups.push(group);
this.groupItems.push(...nextItems);
} else {
this.groups.splice(0, 0, group);
this.groupItems.splice(0, 0, ...nextItems);
if (this.startCursor > -1) {
++this.startCursor;
++this.endCursor;
}
}
return {
group,
items: nextItems,
};
}
public shouldRerenderItems() {
let isRerender = false;
this.getVisibleGroups().forEach((group) => {
const items = group.items;
if (
items.length === group.renderItems.length
|| items.every((item) => item.mountState === MOUNT_STATE.UNCHECKED)
) {
return;
}
isRerender = true;
group.renderItems = [...items];
});
if (isRerender) {
this.items = this._getRenderingItems();
}
return isRerender;
}
protected _updateItems(items: GridItem[]): void {
this.itemRenderer.updateEqualSizeItems(items, this.groupItems);
}
private _getGroupItems() {
return flatGroups(this.getGroups(true));
}
private _getRenderingItems() {
const items = flat(this.getVisibleGroups(true).map((item) => item.renderItems));
const loadingGrid = this._loadingGrid;
const loadingItem = loadingGrid.getLoadingItem();
if (loadingItem) {
if (loadingGrid.type === "end") {
items.push(loadingItem);
} else if (loadingGrid.type === "start") {
items.unshift(loadingItem);
}
}
return items;
}
private _checkShouldRender(options: Record<string, any>) {
const GridConstructor = this.options.gridConstructor!;
const prevOptions = this.gridOptions;
const propertyTypes = GridConstructor.propertyTypes;
for (const name in prevOptions) {
if (!(name in options) && propertyTypes[name] === PROPERTY_TYPE.RENDER_PROPERTY) {
return true;
}
}
for (const name in options) {
if (prevOptions[name] !== options[name] && propertyTypes[name] === PROPERTY_TYPE.RENDER_PROPERTY) {
return true;
}
}
return false;
}
private _applyVirtualGrid(grid: Grid, direction: "start" | "end", outline: number[]) {
const startOutline = outline.length ? [...outline] : [0];
const prevOutlines = grid.getOutlines();
const prevOutline = prevOutlines[direction === "end" ? "start" : "end"];
if (
prevOutline.length !== startOutline.length
|| prevOutline.some((value, i) => value !== startOutline[i])
) {
return {
start: [...startOutline],
end: [...startOutline],
};
}
return prevOutlines;
}
private _syncItemInfos(
nextItemInfos: InfiniteGridItemStatus[],
prevItemKeys: Record<string | number, InfiniteGridItem> = {},
) {
const horizontal = this.options.horizontal;
const nextItemKeys = this.itemKeys;
nextItemInfos.filter((info) => info.key != null).forEach((info) => {
const key = info.key!;
const prevItem = prevItemKeys[key];
if (!prevItem) {
nextItemKeys[key] = new InfiniteGridItem(horizontal, {
...info,
});
} else if (prevItem.type === ITEM_TYPE.VIRTUAL && info.type !== ITEM_TYPE.VIRTUAL) {
nextItemKeys[key] = new InfiniteGridItem(horizontal, {
orgRect: prevItem.orgRect,
rect: prevItem.rect,
...info,
});
} else {
if (info.data) {
prevItem.data = info.data;
}
if (info.groupKey != null) {
prevItem.groupKey = info.groupKey!;
}
if (info.element) {
prevItem.element = info.element;
}
nextItemKeys[key] = prevItem;
}
});
const nextItems = nextItemInfos.map((info) => {
let key = info.key!;
if (info.key == null) {
key = makeKey(nextItemKeys, info.type === ITEM_TYPE.VIRTUAL ? "virtual_" : "");
}
let item = nextItemKeys[key];
if (!item) {
const prevItem = prevItemKeys[key];
if (prevItem) {
item = prevItem;
if (info.data) {
item.data = info.data;
}
if (info.element) {
item.element = info.element;
}
} else {
item = new InfiniteGridItem(horizontal, {
...info,
key,
});
}
nextItemKeys[key] = item;
}
return item;
});
return nextItems;
}
private _registerGroups(groups: InfiniteGridGroup[]) {
const nextGroupKeys: Record<string | number, InfiniteGridGroup> = {};
groups.forEach((group) => {
nextGroupKeys[group.groupKey] = group;
});
this.groups = groups;
this.groupKeys = nextGroupKeys;
this.groupItems = this._getGroupItems();
}
private _splitVirtualGroups(direction: "start" | "end", nextGroups: CategorizedGroup[]) {
const groups = splitVirtualGroups(this.groups, direction, nextGroups);
const itemKeys = this.itemKeys;
groups.forEach(({ renderItems }) => {
renderItems.forEach((item) => {
itemKeys[item.key] = item;
});
});
return groups;
}
private _mergeVirtualGroups(groups: Array<CategorizedGroup<InfiniteGridItem>>) {
const itemKeys = this.itemKeys;
const groupKeys = this.groupKeys;
groups.forEach((group) => {
const prevGroup = groupKeys[group.groupKey];
if (!prevGroup) {
return;
}
const items = group.items;
if (items.every((item) => item.mountState === MOUNT_STATE.UNCHECKED)) {
prevGroup.renderItems.forEach((item) => {
if (item.type === ITEM_TYPE.VIRTUAL && !itemKeys[item.key]) {
items.push(item);
itemKeys[item.key] = item;
}
});
}
});
return groups;
}
private _updatePlaceholder(items = this.groupItems) {
const placeholder = this._placeholder;
if (!placeholder) {
return;
}
items.filter((item) => item.type === ITEM_TYPE.VIRTUAL).forEach((item) => {
setPlaceholder(item, placeholder);
});
}
private _makeGrid() {
const GridConstructor = this.options.gridConstructor!;
const gridOptions = this.gridOptions;
const container = this.containerElement;
return new GridConstructor(container, {
...gridOptions,
useFit: false,
autoResize: false,
useResizeObserver: false,
observeChildren: false,
renderOnPropertyChange: false,
externalContainerManager: this.containerManager,
externalItemRenderer: this.itemRenderer,
});
}
private _getLoadingGroup(): InfiniteGridGroup {
const loadingGrid = this._loadingGrid;
const items = loadingGrid.getItems() as InfiniteGridItem[];
return {
groupKey: LOADING_GROUP_KEY,
type: GROUP_TYPE.NORMAL,
grid: loadingGrid,
items,
renderItems: items,
};
}
private _getLoadingItem() {
return this._loadingGrid.getLoadingItem();
}
}
export interface GroupManager extends Properties<typeof GroupManager> {
getItems(): InfiniteGridItem[];
}