@maas/vue-equipment 0.35.2 → 0.36.0
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/MagicDraggable/index.d.ts +2 -1
- package/dist/plugins/MagicDraggable/index.mjs +2 -1
- package/dist/plugins/MagicDraggable/nuxt.mjs +10 -1
- package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue +10 -14
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.d.ts +1 -0
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.mjs +26 -2
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableSnap.mjs +1 -1
- package/dist/plugins/MagicDraggable/src/composables/useMagicDraggable.d.ts +6 -0
- package/dist/plugins/MagicDraggable/src/composables/useMagicDraggable.mjs +14 -0
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +11 -5
- package/package.json +1 -1
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from 'vue';
|
|
2
2
|
import MagicDraggable from './src/components/MagicDraggable.vue.js';
|
|
3
|
+
import { useMagicDraggable } from './src/composables/useMagicDraggable.js';
|
|
3
4
|
import type { MagicDraggableOptions } from './src/types/index.js';
|
|
4
5
|
declare const MagicDraggablePlugin: Plugin;
|
|
5
|
-
export { MagicDraggablePlugin, MagicDraggable };
|
|
6
|
+
export { MagicDraggablePlugin, MagicDraggable, useMagicDraggable };
|
|
6
7
|
export type { MagicDraggableOptions };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import MagicDraggable from "./src/components/MagicDraggable.vue";
|
|
2
|
+
import { useMagicDraggable } from "./src/composables/useMagicDraggable.mjs";
|
|
2
3
|
const MagicDraggablePlugin = {
|
|
3
4
|
install: (app) => {
|
|
4
5
|
app.component("MagicDraggable", MagicDraggable);
|
|
5
6
|
}
|
|
6
7
|
};
|
|
7
|
-
export { MagicDraggablePlugin, MagicDraggable };
|
|
8
|
+
export { MagicDraggablePlugin, MagicDraggable, useMagicDraggable };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
defineNuxtModule,
|
|
3
|
+
createResolver,
|
|
4
|
+
addComponent,
|
|
5
|
+
addImports
|
|
6
|
+
} from "@nuxt/kit";
|
|
2
7
|
export default defineNuxtModule({
|
|
3
8
|
meta: {
|
|
4
9
|
name: "@maas/vue-equipment/nuxt/MagicDraggable"
|
|
@@ -10,5 +15,9 @@ export default defineNuxtModule({
|
|
|
10
15
|
name: "MagicDraggable",
|
|
11
16
|
global: true
|
|
12
17
|
});
|
|
18
|
+
addImports({
|
|
19
|
+
from: "@maas/vue-equipment/plugins/MagicDraggable",
|
|
20
|
+
name: "useMagicDraggable"
|
|
21
|
+
});
|
|
13
22
|
}
|
|
14
23
|
});
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
computed,
|
|
35
35
|
toValue,
|
|
36
36
|
onMounted,
|
|
37
|
+
onBeforeUnmount,
|
|
37
38
|
type Component,
|
|
38
39
|
type MaybeRef,
|
|
39
40
|
} from 'vue'
|
|
@@ -77,16 +78,15 @@ const disabled = computed(() => {
|
|
|
77
78
|
|
|
78
79
|
const { snapPoints, animation, initial, threshold } = mappedOptions
|
|
79
80
|
|
|
80
|
-
const {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
81
|
+
const { onPointerdown, onClick, style, hasDragged } = useDraggableDrag({
|
|
82
|
+
id: props.id,
|
|
83
|
+
elRef,
|
|
84
|
+
wrapperRef,
|
|
85
|
+
threshold,
|
|
86
|
+
snapPoints,
|
|
87
|
+
animation,
|
|
88
|
+
initial,
|
|
89
|
+
})
|
|
90
90
|
|
|
91
91
|
// Public functions
|
|
92
92
|
function guardedPointerdown(event: PointerEvent) {
|
|
@@ -100,10 +100,6 @@ function guardedClick(event: PointerEvent) {
|
|
|
100
100
|
onClick(event)
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
onMounted(() => {
|
|
105
|
-
initialize()
|
|
106
|
-
})
|
|
107
103
|
</script>
|
|
108
104
|
|
|
109
105
|
<style>
|
|
@@ -11,6 +11,7 @@ type UseDraggableDragArgs = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare function useDraggableDrag(args: UseDraggableDragArgs): {
|
|
13
13
|
initialize: () => Promise<void>;
|
|
14
|
+
destroy: () => void;
|
|
14
15
|
onPointerdown: (e: PointerEvent) => void;
|
|
15
16
|
onClick: (e: MouseEvent) => void;
|
|
16
17
|
style: import("vue").ComputedRef<string>;
|
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
computed,
|
|
4
4
|
toValue,
|
|
5
5
|
nextTick,
|
|
6
|
-
watch
|
|
6
|
+
watch,
|
|
7
|
+
onBeforeUnmount,
|
|
8
|
+
onMounted
|
|
7
9
|
} from "vue";
|
|
8
10
|
import {
|
|
9
11
|
useEventListener,
|
|
@@ -18,7 +20,9 @@ import {
|
|
|
18
20
|
isIOS,
|
|
19
21
|
isWithinRange
|
|
20
22
|
} from "@maas/vue-equipment/utils";
|
|
21
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
useMagicEmitter
|
|
25
|
+
} from "@maas/vue-equipment/plugins";
|
|
22
26
|
import { useDraggableSnap } from "./useDraggableSnap.mjs";
|
|
23
27
|
import { useDraggableState } from "./useDraggableState.mjs";
|
|
24
28
|
import { useDraggableScrollLock } from "./useDraggableScrollLock.mjs";
|
|
@@ -102,6 +106,15 @@ export function useDraggableDrag(args) {
|
|
|
102
106
|
cancelPointerup?.();
|
|
103
107
|
cancelPointermove?.();
|
|
104
108
|
}
|
|
109
|
+
function snapToCallback(payload) {
|
|
110
|
+
if (payload.id === toValue(id)) {
|
|
111
|
+
snapTo({
|
|
112
|
+
snapPoint: payload.snapPoint,
|
|
113
|
+
interpolate: true,
|
|
114
|
+
duration: payload.duration
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
105
118
|
function detectCollision() {
|
|
106
119
|
const childRect = toValue(elRect);
|
|
107
120
|
const parentRect = toValue(wrapperRect);
|
|
@@ -336,6 +349,7 @@ export function useDraggableDrag(args) {
|
|
|
336
349
|
async function initialize() {
|
|
337
350
|
await getSizes();
|
|
338
351
|
if (elRect.value && wrapperRect.value) {
|
|
352
|
+
emitter.on("snapTo", snapToCallback);
|
|
339
353
|
if (elRect.value.width > wrapperRect.value.width || elRect.value.height > wrapperRect.value.height) {
|
|
340
354
|
console.warn("MagicDraggable is too small for its content");
|
|
341
355
|
return;
|
|
@@ -351,6 +365,12 @@ export function useDraggableDrag(args) {
|
|
|
351
365
|
}
|
|
352
366
|
}
|
|
353
367
|
}
|
|
368
|
+
function destroy() {
|
|
369
|
+
emitter.off("snapTo", snapToCallback);
|
|
370
|
+
}
|
|
371
|
+
onMounted(() => {
|
|
372
|
+
initialize();
|
|
373
|
+
});
|
|
354
374
|
useResizeObserver(wrapperRef, async () => {
|
|
355
375
|
useThrottleFn(async () => {
|
|
356
376
|
await getSizes();
|
|
@@ -375,8 +395,12 @@ export function useDraggableDrag(args) {
|
|
|
375
395
|
onIdle();
|
|
376
396
|
}
|
|
377
397
|
});
|
|
398
|
+
onBeforeUnmount(() => {
|
|
399
|
+
destroy();
|
|
400
|
+
});
|
|
378
401
|
return {
|
|
379
402
|
initialize,
|
|
403
|
+
destroy,
|
|
380
404
|
onPointerdown,
|
|
381
405
|
onClick,
|
|
382
406
|
style,
|
|
@@ -94,7 +94,7 @@ export function useDraggableSnap(args) {
|
|
|
94
94
|
const {
|
|
95
95
|
x,
|
|
96
96
|
y,
|
|
97
|
-
duration = toValue(animation)
|
|
97
|
+
duration = toValue(animation)?.snap?.duration || 300,
|
|
98
98
|
easing = toValue(animation).snap?.easing
|
|
99
99
|
} = args2;
|
|
100
100
|
const snapPoint = snapPointsMap.value[`x${x}y${y}`];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type MaybeRef } from 'vue';
|
|
2
|
+
import type { DraggableSnapPoint } from '../types/index.js';
|
|
3
|
+
export declare function useMagicDraggable(id: MaybeRef<string>): {
|
|
4
|
+
snapTo: (snapPoint: DraggableSnapPoint, duration?: number) => void;
|
|
5
|
+
};
|
|
6
|
+
export type UseMagicDrawerReturn = ReturnType<typeof useMagicDraggable>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { toValue } from "vue";
|
|
2
|
+
import { useMagicEmitter } from "@maas/vue-equipment/plugins";
|
|
3
|
+
export function useMagicDraggable(id) {
|
|
4
|
+
function snapTo(snapPoint, duration) {
|
|
5
|
+
useMagicEmitter().emit("snapTo", {
|
|
6
|
+
id: toValue(id),
|
|
7
|
+
snapPoint,
|
|
8
|
+
duration
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
snapTo
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -285,6 +285,15 @@ export function useDrawerDrag(args) {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
+
async function initialize() {
|
|
289
|
+
await getSizes();
|
|
290
|
+
emitter.on("snapTo", snapToCallback);
|
|
291
|
+
emitter.on("afterLeave", afterLeaveCallback);
|
|
292
|
+
}
|
|
293
|
+
function destroy() {
|
|
294
|
+
emitter.off("snapTo", snapToCallback);
|
|
295
|
+
emitter.off("afterLeave", afterLeaveCallback);
|
|
296
|
+
}
|
|
288
297
|
function onCancel() {
|
|
289
298
|
switch (position) {
|
|
290
299
|
case "bottom":
|
|
@@ -415,9 +424,7 @@ export function useDrawerDrag(args) {
|
|
|
415
424
|
}
|
|
416
425
|
}
|
|
417
426
|
onMounted(async () => {
|
|
418
|
-
await
|
|
419
|
-
emitter.on("snapTo", snapToCallback);
|
|
420
|
-
emitter.on("afterLeave", afterLeaveCallback);
|
|
427
|
+
await initialize();
|
|
421
428
|
});
|
|
422
429
|
watch(
|
|
423
430
|
() => [unrefElement(elRef), unrefElement(wrapperRef)],
|
|
@@ -451,8 +458,7 @@ export function useDrawerDrag(args) {
|
|
|
451
458
|
}, 100)();
|
|
452
459
|
});
|
|
453
460
|
onBeforeUnmount(() => {
|
|
454
|
-
|
|
455
|
-
emitter.off("afterLeave", afterLeaveCallback);
|
|
461
|
+
destroy();
|
|
456
462
|
});
|
|
457
463
|
return {
|
|
458
464
|
onPointerdown,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maas/vue-equipment",
|
|
3
3
|
"description": "A magic collection of Vue composables, plugins, components and directives",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.36.0",
|
|
5
5
|
"author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"devDependencies": {
|