@maas/vue-equipment 0.16.8 → 0.17.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,5 +1,5 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment/nuxt",
3
3
  "configKey": "vueEquipment",
4
- "version": "0.16.7"
4
+ "version": "0.16.9"
5
5
  }
@@ -97,7 +97,7 @@ import '@maas/vue-equipment/utils/css/animations/slide-btt-out.css'
97
97
 
98
98
  // Prevent deep merge of certain options
99
99
  const customDefu = createDefu((obj, key, value) => {
100
- if (key === 'keys' || key === 'snapPoints') {
100
+ if (key === 'keys' || key === 'points') {
101
101
  obj[key] = value
102
102
  return true
103
103
  }
@@ -126,7 +126,7 @@ const mappedOptions: typeof defaultOptions = customDefu(
126
126
  )
127
127
 
128
128
  const overshoot = ref(0)
129
- const { position, threshold, snapPoints, snapPoint, canClose } = mappedOptions
129
+ const { position, threshold, snap, canClose } = mappedOptions
130
130
 
131
131
  const {
132
132
  isActive,
@@ -148,8 +148,7 @@ const { onPointerdown, dragging, style } = useDrawerDrag({
148
148
  position,
149
149
  threshold,
150
150
  overshoot,
151
- snapPoints,
152
- snapPoint,
151
+ snap,
153
152
  canClose,
154
153
  close,
155
154
  })
@@ -290,5 +289,5 @@ onBeforeUnmount(() => {
290
289
  </script>
291
290
 
292
291
  <style>
293
- :root{--magic-drawer-height:75svh;--magic-drawer-z-index:999;--magic-drawer-justify-content:center;--magic-drawer-align-items:flex-end;--magic-drawer-backdrop-color:rgba(0,0,0,.5);--magic-drawer-backdrop-filter:unset;--magic-drawer-content-overflow-x:hidden;--magic-drawer-content-overflow-y:auto;--magic-drawer-handle-wrapper-height:2rem;--magic-drawer-handle-width:3rem;--magic-drawer-handle-height:0.375rem;--magic-drawer-handle-color:#d4d4d8;--magic-drawer-handle-border-radius:0.25rem;--magic-drawer-enter-animation:slide-btt-in 300ms ease;--magic-drawer-leave-animation:slide-btt-out 300ms ease;--magic-drawer-drag-overshoot:4rem;--magic-drawer-drag-overshoot-x:0;--magic-drawer-drag-overshoot-y:0}.magic-drawer{align-items:var(--magic-drawer-align-items);background:transparent;border:none;color:inherit;display:flex;height:100%;inset:0;justify-content:var(--magic-drawer-justify-content);padding:0;pointer-events:none;position:fixed;width:100%;z-index:var(--magic-drawer-z-index)}.magic-drawer.-bottom{--magic-drawer-drag-overshoot-y:var(--magic-drawer-drag-overshoot)}.magic-drawer.-top{--magic-drawer-enter-animation:slide-ttb-in 300ms ease;--magic-drawer-leave-animation:slide-ttb-out 300ms ease;--magic-drawer-align-items:flex-start;--magic-drawer-drag-overshoot-y:calc(var(--magic-drawer-drag-overshoot)*-1)}.magic-drawer.-right{--magic-drawer-enter-animation:slide-rtl-in 300ms ease;--magic-drawer-leave-animation:slide-rtl-out 300ms ease;--magic-drawer-align-items:center;--magic-drawer-justify-content:flex-end;--magic-drawer-drag-overshoot-x:var(--magic-drawer-drag-overshoot)}.magic-drawer.-left{--magic-drawer-enter-animation:slide-ltr-in 300ms ease;--magic-drawer-leave-animation:slide-ltr-out 300ms ease;--magic-drawer-align-items:center;--magic-drawer-justify-content:flex-start;--magic-drawer-drag-overshoot-x:calc(var(--magic-drawer-drag-overshoot)*-1)}.magic-drawer__wrapper{height:calc(var(--magic-drawer-height) + var(--magic-drawer-drag-overshoot));pointer-events:none;transform:translate(var(--magic-drawer-drag-overshoot-x),var(--magic-drawer-drag-overshoot-y));width:100%}.magic-drawer__content{height:100%;max-height:100%;position:relative;width:100%}.magic-drawer__drag{-webkit-overflow-scrolling:touch;align-items:var(--magic-drawer-align-items);cursor:grab;display:flex;height:100%;justify-content:var(--magic-drawer-justify-content);overflow-x:var(--magic-drawer-content-overflow-x);overflow-y:var(--magic-drawer-content-overflow-y);pointer-events:auto;position:relative;scroll-behavior:smooth;width:100%}.magic-drawer.-dragging .magic-drawer__drag{cursor:grabbing}.magic-drawer__backdrop{-webkit-backdrop-filter:var(--magic-drawer-backdrop-filter);backdrop-filter:var(--magic-drawer-backdrop-filter);background-color:var(--magic-drawer-backdrop-color);bottom:0;height:100%;left:0;pointer-events:auto;position:fixed;right:0;top:0;width:100%;z-index:-1}.magic-drawer--content-enter-active{animation:var(--magic-drawer-enter-animation)}.magic-drawer--content-leave-active{animation:var(--magic-drawer-leave-animation)}.magic-drawer--backdrop-enter-active{animation:fade-in .3s ease}.magic-drawer--backdrop-leave-active{animation:fade-out .3s ease}
292
+ :root{--magic-drawer-height:75svh;--magic-drawer-width:100%;--magic-drawer-z-index:999;--magic-drawer-justify-content:center;--magic-drawer-align-items:flex-end;--magic-drawer-backdrop-color:rgba(0,0,0,.5);--magic-drawer-backdrop-filter:unset;--magic-drawer-content-overflow-x:hidden;--magic-drawer-content-overflow-y:hidden;--magic-drawer-handle-wrapper-height:2rem;--magic-drawer-handle-width:3rem;--magic-drawer-handle-height:0.375rem;--magic-drawer-handle-color:#d4d4d8;--magic-drawer-handle-border-radius:0.25rem;--magic-drawer-enter-animation:slide-btt-in 300ms ease;--magic-drawer-leave-animation:slide-btt-out 300ms ease;--magic-drawer-drag-overshoot:4rem;--magic-drawer-drag-overshoot-x:0rem;--magic-drawer-drag-overshoot-y:0rem;--magic-drawer-padding:0rem}.magic-drawer{align-items:var(--magic-drawer-align-items);background:transparent;border:none;color:inherit;display:flex;height:100%;inset:0;justify-content:var(--magic-drawer-justify-content);padding:0;pointer-events:none;position:fixed;width:100%;z-index:var(--magic-drawer-z-index)}.magic-drawer.-bottom{--magic-drawer-drag-overshoot-y:var(--magic-drawer-drag-overshoot);--magic-drawer-padding:0 0 var(--magic-drawer-drag-overshoot-y) 0}.magic-drawer.-top{--magic-drawer-enter-animation:slide-ttb-in 300ms ease;--magic-drawer-leave-animation:slide-ttb-out 300ms ease;--magic-drawer-align-items:flex-start;--magic-drawer-drag-overshoot-y:calc(var(--magic-drawer-drag-overshoot)*-1);--magic-drawer-padding:var(--magic-drawer-drag-overshoot-y) 0 0 0}.magic-drawer.-right{--magic-drawer-enter-animation:slide-rtl-in 300ms ease;--magic-drawer-leave-animation:slide-rtl-out 300ms ease;--magic-drawer-align-items:center;--magic-drawer-justify-content:flex-end;--magic-drawer-drag-overshoot-x:var(--magic-drawer-drag-overshoot);--magic-drawer-padding:0 var(--magic-drawer-drag-overshoot-x) 0 0}.magic-drawer.-left{--magic-drawer-enter-animation:slide-ltr-in 300ms ease;--magic-drawer-leave-animation:slide-ltr-out 300ms ease;--magic-drawer-align-items:center;--magic-drawer-justify-content:flex-start;--magic-drawer-drag-overshoot-x:calc(var(--magic-drawer-drag-overshoot)*-1);--magic-drawer-padding:0 0 0 var(--magic-drawer-drag-overshoot-x)}.magic-drawer__wrapper{height:calc(var(--magic-drawer-height) + var(--magic-drawer-drag-overshoot-y));pointer-events:none;transform:translate(var(--magic-drawer-drag-overshoot-x),var(--magic-drawer-drag-overshoot-y));width:calc(var(--magic-drawer-width) + var(--magic-drawer-drag-overshoot-x))}.magic-drawer__content{height:100%;max-height:100%;position:relative;width:100%}.magic-drawer__drag{-webkit-overflow-scrolling:touch;align-items:var(--magic-drawer-align-items);cursor:grab;display:flex;height:100%;justify-content:var(--magic-drawer-justify-content);overflow-x:var(--magic-drawer-content-overflow-x);overflow-y:var(--magic-drawer-content-overflow-y);pointer-events:auto;position:relative;scroll-behavior:smooth;width:100%}.magic-drawer.-dragging .magic-drawer__drag{cursor:grabbing}.magic-drawer__drag>*{padding:var(--magic-drawer-padding)}.magic-drawer__backdrop{-webkit-backdrop-filter:var(--magic-drawer-backdrop-filter);backdrop-filter:var(--magic-drawer-backdrop-filter);background-color:var(--magic-drawer-backdrop-color);bottom:0;height:100%;left:0;pointer-events:auto;position:fixed;right:0;top:0;width:100%;z-index:-1}.magic-drawer--content-enter-active{animation:var(--magic-drawer-enter-animation)}.magic-drawer--content-leave-active{animation:var(--magic-drawer-leave-animation)}.magic-drawer--backdrop-enter-active{animation:fade-in .3s ease}.magic-drawer--backdrop-leave-active{animation:fade-out .3s ease}
294
293
  </style>
@@ -1,23 +1,22 @@
1
- import { type MaybeRef } from 'vue';
1
+ import { type Ref, type MaybeRef } from 'vue';
2
2
  import { type DefaultOptions } from '../../utils/defaultOptions.js';
3
3
  type UseDrawerDragArgs = {
4
4
  id: MaybeRef<string>;
5
5
  isActive: MaybeRef<boolean>;
6
- elRef: MaybeRef<HTMLDivElement | undefined>;
7
- wrapperRef: MaybeRef<HTMLDivElement | undefined>;
6
+ elRef: Ref<HTMLDivElement | undefined>;
7
+ wrapperRef: Ref<HTMLDivElement | undefined>;
8
8
  position: MaybeRef<DefaultOptions['position']>;
9
9
  threshold: MaybeRef<DefaultOptions['threshold']>;
10
- snapPoints: MaybeRef<DefaultOptions['snapPoints']>;
11
- snapPoint: MaybeRef<DefaultOptions['snapPoint']>;
10
+ snap: MaybeRef<DefaultOptions['snap']>;
12
11
  canClose: MaybeRef<DefaultOptions['canClose']>;
13
12
  overshoot: MaybeRef<number>;
14
13
  close: () => void;
15
14
  };
16
15
  export declare function useDrawerDrag(args: UseDrawerDragArgs): {
17
16
  style: import("vue").ComputedRef<string>;
18
- draggedX: import("vue").Ref<number>;
19
- draggedY: import("vue").Ref<number>;
20
- dragging: import("vue").Ref<boolean>;
17
+ draggedX: Ref<number>;
18
+ draggedY: Ref<number>;
19
+ dragging: Ref<boolean>;
21
20
  onPointerdown: (e: PointerEvent) => void;
22
21
  };
23
22
  export {};
@@ -24,11 +24,10 @@ export function useDrawerDrag(args) {
24
24
  isActive,
25
25
  elRef,
26
26
  wrapperRef,
27
- snapPoints,
28
27
  position,
29
28
  overshoot,
30
29
  threshold,
31
- snapPoint,
30
+ snap,
32
31
  canClose,
33
32
  close
34
33
  } = args;
@@ -46,9 +45,10 @@ export function useDrawerDrag(args) {
46
45
  const relDirectionX = ref("absolute");
47
46
  const absDirectionY = ref(void 0);
48
47
  const absDirectionX = ref(void 0);
49
- const hasSnapPoints = computed(() => toValue(snapPoints).length > 1);
48
+ const hasSnapPoints = computed(() => toValue(snap)?.points.length > 1);
50
49
  const elRect = ref(void 0);
51
50
  const wrapperRect = ref(void 0);
51
+ const duration = computed(() => toValue(snap)?.duration);
52
52
  const draggedX = ref(0);
53
53
  const draggedY = ref(0);
54
54
  const style = computed(
@@ -67,7 +67,7 @@ export function useDrawerDrag(args) {
67
67
  } = useDrawerSnap({
68
68
  id,
69
69
  wrapperRect,
70
- snapPoints,
70
+ snap,
71
71
  canClose,
72
72
  position,
73
73
  overshoot,
@@ -301,7 +301,11 @@ export function useDrawerDrag(args) {
301
301
  console.warn("Cannot snap to point when drawer is not open");
302
302
  return;
303
303
  } else {
304
- snapTo({ snapPoint: payload.snapPoint, interpolate: true });
304
+ snapTo({
305
+ snapPoint: payload.snapPoint,
306
+ interpolate: true,
307
+ duration: duration.value
308
+ });
305
309
  }
306
310
  }
307
311
  }
@@ -310,7 +314,10 @@ export function useDrawerDrag(args) {
310
314
  close();
311
315
  } else if (interpolateTo.value || interpolateTo.value === 0) {
312
316
  if (scrollLock && scrollLock.value || canInterpolate(e.target)) {
313
- interpolateDragged(interpolateTo.value);
317
+ interpolateDragged({
318
+ to: interpolateTo.value,
319
+ duration: duration.value
320
+ });
314
321
  }
315
322
  activeSnapPoint.value = snapPointsMap.value[interpolateTo.value];
316
323
  switch (position) {
@@ -327,11 +334,17 @@ export function useDrawerDrag(args) {
327
334
  switch (position) {
328
335
  case "bottom":
329
336
  case "top":
330
- interpolateDragged(snappedY.value);
337
+ interpolateDragged({
338
+ to: snappedY.value,
339
+ duration: duration.value
340
+ });
331
341
  break;
332
342
  case "right":
333
343
  case "left":
334
- interpolateDragged(snappedX.value);
344
+ interpolateDragged({
345
+ to: snappedX.value,
346
+ duration: duration.value
347
+ });
335
348
  break;
336
349
  }
337
350
  }
@@ -379,9 +392,10 @@ export function useDrawerDrag(args) {
379
392
  useDrawerEmitter().on("*", emitterCallback);
380
393
  });
381
394
  watch(
382
- () => [unrefElement(wrapperRef), unrefElement(wrapperRef)],
395
+ () => [unrefElement(elRef), unrefElement(wrapperRef)],
383
396
  async () => {
384
397
  await getSizes();
398
+ const snapPoint = toValue(snap)?.initial;
385
399
  snapTo({ snapPoint, interpolate: false });
386
400
  }
387
401
  );
@@ -1,8 +1,8 @@
1
- import { type MaybeRef } from 'vue';
1
+ import { type Ref, type MaybeRef } from 'vue';
2
2
  import { type DefaultOptions } from '../../utils/defaultOptions.js';
3
3
  import { type SnapPoint } from '../../types.js';
4
4
  interface UseDrawerGuardsArgs {
5
- elRef: MaybeRef<HTMLDivElement | undefined>;
5
+ elRef: Ref<HTMLDivElement | undefined>;
6
6
  absDirectionX: MaybeRef<'with' | 'against' | undefined>;
7
7
  absDirectionY: MaybeRef<'with' | 'against' | undefined>;
8
8
  position: MaybeRef<DefaultOptions['position']>;
@@ -2,13 +2,15 @@ import { computed, toValue } from "vue";
2
2
  import { unrefElement } from "@vueuse/core";
3
3
  export function useDrawerGuards(args) {
4
4
  const { elRef, absDirectionX, absDirectionY, position, activeSnapPoint } = args;
5
- const isHoverSupported = matchMedia("(hover: hover)").matches;
5
+ const hasCursor = computed(() => {
6
+ return typeof window !== "undefined" && matchMedia("(hover: hover)").matches;
7
+ });
6
8
  const canSnap = computed(() => {
7
9
  return toValue(activeSnapPoint) !== 1 && !!toValue(activeSnapPoint);
8
10
  });
9
11
  function canDrag(el) {
10
12
  let element = el;
11
- if (isHoverSupported) {
13
+ if (hasCursor.value) {
12
14
  return true;
13
15
  }
14
16
  if (canSnap.value) {
@@ -27,6 +29,9 @@ export function useDrawerGuards(args) {
27
29
  if (toValue(absDirectionY) === "with") {
28
30
  return false;
29
31
  }
32
+ if (!toValue(absDirectionY)) {
33
+ return false;
34
+ }
30
35
  }
31
36
  break;
32
37
  case "top":
@@ -38,6 +43,9 @@ export function useDrawerGuards(args) {
38
43
  if (toValue(absDirectionY) === "with") {
39
44
  return false;
40
45
  }
46
+ if (!toValue(absDirectionY)) {
47
+ return false;
48
+ }
41
49
  }
42
50
  break;
43
51
  case "right":
@@ -48,6 +56,9 @@ export function useDrawerGuards(args) {
48
56
  if (toValue(absDirectionX) === "with") {
49
57
  return false;
50
58
  }
59
+ if (!toValue(absDirectionX)) {
60
+ return false;
61
+ }
51
62
  }
52
63
  break;
53
64
  case "left":
@@ -59,6 +70,9 @@ export function useDrawerGuards(args) {
59
70
  if (toValue(absDirectionX) === "with") {
60
71
  return false;
61
72
  }
73
+ if (!toValue(absDirectionX)) {
74
+ return false;
75
+ }
62
76
  }
63
77
  break;
64
78
  }
@@ -68,7 +82,7 @@ export function useDrawerGuards(args) {
68
82
  }
69
83
  function canInterpolate(el) {
70
84
  let element = el;
71
- if (isHoverSupported) {
85
+ if (hasCursor.value) {
72
86
  return true;
73
87
  }
74
88
  while (element) {
@@ -94,7 +108,7 @@ export function useDrawerGuards(args) {
94
108
  }
95
109
  function lockScroll(el) {
96
110
  let element = el;
97
- if (isHoverSupported) {
111
+ if (hasCursor.value && !canSnap.value) {
98
112
  return void 0;
99
113
  }
100
114
  while (element) {
@@ -5,7 +5,7 @@ import { useDrawerEmitter } from "../useDrawerEmitter.mjs";
5
5
  export function useDrawerSnap(args) {
6
6
  const {
7
7
  id,
8
- snapPoints,
8
+ snap,
9
9
  position,
10
10
  wrapperRect,
11
11
  overshoot,
@@ -16,7 +16,8 @@ export function useDrawerSnap(args) {
16
16
  const mappedSnapPoints = computedWithControl(
17
17
  () => toValue(wrapperRect),
18
18
  () => {
19
- const extended = toValue(canClose) ? [...toValue(snapPoints), 0] : toValue(snapPoints);
19
+ const snapPoints = toValue(snap)?.points;
20
+ const extended = toValue(canClose) ? [...snapPoints, 0] : snapPoints;
20
21
  const mapped = extended.map((snapPoint) => {
21
22
  return mapSnapPoint(snapPoint);
22
23
  });
@@ -28,10 +29,12 @@ export function useDrawerSnap(args) {
28
29
  );
29
30
  const snapPointsMap = computedWithControl(
30
31
  () => {
31
- return { ...toValue(snapPoints) };
32
+ const snapPoints = toValue(snap)?.points;
33
+ return { ...snapPoints };
32
34
  },
33
35
  () => {
34
- const extended = toValue(canClose) ? [...toValue(snapPoints), 0] : toValue(snapPoints);
36
+ const snapPoints = toValue(snap)?.points;
37
+ const extended = toValue(canClose) ? [...snapPoints, 0] : snapPoints;
35
38
  const mapped = extended.reduce((acc, current) => {
36
39
  const key = mapSnapPoint(current);
37
40
  if (key || key === 0) {
@@ -145,12 +148,12 @@ export function useDrawerSnap(args) {
145
148
  }
146
149
  }
147
150
  async function snapTo(args2) {
148
- const { snapPoint, interpolate: interpolate2 } = args2;
151
+ const { snapPoint, interpolate: interpolate2, duration = 200 } = args2;
149
152
  await nextTick();
150
153
  switch (position) {
151
154
  case "top":
152
155
  case "bottom":
153
- const mappedSnapPointY = mapSnapPoint(toValue(snapPoint));
156
+ const mappedSnapPointY = mapSnapPoint(snapPoint);
154
157
  if (!mappedSnapPointY && mappedSnapPointY !== 0)
155
158
  return;
156
159
  const closestY = await findClosestSnapPoint({
@@ -158,7 +161,7 @@ export function useDrawerSnap(args) {
158
161
  draggedY: mappedSnapPointY
159
162
  }) || 0;
160
163
  if (interpolate2) {
161
- await interpolateDragged(closestY);
164
+ await interpolateDragged({ to: closestY, duration });
162
165
  } else {
163
166
  draggedY.value = closestY;
164
167
  }
@@ -175,7 +178,7 @@ export function useDrawerSnap(args) {
175
178
  draggedY
176
179
  }) || 0;
177
180
  if (interpolate2) {
178
- await interpolateDragged(closestX);
181
+ await interpolateDragged({ to: closestX, duration });
179
182
  } else {
180
183
  draggedX.value = closestX;
181
184
  snappedX.value = closestX;
@@ -185,19 +188,20 @@ export function useDrawerSnap(args) {
185
188
  break;
186
189
  }
187
190
  }
188
- async function interpolateDragged(target) {
189
- const snapPoint = snapPointsMap.value[target];
191
+ async function interpolateDragged(args2) {
192
+ const { to, duration = 200 } = args2;
193
+ const snapPoint = snapPointsMap.value[to];
190
194
  useDrawerEmitter().emit("beforeSnap", { id: toValue(id), snapPoint });
191
195
  switch (position) {
192
196
  case "bottom":
193
197
  case "top":
194
198
  interpolate({
195
199
  from: draggedY.value,
196
- to: target,
197
- duration: 300,
200
+ to,
201
+ duration,
198
202
  callback: (value) => {
199
203
  draggedY.value = value;
200
- if (draggedY.value === target) {
204
+ if (draggedY.value === to) {
201
205
  useDrawerEmitter().emit("afterSnap", {
202
206
  id: toValue(id),
203
207
  snapPoint
@@ -210,11 +214,11 @@ export function useDrawerSnap(args) {
210
214
  case "left":
211
215
  interpolate({
212
216
  from: draggedX.value,
213
- to: target,
214
- duration: 300,
217
+ to,
218
+ duration,
215
219
  callback: (value) => {
216
220
  draggedX.value = value;
217
- if (draggedX.value === target) {
221
+ if (draggedX.value === to) {
218
222
  useDrawerEmitter().emit("afterSnap", {
219
223
  id: toValue(id),
220
224
  snapPoint
@@ -23,8 +23,11 @@ export type DrawerOptions = {
23
23
  open: boolean;
24
24
  animate: boolean;
25
25
  };
26
- snapPoints?: SnapPoint[];
27
- snapPoint?: SnapPoint;
26
+ snap?: {
27
+ points: SnapPoint[];
28
+ duration?: number;
29
+ initial?: SnapPoint;
30
+ };
28
31
  canClose?: boolean;
29
32
  };
30
33
  export type DrawerEvents = {
@@ -22,8 +22,11 @@ const defaultOptions = {
22
22
  open: false,
23
23
  animate: false
24
24
  },
25
- snapPoints: [1],
26
- snapPoint: 1,
25
+ snap: {
26
+ points: [1],
27
+ duration: 200,
28
+ initial: 1
29
+ },
27
30
  canClose: true
28
31
  };
29
32
  export { defaultOptions };
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.16.8",
4
+ "version": "0.17.0",
5
5
  "author": "Robin Scholz <https://github.com/robinscholz>, Christoph Jeworutzki <https://github.com/ChristophJeworutzki>",
6
6
  "devDependencies": {
7
7
  "@antfu/ni": "^0.21.12",