@egjs/svelte-infinitegrid 3.2.5 → 4.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.storybook/main.js +32 -0
  2. package/.storybook/manager.js +5 -0
  3. package/.storybook/preview.js +25 -0
  4. package/README.md +79 -155
  5. package/dist/infinitegrid.cjs.js +203 -533
  6. package/dist/infinitegrid.cjs.js.map +1 -1
  7. package/dist/infinitegrid.esm.js +198 -522
  8. package/dist/infinitegrid.esm.js.map +1 -1
  9. package/global.d.ts +8 -0
  10. package/package.json +41 -50
  11. package/public/global.css +6 -5
  12. package/public/index.html +3 -3
  13. package/rollup.config.js +7 -6
  14. package/src/InfiniteGrid.js +23 -16
  15. package/src/InfiniteGrid.svelte +91 -138
  16. package/src/consts.js +8 -13
  17. package/src/grids/FrameInfiniteGrid.js +17 -0
  18. package/src/grids/JustifiedInfiniteGrid.js +17 -0
  19. package/src/grids/MasonryInfiniteGrid.js +17 -0
  20. package/src/grids/PackingInfiniteGrid.js +17 -0
  21. package/src/index.d.ts +14 -27
  22. package/src/index.js +5 -13
  23. package/src/index.umd.js +2 -6
  24. package/src/{demo/main.js → main.ts} +1 -1
  25. package/stories/1-MasonryInfiniteGrid/0-MasonryInfiniteGrid.stories.ts +4 -0
  26. package/stories/1-MasonryInfiniteGrid/1-MasonryInfiniteGrid.stories.ts +27 -0
  27. package/stories/1-MasonryInfiniteGrid/apps/SvelteMasonryInfiniteGridApp.svelte +42 -0
  28. package/stories/2-JustifiedInfiniteGrid/0-JustifiedInfiniteGrid.stories.ts +5 -0
  29. package/stories/2-JustifiedInfiniteGrid/1-JustifiedInfiniteGrid.stories.ts +10 -0
  30. package/stories/2-JustifiedInfiniteGrid/apps/SvelteJustifiedInfiniteGridApp.svelte +43 -0
  31. package/stories/3-FrameInfiniteGrid/0-FrameInfiniteGrid.stories.ts +5 -0
  32. package/stories/3-FrameInfiniteGrid/1-FrameInfiniteGrid.stories.ts +10 -0
  33. package/stories/3-FrameInfiniteGrid/apps/SvelteFrameInfiniteGridApp.svelte +44 -0
  34. package/stories/4-PackingInfiniteGrid/0-PackingInfiniteGrid.stories.ts +5 -0
  35. package/stories/4-PackingInfiniteGrid/1-PackingInfiniteGrid.stories.ts +10 -0
  36. package/stories/4-PackingInfiniteGrid/apps/SveltePackingInfiniteGridApp.svelte +40 -0
  37. package/stories/5-DataLoading/0-DataLoading.stories.ts +7 -0
  38. package/stories/5-DataLoading/1-WaitNReady.stories.ts +10 -0
  39. package/stories/5-DataLoading/2-Placeholder.stories.ts +10 -0
  40. package/stories/5-DataLoading/3-Loading.stories.ts +10 -0
  41. package/stories/5-DataLoading/apps/SvelteLoadingApp.svelte +54 -0
  42. package/stories/5-DataLoading/apps/SveltePlaceholderApp.svelte +54 -0
  43. package/stories/5-DataLoading/apps/SvelteWaitNReadyApp.svelte +47 -0
  44. package/tsconfig.json +4 -61
  45. package/.editorconfig +0 -3
  46. package/LICENSE +0 -19
  47. package/babel.config.js +0 -10
  48. package/jest.config.js +0 -14
  49. package/rollup_start_dev.js +0 -12
  50. package/src/LoadingChecker.svelte +0 -9
  51. package/src/demo/App.svelte +0 -86
  52. package/src/demo/useFirstRender.svelte +0 -67
  53. package/src/layouts/FrameLayout.js +0 -9
  54. package/src/layouts/GridLayout.js +0 -9
  55. package/src/layouts/JustifiedLayout.js +0 -9
  56. package/src/layouts/PackingLayout.js +0 -9
  57. package/src/layouts/SquareLayout.js +0 -9
  58. package/svelte.config.js +0 -5
  59. package/test/unit/demo.spec.ts +0 -23
@@ -1,62 +1,23 @@
1
1
  /*
2
- Copyright (c) 2019-present NAVER Corp.
2
+ Copyright (c) NAVER Corp.
3
3
  name: @egjs/svelte-infinitegrid
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-infinitegrid
7
- version: 3.2.5
7
+ version: 4.0.1-beta.0
8
8
  */
9
9
  'use strict';
10
10
 
11
11
  var internal = require('svelte/internal');
12
12
  var svelte = require('svelte');
13
- var VanillaInfiniteGrid = require('@egjs/infinitegrid');
13
+ var infinitegrid = require('@egjs/infinitegrid');
14
14
 
