@egjs/flicking 4.12.0-beta.1 → 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;
@@ -15,9 +16,14 @@ export declare class CrossFlicking extends Flicking {
15
16
  private _verticalState;
16
17
  private _moveDirection;
17
18
  private _nextIndex;
19
+ get verticalFlicking(): Flicking[];
20
+ get verticalState(): VerticalState[];
18
21
  get verticalOptions(): FlickingOptions;
19
22
  constructor(root: HTMLElement | string, { verticalOptions }?: Partial<CrossFlickingOptions>);
20
23
  init(): Promise<void>;
24
+ private _addComponentEvents;
25
+ private _createVerticalState;
26
+ private _createVerticalFlicking;
21
27
  private _syncToCategory;
22
28
  private _onHorizontalHoldStart;
23
29
  private _onHorizontalMove;
@@ -34,6 +34,8 @@ export declare const MOVE_TYPE: {
34
34
  readonly STRICT: "strict";
35
35
  };
36
36
  export declare const CLASS: {
37
+ VIEWPORT: string;
38
+ CAMERA: string;
37
39
  VERTICAL: string;
38
40
  HIDDEN: string;
39
41
  DEFAULT_VIRTUAL: string;
@@ -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.1
7
+ version: 4.12.0-beta.3
8
8
  */
9
9
  'use strict';
10
10
 
@@ -387,6 +387,8 @@ var MOVE_TYPE = {
387
387
  STRICT: "strict"
388
388
  };
389
389
  var CLASS = {
390
+ VIEWPORT: "flicking-viewport",
391
+ CAMERA: "flicking-camera",
390
392
  VERTICAL: "vertical",
391
393
  HIDDEN: "flicking-hidden",
392
394
  DEFAULT_VIRTUAL: "flicking-panel"
@@ -738,6 +740,26 @@ var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
738
740
  obj.__proto__ = proto;
739
741
  return obj;
740
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
+ };
741
763
 
742
764
  /*
743
765
  * Copyright (c) 2015 NAVER Corp.
@@ -7873,7 +7895,7 @@ var Flicking = /*#__PURE__*/function (_super) {
7873
7895
  * Flicking.VERSION; // ex) 4.0.0
7874
7896
  * ```
7875
7897
  */
7876
- Flicking.VERSION = "4.12.0-beta.1";
7898
+ Flicking.VERSION = "4.12.0-beta.3";
7877
7899
  return Flicking;
7878
7900
  }(Component);
7879
7901
 
@@ -7890,7 +7912,6 @@ var Flicking = /*#__PURE__*/function (_super) {
7890
7912
  var CrossFlicking = /*#__PURE__*/function (_super) {
7891
7913
  __extends(CrossFlicking, _super);
7892
7914
  // Options Setter
7893
- // UI / LAYOUT
7894
7915
  // public set align(val: FlickingOptions["align"]) {
7895
7916
  // this._align = val;
7896
7917
  // }
@@ -7963,18 +7984,53 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
7963
7984
  }
7964
7985
  };
7965
7986
  // Internal states
7966
- _this._verticalState = [];
7987
+ _this._verticalState = _this._createVerticalState();
7967
7988
  _this._moveDirection = null;
7968
7989
  _this._nextIndex = 0;
7969
7990
  // Bind options
7970
7991
  _this._verticalOptions = verticalOptions;
7971
- return _this;
7972
7992
  // Create core components
7973
- // this._viewport = new Viewport(this, getElement(root));
7993
+ _this._verticalFlicking = _this._createVerticalFlicking();
7994
+ return _this;
7974
7995
  }
7975
7996
  var __proto = CrossFlicking.prototype;
7976
- Object.defineProperty(__proto, "verticalOptions", {
7997
+ Object.defineProperty(__proto, "verticalFlicking", {
7977
7998
  // 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
+ get: function () {
8010
+ return this._verticalFlicking;
8011
+ },
8012
+ enumerable: false,
8013
+ configurable: true
8014
+ });
8015
+ Object.defineProperty(__proto, "verticalState", {
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
+ get: function () {
8027
+ return this._verticalState;
8028
+ },
8029
+ enumerable: false,
8030
+ configurable: true
8031
+ });
8032
+ Object.defineProperty(__proto, "verticalOptions", {
8033
+ // Options Getter
7978
8034
  /**
7979
8035
  * Change active panel index on mouse/touch hold while animating.
7980
8036
  * `index` of the `willChange`/`willRestore` event will be used as new index.
@@ -8001,37 +8057,102 @@ var CrossFlicking = /*#__PURE__*/function (_super) {
8001
8057
  __proto.init = function () {
8002
8058
  var _this = this;
8003
8059
  return _super.prototype.init.call(this).then(function () {
8004
- // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8005
- // camera.children들에 대해 갯수 세기
8006
- var verticalPanels = "";
8007
- _this._verticalState = _this.camera.children.reduce(function (state, child) {
8060
+ return _this._addComponentEvents();
8061
+ });
8062
+ };
8063
+ __proto._addComponentEvents = function () {
8064
+ var _this = this;
8065
+ this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
8066
+ this.on(EVENTS.MOVE, this._onHorizontalMove);
8067
+ this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
8068
+ this._verticalFlicking.forEach(function (flicking) {
8069
+ flicking.on(EVENTS.HOLD_START, _this._onVerticalHoldStart);
8070
+ flicking.on(EVENTS.MOVE, _this._onVerticalMove);
8071
+ flicking.on(EVENTS.MOVE_END, _this._onVerticalMoveEnd);
8072
+ flicking.on(EVENTS.CHANGED, _this._onVerticalChanged);
8073
+ });
8074
+ };
8075
+ __proto._createVerticalState = function () {
8076
+ var _this = this;
8077
+ // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
8078
+ // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
8079
+ // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
8080
+ var cameraEl = this.camera.element;
8081
+ var panels = toArray(cameraEl.children);
8082
+ var verticalState;
8083
+ var verticalPanels = "";
8084
+ // check data attribute exists
8085
+ var groupKeys = [];
8086
+ var groupPanels = {};
8087
+ var verticalCamera = document.createElement("div");
8088
+ verticalCamera.classList.add(CLASS.CAMERA);
8089
+ panels.forEach(function (panel) {
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;
8098
+ });
8099
+ if (groupKeys.length) {
8100
+ panels.forEach(function () {
8101
+ return _this.remove(0);
8102
+ });
8103
+ verticalState = groupKeys.reduce(function (state, key) {
8008
8104
  var start = state.length ? +state[state.length - 1].end + 1 : 0;
8009
- verticalPanels += child.children[0].innerHTML;
8105
+ var element = groupPanels[key].reduce(function (el, panel) {
8106
+ verticalPanels += panel.outerHTML;
8107
+ el.appendChild(panel);
8108
+ return el;
8109
+ }, document.createElement("div"));
8010
8110
  return __spread(state, [{
8111
+ key: key,
8011
8112
  start: start,
8012
- end: start + child.children[0].children.length - 1,
8013
- element: child
8113
+ end: start + groupPanels[key].length - 1,
8114
+ element: element
8014
8115
  }]);
8015
8116
  }, []);
8016
- _this.camera.children.forEach(function (child) {
8017
- child.children[0].innerHTML = verticalPanels;
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);
8018
8124
  });
8019
- _this._verticalFlicking = _this.camera.children.map(function (child, i) {
8020
- return new Flicking(child, __assign(__assign({}, _this.verticalOptions), {
8021
- horizontal: false,
8022
- panelsPerView: 1,
8023
- defaultIndex: _this._verticalState[i].start
8024
- }));
8025
- });
8026
- _this.on(EVENTS.HOLD_START, _this._onHorizontalHoldStart);
8027
- _this.on(EVENTS.MOVE, _this._onHorizontalMove);
8028
- _this.on(EVENTS.MOVE_END, _this._onHorizontalMoveEnd);
8029
- _this._verticalFlicking.forEach(function (child) {
8030
- child.on(EVENTS.HOLD_START, _this._onVerticalHoldStart);
8031
- child.on(EVENTS.MOVE, _this._onVerticalMove);
8032
- child.on(EVENTS.MOVE_END, _this._onVerticalMoveEnd);
8033
- child.on(EVENTS.CHANGED, _this._onVerticalChanged);
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;
8034
8144
  });
8145
+ }
8146
+ return verticalState;
8147
+ };
8148
+ __proto._createVerticalFlicking = function () {
8149
+ var _this = this;
8150
+ return this.camera.children.map(function (panel, i) {
8151
+ return new Flicking(panel, __assign(__assign({}, _this.verticalOptions), {
8152
+ horizontal: false,
8153
+ panelsPerView: 1,
8154
+ defaultIndex: _this._verticalState[i].start
8155
+ }));
8035
8156
  });
8036
8157
  };
8037
8158
  __proto._syncToCategory = function (index, outerIndex) {
@@ -8339,7 +8460,9 @@ var modules = {
8339
8460
  circulateIndex: circulateIndex,
8340
8461
  range: range,
8341
8462
  getElementSize: getElementSize,
8342
- setPrototypeOf: setPrototypeOf
8463
+ setPrototypeOf: setPrototypeOf,
8464
+ camelize: camelize,
8465
+ getDataAttributes: getDataAttributes
8343
8466
  };
8344
8467
 
8345
8468
  /*
@@ -8390,6 +8513,7 @@ exports.VirtualElementProvider = VirtualElementProvider;
8390
8513
  exports.VirtualManager = VirtualManager;
8391
8514
  exports.VirtualPanel = VirtualPanel;
8392
8515
  exports.VirtualRenderingStrategy = VirtualRenderingStrategy;
8516
+ exports.camelize = camelize;
8393
8517
  exports.checkExistence = checkExistence;
8394
8518
  exports.circulateIndex = circulateIndex;
8395
8519
  exports.circulatePosition = circulatePosition;
@@ -8398,6 +8522,7 @@ exports["default"] = Flicking;
8398
8522
  exports.find = find;
8399
8523
  exports.findIndex = findIndex;
8400
8524
  exports.findRight = findRight;
8525
+ exports.getDataAttributes = getDataAttributes;
8401
8526
  exports.getDefaultCameraTransform = getDefaultCameraTransform;
8402
8527
  exports.getDirection = getDirection;
8403
8528
  exports.getElement = getElement;