@egjs/react-flicking 4.15.0 → 4.16.0-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 (84) hide show
  1. package/dev/archive/App.css +32 -0
  2. package/dev/archive/App.tsx +52 -0
  3. package/dev/archive/DebugPage.css +21 -0
  4. package/dev/archive/DebugPage.tsx +93 -0
  5. package/dev/archive/Header.tsx +52 -0
  6. package/dev/archive/StatePage.css +21 -0
  7. package/dev/archive/StatePage.tsx +107 -0
  8. package/dev/archive/css/align.css +79 -0
  9. package/dev/archive/css/bound.css +88 -0
  10. package/dev/archive/css/common.css +76 -0
  11. package/dev/archive/css/cross.css +21 -0
  12. package/dev/archive/css/features.css +49 -0
  13. package/dev/archive/css/gap.css +13 -0
  14. package/dev/archive/css/highlight.css +96 -0
  15. package/dev/archive/css/infinite.css +35 -0
  16. package/dev/archive/css/parallax.css +3 -0
  17. package/dev/archive/css/plugins.css +46 -0
  18. package/dev/archive/css/progress.css +16 -0
  19. package/dev/archive/css/variable-size.css +15 -0
  20. package/dev/archive/features/Align.tsx +149 -0
  21. package/dev/archive/features/Bound.tsx +83 -0
  22. package/dev/archive/features/CrossFlicking.tsx +74 -0
  23. package/dev/archive/features/FreeScroll.tsx +66 -0
  24. package/dev/archive/features/InfiniteFlicking.tsx +192 -0
  25. package/dev/archive/features/PlaceHolderItem.tsx +36 -0
  26. package/dev/archive/features/Progress.tsx +241 -0
  27. package/dev/archive/features/PropChange.tsx +171 -0
  28. package/dev/archive/features/Snap.tsx +95 -0
  29. package/dev/archive/features/VariableSize.tsx +42 -0
  30. package/dev/archive/features/Virtual.tsx +45 -0
  31. package/dev/archive/plugins/Arrow.tsx +25 -0
  32. package/dev/archive/plugins/AutoPlay.tsx +70 -0
  33. package/dev/archive/plugins/Fade.tsx +69 -0
  34. package/dev/archive/plugins/Parallax.tsx +70 -0
  35. package/dev/archive/utils.ts +3 -0
  36. package/dev/basic-sample/App.tsx +36 -0
  37. package/dev/basic-sample/index.html +12 -0
  38. package/dev/basic-sample/main.tsx +10 -0
  39. package/dev/index.html +18 -0
  40. package/dev/plugin-check/App.tsx +341 -0
  41. package/dev/plugin-check/index.html +15 -0
  42. package/dev/plugin-check/main.tsx +6 -0
  43. package/dev/scratch/App.tsx +34 -0
  44. package/dev/scratch/index.html +15 -0
  45. package/dev/scratch/main.tsx +13 -0
  46. package/dev/tsconfig.json +12 -0
  47. package/dev/vite-env.d.ts +3 -0
  48. package/{declaration → dist}/CrossFlicking.d.ts +3 -5
  49. package/{declaration → dist}/CrossGroup.d.ts +1 -1
  50. package/{declaration → dist}/Flicking.d.ts +8 -8
  51. package/{declaration → dist}/NonStrictPanel.d.ts +1 -1
  52. package/{declaration → dist}/ReactRenderer.d.ts +1 -1
  53. package/{declaration → dist}/StrictPanel.d.ts +1 -1
  54. package/{declaration → dist}/ViewportSlot.d.ts +1 -1
  55. package/dist/flicking.cjs.js +1514 -579
  56. package/dist/flicking.cjs.js.map +1 -1
  57. package/dist/flicking.esm.js +1573 -651
  58. package/dist/flicking.esm.js.map +1 -1
  59. package/dist/flicking.js +1634 -0
  60. package/dist/flicking.js.map +1 -0
  61. package/{declaration → dist}/index.d.ts +3 -3
  62. package/{declaration → dist}/types.d.ts +1 -2
  63. package/package.json +18 -33
  64. package/src/react-flicking/CrossFlicking.tsx +28 -37
  65. package/src/react-flicking/CrossGroup.tsx +6 -8
  66. package/src/react-flicking/Flicking.tsx +81 -69
  67. package/src/react-flicking/NonStrictPanel.tsx +15 -7
  68. package/src/react-flicking/ReactElementProvider.ts +6 -4
  69. package/src/react-flicking/ReactRenderer.ts +1 -2
  70. package/src/react-flicking/StrictPanel.tsx +10 -6
  71. package/src/react-flicking/consts.ts +14 -14
  72. package/src/react-flicking/index.ts +4 -7
  73. package/src/react-flicking/index.umd.ts +1 -1
  74. package/src/react-flicking/reactive.ts +3 -3
  75. package/src/react-flicking/types.ts +17 -17
  76. package/tsconfig.json +2 -9
  77. package/vite.config.ts +38 -0
  78. package/vite.dev.config.ts +58 -0
  79. package/dist/flicking.umd.js +0 -699
  80. package/dist/flicking.umd.js.map +0 -1
  81. /package/{declaration → dist}/ReactElementProvider.d.ts +0 -0
  82. /package/{declaration → dist}/consts.d.ts +0 -0
  83. /package/{declaration → dist}/index.umd.d.ts +0 -0
  84. /package/{declaration → dist}/reactive.d.ts +0 -0