15
- /* src/LoadingChecker.svelte generated by Svelte v3.31.0 */
15
+ const SVELTE_INFINITEGRID_PROPS = ["status", "useFirstRender", "useLoading", "usePlaceholder", "items", "itemBy", "groupBy"];
16
16
 
17
- function instance($$self, $$props, $$invalidate) {
18
- let {
19
- hasLoading = true
20
- } = $$props;
21
- svelte.onMount(() => {
22
- $$invalidate(0, hasLoading = false);
23
- });
24
-
25
- $$self.$$set = $$props => {
26
- if ("hasLoading" in $$props) $$invalidate(0, hasLoading = $$props.hasLoading);
27
- };
28
-
29
- return [hasLoading];
30
- }
31
-
32
- class LoadingChecker extends internal.SvelteComponent {
33
- constructor(options) {
34
- super();
35
- internal.init(this, options, instance, null, internal.safe_not_equal, {
36
- hasLoading: 0
37
- });
38
- }
39
-
40
- }
41
-
42
- const PROP_NAMES = ["groupBy", "itemBy", "items", "useFirstRender", "loading", "status", "layoutType", "options", "layoutOptions", "_forceCount", "viewer", "container"];
43
-
44
- /* src/InfiniteGrid.svelte generated by Svelte v3.31.0 */
45
-
46
- const get_loading_slot_changes_1 = dirty => ({
47
- visibleItems: dirty[0] &
48
- /*visibleItems*/
49
- 8
50
- });
51
-
52
- const get_loading_slot_context_1 = ctx => ({
53
- visibleItems:
54
- /*visibleItems*/
55
- ctx[3]
56
- });
17
+ /* src/InfiniteGrid.svelte generated by Svelte v3.43.0 */
57
18
 
58
19
  const get_default_slot_changes_1 = dirty => ({
59
- visibleItems: dirty[0] &
20
+ visibleItems: dirty &
60
21
  /*visibleItems*/
61
22
  8
62
23
  });
@@ -67,20 +28,8 @@ const get_default_slot_context_1 = ctx => ({
67
28
  ctx[3]
68
29
  });
69
30
 
70
- const get_loading_slot_changes = dirty => ({
71
- visibleItems: dirty[0] &
72
- /*visibleItems*/
73
- 8
74
- });
75
-
76
- const get_loading_slot_context = ctx => ({
77
- visibleItems:
78
- /*visibleItems*/
79
- ctx[3]
80
- });
81
-
82
31
  const get_default_slot_changes = dirty => ({
83
- visibleItems: dirty[0] &
32
+ visibleItems: dirty &
84
33
  /*visibleItems*/
85
34
  8
86
35
  });
@@ -89,30 +38,20 @@ const get_default_slot_context = ctx => ({
89
38
  visibleItems:
90
39
  /*visibleItems*/
91
40
  ctx[3]
92
- }); // (147:2) {:else}
41
+ }); // (137:2) {:else}
93
42
 
94
43
 
95
44
  function create_else_block(ctx) {
96
- let t;
97
45
  let current;
98
46
  const default_slot_template =
99
47
  /*#slots*/
100
- ctx[17].default;
48
+ ctx[8].default;
101
49
  const default_slot = internal.create_slot(default_slot_template, ctx,
102
50
  /*$$scope*/
103
- ctx[16], get_default_slot_context_1);
104
- const loading_slot_template =
105
- /*#slots*/
106
- ctx[17].loading;
107
- const loading_slot = internal.create_slot(loading_slot_template, ctx,
108
- /*$$scope*/
109
- ctx[16], get_loading_slot_context_1);
110
- const loading_slot_or_fallback = loading_slot || fallback_block_1(ctx);
51
+ ctx[7], get_default_slot_context_1);
111
52
  return {
112
53
  c() {
113
54
  if (default_slot) default_slot.c();
114
- t = internal.space();
115
- if (loading_slot_or_fallback) loading_slot_or_fallback.c();
116
55
  },
117
56
 
118
57
  m(target, anchor) {
@@ -120,39 +59,21 @@ function create_else_block(ctx) {
120
59
  default_slot.m(target, anchor);
121
60
  }
122
61
 
123
- internal.insert(target, t, anchor);
124
-
125
- if (loading_slot_or_fallback) {
126
- loading_slot_or_fallback.m(target, anchor);
127
- }
128
-
129
62
  current = true;
130
63
  },
131
64
 
132
65
  p(ctx, dirty) {
133
66
  if (default_slot) {
134
- if (default_slot.p && dirty[0] &
67
+ if (default_slot.p && (!current || dirty &
135
68
  /*$$scope, visibleItems*/
136
- 65544) {
137
- internal.update_slot(default_slot, default_slot_template, ctx,
69
+ 136)) {
70
+ internal.update_slot_base(default_slot, default_slot_template, ctx,
138
71
  /*$$scope*/
139
- ctx[16], dirty, get_default_slot_changes_1, get_default_slot_context_1);
140
- }
141
- }
142
-
143
- if (loading_slot) {
144
- if (loading_slot.p && dirty[0] &
145
- /*$$scope, visibleItems*/
146
- 65544) {
147
- internal.update_slot(loading_slot, loading_slot_template, ctx,
72
+ ctx[7], !current ? internal.get_all_dirty_from_scope(
148
73
  /*$$scope*/
149
- ctx[16], dirty, get_loading_slot_changes_1, get_loading_slot_context_1);
150
- }
151
- } else {
152
- if (loading_slot_or_fallback && loading_slot_or_fallback.p && dirty[0] &
153
- /*hasLoadingElement*/
154
- 16) {
155
- loading_slot_or_fallback.p(ctx, dirty);
74
+ ctx[7]) : internal.get_slot_changes(default_slot_template,
75
+ /*$$scope*/
76
+ ctx[7], dirty, get_default_slot_changes_1), get_default_slot_context_1);
156
77
  }
157
78
  }
158
79
  },
@@ -160,50 +81,36 @@ function create_else_block(ctx) {
160
81
  i(local) {
161
82
  if (current) return;
162
83
  internal.transition_in(default_slot, local);
163
- internal.transition_in(loading_slot_or_fallback, local);
164
84
  current = true;
165
85
  },
166
86
 
167
87
  o(local) {
168
88
  internal.transition_out(default_slot, local);
169
- internal.transition_out(loading_slot_or_fallback, local);
170
89
  current = false;
171
90
  },
172
91
 
173
92
  d(detaching) {
174
93
  if (default_slot) default_slot.d(detaching);
175
- if (detaching) internal.detach(t);
176
- if (loading_slot_or_fallback) loading_slot_or_fallback.d(detaching);
177
94
  }
178
95
 
179
96
  };
180
- } // (140:2) {#if options.isOverflowScroll}
97
+ } // (133:2) {#if $$props.container === true}
181
98
 
