sard-uniapp 1.18.0 → 1.19.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +6 -1
  3. package/components/button/button.vue +2 -0
  4. package/components/button/common.d.ts +1 -0
  5. package/components/button/index.scss +9 -0
  6. package/components/cascader/cascader.vue +7 -0
  7. package/components/cascader-input/cascader-input.vue +1 -1
  8. package/components/crop-image/crop-image.vue +7 -7
  9. package/components/dialog-agent/common.d.ts +3 -0
  10. package/components/dialog-agent/dialog-agent.vue +10 -1
  11. package/components/dropdown/common.d.ts +5 -0
  12. package/components/dropdown/index.d.ts +1 -1
  13. package/components/dropdown-item/dropdown-item.vue +77 -21
  14. package/components/floating-bubble/floating-bubble.vue +4 -4
  15. package/components/form/form.vue +4 -1
  16. package/components/form-item/index.scss +10 -0
  17. package/components/marquee/marquee.vue +8 -5
  18. package/components/notice-bar/notice-bar.vue +8 -5
  19. package/components/notify/notify.vue +10 -7
  20. package/components/picker-item/index.scss +0 -1
  21. package/components/pull-down-refresh/pull-down-refresh.vue +15 -9
  22. package/components/swipe-action/common.d.ts +23 -0
  23. package/components/swipe-action/common.js +1 -0
  24. package/components/swipe-action/index.d.ts +1 -0
  25. package/components/swipe-action/index.js +1 -0
  26. package/components/swipe-action/index.scss +53 -0
  27. package/components/swipe-action/swipe-action.d.ts +16 -0
  28. package/components/swipe-action/swipe-action.vue +275 -0
  29. package/components/swipe-action/variables.scss +3 -0
  30. package/components/toast/toast.vue +10 -7
  31. package/global.d.ts +1 -0
  32. package/index.d.ts +1 -0
  33. package/index.js +1 -0
  34. package/index.scss +1 -0
  35. package/package.json +2 -7
  36. package/use/index.d.ts +3 -1
  37. package/use/index.js +3 -1
  38. package/use/useScrollSpy.js +4 -4
  39. package/use/useSimulatedClick.js +4 -4
  40. package/use/useSimulatedPress.js +5 -5
  41. package/use/useStopMovedClick.d.ts +6 -0
  42. package/use/useStopMovedClick.js +26 -0
  43. package/use/useTimeout.d.ts +11 -0
  44. package/use/useTimeout.js +39 -0
  45. package/use/useTimeoutLoading.js +9 -7
  46. package/use/useSetTimeout.d.ts +0 -1
  47. package/use/useSetTimeout.js +0 -24
