@abraca/nuxt 2.87.0 → 2.88.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/module.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export interface EdgeSwipeOptions {
|
|
3
|
+
/** A swipe that began at the left edge and travelled inward. */
|
|
4
|
+
onFromLeft?: () => void;
|
|
5
|
+
/** A swipe that began at the right edge and travelled inward. */
|
|
6
|
+
onFromRight?: () => void;
|
|
7
|
+
/** Turn the whole thing off without unmounting the caller. */
|
|
8
|
+
disabled?: MaybeRefOrGetter<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* How far from an edge a touch counts as an edge touch.
|
|
11
|
+
*
|
|
12
|
+
* 50px by default, which is deliberately WIDER than iOS's own back-swipe
|
|
13
|
+
* zone (~30–40px): a gesture that competes with the browser's has to be
|
|
14
|
+
* recognised before the browser recognises its own.
|
|
15
|
+
*/
|
|
16
|
+
edge?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The narrower band where an edge swipe wins even inside something that
|
|
19
|
+
* scrolls horizontally.
|
|
20
|
+
*
|
|
21
|
+
* A renderer that owns its horizontal axis — a kanban, a map, a timeline —
|
|
22
|
+
* would otherwise trap the reader: every swipe belongs to the renderer and
|
|
23
|
+
* nothing can be opened from inside it. 20px is enough to reach and small
|
|
24
|
+
* enough not to steal the renderer's own gestures.
|
|
25
|
+
*/
|
|
26
|
+
forceEdge?: number;
|
|
27
|
+
/** Minimum inward travel before it counts. */
|
|
28
|
+
threshold?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Also stop the BROWSER acting on the gesture.
|
|
31
|
+
*
|
|
32
|
+
* This is the whole reason edge handling is separate from an ordinary swipe:
|
|
33
|
+
* without `preventDefault` on an edge touch, iOS runs its own back-navigation
|
|
34
|
+
* and the app's gesture and the browser's fight over the same finger. Costs a
|
|
35
|
+
* non-passive `touchmove`, which is why it is a choice.
|
|
36
|
+
*/
|
|
37
|
+
preventBrowserGesture?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A swipe that starts at the screen's edge — the gesture that opens things.
|
|
41
|
+
*
|
|
42
|
+
* Distinct from `useSwipeGesture`, which watches an ELEMENT and tells you which
|
|
43
|
+
* way a finger travelled across it. This watches the WINDOW, cares where the
|
|
44
|
+
* finger started, and exists mostly to win an argument with the browser.
|
|
45
|
+
*
|
|
46
|
+
* Two zones and a scroll check, all three earned in cou-sh:
|
|
47
|
+
*
|
|
48
|
+
* - anything inside `data-swipe-ignore`, or inside a container that actually
|
|
49
|
+
* scrolls horizontally, keeps its own gesture — unless the touch began in
|
|
50
|
+
* the narrow `forceEdge` band;
|
|
51
|
+
* - a touch that starts on a control (a button, a link, an input) is not a
|
|
52
|
+
* swipe, so the control still works at the edge of the screen;
|
|
53
|
+
* - a gesture that travels mostly VERTICALLY is a scroll, not an edge swipe.
|
|
54
|
+
*
|
|
55
|
+
* Client-only by construction: it binds in `onMounted`-free fashion via a guard
|
|
56
|
+
* on `window`, and disposes with the calling scope.
|
|
57
|
+
*/
|
|
58
|
+
export declare function useEdgeSwipe(options?: EdgeSwipeOptions): void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { onScopeDispose, toValue } from "vue";
|
|
2
|
+
export function useEdgeSwipe(options = {}) {
|
|
3
|
+
if (typeof window === "undefined") return;
|
|
4
|
+
const EDGE = options.edge ?? 50;
|
|
5
|
+
const FORCE_EDGE = options.forceEdge ?? 20;
|
|
6
|
+
const THRESHOLD = options.threshold ?? 60;
|
|
7
|
+
const VERTICAL_SLOP = 40;
|
|
8
|
+
let startX = 0;
|
|
9
|
+
let startY = 0;
|
|
10
|
+
let fromLeft = false;
|
|
11
|
+
let fromRight = false;
|
|
12
|
+
let tracking = false;
|
|
13
|
+
let fired = false;
|
|
14
|
+
function scrollsHorizontally(target) {
|
|
15
|
+
let el = target;
|
|
16
|
+
let depth = 0;
|
|
17
|
+
while (el && el !== document.documentElement && depth < 15) {
|
|
18
|
+
if (el.hasAttribute("data-swipe-ignore")) return true;
|
|
19
|
+
const style = getComputedStyle(el);
|
|
20
|
+
if (style.overflowX === "auto" || style.overflowX === "scroll") {
|
|
21
|
+
const box = el;
|
|
22
|
+
if (box.scrollWidth > box.clientWidth) return true;
|
|
23
|
+
}
|
|
24
|
+
el = el.parentElement;
|
|
25
|
+
depth++;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function onTouchStart(e) {
|
|
30
|
+
tracking = false;
|
|
31
|
+
fired = false;
|
|
32
|
+
if (toValue(options.disabled)) return;
|
|
33
|
+
if (e.touches.length !== 1) return;
|
|
34
|
+
const touch = e.touches[0];
|
|
35
|
+
startX = touch.clientX;
|
|
36
|
+
startY = touch.clientY;
|
|
37
|
+
const atLeft = startX < EDGE;
|
|
38
|
+
const atRight = window.innerWidth - startX < EDGE;
|
|
39
|
+
if (!atLeft && !atRight) return;
|
|
40
|
+
const target = e.target;
|
|
41
|
+
if (target?.closest?.('button, a, input, textarea, select, label, [role="button"]')) return;
|
|
42
|
+
const forced = startX < FORCE_EDGE || window.innerWidth - startX < FORCE_EDGE;
|
|
43
|
+
if (scrollsHorizontally(target) && !forced) return;
|
|
44
|
+
fromLeft = atLeft;
|
|
45
|
+
fromRight = atRight && !atLeft;
|
|
46
|
+
tracking = true;
|
|
47
|
+
}
|
|
48
|
+
function onTouchMove(e) {
|
|
49
|
+
if (!tracking || fired) return;
|
|
50
|
+
const touch = e.touches[0];
|
|
51
|
+
if (!touch) return;
|
|
52
|
+
const dx = touch.clientX - startX;
|
|
53
|
+
const dy = touch.clientY - startY;
|
|
54
|
+
if (Math.abs(dy) > VERTICAL_SLOP && Math.abs(dy) > Math.abs(dx)) {
|
|
55
|
+
tracking = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (options.preventBrowserGesture && e.cancelable) e.preventDefault();
|
|
59
|
+
if (fromLeft && dx > THRESHOLD) {
|
|
60
|
+
fired = true;
|
|
61
|
+
options.onFromLeft?.();
|
|
62
|
+
} else if (fromRight && dx < -THRESHOLD) {
|
|
63
|
+
fired = true;
|
|
64
|
+
options.onFromRight?.();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function onTouchEnd() {
|
|
68
|
+
tracking = false;
|
|
69
|
+
fired = false;
|
|
70
|
+
}
|
|
71
|
+
const moveOptions = { passive: !options.preventBrowserGesture };
|
|
72
|
+
window.addEventListener("touchstart", onTouchStart, { passive: true });
|
|
73
|
+
window.addEventListener("touchmove", onTouchMove, moveOptions);
|
|
74
|
+
window.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
75
|
+
window.addEventListener("touchcancel", onTouchEnd, { passive: true });
|
|
76
|
+
onScopeDispose(() => {
|
|
77
|
+
window.removeEventListener("touchstart", onTouchStart);
|
|
78
|
+
window.removeEventListener("touchmove", onTouchMove);
|
|
79
|
+
window.removeEventListener("touchend", onTouchEnd);
|
|
80
|
+
window.removeEventListener("touchcancel", onTouchEnd);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -22,6 +22,28 @@ export interface SwipeGestureOptions {
|
|
|
22
22
|
disabled?: MaybeRefOrGetter<boolean>;
|
|
23
23
|
/** Restrict to a single axis. Gestures on the other axis pass through. */
|
|
24
24
|
axis?: 'x' | 'y';
|
|
25
|
+
/**
|
|
26
|
+
* Which input may fire this gesture.
|
|
27
|
+
*
|
|
28
|
+
* `any` (the default) keeps the trackpad: a deck, a slideover and a window
|
|
29
|
+
* manager are PAGERS, and paging them with a two-finger flick is the whole
|
|
30
|
+
* point of the wheel half.
|
|
31
|
+
*
|
|
32
|
+
* `touch` is for surfaces where a horizontal wheel is not a gesture but an
|
|
33
|
+
* accident. A reading page is the example: on a Mac, brushing sideways past a
|
|
34
|
+
* wide code block emits exactly the deltas this composable counts, and the
|
|
35
|
+
* reader is navigated away from the page they were reading. Measured, not
|
|
36
|
+
* theorised — eight `deltaX: 25` events took a documentation page to its
|
|
37
|
+
* neighbour.
|
|
38
|
+
*/
|
|
39
|
+
pointer?: 'any' | 'touch';
|
|
40
|
+
/**
|
|
41
|
+
* Damping multiplier for a valid direction. `0` follows the finger with no
|
|
42
|
+
* visible offset at all — which is what a caller passes for a reader who has
|
|
43
|
+
* asked their system for less motion: the gesture still fires, the rubber
|
|
44
|
+
* band is simply not drawn.
|
|
45
|
+
*/
|
|
46
|
+
damp?: MaybeRefOrGetter<number>;
|
|
25
47
|
}
|
|
26
48
|
/**
|
|
27
49
|
* Swipe gesture detection for both touch (mobile) and trackpad/wheel (desktop).
|
|
@@ -31,7 +53,16 @@ export interface SwipeGestureOptions {
|
|
|
31
53
|
*
|
|
32
54
|
* A child with `data-swipe-ignore` lets its own touch-scroll pass through.
|
|
33
55
|
*
|
|
34
|
-
*
|
|
56
|
+
* Shared with cou-sh, which is where this shape was proven. Two things beyond
|
|
57
|
+
* that port, both of which a SITE needs and a dashboard did not:
|
|
58
|
+
*
|
|
59
|
+
* - `disabled` is re-checked on move and on end. It can flip true AFTER
|
|
60
|
+
* `touchstart` — a drag taking over the pointer mid-gesture is the usual
|
|
61
|
+
* way — and an in-flight swipe must then abort and snap back rather than
|
|
62
|
+
* finish and navigate.
|
|
63
|
+
* - `damp` is a caller's, so `prefers-reduced-motion` can be honoured by the
|
|
64
|
+
* thing that knows about it. `damp: 0` still fires the gesture and simply
|
|
65
|
+
* does not draw the rubber band.
|
|
35
66
|
*/
|
|
36
67
|
export declare function useSwipeGesture(options: SwipeGestureOptions): {
|
|
37
68
|
swipeOffset: Ref<{
|
|
@@ -10,6 +10,8 @@ export function useSwipeGesture(options) {
|
|
|
10
10
|
const SWIPE_TRIGGER = 24;
|
|
11
11
|
const DAMP_VALID = 0.4;
|
|
12
12
|
const DAMP_INVALID = 0.1;
|
|
13
|
+
const dampValid = () => toValue(options.damp) ?? DAMP_VALID;
|
|
14
|
+
const dampInvalid = () => toValue(options.damp) == null ? DAMP_INVALID : dampValid() * 0.25;
|
|
13
15
|
function isInsideSwipeIgnore(target, boundary) {
|
|
14
16
|
let el = target;
|
|
15
17
|
while (el && el !== boundary) {
|
|
@@ -35,8 +37,17 @@ export function useSwipeGesture(options) {
|
|
|
35
37
|
isSwiping.value = false;
|
|
36
38
|
swipeOffset.value = { x: 0, y: 0 };
|
|
37
39
|
}
|
|
40
|
+
function resetSwipe() {
|
|
41
|
+
swipeOffset.value = { x: 0, y: 0 };
|
|
42
|
+
isSwiping.value = false;
|
|
43
|
+
touchLockedAxis = null;
|
|
44
|
+
}
|
|
38
45
|
function onTouchMove(e) {
|
|
39
46
|
if (touchIgnored) return;
|
|
47
|
+
if (toValue(options.disabled)) {
|
|
48
|
+
resetSwipe();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
40
51
|
const touch = e.touches[0];
|
|
41
52
|
const dx = touch.clientX - touchStartX;
|
|
42
53
|
const dy = touch.clientY - touchStartY;
|
|
@@ -51,17 +62,21 @@ export function useSwipeGesture(options) {
|
|
|
51
62
|
const canL = toValue(options.canSwipeLeft) ?? !!options.onSwipeLeft;
|
|
52
63
|
const canR = toValue(options.canSwipeRight) ?? !!options.onSwipeRight;
|
|
53
64
|
const valid = dx < 0 && canL || dx > 0 && canR;
|
|
54
|
-
swipeOffset.value = { x: dx * (valid ?
|
|
65
|
+
swipeOffset.value = { x: dx * (valid ? dampValid() : dampInvalid()), y: 0 };
|
|
55
66
|
} else {
|
|
56
67
|
const canU = toValue(options.canSwipeUp) ?? !!options.onSwipeUp;
|
|
57
68
|
const canD = toValue(options.canSwipeDown) ?? !!options.onSwipeDown;
|
|
58
69
|
const valid = dy < 0 && canU || dy > 0 && canD;
|
|
59
|
-
swipeOffset.value = { x: 0, y: dy * (valid ?
|
|
70
|
+
swipeOffset.value = { x: 0, y: dy * (valid ? dampValid() : dampInvalid()) };
|
|
60
71
|
}
|
|
61
72
|
e.preventDefault();
|
|
62
73
|
}
|
|
63
74
|
function onTouchEnd() {
|
|
64
75
|
if (touchIgnored) return;
|
|
76
|
+
if (toValue(options.disabled)) {
|
|
77
|
+
resetSwipe();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
65
80
|
if (touchLockedAxis === "x" && Math.abs(swipeOffset.value.x) > SWIPE_TRIGGER) {
|
|
66
81
|
if (swipeOffset.value.x < 0) options.onSwipeLeft?.();
|
|
67
82
|
else options.onSwipeRight?.();
|
|
@@ -85,6 +100,7 @@ export function useSwipeGesture(options) {
|
|
|
85
100
|
wheelTimer = null;
|
|
86
101
|
}
|
|
87
102
|
function onWheel(e) {
|
|
103
|
+
if (options.pointer === "touch") return;
|
|
88
104
|
if (toValue(options.disabled)) return;
|
|
89
105
|
if (e.ctrlKey) return;
|
|
90
106
|
wheelAccumX += e.deltaX;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/nuxt",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.88.0",
|
|
4
4
|
"description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
|
|
5
5
|
"repository": "abracadabra/abracadabra-nuxt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -173,9 +173,9 @@
|
|
|
173
173
|
}
|
|
174
174
|
},
|
|
175
175
|
"devDependencies": {
|
|
176
|
-
"@abraca/convert": "^2.
|
|
177
|
-
"@abraca/dabra": "^2.
|
|
178
|
-
"@abraca/plugin": "^2.
|
|
176
|
+
"@abraca/convert": "^2.87.0",
|
|
177
|
+
"@abraca/dabra": "^2.87.0",
|
|
178
|
+
"@abraca/plugin": "^2.87.0",
|
|
179
179
|
"@codemirror/autocomplete": "^6.18.0",
|
|
180
180
|
"@codemirror/commands": "^6.7.0",
|
|
181
181
|
"@codemirror/lang-css": "^6.3.1",
|