@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.
@@ -5,6 +5,7 @@ export interface CrossFlickingOptions {
5
5
  verticalOptions: FlickingOptions | undefined;
6
6
  }
7
7
  export interface VerticalState {
8
+ key: string;
8
9
  start: number;
9
10
  end: number;
10
11
  element: HTMLElement;
@@ -43,3 +43,5 @@ export declare const getElementSize: ({ el, horizontal, useFractionalSize, useOf
43
43
  style: CSSStyleDeclaration;
44
44
  }) => number;
45
45
  export declare const setPrototypeOf: (o: any, proto: object) => any;
46
+ export declare const camelize: (str: string) => string;
47
+ export declare const getDataAttributes: (element: HTMLElement, attributePrefix: string) => Record<string, string>;
@@ -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
  'use strict';
10
10
 
@@ -740,6 +740,26 @@ var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
740
740
  obj.__proto__ = proto;
741
741
  return obj;
742
742
  };
743
+ var camelize = function (str) {
744
+ return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
745
+ return letter.toUpperCase();
746
+ });
747
+ };
748
+ var getDataAttributes = function (element, attributePrefix) {
749
+ var dataAttributes = {};
750
+ var attributes = element.attributes;
751
+ var length = attributes.length;
752
+ for (var i = 0; i < length; ++i) {
753
+ var attribute = attributes[i];
754
+ var name_1 = attribute.name,
755
+ value = attribute.value;
756
+ if (name_1.indexOf(attributePrefix) === -1) {
757
+ continue;
758
+ }
759
+ dataAttributes[camelize(name_1.replace(attributePrefix, ""))] = value;
760
+ }
761
+ return dataAttributes;
762
+ };
743
763
 
744
764
  /*
745
765
  * Copyright (c) 2015 NAVER Corp.
@@ -7875,7 +7895,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7875
7895
  * Flicking.VERSION; // ex) 4.0.0
7876
7896
  * ```
7877
7897
  */
7878
- Flicking.VERSION = "4.12.0-beta.2";
7898
+ Flicking.VERSION = "4.12.0-beta.3";
7879
7899
  return Flicking;
7880
7900
  }(Component);
7881
7901
 
@@ -7963,15 +7983,14 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
7963
7983
  _this._syncToCategory(e.index, _this.index);
7964
7984
  }
7965
7985
  };
7966
- var horizontalPanels = toArray(getElement(root).children[0].children);
7967
7986
  // Internal states
7968
- _this._verticalState = _this._createVerticalState(horizontalPanels);
7987
+ _this._verticalState = _this._createVerticalState();
7969
7988
  _this._moveDirection = null;
7970
7989
  _this._nextIndex = 0;
7971
7990
  // Bind options
7972
7991
  _this._verticalOptions = verticalOptions;
7973
7992
  // Create core components
7974
- _this._verticalFlicking = _this._createVerticalFlicking(horizontalPanels);
7993
+ _this._verticalFlicking = _this._createVerticalFlicking();
7975
7994
  return _this;
7976
7995
  }
7977
7996
  var __proto = CrossFlicking.prototype;
@@ -8053,36 +8072,82 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8053
8072
  flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
8054
8073
  });
8055
8074
  };
