@egjs/flicking 4.12.0-beta.8 → 4.12.0-beta.9

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,7 +4,7 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.12.0-beta.8
7
+ version: 4.12.0-beta.9
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -7980,6 +7980,7 @@ version: 4.12.0-beta.8
7980
7980
  var _this = this;
7981
7981
  var _b = (_a === void 0 ? {} : _a).align,
7982
7982
  align = _b === void 0 ? ALIGN.CENTER : _b;
7983
+ this._lookedOffset = 0;
7983
7984
  this._checkTranslateSupport = function () {
7984
7985
  var e_1, _a;
7985
7986
  var transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
@@ -8339,6 +8340,8 @@ version: 4.12.0-beta.8
8339
8340
  */
8340
8341
  __proto.lookAt = function (pos) {
8341
8342
  var _this = this;
8343
+ var prevOffset = this._offset;
8344
+ var isChangedOffset = this._lookedOffset !== prevOffset;
8342
8345
  var flicking = getFlickingAttached(this._flicking);
8343
8346
  var prevPos = this._position;
8344
8347
  this._position = pos;
@@ -8349,7 +8352,12 @@ version: 4.12.0-beta.8
8349
8352
  if (toggled) {
8350
8353
  void flicking.renderer.render().then(function () {
8351
8354
  _this.updateOffset();
8355
+ _this._lookedOffset = _this._offset;
8352
8356
  });
8357
+ } else if (isChangedOffset) {
8358
+ // sync offset for renderOnlyVisible on resize
8359
+ this.updateOffset();
8360
+ this._lookedOffset = this._offset;
8353
8361
  } else {
8354
8362
  this.applyTransform();
8355
8363
  }
@@ -8524,8 +8532,8 @@ version: 4.12.0-beta.8
8524
8532
  return this;
8525
8533
  };
8526
8534
  /**
8527
- * Update Viewport's height to active panel's height
8528
- * @ko 현재 선택된 패널의 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
8535
+ * Update Viewport's height to visible panel's max height
8536
+ * @ko 현재 활성화된 패널과 보이는 패널의 최대 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
8529
8537
  * @throws {FlickingError}
8530
8538
  * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
8531
8539
  * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
@@ -8535,9 +8543,17 @@ version: 4.12.0-beta.8
8535
8543
  __proto.updateAdaptiveHeight = function () {
8536
8544
  var flicking = getFlickingAttached(this._flicking);
8537
8545
  var activePanel = flicking.control.activePanel;
8538
- if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
8546
+ var visiblePanels = flicking.visiblePanels;
8547
+ var selectedPanels = __spread$1(visiblePanels);
8548
+ if (activePanel) {
8549
+ selectedPanels.push(activePanel);
8550
+ }
8551
+ if (!flicking.horizontal || !flicking.adaptive || !selectedPanels.length) return;
8552
+ var maxHeight = Math.max.apply(Math, __spread$1(selectedPanels.map(function (panel) {
8553
+ return panel.height;
8554
+ })));
8539
8555
  flicking.viewport.setSize({
8540
- height: activePanel.height
8556
+ height: maxHeight
8541
8557
  });
8542
8558
  };
8543
8559
  /**
@@ -8608,6 +8624,7 @@ version: 4.12.0-beta.8
8608
8624
  };
8609
8625
  __proto._resetInternalValues = function () {
8610
8626
  this._position = 0;
8627
+ this._lookedOffset = 0;
8611
8628
  this._alignPos = 0;
8612
8629
  this._offset = 0;
8613
8630
  this._circularOffset = 0;
@@ -13026,103 +13043,139 @@ version: 4.12.0-beta.8
13026
13043
  * Flicking.VERSION; // ex) 4.0.0
13027
13044
  * ```
13028
13045
  */
13029
- Flicking.VERSION = "4.12.0-beta.8";
13046
+ Flicking.VERSION = "4.12.0-beta.9";
13030
13047
  return Flicking;
13031
13048
  }(Component);
13032
13049
 
