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