@@ -1,699 +0,0 @@
1
- /*
2
- Copyright (c) 2015-present NAVER Corp.
3
- name: @egjs/react-flicking
4
- license: MIT
5
- author: NAVER Corp.
6
- repository: https://github.com/naver/egjs-flicking/tree/master/packages/react-flicking
7
- version: 4.15.0
8
- */
9
- (function (global, factory) {
10
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('@egjs/component'), require('@egjs/list-differ'), require('@egjs/flicking'), require('@cfcs/react')) :
11
- typeof define === 'function' && define.amd ? define(['react', '@egjs/component', '@egjs/list-differ', '@egjs/flicking', '@cfcs/react'], factory) :
12
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ReactFlicking = factory(global.React, global.Component, global.eg.ListDiffer, global.Flicking, global.react));
13
- })(this, (function (React, Component, ListDiffer, VanillaFlicking, react) { 'use strict';
14
-
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise */
30
-
31
- var extendStatics = function (d, b) {
32
- extendStatics = Object.setPrototypeOf || {
33
- __proto__: []
34
- } instanceof Array && function (d, b) {
35
- d.__proto__ = b;
36
- } || function (d, b) {
37
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
38
- };
39
- return extendStatics(d, b);
40
- };
41
- function __extends(d, b) {
42
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
43
- extendStatics(d, b);
44
- function __() {
45
- this.constructor = d;
46
- }
47
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
48
- }
49
- var __assign = function () {
50
- __assign = Object.assign || function __assign(t) {
51
- for (var s, i = 1, n = arguments.length; i < n; i++) {
52
- s = arguments[i];
53
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
54
- }
55
- return t;
56
- };
57
- return __assign.apply(this, arguments);
58
- };
59
- function __rest(s, e) {
60
- var t = {};
61
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
62
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
63
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
64
- }
65
- return t;
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
- function __awaiter(thisArg, _arguments, P, generator) {
75
- function adopt(value) {
76
- return value instanceof P ? value : new P(function (resolve) {
77
- resolve(value);
78
- });
79
- }
80
- return new (P || (P = Promise))(function (resolve, reject) {
81
- function fulfilled(value) {
82
- try {
83
- step(generator.next(value));
84
- } catch (e) {
85
- reject(e);
86
- }
87
- }
88
- function rejected(value) {
89
- try {
90
- step(generator["throw"](value));
91
- } catch (e) {
92
- reject(e);
93
- }
94
- }
95
- function step(result) {
96
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
97
- }
98
- step((generator = generator.apply(thisArg, _arguments || [])).next());
99
- });
100
- }
101
- function __generator(thisArg, body) {
102
- var _ = {
103
- label: 0,
104
- sent: function () {
105
- if (t[0] & 1) throw t[1];
106
- return t[1];
107
- },
108
- trys: [],
109
- ops: []
110
- },
111
- f,
112
- y,
113
- t,
114
- g;
115
- return g = {
116
- next: verb(0),
117
- "throw": verb(1),
118
- "return": verb(2)
119
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
120
- return this;
121
- }), g;
122
- function verb(n) {
123
- return function (v) {
124
- return step([n, v]);
125
- };
126
- }
127
- function step(op) {
128
- if (f) throw new TypeError("Generator is already executing.");
129
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
130
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
131
- if (y = 0, t) op = [op[0] & 2, t.value];
132
- switch (op[0]) {
133
- case 0:
134
- case 1:
135
- t = op;
136
- break;
137
- case 4:
138
- _.label++;
139
- return {
140
- value: op[1],
141
- done: false
142
- };
143
- case 5:
144
- _.label++;
145
- y = op[1];
146
- op = [0];
147
- continue;
148
- case 7:
149
- op = _.ops.pop();
150
- _.trys.pop();
151
- continue;
152
- default:
153
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
154
- _ = 0;
155
- continue;
156
- }
157
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
158
- _.label = op[1];
159
- break;
160
- }
161
- if (op[0] === 6 && _.label < t[1]) {
162
- _.label = t[1];
163
- t = op;
164
- break;
165
- }
166
- if (t && _.label < t[2]) {
167
- _.label = t[2];
168
- _.ops.push(op);
169
- break;
170
- }
171
- if (t[2]) _.ops.pop();
172
- _.trys.pop();
173
- continue;
174
- }
175
- op = body.call(thisArg, _);
176
- } catch (e) {
177
- op = [6, e];
178
- y = 0;
179
- } finally {
180
- f = t = 0;
181
- }
182
- if (op[0] & 5) throw op[1];
183
- return {
184
- value: op[0] ? op[1] : void 0,
185
- done: true
186
- };
187
- }
188
- }
189
- function __spreadArray(to, from, pack) {
190
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
191
- if (ar || !(i in from)) {
192
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
193
- ar[i] = from[i];
194
- }
195
- }
196
- return to.concat(ar || Array.prototype.slice.call(from));
197
- }
198
-
199
- var DEFAULT_PROPS = {
200
- viewportTag: "div",
201
- cameraTag: "div",
202
- cameraClass: "",
203
- firstPanelSize: "",
204
- renderOnSameKey: false,
205
- plugins: [],
206
- useFindDOMNode: false,
207
- hideBeforeInit: false,
208
- onReady: function (e) {},
209
- onBeforeResize: function (e) {},
210
- onAfterResize: function (e) {},
211
- onHoldStart: function (e) {},
212
- onHoldEnd: function (e) {},
213
- onMoveStart: function (e) {},
214
- onMove: function (e) {},
215
- onMoveEnd: function (e) {},
216
- onWillChange: function (e) {},
217
- onChanged: function (e) {},
218
- onWillRestore: function (e) {},
219
- onRestored: function (e) {},
220
- onSelect: function (e) {},
221
- onNeedPanel: function (e) {},
222
- onVisibleChange: function (e) {},
223
- onReachEdge: function (e) {},
224
- onPanelChange: function (e) {}
225
- };
226
-
227
- var ReactRenderer = /*#__PURE__*/function (_super) {
228
- __extends(ReactRenderer, _super);
229
- function ReactRenderer(options) {
230
- var _this = _super.call(this, options) || this;
231
- _this._reactFlicking = options.reactFlicking;
232
- return _this;
233
- }
234
- // eslint-disable-next-line @typescript-eslint/require-await
235
- var __proto = ReactRenderer.prototype;
236
- __proto.render = function () {
237
- return __awaiter(this, void 0, void 0, function () {
238
- var flicking, reactFlicking, strategy;
239
- var _this = this;
240
- return __generator(this, function (_a) {
241
- flicking = VanillaFlicking.getFlickingAttached(this._flicking);
242
- reactFlicking = this._reactFlicking;
243
- strategy = this._strategy;
244
- if (flicking.virtualEnabled) {
245
- // virtual 값은 VirtualManager Object 이므로 virtualEnabled 로 검사하는 것이 맞습니다.
246
- // applyTransform does not work when renderer.rendering is true. #916
247
- // updateRenderingPanels should be called before rendering becomes true, or transform will be applied later.
248
- strategy.updateRenderingPanels(flicking);
249
- this._rendering = true;
250
- } else {
251
- this._rendering = true;
252
- strategy.updateRenderingPanels(flicking);
253
- }
254
- strategy.renderPanels(flicking);
255
- return [2 /*return*/, new Promise(function (resolve) {
256
- reactFlicking.renderEmitter.once("render", function () {
257
- _this._rendering = false;
258
- _this._afterRender();
259
- resolve();
260
- });
261
- reactFlicking.forceUpdate();
262
- })];
263
- });
264
- });
265
- };
266
- __proto.forceRenderAllPanels = function () {
267
- return __awaiter(this, void 0, void 0, function () {
268
- var reactFlicking;
269
- var _this = this;
270
- return __generator(this, function (_a) {
271
- switch (_a.label) {
272
- case 0:
273
- reactFlicking = this._reactFlicking;
274
- this._rendering = true;
275
- return [4 /*yield*/, _super.prototype.forceRenderAllPanels.call(this)];
276
- case 1:
277
- _a.sent();
278
- return [2 /*return*/, new Promise(function (resolve) {
279
- reactFlicking.renderEmitter.once("render", function () {
280
- _this._rendering = false;
281
- resolve();
282
- });
283
- reactFlicking.forceUpdate();
284
- })];
285
- }
286
- });
287
- });
288
- };
289
- __proto.destroy = function () {
290
- _super.prototype.destroy.call(this);
291
- this._reactFlicking.renderEmitter.off("render");
292
- };
293
- __proto._collectPanels = function () {
294
- var flicking = VanillaFlicking.getFlickingAttached(this._flicking);
295
- var reactFlicking = this._reactFlicking;
296
- var reactPanels = reactFlicking.reactPanels;
297
- this._panels = this._strategy.collectPanels(flicking, reactPanels);
298
- };
299
- __proto._createPanel = function (externalComponent, options) {
300
- return this._strategy.createPanel(externalComponent, options);
301
- };
302
- return ReactRenderer;
303
- }(VanillaFlicking.ExternalRenderer);
304
-
305
- var StrictPanel = /*#__PURE__*/function (_super) {
306
- __extends(StrictPanel, _super);
307
- function StrictPanel() {
308
- var _this = _super !== null && _super.apply(this, arguments) || this;
309
- _this._hide = false;
310
- _this._elRef = React.createRef();
311
- return _this;
312
- }
313
- var __proto = StrictPanel.prototype;
314
- Object.defineProperty(__proto, "nativeElement", {
315
- get: function () {
316
- return this._elRef.current;
317
- },
318
- enumerable: false,
319
- configurable: true
320
- });
321
- Object.defineProperty(__proto, "rendered", {
322
- get: function () {
323
- return !this._hide;
324
- },
325
- enumerable: false,
326
- configurable: true
327
- });
328
- Object.defineProperty(__proto, "elRef", {
329
- get: function () {
330
- return this._elRef;
331
- },
332
- enumerable: false,
333
- configurable: true
334
- });
335
- __proto.render = function () {
336
- return this._hide ? React.createElement(React.Fragment, null) : this._getElement();
337
- };
338
- __proto.show = function () {
339
- this._hide = false;
340
- };
341
- __proto.hide = function () {
342
- this._hide = true;
343
- };
344
- __proto._getElement = function () {
345
- return React.cloneElement(React.Children.only(this.props.children), {
346
- ref: this._elRef
347
- });
348
- };
349
- return StrictPanel;
350
- }(React.Component);
351
-
352
- /*
353
- * Copyright (c) 2015 NAVER Corp.
354
- * egjs projects are licensed under the MIT license
355
- */
356
- var ViewportSlot = React.memo(function (props) {
357
- return React.createElement(React.Fragment, null, props.children);
358
- });
359
-
360
- var ReactElementProvider = /*#__PURE__*/function () {
361
- function ReactElementProvider(el) {
362
- this._el = el;
363
- }
364
- var __proto = ReactElementProvider.prototype;
365
- Object.defineProperty(__proto, "element", {
366
- get: function () {
367
- var _a;
368
- return (_a = this._el) === null || _a === void 0 ? void 0 : _a.nativeElement;
369
- },
370
- enumerable: false,
371
- configurable: true
372
- });
373
- Object.defineProperty(__proto, "rendered", {
374
- get: function () {
375
- var _a;
376
- return (_a = this._el) === null || _a === void 0 ? void 0 : _a.rendered;
377
- },
378
- enumerable: false,
379
- configurable: true
380
- });
381
- __proto.show = function () {
382
- var _a;
383
- (_a = this._el) === null || _a === void 0 ? void 0 : _a.show();
384
- };
385
- __proto.hide = function () {
386
- var _a;
387
- (_a = this._el) === null || _a === void 0 ? void 0 : _a.hide();
388
- };
389
- return ReactElementProvider;
390
- }();
391
-
392
- var Flicking = /*#__PURE__*/function (_super) {
393
- __extends(Flicking, _super);
394
- function Flicking(props) {
395
- var _this = _super.call(this, props) || this;
396
- _this._panels = [];
397
- _this._renderEmitter = new Component();
398
- var children = _this._getChildren();
399
- _this._panels = _this._createPanelRefs(props, children);
400
- _this._prevChildren = children;
401
- return _this;
402
- }
403
- var __proto = Flicking.prototype;
404
- Object.defineProperty(__proto, "reactPanels", {
405
- get: function () {
406
- return this._panels.map(function (panel) {
407
- return panel.current;
408
- });
409
- },
410
- enumerable: false,
411
- configurable: true
412
- });
413
- Object.defineProperty(__proto, "renderEmitter", {
414
- get: function () {
415
- return this._renderEmitter;
416
- },
417
- enumerable: false,
418
- configurable: true
419
- });
420
- __proto.componentDidMount = function () {
421
- var props = this.props;
422
- var rendererOptions = {
423
- reactFlicking: this,
424
- align: props.align,
425
- strategy: props.virtual && props.panelsPerView > 0 ? new VanillaFlicking.VirtualRenderingStrategy() : new VanillaFlicking.NormalRenderingStrategy({
426
- providerCtor: ReactElementProvider
427
- })
428
- };
429
- var flicking = new VanillaFlicking(this._viewportElement, __assign(__assign({}, props), {
430
- externalRenderer: new ReactRenderer(rendererOptions)
431
- }));
432
- this._vanillaFlicking = flicking;
433
- var children = this._getChildren();
434
- this._jsxDiffer = new ListDiffer(children, function (panel) {
435
- return panel.key;
436
- });
437
- this._pluginsDiffer = new ListDiffer();
438
- this._prevChildren = children;
439
- this._bindEvents();
440
- this._checkPlugins();
441
- if (props.status) {
442
- flicking.setStatus(props.status);
443
- }
444
- };
445
- __proto.componentWillUnmount = function () {
446
- var _a;
447
- (_a = this._vanillaFlicking) === null || _a === void 0 ? void 0 : _a.destroy();
448
- };
449
- __proto.shouldComponentUpdate = function (nextProps) {
450
- var vanillaFlicking = this._vanillaFlicking;
451
- var prevProps = this.props;
452
- if (!vanillaFlicking || !vanillaFlicking.initialized) return false;
453
- var children = nextProps.children,
454
- restProps = __rest(nextProps, ["children"]);
455
- for (var key in restProps) {
456
- if (prevProps[key] !== nextProps[key]) {
457
- return true;
458
- }
459
- }
460
- var prevChildren = this._prevChildren;
461
- var nextChildren = this._getChildren(children);
462
- if (nextProps.renderOnSameKey || !this._hasSameChildren(prevChildren, nextChildren)) return true;
463
- return false;
464
- };
465
- __proto.beforeRender = function () {
466
- var vanillaFlicking = this._vanillaFlicking;
467
- var props = this.props;
468
- var prevChildren = this._prevChildren;
469
- // Ignore updates before init, they will be updated after "ready" event's force update
470
- // Also, prevent updates when another update is already queued.
471
- // This usually happens when render() called twice without calling componentDidMount, like in the case of React.StrictMode.
472
- if (!vanillaFlicking || !vanillaFlicking.initialized || this._diffResult) return;
473
- var nextChildren = this._getChildren(props.children);
474
- if (props.renderOnSameKey || !this._hasSameChildren(prevChildren, nextChildren)) {
475
- this._panels = this._createPanelRefs(props, nextChildren);
476
- this._diffResult = this._jsxDiffer.update(nextChildren);
477
- this._prevChildren = nextChildren;
478
- }
479
- };
480
- __proto.componentDidUpdate = function () {
481
- var flicking = this._vanillaFlicking;
482
- var renderEmitter = this._renderEmitter;
483
- var diffResult = this._diffResult;
484
- this._checkPlugins();
485
- renderEmitter.trigger("render");
486
- flicking.camera.updateOffset();
487
- // Omit 'virtual', as it can't have any setter
488
- var _a = this.props;
489
- _a.virtual;
490
- var props = __rest(_a, ["virtual"]);
491
- for (var key in props) {
492
- if (key in flicking && flicking[key] !== props[key]) {
493
- flicking[key] = props[key];
494
- }
495
- }
496
- if (!diffResult || !flicking.initialized) return;
497
- VanillaFlicking.sync(flicking, diffResult, this.reactPanels);
498
- this._diffResult = null;
499
- };
500
- __proto.render = function () {
501
- var _this = this;
502
- var _a;
503
- var props = this.props;
504
- var Viewport = props.viewportTag;
505
- var Camera = props.cameraTag;
506
- var attributes = {};
507
- this.beforeRender();
508
- for (var name in props) {
509
- if (!(name in DEFAULT_PROPS) && !(name in VanillaFlicking.prototype)) {
510
- attributes[name] = props[name];
511
- }
512
- }
513
- var _b = this._getClasses(attributes, props),
514
- viewportClasses = _b.viewportClasses,
515
- cameraClasses = _b.cameraClasses,
516
- cameraProps = _b.cameraProps;
517
- var panels = !!props.virtual && ((_a = props.panelsPerView) !== null && _a !== void 0 ? _a : -1) > 0 ? this._getVirtualPanels() : this._getPanels();
518
- return React.createElement(Viewport, __assign({}, attributes, {
519
- className: viewportClasses.join(" "),
520
- ref: function (e) {
521
- e && (_this._viewportElement = e);
522
- }
523
- }), React.createElement(Camera, __assign({
524
- className: cameraClasses.join(" ")
525
- }, cameraProps), panels), this._getViewportSlot());
526
- };
527
- __proto._createPanelRefs = function (props, children) {
528
- var _a;
529
- var panelsPerView = (_a = props.panelsPerView) !== null && _a !== void 0 ? _a : -1;
530
- return panelsPerView > 0 && !!props.virtual ? VanillaFlicking.range(panelsPerView + 1).map(function () {
531
- return React.createRef();
532
- }) : children.map(function () {
533
- return React.createRef();
534
- });
535
- };
536
- __proto._bindEvents = function () {
537
- var _this = this;
538
- var flicking = this._vanillaFlicking;
539
- Object.keys(VanillaFlicking.EVENTS).forEach(function (eventKey) {
540
- var eventName = VanillaFlicking.EVENTS[eventKey];
541
- _this._bindEvent(eventName);
542
- });
543
- flicking.once(VanillaFlicking.EVENTS.READY, function () {
544
- _this.forceUpdate();
545
- });
546
- };
547
- __proto._bindEvent = function (eventName) {
548
- var _this = this;
549
- var propName = "on".concat(eventName.charAt(0).toUpperCase() + eventName.slice(1));
550
- this._vanillaFlicking.on(eventName, function (e) {
551
- e.currentTarget = _this;
552
- var evtHandler = _this.props[propName];
553
- evtHandler(e);
554
- });
555
- };
556
- __proto._checkPlugins = function () {
557
- var flicking = this._vanillaFlicking;
558
- var _a = this._pluginsDiffer.update(this.props.plugins),
559
- list = _a.list,
560
- added = _a.added,
561
- removed = _a.removed,
562
- prevList = _a.prevList;
563
- flicking.addPlugins.apply(flicking, added.map(function (index) {
564
- return list[index];
565
- }));
566
- flicking.removePlugins.apply(flicking, removed.map(function (index) {
567
- return prevList[index];
568
- }));
569
- };
570
- __proto._getClasses = function (attributes, props) {
571
- var _a;
572
- var flicking = this._vanillaFlicking;
573
- var initialized = flicking && flicking.initialized;
574
- var viewportClasses = ["flicking-viewport"];
575
- var cameraClasses = ["flicking-camera"];
576
- var isHorizontal = flicking ? flicking.horizontal : (_a = props.horizontal) !== null && _a !== void 0 ? _a : true;
577
- if (!isHorizontal) {
578
- viewportClasses.push("vertical");
579
- }
580
- if (props.hideBeforeInit && !initialized) {
581
- viewportClasses.push("flicking-hidden");
582
- }
583
- if (attributes.className) {
584
- viewportClasses.push(attributes.className);
585
- }
586
- if (props.cameraClass) {
587
- cameraClasses.push(props.cameraClass);
588
- }
589
- var cameraProps = !initialized && props.firstPanelSize ? {
590
- style: {
591
- transform: VanillaFlicking.getDefaultCameraTransform(this.props.align, this.props.horizontal, this.props.firstPanelSize)
592
- }
593
- } : {};
594
- return {
595
- viewportClasses: viewportClasses,
596
- cameraClasses: cameraClasses,
597
- cameraProps: cameraProps
598
- };
599
- };
600
- __proto._hasSameChildren = function (prevChildren, nextChildren) {
601
- if (prevChildren.length !== nextChildren.length || prevChildren.length === 0) return false;
602
- var same = prevChildren.every(function (child, idx) {
603
- var nextChild = nextChildren[idx];
604
- return child === nextChild;
605
- });
606
- return same;
607
- };
608
- __proto._getChildren = function (children) {
609
- var _this = this;
610
- if (children === void 0) {
611
- children = this.props.children;
612
- }
613
- return React.Children.toArray(children).filter(function (child) {
614
- return child.type !== ViewportSlot;
615
- }).reduce(function (all, child) {
616
- return __spreadArray(__spreadArray([], all, true), _this._unpackFragment(child), true);
617
- }, []);
618
- };
619
- __proto._getViewportSlot = function () {
620
- return React.Children.toArray(this.props.children).filter(function (child) {
621
- return child.type === ViewportSlot;
622
- });
623
- };
624
- __proto._unpackFragment = function (child) {
625
- var _this = this;
626
- return this._isFragment(child) ? React.Children.toArray(child.props.children).reduce(function (allChilds, fragChild) {
627
- return __spreadArray(__spreadArray([], allChilds, true), _this._unpackFragment(fragChild), true);
628
- }, []) : [child];
629
- };
630
- __proto._getVirtualPanels = function () {
631
- var _this = this;
632
- var _a = this.props.virtual.panelClass,
633
- panelClass = _a === void 0 ? "flicking-panel" : _a;
634
- var panelsPerView = this.props.panelsPerView;
635
- var flicking = this._vanillaFlicking;
636
- var initialized = flicking && flicking.initialized;
637
- var renderingIndexes = initialized ? flicking.renderer.strategy.getRenderingIndexesByOrder(flicking) : VanillaFlicking.range(panelsPerView + 1);
638
- var firstPanel = flicking && flicking.panels[0];
639
- var size = firstPanel ? flicking.horizontal ? {
640
- width: firstPanel.size
641
- } : {
642
- height: firstPanel.size
643
- } : {};
644
- return renderingIndexes.map(function (idx) {
645
- return React.createElement(StrictPanel, {
646
- key: idx,
647
- ref: _this._panels[idx]
648
- }, React.createElement("div", {
649
- "data-element-index": idx,
650
- className: panelClass,
651
- style: size
652
- }));
653
- });
654
- };
655
- __proto._getPanels = function () {
656
- var _this = this;
657
- var origChildren = this._getChildren();
658
- var vanillaFlicking = this._vanillaFlicking;
659
- var diffResult = this._diffResult;
660
- var children = vanillaFlicking && vanillaFlicking.initialized ? diffResult ? VanillaFlicking.getRenderingPanels(vanillaFlicking, diffResult) : VanillaFlicking.getRenderingPanels(vanillaFlicking, ListDiffer.diff(origChildren, origChildren)) : origChildren;
661
- return children.map(function (child, idx) {
662
- return React.createElement(StrictPanel, {
663
- key: child.key,
664
- ref: _this._panels[idx]
665
- }, child);
666
- });
667
- };
668
- __proto._isFragment = function (child) {
669
- if (child.type) {
670
- return child.type === React.Fragment;
671
- }
672
- return child === React.Fragment;
673
- };
674
- Flicking.defaultProps = DEFAULT_PROPS;
675
- __decorate([VanillaFlicking.withFlickingMethods], Flicking.prototype, "_vanillaFlicking", void 0);
676
- return Flicking;
677
- }(React.Component);
678
-
679
- var useFlickingReactiveAPI = function (flickingRef, options) {
680
- return react.useReactive(VanillaFlicking.flickingReactiveAPIAdapter, function () {
681
- var _a;
682
- return {
683
- flicking: (_a = flickingRef.current) !== null && _a !== void 0 ? _a : undefined,
684
- options: options
685
- };
686
- });
687
- };
688
-
689
- /*
690
- * Copyright (c) 2015 NAVER Corp.
691
- * egjs projects are licensed under the MIT license
692
- */
693
- Flicking.ViewportSlot = ViewportSlot;
694
- Flicking.useFlickingReactiveAPI = useFlickingReactiveAPI;
695
-
696
- return Flicking;
697
-
698
- }));
699
- //# sourceMappingURL=flicking.umd.js.map