@@ -0,0 +1,53 @@
1
+ @use '../style/base' as *;
2
+
3
+ @include bem(swipe-action) {
4
+ @include b() {
5
+ @include universal;
6
+ overflow: hidden;
7
+ }
8
+
9
+ @include e(content) {
10
+ @include universal;
11
+ cursor: grab;
12
+ }
13
+
14
+ @include e(actions) {
15
+ @include universal;
16
+ position: absolute;
17
+ left: 0;
18
+ top: 0;
19
+ right: 0;
20
+ bottom: 0;
21
+ overflow: hidden;
22
+ pointer-events: none;
23
+ }
24
+
25
+ @include e(actions-wrapper) {
26
+ @include universal;
27
+ position: absolute;
28
+ left: 0;
29
+ top: 0;
30
+ right: 0;
31
+ bottom: 0;
32
+ }
33
+
34
+ @include e(left, right) {
35
+ @include universal;
36
+ position: absolute;
37
+ top: 0;
38
+ bottom: 0;
39
+ display: flex;
40
+ flex-direction: row;
41
+ pointer-events: auto;
42
+ }
43
+
44
+ @include e(left) {
45
+ left: 0;
46
+ transform: translateX(-100%);
47
+ }
48
+
49
+ @include e(right) {
50
+ right: 0;
51
+ transform: translateX(100%);
52
+ }
53
+ }
@@ -0,0 +1,16 @@
1
+ import { type SwipeActionProps, type SwipeActionSlots, type SwipeActionVisible } from './common';
2
+ declare function __VLS_template(): Readonly<SwipeActionSlots> & SwipeActionSlots;
3
+ declare const __VLS_component: import("vue").DefineComponent<SwipeActionProps, {
4
+ hide: () => void;
5
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
6
+ "update:visible": (value: SwipeActionVisible) => any;
7
+ }, string, import("vue").PublicProps, Readonly<SwipeActionProps> & Readonly<{
8
+ "onUpdate:visible"?: ((value: SwipeActionVisible) => any) | undefined;
9
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
11
+ export default _default;
12
+ type __VLS_WithTemplateSlots<T, S> = T & {
13
+ new (): {
14
+ $slots: S;
15
+ };
16
+ };
@@ -0,0 +1,275 @@
1
+ <template>
2
+ <view
3
+ :class="swipeActionClass"
4
+ :style="swipeActionStyle"
5
+ @touchstart="onTouchStart"
6
+ @touchmove="onTouchMove"
7
+ @touchend="onTouchEnd"
8
+ @touchcancel="onTouchEnd"
9
+ @mousedown="onMouseDown"
10
+ >
11
+ <view
12
+ :id="contentId"
13
+ :class="bem.e('content')"
14
+ :style="translateStyle"
15
+ @click="onContentClick"
16
+ @mousedown="onContentMouseDown"
17
+ @mousemove="onMouseMove"
18
+ @mouseup="onMouseUp"
19
+ >
20
+ <slot></slot>
21
+ <view v-if="$slots.left" :id="leftId" :class="bem.e('left')" @click.stop>
22
+ <slot name="left" :hide="hide"></slot>
23
+ </view>
24
+ <view
25
+ v-if="$slots.right"
26
+ :id="rightId"
27
+ :class="bem.e('right')"
28
+ @click.stop
29
+ >
30
+ <slot name="right" :hide="hide"></slot>
31
+ </view>
32
+ </view>
33
+ </view>
34
+ </template>
35
+
36
+ <script>
37
+ import { useSlots as _useSlots, defineComponent as _defineComponent } from "vue";
38
+ import { computed, getCurrentInstance, onMounted, ref, watch } from "vue";
39
+ import {
40
+ classNames,
41
+ stringifyStyle,
42
+ createBem,
43
+ uniqid,
44
+ getBoundingClientRect
45
+ } from "../../utils";
46
+ import { useMouseDown, useInitialVelocity, useStopMovedClick } from "../../use";
47
+ export default _defineComponent({
48
+ ...{
49
+ options: {
50
+ virtualHost: true,
51
+ styleIsolation: "shared"
52
+ }
53
+ },
54
+ __name: "swipe-action",
55
+ props: {
56
+ rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
57
+ rootClass: { type: String, required: false },
58
+ disabled: { type: Boolean, required: false },
59
+ visible: { type: [String, Boolean], required: false }
60
+ },
61
+ emits: ["update:visible"],
62
+ setup(__props, { expose: __expose, emit: __emit }) {
63
+ const props = __props;
64
+ const slots = _useSlots();
65
+ const emit = __emit;
66
+ const bem = createBem("swipe-action");
67
+ const innerVisible = ref(props.visible || false);
68
+ watch(
69
+ () => props.visible,
70
+ () => {
71
+ if (props.visible !== innerVisible.value) {
72
+ innerVisible.value = props.visible || false;
73
+ setTranslateXByVisible(innerVisible.value);
74
+ }
75
+ }
76
+ );
77
+ const triggerVisible = (visible) => {
78
+ if (innerVisible.value !== visible) {
79
+ innerVisible.value = visible;
80
+ emit("update:visible", visible);
81
+ }
82
+ };
83
+ const hide = () => {
84
+ triggerVisible(false);
85
+ setTranslateXByVisible(false);
86
+ };
87
+ const onContentClick = () => {
88
+ if (!props.disabled && !isStoppedClick.value) {
89
+ hide();
90
+ }
91
+ };
92
+ const {
93
+ isStoppedClick,
94
+ onMouseDown: onContentMouseDown,
95
+ onMouseMove,
96
+ onMouseUp
97
+ } = useStopMovedClick();
98
+ const contentId = uniqid();
99
+ const leftId = uniqid();
100
+ const rightId = uniqid();
101
+ const instance = getCurrentInstance();
102
+ let contentWidth = null;
103
+ let leftWidth = null;
104
+ let rightWidth = null;
105
+ const translateX = ref(0);
106
+ const movable = ref(false);
107
+ let startX = 0;
108
+ let startY = 0;
109
+ let downTranslateX = 0;
110
+ let lockDirection = "";
111
+ let canResolveVisible = false;
112
+ const initVelocity = useInitialVelocity();
113
+ const getWidth = async () => {
114
+ return Promise.all([
115
+ getBoundingClientRect(`#${contentId}`, instance).then((rect) => {
116
+ contentWidth = rect.width;
117
+ }),
118
+ slots.left && getBoundingClientRect(`#${leftId}`, instance).then((rect) => {
119
+ leftWidth = rect.width;
120
+ }),
121
+ slots.right && getBoundingClientRect(`#${rightId}`, instance).then((rect) => {
122
+ rightWidth = rect.width;
123
+ })
124
+ ]);
125
+ };
126
+ const setTranslateXByVisible = (visible) => {
127
+ translateX.value = visible === "left" ? leftWidth || 0 : visible === "right" ? -(rightWidth || 0) : 0;
128
+ };
129
+ onMounted(() => {
130
+ setTimeout(() => {
131
+ if (innerVisible.value) {
132
+ getWidth().then(() => {
133
+ setTranslateXByVisible(innerVisible.value);
134
+ });
135
+ } else {
136
+ getWidth();
137
+ }
138
+ });
139
+ });
140
+ const onTouchStart = async (event) => {
141
+ if (props.disabled || !slots.left && !slots.right) {
142
+ return;
143
+ }
144
+ startX = event.touches[0].clientX;
145
+ startY = event.touches[0].clientY;
146
+ initVelocity.onStart({
147
+ x: startX,
148
+ y: startY
149
+ });
150
+ downTranslateX = translateX.value;
151
+ movable.value = true;
152
+ getWidth();
153
+ };
154
+ const onTouchMove = (event) => {
155
+ if (!movable.value || lockDirection && lockDirection !== "x") {
156
+ return;
157
+ }
158
+ const clientX = event.touches[0].clientX;
159
+ const clientY = event.touches[0].clientY;
160
+ const deltaX = clientX - startX;
161
+ const deltaY = clientY - startY;
162
+ initVelocity.onMove({
163
+ x: clientX,
164
+ y: clientY
165
+ });
166
+ if (!lockDirection) {
167
+ const isHorizontal = Math.abs(deltaX) >= Math.abs(deltaY);
168
+ lockDirection = isHorizontal ? "x" : "y";
169
+ }
170
+ if (lockDirection === "x") {
171
+ if (contentWidth !== null && (!slots.left || leftWidth !== null) && (!slots.right || rightWidth !== null)) {
172
+ event.preventDefault();
173
+ if (event.stopImmediatePropagation) {
174
+ event.stopImmediatePropagation();
175
+ } else if (event.stopPropagation) {
176
+ event.stopPropagation();
177
+ }
178
+ let nextTranslateX = downTranslateX + deltaX;
179
+ const leftEdge = leftWidth !== null ? leftWidth : 0;
180
+ const rightEdge = rightWidth !== null ? -rightWidth : 0;
181
+ if (nextTranslateX > leftEdge) {
182
+ nextTranslateX = leftEdge;
183
+ }
184
+ if (nextTranslateX < rightEdge) {
185
+ nextTranslateX = rightEdge;
186
+ }
187
+ translateX.value = nextTranslateX;
188
+ canResolveVisible = true;
189
+ }
190
+ }
191
+ };
192
+ const onTouchEnd = () => {
193
+ if (canResolveVisible) {
194
+ const velocity = initVelocity.onEnd();
195
+ const dependsOnSpeed = Math.abs(velocity.x) > 0.2;
196
+ const x = translateX.value;
197
+ let nextVisible = false;
198
+ if (x < 0) {
199
+ if (dependsOnSpeed && velocity.x < 0 || !dependsOnSpeed && Math.abs(x) >= rightWidth / 2) {
200
+ nextVisible = "right";
201
+ translateX.value = -rightWidth;
202
+ } else {
203
+ translateX.value = 0;
204
+ }
205
+ } else if (x > 0) {
206
+ if (dependsOnSpeed && velocity.x > 0 || !dependsOnSpeed && Math.abs(x) >= leftWidth / 2) {
207
+ nextVisible = "left";
208
+ translateX.value = leftWidth;
209
+ } else {
210
+ translateX.value = 0;
211
+ }
212
+ }
213
+ triggerVisible(nextVisible);
214
+ }
215
+ movable.value = false;
216
+ lockDirection = "";
217
+ canResolveVisible = false;
218
+ };
219
+ const onMouseDown = useMouseDown(onTouchStart, onTouchMove, onTouchEnd);
220
+ __expose({
221
+ hide
222
+ });
223
+ const swipeActionClass = computed(() => {
224
+ return classNames(bem.b(), props.rootClass);
225
+ });
226
+ const swipeActionStyle = computed(() => {
227
+ return stringifyStyle(props.rootStyle);
228
+ });
229
+ const translateStyle = computed(() => {
230
+ return stringifyStyle({
231
+ transform: `translate3d(${translateX.value}px,0,0)`,
232
+ transition: movable.value ? "none" : `transform 300ms`
233
+ });
234
+ });
235
+ const __returned__ = { props, slots, emit, bem, innerVisible, triggerVisible, hide, onContentClick, isStoppedClick, onContentMouseDown, onMouseMove, onMouseUp, contentId, leftId, rightId, instance, get contentWidth() {
236
+ return contentWidth;
237
+ }, set contentWidth(v) {
238
+ contentWidth = v;
239
+ }, get leftWidth() {
240
+ return leftWidth;
241
+ }, set leftWidth(v) {
242
+ leftWidth = v;
243
+ }, get rightWidth() {
244
+ return rightWidth;
245
+ }, set rightWidth(v) {
246
+ rightWidth = v;
247
+ }, translateX, movable, get startX() {
248
+ return startX;
249
+ }, set startX(v) {
250
+ startX = v;
251
+ }, get startY() {
252
+ return startY;
253
+ }, set startY(v) {
254
+ startY = v;
255
+ }, get downTranslateX() {
256
+ return downTranslateX;
257
+ }, set downTranslateX(v) {
258
+ downTranslateX = v;
259
+ }, get lockDirection() {
260
+ return lockDirection;
261
+ }, set lockDirection(v) {
262
+ lockDirection = v;
263
+ }, get canResolveVisible() {
264
+ return canResolveVisible;
265
+ }, set canResolveVisible(v) {
266
+ canResolveVisible = v;
267
+ }, initVelocity, getWidth, setTranslateXByVisible, onTouchStart, onTouchMove, onTouchEnd, onMouseDown, swipeActionClass, swipeActionStyle, translateStyle };
268
+ return __returned__;
269
+ }
270
+ });
271
+ </script>
272
+
273
+ <style lang="scss">
274
+ @import './index.scss';
275
+ </style>
@@ -0,0 +1,3 @@
1
+ // #variables
2
+
3
+ // #endvariables
@@ -24,7 +24,7 @@ import { classNames, stringifyStyle, createBem } from "../../utils";
24
24
  import SarPopup from "../popup/popup.vue";
25
25
  import SarLoading from "../loading/loading.vue";
26
26
  import SarIcon from "../icon/icon.vue";
27
- import { useSetTimeout } from "../../use";
27
+ import { useTimeout } from "../../use";
28
28
  import {
29
29
  defaultToastProps
30
30
  } from "./common";
@@ -61,15 +61,18 @@ export default _defineComponent({
61
61
  const emit = __emit;
62
62
  const bem = createBem("toast");
63
63
  const innerVisible = ref(props.visible);
64
- const [hideLater, cancelHide] = useSetTimeout(() => {
65
- innerVisible.value = false;
66
- emit("update:visible", false);
67
- });
64
+ const { start: hideLater, stop: cancelHide } = useTimeout(
65
+ () => {
66
+ innerVisible.value = false;
67
+ emit("update:visible", false);
68
+ },
69
+ () => props.timeout
70
+ );
68
71
  const reHideLater = () => {
69
72
  cancelHide();
70
73
  nextTick(() => {
71
74
  if (props.type !== "loading" && props.timeout > 0) {
72
- hideLater(props.timeout);
75
+ hideLater();
73
76
  }
74
77
  });
75
78
  };
@@ -79,7 +82,7 @@ export default _defineComponent({
79
82
  innerVisible.value = props.visible;
80
83
  if (props.visible) {
81
84
  if (props.type !== "loading" && props.timeout > 0) {
82
- hideLater(props.timeout);
85
+ hideLater();
83
86
  }
84
87
  }
85
88
  }
package/global.d.ts CHANGED
@@ -102,6 +102,7 @@ declare module 'vue' {
102
102
  SarStep: typeof import('./components/step/step').default
103
103
  SarStepper: typeof import('./components/stepper/stepper').default
104
104
  SarSteps: typeof import('./components/steps/steps').default
105
+ SarSwipeAction: typeof import('./components/swipe-action/swipe-action').default
105
106
  SarSwiperDot: typeof import('./components/swiper-dot/swiper-dot').default
106
107
  SarSwitch: typeof import('./components/switch/switch').default
107
108
  SarTab: typeof import('./components/tab/tab').default
package/index.d.ts CHANGED
@@ -88,6 +88,7 @@ export * from './components/status-bar';
88
88
  export * from './components/step';
89
89
  export * from './components/stepper';
90
90
  export * from './components/steps';
91
+ export * from './components/swipe-action';
91
92
  export * from './components/swiper-dot';
92
93
  export * from './components/switch';
93
94
  export * from './components/tabbar';
package/index.js CHANGED
@@ -88,6 +88,7 @@ export * from './components/status-bar';
88
88
  export * from './components/step';
89
89
  export * from './components/stepper';
90
90
  export * from './components/steps';
91
+ export * from './components/swipe-action';
91
92
  export * from './components/swiper-dot';
92
93
  export * from './components/switch';
93
94
  export * from './components/tabbar';
package/index.scss CHANGED
@@ -62,6 +62,7 @@
62
62
  @use './components/stepper/variables.scss' as *;
63
63
  @use './components/steps/variables.scss' as *;
64
64
  @use './components/style/variables.scss' as *;
65
+ @use './components/swipe-action/variables.scss' as *;
65
66
  @use './components/swiper-dot/variables.scss' as *;
66
67
  @use './components/switch/variables.scss' as *;
67
68
  @use './components/tabbar/variables.scss' as *;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "sard-uniapp",
3
3
  "name": "sard-uniapp",
4
4
  "displayName": "sard-uniapp",
5
- "version": "1.18.0",
5
+ "version": "1.19.1",
6
6
  "description": "sard-uniapp 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库",
7
7
  "main": "index.js",
8
8
  "scripts": {
@@ -122,7 +122,7 @@
122
122
  "lodash-es": "^4.17.21",
123
123
  "prettier": "^3.5.3",
124
124
  "region-data": "^1.2.3",
125
- "sard-cli": "^1.2.0",
125
+ "sard-cli": "^1.2.4",
126
126
  "sass": "^1.69.7",
127
127
  "tel-area-code": "^1.1.0",
128
128
  "ts-custom-error": "^3.3.1",
@@ -223,10 +223,5 @@
223
223
  },
224
224
  "engines": {
225
225
  "HBuilderX": "^3.6.0"
226
- },
227
- "pnpm": {
228
- "overrides": {
229
- "sard-cli": "link:../sard-cli"
230
- }
231
226
  }
232
227
  }
package/use/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './useTransition';
2
- export * from './useSetTimeout';
2
+ export * from './useTimeout';
3
3
  export * from './useZIndex';
4
4
  export * from './useImperative';
5
5
  export * from './useLuckyGrid';
@@ -16,3 +16,5 @@ export * from './useTimeoutLoading';
16
16
  export * from './useTwoWayVisible';
17
17
  export * from './usePopoutInput';
18
18
  export * from './useFormPopout';
19
+ export * from './useInitialVelocity';
20
+ export * from './useStopMovedClick';
package/use/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './useTransition';
2
- export * from './useSetTimeout';
2
+ export * from './useTimeout';
3
3
  export * from './useZIndex';
4
4
  export * from './useImperative';
5
5
  export * from './useLuckyGrid';
@@ -16,3 +16,5 @@ export * from './useTimeoutLoading';
16
16
  export * from './useTwoWayVisible';
17
17
  export * from './usePopoutInput';
18
18
  export * from './useFormPopout';
19
+ export * from './useInitialVelocity';
20
+ export * from './useStopMovedClick';
@@ -1,5 +1,5 @@
1
1
  import { computed, ref, shallowRef } from 'vue';
2
- import { useSetTimeout } from './useSetTimeout';
2
+ import { useTimeout } from './useTimeout';
3
3
  import { isNullish, matchScrollVisible } from '../utils';
4
4
  export function useScrollSpy(options) {
5
5
  const { defaultCurrent, initialScroll, onChange, getSpiedRect } = options;
@@ -10,9 +10,9 @@ export function useScrollSpy(options) {
10
10
  const anchorRectList = shallowRef([]);
11
11
  const anchorMap = new Map();
12
12
  let lockScroll = false;
13
- const [unLockScrollLater] = useSetTimeout(() => {
13
+ const { start: unLockScrollLater } = useTimeout(() => {
14
14
  lockScroll = false;
15
- });
15
+ }, 150);
16
16
  const register = (name, getRect) => {
17
17
  anchorMap.set(name, getRect);
18
18
  };
@@ -44,7 +44,7 @@ export function useScrollSpy(options) {
44
44
  const offset = item[1].top;
45
45
  scrollTop.value = offset - startOffset.value;
46
46
  lockScroll = true;
47
- unLockScrollLater(150);
47
+ unLockScrollLater();
48
48
  }
49
49
  }
50
50
  };
@@ -1,17 +1,17 @@
1
1
  import { getDistanceBetweenTwoPoints } from '../utils';
2
- import { useSetTimeout } from './useSetTimeout';
2
+ import { useTimeout } from './useTimeout';
3
3
  export function useSimulatedClick(click, duration = 10000) {
4
4
  let timeout = false;
5
5
  let downCoord = { x: 0, y: 0 };
6
- const [timeoutLater, cancelTimeout] = useSetTimeout(() => {
6
+ const { start: timeoutLater, stop: cancelTimeout } = useTimeout(() => {
7
7
  timeout = true;
8
- });
8
+ }, duration);
9
9
  const onTouchStart = (event) => {
10
10
  downCoord = {
11
11
  x: event.touches[0].clientX,
12
12
  y: event.touches[0].clientY,
13
13
  };
14
- timeoutLater(duration);
14
+ timeoutLater();
15
15
  };
16
16
  const onTouchEnd = (event) => {
17
17
  cancelTimeout();
@@ -1,19 +1,19 @@
1
1
  import { getDistanceBetweenTwoPoints } from '../utils';
2
- import { useSetTimeout } from './useSetTimeout';
2
+ import { useTimeout } from './useTimeout';
3
3
  export function useSimulatedPress(options = {}) {
4
4
  const { start, move, end, duration = 500 } = options;
5
5
  let downCoord = { x: 0, y: 0 };
6
6
  let isPressing = false;
7
- const [triggerPressLater, cancelTriggerPress, isWaitingToTriggerPress] = useSetTimeout(() => {
7
+ const { start: triggerPressLater, stop: cancelTriggerPress, isPending: isWaitingToTriggerPress, } = useTimeout(() => {
8
8
  isPressing = true;
9
9
  start?.();
10
- });
10
+ }, duration);
11
11
  const onTouchStart = (event) => {
12
12
  downCoord = {
13
13
  x: event.touches[0].clientX,
14
14
  y: event.touches[0].clientY,
15
15
  };
16
- triggerPressLater(duration);
16
+ triggerPressLater();
17
17
  };
18
18
  const onTouchMove = (event) => {
19
19
  const moveCoord = {
@@ -28,7 +28,7 @@ export function useSimulatedPress(options = {}) {
28
28
  },
29
29
  });
30
30
  }
31
- else if (isWaitingToTriggerPress()) {
31
+ else if (isWaitingToTriggerPress.value) {
32
32
  const distance = getDistanceBetweenTwoPoints(downCoord, moveCoord);
33
33
  if (distance > 10) {
34
34
  cancelTriggerPress();
@@ -0,0 +1,6 @@
1
+ export declare function useStopMovedClick(): {
2
+ onMouseDown: () => void;
3
+ onMouseMove: () => void;
4
+ onMouseUp: () => void;
5
+ isStoppedClick: import("vue").Ref<boolean, boolean>;
6
+ };
@@ -0,0 +1,26 @@
1
+ import { ref } from 'vue';
2
+ export function useStopMovedClick() {
3
+ let isDown = false;
4
+ let moved = false;
5
+ const isStoppedClick = ref(false);
6
+ const onMouseDown = () => {
7
+ isDown = true;
8
+ moved = false;
9
+ isStoppedClick.value = false;
10
+ };
11
+ const onMouseMove = () => {
12
+ moved = true;
13
+ };
14
+ const onMouseUp = () => {
15
+ if (isDown && moved) {
16
+ isStoppedClick.value = true;
17
+ }
18
+ isDown = false;
19
+ };
20
+ return {
21
+ onMouseDown,
22
+ onMouseMove,
23
+ onMouseUp,
24
+ isStoppedClick,
25
+ };
26
+ }
@@ -0,0 +1,11 @@
1
+ import { MaybeRefOrGetter } from 'vue';
2
+ export interface UseTimeoutFnOptions {
3
+ immediate?: boolean;
4
+ immediateCallback?: boolean;
5
+ }
6
+ export declare function useTimeout<CallbackFn extends (...args: any[]) => any>(cb: CallbackFn, interval: MaybeRefOrGetter<number>, options?: UseTimeoutFnOptions): {
7
+ isPending: Readonly<import("vue").ShallowRef<boolean, boolean>>;
8
+ start: (...args: Parameters<CallbackFn> | []) => void;
9
+ stop: () => void;
10
+ };
11
+ export declare const useSetTimeout: typeof useTimeout;
@@ -0,0 +1,39 @@
1
+ import { onUnmounted, shallowReadonly, shallowRef, toValue, } from 'vue';
2
+ export function useTimeout(cb, interval, options = {}) {
3
+ const { immediate = false, immediateCallback = false } = options;
4
+ const isPending = shallowRef(false);
5
+ let timer = null;
6
+ function clear() {
7
+ if (timer) {
8
+ clearTimeout(timer);
9
+ timer = null;
10
+ }
11
+ }
12
+ function stop() {
13
+ isPending.value = false;
14
+ clear();
15
+ }
16
+ function start(...args) {
17
+ if (immediateCallback)
18
+ cb();
19
+ clear();
20
+ isPending.value = true;
21
+ timer = setTimeout(() => {
22
+ isPending.value = false;
23
+ timer = null;
24
+ cb(...args);
25
+ }, toValue(interval));
26
+ }
27
+ if (immediate) {
28
+ start();
29
+ }
30
+ onUnmounted(() => {
31
+ stop();
32
+ });
33
+ return {
34
+ isPending: shallowReadonly(isPending),
35
+ start,
36
+ stop,
37
+ };
38
+ }
39
+ export const useSetTimeout = useTimeout;