8056
- __proto._createVerticalState = function (panels) {
8075
+ __proto._createVerticalState = function () {
8076
+ var _this = this;
8057
8077
  // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8058
8078
  // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8059
8079
  // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8080
+ var cameraEl = this.camera.element;
8081
+ var panels = toArray(cameraEl.children);
8082
+ var verticalState;
8060
8083
  var verticalPanels = "";
8061
- var verticalState = panels.reduce(function (state, panel) {
8062
- var start = state.length ? +state[state.length - 1].end + 1 : 0;
8063
- verticalPanels += panel.innerHTML;
8064
- return __spread(state, [{
8065
- start: start,
8066
- end: start + panel.children.length - 1,
8067
- element: panel
8068
- }]);
8069
- }, []);
8084
+ // check data attribute exists
8085
+ var groupKeys = [];
8086
+ var groupPanels = {};
8070
8087
  var verticalCamera = document.createElement("div");
8071
8088
  verticalCamera.classList.add(CLASS.CAMERA);
8072
- verticalCamera.innerHTML = verticalPanels;
8073
8089
  panels.forEach(function (panel) {
8074
- [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8075
- if (!panel.classList.contains(className)) {
8076
- panel.classList.add(className);
8077
- }
8078
- });
8079
- panel.innerHTML = verticalCamera.outerHTML;
8090
+ var groupKey = getDataAttributes(panel, "data-flicking-").groupkey;
8091
+ if (groupKey && !includes(groupKeys, groupKey)) {
8092
+ groupKeys.push(groupKey);
8093
+ groupPanels[groupKey] = [panel];
8094
+ } else if (groupKey) {
8095
+ groupPanels[groupKey].push(panel);
8096
+ }
8097
+ return groupKey;
8080
8098
  });
8099
+ if (groupKeys.length) {
8100
+ panels.forEach(function () {
8101
+ return _this.remove(0);
8102
+ });
8103
+ verticalState = groupKeys.reduce(function (state, key) {
8104
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8105
+ var element = groupPanels[key].reduce(function (el, panel) {
8106
+ verticalPanels += panel.outerHTML;
8107
+ el.appendChild(panel);
8108
+ return el;
8109
+ }, document.createElement("div"));
8110
+ return __spread(state, [{
8111
+ key: key,
8112
+ start: start,
8113
+ end: start + groupPanels[key].length - 1,
8114
+ element: element
8115
+ }]);
8116
+ }, []);
8117
+ verticalCamera.innerHTML = verticalPanels;
8118
+ cameraEl.innerHTML = "";
8119
+ groupKeys.forEach(function () {
8120
+ var panel = document.createElement("div");
8121
+ panel.classList.add(CLASS.VIEWPORT, CLASS.VERTICAL);
8122
+ panel.innerHTML = verticalCamera.outerHTML;
8123
+ _this.append(panel);
8124
+ });
8125
+ } else {
8126
+ verticalState = panels.reduce(function (state, panel, i) {
8127
+ var start = state.length ? +state[state.length - 1].end + 1 : 0;
8128
+ verticalPanels += panel.innerHTML;
8129
+ return __spread(state, [{
8130
+ key: i.toString(),
8131
+ start: start,
8132
+ end: start + panel.children.length - 1,
8133
+ element: panel
8134
+ }]);
8135
+ }, []);
8136
+ verticalCamera.innerHTML = verticalPanels;
8137
+ panels.forEach(function (panel) {
8138
+ [CLASS.VIEWPORT, CLASS.VERTICAL].forEach(function (className) {
8139
+ if (!panel.classList.contains(className)) {
8140
+ panel.classList.add(className);
8141
+ }
8142
+ });
8143
+ panel.innerHTML = verticalCamera.outerHTML;
8144
+ });
8145
+ }
8081
8146
  return verticalState;
8082
8147
  };
8083
- __proto._createVerticalFlicking = function (panels) {
8148
+ __proto._createVerticalFlicking = function () {
8084
8149
  var _this = this;
8085
- return panels.map(function (panel, i) {
8150
+ return this.camera.children.map(function (panel, i) {
8086
8151
  return new Flicking(panel, __assign(__assign({}, _this.verticalOptions), {
8087
8152
  horizontal: false,
8088
8153
  panelsPerView: 1,
@@ -8395,7 +8460,9 @@ var modules = {
8395
8460
  circulateIndex: circulateIndex,
8396
8461
  range: range,
8397
8462
  getElementSize: getElementSize,
8398
- setPrototypeOf: setPrototypeOf
8463
+ setPrototypeOf: setPrototypeOf,
8464
+ camelize: camelize,
8465
+ getDataAttributes: getDataAttributes
8399
8466
  };
8400
8467
 
8401
8468
  /*
@@ -8446,6 +8513,7 @@ exports.VirtualElementProvider = VirtualElementProvider;
8446
8513
  exports.VirtualManager = VirtualManager;
8447
8514
  exports.VirtualPanel = VirtualPanel;
8448
8515
  exports.VirtualRenderingStrategy = VirtualRenderingStrategy;
8516
+ exports.camelize = camelize;
8449
8517
  exports.checkExistence = checkExistence;
8450
8518
  exports.circulateIndex = circulateIndex;
8451
8519
  exports.circulatePosition = circulatePosition;
@@ -8454,6 +8522,7 @@ exports["default"] = Flicking;
8454
8522
  exports.find = find;
8455
8523
  exports.findIndex = findIndex;
8456
8524
  exports.findRight = findRight;
8525
+ exports.getDataAttributes = getDataAttributes;
8457
8526
  exports.getDefaultCameraTransform = getDefaultCameraTransform;
8458
8527
  exports.getDirection = getDirection;
8459
8528
  exports.getElement = getElement;