@maas/vue-equipment 0.15.0 → 0.16.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/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +20 -9
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerSnap.d.ts +1 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerSnap.mjs +25 -22
- package/dist/plugins/MagicScroll/src/components/MagicScrollCollision.vue +1 -6
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.d.ts +2 -2
- package/dist/plugins/MagicScroll/src/composables/useCollisionDetect.mjs +9 -7
- package/dist/plugins/MagicScroll/src/types/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/nuxt/module.json
CHANGED
|
@@ -23,8 +23,10 @@ export function useDrawerDrag(args) {
|
|
|
23
23
|
canClose,
|
|
24
24
|
close
|
|
25
25
|
} = args;
|
|
26
|
+
const elRect = ref(void 0);
|
|
27
|
+
const wrapperRect = ref(void 0);
|
|
26
28
|
const { findClosestSnapPoint, mapSnapPoint, drawerHeight, drawerWidth } = useDrawerSnap({
|
|
27
|
-
|
|
29
|
+
wrapperRect,
|
|
28
30
|
snapPoints,
|
|
29
31
|
canClose,
|
|
30
32
|
position,
|
|
@@ -34,7 +36,6 @@ export function useDrawerDrag(args) {
|
|
|
34
36
|
const dragging = ref(false);
|
|
35
37
|
const shouldClose = ref(false);
|
|
36
38
|
const interpolateTo = ref(void 0);
|
|
37
|
-
const elRect = ref(void 0);
|
|
38
39
|
let cancelPointerup = void 0;
|
|
39
40
|
let cancelPointermove = void 0;
|
|
40
41
|
const originX = ref(0);
|
|
@@ -49,8 +50,10 @@ export function useDrawerDrag(args) {
|
|
|
49
50
|
const style = computed(
|
|
50
51
|
() => `transform: translate(${draggedX.value}px, ${draggedY.value}px)`
|
|
51
52
|
);
|
|
52
|
-
function getSizes() {
|
|
53
|
+
async function getSizes() {
|
|
53
54
|
elRect.value = unrefElement(elRef)?.getBoundingClientRect();
|
|
55
|
+
wrapperRect.value = unrefElement(wrapperRef)?.getBoundingClientRect();
|
|
56
|
+
await nextTick();
|
|
54
57
|
}
|
|
55
58
|
async function checkPosition() {
|
|
56
59
|
switch (position) {
|
|
@@ -223,15 +226,23 @@ export function useDrawerDrag(args) {
|
|
|
223
226
|
switch (position) {
|
|
224
227
|
case "top":
|
|
225
228
|
case "bottom":
|
|
229
|
+
const mappedSnapPointY = mapSnapPoint(toValue(snapPoint));
|
|
230
|
+
console.log("toValue(snapPoint):", toValue(snapPoint));
|
|
231
|
+
console.log("mappedSnapPointY:", mappedSnapPointY);
|
|
232
|
+
if (!mappedSnapPointY)
|
|
233
|
+
return;
|
|
226
234
|
draggedY.value = await findClosestSnapPoint({
|
|
227
235
|
draggedX,
|
|
228
|
-
draggedY:
|
|
236
|
+
draggedY: mappedSnapPointY
|
|
229
237
|
}) || 0;
|
|
230
238
|
break;
|
|
231
239
|
case "left":
|
|
232
240
|
case "right":
|
|
241
|
+
const mappedSnapPointX = mapSnapPoint(toValue(snapPoint));
|
|
242
|
+
if (!mappedSnapPointX)
|
|
243
|
+
return;
|
|
233
244
|
draggedX.value = await findClosestSnapPoint({
|
|
234
|
-
draggedX:
|
|
245
|
+
draggedX: mappedSnapPointX,
|
|
235
246
|
draggedY
|
|
236
247
|
}) || 0;
|
|
237
248
|
break;
|
|
@@ -329,14 +340,14 @@ export function useDrawerDrag(args) {
|
|
|
329
340
|
onPointermove(e);
|
|
330
341
|
e.preventDefault();
|
|
331
342
|
}
|
|
332
|
-
onMounted(() => {
|
|
333
|
-
getSizes();
|
|
343
|
+
onMounted(async () => {
|
|
344
|
+
await getSizes();
|
|
334
345
|
useDrawerEmitter().on("*", emitterCallback);
|
|
335
346
|
});
|
|
336
347
|
watch(
|
|
337
348
|
() => [unrefElement(elRef), unrefElement(wrapperRef)],
|
|
338
|
-
() => {
|
|
339
|
-
getSizes();
|
|
349
|
+
async () => {
|
|
350
|
+
await getSizes();
|
|
340
351
|
setInitial();
|
|
341
352
|
}
|
|
342
353
|
);
|
|
@@ -2,7 +2,7 @@ import { type MaybeRef } from 'vue';
|
|
|
2
2
|
import { type DefaultOptions } from '../../utils/defaultOptions.js';
|
|
3
3
|
import { type SnapPoint } from '../../types.js';
|
|
4
4
|
type UseDrawerSnapArgs = {
|
|
5
|
-
|
|
5
|
+
wrapperRect: MaybeRef<DOMRect | undefined>;
|
|
6
6
|
position: MaybeRef<DefaultOptions['position']>;
|
|
7
7
|
snapPoints: MaybeRef<DefaultOptions['snapPoints']>;
|
|
8
8
|
canClose: MaybeRef<DefaultOptions['canClose']>;
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { unrefElement } from "@vueuse/core";
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
3
2
|
import { mapValue } from "@maas/vue-equipment/utils";
|
|
4
3
|
export function useDrawerSnap(args) {
|
|
5
|
-
const { snapPoints, position,
|
|
6
|
-
const wrapperRect = ref(void 0);
|
|
4
|
+
const { snapPoints, position, wrapperRect, overshoot, canClose } = args;
|
|
7
5
|
const mappedSnapPoints = computed(() => {
|
|
8
6
|
const extended = toValue(canClose) ? [...toValue(snapPoints), 0] : toValue(snapPoints);
|
|
9
7
|
const mapped = extended.map((snapPoint) => {
|
|
10
8
|
return mapSnapPoint(snapPoint);
|
|
11
9
|
});
|
|
12
|
-
const filtered = mapped.filter(
|
|
10
|
+
const filtered = mapped.filter(
|
|
11
|
+
(snapPoint) => !!snapPoint || snapPoint === 0
|
|
12
|
+
).sort((a, b) => a - b);
|
|
13
13
|
return filtered;
|
|
14
14
|
});
|
|
15
|
-
const drawerHeight = computed(
|
|
16
|
-
()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
const drawerHeight = computed(() => {
|
|
16
|
+
if (toValue(wrapperRect) === void 0) {
|
|
17
|
+
return 0;
|
|
18
|
+
} else {
|
|
19
|
+
return toValue(wrapperRect)?.height - toValue(overshoot);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const drawerWidth = computed(() => {
|
|
23
|
+
if (toValue(wrapperRect) === void 0) {
|
|
24
|
+
return 0;
|
|
25
|
+
} else {
|
|
26
|
+
return toValue(wrapperRect)?.width - toValue(overshoot);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
25
29
|
function findClosestNumber(args2) {
|
|
26
30
|
const { number, numbers, direction } = args2;
|
|
27
31
|
let filtered = numbers;
|
|
@@ -53,7 +57,7 @@ export function useDrawerSnap(args) {
|
|
|
53
57
|
const reversedSnapPoint = mapValue(snapPoint, 0, 1, 1, 0);
|
|
54
58
|
const vh = window.innerHeight;
|
|
55
59
|
const vw = window.innerWidth;
|
|
56
|
-
if (wrapperRect
|
|
60
|
+
if (toValue(wrapperRect) === void 0) {
|
|
57
61
|
return void 0;
|
|
58
62
|
}
|
|
59
63
|
switch (position) {
|
|
@@ -63,34 +67,34 @@ export function useDrawerSnap(args) {
|
|
|
63
67
|
else if (reversedSnapPoint === 0)
|
|
64
68
|
return 0;
|
|
65
69
|
else
|
|
66
|
-
return vh * reversedSnapPoint - wrapperRect
|
|
70
|
+
return vh * reversedSnapPoint - toValue(wrapperRect)?.top;
|
|
67
71
|
case "top":
|
|
68
72
|
if (reversedSnapPoint === 1)
|
|
69
73
|
return drawerHeight.value * -1;
|
|
70
74
|
else if (reversedSnapPoint === 0)
|
|
71
75
|
return 0;
|
|
72
76
|
else
|
|
73
|
-
return vh * reversedSnapPoint - wrapperRect
|
|
77
|
+
return vh * reversedSnapPoint - toValue(wrapperRect)?.bottom;
|
|
74
78
|
case "right":
|
|
75
79
|
if (reversedSnapPoint === 1)
|
|
76
80
|
return drawerWidth.value;
|
|
77
81
|
else if (reversedSnapPoint === 0)
|
|
78
82
|
return 0;
|
|
79
83
|
else
|
|
80
|
-
return vw * reversedSnapPoint - wrapperRect
|
|
84
|
+
return vw * reversedSnapPoint - toValue(wrapperRect)?.left;
|
|
81
85
|
case "left":
|
|
82
86
|
if (reversedSnapPoint === 1)
|
|
83
87
|
return drawerWidth.value * -1;
|
|
84
88
|
else if (reversedSnapPoint === 0)
|
|
85
89
|
return 0;
|
|
86
90
|
else
|
|
87
|
-
return vw * reversedSnapPoint - wrapperRect
|
|
91
|
+
return vw * reversedSnapPoint - toValue(wrapperRect)?.right;
|
|
88
92
|
default:
|
|
89
93
|
return 0;
|
|
90
94
|
}
|
|
91
95
|
} else {
|
|
92
96
|
const parsedSnapPoint = parseFloat(snapPoint);
|
|
93
|
-
if (drawerHeight.value
|
|
97
|
+
if (!drawerHeight.value || !drawerWidth.value) {
|
|
94
98
|
return void 0;
|
|
95
99
|
}
|
|
96
100
|
switch (position) {
|
|
@@ -109,7 +113,6 @@ export function useDrawerSnap(args) {
|
|
|
109
113
|
}
|
|
110
114
|
async function findClosestSnapPoint(args2) {
|
|
111
115
|
const { draggedY, draggedX, direction = "absolute" } = args2;
|
|
112
|
-
await getSizes();
|
|
113
116
|
let closest = 0;
|
|
114
117
|
switch (position) {
|
|
115
118
|
case "bottom":
|
|
@@ -18,16 +18,11 @@ interface Props {
|
|
|
18
18
|
|
|
19
19
|
const props = defineProps<Props>()
|
|
20
20
|
const targetRef = ref<HTMLElement | undefined>(undefined)
|
|
21
|
-
const colDetect = ref()
|
|
22
21
|
|
|
23
22
|
const scrollPosition = inject(ScrollPositionKey, undefined)
|
|
24
23
|
const pageYOffset = computed(() => toValue(scrollPosition?.y) || 0)
|
|
25
24
|
|
|
26
25
|
onMounted(() => {
|
|
27
|
-
|
|
28
|
-
pageYOffset,
|
|
29
|
-
props.collisionEntries,
|
|
30
|
-
toValue(targetRef.value),
|
|
31
|
-
)
|
|
26
|
+
useCollisionDetect(pageYOffset, props.collisionEntries, toValue(targetRef))
|
|
32
27
|
})
|
|
33
28
|
</script>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
-
import type { CollisionEntry,
|
|
2
|
+
import type { CollisionEntry, MappedCollisionEntry } from '../types.js';
|
|
3
3
|
export declare function useCollisionDetect(pageYOffset: ComputedRef<number>, collisionEntries: CollisionEntry[], parent: HTMLElement | undefined): {
|
|
4
|
-
|
|
4
|
+
mappedCollisionEntries: Ref<MappedCollisionEntry[]>;
|
|
5
5
|
};
|
|
6
6
|
export type UseCollisionDetectReturn = ReturnType<typeof useCollisionDetect>;
|
|
@@ -5,7 +5,7 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
5
5
|
const scrolled = ref(0);
|
|
6
6
|
const intersecting = ref();
|
|
7
7
|
const scrollDirection = ref();
|
|
8
|
-
const
|
|
8
|
+
const mappedCollisionEntries = ref([]);
|
|
9
9
|
const oppositeScrollDirection = computed(
|
|
10
10
|
() => scrollDirection.value === "up" ? "down" : "up"
|
|
11
11
|
);
|
|
@@ -19,7 +19,7 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
19
19
|
function initialize() {
|
|
20
20
|
if (!parent)
|
|
21
21
|
return;
|
|
22
|
-
|
|
22
|
+
mappedCollisionEntries.value = collisionEntries.map((entry) => {
|
|
23
23
|
const alerted = {
|
|
24
24
|
up: {
|
|
25
25
|
top: false,
|
|
@@ -32,8 +32,10 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
32
32
|
};
|
|
33
33
|
const offset = { top: 0, bottom: 0, ...entry.offset };
|
|
34
34
|
const element = entry.element ? parent?.querySelector(entry.element) : parent;
|
|
35
|
+
if (!element)
|
|
36
|
+
return void 0;
|
|
35
37
|
return { ...entry, offset, element, alerted };
|
|
36
|
-
});
|
|
38
|
+
}).filter((element) => !!element);
|
|
37
39
|
useIntersectionObserver(
|
|
38
40
|
parent.querySelector("*"),
|
|
39
41
|
([{ isIntersecting }]) => {
|
|
@@ -51,9 +53,9 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
51
53
|
}
|
|
52
54
|
scrollDirection.value = scrolled.value <= pageYOffset.value ? "down" : "up";
|
|
53
55
|
scrolled.value = pageYOffset.value;
|
|
54
|
-
let i =
|
|
56
|
+
let i = mappedCollisionEntries.value.length;
|
|
55
57
|
while (i--) {
|
|
56
|
-
const entry =
|
|
58
|
+
const entry = mappedCollisionEntries.value[i];
|
|
57
59
|
if (!entry.element)
|
|
58
60
|
return;
|
|
59
61
|
const boundingRect = entry.element.getBoundingClientRect();
|
|
@@ -66,7 +68,7 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
function resetAll() {
|
|
69
|
-
|
|
71
|
+
mappedCollisionEntries.value = mappedCollisionEntries.value.map((entry) => {
|
|
70
72
|
const alerted = {
|
|
71
73
|
up: {
|
|
72
74
|
top: false,
|
|
@@ -112,6 +114,6 @@ export function useCollisionDetect(pageYOffset, collisionEntries, parent) {
|
|
|
112
114
|
}
|
|
113
115
|
);
|
|
114
116
|
return {
|
|
115
|
-
|
|
117
|
+
mappedCollisionEntries
|
|
116
118
|
};
|
|
117
119
|
}
|
|
@@ -18,7 +18,7 @@ interface CollisionEntry {
|
|
|
18
18
|
element?: string;
|
|
19
19
|
data: Record<string, any>;
|
|
20
20
|
}
|
|
21
|
-
interface
|
|
21
|
+
interface MappedCollisionEntry extends Omit<CollisionEntry, 'element'> {
|
|
22
22
|
alerted: {
|
|
23
23
|
up: AlertPositions;
|
|
24
24
|
down: AlertPositions;
|
|
@@ -30,4 +30,4 @@ type Dimensions = {
|
|
|
30
30
|
height: number;
|
|
31
31
|
};
|
|
32
32
|
type FromTo = 'top-top' | 'top-center' | 'top-bottom' | 'center-top' | 'center-center' | 'center-bottom' | 'bottom-top' | 'bottom-center' | 'bottom-bottom';
|
|
33
|
-
export type { FromTo, CollisionEvents, CollisionEntry,
|
|
33
|
+
export type { FromTo, CollisionEvents, CollisionEntry, MappedCollisionEntry, Dimensions, };
|
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.16.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",
|