@remit/ui 0.0.221 → 0.0.223
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/package.json +14 -3
- package/src/components/DropdownMenu.tsx +100 -0
- package/src/components/EmptyState.tsx +11 -0
- package/src/components/ErrorBanner.render.test.ts +107 -0
- package/src/components/ErrorBanner.stories.tsx +132 -0
- package/src/components/ErrorBanner.tsx +122 -0
- package/src/components/ErrorBannerStack.tsx +34 -0
- package/src/components/ErrorState.render.test.ts +82 -0
- package/src/components/ErrorState.tsx +80 -0
- package/src/components/KeyboardShortcutsModal.tsx +111 -0
- package/src/components/account-service-change-dialog.render.test.ts +1 -41
- package/src/components/account-service-choice.render.test.ts +0 -26
- package/src/components/account-service-toggles.render.test.ts +0 -6
- package/src/components/address-display.render.test.ts +1 -38
- package/src/components/address-tag.render.test.ts +0 -11
- package/src/components/agenda-flow.reach.test.ts +0 -8
- package/src/components/agenda-flow.render.test.ts +0 -31
- package/src/components/agenda-panels.render.test.ts +0 -5
- package/src/components/app-shell-slotted.render.test.ts +0 -118
- package/src/components/attachment-list.render.test.ts +41 -24
- package/src/components/attachment-list.stories.tsx +67 -0
- package/src/components/attachment-list.tsx +112 -35
- package/src/components/attendee-row.render.test.ts +0 -41
- package/src/components/attention-dot.stories.tsx +46 -0
- package/src/components/attention-dot.tsx +23 -0
- package/src/components/banner.render.test.ts +0 -7
- package/src/components/bottom-sheet.render.test.ts +0 -42
- package/src/components/brief-section.render.test.ts +0 -13
- package/src/components/brief-sections.keyboard.test.ts +0 -13
- package/src/components/brief-sections.render.test.ts +0 -22
- package/src/components/calendar-clash-strip.render.test.ts +0 -19
- package/src/components/calendar-grid.render.test.ts +0 -79
- package/src/components/calendar-invite-card.render.test.ts +0 -19
- package/src/components/calendar-list.render.test.ts +0 -21
- package/src/components/calendar-slot-offers.render.test.ts +0 -24
- package/src/components/calendar-suggestion-deck.render.test.ts +0 -18
- package/src/components/calendar-toolbar.render.test.ts +1 -53
- package/src/components/category-badge.render.test.ts +1 -24
- package/src/components/compose-action-bar.render.test.ts +0 -5
- package/src/components/compose-attachments.render.test.ts +0 -38
- package/src/components/event-detail.render.test.ts +0 -27
- package/src/components/event-editor.render.test.ts +0 -4
- package/src/components/event-suggestion-card.render.test.ts +0 -61
- package/src/components/event-suggestion-card.zone-gate.test.ts +1 -7
- package/src/components/filter-clause-chip.tsx +1 -60
- package/src/components/filter-rule-editor.create.test.ts +0 -6
- package/src/components/filter-rule-editor.stories.tsx +24 -138
- package/src/components/filter-rule-editor.tsx +7 -93
- package/src/components/filter-rule.render.test.ts +9 -299
- package/src/components/filter-rule.ts +20 -85
- package/src/components/filter-sheet.render.test.ts +0 -7
- package/src/components/folder-manage-actions.render.test.ts +0 -13
- package/src/components/folder-manager.render.test.ts +0 -31
- package/src/components/folder-mutation-dialog.render.test.ts +0 -83
- package/src/components/folder-rename-dialog.render.test.ts +0 -14
- package/src/components/folder-row.render.test.ts +0 -30
- package/src/components/folder-sync-state.test.ts +0 -61
- package/src/components/folder-tree-picker.create.test.ts +0 -30
- package/src/components/folder-tree-picker.render.test.ts +0 -35
- package/src/components/intelligence-calendar-fixtures.ts +0 -2
- package/src/components/intelligence-calendar.render.test.ts +0 -4
- package/src/components/intelligence-panel.render.test.ts +1 -62
- package/src/components/intelligence-panel.stories.tsx +0 -76
- package/src/components/intelligence-panel.tab-strip.test.ts +0 -1
- package/src/components/intelligence-panel.tsx +6 -176
- package/src/components/intelligence-toggle.render.test.ts +0 -5
- package/src/components/isolated-email-frame.render.test.ts +0 -122
- package/src/components/isolated-email-frame.tsx +55 -3
- package/src/components/keyboard-hint-bar.render.test.ts +0 -7
- package/src/components/label-chip.render.test.ts +0 -28
- package/src/components/label-chip.tsx +1 -1
- package/src/components/mail-header.render.test.ts +0 -20
- package/src/components/mcp-connected-apps-page.stories.tsx +58 -0
- package/src/components/mcp-connected-apps-page.tsx +79 -0
- package/src/components/mcp-consent-page.stories.tsx +39 -0
- package/src/components/mcp-consent-page.tsx +47 -0
- package/src/components/mcp-device-page.stories.tsx +57 -0
- package/src/components/mcp-device-page.tsx +107 -0
- package/src/components/mcp-error-notice.stories.tsx +34 -0
- package/src/components/mcp-error-notice.tsx +23 -0
- package/src/components/mcp-error-page.stories.tsx +17 -0
- package/src/components/mcp-error-page.tsx +15 -0
- package/src/components/mcp-fixtures.ts +16 -0
- package/src/components/mcp-login-page.stories.tsx +37 -0
- package/src/components/mcp-login-page.tsx +58 -0
- package/src/components/mcp-page.stories.tsx +27 -0
- package/src/components/mcp-page.tsx +35 -0
- package/src/components/mcp-permission-list.stories.tsx +21 -0
- package/src/components/mcp-permission-list.tsx +22 -0
- package/src/components/message-body-view.render.test.ts +0 -21
- package/src/components/message-list-pane.brief-filter.test.ts +0 -6
- package/src/components/message-list-pane.render.test.ts +0 -54
- package/src/components/message-list-state.render.test.ts +0 -84
- package/src/components/{quarantine-bug-dialog.tsx → message-report-dialog.tsx} +9 -14
- package/src/components/message-row.render.test.ts +1 -98
- package/src/components/mobile-message-action-bar.render.test.ts +0 -59
- package/src/components/mobile-reading-pane.render.test.ts +0 -48
- package/src/components/mobile-reading-pane.stories.tsx +78 -0
- package/src/components/mobile-reading-pane.tsx +55 -41
- package/src/components/mobile-search-view.render.test.ts +0 -16
- package/src/components/mobile-search-view.stories.tsx +8 -11
- package/src/components/mobile-search-view.tsx +1 -1
- package/src/components/nav-sidebar.keyboard.test.ts +0 -8
- package/src/components/nav-sidebar.render.test.ts +2 -133
- package/src/components/new-folder-form.render.test.ts +0 -26
- package/src/components/outbox-row.render.test.ts +0 -9
- package/src/components/pane-layout.render.test.ts +0 -18
- package/src/components/plain-text-editor.mount.test.ts +0 -16
- package/src/components/popover-menu.render.test.ts +0 -11
- package/src/components/progress-bar.render.test.ts +0 -14
- package/src/components/quarantine-report.test.ts +0 -8
- package/src/components/quarantine-section.render.test.ts +16 -13
- package/src/components/quarantine-section.stories.tsx +11 -8
- package/src/components/reading-pane.render.test.ts +2 -106
- package/src/components/reading-pane.stories.tsx +3 -0
- package/src/components/refresh-button.render.test.ts +0 -9
- package/src/components/rescue-from-spam-flow.render.test.ts +0 -24
- package/src/components/rich-text-editor.mount.test.ts +0 -19
- package/src/components/rich-text-image-node.ts +11 -9
- package/src/components/role-appointment-list.render.test.ts +0 -49
- package/src/components/role-appointment-prompt.render.test.ts +0 -79
- package/src/components/row-actions.render.test.ts +0 -34
- package/src/components/search-bar.render.test.ts +0 -44
- package/src/components/search-chip-input.render.test.ts +0 -71
- package/src/components/search-conversion-notice.stories.tsx +0 -6
- package/src/components/search-conversion-notice.tsx +3 -9
- package/src/components/search-conversion.render.test.ts +0 -52
- package/src/components/search-conversion.ts +2 -18
- package/src/components/search-result-row.tsx +5 -26
- package/src/components/search-results.render.test.ts +0 -68
- package/src/components/search-results.stories.tsx +0 -30
- package/src/components/search-results.tsx +1 -1
- package/src/components/security-select.render.test.ts +1 -14
- package/src/components/selection-top-bar.render.test.ts +0 -180
- package/src/components/selection-wizard-fixtures.ts +0 -2
- package/src/components/selection-wizard.render.test.ts +7 -212
- package/src/components/selection-wizard.stories.tsx +24 -164
- package/src/components/selection-wizard.tsx +10 -86
- package/src/components/self-update.render.test.ts +0 -113
- package/src/components/sender-trust-indicator.render.test.ts +0 -30
- package/src/components/shell-top-bar.render.test.ts +0 -31
- package/src/components/shell-top-bar.stories.tsx +7 -0
- package/src/components/shell-top-bar.tsx +11 -2
- package/src/components/slide-panel.render.test.ts +0 -18
- package/src/components/suggest-list.render.test.ts +0 -6
- package/src/components/swipeable-row.gesture.test.ts +85 -40
- package/src/components/swipeable-row.render.test.ts +0 -7
- package/src/components/swipeable-row.stories.tsx +3 -2
- package/src/components/swipeable-row.tsx +65 -144
- package/src/components/sync-warning-fixtures.ts +22 -0
- package/src/components/sync-warning-report.ts +38 -0
- package/src/components/sync-warning-row.tsx +51 -0
- package/src/components/sync-warning-section.render.test.ts +19 -0
- package/src/components/sync-warning-section.stories.tsx +94 -0
- package/src/components/sync-warning-section.tsx +56 -0
- package/src/components/touch-list-body.render.test.ts +0 -29
- package/src/components/wizard.render.test.ts +0 -22
- package/src/filter-presets.test.ts +1 -107
- package/src/index.ts +40 -34
- package/src/lib/compose-language.test.ts +0 -11
- package/src/lib/email-render-treatment.test.ts +0 -21
- package/src/lib/keymap.test.ts +0 -32
- package/src/lib/property-prefill.ts +2 -2
- package/src/lib/search-rule.test.ts +0 -4
- package/src/lib/search-rule.ts +0 -9
- package/src/lib/sender-derivation.ts +3 -5
- package/src/lib/swipe-config.ts +11 -0
- package/src/lib/use-list-cursor.test.ts +0 -7
- package/src/lib/use-list-keyboard.test.ts +0 -14
- package/src/lib/use-long-press.test.ts +53 -36
- package/src/lib/use-long-press.ts +62 -56
- package/src/lib/use-modal-focus.test.ts +0 -20
- package/src/lib/use-selection.hook.test.ts +0 -13
- package/src/lib/use-selection.test.ts +0 -101
- package/src/lib/use-swipe-navigation.test.ts +162 -0
- package/src/lib/use-swipe-navigation.ts +90 -0
- package/src/lib/wizard-steps.test.ts +18 -79
- package/src/lib/wizard-steps.ts +27 -67
- package/src/mcp-pages.ts +36 -0
- package/src/category-presentation.test.ts +0 -76
- package/src/components/account-service-status.render.test.ts +0 -82
- package/src/components/app-password-hint.render.test.ts +0 -23
- package/src/components/app-top-bar.render.test.ts +0 -59
- package/src/components/auth-card.render.test.ts +0 -24
- package/src/components/auth-footer.render.test.ts +0 -17
- package/src/components/auth-hero.render.test.ts +0 -31
- package/src/components/auto-moved-badge.render.test.ts +0 -65
- package/src/components/button.render.test.ts +0 -29
- package/src/components/calendar-event-chip.render.test.ts +0 -67
- package/src/components/calendar-parse-badge.render.test.ts +0 -40
- package/src/components/checkbox.render.test.ts +0 -65
- package/src/components/compose-form-shell.render.test.ts +0 -106
- package/src/components/dialog.render.test.ts +0 -51
- package/src/components/field-label.render.test.ts +0 -16
- package/src/components/mail-action-toolbar.render.test.ts +0 -43
- package/src/components/nav-link-surface.render.test.ts +0 -126
- package/src/components/new-folder-action.render.test.ts +0 -44
- package/src/components/pane-header.render.test.ts +0 -22
- package/src/components/pull-to-refresh.render.test.ts +0 -46
- package/src/components/recurrence-scope-prompt.render.test.ts +0 -36
- package/src/components/rescue-banner.render.test.ts +0 -32
- package/src/components/rescue-candidate-row.render.test.ts +0 -68
- package/src/components/search-token-chip.render.test.ts +0 -42
- package/src/components/self-update-dot.tsx +0 -32
- package/src/components/settings-primitives.render.test.ts +0 -160
- package/src/lib/email-layout-clamp.test.ts +0 -139
- package/src/lib/label-color.test.ts +0 -25
- package/src/lib/semantic-off.ts +0 -20
- package/src/stories-viewport-globals.test.ts +0 -77
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* use-long-press — exercises the real hook (react-aria's `useLongPress`)
|
|
3
|
-
* against a jsdom-mounted element, not a reimplementation of its logic. The
|
|
4
|
-
* hook this replaces (`packages/web-client/src/hooks/useLongPress.ts`) had a
|
|
5
|
-
* decoy test that reimplemented the timer/threshold logic locally and so
|
|
6
|
-
* gave zero regression coverage on the actual hook; these tests dispatch
|
|
7
|
-
* real PointerEvents at a real mounted node and assert on the callback and
|
|
8
|
-
* the DOM side effects react-aria owns (contextmenu suppression).
|
|
9
|
-
*
|
|
10
|
-
* react-aria's pointerdown → threshold timer → onLongPress path, its global
|
|
11
|
-
* pointerup/pointercancel listeners, and its contextmenu suppression all
|
|
12
|
-
* need a real `document`/`window`/`PointerEvent`, which `renderToString`
|
|
13
|
-
* (the pattern used elsewhere in this repo for presentational components)
|
|
14
|
-
* cannot exercise.
|
|
15
|
-
*
|
|
16
|
-
* The clock is mocked. Every timing assertion here is about one boundary —
|
|
17
|
-
* the press crossed the threshold, or it ended first — and racing that
|
|
18
|
-
* boundary against a wall clock on a loaded runner turns a passing test red
|
|
19
|
-
* (#645). Time only moves when `advance` moves it.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
1
|
import "@remit/test-dom";
|
|
23
2
|
import assert from "node:assert/strict";
|
|
24
3
|
import { afterEach, beforeEach, describe, it, mock } from "node:test";
|
|
@@ -28,8 +7,7 @@ import { useLongPress } from "./use-long-press.js";
|
|
|
28
7
|
|
|
29
8
|
const THRESHOLD = 40;
|
|
30
9
|
|
|
31
|
-
|
|
32
|
-
const AFTER_ARIA_CONTEXTMENU_TEARDOWN = 100;
|
|
10
|
+
const AFTER_RELEASE = 100;
|
|
33
11
|
|
|
34
12
|
let container: HTMLElement;
|
|
35
13
|
let root: Root;
|
|
@@ -69,6 +47,7 @@ function pointerDown(row: Element, pointerType = "touch") {
|
|
|
69
47
|
row.dispatchEvent(
|
|
70
48
|
new PointerEvent("pointerdown", {
|
|
71
49
|
bubbles: true,
|
|
50
|
+
buttons: 1,
|
|
72
51
|
pointerType,
|
|
73
52
|
pointerId: 1,
|
|
74
53
|
clientX: 10,
|
|
@@ -77,6 +56,19 @@ function pointerDown(row: Element, pointerType = "touch") {
|
|
|
77
56
|
);
|
|
78
57
|
}
|
|
79
58
|
|
|
59
|
+
function pointerMove(row: Element, x: number, y: number) {
|
|
60
|
+
row.dispatchEvent(
|
|
61
|
+
new PointerEvent("pointermove", {
|
|
62
|
+
bubbles: true,
|
|
63
|
+
buttons: 1,
|
|
64
|
+
pointerType: "touch",
|
|
65
|
+
pointerId: 1,
|
|
66
|
+
clientX: x,
|
|
67
|
+
clientY: y,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
80
72
|
function dispatchContextMenu(row: Element) {
|
|
81
73
|
const event = new MouseEvent("contextmenu", {
|
|
82
74
|
bubbles: true,
|
|
@@ -111,7 +103,13 @@ function pointerUpOn(row: Element) {
|
|
|
111
103
|
}
|
|
112
104
|
|
|
113
105
|
function pointerCancel(row: Element) {
|
|
114
|
-
row.dispatchEvent(
|
|
106
|
+
row.dispatchEvent(
|
|
107
|
+
new PointerEvent("pointercancel", {
|
|
108
|
+
bubbles: true,
|
|
109
|
+
pointerType: "touch",
|
|
110
|
+
pointerId: 1,
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
function advance(ms: number) {
|
|
@@ -130,17 +128,19 @@ beforeEach(() => {
|
|
|
130
128
|
afterEach(() => {
|
|
131
129
|
// The hook's contextmenu arming is module state bounded by a timer, and a
|
|
132
130
|
// test that leaves the finger down leaves it armed. Release the pointer so
|
|
133
|
-
// the next test starts disarmed rather than inheriting a dead timer id.
|
|
131
|
+
// the next test starts disarmed rather than inheriting a dead timer id. The
|
|
132
|
+
// click swallow armed by a fired hold expires on the same clock.
|
|
134
133
|
act(() => {
|
|
135
134
|
pointerUp();
|
|
136
135
|
});
|
|
136
|
+
mock.timers.tick(10_000);
|
|
137
137
|
mock.timers.reset();
|
|
138
138
|
act(() => {
|
|
139
139
|
root.unmount();
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
|
|
143
|
-
describe("useLongPress
|
|
143
|
+
describe("useLongPress", () => {
|
|
144
144
|
it("fires onLongPress after the threshold with no interruption", async () => {
|
|
145
145
|
let fired = 0;
|
|
146
146
|
const row = mount({ onLongPress: () => fired++ });
|
|
@@ -160,16 +160,13 @@ describe("useLongPress (react-aria wrapper)", () => {
|
|
|
160
160
|
|
|
161
161
|
pointerDown(row);
|
|
162
162
|
await advance(THRESHOLD - 1);
|
|
163
|
-
|
|
163
|
+
pointerUpOn(row);
|
|
164
164
|
await advance(THRESHOLD);
|
|
165
165
|
|
|
166
166
|
assert.equal(fired, 0);
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it("does not fire when cancelled via a pointercancel before the threshold", async () => {
|
|
170
|
-
// This is the mechanism SwipeableRow's axis arbitration relies on: it
|
|
171
|
-
// dispatches a synthetic pointercancel to abort a pending long press
|
|
172
|
-
// once a horizontal or vertical drag claims the gesture.
|
|
173
170
|
let fired = 0;
|
|
174
171
|
const row = mount({ onLongPress: () => fired++ });
|
|
175
172
|
|
|
@@ -181,6 +178,28 @@ describe("useLongPress (react-aria wrapper)", () => {
|
|
|
181
178
|
assert.equal(fired, 0);
|
|
182
179
|
});
|
|
183
180
|
|
|
181
|
+
it("fires when the finger drifts less than the drift tolerance", async () => {
|
|
182
|
+
let fired = 0;
|
|
183
|
+
const row = mount({ onLongPress: () => fired++ });
|
|
184
|
+
|
|
185
|
+
pointerDown(row);
|
|
186
|
+
pointerMove(row, 30, 12);
|
|
187
|
+
await advance(THRESHOLD);
|
|
188
|
+
|
|
189
|
+
assert.equal(fired, 1);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("does not fire once the finger has moved past the drift tolerance", async () => {
|
|
193
|
+
let fired = 0;
|
|
194
|
+
const row = mount({ onLongPress: () => fired++ });
|
|
195
|
+
|
|
196
|
+
pointerDown(row);
|
|
197
|
+
pointerMove(row, 80, 12);
|
|
198
|
+
await advance(THRESHOLD);
|
|
199
|
+
|
|
200
|
+
assert.equal(fired, 0);
|
|
201
|
+
});
|
|
202
|
+
|
|
184
203
|
it("does not fire while isDisabled", async () => {
|
|
185
204
|
let fired = 0;
|
|
186
205
|
const row = mount({ onLongPress: () => fired++, isDisabled: true });
|
|
@@ -249,7 +268,7 @@ describe("useLongPress (react-aria wrapper)", () => {
|
|
|
249
268
|
"the touch long-press menu is still suppressed",
|
|
250
269
|
);
|
|
251
270
|
pointerUpOn(row);
|
|
252
|
-
await advance(
|
|
271
|
+
await advance(AFTER_RELEASE);
|
|
253
272
|
|
|
254
273
|
assert.equal(
|
|
255
274
|
dispatchContextMenu(row).defaultPrevented,
|
|
@@ -259,15 +278,13 @@ describe("useLongPress (react-aria wrapper)", () => {
|
|
|
259
278
|
});
|
|
260
279
|
|
|
261
280
|
it("does not suppress the keyboard menu after a touch tap that raised no menu", async () => {
|
|
262
|
-
// A tap that lifts without a menu must still disarm suppression
|
|
263
|
-
//
|
|
264
|
-
// listener, which it removes shortly after pointerup — in a browser a
|
|
265
|
-
// keyboard menu arrives long after that, so only this hook's ref decides.
|
|
281
|
+
// A tap that lifts without a menu must still disarm suppression; a
|
|
282
|
+
// keyboard menu arrives long after the release.
|
|
266
283
|
const row = mount({ onLongPress: () => undefined });
|
|
267
284
|
|
|
268
285
|
pointerDown(row, "touch");
|
|
269
286
|
pointerUpOn(row);
|
|
270
|
-
await advance(
|
|
287
|
+
await advance(AFTER_RELEASE);
|
|
271
288
|
|
|
272
289
|
assert.equal(dispatchContextMenu(row).defaultPrevented, false);
|
|
273
290
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import { mergeProps
|
|
1
|
+
import { type FullGestureState, useDrag } from "@use-gesture/react";
|
|
2
|
+
import type { HTMLAttributes, PointerEvent } from "react";
|
|
3
|
+
import { mergeProps } from "react-aria";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Suppression lives on the document, not on the row.
|
|
@@ -27,7 +27,7 @@ const MAX_ARMED_MS = 5_000;
|
|
|
27
27
|
* release disarms too, which is what keeps a keyboard-invoked menu
|
|
28
28
|
* (Context-Menu key / Shift+F10) raised later from inheriting a press that is
|
|
29
29
|
* long over. Deliberately keyed to `pointerup` and not to `pointercancel`: on
|
|
30
|
-
* Android the browser
|
|
30
|
+
* Android the browser can cancel the
|
|
31
31
|
* pointer before the `contextmenu` it raised arrives, which would race the
|
|
32
32
|
* suppression away.
|
|
33
33
|
*/
|
|
@@ -54,74 +54,80 @@ function arm(): void {
|
|
|
54
54
|
armedTimer = setTimeout(disarm, MAX_ARMED_MS);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
let clickTimer: ReturnType<typeof setTimeout> | undefined;
|
|
58
|
+
|
|
59
|
+
function swallowClick(event: Event): void {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
event.stopPropagation();
|
|
62
|
+
releaseClick();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function releaseClick(): void {
|
|
66
|
+
if (clickTimer === undefined) return;
|
|
67
|
+
clearTimeout(clickTimer);
|
|
68
|
+
clickTimer = undefined;
|
|
69
|
+
document.removeEventListener("click", swallowClick, true);
|
|
70
|
+
document.removeEventListener("pointerdown", releaseClick, true);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function swallowReleaseClick(): void {
|
|
74
|
+
releaseClick();
|
|
75
|
+
document.addEventListener("click", swallowClick, true);
|
|
76
|
+
document.addEventListener("pointerdown", releaseClick, true);
|
|
77
|
+
clickTimer = setTimeout(releaseClick, MAX_ARMED_MS);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const LONG_PRESS_DELAY_MS = 500;
|
|
81
|
+
|
|
82
|
+
export const LONG_PRESS_DRIFT_PX = 36;
|
|
83
|
+
|
|
57
84
|
export interface UseLongPressOptions {
|
|
58
|
-
/** Called once the threshold elapses while the press stays over the target. */
|
|
59
85
|
onLongPress: () => void;
|
|
60
|
-
/** Long press is a no-op while true (e.g. a row already in selection mode). */
|
|
61
86
|
isDisabled?: boolean;
|
|
62
|
-
/** @default 500 */
|
|
63
87
|
delayMs?: number;
|
|
64
|
-
/**
|
|
65
|
-
* Announced to assistive technology as the long-press action, e.g.
|
|
66
|
-
* "Select message". TalkBack/VoiceOver have no gesture equivalent for a
|
|
67
|
-
* timed hold, so this description — not the gesture itself — is what
|
|
68
|
-
* makes the action discoverable to a screen reader user.
|
|
69
|
-
*/
|
|
70
88
|
accessibilityDescription?: string;
|
|
71
89
|
}
|
|
72
90
|
|
|
73
91
|
export interface UseLongPressResult {
|
|
74
|
-
|
|
75
|
-
longPressProps: DOMAttributes;
|
|
92
|
+
longPressProps: HTMLAttributes<HTMLElement>;
|
|
76
93
|
}
|
|
77
94
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* the swipeable row with the plain one while the finger is still down, so a
|
|
97
|
-
* handler bound to the pressed node is gone by the time the menu arrives.
|
|
98
|
-
*
|
|
99
|
-
* Single source of truth for the app's long-press threshold — both mobile
|
|
100
|
-
* row consumers (the plain row and the swipeable row) go through this hook
|
|
101
|
-
* so their timing can't drift apart again.
|
|
102
|
-
*/
|
|
95
|
+
export const holdConfig = (delayMs: number) =>
|
|
96
|
+
({
|
|
97
|
+
delay: delayMs,
|
|
98
|
+
threshold: LONG_PRESS_DRIFT_PX,
|
|
99
|
+
triggerAllEvents: true,
|
|
100
|
+
pointer: { keys: false },
|
|
101
|
+
}) as const;
|
|
102
|
+
|
|
103
|
+
export const isHold = (state: FullGestureState<"drag">): boolean =>
|
|
104
|
+
state.event.type === "pointerdown" && state.first;
|
|
105
|
+
|
|
106
|
+
export const touchMenuSuppressionProps = {
|
|
107
|
+
onPointerDown: (event: PointerEvent) => {
|
|
108
|
+
if (event.pointerType !== "touch" && event.pointerType !== "pen") return;
|
|
109
|
+
arm();
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
103
113
|
export function useLongPress({
|
|
104
114
|
onLongPress,
|
|
105
115
|
isDisabled,
|
|
106
|
-
delayMs =
|
|
116
|
+
delayMs = LONG_PRESS_DELAY_MS,
|
|
107
117
|
accessibilityDescription,
|
|
108
118
|
}: UseLongPressOptions): UseLongPressResult {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// (Context-Menu key / Shift+F10) that is preceded by no press at all, keep
|
|
118
|
-
// the native menu.
|
|
119
|
-
const onPointerDown = useCallback((event: PointerEvent) => {
|
|
120
|
-
if (event.pointerType !== "touch" && event.pointerType !== "pen") return;
|
|
121
|
-
arm();
|
|
122
|
-
}, []);
|
|
119
|
+
const bind = useDrag(
|
|
120
|
+
(state) => {
|
|
121
|
+
if (!isHold(state)) return;
|
|
122
|
+
swallowReleaseClick();
|
|
123
|
+
onLongPress();
|
|
124
|
+
},
|
|
125
|
+
{ ...holdConfig(delayMs), enabled: !isDisabled },
|
|
126
|
+
);
|
|
123
127
|
|
|
124
128
|
return {
|
|
125
|
-
longPressProps: mergeProps(
|
|
129
|
+
longPressProps: mergeProps(bind(), touchMenuSuppressionProps, {
|
|
130
|
+
"aria-description": accessibilityDescription,
|
|
131
|
+
}),
|
|
126
132
|
};
|
|
127
133
|
}
|
|
@@ -54,11 +54,6 @@ describe("useModalFocus", () => {
|
|
|
54
54
|
assert.equal(document.activeElement?.textContent, "First action");
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
it("leaves focus on the body while closed", () => {
|
|
58
|
-
act(() => root.render(createElement(Panel, { open: false })));
|
|
59
|
-
assert.equal(document.activeElement, document.body);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
57
|
it("moves focus in when an already-mounted panel opens", () => {
|
|
63
58
|
act(() => root.render(createElement(Panel, { open: false })));
|
|
64
59
|
assert.equal(document.activeElement, document.body);
|
|
@@ -144,21 +139,6 @@ describe("useModalFocus", () => {
|
|
|
144
139
|
outside.remove();
|
|
145
140
|
});
|
|
146
141
|
|
|
147
|
-
it("leaves focus outside the panel alone on Shift+Tab too", () => {
|
|
148
|
-
const outside = document.createElement("button");
|
|
149
|
-
outside.textContent = "Behind the panel";
|
|
150
|
-
document.body.appendChild(outside);
|
|
151
|
-
|
|
152
|
-
act(() => root.render(createElement(Panel, { open: true })));
|
|
153
|
-
outside.focus();
|
|
154
|
-
|
|
155
|
-
const event = tab(true);
|
|
156
|
-
|
|
157
|
-
assert.equal(event.defaultPrevented, false);
|
|
158
|
-
assert.equal(document.activeElement, outside);
|
|
159
|
-
outside.remove();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
142
|
/**
|
|
163
143
|
* Clicking the title of a dialog — a region no control owns — leaves focus on
|
|
164
144
|
* the body, and the next Tab has to land back inside the surface rather than
|
|
@@ -49,13 +49,6 @@ afterEach(() => {
|
|
|
49
49
|
const ids = ["a", "b", "c", "d"];
|
|
50
50
|
|
|
51
51
|
describe("useSelection", () => {
|
|
52
|
-
it("starts empty", () => {
|
|
53
|
-
assert.deepEqual(selected(), []);
|
|
54
|
-
assert.equal(api.selectedCount, 0);
|
|
55
|
-
assert.equal(api.hasSelection, false);
|
|
56
|
-
assert.equal(api.anchorId, undefined);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
52
|
it("toggles a row on and off, anchoring on it either way", () => {
|
|
60
53
|
run(() => api.toggle("b"));
|
|
61
54
|
assert.deepEqual(selected(), ["b"]);
|
|
@@ -101,12 +94,6 @@ describe("useSelection", () => {
|
|
|
101
94
|
assert.deepEqual(selected(), ids);
|
|
102
95
|
});
|
|
103
96
|
|
|
104
|
-
it("seeds the anchor without touching the selection", () => {
|
|
105
|
-
run(() => api.setAnchor("c"));
|
|
106
|
-
assert.deepEqual(selected(), []);
|
|
107
|
-
assert.equal(api.anchorId, "c");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
97
|
it("extends a range from the anchor, and keeps extending from it", () => {
|
|
111
98
|
run(() => api.toggle("b"));
|
|
112
99
|
run(() => api.selectRange(ids, "d"));
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
deriveIsMultiSelectMode,
|
|
6
6
|
intersectSelectedIds,
|
|
7
7
|
isModified,
|
|
8
|
-
modifiersOf,
|
|
9
8
|
nextFocusId,
|
|
10
9
|
resolveRangeAnchor,
|
|
11
10
|
rowSelectIntent,
|
|
@@ -13,38 +12,6 @@ import {
|
|
|
13
12
|
|
|
14
13
|
const ids = ["a", "b", "c", "d", "e"];
|
|
15
14
|
|
|
16
|
-
// Mirrors the hook's `selectRange` state transition (anchor + selection) using
|
|
17
|
-
// the same pure helpers it runs, so the mouse/keyboard sequences below exercise
|
|
18
|
-
// the real logic without an interactive DOM. Returns the next {selected, anchor}.
|
|
19
|
-
const applyRange = (
|
|
20
|
-
state: { selected: Set<string>; anchor: string | undefined },
|
|
21
|
-
orderedIds: string[],
|
|
22
|
-
targetId: string,
|
|
23
|
-
fallbackAnchor?: string,
|
|
24
|
-
): { selected: Set<string>; anchor: string | undefined } => {
|
|
25
|
-
const anchor = resolveRangeAnchor(
|
|
26
|
-
orderedIds,
|
|
27
|
-
state.anchor,
|
|
28
|
-
fallbackAnchor,
|
|
29
|
-
targetId,
|
|
30
|
-
);
|
|
31
|
-
const range = computeRange(orderedIds, anchor, targetId);
|
|
32
|
-
const selected = new Set(state.selected);
|
|
33
|
-
for (const id of range) selected.add(id);
|
|
34
|
-
return { selected, anchor };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Mirrors a cmd/ctrl-click: toggle membership and re-anchor on the clicked row.
|
|
38
|
-
const applyToggle = (
|
|
39
|
-
state: { selected: Set<string>; anchor: string | undefined },
|
|
40
|
-
targetId: string,
|
|
41
|
-
): { selected: Set<string>; anchor: string | undefined } => {
|
|
42
|
-
const selected = new Set(state.selected);
|
|
43
|
-
if (selected.has(targetId)) selected.delete(targetId);
|
|
44
|
-
else selected.add(targetId);
|
|
45
|
-
return { selected, anchor: targetId };
|
|
46
|
-
};
|
|
47
|
-
|
|
48
15
|
describe("computeRange", () => {
|
|
49
16
|
test("forward range: anchor above target selects the inclusive slice", () => {
|
|
50
17
|
assert.deepStrictEqual(computeRange(ids, "b", "d"), ["b", "c", "d"]);
|
|
@@ -105,57 +72,6 @@ describe("resolveRangeAnchor", () => {
|
|
|
105
72
|
});
|
|
106
73
|
});
|
|
107
74
|
|
|
108
|
-
describe("shift-click range over a filtered/search-narrowed list (#142, #144)", () => {
|
|
109
|
-
test("shift-click range with an active filter builds the range within the visible rows", () => {
|
|
110
|
-
// Full inbox is a..h; the "Automated" filter leaves only these rows.
|
|
111
|
-
const filtered = ["b", "d", "f", "g"];
|
|
112
|
-
// The open row "d" is visible; nothing selected yet, no stored anchor.
|
|
113
|
-
let state = {
|
|
114
|
-
selected: new Set<string>(),
|
|
115
|
-
anchor: undefined as string | undefined,
|
|
116
|
-
};
|
|
117
|
-
// Shift-click "g": ranges from the open/focused row "d" to "g".
|
|
118
|
-
state = applyRange(state, filtered, "g", "d");
|
|
119
|
-
assert.deepStrictEqual([...state.selected], ["d", "f", "g"]);
|
|
120
|
-
assert.strictEqual(state.anchor, "d");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("range where the anchor left the visible set re-anchors instead of no-oping", () => {
|
|
124
|
-
const filtered = ["b", "d", "f", "g"];
|
|
125
|
-
// Stored anchor "a" was selected before the filter narrowed the list and is
|
|
126
|
-
// no longer visible; there is no open/focused fallback row.
|
|
127
|
-
let state = {
|
|
128
|
-
selected: new Set<string>(),
|
|
129
|
-
anchor: "a" as string | undefined,
|
|
130
|
-
};
|
|
131
|
-
// First shift-click adopts the clicked row as the new visible anchor.
|
|
132
|
-
state = applyRange(state, filtered, "f");
|
|
133
|
-
assert.deepStrictEqual([...state.selected], ["f"]);
|
|
134
|
-
assert.strictEqual(state.anchor, "f");
|
|
135
|
-
// Second shift-click now builds a real range from that adopted anchor.
|
|
136
|
-
state = applyRange(state, filtered, "b");
|
|
137
|
-
assert.deepStrictEqual([...state.selected].sort(), ["b", "d", "f"]);
|
|
138
|
-
assert.strictEqual(state.anchor, "f");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("multi-select across a search-results list: cmd-click then shift-click", () => {
|
|
142
|
-
// Search "npm" yields these results; the inbox anchor is gone from this set.
|
|
143
|
-
const results = ["m1", "m2", "m3", "m4", "m5"];
|
|
144
|
-
let state = {
|
|
145
|
-
selected: new Set<string>(),
|
|
146
|
-
anchor: "inbox-row" as string | undefined,
|
|
147
|
-
};
|
|
148
|
-
// Cmd-click "m2": toggles it in and re-anchors on it (a visible row).
|
|
149
|
-
state = applyToggle(state, "m2");
|
|
150
|
-
assert.deepStrictEqual([...state.selected], ["m2"]);
|
|
151
|
-
assert.strictEqual(state.anchor, "m2");
|
|
152
|
-
// Shift-click "m4": ranges from the cmd-clicked anchor across the results.
|
|
153
|
-
state = applyRange(state, results, "m4");
|
|
154
|
-
assert.deepStrictEqual([...state.selected].sort(), ["m2", "m3", "m4"]);
|
|
155
|
-
assert.strictEqual(state.anchor, "m2");
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
75
|
describe("nextFocusId", () => {
|
|
160
76
|
test("moves down one row", () => {
|
|
161
77
|
assert.strictEqual(nextFocusId(ids, "b", 1), "c");
|
|
@@ -247,23 +163,6 @@ describe("intersectSelectedIds", () => {
|
|
|
247
163
|
});
|
|
248
164
|
});
|
|
249
165
|
|
|
250
|
-
describe("modifiersOf", () => {
|
|
251
|
-
test("keeps only the three keys a selection reads off an event", () => {
|
|
252
|
-
const event = {
|
|
253
|
-
shiftKey: true,
|
|
254
|
-
metaKey: false,
|
|
255
|
-
ctrlKey: true,
|
|
256
|
-
altKey: true,
|
|
257
|
-
button: 0,
|
|
258
|
-
};
|
|
259
|
-
assert.deepStrictEqual(modifiersOf(event), {
|
|
260
|
-
shiftKey: true,
|
|
261
|
-
metaKey: false,
|
|
262
|
-
ctrlKey: true,
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
166
|
describe("isModified", () => {
|
|
268
167
|
test("is true for any of the three keys a keyboard can add", () => {
|
|
269
168
|
assert.equal(
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import "@remit/test-dom";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { afterEach, beforeEach, describe, it } from "node:test";
|
|
4
|
+
import { act, createElement } from "react";
|
|
5
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
6
|
+
import { MobileReadingPane } from "../components/mobile-reading-pane.js";
|
|
7
|
+
import { SWIPE_EVENT } from "./use-swipe-navigation.js";
|
|
8
|
+
|
|
9
|
+
let container: HTMLElement;
|
|
10
|
+
let root: Root;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
container = document.getElementById("root") as unknown as HTMLElement;
|
|
14
|
+
container.innerHTML = "";
|
|
15
|
+
root = createRoot(container);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
act(() => {
|
|
20
|
+
root.unmount();
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(window, "visualViewport", {
|
|
23
|
+
value: undefined,
|
|
24
|
+
configurable: true,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
interface Navigation {
|
|
29
|
+
next: number;
|
|
30
|
+
previous: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mount(): { area: HTMLElement; navigation: Navigation } {
|
|
34
|
+
const navigation: Navigation = { next: 0, previous: 0 };
|
|
35
|
+
act(() => {
|
|
36
|
+
root.render(
|
|
37
|
+
createElement(
|
|
38
|
+
MobileReadingPane,
|
|
39
|
+
{
|
|
40
|
+
thread: { subject: "Subject", messages: [] },
|
|
41
|
+
onBack: () => undefined,
|
|
42
|
+
onSwipeNext: () => navigation.next++,
|
|
43
|
+
onSwipePrevious: () => navigation.previous++,
|
|
44
|
+
},
|
|
45
|
+
createElement("p", { id: "body" }, "body"),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
const body = document.getElementById("body");
|
|
50
|
+
assert.ok(body?.parentElement, "reading area did not mount");
|
|
51
|
+
return { area: body.parentElement, navigation };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function touch(
|
|
55
|
+
target: Element,
|
|
56
|
+
type: "pointerdown" | "pointermove" | "pointerup",
|
|
57
|
+
x: number,
|
|
58
|
+
y: number,
|
|
59
|
+
pointerType = "touch",
|
|
60
|
+
) {
|
|
61
|
+
act(() => {
|
|
62
|
+
target.dispatchEvent(
|
|
63
|
+
new PointerEvent(type, {
|
|
64
|
+
bubbles: true,
|
|
65
|
+
buttons: type === "pointerup" ? 0 : 1,
|
|
66
|
+
pointerType,
|
|
67
|
+
pointerId: 1,
|
|
68
|
+
clientX: x,
|
|
69
|
+
clientY: y,
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function drag(
|
|
76
|
+
target: Element,
|
|
77
|
+
from: [number, number],
|
|
78
|
+
to: [number, number],
|
|
79
|
+
pointerType = "touch",
|
|
80
|
+
) {
|
|
81
|
+
touch(target, "pointerdown", from[0], from[1], pointerType);
|
|
82
|
+
touch(target, "pointermove", to[0] / 2 + from[0] / 2, from[1], pointerType);
|
|
83
|
+
touch(target, "pointermove", to[0], to[1], pointerType);
|
|
84
|
+
touch(target, "pointerup", to[0], to[1], pointerType);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe("reading pane swipe", () => {
|
|
88
|
+
it("opens the next message on a swipe left", () => {
|
|
89
|
+
const { area, navigation } = mount();
|
|
90
|
+
|
|
91
|
+
drag(area, [300, 200], [100, 205]);
|
|
92
|
+
|
|
93
|
+
assert.deepEqual(navigation, { next: 1, previous: 0 });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("opens the previous message on a swipe right", () => {
|
|
97
|
+
const { area, navigation } = mount();
|
|
98
|
+
|
|
99
|
+
drag(area, [100, 200], [300, 195]);
|
|
100
|
+
|
|
101
|
+
assert.deepEqual(navigation, { next: 0, previous: 1 });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("ignores a drag shorter than the swipe distance", () => {
|
|
105
|
+
const { area, navigation } = mount();
|
|
106
|
+
|
|
107
|
+
drag(area, [200, 200], [170, 200]);
|
|
108
|
+
|
|
109
|
+
assert.deepEqual(navigation, { next: 0, previous: 0 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("ignores a mostly vertical drag, which is a scroll", () => {
|
|
113
|
+
const { area, navigation } = mount();
|
|
114
|
+
|
|
115
|
+
drag(area, [200, 100], [140, 500]);
|
|
116
|
+
|
|
117
|
+
assert.deepEqual(navigation, { next: 0, previous: 0 });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("ignores a mouse drag", () => {
|
|
121
|
+
const { area, navigation } = mount();
|
|
122
|
+
|
|
123
|
+
drag(area, [300, 200], [100, 200], "mouse");
|
|
124
|
+
|
|
125
|
+
assert.deepEqual(navigation, { next: 0, previous: 0 });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("opens the next message on a swipe raised inside the message frame", () => {
|
|
129
|
+
const { area, navigation } = mount();
|
|
130
|
+
|
|
131
|
+
act(() => {
|
|
132
|
+
area.dispatchEvent(
|
|
133
|
+
new CustomEvent(SWIPE_EVENT, { bubbles: true, detail: "left" }),
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
assert.deepEqual(navigation, { next: 1, previous: 0 });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("leaves the browser to pan and pinch while the page is zoomed in", () => {
|
|
141
|
+
Object.defineProperty(window, "visualViewport", {
|
|
142
|
+
value: {
|
|
143
|
+
scale: 2,
|
|
144
|
+
addEventListener: () => undefined,
|
|
145
|
+
removeEventListener: () => undefined,
|
|
146
|
+
},
|
|
147
|
+
configurable: true,
|
|
148
|
+
});
|
|
149
|
+
const { area, navigation } = mount();
|
|
150
|
+
|
|
151
|
+
drag(area, [300, 200], [100, 200]);
|
|
152
|
+
|
|
153
|
+
assert.deepEqual(navigation, { next: 0, previous: 0 });
|
|
154
|
+
assert.equal(area.style.touchAction, "auto");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("keeps native pinch-zoom enabled at rest", () => {
|
|
158
|
+
const { area } = mount();
|
|
159
|
+
|
|
160
|
+
assert.equal(area.style.touchAction, "pan-y pinch-zoom");
|
|
161
|
+
});
|
|
162
|
+
});
|