@maas/vue-equipment 1.0.1 → 1.2.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 +2 -2
- package/dist/plugins/MagicCarousel/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicDraggable/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicDrawer/index.d.ts +2 -2
- package/dist/plugins/MagicDrawer/src/components/MagicDrawerContent.vue +4 -0
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDrag.mjs +128 -170
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerProgress.mjs +57 -77
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerSnap.d.ts +16 -11
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerSnap.mjs +175 -175
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerState.mjs +2 -1
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerUtils.d.ts +3 -0
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerUtils.mjs +11 -1
- package/dist/plugins/MagicDrawer/src/composables/useMagicDrawer.d.ts +1 -0
- package/dist/plugins/MagicDrawer/src/composables/useMagicDrawer.mjs +2 -1
- package/dist/plugins/MagicDrawer/src/types/index.d.ts +8 -1
- package/dist/plugins/MagicDrawer/src/utils/defaultOptions.mjs +1 -1
- package/dist/plugins/MagicTray/index.d.ts +4 -3
- package/dist/plugins/MagicTray/index.mjs +3 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.d.vue.ts +2 -2
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.vue +17 -16
- package/dist/plugins/MagicTray/src/components/MagicTrayContent.vue.d.ts +2 -2
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.d.vue.ts +25 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.vue +90 -0
- package/dist/plugins/MagicTray/src/components/MagicTrayTrigger.vue.d.ts +25 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayDrag.d.ts +0 -4
- package/dist/plugins/MagicTray/src/composables/private/useTrayDrag.mjs +27 -385
- package/dist/plugins/MagicTray/src/composables/private/useTrayGesture.d.ts +16 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayGesture.mjs +426 -0
- package/dist/plugins/MagicTray/src/composables/private/useTrayMagnetism.mjs +11 -37
- package/dist/plugins/MagicTray/src/composables/private/useTrayProgress.mjs +1 -1
- package/dist/plugins/MagicTray/src/composables/private/useTraySnap.d.ts +12 -7
- package/dist/plugins/MagicTray/src/composables/private/useTraySnap.mjs +88 -40
- package/dist/plugins/MagicTray/src/composables/private/useTrayUtils.d.ts +10 -1
- package/dist/plugins/MagicTray/src/composables/private/useTrayUtils.mjs +17 -1
- package/dist/plugins/MagicTray/src/types/index.d.ts +7 -1
- package/dist/plugins/MagicTray/src/utils/defaultOptions.mjs +1 -1
- package/dist/utils/index.d.ts +46 -1
- package/dist/utils/index.js +75 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import type { MaybeRef, Ref } from 'vue';
|
|
2
|
-
import type { MagicDrawerSnapPoint, RequiredMagicDrawerOptions } from '../../types/index.js';
|
|
2
|
+
import type { MagicDrawerSnapPoint, MagicDrawerSnapRange, RequiredMagicDrawerOptions } from '../../types/index.js';
|
|
3
3
|
type UseDrawerSnapArgs = {
|
|
4
4
|
id: MaybeRef<string>;
|
|
5
5
|
wrapperRect: Ref<DOMRect | undefined>;
|
|
6
6
|
draggedY: Ref<number>;
|
|
7
7
|
draggedX: Ref<number>;
|
|
8
|
+
activeSnapPoint: Ref<MagicDrawerSnapPoint | undefined>;
|
|
8
9
|
position: MaybeRef<RequiredMagicDrawerOptions['position']>;
|
|
9
10
|
animation: MaybeRef<RequiredMagicDrawerOptions['animation']>;
|
|
10
11
|
snapPoints: MaybeRef<RequiredMagicDrawerOptions['snapPoints']>;
|
|
11
12
|
preventDragClose: MaybeRef<RequiredMagicDrawerOptions['preventDragClose']>;
|
|
12
13
|
overshoot: MaybeRef<number>;
|
|
13
14
|
};
|
|
14
|
-
type FindClosestSnapPointArgs = {
|
|
15
|
-
draggedY: MaybeRef<number>;
|
|
16
|
-
draggedX: MaybeRef<number>;
|
|
17
|
-
direction?: 'below' | 'above' | 'absolute';
|
|
18
|
-
};
|
|
19
15
|
type SnapToArgs = {
|
|
20
16
|
snapPoint: MagicDrawerSnapPoint;
|
|
21
17
|
interpolate: boolean;
|
|
@@ -26,15 +22,24 @@ type InterpolateDraggedArgs = {
|
|
|
26
22
|
duration?: number;
|
|
27
23
|
easing?: (t: number) => number;
|
|
28
24
|
};
|
|
25
|
+
type MappedSnapRange = {
|
|
26
|
+
min: number;
|
|
27
|
+
max: number;
|
|
28
|
+
momentum?: boolean;
|
|
29
|
+
range: MagicDrawerSnapRange;
|
|
30
|
+
};
|
|
29
31
|
export declare function useDrawerSnap(args: UseDrawerSnapArgs): {
|
|
30
32
|
snappedY: import("vue").ShallowRef<number, number>;
|
|
31
33
|
snappedX: import("vue").ShallowRef<number, number>;
|
|
32
|
-
activeSnapPoint: import("vue").ShallowRef<MagicDrawerSnapPoint | undefined, MagicDrawerSnapPoint | undefined>;
|
|
33
|
-
snapTo: (args: SnapToArgs) => Promise<void>;
|
|
34
|
-
findClosestSnapPoint: (args: FindClosestSnapPointArgs) => number | undefined;
|
|
35
|
-
interpolateDragged: (args: InterpolateDraggedArgs) => void;
|
|
36
|
-
snapPointsMap: import("@vueuse/core").ComputedRefWithControl<Record<number, MagicDrawerSnapPoint>>;
|
|
37
34
|
drawerHeight: import("vue").ComputedRef<number>;
|
|
38
35
|
drawerWidth: import("vue").ComputedRef<number>;
|
|
36
|
+
mappedSnapPoints: import("vue").ComputedRef<any[]>;
|
|
37
|
+
mappedRanges: import("vue").ComputedRef<MappedSnapRange[]>;
|
|
38
|
+
rangeAt: (offset: number) => any;
|
|
39
|
+
snapPointAt: (offset: number) => MagicDrawerSnapPoint | undefined;
|
|
40
|
+
restingOffset: (offset: number) => any;
|
|
41
|
+
isSnapTarget: (snapPoint: MagicDrawerSnapPoint) => boolean;
|
|
42
|
+
snapTo: (args: SnapToArgs) => Promise<void>;
|
|
43
|
+
interpolateDragged: (args: InterpolateDraggedArgs) => void;
|
|
39
44
|
};
|
|
40
45
|
export {};
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { computed, nextTick, shallowRef, toValue } from "vue";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
clampValue,
|
|
4
|
+
interpolate,
|
|
5
|
+
mapValue,
|
|
6
|
+
snapRangeAt,
|
|
7
|
+
snapTargetAt
|
|
8
|
+
} from "@maas/vue-equipment/utils";
|
|
4
9
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
10
|
+
import { useDrawerUtils } from "./useDrawerUtils.mjs";
|
|
11
|
+
function isMapped(value) {
|
|
12
|
+
return value !== void 0 && !Number.isNaN(value);
|
|
13
|
+
}
|
|
14
|
+
function roundDecimal(value) {
|
|
15
|
+
return Math.round(value * 1e4) / 1e4;
|
|
16
|
+
}
|
|
5
17
|
export function useDrawerSnap(args) {
|
|
6
18
|
const {
|
|
7
19
|
id,
|
|
@@ -12,43 +24,21 @@ export function useDrawerSnap(args) {
|
|
|
12
24
|
overshoot,
|
|
13
25
|
draggedY,
|
|
14
26
|
draggedX,
|
|
27
|
+
activeSnapPoint,
|
|
15
28
|
preventDragClose
|
|
16
29
|
} = args;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return filtered;
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
const snapPointsMap = computedWithControl(
|
|
31
|
-
() => toValue(snapPoints),
|
|
32
|
-
() => {
|
|
33
|
-
const extended = toValue(preventDragClose) ? toValue(snapPoints) : [...toValue(snapPoints), 0];
|
|
34
|
-
const mapped = extended.reduce(
|
|
35
|
-
(acc, current) => {
|
|
36
|
-
const key = mapSnapPoint(current);
|
|
37
|
-
if (key || key === 0) {
|
|
38
|
-
acc[key] = current;
|
|
39
|
-
}
|
|
40
|
-
return acc;
|
|
41
|
-
},
|
|
42
|
-
{}
|
|
43
|
-
);
|
|
44
|
-
return mapped;
|
|
45
|
-
}
|
|
46
|
-
);
|
|
30
|
+
const { isSnapRange, flattenSnapPoints } = useDrawerUtils();
|
|
31
|
+
const emitter = useMagicEmitter();
|
|
32
|
+
const isVertical = computed(() => {
|
|
33
|
+
const side = toValue(position);
|
|
34
|
+
return side === "top" || side === "bottom";
|
|
35
|
+
});
|
|
36
|
+
const configuredPoints = computed(() => {
|
|
37
|
+
const flattened = flattenSnapPoints(toValue(snapPoints));
|
|
38
|
+
return toValue(preventDragClose) ? flattened : [...flattened, 0];
|
|
39
|
+
});
|
|
47
40
|
const snappedY = shallowRef(0);
|
|
48
41
|
const snappedX = shallowRef(0);
|
|
49
|
-
const activeSnapPoint = shallowRef(
|
|
50
|
-
void 0
|
|
51
|
-
);
|
|
52
42
|
const drawerHeight = computed(() => {
|
|
53
43
|
const rect = toValue(wrapperRect);
|
|
54
44
|
if (rect === void 0) {
|
|
@@ -63,36 +53,27 @@ export function useDrawerSnap(args) {
|
|
|
63
53
|
}
|
|
64
54
|
return rect.width - toValue(overshoot);
|
|
65
55
|
});
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
break;
|
|
77
|
-
case "below":
|
|
78
|
-
filtered = numbers.filter((num) => num < number);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
if (filtered.length === 0) {
|
|
82
|
-
switch (direction) {
|
|
83
|
-
case "above":
|
|
84
|
-
return Math.max(...numbers);
|
|
85
|
-
case "below":
|
|
86
|
-
return Math.min(...numbers);
|
|
87
|
-
default:
|
|
88
|
-
return void 0;
|
|
56
|
+
const mappedSnapPoints = computed(() => {
|
|
57
|
+
const mapped = configuredPoints.value.map(mapSnapPoint).filter(isMapped);
|
|
58
|
+
return [...new Set(mapped)].sort((a, b) => a - b);
|
|
59
|
+
});
|
|
60
|
+
const mappedRanges = computed(
|
|
61
|
+
() => toValue(snapPoints).filter(isSnapRange).flatMap((range) => {
|
|
62
|
+
const min = mapSnapPoint(range.min);
|
|
63
|
+
const max = mapSnapPoint(range.max);
|
|
64
|
+
if (!isMapped(min) || !isMapped(max)) {
|
|
65
|
+
return [];
|
|
89
66
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
67
|
+
return [
|
|
68
|
+
{
|
|
69
|
+
min: Math.min(min, max),
|
|
70
|
+
max: Math.max(min, max),
|
|
71
|
+
momentum: range.momentum,
|
|
72
|
+
range
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
})
|
|
76
|
+
);
|
|
96
77
|
function mapSnapPoint(snapPoint) {
|
|
97
78
|
if (typeof snapPoint === "number") {
|
|
98
79
|
const reversedSnapPoint = mapValue(snapPoint, 0, 1, 1, 0);
|
|
@@ -176,49 +157,114 @@ export function useDrawerSnap(args) {
|
|
|
176
157
|
}
|
|
177
158
|
}
|
|
178
159
|
}
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
160
|
+
function decimalAt(offset) {
|
|
161
|
+
const rect = toValue(wrapperRect);
|
|
162
|
+
if (!rect) {
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
182
165
|
switch (position) {
|
|
166
|
+
case "bottom":
|
|
167
|
+
return 1 - (offset + rect.top) / window.innerHeight;
|
|
183
168
|
case "top":
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const closestY = findClosestSnapPoint({
|
|
190
|
-
draggedX,
|
|
191
|
-
draggedY: mappedSnapPointY
|
|
192
|
-
}) || 0;
|
|
193
|
-
if (interpolate2) {
|
|
194
|
-
interpolateDragged({ to: closestY, duration });
|
|
195
|
-
} else {
|
|
196
|
-
draggedY.value = closestY;
|
|
197
|
-
}
|
|
198
|
-
snappedY.value = closestY;
|
|
199
|
-
activeSnapPoint.value = toValue(snapPoint);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
169
|
+
return 1 - (offset + rect.bottom) / window.innerHeight;
|
|
170
|
+
case "right":
|
|
171
|
+
return 1 - (offset + rect.left) / window.innerWidth;
|
|
202
172
|
case "left":
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
173
|
+
return 1 - (offset + rect.right) / window.innerWidth;
|
|
174
|
+
default:
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function pixelsAt(offset) {
|
|
179
|
+
switch (position) {
|
|
180
|
+
case "bottom":
|
|
181
|
+
return drawerHeight.value - offset;
|
|
182
|
+
case "top":
|
|
183
|
+
return drawerHeight.value + offset;
|
|
184
|
+
case "right":
|
|
185
|
+
return drawerWidth.value - offset;
|
|
186
|
+
case "left":
|
|
187
|
+
return drawerWidth.value + offset;
|
|
188
|
+
default:
|
|
189
|
+
return offset;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function configuredPointAt(offset) {
|
|
193
|
+
return configuredPoints.value.find((snapPoint) => {
|
|
194
|
+
const mapped = mapSnapPoint(snapPoint);
|
|
195
|
+
return mapped === offset;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function draggedOnAxis() {
|
|
199
|
+
return isVertical.value ? draggedY.value : draggedX.value;
|
|
200
|
+
}
|
|
201
|
+
function setDraggedOnAxis(value) {
|
|
202
|
+
if (isVertical.value) {
|
|
203
|
+
draggedY.value = value;
|
|
204
|
+
} else {
|
|
205
|
+
draggedX.value = value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function setSnappedOnAxis(value) {
|
|
209
|
+
if (isVertical.value) {
|
|
210
|
+
snappedY.value = value;
|
|
211
|
+
} else {
|
|
212
|
+
snappedX.value = value;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function rangeAt(offset) {
|
|
216
|
+
return snapRangeAt({ ranges: mappedRanges.value, position: offset });
|
|
217
|
+
}
|
|
218
|
+
function snapPointAt(offset) {
|
|
219
|
+
const configured = configuredPointAt(offset);
|
|
220
|
+
if (configured !== void 0) {
|
|
221
|
+
return configured;
|
|
222
|
+
}
|
|
223
|
+
const mapped = rangeAt(offset);
|
|
224
|
+
if (!mapped) {
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
const { min, max } = mapped.range;
|
|
228
|
+
return typeof min === "number" && typeof max === "number" ? roundDecimal(decimalAt(offset)) : `${Math.round(pixelsAt(offset))}px`;
|
|
229
|
+
}
|
|
230
|
+
function restingOffset(offset) {
|
|
231
|
+
const range = rangeAt(offset);
|
|
232
|
+
const snapPoint = snapPointAt(offset);
|
|
233
|
+
if (!range || snapPoint === void 0) {
|
|
234
|
+
return offset;
|
|
235
|
+
}
|
|
236
|
+
const mapped = mapSnapPoint(snapPoint);
|
|
237
|
+
return isMapped(mapped) ? clampValue(mapped, range.min, range.max) : offset;
|
|
238
|
+
}
|
|
239
|
+
function isSnapTarget(snapPoint) {
|
|
240
|
+
const mapped = mapSnapPoint(snapPoint);
|
|
241
|
+
if (!isMapped(mapped)) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return !!rangeAt(mapped) || mappedSnapPoints.value.includes(mapped);
|
|
245
|
+
}
|
|
246
|
+
function findSnapTarget(offset) {
|
|
247
|
+
const target = snapTargetAt({
|
|
248
|
+
points: mappedSnapPoints.value,
|
|
249
|
+
ranges: mappedRanges.value,
|
|
250
|
+
value: offset
|
|
251
|
+
});
|
|
252
|
+
return target === void 0 ? void 0 : restingOffset(target);
|
|
253
|
+
}
|
|
254
|
+
async function snapTo(args2) {
|
|
255
|
+
const { snapPoint, interpolate: shouldInterpolate, duration } = args2;
|
|
256
|
+
await nextTick();
|
|
257
|
+
const mapped = mapSnapPoint(snapPoint);
|
|
258
|
+
if (!isMapped(mapped)) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const closest = findSnapTarget(mapped) ?? 0;
|
|
262
|
+
setSnappedOnAxis(closest);
|
|
263
|
+
activeSnapPoint.value = snapPointAt(closest) ?? snapPoint;
|
|
264
|
+
if (shouldInterpolate) {
|
|
265
|
+
interpolateDragged({ to: closest, duration });
|
|
266
|
+
} else {
|
|
267
|
+
setDraggedOnAxis(closest);
|
|
222
268
|
}
|
|
223
269
|
}
|
|
224
270
|
function interpolateDragged(args2) {
|
|
@@ -227,86 +273,40 @@ export function useDrawerSnap(args) {
|
|
|
227
273
|
duration = toValue(animation).snap.duration,
|
|
228
274
|
easing = toValue(animation).snap.easing
|
|
229
275
|
} = args2;
|
|
230
|
-
const snapPoint =
|
|
231
|
-
if (
|
|
276
|
+
const snapPoint = snapPointAt(to);
|
|
277
|
+
if (snapPoint === void 0) {
|
|
232
278
|
return;
|
|
233
279
|
}
|
|
234
280
|
emitter.emit("beforeSnap", { id: toValue(id), snapPoint });
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
interpolate({
|
|
239
|
-
from: draggedY.value,
|
|
240
|
-
to,
|
|
241
|
-
duration,
|
|
242
|
-
easing,
|
|
243
|
-
callback: (value) => {
|
|
244
|
-
draggedY.value = value;
|
|
245
|
-
if (draggedY.value === to) {
|
|
246
|
-
emitter.emit("afterSnap", {
|
|
247
|
-
id: toValue(id),
|
|
248
|
-
snapPoint
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
break;
|
|
254
|
-
case "right":
|
|
255
|
-
case "left":
|
|
256
|
-
interpolate({
|
|
257
|
-
from: draggedX.value,
|
|
258
|
-
to,
|
|
259
|
-
duration,
|
|
260
|
-
easing,
|
|
261
|
-
callback: (value) => {
|
|
262
|
-
draggedX.value = value;
|
|
263
|
-
if (draggedX.value === to) {
|
|
264
|
-
emitter.emit("afterSnap", {
|
|
265
|
-
id: toValue(id),
|
|
266
|
-
snapPoint
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
break;
|
|
281
|
+
if (draggedOnAxis() === to) {
|
|
282
|
+
emitter.emit("afterSnap", { id: toValue(id), snapPoint });
|
|
283
|
+
return;
|
|
272
284
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
number: toValue(draggedY2),
|
|
283
|
-
numbers: mappedSnapPoints.value,
|
|
284
|
-
direction
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
break;
|
|
288
|
-
case "right":
|
|
289
|
-
case "left":
|
|
290
|
-
if (!!toValue(draggedX2) || toValue(draggedX2) === 0) {
|
|
291
|
-
closest = findClosestNumber({
|
|
292
|
-
number: toValue(draggedX2),
|
|
293
|
-
numbers: mappedSnapPoints.value,
|
|
294
|
-
direction
|
|
295
|
-
});
|
|
285
|
+
interpolate({
|
|
286
|
+
from: draggedOnAxis(),
|
|
287
|
+
to,
|
|
288
|
+
duration,
|
|
289
|
+
easing,
|
|
290
|
+
callback: (value) => {
|
|
291
|
+
setDraggedOnAxis(value);
|
|
292
|
+
if (value === to) {
|
|
293
|
+
emitter.emit("afterSnap", { id: toValue(id), snapPoint });
|
|
296
294
|
}
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
return closest;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
300
297
|
}
|
|
301
298
|
return {
|
|
302
299
|
snappedY,
|
|
303
300
|
snappedX,
|
|
304
|
-
activeSnapPoint,
|
|
305
|
-
snapTo,
|
|
306
|
-
findClosestSnapPoint,
|
|
307
|
-
interpolateDragged,
|
|
308
|
-
snapPointsMap,
|
|
309
301
|
drawerHeight,
|
|
310
|
-
drawerWidth
|
|
302
|
+
drawerWidth,
|
|
303
|
+
mappedSnapPoints,
|
|
304
|
+
mappedRanges,
|
|
305
|
+
rangeAt,
|
|
306
|
+
snapPointAt,
|
|
307
|
+
restingOffset,
|
|
308
|
+
isSnapTarget,
|
|
309
|
+
snapTo,
|
|
310
|
+
interpolateDragged
|
|
311
311
|
};
|
|
312
312
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { MagicDrawerSnapEntry, MagicDrawerSnapRange } from '../../types/index.js';
|
|
1
2
|
export declare function useDrawerUtils(): {
|
|
2
3
|
clamp: (value: number, from: number, to: number, flip: boolean) => any;
|
|
4
|
+
isSnapRange: (entry: MagicDrawerSnapEntry) => entry is MagicDrawerSnapRange;
|
|
5
|
+
flattenSnapPoints: (entries: Array<MagicDrawerSnapEntry>) => import("../../types/index.js").MagicDrawerSnapPoint[];
|
|
3
6
|
};
|
|
@@ -10,7 +10,17 @@ export function useDrawerUtils() {
|
|
|
10
10
|
return flip ? Math.min(value, to) : Math.max(value, to);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
function isSnapRange(entry) {
|
|
14
|
+
return typeof entry === "object";
|
|
15
|
+
}
|
|
16
|
+
function flattenSnapPoints(entries) {
|
|
17
|
+
return entries.flatMap(
|
|
18
|
+
(entry) => isSnapRange(entry) ? [entry.min, entry.max] : [entry]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
13
21
|
return {
|
|
14
|
-
clamp
|
|
22
|
+
clamp,
|
|
23
|
+
isSnapRange,
|
|
24
|
+
flattenSnapPoints
|
|
15
25
|
};
|
|
16
26
|
}
|
|
@@ -3,6 +3,7 @@ import type { MagicDrawerOptions, MagicDrawerSnapPoint } from '../types/index.js
|
|
|
3
3
|
export declare function useMagicDrawer(id: MaybeRef<string>, options?: MagicDrawerOptions): {
|
|
4
4
|
isActive: import("vue").ComputedRef<any>;
|
|
5
5
|
progress: any;
|
|
6
|
+
activeSnapPoint: any;
|
|
6
7
|
state: any;
|
|
7
8
|
open: () => void;
|
|
8
9
|
close: () => void;
|
|
@@ -4,7 +4,7 @@ import { useDrawerState } from "./private/useDrawerState.mjs";
|
|
|
4
4
|
export function useMagicDrawer(id, options) {
|
|
5
5
|
const { initializeState } = useDrawerState(toValue(id));
|
|
6
6
|
const state = initializeState(options);
|
|
7
|
-
const { progress, active } = toRefs(state);
|
|
7
|
+
const { progress, active, activeSnapPoint } = toRefs(state);
|
|
8
8
|
const emitter = useMagicEmitter();
|
|
9
9
|
const isActive = computed(() => active.value);
|
|
10
10
|
function open() {
|
|
@@ -23,6 +23,7 @@ export function useMagicDrawer(id, options) {
|
|
|
23
23
|
return {
|
|
24
24
|
isActive,
|
|
25
25
|
progress,
|
|
26
|
+
activeSnapPoint,
|
|
26
27
|
state,
|
|
27
28
|
open,
|
|
28
29
|
close,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Options as FocusTrapOptions } from 'focus-trap';
|
|
2
2
|
import type { RequireAllNested } from '@maas/vue-equipment/utils';
|
|
3
3
|
export type MagicDrawerSnapPoint = number | `${number}px`;
|
|
4
|
+
export interface MagicDrawerSnapRange {
|
|
5
|
+
min: MagicDrawerSnapPoint;
|
|
6
|
+
max: MagicDrawerSnapPoint;
|
|
7
|
+
momentum?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type MagicDrawerSnapEntry = MagicDrawerSnapPoint | MagicDrawerSnapRange;
|
|
4
10
|
export type DrawerSnapMode = 'closest' | 'step';
|
|
5
11
|
export interface MagicDrawerOptions {
|
|
6
12
|
position?: 'top' | 'right' | 'bottom' | 'left';
|
|
@@ -9,7 +15,7 @@ export interface MagicDrawerOptions {
|
|
|
9
15
|
scrollLock?: boolean | {
|
|
10
16
|
padding: boolean;
|
|
11
17
|
};
|
|
12
|
-
snapPoints?:
|
|
18
|
+
snapPoints?: Array<MagicDrawerSnapEntry>;
|
|
13
19
|
snap?: {
|
|
14
20
|
mode?: DrawerSnapMode;
|
|
15
21
|
};
|
|
@@ -64,6 +70,7 @@ export interface DrawerState {
|
|
|
64
70
|
x: number;
|
|
65
71
|
y: number;
|
|
66
72
|
};
|
|
73
|
+
activeSnapPoint: MagicDrawerSnapPoint | undefined;
|
|
67
74
|
shouldClose: boolean;
|
|
68
75
|
interpolateTo: number | undefined;
|
|
69
76
|
originX: number;
|
|
@@ -2,10 +2,11 @@ import MagicTray from './src/components/MagicTray.vue.js';
|
|
|
2
2
|
import MagicTrayProvider from './src/components/MagicTrayProvider.vue.js';
|
|
3
3
|
import MagicTrayContent from './src/components/MagicTrayContent.vue.js';
|
|
4
4
|
import MagicTrayHandle from './src/components/MagicTrayHandle.vue.js';
|
|
5
|
+
import MagicTrayTrigger from './src/components/MagicTrayTrigger.vue.js';
|
|
5
6
|
import MagicTrayTransform from './src/components/MagicTrayTransform.vue.js';
|
|
6
7
|
import { useMagicTray } from './src/composables/useMagicTray.js';
|
|
7
8
|
import type { Plugin } from 'vue';
|
|
8
|
-
import type { MagicTrayDragMode, MagicTrayOptions, MagicTraySide, MagicTraySidePayload, MagicTraySnapMode, MagicTraySnapPoint, MagicTraySnapPointPayload, MagicTrayTransformAxis, MagicTrayWillSnapToPayload } from './src/types/index.js';
|
|
9
|
+
import type { MagicTrayDragMode, MagicTrayOptions, MagicTraySide, MagicTraySidePayload, MagicTraySnapEntry, MagicTraySnapMode, MagicTraySnapPoint, MagicTraySnapPointPayload, MagicTraySnapRange, MagicTrayTransformAxis, MagicTrayWillSnapToPayload } from './src/types/index.js';
|
|
9
10
|
declare const MagicTrayPlugin: Plugin;
|
|
10
|
-
export { MagicTrayPlugin, MagicTray, MagicTrayProvider, MagicTrayContent, MagicTrayHandle, MagicTrayTransform, useMagicTray, };
|
|
11
|
-
export type { MagicTrayOptions, MagicTraySide, MagicTraySidePayload, MagicTraySnapMode, MagicTrayDragMode, MagicTraySnapPoint, MagicTraySnapPointPayload, MagicTrayWillSnapToPayload, MagicTrayTransformAxis, };
|
|
11
|
+
export { MagicTrayPlugin, MagicTray, MagicTrayProvider, MagicTrayContent, MagicTrayHandle, MagicTrayTrigger, MagicTrayTransform, useMagicTray, };
|
|
12
|
+
export type { MagicTrayOptions, MagicTraySide, MagicTraySidePayload, MagicTraySnapMode, MagicTrayDragMode, MagicTraySnapPoint, MagicTraySnapRange, MagicTraySnapEntry, MagicTraySnapPointPayload, MagicTrayWillSnapToPayload, MagicTrayTransformAxis, };
|
|
@@ -2,6 +2,7 @@ import MagicTray from "./src/components/MagicTray.vue";
|
|
|
2
2
|
import MagicTrayProvider from "./src/components/MagicTrayProvider.vue";
|
|
3
3
|
import MagicTrayContent from "./src/components/MagicTrayContent.vue";
|
|
4
4
|
import MagicTrayHandle from "./src/components/MagicTrayHandle.vue";
|
|
5
|
+
import MagicTrayTrigger from "./src/components/MagicTrayTrigger.vue";
|
|
5
6
|
import MagicTrayTransform from "./src/components/MagicTrayTransform.vue";
|
|
6
7
|
import { useMagicTray } from "./src/composables/useMagicTray.mjs";
|
|
7
8
|
const MagicTrayPlugin = {
|
|
@@ -10,6 +11,7 @@ const MagicTrayPlugin = {
|
|
|
10
11
|
app.component("MagicTrayProvider", MagicTrayProvider);
|
|
11
12
|
app.component("MagicTrayContent", MagicTrayContent);
|
|
12
13
|
app.component("MagicTrayHandle", MagicTrayHandle);
|
|
14
|
+
app.component("MagicTrayTrigger", MagicTrayTrigger);
|
|
13
15
|
app.component("MagicTrayTransform", MagicTrayTransform);
|
|
14
16
|
}
|
|
15
17
|
};
|
|
@@ -19,6 +21,7 @@ export {
|
|
|
19
21
|
MagicTrayProvider,
|
|
20
22
|
MagicTrayContent,
|
|
21
23
|
MagicTrayHandle,
|
|
24
|
+
MagicTrayTrigger,
|
|
22
25
|
MagicTrayTransform,
|
|
23
26
|
useMagicTray
|
|
24
27
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { MagicTraySide } from '../types/index.js';
|
|
2
|
-
declare var __VLS_9: {}, __VLS_11: {},
|
|
2
|
+
declare var __VLS_9: {}, __VLS_11: {}, __VLS_24: "handle-top" | "handle-right" | "handle-bottom" | "handle-left" | "handle", __VLS_25: {
|
|
3
3
|
side: MagicTraySide;
|
|
4
4
|
};
|
|
5
5
|
type __VLS_Slots = {} & {
|
|
6
|
-
[K in NonNullable<typeof
|
|
6
|
+
[K in NonNullable<typeof __VLS_24>]?: (props: typeof __VLS_25) => any;
|
|
7
7
|
} & {
|
|
8
8
|
background?: (props: typeof __VLS_9) => any;
|
|
9
9
|
} & {
|