@egjs/vue3-flicking 4.3.0 → 4.4.2

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.
@@ -4,12 +4,12 @@ name: @egjs/vue3-flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking/tree/master/packages/vue3-flicking
7
- version: 4.3.0
7
+ version: 4.4.2
8
8
  */
9
- import { Vue, Options, prop } from 'vue-class-component';
9
+ import { defineComponent, getCurrentInstance, resolveComponent, h, Fragment } from 'vue';
10
10
  import ListDiffer from '@egjs/list-differ';
11
- import { h, Fragment, resolveComponent } from 'vue';
12
- import VanillaFlicking, { ExternalPanel, ExternalRenderer, EVENTS, sync, getDefaultCameraTransform, getRenderingPanels, withFlickingMethods } from '@egjs/flicking';
11
+ import Component from '@egjs/component';
12
+ import VanillaFlicking__default, { getFlickingAttached, ExternalRenderer, getRenderingPanels, range, withFlickingMethods, VirtualRenderingStrategy, NormalRenderingStrategy, EVENTS, sync, getDefaultCameraTransform } from '@egjs/flicking';
13
13
  export * from '@egjs/flicking';
14
14
 
15
15
  /*! *****************************************************************************
@@ -63,13 +63,6 @@ var __assign = function () {
63
63
 
64
64
  return __assign.apply(this, arguments);
65
65
  };
66
- function __decorate(decorators, target, key, desc) {
67
- var c = arguments.length,
68
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
69
- d;
70
- 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;
71
- return c > 3 && r && Object.defineProperty(target, key, r), r;
72
- }
73
66
  function __awaiter(thisArg, _arguments, P, generator) {
74
67
  function adopt(value) {
75
68
  return value instanceof P ? value : new P(function (resolve) {
@@ -209,51 +202,55 @@ function __generator(thisArg, body) {
209
202
  };
210
203
  }
211
204
  }
212
- /** @deprecated */
213
-
214
- function __spreadArrays() {
215
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
216
-
217
- 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];
218
-
219
- return r;
220
- }
221
-
222
- var VuePanel =
223
- /*#__PURE__*/
224
- function (_super) {
225
- __extends(VuePanel, _super);
226
-
227
- function VuePanel() {
228
- return _super !== null && _super.apply(this, arguments) || this;
205
+ function __spreadArray(to, from, pack) {
206
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
207
+ if (ar || !(i in from)) {
208
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
209
+ ar[i] = from[i];
210
+ }
229
211
  }
212
+ return to.concat(ar || Array.prototype.slice.call(from));
213
+ }
230
214
 
231
- var __proto = VuePanel.prototype;
232
- Object.defineProperty(__proto, "element", {
233
- get: function () {
234
- return this._externalComponent.$.subTree.children[0].el;
215
+ var FlickingProps = {
216
+ viewportTag: {
217
+ type: String,
218
+ default: "div",
219
+ required: false
220
+ },
221
+ cameraTag: {
222
+ type: String,
223
+ default: "div",
224
+ required: false
225
+ },
226
+ hideBeforeInit: {
227
+ type: Boolean,
228
+ default: false,
229
+ required: false
230
+ },
231
+ firstPanelSize: {
232
+ type: String,
233
+ required: false
234
+ },
235
+ options: {
236
+ type: Object,
237
+ default: function () {
238
+ return {};
235
239
  },
236
- enumerable: false,
237
- configurable: true
238
- });
239
- Object.defineProperty(__proto, "rendered", {
240
- get: function () {
241
- return !this._externalComponent.hide;
240
+ required: false
241
+ },
242
+ plugins: {
243
+ type: Array,
244
+ default: function () {
245
+ return [];
242
246
  },
243
- enumerable: false,
244
- configurable: true
245
- });
246
-
247
- __proto.markForShow = function () {
248
- this._externalComponent.hide = false;
249
- };
250
-
251
- __proto.markForHide = function () {
252
- this._externalComponent.hide = true;
253
- };
254
-
255
- return VuePanel;
256
- }(ExternalPanel);
247
+ required: false
248
+ },
249
+ status: {
250
+ type: Object,
251
+ required: false
252
+ }
253
+ };
257
254
 
258
255
  var VueRenderer =
259
256
  /*#__PURE__*/
@@ -265,159 +262,206 @@ function (_super) {
265
262
 
266
263
  _this._vueFlicking = options.vueFlicking;
267
264
  return _this;
268
- } // eslint-disable-next-line @typescript-eslint/require-await
269
-
265
+ }
270
266
 
271
267
  var __proto = VueRenderer.prototype;
272
268
 
273
269
  __proto.render = function () {
274
270
  return __awaiter(this, void 0, void 0, function () {
275
- var flicking;
271
+ var flicking, vueFlicking, strategy;
276
272
  return __generator(this, function (_a) {
277
- flicking = this._flicking;
278
- if (!flicking) return [2
279
- /*return*/
280
- ];
281
-
282
- this._updateRenderingPanels();
283
-
284
- this._vueFlicking.$forceUpdate();
285
-
273
+ flicking = getFlickingAttached(this._flicking);
274
+ vueFlicking = this._vueFlicking;
275
+ strategy = this._strategy;
276
+ strategy.updateRenderingPanels(flicking);
277
+ strategy.renderPanels(flicking);
286
278
  return [2
287
279
  /*return*/
288
- ];
280
+ , new Promise(function (resolve) {
281
+ vueFlicking.renderEmitter.once("render", resolve);
282
+ vueFlicking.$forceUpdate();
283
+ })];
289
284
  });
290
285
  });
291
- }; // eslint-disable-next-line @typescript-eslint/require-await
292
-
286
+ };
293
287
 
