@remit/web-client 0.0.35 → 0.0.36
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remit/web-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Remit web client, published as composable primitives — the app shell, auth shells, and runtime config. A distributor imports what it composes and bundles it.",
|
|
6
6
|
"exports": {
|
|
@@ -423,7 +423,10 @@ export const MessageList = ({
|
|
|
423
423
|
const handleRowSelect = useCallback(
|
|
424
424
|
(messageId: string, modifiers: SelectionModifiers): boolean => {
|
|
425
425
|
if (modifiers.shiftKey) {
|
|
426
|
-
|
|
426
|
+
// The open/focused row is the fallback origin when the stored anchor
|
|
427
|
+
// has been filtered or searched out of the visible list, so the first
|
|
428
|
+
// shift-click still ranges from where the user is (#142, #144).
|
|
429
|
+
selectRange(orderedIds, messageId, focusedMessageId);
|
|
427
430
|
return true;
|
|
428
431
|
}
|
|
429
432
|
if (modifiers.metaKey || modifiers.ctrlKey) {
|
|
@@ -438,7 +441,14 @@ export const MessageList = ({
|
|
|
438
441
|
setAnchor(messageId);
|
|
439
442
|
return false;
|
|
440
443
|
},
|
|
441
|
-
[
|
|
444
|
+
[
|
|
445
|
+
orderedIds,
|
|
446
|
+
focusedMessageId,
|
|
447
|
+
selectRange,
|
|
448
|
+
toggleCheck,
|
|
449
|
+
clearSelection,
|
|
450
|
+
setAnchor,
|
|
451
|
+
],
|
|
442
452
|
);
|
|
443
453
|
|
|
444
454
|
// Open the delete confirmation for an explicit set of ids. All delete
|
|
@@ -4,10 +4,43 @@ import {
|
|
|
4
4
|
computeRange,
|
|
5
5
|
intersectSelectedIds,
|
|
6
6
|
nextFocusId,
|
|
7
|
+
resolveRangeAnchor,
|
|
7
8
|
} from "./useSelection.js";
|
|
8
9
|
|
|
9
10
|
const ids = ["a", "b", "c", "d", "e"];
|
|
10
11
|
|
|
12
|
+
// Mirrors the hook's `selectRange` state transition (anchor + selection) using
|
|
13
|
+
// the same pure helpers it runs, so the mouse/keyboard sequences below exercise
|
|
14
|
+
// the real logic without an interactive DOM. Returns the next {selected, anchor}.
|
|
15
|
+
const applyRange = (
|
|
16
|
+
state: { selected: Set<string>; anchor: string | undefined },
|
|
17
|
+
orderedIds: string[],
|
|
18
|
+
targetId: string,
|
|
19
|
+
fallbackAnchor?: string,
|
|
20
|
+
): { selected: Set<string>; anchor: string | undefined } => {
|
|
21
|
+
const anchor = resolveRangeAnchor(
|
|
22
|
+
orderedIds,
|
|
23
|
+
state.anchor,
|
|
24
|
+
fallbackAnchor,
|
|
25
|
+
targetId,
|
|
26
|
+
);
|
|
27
|
+
const range = computeRange(orderedIds, anchor, targetId);
|
|
28
|
+
const selected = new Set(state.selected);
|
|
29
|
+
for (const id of range) selected.add(id);
|
|
30
|
+
return { selected, anchor };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Mirrors a cmd/ctrl-click: toggle membership and re-anchor on the clicked row.
|
|
34
|
+
const applyToggle = (
|
|
35
|
+
state: { selected: Set<string>; anchor: string | undefined },
|
|
36
|
+
targetId: string,
|
|
37
|
+
): { selected: Set<string>; anchor: string | undefined } => {
|
|
38
|
+
const selected = new Set(state.selected);
|
|
39
|
+
if (selected.has(targetId)) selected.delete(targetId);
|
|
40
|
+
else selected.add(targetId);
|
|
41
|
+
return { selected, anchor: targetId };
|
|
42
|
+
};
|
|
43
|
+
|
|
11
44
|
describe("computeRange", () => {
|
|
12
45
|
test("forward range: anchor above target selects the inclusive slice", () => {
|
|
13
46
|
assert.deepStrictEqual(computeRange(ids, "b", "d"), ["b", "c", "d"]);
|
|
@@ -44,6 +77,81 @@ describe("computeRange", () => {
|
|
|
44
77
|
});
|
|
45
78
|
});
|
|
46
79
|
|
|
80
|
+
describe("resolveRangeAnchor", () => {
|
|
81
|
+
test("keeps a still-visible stored anchor so consecutive shift-clicks extend from it", () => {
|
|
82
|
+
assert.strictEqual(resolveRangeAnchor(ids, "b", undefined, "d"), "b");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("a stored anchor no longer visible falls back to the open/focused row", () => {
|
|
86
|
+
// The stored anchor "z" was filtered/searched out of the visible list; the
|
|
87
|
+
// open row "b" is still visible, so the range anchors there.
|
|
88
|
+
assert.strictEqual(resolveRangeAnchor(ids, "z", "b", "d"), "b");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("with neither a visible stored anchor nor a visible fallback, the target anchors itself", () => {
|
|
92
|
+
assert.strictEqual(resolveRangeAnchor(ids, "z", "y", "d"), "d");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("no stored anchor and no fallback selects just the target", () => {
|
|
96
|
+
assert.strictEqual(resolveRangeAnchor(ids, undefined, undefined, "c"), "c");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("a stored anchor beats the fallback while it stays visible", () => {
|
|
100
|
+
assert.strictEqual(resolveRangeAnchor(ids, "a", "c", "e"), "a");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("shift-click range over a filtered/search-narrowed list (#142, #144)", () => {
|
|
105
|
+
test("shift-click range with an active filter builds the range within the visible rows", () => {
|
|
106
|
+
// Full inbox is a..h; the "Automated" filter leaves only these rows.
|
|
107
|
+
const filtered = ["b", "d", "f", "g"];
|
|
108
|
+
// The open row "d" is visible; nothing selected yet, no stored anchor.
|
|
109
|
+
let state = {
|
|
110
|
+
selected: new Set<string>(),
|
|
111
|
+
anchor: undefined as string | undefined,
|
|
112
|
+
};
|
|
113
|
+
// Shift-click "g": ranges from the open/focused row "d" to "g".
|
|
114
|
+
state = applyRange(state, filtered, "g", "d");
|
|
115
|
+
assert.deepStrictEqual([...state.selected], ["d", "f", "g"]);
|
|
116
|
+
assert.strictEqual(state.anchor, "d");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("range where the anchor left the visible set re-anchors instead of no-oping", () => {
|
|
120
|
+
const filtered = ["b", "d", "f", "g"];
|
|
121
|
+
// Stored anchor "a" was selected before the filter narrowed the list and is
|
|
122
|
+
// no longer visible; there is no open/focused fallback row.
|
|
123
|
+
let state = {
|
|
124
|
+
selected: new Set<string>(),
|
|
125
|
+
anchor: "a" as string | undefined,
|
|
126
|
+
};
|
|
127
|
+
// First shift-click adopts the clicked row as the new visible anchor.
|
|
128
|
+
state = applyRange(state, filtered, "f");
|
|
129
|
+
assert.deepStrictEqual([...state.selected], ["f"]);
|
|
130
|
+
assert.strictEqual(state.anchor, "f");
|
|
131
|
+
// Second shift-click now builds a real range from that adopted anchor.
|
|
132
|
+
state = applyRange(state, filtered, "b");
|
|
133
|
+
assert.deepStrictEqual([...state.selected].sort(), ["b", "d", "f"]);
|
|
134
|
+
assert.strictEqual(state.anchor, "f");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("multi-select across a search-results list: cmd-click then shift-click", () => {
|
|
138
|
+
// Search "npm" yields these results; the inbox anchor is gone from this set.
|
|
139
|
+
const results = ["m1", "m2", "m3", "m4", "m5"];
|
|
140
|
+
let state = {
|
|
141
|
+
selected: new Set<string>(),
|
|
142
|
+
anchor: "inbox-row" as string | undefined,
|
|
143
|
+
};
|
|
144
|
+
// Cmd-click "m2": toggles it in and re-anchors on it (a visible row).
|
|
145
|
+
state = applyToggle(state, "m2");
|
|
146
|
+
assert.deepStrictEqual([...state.selected], ["m2"]);
|
|
147
|
+
assert.strictEqual(state.anchor, "m2");
|
|
148
|
+
// Shift-click "m4": ranges from the cmd-clicked anchor across the results.
|
|
149
|
+
state = applyRange(state, results, "m4");
|
|
150
|
+
assert.deepStrictEqual([...state.selected].sort(), ["m2", "m3", "m4"]);
|
|
151
|
+
assert.strictEqual(state.anchor, "m2");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
47
155
|
describe("nextFocusId", () => {
|
|
48
156
|
test("moves down one row", () => {
|
|
49
157
|
assert.strictEqual(nextFocusId(ids, "b", 1), "c");
|
|
@@ -37,11 +37,19 @@ interface UseSelectionReturn {
|
|
|
37
37
|
/** Toggle selection for all items */
|
|
38
38
|
toggleAll: (ids: string[]) => void;
|
|
39
39
|
/**
|
|
40
|
-
* Add the contiguous range of ids from the
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* Add the contiguous range of ids from the anchor to `targetId` (inclusive)
|
|
41
|
+
* to the selection, using `orderedIds` for display order. The anchor is the
|
|
42
|
+
* stored one when it is still visible in `orderedIds`; otherwise
|
|
43
|
+
* `fallbackAnchor` when that is visible (the open/focused row); otherwise
|
|
44
|
+
* `targetId`. Whatever anchors the range becomes the new stored anchor, so a
|
|
45
|
+
* filtered or search-narrowed list can still build a range within what's
|
|
46
|
+
* visible (#142, #144).
|
|
43
47
|
*/
|
|
44
|
-
selectRange: (
|
|
48
|
+
selectRange: (
|
|
49
|
+
orderedIds: string[],
|
|
50
|
+
targetId: string,
|
|
51
|
+
fallbackAnchor?: string,
|
|
52
|
+
) => void;
|
|
45
53
|
/**
|
|
46
54
|
* Set the range anchor without changing the selection set. Used by a plain
|
|
47
55
|
* click that navigates but should seed the anchor for a later shift-click.
|
|
@@ -85,6 +93,34 @@ export const computeRange = (
|
|
|
85
93
|
return orderedIds.slice(start, end + 1);
|
|
86
94
|
};
|
|
87
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Resolve which id a shift-range selection anchors from, given the stored
|
|
98
|
+
* anchor and the ids currently visible (`orderedIds`). Pure so the
|
|
99
|
+
* filtered/search anchor behavior can be unit-tested without a DOM.
|
|
100
|
+
*
|
|
101
|
+
* - The stored anchor wins while it is still visible — consecutive shift-clicks
|
|
102
|
+
* keep extending from the same origin (Apple Mail / Gmail).
|
|
103
|
+
* - Once the stored anchor leaves the visible set (filtered out, or a search
|
|
104
|
+
* changed the list), it can't anchor a range in that set, so fall back to
|
|
105
|
+
* `fallbackAnchor` (the open/focused row) when it is visible.
|
|
106
|
+
* - With neither available, the target anchors itself: the clicked row is
|
|
107
|
+
* selected alone and becomes the origin for the next shift-click.
|
|
108
|
+
*/
|
|
109
|
+
export const resolveRangeAnchor = (
|
|
110
|
+
orderedIds: string[],
|
|
111
|
+
storedAnchor: string | undefined,
|
|
112
|
+
fallbackAnchor: string | undefined,
|
|
113
|
+
targetId: string,
|
|
114
|
+
): string => {
|
|
115
|
+
if (storedAnchor !== undefined && orderedIds.includes(storedAnchor)) {
|
|
116
|
+
return storedAnchor;
|
|
117
|
+
}
|
|
118
|
+
if (fallbackAnchor !== undefined && orderedIds.includes(fallbackAnchor)) {
|
|
119
|
+
return fallbackAnchor;
|
|
120
|
+
}
|
|
121
|
+
return targetId;
|
|
122
|
+
};
|
|
123
|
+
|
|
88
124
|
/**
|
|
89
125
|
* The ids from `selectedIds` that are still present in `currentIds` — the
|
|
90
126
|
* survivor set after a list refresh. Only ever narrows: an id absent from
|
|
@@ -211,9 +247,15 @@ export const useSelection = <T>(
|
|
|
211
247
|
}, []);
|
|
212
248
|
|
|
213
249
|
const selectRange = useCallback(
|
|
214
|
-
(orderedIds: string[], targetId: string) => {
|
|
250
|
+
(orderedIds: string[], targetId: string, fallbackAnchor?: string) => {
|
|
251
|
+
const effectiveAnchor = resolveRangeAnchor(
|
|
252
|
+
orderedIds,
|
|
253
|
+
anchorId,
|
|
254
|
+
fallbackAnchor,
|
|
255
|
+
targetId,
|
|
256
|
+
);
|
|
215
257
|
setSelectedIds((prev) => {
|
|
216
|
-
const range = computeRange(orderedIds,
|
|
258
|
+
const range = computeRange(orderedIds, effectiveAnchor, targetId);
|
|
217
259
|
if (range.length === 0) return prev;
|
|
218
260
|
const next = new Set(prev);
|
|
219
261
|
for (const id of range) {
|
|
@@ -221,10 +263,12 @@ export const useSelection = <T>(
|
|
|
221
263
|
}
|
|
222
264
|
return next;
|
|
223
265
|
});
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
|
|
266
|
+
// Whatever anchored the range becomes the stored anchor. A still-visible
|
|
267
|
+
// stored anchor resolves to itself (unchanged), so consecutive
|
|
268
|
+
// shift-clicks keep extending from the same origin; a stored anchor that
|
|
269
|
+
// left the visible set is replaced by the row the range actually used, so
|
|
270
|
+
// a filtered/search-narrowed list can build a range within what's visible.
|
|
271
|
+
setAnchorId(effectiveAnchor);
|
|
228
272
|
},
|
|
229
273
|
[anchorId],
|
|
230
274
|
);
|