13033
- /*
13034
- * Copyright (c) 2015 NAVER Corp.
13035
- * egjs projects are licensed under the MIT license
13036
- */
13050
+ var SIDE_EVENTS = {
13051
+ HOLD_START: "sideHoldStart",
13052
+ HOLD_END: "sideHoldEnd",
13053
+ MOVE_START: "sideMoveStart",
13054
+ MOVE: "sideMove",
13055
+ MOVE_END: "sideMoveEnd",
13056
+ WILL_CHANGE: "sideWillChange",
13057
+ CHANGED: "sideChanged"
13058
+ };
13037
13059
  var CrossFlicking = /*#__PURE__*/function (_super) {
13038
13060
  __extends$3(CrossFlicking, _super);
13039
13061
  function CrossFlicking(root, options) {
13040
- if (options === void 0) {
13041
- options = {
13042
- sideOptions: {},
13043
- preserveIndex: false,
13044
- disableSlideOnHold: false,
13045
- disableIndexSync: false
13046
- };
13047
- }
13048
13062
  var _this = _super.call(this, root, options) || this;
13063
+ _this._syncToCategory = function (index, outerIndex) {
13064
+ if (_this._disableIndexSync) {
13065
+ return;
13066
+ }
13067
+ _this.stopAnimation();
13068
+ _this._sideFlicking.forEach(function (child, i) {
13069
+ var _a = _this._sideState[i],
13070
+ start = _a.start,
13071
+ end = _a.end;
13072
+ if (start <= index && end >= index && outerIndex !== i) {
13073
+ child.stopAnimation();
13074
+ void child.moveTo(index, 0);
13075
+ void _this.moveTo(i, 0);
13076
+ }
13077
+ });
13078
+ };
13079
+ _this._setDraggable = function (direction, draggable) {
13080
+ if (!_this._disableSlideOnHold) {
13081
+ return;
13082
+ }
13083
+ var threshold = draggable ? _this.dragThreshold && _this.dragThreshold >= 10 ? _this.dragThreshold : 10 : Infinity;
13084
+ if (direction === MOVE_DIRECTION.HORIZONTAL === _this.horizontal) {
13085
+ _this.dragThreshold = threshold;
13086
+ } else if (direction === MOVE_DIRECTION.VERTICAL === _this.horizontal) {
13087
+ _this._sideFlicking.forEach(function (child) {
13088
+ child.dragThreshold = threshold;
13089
+ });
13090
+ }
13091
+ };
13092
+ _this._setPreviousSideIndex = function () {
13093
+ _this._sideFlicking.forEach(function (child, i) {
13094
+ var _a = _this._sideState[i],
13095
+ start = _a.start,
13096
+ end = _a.end;
13097
+ if (_this._preserveIndex) {
13098
+ if (_this._nextIndex !== i) {
13099
+ if (child.index < start) {
13100
+ child.stopAnimation();
13101
+ void child.moveTo(start, 0);
13102
+ } else if (child.index > end) {
13103
+ child.stopAnimation();
13104
+ void child.moveTo(end, 0);
13105
+ }
13106
+ }
13107
+ } else {
13108
+ if (_this._nextIndex !== i) {
13109
+ void child.moveTo(start, 0);
13110
+ }
13111
+ }
13112
+ });
13113
+ };
13049
13114
  _this._onHorizontalHoldStart = function () {
13050
- _this.dragThreshold = 10;
13115
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
13051
13116
  _this._moveDirection = null;
13052
13117
  };
13053
13118
  _this._onHorizontalMove = function (e) {
13054
13119
  if (e.isTrusted && !_this._moveDirection) {
13055
- _this._sideFlicking.forEach(function (child) {
13056
- child.dragThreshold = Infinity;
13057
- });
13120
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
13058
13121
  _this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
13059
13122
  }
13060
13123
  };
13061
13124
  _this._onHorizontalMoveEnd = function (e) {
13062
13125
  var visiblePanels = _this.visiblePanels;
13063
- _this._sideFlicking.forEach(function (child) {
13064
- child.dragThreshold = 10;
13065
- });
13066
- _this._moveDirection = null;
13067
13126
  if (visiblePanels.length > 1) {
13068
13127
  _this._nextIndex = e.direction === "NEXT" ? visiblePanels[1].index : visiblePanels[0].index;
13069
13128
  } else {
13070
13129
  _this._nextIndex = visiblePanels[0].index;
13071
13130
  }
13131
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
13132
+ _this._moveDirection = null;
13072
13133
  // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
13073
13134
  requestAnimationFrame(function () {
13074
- _this._sideFlicking.forEach(function (child, i) {
13075
- if (_this._nextIndex !== i) {
13076
- var _a = _this._sideState[i],
13077
- start = _a.start,
13078
- end = _a.end;
13079
- if (child.index < start) {
13080
- child.stopAnimation();
13081
- void child.moveTo(start, 0);
13082
- } else if (child.index > end) {
13083
- child.stopAnimation();
13084
- void child.moveTo(end, 0);
13085
- }
13086
- }
13087
- });
13135
+ return _this._setPreviousSideIndex();
13088
13136
  });
13089
13137
  if (e.isTrusted) {
13090
13138
  _this._syncToCategory(_this._sideFlicking[_this._nextIndex].index, _this._nextIndex);
13091
13139
  }
13092
13140
  };
13093
13141
  _this._onSideHoldStart = function () {
13094
- _this._sideFlicking.forEach(function (child) {
13095
- child.dragThreshold = 10;
13096
- });
13142
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
13097
13143
  _this._moveDirection = null;
13098
13144
  };
13099
13145
  _this._onSideMove = function (e) {
13100
13146
  if (e.isTrusted && !_this._moveDirection) {
13101
- _this.dragThreshold = Infinity;
13147
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
13102
13148
  _this._moveDirection = MOVE_DIRECTION.VERTICAL;
13103
13149
  }
13104
13150
  };
13105
13151
  _this._onSideMoveEnd = function () {
13106
- _this.dragThreshold = 10;
13152
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
13107
13153
  _this._moveDirection = null;
13108
13154
  };
13109
13155
  _this._onSideChanged = function (e) {
13110
- // this.visiblePanels.length 2보다 크다면 가로 방향 Flicking이 조작 중이라는 것을 의미합니다.
13111
- // 경우 가로 방향 Flicking의 이동이 완전히 끝난 _onHorizontalMoveEnd 에서 syncToCategory할 것이므로 여기서는 하지 않습니다.
13156
+ // If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
13157
+ // In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
13112
13158
  if (_this.visiblePanels.length < 2 && _this._sideFlicking[_this.index] === e.currentTarget) {
13113
13159
  _this._syncToCategory(e.index, _this.index);
13114
13160
  }
13115
13161
  };
13162
+ var _a = options.sideOptions,
13163
+ sideOptions = _a === void 0 ? {} : _a,
13164
+ _b = options.preserveIndex,
13165
+ preserveIndex = _b === void 0 ? true : _b,
13166
+ _c = options.disableSlideOnHold,
13167
+ disableSlideOnHold = _c === void 0 ? true : _c,
13168
+ _d = options.disableIndexSync,
13169
+ disableIndexSync = _d === void 0 ? false : _d;
13116
13170
  // Internal states
13117
13171
  _this._moveDirection = null;
13118
13172
  _this._nextIndex = 0;
13119
13173
  // Bind options
13120
- _this._sideOptions = options.sideOptions;
13121
- _this._preserveIndex = options.preserveIndex;
13122
- _this._disableSlideOnHold = options.disableSlideOnHold;
13123
- _this._disableIndexSync = options.disableIndexSync;
13174
+ _this._sideOptions = sideOptions;
13175
+ _this._preserveIndex = preserveIndex;
13176
+ _this._disableSlideOnHold = disableSlideOnHold;
13177
+ _this._disableIndexSync = disableIndexSync;
13124
13178
  return _this;
13125
- // Create core components
13126
13179
  }
13127
13180
  var __proto = CrossFlicking.prototype;
13128
13181
  Object.defineProperty(__proto, "sideFlicking", {
@@ -13191,7 +13244,9 @@ version: 4.12.0-beta.8
13191
13244
  });
13192
13245
  };
