@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "4.12.0-beta.6",
3
+ "version": "4.12.0-beta.8",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.cjs.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -12,7 +12,8 @@
12
12
  "types": "declaration/index.d.ts",
13
13
  "scripts": {
14
14
  "start": "concurrently \"rollup -w --config ./rollup.config.dev.js\" \"http-serve\"",
15
- "build": "run-s build:bundle build:declaration build:css printsizes",
15
+ "build": "run-s build:bundle build:declaration printsizes",
16
+ "build-react": "run-s build:bundle build:declaration && pvu --build=react-flicking",
16
17
  "build:bundle": "rm -rf ./dist && rollup -c",
17
18
  "build:declaration": "rm -rf ./declaration && tsc -p tsconfig.declaration.json",
18
19
  "build:css": "run-s build:css-clear build:sass build:css-prefix build:css-min",
@@ -9,36 +9,17 @@ import { LiteralUnion, ValueOf } from "./type/internal";
9
9
  import { CLASS, EVENTS, MOVE_DIRECTION } from "./const/external";
10
10
  import { getDataAttributes, includes, toArray } from "./utils";
11
11
 
12
- /**
13
- * @interface
14
- */
15
12
  export interface CrossFlickingEvents {
16
13
  // FlickingEvent 들을 확장하자...
17
14
  }
18
15
 
19
- /**
20
- * @interface
21
- */
22
16
  export interface CrossFlickingOptions extends FlickingOptions {
23
17
  sideOptions: Partial<FlickingOptions> | undefined;
24
- // 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
25
- // 이전 패널 기억 여부
18
+ preserveIndex: boolean | undefined;
19
+ disableSlideOnHold: boolean | undefined;
20
+ disableIndexSync: boolean | undefined;
26
21
  }
27
22
 
28
- /**
29
- * Flicking Status returned by {@link Flicking#getStatus}
30
- * @ko {@link Flicking#getStatus}에 의해 반환된 Flicking 상태 객체
31
- * @interface
32
- * @property {number} index An index of the active panel<ko>활성화된 패널의 인덱스</ko>
33
- * @property {object} position A info to restore camera {@link Camera#position position}<ko>카메라 {@link Camera#position position}을 설정하기 위한 정보들</ko>
34
- * @property {number} [position.panel] An index of the panel camera is located at<ko>카메라가 위치한 패널의 인덱스</ko>
35
- * @property {number} [position.progressInPanel] A progress of the camera position inside the panel<ko>패널 내에서의 카메라 위치의 진행도</ko>
36
- * @property {number} visibleOffset An offset to visible panel's original index. This value is available only when `visiblePanelsOnly` is `true`
37
- * <ko>현재 보이는 패널들을 저장했을 때, 원래의 인덱스 대비 offset. `visiblePanelsOnly` 옵션을 사용했을 때만 사용 가능합니다</ko>
38
- * @property {object[]} panels A data array of panels<ko>패널의 정보를 담은 배열</ko>
39
- * @property {index} [panels.index] An index of the panel<ko>패널의 인덱스</ko>
40
- * @property {string | undefined} [panels.html] An `outerHTML` of the panel element<ko>패널 엘리먼트의 `outerHTML`</ko>
41
- */
42
23
  export interface SideState {
43
24
  key: string;
44
25
  start: number;
@@ -46,18 +27,15 @@ export interface SideState {
46
27
  element: HTMLElement;
47
28
  }
48
29
 
49
- /**
50
- * @extends Component
51
- * @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
52
- * @requires {@link https://github.com/naver/egjs-component|@egjs/component}
53
- * @requires {@link https://github.com/naver/egjs-axes|@egjs/axes}
54
- */
55
30
  export class CrossFlicking extends Flicking {
56
31
  // Core components
57
32
  private _sideFlicking: Flicking[];
58
33
 
59
34
  // Options
60
35
  private _sideOptions: CrossFlickingOptions["sideOptions"];
36
+ private _preserveIndex: CrossFlickingOptions["preserveIndex"];
37
+ private _disableSlideOnHold: CrossFlickingOptions["disableSlideOnHold"];
38
+ private _disableIndexSync: CrossFlickingOptions["disableIndexSync"];
61
39
 
62
40
  // Internal State
63
41
  private _sideState: SideState[];
@@ -65,88 +43,69 @@ export class CrossFlicking extends Flicking {
65
43
  private _nextIndex: number;
66
44
 
67
45
  // Components
68
- /**
69
- * {@link Control} instance of the Flicking
70
- * @ko 현재 Flicking에 활성화된 {@link Control} 인스턴스
71
- * @type {Control}
72
- * @default SnapControl
73
- * @readonly
74
- * @see Control
75
- * @see SnapControl
76
- * @see FreeControl
77
- */
78
46
  public get sideFlicking() {
79
47
  return this._sideFlicking;
80
48
  }
81
49
 
82
- // Internal States
83
- /**
84
- * Whether Flicking's {@link Flicking#init init()} is called.
85
- * This is `true` when {@link Flicking#init init()} is called, and is `false` after calling {@link Flicking#destroy destroy()}.
86
- * @ko Flicking의 {@link Flicking#init init()}이 호출되었는지를 나타내는 멤버 변수.
87
- * 이 값은 {@link Flicking#init init()}이 호출되었으면 `true`로 변하고, {@link Flicking#destroy destroy()}호출 이후에 다시 `false`로 변경됩니다.
88
- * @type {boolean}
89
- * @default false
90
- * @readonly
91
- */
92
50
  public get sideState() {
93
51
  return this._sideState;
94
52
  }
95
53
 
96
54
  // Options Getter
97
- /**
98
- * Change active panel index on mouse/touch hold while animating.
99
- * `index` of the `willChange`/`willRestore` event will be used as new index.
100
- * @ko 애니메이션 도중 마우스/터치 입력시 현재 활성화된 패널의 인덱스를 변경합니다.
101
- * `willChange`/`willRestore` 이벤트의 `index`값이 새로운 인덱스로 사용될 것입니다.
102
- * @type {FlickingOptions}
103
- * @default undefined
104
- * @see {@link https://naver.github.io/egjs-flicking/Options#changeonhold changeOnHold ( Options )}
105
- */
106
- public get sideOptions() {
107
- return this._sideOptions;
108
- }
55
+ public get sideOptions() { return this._sideOptions; }
56
+
57
+ public get preserveIndex() { return this._preserveIndex; }
58
+
59
+ public get disableSlideOnHold() { return this._disableSlideOnHold; }
60
+
61
+ public get disableIndexSync() { return this._disableIndexSync; }
109
62
 
110
63
  // Options Setter
111
- // public set align(val: FlickingOptions["align"]) {
112
- // this._align = val;
113
- // }
64
+ public set sideOptions(val: CrossFlickingOptions["sideOptions"]) {
65
+ this._sideOptions = val;
66
+ }
67
+ public set preserveIndex(val: CrossFlickingOptions["preserveIndex"]) {
68
+ this._preserveIndex = val;
69
+ }
70
+ public set disableSlideOnHold(val: CrossFlickingOptions["disableSlideOnHold"]) {
71
+ this._disableSlideOnHold = val;
72
+ }
73
+ public set disableIndexSync(val: CrossFlickingOptions["disableIndexSync"]) {
74
+ this._disableIndexSync = val;
75
+ }
114
76
 
115
77
  public constructor(
116
78
  root: HTMLElement | string,
117
- options: Partial<CrossFlickingOptions> = {}
79
+ options: Partial<CrossFlickingOptions> = {
80
+ sideOptions: {},
81
+ preserveIndex: false,
82
+ disableSlideOnHold: false,
83
+ disableIndexSync: false,
84
+ }
118
85
  ) {
119
86
  super(root, options);
120
87
 
121
88
  // Internal states
122
- this._sideState = this._createSideState();
123
89
  this._moveDirection = null;
124
90
  this._nextIndex = 0;
125
91
 
126
92
  // Bind options
127
93
  this._sideOptions = options.sideOptions;
94
+ this._preserveIndex = options.preserveIndex;
95
+ this._disableSlideOnHold = options.disableSlideOnHold;
96
+ this._disableIndexSync = options.disableIndexSync;
128
97
 
129
98
  // Create core components
130
- this._sideFlicking = this._createSideFlicking();
131
99
  }
132
100
 
133
- /**
134
- * Initialize Flicking and move to the default index
135
- * This is automatically called on Flicking's constructor when `autoInit` is true(default)
136
- * @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
137
- * 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
138
- * @fires Flicking#ready
139
- * @return {Promise<void>}
140
- */
141
101
  public init(): Promise<void> {
142
- return super.init().then(() => this._addComponentEvents());
102
+ return super.init().then(() => {
103
+ this._sideState = this._createSideState();
104
+ this._sideFlicking = this._createSideFlicking();
105
+ this._addComponentEvents();
106
+ });
143
107
  }
144
108
 
145
- /**
146
- * Destroy Flicking and remove all event handlers
147
- * @ko Flicking과 하위 컴포넌트들을 초기 상태로 되돌리고, 부착된 모든 이벤트 핸들러를 제거합니다
148
- * @return {void}
149
- */
150
109
  public destroy(): void {
151
110
  // TODO 모든 child flicking destroy
152
111
  super.destroy();
@@ -165,10 +124,24 @@ export class CrossFlicking extends Flicking {
165
124
  });
166
125
  }
167
126
 
127
+ private _getGroupFromAttribute(panels: HTMLElement[]): Record<string, HTMLElement[]> {
128
+ const groupKeys: string[] = [];
129
+ const groupPanels: Record<string, HTMLElement[]> = {};
130
+
131
+ panels.forEach((panel) => {
132
+ const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
133
+ if (groupKey && !includes(groupKeys, groupKey)) {
134
+ groupKeys.push(groupKey);
135
+ groupPanels[groupKey] = [panel];
136
+ } else if (groupKey) {
137
+ groupPanels[groupKey].push(panel);
138
+ }
139
+ });
140
+
141
+ return groupPanels;
142
+ }
143
+
168
144
  private _createSideState(): SideState[] {
169
- // data-index로 분류하기 전에 임시로 모든 children에 대해 side flicking으로 해보자.
170
- // panels에 data-attributes가 붙어있을 때와 안 붙어있을 때를 다르게 처리
171
- // 붙어있다면 가상의 viewport들을 index 갯수만큼 만들어줘야 한다
172
145
  const viewportEl = this.element;
173
146
  const cameraEl = this.camera.element;
174
147
  const panels = toArray(cameraEl.children) as HTMLElement[];
@@ -176,54 +149,26 @@ export class CrossFlicking extends Flicking {
176
149
  let sidePanels: string = "";
177
150
 
178
151
  // check data attribute exists
179
- const groupKeys: string[] = [];
180
- const groupPanels: Record<string, HTMLElement[]> = {};
181
152
  const sideCamera = document.createElement("div");
182
153
  sideCamera.classList.add(CLASS.CAMERA);
183
154
 
184
- const isCrossStructure = getDataAttributes(viewportEl, "data-cross-").structure;
155
+ const isCrossStructure = getDataAttributes(
156
+ viewportEl,
157
+ "data-cross-"
158
+ ).structure;
185
159
 
186
160
  if (!isCrossStructure) {
187
161
  viewportEl.setAttribute("data-cross-structure", "true");
188
162
 
189
- panels.forEach((panel) => {
190
- const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
191
- if (groupKey && !includes(groupKeys, groupKey)) {
192
- groupKeys.push(groupKey);
193
- groupPanels[groupKey] = [panel];
194
- } else if (groupKey) {
195
- groupPanels[groupKey].push(panel);
196
- }
197
- });
163
+ const groupPanels = this._getGroupFromAttribute(panels);
164
+ const groupKeys = Object.keys(groupPanels);
198
165
 
199
166
  if (groupKeys.length) {
200
- sideState = groupKeys.reduce(
201
- (state: SideState[], key: string) => {
202
- const start = state.length ? +state[state.length - 1].end + 1 : 0;
203
- const element = groupPanels[key].reduce(
204
- (el: HTMLElement, panel: HTMLElement) => {
205
- sidePanels += panel.outerHTML;
206
- el.innerHTML += panel.outerHTML;
207
- return el;
208
- },
209
- document.createElement("div")
210
- );
211
- return [
212
- ...state,
213
- {
214
- key,
215
- start,
216
- end: start + groupPanels[key].length - 1,
217
- element: element
218
- }
219
- ];
220
- },
221
- []
222
- );
223
-
167
+ sideState = this._getSideStateFromGroup(groupPanels);
224
168
  this.remove(0, this.panelCount - groupKeys.length);
225
- sideState.forEach((_, i) => {
169
+ sideState.forEach((state, i) => {
226
170
  const panel = this.camera.children[i];
171
+ sidePanels += state.element.innerHTML;
227
172
  Array.from(panel.attributes).forEach(attribute => panel.removeAttribute(attribute.name));
228
173
  });
229
174
  } else {
@@ -237,8 +182,8 @@ export class CrossFlicking extends Flicking {
237
182
  key: i.toString(),
238
183
  start,
239
184
  end: start + panel.children.length - 1,
240
- element: panel
241
- }
185
+ element: panel,
186
+ },
242
187
  ];
243
188
  },
244
189
  []
@@ -256,50 +201,52 @@ export class CrossFlicking extends Flicking {
256
201
  panel.innerHTML = sideCamera.outerHTML;
257
202
  });
258
203
  } else {
259
- (toArray(panels[0].children[0].children) as HTMLElement[]).forEach((panel) => {
260
- const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
261
- if (groupKey && !includes(groupKeys, groupKey)) {
262
- groupKeys.push(groupKey);
263
- groupPanels[groupKey] = [panel];
264
- } else if (groupKey) {
265
- groupPanels[groupKey].push(panel);
266
- }
267
- });
268
-
269
- sideState = groupKeys.reduce(
270
- (state: SideState[], key: string) => {
271
- const start = state.length ? +state[state.length - 1].end + 1 : 0;
272
- const element = groupPanels[key].reduce(
273
- (el: HTMLElement, panel: HTMLElement) => {
274
- el.innerHTML += panel.outerHTML;
275
- return el;
276
- },
277
- document.createElement("div")
278
- );
279
- return [
280
- ...state,
281
- {
282
- key,
283
- start,
284
- end: start + groupPanels[key].length - 1,
285
- element: element
286
- }
287
- ];
288
- },
289
- []
290
- );
204
+ sideState = this._getSideStateFromPanels(panels);
291
205
  }
292
206
 
207
+ void this.resize();
208
+
293
209
  return sideState;
294
210
  }
295
211
 
212
+ private _getSideStateFromGroup(groupPanels: Record<string, HTMLElement[]>): SideState[] {
213
+ return Object.keys(groupPanels).reduce(
214
+ (state: SideState[], key: string) => {
215
+ const start = state.length ? +state[state.length - 1].end + 1 : 0;
216
+ const element = groupPanels[key].reduce(
217
+ (el: HTMLElement, panel: HTMLElement) => {
218
+ el.innerHTML += panel.outerHTML;
219
+ return el;
220
+ },
221
+ document.createElement("div")
222
+ );
223
+ return [
224
+ ...state,
225
+ {
226
+ key,
227
+ start,
228
+ end: start + groupPanels[key].length - 1,
229
+ element: element
230
+ }
231
+ ];
232
+ },
233
+ []
234
+ );
235
+ }
236
+
237
+ private _getSideStateFromPanels(panels: HTMLElement[]): SideState[] {
238
+ const groupPanels = this._getGroupFromAttribute(panels);
239
+ return this._getSideStateFromGroup(groupPanels);
240
+ }
241
+
296
242
  private _createSideFlicking(): Flicking[] {
297
243
  return this.sideState.map((state, i) => {
298
244
  return new Flicking(this.camera.children[i], {
299
245
  ...this.sideOptions,
300
246
  horizontal: false,
301
247
  panelsPerView: 1,
302
- defaultIndex: state.start
248
+ defaultIndex: state.start,
249
+ moveType: "strict"
303
250
  });
304
251
  });
305
252
  }
@@ -348,8 +295,8 @@ export class CrossFlicking extends Flicking {
348
295
  this._nextIndex = visiblePanels[0].index;
349
296
  }
350
297
 
351
- // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 timeout으로 처리
352
- setTimeout(() => {
298
+ // _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
299
+ requestAnimationFrame(() => {
353
300
  this._sideFlicking.forEach((child, i) => {
354
301
  if (this._nextIndex !== i) {
355
302
  const { start, end } = this._sideState[i];
@@ -1,45 +0,0 @@
1
- .flicking-viewport {
2
- position: relative;
3
- overflow: hidden;
4
- }
5
-
6
- .flicking-viewport:not(.vertical) {
7
- width: 100%;
8
- height: 100%;
9
- }
10
-
11
- .flicking-viewport.vertical,
12
- .flicking-viewport.vertical > .flicking-camera {
13
- display: inline-block;
14
- }
15
-
16
- .flicking-viewport.vertical.middle > .flicking-camera > * {
17
- vertical-align: middle;
18
- }
19
-
20
- .flicking-viewport.vertical.bottom > .flicking-camera > * {
21
- vertical-align: bottom;
22
- }
23
-
24
- .flicking-viewport.vertical > .flicking-camera > * {
25
- display: block;
26
- }
27
-
28
- .flicking-viewport.flicking-hidden > .flicking-camera > * {
29
- visibility: hidden;
30
- }
31
-
32
- .flicking-camera {
33
- width: 100%;
34
- height: 100%;
35
- position: relative;
36
- z-index: 1;
37
- white-space: nowrap;
38
- will-change: transform;
39
- }
40
-
41
- .flicking-camera > * {
42
- display: inline-block;
43
- white-space: normal;
44
- vertical-align: top;
45
- }
@@ -1 +0,0 @@
1
- .flicking-viewport{position:relative;overflow:hidden}.flicking-viewport:not(.vertical){width:100%;height:100%}.flicking-viewport.vertical,.flicking-viewport.vertical>.flicking-camera{display:inline-block}.flicking-viewport.vertical.middle>.flicking-camera>*{vertical-align:middle}.flicking-viewport.vertical.bottom>.flicking-camera>*{vertical-align:bottom}.flicking-viewport.vertical>.flicking-camera>*{display:block}.flicking-viewport.flicking-hidden>.flicking-camera>*{visibility:hidden}.flicking-camera{width:100%;height:100%;position:relative;z-index:1;white-space:nowrap;will-change:transform}.flicking-camera>*{display:inline-block;white-space:normal;vertical-align:top}
package/dist/flicking.css DELETED
@@ -1,44 +0,0 @@
1
- .flicking-viewport {
2
- position: relative;
3
- overflow: hidden;
4
- }
5
-
6
- .flicking-viewport.vertical {
7
- display: -webkit-inline-box;
8
- display: -ms-inline-flexbox;
9
- display: inline-flex;
10
- }
11
-
12
- .flicking-viewport.vertical > .flicking-camera {
13
- display: -webkit-inline-box;
14
- display: -ms-inline-flexbox;
15
- display: inline-flex;
16
- -webkit-box-orient: vertical;
17
- -webkit-box-direction: normal;
18
- -ms-flex-direction: column;
19
- flex-direction: column;
20
- }
21
-
22
- .flicking-viewport.flicking-hidden > .flicking-camera > * {
23
- visibility: hidden;
24
- }
25
-
26
- .flicking-camera {
27
- width: 100%;
28
- height: 100%;
29
- display: -webkit-box;
30
- display: -ms-flexbox;
31
- display: flex;
32
- position: relative;
33
- -webkit-box-orient: horizontal;
34
- -webkit-box-direction: normal;
35
- -ms-flex-direction: row;
36
- flex-direction: row;
37
- z-index: 1;
38
- will-change: transform;
39
- }
40
-
41
- .flicking-camera > * {
42
- -ms-flex-negative: 0;
43
- flex-shrink: 0;
44
- }
@@ -1 +0,0 @@
1
- .flicking-viewport{position:relative;overflow:hidden}.flicking-viewport.vertical{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex}.flicking-viewport.vertical>.flicking-camera{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.flicking-viewport.flicking-hidden>.flicking-camera>*{visibility:hidden}.flicking-camera{width:100%;height:100%;display:-webkit-box;display:-ms-flexbox;display:flex;position:relative;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;z-index:1;will-change:transform}.flicking-camera>*{-ms-flex-negative:0;flex-shrink:0}