@egjs/react-flicking 4.11.5-beta.4 → 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.
Files changed (37) hide show
  1. package/declaration/CrossFlicking.d.ts +24 -0
  2. package/declaration/CrossGroup.d.ts +5 -0
  3. package/declaration/Flicking.d.ts +56 -41
  4. package/declaration/NonStrictPanel.d.ts +12 -12
  5. package/declaration/ReactElementProvider.d.ts +12 -12
  6. package/declaration/ReactRenderer.d.ts +17 -17
  7. package/declaration/StrictPanel.d.ts +14 -14
  8. package/declaration/ViewportSlot.d.ts +5 -5
  9. package/declaration/consts.d.ts +2 -2
  10. package/declaration/index.d.ts +8 -6
  11. package/declaration/index.umd.d.ts +2 -2
  12. package/declaration/types.d.ts +32 -32
  13. package/dist/flicking-inline.css +9 -1
  14. package/dist/flicking.cjs.js +54 -37
  15. package/dist/flicking.cjs.js.map +1 -1
  16. package/dist/flicking.css +4 -0
  17. package/dist/flicking.esm.js +143 -39
  18. package/dist/flicking.esm.js.map +1 -1
  19. package/dist/flicking.js +9221 -0
  20. package/dist/flicking.js.map +1 -0
  21. package/dist/flicking.min.js +10 -0
  22. package/dist/flicking.min.js.map +1 -0
  23. package/dist/flicking.pkgd.js +14483 -0
  24. package/dist/flicking.pkgd.js.map +1 -0
  25. package/dist/flicking.pkgd.min.js +10 -0
  26. package/dist/flicking.pkgd.min.js.map +1 -0
  27. package/dist/flicking.umd.js +54 -37
  28. package/dist/flicking.umd.js.map +1 -1
  29. package/package.json +3 -3
  30. package/src/react-flicking/CrossFlicking.tsx +135 -0
  31. package/src/react-flicking/CrossGroup.tsx +9 -0
  32. package/src/react-flicking/Flicking.tsx +61 -45
  33. package/src/react-flicking/consts.ts +1 -0
  34. package/src/react-flicking/index.ts +5 -1
  35. package/src/react-flicking/types.ts +1 -0
  36. package/dist/flicking-inline.css.map +0 -1
  37. package/dist/flicking.css.map +0 -1
@@ -15,7 +15,8 @@ import VanillaFlicking, {
15
15
  getDefaultCameraTransform,
16
16
  Plugin,
17
17
  range,
18
- NormalRenderingStrategy
18
+ NormalRenderingStrategy,
19
+ FlickingEvents,
19
20
  } from "@egjs/flicking";
20
21
 
21
22
  import { DEFAULT_PROPS } from "./consts";
@@ -29,14 +30,14 @@ import ReactElementProvider from "./ReactElementProvider";
29
30
  class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>> {
30
31
  public static defaultProps: FlickingProps = DEFAULT_PROPS;
31
32
 
32
- @withFlickingMethods private _vanillaFlicking: VanillaFlicking;
33
+ @withFlickingMethods protected _vanillaFlicking: VanillaFlicking;
33
34
  private _panels: React.RefObject<StrictPanel | NonStrictPanel | HTMLDivElement>[] = [];
34
- private _pluginsDiffer: ListDiffer<any>;
35
- private _jsxDiffer: ListDiffer<React.ReactElement>;
36
- private _viewportElement: HTMLElement;
35
+ protected _pluginsDiffer: ListDiffer<any>;
36
+ protected _jsxDiffer: ListDiffer<React.ReactElement>;
37
+ protected _viewportElement: HTMLElement;
37
38
  private _diffResult: DiffResult<React.ReactElement> | null;
38
39
  private _renderEmitter = new Component<{ render: void }>();
39
- private _prevChildren: React.ReactElement[];
40
+ protected _prevChildren: React.ReactElement[];
40
41
 
41
42
  public get reactPanels() { return this._panels.map(panel => panel.current!); }
42
43
  public get renderEmitter() { return this._renderEmitter; }
@@ -156,7 +157,6 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
156
157
  const Viewport = props.viewportTag as any;
157
158
  const Camera = props.cameraTag as any;
158
159
  const attributes: { [key: string]: any } = {};
159
- const flicking = this._vanillaFlicking;
160
160
 
161
161
  this.beforeRender();
162
162
 
@@ -166,31 +166,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
166
166
  }
