@egjs/vue3-flicking 4.3.1 → 4.4.3

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