@loickit-v/swiper 0.0.7 → 0.0.8
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/README.md +143 -63
- package/dist/components/Slide/index.vue.js +3 -2
- package/dist/components/Slide/provide.js +3 -3
- package/dist/components/SlideItem/index.vue.js +34 -27
- package/dist/types/components/Slide/provide.d.ts +3 -1
- package/dist/types/components/SlideItem/index.d.ts +3 -9
- package/dist/types/components/SlideItem/index.vue.d.ts +2 -6
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,73 +1,153 @@
|
|
1
1
|
# @loickit-v/swiper
|
2
2
|
|
3
|
+
[中文](./README-zh.md)
|
4
|
+
|
3
5
|
## Components
|
4
6
|
|
5
7
|
### LSlide
|
6
|
-
|
7
|
-
Slide Component
|
8
|
-
|
8
|
+
The Slide Component
|
9
9
|
#### Props
|
10
|
+
- `name`
|
11
|
+
A unique identifier for the slide, which should be obtained via `defineSlide`.
|
12
|
+
- `list <Array>`
|
13
|
+
Only takes effect in `infinite` mode; enables automatic cached rendering.
|
14
|
+
- `loadMore <Function>`
|
15
|
+
Only takes effect in `infinite` mode; triggered when the sliding pointer reaches the end of the list.
|
10
16
|
|
11
|
-
- `name`
|
12
|
-
The unique identifier of the slide, which should be obtained via `defineSlide`.
|
13
|
-
|
14
|
-
- `list <Array>`
|
15
|
-
Only effective in `infinite` mode; automatic cached rendering will be performed.
|
16
|
-
|
17
|
-
- `loadMore <Function>`
|
18
|
-
Only effective in `infinite` mode; triggered when the sliding pointer points to the end of the list.
|
19
|
-
|
20
|
-
#### Hooks
|
21
|
-
|
22
|
-
##### `defineSlide`
|
23
|
-
|
24
|
-
Define a slide.
|
25
|
-
|
26
|
-
Parameters:
|
27
|
-
|
28
|
-
- `provideKey <string>`
|
29
|
-
Set a unique identifier for the current slide.
|
30
|
-
|
31
|
-
Returns:
|
32
|
-
`[createSlide, useSlide]`
|
33
|
-
|
34
|
-
- `createSlide`
|
35
|
-
Create a slide state; register the `l-slide` component through its return value.
|
36
|
-
Parameters:
|
37
|
-
|
38
|
-
- `initial <SlideState>`
|
39
|
-
- `direction <SLIDE_DIRECTION>` _optional_
|
40
|
-
Sliding direction.
|
41
|
-
Default value: SLIDE_DIRECTION.HORIZONTAL
|
42
|
-
- `currentIndex <number>` _optional_
|
43
|
-
Pointer.
|
44
|
-
Default value: 0
|
45
|
-
- `duration <number>` _optional_
|
46
|
-
Animation duration for slide switching.
|
47
|
-
Default value: 300 (ms)
|
48
|
-
- `infinite <boolean>` _optional_
|
49
|
-
Whether to enable infinite mode.
|
50
|
-
Default value: false
|
51
|
-
Return value:
|
52
|
-
- `name`
|
53
|
-
The unique identifier of the slide, which should be assigned to the `name` prop of `l-slide`.
|
54
|
-
- `state <SlideState>`
|
55
|
-
The slide state.
|
56
|
-
|
57
|
-
- `useSlide`
|
58
|
-
Return value: `<SlideState>`
|
59
|
-
Use it to get the slide state in any child component.
|
60
|
-
|
61
|
-
#### Slot
|
62
|
-
|
63
|
-
**default**
|
64
|
-
|
65
|
-
- `cacheList`
|
66
|
-
Only effective in `infinite` mode; caches the list data.
|
67
17
|
|
68
18
|
### LSlideItem
|
69
|
-
|
19
|
+
The Slide Item Component
|
70
20
|
#### Props
|
71
|
-
|
72
|
-
|
73
|
-
|
21
|
+
- `index <number>` _optional_
|
22
|
+
Must be passed in `infinite` mode, used for dynamic rendering calculations.
|
23
|
+
|
24
|
+
|
25
|
+
## Hooks
|
26
|
+
|
27
|
+
### `defineSlide`
|
28
|
+
Defines a slide
|
29
|
+
|
30
|
+
**Parameters**:
|
31
|
+
- `provideKey <string>`
|
32
|
+
Sets a unique identifier for the current slide.
|
33
|
+
|
34
|
+
**Returns**:
|
35
|
+
`[createSlide, useSlide]`
|
36
|
+
|
37
|
+
- `createSlide`
|
38
|
+
Creates a slide state; its return value is used to register the `l-slide` component.
|
39
|
+
|
40
|
+
**Parameters**:
|
41
|
+
- `initial <SlideState>`
|
42
|
+
- `direction <SLIDE_DIRECTION>` _optional_
|
43
|
+
Sliding direction
|
44
|
+
Default value: SLIDE_DIRECTION.HORIZONTAL
|
45
|
+
- `currentIndex <number>` _optional_
|
46
|
+
Pointer
|
47
|
+
Default value: 0
|
48
|
+
- `duration <number>` _optional_
|
49
|
+
Animation duration for slide switching
|
50
|
+
Default value: 300 (ms)
|
51
|
+
- `infinite <boolean>` _optional_
|
52
|
+
Whether to enable infinite mode
|
53
|
+
Default value: false
|
54
|
+
|
55
|
+
**Returns**:
|
56
|
+
- `name`
|
57
|
+
A unique identifier for the slide, which should be assigned to the `name` prop of `l-slide`.
|
58
|
+
- `state <SlideState>`
|
59
|
+
The slide state
|
60
|
+
|
61
|
+
- `useSlide`
|
62
|
+
**Returns**: `<SlideState>`
|
63
|
+
Use it to get the current slide state in any child component.
|
64
|
+
|
65
|
+
|
66
|
+
## Slot
|
67
|
+
**default**
|
68
|
+
- `cacheList`
|
69
|
+
Only takes effect in `infinite` mode; caches the list data.
|
70
|
+
|
71
|
+
|
72
|
+
## Usage
|
73
|
+
|
74
|
+
```vue
|
75
|
+
<script setup lang="ts">
|
76
|
+
import {
|
77
|
+
defineSlide,
|
78
|
+
LSlide,
|
79
|
+
LSlideItem,
|
80
|
+
SLIDE_DIRECTION,
|
81
|
+
type SlideSwitchEvent
|
82
|
+
} from '@loickit-v/swiper';
|
83
|
+
import '@loickit-v/swiper/style';
|
84
|
+
import { reactive } from 'vue';
|
85
|
+
|
86
|
+
const handleSwitch = (value: SlideSwitchEvent) => {
|
87
|
+
console.log(value);
|
88
|
+
};
|
89
|
+
|
90
|
+
const [createSlide] = defineSlide('one');
|
91
|
+
const oneSlide = createSlide({
|
92
|
+
currentIndex: 1
|
93
|
+
});
|
94
|
+
|
95
|
+
const [createSlide2] = defineSlide('two');
|
96
|
+
const twoSlide = createSlide2({
|
97
|
+
direction: SLIDE_DIRECTION.VERTICAL
|
98
|
+
});
|
99
|
+
const oneToTwo = () => {
|
100
|
+
oneSlide.state.currentIndex = 1;
|
101
|
+
};
|
102
|
+
const list = reactive([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
|
103
|
+
const onLoadMore = () => {
|
104
|
+
list.push({ id: list[list.length - 1].id + 1 });
|
105
|
+
};
|
106
|
+
</script>
|
107
|
+
|
108
|
+
<template>
|
109
|
+
<div style="position: fixed; bottom: 0; left: 0; z-index: 999">
|
110
|
+
<p>one currentIndex: {{ oneSlide.state.currentIndex }}</p>
|
111
|
+
<p>two currentIndex: {{ twoSlide.state.currentIndex }}</p>
|
112
|
+
|
113
|
+
<button @click="oneToTwo">click to two "HORIZONTAL-2"</button>
|
114
|
+
</div>
|
115
|
+
<LSlide :name="oneSlide.name" @switch="handleSwitch">
|
116
|
+
<LSlideItem style="background-color: red; width: 30%">
|
117
|
+
<h1>HORIZONTAL-1</h1>
|
118
|
+
</LSlideItem>
|
119
|
+
<LSlideItem style="background-color: blue">
|
120
|
+
<h1>HORIZONTAL-2</h1>
|
121
|
+
</LSlideItem>
|
122
|
+
<LSlideItem style="background-color: green">
|
123
|
+
<LSlide
|
124
|
+
infinite
|
125
|
+
:name="twoSlide.name"
|
126
|
+
:list="list"
|
127
|
+
:load-more="onLoadMore"
|
128
|
+
@switch="handleSwitch"
|
129
|
+
>
|
130
|
+
<template #="{ cacheList }">
|
131
|
+
<LSlideItem
|
132
|
+
v-for="(item, idx) in cacheList"
|
133
|
+
:key="item.id"
|
134
|
+
:index="idx"
|
135
|
+
>
|
136
|
+
<h1>INFINITE-VERTICAL</h1>
|
137
|
+
<h2>{{ item.id }}</h2>
|
138
|
+
</LSlideItem>
|
139
|
+
</template>
|
140
|
+
</LSlide>
|
141
|
+
</LSlideItem>
|
142
|
+
</LSlide>
|
143
|
+
</template>
|
144
|
+
|
145
|
+
<style lang="scss">
|
146
|
+
body,
|
147
|
+
#app {
|
148
|
+
background-color: #ccc;
|
149
|
+
height: 800px;
|
150
|
+
width: 800px;
|
151
|
+
}
|
152
|
+
</style>
|
153
|
+
```
|
@@ -6,7 +6,7 @@ import { checkDirection as U } from "../../utils/slide.js";
|
|
6
6
|
import { COMMON_SLIDE_PROVIDE_NAME as M } from "../constant/private.js";
|
7
7
|
import { useSlideState as G } from "../Provide/index.js";
|
8
8
|
import { defaultState as J } from "../../hooks/defineSlide/default.js";
|
9
|
-
import {
|
9
|
+
import { createSlidePrivateProvide as K } from "./provide.js";
|
10
10
|
const le = /* @__PURE__ */ H({
|
11
11
|
name: "LSlide",
|
12
12
|
__name: "index",
|
@@ -30,7 +30,8 @@ const le = /* @__PURE__ */ H({
|
|
30
30
|
), m(e.direction, r.value, -s.value);
|
31
31
|
}, p = K({
|
32
32
|
name: t.name,
|
33
|
-
itemsInfo: []
|
33
|
+
itemsInfo: [],
|
34
|
+
infinite: t.infinite
|
34
35
|
}), O = () => {
|
35
36
|
const n = b(J);
|
36
37
|
return j(t.name, n), n;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { createProvide as e } from "../../utils/createProvide.js";
|
2
2
|
import { SLIDE_PROVIDE_KEY as r } from "../constant/private.js";
|
3
|
-
const [o,
|
3
|
+
const [o, a] = e(r);
|
4
4
|
export {
|
5
|
-
o as
|
6
|
-
|
5
|
+
o as createSlidePrivateProvide,
|
6
|
+
a as useSlidePrivateState
|
7
7
|
};
|
@@ -1,45 +1,52 @@
|
|
1
|
-
import { defineComponent as
|
2
|
-
import { useSlideState as
|
3
|
-
import { useSlidePrivateState as
|
4
|
-
const
|
1
|
+
import { defineComponent as a, ref as l, watch as c, onMounted as m, onBeforeUnmount as p, createElementBlock as u, openBlock as h, createElementVNode as x, renderSlot as v } from "vue";
|
2
|
+
import { useSlideState as I } from "../Provide/index.js";
|
3
|
+
import { useSlidePrivateState as w } from "../Slide/provide.js";
|
4
|
+
const C = /* @__PURE__ */ a({
|
5
5
|
name: "LSlideItem",
|
6
6
|
__name: "index",
|
7
7
|
props: {
|
8
|
-
index: {
|
8
|
+
index: {}
|
9
9
|
},
|
10
|
-
setup(
|
11
|
-
const
|
12
|
-
|
13
|
-
(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
setup(f) {
|
11
|
+
const i = f, e = w(), r = I(e.name), o = l(), s = l();
|
12
|
+
if (e.infinite) {
|
13
|
+
if (typeof i.index != "number")
|
14
|
+
throw new Error(
|
15
|
+
`index is required when infinite is true
|
16
|
+
please use the second parameter of the "v-for" directive`
|
17
|
+
);
|
18
|
+
c(
|
19
|
+
() => r.currentIndex,
|
20
|
+
() => {
|
21
|
+
var t;
|
22
|
+
r.currentIndex <= i.index + 1 && r.currentIndex >= i.index - 1 ? (t = o.value) == null || t.appendChild(
|
23
|
+
e.itemsInfo[i.index].el
|
24
|
+
) : s.value.remove();
|
25
|
+
}
|
26
|
+
);
|
27
|
+
}
|
28
|
+
const n = {
|
29
|
+
index: i.index
|
23
30
|
};
|
24
31
|
return m(() => {
|
25
32
|
var d;
|
26
|
-
const
|
27
|
-
|
33
|
+
const t = (d = o.value) == null ? void 0 : d.getBoundingClientRect();
|
34
|
+
n.width = t.width, n.height = t.height, e.infinite && (n.el = s.value), e.itemsInfo.push(n);
|
28
35
|
}), p(() => {
|
29
|
-
|
30
|
-
|
36
|
+
e.itemsInfo.splice(
|
37
|
+
e.itemsInfo.indexOf(n),
|
31
38
|
1
|
32
39
|
);
|
33
|
-
}), (
|
40
|
+
}), (t, d) => (h(), u(
|
34
41
|
"div",
|
35
42
|
{
|
36
43
|
ref_key: "slideItemRef",
|
37
|
-
ref:
|
44
|
+
ref: o,
|
38
45
|
class: "loickit-slide-item",
|
39
46
|
style: { position: "relative" }
|
40
47
|
},
|
41
48
|
[
|
42
|
-
|
49
|
+
x(
|
43
50
|
"div",
|
44
51
|
{
|
45
52
|
ref_key: "slideItemContentWrapperRef",
|
@@ -47,7 +54,7 @@ const R = /* @__PURE__ */ f({
|
|
47
54
|
class: "loickit-slide-item-content-wrapper"
|
48
55
|
},
|
49
56
|
[
|
50
|
-
|
57
|
+
v(t.$slots, "default")
|
51
58
|
],
|
52
59
|
512
|
53
60
|
/* NEED_PATCH */
|
@@ -59,5 +66,5 @@ const R = /* @__PURE__ */ f({
|
|
59
66
|
}
|
60
67
|
});
|
61
68
|
export {
|
62
|
-
|
69
|
+
C as default
|
63
70
|
};
|
@@ -2,8 +2,9 @@ import { SlideItemInfo, SlideNameType } from '../types/private';
|
|
2
2
|
type SlidePrivateState = {
|
3
3
|
name: SlideNameType;
|
4
4
|
itemsInfo: SlideItemInfo[];
|
5
|
+
infinite: boolean;
|
5
6
|
};
|
6
|
-
export declare const
|
7
|
+
export declare const createSlidePrivateProvide: (state: SlidePrivateState) => {
|
7
8
|
name: SlideNameType;
|
8
9
|
itemsInfo: {
|
9
10
|
height: number;
|
@@ -11,5 +12,6 @@ export declare const useSlidePrivateProvide: (state: SlidePrivateState) => {
|
|
11
12
|
index: import("../types/private").SlideItemInfoNameType;
|
12
13
|
el?: HTMLElement | undefined;
|
13
14
|
}[];
|
15
|
+
infinite: boolean;
|
14
16
|
}, useSlidePrivateState: () => SlidePrivateState;
|
15
17
|
export {};
|
@@ -1,9 +1,7 @@
|
|
1
1
|
export declare const LSlideItem: {
|
2
2
|
new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<{
|
3
3
|
index?: number;
|
4
|
-
}> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {
|
5
|
-
index: number;
|
6
|
-
}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
4
|
+
}> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
|
7
5
|
P: {};
|
8
6
|
B: {};
|
9
7
|
D: {};
|
@@ -12,17 +10,13 @@ export declare const LSlideItem: {
|
|
12
10
|
Defaults: {};
|
13
11
|
}, Readonly<{
|
14
12
|
index?: number;
|
15
|
-
}> & Readonly<{}>, {}, {}, {}, {}, {
|
16
|
-
index: number;
|
17
|
-
}>;
|
13
|
+
}> & Readonly<{}>, {}, {}, {}, {}, {}>;
|
18
14
|
__isFragment?: never;
|
19
15
|
__isTeleport?: never;
|
20
16
|
__isSuspense?: never;
|
21
17
|
} & import("vue").ComponentOptionsBase<Readonly<{
|
22
18
|
index?: number;
|
23
|
-
}> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {
|
24
|
-
index: number;
|
25
|
-
}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
19
|
+
}> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
|
26
20
|
$slots: {
|
27
21
|
default?: ((props: {}) => any) | undefined;
|
28
22
|
};
|
@@ -11,12 +11,8 @@ type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$
|
|
11
11
|
declare const __VLS_self: import("vue").DefineComponent<__VLS_Props, {
|
12
12
|
slideItemRef: typeof slideItemRef;
|
13
13
|
slideItemContentWrapperRef: typeof slideItemContentWrapperRef;
|
14
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
15
|
-
|
16
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
17
|
-
declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
18
|
-
index: number;
|
19
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
15
|
+
declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
20
16
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
21
17
|
export default _default;
|
22
18
|
type __VLS_WithSlots<T, S> = T & {
|