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