167
167
  }
168
168
 
169
- const initialized = flicking && flicking.initialized;
170
- const viewportClasses: string[] = ["flicking-viewport"];
171
- const cameraClasses: string[] = ["flicking-camera"];
172
- const isHorizontal = flicking
173
- ? flicking.horizontal
174
- : props.horizontal ?? true;
175
-
176
- if (!isHorizontal) {
177
- viewportClasses.push("vertical");
178
- }
179
- if (props.hideBeforeInit && !initialized) {
180
- viewportClasses.push("flicking-hidden");
181
- }
182
- if (attributes.className) {
183
- viewportClasses.push(attributes.className);
184
- }
185
- if (props.cameraClass) {
186
- cameraClasses.push(props.cameraClass);
187
- }
188
-
189
- const cameraProps = !initialized && props.firstPanelSize
190
- ? { style: {
191
- transform: getDefaultCameraTransform(this.props.align, this.props.horizontal, this.props.firstPanelSize)
192
- }}
193
- : {};
169
+ const { viewportClasses, cameraClasses, cameraProps } = this._getClasses(attributes, props);
194
170
 
195
171
  const panels = !!props.virtual && (props.panelsPerView ?? -1) > 0
196
172
  ? this._getVirtualPanels()
@@ -216,19 +192,12 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
216
192
  : children.map(() => React.createRef());
217
193
  }
218
194
 
