UNPKG

2.04 kBPlain TextView Raw
1import { GridItem, GridItemStatus, MOUNT_STATE } from "@egjs/grid";
2import { INVISIBLE_POS, ITEM_TYPE } from "./consts";
3import { InfiniteGridItemInfo } from "./types";
4
5
6export interface InfiniteGridItemStatus extends GridItemStatus {
7 type?: ITEM_TYPE;
8 groupKey?: string | number;
9 key?: string | number;
10 html?: string;
11}
12
13/**
14 * @extends Grid.GridItem
15 */
16export class InfiniteGridItem extends GridItem implements Required<InfiniteGridItemInfo> {
17 public groupKey: string | number;
18 public inserted: boolean;
19 public readonly html: string;
20 constructor(horizontal: boolean, itemStatus?: Partial<InfiniteGridItemStatus>) {
21 super(horizontal, {
22 html: "",
23 type: ITEM_TYPE.NORMAL,
24 cssRect: { top: INVISIBLE_POS, left: INVISIBLE_POS },
25 ...itemStatus,
26 } as GridItemStatus);
27
28 if (this.type === ITEM_TYPE.VIRTUAL) {
29 if (this.rect.width || this.rect.height) {
30 this.mountState = MOUNT_STATE.UNMOUNTED;
31 }
32 const orgRect = this.orgRect;
33 const rect = this.rect;
34 const cssRect = this.cssRect;
35
36 if (cssRect.width) {
37 rect.width = cssRect.width;
38 } else if (orgRect.width) {
39 rect.width = orgRect.width;
40 }
41 if (cssRect.height) {
42 rect.height = cssRect.height;
43 } else if (orgRect.height) {
44 rect.height = orgRect.height;
45 }
46 }
47 }
48 public getVirtualStatus(): Partial<InfiniteGridItemStatus> {
49 return {
50 type: ITEM_TYPE.VIRTUAL,
51 groupKey: this.groupKey,
52 key: this.key,
53 orgRect: this.orgRect,
54 rect: this.rect,
55 cssRect: this.cssRect,
56 attributes: this.attributes,
57 };
58 }
59 public getMinimizedStatus(): Partial<InfiniteGridItemStatus> {
60 const status: Partial<InfiniteGridItemStatus> = {
61 ...super.getMinimizedStatus(),
62 type: ITEM_TYPE.NORMAL,
63 groupKey: this.groupKey,
64 };
65 if (this.html) {
66 status.html = this.html;
67 }
68 return status;
69 }
70}
71
72export interface InfiniteGridItem extends Required<InfiniteGridItemStatus> {}