@maas/vue-equipment 0.35.1 → 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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment/nuxt",
3
3
  "configKey": "vueEquipment",
4
- "version": "0.35.0",
4
+ "version": "0.35.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
@@ -32,7 +32,7 @@ const functions$1 = [
32
32
  {
33
33
  name: "MagicDraggable",
34
34
  "package": "plugins",
35
- lastUpdated: 1716533739000,
35
+ lastUpdated: 1727253131000,
36
36
  docs: "https://maas.egineering/vue-equipment/plugins/MagicDraggable/",
37
37
  description: "draggable"
38
38
  },
@@ -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 { defineNuxtModule, createResolver, addComponent } from "@nuxt/kit";
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 { initialize, onPointerdown, onClick, style, hasDragged } =
81
- useDraggableDrag({
82
- id: props.id,
83
- elRef,
84
- wrapperRef,
85
- threshold,
86
- snapPoints,
87
- animation,
88
- initial,
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 { useMagicEmitter } from "@maas/vue-equipment/plugins";
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).snap?.duration,
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":
@@ -352,7 +361,6 @@ export function useDrawerDrag(args) {
352
361
  guardedReleasePointerCapture({ event: e, element: elRef.value });
353
362
  }
354
363
  function onPointermove(e) {
355
- console.log("onPointermove", e);
356
364
  if (e.isTrusted && wheeling.value) {
357
365
  return;
358
366
  }
@@ -416,9 +424,7 @@ export function useDrawerDrag(args) {
416
424
  }
417
425
  }
418
426
  onMounted(async () => {
419
- await getSizes();
420
- emitter.on("snapTo", snapToCallback);
421
- emitter.on("afterLeave", afterLeaveCallback);
427
+ await initialize();
422
428
  });
423
429
  watch(
424
430
  () => [unrefElement(elRef), unrefElement(wrapperRef)],
@@ -452,8 +458,7 @@ export function useDrawerDrag(args) {
452
458
  }, 100)();
453
459
  });
454
460
  onBeforeUnmount(() => {
455
- emitter.off("snapTo", snapToCallback);
456
- emitter.off("afterLeave", afterLeaveCallback);
461
+ destroy();
457
462
  });
458
463
  return {
459
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.35.1",
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": {