219
- private _bindEvents() {
195
+ protected _bindEvents() {
220
196
  const flicking = this._vanillaFlicking!;
221
197
 
222
198
  Object.keys(EVENTS).forEach((eventKey: keyof typeof EVENTS) => {
223
199
  const eventName = EVENTS[eventKey];
224
- const propName = `on${eventName.charAt(0).toUpperCase() + eventName.slice(1)}`;
225
-
226
- flicking.on(eventName, e => {
227
- e.currentTarget = this;
228
-
229
- const evtHandler = this.props[propName];
230
- evtHandler(e);
231
- });
200
+ this._bindEvent(eventName);
232
201
  });
233
202
 
234
203
  flicking.once(EVENTS.READY, () => {
@@ -236,7 +205,18 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
236
205
  });
237
206
  }
238
207
 
239
- private _checkPlugins() {
208
+ protected _bindEvent(eventName: keyof FlickingEvents) {
209
+ const propName = `on${eventName.charAt(0).toUpperCase() + eventName.slice(1)}`;
210
+
211
+ this._vanillaFlicking!.on(eventName, e => {
212
+ e.currentTarget = this;
213
+
214
+ const evtHandler = this.props[propName];
215
+ evtHandler(e);
216
+ });
217
+ }
218
+
219
+ protected _checkPlugins() {
240
220
  const flicking = this._vanillaFlicking;
241
221
  const { list, added, removed, prevList } = this._pluginsDiffer.update(this.props.plugins!) as DiffResult<Plugin>;
242
222
 
@@ -244,6 +224,42 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
244
224
  flicking.removePlugins(...removed.map(index => prevList[index]));
245
225
  }
246
226
 
227
+ protected _getClasses(attributes: { [key: string]: any }, props: typeof this.props) {
228
+ const flicking = this._vanillaFlicking;
229
+
230
+ const initialized = flicking && flicking.initialized;
231
+ const viewportClasses: string[] = ["flicking-viewport"];
232
+ const cameraClasses: string[] = ["flicking-camera"];
233
+ const isHorizontal = flicking
234
+ ? flicking.horizontal
235
+ : props.horizontal ?? true;
236
+
237
+ if (!isHorizontal) {
238
+ viewportClasses.push("vertical");
239
+ }
240
+ if (props.hideBeforeInit && !initialized) {
241
+ viewportClasses.push("flicking-hidden");
242
+ }
243
+ if (attributes.className) {
244
+ viewportClasses.push(attributes.className);
245
+ }
246
+ if (props.cameraClass) {
247
+ cameraClasses.push(props.cameraClass);
248
+ }
249
+
250
+ const cameraProps = !initialized && props.firstPanelSize
251
+ ? { style: {
252
+ transform: getDefaultCameraTransform(this.props.align, this.props.horizontal, this.props.firstPanelSize)
253
+ }}
254
+ : {};
255
+
256
+ return {
257
+ viewportClasses,
258
+ cameraClasses,
259
+ cameraProps,
260
+ };
261
+ }
262
+
247
263
  private _hasSameChildren(prevChildren: React.ReactElement[], nextChildren: React.ReactElement[]) {
248
264
  if (prevChildren.length !== nextChildren.length || prevChildren.length === 0) return false;
249
265
 
@@ -260,7 +276,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
260
276
  return same;
261
277
  }
262
278
 
263
- private _getChildren(children: React.ReactNode = this.props.children) {
279
+ protected _getChildren(children: React.ReactNode = this.props.children) {
264
280
  return (React.Children.toArray(children) as Array<React.ReactElement<any>>)
265
281
  .filter(child => child.type !== ViewportSlot)
266
282
  .reduce((all, child) => {
@@ -268,7 +284,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
268
284
  }, []) as Array<React.ReactElement<any>>;
269
285
  }
270
286
 
271
- private _getViewportSlot() {
287
+ protected _getViewportSlot() {
272
288
  return (React.Children.toArray(this.props.children) as Array<React.ReactElement<any>>)
273
289
  .filter(child => child.type === ViewportSlot);
274
290
  }
@@ -309,7 +325,7 @@ class Flicking extends React.Component<Partial<FlickingProps & FlickingOptions>>
309
325
  });
310
326
  }
311
327
 
312
- private _getPanels() {
328
+ protected _getPanels() {
313
329
  const origChildren = this._getChildren();
314
330
  const vanillaFlicking = this._vanillaFlicking;
315
331
  const diffResult = this._diffResult;
@@ -28,6 +28,7 @@ export const DEFAULT_PROPS: FlickingProps = {
28
28
  viewportTag: "div",
29
29
  cameraTag: "div",
30
30
  cameraClass: "",
31
+ firstPanelSize: "",
31
32
  renderOnSameKey: false,
32
33
  plugins: [],
33
34
  useFindDOMNode: false,
@@ -3,12 +3,16 @@
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
5
  import Flicking from "./Flicking";
6
+ import CrossFlicking from "./CrossFlicking";
7
+ import CrossGroup from "./CrossGroup";
6
8
  import ViewportSlot from "./ViewportSlot";
7
9
 
8
10
  export * from "@egjs/flicking";
9
11
  export * from "./types";
10
12
 
11
13
  export {
12
- ViewportSlot
14
+ CrossFlicking,
15
+ CrossGroup,
16
+ ViewportSlot,
13
17
  }
14
18
  export default Flicking;
@@ -54,3 +54,4 @@ export interface FlickingProps {
54
54
  onPanelChange: (e: PanelChangeEvent<ReactFlicking>) => any;
55
55
  [key: string]: any;
56
56
  }
57
+
@@ -1 +0,0 @@
1
- {"version":3,"sourceRoot":"","sources":["../sass/flicking-inline.sass"],"names":[],"mappings":"AAAA;EACE;EACA;;AACA;EACE;EACA;;AACF;EAEE;;AAEA;EACE;;AACF;EACE;;AACF;EACE;;AACJ;EACE;;;AAEJ;EACE;EACA;EACA;EACA;EACA;EACA;;AACA;EACE;EACA;EACA","file":"flicking-inline.css"}
@@ -1 +0,0 @@
1
- {"version":3,"sourceRoot":"","sources":["../sass/flicking.sass"],"names":[],"mappings":"AAAA;EACE;EACA;;AACA;EACE;;AACA;EACE;EACA;;AAGA;EACE;;;AAER;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AACA;EACE","file":"flicking.css"}