UNPKG

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