@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.
package/dist/flicking.js CHANGED
@@ -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(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
@@ -3815,6 +3815,7 @@ version: 4.12.0-beta.8
3815
3815
  var _this = this;
3816
3816
  var _b = (_a === void 0 ? {} : _a).align,
3817
3817
  align = _b === void 0 ? ALIGN.CENTER : _b;
3818
+ this._lookedOffset = 0;
3818
3819
  this._checkTranslateSupport = function () {
3819
3820
  var e_1, _a;
3820
3821
  var transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
@@ -4174,6 +4175,8 @@ version: 4.12.0-beta.8
4174
4175
  */
4175
4176
  __proto.lookAt = function (pos) {
4176
4177
  var _this = this;
4178
+ var prevOffset = this._offset;
4179
+ var isChangedOffset = this._lookedOffset !== prevOffset;
4177
4180
  var flicking = getFlickingAttached(this._flicking);
4178
4181
  var prevPos = this._position;
4179
4182
  this._position = pos;
@@ -4184,7 +4187,12 @@ version: 4.12.0-beta.8
4184
4187
  if (toggled) {
4185
4188
  void flicking.renderer.render().then(function () {
4186
4189
  _this.updateOffset();
4190
+ _this._lookedOffset = _this._offset;
4187
4191
  });
4192
+ } else if (isChangedOffset) {
4193
+ // sync offset for renderOnlyVisible on resize
4194
+ this.updateOffset();
4195
+ this._lookedOffset = this._offset;
4188
4196
  } else {
4189
4197
  this.applyTransform();
4190
4198
  }
@@ -4359,8 +4367,8 @@ version: 4.12.0-beta.8
4359
4367
  return this;
4360
4368
  };
4361
4369
  /**
4362
- * Update Viewport's height to active panel's height
4363
- * @ko 현재 선택된 패널의 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
4370
+ * Update Viewport's height to visible panel's max height
4371
+ * @ko 현재 활성화된 패널과 보이는 패널의 최대 높이와 동일하도록 뷰포트의 높이를 업데이트합니다
4364
4372
  * @throws {FlickingError}
4365
4373
  * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
4366
4374
  * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
@@ -4370,9 +4378,17 @@ version: 4.12.0-beta.8
4370
4378
  __proto.updateAdaptiveHeight = function () {
4371
4379
  var flicking = getFlickingAttached(this._flicking);
4372
4380
  var activePanel = flicking.control.activePanel;
4373
- if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
4381
+ var visiblePanels = flicking.visiblePanels;
4382
+ var selectedPanels = __spread(visiblePanels);
4383
+ if (activePanel) {
4384
+ selectedPanels.push(activePanel);
4385
+ }
4386
+ if (!flicking.horizontal || !flicking.adaptive || !selectedPanels.length) return;
4387
+ var maxHeight = Math.max.apply(Math, __spread(selectedPanels.map(function (panel) {
4388
+ return panel.height;
4389
+ })));
4374
4390
  flicking.viewport.setSize({
4375
- height: activePanel.height
4391
+ height: maxHeight
4376
4392
  });
4377
4393
  };
4378
4394
  /**
@@ -4443,6 +4459,7 @@ version: 4.12.0-beta.8
4443
4459
  };
4444
4460
  __proto._resetInternalValues = function () {
4445
4461
  this._position = 0;
4462
+ this._lookedOffset = 0;
4446
4463
  this._alignPos = 0;
4447
4464
  this._offset = 0;
4448
4465
  this._circularOffset = 0;
@@ -7991,103 +8008,139 @@ version: 4.12.0-beta.8
7991
8008
  * Flicking.VERSION; // ex) 4.0.0
7992
8009
  * ```
7993
8010
  */
7994
- Flicking.VERSION = "4.12.0-beta.8";
8011
+ Flicking.VERSION = "4.12.0-beta.9";
7995
8012
  return Flicking;
7996
8013
  }(Component);
7997
8014
 
7998
- /*
7999
- * Copyright (c) 2015 NAVER Corp.
8000
- * egjs projects are licensed under the MIT license
8001
- */
8015
+ var SIDE_EVENTS = {
8016
+ HOLD_START: "sideHoldStart",
8017
+ HOLD_END: "sideHoldEnd",
8018
+ MOVE_START: "sideMoveStart",
8019
+ MOVE: "sideMove",
8020
+ MOVE_END: "sideMoveEnd",
8021
+ WILL_CHANGE: "sideWillChange",
8022
+ CHANGED: "sideChanged"
8023
+ };
8002
8024
  var CrossFlicking = /*#__PURE__*/function (_super) {
8003
8025
  __extends(CrossFlicking, _super);
8004
8026
  function CrossFlicking(root, options) {
8005
- if (options === void 0) {
8006
- options = {
8007
- sideOptions: {},
8008
- preserveIndex: false,
8009
- disableSlideOnHold: false,
8010
- disableIndexSync: false
8011
- };
8012
- }
8013
8027
  var _this = _super.call(this, root, options) || this;
8028
+ _this._syncToCategory = function (index, outerIndex) {
8029
+ if (_this._disableIndexSync) {
8030
+ return;
8031
+ }
8032
+ _this.stopAnimation();
8033
+ _this._sideFlicking.forEach(function (child, i) {
8034
+ var _a = _this._sideState[i],
8035
+ start = _a.start,
8036
+ end = _a.end;
8037
+ if (start <= index && end >= index && outerIndex !== i) {
8038
+ child.stopAnimation();
8039
+ void child.moveTo(index, 0);
8040
+ void _this.moveTo(i, 0);
8041
+ }
8042
+ });
8043
+ };
8044
+ _this._setDraggable = function (direction, draggable) {
8045
+ if (!_this._disableSlideOnHold) {
8046
+ return;
8047
+ }
8048
+ var threshold = draggable ? _this.dragThreshold && _this.dragThreshold >= 10 ? _this.dragThreshold : 10 : Infinity;
8049
+ if (direction === MOVE_DIRECTION.HORIZONTAL === _this.horizontal) {
8050
+ _this.dragThreshold = threshold;
8051
+ } else if (direction === MOVE_DIRECTION.VERTICAL === _this.horizontal) {
8052
+ _this._sideFlicking.forEach(function (child) {
8053
+ child.dragThreshold = threshold;
8054
+ });
8055
+ }
8056
+ };
8057
+ _this._setPreviousSideIndex = function () {
8058
+ _this._sideFlicking.forEach(function (child, i) {
8059
+ var _a = _this._sideState[i],
8060
+ start = _a.start,
8061
+ end = _a.end;
8062
+ if (_this._preserveIndex) {
8063
+ if (_this._nextIndex !== i) {
8064
+ if (child.index < start) {
8065
+ child.stopAnimation();
8066
+ void child.moveTo(start, 0);
8067
+ } else if (child.index > end) {
8068
+ child.stopAnimation();
8069
+ void child.moveTo(end, 0);
8070
+ }
8071
+ }
8072
+ } else {
8073
+ if (_this._nextIndex !== i) {
8074
+ void child.moveTo(start, 0);
8075
+ }
8076
+ }
8077
+ });
8078
+ };
8014
8079
  _this._onHorizontalHoldStart = function () {
8015
- _this.dragThreshold = 10;
8080
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
8016
8081
  _this._moveDirection = null;
8017
8082
  };
8018
8083
  _this._onHorizontalMove = function (e) {
8019
8084
  if (e.isTrusted && !_this._moveDirection) {
8020
- _this._sideFlicking.forEach(function (child) {
8021
- child.dragThreshold = Infinity;
8022
- });
8085
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
8023
8086
  _this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
8024
8087
  }
8025
8088
  };
8026
8089
  _this._onHorizontalMoveEnd = function (e) {
8027
8090
  var visiblePanels = _this.visiblePanels;
8028
- _this._sideFlicking.forEach(function (child) {
8029
- child.dragThreshold = 10;
8030
- });
8031
- _this._moveDirection = null;
8032
8091
  if (visiblePanels.length > 1) {
8033
8092
  _this._nextIndex = e.direction === "NEXT" ? visiblePanels[1].index : visiblePanels[0].index;
8034
8093
  } else {
8035
8094
  _this._nextIndex = visiblePanels[0].index;
8036
8095
  }
8096
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
8097
+ _this._moveDirection = null;
8037
8098
  // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
8038
8099
  requestAnimationFrame(function () {
8039
- _this._sideFlicking.forEach(function (child, i) {
8040
- if (_this._nextIndex !== i) {
8041
- var _a = _this._sideState[i],
8042
- start = _a.start,
8043
- end = _a.end;
8044
- if (child.index < start) {
8045
- child.stopAnimation();
8046
- void child.moveTo(start, 0);
8047
- } else if (child.index > end) {
8048
- child.stopAnimation();
8049
- void child.moveTo(end, 0);
8050
- }
8051
- }
8052
- });
8100
+ return _this._setPreviousSideIndex();
8053
8101
  });
8054
8102
  if (e.isTrusted) {
8055
8103
  _this._syncToCategory(_this._sideFlicking[_this._nextIndex].index, _this._nextIndex);
8056
8104
  }
8057
8105
  };
8058
8106
  _this._onSideHoldStart = function () {
8059
- _this._sideFlicking.forEach(function (child) {
8060
- child.dragThreshold = 10;
8061
- });
8107
+ _this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
8062
8108
  _this._moveDirection = null;
8063
8109
  };
8064
8110
  _this._onSideMove = function (e) {
8065
8111
  if (e.isTrusted && !_this._moveDirection) {
8066
- _this.dragThreshold = Infinity;
8112
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
8067
8113
  _this._moveDirection = MOVE_DIRECTION.VERTICAL;
8068
8114
  }
8069
8115
  };
8070
8116
  _this._onSideMoveEnd = function () {
8071
- _this.dragThreshold = 10;
8117
+ _this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
8072
8118
  _this._moveDirection = null;
8073
8119
  };
8074
8120
  _this._onSideChanged = function (e) {
8075
- // this.visiblePanels.length 2보다 크다면 가로 방향 Flicking이 조작 중이라는 것을 의미합니다.
8076
- // 경우 가로 방향 Flicking의 이동이 완전히 끝난 _onHorizontalMoveEnd 에서 syncToCategory할 것이므로 여기서는 하지 않습니다.
8121
+ // If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
8122
+ // In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
8077
8123
  if (_this.visiblePanels.length < 2 && _this._sideFlicking[_this.index] === e.currentTarget) {
8078
8124
  _this._syncToCategory(e.index, _this.index);
8079
8125
  }
8080
8126
  };
8127
+ var _a = options.sideOptions,
8128
+ sideOptions = _a === void 0 ? {} : _a,
8129
+ _b = options.preserveIndex,
8130
+ preserveIndex = _b === void 0 ? true : _b,
8131
+ _c = options.disableSlideOnHold,
8132
+ disableSlideOnHold = _c === void 0 ? true : _c,
8133
+ _d = options.disableIndexSync,
8134
+ disableIndexSync = _d === void 0 ? false : _d;
8081
8135
  // Internal states
8082
8136
  _this._moveDirection = null;
8083
8137
  _this._nextIndex = 0;
8084
8138
  // Bind options
8085
- _this._sideOptions = options.sideOptions;
8086
- _this._preserveIndex = options.preserveIndex;
8087
- _this._disableSlideOnHold = options.disableSlideOnHold;
8088
- _this._disableIndexSync = options.disableIndexSync;
8139
+ _this._sideOptions = sideOptions;
8140
+ _this._preserveIndex = preserveIndex;
8141
+ _this._disableSlideOnHold = disableSlideOnHold;
8142
+ _this._disableIndexSync = disableIndexSync;
8089
8143
  return _this;
8090
- // Create core components
8091
8144
  }
8092
8145
  var __proto = CrossFlicking.prototype;
8093
8146
  Object.defineProperty(__proto, "sideFlicking", {
@@ -8156,7 +8209,9 @@ version: 4.12.0-beta.8
8156
8209
  });
8157
8210
  };
8158
8211
  __proto.destroy = function () {
8159
- // TODO 모든 child flicking destroy
8212
+ this._sideFlicking.forEach(function (flicking) {
8213
+ flicking.destroy();
8214
+ });
8160
8215
  _super.prototype.destroy.call(this);
8161
8216
  };
8162
8217
  __proto._addComponentEvents = function () {
@@ -8164,80 +8219,80 @@ version: 4.12.0-beta.8
8164
8219
  this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
8165
8220
  this.on(EVENTS.MOVE, this._onHorizontalMove);
8166
8221
  this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
8167
- this._sideFlicking.forEach(function (flicking) {
8222
+ this._sideFlicking.forEach(function (flicking, mainIndex) {
8168
8223
  flicking.on(EVENTS.HOLD_START, _this._onSideHoldStart);
8169
8224
  flicking.on(EVENTS.MOVE, _this._onSideMove);
8170
8225
  flicking.on(EVENTS.MOVE_END, _this._onSideMoveEnd);
8171
8226
  flicking.on(EVENTS.CHANGED, _this._onSideChanged);
8227
+ Object.keys(SIDE_EVENTS).forEach(function (name) {
8228
+ flicking.on(EVENTS[name], function (event) {
8229
+ _this.trigger(new Component.ComponentEvent(SIDE_EVENTS[name], __assign({
8230
+ mainIndex: mainIndex
8231
+ }, event)));
8232
+ });
8233
+ });
8172
8234
  });
8173
8235
  };
8174
- __proto._getGroupFromAttribute = function (panels) {
8175
- var groupKeys = [];
8176
- var groupPanels = {};
8177
- panels.forEach(function (panel) {
8178
- var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8179
- if (groupKey && !includes(groupKeys, groupKey)) {
8180
- groupKeys.push(groupKey);
8181
- groupPanels[groupKey] = [panel];
8182
- } else if (groupKey) {
8183
- groupPanels[groupKey].push(panel);
8184
- }
8185
- });
8186
- return groupPanels;
8187
- };
8188
8236
  __proto._createSideState = function () {
8189
- var _this = this;
8190
8237
  var viewportEl = this.element;
8191
8238
  var cameraEl = this.camera.element;
8192
8239
  var panels = toArray(cameraEl.children);
8193
- var sideState = [];
8194
- var sidePanels = "";
8195
- // check data attribute exists
8196
- var sideCamera = document.createElement("div");
8197
- sideCamera.classList.add(CLASS.CAMERA);
8198
8240
  var isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
8241
+ var sideState = [];
8199
8242
  if (!isCrossStructure) {
8200
- viewportEl.setAttribute("data-cross-structure", "true");
8201
8243
  var groupPanels = this._getGroupFromAttribute(panels);
8202
8244
  var groupKeys = Object.keys(groupPanels);
8203
8245
  if (groupKeys.length) {
8204
8246
  sideState = this._getSideStateFromGroup(groupPanels);
8205
8247
  this.remove(0, this.panelCount - groupKeys.length);
8206
- sideState.forEach(function (state, i) {
8207
- var panel = _this.camera.children[i];
8208
- sidePanels += state.element.innerHTML;
8209
- Array.from(panel.attributes).forEach(function (attribute) {
8210
- return panel.removeAttribute(attribute.name);
8211
- });
8212
- });
8213
8248
  } else {
8214
- sideState = panels.reduce(function (state, panel, i) {
8215
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8216
- sidePanels += panel.innerHTML;
8217
- return __spread(state, [{
8218
- key: i.toString(),
8219
- start: start,
8220
- end: start + panel.children.length - 1,
8221
- element: panel
8222
- }]);
8223
- }, []);
8249
+ sideState = this._getSideStateFromPanels(panels);
8224
8250
  }
8225
- sideCamera.innerHTML = sidePanels;
8226
- sideState.forEach(function (_, i) {
8227
- var panel = _this.camera.children[i];
8228
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8229
- if (!panel.classList.contains(className)) {
8230
- panel.classList.add(className);
8231
- }
8232
- });
8233
- panel.innerHTML = sideCamera.outerHTML;
8234
- });
8251
+ this._createCrossStructure(sideState);
8235
8252
  } else {
8236
- sideState = this._getSideStateFromPanels(panels);
8253
+ sideState = this._getSideStateFromCrossStructure(panels);
8237
8254
  }
8238
8255
  void this.resize();
8239
8256
  return sideState;
8240
8257
  };
8258
+ __proto._createCrossStructure = function (sideState) {
8259
+ var _this = this;
8260
+ var sideCamera = document.createElement("div");
8261
+ var sidePanels = "";
8262
+ sideCamera.classList.add(CLASS.CAMERA);
8263
+ sideState.forEach(function (state, i) {
8264
+ var panel = _this.camera.children[i];
8265
+ sidePanels += state.element.innerHTML;
8266
+ Array.from(panel.attributes).forEach(function (attribute) {
8267
+ return panel.removeAttribute(attribute.name);
8268
+ });
8269
+ });
8270
+ sideCamera.innerHTML = sidePanels;
8271
+ sideState.forEach(function (_, i) {
8272
+ var panel = _this.camera.children[i];
8273
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8274
+ if (!panel.classList.contains(className)) {
8275
+ panel.classList.add(className);
8276
+ }
8277
+ });
8278
+ panel.innerHTML = sideCamera.outerHTML;
8279
+ });
8280
+ this.element.setAttribute("data-cross-structure", "true");
8281
+ };
8282
+ __proto._getGroupFromAttribute = function (panels) {
8283
+ var groupKeys = [];
8284
+ var groupPanels = {};
8285
+ panels.forEach(function (panel) {
8286
+ var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8287
+ if (groupKey && !includes(groupKeys, groupKey)) {
8288
+ groupKeys.push(groupKey);
8289
+ groupPanels[groupKey] = [panel];
8290
+ } else if (groupKey) {
8291
+ groupPanels[groupKey].push(panel);
8292
+ }
8293
+ });
8294
+ return groupPanels;
8295
+ };
8241
8296
  __proto._getSideStateFromGroup = function (groupPanels) {
8242
8297
  return Object.keys(groupPanels).reduce(function (state, key) {
8243
8298
  var start = state.length ? +state[state.length - 1].end + 1 : 0;
@@ -8254,6 +8309,17 @@ version: 4.12.0-beta.8
8254
8309
  }, []);
8255
8310
  };
