shelving 1.328.1 → 1.328.3

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.
@@ -37706,6 +37706,7 @@ Swipe an element (or the whole page) to make a change, and scrub the change's vi
37706
37706
  - It does not start on a field, inside an element that can still scroll the other way, or inside a `<dialog>` that does not hold the target.
37707
37707
  - `edge` limits the start to a strip along the screen edge the finger moves away from, for example `24` for swipe-back from the left edge.
37708
37708
  - Only one swipe runs at a time. A swipe on `document` decides first, so an edge swipe wins over a swipe on an element below it.
37709
+ - While a swipe runs, the page does not scroll (also in Safari). If the end of a touch is lost, the next touch ends the swipe, so it never stays stuck halfway.
37709
37710
  - The swipe keeps working when `start` takes the touched element out of the page. If the content can keep state, hide it in a React `<Activity>` instead of unmounting it, so `cancel` can show it again as it was.
37710
37711
 
37711
37712
  ## Usage
@@ -22,6 +22,7 @@ Swipe an element (or the whole page) to make a change, and scrub the change's vi
22
22
  - It does not start on a field, inside an element that can still scroll the other way, or inside a `<dialog>` that does not hold the target.
23
23
  - `edge` limits the start to a strip along the screen edge the finger moves away from, for example `24` for swipe-back from the left edge.
24
24
  - Only one swipe runs at a time. A swipe on `document` decides first, so an edge swipe wins over a swipe on an element below it.
25
+ - While a swipe runs, the page does not scroll (also in Safari). If the end of a touch is lost, the next touch ends the swipe, so it never stays stuck halfway.
25
26
  - The swipe keeps working when `start` takes the touched element out of the page. If the content can keep state, hide it in a React `<Activity>` instead of unmounting it, so `cancel` can show it again as it was.
26
27
 
27
28
  ## Usage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.328.1",
3
+ "version": "1.328.3",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -6,11 +6,15 @@
6
6
  @layer components {
7
7
  .notices {
8
8
  position: fixed;
9
- right: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-right, 0px));
10
- left: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-left, 0px));
9
+ right: calc(var(--notices-offset, var(--space-normal)) - var(--space-normal) + env(safe-area-inset-right, 0px));
10
+ left: calc(var(--notices-offset, var(--space-normal)) - var(--space-normal) + env(safe-area-inset-left, 0px));
11
11
  z-index: 1000;
12
12
  display: flex;
13
- max-width: var(--notices-width, var(--width-narrow));
13
+ box-sizing: border-box;
14
+ max-width: calc(var(--notices-width, var(--width-narrow)) + 2 * var(--space-normal));
15
+
16
+ /* Room for the shadows inside the list's own box. The list has its own view transition layer, and Safari clips a named element to its box, so a shadow outside it is cut off. The offsets above take this room back off. */
17
+ padding: var(--space-normal);
14
18
  flex-direction: column;
15
19
  gap: var(--notices-gap, var(--space-small));
16
20
 
@@ -33,11 +37,11 @@
33
37
 
34
38
  /* Places. The list keeps `--notices-offset` clear of the edges, plus the safe area of the device. */
35
39
  .top {
36
- top: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-top, 0px));
40
+ top: calc(var(--notices-offset, var(--space-normal)) - var(--space-normal) + env(safe-area-inset-top, 0px));
37
41
  }
38
42
 
39
43
  .bottom {
40
- bottom: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-bottom, 0px));
44
+ bottom: calc(var(--notices-offset, var(--space-normal)) - var(--space-normal) + env(safe-area-inset-bottom, 0px));
41
45
  }
42
46
 