182
99
 
183
100
  function create_if_block(ctx) {
184
101
  let div;
185
- let t;
186
102
  let current;
187
103
  const default_slot_template =
188
104
  /*#slots*/
189
- ctx[17].default;
105
+ ctx[8].default;
190
106
  const default_slot = internal.create_slot(default_slot_template, ctx,
191
107
  /*$$scope*/
192
- ctx[16], get_default_slot_context);
193
- const loading_slot_template =
194
- /*#slots*/
195
- ctx[17].loading;
196
- const loading_slot = internal.create_slot(loading_slot_template, ctx,
197
- /*$$scope*/
198
- ctx[16], get_loading_slot_context);
199
- const loading_slot_or_fallback = loading_slot || fallback_block(ctx);
108
+ ctx[7], get_default_slot_context);
200
109
  return {
201
110
  c() {
202
111
  div = internal.element("div");
203
112
  if (default_slot) default_slot.c();
204
- t = internal.space();
205
- if (loading_slot_or_fallback) loading_slot_or_fallback.c();
206
- internal.attr(div, "class", VanillaInfiniteGrid.CONTAINER_CLASSNAME);
113
+ internal.attr(div, "class", infinitegrid.CONTAINER_CLASS_NAME);
207
114
  },
208
115
 
209
116
  m(target, anchor) {
@@ -212,43 +119,25 @@ function create_if_block(ctx) {
212
119
  if (default_slot) {
213
120
  default_slot.m(div, null);
214
121
  }
215
-
216
- internal.append(div, t);
217
-
218
- if (loading_slot_or_fallback) {
219
- loading_slot_or_fallback.m(div, null);
220
- }
221
122
  /*div_binding*/
222
123
 
223
124
 
224
- ctx[19](div);
125
+ ctx[9](div);
225
126
  current = true;
226
127
  },
227
128
 
228
129
  p(ctx, dirty) {
229
130
  if (default_slot) {
230
- if (default_slot.p && dirty[0] &
131
+ if (default_slot.p && (!current || dirty &
231
132
  /*$$scope, visibleItems*/
232
- 65544) {
233
- internal.update_slot(default_slot, default_slot_template, ctx,
133
+ 136)) {
134
+ internal.update_slot_base(default_slot, default_slot_template, ctx,
234
135
  /*$$scope*/
235
- ctx[16], dirty, get_default_slot_changes, get_default_slot_context);
236
- }
237
- }
238
-
239
- if (loading_slot) {
240
- if (loading_slot.p && dirty[0] &
241
- /*$$scope, visibleItems*/
242
- 65544) {
243
- internal.update_slot(loading_slot, loading_slot_template, ctx,
136
+ ctx[7], !current ? internal.get_all_dirty_from_scope(
244
137
  /*$$scope*/
245
- ctx[16], dirty, get_loading_slot_changes, get_loading_slot_context);
246
- }
247
- } else {
248
- if (loading_slot_or_fallback && loading_slot_or_fallback.p && dirty[0] &
249
- /*hasLoadingElement*/
250
- 16) {
251
- loading_slot_or_fallback.p(ctx, dirty);
138
+ ctx[7]) : internal.get_slot_changes(default_slot_template,
139
+ /*$$scope*/
140
+ ctx[7], dirty, get_default_slot_changes), get_default_slot_context);
252
141
  }
253
142
  }
254
143
  },
@@ -256,161 +145,20 @@ function create_if_block(ctx) {
256
145
  i(local) {
257
146
  if (current) return;
258
147
  internal.transition_in(default_slot, local);
259
- internal.transition_in(loading_slot_or_fallback, local);
260
148
  current = true;
261
149
  },
262
150
 
263
151
  o(local) {
264
152
  internal.transition_out(default_slot, local);
265
- internal.transition_out(loading_slot_or_fallback, local);
266
153
  current = false;
267
154
  },
268
155
 
269
156
  d(detaching) {
270
157
  if (detaching) internal.detach(div);
271
158
  if (default_slot) default_slot.d(detaching);
272
- if (loading_slot_or_fallback) loading_slot_or_fallback.d(detaching);
273
159
  /*div_binding*/
274
160
 
275
- ctx[19](null);
276
- }
277
-
278
- };
279
- } // (149:25)
280
-
281
-
282
- function fallback_block_1(ctx) {
283
- let loadingchecker;
284
- let updating_hasLoading;
285
- let current;
286
-
287
- function loadingchecker_hasLoading_binding_1(value) {
288
- /*loadingchecker_hasLoading_binding_1*/
289
- ctx[20].call(null, value);
290
- }
291
-
292
- let loadingchecker_props = {};
293
-
294
- if (
295
- /*hasLoadingElement*/
296
- ctx[4] !== void 0) {
297
- loadingchecker_props.hasLoading =
298
- /*hasLoadingElement*/
299
- ctx[4];
300
- }
301
-
302
- loadingchecker = new LoadingChecker({
303
- props: loadingchecker_props
304
- });
305
- internal.binding_callbacks.push(() => internal.bind(loadingchecker, "hasLoading", loadingchecker_hasLoading_binding_1));
306
- return {
307
- c() {
308
- internal.create_component(loadingchecker.$$.fragment);
309
- },
310
-
311
- m(target, anchor) {
312
- internal.mount_component(loadingchecker, target, anchor);
313
- current = true;
314
- },
315
-
316
- p(ctx, dirty) {
317
- const loadingchecker_changes = {};
318
-
319
- if (!updating_hasLoading && dirty[0] &
320
- /*hasLoadingElement*/
321
- 16) {
322
- updating_hasLoading = true;
323
- loadingchecker_changes.hasLoading =
324
- /*hasLoadingElement*/
325
- ctx[4];
326
- internal.add_flush_callback(() => updating_hasLoading = false);
327
- }
328
-
329
- loadingchecker.$set(loadingchecker_changes);
330
- },
331
-
332
- i(local) {
333
- if (current) return;
334
- internal.transition_in(loadingchecker.$$.fragment, local);
335
- current = true;
336
- },
337
-
338
- o(local) {
339
- internal.transition_out(loadingchecker.$$.fragment, local);
340
- current = false;
341
- },
342
-
343
- d(detaching) {
344
- internal.destroy_component(loadingchecker, detaching);
345
- }
346
-
347
- };
348
- } // (143:27)
349
-
350
-
351
- function fallback_block(ctx) {
352
- let loadingchecker;
353
- let updating_hasLoading;
354
- let current;
355
-
356
- function loadingchecker_hasLoading_binding(value) {
357
- /*loadingchecker_hasLoading_binding*/
358
- ctx[18].call(null, value);
359
- }
360
-
361
- let loadingchecker_props = {};
362
-
363
- if (
364
- /*hasLoadingElement*/
365
- ctx[4] !== void 0) {
366
- loadingchecker_props.hasLoading =
367
- /*hasLoadingElement*/
368
- ctx[4];
369
- }
370
-
371
- loadingchecker = new LoadingChecker({
372
- props: loadingchecker_props
373
- });
374
- internal.binding_callbacks.push(() => internal.bind(loadingchecker, "hasLoading", loadingchecker_hasLoading_binding));
375
- return {
376
- c() {
377
- internal.create_component(loadingchecker.$$.fragment);
378
- },
379
-
380
- m(target, anchor) {
381
- internal.mount_component(loadingchecker, target, anchor);
382
- current = true;
383
- },
384
-
385
- p(ctx, dirty) {
386
- const loadingchecker_changes = {};
387
-
388
- if (!updating_hasLoading && dirty[0] &
389
- /*hasLoadingElement*/
390
- 16) {
391
- updating_hasLoading = true;
392
- loadingchecker_changes.hasLoading =
393
- /*hasLoadingElement*/
394
- ctx[4];
395
- internal.add_flush_callback(() => updating_hasLoading = false);
396
- }
397
-
398
- loadingchecker.$set(loadingchecker_changes);
399
- },
400
-
401
- i(local) {
402
- if (current) return;
403
- internal.transition_in(loadingchecker.$$.fragment, local);
404
- current = true;
405
- },
406
-
407
- o(local) {
408
- internal.transition_out(loadingchecker.$$.fragment, local);
409
- current = false;
410
- },
411
-
412
- d(detaching) {
413
- internal.destroy_component(loadingchecker, detaching);
161
+ ctx[9](null);
414
162
  }
415
163
 
416
164
  };
@@ -426,8 +174,8 @@ function create_fragment(ctx) {
426
174
 
427
175
  function select_block_type(ctx, dirty) {
428
176
  if (
429
- /*options*/
430
- ctx[0].isOverflowScroll) return 0;
177
+ /*$$props*/
178
+ ctx[4].container === true) return 0;
431
179
  return 1;
432
180
  }
433
181
 
@@ -435,7 +183,7 @@ function create_fragment(ctx) {
435
183
  if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
436
184
  let div_levels = [
437
185
  /*attributes*/
438
- ctx[5]];
186
+ ctx[2]];
439
187
  let div_data = {};
440
188
 
441
189
  for (let i = 0; i < div_levels.length; i += 1) {
@@ -454,11 +202,11 @@ function create_fragment(ctx) {
454
202
  if_blocks[current_block_type_index].m(div, null);
455
203
  /*div_binding_1*/
456
204
 
457
- ctx[21](div);
205
+ ctx[10](div);
458
206
  current = true;
459
207
  },
460
208
 
461
- p(ctx, dirty) {
209
+ p(ctx, [dirty]) {
462
210
  let previous_block_index = current_block_type_index;
463
211
  current_block_type_index = select_block_type(ctx);
464
212
 
@@ -483,11 +231,11 @@ function create_fragment(ctx) {
483
231
  if_block.m(div, null);
484
232
  }
485
233
 
486
- internal.set_attributes(div, div_data = internal.get_spread_update(div_levels, [dirty[0] &
234
+ internal.set_attributes(div, div_data = internal.get_spread_update(div_levels, [dirty &
487
235
  /*attributes*/
488
- 32 &&
236
+ 4 &&
489
237
  /*attributes*/
490
- ctx[5]]));
238
+ ctx[2]]));
491
239
  },
492
240
 
493
241
  i(local) {
@@ -506,342 +254,264 @@ function create_fragment(ctx) {
506
254
  if_blocks[current_block_type_index].d();
507
255
  /*div_binding_1*/
508
256
 
509
- ctx[21](null);
257
+ ctx[10](null);
510
258
  }
511
259
 
512
260
  };
513
261
  }
514
262
 
515
- function instance$1($$self, $$props, $$invalidate) {
263
+ function instance($$self, $$props, $$invalidate) {
516
264
  let {
517
265
  $$slots: slots = {},
518
266
  $$scope
519
267
  } = $$props;
520
268
  let {
521
- groupBy = (item, index) => item.groupKey
522
- } = $$props;
523
- let {
524
- itemBy = (item, index) => item.key
525
- } = $$props;
526
- let {
527
- items = []
528
- } = $$props;
529
- let {
530
- useFirstRender = false
531
- } = $$props;
532
- let {
533
- status = null
534
- } = $$props;
535
- let {
536
- layoutType = VanillaInfiniteGrid.GridLayout
537
- } = $$props;
538
- let {
539
- options = {}
540
- } = $$props;
541
- let {
542
- layoutOptions = {}
543
- } = $$props;
544
- let {
545
- _forceCount = 0
269
+ GridClass
546
270
  } = $$props;
547
271
  const dispatch = svelte.createEventDispatcher();
548
- let viewer;
272
+ const renderer = new infinitegrid.Renderer();
273
+ let wrapper;
549
274
  let container;
550
-
551
- let nextFunction = () => {};
552
-
553
- let layoutState;
554
- let visibleItems = [];
555
- let ig;
556
- let hasLoadingElement = true;
275
+ let grid;
557
276
  let attributes = {};
558
- let isFirstMount = true;
559
-
560
- function toItems(items) {
561
- return items.map((item, i) => ({
562
- groupKey: groupBy(item, i),
563
- itemKey: itemBy(item, i),
564
- data: item
565
- }));
566
- }
277
+ let visibleItems = [];
567
278
 
568
- function beforeSync(items) {
569
- return ig.beforeSync(toItems(items));
570
- }
279
+ function updateAttributes() {
280
+ $$invalidate(2, attributes = { ...$$props
281
+ });
282
+ const defaultOptions = GridClass.defaultOptions;
283
+ delete attributes["GridClass"];
571
284
 
572
- function getLoadingElement() {
573
- if (hasLoadingElement) {
574
- const el = container || viewer;
575
- return el.lastElementChild;
285
+ for (const name in defaultOptions) {
286
+ delete attributes[name];
576
287
  }
288
+
289
+ SVELTE_INFINITEGRID_PROPS.forEach(name => {
290
+ delete attributes[name];
291
+ });
577
292
  }
578
293
 
579
- function getElements() {
580
- const el = container || viewer;
581
- const elements = [].slice.call(el.children);
294
+ function getItemInfos() {
295
+ const items = $$props.items || [];
582
296
 
583
- if (hasLoadingElement) {
584
- return elements.slice(0, -1);
585
- }
297
+ const itemBy = $$props.itemBy || (item => item.key);
586
298
 
587
- return elements;
588
- }
299
+ const groupBy = $$props.groupBy || (item => item.groupKey);
589
300
 
590
- function updateAttributes() {
591
- $$invalidate(5, attributes = { ...$$props
592
- });
593
- PROP_NAMES.forEach(name => {
594
- delete attributes[name];
301
+ return items.map((item, i) => {
302
+ return {
303
+ groupKey: groupBy(item, i),
304
+ key: itemBy(item, i),
305
+ data: item
306
+ };
595
307
  });
596
308
  }
597
309
 
598
- const groups = VanillaInfiniteGrid.categorize(items);
599
-
600
- if (status) {
601
- const {
602
- startCursor,
603
- endCursor
604
- } = status._infinite;
605
- visibleItems = VanillaInfiniteGrid.ItemManager.pluck(groups.slice(startCursor, endCursor + 1), "items").map(item => item.data);
606
- } else if (useFirstRender) {
607
- visibleItems = items;
310
+ function updateVisibleChildren() {
311
+ $$invalidate(3, visibleItems = infinitegrid.getRenderingItems(getItemInfos(), {
312
+ grid,
313
+ status: $$props.status,
314
+ usePlaceholder: $$props.usePlaceholder,
315
+ useFirstRender: $$props.useFirstRender,
316
+ useLoading: $$props.useLoading,
317
+ horizontal: $$props.horizontal
318
+ }));
608
319
  }
609
320
 
610
321
  svelte.beforeUpdate(() => {
611
322
  updateAttributes();
323
+ updateVisibleChildren();
324
+ });
325
+ svelte.onMount(() => {
326
+ const defaultOptions = GridClass.defaultOptions;
327
+ const options = {};
612
328
 
613
- if (!ig) {
614
- return;
329
+ for (const name in defaultOptions) {
330
+ if (name in $$props) {
331
+ options[name] = $$props[name];
332
+ }
615
333
  }
616
334
 
617
- const result = beforeSync(items);
618
- layoutState = result === "relayout" ? result : layoutState || result;
619
- $$invalidate(3, visibleItems = ig.getRenderingItems().map(item => item.data));
620
- const loadingElement = getLoadingElement();
621
-
622
- if (loadingElement) {
623
- ig.setLoadingBar({
624
- append: loadingElement,
625
- prepend: loadingElement
626
- });
627
- } else {
628
- ig.setLoadingBar();
335
+ if (container) {
336
+ options.container = container;
629
337
  }
630
- });
631
- svelte.onMount(() => {
632
- ig = new VanillaInfiniteGrid(viewer, { ...options,
633
- renderExternal: true
634
- }).on("render", ({
635
- next
636
- }) => {
637
- setTimeout(() => {
638
- nextFunction = next;
639
- $$invalidate(6, ++_forceCount);
640
- });
641
- });
642
- VanillaInfiniteGrid.INFINITEGRID_EVENTS.forEach(name => {
643
- ig.on(name, e => {
644
- dispatch(name, e);
645
- });
646
- });
647
- ig.setLayout(layoutType, layoutOptions);
648
- const loadingElement = getLoadingElement();
649
338
 
650
- if (loadingElement) {
651
- ig.setLoadingBar({
652
- append: loadingElement,
653
- prepend: loadingElement
339
+ options.renderer = renderer;
340
+ grid = new GridClass(wrapper, options);
341
+
342
+ for (const name in infinitegrid.INFINITEGRID_EVENTS) {
343
+ const eventName = infinitegrid.INFINITEGRID_EVENTS[name];
344
+ grid.on(eventName, e => {
345
+ dispatch(eventName, e);
654
346
  });
655
347
  }
656
348
 
657
- if (status) {
658
- setStatus(status, true);
659
- } else {
660
- beforeSync(items);
661
- ig.layout(true);
662
- }
349
+ renderer.on("requestUpdate", () => {
350
+ updateVisibleChildren();
351
+ });
352
+ infinitegrid.mountRenderingItems(getItemInfos(), {
353
+ grid,
354
+ status: $$props.status,
355
+ usePlaceholder: $$props.usePlaceholder,
356
+ useFirstRender: $$props.useFirstRender,
357
+ useLoading: $$props.useLoading,
358
+ horizontal: $$props.horizontal
359
+ });
360
+ renderer.updated();
663
361
  });
664
362
  svelte.afterUpdate(() => {
665
- if (isFirstMount) {
666
- isFirstMount = false;
667
- return;
668
- }
669
363
 
670
- const currentNextFunction = nextFunction;
364
+ const propertyTypes = GridClass.propertyTypes;
671
365
 
672
- nextFunction = () => {};
673
-
674
- ig.sync(getElements());
675
-
676
- if (layoutState) {
677
- layoutState = "";
678
- ig.layout(layoutState === "relayout");
366
+ for (const name in propertyTypes) {
367
+ if (name in $$props) {
368
+ grid[name] = $$props[name];
369
+ }
679
370
  }
680
371
 
681
- currentNextFunction();
372
+ renderer.updated();
682
373
  });
683
374
  svelte.onDestroy(() => {
684
- ig.destroy();
375
+ grid?.destroy();
685
376
  });
686
377
 
687
378
  function getInstance() {
688
- return ig;
689
- }
690
-
691
- function setStatus(status, applyScrollPos, syncElements = getElements()) {
692
- ig.setStatus(status, applyScrollPos, syncElements);
693
- return ig;
694
- }
695
-
696
- function loadingchecker_hasLoading_binding(value) {
697
- hasLoadingElement = value;
698
- $$invalidate(4, hasLoadingElement);
379
+ return grid;
699
380
  }
700
381
 
701
382
  function div_binding($$value) {
702
- internal.binding_callbacks[$$value ? "unshift" : "push"](() => {
383
+ internal.binding_callbacks[$$value ? 'unshift' : 'push'](() => {
703
384
  container = $$value;
704
- $$invalidate(2, container);
385
+ $$invalidate(1, container);
705
386
  });
706
387
  }
707
388
 
708
- function loadingchecker_hasLoading_binding_1(value) {
709
- hasLoadingElement = value;
710
- $$invalidate(4, hasLoadingElement);
711
- }
712
-
713
389
  function div_binding_1($$value) {
714
- internal.binding_callbacks[$$value ? "unshift" : "push"](() => {
715
- viewer = $$value;
716
- $$invalidate(1, viewer);
390
+ internal.binding_callbacks[$$value ? 'unshift' : 'push'](() => {
391
+ wrapper = $$value;
392
+ $$invalidate(0, wrapper);
717
393
  });
718
394
  }
719
395
 
720
396
  $$self.$$set = $$new_props => {
721
- $$invalidate(33, $$props = internal.assign(internal.assign({}, $$props), internal.exclude_internal_props($$new_props)));
722
- if ("groupBy" in $$new_props) $$invalidate(7, groupBy = $$new_props.groupBy);
723
- if ("itemBy" in $$new_props) $$invalidate(8, itemBy = $$new_props.itemBy);
724
- if ("items" in $$new_props) $$invalidate(9, items = $$new_props.items);
725
- if ("useFirstRender" in $$new_props) $$invalidate(10, useFirstRender = $$new_props.useFirstRender);
726
- if ("status" in $$new_props) $$invalidate(11, status = $$new_props.status);
727
- if ("layoutType" in $$new_props) $$invalidate(12, layoutType = $$new_props.layoutType);
728
- if ("options" in $$new_props) $$invalidate(0, options = $$new_props.options);
729
- if ("layoutOptions" in $$new_props) $$invalidate(13, layoutOptions = $$new_props.layoutOptions);
730
- if ("_forceCount" in $$new_props) $$invalidate(6, _forceCount = $$new_props._forceCount);
731
- if ("$$scope" in $$new_props) $$invalidate(16, $$scope = $$new_props.$$scope);
397
+ $$invalidate(4, $$props = internal.assign(internal.assign({}, $$props), internal.exclude_internal_props($$new_props)));
398
+ if ('GridClass' in $$new_props) $$invalidate(5, GridClass = $$new_props.GridClass);
399
+ if ('$$scope' in $$new_props) $$invalidate(7, $$scope = $$new_props.$$scope);
732
400
  };
733
401
 
734
402
  $$props = internal.exclude_internal_props($$props);
735
- return [options, viewer, container, visibleItems, hasLoadingElement, attributes, _forceCount, groupBy, itemBy, items, useFirstRender, status, layoutType, layoutOptions, getInstance, setStatus, $$scope, slots, loadingchecker_hasLoading_binding, div_binding, loadingchecker_hasLoading_binding_1, div_binding_1];
403
+ return [wrapper, container, attributes, visibleItems, $$props, GridClass, getInstance, $$scope, slots, div_binding, div_binding_1];
736
404
  }
737
405
 
738
- class InfiniteGrid extends internal.SvelteComponent {
406
+ class InfiniteGrid$1 extends internal.SvelteComponent {
739
407
  constructor(options) {
740
408
  super();
741
- internal.init(this, options, instance$1, create_fragment, internal.safe_not_equal, {
742
- groupBy: 7,
743
- itemBy: 8,
744
- items: 9,
745
- useFirstRender: 10,
746
- status: 11,
747
- layoutType: 12,
748
- options: 0,
749
- layoutOptions: 13,
750
- _forceCount: 6,
751
- getInstance: 14,
752
- setStatus: 15
753
- }, [-1, -1]);
409
+ internal.init(this, options, instance, create_fragment, internal.safe_not_equal, {
410
+ GridClass: 5,
411
+ getInstance: 6
412
+ });
754
413
  }
755
414
 
756
415
  get getInstance() {
757
- return this.$$.ctx[14];
758
- }
759
-
760
- get setStatus() {
761
- return this.$$.ctx[15];
416
+ return this.$$.ctx[6];
762
417
  }
763
418
 
764
419
  }
765
420
 
766
- var InfiniteGrid$1 = /*#__PURE__*/
767
- (() => {
768
- const prototype = InfiniteGrid.prototype;
769
-
770
- for (const name in VanillaInfiniteGrid.INFINITEGRID_METHODS) {
771
- if (name in prototype) {
772
- continue;
773
- }
421
+ /**
422
+ * egjs-infinitegrid
423
+ * Copyright (c) 2021-present NAVER Corp.
424
+ * MIT license
425
+ */
426
+ var InfiniteGrid = /*#__PURE__*/(() => {
427
+ const prototype = InfiniteGrid$1.prototype;
428
+
429
+ if (prototype) {
430
+ infinitegrid.INFINITEGRID_METHODS.forEach(name => {
431
+ if (name in prototype) {
432
+ return;
433
+ }
774
434
 
775
- prototype[name] = function (...args) {
776
- const self = this.getInstance();
777
- const result = self[name](...args);
435
+ prototype[name] = function (...args) {
436
+ const self = this.getInstance();
437
+ const result = self[name](...args);
778
438
 
779
- if (result === self) {
780
- return this;
781
- } else {
782
- return result;
783
- }
784
- };
439
+ if (result === self) {
440
+ return this;
441
+ } else {
442
+ return result;
443
+ }
444
+ };
445
+ });
785
446
  }
786
447
 
787
- return InfiniteGrid;
448
+ return InfiniteGrid$1;
788
449
  })();
789
450
 
790
- class GridLayout extends InfiniteGrid {
791
- constructor(options) {
792
- options.props.layoutType = VanillaInfiniteGrid.GridLayout;
793
- super(options);
794
- }
795
-
796
- }
451
+ let MasonryInfiniteGrid;
797
452
 
798
- class JustifiedLayout extends InfiniteGrid {
799
- constructor(options) {
800
- options.props.layoutType = VanillaInfiniteGrid.JustifiedLayout;
801
- super(options);
802
- }
453
+ if (typeof InfiniteGrid$1 === "object") {
454
+ MasonryInfiniteGrid = InfiniteGrid$1;
455
+ } else {
456
+ MasonryInfiniteGrid = class MasonryInfiniteGrid extends InfiniteGrid$1 {
457
+ constructor(options) {
458
+ options.props.GridClass = infinitegrid.MasonryInfiniteGrid;
459
+ super(options);
460
+ }
803
461
 
462
+ };
804
463
  }
805
464
 
806
- class FrameLayout extends InfiniteGrid {
807
- constructor(options) {
808
- options.props.layoutType = VanillaInfiniteGrid.FrameLayout;
809
- super(options);
810
- }
811
-
812
- }
465
+ let JustifiedInfiniteGrid;
813
466
 
814
- class SquareLayout extends InfiniteGrid {
815
- constructor(options) {
816
- options.props.layoutType = VanillaInfiniteGrid.SquareLayout;
817
- super(options);
818
- }
467
+ if (typeof InfiniteGrid$1 === "object") {
468
+ JustifiedInfiniteGrid = InfiniteGrid$1;
469
+ } else {
470
+ JustifiedInfiniteGrid = class JustifiedInfiniteGrid extends InfiniteGrid$1 {
471
+ constructor(options) {
472
+ options.props.GridClass = infinitegrid.JustifiedInfiniteGrid;
473
+ super(options);
474
+ }
819
475
 
476
+ };
820
477
  }
821
478
 
822
- class PackingLayout extends InfiniteGrid {
823
- constructor(options) {
824
- options.props.layoutType = VanillaInfiniteGrid.PackingLayout;
825
- super(options);
826
- }
479
+ let FrameInfiniteGrid;
827
480
 
828
- }
481
+ if (typeof InfiniteGrid$1 === "object") {
482
+ FrameInfiniteGrid = InfiniteGrid$1;
483
+ } else {
484
+ FrameInfiniteGrid = class FrameInfiniteGrid extends InfiniteGrid$1 {
485
+ constructor(options) {
486
+ options.props.GridClass = infinitegrid.FrameInfiniteGrid;
487
+ super(options);
488
+ }
829
489
 
490
+ };
491
+ }
830
492
 
493
+ let PackingInfiniteGrid;
831
494
 
832
- var modules = ({
833
- __proto__: null,
834
- 'default': InfiniteGrid$1,
835
- GridLayout: GridLayout,
836
- JustifiedLayout: JustifiedLayout,
837
- FrameLayout: FrameLayout,
838
- PackingLayout: PackingLayout,
839
- SquareLayout: SquareLayout
840
- });
495
+ if (typeof InfiniteGrid$1 === "object") {
496
+ PackingInfiniteGrid = InfiniteGrid$1;
497
+ } else {
498
+ PackingInfiniteGrid = class PackingInfiniteGrid extends InfiniteGrid$1 {
499
+ constructor(options) {
500
+ options.props.GridClass = infinitegrid.PackingInfiniteGrid;
501
+ super(options);
502
+ }
841
503
 
842
- for (const name in modules) {
843
- InfiniteGrid$1[name] = modules[name];
504
+ };
844
505
  }
845
506
 
846
- module.exports = InfiniteGrid$1;
507
+ var modules = {
508
+ __proto__: null,
509
+ InfiniteGrid: InfiniteGrid,
510
+ get MasonryInfiniteGrid () { return MasonryInfiniteGrid; },
511
+ get JustifiedInfiniteGrid () { return JustifiedInfiniteGrid; },
512
+ get FrameInfiniteGrid () { return FrameInfiniteGrid; },
513
+ get PackingInfiniteGrid () { return PackingInfiniteGrid; }
514
+ };
515
+
516
+ module.exports = modules;
847
517
  //# sourceMappingURL=infinitegrid.cjs.js.map