UNPKG

98.8 kBJavaScriptView Raw
1/*
2Copyright (c) 2015 NAVER Corp.
3name: @egjs/infinitegrid
4license: MIT
5author: NAVER Corp.
6repository: https://github.com/naver/egjs-infinitegrid
7version: 4.1.0
8*/
9'use strict';
10
11var Component = require('@egjs/component');
12var Grid = require('@egjs/grid');
13var listDiffer = require('@egjs/list-differ');
14
15/*! *****************************************************************************
16Copyright (c) Microsoft Corporation.
17
18Permission to use, copy, modify, and/or distribute this software for any
19purpose with or without fee is hereby granted.
20
21THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27PERFORMANCE OF THIS SOFTWARE.
28***************************************************************************** */
29
30/* global Reflect, Promise */
31var extendStatics = function (d, b) {
32 extendStatics = Object.setPrototypeOf || {
33 __proto__: []
34 } instanceof Array && function (d, b) {
35 d.__proto__ = b;
36 } || function (d, b) {
37 for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
38 };
39
40 return extendStatics(d, b);
41};
42
43function __extends(d, b) {
44 if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
45 extendStatics(d, b);
46
47 function __() {
48 this.constructor = d;
49 }
50
51 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
52}
53var __assign = function () {
54 __assign = Object.assign || function __assign(t) {
55 for (var s, i = 1, n = arguments.length; i < n; i++) {
56 s = arguments[i];
57
58 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
59 }
60
61 return t;
62 };
63
64 return __assign.apply(this, arguments);
65};
66function __rest(s, e) {
67 var t = {};
68
69 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
70
71 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
72 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
73 }
74 return t;
75}
76function __decorate(decorators, target, key, desc) {
77 var c = arguments.length,
78 r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
79 d;
80 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
81 return c > 3 && r && Object.defineProperty(target, key, r), r;
82}
83/** @deprecated */
84
85function __spreadArrays() {
86 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
87
88 for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
89
90 return r;
91}
92
93var ua = typeof window !== "undefined" ? window.navigator.userAgent : "";
94var IS_IOS = /iPhone|iPad/.test(ua);
95var CONTAINER_CLASS_NAME = "infinitegrid-container";
96var IGNORE_PROPERITES_MAP = {
97 renderOnPropertyChange: true,
98 useFit: true,
99 autoResize: true
100};
101var INFINITEGRID_PROPERTY_TYPES = __assign({}, Grid.GRID_PROPERTY_TYPES);
102var DIRECTION = {
103 START: "start",
104 END: "end",
105 NONE: ""
106};
107var INFINITEGRID_EVENTS = {
108 CHANGE_SCROLL: "changeScroll",
109 REQUEST_APPEND: "requestAppend",
110 REQUEST_PREPEND: "requestPrepend",
111 RENDER_COMPLETE: "renderComplete",
112 CONTENT_ERROR: "contentError"
113}; // type?: ITEM_TYPE;
114// groupKey?: string | number;
115// key?: string | number;
116// element?: HTMLElement | null;
117// html?: string;
118// data?: Record<string, any>;
119
120var ITEM_INFO_PROPERTIES = {
121 type: true,
122 groupKey: true,
123 key: true,
124 element: true,
125 html: true,
126 data: true
127};
128var INFINITEGRID_METHODS = ["updateItems", "getItems", "getVisibleItems", "getGroups", "getVisibleGroups", "renderItems", "getContainerElement", "getScrollContainerElement", "getWrapperElement", "setStatus", "getStatus", "removePlaceholders", "prependPlaceholders", "appendPlaceholders", "getStartCursor", "getEndCursor", "setCursors"];
129var GROUP_TYPE;
130
131(function (GROUP_TYPE) {
132 GROUP_TYPE[GROUP_TYPE["NORMAL"] = 0] = "NORMAL";
133 GROUP_TYPE[GROUP_TYPE["VIRTUAL"] = 1] = "VIRTUAL";
134 GROUP_TYPE[GROUP_TYPE["LOADING"] = 2] = "LOADING";
135})(GROUP_TYPE || (GROUP_TYPE = {}));
136
137var ITEM_TYPE;
138
139(function (ITEM_TYPE) {
140 ITEM_TYPE[ITEM_TYPE["NORMAL"] = 0] = "NORMAL";
141 ITEM_TYPE[ITEM_TYPE["VIRTUAL"] = 1] = "VIRTUAL";
142 ITEM_TYPE[ITEM_TYPE["LOADING"] = 2] = "LOADING";
143})(ITEM_TYPE || (ITEM_TYPE = {}));
144
145var STATUS_TYPE;
146
147(function (STATUS_TYPE) {
148 // does not remove anything.
149 STATUS_TYPE[STATUS_TYPE["NOT_REMOVE"] = 0] = "NOT_REMOVE"; // Minimize information on invisible items
150
151 STATUS_TYPE[STATUS_TYPE["MINIMIZE_INVISIBLE_ITEMS"] = 1] = "MINIMIZE_INVISIBLE_ITEMS"; // Minimize information on invisible groups
152
153 STATUS_TYPE[STATUS_TYPE["MINIMIZE_INVISIBLE_GROUPS"] = 2] = "MINIMIZE_INVISIBLE_GROUPS"; // remove invisible groups
154
155 STATUS_TYPE[STATUS_TYPE["REMOVE_INVISIBLE_GROUPS"] = 3] = "REMOVE_INVISIBLE_GROUPS";
156})(STATUS_TYPE || (STATUS_TYPE = {}));
157
158var INVISIBLE_POS = -9999;
159
160/**
161 * @extends Grid.GridItem
162 */
163
164var InfiniteGridItem =
165/*#__PURE__*/
166function (_super) {
167 __extends(InfiniteGridItem, _super);
168
169 function InfiniteGridItem(horizontal, itemStatus) {
170 var _this = _super.call(this, horizontal, __assign({
171 html: "",
172 type: ITEM_TYPE.NORMAL,
173 cssRect: {
174 top: INVISIBLE_POS,
175 left: INVISIBLE_POS
176 }
177 }, itemStatus)) || this;
178
179 if (_this.type === ITEM_TYPE.VIRTUAL) {
180 if (_this.rect.width || _this.rect.height) {
181 _this.mountState = Grid.MOUNT_STATE.UNMOUNTED;
182 }
183
184 var orgRect = _this.orgRect;
185 var rect = _this.rect;
186 var cssRect = _this.cssRect;
187
188 if (cssRect.width) {
189 rect.width = cssRect.width;
190 } else if (orgRect.width) {
191 rect.width = orgRect.width;
192 }
193
194 if (cssRect.height) {
195 rect.height = cssRect.height;
196 } else if (orgRect.height) {
197 rect.height = orgRect.height;
198 }
199 }
200
201 return _this;
202 }
203
204 var __proto = InfiniteGridItem.prototype;
205
206 __proto.getVirtualStatus = function () {
207 return {
208 type: ITEM_TYPE.VIRTUAL,
209 groupKey: this.groupKey,
210 key: this.key,
211 orgRect: this.orgRect,
212 rect: this.rect,
213 cssRect: this.cssRect,
214 attributes: this.attributes
215 };
216 };
217
218 __proto.getMinimizedStatus = function () {
219 var status = __assign(__assign({}, _super.prototype.getStatus.call(this)), {
220 type: ITEM_TYPE.NORMAL,
221 groupKey: this.groupKey
222 });
223
224 if (this.html) {
225 status.html = this.html;
226 }
227
228 return status;
229 };
230
231 return InfiniteGridItem;
232}(Grid.GridItem);
233
234var LOADING_GROUP_KEY = "__INFINITEGRID__LOADING_GRID";
235var LOADING_ITEM_KEY = "__INFINITEGRID__LOADING_ITEM";
236
237var LoadingGrid =
238/*#__PURE__*/
239function (_super) {
240 __extends(LoadingGrid, _super);
241
242 function LoadingGrid() {
243 var _this = _super !== null && _super.apply(this, arguments) || this;
244
245 _this.type = "";
246 return _this;
247 }
248
249 var __proto = LoadingGrid.prototype;
250
251 __proto.getLoadingItem = function () {
252 return this.items[0] || null;
253 };
254
255 __proto.setLoadingItem = function (item) {
256 if (item) {
257 var loadingItem = this.getLoadingItem();
258
259 if (!loadingItem) {
260 this.items = [new InfiniteGridItem(this.options.horizontal, __assign(__assign({}, item), {
261 type: ITEM_TYPE.LOADING,
262 key: LOADING_ITEM_KEY
263 }))];
264 } else {
265 for (var name in item) {
266 loadingItem[name] = item[name];
267 }
268 }
269 } else {
270 this.items = [];
271 }
272 };
273
274 __proto.applyGrid = function (items, direction, outline) {
275 if (!items.length) {
276 return {
277 start: outline,
278 end: outline
279 };
280 }
281
282 var nextOutline = outline.length ? __spreadArrays(outline) : [0];
283 var item = items[0];
284 var offset = item.contentSize + this.gap;
285 item.cssInlinePos = this.getContainerInlineSize() / 2 - item.inlineSize / 2;
286
287 if (direction === "end") {
288 var maxPos = Math.max.apply(Math, nextOutline);
289 item.cssContentPos = maxPos;
290 return {
291 start: nextOutline,
292 end: nextOutline.map(function (pos) {
293 return pos + offset;
294 })
295 };
296 } else {
297 var minPos = Math.min.apply(Math, nextOutline);
298 item.cssContentPos = minPos - offset;
299 return {
300 start: nextOutline.map(function (pos) {
301 return pos - offset;
302 }),
303 end: nextOutline
304 };
305 }
306 };
307
308 return LoadingGrid;
309}(Grid);
310
311function isWindow(el) {
312 return el === window;
313}
314function isNumber(val) {
315 return typeof val === "number";
316}
317function isString(val) {
318 return typeof val === "string";
319}
320function isObject(val) {
321 return typeof val === "object";
322}
323function flat(arr) {
324 return arr.reduce(function (prev, cur) {
325 return __spreadArrays(prev, cur);
326 }, []);
327}
328function splitOptions(options) {
329 var gridOptions = options.gridOptions,
330 otherOptions = __rest(options, ["gridOptions"]);
331
332 return __assign(__assign({}, splitGridOptions(gridOptions)), otherOptions);
333}
334function splitGridOptions(options) {
335 var nextOptions = {};
336 var gridOptions = {};
337 var defaultOptions = Grid.defaultOptions;
338
339 for (var name in options) {
340 var value = options[name];
341
342 if (!(name in IGNORE_PROPERITES_MAP)) {
343 gridOptions[name] = value;
344 }
345
346 if (name in defaultOptions) {
347 nextOptions[name] = value;
348 }
349 }
350
351 return __assign(__assign({}, nextOptions), {
352 gridOptions: gridOptions
353 });
354}
355function categorize(items) {
356 var groups = [];
357 var groupKeys = {};
358 var registeredGroupKeys = {};
359 items.filter(function (item) {
360 return item.groupKey != null;
361 }).forEach(function (_a) {
362 var groupKey = _a.groupKey;
363 registeredGroupKeys[groupKey] = true;
364 });
365 var generatedGroupKey;
366 var isContinuousGroupKey = false;
367 items.forEach(function (item) {
368 if (item.groupKey != null) {
369 isContinuousGroupKey = false;
370 } else {
371 if (!isContinuousGroupKey) {
372 generatedGroupKey = makeKey(registeredGroupKeys);
373 isContinuousGroupKey = true;
374 registeredGroupKeys[generatedGroupKey] = true;
375 }
376
377 item.groupKey = generatedGroupKey;
378 }
379
380 var groupKey = item.groupKey;
381 var group = groupKeys[groupKey];
382
383 if (!group) {
384 group = {
385 groupKey: groupKey,
386 items: []
387 };
388 groupKeys[groupKey] = group;
389 groups.push(group);
390 }
391
392 group.items.push(item);
393 });
394 return groups;
395}
396function getNextCursors(prevKeys, nextKeys, prevStartCursor, prevEndCursor) {
397 var result = listDiffer.diff(prevKeys, nextKeys, function (key) {
398 return key;
399 });
400 var nextStartCursor = -1;
401 var nextEndCursor = -1; // sync cursors
402
403 result.maintained.forEach(function (_a) {
404 var prevIndex = _a[0],
405 nextIndex = _a[1];
406
407 if (prevStartCursor <= prevIndex && prevIndex <= prevEndCursor) {
408 if (nextStartCursor === -1) {
409 nextStartCursor = nextIndex;
410 nextEndCursor = nextIndex;
411 } else {
412 nextStartCursor = Math.min(nextStartCursor, nextIndex);
413 nextEndCursor = Math.max(nextEndCursor, nextIndex);
414 }
415 }
416 });
417 return {
418 startCursor: nextStartCursor,
419 endCursor: nextEndCursor
420 };
421}
422function splitVirtualGroups(groups, direction, nextGroups) {
423 var virtualGroups = [];
424
425 if (direction === "start") {
426 var index = findIndex(groups, function (group) {
427 return group.type === GROUP_TYPE.NORMAL;
428 });
429
430 if (index === -1) {
431 return [];
432 }
433
434 virtualGroups = groups.slice(0, index);
435 } else {
436 var index = findLastIndex(groups, function (group) {
437 return group.type === GROUP_TYPE.NORMAL;
438 });
439
440 if (index === -1) {
441 return [];
442 }
443
444 virtualGroups = groups.slice(index + 1);
445 }
446
447 var nextVirtualGroups = listDiffer.diff(virtualGroups, nextGroups, function (_a) {
448 var groupKey = _a.groupKey;
449 return groupKey;
450 }).removed.map(function (index) {
451 return virtualGroups[index];
452 }).reverse();
453 return nextVirtualGroups;
454}
455function getFirstRenderingItems(nextItems, horizontal) {
456 var groups = categorize(nextItems);
457
458 if (!groups[0]) {
459 return [];
460 }
461
462 return groups[0].items.map(function (item) {
463 return new InfiniteGridItem(horizontal, __assign({}, item));
464 });
465}
466function getRenderingItemsByStatus(groupManagerStatus, nextItems, usePlaceholder, horizontal) {
467 var prevGroups = groupManagerStatus.groups;
468 var groups = categorize(nextItems);
469 var startVirtualGroups = splitVirtualGroups(prevGroups, "start", groups);
470 var endVirtualGroups = splitVirtualGroups(prevGroups, "end", groups);
471
472 var nextGroups = __spreadArrays(startVirtualGroups, groups, endVirtualGroups);
473
474 var _a = getNextCursors(prevGroups.map(function (group) {
475 return group.groupKey;
476 }), nextGroups.map(function (group) {
477 return group.groupKey;
478 }), groupManagerStatus.cursors[0], groupManagerStatus.cursors[1]),
479 startCursor = _a.startCursor,
480 endCursor = _a.endCursor;
481
482 var nextVisibleItems = flat(nextGroups.slice(startCursor, endCursor + 1).map(function (group) {
483 return group.items.map(function (item) {
484 return new InfiniteGridItem(horizontal, __assign({}, item));
485 });
486 }));
487
488 if (!usePlaceholder) {
489 nextVisibleItems = nextVisibleItems.filter(function (item) {
490 return item.type !== ITEM_TYPE.VIRTUAL;
491 });
492 }
493
494 return nextVisibleItems;
495}
496function mountRenderingItems(items, options) {
497 var grid = options.grid,
498 usePlaceholder = options.usePlaceholder,
499 useLoading = options.useLoading,
500 useFirstRender = options.useFirstRender,
501 status = options.status;
502
503 if (!grid) {
504 return;
505 }
506
507 if (usePlaceholder) {
508 grid.setPlaceholder({});
509 }
510
511 if (useLoading) {
512 grid.setLoading({});
513 }
514
515 if (status) {
516 grid.setStatus(status, true);
517 }
518
519 grid.syncItems(items);
520
521 if (useFirstRender && !status && grid.getGroups().length) {
522 grid.setCursors(0, 0, true);
523 }
524}
525function getRenderingItems(items, options) {
526 var status = options.status,
527 usePlaceholder = options.usePlaceholder,
528 useLoading = options.useLoading,
529 horizontal = options.horizontal,
530 useFirstRender = options.useFirstRender,
531 grid = options.grid;
532 var visibleItems = [];
533
534 if (grid) {
535 grid.setPlaceholder(usePlaceholder ? {} : null);
536 grid.setLoading(useLoading ? {} : null);
537 grid.syncItems(items);
538 visibleItems = grid.getRenderingItems();
539 } else if (status) {
540 visibleItems = getRenderingItemsByStatus(status.groupManager, items, !!usePlaceholder, !!horizontal);
541 } else if (useFirstRender) {
542 visibleItems = getFirstRenderingItems(items, !!horizontal);
543 }
544
545 return visibleItems;
546}
547/* Class Decorator */
548
549function InfiniteGridGetterSetter(component) {
550 var prototype = component.prototype,
551 propertyTypes = component.propertyTypes;
552
553 var _loop_1 = function (name) {
554 var attributes = {
555 enumerable: true,
556 configurable: true,
557 get: function () {
558 var options = this.groupManager.options;
559
560 if (name in options) {
561 return options[name];
562 } else {
563 return options.gridOptions[name];
564 }
565 },
566 set: function (value) {
567 var _a;
568
569 var prevValue = this.groupManager[name];
570
571 if (prevValue === value) {
572 return;
573 }
574
575 this.groupManager.gridOptions = (_a = {}, _a[name] = value, _a);
576 }
577 };
578 Object.defineProperty(prototype, name, attributes);
579 };
580
581 for (var name in propertyTypes) {
582 _loop_1(name);
583 }
584}
585function makeKey(registeredKeys) {
586 // eslint-disable-next-line no-constant-condition
587 while (true) {
588 var key = new Date().getTime() + Math.floor(Math.random() * 1000);
589
590 if (!(key in registeredKeys)) {
591 return key;
592 }
593 }
594}
595function convertHTMLtoElement(html) {
596 var dummy = document.createElement("div");
597 dummy.innerHTML = html;
598 return toArray(dummy.children);
599}
600function convertInsertedItems(items, groupKey) {
601 var insertedItems;
602
603 if (isString(items)) {
604 insertedItems = convertHTMLtoElement(items);
605 } else {
606 insertedItems = items;
607 }
608
609 return insertedItems.map(function (item) {
610 var element;
611 var html = "";
612 var key;
613
614 if (isString(item)) {
615 html = item;
616 } else if ("parentNode" in item) {
617 element = item;
618 html = item.outerHTML;
619 } else {
620 return __assign({
621 groupKey: groupKey
622 }, item);
623 }
624
625 return {
626 key: key,
627 groupKey: groupKey,
628 html: html,
629 element: element
630 };
631 });
632}
633function toArray(nodes) {
634 var array = [];
635
636 if (nodes) {
637 var length = nodes.length;
638
639 for (var i = 0; i < length; i++) {
640 array.push(nodes[i]);
641 }
642 }
643
644 return array;
645}
646function findIndex(arr, callback) {
647 var length = arr.length;
648
649 for (var i = 0; i < length; ++i) {
650 if (callback(arr[i], i)) {
651 return i;
652 }
653 }
654
655 return -1;
656}
657function findLastIndex(arr, callback) {
658 var length = arr.length;
659
660 for (var i = length - 1; i >= 0; --i) {
661 if (callback(arr[i], i)) {
662 return i;
663 }
664 }
665
666 return -1;
667}
668function getItemInfo(info) {
669 var nextInfo = {};
670
671 for (var name in info) {
672 if (name in ITEM_INFO_PROPERTIES) {
673 nextInfo[name] = info[name];
674 }
675 }
676
677 return nextInfo;
678}
679function setPlaceholder(item, info) {
680 for (var name in info) {
681 var value = info[name];
682
683 if (isObject(value)) {
684 item[name] = __assign(__assign({}, item[name]), value);
685 } else {
686 item[name] = info[name];
687 }
688 }
689}
690function isFlatOutline(start, end) {
691 return start.length === end.length && start.every(function (pos, i) {
692 return end[i] === pos;
693 });
694}
695function range(length) {
696 var arr = [];
697
698 for (var i = 0; i < length; ++i) {
699 arr.push(i);
700 }
701
702 return arr;
703}
704function flatGroups(groups) {
705 return flat(groups.map(function (_a) {
706 var grid = _a.grid;
707 return grid.getItems();
708 }));
709}
710function filterVirtuals(items, includePlaceholders) {
711 if (includePlaceholders) {
712 return items;
713 } else {
714 return items.filter(function (item) {
715 return item.type !== ITEM_TYPE.VIRTUAL;
716 });
717 }
718}
719/**
720 * Decorator that makes the method of InfiniteGrid available in the framework.
721 * @ko 프레임워크에서 InfiniteGrid의 메소드를 사용할 수 있게 하는 데코레이터.
722 * @private
723 * @example
724 * ```js
725 * import { withInfiniteGridMethods } from "@egjs/infinitegrid";
726 *
727 * class Grid extends React.Component<Partial<InfiniteGridProps & InfiniteGridOptions>> {
728 * &#64;withInfiniteGridMethods
729 * private grid: NativeGrid;
730 * }
731 * ```
732 */
733
734var withInfiniteGridMethods = Grid.withMethods(INFINITEGRID_METHODS);
735
736var GroupManager =
737/*#__PURE__*/
738function (_super) {
739 __extends(GroupManager, _super);
740
741 function GroupManager(container, options) {
742 var _this = _super.call(this, container, splitOptions(options)) || this;
743
744 _this.groupItems = [];
745 _this.groups = [];
746 _this.itemKeys = {};
747 _this.groupKeys = {};
748 _this.startCursor = 0;
749 _this.endCursor = 0;
750 _this._placeholder = null;
751 _this._loadingGrid = new LoadingGrid(container, {
752 externalContainerManager: _this.containerManager,
753 useFit: false,
754 autoResize: false,
755 renderOnPropertyChange: false,
756 gap: _this.gap
757 });
758 return _this;
759 }
760
761 var __proto = GroupManager.prototype;
762 Object.defineProperty(__proto, "gridOptions", {
763 set: function (options) {
764 var _a = splitGridOptions(options),
765 gridOptions = _a.gridOptions,
766 otherOptions = __rest(_a, ["gridOptions"]);
767
768 var shouldRender = this._checkShouldRender(options);
769
770 this.options.gridOptions = __assign(__assign({}, this.options.gridOptions), gridOptions);
771 this.groups.forEach(function (_a) {
772 var grid = _a.grid;
773
774 for (var name in options) {
775 grid[name] = options[name];
776 }
777 });
778
779 for (var name in otherOptions) {
780 this[name] = otherOptions[name];
781 }
782
783 this._loadingGrid.gap = this.gap;
784
785 if (shouldRender) {
786 this.scheduleRender();
787 }
788 },
789 enumerable: false,
790 configurable: true
791 });
792
793 __proto.getItemByKey = function (key) {
794 return this.itemKeys[key] || null;
795 };
796
797 __proto.getGroupItems = function (includePlaceholders) {
798 return filterVirtuals(this.groupItems, includePlaceholders);
799 };
800
801 __proto.getVisibleItems = function (includePlaceholders) {
802 return filterVirtuals(this.items, includePlaceholders);
803 };
804
805 __proto.getRenderingItems = function () {
806 if (this.hasPlaceholder()) {
807 return this.items;
808 } else {
809 return this.items.filter(function (item) {
810 return item.type !== ITEM_TYPE.VIRTUAL;
811 });
812 }
813 };
814
815 __proto.getGroups = function (includePlaceholders) {
816 return filterVirtuals(this.groups, includePlaceholders);
817 };
818
819 __proto.hasVisibleVirtualGroups = function () {
820 return this.getVisibleGroups(true).some(function (group) {
821 return group.type === GROUP_TYPE.VIRTUAL;
822 });
823 };
824
825 __proto.hasPlaceholder = function () {
826 return !!this._placeholder;
827 };
828
829 __proto.hasLoadingItem = function () {
830 return !!this._getLoadingItem();
831 };
832
833 __proto.setPlaceholder = function (placeholder) {
834 this._placeholder = placeholder;
835
836 this._updatePlaceholder();
837 };
838
839 __proto.getLoadingType = function () {
840 return this._loadingGrid.type;
841 };
842
843 __proto.startLoading = function (type) {
844 this._loadingGrid.type = type;
845 this.items = this._getRenderingItems();
846 return true;
847 };
848
849 __proto.endLoading = function () {
850 var prevType = this._loadingGrid.type;
851 this._loadingGrid.type = "";
852 this.items = this._getRenderingItems();
853 return !!prevType;
854 };
855
856 __proto.setLoading = function (loading) {
857 this._loadingGrid.setLoadingItem(loading);
858
859 this.items = this._getRenderingItems();
860 };
861
862 __proto.getVisibleGroups = function (includePlaceholders) {
863 var groups = this.groups.slice(this.startCursor, this.endCursor + 1);
864 return filterVirtuals(groups, includePlaceholders);
865 };
866
867 __proto.applyGrid = function (items, direction, outline) {
868 var _this = this;
869
870 items.forEach(function (item) {
871 item.mountState = Grid.MOUNT_STATE.MOUNTED;
872 });
873 var renderingGroups = this.groups.slice();
874
875 if (!renderingGroups.length) {
876 return {
877 start: [],
878 end: []
879 };
880 }
881
882 var loadingGrid = this._loadingGrid;
883
884 if (loadingGrid.getLoadingItem()) {
885 if (loadingGrid.type === "start") {
886 renderingGroups.unshift(this._getLoadingGroup());
887 } else if (loadingGrid.type === "end") {
888 renderingGroups.push(this._getLoadingGroup());
889 }
890 }
891
892 var groups = renderingGroups.slice();
893 var nextOutline = outline;
894
895 if (direction === "start") {
896 groups.reverse();
897 }
898
899 groups.forEach(function (group) {
900 var grid = group.grid;
901 var gridItems = grid.getItems();
902 var isVirtual = group.type === GROUP_TYPE.VIRTUAL && !gridItems[0];
903 var appliedItems = gridItems.filter(function (item) {
904 return item.mountState !== Grid.MOUNT_STATE.UNCHECKED && item.rect.width;
905 });
906 var gridOutlines;
907
908 if (isVirtual) {
909 gridOutlines = _this._applyVirtualGrid(grid, direction, nextOutline);
910 } else if (appliedItems.length) {
911 gridOutlines = grid.applyGrid(appliedItems, direction, nextOutline);
912 } else {
913 gridOutlines = {
914 start: __spreadArrays(nextOutline),
915 end: __spreadArrays(nextOutline)
916 };
917 }
918
919 grid.setOutlines(gridOutlines);
920 nextOutline = gridOutlines[direction];
921 });
922 return {
923 start: renderingGroups[0].grid.getOutlines().start,
924 end: renderingGroups[renderingGroups.length - 1].grid.getOutlines().end
925 };
926 };
927
928 __proto.syncItems = function (nextItemInfos) {
929 var _this = this;
930
931 var prevItemKeys = this.itemKeys;
932 this.itemKeys = {};
933
934 var nextItems = this._syncItemInfos(nextItemInfos.map(function (info) {
935 return getItemInfo(info);
936 }), prevItemKeys);
937
938 var prevGroupKeys = this.groupKeys;
939 var nextManagerGroups = categorize(nextItems);
940
941 var startVirtualGroups = this._splitVirtualGroups("start", nextManagerGroups);
942
943 var endVirtualGroups = this._splitVirtualGroups("end", nextManagerGroups);
944
945 nextManagerGroups = __spreadArrays(startVirtualGroups, this._mergeVirtualGroups(nextManagerGroups), endVirtualGroups);
946 var nextGroups = nextManagerGroups.map(function (_a) {
947 var _b, _c;
948
949 var groupKey = _a.groupKey,
950 items = _a.items;
951 var isVirtual = !items[0] || items[0].type === ITEM_TYPE.VIRTUAL;
952 var grid = (_c = (_b = prevGroupKeys[groupKey]) === null || _b === void 0 ? void 0 : _b.grid) !== null && _c !== void 0 ? _c : _this._makeGrid();
953 var gridItems = isVirtual ? items : items.filter(function (_a) {
954 var type = _a.type;
955 return type === ITEM_TYPE.NORMAL;
956 });
957 grid.setItems(gridItems);
958 return {
959 type: isVirtual ? GROUP_TYPE.VIRTUAL : GROUP_TYPE.NORMAL,
960 groupKey: groupKey,
961 grid: grid,
962 items: gridItems,
963 renderItems: items
964 };
965 });
966
967 this._registerGroups(nextGroups);
968 };
969
970 __proto.renderItems = function (options) {
971 if (options === void 0) {
972 options = {};
973 }
974
975 if (options.useResize) {
976 this.groupItems.forEach(function (item) {
977 item.updateState = Grid.UPDATE_STATE.NEED_UPDATE;
978 });
979
980 var loadingItem = this._getLoadingItem();
981
982 if (loadingItem) {
983 loadingItem.updateState = Grid.UPDATE_STATE.NEED_UPDATE;
984 }
985 }
986
987 return _super.prototype.renderItems.call(this, options);
988 };
989
990 __proto.setCursors = function (startCursor, endCursor) {
991 this.startCursor = startCursor;
992 this.endCursor = endCursor;
993 this.items = this._getRenderingItems();
994 };
995
996 __proto.getStartCursor = function () {
997 return this.startCursor;
998 };
999
1000 __proto.getEndCursor = function () {
1001 return this.endCursor;
1002 };
1003
1004 __proto.getGroupStatus = function (type) {
1005 var orgStartCursor = this.startCursor;
1006 var orgEndCursor = this.endCursor;
1007 var orgGroups = this.groups;
1008 var startCursor = orgStartCursor;
1009 var endCursor = orgEndCursor;
1010 var isMinimizeItems = type === STATUS_TYPE.MINIMIZE_INVISIBLE_ITEMS;
1011 var isMinimizeGroups = type === STATUS_TYPE.MINIMIZE_INVISIBLE_GROUPS;
1012 var groups;
1013
1014 if (type === STATUS_TYPE.REMOVE_INVISIBLE_GROUPS) {
1015 groups = this.getVisibleGroups();
1016 endCursor -= startCursor;
1017 startCursor = 0;
1018 } else {
1019 groups = this.getGroups();
1020 }
1021
1022 var groupStatus = groups.map(function (_a, i) {
1023 var grid = _a.grid,
1024 groupKey = _a.groupKey;
1025 var isOutsideCursor = i < startCursor || endCursor < i;
1026 var isVirtualItems = isMinimizeItems && isOutsideCursor;
1027 var isVirtualGroup = isMinimizeGroups && isOutsideCursor;
1028 var gridItems = grid.getItems();
1029 var items = isVirtualGroup ? [] : gridItems.map(function (item) {
1030 return isVirtualItems ? item.getVirtualStatus() : item.getMinimizedStatus();
1031 });
1032 return {
1033 type: isVirtualGroup || isVirtualItems ? GROUP_TYPE.VIRTUAL : GROUP_TYPE.NORMAL,
1034 groupKey: groupKey,
1035 outlines: grid.getOutlines(),
1036 items: items
1037 };
1038 });
1039 var startGroup = orgGroups[orgStartCursor];
1040 var endGroup = orgGroups[orgEndCursor];
1041 var totalItems = this.getGroupItems();
1042 var itemStartCursor = totalItems.indexOf(startGroup === null || startGroup === void 0 ? void 0 : startGroup.items[0]);
1043 var itemEndCursor = totalItems.indexOf(endGroup === null || endGroup === void 0 ? void 0 : endGroup.items.slice().reverse()[0]);
1044 return {
1045 cursors: [startCursor, endCursor],
1046 orgCursors: [orgStartCursor, orgEndCursor],
1047 itemCursors: [itemStartCursor, itemEndCursor],
1048 startGroupKey: startGroup === null || startGroup === void 0 ? void 0 : startGroup.groupKey,
1049 endGroupKey: endGroup === null || endGroup === void 0 ? void 0 : endGroup.groupKey,
1050 groups: groupStatus,
1051 outlines: this.outlines
1052 };
1053 };
1054
1055 __proto.setGroupStatus = function (status) {
1056 var _this = this;
1057
1058 this.itemKeys = {};
1059 this.groupItems = [];
1060 this.items = [];
1061 var prevGroupKeys = this.groupKeys;
1062 var nextGroups = status.groups.map(function (_a) {
1063 var _b, _c;
1064
1065 var type = _a.type,
1066 groupKey = _a.groupKey,
1067 items = _a.items,
1068 outlines = _a.outlines;
1069
1070 var nextItems = _this._syncItemInfos(items);
1071
1072 var grid = (_c = (_b = prevGroupKeys[groupKey]) === null || _b === void 0 ? void 0 : _b.grid) !== null && _c !== void 0 ? _c : _this._makeGrid();
1073 grid.setOutlines(outlines);
1074 grid.setItems(nextItems);
1075 return {
1076 type: type,
1077 groupKey: groupKey,
1078 grid: grid,
1079 items: nextItems,
1080 renderItems: nextItems
1081 };
1082 });
1083 this.setOutlines(status.outlines);
1084
1085 this._registerGroups(nextGroups);
1086
1087 this._updatePlaceholder();
1088
1089 this.setCursors(status.cursors[0], status.cursors[1]);
1090 };
1091
1092 __proto.appendPlaceholders = function (items, groupKey) {
1093 return this.insertPlaceholders("end", items, groupKey);
1094 };
1095
1096 __proto.prependPlaceholders = function (items, groupKey) {
1097 return this.insertPlaceholders("start", items, groupKey);
1098 };
1099
1100 __proto.removePlaceholders = function (type) {
1101 var groups = this.groups;
1102 var length = groups.length;
1103
1104 if (type === "start") {
1105 var index = findIndex(groups, function (group) {
1106 return group.type === GROUP_TYPE.NORMAL;
1107 });
1108 groups.splice(0, index);
1109 } else if (type === "end") {
1110 var index = findLastIndex(groups, function (group) {
1111 return group.type === GROUP_TYPE.NORMAL;
1112 });
1113 groups.splice(index + 1, length - index - 1);
1114 } else {
1115 var groupKey_1 = type.groupKey;
1116 var index = findIndex(groups, function (group) {
1117 return group.groupKey === groupKey_1;
1118 });
1119
1120 if (index > -1) {
1121 groups.splice(index, 1);
1122 }
1123 }
1124
1125 this.syncItems(flatGroups(this.getGroups()));
1126 };
1127
1128 __proto.insertPlaceholders = function (direction, items, groupKey) {
1129 var _a, _b;
1130
1131 if (groupKey === void 0) {
1132 groupKey = makeKey(this.groupKeys);
1133 }
1134
1135 var infos = [];
1136
1137 if (isNumber(items)) {
1138 infos = range(items).map(function () {
1139 return {
1140 type: ITEM_TYPE.VIRTUAL,
1141 groupKey: groupKey
1142 };
1143 });
1144 } else if (Array.isArray(items)) {
1145 infos = items.map(function (status) {
1146 return __assign(__assign({
1147 groupKey: groupKey
1148 }, status), {
1149 type: ITEM_TYPE.VIRTUAL
1150 });
1151 });
1152 }
1153
1154 var grid = this._makeGrid();
1155
1156 var nextItems = this._syncItemInfos(infos, this.itemKeys);
1157
1158 this._updatePlaceholder(nextItems);
1159
1160 grid.setItems(nextItems);
1161 var group = {
1162 type: GROUP_TYPE.VIRTUAL,
1163 groupKey: groupKey,
1164 grid: grid,
1165 items: nextItems,
1166 renderItems: nextItems
1167 };
1168 this.groupKeys[groupKey] = group;
1169
1170 if (direction === "end") {
1171 this.groups.push(group);
1172
1173 (_a = this.groupItems).push.apply(_a, nextItems);
1174 } else {
1175 this.groups.splice(0, 0, group);
1176
1177 (_b = this.groupItems).splice.apply(_b, __spreadArrays([0, 0], nextItems));
1178
1179 if (this.startCursor > -1) {
1180 ++this.startCursor;
1181 ++this.endCursor;
1182 }
1183 }
1184
1185 return {
1186 group: group,
1187 items: nextItems
1188 };
1189 };
1190
1191 __proto.shouldRerenderItems = function () {
1192 var isRerender = false;
1193 this.getVisibleGroups().forEach(function (group) {
1194 var items = group.items;
1195
1196 if (items.length === group.renderItems.length || items.every(function (item) {
1197 return item.mountState === Grid.MOUNT_STATE.UNCHECKED;
1198 })) {
1199 return;
1200 }
1201
1202 isRerender = true;
1203 group.renderItems = __spreadArrays(items);
1204 });
1205
1206 if (isRerender) {
1207 this.items = this._getRenderingItems();
1208 }
1209
1210 return isRerender;
1211 };
1212
1213 __proto._getGroupItems = function () {
1214 return flatGroups(this.getGroups(true));
1215 };
1216
1217 __proto._getRenderingItems = function () {
1218 var items = flat(this.getVisibleGroups(true).map(function (item) {
1219 return item.renderItems;
1220 }));
1221 var loadingGrid = this._loadingGrid;
1222 var loadingItem = loadingGrid.getLoadingItem();
1223
1224 if (loadingItem) {
1225 if (loadingGrid.type === "end") {
1226 items.push(loadingItem);
1227 } else if (loadingGrid.type === "start") {
1228 items.unshift(loadingItem);
1229 }
1230 }
1231
1232 return items;
1233 };
1234
1235 __proto._checkShouldRender = function (options) {
1236 var GridConstructor = this.options.gridConstructor;
1237 var prevOptions = this.gridOptions;
1238 var propertyTypes = GridConstructor.propertyTypes;
1239
1240 for (var name in prevOptions) {
1241 if (!(name in options) && propertyTypes[name] === Grid.PROPERTY_TYPE.RENDER_PROPERTY) {
1242 return true;
1243 }
1244 }
1245
1246 for (var name in options) {
1247 if (prevOptions[name] !== options[name] && propertyTypes[name] === Grid.PROPERTY_TYPE.RENDER_PROPERTY) {
1248 return true;
1249 }
1250 }
1251
1252 return false;
1253 };
1254
1255 __proto._applyVirtualGrid = function (grid, direction, outline) {
1256 var startOutline = outline.length ? __spreadArrays(outline) : [0];
1257 var prevOutlines = grid.getOutlines();
1258 var prevOutline = prevOutlines[direction === "end" ? "start" : "end"];
1259
1260 if (prevOutline.length !== startOutline.length || prevOutline.some(function (value, i) {
1261 return value !== startOutline[i];
1262 })) {
1263 return {
1264 start: __spreadArrays(startOutline),
1265 end: __spreadArrays(startOutline)
1266 };
1267 }
1268
1269 return prevOutlines;
1270 };
1271
1272 __proto._syncItemInfos = function (nextItemInfos, prevItemKeys) {
1273 if (prevItemKeys === void 0) {
1274 prevItemKeys = {};
1275 }
1276
1277 var horizontal = this.options.horizontal;
1278 var nextItemKeys = this.itemKeys;
1279 nextItemInfos.filter(function (info) {
1280 return info.key != null;
1281 }).forEach(function (info) {
1282 var key = info.key;
1283 var prevItem = prevItemKeys[key];
1284
1285 if (!prevItem) {
1286 nextItemKeys[key] = new InfiniteGridItem(horizontal, __assign({}, info));
1287 } else if (prevItem.type === ITEM_TYPE.VIRTUAL && info.type !== ITEM_TYPE.VIRTUAL) {
1288 nextItemKeys[key] = new InfiniteGridItem(horizontal, __assign({
1289 orgRect: prevItem.orgRect,
1290 rect: prevItem.rect
1291 }, info));
1292 } else {
1293 if (info.data) {
1294 prevItem.data = info.data;
1295 }
1296
1297 nextItemKeys[key] = prevItem;
1298 }
1299 });
1300 var nextItems = nextItemInfos.map(function (info) {
1301 var key = info.key;
1302
1303 if (info.key == null) {
1304 key = makeKey(nextItemKeys);
1305 nextItemKeys[key] = new InfiniteGridItem(horizontal, __assign(__assign({}, info), {
1306 key: key
1307 }));
1308 }
1309
1310 return nextItemKeys[key];
1311 });
1312 return nextItems;
1313 };
1314
1315 __proto._registerGroups = function (groups) {
1316 var nextGroupKeys = {};
1317 groups.forEach(function (group) {
1318 nextGroupKeys[group.groupKey] = group;
1319 });
1320 this.groups = groups;
1321 this.groupKeys = nextGroupKeys;
1322 this.groupItems = this._getGroupItems();
1323 };
1324
1325 __proto._splitVirtualGroups = function (direction, nextGroups) {
1326 var groups = splitVirtualGroups(this.groups, direction, nextGroups);
1327 var itemKeys = this.itemKeys;
1328 groups.forEach(function (_a) {
1329 var renderItems = _a.renderItems;
1330 renderItems.forEach(function (item) {
1331 itemKeys[item.key] = item;
1332 });
1333 });
1334 return groups;
1335 };
1336
1337 __proto._mergeVirtualGroups = function (groups) {
1338 var itemKeys = this.itemKeys;
1339 var groupKeys = this.groupKeys;
1340 groups.forEach(function (group) {
1341 var prevGroup = groupKeys[group.groupKey];
1342
1343 if (!prevGroup) {
1344 return;
1345 }
1346
1347 var items = group.items;
1348
1349 if (items.every(function (item) {
1350 return item.mountState === Grid.MOUNT_STATE.UNCHECKED;
1351 })) {
1352 prevGroup.renderItems.forEach(function (item) {
1353 if (item.type === ITEM_TYPE.VIRTUAL && !itemKeys[item.key]) {
1354 items.push(item);
1355 itemKeys[item.key] = item;
1356 }
1357 });
1358 }
1359 });
1360 return groups;
1361 };
1362
1363 __proto._updatePlaceholder = function (items) {
1364 if (items === void 0) {
1365 items = this.groupItems;
1366 }
1367
1368 var placeholder = this._placeholder;
1369
1370 if (!placeholder) {
1371 return;
1372 }
1373
1374 items.filter(function (item) {
1375 return item.type === ITEM_TYPE.VIRTUAL;
1376 }).forEach(function (item) {
1377 setPlaceholder(item, placeholder);
1378 });
1379 };
1380
1381 __proto._makeGrid = function () {
1382 var GridConstructor = this.options.gridConstructor;
1383 var gridOptions = this.gridOptions;
1384 var container = this.containerElement;
1385 return new GridConstructor(container, __assign(__assign({}, gridOptions), {
1386 useFit: false,
1387 autoResize: false,
1388 renderOnPropertyChange: false,
1389 externalContainerManager: this.containerManager,
1390 externalItemRenderer: this.itemRenderer
1391 }));
1392 };
1393
1394 __proto._getLoadingGroup = function () {
1395 var loadingGrid = this._loadingGrid;
1396 var items = loadingGrid.getItems();
1397 return {
1398 groupKey: LOADING_GROUP_KEY,
1399 type: GROUP_TYPE.NORMAL,
1400 grid: loadingGrid,
1401 items: items,
1402 renderItems: items
1403 };
1404 };
1405
1406 __proto._getLoadingItem = function () {
1407 return this._loadingGrid.getLoadingItem();
1408 };
1409
1410 GroupManager.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
1411 gridConstructor: null,
1412 gridOptions: {}
1413 });
1414 GroupManager.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
1415 gridConstructor: Grid.PROPERTY_TYPE.PROPERTY,
1416 gridOptions: Grid.PROPERTY_TYPE.PROPERTY
1417 });
1418 GroupManager = __decorate([Grid.GetterSetter], GroupManager);
1419 return GroupManager;
1420}(Grid);
1421
1422var Infinite =
1423/*#__PURE__*/
1424function (_super) {
1425 __extends(Infinite, _super);
1426
1427 function Infinite(options) {
1428 var _this = _super.call(this) || this;
1429
1430 _this.startCursor = -1;
1431 _this.endCursor = -1;
1432 _this.size = 0;
1433 _this.items = [];
1434 _this.itemKeys = {};
1435 _this.options = __assign({
1436 threshold: 0,
1437 useRecycle: true,
1438 defaultDirection: "end"
1439 }, options);
1440 return _this;
1441 }
1442
1443 var __proto = Infinite.prototype;
1444
1445 __proto.scroll = function (scrollPos) {
1446 var prevStartCursor = this.startCursor;
1447 var prevEndCursor = this.endCursor;
1448 var items = this.items;
1449 var length = items.length;
1450 var size = this.size;
1451 var _a = this.options,
1452 defaultDirection = _a.defaultDirection,
1453 threshold = _a.threshold,
1454 useRecycle = _a.useRecycle;
1455 var isDirectionEnd = defaultDirection === "end";
1456
1457 if (!length) {
1458 this.trigger(isDirectionEnd ? "requestAppend" : "requestPrepend", {
1459 key: undefined,
1460 isVirtual: false
1461 });
1462 return;
1463 } else if (prevStartCursor === -1 || prevEndCursor === -1) {
1464 var nextCursor = isDirectionEnd ? 0 : length - 1;
1465 this.trigger("change", {
1466 prevStartCursor: prevStartCursor,
1467 prevEndCursor: prevEndCursor,
1468 nextStartCursor: nextCursor,
1469 nextEndCursor: nextCursor
1470 });
1471 return;
1472 }
1473
1474 var endScrollPos = scrollPos + size;
1475 var startEdgePos = Math.max.apply(Math, items[prevStartCursor].startOutline);
1476 var endEdgePos = Math.min.apply(Math, items[prevEndCursor].endOutline);
1477 var visibles = items.map(function (item) {
1478 var startOutline = item.startOutline,
1479 endOutline = item.endOutline;
1480
1481 if (!startOutline.length || !endOutline.length) {
1482 return false;
1483 }
1484
1485 var startPos = Math.min.apply(Math, startOutline);
1486 var endPos = Math.max.apply(Math, endOutline);
1487
1488 if (startPos - threshold <= endScrollPos && scrollPos <= endPos + threshold) {
1489 return true;
1490 }
1491
1492 return false;
1493 });
1494 var hasStartItems = 0 < prevStartCursor;
1495 var hasEndItems = prevEndCursor < length - 1;
1496 var isStart = scrollPos <= startEdgePos + threshold;
1497 var isEnd = endScrollPos >= endEdgePos - threshold;
1498 var nextStartCursor = visibles.indexOf(true);
1499 var nextEndCursor = visibles.lastIndexOf(true);
1500
1501 if (nextStartCursor === -1) {
1502 nextStartCursor = prevStartCursor;
1503 nextEndCursor = prevEndCursor;
1504 }
1505
1506 if (!useRecycle) {
1507 nextStartCursor = Math.min(nextStartCursor, prevStartCursor);
1508 nextEndCursor = Math.max(nextEndCursor, prevEndCursor);
1509 }
1510
1511 if (nextStartCursor === prevStartCursor && hasStartItems && isStart) {
1512 nextStartCursor -= 1;
1513 }
1514
1515 if (nextEndCursor === prevEndCursor && hasEndItems && isEnd) {
1516 nextEndCursor += 1;
1517 }
1518
1519 if (prevStartCursor !== nextStartCursor || prevEndCursor !== nextEndCursor) {
1520 this.trigger("change", {
1521 prevStartCursor: prevStartCursor,
1522 prevEndCursor: prevEndCursor,
1523 nextStartCursor: nextStartCursor,
1524 nextEndCursor: nextEndCursor
1525 });
1526 return;
1527 } else if (this._requestVirtualItems()) {
1528 return;
1529 } else if ((!isDirectionEnd || !isEnd) && isStart) {
1530 this.trigger("requestPrepend", {
1531 key: items[prevStartCursor].key,
1532 isVirtual: false
1533 });
1534 } else if ((isDirectionEnd || !isStart) && isEnd) {
1535 this.trigger("requestAppend", {
1536 key: items[prevEndCursor].key,
1537 isVirtual: false
1538 });
1539 }
1540 };
1541 /**
1542 * @private
1543 * Call the requestAppend or requestPrepend event to fill the virtual items.
1544 * @ko virtual item을 채우기 위해 requestAppend 또는 requestPrepend 이벤트를 호출합니다.
1545 * @return - Whether the event is called. <ko>이벤트를 호출했는지 여부.</ko>
1546 */
1547
1548
1549 __proto._requestVirtualItems = function () {
1550 var isDirectionEnd = this.options.defaultDirection === "end";
1551 var items = this.items;
1552 var totalVisibleItems = this.getVisibleItems();
1553 var visibleItems = totalVisibleItems.filter(function (item) {
1554 return !item.isVirtual;
1555 });
1556 var totalVisibleLength = totalVisibleItems.length;
1557 var visibleLength = visibleItems.length;
1558 var startCursor = this.getStartCursor();
1559 var endCursor = this.getEndCursor();
1560
1561 if (visibleLength === totalVisibleLength) {
1562 return false;
1563 } else if (visibleLength) {
1564 var startKey_1 = visibleItems[0].key;
1565 var endKey_1 = visibleItems[visibleLength - 1].key;
1566 var startIndex = findIndex(items, function (item) {
1567 return item.key === startKey_1;
1568 }) - 1;
1569 var endIndex = findIndex(items, function (item) {
1570 return item.key === endKey_1;
1571 }) + 1;
1572 var isEnd = endIndex <= endCursor;
1573 var isStart = startIndex >= startCursor; // Fill the placeholder with the original item.
1574
1575 if ((isDirectionEnd || !isStart) && isEnd) {
1576 this.trigger("requestAppend", {
1577 key: endKey_1,
1578 nextKey: items[endIndex].key,
1579 isVirtual: true
1580 });
1581 return true;
1582 } else if ((!isDirectionEnd || !isEnd) && isStart) {
1583 this.trigger("requestPrepend", {
1584 key: startKey_1,
1585 nextKey: items[startIndex].key,
1586 isVirtual: true
1587 });
1588 return true;
1589 }
1590 } else if (totalVisibleLength) {
1591 var lastItem = totalVisibleItems[totalVisibleLength - 1];
1592
1593 if (isDirectionEnd) {
1594 this.trigger("requestAppend", {
1595 nextKey: totalVisibleItems[0].key,
1596 isVirtual: true
1597 });
1598 } else {
1599 this.trigger("requestPrepend", {
1600 nextKey: lastItem.key,
1601 isVirtual: true
1602 });
1603 }
1604
1605 return true;
1606 }
1607
1608 return false;
1609 };
1610
1611 __proto.setCursors = function (startCursor, endCursor) {
1612 this.startCursor = startCursor;
1613 this.endCursor = endCursor;
1614 };
1615
1616 __proto.setSize = function (size) {
1617 this.size = size;
1618 };
1619
1620 __proto.getStartCursor = function () {
1621 return this.startCursor;
1622 };
1623
1624 __proto.getEndCursor = function () {
1625 return this.endCursor;
1626 };
1627
1628 __proto.isLoading = function (direction) {
1629 var startCursor = this.startCursor;
1630 var endCursor = this.endCursor;
1631 var items = this.items;
1632 var firstItem = items[startCursor];
1633 var lastItem = items[endCursor];
1634 var length = items.length;
1635
1636 if (direction === DIRECTION.END && endCursor > -1 && endCursor < length - 1 && !lastItem.isVirtual && !isFlatOutline(lastItem.startOutline, lastItem.endOutline)) {
1637 return false;
1638 }
1639
1640 if (direction === DIRECTION.START && startCursor > 0 && !firstItem.isVirtual && !isFlatOutline(firstItem.startOutline, firstItem.endOutline)) {
1641 return false;
1642 }
1643
1644 return true;
1645 };
1646
1647 __proto.setItems = function (nextItems) {
1648 this.items = nextItems;
1649 var itemKeys = {};
1650 nextItems.forEach(function (item) {
1651 itemKeys[item.key] = item;
1652 });
1653 this.itemKeys = itemKeys;
1654 };
1655
1656 __proto.syncItems = function (nextItems) {
1657 var prevItems = this.items;
1658 var prevStartCursor = this.startCursor;
1659 var prevEndCursor = this.endCursor;
1660
1661 var _a = getNextCursors(this.items.map(function (item) {
1662 return item.key;
1663 }), nextItems.map(function (item) {
1664 return item.key;
1665 }), prevStartCursor, prevEndCursor),
1666 nextStartCursor = _a.startCursor,
1667 nextEndCursor = _a.endCursor; // sync items between cursors
1668
1669
1670 var isChange = nextEndCursor - nextStartCursor !== prevEndCursor - prevStartCursor || prevStartCursor === -1 || nextStartCursor === -1;
1671
1672 if (!isChange) {
1673 var prevVisibleItems = prevItems.slice(prevStartCursor, prevEndCursor + 1);
1674 var nextVisibleItems = nextItems.slice(nextStartCursor, nextEndCursor + 1);
1675 var visibleResult = listDiffer.diff(prevVisibleItems, nextVisibleItems, function (item) {
1676 return item.key;
1677 });
1678 isChange = visibleResult.added.length > 0 || visibleResult.removed.length > 0 || visibleResult.changed.length > 0;
1679 }
1680
1681 this.setItems(nextItems);
1682 this.setCursors(nextStartCursor, nextEndCursor);
1683 return isChange;
1684 };
1685
1686 __proto.getItems = function () {
1687 return this.items;
1688 };
1689
1690 __proto.getVisibleItems = function () {
1691 var startCursor = this.startCursor;
1692 var endCursor = this.endCursor;
1693
1694 if (startCursor === -1) {
1695 return [];
1696 }
1697
1698 return this.items.slice(startCursor, endCursor + 1);
1699 };
1700
1701 __proto.getItemByKey = function (key) {
1702 return this.itemKeys[key];
1703 };
1704
1705 __proto.getRenderedVisibleItems = function () {
1706 var items = this.getVisibleItems();
1707 var rendered = items.map(function (_a) {
1708 var startOutline = _a.startOutline,
1709 endOutline = _a.endOutline;
1710 var length = startOutline.length;
1711
1712 if (length === 0 || length !== endOutline.length) {
1713 return false;
1714 }
1715
1716 return startOutline.some(function (pos, i) {
1717 return endOutline[i] !== pos;
1718 });
1719 });
1720 var startIndex = rendered.indexOf(true);
1721 var endIndex = rendered.lastIndexOf(true);
1722 return endIndex === -1 ? [] : items.slice(startIndex, endIndex + 1);
1723 };
1724
1725 __proto.destroy = function () {
1726 this.off();
1727 this.startCursor = -1;
1728 this.endCursor = -1;
1729 this.items = [];
1730 this.size = 0;
1731 };
1732
1733 return Infinite;
1734}(Component);
1735
1736var Renderer =
1737/*#__PURE__*/
1738function (_super) {
1739 __extends(Renderer, _super);
1740
1741 function Renderer() {
1742 var _this = _super !== null && _super.apply(this, arguments) || this;
1743
1744 _this.items = [];
1745 _this.container = null;
1746 _this.rendererKey = 0;
1747 _this._updateTimer = 0;
1748 _this._state = {};
1749 return _this;
1750 }
1751
1752 var __proto = Renderer.prototype;
1753
1754 __proto.updateKey = function () {
1755 this.rendererKey = Date.now();
1756 };
1757
1758 __proto.getItems = function () {
1759 return this.items;
1760 };
1761
1762 __proto.setContainer = function (container) {
1763 this.container = container;
1764 };
1765
1766 __proto.render = function (nextItems, state) {
1767 if (state) {
1768 this._state = state;
1769 }
1770
1771 return this.syncItems(nextItems);
1772 };
1773
1774 __proto.update = function (state) {
1775 var _this = this;
1776
1777 if (state === void 0) {
1778 state = {};
1779 }
1780
1781 this._state = state;
1782 this.trigger("update", {
1783 state: state
1784 });
1785 clearTimeout(this._updateTimer);
1786 this._updateTimer = window.setTimeout(function () {
1787 _this.trigger("requestUpdate", {
1788 state: state
1789 });
1790 });
1791 };
1792
1793 __proto.updated = function (nextElements) {
1794 var _a, _b;
1795
1796 if (nextElements === void 0) {
1797 nextElements = (_b = (_a = this.container) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [];
1798 }
1799
1800 var diffResult = this._diffResult;
1801 var isChanged = !!(diffResult.added.length || diffResult.removed.length || diffResult.changed.length);
1802 var state = this._state;
1803 this._state = {};
1804 var nextItems = diffResult.list;
1805 this.items = nextItems;
1806 nextItems.forEach(function (item, i) {
1807 item.element = nextElements[i];
1808 });
1809 this.trigger("updated", {
1810 items: nextItems,
1811 elements: toArray(nextElements),
1812 diffResult: this._diffResult,
1813 state: state,
1814 isChanged: isChanged
1815 });
1816 return isChanged;
1817 };
1818
1819 __proto.destroy = function () {
1820 this.off();
1821 };
1822
1823 __proto.syncItems = function (items) {
1824 var rendererKey = this.rendererKey;
1825 var prevItems = this.items;
1826 var nextItems = items.map(function (item) {
1827 return __assign(__assign({}, item), {
1828 renderKey: rendererKey + "_" + item.key
1829 });
1830 });
1831 var result = listDiffer.diff(prevItems, nextItems, function (item) {
1832 return item.renderKey;
1833 });
1834 this._diffResult = result;
1835 return result;
1836 };
1837
1838 return Renderer;
1839}(Component);
1840
1841var VanillaRenderer =
1842/*#__PURE__*/
1843function (_super) {
1844 __extends(VanillaRenderer, _super);
1845
1846 function VanillaRenderer() {
1847 return _super !== null && _super.apply(this, arguments) || this;
1848 }
1849
1850 var __proto = VanillaRenderer.prototype;
1851
1852 __proto.render = function (nextItems, state) {
1853 var container = this.container;
1854
1855 var result = _super.prototype.render.call(this, nextItems, state);
1856
1857 var prevList = result.prevList,
1858 removed = result.removed,
1859 ordered = result.ordered,
1860 added = result.added,
1861 list = result.list;
1862
1863 var diffList = __spreadArrays(prevList);
1864
1865 removed.forEach(function (index) {
1866 diffList.splice(index, 1);
1867 container.removeChild(prevList[index].element);
1868 });
1869 ordered.forEach(function (_a) {
1870 var _b, _c;
1871
1872 var prevIndex = _a[0],
1873 nextIndex = _a[1];
1874 var item = diffList.splice(prevIndex, 1)[0];
1875 diffList.splice(nextIndex, 0, item);
1876 container.insertBefore(item.element, (_c = (_b = diffList[nextIndex + 1]) === null || _b === void 0 ? void 0 : _b.element) !== null && _c !== void 0 ? _c : null);
1877 });
1878 added.forEach(function (index) {
1879 var _a, _b;
1880
1881 var item = list[index];
1882 diffList.splice(index, 0, item);
1883 container.insertBefore(item.element, (_b = (_a = diffList[index + 1]) === null || _a === void 0 ? void 0 : _a.element) !== null && _b !== void 0 ? _b : null);
1884 });
1885 this.updated(container.children);
1886 return result;
1887 };
1888
1889 return VanillaRenderer;
1890}(Renderer);
1891
1892var VanillaGridRenderer =
1893/*#__PURE__*/
1894function (_super) {
1895 __extends(VanillaGridRenderer, _super);
1896
1897 function VanillaGridRenderer() {
1898 return _super !== null && _super.apply(this, arguments) || this;
1899 }
1900
1901 var __proto = VanillaGridRenderer.prototype;
1902
1903 __proto.syncItems = function (nextItems) {
1904 var result = _super.prototype.syncItems.call(this, nextItems);
1905
1906 var added = result.added,
1907 list = result.list;
1908 added.forEach(function (index) {
1909 var orgItem = nextItems[index].orgItem;
1910
1911 if (orgItem.html && !orgItem.element) {
1912 orgItem.element = convertHTMLtoElement(orgItem.html)[0];
1913 }
1914
1915 list[index].element = orgItem.element;
1916 });
1917 return result;
1918 };
1919
1920 return VanillaGridRenderer;
1921}(VanillaRenderer);
1922
1923var ScrollManager =
1924/*#__PURE__*/
1925function (_super) {
1926 __extends(ScrollManager, _super);
1927
1928 function ScrollManager(wrapper, options) {
1929 var _this = _super.call(this) || this;
1930
1931 _this.wrapper = wrapper;
1932 _this.prevScrollPos = null;
1933 _this.scrollOffset = 0;
1934 _this.contentSize = 0;
1935 _this._isScrollIssue = IS_IOS;
1936
1937 _this._onCheck = function () {
1938 var prevScrollPos = _this.getScrollPos();
1939
1940 var nextScrollPos = _this.getOrgScrollPos();
1941
1942 _this.setScrollPos(nextScrollPos);
1943
1944 if (prevScrollPos === null || _this._isScrollIssue && nextScrollPos === 0 || prevScrollPos === nextScrollPos) {
1945 nextScrollPos && (_this._isScrollIssue = false);
1946 return;
1947 }
1948
1949 _this._isScrollIssue = false;
1950
1951 _this.trigger(new Component.ComponentEvent("scroll", {
1952 direction: prevScrollPos < nextScrollPos ? "end" : "start",
1953 scrollPos: nextScrollPos,
1954 relativeScrollPos: _this.getRelativeScrollPos()
1955 }));
1956 };
1957
1958 _this.options = __assign({
1959 container: false,
1960 containerTag: "div",
1961 horizontal: false
1962 }, options);
1963
1964 _this._init();
1965
1966 return _this;
1967 }
1968
1969 var __proto = ScrollManager.prototype;
1970
1971 __proto.getWrapper = function () {
1972 return this.wrapper;
1973 };
1974
1975 __proto.getContainer = function () {
1976 return this.container;
1977 };
1978
1979 __proto.getScrollContainer = function () {
1980 return this.scrollContainer;
1981 };
1982
1983 __proto.getScrollOffset = function () {
1984 return this.scrollOffset;
1985 };
1986
1987 __proto.getContentSize = function () {
1988 return this.contentSize;
1989 };
1990
1991 __proto.getRelativeScrollPos = function () {
1992 return (this.prevScrollPos || 0) - this.scrollOffset;
1993 };
1994
1995 __proto.getScrollPos = function () {
1996 return this.prevScrollPos;
1997 };
1998
1999 __proto.setScrollPos = function (pos) {
2000 this.prevScrollPos = pos;
2001 };
2002
2003 __proto.getOrgScrollPos = function () {
2004 var eventTarget = this.eventTarget;
2005 var horizontal = this.options.horizontal;
2006 var prop = "scroll" + (horizontal ? "Left" : "Top");
2007
2008 if (isWindow(eventTarget)) {
2009 return window[horizontal ? "pageXOffset" : "pageYOffset"] || document.documentElement[prop] || document.body[prop];
2010 } else {
2011 return eventTarget[prop];
2012 }
2013 };
2014
2015 __proto.setStatus = function (status) {
2016 this.contentSize = status.contentSize;
2017 this.scrollOffset = status.scrollOffset;
2018 this.prevScrollPos = status.prevScrollPos;
2019 this.scrollTo(this.prevScrollPos);
2020 };
2021
2022 __proto.getStatus = function () {
2023 return {
2024 contentSize: this.contentSize,
2025 scrollOffset: this.scrollOffset,
2026 prevScrollPos: this.prevScrollPos
2027 };
2028 };
2029
2030 __proto.scrollTo = function (pos) {
2031 var eventTarget = this.eventTarget;
2032 var horizontal = this.options.horizontal;
2033
2034 var _a = horizontal ? [pos, 0] : [0, pos],
2035 x = _a[0],
2036 y = _a[1];
2037
2038 if (isWindow(eventTarget)) {
2039 eventTarget.scroll(x, y);
2040 } else {
2041 eventTarget.scrollLeft = x;
2042 eventTarget.scrollTop = y;
2043 }
2044 };
2045
2046 __proto.scrollBy = function (pos) {
2047 if (!pos) {
2048 return;
2049 }
2050
2051 var eventTarget = this.eventTarget;
2052 var horizontal = this.options.horizontal;
2053
2054 var _a = horizontal ? [pos, 0] : [0, pos],
2055 x = _a[0],
2056 y = _a[1];
2057
2058 this.prevScrollPos += pos;
2059
2060 if (isWindow(eventTarget)) {
2061 eventTarget.scrollBy(x, y);
2062 } else {
2063 eventTarget.scrollLeft += x;
2064 eventTarget.scrollTop += y;
2065 }
2066 };
2067
2068 __proto.resize = function () {
2069 var scrollContainer = this.scrollContainer;
2070 var horizontal = this.options.horizontal;
2071 var scrollContainerRect = scrollContainer === document.body ? {
2072 top: 0,
2073 left: 0
2074 } : scrollContainer.getBoundingClientRect();
2075 var containerRect = this.container.getBoundingClientRect();
2076 this.scrollOffset = (this.prevScrollPos || 0) + (horizontal ? containerRect.left - scrollContainerRect.left : containerRect.top - scrollContainerRect.top);
2077 this.contentSize = horizontal ? scrollContainer.offsetWidth : scrollContainer.offsetHeight;
2078 };
2079
2080 __proto.destroy = function () {
2081 var container = this.container;
2082 this.eventTarget.removeEventListener("scroll", this._onCheck);
2083
2084 if (this._isCreateElement) {
2085 var scrollContainer = this.scrollContainer;
2086 var fragment_1 = document.createDocumentFragment();
2087 var childNodes = toArray(container.childNodes);
2088 scrollContainer.removeChild(container);
2089 childNodes.forEach(function (childNode) {
2090 fragment_1.appendChild(childNode);
2091 });
2092 scrollContainer.appendChild(fragment_1);
2093 } else if (this.options.container) {
2094 container.style.cssText = this._orgCSSText;
2095 }
2096 };
2097
2098 __proto._init = function () {
2099 var _a;
2100
2101 var _b = this.options,
2102 containerOption = _b.container,
2103 containerTag = _b.containerTag,
2104 horizontal = _b.horizontal;
2105 var wrapper = this.wrapper;
2106 var scrollContainer = wrapper;
2107 var container = wrapper;
2108 var containerCSSText = "";
2109
2110 if (!containerOption) {
2111 scrollContainer = document.body;
2112 containerCSSText = container.style.cssText;
2113 } else {
2114 if (containerOption instanceof HTMLElement) {
2115 // Container that already exists
2116 container = containerOption;
2117 } else if (containerOption === true) {
2118 // Create Container
2119 container = document.createElement(containerTag);
2120 container.style.position = "relative";
2121 container.className = CONTAINER_CLASS_NAME;
2122 var childNodes = toArray(scrollContainer.childNodes);
2123 childNodes.forEach(function (childNode) {
2124 container.appendChild(childNode);
2125 });
2126 scrollContainer.appendChild(container);
2127 this._isCreateElement = true;
2128 } else {
2129 // Find Container by Selector
2130 container = scrollContainer.querySelector(containerOption);
2131 }
2132
2133 containerCSSText = container.style.cssText;
2134 var style = scrollContainer.style;
2135 _a = horizontal ? ["scroll", "hidden"] : ["hidden", "scroll"], style.overflowX = _a[0], style.overflowY = _a[1];
2136
2137 if (horizontal) {
2138 container.style.height = "100%";
2139 }
2140 }
2141
2142 var eventTarget = scrollContainer === document.body ? window : scrollContainer;
2143 eventTarget.addEventListener("scroll", this._onCheck);
2144 this._orgCSSText = containerCSSText;
2145 this.container = container;
2146 this.scrollContainer = scrollContainer;
2147 this.eventTarget = eventTarget;
2148 this.resize();
2149 this.setScrollPos(this.getOrgScrollPos());
2150 };
2151
2152 return ScrollManager;
2153}(Component);
2154
2155/**
2156 * A module used to arrange items including content infinitely according to layout type. With this module, you can implement various layouts composed of different items whose sizes vary. It guarantees performance by maintaining the number of DOMs the module is handling under any circumstance
2157 * @ko 콘텐츠가 있는 아이템을 레이아웃 타입에 따라 무한으로 배치하는 모듈. 다양한 크기의 아이템을 다양한 레이아웃으로 배치할 수 있다. 아이템의 개수가 계속 늘어나도 모듈이 처리하는 DOM의 개수를 일정하게 유지해 최적의 성능을 보장한다
2158 * @extends Component
2159 * @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
2160 * @example
2161```html
2162<ul id="grid">
2163 <li class="card">
2164 <div>test1</div>
2165 </li>
2166 <li class="card">
2167 <div>test2</div>
2168 </li>
2169 <li class="card">
2170 <div>test3</div>
2171 </li>
2172 <li class="card">
2173 <div>test4</div>
2174 </li>
2175 <li class="card">
2176 <div>test5</div>
2177 </li>
2178 <li class="card">
2179 <div>test6</div>
2180 </li>
2181</ul>
2182<script>
2183import { MasonryInfiniteGrid } from "@egjs/infinitegrid";
2184var some = new MasonryInfiniteGrid("#grid").on("renderComplete", function(e) {
2185 // ...
2186});
2187// If you already have items in the container, call "layout" method.
2188some.renderItems();
2189</script>
2190```
2191 */
2192
2193var InfiniteGrid =
2194/*#__PURE__*/
2195function (_super) {
2196 __extends(InfiniteGrid, _super);
2197 /**
2198 * @param - A base element for a module <ko>모듈을 적용할 기준 엘리먼트</ko>
2199 * @param - The option object of the InfiniteGrid module <ko>eg.InfiniteGrid 모듈의 옵션 객체</ko>
2200 */
2201
2202
2203 function InfiniteGrid(wrapper, options) {
2204 var _this = _super.call(this) || this;
2205
2206 _this._waitType = "";
2207
2208 _this._onScroll = function (_a) {
2209 var direction = _a.direction,
2210 scrollPos = _a.scrollPos,
2211 relativeScrollPos = _a.relativeScrollPos;
2212
2213 _this._scroll();
2214 /**
2215 * This event is fired when scrolling.
2216 * @ko 스크롤하면 발생하는 이벤트이다.
2217 * @event InfiniteGrid#changeScroll
2218 * @param {InfiniteGrid.OnChangeScroll} e - The object of data to be sent to an event <ko>이벤트에 전달되는 데이터 객체</ko>
2219 */
2220
2221
2222 _this.trigger(new Component.ComponentEvent(INFINITEGRID_EVENTS.CHANGE_SCROLL, {
2223 direction: direction,
2224 scrollPos: scrollPos,
2225 relativeScrollPos: relativeScrollPos
2226 }));
2227 };
2228
2229 _this._onChange = function (e) {
2230 _this.setCursors(e.nextStartCursor, e.nextEndCursor);
2231 };
2232
2233 _this._onRendererUpdated = function (e) {
2234 if (!e.isChanged) {
2235 _this._checkEndLoading();
2236
2237 _this._scroll();
2238
2239 return;
2240 }
2241
2242 var renderedItems = e.items;
2243 var _a = e.diffResult,
2244 added = _a.added,
2245 removed = _a.removed,
2246 prevList = _a.prevList,
2247 list = _a.list;
2248 removed.forEach(function (index) {
2249 var orgItem = prevList[index].orgItem;
2250
2251 if (orgItem.mountState !== Grid.MOUNT_STATE.UNCHECKED) {
2252 orgItem.mountState = Grid.MOUNT_STATE.UNMOUNTED;
2253 }
2254 });
2255 renderedItems.forEach(function (item) {
2256 // set grid element
2257 var gridItem = item.orgItem;
2258 gridItem.element = item.element;
2259 });
2260 var horizontal = _this.options.horizontal;
2261 var addedItems = added.map(function (index) {
2262 var gridItem = list[index].orgItem;
2263 var element = gridItem.element;
2264
2265 if (gridItem.type === ITEM_TYPE.VIRTUAL) {
2266 var cssRect = __assign({}, gridItem.cssRect);
2267
2268 var rect = gridItem.rect;
2269
2270 if (!cssRect.width && rect.width) {
2271 cssRect.width = rect.width;
2272 }
2273
2274 if (!cssRect.height && rect.height) {
2275 cssRect.height = rect.height;
2276 } // virtual item
2277
2278
2279 return new Grid.GridItem(horizontal, {
2280 element: element,
2281 cssRect: cssRect
2282 });
2283 }
2284
2285 return gridItem;
2286 });
2287 var _b = e.state,
2288 isRestore = _b.isRestore,
2289 isResize = _b.isResize;
2290
2291 _this.itemRenderer.renderItems(addedItems);
2292
2293 if (isRestore) {
2294 _this._onRenderComplete({
2295 mounted: added.map(function (index) {
2296 return list[index].orgItem;
2297 }),
2298 updated: [],
2299 isResize: false,
2300 direction: _this.defaultDirection
2301 });
2302
2303 if (isResize) {
2304 _this.groupManager.renderItems();
2305 }
2306 } else {
2307 _this.groupManager.renderItems();
2308 }
2309 };
2310
2311 _this._onResize = function () {
2312 _this.renderItems({
2313 useResize: true
2314 });
2315 };
2316
2317 _this._onRequestAppend = function (e) {
2318 /**
2319 * The event is fired when scrolling reaches the end or when data for a virtual group is required.
2320 * @ko 스크롤이 끝에 도달하거나 virtual 그룹에 대한 데이터가 필요한 경우 이벤트가 발생한다.
2321 * @event InfiniteGrid#requestAppend
2322 * @param {InfiniteGrid.OnRequestAppend} e - The object of data to be sent to an event <ko>이벤트에 전달되는 데이터 객체</ko>
2323 */
2324 _this._onRequestInsert(DIRECTION.END, INFINITEGRID_EVENTS.REQUEST_APPEND, e);
2325 };
2326
2327 _this._onRequestPrepend = function (e) {
2328 /**
2329 * The event is fired when scrolling reaches the start or when data for a virtual group is required.
2330 * @ko 스크롤이 끝에 도달하거나 virtual 그룹에 대한 데이터가 필요한 경우 이벤트가 발생한다.
2331 * @event InfiniteGrid#requestPrepend
2332 * @param {InfiniteGrid.OnRequestPrepend} e - The object of data to be sent to an event <ko>이벤트에 전달되는 데이터 객체</ko>
2333 */
2334 _this._onRequestInsert(DIRECTION.START, INFINITEGRID_EVENTS.REQUEST_PREPEND, e);
2335 };
2336
2337 _this._onContentError = function (_a) {
2338 var element = _a.element,
2339 target = _a.target,
2340 item = _a.item,
2341 update = _a.update;
2342 /**
2343 * The event is fired when scrolling reaches the start or when data for a virtual group is required.
2344 * @ko 스크롤이 끝에 도달하거나 virtual 그룹에 대한 데이터가 필요한 경우 이벤트가 발생한다.
2345 * @event InfiniteGrid#contentError
2346 * @param {InfiniteGrid.OnContentError} e - The object of data to be sent to an event <ko>이벤트에 전달되는 데이터 객체</ko>
2347 */
2348
2349 _this.trigger(new Component.ComponentEvent(INFINITEGRID_EVENTS.CONTENT_ERROR, {
2350 element: element,
2351 target: target,
2352 item: item,
2353 update: update,
2354 remove: function () {
2355 _this.removeByKey(item.key);
2356 }
2357 }));
2358 };
2359
2360 _this._onRenderComplete = function (_a) {
2361 var isResize = _a.isResize,
2362 mounted = _a.mounted,
2363 updated = _a.updated,
2364 direction = _a.direction;
2365 var infinite = _this.infinite;
2366 var prevRenderedGroups = infinite.getRenderedVisibleItems();
2367 var length = prevRenderedGroups.length;
2368 var isDirectionEnd = direction === DIRECTION.END;
2369
2370 _this._syncInfinite();
2371
2372 if (length) {
2373 var prevStandardGroup = prevRenderedGroups[isDirectionEnd ? 0 : length - 1];
2374 var nextStandardGroup = infinite.getItemByKey(prevStandardGroup.key);
2375 var offset = isDirectionEnd ? Math.min.apply(Math, nextStandardGroup.startOutline) - Math.min.apply(Math, prevStandardGroup.startOutline) : Math.max.apply(Math, nextStandardGroup.endOutline) - Math.max.apply(Math, prevStandardGroup.endOutline);
2376
2377 _this.scrollManager.scrollBy(offset);
2378 }
2379 /**
2380 * This event is fired when the InfiniteGrid has completed rendering.
2381 * @ko InfiniteGrid가 렌더링이 완료됐을 때 이벤트가 발생한다.
2382 * @event InfiniteGrid#renderComplete
2383 * @param {InfiniteGrid.OnRenderComplete} e - The object of data to be sent to an event <ko>이벤트에 전달되는 데이터 객체</ko>
2384 */
2385
2386
2387 _this.trigger(new Component.ComponentEvent(INFINITEGRID_EVENTS.RENDER_COMPLETE, {
2388 isResize: isResize,
2389 direction: direction,
2390 mounted: mounted.filter(function (item) {
2391 return item.type !== ITEM_TYPE.LOADING;
2392 }),
2393 updated: updated.filter(function (item) {
2394 return item.type !== ITEM_TYPE.LOADING;
2395 }),
2396 startCursor: _this.getStartCursor(),
2397 endCursor: _this.getEndCursor(),
2398 items: _this.getVisibleItems(true),
2399 groups: _this.getVisibleGroups(true)
2400 }));
2401
2402 if (_this.groupManager.shouldRerenderItems()) {
2403 _this._update();
2404 } else {
2405 _this._checkEndLoading();
2406
2407 _this._scroll();
2408 }
2409 };
2410
2411 _this.options = __assign(__assign(__assign({}, _this.constructor.defaultOptions), {
2412 renderer: new VanillaGridRenderer().on("requestUpdate", function () {
2413 return _this._render();
2414 })
2415 }), options);
2416
2417 var _a = _this.options,
2418 gridConstructor = _a.gridConstructor,
2419 containerTag = _a.containerTag,
2420 container = _a.container,
2421 renderer = _a.renderer,
2422 threshold = _a.threshold,
2423 useRecycle = _a.useRecycle,
2424 gridOptions = __rest(_a, ["gridConstructor", "containerTag", "container", "renderer", "threshold", "useRecycle"]); // options.container === false, wrapper = container, scrollContainer = document.body
2425 // options.container === true, wrapper = scrollContainer, container = wrapper's child
2426 // options.container === string,
2427
2428
2429 var horizontal = gridOptions.horizontal,
2430 attributePrefix = gridOptions.attributePrefix,
2431 useTransform = gridOptions.useTransform,
2432 percentage = gridOptions.percentage,
2433 isConstantSize = gridOptions.isConstantSize,
2434 isEqualSize = gridOptions.isEqualSize;
2435 var wrapperElement = isString(wrapper) ? document.querySelector(wrapper) : wrapper;
2436 var scrollManager = new ScrollManager(wrapperElement, {
2437 container: container,
2438 containerTag: containerTag,
2439 horizontal: horizontal
2440 }).on({
2441 scroll: _this._onScroll
2442 });
2443 var containerElement = scrollManager.getContainer();
2444 var containerManager = new Grid.ContainerManager(containerElement, {
2445 horizontal: horizontal
2446 }).on("resize", _this._onResize);
2447 var itemRenderer = new Grid.ItemRenderer({
2448 attributePrefix: attributePrefix,
2449 horizontal: horizontal,
2450 useTransform: useTransform,
2451 percentage: percentage,
2452 isEqualSize: isEqualSize,
2453 isConstantSize: isConstantSize
2454 });
2455 var infinite = new Infinite({
2456 useRecycle: useRecycle,
2457 threshold: threshold
2458 }).on({
2459 "change": _this._onChange,
2460 "requestAppend": _this._onRequestAppend,
2461 "requestPrepend": _this._onRequestPrepend
2462 });
2463 infinite.setSize(scrollManager.getContentSize());
2464 var groupManager = new GroupManager(containerElement, {
2465 gridConstructor: gridConstructor,
2466 externalItemRenderer: itemRenderer,
2467 externalContainerManager: containerManager,
2468 gridOptions: gridOptions
2469 });
2470 groupManager.on({
2471 "renderComplete": _this._onRenderComplete,
2472 "contentError": _this._onContentError
2473 });
2474 renderer.setContainer(containerElement);
2475 renderer.on("updated", _this._onRendererUpdated);
2476 _this.itemRenderer = itemRenderer;
2477 _this.groupManager = groupManager;
2478 _this.wrapperElement = wrapperElement;
2479 _this.scrollManager = scrollManager;
2480 _this.containerManager = containerManager;
2481 _this.infinite = infinite;
2482
2483 _this.containerManager.resize();
2484
2485 return _this;
2486 }
2487
2488 var __proto = InfiniteGrid.prototype;
2489 InfiniteGrid_1 = InfiniteGrid;
2490 /**
2491 * Rearrange items to fit the grid and render them. When rearrange is complete, the `renderComplete` event is fired.
2492 * @ko grid에 맞게 아이템을 재배치하고 렌더링을 한다. 배치가 완료되면 `renderComplete` 이벤트가 발생한다.
2493 * @param - Options for rendering. <ko>렌더링을 하기 위한 옵션.</ko>
2494 * @example
2495 * ```ts
2496 * import { MasonryInfiniteGrid } from "@egjs/infinitegrid";
2497 * const grid = new MasonryInfiniteGrid();
2498 *
2499 * grid.on("renderComplete", e => {
2500 * console.log(e);
2501 * });
2502 * grid.renderItems();
2503 * ```
2504 */
2505
2506 __proto.renderItems = function (options) {
2507 if (options === void 0) {
2508 options = {};
2509 }
2510
2511 if (options.useResize) {
2512 this.containerManager.resize();
2513 }
2514
2515 this._resizeScroll();
2516
2517 if (!this.getRenderingItems().length) {
2518 var children = toArray(this.getContainerElement().children);
2519
2520 if (children.length > 0) {
2521 this.append(children);
2522 } else {
2523 this.infinite.scroll(0);
2524 return this;
2525 }
2526 }
2527
2528 if (!this.getVisibleGroups(true).length) {
2529 this.setCursors(0, 0);
2530 } else {
2531 this.groupManager.renderItems(options);
2532 }
2533
2534 return this;
2535 };
2536 /**
2537 * Returns the wrapper element specified by the user.
2538 * @ko 컨테이너 엘리먼트를 반환한다.
2539 */
2540
2541
2542 __proto.getWrapperElement = function () {
2543 return this.scrollManager.getWrapper();
2544 };
2545 /**
2546 * Returns the container element corresponding to the scroll area.
2547 * @ko 스크롤 영역에 해당하는 컨테이너 엘리먼트를 반환한다.
2548 */
2549
2550
2551 __proto.getScrollContainerElement = function () {
2552 return this.scrollManager.getScrollContainer();
2553 };
2554 /**
2555 * Returns the container element containing item elements.
2556 * @ko 아이템 엘리먼트들을 담긴 컨테이너 엘리먼트를 반환한다.
2557 */
2558
2559
2560 __proto.getContainerElement = function () {
2561 return this.scrollManager.getContainer();
2562 };
2563 /**
2564 * When items change, it synchronizes and renders items.
2565 * @ko items가 바뀐 경우 동기화를 하고 렌더링을 한다.
2566 * @param - Options for rendering. <ko>렌더링을 하기 위한 옵션.</ko>
2567 */
2568
2569
2570 __proto.syncItems = function (items) {
2571 this.groupManager.syncItems(items);
2572
2573 this._syncGroups();
2574
2575 return this;
2576 };
2577 /**
2578 * Change the currently visible groups.
2579 * @ko 현재 보이는 그룹들을 바꾼다.
2580 * @param - first index of visible groups. <ko>보이는 그룹의 첫번째 index.</ko>
2581 * @param - last index of visible groups. <ko>보이는 그룹의 마지막 index.</ko>
2582 * @param - Whether the first rendering has already been done. <ko>첫 렌더링이 이미 되어있는지 여부.</ko>
2583 */
2584
2585
2586 __proto.setCursors = function (startCursor, endCursor, useFirstRender) {
2587 this.groupManager.setCursors(startCursor, endCursor);
2588 this.infinite.setCursors(startCursor, endCursor);
2589
2590 if (useFirstRender) {
2591 this._render();
2592 } else {
2593 this._update();
2594
2595 this._checkEndLoading();
2596 }
2597
2598 return this;
2599 };
2600 /**
2601 * Returns the first index of visible groups.
2602 * @ko 보이는 그룹들의 첫번째 index를 반환한다.
2603 */
2604
2605
2606 __proto.getStartCursor = function () {
2607 return this.infinite.getStartCursor();
2608 };
2609 /**
2610 * Returns the last index of visible groups.
2611 * @ko 보이는 그룹들의 마지막 index를 반환한다.
2612 */
2613
2614
2615 __proto.getEndCursor = function () {
2616 return this.infinite.getEndCursor();
2617 };
2618 /**
2619 * Add items at the bottom(right) of the grid.
2620 * @ko 아이템들을 grid 아래(오른쪽)에 추가한다.
2621 * @param - items to be added <ko>추가할 아이템들</ko>
2622 * @param - The group key to be configured in items. It is automatically generated by default. <ko>추가할 아이템에 설정할 그룹 키. 생략하면 값이 자동으로 생성된다.</ko>
2623 * @return - An instance of a module itself<ko>모듈 자신의 인스턴스</ko>
2624 * @example
2625 * ```js
2626 * ig.append(`<div class="item">test1</div><div class="item">test2</div>`);
2627 * ig.append([`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
2628 * ig.append([HTMLElement1, HTMLElement2]);
2629 * ```
2630 */
2631
2632
2633 __proto.append = function (items, groupKey) {
2634 return this.insert(-1, items, groupKey);
2635 };
2636 /**
2637 * Add items at the top(left) of the grid.
2638 * @ko 아이템들을 grid 위(왼쪽)에 추가한다.
2639 * @param - items to be added <ko>추가할 아이템들</ko>
2640 * @param - The group key to be configured in items. It is automatically generated by default. <ko>추가할 아이템에 설정할 그룹 키. 생략하면 값이 자동으로 생성된다.</ko>
2641 * @return - An instance of a module itself<ko>모듈 자신의 인스턴스</ko>
2642 * @example
2643 * ```ts
2644 * ig.prepend(`<div class="item">test1</div><div class="item">test2</div>`);
2645 * ig.prepend([`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
2646 * ig.prepend([HTMLElement1, HTMLElement2]);
2647 * ```
2648 */
2649
2650
2651 __proto.prepend = function (items, groupKey) {
2652 return this.insert(0, items, groupKey);
2653 };
2654 /**
2655 * Add items to a specific index.
2656 * @ko 아이템들을 특정 index에 추가한다.
2657 * @param - index to add <ko>추가하기 위한 index</ko>
2658 * @param - items to be added <ko>추가할 아이템들</ko>
2659 * @param - The group key to be configured in items. It is automatically generated by default. <ko>추가할 아이템에 설정할 그룹 키. 생략하면 값이 자동으로 생성된다.</ko>
2660 * @return - An instance of a module itself<ko>모듈 자신의 인스턴스</ko>
2661 * @example
2662 * ```ts
2663 * ig.insert(2, `<div class="item">test1</div><div class="item">test2</div>`);
2664 * ig.insert(3, [`<div class="item">test1</div>`, `<div class="item">test2</div>`]);
2665 * ig.insert(4, [HTMLElement1, HTMLElement2]);
2666 * ```
2667 */
2668
2669
2670 __proto.insert = function (index, items, groupKey) {
2671 var nextItemInfos = this.groupManager.getGroupItems();
2672 var itemInfos = convertInsertedItems(items, groupKey);
2673
2674 if (index === -1) {
2675 nextItemInfos.push.apply(nextItemInfos, itemInfos);
2676 } else {
2677 nextItemInfos.splice.apply(nextItemInfos, __spreadArrays([index, 0], itemInfos));
2678 }
2679
2680 return this.syncItems(nextItemInfos);
2681 };
2682 /**
2683 * Returns the current state of a module such as location information. You can use the setStatus() method to restore the information returned through a call to this method.
2684 * @ko 아이템의 위치 정보 등 모듈의 현재 상태 정보를 반환한다. 이 메서드가 반환한 정보를 저장해 두었다가 setStatus() 메서드로 복원할 수 있다
2685 * @param - STATUS_TYPE.NOT_REMOVE = Get all information about items. STATUS_TYPE.REMOVE_INVISIBLE_ITEMS = Get information on visible items only. STATUS_TYPE.MINIMIZE_INVISIBLE_ITEMS = Compress invisible items. You can replace it with a placeholder. STATUS_TYPE.MINIMIZE_INVISIBLE_GROUPS = Compress invisible groups. <ko> STATUS_TYPE.NOT_REMOVE = 모든 아이템들의 정보를 가져온다. STATUS_TYPE.REMOVE_INVISIBLE_ITEMS = 보이는 아이템들의 정보만 가져온다. STATUS_TYPE.MINIMIZE_INVISIBLE_ITEMS = 안보이는 아이템들을 압축한다. placeholder로 대체가 가능하다. STATUS_TYPE.MINIMIZE_INVISIBLE_GROUPS = 안보이는 그룹을 압축한다.</ko>
2686 */
2687
2688
2689 __proto.getStatus = function (type) {
2690 return {
2691 containerManager: this.containerManager.getStatus(),
2692 itemRenderer: this.itemRenderer.getStatus(),
2693 groupManager: this.groupManager.getGroupStatus(type),
2694 scrollManager: this.scrollManager.getStatus()
2695 };
2696 };
2697 /**
2698 * You can set placeholders to restore status or wait for items to be added.
2699 * @ko status 복구 또는 아이템 추가 대기를 위한 placeholder를 설정할 수 있다.
2700 * @param - The placeholder status. <ko>placeholder의 status</ko>
2701 */
2702
2703
2704 __proto.setPlaceholder = function (info) {
2705 this.groupManager.setPlaceholder(info);
2706 return this;
2707 };
2708 /**
2709 * You can set placeholders to restore status or wait for items to be added.
2710 * @ko status 복구 또는 아이템 추가 대기를 위한 placeholder를 설정할 수 있다.
2711 * @param - The placeholder status. <ko>placeholder의 status</ko>
2712 */
2713
2714
2715 __proto.setLoading = function (info) {
2716 this.groupManager.setLoading(info);
2717 return this;
2718 };
2719 /**
2720 * Add the placeholder at the end.
2721 * @ko placeholder들을 마지막에 추가한다.
2722 * @param - Items that correspond to placeholders. If it is a number, it duplicates the number of copies. <ko>placeholder에 해당하는 아이템들. 숫자면 갯수만큼 복제를 한다.</ko>
2723 * @param - The group key to be configured in items. It is automatically generated by default. <ko>추가할 아이템에 설정할 그룹 키. 생략하면 값이 자동으로 생성된다.</ko>
2724 */
2725
2726
2727 __proto.appendPlaceholders = function (items, groupKey) {
2728 var _this = this;
2729
2730 var result = this.groupManager.appendPlaceholders(items, groupKey);
2731
2732 this._syncGroups(true);
2733
2734 return __assign(__assign({}, result), {
2735 remove: function () {
2736 _this.removePlaceholders({
2737 groupKey: result.group.groupKey
2738 });
2739 }
2740 });
2741 };
2742 /**
2743 * Add the placeholder at the start.
2744 * @ko placeholder들을 처음에 추가한다.
2745 * @param - Items that correspond to placeholders. If it is a number, it duplicates the number of copies. <ko>placeholder에 해당하는 아이템들. 숫자면 갯수만큼 복제를 한다.</ko>
2746 * @param - The group key to be configured in items. It is automatically generated by default. <ko>추가할 아이템에 설정할 그룹 키. 생략하면 값이 자동으로 생성된다.</ko>
2747 */
2748
2749
2750 __proto.prependPlaceholders = function (items, groupKey) {
2751 var _this = this;
2752
2753 var result = this.groupManager.prependPlaceholders(items, groupKey);
2754
2755 this._syncGroups(true);
2756
2757 return __assign(__assign({}, result), {
2758 remove: function () {
2759 _this.removePlaceholders({
2760 groupKey: result.group.groupKey
2761 });
2762 }
2763 });
2764 };
2765 /**
2766 * Remove placeholders
2767 * @ko placeholder들을 삭제한다.
2768 * @param type - Remove the placeholders corresponding to the groupkey. When "start" or "end", remove all placeholders in that direction. <ko>groupkey에 해당하는 placeholder들을 삭제한다. "start" 또는 "end" 일 때 해당 방향의 모든 placeholder들을 삭제한다.</ko>
2769 */
2770
2771
2772 __proto.removePlaceholders = function (type) {
2773 this.groupManager.removePlaceholders(type);
2774
2775 this._syncGroups(true);
2776 };
2777 /**
2778 * Sets the status of the InfiniteGrid module with the information returned through a call to the getStatus() method.
2779 * @ko getStatus() 메서드가 저장한 정보로 InfiniteGrid 모듈의 상태를 설정한다.
2780 * @param - status object of the InfiniteGrid module. <ko>InfiniteGrid 모듈의 status 객체.</ko>
2781 * @param - Whether the first rendering has already been done. <ko>첫 렌더링이 이미 되어있는지 여부.</ko>
2782 */
2783
2784
2785 __proto.setStatus = function (status, useFirstRender) {
2786 this.itemRenderer.setStatus(status.itemRenderer);
2787 this.containerManager.setStatus(status.containerManager);
2788 this.scrollManager.setStatus(status.scrollManager);
2789 var groupManager = this.groupManager;
2790 var prevInlineSize = this.containerManager.getInlineSize();
2791 groupManager.setGroupStatus(status.groupManager);
2792
2793 this._syncInfinite();
2794
2795 this.infinite.setCursors(groupManager.getStartCursor(), groupManager.getEndCursor());
2796
2797 this._getRenderer().updateKey();
2798
2799 var state = {
2800 isReisze: this.containerManager.getInlineSize() !== prevInlineSize,
2801 isRestore: true
2802 };
2803
2804 if (useFirstRender) {
2805 this._render(state);
2806 } else {
2807 this._update(state);
2808 }
2809
2810 return this;
2811 };
2812 /**
2813 * Removes the group corresponding to index.
2814 * @ko index에 해당하는 그룹을 제거 한다.
2815 */
2816
2817
2818 __proto.removeGroupByIndex = function (index) {
2819 var nextGroups = this.groupManager.getGroups();
2820 return this.removeGroupByKey(nextGroups[index].groupKey);
2821 };
2822 /**
2823 * Removes the group corresponding to key.
2824 * @ko key에 해당하는 그룹을 제거 한다.
2825 */
2826
2827
2828 __proto.removeGroupByKey = function (key) {
2829 var nextItemInfos = this.groupManager.getItems();
2830 var firstIndex = findIndex(nextItemInfos, function (item) {
2831 return item.groupKey === key;
2832 });
2833 var lastIndex = findLastIndex(nextItemInfos, function (item) {
2834 return item.groupKey === key;
2835 });
2836
2837 if (firstIndex === -1) {
2838 return this;
2839 }
2840
2841 nextItemInfos.splice(firstIndex, lastIndex - firstIndex + 1);
2842 return this.syncItems(nextItemInfos);
2843 };
2844 /**
2845 * Removes the item corresponding to index.
2846 * @ko index에 해당하는 아이템을 제거 한다.
2847 */
2848
2849
2850 __proto.removeByIndex = function (index) {
2851 var nextItemInfos = this.getItems(true);
2852 nextItemInfos.splice(index, 1);
2853 return this.syncItems(nextItemInfos);
2854 };
2855 /**
2856 * Removes the item corresponding to key.
2857 * @ko key에 해당하는 아이템을 제거 한다.
2858 */
2859
2860
2861 __proto.removeByKey = function (key) {
2862 var nextItemInfos = this.getItems(true);
2863 var index = findIndex(nextItemInfos, function (item) {
2864 return item.key === key;
2865 });
2866 return this.removeByIndex(index);
2867 };
2868 /**
2869 * Update the size of the items and render them.
2870 * @ko 아이템들의 사이즈를 업데이트하고 렌더링을 한다.
2871 * @param - Items to be updated. <ko>업데이트할 아이템들.</ko>
2872 * @param - Options for rendering. <ko>렌더링을 하기 위한 옵션.</ko>
2873 */
2874
2875
2876 __proto.updateItems = function (items, options) {
2877 if (options === void 0) {
2878 options = {};
2879 }
2880
2881 this.groupManager.updateItems(items, options);
2882 return this;
2883 };
2884 /**
2885 * Return all items of InfiniteGrid.
2886 * @ko InfiniteGrid의 모든 아이템들을 반환한다.
2887 * @param - Whether to include items corresponding to placeholders. <ko>placeholder에 해당하는 아이템들을 포함할지 여부.</ko>
2888 */
2889
2890
2891 __proto.getItems = function (includePlaceholders) {
2892 return this.groupManager.getGroupItems(includePlaceholders);
2893 };
2894 /**
2895 * Return visible items of InfiniteGrid.
2896 * @ko InfiniteGrid의 보이는 아이템들을 반환한다.
2897 * @param - Whether to include items corresponding to placeholders. <ko>placeholder에 해당하는 아이템들을 포함할지 여부.</ko>
2898 */
2899
2900
2901 __proto.getVisibleItems = function (includePlaceholders) {
2902 return this.groupManager.getVisibleItems(includePlaceholders);
2903 };
2904 /**
2905 * Return rendering items of InfiniteGrid.
2906 * @ko InfiniteGrid의 렌더링 아이템들을 반환한다.
2907 */
2908
2909
2910 __proto.getRenderingItems = function () {
2911 return this.groupManager.getRenderingItems();
2912 };
2913 /**
2914 * Return all groups of InfiniteGrid.
2915 * @ko InfiniteGrid의 모든 그룹들을 반환한다.
2916 * @param - Whether to include groups corresponding to placeholders. <ko>placeholder에 해당하는 그룹들을 포함할지 여부.</ko>
2917 */
2918
2919
2920 __proto.getGroups = function (includePlaceholders) {
2921 return this.groupManager.getGroups(includePlaceholders);
2922 };
2923 /**
2924 * Return visible groups of InfiniteGrid.
2925 * @ko InfiniteGrid의 보이는 그룹들을 반환한다.
2926 * @param - Whether to include groups corresponding to placeholders. <ko>placeholder에 해당하는 그룹들을 포함할지 여부.</ko>
2927 */
2928
2929
2930 __proto.getVisibleGroups = function (includePlaceholders) {
2931 return this.groupManager.getVisibleGroups(includePlaceholders);
2932 };
2933 /**
2934 * Set to wait to request data.
2935 * @ko 데이터를 요청하기 위해 대기 상태로 설정한다.
2936 * @param direction - direction in which data will be added. <ko>데이터를 추가하기 위한 방향.</ko>
2937 */
2938
2939
2940 __proto.wait = function (direction) {
2941 if (direction === void 0) {
2942 direction = DIRECTION.END;
2943 }
2944
2945 this._waitType = direction;
2946
2947 this._checkStartLoading(direction);
2948 };
2949 /**
2950 * When the data request is complete, it is set to ready state.
2951 * @ko 데이터 요청이 끝났다면 준비 상태로 설정한다.
2952 */
2953
2954
2955 __proto.ready = function () {
2956 this._waitType = "";
2957 };
2958 /**
2959 * Returns whether it is set to wait to request data.
2960 * @ko 데이터를 요청하기 위해 대기 상태로 설정되어 있는지 여부를 반환한다.
2961 */
2962
2963
2964 __proto.isWait = function () {
2965 return !!this._waitType;
2966 };
2967 /**
2968 * Releases the instnace and events and returns the CSS of the container and elements.
2969 * @ko 인스턴스와 이벤트를 해제하고 컨테이너와 엘리먼트들의 CSS를 되돌린다.
2970 */
2971
2972
2973 __proto.destroy = function () {
2974 this.off();
2975 this.groupManager.destroy();
2976 this.scrollManager.destroy();
2977 this.infinite.destroy();
2978 };
2979
2980 __proto._getRenderer = function () {
2981 return this.options.renderer;
2982 };
2983
2984 __proto._render = function (state) {
2985 this._getRenderer().render(this.getRenderingItems().map(function (item) {
2986 return {
2987 element: item.element,
2988 key: item.type + "_" + item.key,
2989 orgItem: item
2990 };
2991 }), state);
2992 };
2993
2994 __proto._update = function (state) {
2995 if (state === void 0) {
2996 state = {};
2997 }
2998
2999 this._getRenderer().update(state);
3000 };
3001
3002 __proto._resizeScroll = function () {
3003 var scrollManager = this.scrollManager;
3004 scrollManager.resize();
3005 this.infinite.setSize(scrollManager.getContentSize());
3006 };
3007
3008 __proto._syncGroups = function (isUpdate) {
3009 var infinite = this.infinite;
3010
3011 this._syncInfinite();
3012
3013 this.groupManager.setCursors(infinite.getStartCursor(), infinite.getEndCursor());
3014
3015 if (isUpdate) {
3016 this._update();
3017 } else {
3018 this._render();
3019 }
3020 };
3021
3022 __proto._syncInfinite = function () {
3023 this.infinite.syncItems(this.getGroups(true).map(function (_a) {
3024 var groupKey = _a.groupKey,
3025 grid = _a.grid,
3026 type = _a.type;
3027 var outlines = grid.getOutlines();
3028 return {
3029 key: groupKey,
3030 isVirtual: type === GROUP_TYPE.VIRTUAL,
3031 startOutline: outlines.start,
3032 endOutline: outlines.end
3033 };
3034 }));
3035 };
3036
3037 __proto._scroll = function () {
3038 this.infinite.scroll(this.scrollManager.getRelativeScrollPos());
3039 };
3040
3041 __proto._onRequestInsert = function (direction, eventType, e) {
3042 var _this = this;
3043
3044 if (this._waitType) {
3045 this._checkStartLoading(this._waitType);
3046
3047 return;
3048 }
3049
3050 this.trigger(new Component.ComponentEvent(eventType, {
3051 groupKey: e.key,
3052 nextGroupKey: e.nextKey,
3053 isVirtual: e.isVirtual,
3054 wait: function () {
3055 _this.wait(direction);
3056 },
3057 ready: function () {
3058 _this.ready();
3059 }
3060 }));
3061 };
3062
3063 __proto._checkStartLoading = function (direction) {
3064 var groupManager = this.groupManager;
3065 var infinite = this.infinite;
3066
3067 if (!groupManager.getLoadingType() && infinite.isLoading(direction) && groupManager.startLoading(direction) && groupManager.hasLoadingItem()) {
3068 this._update();
3069 }
3070 };
3071
3072 __proto._checkEndLoading = function () {
3073 var groupManager = this.groupManager;
3074 var loadingType = this.groupManager.getLoadingType();
3075
3076 if (loadingType && (!this._waitType || !this.infinite.isLoading(loadingType)) && groupManager.endLoading() && groupManager.hasLoadingItem()) {
3077 this._update();
3078 }
3079 };
3080
3081 var InfiniteGrid_1;
3082 InfiniteGrid.defaultOptions = __assign(__assign({}, Grid.DEFAULT_GRID_OPTIONS), {
3083 container: false,
3084 containerTag: "div",
3085 renderer: null,
3086 threshold: 100,
3087 useRecycle: true
3088 });
3089 InfiniteGrid.propertyTypes = INFINITEGRID_PROPERTY_TYPES;
3090 InfiniteGrid = InfiniteGrid_1 = __decorate([InfiniteGridGetterSetter], InfiniteGrid);
3091 return InfiniteGrid;
3092}(Component);
3093
3094/**
3095 * MasonryInfiniteGrid is a grid that stacks items with the same width as a stack of bricks. Adjust the width of all images to the same size, find the lowest height column, and insert a new item.
3096 * @ko MasonryInfiniteGrid는 벽돌을 쌓아 올린 모양처럼 동일한 너비를 가진 아이템을 쌓는 레이아웃이다. 모든 이미지의 너비를 동일한 크기로 조정하고, 가장 높이가 낮은 열을 찾아 새로운 이미지를 삽입한다. 따라서 배치된 아이템 사이에 빈 공간이 생기지는 않지만 배치된 레이아웃의 아래쪽은 울퉁불퉁해진다.
3097 * @param {HTMLElement | string} container - A base element for a module <ko>모듈을 적용할 기준 엘리먼트</ko>
3098 * @param {MasonryInfiniteGridOptions} options - The option object of the MasonryInfiniteGrid module <ko>MasonryInfiniteGrid 모듈의 옵션 객체</ko>
3099 */
3100
3101var MasonryInfiniteGrid =
3102/*#__PURE__*/
3103function (_super) {
3104 __extends(MasonryInfiniteGrid, _super);
3105
3106 function MasonryInfiniteGrid() {
3107 return _super !== null && _super.apply(this, arguments) || this;
3108 }
3109
3110 MasonryInfiniteGrid.propertyTypes = __assign(__assign({}, InfiniteGrid.propertyTypes), Grid.MasonryGrid.propertyTypes);
3111 MasonryInfiniteGrid.defaultOptions = __assign(__assign(__assign({}, InfiniteGrid.defaultOptions), Grid.MasonryGrid.defaultOptions), {
3112 gridConstructor: Grid.MasonryGrid
3113 });
3114 MasonryInfiniteGrid = __decorate([InfiniteGridGetterSetter], MasonryInfiniteGrid);
3115 return MasonryInfiniteGrid;
3116}(InfiniteGrid);
3117
3118/**
3119 * 'justified' is a printing term with the meaning that 'it fits in one row wide'. JustifiedInfiniteGrid is a grid that the item is filled up on the basis of a line given a size.
3120 * If 'data-grid-inline-offset' or 'data-grid-content-offset' are set for item element, the ratio is maintained except for the offset value.
3121 * If 'data-grid-maintained-target' is set for an element whose ratio is to be maintained, the item is rendered while maintaining the ratio of the element.
3122 * @ko 'justified'는 '1행의 너비에 맞게 꼭 들어찬'이라는 의미를 가진 인쇄 용어다. JustifiedInfiniteGrid는 용어의 의미대로 너비가 주어진 사이즈를 기준으로 아이템가 가득 차도록 배치하는 Grid다.
3123 * 아이템 엘리먼트에 'data-grid-inline-offset' 또는 'data-grid-content-offset'를 설정하면 offset 값을 제외하고 비율을 유지한다.
3124 * 비율을 유지하고 싶은 엘리먼트에 'data-grid-maintained-target'을 설정한다면 해당 엘리먼트의 비율을 유지하면서 아이템이 렌더링이 된다.
3125 * @param {HTMLElement | string} container - A base element for a module <ko>모듈을 적용할 기준 엘리먼트</ko>
3126 * @param {JustifiedInfiniteGridOptions} options - The option object of the JustifiedInfiniteGrid module <ko>JustifiedInfiniteGrid 모듈의 옵션 객체</ko>
3127 */
3128
3129var JustifiedInfiniteGrid =
3130/*#__PURE__*/
3131function (_super) {
3132 __extends(JustifiedInfiniteGrid, _super);
3133
3134 function JustifiedInfiniteGrid() {
3135 return _super !== null && _super.apply(this, arguments) || this;
3136 }
3137
3138 JustifiedInfiniteGrid.propertyTypes = __assign(__assign({}, InfiniteGrid.propertyTypes), Grid.JustifiedGrid.propertyTypes);
3139 JustifiedInfiniteGrid.defaultOptions = __assign(__assign(__assign({}, InfiniteGrid.defaultOptions), Grid.JustifiedGrid.defaultOptions), {
3140 gridConstructor: Grid.JustifiedGrid
3141 });
3142 JustifiedInfiniteGrid = __decorate([InfiniteGridGetterSetter], JustifiedInfiniteGrid);
3143 return JustifiedInfiniteGrid;
3144}(InfiniteGrid);
3145
3146/**
3147 * 'Frame' is a printing term with the meaning that 'it fits in one row wide'. FrameInfiniteGrid is a grid that the item is filled up on the basis of a line given a size.
3148 * @ko 'Frame'는 '1행의 너비에 맞게 꼭 들어찬'이라는 의미를 가진 인쇄 용어다. FrameInfiniteGrid는 용어의 의미대로 너비가 주어진 사이즈를 기준으로 아이템이 가득 차도록 배치하는 Grid다.
3149 * @param {HTMLElement | string} container - A base element for a module <ko>모듈을 적용할 기준 엘리먼트</ko>
3150 * @param {FrameInfiniteGridOptions} options - The option object of the FrameInfiniteGrid module <ko>FrameGrid 모듈의 옵션 객체</ko>
3151 */
3152
3153var FrameInfiniteGrid =
3154/*#__PURE__*/
3155function (_super) {
3156 __extends(FrameInfiniteGrid, _super);
3157
3158 function FrameInfiniteGrid() {
3159 return _super !== null && _super.apply(this, arguments) || this;
3160 }
3161
3162 FrameInfiniteGrid.propertyTypes = __assign(__assign({}, InfiniteGrid.propertyTypes), Grid.FrameGrid.propertyTypes);
3163 FrameInfiniteGrid.defaultOptions = __assign(__assign(__assign({}, InfiniteGrid.defaultOptions), Grid.FrameGrid.defaultOptions), {
3164 gridConstructor: Grid.FrameGrid
3165 });
3166 FrameInfiniteGrid = __decorate([InfiniteGridGetterSetter], FrameInfiniteGrid);
3167 return FrameInfiniteGrid;
3168}(InfiniteGrid);
3169
3170/**
3171 * The PackingInfiniteGrid is a grid that shows the important items bigger without sacrificing the weight of the items.
3172 * Rows and columns are separated so that items are dynamically placed within the horizontal and vertical space rather than arranged in an orderly fashion.
3173 * If `sizeWeight` is higher than `ratioWeight`, the size of items is preserved as much as possible.
3174 * Conversely, if `ratioWeight` is higher than `sizeWeight`, the ratio of items is preserved as much as possible.
3175 * @ko PackingInfiniteGrid는 아이템의 본래 크기에 따른 비중을 해치지 않으면서 중요한 카드는 더 크게 보여 주는 레이아웃이다.
3176 * 행과 열이 구분돼 아이템을 정돈되게 배치하는 대신 가로세로 일정 공간 내에서 동적으로 아이템을 배치한다.
3177 * `sizeWeight`가 `ratioWeight`보다 높으면 아이템들의 size가 최대한 보존이 된다.
3178 * 반대로 `ratioWeight`가 `sizeWeight`보다 높으면 아이템들의 비율이 최대한 보존이 된다.
3179 * @param {HTMLElement | string} container - A base element for a module <ko>모듈을 적용할 기준 엘리먼트</ko>
3180 * @param {PackingInfiniteGridOptions} options - The option object of the PackingInfiniteGrid module <ko>PackingInfiniteGrid 모듈의 옵션 객체</ko>
3181 */
3182
3183var PackingInfiniteGrid =
3184/*#__PURE__*/
3185function (_super) {
3186 __extends(PackingInfiniteGrid, _super);
3187
3188 function PackingInfiniteGrid() {
3189 return _super !== null && _super.apply(this, arguments) || this;
3190 }
3191
3192 PackingInfiniteGrid.propertyTypes = __assign(__assign({}, InfiniteGrid.propertyTypes), Grid.PackingGrid.propertyTypes);
3193 PackingInfiniteGrid.defaultOptions = __assign(__assign(__assign({}, InfiniteGrid.defaultOptions), Grid.PackingGrid.defaultOptions), {
3194 gridConstructor: Grid.PackingGrid
3195 });
3196 PackingInfiniteGrid = __decorate([InfiniteGridGetterSetter], PackingInfiniteGrid);
3197 return PackingInfiniteGrid;
3198}(InfiniteGrid);
3199
3200
3201
3202var modules = {
3203 __proto__: null,
3204 'default': InfiniteGrid,
3205 withInfiniteGridMethods: withInfiniteGridMethods,
3206 getRenderingItems: getRenderingItems,
3207 mountRenderingItems: mountRenderingItems,
3208 InfiniteGridItem: InfiniteGridItem,
3209 MasonryInfiniteGrid: MasonryInfiniteGrid,
3210 JustifiedInfiniteGrid: JustifiedInfiniteGrid,
3211 FrameInfiniteGrid: FrameInfiniteGrid,
3212 PackingInfiniteGrid: PackingInfiniteGrid,
3213 Renderer: Renderer,
3214 IS_IOS: IS_IOS,
3215 CONTAINER_CLASS_NAME: CONTAINER_CLASS_NAME,
3216 IGNORE_PROPERITES_MAP: IGNORE_PROPERITES_MAP,
3217 INFINITEGRID_PROPERTY_TYPES: INFINITEGRID_PROPERTY_TYPES,
3218 DIRECTION: DIRECTION,
3219 INFINITEGRID_EVENTS: INFINITEGRID_EVENTS,
3220 ITEM_INFO_PROPERTIES: ITEM_INFO_PROPERTIES,
3221 INFINITEGRID_METHODS: INFINITEGRID_METHODS,
3222 get GROUP_TYPE () { return GROUP_TYPE; },
3223 get ITEM_TYPE () { return ITEM_TYPE; },
3224 get STATUS_TYPE () { return STATUS_TYPE; },
3225 INVISIBLE_POS: INVISIBLE_POS
3226};
3227
3228for (var name in modules) {
3229 InfiniteGrid[name] = modules[name];
3230}
3231
3232module.exports = InfiniteGrid;
3233//# sourceMappingURL=infinitegrid.cjs.js.map