43
47
  .left {
@@ -41,13 +41,18 @@ export function useSwipe(target, options) {
41
41
  node?.removeEventListener("touchmove", onMove);
42
42
  node?.removeEventListener("touchend", onEnd);
43
43
  node?.removeEventListener("touchcancel", onEnd);
44
+ document.removeEventListener("touchend", onEnd, true);
45
+ document.removeEventListener("touchcancel", onEnd, true);
44
46
  node = undefined;
45
47
  };
46
48
  const onStart = (e) => {
47
49
  const touch = e.touches[0];
48
50
  const { disabled, edge, direction, ignore } = optionsRef.current;
49
51
  pending = false;
50
- if (disabled || _active || gesture || e.touches.length !== 1 || !touch)
52
+ // A new touch while a swipe still runs means its end was lost: end it now, so it never stays stuck halfway.
53
+ if (gesture)
54
+ onEnd(e);
55
+ if (disabled || _active || e.touches.length !== 1 || !touch)
51
56
  return;
52
57
  if (!(e.target instanceof Element) || e.target.closest(_FIELDS) || (ignore && e.target.closest(ignore)))
53
58
  return;
@@ -67,6 +72,9 @@ export function useSwipe(target, options) {
67
72
  node.addEventListener("touchmove", onMove, { passive: false });
68
73
  node.addEventListener("touchend", onEnd, { passive: true });
69
74
  node.addEventListener("touchcancel", onEnd, { passive: true });
75
+ // Also on the document, in case the browser sends the end somewhere else.
76
+ document.addEventListener("touchend", onEnd, { capture: true, passive: true });
77
+ document.addEventListener("touchcancel", onEnd, { capture: true, passive: true });
70
78
  };
71
79
  const onMove = (e) => {
72
80
  const touch = e.touches[0];
@@ -101,6 +109,9 @@ export function useSwipe(target, options) {
101
109
  gesture.scrub?.seek(distance / gesture.size);
102
110
  };
103
111
  const onEnd = (e) => {
112
+ // The document and the touched node both get the end. Act on it once.
113
+ if (!pending && !gesture)
114
+ return detach();
104
115
  pending = false;
105
116
  detach();
106
117
  const ended = gesture;
@@ -122,8 +133,15 @@ export function useSwipe(target, options) {
122
133
  // A swipe on `document` listens in the capture phase, so it decides before a swipe on an element below it.
123
134
  const listen = { capture, passive: true };
124
135
  el.addEventListener("touchstart", onStart, listen);
136
+ // A touchmove listener that is not passive must be on the target before the touch starts, or Safari scrolls the page and ignores `preventDefault()`.
137
+ const block = (e) => {
138
+ if (gesture && e.cancelable)
139
+ e.preventDefault();
140
+ };
141
+ el.addEventListener("touchmove", block, { capture, passive: false });
125
142
  return () => {
126
143
  el.removeEventListener("touchstart", onStart, listen);
144
+ el.removeEventListener("touchmove", block, { capture });
127
145
  // A swipe that runs now ends on its own: the update may unmount this component (for example a closed notice).
128
146
  if (!gesture)
129
147
  detach();
@@ -11,6 +11,7 @@ Swipe an element (or the whole page) to make a change, and scrub the change's vi
11
11
  - It does not start on a field, inside an element that can still scroll the other way, or inside a `<dialog>` that does not hold the target.
12
12
  - `edge` limits the start to a strip along the screen edge the finger moves away from, for example `24` for swipe-back from the left edge.
13
13
  - Only one swipe runs at a time. A swipe on `document` decides first, so an edge swipe wins over a swipe on an element below it.
14
+ - While a swipe runs, the page does not scroll (also in Safari). If the end of a touch is lost, the next touch ends the swipe, so it never stays stuck halfway.
14
15
  - The swipe keeps working when `start` takes the touched element out of the page. If the content can keep state, hide it in a React `<Activity>` instead of unmounting it, so `cancel` can show it again as it was.
15
16
 
16
17
  ## Usage
@@ -101,6 +101,8 @@ export function useSwipe(target: RefObject<Element | null> | Document, options:
101
101
  node?.removeEventListener("touchmove", onMove);
102
102
  node?.removeEventListener("touchend", onEnd);
103
103
  node?.removeEventListener("touchcancel", onEnd);
104
+ document.removeEventListener("touchend", onEnd, true);
105
+ document.removeEventListener("touchcancel", onEnd, true);
104
106
  node = undefined;
105
107
  };
106
108
 
@@ -108,7 +110,9 @@ export function useSwipe(target: RefObject<Element | null> | Document, options:
108
110
  const touch = (e as TouchEvent).touches[0];
109
111
  const { disabled, edge, direction, ignore } = optionsRef.current;
110
112
  pending = false;
111
- if (disabled || _active || gesture || (e as TouchEvent).touches.length !== 1 || !touch) return;
113
+ // A new touch while a swipe still runs means its end was lost: end it now, so it never stays stuck halfway.
114
+ if (gesture) onEnd(e);
115
+ if (disabled || _active || (e as TouchEvent).touches.length !== 1 || !touch) return;
112
116
  if (!(e.target instanceof Element) || e.target.closest(_FIELDS) || (ignore && e.target.closest(ignore))) return;
113
117
  // A touch inside a dialog never swipes something behind the dialog.
114
118
  if (e.target.closest("dialog") !== (capture ? null : (el as Element).closest("dialog"))) return;
@@ -123,6 +127,9 @@ export function useSwipe(target: RefObject<Element | null> | Document, options:
123
127
  node.addEventListener("touchmove", onMove, { passive: false });
124
128
  node.addEventListener("touchend", onEnd, { passive: true });
125
129
  node.addEventListener("touchcancel", onEnd, { passive: true });
130
+ // Also on the document, in case the browser sends the end somewhere else.
131
+ document.addEventListener("touchend", onEnd, { capture: true, passive: true });
132
+ document.addEventListener("touchcancel", onEnd, { capture: true, passive: true });
126
133
  };
127
134
 
128
135
  const onMove = (e: Event) => {
@@ -154,6 +161,8 @@ export function useSwipe(target: RefObject<Element | null> | Document, options:
154
161
  };
155
162
 
156
163
  const onEnd = (e: Event) => {
164
+ // The document and the touched node both get the end. Act on it once.
165
+ if (!pending && !gesture) return detach();
157
166
  pending = false;
158
167
  detach();
159
168
  const ended = gesture;
@@ -175,8 +184,14 @@ export function useSwipe(target: RefObject<Element | null> | Document, options:
175
184
  // A swipe on `document` listens in the capture phase, so it decides before a swipe on an element below it.
176
185
  const listen = { capture, passive: true };
177
186
  el.addEventListener("touchstart", onStart, listen);
187
+ // A touchmove listener that is not passive must be on the target before the touch starts, or Safari scrolls the page and ignores `preventDefault()`.
188
+ const block = (e: Event) => {
189
+ if (gesture && e.cancelable) e.preventDefault();
190
+ };
191
+ el.addEventListener("touchmove", block, { capture, passive: false });
178
192
  return () => {
179
193
  el.removeEventListener("touchstart", onStart, listen);
194
+ el.removeEventListener("touchmove", block, { capture });
180
195
  // A swipe that runs now ends on its own: the update may unmount this component (for example a closed notice).
181
196
  if (!gesture) detach();
182
197
  };