@maas/vue-equipment 1.0.0-beta.76 → 1.0.0-beta.77
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/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +1 -1
- package/dist/plugins/MagicEmitter/src/composables/useMagicEmitter.d.ts +4 -4
- package/dist/plugins/MagicToast/src/components/MagicToastView.vue +2 -2
- package/dist/plugins/MagicToast/src/composables/private/useToastDrag.d.ts +1 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastDrag.mjs +45 -28
- package/dist/plugins/MagicToast/src/composables/private/useToastState.mjs +1 -0
- package/dist/plugins/MagicToast/src/composables/private/useToastView.d.ts +1 -1
- package/dist/plugins/MagicToast/src/composables/private/useToastView.mjs +3 -1
- package/dist/plugins/MagicToast/src/composables/useMagicToast.d.ts +4 -0
- package/dist/plugins/MagicToast/src/composables/useMagicToast.mjs +42 -2
- package/dist/plugins/MagicToast/src/types/index.d.ts +6 -0
- package/dist/plugins/MagicToast/src/utils/defaultOptions.mjs +3 -0
- package/package.json +1 -1
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -109,7 +109,7 @@ const functions$1 = [
|
|
|
109
109
|
{
|
|
110
110
|
name: "MagicTray",
|
|
111
111
|
"package": "plugins",
|
|
112
|
-
lastUpdated:
|
|
112
|
+
lastUpdated: 1782999583000,
|
|
113
113
|
docs: "https://maas.egineering/vue-equipment/plugins/MagicTray/",
|
|
114
114
|
description: "MagicTray is a flexible"
|
|
115
115
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function useMagicEmitter(): {
|
|
2
2
|
on: {
|
|
3
|
-
<Key extends "progress" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents |
|
|
3
|
+
<Key extends "progress" | "acceptAll" | "acceptSelected" | "rejectAll" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents | keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>(type: Key, handler: import("mitt").Handler<({
|
|
4
4
|
beforeEnter: string | {
|
|
5
5
|
id: string;
|
|
6
6
|
viewId: string;
|
|
@@ -670,7 +670,7 @@ export declare function useMagicEmitter(): {
|
|
|
670
670
|
} & Omit<object, keyof import("../../../MagicTray/src/types/index.js").TrayEvents>, keyof import("../../../MagicToast/src/types/index.js").ToastEvents>, "collision">, keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents>, keyof import("../../../MagicMenu/src/types/index.js").MenuEvents>, keyof import("../../../MagicModal/src/types/index.js").ModalEvents>, keyof import("../../../MagicDrawer/src/types/index.js").DrawerEvents>, keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents>, keyof import("../../../MagicCookie/src/types/index.js").CookieEvents>, keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>>): void;
|
|
671
671
|
};
|
|
672
672
|
off: {
|
|
673
|
-
<Key extends "progress" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents |
|
|
673
|
+
<Key extends "progress" | "acceptAll" | "acceptSelected" | "rejectAll" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents | keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>(type: Key, handler?: import("mitt").Handler<({
|
|
674
674
|
beforeEnter: string | {
|
|
675
675
|
id: string;
|
|
676
676
|
viewId: string;
|
|
@@ -1340,7 +1340,7 @@ export declare function useMagicEmitter(): {
|
|
|
1340
1340
|
} & Omit<object, keyof import("../../../MagicTray/src/types/index.js").TrayEvents>, keyof import("../../../MagicToast/src/types/index.js").ToastEvents>, "collision">, keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents>, keyof import("../../../MagicMenu/src/types/index.js").MenuEvents>, keyof import("../../../MagicModal/src/types/index.js").ModalEvents>, keyof import("../../../MagicDrawer/src/types/index.js").DrawerEvents>, keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents>, keyof import("../../../MagicCookie/src/types/index.js").CookieEvents>, keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>>): void;
|
|
1341
1341
|
};
|
|
1342
1342
|
emit: {
|
|
1343
|
-
<Key extends "progress" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents |
|
|
1343
|
+
<Key extends "progress" | "acceptAll" | "acceptSelected" | "rejectAll" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents | keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>(type: Key, event: ({
|
|
1344
1344
|
beforeEnter: string | {
|
|
1345
1345
|
id: string;
|
|
1346
1346
|
viewId: string;
|
|
@@ -1674,7 +1674,7 @@ export declare function useMagicEmitter(): {
|
|
|
1674
1674
|
} & import("../../../MagicTray/index.js").TraySidePayload;
|
|
1675
1675
|
willSnapTo: import("../../../MagicTray/index.js").TrayWillSnapToPayload;
|
|
1676
1676
|
} & Omit<object, keyof import("../../../MagicTray/src/types/index.js").TrayEvents>, keyof import("../../../MagicToast/src/types/index.js").ToastEvents>, "collision">, keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents>, keyof import("../../../MagicMenu/src/types/index.js").MenuEvents>, keyof import("../../../MagicModal/src/types/index.js").ModalEvents>, keyof import("../../../MagicDrawer/src/types/index.js").DrawerEvents>, keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents>, keyof import("../../../MagicCookie/src/types/index.js").CookieEvents>, keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>)[Key]): void;
|
|
1677
|
-
<Key extends "progress" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents |
|
|
1677
|
+
<Key extends "progress" | "acceptAll" | "acceptSelected" | "rejectAll" | "staticClick" | "magnet" | "willSnapTo" | "collision" | keyof import("../../../MagicPlayer/src/types/index.js").PlayerEvents | keyof import("../../../MagicDraggable/src/types/index.js").DraggableEvents | keyof import("../../../MagicAccordion/src/types/index.js").AccordionEvents>(type: undefined extends ({
|
|
1678
1678
|
beforeEnter: string | {
|
|
1679
1679
|
id: string;
|
|
1680
1680
|
viewId: string;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
:data-id="id"
|
|
5
5
|
:data-expanded="state.expanded"
|
|
6
6
|
:data-dragging="view?.dragging"
|
|
7
|
-
:data-draggable="
|
|
7
|
+
:data-draggable="draggable"
|
|
8
8
|
:data-position="state.options.position"
|
|
9
9
|
:data-debug="state.options.debug"
|
|
10
10
|
:style="{
|
|
@@ -60,7 +60,7 @@ const offset = computed(() => {
|
|
|
60
60
|
const mapped = state.views.slice(index + 1).reduce((acc, view2) => acc + (view2.dimensions?.height ?? 0), 0);
|
|
61
61
|
return `${mapped}px`;
|
|
62
62
|
});
|
|
63
|
-
const { style, onPointerdown, onClick } = useToastDrag({
|
|
63
|
+
const { style, onPointerdown, onClick, draggable } = useToastDrag({
|
|
64
64
|
view: view.value,
|
|
65
65
|
instanceId
|
|
66
66
|
});
|
|
@@ -16,7 +16,23 @@ export function useToastDrag(args) {
|
|
|
16
16
|
const { initializeState } = useToastState(instanceId);
|
|
17
17
|
const state = initializeState();
|
|
18
18
|
const { options } = toRefs(state);
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
threshold,
|
|
21
|
+
animation,
|
|
22
|
+
position: anchorPosition,
|
|
23
|
+
scrollLock,
|
|
24
|
+
draggable: defaultDraggable,
|
|
25
|
+
drag
|
|
26
|
+
} = options.value;
|
|
27
|
+
const isDraggable = computed(() => view.draggable ?? defaultDraggable);
|
|
28
|
+
const directions = drag.direction === "auto" ? [] : [].concat(drag.direction);
|
|
29
|
+
const allowLeft = directions.includes("left");
|
|
30
|
+
const allowRight = directions.includes("right");
|
|
31
|
+
const allowUp = directions.includes("up");
|
|
32
|
+
const allowDown = directions.includes("down");
|
|
33
|
+
const isHorizontalOverride = allowLeft || allowRight;
|
|
34
|
+
const isVerticalOverride = allowUp || allowDown;
|
|
35
|
+
const position = isHorizontalOverride ? "left" : isVerticalOverride ? "top" : anchorPosition;
|
|
20
36
|
const { deleteView } = useToastView(instanceId);
|
|
21
37
|
const {
|
|
22
38
|
dragStart,
|
|
@@ -48,9 +64,15 @@ export function useToastDrag(args) {
|
|
|
48
64
|
});
|
|
49
65
|
return hasDraggedX || hasDraggedY;
|
|
50
66
|
});
|
|
51
|
-
const style = computed(
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
const style = computed(() => {
|
|
68
|
+
const transform = `translate(${draggedX.value}px, ${draggedY.value}px)`;
|
|
69
|
+
const isHorizontal = position === "left" || position === "right";
|
|
70
|
+
const dragged = isHorizontal ? draggedX.value : draggedY.value;
|
|
71
|
+
const distance = Math.abs(dragged);
|
|
72
|
+
const fadeDistance = toValue(threshold).distance * 4;
|
|
73
|
+
const opacity = 1 - Math.min(distance / fadeDistance, 1);
|
|
74
|
+
return `transform: ${transform}; opacity: ${opacity}`;
|
|
75
|
+
});
|
|
54
76
|
const emitter = useMagicEmitter();
|
|
55
77
|
const { lockScroll, unlockScroll } = useToastScrollLock();
|
|
56
78
|
function interpolateDragged(args2) {
|
|
@@ -146,38 +168,32 @@ export function useToastDrag(args) {
|
|
|
146
168
|
}
|
|
147
169
|
}
|
|
148
170
|
function setDragged({ x, y }) {
|
|
149
|
-
|
|
171
|
+
if (isHorizontalOverride) {
|
|
172
|
+
const raw = x - originX.value;
|
|
173
|
+
draggedX.value = allowLeft && allowRight ? raw : allowLeft ? Math.min(raw, 0) : Math.max(raw, 0);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (isVerticalOverride) {
|
|
177
|
+
const raw = y - originY.value;
|
|
178
|
+
draggedY.value = allowUp && allowDown ? raw : allowUp ? Math.min(raw, 0) : Math.max(raw, 0);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
switch (anchorPosition) {
|
|
150
182
|
case "top":
|
|
151
|
-
const newDraggedTC = Math.min(y - originY.value, 0);
|
|
152
|
-
draggedY.value = newDraggedTC;
|
|
153
|
-
break;
|
|
154
183
|
case "top-left":
|
|
155
|
-
const newDraggedTL = Math.min(y - originY.value, 0);
|
|
156
|
-
draggedY.value = newDraggedTL;
|
|
157
|
-
break;
|
|
158
184
|
case "top-right":
|
|
159
|
-
|
|
160
|
-
draggedY.value = newDraggedTR;
|
|
185
|
+
draggedY.value = Math.min(y - originY.value, 0);
|
|
161
186
|
break;
|
|
162
187
|
case "bottom":
|
|
163
|
-
const newDraggedBC = Math.max(y - originY.value, 0);
|
|
164
|
-
draggedY.value = newDraggedBC;
|
|
165
|
-
break;
|
|
166
188
|
case "bottom-left":
|
|
167
|
-
const newDraggedBL = Math.max(y - originY.value, 0);
|
|
168
|
-
draggedY.value = newDraggedBL;
|
|
169
|
-
break;
|
|
170
189
|
case "bottom-right":
|
|
171
|
-
|
|
172
|
-
draggedY.value = newDraggedBR;
|
|
190
|
+
draggedY.value = Math.max(y - originY.value, 0);
|
|
173
191
|
break;
|
|
174
192
|
case "left":
|
|
175
|
-
|
|
176
|
-
draggedX.value = newDraggedCL;
|
|
193
|
+
draggedX.value = Math.min(x - originX.value, 0);
|
|
177
194
|
break;
|
|
178
195
|
case "right":
|
|
179
|
-
|
|
180
|
-
draggedX.value = newDraggedCR;
|
|
196
|
+
draggedX.value = Math.max(x - originX.value, 0);
|
|
181
197
|
break;
|
|
182
198
|
}
|
|
183
199
|
}
|
|
@@ -262,7 +278,7 @@ export function useToastDrag(args) {
|
|
|
262
278
|
cancelTouchcancel?.();
|
|
263
279
|
}
|
|
264
280
|
function onPointerdown(e) {
|
|
265
|
-
if (!
|
|
281
|
+
if (!isDraggable.value) {
|
|
266
282
|
return;
|
|
267
283
|
}
|
|
268
284
|
const scrollLockValue = toValue(scrollLock);
|
|
@@ -308,7 +324,7 @@ export function useToastDrag(args) {
|
|
|
308
324
|
e.preventDefault();
|
|
309
325
|
return;
|
|
310
326
|
}
|
|
311
|
-
if (
|
|
327
|
+
if (anchorPosition === "left" || anchorPosition === "right") {
|
|
312
328
|
return;
|
|
313
329
|
}
|
|
314
330
|
if (state.options.layout?.expand === "click") {
|
|
@@ -321,6 +337,7 @@ export function useToastDrag(args) {
|
|
|
321
337
|
return {
|
|
322
338
|
onPointerdown,
|
|
323
339
|
onClick,
|
|
324
|
-
style
|
|
340
|
+
style,
|
|
341
|
+
draggable: isDraggable
|
|
325
342
|
};
|
|
326
343
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MaybeRef } from 'vue';
|
|
2
2
|
import { type ToastView } from '../../types/index.js';
|
|
3
|
-
export type AddViewArgs = Pick<ToastView, 'component' | 'props' | 'slots'> & {
|
|
3
|
+
export type AddViewArgs = Pick<ToastView, 'component' | 'props' | 'slots' | 'draggable'> & {
|
|
4
4
|
id?: string;
|
|
5
5
|
};
|
|
6
6
|
type InitializeViewArgs = AddViewArgs;
|
|
@@ -8,11 +8,12 @@ export function useToastView(instanceId) {
|
|
|
8
8
|
return Math.random().toString(36).slice(2, 11);
|
|
9
9
|
}
|
|
10
10
|
function createView(args) {
|
|
11
|
-
const { id = uuid(), props, slots, component } = args;
|
|
11
|
+
const { id = uuid(), props, slots, component, draggable } = args;
|
|
12
12
|
const view = {
|
|
13
13
|
component: markRaw(component),
|
|
14
14
|
props,
|
|
15
15
|
slots,
|
|
16
|
+
draggable,
|
|
16
17
|
id,
|
|
17
18
|
dragStart: void 0,
|
|
18
19
|
dragging: false,
|
|
@@ -42,6 +43,7 @@ export function useToastView(instanceId) {
|
|
|
42
43
|
}
|
|
43
44
|
function deleteView(id) {
|
|
44
45
|
state.views = state.views?.filter((view) => view.id !== id);
|
|
46
|
+
state.hiddenViews = state.hiddenViews?.filter((view) => view.id !== id);
|
|
45
47
|
}
|
|
46
48
|
function getView(id) {
|
|
47
49
|
return state.views?.find((view) => view.id === id);
|
|
@@ -5,14 +5,18 @@ export interface AddArgs {
|
|
|
5
5
|
props?: ToastView['props'];
|
|
6
6
|
slots?: ToastView['slots'];
|
|
7
7
|
duration?: number;
|
|
8
|
+
draggable?: boolean;
|
|
8
9
|
id?: string;
|
|
9
10
|
}
|
|
10
11
|
export declare function useMagicToast(id: MaybeRef<string>): {
|
|
11
12
|
toasts: import("vue").ComputedRef<ToastView[]>;
|
|
12
13
|
count: import("vue").ComputedRef<number>;
|
|
14
|
+
hiddenCount: import("vue").ComputedRef<number>;
|
|
13
15
|
add: (args: AddArgs) => string;
|
|
14
16
|
remove: (id: string) => void;
|
|
15
17
|
clear: (transition?: string) => Promise<void>;
|
|
18
|
+
hide: (transition?: string) => Promise<void>;
|
|
19
|
+
show: (transition?: string) => Promise<void>;
|
|
16
20
|
expand: () => void;
|
|
17
21
|
collapse: () => void;
|
|
18
22
|
};
|
|
@@ -8,9 +8,17 @@ export function useMagicToast(id) {
|
|
|
8
8
|
const { initializeView, deleteView } = useToastView(id);
|
|
9
9
|
const toasts = computed(() => state.views);
|
|
10
10
|
const count = computed(() => toasts.value?.length);
|
|
11
|
+
const hiddenCount = computed(() => state.hiddenViews?.length);
|
|
11
12
|
function add(args) {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if (state.hiddenViews.length > 0) {
|
|
14
|
+
state.views = state.hiddenViews;
|
|
15
|
+
state.hiddenViews = [];
|
|
16
|
+
state.views.forEach((view2) => {
|
|
17
|
+
view2.timeout?.play();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const { id: id2, component, props, slots, duration, draggable } = args;
|
|
21
|
+
const view = initializeView({ id: id2, component, props, slots, draggable });
|
|
14
22
|
const mappedDuration = duration ?? state.options.duration;
|
|
15
23
|
if (mappedDuration > 0) {
|
|
16
24
|
view.timeout = useToastTimeout(() => deleteView(view.id), {
|
|
@@ -27,7 +35,36 @@ export function useMagicToast(id) {
|
|
|
27
35
|
const lastTransition = state.options.transition;
|
|
28
36
|
state.options.transition = transition ?? "";
|
|
29
37
|
state.views = [];
|
|
38
|
+
state.hiddenViews = [];
|
|
39
|
+
await nextTick();
|
|
40
|
+
state.options.transition = lastTransition;
|
|
41
|
+
}
|
|
42
|
+
async function hide(transition) {
|
|
43
|
+
if (state.views.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const lastTransition = state.options.transition;
|
|
47
|
+
state.options.transition = transition ?? "";
|
|
48
|
+
state.views.forEach((view) => {
|
|
49
|
+
view.timeout?.pause();
|
|
50
|
+
});
|
|
51
|
+
state.hiddenViews = state.views;
|
|
52
|
+
state.views = [];
|
|
53
|
+
await nextTick();
|
|
54
|
+
state.options.transition = lastTransition;
|
|
55
|
+
}
|
|
56
|
+
async function show(transition) {
|
|
57
|
+
if (state.hiddenViews.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const lastTransition = state.options.transition;
|
|
61
|
+
state.options.transition = transition ?? "";
|
|
62
|
+
state.views = state.hiddenViews;
|
|
63
|
+
state.hiddenViews = [];
|
|
30
64
|
await nextTick();
|
|
65
|
+
state.views.forEach((view) => {
|
|
66
|
+
view.timeout?.play();
|
|
67
|
+
});
|
|
31
68
|
state.options.transition = lastTransition;
|
|
32
69
|
}
|
|
33
70
|
function expand() {
|
|
@@ -39,9 +76,12 @@ export function useMagicToast(id) {
|
|
|
39
76
|
return {
|
|
40
77
|
toasts,
|
|
41
78
|
count,
|
|
79
|
+
hiddenCount,
|
|
42
80
|
add,
|
|
43
81
|
remove,
|
|
44
82
|
clear,
|
|
83
|
+
hide,
|
|
84
|
+
show,
|
|
45
85
|
expand,
|
|
46
86
|
collapse
|
|
47
87
|
};
|
|
@@ -2,11 +2,13 @@ import type { MaybeRef, Slots } from 'vue';
|
|
|
2
2
|
import type { RequireAllNested } from '@maas/vue-equipment/utils';
|
|
3
3
|
import type { UseToastTimeout } from '../composables/private/useToastTimeout.js';
|
|
4
4
|
type Position = 'top-left' | 'top' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right';
|
|
5
|
+
export type DragDirection = 'left' | 'right' | 'up' | 'down';
|
|
5
6
|
export interface ToastView {
|
|
6
7
|
id: string;
|
|
7
8
|
component: object;
|
|
8
9
|
props?: MaybeRef<Record<string, unknown>>;
|
|
9
10
|
slots?: Slots;
|
|
11
|
+
draggable?: boolean;
|
|
10
12
|
dimensions?: {
|
|
11
13
|
height: number;
|
|
12
14
|
padding: {
|
|
@@ -32,6 +34,7 @@ export interface ToastState {
|
|
|
32
34
|
id: string;
|
|
33
35
|
refCount: number;
|
|
34
36
|
views: ToastView[];
|
|
37
|
+
hiddenViews: ToastView[];
|
|
35
38
|
expanded: boolean;
|
|
36
39
|
animating: boolean;
|
|
37
40
|
options: RequiredMagicToastOptions;
|
|
@@ -57,6 +60,9 @@ export interface MagicToastOptions {
|
|
|
57
60
|
position?: Position;
|
|
58
61
|
duration?: number;
|
|
59
62
|
draggable?: boolean;
|
|
63
|
+
drag?: {
|
|
64
|
+
direction?: 'auto' | DragDirection | DragDirection[];
|
|
65
|
+
};
|
|
60
66
|
scrollLock?: boolean | {
|
|
61
67
|
padding: boolean;
|
|
62
68
|
};
|