@egjs/flicking 4.12.0-beta.1 → 4.12.0-beta.11
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 +66 -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 +327 -122
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.css +5 -5
- package/dist/flicking.esm.js +321 -122
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +324 -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 +1091 -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 +4 -3
- package/sass/flicking.sass +13 -0
- package/src/CrossFlicking.ts +336 -143
- package/src/camera/Camera.ts +24 -4
- package/src/const/external.ts +2 -0
- package/src/control/states/HoldingState.ts +4 -0
- package/src/core/panel/Panel.ts +4 -0
- package/src/index.ts +2 -1
- package/src/utils.ts +21 -0
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.11",
|
|
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",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "concurrently \"rollup -w --config ./rollup.config.dev.js\" \"http-serve\"",
|
|
15
15
|
"build": "run-s build:bundle build:declaration build:css 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",
|
|
@@ -114,7 +115,6 @@
|
|
|
114
115
|
"husky": "^1.3.1",
|
|
115
116
|
"jsdoc-to-mdx": "^1.1.2",
|
|
116
117
|
"karma-typescript-es6-transform": "^5.5.2",
|
|
117
|
-
"node-sass": "^7.0.1",
|
|
118
118
|
"npm-run-all": "^4.1.5",
|
|
119
119
|
"postcss-clean": "^1.2.2",
|
|
120
120
|
"postcss-cli": "^7.1.2",
|
|
@@ -129,6 +129,7 @@
|
|
|
129
129
|
"rollup-plugin-terser": "^7.0.2",
|
|
130
130
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
131
131
|
"rollup-plugin-visualizer": "^4.2.1",
|
|
132
|
+
"sass": "^1.79.3",
|
|
132
133
|
"sync-exec": "^0.6.2",
|
|
133
134
|
"ts-mock-imports": "^1.3.3",
|
|
134
135
|
"tsconfig-paths-webpack-plugin": "^3.5.1",
|
|
@@ -139,7 +140,7 @@
|
|
|
139
140
|
"typescript-transform-paths": "^2.2.3"
|
|
140
141
|
},
|
|
141
142
|
"dependencies": {
|
|
142
|
-
"@egjs/axes": "^3.9.
|
|
143
|
+
"@egjs/axes": "^3.9.1",
|
|
143
144
|
"@egjs/component": "^3.0.1",
|
|
144
145
|
"@egjs/imready": "^1.3.1",
|
|
145
146
|
"@egjs/list-differ": "^1.0.1"
|
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,326 @@
|
|
|
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
|
+
RestoredEvent,
|
|
17
|
+
WillChangeEvent,
|
|
18
|
+
WillRestoreEvent
|
|
19
|
+
} from "./type/event";
|
|
8
20
|
import { LiteralUnion, ValueOf } from "./type/internal";
|
|
9
|
-
import { EVENTS, MOVE_DIRECTION } from "./const/external";
|
|
21
|
+
import { CLASS, EVENTS, MOVE_DIRECTION } from "./const/external";
|
|
22
|
+
import { getDataAttributes, includes, toArray } from "./utils";
|
|
10
23
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
export const SIDE_EVENTS = {
|
|
25
|
+
HOLD_START: "sideHoldStart",
|
|
26
|
+
HOLD_END: "sideHoldEnd",
|
|
27
|
+
MOVE_START: "sideMoveStart",
|
|
28
|
+
MOVE: "sideMove",
|
|
29
|
+
MOVE_END: "sideMoveEnd",
|
|
30
|
+
WILL_CHANGE: "sideWillChange",
|
|
31
|
+
CHANGED: "sideChanged",
|
|
32
|
+
WILL_RESTORE: "sideWillRestore",
|
|
33
|
+
RESTORED: "sideRestored"
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
export type CrossFlickingEvent<T> = { mainIndex: number } & T;
|
|
37
|
+
|
|
38
|
+
export interface CrossFlickingEvents extends FlickingEvents {
|
|
39
|
+
[SIDE_EVENTS.HOLD_START]: CrossFlickingEvent<HoldStartEvent>;
|
|
40
|
+
[SIDE_EVENTS.HOLD_END]: CrossFlickingEvent<HoldEndEvent>;
|
|
41
|
+
[SIDE_EVENTS.MOVE_START]: CrossFlickingEvent<MoveStartEvent>;
|
|
42
|
+
[SIDE_EVENTS.MOVE]: CrossFlickingEvent<MoveEvent>;
|
|
43
|
+
[SIDE_EVENTS.MOVE_END]: CrossFlickingEvent<MoveEndEvent>;
|
|
44
|
+
[SIDE_EVENTS.WILL_CHANGE]: CrossFlickingEvent<WillChangeEvent>;
|
|
45
|
+
[SIDE_EVENTS.CHANGED]: CrossFlickingEvent<ChangedEvent>;
|
|
46
|
+
[SIDE_EVENTS.WILL_RESTORE]: CrossFlickingEvent<WillRestoreEvent>;
|
|
47
|
+
[SIDE_EVENTS.RESTORED]: CrossFlickingEvent<RestoredEvent>;
|
|
16
48
|
}
|
|
17
49
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
|
|
24
|
-
// 이전 패널 기억 여부
|
|
50
|
+
export interface CrossFlickingOptions extends FlickingOptions {
|
|
51
|
+
sideOptions: Partial<FlickingOptions> | undefined;
|
|
52
|
+
preserveIndex: boolean | undefined;
|
|
53
|
+
disableSlideOnHold: boolean | undefined;
|
|
54
|
+
disableIndexSync: boolean | undefined;
|
|
25
55
|
}
|
|
26
56
|
|
|
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 {
|
|
57
|
+
export interface SideState {
|
|
58
|
+
key: string;
|
|
42
59
|
start: number;
|
|
43
60
|
end: number;
|
|
44
61
|
element: HTMLElement;
|
|
45
62
|
}
|
|
46
63
|
|
|
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
64
|
export class CrossFlicking extends Flicking {
|
|
54
65
|
// Core components
|
|
55
|
-
private
|
|
66
|
+
private _sideFlicking: Flicking[];
|
|
56
67
|
|
|
57
68
|
// Options
|
|
58
|
-
private
|
|
69
|
+
private _sideOptions: CrossFlickingOptions["sideOptions"];
|
|
70
|
+
private _preserveIndex: CrossFlickingOptions["preserveIndex"];
|
|
71
|
+
private _disableSlideOnHold: CrossFlickingOptions["disableSlideOnHold"];
|
|
72
|
+
private _disableIndexSync: CrossFlickingOptions["disableIndexSync"];
|
|
59
73
|
|
|
60
74
|
// Internal State
|
|
61
|
-
private
|
|
62
|
-
|
|
75
|
+
private _sideState: SideState[];
|
|
63
76
|
private _moveDirection: LiteralUnion<ValueOf<typeof MOVE_DIRECTION>> | null;
|
|
77
|
+
private _originalDragThreshold: number;
|
|
64
78
|
private _nextIndex: number;
|
|
65
79
|
|
|
66
80
|
// 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;
|
|
81
|
+
public get sideFlicking() {
|
|
82
|
+
return this._sideFlicking;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public get sideState() {
|
|
86
|
+
return this._sideState;
|
|
78
87
|
}
|
|
79
88
|
|
|
89
|
+
// Options Getter
|
|
90
|
+
public get sideOptions() { return this._sideOptions; }
|
|
91
|
+
|
|
92
|
+
public get preserveIndex() { return this._preserveIndex; }
|
|
93
|
+
|
|
94
|
+
public get disableSlideOnHold() { return this._disableSlideOnHold; }
|
|
95
|
+
|
|
96
|
+
public get disableIndexSync() { return this._disableIndexSync; }
|
|
97
|
+
|
|
80
98
|
// Options Setter
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
public set sideOptions(val: CrossFlickingOptions["sideOptions"]) {
|
|
100
|
+
this._sideOptions = val;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public set preserveIndex(val: CrossFlickingOptions["preserveIndex"]) {
|
|
104
|
+
this._preserveIndex = val;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public set disableSlideOnHold(val: CrossFlickingOptions["disableSlideOnHold"]) {
|
|
108
|
+
this._disableSlideOnHold = val;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public set disableIndexSync(val: CrossFlickingOptions["disableIndexSync"]) {
|
|
112
|
+
this._disableIndexSync = val;
|
|
113
|
+
}
|
|
85
114
|
|
|
86
115
|
public constructor(
|
|
87
116
|
root: HTMLElement | string,
|
|
88
|
-
|
|
117
|
+
options: Partial<CrossFlickingOptions>
|
|
89
118
|
) {
|
|
90
|
-
super(root);
|
|
119
|
+
super(root, options);
|
|
120
|
+
const {
|
|
121
|
+
sideOptions = {},
|
|
122
|
+
preserveIndex = true,
|
|
123
|
+
disableSlideOnHold = true,
|
|
124
|
+
disableIndexSync = false
|
|
125
|
+
} = options;
|
|
91
126
|
|
|
92
127
|
// Internal states
|
|
93
|
-
this._verticalState = [];
|
|
94
128
|
this._moveDirection = null;
|
|
95
129
|
this._nextIndex = 0;
|
|
130
|
+
this._originalDragThreshold = this.dragThreshold;
|
|
96
131
|
|
|
97
132
|
// Bind options
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
133
|
+
this._sideOptions = sideOptions;
|
|
134
|
+
this._preserveIndex = preserveIndex;
|
|
135
|
+
this._disableSlideOnHold = disableSlideOnHold;
|
|
136
|
+
this._disableIndexSync = disableIndexSync;
|
|
102
137
|
}
|
|
103
138
|
|
|
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
139
|
public init(): Promise<void> {
|
|
113
140
|
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
|
-
|
|
141
|
+
this._sideState = this._createSideState();
|
|
142
|
+
this._sideFlicking = this._createSideFlicking();
|
|
143
|
+
this._addComponentEvents();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public destroy(): void {
|
|
148
|
+
this._sideFlicking.forEach((flicking) => {
|
|
149
|
+
flicking.destroy();
|
|
150
|
+
});
|
|
151
|
+
super.destroy();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private _addComponentEvents(): void {
|
|
155
|
+
this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
|
|
156
|
+
this.on(EVENTS.MOVE, this._onHorizontalMove);
|
|
157
|
+
this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
|
|
158
|
+
|
|
159
|
+
this._sideFlicking.forEach((flicking, mainIndex) => {
|
|
160
|
+
flicking.on(EVENTS.HOLD_START, this._onSideHoldStart);
|
|
161
|
+
flicking.on(EVENTS.MOVE, this._onSideMove);
|
|
162
|
+
flicking.on(EVENTS.MOVE_END, this._onSideMoveEnd);
|
|
163
|
+
flicking.on(EVENTS.CHANGED, this._onSideChanged);
|
|
164
|
+
|
|
165
|
+
Object.keys(SIDE_EVENTS).forEach((name: EventKey<FlickingEvents>) => {
|
|
166
|
+
flicking.on(EVENTS[name], (event) => {
|
|
167
|
+
this.trigger(
|
|
168
|
+
new ComponentEvent(SIDE_EVENTS[name], {
|
|
169
|
+
mainIndex,
|
|
170
|
+
...event
|
|
171
|
+
})
|
|
172
|
+
);
|
|
141
173
|
});
|
|
142
174
|
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private _createSideState(): SideState[] {
|
|
179
|
+
const viewportEl = this.element;
|
|
180
|
+
const cameraEl = this.camera.element;
|
|
181
|
+
const panels = toArray(cameraEl.children) as HTMLElement[];
|
|
182
|
+
const isCrossStructure = getDataAttributes(
|
|
183
|
+
viewportEl,
|
|
184
|
+
"data-cross-"
|
|
185
|
+
).structure;
|
|
186
|
+
let sideState: SideState[] = [];
|
|
187
|
+
|
|
188
|
+
if (!isCrossStructure) {
|
|
189
|
+
const groupPanels = this._getGroupFromAttribute(panels);
|
|
190
|
+
const groupKeys = Object.keys(groupPanels);
|
|
191
|
+
|
|
192
|
+
if (groupKeys.length) {
|
|
193
|
+
sideState = this._getSideStateFromGroup(groupPanels);
|
|
194
|
+
this.remove(0, this.panelCount - groupKeys.length);
|
|
195
|
+
} else {
|
|
196
|
+
sideState = this._getSideStateFromPanels(panels);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this._createCrossStructure(sideState);
|
|
200
|
+
} else {
|
|
201
|
+
sideState = this._getSideStateFromCrossStructure(panels);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void this.resize();
|
|
205
|
+
|
|
206
|
+
return sideState;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private _createCrossStructure(sideState: SideState[]) {
|
|
210
|
+
const sideCamera = document.createElement("div");
|
|
211
|
+
let sidePanels: string = "";
|
|
212
|
+
|
|
213
|
+
sideCamera.classList.add(CLASS.CAMERA);
|
|
214
|
+
sideState.forEach((state, i) => {
|
|
215
|
+
const panel = this.camera.children[i];
|
|
216
|
+
sidePanels += state.element.innerHTML;
|
|
217
|
+
Array.from(panel.attributes).forEach((attribute) =>
|
|
218
|
+
panel.removeAttribute(attribute.name)
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
sideCamera.innerHTML = sidePanels;
|
|
223
|
+
|
|
224
|
+
sideState.forEach((_, i) => {
|
|
225
|
+
const panel = this.camera.children[i];
|
|
226
|
+
[CLASS.VIEWPORT, CLASS.VERTICAL].forEach((className) => {
|
|
227
|
+
if (!panel.classList.contains(className)) {
|
|
228
|
+
panel.classList.add(className);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
panel.innerHTML = sideCamera.outerHTML;
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
this.element.setAttribute("data-cross-structure", "true");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private _getGroupFromAttribute(
|
|
238
|
+
panels: HTMLElement[]
|
|
239
|
+
): Record<string, HTMLElement[]> {
|
|
240
|
+
const groupKeys: string[] = [];
|
|
241
|
+
const groupPanels: Record<string, HTMLElement[]> = {};
|
|
242
|
+
|
|
243
|
+
panels.forEach((panel) => {
|
|
244
|
+
const groupKey = getDataAttributes(panel, "data-cross-").groupkey;
|
|
245
|
+
if (groupKey && !includes(groupKeys, groupKey)) {
|
|
246
|
+
groupKeys.push(groupKey);
|
|
247
|
+
groupPanels[groupKey] = [panel];
|
|
248
|
+
} else if (groupKey) {
|
|
249
|
+
groupPanels[groupKey].push(panel);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return groupPanels;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private _getSideStateFromGroup(
|
|
257
|
+
groupPanels: Record<string, HTMLElement[]>
|
|
258
|
+
): SideState[] {
|
|
259
|
+
return Object.keys(groupPanels).reduce(
|
|
260
|
+
(state: SideState[], key: string) => {
|
|
261
|
+
const start = state.length ? +state[state.length - 1].end + 1 : 0;
|
|
262
|
+
const element = groupPanels[key].reduce(
|
|
263
|
+
(el: HTMLElement, panel: HTMLElement) => {
|
|
264
|
+
el.innerHTML += panel.outerHTML;
|
|
265
|
+
return el;
|
|
266
|
+
},
|
|
267
|
+
document.createElement("div")
|
|
268
|
+
);
|
|
269
|
+
return [
|
|
270
|
+
...state,
|
|
271
|
+
{
|
|
272
|
+
key,
|
|
273
|
+
start,
|
|
274
|
+
end: start + groupPanels[key].length - 1,
|
|
275
|
+
element: element
|
|
276
|
+
}
|
|
277
|
+
];
|
|
278
|
+
},
|
|
279
|
+
[]
|
|
280
|
+
);
|
|
281
|
+
}
|
|
143
282
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
283
|
+
private _getSideStateFromPanels(panels: HTMLElement[]): SideState[] {
|
|
284
|
+
return panels.reduce(
|
|
285
|
+
(state: SideState[], panel: HTMLElement, i: number) => {
|
|
286
|
+
const start = state.length ? +state[state.length - 1].end + 1 : 0;
|
|
287
|
+
return [
|
|
288
|
+
...state,
|
|
289
|
+
{
|
|
290
|
+
key: i.toString(),
|
|
291
|
+
start,
|
|
292
|
+
end: start + panel.children.length - 1,
|
|
293
|
+
element: panel
|
|
294
|
+
}
|
|
295
|
+
];
|
|
296
|
+
},
|
|
297
|
+
[]
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private _getSideStateFromCrossStructure(panels: HTMLElement[]): SideState[] {
|
|
302
|
+
const groupPanels = this._getGroupFromAttribute(panels);
|
|
303
|
+
return this._getSideStateFromGroup(groupPanels);
|
|
304
|
+
}
|
|
147
305
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
306
|
+
private _createSideFlicking(): Flicking[] {
|
|
307
|
+
return this.sideState.map((state, i) => {
|
|
308
|
+
return new Flicking(this.camera.children[i], {
|
|
309
|
+
...this.sideOptions,
|
|
310
|
+
horizontal: false,
|
|
311
|
+
panelsPerView: 1,
|
|
312
|
+
defaultIndex: state.start
|
|
153
313
|
});
|
|
154
314
|
});
|
|
155
315
|
}
|
|
156
316
|
|
|
157
|
-
private _syncToCategory(index: number, outerIndex: number): void {
|
|
317
|
+
private _syncToCategory = (index: number, outerIndex: number): void => {
|
|
318
|
+
if (this._disableIndexSync) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
158
322
|
this.stopAnimation();
|
|
159
|
-
this.
|
|
160
|
-
const { start, end } = this.
|
|
323
|
+
this._sideFlicking.forEach((child, i) => {
|
|
324
|
+
const { start, end } = this._sideState[i];
|
|
161
325
|
|
|
162
326
|
if (start <= index && end >= index && outerIndex !== i) {
|
|
163
327
|
child.stopAnimation();
|
|
@@ -165,18 +329,62 @@ export class CrossFlicking extends Flicking {
|
|
|
165
329
|
void this.moveTo(i, 0);
|
|
166
330
|
}
|
|
167
331
|
});
|
|
168
|
-
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
private _setDraggable = (
|
|
335
|
+
direction: ValueOf<typeof MOVE_DIRECTION>,
|
|
336
|
+
draggable: boolean
|
|
337
|
+
): void => {
|
|
338
|
+
if (!this._disableSlideOnHold) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const dragThreshold = this._originalDragThreshold;
|
|
343
|
+
const threshold = draggable
|
|
344
|
+
? dragThreshold && dragThreshold >= 10
|
|
345
|
+
? dragThreshold
|
|
346
|
+
: 10
|
|
347
|
+
: Infinity;
|
|
348
|
+
|
|
349
|
+
if ((direction === MOVE_DIRECTION.HORIZONTAL) === this.horizontal) {
|
|
350
|
+
this.dragThreshold = threshold;
|
|
351
|
+
} else if ((direction === MOVE_DIRECTION.VERTICAL) === this.horizontal) {
|
|
352
|
+
this._sideFlicking.forEach((child) => {
|
|
353
|
+
child.dragThreshold = threshold;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
private _setPreviousSideIndex = () => {
|
|
359
|
+
this._sideFlicking.forEach((child, i) => {
|
|
360
|
+
const { start, end } = this._sideState[i];
|
|
361
|
+
|
|
362
|
+
if (this._preserveIndex) {
|
|
363
|
+
if (this._nextIndex !== i) {
|
|
364
|
+
if (child.index < start) {
|
|
365
|
+
child.stopAnimation();
|
|
366
|
+
void child.moveTo(start, 0);
|
|
367
|
+
} else if (child.index > end) {
|
|
368
|
+
child.stopAnimation();
|
|
369
|
+
void child.moveTo(end, 0);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
if (this._nextIndex !== i) {
|
|
374
|
+
void child.moveTo(start, 0);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
};
|
|
169
379
|
|
|
170
380
|
private _onHorizontalHoldStart = (): void => {
|
|
171
|
-
this.
|
|
381
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
|
|
172
382
|
this._moveDirection = null;
|
|
173
383
|
};
|
|
174
384
|
|
|
175
385
|
private _onHorizontalMove = (e: MoveEvent): void => {
|
|
176
386
|
if (e.isTrusted && !this._moveDirection) {
|
|
177
|
-
this.
|
|
178
|
-
child.dragThreshold = Infinity;
|
|
179
|
-
});
|
|
387
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, false);
|
|
180
388
|
this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
|
|
181
389
|
}
|
|
182
390
|
};
|
|
@@ -184,11 +392,6 @@ export class CrossFlicking extends Flicking {
|
|
|
184
392
|
private _onHorizontalMoveEnd = (e: MoveEndEvent): void => {
|
|
185
393
|
const visiblePanels = this.visiblePanels;
|
|
186
394
|
|
|
187
|
-
this._verticalFlicking.forEach((child) => {
|
|
188
|
-
child.dragThreshold = 10;
|
|
189
|
-
});
|
|
190
|
-
this._moveDirection = null;
|
|
191
|
-
|
|
192
395
|
if (visiblePanels.length > 1) {
|
|
193
396
|
this._nextIndex =
|
|
194
397
|
e.direction === "NEXT"
|
|
@@ -198,53 +401,43 @@ export class CrossFlicking extends Flicking {
|
|
|
198
401
|
this._nextIndex = visiblePanels[0].index;
|
|
199
402
|
}
|
|
200
403
|
|
|
201
|
-
this.
|
|
202
|
-
|
|
203
|
-
const { start, end } = this._verticalState[i];
|
|
404
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
|
|
405
|
+
this._moveDirection = null;
|
|
204
406
|
|
|
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
|
-
});
|
|
407
|
+
// _syncToCategory에서 완전히 가로 이동이 이루어지기 전에 세로 방향 index가 변하는 경우가 있어 requestAnimationFrame 처리
|
|
408
|
+
requestAnimationFrame(() => this._setPreviousSideIndex());
|
|
214
409
|
|
|
215
410
|
if (e.isTrusted) {
|
|
216
411
|
this._syncToCategory(
|
|
217
|
-
this.
|
|
412
|
+
this._sideFlicking[this._nextIndex].index,
|
|
218
413
|
this._nextIndex
|
|
219
414
|
);
|
|
220
415
|
}
|
|
221
416
|
};
|
|
222
417
|
|
|
223
|
-
private
|
|
224
|
-
this.
|
|
225
|
-
child.dragThreshold = 10;
|
|
226
|
-
});
|
|
418
|
+
private _onSideHoldStart = (): void => {
|
|
419
|
+
this._setDraggable(MOVE_DIRECTION.VERTICAL, true);
|
|
227
420
|
this._moveDirection = null;
|
|
228
421
|
};
|
|
229
422
|
|
|
230
|
-
private
|
|
423
|
+
private _onSideMove = (e: MoveEvent): void => {
|
|
231
424
|
if (e.isTrusted && !this._moveDirection) {
|
|
232
|
-
this.
|
|
425
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, false);
|
|
233
426
|
this._moveDirection = MOVE_DIRECTION.VERTICAL;
|
|
234
427
|
}
|
|
235
428
|
};
|
|
236
429
|
|
|
237
|
-
private
|
|
238
|
-
this.
|
|
430
|
+
private _onSideMoveEnd = (): void => {
|
|
431
|
+
this._setDraggable(MOVE_DIRECTION.HORIZONTAL, true);
|
|
239
432
|
this._moveDirection = null;
|
|
240
433
|
};
|
|
241
434
|
|
|
242
|
-
private
|
|
243
|
-
// this.visiblePanels.length
|
|
244
|
-
//
|
|
435
|
+
private _onSideChanged = (e: ChangedEvent): void => {
|
|
436
|
+
// If this.visiblePanels.length >= 2, it means that horizontal flicking is being dragged.
|
|
437
|
+
// In this case, syncToCategory in _onHorizontalMoveEnd will fire after moving finishes, so we don't fire it here.
|
|
245
438
|
if (
|
|
246
439
|
this.visiblePanels.length < 2 &&
|
|
247
|
-
this.
|
|
440
|
+
this._sideFlicking[this.index] === e.currentTarget
|
|
248
441
|
) {
|
|
249
442
|
this._syncToCategory(e.index, this.index);
|
|
250
443
|
}
|