@maas/vue-equipment 1.0.0-beta.43 → 1.0.0-beta.44
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/dist/composables/useScrollLockPadding/index.js +1 -0
- package/dist/composables/useScrollLockPadding/index.js.map +1 -1
- package/dist/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +1 -1
- package/dist/plugins/MagicAccordion/src/components/MagicAccordionProvider.vue +2 -5
- package/dist/plugins/MagicAccordion/src/composables/private/useAccordionState.d.ts +2 -3
- package/dist/plugins/MagicAccordion/src/composables/private/useAccordionState.mjs +38 -11
- package/dist/plugins/MagicAccordion/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.d.vue.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue +2 -5
- package/dist/plugins/MagicCommand/src/components/MagicCommandRenderer.vue +1 -0
- package/dist/plugins/MagicCommand/src/composables/private/useCommandState.d.ts +2 -3
- package/dist/plugins/MagicCommand/src/composables/private/useCommandState.mjs +36 -11
- package/dist/plugins/MagicCommand/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicCookie/src/composables/private/useCookieState.d.ts +2 -3
- package/dist/plugins/MagicCookie/src/composables/private/useCookieState.mjs +35 -12
- package/dist/plugins/MagicCookie/src/composables/useMagicCookie.mjs +6 -1
- package/dist/plugins/MagicCookie/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.mjs +28 -11
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableSnap.mjs +11 -1
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableState.d.ts +1 -1
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableState.mjs +41 -11
- package/dist/plugins/MagicDraggable/src/composables/useMagicDraggable.mjs +2 -1
- package/dist/plugins/MagicDraggable/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.d.vue.ts +2 -2
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +11 -3
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue.d.ts +2 -2
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.d.ts +2 -0
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +184 -29
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerState.d.ts +2 -3
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerState.mjs +35 -10
- package/dist/plugins/MagicDrawer/src/composables/useMagicDrawer.mjs +2 -1
- package/dist/plugins/MagicDrawer/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicEmitter/src/composables/useMagicEmitter.mjs +10 -5
- package/dist/plugins/MagicMarquee/src/components/MagicMarquee.vue +2 -5
- package/dist/plugins/MagicMarquee/src/composables/private/useMarqueeState.d.ts +2 -3
- package/dist/plugins/MagicMarquee/src/composables/private/useMarqueeState.mjs +36 -11
- package/dist/plugins/MagicMarquee/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.d.vue.ts +2 -2
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue.d.ts +2 -2
- package/dist/plugins/MagicMenu/src/components/MagicMenuProvider.vue +2 -6
- package/dist/plugins/MagicMenu/src/composables/private/useMenuCursor.mjs +13 -1
- package/dist/plugins/MagicMenu/src/composables/private/useMenuState.d.ts +2 -3
- package/dist/plugins/MagicMenu/src/composables/private/useMenuState.mjs +32 -12
- package/dist/plugins/MagicMenu/src/composables/private/useMenuTrigger.mjs +1 -1
- package/dist/plugins/MagicMenu/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicModal/src/composables/private/useModalState.d.ts +6 -0
- package/dist/plugins/MagicModal/src/composables/private/useModalState.mjs +58 -0
- package/dist/plugins/MagicModal/src/composables/private/useModalStore.d.ts +1 -5
- package/dist/plugins/MagicModal/src/composables/private/useModalStore.mjs +1 -15
- package/dist/plugins/MagicModal/src/composables/useMagicModal.mjs +7 -6
- package/dist/plugins/MagicModal/src/types/index.d.ts +5 -0
- package/dist/plugins/MagicNoise/src/components/MagicNoise.vue +14 -2
- package/dist/plugins/MagicPie/src/components/MagicPie.vue +12 -6
- package/dist/plugins/MagicPie/src/composables/private/usePieState.d.ts +1 -1
- package/dist/plugins/MagicPie/src/composables/private/usePieState.mjs +33 -12
- package/dist/plugins/MagicPie/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudio.vue +9 -6
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudioControls.vue +4 -8
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue +8 -1
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerProvider.vue +2 -11
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideo.vue +10 -6
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideoControls.vue +4 -8
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerControlsApi.d.ts +0 -1
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerControlsApi.mjs +20 -9
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerEmitter.mjs +124 -75
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerMediaApi.mjs +100 -32
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.d.ts +0 -1
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.mjs +33 -13
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerState.d.ts +2 -3
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerState.mjs +35 -10
- package/dist/plugins/MagicPlayer/src/composables/useMagicPlayer.d.ts +0 -2
- package/dist/plugins/MagicPlayer/src/types/index.d.ts +1 -0
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +2 -2
- package/dist/plugins/MagicScroll/src/components/MagicScrollMotion.vue +13 -1
- package/dist/plugins/MagicScroll/src/components/MagicScrollScene.vue +9 -5
- package/dist/plugins/MagicScroll/src/composables/private/useCollisionDetection.mjs +2 -1
- package/dist/plugins/MagicToast/src/components/MagicToastProvider.vue +2 -11
- package/dist/plugins/MagicToast/src/components/MagicToastView.vue +1 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastDrag.mjs +13 -1
- package/dist/plugins/MagicToast/src/composables/private/useToastState.d.ts +2 -3
- package/dist/plugins/MagicToast/src/composables/private/useToastState.mjs +35 -12
- package/dist/plugins/MagicToast/src/types/index.d.ts +1 -0
- package/dist/utils/index.d.ts +8 -1
- package/dist/utils/index.js +56497 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/plugins/MagicError/src/MagicError.d.ts +0 -0
- package/dist/plugins/MagicError/src/MagicError.mjs +0 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
onScopeDispose,
|
|
3
|
+
shallowRef,
|
|
4
|
+
toRefs,
|
|
5
|
+
toValue
|
|
6
|
+
} from "vue";
|
|
2
7
|
import { useEventListener } from "@vueuse/core";
|
|
3
8
|
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
4
9
|
import { usePlayerState } from "./usePlayerState.mjs";
|
|
@@ -13,6 +18,9 @@ export function usePlayerRuntime(args) {
|
|
|
13
18
|
const { initializeState } = usePlayerState(toValue(id));
|
|
14
19
|
const state = initializeState();
|
|
15
20
|
const { loaded } = toRefs(state);
|
|
21
|
+
let cancelLoaded = void 0;
|
|
22
|
+
let cancelPlay = void 0;
|
|
23
|
+
let cancelPause = void 0;
|
|
16
24
|
function handleHlsRuntimeError(args2) {
|
|
17
25
|
const { data, hls: hls2 } = args2;
|
|
18
26
|
const error = new Error(data.details || "HLS error");
|
|
@@ -63,13 +71,18 @@ export function usePlayerRuntime(args) {
|
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
function useNative() {
|
|
74
|
+
if (!mediaRef) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
66
77
|
const el = toValue(mediaRef);
|
|
67
78
|
if (!el || !src) {
|
|
68
79
|
return;
|
|
69
80
|
}
|
|
70
81
|
try {
|
|
71
82
|
el.src = src;
|
|
72
|
-
|
|
83
|
+
cancelLoaded?.();
|
|
84
|
+
cancelLoaded = useEventListener(
|
|
85
|
+
mediaRef,
|
|
73
86
|
"loadeddata",
|
|
74
87
|
() => {
|
|
75
88
|
loaded.value = true;
|
|
@@ -114,10 +127,12 @@ export function usePlayerRuntime(args) {
|
|
|
114
127
|
hls.on(Hls.Events.ERROR, (_event, data) => {
|
|
115
128
|
handleHlsRuntimeError({ data, hls });
|
|
116
129
|
});
|
|
117
|
-
|
|
130
|
+
cancelPause?.();
|
|
131
|
+
cancelPause = useEventListener(mediaRef, "pause", () => {
|
|
118
132
|
hls?.stopLoad();
|
|
119
133
|
});
|
|
120
|
-
|
|
134
|
+
cancelPlay?.();
|
|
135
|
+
cancelPlay = useEventListener(mediaRef, "play", () => {
|
|
121
136
|
hls?.startLoad();
|
|
122
137
|
});
|
|
123
138
|
hls.loadSource(src);
|
|
@@ -130,14 +145,10 @@ export function usePlayerRuntime(args) {
|
|
|
130
145
|
});
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
|
-
function initialize(autoplay = false) {
|
|
134
|
-
if (srcType === "native") {
|
|
135
|
-
useNative();
|
|
136
|
-
} else if (srcType === "hls") {
|
|
137
|
-
useHlsJS(autoplay);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
148
|
function destroy() {
|
|
149
|
+
cancelLoaded?.();
|
|
150
|
+
cancelPlay?.();
|
|
151
|
+
cancelPause?.();
|
|
141
152
|
try {
|
|
142
153
|
hls?.destroy();
|
|
143
154
|
} finally {
|
|
@@ -145,8 +156,17 @@ export function usePlayerRuntime(args) {
|
|
|
145
156
|
deferredLoading.value = false;
|
|
146
157
|
}
|
|
147
158
|
}
|
|
159
|
+
function initialize(autoplay = false) {
|
|
160
|
+
if (srcType === "native") {
|
|
161
|
+
useNative();
|
|
162
|
+
} else if (srcType === "hls") {
|
|
163
|
+
useHlsJS(autoplay);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
onScopeDispose(() => {
|
|
167
|
+
destroy();
|
|
168
|
+
});
|
|
148
169
|
return {
|
|
149
|
-
initialize
|
|
150
|
-
destroy
|
|
170
|
+
initialize
|
|
151
171
|
};
|
|
152
172
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
2
|
import type { PlayerState } from '../../types/index.js';
|
|
3
3
|
export declare function usePlayerState(id: MaybeRef<string>): {
|
|
4
4
|
initializeState: () => PlayerState;
|
|
5
|
-
|
|
6
|
-
playerStateStore: Ref<PlayerState[], PlayerState[]>;
|
|
5
|
+
playerStateStore: import("vue").Ref<PlayerState[], PlayerState[]>;
|
|
7
6
|
};
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { reactive, toValue, onScopeDispose } from "vue";
|
|
2
|
+
import { createStateStore } from "@maas/vue-equipment/utils";
|
|
3
|
+
const getPlayerStateStore = createStateStore(
|
|
4
|
+
"MagicPlayer",
|
|
5
|
+
() => []
|
|
6
|
+
);
|
|
3
7
|
export function usePlayerState(id) {
|
|
8
|
+
const playerStateStore = getPlayerStateStore();
|
|
9
|
+
let scopeCounted = false;
|
|
4
10
|
function createState(id2) {
|
|
5
11
|
const state = {
|
|
6
12
|
id: id2,
|
|
13
|
+
refCount: 0,
|
|
7
14
|
buffered: [],
|
|
8
15
|
currentTime: 0,
|
|
9
16
|
dragging: false,
|
|
@@ -42,21 +49,39 @@ export function usePlayerState(id) {
|
|
|
42
49
|
playerStateStore.value = [...playerStateStore.value, state];
|
|
43
50
|
return state;
|
|
44
51
|
}
|
|
52
|
+
function deleteState() {
|
|
53
|
+
const currentId = toValue(id);
|
|
54
|
+
playerStateStore.value = playerStateStore.value.filter(
|
|
55
|
+
(x) => x.id !== currentId
|
|
56
|
+
);
|
|
57
|
+
}
|
|
45
58
|
function initializeState() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
59
|
+
const currentId = toValue(id);
|
|
60
|
+
let state = playerStateStore.value.find((entry) => entry.id === currentId);
|
|
49
61
|
if (!state) {
|
|
50
|
-
state = addState(
|
|
62
|
+
state = addState(currentId);
|
|
63
|
+
}
|
|
64
|
+
if (!scopeCounted) {
|
|
65
|
+
state.refCount++;
|
|
66
|
+
scopeCounted = true;
|
|
51
67
|
}
|
|
52
68
|
return state;
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
onScopeDispose(() => {
|
|
71
|
+
if (!scopeCounted) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const currentId = toValue(id);
|
|
75
|
+
const state = playerStateStore.value.find((entry) => entry.id === currentId);
|
|
76
|
+
if (state) {
|
|
77
|
+
state.refCount--;
|
|
78
|
+
if (state.refCount <= 0) {
|
|
79
|
+
deleteState();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
57
83
|
return {
|
|
58
84
|
initializeState,
|
|
59
|
-
deleteState,
|
|
60
85
|
playerStateStore
|
|
61
86
|
};
|
|
62
87
|
}
|
|
@@ -43,7 +43,6 @@ export declare function useMagicPlayer(id: MaybeRef<string>): {
|
|
|
43
43
|
};
|
|
44
44
|
controlsApi: {
|
|
45
45
|
initialize: () => void;
|
|
46
|
-
destroy: () => void;
|
|
47
46
|
bufferedPercentage: import("vue").ComputedRef<number>;
|
|
48
47
|
onMouseenter: () => void;
|
|
49
48
|
onMouseleave: () => void;
|
|
@@ -53,7 +52,6 @@ export declare function useMagicPlayer(id: MaybeRef<string>): {
|
|
|
53
52
|
};
|
|
54
53
|
playerRuntime: {
|
|
55
54
|
initialize: (autoplay?: boolean) => void;
|
|
56
|
-
destroy: () => void;
|
|
57
55
|
};
|
|
58
56
|
};
|
|
59
57
|
export type UseMagicPlayerReturn = ReturnType<typeof useMagicPlayer>;
|
|
@@ -56,8 +56,8 @@ watch(
|
|
|
56
56
|
);
|
|
57
57
|
useIntersectionObserver(
|
|
58
58
|
elRef,
|
|
59
|
-
([
|
|
60
|
-
intersecting.value = isIntersecting;
|
|
59
|
+
([entry]) => {
|
|
60
|
+
intersecting.value = entry?.isIntersecting ?? intersecting.value;
|
|
61
61
|
},
|
|
62
62
|
{ rootMargin: "150% 0px 150% 0px", immediate: true }
|
|
63
63
|
);
|
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup>
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ref,
|
|
10
|
+
inject,
|
|
11
|
+
computed,
|
|
12
|
+
onMounted,
|
|
13
|
+
watch,
|
|
14
|
+
useTemplateRef,
|
|
15
|
+
onUnmounted
|
|
16
|
+
} from "vue";
|
|
9
17
|
import { unrefElement } from "@vueuse/core";
|
|
10
18
|
import defu from "defu";
|
|
11
19
|
import {
|
|
@@ -63,4 +71,8 @@ watch(
|
|
|
63
71
|
onMounted(() => {
|
|
64
72
|
createAnimation();
|
|
65
73
|
});
|
|
74
|
+
onUnmounted(() => {
|
|
75
|
+
animation.value?.cancel();
|
|
76
|
+
animation.value = void 0;
|
|
77
|
+
});
|
|
66
78
|
</script>
|
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
watch,
|
|
13
13
|
nextTick,
|
|
14
14
|
readonly,
|
|
15
|
-
useTemplateRef
|
|
15
|
+
useTemplateRef,
|
|
16
|
+
onBeforeUnmount
|
|
16
17
|
} from "vue";
|
|
17
18
|
import { useIntersectionObserver } from "@vueuse/core";
|
|
18
19
|
import {
|
|
@@ -67,15 +68,18 @@ watch(
|
|
|
67
68
|
},
|
|
68
69
|
{ once: true }
|
|
69
70
|
);
|
|
70
|
-
useIntersectionObserver(
|
|
71
|
+
const intersectionObserver = useIntersectionObserver(
|
|
71
72
|
elRef,
|
|
72
|
-
([
|
|
73
|
-
intersecting.value = isIntersecting;
|
|
74
|
-
if (isIntersecting) {
|
|
73
|
+
([entry]) => {
|
|
74
|
+
intersecting.value = entry?.isIntersecting ?? intersecting.value;
|
|
75
|
+
if (entry?.isIntersecting) {
|
|
75
76
|
calculate();
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
79
|
{ rootMargin: "150% 0px 150% 0px", immediate: true }
|
|
79
80
|
);
|
|
81
|
+
onBeforeUnmount(() => {
|
|
82
|
+
intersectionObserver.stop();
|
|
83
|
+
});
|
|
80
84
|
provide(MagicScrollProgress, readonly(progress));
|
|
81
85
|
</script>
|
|
@@ -3,6 +3,7 @@ import { useElementBounding, useWindowSize } from "@vueuse/core";
|
|
|
3
3
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
4
4
|
export function useCollisionDetection(args) {
|
|
5
5
|
const { id, scrollY, child, parent, offset } = args;
|
|
6
|
+
const magicEmitter = useMagicEmitter();
|
|
6
7
|
const alerted = reactive({
|
|
7
8
|
up: {
|
|
8
9
|
top: {
|
|
@@ -114,7 +115,7 @@ export function useCollisionDetection(args) {
|
|
|
114
115
|
const mappedParentEdge = toValue(mappedParentBoundingRect[parentEdge]) + offset2;
|
|
115
116
|
if (direction === "down" && mappedChildEdge <= mappedParentEdge || direction === "up" && mappedChildEdge >= mappedParentEdge) {
|
|
116
117
|
alerted[direction][childEdge][parentEdge] = true;
|
|
117
|
-
|
|
118
|
+
magicEmitter.emit("collision", {
|
|
118
119
|
id,
|
|
119
120
|
direction,
|
|
120
121
|
parentEdge,
|
|
@@ -42,13 +42,7 @@
|
|
|
42
42
|
</template>
|
|
43
43
|
|
|
44
44
|
<script setup>
|
|
45
|
-
import {
|
|
46
|
-
toValue,
|
|
47
|
-
useTemplateRef,
|
|
48
|
-
provide,
|
|
49
|
-
watch,
|
|
50
|
-
onBeforeUnmount
|
|
51
|
-
} from "vue";
|
|
45
|
+
import { toValue, useTemplateRef, provide, watch } from "vue";
|
|
52
46
|
import { onClickOutside } from "@vueuse/core";
|
|
53
47
|
import { useToastState } from "../composables/private/useToastState";
|
|
54
48
|
import { useToastView } from "../composables/private/useToastView";
|
|
@@ -71,7 +65,7 @@ defineOptions({
|
|
|
71
65
|
inheritAttrs: false
|
|
72
66
|
});
|
|
73
67
|
const { deleteView } = useToastView(id);
|
|
74
|
-
const {
|
|
68
|
+
const { initializeState } = useToastState(id);
|
|
75
69
|
const state = initializeState(options);
|
|
76
70
|
const listRef = useTemplateRef("list");
|
|
77
71
|
const {
|
|
@@ -93,9 +87,6 @@ watch(
|
|
|
93
87
|
deep: true
|
|
94
88
|
}
|
|
95
89
|
);
|
|
96
|
-
onBeforeUnmount(() => {
|
|
97
|
-
deleteState();
|
|
98
|
-
});
|
|
99
90
|
provide(MagicToastInstanceId, id);
|
|
100
91
|
</script>
|
|
101
92
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, toRefs, toValue } from "vue";
|
|
1
|
+
import { computed, onScopeDispose, toRefs, toValue } from "vue";
|
|
2
2
|
import { useEventListener } from "@vueuse/core";
|
|
3
3
|
import {
|
|
4
4
|
guardedReleasePointerCapture,
|
|
@@ -34,6 +34,7 @@ export function useToastDrag(args) {
|
|
|
34
34
|
let cancelPointerup = void 0;
|
|
35
35
|
let cancelPointermove = void 0;
|
|
36
36
|
let cancelTouchend = void 0;
|
|
37
|
+
let cancelTouchcancel = void 0;
|
|
37
38
|
const hasDragged = computed(() => {
|
|
38
39
|
const hasDraggedX = !isWithinRange({
|
|
39
40
|
input: draggedX.value,
|
|
@@ -187,6 +188,7 @@ export function useToastDrag(args) {
|
|
|
187
188
|
cancelTouchend?.();
|
|
188
189
|
cancelPointerup?.();
|
|
189
190
|
cancelPointermove?.();
|
|
191
|
+
cancelTouchcancel?.();
|
|
190
192
|
}
|
|
191
193
|
function onPointerup(e) {
|
|
192
194
|
if (shouldClose.value) {
|
|
@@ -248,6 +250,12 @@ export function useToastDrag(args) {
|
|
|
248
250
|
y: draggedY.value
|
|
249
251
|
});
|
|
250
252
|
}
|
|
253
|
+
function destroy() {
|
|
254
|
+
cancelPointermove?.();
|
|
255
|
+
cancelPointerup?.();
|
|
256
|
+
cancelTouchend?.();
|
|
257
|
+
cancelTouchcancel?.();
|
|
258
|
+
}
|
|
251
259
|
function onPointerdown(e) {
|
|
252
260
|
const scrollLockValue = toValue(scrollLock);
|
|
253
261
|
if (scrollLockValue) {
|
|
@@ -270,6 +278,7 @@ export function useToastDrag(args) {
|
|
|
270
278
|
lastDraggedX.value = draggedX.value;
|
|
271
279
|
lastDraggedY.value = draggedY.value;
|
|
272
280
|
cancelPointerup = useEventListener(document, "pointerup", onPointerup);
|
|
281
|
+
cancelTouchcancel = useEventListener(document, "touchcancel", onPointerup);
|
|
273
282
|
cancelPointermove = useEventListener(
|
|
274
283
|
document,
|
|
275
284
|
"pointermove",
|
|
@@ -295,6 +304,9 @@ export function useToastDrag(args) {
|
|
|
295
304
|
state.expanded = true;
|
|
296
305
|
}
|
|
297
306
|
}
|
|
307
|
+
onScopeDispose(() => {
|
|
308
|
+
destroy();
|
|
309
|
+
});
|
|
298
310
|
return {
|
|
299
311
|
onPointerdown,
|
|
300
312
|
onClick,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
2
|
import type { ToastState, MagicToastOptions } from '../../types/index.js';
|
|
3
3
|
export declare function useToastState(instanceId: MaybeRef<string>): {
|
|
4
4
|
initializeState: (options?: MagicToastOptions) => ToastState;
|
|
5
|
-
|
|
6
|
-
toastStateStore: Ref<ToastState[], ToastState[]>;
|
|
5
|
+
toastStateStore: import("vue").Ref<ToastState[], ToastState[]>;
|
|
7
6
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { reactive, toValue, onScopeDispose } from "vue";
|
|
2
2
|
import { defu } from "defu";
|
|
3
|
+
import { createStateStore } from "@maas/vue-equipment/utils";
|
|
3
4
|
import { defaultOptions } from "../../utils/defaultOptions.mjs";
|
|
4
|
-
const
|
|
5
|
+
const getToastStateStore = createStateStore(
|
|
6
|
+
"MagicToast",
|
|
7
|
+
() => []
|
|
8
|
+
);
|
|
5
9
|
export function useToastState(instanceId) {
|
|
10
|
+
const toastStateStore = getToastStateStore();
|
|
11
|
+
let scopeCounted = false;
|
|
6
12
|
function createState(id) {
|
|
7
13
|
const state = {
|
|
8
14
|
id,
|
|
15
|
+
refCount: 0,
|
|
9
16
|
options: { ...defaultOptions },
|
|
10
17
|
views: [],
|
|
11
18
|
expanded: false,
|
|
@@ -18,12 +25,21 @@ export function useToastState(instanceId) {
|
|
|
18
25
|
toastStateStore.value = [...toastStateStore.value, state];
|
|
19
26
|
return state;
|
|
20
27
|
}
|
|
28
|
+
function deleteState() {
|
|
29
|
+
const currentId = toValue(instanceId);
|
|
30
|
+
toastStateStore.value = toastStateStore.value.filter(
|
|
31
|
+
(x) => x.id !== currentId
|
|
32
|
+
);
|
|
33
|
+
}
|
|
21
34
|
function initializeState(options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
35
|
+
const currentId = toValue(instanceId);
|
|
36
|
+
let state = toastStateStore.value.find((entry) => entry.id === currentId);
|
|
25
37
|
if (!state) {
|
|
26
|
-
state = addState(
|
|
38
|
+
state = addState(currentId);
|
|
39
|
+
}
|
|
40
|
+
if (!scopeCounted) {
|
|
41
|
+
state.refCount++;
|
|
42
|
+
scopeCounted = true;
|
|
27
43
|
}
|
|
28
44
|
if (options) {
|
|
29
45
|
const mappedOptions = defu(options, defaultOptions);
|
|
@@ -32,14 +48,21 @@ export function useToastState(instanceId) {
|
|
|
32
48
|
}
|
|
33
49
|
return state;
|
|
34
50
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
onScopeDispose(() => {
|
|
52
|
+
if (!scopeCounted) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const currentId = toValue(instanceId);
|
|
56
|
+
const state = toastStateStore.value.find((entry) => entry.id === currentId);
|
|
57
|
+
if (state) {
|
|
58
|
+
state.refCount--;
|
|
59
|
+
if (state.refCount <= 0) {
|
|
60
|
+
deleteState();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
40
64
|
return {
|
|
41
65
|
initializeState,
|
|
42
|
-
deleteState,
|
|
43
66
|
toastStateStore
|
|
44
67
|
};
|
|
45
68
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
|
|
1
3
|
declare function clampValue(value: number, min: number, max: number): number;
|
|
2
4
|
|
|
5
|
+
type CreateStore<T> = () => Ref<T>;
|
|
6
|
+
declare function createStateStore<T>(key: string, setInitialValue: () => T): CreateStore<T>;
|
|
7
|
+
|
|
3
8
|
declare function linear(t: number): number;
|
|
4
9
|
declare function easeInQuad(t: number): number;
|
|
5
10
|
declare function easeOutQuad(t: number): number;
|
|
@@ -27,6 +32,8 @@ type InterpolateArgs = {
|
|
|
27
32
|
};
|
|
28
33
|
declare function interpolate(args: InterpolateArgs): number;
|
|
29
34
|
|
|
35
|
+
declare function isAndroid(): boolean;
|
|
36
|
+
|
|
30
37
|
declare function isIOS(): boolean;
|
|
31
38
|
|
|
32
39
|
interface isWithinRangeArgs {
|
|
@@ -81,4 +88,4 @@ type RequireAllNested<T> = {
|
|
|
81
88
|
|
|
82
89
|
type ValueOf<T> = T[keyof T];
|
|
83
90
|
|
|
84
|
-
export { type InterpolateArgs, type PickPartial, type RequireAll, type RequireAllNested, type SlugifyOptions, type ValueOf, clampValue, easeInCubic, easeInOutCubic, easeInOutQuad, easeInOutQuart, easeInOutQuint, easeInQuad, easeInQuart, easeInQuint, easeOutBack, easeOutCubic, easeOutQuad, easeOutQuart, easeOutQuint, formatTime, guardedReleasePointerCapture, guardedSetPointerCapture, interpolate, isIOS, isWithinRange, linear, mapValue, matchClass, scrollbarGutterSupport, scrollbarWidth, slugify, uniq };
|
|
91
|
+
export { type CreateStore, type InterpolateArgs, type PickPartial, type RequireAll, type RequireAllNested, type SlugifyOptions, type ValueOf, clampValue, createStateStore, easeInCubic, easeInOutCubic, easeInOutQuad, easeInOutQuart, easeInOutQuint, easeInQuad, easeInQuart, easeInQuint, easeOutBack, easeOutCubic, easeOutQuad, easeOutQuart, easeOutQuint, formatTime, guardedReleasePointerCapture, guardedSetPointerCapture, interpolate, isAndroid, isIOS, isWithinRange, linear, mapValue, matchClass, scrollbarGutterSupport, scrollbarWidth, slugify, uniq };
|