@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
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -45,7 +45,7 @@ const functions$1 = [
|
|
|
45
45
|
{
|
|
46
46
|
name: "MagicDrawer",
|
|
47
47
|
"package": "plugins",
|
|
48
|
-
lastUpdated:
|
|
48
|
+
lastUpdated: 1792678394000,
|
|
49
49
|
docs: "https://vue.equipment/plugins/MagicDrawer",
|
|
50
50
|
description: "MagicDrawer is a flexible"
|
|
51
51
|
},
|
|
@@ -122,7 +122,7 @@ const functions$1 = [
|
|
|
122
122
|
{
|
|
123
123
|
name: "MagicTray",
|
|
124
124
|
"package": "plugins",
|
|
125
|
-
lastUpdated:
|
|
125
|
+
lastUpdated: 1793032883000,
|
|
126
126
|
docs: "https://vue.equipment/plugins/MagicTray",
|
|
127
127
|
description: "MagicTray is a flexible"
|
|
128
128
|
},
|
|
@@ -6,7 +6,7 @@ import MagicDrawerContent from './src/components/MagicDrawerContent.vue.js';
|
|
|
6
6
|
import MagicDrawerTrigger from './src/components/MagicDrawerTrigger.vue.js';
|
|
7
7
|
import { useMagicDrawer } from './src/composables/useMagicDrawer.js';
|
|
8
8
|
import type { Plugin } from 'vue';
|
|
9
|
-
import type { MagicDrawerOptions, MagicDrawerSnapPoint, MagicDrawerWillSnapToPayload } from './src/types/index.js';
|
|
9
|
+
import type { MagicDrawerOptions, MagicDrawerSnapPoint, MagicDrawerSnapRange, MagicDrawerSnapEntry, MagicDrawerWillSnapToPayload } from './src/types/index.js';
|
|
10
10
|
declare const MagicDrawerPlugin: Plugin;
|
|
11
11
|
export { MagicDrawerPlugin, MagicDrawer, MagicDrawerProvider, MagicDrawerTeleport, MagicDrawerBackdrop, MagicDrawerContent, MagicDrawerTrigger, useMagicDrawer, };
|
|
12
|
-
export type { MagicDrawerOptions, MagicDrawerSnapPoint, MagicDrawerWillSnapToPayload, };
|
|
12
|
+
export type { MagicDrawerOptions, MagicDrawerSnapPoint, MagicDrawerSnapRange, MagicDrawerSnapEntry, MagicDrawerWillSnapToPayload, };
|
|
@@ -367,6 +367,10 @@ dialog.magic-drawer-content__drag::backdrop {
|
|
|
367
367
|
user-select: none;
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
+
.magic-drawer-content[data-dragging='true'] .magic-drawer-content__drag * {
|
|
371
|
+
-webkit-user-drag: none;
|
|
372
|
+
}
|
|
373
|
+
|
|
370
374
|
.magic-drawer-content[data-wheeling='true'] .magic-drawer-content__drag {
|
|
371
375
|
cursor: auto;
|
|
372
376
|
}
|
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
guardedSetPointerCapture,
|
|
22
22
|
isAndroid,
|
|
23
23
|
isIOS,
|
|
24
|
-
isWithinRange
|
|
24
|
+
isWithinRange,
|
|
25
|
+
snapCommit,
|
|
26
|
+
snapRelease
|
|
25
27
|
} from "@maas/vue-equipment/utils";
|
|
26
28
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
27
29
|
import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
|
|
@@ -69,10 +71,12 @@ export function useDrawerDrag(args) {
|
|
|
69
71
|
absDirectionX,
|
|
70
72
|
absDirectionY,
|
|
71
73
|
elRect,
|
|
72
|
-
wrapperRect
|
|
74
|
+
wrapperRect,
|
|
75
|
+
activeSnapPoint
|
|
73
76
|
} = toRefs(state);
|
|
74
77
|
const { isActive, close } = useMagicDrawer(id);
|
|
75
78
|
let lastPendingTarget = void 0;
|
|
79
|
+
let flicked = false;
|
|
76
80
|
let pointerdownTarget = void 0;
|
|
77
81
|
let cancelPointerup = void 0;
|
|
78
82
|
let cancelPointermove = void 0;
|
|
@@ -99,22 +103,23 @@ export function useDrawerDrag(args) {
|
|
|
99
103
|
() => `transform: translate(${draggedX.value}px, ${draggedY.value}px)`
|
|
100
104
|
);
|
|
101
105
|
const snapMode = computed(() => toValue(snap).mode);
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
() => snapMode.value === "step" ? lastDraggedY.value : draggedY.value
|
|
107
|
-
);
|
|
106
|
+
const isVertical = computed(() => {
|
|
107
|
+
const side = toValue(position);
|
|
108
|
+
return side === "top" || side === "bottom";
|
|
109
|
+
});
|
|
108
110
|
const {
|
|
109
111
|
snappedY,
|
|
110
112
|
snappedX,
|
|
111
|
-
activeSnapPoint,
|
|
112
|
-
snapTo,
|
|
113
|
-
snapPointsMap,
|
|
114
|
-
interpolateDragged,
|
|
115
|
-
findClosestSnapPoint,
|
|
116
113
|
drawerHeight,
|
|
117
|
-
drawerWidth
|
|
114
|
+
drawerWidth,
|
|
115
|
+
mappedSnapPoints,
|
|
116
|
+
mappedRanges,
|
|
117
|
+
rangeAt,
|
|
118
|
+
snapPointAt,
|
|
119
|
+
restingOffset,
|
|
120
|
+
isSnapTarget,
|
|
121
|
+
snapTo,
|
|
122
|
+
interpolateDragged
|
|
118
123
|
} = useDrawerSnap({
|
|
119
124
|
id,
|
|
120
125
|
wrapperRect,
|
|
@@ -124,7 +129,8 @@ export function useDrawerDrag(args) {
|
|
|
124
129
|
position,
|
|
125
130
|
overshoot,
|
|
126
131
|
draggedY,
|
|
127
|
-
draggedX
|
|
132
|
+
draggedX,
|
|
133
|
+
activeSnapPoint
|
|
128
134
|
});
|
|
129
135
|
const { canDrag, canInterpolate, lockScroll } = useDrawerGuards({
|
|
130
136
|
elRef,
|
|
@@ -142,96 +148,79 @@ export function useDrawerDrag(args) {
|
|
|
142
148
|
wrapperRect.value = wrapper ? markRaw(wrapper.getBoundingClientRect()) : void 0;
|
|
143
149
|
await nextTick();
|
|
144
150
|
}
|
|
145
|
-
function
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
draggedY: 0,
|
|
171
|
-
direction: relDirectionX.value
|
|
172
|
-
});
|
|
173
|
-
if (Math.abs(snapPointX ?? 0) === drawerWidth.value) {
|
|
174
|
-
shouldClose.value = true;
|
|
175
|
-
} else {
|
|
176
|
-
interpolateTo.value = snapPointX;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
151
|
+
function snapDrag() {
|
|
152
|
+
const layout = {
|
|
153
|
+
points: mappedSnapPoints.value,
|
|
154
|
+
ranges: mappedRanges.value,
|
|
155
|
+
mode: snapMode.value
|
|
156
|
+
};
|
|
157
|
+
return isVertical.value ? {
|
|
158
|
+
...layout,
|
|
159
|
+
rest: snappedY.value,
|
|
160
|
+
start: lastDraggedY.value,
|
|
161
|
+
position: draggedY.value
|
|
162
|
+
} : {
|
|
163
|
+
...layout,
|
|
164
|
+
rest: snappedX.value,
|
|
165
|
+
start: lastDraggedX.value,
|
|
166
|
+
position: draggedX.value
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function isClosing(offset) {
|
|
170
|
+
const extent = isVertical.value ? drawerHeight.value : drawerWidth.value;
|
|
171
|
+
if (extent <= 0) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (Math.abs(offset) === extent) {
|
|
175
|
+
return true;
|
|
181
176
|
}
|
|
177
|
+
const side = toValue(position);
|
|
178
|
+
const closed = side === "bottom" || side === "right" ? extent : -extent;
|
|
179
|
+
const rest = isVertical.value ? snappedY.value : snappedX.value;
|
|
180
|
+
const range = rangeAt(offset);
|
|
181
|
+
const reachesClosed = range?.min === closed || range?.max === closed;
|
|
182
|
+
const towardClosed = Math.abs(closed - offset) < Math.abs(closed - rest);
|
|
183
|
+
return hasDragged.value && reachesClosed && towardClosed && Math.abs(closed - offset) <= toValue(threshold).distance;
|
|
184
|
+
}
|
|
185
|
+
function settleTarget() {
|
|
186
|
+
const target = snapRelease({
|
|
187
|
+
...snapDrag(),
|
|
188
|
+
committed: interpolateTo.value,
|
|
189
|
+
flicked,
|
|
190
|
+
tapped: !hasDragged.value
|
|
191
|
+
});
|
|
192
|
+
return restingOffset(target);
|
|
182
193
|
}
|
|
183
194
|
function checkMomentum() {
|
|
184
195
|
const elapsed = Date.now() - dragStart.value.getTime();
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
shouldClose.value = true;
|
|
200
|
-
} else {
|
|
201
|
-
interpolateTo.value = snapPointY;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case "right":
|
|
207
|
-
case "left": {
|
|
208
|
-
if (velocityX > toValue(threshold).momentum) {
|
|
209
|
-
const snapPointX = findClosestSnapPoint({
|
|
210
|
-
draggedX: draggedRefX.value,
|
|
211
|
-
draggedY,
|
|
212
|
-
direction: relDirectionX.value
|
|
213
|
-
});
|
|
214
|
-
if (Math.abs(snapPointX ?? 0) === drawerWidth.value) {
|
|
215
|
-
shouldClose.value = true;
|
|
216
|
-
} else {
|
|
217
|
-
interpolateTo.value = snapPointX;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
196
|
+
const { position: dragged, start } = snapDrag();
|
|
197
|
+
const distance = Math.abs(dragged - start);
|
|
198
|
+
const velocity = elapsed && distance ? distance / elapsed : 0;
|
|
199
|
+
flicked = velocity > toValue(threshold).momentum;
|
|
200
|
+
}
|
|
201
|
+
function checkPosition() {
|
|
202
|
+
const direction = isVertical.value ? relDirectionY.value : relDirectionX.value;
|
|
203
|
+
interpolateTo.value = snapCommit({
|
|
204
|
+
...snapDrag(),
|
|
205
|
+
distance: toValue(threshold).distance,
|
|
206
|
+
flicked,
|
|
207
|
+
flickDirection: direction === "absolute" ? void 0 : direction
|
|
208
|
+
});
|
|
209
|
+
shouldClose.value = isClosing(settleTarget());
|
|
223
210
|
}
|
|
224
211
|
function emitWillSnapTo() {
|
|
225
|
-
const target = interpolateTo.value || interpolateTo.value === 0 ? interpolateTo.value : position === "top" || position === "bottom" ? snappedY.value : snappedX.value;
|
|
226
212
|
if (shouldClose.value) {
|
|
227
213
|
return;
|
|
228
214
|
}
|
|
229
|
-
|
|
215
|
+
const target = settleTarget();
|
|
216
|
+
const isPoint = mappedSnapPoints.value.includes(target);
|
|
217
|
+
const pending = !isPoint && rangeAt(target)?.range || target;
|
|
218
|
+
if (pending === lastPendingTarget) {
|
|
230
219
|
return;
|
|
231
220
|
}
|
|
232
|
-
lastPendingTarget =
|
|
233
|
-
const snapPoint =
|
|
234
|
-
if (
|
|
221
|
+
lastPendingTarget = pending;
|
|
222
|
+
const snapPoint = snapPointAt(target);
|
|
223
|
+
if (snapPoint === void 0) {
|
|
235
224
|
return;
|
|
236
225
|
}
|
|
237
226
|
emitter.emit("willSnapTo", {
|
|
@@ -239,6 +228,27 @@ export function useDrawerDrag(args) {
|
|
|
239
228
|
snapPoint
|
|
240
229
|
});
|
|
241
230
|
}
|
|
231
|
+
function settle(target) {
|
|
232
|
+
if (shouldClose.value) {
|
|
233
|
+
close();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const destination = settleTarget();
|
|
237
|
+
const snapped = isVertical.value ? snappedY.value : snappedX.value;
|
|
238
|
+
if (destination === snapped && interpolateTo.value === void 0) {
|
|
239
|
+
interpolateDragged({ to: snapped });
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
activeSnapPoint.value = snapPointAt(destination);
|
|
243
|
+
if (isVertical.value) {
|
|
244
|
+
snappedY.value = destination;
|
|
245
|
+
} else {
|
|
246
|
+
snappedX.value = destination;
|
|
247
|
+
}
|
|
248
|
+
if (scrollLock && scrollLock.value || canInterpolate(target)) {
|
|
249
|
+
interpolateDragged({ to: destination });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
242
252
|
function setDragged({ x, y }) {
|
|
243
253
|
const os = toValue(overshoot);
|
|
244
254
|
switch (position) {
|
|
@@ -336,14 +346,23 @@ export function useDrawerDrag(args) {
|
|
|
336
346
|
resetSnapState();
|
|
337
347
|
}
|
|
338
348
|
}
|
|
349
|
+
function isUnknownSnapPoint(snapPoint) {
|
|
350
|
+
return !!wrapperRect.value && !isSnapTarget(snapPoint);
|
|
351
|
+
}
|
|
339
352
|
function snapToCallback(payload) {
|
|
340
353
|
if (payload.id === toValue(id)) {
|
|
354
|
+
const snapPoint = payload.snapPoint;
|
|
341
355
|
if (!toValue(isActive)) {
|
|
342
356
|
logWarning("Cannot snap to point when drawer is not open");
|
|
343
357
|
return;
|
|
358
|
+
} else if (isUnknownSnapPoint(snapPoint)) {
|
|
359
|
+
logWarning(
|
|
360
|
+
`Cannot snap to ${snapPoint}, which is neither a snap point nor inside a range`
|
|
361
|
+
);
|
|
362
|
+
return;
|
|
344
363
|
} else {
|
|
345
364
|
snapTo({
|
|
346
|
-
snapPoint
|
|
365
|
+
snapPoint,
|
|
347
366
|
interpolate: true,
|
|
348
367
|
duration: payload.duration
|
|
349
368
|
});
|
|
@@ -414,41 +433,7 @@ export function useDrawerDrag(args) {
|
|
|
414
433
|
});
|
|
415
434
|
}
|
|
416
435
|
function onPointerup(e) {
|
|
417
|
-
|
|
418
|
-
close();
|
|
419
|
-
} else if (interpolateTo.value || interpolateTo.value === 0) {
|
|
420
|
-
if (scrollLock && scrollLock.value || canInterpolate(e.target)) {
|
|
421
|
-
interpolateDragged({
|
|
422
|
-
to: interpolateTo.value
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
activeSnapPoint.value = snapPointsMap.value[interpolateTo.value];
|
|
426
|
-
switch (position) {
|
|
427
|
-
case "bottom":
|
|
428
|
-
case "top":
|
|
429
|
-
snappedY.value = interpolateTo.value;
|
|
430
|
-
break;
|
|
431
|
-
case "right":
|
|
432
|
-
case "left":
|
|
433
|
-
snappedX.value = interpolateTo.value;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
switch (position) {
|
|
438
|
-
case "bottom":
|
|
439
|
-
case "top":
|
|
440
|
-
interpolateDragged({
|
|
441
|
-
to: snappedY.value
|
|
442
|
-
});
|
|
443
|
-
break;
|
|
444
|
-
case "right":
|
|
445
|
-
case "left":
|
|
446
|
-
interpolateDragged({
|
|
447
|
-
to: snappedX.value
|
|
448
|
-
});
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
436
|
+
settle(e.target);
|
|
452
437
|
emitter.emit("afterDrag", {
|
|
453
438
|
id: toValue(id),
|
|
454
439
|
x: draggedX.value,
|
|
@@ -471,8 +456,6 @@ export function useDrawerDrag(args) {
|
|
|
471
456
|
return;
|
|
472
457
|
}
|
|
473
458
|
checkDirection({ x: firstTouch.clientX, y: firstTouch.clientY });
|
|
474
|
-
shouldClose.value = false;
|
|
475
|
-
checkDirection({ x: firstTouch.clientX, y: firstTouch.clientY });
|
|
476
459
|
if (!scrollLock) {
|
|
477
460
|
const scrollLockTarget = lockScroll(firstTouch.target);
|
|
478
461
|
if (scrollLockTarget) {
|
|
@@ -498,41 +481,7 @@ export function useDrawerDrag(args) {
|
|
|
498
481
|
});
|
|
499
482
|
}
|
|
500
483
|
function onTouchend(e) {
|
|
501
|
-
|
|
502
|
-
close();
|
|
503
|
-
} else if (interpolateTo.value || interpolateTo.value === 0) {
|
|
504
|
-
if (scrollLock && scrollLock.value || canInterpolate(e.target)) {
|
|
505
|
-
interpolateDragged({
|
|
506
|
-
to: interpolateTo.value
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
activeSnapPoint.value = snapPointsMap.value[interpolateTo.value];
|
|
510
|
-
switch (position) {
|
|
511
|
-
case "bottom":
|
|
512
|
-
case "top":
|
|
513
|
-
snappedY.value = interpolateTo.value;
|
|
514
|
-
break;
|
|
515
|
-
case "right":
|
|
516
|
-
case "left":
|
|
517
|
-
snappedX.value = interpolateTo.value;
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
|
-
} else {
|
|
521
|
-
switch (position) {
|
|
522
|
-
case "bottom":
|
|
523
|
-
case "top":
|
|
524
|
-
interpolateDragged({
|
|
525
|
-
to: snappedY.value
|
|
526
|
-
});
|
|
527
|
-
break;
|
|
528
|
-
case "right":
|
|
529
|
-
case "left":
|
|
530
|
-
interpolateDragged({
|
|
531
|
-
to: snappedX.value
|
|
532
|
-
});
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
484
|
+
settle(e.target);
|
|
536
485
|
emitter.emit("afterDrag", {
|
|
537
486
|
id: toValue(id),
|
|
538
487
|
x: draggedX.value,
|
|
@@ -557,6 +506,7 @@ export function useDrawerDrag(args) {
|
|
|
557
506
|
}
|
|
558
507
|
dragging.value = true;
|
|
559
508
|
lastPendingTarget = void 0;
|
|
509
|
+
flicked = false;
|
|
560
510
|
pointerdownTarget = e.target;
|
|
561
511
|
guardedSetPointerCapture({
|
|
562
512
|
event: e,
|
|
@@ -618,6 +568,7 @@ export function useDrawerDrag(args) {
|
|
|
618
568
|
e.stopPropagation();
|
|
619
569
|
dragging.value = true;
|
|
620
570
|
lastPendingTarget = void 0;
|
|
571
|
+
flicked = false;
|
|
621
572
|
pointerdownTarget = e.target;
|
|
622
573
|
emitter.emit("beforeDrag", {
|
|
623
574
|
id: toValue(id),
|
|
@@ -657,9 +608,17 @@ export function useDrawerDrag(args) {
|
|
|
657
608
|
async () => {
|
|
658
609
|
await getSizes();
|
|
659
610
|
const snapPoint = toValue(initial)?.snapPoint;
|
|
660
|
-
if (snapPoint) {
|
|
661
|
-
|
|
611
|
+
if (!snapPoint) {
|
|
612
|
+
activeSnapPoint.value = snapPointAt(0);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (isUnknownSnapPoint(snapPoint)) {
|
|
616
|
+
logWarning(
|
|
617
|
+
`initial.snapPoint (${snapPoint}) is neither a snap point nor inside a range and is ignored`
|
|
618
|
+
);
|
|
619
|
+
return;
|
|
662
620
|
}
|
|
621
|
+
snapTo({ snapPoint, interpolate: false });
|
|
663
622
|
}
|
|
664
623
|
);
|
|
665
624
|
watch([snappedX, snappedY], ([x, y]) => {
|
|
@@ -679,7 +638,6 @@ export function useDrawerDrag(args) {
|
|
|
679
638
|
await getSizes();
|
|
680
639
|
if (activeSnapPoint.value) {
|
|
681
640
|
await snapTo({ snapPoint: activeSnapPoint.value, interpolate: false });
|
|
682
|
-
snapPointsMap.trigger();
|
|
683
641
|
}
|
|
684
642
|
}, 100)();
|
|
685
643
|
});
|
|
@@ -14,6 +14,10 @@ import { useDrawerState } from "./useDrawerState.mjs";
|
|
|
14
14
|
export function useDrawerProgress(args) {
|
|
15
15
|
const { id, drawerRef, elRef, position, overshoot } = args;
|
|
16
16
|
const { initializeState } = useDrawerState(id);
|
|
17
|
+
const emitter = useMagicEmitter();
|
|
18
|
+
const state = initializeState();
|
|
19
|
+
const { draggedX, draggedY, wrapperRect } = toRefs(state);
|
|
20
|
+
let transitioning = false;
|
|
17
21
|
const drawerRect = useElementBounding(drawerRef);
|
|
18
22
|
const elRect = useElementBounding(elRef);
|
|
19
23
|
const maxX = computed(
|
|
@@ -22,27 +26,38 @@ export function useDrawerProgress(args) {
|
|
|
22
26
|
const maxY = computed(
|
|
23
27
|
() => drawerRect.height.value - elRect.height.value + toValue(overshoot)
|
|
24
28
|
);
|
|
25
|
-
const state = initializeState();
|
|
26
29
|
const { progress } = toRefs(state);
|
|
27
|
-
function
|
|
30
|
+
function setProgress(x, y) {
|
|
31
|
+
progress.value = {
|
|
32
|
+
x: clampValue(x, 0, 1) || 0,
|
|
33
|
+
y: clampValue(y, 0, 1) || 0
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function calculate() {
|
|
37
|
+
const rect = wrapperRect.value;
|
|
38
|
+
if (!rect) {
|
|
39
|
+
setProgress(0, 0);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const extentX = rect.width - toValue(overshoot);
|
|
43
|
+
const extentY = rect.height - toValue(overshoot);
|
|
44
|
+
switch (toValue(position)) {
|
|
45
|
+
case "top":
|
|
46
|
+
case "bottom":
|
|
47
|
+
setProgress(0, extentY ? 1 - Math.abs(draggedY.value) / extentY : 0);
|
|
48
|
+
break;
|
|
49
|
+
case "left":
|
|
50
|
+
case "right":
|
|
51
|
+
setProgress(extentX ? 1 - Math.abs(draggedX.value) / extentX : 0, 0);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function measure() {
|
|
28
56
|
drawerRect.update();
|
|
29
57
|
elRect.update();
|
|
30
|
-
calculateProgress();
|
|
31
|
-
}
|
|
32
|
-
const emitter = useMagicEmitter();
|
|
33
|
-
const { pause: snapPause, resume: snapResume } = useRafFn(rafCallback, {
|
|
34
|
-
immediate: false
|
|
35
|
-
});
|
|
36
|
-
const { pause: dragPause, resume: dragResume } = useRafFn(rafCallback, {
|
|
37
|
-
immediate: false
|
|
38
|
-
});
|
|
39
|
-
const { pause, resume } = useRafFn(rafCallback, {
|
|
40
|
-
immediate: false
|
|
41
|
-
});
|
|
42
|
-
function calculateProgress() {
|
|
43
58
|
let rawX = 0;
|
|
44
59
|
let rawY = 0;
|
|
45
|
-
switch (position) {
|
|
60
|
+
switch (toValue(position)) {
|
|
46
61
|
case "bottom":
|
|
47
62
|
rawY = mapValue(
|
|
48
63
|
elRect.top.value,
|
|
@@ -80,81 +95,46 @@ export function useDrawerProgress(args) {
|
|
|
80
95
|
);
|
|
81
96
|
break;
|
|
82
97
|
}
|
|
83
|
-
|
|
84
|
-
rawX = 0;
|
|
85
|
-
}
|
|
86
|
-
if (Object.is(rawY, -0)) {
|
|
87
|
-
rawY = 0;
|
|
88
|
-
}
|
|
89
|
-
const x = clampValue(rawX, 0, 1);
|
|
90
|
-
const y = clampValue(rawY, 0, 1);
|
|
91
|
-
progress.value = { x, y };
|
|
98
|
+
setProgress(rawX, rawY);
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
id: toValue(id),
|
|
96
|
-
x,
|
|
97
|
-
y
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
function beforeCallback(payload) {
|
|
100
|
+
const { pause, resume } = useRafFn(measure, { immediate: false });
|
|
101
|
+
function beforeTransition(payload) {
|
|
101
102
|
if (payload === toValue(id)) {
|
|
103
|
+
transitioning = true;
|
|
102
104
|
resume();
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
function
|
|
106
|
-
if (payload.id === toValue(id)) {
|
|
107
|
-
snapResume();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function beforeDragCallback(payload) {
|
|
111
|
-
if (payload.id === toValue(id)) {
|
|
112
|
-
dragResume();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function afterCallback(payload) {
|
|
107
|
+
async function afterTransition(payload) {
|
|
116
108
|
await nextTick();
|
|
117
109
|
if (payload === toValue(id)) {
|
|
118
110
|
pause();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function afterSnapCallback(payload) {
|
|
124
|
-
await nextTick();
|
|
125
|
-
if (payload.id === toValue(id)) {
|
|
126
|
-
snapPause();
|
|
127
|
-
await nextTick();
|
|
128
|
-
rafCallback();
|
|
111
|
+
transitioning = false;
|
|
112
|
+
calculate();
|
|
129
113
|
}
|
|
130
114
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
dragPause();
|
|
135
|
-
await nextTick();
|
|
136
|
-
rafCallback();
|
|
115
|
+
watch([draggedX, draggedY, wrapperRect, () => toValue(overshoot)], () => {
|
|
116
|
+
if (!transitioning) {
|
|
117
|
+
calculate();
|
|
137
118
|
}
|
|
138
|
-
}
|
|
119
|
+
});
|
|
120
|
+
watch([() => progress.value.x, () => progress.value.y], ([x, y]) => {
|
|
121
|
+
emitter.emit("progress", {
|
|
122
|
+
id: toValue(id),
|
|
123
|
+
x,
|
|
124
|
+
y
|
|
125
|
+
});
|
|
126
|
+
});
|
|
139
127
|
onMounted(() => {
|
|
140
|
-
emitter.on("beforeEnter",
|
|
141
|
-
emitter.on("afterEnter",
|
|
142
|
-
emitter.on("
|
|
143
|
-
emitter.on("
|
|
144
|
-
emitter.on("beforeSnap", beforeSnapCallback);
|
|
145
|
-
emitter.on("afterSnap", afterSnapCallback);
|
|
146
|
-
emitter.on("beforeLeave", beforeCallback);
|
|
147
|
-
emitter.on("afterLeave", afterCallback);
|
|
128
|
+
emitter.on("beforeEnter", beforeTransition);
|
|
129
|
+
emitter.on("afterEnter", afterTransition);
|
|
130
|
+
emitter.on("beforeLeave", beforeTransition);
|
|
131
|
+
emitter.on("afterLeave", afterTransition);
|
|
148
132
|
});
|
|
149
133
|
onBeforeUnmount(() => {
|
|
150
|
-
emitter.off("beforeEnter",
|
|
151
|
-
emitter.off("afterEnter",
|
|
152
|
-
emitter.off("
|
|
153
|
-
emitter.off("
|
|
154
|
-
emitter.off("beforeSnap", beforeSnapCallback);
|
|
155
|
-
emitter.off("afterSnap", afterSnapCallback);
|
|
156
|
-
emitter.off("beforeLeave", beforeCallback);
|
|
157
|
-
emitter.off("afterLeave", afterCallback);
|
|
134
|
+
emitter.off("beforeEnter", beforeTransition);
|
|
135
|
+
emitter.off("afterEnter", afterTransition);
|
|
136
|
+
emitter.off("beforeLeave", beforeTransition);
|
|
137
|
+
emitter.off("afterLeave", afterTransition);
|
|
158
138
|
});
|
|
159
139
|
return { progress };
|
|
160
140
|
}
|