13193
13246
  __proto.destroy = function () {
13194
- // TODO 모든 child flicking destroy
13247
+ this._sideFlicking.forEach(function (flicking) {
13248
+ flicking.destroy();
13249
+ });
13195
13250
  _super.prototype.destroy.call(this);
13196
13251
  };
13197
13252
  __proto._addComponentEvents = function () {
@@ -13199,80 +13254,80 @@ version: 4.12.0-beta.8
13199
13254
  this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
13200
13255
  this.on(EVENTS.MOVE, this._onHorizontalMove);
13201
13256
  this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
13202
- this._sideFlicking.forEach(function (flicking) {
13257
+ this._sideFlicking.forEach(function (flicking, mainIndex) {
13203
13258
  flicking.on(EVENTS.HOLD_START, _this._onSideHoldStart);
13204
13259
  flicking.on(EVENTS.MOVE, _this._onSideMove);
13205
13260
  flicking.on(EVENTS.MOVE_END, _this._onSideMoveEnd);
13206
13261
  flicking.on(EVENTS.CHANGED, _this._onSideChanged);
13262
+ Object.keys(SIDE_EVENTS).forEach(function (name) {
13263
+ flicking.on(EVENTS[name], function (event) {
13264
+ _this.trigger(new ComponentEvent$1(SIDE_EVENTS[name], __assign$2({
13265
+ mainIndex: mainIndex
13266
+ }, event)));
13267
+ });
13268
+ });
13207
13269
  });
13208
13270
  };
13209
- __proto._getGroupFromAttribute = function (panels) {
13210
- var groupKeys = [];
13211
- var groupPanels = {};
13212
- panels.forEach(function (panel) {
13213
- var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
13214
- if (groupKey && !includes(groupKeys, groupKey)) {
13215
- groupKeys.push(groupKey);
13216
- groupPanels[groupKey] = [panel];
13217
- } else if (groupKey) {
13218
- groupPanels[groupKey].push(panel);
13219
- }
13220
- });
13221
- return groupPanels;
13222
- };
13223
13271
  __proto._createSideState = function () {
13224
- var _this = this;
13225
13272
  var viewportEl = this.element;
13226
13273
  var cameraEl = this.camera.element;
13227
13274
  var panels = toArray$2(cameraEl.children);
13228
- var sideState = [];
13229
- var sidePanels = "";
13230
- // check data attribute exists
13231
- var sideCamera = document.createElement("div");
13232
- sideCamera.classList.add(CLASS.CAMERA);
13233
13275
  var isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
13276
+ var sideState = [];
13234
13277
  if (!isCrossStructure) {
13235
- viewportEl.setAttribute("data-cross-structure", "true");
13236
13278
  var groupPanels = this._getGroupFromAttribute(panels);
13237
13279
  var groupKeys = Object.keys(groupPanels);
13238
13280
  if (groupKeys.length) {
13239
13281
  sideState = this._getSideStateFromGroup(groupPanels);
13240
13282
  this.remove(0, this.panelCount - groupKeys.length);
13241
- sideState.forEach(function (state, i) {
13242
- var panel = _this.camera.children[i];
13243
- sidePanels += state.element.innerHTML;
13244
- Array.from(panel.attributes).forEach(function (attribute) {
13245
- return panel.removeAttribute(attribute.name);
13246
- });
13247
- });
13248
13283
  } else {
13249
- sideState = panels.reduce(function (state, panel, i) {
13250
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
13251
- sidePanels += panel.innerHTML;
13252
- return __spread$1(state, [{
13253
- key: i.toString(),
13254
- start: start,
13255
- end: start + panel.children.length - 1,
13256
- element: panel
13257
- }]);
13258
- }, []);
13284
+ sideState = this._getSideStateFromPanels(panels);
13259
13285
  }
13260
- sideCamera.innerHTML = sidePanels;
13261
- sideState.forEach(function (_, i) {
13262
- var panel = _this.camera.children[i];
13263
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
13264
- if (!panel.classList.contains(className)) {
13265
- panel.classList.add(className);
13266
- }
13267
- });
13268
- panel.innerHTML = sideCamera.outerHTML;
13269
- });
13286
+ this._createCrossStructure(sideState);
13270
13287
  } else {
13271
- sideState = this._getSideStateFromPanels(panels);
13288
+ sideState = this._getSideStateFromCrossStructure(panels);
13272
13289
  }
13273
13290
  void this.resize();
13274
13291
  return sideState;
13275
13292
  };
