@egjs/vue3-flicking 4.3.1 → 4.4.3

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.
@@ -1,8 +1,16 @@
1
- import { ExternalRenderer, PanelOptions, RendererOptions } from "@egjs/flicking";
1
+ /*
2
+ * Copyright (c) 2015 NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import {
6
+ ExternalRenderer,
7
+ getFlickingAttached,
8
+ PanelOptions,
9
+ RendererOptions
10
+ } from "@egjs/flicking";
2
11
 
3
12
  import VueFlicking from "./Flicking";
4
13
  import VuePanel from "./VuePanel";
5
- import VuePanelComponent from "./VuePanelComponent";
6
14
 
7
15
  export interface VueRendererOptions extends RendererOptions {
8
16
  vueFlicking: VueFlicking;
@@ -10,7 +18,7 @@ export interface VueRendererOptions extends RendererOptions {
10
18
 
11
19
  class VueRenderer extends ExternalRenderer {
12
20
  // Internal States
13
- protected _vueFlicking: VueFlicking;
21
+ private _vueFlicking: VueFlicking;
14
22
 
15
23
  public constructor(options: VueRendererOptions) {
16
24
  super(options);
@@ -18,37 +26,42 @@ class VueRenderer extends ExternalRenderer {
18
26
  this._vueFlicking = options.vueFlicking;
19
27
  }
20
28
 
21
- // eslint-disable-next-line @typescript-eslint/require-await
22
29
  public async render() {
23
- const flicking = this._flicking;
30
+ const flicking = getFlickingAttached(this._flicking);
31
+ const vueFlicking = this._vueFlicking;
32
+ const strategy = this._strategy;
24
33
 
25
- if (!flicking) return;
34
+ strategy.updateRenderingPanels(flicking);
35
+ strategy.renderPanels(flicking);
26
36
 
27
- this._updateRenderingPanels();
28
- this._vueFlicking.$forceUpdate();
37
+ return new Promise<void>((resolve) => {
38
+ vueFlicking.renderEmitter.once("render", resolve);
39
+ vueFlicking.$forceUpdate();
40
+ });
29
41
  }
30
42
 
31
- // eslint-disable-next-line @typescript-eslint/require-await
32
43
  public async forceRenderAllPanels() {
33
- this._panels.forEach(panel => panel.markForShow());
34
- this._vueFlicking.$forceUpdate();
44
+ const vueFlicking = this._vueFlicking;
45
+
46
+ await super.forceRenderAllPanels();
47
+
48
+ return new Promise<void>((resolve) => {
49
+ vueFlicking.renderEmitter.once("render", resolve);
50
+ vueFlicking.$forceUpdate();
51
+ });
35
52
  }
36
53
 
37
54
  protected _collectPanels() {
38
- const align = this._getPanelAlign();
39
- const childRefs = this._vueFlicking.$refs;
40
- const children: any[] = Object.keys(childRefs).map(refKey => childRefs[refKey]);
41
-
42
- this._panels = children.map((panelComponent, index) => new VuePanel({
43
- flicking: this._flicking!,
44
- index,
45
- align,
46
- externalComponent: panelComponent
47
- }));
55
+ const flicking = getFlickingAttached(this._flicking);
56
+ const vueFlicking = this._vueFlicking;
57
+ const childRefs = vueFlicking.$refs;
58
+ const vuePanels: any[] = Object.keys(childRefs).map(refKey => childRefs[refKey]);
59
+
60
+ this._panels = this._strategy.collectPanels(flicking, vuePanels);
48
61
  }
49
62
 
50
- protected _createPanel(externalComponent: VuePanelComponent, options: PanelOptions) {
51
- return new VuePanel({ externalComponent, ...options });
63
+ protected _createPanel(externalComponent: VuePanel, options: PanelOptions) {
64
+ return this._strategy.createPanel(externalComponent, options);
52
65
  }
53
66
  }
54
67
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import Flicking from "./Flicking";
2
2
 
3
- export default Flicking;
4
3
  export * from "@egjs/flicking";
4
+ export default Flicking;
@@ -1,6 +1,6 @@
1
- /* eslint-disable */
2
- declare module '*.vue' {
3
- import type { DefineComponent } from 'vue'
4
- const component: DefineComponent<{}, {}, any>
5
- export default component
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ declare module "*.vue" {
3
+ import type { DefineComponent } from "vue";
4
+ const component: DefineComponent<{}, {}, any>;
5
+ export default component;
6
6
  }
package/src/types.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { ComponentOptionsMixin, DefineComponent, VNode } from "vue";
2
+ import VanillaFlicking, {
3
+ Plugin,
4
+ Status,
5
+ FlickingOptions,
6
+ FlickingEvents
7
+ } from "@egjs/flicking";
8
+ import Component from "@egjs/component";
9
+ import ListDiffer, { DiffResult } from "@egjs/list-differ";
10
+
11
+ import FlickingProps from "./FlickingProps";
12
+
13
+ export interface FlickingData {
14
+ renderEmitter: Component<{ render: void }>;
15
+ vanillaFlicking: VanillaFlicking;
16
+ pluginsDiffer: ListDiffer<Plugin>;
17
+ slotDiffer: ListDiffer<VNode>;
18
+ diffResult: DiffResult<VNode> | null;
19
+ }
20
+
21
+ type VueFlickingEmits = {
22
+ [key in keyof FlickingEvents]: (evt: FlickingEvents[key]) => any;
23
+ };
24
+
25
+ /* eslint-disable @typescript-eslint/indent */
26
+ export type VueFlicking = DefineComponent<
27
+ typeof FlickingProps,
28
+ // RawBindings
29
+ unknown,
30
+ // Data
31
+ FlickingData,
32
+ // Computed
33
+ {},
34
+ // Methods
35
+ {},
36
+ // Mixin
37
+ ComponentOptionsMixin,
38
+ // Extends
39
+ ComponentOptionsMixin,
40
+ // Emits
41
+ VueFlickingEmits,
42
+ string,
43
+ // Public Props
44
+ import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps,
45
+ // Props
46
+ Readonly<{
47
+ viewportTag?: unknown;
48
+ cameraTag?: unknown;
49
+ hideBeforeInit?: unknown;
50
+ firstPanelSize?: unknown;
51
+ options?: unknown;
52
+ plugins?: unknown;
53
+ status?: unknown;
54
+ } & {
55
+ viewportTag: string;
56
+ cameraTag: string;
57
+ hideBeforeInit: boolean;
58
+ options: Partial<FlickingOptions>;
59
+ plugins: Plugin[];
60
+ } & {
61
+ firstPanelSize?: string;
62
+ status?: Status;
63
+ } & {
64
+ [K in keyof VueFlickingEmits as `on${Capitalize<K>}`]?: VueFlickingEmits[K];
65
+ }>,
66
+ // Defaults
67
+ {
68
+ viewportTag: string;
69
+ cameraTag: string;
70
+ hideBeforeInit: boolean;
71
+ options: Partial<FlickingOptions>;
72
+ plugins: Plugin[];
73
+ }
74
+ >;
75
+ /* eslint-enable @typescript-eslint/indent */
@@ -1,6 +0,0 @@
1
- import { Vue } from "vue-class-component";
2
- declare class VuePanelComponent extends Vue {
3
- hide: boolean;
4
- render(): any;
5
- }
6
- export default VuePanelComponent;
@@ -1,14 +0,0 @@
1
-
2
- import { Vue } from "vue-class-component";
3
-
4
- class VuePanelComponent extends Vue {
5
- public hide: boolean = false;
6
-
7
- public render() {
8
- if (this.hide || !this.$slots.default) return;
9
-
10
- return this.$slots.default() as any;
11
- }
12
- }
13
-
14
- export default VuePanelComponent;