@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
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -738,6 +738,26 @@ var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
738
738
  obj.__proto__ = proto;
739
739
  return obj;
740
740
  };
741
+ var camelize = function (str) {
742
+ return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
743
+ return letter.toUpperCase();
744
+ });
745
+ };
746
+ var getDataAttributes = function (element, attributePrefix) {
747
+ var dataAttributes = {};
748
+ var attributes = element.attributes;
749
+ var length = attributes.length;
750
+ for (var i = 0; i < length; ++i) {
751
+ var attribute = attributes[i];
752
+ var name_1 = attribute.name,
753
+ value = attribute.value;
754
+ if (name_1.indexOf(attributePrefix) === -1) {
755
+ continue;
756
+ }
757
+ dataAttributes[camelize(name_1.replace(attributePrefix, ""))] = value;
758
+ }
759
+ return dataAttributes;
760
+ };
741
761
 
742
762
  /*
743
763
  * Copyright (c) 2015 NAVER Corp.
@@ -7873,7 +7893,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7873
7893
  * Flicking.VERSION; // ex) 4.0.0
7874
7894
  * ```
7875
7895
  */
7876
- Flicking.VERSION = "4.12.0-beta.2";
7896
+ Flicking.VERSION = "4.12.0-beta.3";
7877
7897
  return Flicking;
7878
7898
  }(Component);
7879
7899
 
@@ -7961,15 +7981,14 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
7961
7981
  _this._syncToCategory(e.index, _this.index);
7962
7982
  }
7963
7983
  };
7964
- var horizontalPanels = toArray(getElement(root).children[0].children);
7965
7984
  // Internal states
7966
- _this._verticalState = _this._createVerticalState(horizontalPanels);
7985
+ _this._verticalState = _this._createVerticalState();
7967
7986
  _this._moveDirection = null;
7968
7987
  _this._nextIndex = 0;
7969
7988
  // Bind options
7970
7989
  _this._verticalOptions = verticalOptions;
7971
7990
  // Create core components
7972
- _this._verticalFlicking = _this._createVerticalFlicking(horizontalPanels);
7991
+ _this._verticalFlicking = _this._createVerticalFlicking();
7973
7992
  return _this;
7974
7993
  }
7975
7994
  var __proto = CrossFlicking.prototype;
@@ -8051,36 +8070,82 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8051
8070
  flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
8052
8071
  });
8053
8072
  };
8054
- __proto._createVerticalState = function (panels) {
8073
+ __proto._createVerticalState = function () {
8074
+ var _this = this;
8055
8075
  // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8056
8076
  // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8057
8077
  // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8078
+ var cameraEl = this.camera.element;
8079
+ var panels = toArray(cameraEl.children);
8080
+ var verticalState;
8058
8081
  var verticalPanels = "";
8059
- var verticalState = panels.reduce(function (state, panel) {
8060
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8061
- verticalPanels += panel.innerHTML;
8062
- return __spread(state, [{
8063
- start: start,
8064
- end: start + panel.children.length - 1,
8065
- element: panel
8066
- }]);
8067
- }, []);
8082
+ // check data attribute exists
8083
+ var groupKeys = [];
8084
+ var groupPanels = {};
8068
8085
  var verticalCamera = document.createElement("div");
8069
8086
  verticalCamera.classList.add(CLASS.CAMERA);
8070
- verticalCamera.innerHTML = verticalPanels;
8071
8087
  panels.forEach(function (panel) {
8072
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8073
- if (!panel.classList.contains(className)) {
8074
- panel.classList.add(className);
8075
- }
8076
- });
8077
- panel.innerHTML = verticalCamera.outerHTML;
8088
+ var groupKey = getDataAttributes(panel, "data-flicking-").groupkey;
8089
+ if (groupKey && !includes(groupKeys, groupKey)) {
8090
+ groupKeys.push(groupKey);
8091
+ groupPanels[groupKey] = [panel];
8092
+ } else if (groupKey) {
8093
+ groupPanels[groupKey].push(panel);
8094
+ }
8095
+ return groupKey;
8078
8096
  });
