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

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.7
7
+ version: 4.12.0-beta.8
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -7893,7 +7893,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7893
7893
  * Flicking.VERSION; // ex) 4.0.0
7894
7894
  * ```
7895
7895
  */
7896
- Flicking.VERSION = "4.12.0-beta.7";
7896
+ Flicking.VERSION = "4.12.0-beta.8";
7897
7897
  return Flicking;
7898
7898
  }(Component);
7899
7899
 
@@ -7901,21 +7901,16 @@ var Flicking = /*#__PURE__*/function (_super) {
7901
7901
  * Copyright (c) 2015 NAVER Corp.
7902
7902
  * egjs projects are licensed under the MIT license
7903
7903
  */
7904
- /**
7905
- * @extends Component
7906
- * @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
7907
- * @requires {@link https://github.com/naver/egjs-component|@egjs/component}
7908
- * @requires {@link https://github.com/naver/egjs-axes|@egjs/axes}
7909
- */
7910
7904
  var CrossFlicking = /*#__PURE__*/function (_super) {
7911
7905
  __extends(CrossFlicking, _super);
7912
- // Options Setter
7913
- // public set align(val: FlickingOptions["align"]) {
7914
- // this._align = val;
7915
- // }
7916
7906
  function CrossFlicking(root, options) {
7917
7907
  if (options === void 0) {
7918
- options = {};
7908
+ options = {
7909
+ sideOptions: {},
7910
+ preserveIndex: false,
7911
+ disableSlideOnHold: false,
7912
+ disableIndexSync: false
7913
+ };
7919
7914
  }
7920
7915
  var _this = _super.call(this, root, options) || this;
7921
7916
  _this._onHorizontalHoldStart = function () {
@@ -7941,20 +7936,22 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
7941
7936
  } else {
7942
7937
  _this._nextIndex = visiblePanels[0].index;
7943
7938
  }
7944
- // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 timeout으로 처리
7945
- _this._sideFlicking.forEach(function (child, i) {
7946
- if (_this._nextIndex !== i) {
7947
- var _a = _this._sideState[i],
7948
- start = _a.start,
7949
- end = _a.end;
7950
- if (child.index < start) {
7951
- child.stopAnimation();
7952
- void child.moveTo(start, 0);
7953
- } else if (child.index > end) {
7954
- child.stopAnimation();
7955
- void child.moveTo(end, 0);
7939
+ // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
7940
+ requestAnimationFrame(function () {
7941
+ _this._sideFlicking.forEach(function (child, i) {
7942
+ if (_this._nextIndex !== i) {
7943
+ var _a = _this._sideState[i],
7944
+ start = _a.start,
7945
+ end = _a.end;
7946
+ if (child.index < start) {
7947
+ child.stopAnimation();
7948
+ void child.moveTo(start, 0);
7949
+ } else if (child.index > end) {
7950
+ child.stopAnimation();
7951
+ void child.moveTo(end, 0);
7952
+ }
7956
7953
  }
7957
- }
7954
+ });
7958
7955
  });
7959
7956
  if (e.isTrusted) {
7960
7957
  _this._syncToCategory(_this._sideFlicking[_this._nextIndex].index, _this._nextIndex);
@@ -7984,28 +7981,19 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
7984
7981
  }
7985
7982
  };
7986
7983
  // Internal states
7987
- _this._sideState = _this._createSideState();
7988
7984
  _this._moveDirection = null;
7989
7985
  _this._nextIndex = 0;
7990
7986
  // Bind options
7991
7987
  _this._sideOptions = options.sideOptions;
7992
- // Create core components
7993
- _this._sideFlicking = _this._createSideFlicking();
7988
+ _this._preserveIndex = options.preserveIndex;
7989
+ _this._disableSlideOnHold = options.disableSlideOnHold;
7990
+ _this._disableIndexSync = options.disableIndexSync;
7994
7991
  return _this;
7992
+ // Create core components
7995
7993
  }
7996
7994
  var __proto = CrossFlicking.prototype;
7997
7995
  Object.defineProperty(__proto, "sideFlicking", {
7998
7996
  // Components
7999
- /**
8000
- * {@link Control} instance of the Flicking
8001
- * @ko 현재 Flicking에 활성화된 {@link Control} 인스턴스
8002
- * @type {Control}
8003
- * @default SnapControl
8004
- * @readonly
8005
- * @see Control
8006
- * @see SnapControl
8007
- * @see FreeControl
8008
- */
8009
7997
  get: function () {
8010
7998
  return this._sideFlicking;
8011
7999
  },
@@ -8013,16 +8001,6 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8013
8001
  configurable: true
8014
8002
  });
8015
8003
  Object.defineProperty(__proto, "sideState", {
8016
- // Internal States
8017
- /**
8018
- * Whether Flicking's {@link Flicking#init init()} is called.
8019
- * This is `true` when {@link Flicking#init init()} is called, and is `false` after calling {@link Flicking#destroy destroy()}.
8020
- * @ko Flicking의 {@link Flicking#init init()}이 호출되었는지를 나타내는 멤버 변수.
8021
- * 이 값은 {@link Flicking#init init()}이 호출되었으면 `true`로 변하고, {@link Flicking#destroy destroy()}호출 이후에 다시 `false`로 변경됩니다.
8022
- * @type {boolean}
8023
- * @default false
8024
- * @readonly
8025
- */
8026
8004
  get: function () {
8027
8005
  return this._sideState;
8028
8006
  },
@@ -8031,40 +8009,54 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8031
8009
  });
8032
8010
  Object.defineProperty(__proto, "sideOptions", {
8033
8011
  // Options Getter
8034
- /**
8035
- * Change active panel index on mouse/touch hold while animating.
8036
- * `index` of the `willChange`/`willRestore` event will be used as new index.
8037
- * @ko 애니메이션 도중 마우스/터치 입력시 현재 활성화된 패널의 인덱스를 변경합니다.
8038
- * `willChange`/`willRestore` 이벤트의 `index`값이 새로운 인덱스로 사용될 것입니다.
8039
- * @type {FlickingOptions}
8040
- * @default undefined
8041
- * @see {@link https://naver.github.io/egjs-flicking/Options#changeonhold changeOnHold ( Options )}
8042
- */
8043
8012
  get: function () {
8044
8013
  return this._sideOptions;
8045
8014
  },
8015
+ // Options Setter
8016
+ set: function (val) {
8017
+ this._sideOptions = val;
8018
+ },
8019
+ enumerable: false,
8020
+ configurable: true
8021
+ });
8022
+ Object.defineProperty(__proto, "preserveIndex", {
8023
+ get: function () {
8024
+ return this._preserveIndex;
8025
+ },
8026
+ set: function (val) {
8027
+ this._preserveIndex = val;
8028
+ },
8029
+ enumerable: false,
8030
+ configurable: true
8031
+ });
8032
+ Object.defineProperty(__proto, "disableSlideOnHold", {
8033
+ get: function () {
8034
+ return this._disableSlideOnHold;
8035
+ },
8036
+ set: function (val) {
8037
+ this._disableSlideOnHold = val;
8038
+ },
8039
+ enumerable: false,
8040
+ configurable: true
8041
+ });
8042
+ Object.defineProperty(__proto, "disableIndexSync", {
8043
+ get: function () {
8044
+ return this._disableIndexSync;
8045
+ },
8046
+ set: function (val) {
8047
+ this._disableIndexSync = val;
8048
+ },
8046
8049
  enumerable: false,
8047
8050
  configurable: true
8048
8051
  });
8049
- /**
8050
- * Initialize Flicking and move to the default index
8051
- * This is automatically called on Flicking's constructor when `autoInit` is true(default)
8052
- * @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
8053
- * 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
8054
- * @fires Flicking#ready
8055
- * @return {Promise<void>}
8056
- */
8057
8052
  __proto.init = function () {
8058
8053
  var _this = this;
8059
8054
  return _super.prototype.init.call(this).then(function () {
8060
- return _this._addComponentEvents();
8055
+ _this._sideState = _this._createSideState();
8056
+ _this._sideFlicking = _this._createSideFlicking();
8057
+ _this._addComponentEvents();
8061
8058
  });
8062
8059
  };
8063
- /**
8064
- * Destroy Flicking and remove all event handlers
8065
- * @ko Flicking과 하위 컴포넌트들을 초기 상태로 되돌리고, 부착된 모든 이벤트 핸들러를 제거합니다
8066
- * @return {void}
8067
- */
8068
8060
  __proto.destroy = function () {
8069
8061
  // TODO 모든 child flicking destroy
8070
8062
  _super.prototype.destroy.call(this);
@@ -8081,51 +8073,41 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8081
8073
  flicking.on(EVENTS.CHANGED, _this._onSideChanged);
8082
8074
  });
8083
8075
  };
8076
+ __proto._getGroupFromAttribute = function (panels) {
8077
+ var groupKeys = [];
8078
+ var groupPanels = {};
8079
+ panels.forEach(function (panel) {
8080
+ var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8081
+ if (groupKey && !includes(groupKeys, groupKey)) {
8082
+ groupKeys.push(groupKey);
8083
+ groupPanels[groupKey] = [panel];
8084
+ } else if (groupKey) {
8085
+ groupPanels[groupKey].push(panel);
8086
+ }
8087
+ });
8088
+ return groupPanels;
8089
+ };
8084
8090
  __proto._createSideState = function () {
8085
8091
  var _this = this;
8086
- // data-index로 분류하기 전에 임시로 모든 children에 대해 side flicking으로 해보자.
8087
- // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8088
- // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8089
8092
  var viewportEl = this.element;
8090
8093
  var cameraEl = this.camera.element;
8091
8094
  var panels = toArray(cameraEl.children);
8092
8095
  var sideState = [];
8093
8096
  var sidePanels = "";
8094
8097
  // check data attribute exists
8095
- var groupKeys = [];
8096
- var groupPanels = {};
8097
8098
  var sideCamera = document.createElement("div");
8098
8099
  sideCamera.classList.add(CLASS.CAMERA);
8099
8100
  var isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
8100
8101
  if (!isCrossStructure) {
8101
8102
  viewportEl.setAttribute("data-cross-structure", "true");
8102
- panels.forEach(function (panel) {
8103
- var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8104
- if (groupKey && !includes(groupKeys, groupKey)) {
8105
- groupKeys.push(groupKey);
8106
- groupPanels[groupKey] = [panel];
8107
- } else if (groupKey) {
8108
- groupPanels[groupKey].push(panel);
8109
- }
8110
- });
8103
+ var groupPanels = this._getGroupFromAttribute(panels);
8104
+ var groupKeys = Object.keys(groupPanels);
8111
8105
  if (groupKeys.length) {
8112
- sideState = groupKeys.reduce(function (state, key) {
8113
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8114
- var element = groupPanels[key].reduce(function (el, panel) {
8115
- sidePanels += panel.outerHTML;
8116
- el.innerHTML += panel.outerHTML;
8117
- return el;
8118
- }, document.createElement("div"));
8119
- return __spread(state, [{
8120
- key: key,
8121
- start: start,
8122
- end: start + groupPanels[key].length - 1,
8123
- element: element
8124
- }]);
8125
- }, []);
8106
+ sideState = this._getSideStateFromGroup(groupPanels);
8126
8107
  this.remove(0, this.panelCount - groupKeys.length);
8127
- sideState.forEach(function (_, i) {
8108
+ sideState.forEach(function (state, i) {
8128
8109
  var panel = _this.camera.children[i];
8110
+ sidePanels += state.element.innerHTML;
8129
8111
  Array.from(panel.attributes).forEach(function (attribute) {
8130
8112
  return panel.removeAttribute(attribute.name);
8131
8113
  });
@@ -8153,38 +8135,38 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8153
8135
  panel.innerHTML = sideCamera.outerHTML;
8154
8136
  });
8155
8137
  } else {
8156
- toArray(panels[0].children[0].children).forEach(function (panel) {
8157
- var groupKey = getDataAttributes(panel, "data-cross-").groupkey;
8158
- if (groupKey && !includes(groupKeys, groupKey)) {
8159
- groupKeys.push(groupKey);
8160
- groupPanels[groupKey] = [panel];
8161
- } else if (groupKey) {
8162
- groupPanels[groupKey].push(panel);
8163
- }
8164
- });
8165
- sideState = groupKeys.reduce(function (state, key) {
8166
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8167
- var element = groupPanels[key].reduce(function (el, panel) {
8168
- el.innerHTML += panel.outerHTML;
8169
- return el;
8170
- }, document.createElement("div"));
8171
- return __spread(state, [{
8172
- key: key,
8173
- start: start,
8174
- end: start + groupPanels[key].length - 1,
8175
- element: element
8176
- }]);
8177
- }, []);
8138
+ sideState = this._getSideStateFromPanels(panels);
8178
8139
  }
8140
+ void this.resize();
8179
8141
  return sideState;
8180
8142
  };
8143
+ __proto._getSideStateFromGroup = function (groupPanels) {
8144
+ return Object.keys(groupPanels).reduce(function (state, key) {
8145
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8146
+ var element = groupPanels[key].reduce(function (el, panel) {
8147
+ el.innerHTML += panel.outerHTML;
8148
+ return el;
8149
+ }, document.createElement("div"));
8150
+ return __spread(state, [{
8151
+ key: key,
8152
+ start: start,
8153
+ end: start + groupPanels[key].length - 1,
8154
+ element: element
8155
+ }]);
8156
+ }, []);
8157
+ };
8158
+ __proto._getSideStateFromPanels = function (panels) {
8159
+ var groupPanels = this._getGroupFromAttribute(panels);
8160
+ return this._getSideStateFromGroup(groupPanels);
8161
+ };
8181
8162
  __proto._createSideFlicking = function () {
8182
8163
  var _this = this;
8183
8164
  return this.sideState.map(function (state, i) {
8184
8165
  return new Flicking(_this.camera.children[i], __assign(__assign({}, _this.sideOptions), {
8185
8166
  horizontal: false,
8186
8167
  panelsPerView: 1,
8187
- defaultIndex: state.start
8168
+ defaultIndex: state.start,
8169
+ moveType: "strict"
8188
8170
  }));
8189
8171
  });
8190
8172
  };