shelving 1.328.2 → 1.329.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.
@@ -31198,15 +31198,16 @@ function StackBar() {
31198
31198
 
31199
31199
  ## Styling
31200
31200
 
31201
- | Variable | Styles | Default |
31202
- | ----------------------------- | ----------------------------------------------------- | ------------------------------------------- |
31203
- | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
31204
- | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
31205
- | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
31206
- | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
31207
- | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
31208
- | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
31209
- | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
31201
+ | Variable | Styles | Default |
31202
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
31203
+ | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
31204
+ | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
31205
+ | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
31206
+ | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
31207
+ | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
31208
+ | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
31209
+ | `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
31210
+ | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
31210
31211
 
31211
31212
  The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
31212
31213
 
@@ -37706,6 +37707,7 @@ Swipe an element (or the whole page) to make a change, and scrub the change's vi
37706
37707
  - 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
37708
  - `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
37709
  - 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.
37710
+ - 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
37711
  - 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
37712
 
37711
37713
  ## Usage
@@ -59,15 +59,16 @@ function StackBar() {
59
59
 
60
60
  ## Styling
61
61
 
62
- | Variable | Styles | Default |
63
- | ----------------------------- | ----------------------------------------------------- | ------------------------------------------- |
64
- | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
65
- | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
66
- | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
67
- | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
68
- | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
69
- | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
70
- | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
62
+ | Variable | Styles | Default |
63
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
64
+ | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
65
+ | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
66
+ | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
67
+ | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
68
+ | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
69
+ | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
70
+ | `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
71
+ | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
71
72
 
72
73
  The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
73
74
 
@@ -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.2",
3
+ "version": "1.329.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,15 +51,16 @@ function StackBar() {
51
51
 
52
52
  ## Styling
53
53
 
54
- | Variable | Styles | Default |
55
- | ----------------------------- | ----------------------------------------------------- | ------------------------------------------- |
56
- | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
57
- | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
58
- | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
59
- | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
60
- | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
61
- | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
62
- | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
54
+ | Variable | Styles | Default |
55
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
56
+ | `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
57
+ | `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
58
+ | `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
59
+ | `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
60
+ | `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
61
+ | `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
62
+ | `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
63
+ | `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
63
64
 
64
65
  The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
65
66
 
@@ -81,8 +81,11 @@
81
81
  color: var(--app-layout-nav-color, var(--tint-00));
82
82
  box-shadow: var(--app-layout-nav-shadow, none);
83
83
 
84
- /* No view-transition name of its own. Pages slide sideways in the content slot above it, so they never pass over it.
85
- * A named bar would draw above everything else during any view transition, and jump over a dialog or notice that covers it. */
84
+ /* No view-transition name of its own by default. Pages slide sideways in the content slot above it, so they never pass over it.
85
+ * A named bar would draw above everything else during any view transition, and jump over a dialog or notice that covers it.
86
+ * An app can name it for its own transitions only, for example parts of a page that slide in their own layers and would pass over it:
87
+ * `:root:active-view-transition-type(tab) { --app-layout-nav-transition-name: app-nav; }` */
88
+ view-transition-name: var(--app-layout-nav-transition-name, none);
86
89
 
87
90
  /* Each item takes an equal share of the bar. */
88
91
  > * {
@@ -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
  };