@egjs/flicking 4.12.0-beta.2 → 4.12.0-beta.3

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.2
7
+ version: 4.12.0-beta.3
8
8
  */
9
9
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -1160,6 +1160,26 @@ version: 4.12.0-beta.2
1160
1160
  obj.__proto__ = proto;
1161
1161
  return obj;
1162
1162
  };
1163
+ var camelize = function (str) {
1164
+ return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
1165
+ return letter.toUpperCase();
1166
+ });
1167
+ };
1168
+ var getDataAttributes = function (element, attributePrefix) {
1169
+ var dataAttributes = {};
1170
+ var attributes = element.attributes;
1171
+ var length = attributes.length;
1172
+ for (var i = 0; i < length; ++i) {
1173
+ var attribute = attributes[i];
1174
+ var name_1 = attribute.name,
1175
+ value = attribute.value;
1176
+ if (name_1.indexOf(attributePrefix) === -1) {
1177
+ continue;
1178
+ }
1179
+ dataAttributes[camelize(name_1.replace(attributePrefix, ""))] = value;
1180
+ }
1181
+ return dataAttributes;
1182
+ };
1163
1183
 
1164
1184
  var Utils = {
1165
1185
  __proto__: null,
@@ -1191,7 +1211,9 @@ version: 4.12.0-beta.2
1191
1211
  circulateIndex: circulateIndex,
1192
1212
  range: range,
1193
1213
  getElementSize: getElementSize,
1194
- setPrototypeOf: setPrototypeOf
1214
+ setPrototypeOf: setPrototypeOf,
1215
+ camelize: camelize,
1216
+ getDataAttributes: getDataAttributes
1195
1217
  };
1196
1218
 
1197
1219
  /*
@@ -13004,7 +13026,7 @@ version: 4.12.0-beta.2
13004
13026
  * Flicking.VERSION; // ex) 4.0.0
13005
13027
  * ```
13006
13028
  */
13007
- Flicking.VERSION = "4.12.0-beta.2";
13029
+ Flicking.VERSION = "4.12.0-beta.3";
13008
13030
  return Flicking;
13009
13031
  }(Component);
13010
13032
 
@@ -13092,15 +13114,14 @@ version: 4.12.0-beta.2
13092
13114
  _this._syncToCategory(e.index, _this.index);
13093
13115
  }
13094
13116
  };
13095
- var horizontalPanels = toArray$2(getElement(root).children[0].children);
13096
13117
  // Internal states
13097
- _this._verticalState = _this._createVerticalState(horizontalPanels);
13118
+ _this._verticalState = _this._createVerticalState();
13098
13119
  _this._moveDirection = null;
13099
13120
  _this._nextIndex = 0;
13100
13121
  // Bind options
13101
13122
  _this._verticalOptions = verticalOptions;
13102
13123
  // Create core components
13103
- _this._verticalFlicking = _this._createVerticalFlicking(horizontalPanels);
13124
+ _this._verticalFlicking = _this._createVerticalFlicking();
13104
13125
  return _this;
13105
13126
  }
13106
13127
  var __proto = CrossFlicking.prototype;
@@ -13182,36 +13203,82 @@ version: 4.12.0-beta.2
13182
13203
  flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
13183
13204
  });
13184
13205
  };
13185
- __proto._createVerticalState = function (panels) {
13206
+ __proto._createVerticalState = function () {
13207
+ var _this = this;
13186
13208
  // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
13187
13209
  // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
13188
13210
  // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
13211
+ var cameraEl = this.camera.element;
13212
+ var panels = toArray$2(cameraEl.children);
13213
+ var verticalState;
13189
13214
  var verticalPanels = "";
13190
- var verticalState = panels.reduce(function (state, panel) {
13191
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
13192
- verticalPanels += panel.innerHTML;
13193
- return __spread$1(state, [{
13194
- start: start,
13195
- end: start + panel.children.length - 1,
13196
- element: panel
13197
- }]);
13198
- }, []);
13215
+ // check data attribute exists
13216
+ var groupKeys = [];
13217
+ var groupPanels = {};
13199
13218
  var verticalCamera = document.createElement("div");
13200
13219
  verticalCamera.classList.add(CLASS.CAMERA);
13201
- verticalCamera.innerHTML = verticalPanels;
13202
13220
  panels.forEach(function (panel) {
13203
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
13204
- if (!panel.classList.contains(className)) {
13205
- panel.classList.add(className);
13206
- }
13207
- });
13208
- panel.innerHTML = verticalCamera.outerHTML;
13221
+ var groupKey = getDataAttributes(panel, "data-flicking-").groupkey;
13222
+ if (groupKey && !includes(groupKeys, groupKey)) {
13223
+ groupKeys.push(groupKey);
13224
+ groupPanels[groupKey] = [panel];
13225
+ } else if (groupKey) {
13226
+ groupPanels[groupKey].push(panel);
13227
+ }
13228
+ return groupKey;
13209
13229
  });
13230
+ if (groupKeys.length) {
13231
+ panels.forEach(function () {
13232
+ return _this.remove(0);
13233
+ });
13234
+ verticalState = groupKeys.reduce(function (state, key) {
13235
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
13236
+ var element = groupPanels[key].reduce(function (el, panel) {
13237
+ verticalPanels += panel.outerHTML;
13238
+ el.appendChild(panel);
13239
+ return el;
13240
+ }, document.createElement("div"));
13241
+ return __spread$1(state, [{
13242
+ key: key,
13243
+ start: start,
13244
+ end: start + groupPanels[key].length - 1,
13245
+ element: element
13246
+ }]);
13247
+ }, []);
13248
+ verticalCamera.innerHTML = verticalPanels;
13249
+ cameraEl.innerHTML = "";
13250
+ groupKeys.forEach(function () {
13251
+ var panel = document.createElement("div");
13252
+ panel.classList.add(CLASS.VIEWPORT, CLASS.VERTICAL);
13253
+ panel.innerHTML = verticalCamera.outerHTML;
13254
+ _this.append(panel);
13255
+ });
13256
+ } else {
13257
+ verticalState = panels.reduce(function (state, panel, i) {
13258
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
13259
+ verticalPanels += panel.innerHTML;
13260
+ return __spread$1(state, [{
13261
+ key: i.toString(),
13262
+ start: start,
13263
+ end: start + panel.children.length - 1,
13264
+ element: panel
13265
+ }]);
13266
+ }, []);
13267
+ verticalCamera.innerHTML = verticalPanels;
13268
+ panels.forEach(function (panel) {
13269
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
13270
+ if (!panel.classList.contains(className)) {
13271
+ panel.classList.add(className);
13272
+ }
13273
+ });
13274
+ panel.innerHTML = verticalCamera.outerHTML;
13275
+ });
13276
+ }
13210
13277
  return verticalState;
13211
13278
  };
13212
- __proto._createVerticalFlicking = function (panels) {
13279
+ __proto._createVerticalFlicking = function () {
13213
13280
  var _this = this;
13214
- return panels.map(function (panel, i) {
13281
+ return this.camera.children.map(function (panel, i) {
13215
13282
  return new Flicking(panel, __assign$2(__assign$2({}, _this.verticalOptions), {
13216
13283
  horizontal: false,
13217
13284
  panelsPerView: 1,