13293
+ __proto._createCrossStructure = function (sideState) {
13294
+ var _this = this;
13295
+ var sideCamera = document.createElement("div");
13296
+ var sidePanels = "";
13297
+ sideCamera.classList.add(CLASS.CAMERA);
13298
+ sideState.forEach(function (state, i) {
13299
+ var panel = _this.camera.children[i];
13300
+ sidePanels += state.element.innerHTML;
13301
+ Array.from(panel.attributes).forEach(function (attribute) {
13302
+ return panel.removeAttribute(attribute.name);
13303
+ });
13304
+ });
13305
+ sideCamera.innerHTML = sidePanels;
13306
+ sideState.forEach(function (_, i) {
13307
+ var panel = _this.camera.children[i];
13308
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
13309
+ if (!panel.classList.contains(className)) {
13310
+ panel.classList.add(className);
13311
+ }
13312
+ });
13313
+ panel.innerHTML = sideCamera.outerHTML;
13314
+ });
13315
+ this.element.setAttribute("data-cross-structure", "true");
13316
+ };
13317
+ __proto._getGroupFromAttribute = function (panels) {
13318
+ var groupKeys = [];
13319
+ var groupPanels = {};
13320
+ panels.forEach(function (panel) {
13321
+ var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
13322
+ if (groupKey && !includes(groupKeys, groupKey)) {
13323
+ groupKeys.push(groupKey);
13324
+ groupPanels[groupKey] = [panel];
13325
+ } else if (groupKey) {
13326
+ groupPanels[groupKey].push(panel);
13327
+ }
13328
+ });
13329
+ return groupPanels;
13330
+ };
13276
13331
  __proto._getSideStateFromGroup = function (groupPanels) {
13277
13332
  return Object.keys(groupPanels).reduce(function (state, key) {
13278
13333
  var start = state.length ? +state[state.length - 1].end + 1 : 0;
@@ -13289,6 +13344,17 @@ version: 4.12.0-beta.8
13289
13344
  }, []);
13290
13345
  };