8256
8311
  __proto._getSideStateFromPanels = function (panels) {
8312
+ return panels.reduce(function (state, panel, i) {
8313
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8314
+ return __spread(state, [{
8315
+ key: i.toString(),
8316
+ start: start,
8317
+ end: start + panel.children.length - 1,
8318
+ element: panel
8319
+ }]);
8320
+ }, []);
8321
+ };
8322
+ __proto._getSideStateFromCrossStructure = function (panels) {
8257
8323
  var groupPanels = this._getGroupFromAttribute(panels);
8258
8324
  return this._getSideStateFromGroup(groupPanels);
8259
8325
  };
@@ -8263,30 +8329,16 @@ version: 4.12.0-beta.8
8263
8329
  return new Flicking(_this.camera.children[i], __assign(__assign({}, _this.sideOptions), {
8264
8330
  horizontal: false,
8265
8331
  panelsPerView: 1,
8266
- defaultIndex: state.start,
8267
- moveType: "strict"
8332
+ defaultIndex: state.start
8268
8333
  }));
8269
8334
  });
8270
8335
  };
8271
- __proto._syncToCategory = function (index, outerIndex) {
8272
- var _this = this;
8273
- this.stopAnimation();
8274
- this._sideFlicking.forEach(function (child, i) {
8275
- var _a = _this._sideState[i],
8276
- start = _a.start,
8277
- end = _a.end;
8278
- if (start <= index && end >= index && outerIndex !== i) {
8279
- child.stopAnimation();
8280
- void child.moveTo(index, 0);
8281
- void _this.moveTo(i, 0);
8282
- }
8283
- });
8284
- };
8285
8336
  return CrossFlicking;
8286
8337
  }(Flicking);
8287
8338
 
8288
8339
  var CrossFlicking$1 = {
8289
8340
  __proto__: null,
8341
+ SIDE_EVENTS: SIDE_EVENTS,
8290
8342
  CrossFlicking: CrossFlicking
8291
8343
  };
8292
8344