8097
+ if (groupKeys.length) {
8098
+ panels.forEach(function () {
8099
+ return _this.remove(0);
8100
+ });
8101
+ verticalState = groupKeys.reduce(function (state, key) {
8102
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8103
+ var element = groupPanels[key].reduce(function (el, panel) {
8104
+ verticalPanels += panel.outerHTML;
8105
+ el.appendChild(panel);
8106
+ return el;
8107
+ }, document.createElement("div"));
8108
+ return __spread(state, [{
8109
+ key: key,
8110
+ start: start,
8111
+ end: start + groupPanels[key].length - 1,
8112
+ element: element
8113
+ }]);
8114
+ }, []);
8115
+ verticalCamera.innerHTML = verticalPanels;
8116
+ cameraEl.innerHTML = "";
8117
+ groupKeys.forEach(function () {
8118
+ var panel = document.createElement("div");
8119
+ panel.classList.add(CLASS.VIEWPORT, CLASS.VERTICAL);
8120
+ panel.innerHTML = verticalCamera.outerHTML;
8121
+ _this.append(panel);
8122
+ });
8123
+ } else {
8124
+ verticalState = panels.reduce(function (state, panel, i) {
8125
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8126
+ verticalPanels += panel.innerHTML;
8127
+ return __spread(state, [{
8128
+ key: i.toString(),
8129
+ start: start,
8130
+ end: start + panel.children.length - 1,
8131
+ element: panel
8132
+ }]);
8133
+ }, []);
8134
+ verticalCamera.innerHTML = verticalPanels;
8135
+ panels.forEach(function (panel) {
8136
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8137
+ if (!panel.classList.contains(className)) {
8138
+ panel.classList.add(className);
8139
+ }
8140
+ });
8141
+ panel.innerHTML = verticalCamera.outerHTML;
8142
+ });
8143
+ }
8079
8144
  return verticalState;
8080
8145
  };
8081
- __proto._createVerticalFlicking = function (panels) {
8146
+ __proto._createVerticalFlicking = function () {
8082
8147
  var _this = this;
8083
- return panels.map(function (panel, i) {
8148
+ return this.camera.children.map(function (panel, i) {
8084
8149
  return new Flicking(panel, __assign(__assign({}, _this.verticalOptions), {
8085
8150
  horizontal: false,
8086
8151
  panelsPerView: 1,
@@ -8319,5 +8384,5 @@ var parseAlign = function (alignVal) {
8319
8384
  * egjs projects are licensed under the MIT license
8320
8385
  */
8321
8386
 
8322
- export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, CrossFlicking, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_DIRECTION, MOVE_TYPE, NormalRenderingStrategy, ORDER, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8387
+ export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCameraMode, CIRCULAR_FALLBACK, CLASS, Camera, CircularCameraMode, Control, CrossFlicking, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCameraMode, MOVE_DIRECTION, MOVE_TYPE, NormalRenderingStrategy, ORDER, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaElementProvider, VanillaRenderer, Viewport, VirtualElementProvider, VirtualManager, VirtualPanel, VirtualRenderingStrategy, camelize, checkExistence, circulateIndex, circulatePosition, clamp, Flicking as default, find, findIndex, findRight, getDataAttributes, getDefaultCameraTransform, getDirection, getElement, getElementSize, getFlickingAttached, getMinusCompensatedIndex, getProgress, getRenderingPanels, getStyle, includes, isBetween, isString, merge, parseAlign$1 as parseAlign, parseArithmeticExpression, parseArithmeticSize, parseBounce, parseCSSSizeValue, parseElement, parsePanelAlign, range, setPrototypeOf, setSize, sync, toArray, withFlickingMethods };
8323
8388
  //# sourceMappingURL=flicking.esm.js.map