294
288
  __proto.forceRenderAllPanels = function () {
295
289
  return __awaiter(this, void 0, void 0, function () {
290
+ var vueFlicking;
296
291
  return __generator(this, function (_a) {
297
- this._panels.forEach(function (panel) {
298
- return panel.markForShow();
299
- });
300
-
301
- this._vueFlicking.$forceUpdate();
302
-
303
- return [2
304
- /*return*/
305
- ];
292
+ switch (_a.label) {
293
+ case 0:
294
+ vueFlicking = this._vueFlicking;
295
+ return [4
296
+ /*yield*/
297
+ , _super.prototype.forceRenderAllPanels.call(this)];
298
+
299
+ case 1:
300
+ _a.sent();
301
+
302
+ return [2
303
+ /*return*/
304
+ , new Promise(function (resolve) {
305
+ vueFlicking.renderEmitter.once("render", resolve);
306
+ vueFlicking.$forceUpdate();
307
+ })];
308
+ }
306
309
  });
307
310
  });
308
311
  };
309
312
 
310
313
  __proto._collectPanels = function () {
311
- var _this = this;
312
-
313
- var align = this._getPanelAlign();
314
-
315
- var childRefs = this._vueFlicking.$refs;
316
- var children = Object.keys(childRefs).map(function (refKey) {
314
+ var flicking = getFlickingAttached(this._flicking);
315
+ var vueFlicking = this._vueFlicking;
316
+ var childRefs = vueFlicking.$refs;
317
+ var vuePanels = Object.keys(childRefs).map(function (refKey) {
317
318
  return childRefs[refKey];
318
319
  });
319
- this._panels = children.map(function (panelComponent, index) {
320
- return new VuePanel({
321
- flicking: _this._flicking,
322
- index: index,
323
- align: align,
324
- externalComponent: panelComponent
325
- });
326
- });
320
+ this._panels = this._strategy.collectPanels(flicking, vuePanels);
327
321
  };
328
322
 
329
323
  __proto._createPanel = function (externalComponent, options) {
330
- return new VuePanel(__assign({
331
- externalComponent: externalComponent
332
- }, options));
324
+ return this._strategy.createPanel(externalComponent, options);
333
325
  };
334
326
 
335
327
  return VueRenderer;
336
328
  }(ExternalRenderer);
337
329
 
338
- var VuePanelComponent =
330
+ /*
331
+ * Copyright (c) 2015 NAVER Corp.
332
+ * egjs projects are licensed under the MIT license
333
+ */
334
+ var VuePanel = defineComponent({
335
+ data: function () {
336
+ return {
337
+ hide: false
338
+ };
339
+ },
340
+ render: function () {
341
+ if (this.hide || !this.$slots.default) return;
342
+ return this.$slots.default();
343
+ }
344
+ });
345
+
346
+ var VueElementProvider =
339
347
  /*#__PURE__*/
340
- function (_super) {
341
- __extends(VuePanelComponent, _super);
348
+ function () {
349
+ function VueElementProvider(el) {
350
+ this._el = el;
351
+ }
342
352
 
343
- function VuePanelComponent() {
344
- var _this = _super !== null && _super.apply(this, arguments) || this;
353
+ var __proto = VueElementProvider.prototype;
354
+ Object.defineProperty(__proto, "rendered", {
355
+ get: function () {
356
+ return !this._el.hide;
357
+ },
358
+ enumerable: false,
359
+ configurable: true
360
+ });
361
+ Object.defineProperty(__proto, "element", {
362
+ get: function () {
363
+ var el = this._el.$el.nextSibling;
345
364
 
346
- _this.hide = false;
347
- return _this;
348
- }
365
+ if (el && el.nodeType === Node.ELEMENT_NODE) {
366
+ this._cachedElement = el;
367
+ }
349
368
 
350
- var __proto = VuePanelComponent.prototype;
369
+ return this._cachedElement;
370
+ },
371
+ enumerable: false,
372
+ configurable: true
373
+ });
351
374
 
352
- __proto.render = function () {
353
- if (this.hide || !this.$slots.default) return;
354
- return this.$slots.default();
375
+ __proto.show = function () {
376
+ this._el.hide = false;
355
377
  };
356
378
 
357
- return VuePanelComponent;
358
- }(Vue);
359
-
360
- var FlickingProps =
361
- /*#__PURE__*/
362
- function () {
363
- function FlickingProps() {
364
- this.viewportTag = prop({
365
- required: false,
366
- default: "div"
367
- });
368
- this.cameraTag = prop({
369
- required: false,
370
- default: "div"
371
- });
372
- this.hideBeforeInit = prop({
373
- required: false,
374
- default: false
375
- });
376
- this.firstPanelSize = prop({
377
- required: false
378
- });
379
- this.options = prop({
380
- required: false,
381
- default: {}
382
- });
383
- this.plugins = prop({
384
- required: false,
385
- default: []
386
- });
387
- this.status = prop({
388
- required: false
389
- });
390
- }
379
+ __proto.hide = function () {
380
+ this._el.hide = true;
381
+ };
391
382
 
392
- return FlickingProps;
383
+ return VueElementProvider;
393
384
  }();
394
385
 
395
- var Flicking =
396
- /*#__PURE__*/
397
- function (_super) {
398
- __extends(Flicking, _super);
386
+ var Flicking = defineComponent({
387
+ props: FlickingProps,
388
+ components: {
389
+ Panel: VuePanel
390
+ },
391
+ data: function () {
392
+ return {};
393
+ },
394
+ created: function () {
395
+ var _this = this;
399
396
 
400
- function Flicking() {
401
- var _this = _super !== null && _super.apply(this, arguments) || this;
397
+ this.vanillaFlicking = null;
398
+ this.renderEmitter = new Component();
399
+ this.diffResult = null;
402
400
 
403
- _this.vanillaFlicking = null;
404
- _this.diffResult = undefined;
405
- return _this;
406
- }
401
+ this.getPanels = function () {
402
+ var componentInstance = getCurrentInstance();
403
+ var vueFlicking = componentInstance === null || componentInstance === void 0 ? void 0 : componentInstance.ctx;
404
+ var flicking = _this.vanillaFlicking;
407
405
 
408
- var __proto = Flicking.prototype;
406
+ var defaultSlots = _this.getSlots();
409
407
 
410
- __proto.mounted = function () {
408
+ var diffResult = vueFlicking === null || vueFlicking === void 0 ? void 0 : vueFlicking.diffResult;
409
+ var slots = diffResult ? getRenderingPanels(flicking, diffResult) : defaultSlots;
410
+ var panelComponent = resolveComponent("Panel");
411
+ var panels = slots.map(function (slot, idx) {
412
+ return h(panelComponent, {
413
+ key: slot.key,
414
+ ref: idx.toString()
415
+ }, function () {
416
+ return slot;
417
+ });
418
+ });
419
+ return panels;
420
+ };
421
+
422
+ this.getVirtualPanels = function () {
423
+ var options = _this.options;
424
+ var _a = options.virtual.panelClass,
425
+ panelClass = _a === void 0 ? "flicking-panel" : _a;
426
+ var panelsPerView = options.panelsPerView;
427
+ var flicking = _this.vanillaFlicking;
428
+ var initialized = flicking && flicking.initialized;
429
+ var renderingIndexes = initialized ? flicking.renderer.strategy.getRenderingIndexesByOrder(flicking) : range(panelsPerView + 1);
430
+ var firstPanel = initialized && flicking.panels[0];
431
+ var size = firstPanel ? flicking.horizontal ? {
432
+ width: firstPanel.size
433
+ } : {
434
+ height: firstPanel.size
435
+ } : {};
436
+ return renderingIndexes.map(function (idx) {
437
+ return h("div", {
438
+ key: idx,
439
+ ref: idx.toString(),
440
+ class: panelClass,
441
+ style: size,
442
+ "data-element-index": idx
443
+ });
444
+ });
445
+ };
446
+
447
+ withFlickingMethods(this, "vanillaFlicking");
448
+ },
449
+ mounted: function () {
411
450
  var _this = this;
412
451
 
452
+ var _a;
453
+
454
+ var options = this.options;
413
455
  var viewportEl = this.$el;
414
- var flicking = new VanillaFlicking(viewportEl, __assign(__assign({}, this.options), {
415
- renderExternal: {
416
- renderer: VueRenderer,
417
- rendererOptions: {
418
- vueFlicking: this
419
- }
420
- }
456
+ var rendererOptions = {
457
+ vueFlicking: this,
458
+ align: options.align,
459
+ strategy: options.virtual && ((_a = options.panelsPerView) !== null && _a !== void 0 ? _a : -1) > 0 ? new VirtualRenderingStrategy() : new NormalRenderingStrategy({
460
+ providerCtor: VueElementProvider
461
+ })
462
+ };
463
+ var flicking = new VanillaFlicking__default(viewportEl, __assign(__assign({}, options), {
464
+ externalRenderer: new VueRenderer(rendererOptions)
421
465
  }));
422
466
  this.vanillaFlicking = flicking;
423
467
  flicking.once(EVENTS.READY, function () {
@@ -428,52 +472,45 @@ function (_super) {
428
472
  return vnode.key;
429
473
  });
430
474
  this.pluginsDiffer = new ListDiffer();
431
-
432
- this._bindEvents();
433
-
434
- this._checkPlugins();
475
+ this.bindEvents();
476
+ this.checkPlugins();
435
477
 
436
478
  if (this.status) {
437
479
  flicking.setStatus(this.status);
438
480
  }
439
- };
440
-
441
- __proto.beforeDestroy = function () {
481
+ },
482
+ beforeUnmount: function () {
442
483
  var _a;
443
484
 
444
485
  (_a = this.vanillaFlicking) === null || _a === void 0 ? void 0 : _a.destroy();
445
- };
446
-
447
- __proto.beforeMount = function () {
448
- this._fillKeys();
449
- };
450
-
451
- __proto.beforeUpdate = function () {
452
- this._fillKeys();
453
- };
454
-
455
- __proto.updated = function () {
486
+ },
487
+ beforeMount: function () {
488
+ this.fillKeys();
489
+ },
490
+ beforeUpdate: function () {
491
+ this.fillKeys();
492
+ this.diffResult = this.slotDiffer.update(this.getSlots());
493
+ },
494
+ updated: function () {
456
495
  var flicking = this.vanillaFlicking;
457
496
  var diffResult = this.diffResult;
458
- if (!diffResult) return;
459
- var children = this.$.subTree.children[0].children.map(function (c) {
460
- return c.component.ctx;
461
- });
497
+ this.checkPlugins();
498
+ this.renderEmitter.trigger("render");
499
+ if (!diffResult || !(flicking === null || flicking === void 0 ? void 0 : flicking.initialized)) return;
500
+ var children = this.getChildren();
462
501
  sync(flicking, diffResult, children);
463
502
 
464
- this._checkPlugins();
465
-
466
503
  if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
467
504
  this.$forceUpdate();
468
505
  }
469
- };
470
-
471
- __proto.render = function () {
472
- var _this = this;
473
506
 
507
+ this.diffResult = undefined;
508
+ },
509
+ render: function () {
474
510
  var _a;
475
511
 
476
512
  var flicking = this.vanillaFlicking;
513
+ var options = this.options;
477
514
  var initialized = flicking && flicking.initialized;
478
515
  var isHorizontal = flicking ? flicking.horizontal : (_a = this.options.horizontal) !== null && _a !== void 0 ? _a : true;
479
516
  var viewportData = {
@@ -491,111 +528,88 @@ function (_super) {
491
528
  transform: getDefaultCameraTransform(this.options.align, this.options.horizontal, this.firstPanelSize)
492
529
  } : {}
493
530
  };
494
-
495
- var getPanels = function () {
496
- var defaultSlots = _this.getSlots();
497
-
498
- _this.diffResult = initialized ? _this.slotDiffer.update(defaultSlots) : undefined;
499
- var slots = _this.diffResult ? getRenderingPanels(flicking, _this.diffResult) : defaultSlots;
500
- var panelComponent = resolveComponent("Panel");
501
- var panels = slots.map(function (slot, idx) {
502
- return h(panelComponent, {
503
- key: slot.key,
504
- ref: idx.toString()
505
- }, function () {
506
- return slot;
507
- });
508
- });
509
- return panels;
510
- };
511
-
531
+ var panels = options.virtual && options.panelsPerView && options.panelsPerView > 0 ? this.getVirtualPanels : this.getPanels;
512
532
  var viewportSlots = this.$slots.viewport ? this.$slots.viewport() : [];
513
- return h(this.viewportTag, viewportData, __spreadArrays([h(this.cameraTag, cameraData, {
514
- default: getPanels
515
- })], viewportSlots));
516
- };
517
-
518
- __proto.getSlots = function () {
519
- var _this = this;
533
+ return h(this.viewportTag, viewportData, __spreadArray([h(this.cameraTag, cameraData, {
534
+ default: panels
535
+ })], viewportSlots, true));
536
+ },
537
+ methods: {
538
+ getSlots: function () {
539
+ var _this = this;
540
+
541
+ var slots = this.$slots.default ? this.$slots.default() : [];
542
+ return slots.reduce(function (elementSlots, slot) {
543
+ return __spreadArray(__spreadArray([], elementSlots, true), _this.getElementVNodes(slot), true);
544
+ }, []);
545
+ },
546
+ getElementVNodes: function (slot, childSlots) {
547
+ var _this = this;
520
548
 
521
- var slots = this.$slots.default ? this.$slots.default() : [];
522
- return slots.reduce(function (elementSlots, slot) {
523
- return __spreadArrays(elementSlots, _this.getElementVNodes(slot));
524
- }, []);
525
- };
549
+ if (childSlots === void 0) {
550
+ childSlots = [];
551
+ }
526
552
 
527
- __proto.getElementVNodes = function (slot, childSlots) {
528
- var _this = this;
553
+ if (slot.type === Fragment && Array.isArray(slot.children)) {
554
+ slot.children.filter(function (child) {
555
+ return child && typeof child === "object";
556
+ }).forEach(function (child) {
557
+ return _this.getElementVNodes(child, childSlots);
558
+ });
559
+ } else {
560
+ childSlots.push(slot);
561
+ }
529
562
 
530
- if (childSlots === void 0) {
531
- childSlots = [];
532
- }
563
+ return childSlots;
564
+ },
565
+ bindEvents: function () {
566
+ var _this = this;
533
567
 
534
- if (slot.type === Fragment && Array.isArray(slot.children)) {
535
- slot.children.filter(function (child) {
536
- return child && typeof child === "object";
537
- }).forEach(function (child) {
538
- return _this.getElementVNodes(child, childSlots);
568
+ var flicking = this.vanillaFlicking;
569
+ var events = Object.keys(EVENTS).map(function (key) {
570
+ return EVENTS[key];
539
571
  });
540
- } else {
541
- childSlots.push(slot);
542
- }
543
-
544
- return childSlots;
545
- };
546
-
547
- __proto._bindEvents = function () {
548
- var _this = this;
549
-
550
- var flicking = this.vanillaFlicking;
551
- var events = Object.keys(EVENTS).map(function (key) {
552
- return EVENTS[key];
553
- });
554
- events.forEach(function (eventName) {
555
- flicking.on(eventName, function (e) {
556
- e.currentTarget = _this; // Make events from camelCase to kebab-case
572
+ events.forEach(function (eventName) {
573
+ flicking.on(eventName, function (e) {
574
+ e.currentTarget = _this; // Make events from camelCase to kebab-case
557
575
 
558
- _this.$emit(eventName.replace(/([A-Z])/g, "-$1").toLowerCase(), e);
576
+ _this.$emit(eventName.replace(/([A-Z])/g, "-$1").toLowerCase(), e);
577
+ });
578
+ });
579
+ },
580
+ checkPlugins: function () {
581
+ var _a, _b;
582
+
583
+ var _c = this.pluginsDiffer.update(this.plugins),
584
+ list = _c.list,
585
+ added = _c.added,
586
+ removed = _c.removed,
587
+ prevList = _c.prevList;
588
+
589
+ (_a = this.vanillaFlicking).addPlugins.apply(_a, added.map(function (index) {
590
+ return list[index];
591
+ }));
592
+
593
+ (_b = this.vanillaFlicking).removePlugins.apply(_b, removed.map(function (index) {
594
+ return prevList[index];
595
+ }));
596
+ },
597
+ fillKeys: function () {
598
+ var vnodes = this.getSlots();
599
+ vnodes.forEach(function (node, idx) {
600
+ if (node.key == null) {
601
+ node.key = "$_" + idx;
602
+ }
603
+ });
604
+ },
605
+ getChildren: function () {
606
+ var childRefs = this.$refs;
607
+ return Object.keys(childRefs).map(function (refKey) {
608
+ return childRefs[refKey];
559
609
  });
560
- });
561
- };
562
-
563
- __proto._checkPlugins = function () {
564
- var _a, _b;
565
-
566
- var _c = this.pluginsDiffer.update(this.plugins),
567
- list = _c.list,
568
- added = _c.added,
569
- removed = _c.removed,
570
- prevList = _c.prevList;
571
-
572
- (_a = this.vanillaFlicking).addPlugins.apply(_a, added.map(function (index) {
573
- return list[index];
574
- }));
575
-
576
- (_b = this.vanillaFlicking).removePlugins.apply(_b, removed.map(function (index) {
577
- return prevList[index];
578
- }));
579
- };
580
-
581
- __proto._fillKeys = function () {
582
- var vnodes = this.getSlots();
583
- vnodes.forEach(function (node, idx) {
584
- if (node.key == null) {
585
- node.key = "$_" + idx;
586
- }
587
- });
588
- };
589
-
590
- __decorate([withFlickingMethods], Flicking.prototype, "vanillaFlicking", void 0);
591
-
592
- Flicking = __decorate([Options({
593
- components: {
594
- Panel: VuePanelComponent
595
610
  }
596
- })], Flicking);
597
- return Flicking;
598
- }(Vue.with(FlickingProps));
611
+ }
612
+ });
599
613
 
600
- export default Flicking;
614
+ export { Flicking as default };
601
615
  //# sourceMappingURL=flicking.esm.js.map