13291
13346
  __proto._getSideStateFromPanels = function (panels) {
13347
+ return panels.reduce(function (state, panel, i) {
13348
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
13349
+ return __spread$1(state, [{
13350
+ key: i.toString(),
13351
+ start: start,
13352
+ end: start + panel.children.length - 1,
13353
+ element: panel
13354
+ }]);
13355
+ }, []);
13356
+ };
13357
+ __proto._getSideStateFromCrossStructure = function (panels) {
13292
13358
  var groupPanels = this._getGroupFromAttribute(panels);
13293
13359
  return this._getSideStateFromGroup(groupPanels);
13294
13360
  };
@@ -13298,30 +13364,16 @@ version: 4.12.0-beta.8
13298
13364
  return new Flicking(_this.camera.children[i], __assign$2(__assign$2({}, _this.sideOptions), {
13299
13365
  horizontal: false,
13300
13366
  panelsPerView: 1,
13301
- defaultIndex: state.start,
13302
- moveType: "strict"
13367
+ defaultIndex: state.start
13303
13368
  }));
13304
13369
  });
13305
13370
  };
13306
- __proto._syncToCategory = function (index, outerIndex) {
13307
- var _this = this;
13308
- this.stopAnimation();
13309
- this._sideFlicking.forEach(function (child, i) {
13310
- var _a = _this._sideState[i],
13311
- start = _a.start,
13312
- end = _a.end;
13313
- if (start <= index && end >= index && outerIndex !== i) {
13314
- child.stopAnimation();
13315
- void child.moveTo(index, 0);
13316
- void _this.moveTo(i, 0);
13317
- }
13318
- });
13319
- };
13320
13371
  return CrossFlicking;
13321
13372
  }(Flicking);
13322
13373
 
13323
13374
  var CrossFlicking$1 = {
13324
13375
  __proto__: null,
13376
+ SIDE_EVENTS: SIDE_EVENTS,
13325
13377
  CrossFlicking: CrossFlicking
13326
13378
  };
13327
13379