@egjs/flicking 4.12.0-beta.1 → 4.12.0-beta.10
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/declaration/CrossFlicking.d.ts +62 -14
- package/declaration/camera/Camera.d.ts +1 -0
- package/declaration/const/external.d.ts +2 -0
- package/declaration/index.d.ts +2 -1
- package/declaration/utils.d.ts +2 -0
- package/dist/flicking.cjs.js +319 -122
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +313 -122
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +316 -122
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.js +2 -2
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +1083 -882
- package/dist/flicking.pkgd.js.map +1 -1
- package/dist/flicking.pkgd.min.js +2 -2
- package/dist/flicking.pkgd.min.js.map +1 -1
- package/package.json +3 -2
- package/sass/flicking.sass +13 -0
- package/src/CrossFlicking.ts +330 -143
- package/src/camera/Camera.ts +24 -4
- package/src/const/external.ts +2 -0
- package/src/index.ts +2 -1
- package/src/utils.ts +21 -0
- package/dist/flicking-inline.css +0 -45
- package/dist/flicking-inline.min.css +0 -1
- package/dist/flicking.css +0 -44
- package/dist/flicking.min.css +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.12.0-beta.
|
|
3
|
+
"version": "4.12.0-beta.10",
|
|
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
|
|
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",
|
package/sass/flicking.sass
CHANGED
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
position: relative
|
|
3
3
|
overflow: hidden
|
|
4
4
|
&.vertical
|
|
5
|
+
display: -webkit-inline-box
|
|
6
|
+
display: -ms-inline-flexbox
|
|
5
7
|
display: inline-flex
|
|
6
8
|
>.flicking-camera
|
|
9
|
+
display: -webkit-inline-box
|
|
10
|
+
display: -ms-inline-flexbox
|
|
7
11
|
display: inline-flex
|
|
12
|
+
-webkit-box-orient: vertical
|
|
13
|
+
-webkit-box-direction: normal
|
|
14
|
+
-ms-flex-direction: column
|
|
8
15
|
flex-direction: column
|
|
9
16
|
&.flicking-hidden
|
|
10
17
|
>.flicking-camera
|
|
@@ -14,10 +21,16 @@
|
|
|
14
21
|
.flicking-camera
|
|
15
22
|
width: 100%
|
|
16
23
|
height: 100%
|
|
24
|
+
display: -webkit-box
|
|
25
|
+
display: -ms-flexbox
|
|
17
26
|
display: flex
|
|
18
27
|
position: relative
|
|
28
|
+
-webkit-box-orient: horizontal
|
|
29
|
+
-webkit-box-direction: normal
|
|
30
|
+
-ms-flex-direction: row
|
|
19
31
|
flex-direction: row
|
|
20
32
|
z-index: 1
|
|
21
33
|
will-change: transform
|
|
22
34
|
>*
|
|
35
|
+
-ms-flex-negative: 0
|
|
23
36
|
flex-shrink: 0
|
package/src/CrossFlicking.ts
CHANGED
|
@@ -2,162 +2,320 @@
|
|
|
2
2
|
* Copyright (c) 2015 NAVER Corp.
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
+
import { ComponentEvent } from "@egjs/component";
|
|
6
|
+
import { EventKey } from "@egjs/component/declaration/types";
|
|
5
7
|
|
|
6
|
-
import Flicking, { FlickingOptions } from "./Flicking";
|
|
7
|
-
import {
|
|
8
|
+
import Flicking, { FlickingEvents, FlickingOptions } from "./Flicking";
|
|
9
|
+
import {
|
|
10
|
+
ChangedEvent,
|
|
11
|
+
HoldEndEvent,
|
|
12
|
+
HoldStartEvent,
|
|
13
|
+
MoveEndEvent,
|
|
14
|
+
MoveEvent,
|
|
15
|
+
MoveStartEvent,
|
|
16
|
+
WillChangeEvent
|
|
17
|
+
} from "./type/event";
|
|
8
18
|
import { LiteralUnion, ValueOf } from "./type/internal";
|
|
9
|
-
import { EVENTS, MOVE_DIRECTION } from "./const/external";
|
|
19
|
+
import { CLASS, EVENTS, MOVE_DIRECTION } from "./const/external";
|
|
20
|
+
import { getDataAttributes, includes, toArray } from "./utils";
|
|
10
21
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
export const SIDE_EVENTS = {
|
|
23
|
+
HOLD_START: "sideHoldStart",
|
|
24
|
+
HOLD_END: "sideHoldEnd",
|
|
25
|
+
MOVE_START: "sideMoveStart",
|
|
26
|
+
MOVE: "sideMove",
|
|
27
|
+
MOVE_END: "sideMoveEnd",
|
|
28
|
+
WILL_CHANGE: "sideWillChange",
|
|
29
|
+
CHANGED: "sideChanged"
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
export type CrossFlickingEvent<T> = { mainIndex: number } & T;
|
|
33
|
+
|
|
34
|
+
export interface CrossFlickingEvents extends FlickingEvents {
|
|
35
|
+
[SIDE_EVENTS.HOLD_START]: CrossFlickingEvent<HoldStartEvent>;
|
|
36
|
+
[SIDE_EVENTS.HOLD_END]: CrossFlickingEvent<HoldEndEvent>;
|
|
37
|
+
[SIDE_EVENTS.MOVE_START]: CrossFlickingEvent<MoveStartEvent>;
|
|
38
|
+
[SIDE_EVENTS.MOVE]: CrossFlickingEvent<MoveEvent>;
|
|
39
|
+
[SIDE_EVENTS.MOVE_END]: CrossFlickingEvent<MoveEndEvent>;
|
|
40
|
+
[SIDE_EVENTS.WILL_CHANGE]: CrossFlickingEvent<WillChangeEvent>;
|
|
41
|
+
[SIDE_EVENTS.CHANGED]: CrossFlickingEvent<ChangedEvent>;
|
|
16
42
|
}
|
|
17
43
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
|
|
24
|
-
// 이전 패널 기억 여부
|
|
44
|
+
export interface CrossFlickingOptions extends FlickingOptions {
|
|
45
|
+
sideOptions: Partial<FlickingOptions> | undefined;
|
|
46
|
+
preserveIndex: boolean | undefined;
|
|
47
|
+
disableSlideOnHold: boolean | undefined;
|
|
48
|
+
disableIndexSync: boolean | undefined;
|
|
25
49
|
}
|
|
26
50
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* @ko {@link Flicking#getStatus}에 의해 반환된 Flicking 상태 객체
|
|
30
|
-
* @interface
|
|
31
|
-
* @property {number} index An index of the active panel<ko>활성화된 패널의 인덱스</ko>
|
|
32
|
-
* @property {object} position A info to restore camera {@link Camera#position position}<ko>카메라 {@link Camera#position position}을 설정하기 위한 정보들</ko>
|
|
33
|
-
* @property {number} [position.panel] An index of the panel camera is located at<ko>카메라가 위치한 패널의 인덱스</ko>
|
|
34
|
-
* @property {number} [position.progressInPanel] A progress of the camera position inside the panel<ko>패널 내에서의 카메라 위치의 진행도</ko>
|
|
35
|
-
* @property {number} visibleOffset An offset to visible panel's original index. This value is available only when `visiblePanelsOnly` is `true`
|
|
36
|
-
* <ko>현재 보이는 패널들을 저장했을 때, 원래의 인덱스 대비 offset. `visiblePanelsOnly` 옵션을 사용했을 때만 사용 가능합니다</ko>
|
|
37
|
-
* @property {object[]} panels A data array of panels<ko>패널의 정보를 담은 배열</ko>
|
|
38
|
-
* @property {index} [panels.index] An index of the panel<ko>패널의 인덱스</ko>
|
|
39
|
-
* @property {string | undefined} [panels.html] An `outerHTML` of the panel element<ko>패널 엘리먼트의 `outerHTML`</ko>
|
|
40
|
-
*/
|
|
41
|
-
export interface VerticalState {
|
|
51
|
+
export interface SideState {
|
|
52
|
+
key: string;
|
|
42
53
|
start: number;
|
|
43
54
|
end: number;
|
|
44
55
|
element: HTMLElement;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
/**
|
|
48
|
-
* @extends Component
|
|
49
|
-
* @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
|
|
50
|
-
* @requires {@link https://github.com/naver/egjs-component|@egjs/component}
|
|
51
|
-
* @requires {@link https://github.com/naver/egjs-axes|@egjs/axes}
|
|
52
|
-
*/
|
|
53
58
|
export class CrossFlicking extends Flicking {
|
|
54
59
|
// Core components
|
|
55
|
-
private
|
|
60
|
+
private _sideFlicking: Flicking[];
|
|
56
61
|
|
|
57
62
|
// Options
|
|
58
|
-
private
|
|
63
|
+
private _sideOptions: CrossFlickingOptions["sideOptions"];
|
|
64
|
+
private _preserveIndex: CrossFlickingOptions["preserveIndex"];
|
|
65
|
+
private _disableSlideOnHold: CrossFlickingOptions["disableSlideOnHold"];
|
|
66
|
+
private _disableIndexSync: CrossFlickingOptions["disableIndexSync"];
|
|
59
67
|
|
|
60
68
|
// Internal State
|
|
61
|
-
private
|
|
62
|
-
|
|
69
|
+
private _sideState: SideState[];
|
|
63
70
|
private _moveDirection: LiteralUnion<ValueOf<typeof MOVE_DIRECTION>> | null;
|
|
71
|
+
private _originalDragThreshold: number;
|
|
64
72
|
private _nextIndex: number;
|
|
65
73
|
|
|
66
74
|
// Components
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* @default undefined
|
|
74
|
-
* @see {@link https://naver.github.io/egjs-flicking/Options#changeonhold changeOnHold ( Options )}
|
|
75
|
-
*/
|
|
76
|
-
public get verticalOptions() {
|
|
77
|
-
return this._verticalOptions;
|
|
75
|
+
public get sideFlicking() {
|
|
76
|
+
return this._sideFlicking;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public get sideState() {
|
|
80
|
+
return this._sideState;
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
// Options Getter
|
|
84
|
+
public get sideOptions() { return this._sideOptions; }
|
|
85
|
+
|
|
86
|
+
public get preserveIndex() { return this._preserveIndex; }
|
|
87
|
+
|
|
88
|
+
public get disableSlideOnHold() { return this._disableSlideOnHold; }
|
|
89
|
+
|
|
90
|
+
public get disableIndexSync() { return this._disableIndexSync; }
|
|
91
|
+
|
|
80
92
|
// Options Setter
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
public set sideOptions(val: CrossFlickingOptions["sideOptions"]) {
|
|
94
|
+
this._sideOptions = val;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public set preserveIndex(val: CrossFlickingOptions["preserveIndex"]) {
|
|
98
|
+
this._preserveIndex = val;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public set disableSlideOnHold(val: CrossFlickingOptions["disableSlideOnHold"]) {
|
|
102
|
+
this._disableSlideOnHold = val;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public set disableIndexSync(val: CrossFlickingOptions["disableIndexSync"]) {
|
|
106
|
+
this._disableIndexSync = val;
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
public constructor(
|
|
87
110
|
root: HTMLElement | string,
|
|
88
|
-
|
|
111
|
+
options: Partial<CrossFlickingOptions>
|
|
89
112
|
) {
|
|
90
|
-
super(root);
|
|
113
|
+
super(root, options);
|
|
114
|
+
const {
|
|
115
|
+
sideOptions = {},
|
|
116
|
+
preserveIndex = true,
|
|
117
|
+
disableSlideOnHold = true,
|
|
118
|
+
disableIndexSync = false
|
|
119
|
+
} = options;
|
|
91
120
|
|
|
92
121
|
// Internal states
|
|
93
|
-
this._verticalState = [];
|
|
94
122
|
this._moveDirection = null;
|
|
95
123
|
this._nextIndex = 0;
|
|
124
|
+
this._originalDragThreshold = this.dragThreshold;
|
|
96
125
|
|
|
97
126
|
// Bind options
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
this._sideOptions = sideOptions;
|
|
128
|
+
this._preserveIndex = preserveIndex;
|
|
129
|
+
this._disableSlideOnHold = disableSlideOnHold;
|
|
130
|
+
this._disableIndexSync = disableIndexSync;
|
|
102
131
|
}
|
|
103
132
|
|
|
104
|
-
/**
|
|
105
|
-
* Initialize Flicking and move to the default index
|
|
106
|
-
* This is automatically called on Flicking's constructor when `autoInit` is true(default)
|
|
107
|
-
* @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
|
|
108
|
-
* 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
|
|
109
|
-
* @fires Flicking#ready
|
|
110
|
-
* @return {Promise<void>}
|
|
111
|
-
*/
|
|
112
133
|
public init(): Promise<void> {
|
|
113
134
|
return super.init().then(() => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
this._sideState = this._createSideState();
|
|
136
|
+
this._sideFlicking = this._createSideFlicking();
|
|
137
|
+
this._addComponentEvents();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public destroy(): void {
|
|
142
|
+
this._sideFlicking.forEach((flicking) => {
|
|
143
|
+
flicking.destroy();
|
|
144
|
+
});
|
|
145
|
+
super.destroy();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private _addComponentEvents(): void {
|
|
149
|
+
this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
|
|
150
|
+
this.on(EVENTS.MOVE, this._onHorizontalMove);
|
|
151
|
+
this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
|
|
152
|
+
|
|
153
|
+
this._sideFlicking.forEach((flicking, mainIndex) => {
|
|
154
|
+
flicking.on(EVENTS.HOLD_START, this._onSideHoldStart);
|
|
155
|
+
flicking.on(EVENTS.MOVE, this._onSideMove);
|
|
156
|
+
flicking.on(EVENTS.MOVE_END, this._onSideMoveEnd);
|
|
157
|
+
flicking.on(EVENTS.CHANGED, this._onSideChanged);
|
|
158
|
+
|
|
159
|
+
Object.keys(SIDE_EVENTS).forEach((name: EventKey<FlickingEvents>) => {
|
|
160
|
+
flicking.on(EVENTS[name], (event) => {
|
|
161
|
+
this.trigger(
|
|
162
|
+
new ComponentEvent(SIDE_EVENTS[name], {
|
|
163
|
+
mainIndex,
|
|
164
|
+
...event
|
|
165
|
+
})
|
|
166
|
+
);
|
|
141
167
|
});
|
|
142
168
|
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private _createSideState(): SideState[] {
|
|
173
|
+
const viewportEl = this.element;
|
|
174
|
+
const cameraEl = this.camera.element;
|
|
175
|
+
const panels = toArray(cameraEl.children) as HTMLElement[];
|
|
176
|
+
const isCrossStructure = getDataAttributes(
|
|
177
|
+
viewportEl,
|
|
178
|
+
"data-cross-"
|
|
179
|
+
).structure;
|
|
180
|
+
let sideState: SideState[] = [];
|
|
181
|
+
|
|
182
|
+
if (!isCrossStructure) {
|
|
183
|
+
const groupPanels = this._getGroupFromAttribute(panels);
|
|
184
|
+
const groupKeys = Object.keys(groupPanels);
|
|
185
|
+
|
|
186
|
+
if (groupKeys.length) {
|
|
187
|
+
sideState = this._getSideStateFromGroup(groupPanels);
|
|
188
|
+
this.remove(0, this.panelCount - groupKeys.length);
|
|
189
|
+
} else {
|
|
190
|
+
sideState = this._getSideStateFromPanels(panels);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._createCrossStructure(sideState);
|
|
194
|
+
} else {
|
|
195
|
+
sideState = this._getSideStateFromCrossStructure(panels);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void this.resize();
|
|
199
|
+
|
|
200
|
+
return sideState;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private _createCrossStructure(sideState: SideState[]) {
|
|
204
|
+
const sideCamera = document.createElement("div");
|
|
205
|
+
let sidePanels: string = "";
|
|
206
|
+
|
|
207
|
+
sideCamera.classList.add(CLASS.CAMERA);
|
|
208
|
+
sideState.forEach((state, i) => {
|
|
209
|
+
const panel = this.camera.children[i];
|
|
210
|
+
sidePanels += state.element.innerHTML;
|
|
211
|
+
Array.from(panel.attributes).forEach((attribute) =>
|
|
212
|
+
panel.removeAttribute(attribute.name)
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
sideCamera.innerHTML = sidePanels;
|
|
217
|
+
|
|
218
|
+
sideState.forEach((_, i) => {
|
|
219
|
+
const panel = this.camera.children[i];
|
|
220
|
+
[CLASS.VIEWPORT, CLASS.VERTICAL].forEach((className) => {
|
|
221
|
+
if (!panel.classList.contains(className)) {
|
|
222
|
+
panel.classList.add(className);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
panel.innerHTML = sideCamera.outerHTML;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
this.element.setAttribute("data-cross-structure", "true");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private _getGroupFromAttribute(
|
|
232
|
+
panels: HTMLElement[]
|
|
233
|
+
): Record<string, HTMLElement[]> {
|
|
234
|
+
const groupKeys: string[] = [];
|
|
235
|
+
const groupPanels: Record<string, HTMLElement[]> = {};
|
|
236
|
+
|
|
237
|
+
panels.forEach((panel) => {
|
|
238
|
+
const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
|
|
239
|
+
if (groupKey && !includes(groupKeys, groupKey)) {
|
|
240
|
+
groupKeys.push(groupKey);
|
|
241
|
+
groupPanels[groupKey] = [panel];
|
|
242
|
+
} else if (groupKey) {
|
|
243
|
+
groupPanels[groupKey].push(panel);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return groupPanels;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private _getSideStateFromGroup(
|
|
251
|
+
groupPanels: Record<string, HTMLElement[]>
|
|
252
|
+
): SideState[] {
|
|
253
|
+
return Object.keys(groupPanels).reduce(
|
|
254
|
+
(state: SideState[], key: string) => {
|
|
255
|
+
const start = state.length ? +state[state.length - 1].end + 1 : 0;
|
|
256
|
+
const element = groupPanels[key].reduce(
|
|
257
|
+
(el: HTMLElement, panel: HTMLElement) => {
|
|
258
|
+
el.innerHTML += panel.outerHTML;
|
|
259
|
+
return el;
|
|
260
|
+
},
|
|
261
|
+
document.createElement("div")
|
|
262
|
+
);
|
|
263
|
+
return [
|
|
264
|
+
...state,
|
|
265
|
+
{
|
|
266
|
+
key,
|
|
267
|
+
start,
|
|
268
|
+
end: start + groupPanels[key].length - 1,
|
|
269
|
+
element: element
|
|
270
|
+
}
|
|
271
|
+
];
|
|
272
|
+
},
|
|
273
|
+
[]
|
|
274
|
+
);
|
|
275
|
+
}
|
|
143
276
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
277
|
+
private _getSideStateFromPanels(panels: HTMLElement[]): SideState[] {
|
|
278
|
+
return panels.reduce(
|
|
279
|
+
(state: SideState[], panel: HTMLElement, i: number) => {
|
|
280
|
+
const start = state.length ? +state[state.length - 1].end + 1 : 0;
|
|
281
|
+
return [
|
|
282
|
+
...state,
|
|
283
|
+
{
|
|
284
|
+
key: i.toString(),
|
|
285
|
+
start,
|
|
286
|
+
end: start + panel.children.length - 1,
|
|
287
|
+
element: panel
|
|
288
|
+
}
|
|
289
|
+
];
|
|
290
|
+
},
|
|
291
|
+
[]
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private _getSideStateFromCrossStructure(panels: HTMLElement[]): SideState[] {
|
|
296
|
+
const groupPanels = this._getGroupFromAttribute(panels);
|
|
297
|
+
return this._getSideStateFromGroup(groupPanels);
|
|
298
|
+
}
|
|
147
299
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
300
|
+
private _createSideFlicking(): Flicking[] {
|
|
301
|
+
return this.sideState.map((state, i) => {
|
|
302
|
+
return new Flicking(this.camera.children[i], {
|
|
303
|
+
...this.sideOptions,
|
|
304
|
+
horizontal: false,
|
|
305
|
+
panelsPerView: 1,
|
|
306
|
+
defaultIndex: state.start
|
|
153
307
|
});
|
|
154
308
|
});
|
|
155
309
|
}
|
|
156
310
|
|
|
157
|
-
private _syncToCategory(index: number, outerIndex: number): void {
|
|
311
|
+
private _syncToCategory = (index: number, outerIndex: number): void => {
|
|
312
|
+
if (this._disableIndexSync) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
158
316
|
this.stopAnimation();
|
|
159
|
-
this.
|
|
160
|
-
const { start, end } = this.
|
|
317
|
+
this._sideFlicking.forEach((child, i) => {
|
|
318
|
+
const { start, end } = this._sideState[i];
|
|
161
319
|
|
|
162
320
|
if (start <= index && end >= index && outerIndex !== i) {
|
|
163
321
|
child.stopAnimation();
|
|
@@ -165,18 +323,62 @@ export class CrossFlicking extends Flicking {
|
|
|
165
323
|
void this.moveTo(i, 0);
|
|
166
324
|
}
|
|
167
325
|
});
|
|
168
|
-
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
private _setDraggable = (
|
|
329
|
+
direction: ValueOf<typeof MOVE_DIRECTION>,
|
|
330
|
+
draggable: boolean
|
|
331
|
+
): void => {
|
|
332
|
+
if (!this._disableSlideOnHold) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const dragThreshold = this._originalDragThreshold;
|
|
337
|
+
const threshold = draggable
|
|
338
|
+
? dragThreshold && dragThreshold >= 10
|
|
339
|
+
? dragThreshold
|
|
340
|
+
: 10
|
|
341
|
+
: Infinity;
|
|
342
|
+
|
|
343
|
+
if ((direction === MOVE_DIRECTION.HORIZONTAL) === this.horizontal) {
|
|
344
|
+
this.dragThreshold = threshold;
|
|
345
|
+
} else if ((direction === MOVE_DIRECTION.VERTICAL) === this.horizontal) {
|
|
346
|
+
this._sideFlicking.forEach((child) => {
|
|
347
|
+
child.dragThreshold = threshold;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
private _setPreviousSideIndex = () => {
|
|
353
|
+
this._sideFlicking.forEach((child, i) => {
|
|
354
|
+
const { start, end } = this._sideState[i];
|
|
355
|
+
|
|
356
|
+
if (this._preserveIndex) {
|
|
357
|
+
if (this._nextIndex !== i) {
|
|
358
|
+
if (child.index < start) {
|
|
359
|
+
child.stopAnimation();
|
|
360
|
+
void child.moveTo(start, 0);
|
|
361
|
+
} else if (child.index > end) {
|
|
362
|
+
child.stopAnimation();
|
|
363
|
+
void child.moveTo(end, 0);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
if (this._nextIndex !== i) {
|
|
368
|
+
void child.moveTo(start, 0);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
};
|
|
169
373
|
|
|
170
374
|
private _onHorizontalHoldStart = (): void => {
|
|
171
|
-
this.
|
|
375
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
|
|
172
376
|
this._moveDirection = null;
|
|
173
377
|
};
|
|
174
378
|
|
|
175
379
|
private _onHorizontalMove = (e: MoveEvent): void => {
|
|
176
380
|
if (e.isTrusted && !this._moveDirection) {
|
|
177
|
-
this.
|
|
178
|
-
child.dragThreshold = Infinity;
|
|
179
|
-
});
|
|
381
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
|
|
180
382
|
this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
|
|
181
383
|
}
|
|
182
384
|
};
|
|
@@ -184,11 +386,6 @@ export class CrossFlicking extends Flicking {
|
|
|
184
386
|
private _onHorizontalMoveEnd = (e: MoveEndEvent): void => {
|
|
185
387
|
const visiblePanels = this.visiblePanels;
|
|
186
388
|
|
|
187
|
-
this._verticalFlicking.forEach((child) => {
|
|
188
|
-
child.dragThreshold = 10;
|
|
189
|
-
});
|
|
190
|
-
this._moveDirection = null;
|
|
191
|
-
|
|
192
389
|
if (visiblePanels.length > 1) {
|
|
193
390
|
this._nextIndex =
|
|
194
391
|
e.direction === "NEXT"
|
|
@@ -198,53 +395,43 @@ export class CrossFlicking extends Flicking {
|
|
|
198
395
|
this._nextIndex = visiblePanels[0].index;
|
|
199
396
|
}
|
|
200
397
|
|
|
201
|
-
this.
|
|
202
|
-
|
|
203
|
-
const { start, end } = this._verticalState[i];
|
|
398
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
|
|
399
|
+
this._moveDirection = null;
|
|
204
400
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
void child.moveTo(start, 0);
|
|
208
|
-
} else if (child.index > end) {
|
|
209
|
-
child.stopAnimation();
|
|
210
|
-
void child.moveTo(end, 0);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
401
|
+
// _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
|
|
402
|
+
requestAnimationFrame(() => this._setPreviousSideIndex());
|
|
214
403
|
|
|
215
404
|
if (e.isTrusted) {
|
|
216
405
|
this._syncToCategory(
|
|
217
|
-
this.
|
|
406
|
+
this._sideFlicking[this._nextIndex].index,
|
|
218
407
|
this._nextIndex
|
|
219
408
|
);
|
|
220
409
|
}
|
|
221
410
|
};
|
|
222
411
|
|
|
223
|
-
private
|
|
224
|
-
this.
|
|
225
|
-
child.dragThreshold = 10;
|
|
226
|
-
});
|
|
412
|
+
private _onSideHoldStart = (): void => {
|
|
413
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
|
|
227
414
|
this._moveDirection = null;
|
|
228
415
|
};
|
|
229
416
|
|
|
230
|
-
private
|
|
417
|
+
private _onSideMove = (e: MoveEvent): void => {
|
|
231
418
|
if (e.isTrusted && !this._moveDirection) {
|
|
232
|
-
this.
|
|
419
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
|
|
233
420
|
this._moveDirection = MOVE_DIRECTION.VERTICAL;
|
|
234
421
|
}
|
|
235
422
|
};
|
|
236
423
|
|
|
237
|
-
private
|
|
238
|
-
this.
|
|
424
|
+
private _onSideMoveEnd = (): void => {
|
|
425
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
|
|
239
426
|
this._moveDirection = null;
|
|
240
427
|
};
|
|
241
428
|
|
|
242
|
-
private
|
|
243
|
-
// this.visiblePanels.length
|
|
244
|
-
//
|
|
429
|
+
private _onSideChanged = (e: ChangedEvent): void => {
|
|
430
|
+
// If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
|
|
431
|
+
// In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
|
|
245
432
|
if (
|
|
246
433
|
this.visiblePanels.length < 2 &&
|
|
247
|
-
this.
|
|
434
|
+
this._sideFlicking[this.index] === e.currentTarget
|
|
248
435
|
) {
|
|
249
436
|
this._syncToCategory(e.index, this.index);
|
|
250
437
|
}
|