@egjs/flicking 4.12.0-beta.0 → 4.12.0-beta.1
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 +29 -0
- package/declaration/const/external.d.ts +4 -0
- package/declaration/index.d.ts +1 -0
- package/dist/flicking.cjs.js +191 -2
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +188 -3
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +194 -2
- 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 +194 -2
- 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 +1 -1
- package/src/CrossFlicking.ts +252 -0
- package/src/const/external.ts +12 -0
- package/src/index.ts +2 -0
- package/src/index.umd.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import Flicking, { FlickingOptions } from "./Flicking";
|
|
7
|
+
import { ChangedEvent, MoveEndEvent, MoveEvent } from "./type/event";
|
|
8
|
+
import { LiteralUnion, ValueOf } from "./type/internal";
|
|
9
|
+
import { EVENTS, MOVE_DIRECTION } from "./const/external";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @interface
|
|
13
|
+
*/
|
|
14
|
+
export interface CrossFlickingEvents {
|
|
15
|
+
// FlickingEvent 들을 확장하자...
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @interface
|
|
20
|
+
*/
|
|
21
|
+
export interface CrossFlickingOptions {
|
|
22
|
+
verticalOptions: FlickingOptions | undefined;
|
|
23
|
+
// 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
|
|
24
|
+
// 이전 패널 기억 여부
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Flicking Status returned by {@link Flicking#getStatus}
|
|
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 {
|
|
42
|
+
start: number;
|
|
43
|
+
end: number;
|
|
44
|
+
element: HTMLElement;
|
|
45
|
+
}
|
|
46
|
+
|
|
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
|
+
export class CrossFlicking extends Flicking {
|
|
54
|
+
// Core components
|
|
55
|
+
private _verticalFlicking: Flicking[];
|
|
56
|
+
|
|
57
|
+
// Options
|
|
58
|
+
private _verticalOptions: CrossFlickingOptions["verticalOptions"];
|
|
59
|
+
|
|
60
|
+
// Internal State
|
|
61
|
+
private _verticalState: VerticalState[];
|
|
62
|
+
|
|
63
|
+
private _moveDirection: LiteralUnion<ValueOf<typeof MOVE_DIRECTION>> | null;
|
|
64
|
+
private _nextIndex: number;
|
|
65
|
+
|
|
66
|
+
// Components
|
|
67
|
+
/**
|
|
68
|
+
* Change active panel index on mouse/touch hold while animating.
|
|
69
|
+
* `index` of the `willChange`/`willRestore` event will be used as new index.
|
|
70
|
+
* @ko 애니메이션 도중 마우스/터치 입력시 현재 활성화된 패널의 인덱스를 변경합니다.
|
|
71
|
+
* `willChange`/`willRestore` 이벤트의 `index`값이 새로운 인덱스로 사용될 것입니다.
|
|
72
|
+
* @type {FlickingOptions}
|
|
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;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Options Setter
|
|
81
|
+
// UI / LAYOUT
|
|
82
|
+
// public set align(val: FlickingOptions["align"]) {
|
|
83
|
+
// this._align = val;
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
public constructor(
|
|
87
|
+
root: HTMLElement | string,
|
|
88
|
+
{ verticalOptions = undefined }: Partial<CrossFlickingOptions> = {}
|
|
89
|
+
) {
|
|
90
|
+
super(root);
|
|
91
|
+
|
|
92
|
+
// Internal states
|
|
93
|
+
this._verticalState = [];
|
|
94
|
+
this._moveDirection = null;
|
|
95
|
+
this._nextIndex = 0;
|
|
96
|
+
|
|
97
|
+
// Bind options
|
|
98
|
+
this._verticalOptions = verticalOptions;
|
|
99
|
+
|
|
100
|
+
// Create core components
|
|
101
|
+
// this._viewport = new Viewport(this, getElement(root));
|
|
102
|
+
}
|
|
103
|
+
|
|
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
|
+
public init(): Promise<void> {
|
|
113
|
+
return super.init().then(() => {
|
|
114
|
+
// data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
|
|
115
|
+
// camera.children들에 대해 갯수 세기
|
|
116
|
+
let verticalPanels = ``;
|
|
117
|
+
this._verticalState = this.camera.children.reduce(
|
|
118
|
+
(state: VerticalState[], child: HTMLElement) => {
|
|
119
|
+
const start = state.length ? +state[state.length - 1].end + 1 : 0;
|
|
120
|
+
verticalPanels += child.children[0].innerHTML;
|
|
121
|
+
return [
|
|
122
|
+
...state,
|
|
123
|
+
{
|
|
124
|
+
start,
|
|
125
|
+
end: start + child.children[0].children.length - 1,
|
|
126
|
+
element: child,
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
},
|
|
130
|
+
[]
|
|
131
|
+
);
|
|
132
|
+
this.camera.children.forEach((child) => {
|
|
133
|
+
child.children[0].innerHTML = verticalPanels;
|
|
134
|
+
});
|
|
135
|
+
this._verticalFlicking = this.camera.children.map((child, i) => {
|
|
136
|
+
return new Flicking(child, {
|
|
137
|
+
...this.verticalOptions,
|
|
138
|
+
horizontal: false,
|
|
139
|
+
panelsPerView: 1,
|
|
140
|
+
defaultIndex: this._verticalState[i].start,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
|
|
145
|
+
this.on(EVENTS.MOVE, this._onHorizontalMove);
|
|
146
|
+
this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
|
|
147
|
+
|
|
148
|
+
this._verticalFlicking.forEach((child) => {
|
|
149
|
+
child.on(EVENTS.HOLD_START, this._onVerticalHoldStart);
|
|
150
|
+
child.on(EVENTS.MOVE, this._onVerticalMove);
|
|
151
|
+
child.on(EVENTS.MOVE_END, this._onVerticalMoveEnd);
|
|
152
|
+
child.on(EVENTS.CHANGED, this._onVerticalChanged);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private _syncToCategory(index: number, outerIndex: number): void {
|
|
158
|
+
this.stopAnimation();
|
|
159
|
+
this._verticalFlicking.forEach((child, i) => {
|
|
160
|
+
const { start, end } = this._verticalState[i];
|
|
161
|
+
|
|
162
|
+
if (start <= index && end >= index && outerIndex !== i) {
|
|
163
|
+
child.stopAnimation();
|
|
164
|
+
void child.moveTo(index, 0);
|
|
165
|
+
void this.moveTo(i, 0);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private _onHorizontalHoldStart = (): void => {
|
|
171
|
+
this.dragThreshold = 10;
|
|
172
|
+
this._moveDirection = null;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
private _onHorizontalMove = (e: MoveEvent): void => {
|
|
176
|
+
if (e.isTrusted && !this._moveDirection) {
|
|
177
|
+
this._verticalFlicking.forEach((child) => {
|
|
178
|
+
child.dragThreshold = Infinity;
|
|
179
|
+
});
|
|
180
|
+
this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
private _onHorizontalMoveEnd = (e: MoveEndEvent): void => {
|
|
185
|
+
const visiblePanels = this.visiblePanels;
|
|
186
|
+
|
|
187
|
+
this._verticalFlicking.forEach((child) => {
|
|
188
|
+
child.dragThreshold = 10;
|
|
189
|
+
});
|
|
190
|
+
this._moveDirection = null;
|
|
191
|
+
|
|
192
|
+
if (visiblePanels.length > 1) {
|
|
193
|
+
this._nextIndex =
|
|
194
|
+
e.direction === "NEXT"
|
|
195
|
+
? visiblePanels[1].index
|
|
196
|
+
: visiblePanels[0].index;
|
|
197
|
+
} else {
|
|
198
|
+
this._nextIndex = visiblePanels[0].index;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this._verticalFlicking.forEach((child, i) => {
|
|
202
|
+
if (this._nextIndex !== i) {
|
|
203
|
+
const { start, end } = this._verticalState[i];
|
|
204
|
+
|
|
205
|
+
if (child.index < start) {
|
|
206
|
+
child.stopAnimation();
|
|
207
|
+
void child.moveTo(start, 0);
|
|
208
|
+
} else if (child.index > end) {
|
|
209
|
+
child.stopAnimation();
|
|
210
|
+
void child.moveTo(end, 0);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (e.isTrusted) {
|
|
216
|
+
this._syncToCategory(
|
|
217
|
+
this._verticalFlicking[this._nextIndex].index,
|
|
218
|
+
this._nextIndex
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
private _onVerticalHoldStart = (): void => {
|
|
224
|
+
this._verticalFlicking.forEach((child) => {
|
|
225
|
+
child.dragThreshold = 10;
|
|
226
|
+
});
|
|
227
|
+
this._moveDirection = null;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
private _onVerticalMove = (e: MoveEvent): void => {
|
|
231
|
+
if (e.isTrusted && !this._moveDirection) {
|
|
232
|
+
this.dragThreshold = Infinity;
|
|
233
|
+
this._moveDirection = MOVE_DIRECTION.VERTICAL;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
private _onVerticalMoveEnd = (): void => {
|
|
238
|
+
this.dragThreshold = 10;
|
|
239
|
+
this._moveDirection = null;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
private _onVerticalChanged = (e: ChangedEvent): void => {
|
|
243
|
+
// this.visiblePanels.length 가 2보다 크다면 가로 방향 Flicking이 조작 중이라는 것을 의미합니다.
|
|
244
|
+
// 이 경우 가로 방향 Flicking의 이동이 완전히 끝난 뒤 _onHorizontalMoveEnd 에서 syncToCategory할 것이므로 여기서는 하지 않습니다.
|
|
245
|
+
if (
|
|
246
|
+
this.visiblePanels.length < 2 &&
|
|
247
|
+
this._verticalFlicking[this.index] === e.currentTarget
|
|
248
|
+
) {
|
|
249
|
+
this._syncToCategory(e.index, this.index);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
package/src/const/external.ts
CHANGED
|
@@ -122,3 +122,15 @@ export const ORDER = {
|
|
|
122
122
|
LTR: "ltr",
|
|
123
123
|
RTL: "rtl"
|
|
124
124
|
} as const;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* An object that contains the direction that {@link Flicking} is moving
|
|
128
|
+
* @ko {@link Flicking}이 움직이는 방향을 담고 있는 객체
|
|
129
|
+
* @type {object}
|
|
130
|
+
* @property {"horizontal"} HORIZONTAL horizontal<ko>수평 방향</ko>
|
|
131
|
+
* @property {"vertical"} VERTICAL vertical<ko>수직 방향</ko>
|
|
132
|
+
*/
|
|
133
|
+
export const MOVE_DIRECTION = {
|
|
134
|
+
HORIZONTAL: "horizontal",
|
|
135
|
+
VERTICAL: "vertical"
|
|
136
|
+
} as const;
|
package/src/index.ts
CHANGED
package/src/index.umd.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import Flicking from "./Flicking";
|
|
6
|
+
import * as CrossFlicking from "./CrossFlicking";
|
|
6
7
|
import * as Core from "./core";
|
|
7
8
|
import * as Camera from "./camera";
|
|
8
9
|
import * as Control from "./control";
|
|
@@ -19,5 +20,6 @@ merge(Flicking, Renderer);
|
|
|
19
20
|
merge(Flicking, Constants);
|
|
20
21
|
merge(Flicking, CFC);
|
|
21
22
|
merge(Flicking, Utils);
|
|
23
|
+
merge(Flicking, CrossFlicking);
|
|
22
24
|
|
|
23
25
|
export default Flicking;
|