@buoy-gg/time-machine 7.0.28 → 7.0.30

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.
Files changed (68) hide show
  1. package/lib/commonjs/components/TimeMachineBody.js +13 -1
  2. package/lib/commonjs/components/TimeMachineBody.js.map +1 -1
  3. package/lib/commonjs/components/list/RestoreOutcomeCard.js +15 -4
  4. package/lib/commonjs/components/list/RestoreOutcomeCard.js.map +1 -1
  5. package/lib/commonjs/components/list/SnapshotRow.js +5 -0
  6. package/lib/commonjs/components/list/SnapshotRow.js.map +1 -1
  7. package/lib/commonjs/components/list/SourcesStrip.js +2 -0
  8. package/lib/commonjs/components/list/SourcesStrip.js.map +1 -1
  9. package/lib/commonjs/components/list/UndoDeleteBar.js +2 -0
  10. package/lib/commonjs/components/list/UndoDeleteBar.js.map +1 -1
  11. package/lib/commonjs/components/preview/ItemDiffPanel.js +3 -1
  12. package/lib/commonjs/components/preview/ItemDiffPanel.js.map +1 -1
  13. package/lib/commonjs/components/preview/RestorePreviewScreen.js +41 -7
  14. package/lib/commonjs/components/preview/RestorePreviewScreen.js.map +1 -1
  15. package/lib/commonjs/ui/primitives.js +9 -3
  16. package/lib/commonjs/ui/primitives.js.map +1 -1
  17. package/lib/module/components/TimeMachineBody.js +13 -1
  18. package/lib/module/components/TimeMachineBody.js.map +1 -1
  19. package/lib/module/components/list/RestoreOutcomeCard.js +15 -4
  20. package/lib/module/components/list/RestoreOutcomeCard.js.map +1 -1
  21. package/lib/module/components/list/SnapshotRow.js +5 -0
  22. package/lib/module/components/list/SnapshotRow.js.map +1 -1
  23. package/lib/module/components/list/SourcesStrip.js +2 -0
  24. package/lib/module/components/list/SourcesStrip.js.map +1 -1
  25. package/lib/module/components/list/UndoDeleteBar.js +2 -0
  26. package/lib/module/components/list/UndoDeleteBar.js.map +1 -1
  27. package/lib/module/components/preview/ItemDiffPanel.js +3 -1
  28. package/lib/module/components/preview/ItemDiffPanel.js.map +1 -1
  29. package/lib/module/components/preview/RestorePreviewScreen.js +41 -7
  30. package/lib/module/components/preview/RestorePreviewScreen.js.map +1 -1
  31. package/lib/module/ui/primitives.js +9 -3
  32. package/lib/module/ui/primitives.js.map +1 -1
  33. package/lib/typescript/components/list/RestoreOutcomeCard.d.ts.map +1 -1
  34. package/lib/typescript/components/list/SnapshotRow.d.ts.map +1 -1
  35. package/lib/typescript/components/list/SourcesStrip.d.ts.map +1 -1
  36. package/lib/typescript/components/preview/ItemDiffPanel.d.ts +2 -1
  37. package/lib/typescript/components/preview/ItemDiffPanel.d.ts.map +1 -1
  38. package/lib/typescript/components/preview/RestorePreviewScreen.d.ts.map +1 -1
  39. package/lib/typescript/ui/primitives.d.ts +6 -3
  40. package/lib/typescript/ui/primitives.d.ts.map +1 -1
  41. package/package.json +10 -11
  42. package/src/components/HeaderReloadButton.tsx +0 -45
  43. package/src/components/TimeMachineBody.tsx +0 -237
  44. package/src/components/TimeMachineModal.tsx +0 -75
  45. package/src/components/confirm.ts +0 -35
  46. package/src/components/format.ts +0 -17
  47. package/src/components/list/CaptureBar.tsx +0 -100
  48. package/src/components/list/RestoreOutcomeCard.tsx +0 -159
  49. package/src/components/list/SnapshotRow.tsx +0 -155
  50. package/src/components/list/SourcesStrip.tsx +0 -124
  51. package/src/components/list/UndoDeleteBar.tsx +0 -76
  52. package/src/components/list/WipeAllRow.tsx +0 -42
  53. package/src/components/preview/ItemDiffPanel.tsx +0 -77
  54. package/src/components/preview/PreviewFlow.tsx +0 -70
  55. package/src/components/preview/RestorePointNameRow.tsx +0 -80
  56. package/src/components/preview/RestorePreviewScreen.tsx +0 -1090
  57. package/src/components/preview/verdictMeta.ts +0 -40
  58. package/src/components/sources.ts +0 -92
  59. package/src/hooks/useTimeMachine.ts +0 -26
  60. package/src/index.tsx +0 -68
  61. package/src/preset.tsx +0 -47
  62. package/src/store/routeRestore.ts +0 -194
  63. package/src/store/snapshotVault.ts +0 -274
  64. package/src/store/timeMachineStore.ts +0 -881
  65. package/src/sync/timeMachineSyncAdapter.ts +0 -241
  66. package/src/ui/SwipeActionsRow.tsx +0 -199
  67. package/src/ui/primitives.tsx +0 -157
  68. package/src/ui/tmTheme.ts +0 -109
@@ -1,1090 +0,0 @@
1
- /**
2
- * Restore Preview — "what will restoring this snapshot actually change?"
3
- *
4
- * ONE virtualized FlatList is the scrollable area (the section header, the
5
- * source rows, their item rows and the inline diffs are all list rows) with
6
- * a sticky Restore CTA footer — no nested scroll regions, so thousands of
7
- * storage keys stay cheap.
8
- *
9
- * Layout follows the Time Machine mockup: source sections are card
10
- * dropdowns with tool-icon tiles, a "N keys · M changed" detection subtitle,
11
- * ±≈ badges, a search field with an expand/collapse-all button, and a bottom
12
- * "Restore State" pill. Only rows a restore would touch (or can't touch)
13
- * render — unchanged items never do. Every applicable item keeps its
14
- * INCLUDE checkbox (source headers toggle their whole section) — unchecked
15
- * items are passed to restore as exclusions and left untouched.
16
- */
17
- import {
18
- memo,
19
- useCallback,
20
- useEffect,
21
- useMemo,
22
- useRef,
23
- useState,
24
- type ReactNode,
25
- } from "react";
26
- import {
27
- ActivityIndicator,
28
- FlatList,
29
- StyleSheet,
30
- Text,
31
- TouchableOpacity,
32
- View,
33
- type ListRenderItem,
34
- } from "react-native";
35
- import {
36
- ChevronUp,
37
- AlertTriangle,
38
- RefreshCw,
39
- useSafeAreaInsets,
40
- } from "@buoy-gg/shared-ui";
41
- import type { StateSnapshotPreviewItem } from "@buoy-gg/shared-ui";
42
- import { useToolHeader, useToolHost } from "@buoy-gg/core";
43
- import { DisclosureChevron, Group, SectionLabel } from "../../ui/primitives";
44
- import { TM_MONO, tm } from "../../ui/tmTheme";
45
- import type {
46
- PreviewSideRef,
47
- PreviewSource,
48
- PreviewState,
49
- } from "../../store/timeMachineStore";
50
- import { timeMachineStore, willRestoreRoute } from "../../store/timeMachineStore";
51
- import { ItemDiffPanel } from "./ItemDiffPanel";
52
- import { RestorePointNameRow } from "./RestorePointNameRow";
53
- import type { SnapshotMeta } from "../../store/snapshotVault";
54
- import { VERDICT_META } from "./verdictMeta";
55
-
56
- const SOURCE_NOUNS: Record<string, string> = {
57
- storage: "keys",
58
- redux: "slices",
59
- zustand: "stores",
60
- jotai: "atoms",
61
- query: "queries",
62
- };
63
-
64
- /**
65
- * Where a row sits in the one card that holds the whole list. The list has
66
- * to stay flat to stay virtualized, so each row paints its own share of the
67
- * card: the first row rounds its top, the last rounds its bottom, and every
68
- * other row draws the hairline above it.
69
- */
70
- interface CardPosition {
71
- first: boolean;
72
- last: boolean;
73
- }
74
-
75
- interface RowSourceHeader extends CardPosition {
76
- kind: "source";
77
- source: PreviewSource;
78
- collapsed: boolean;
79
- includeState: "all" | "some" | "none";
80
- applicableCount: number;
81
- counts: { added: number; removed: number; changed: number };
82
- /** False when the card has nothing to expand (a clean "No changes" source). */
83
- expandable: boolean;
84
- /** "60 keys · 7 changed" — detection proof without expanding. */
85
- summary: string;
86
- }
87
- interface RowItem extends CardPosition {
88
- kind: "item";
89
- sourceId: string;
90
- item: StateSnapshotPreviewItem;
91
- excluded: boolean;
92
- }
93
- /**
94
- * The route leg, as a row in the same card as the sources. It is not a
95
- * source — nothing diffs it — but "will this also take me back to
96
- * /checkout?" is a decision about THIS restore, so it belongs beside the
97
- * other things the restore is about to do rather than on the list screen.
98
- */
99
- interface RowRoute extends CardPosition {
100
- kind: "route";
101
- href: string;
102
- on: boolean;
103
- }
104
- interface RowDiff extends CardPosition {
105
- kind: "diff";
106
- sourceId: string;
107
- item: StateSnapshotPreviewItem;
108
- }
109
- interface RowNote extends CardPosition {
110
- kind: "note";
111
- id: string;
112
- text: string;
113
- }
114
- type Row = RowSourceHeader | RowItem | RowNote | RowDiff | RowRoute;
115
-
116
- /** Shared empty selection — a stable identity for "nothing is excluded". */
117
- const EMPTY_SELECTION: ReadonlySet<string> = new Set<string>();
118
-
119
- function sameSelection(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
120
- if (a.size !== b.size) return false;
121
- for (const key of a) if (!b.has(key)) return false;
122
- return true;
123
- }
124
-
125
- /** Compound exclusion key — what timeMachineStore.restore expects. */
126
- function cKey(sourceId: string, itemKey: string): string {
127
- return `${sourceId}::${itemKey}`;
128
- }
129
-
130
- function shortPreview(value: unknown): string {
131
- if (value === undefined) return "∅";
132
- try {
133
- const s = typeof value === "string" ? `"${value}"` : JSON.stringify(value);
134
- if (!s) return String(value);
135
- return s.length > 46 ? `${s.slice(0, 43)}…` : s;
136
- } catch {
137
- return "[complex]";
138
- }
139
- }
140
-
141
-
142
-
143
- /**
144
- * The grouped-card shell one row paints. Rounds the ends, insets the card
145
- * from the sheet, and draws the hairline that separates it from the row
146
- * above — the same shape the home list's <Group> makes, rebuilt per row so
147
- * the list stays virtualized.
148
- */
149
- function CardRow({
150
- position,
151
- children,
152
- }: {
153
- position: CardPosition;
154
- children: ReactNode;
155
- }) {
156
- return (
157
- <View
158
- style={[
159
- styles.cardRow,
160
- position.first ? styles.cardRowFirst : null,
161
- position.last ? styles.cardRowLast : null,
162
- ]}
163
- >
164
- {position.first ? null : <View style={styles.cardSeparator} />}
165
- {children}
166
- </View>
167
- );
168
- }
169
-
170
- function CountPill({
171
- glyph,
172
- count,
173
- color,
174
- }: {
175
- glyph: string;
176
- count: number;
177
- color: string;
178
- }) {
179
- return (
180
- <View style={[styles.countPill, { backgroundColor: `${color}26` }]}>
181
- <Text style={[styles.countPillText, { color }]}>
182
- {glyph}
183
- {count}
184
- </Text>
185
- </View>
186
- );
187
- }
188
-
189
- function Checkbox({ state }: { state: "all" | "some" | "none" }) {
190
- return (
191
- <View style={[styles.checkbox, state !== "none" && styles.checkboxChecked]}>
192
- {state === "none" ? null : (
193
- <Text style={styles.checkboxGlyph}>{state === "all" ? "✓" : "−"}</Text>
194
- )}
195
- </View>
196
- );
197
- }
198
-
199
- const ItemRow = memo(function ItemRow({
200
- row,
201
- expanded,
202
- onOpen,
203
- onToggle,
204
- }: {
205
- row: RowItem;
206
- expanded: boolean;
207
- /** Zero-arg by design — press plumbing may invoke handlers with a
208
- * synthetic event; the row is bound at the call site. */
209
- onOpen: () => void;
210
- onToggle: () => void;
211
- }) {
212
- const meta = VERDICT_META[row.item.verdict];
213
- const dimmed = !meta.applies || row.excluded;
214
- const openable =
215
- row.item.verdict === "changed" ||
216
- row.item.verdict === "added" ||
217
- row.item.verdict === "removed";
218
- return (
219
- <CardRow position={row}>
220
- <View style={[styles.itemRow, dimmed && styles.dimmed]}>
221
- <TouchableOpacity
222
- onPress={onToggle}
223
- disabled={!meta.applies}
224
- hitSlop={{ top: 10, bottom: 10, left: 8, right: 8 }}
225
- testID={`tm-preview-toggle-${row.sourceId}-${row.item.key}`}
226
- >
227
- <Checkbox state={!meta.applies || row.excluded ? "none" : "all"} />
228
- </TouchableOpacity>
229
- <TouchableOpacity
230
- style={styles.itemBodyTouch}
231
- onPress={() => openable && onOpen()}
232
- disabled={!openable}
233
- testID={`tm-preview-item-${row.sourceId}-${row.item.key}`}
234
- >
235
- <Text style={[styles.itemGlyph, { color: meta.color }]}>
236
- {meta.glyph}
237
- </Text>
238
- <View style={styles.itemBody}>
239
- <Text style={styles.itemLabel} numberOfLines={1}>
240
- {row.item.label}
241
- </Text>
242
- {row.item.verdict === "changed" && (
243
- <Text style={styles.itemPreview} numberOfLines={1}>
244
- {shortPreview(row.item.oldValue)} →{" "}
245
- {shortPreview(row.item.newValue)}
246
- </Text>
247
- )}
248
- {row.item.verdict === "added" && (
249
- <Text style={styles.itemPreview} numberOfLines={1}>
250
- {shortPreview(row.item.newValue)}
251
- </Text>
252
- )}
253
- {row.item.verdict === "removed" && (
254
- <Text
255
- style={[styles.itemPreview, styles.itemPreviewRemoved]}
256
- numberOfLines={1}
257
- >
258
- {shortPreview(row.item.oldValue)}
259
- </Text>
260
- )}
261
- {row.excluded ? (
262
- <Text style={styles.itemExcluded}>
263
- excluded — restore leaves this untouched
264
- </Text>
265
- ) : (
266
- row.item.reason && (
267
- <Text style={styles.itemReason} numberOfLines={2}>
268
- {row.item.reason}
269
- </Text>
270
- )
271
- )}
272
- </View>
273
- {openable ? (
274
- expanded ? (
275
- <ChevronUp size={16} color={tm.color.labelTertiary} />
276
- ) : (
277
- <DisclosureChevron />
278
- )
279
- ) : null}
280
- </TouchableOpacity>
281
- </View>
282
- </CardRow>
283
- );
284
- });
285
-
286
- export interface RestorePreviewScreenProps {
287
- preview: PreviewState;
288
- snapshots: SnapshotMeta[];
289
- busy: boolean;
290
- onBack: () => void;
291
- onRestore: (mode: "live" | "reload", excludeKeys: string[]) => void;
292
- }
293
-
294
- export function RestorePreviewScreen({
295
- preview,
296
- snapshots,
297
- busy,
298
- onBack,
299
- onRestore,
300
- }: RestorePreviewScreenProps) {
301
- const host = useToolHost();
302
- const hosted = host.instanceId !== undefined;
303
- // `minBottom` is a floor, not a preference: the dimension map can't know
304
- // about a device that ships next year, and an unmapped one falls through to
305
- // `bottom: 0`. This keeps the CTA off the home indicator either way.
306
- const insets = useSafeAreaInsets({ minBottom: 16 });
307
-
308
- const [collapsed, setCollapsed] = useState<Record<string, boolean>>({});
309
- const [excluded, setExcluded] = useState<ReadonlySet<string>>(new Set());
310
- /** Set by every checkbox interaction — see the auto-save effect below. */
311
- const userEditedRef = useRef(false);
312
- /** Item rows whose diff is expanded inline, by compound key. */
313
- const [openDiffs, setOpenDiffs] = useState<ReadonlySet<string>>(EMPTY_SELECTION);
314
- const toggleDiff = useCallback((key: string) => {
315
- setOpenDiffs((prev) => {
316
- const next = new Set(prev);
317
- if (next.has(key)) next.delete(key);
318
- else next.add(key);
319
- return next;
320
- });
321
- }, []);
322
- // Filtering lives in the shared modal header (the magnifier), same as the
323
- // restore-point list and every other Buoy tool — one place to look for it.
324
- const search = host.search;
325
-
326
- const rightMeta =
327
- preview.right === "current"
328
- ? undefined
329
- : snapshots.find(
330
- (s) => s.id === (preview.right as { snapshotId: string }).snapshotId
331
- );
332
- // Latest-ref: `renderRow` is memoized on its handlers, so this one has to
333
- // keep a stable identity while still reading the current snapshot.
334
- const rightMetaRef = useRef(rightMeta);
335
- rightMetaRef.current = rightMeta;
336
-
337
- /** Flip whether this restore also navigates back to the captured route. */
338
- const toggleRoute = useCallback(() => {
339
- if (!rightMetaRef.current) return;
340
- const meta = rightMetaRef.current;
341
- void timeMachineStore.setRestoreRoute(meta.id, !willRestoreRoute(meta));
342
- }, []);
343
-
344
- const isBaseline = rightMeta?.baseline === true;
345
- const liveLeft = preview.left === "current";
346
-
347
- /**
348
- * The selection this restore point already remembers, as exclusions. Null
349
- * until there is a snapshot on the right-hand side to have one.
350
- */
351
- const savedExcluded = useMemo<ReadonlySet<string> | null>(() => {
352
- if (!rightMeta) return null;
353
- return rightMeta.excludedKeys?.length
354
- ? new Set(rightMeta.excludedKeys)
355
- : EMPTY_SELECTION;
356
- }, [rightMeta]);
357
-
358
- /**
359
- * A snapshot still carrying the older `scope` include-list ("only ever
360
- * touch these", set via MCP). It seeds the checkboxes and is converted to
361
- * exclusions on read — a restore of it would otherwise still apply include
362
- * semantics, and the two forms would disagree about what one tap does.
363
- */
364
- const legacyScoped =
365
- !!rightMeta?.scope?.length && !rightMeta?.excludedKeys?.length;
366
- const legacySeed = useMemo<ReadonlySet<string>>(() => {
367
- if (!legacyScoped || !rightMeta?.scope) return EMPTY_SELECTION;
368
- const scopeSet = new Set(rightMeta.scope);
369
- const next = new Set<string>();
370
- for (const src of preview.sources) {
371
- for (const item of src.items) {
372
- const key = cKey(src.id, item.key);
373
- if (VERDICT_META[item.verdict].applies && !scopeSet.has(key)) {
374
- next.add(key);
375
- }
376
- }
377
- }
378
- return next;
379
- }, [legacyScoped, rightMeta, preview.sources]);
380
-
381
- // Open with the saved selection already applied — once per snapshot, and
382
- // only once there is a diff to apply it to.
383
- const seededFor = useRef<string | null>(null);
384
- useEffect(() => {
385
- if (!rightMeta || preview.building || !savedExcluded) return;
386
- if (seededFor.current === rightMeta.id) return;
387
- seededFor.current = rightMeta.id;
388
- userEditedRef.current = false;
389
- const seed = savedExcluded.size > 0 ? savedExcluded : legacySeed;
390
- if (seed.size > 0) setExcluded(new Set(seed));
391
- // Convert an older include-list scope the moment it's read, so the two
392
- // forms never disagree about what a restore will do.
393
- if (legacyScoped && seed.size > 0) {
394
- void timeMachineStore.setExclusions(rightMeta.id, Array.from(seed));
395
- }
396
- }, [rightMeta, preview.building, savedExcluded, legacySeed, legacyScoped]);
397
-
398
- /**
399
- * Auto-save. The checkboxes ARE the restore point's setting, so there is
400
- * nothing to confirm — every edit persists as EXCLUSIONS (the items to
401
- * leave alone), and every later restore of this point honors them, one-tap
402
- * RESTORE and MCP included.
403
- *
404
- * Never an include list: unchecking one of ten keys must keep restoring the
405
- * other nine AND anything that only starts differing tomorrow, which a list
406
- * built from today's diff cannot do.
407
- *
408
- * Gated on a ref rather than on comparing to what's stored, because on the
409
- * frames before the seed lands `excluded` is legitimately empty — writing
410
- * that would erase the saved selection we are about to load.
411
- */
412
- useEffect(() => {
413
- if (!rightMeta || !savedExcluded || !userEditedRef.current) return;
414
- if (sameSelection(excluded, savedExcluded)) return;
415
- const keys = Array.from(excluded);
416
- void timeMachineStore.setExclusions(rightMeta.id, keys.length ? keys : null);
417
- }, [excluded, rightMeta, savedExcluded]);
418
-
419
- const toggleItem = useCallback((key: string) => {
420
- userEditedRef.current = true;
421
- setExcluded((prev) => {
422
- const next = new Set(prev);
423
- if (next.has(key)) next.delete(key);
424
- else next.add(key);
425
- return next;
426
- });
427
- }, []);
428
-
429
- const toggleSource = useCallback(
430
- (source: PreviewSource, includeState: "all" | "some" | "none") => {
431
- userEditedRef.current = true;
432
- setExcluded((prev) => {
433
- const next = new Set(prev);
434
- for (const item of source.items) {
435
- if (!VERDICT_META[item.verdict].applies) continue;
436
- const key = cKey(source.id, item.key);
437
- if (includeState === "all") next.add(key);
438
- else next.delete(key);
439
- }
440
- return next;
441
- });
442
- },
443
- []
444
- );
445
-
446
- // Takes the EFFECTIVE collapsed state — the map is sparse (defaults come
447
- // from the ?? fallback), so `!map[id]` would no-op the first tap on a
448
- // default-collapsed card.
449
- const toggleCollapse = useCallback((id: string, currentlyCollapsed: boolean) => {
450
- setCollapsed((c) => ({ ...c, [id]: !currentlyCollapsed }));
451
- }, []);
452
-
453
- const totals = useMemo(() => {
454
- let applies = 0;
455
- let excludedCount = 0;
456
- let wontApply = 0;
457
- const perSource: string[] = [];
458
- for (const src of preview.sources) {
459
- let n = 0;
460
- for (const item of src.items) {
461
- const m = VERDICT_META[item.verdict];
462
- if (m.applies) {
463
- if (excluded.has(cKey(src.id, item.key))) excludedCount += 1;
464
- else {
465
- applies += 1;
466
- n += 1;
467
- }
468
- } else if (item.verdict === "wont-apply") wontApply += 1;
469
- }
470
- if (n > 0) perSource.push(`${n} ${src.label.toLowerCase()}`);
471
- }
472
- return { applies, excludedCount, wontApply, perSource };
473
- }, [preview.sources, excluded]);
474
-
475
- // Hosted: back + identity in the shared modal header. Restore lives in the
476
- // bottom CTA; the preset's labeled RELOAD APP action stays available.
477
- useToolHeader(
478
- hosted
479
- ? {
480
- title: "Restore Preview",
481
- subtitle: rightMeta?.name ?? "preview",
482
- onBack,
483
- }
484
- : null,
485
- // eslint-disable-next-line react-hooks/exhaustive-deps
486
- [hosted, rightMeta?.name]
487
- );
488
-
489
- const { rows, blockedSources } = useMemo(() => {
490
- const q = search.trim().toLowerCase();
491
- const out: Row[] = [];
492
- // Sources the restore would not touch at all get no card: "no changes"
493
- // rows are noise on a screen about what WILL change.
494
- /** Sources holding a won't-apply item, so the note can name where to look. */
495
- const blocked: string[] = [];
496
- for (const src of preview.sources) {
497
- // Every detected source gets a card whose subtitle carries the
498
- // detection proof ("60 keys · 7 changed" / "2 slices · no changes"),
499
- // so clean sources need no expansion. Unchanged ITEMS never render.
500
- const relevant = src.items.some((i) => i.verdict !== "unchanged");
501
- if (!relevant && !src.error) continue;
502
- const expandable = relevant || src.notes.length > 0 || !!src.error;
503
-
504
- const applicable = src.items.filter(
505
- (i) => VERDICT_META[i.verdict].applies
506
- );
507
- const wontApplyCount = src.items.filter(
508
- (i) => i.verdict === "wont-apply"
509
- ).length;
510
- if (wontApplyCount > 0) blocked.push(src.label);
511
- const noun =
512
- src.items.length === 1
513
- ? (SOURCE_NOUNS[src.id] ?? "items").replace(/ies$/, "y").replace(/s$/, "")
514
- : SOURCE_NOUNS[src.id] ?? "items";
515
- const summary =
516
- `${src.items.length} ${noun} · ` +
517
- (applicable.length > 0
518
- ? `${applicable.length} changed`
519
- : wontApplyCount > 0
520
- ? `${wontApplyCount} won't apply`
521
- : "no changes");
522
- const excludedInSource = applicable.filter((i) =>
523
- excluded.has(cKey(src.id, i.key))
524
- ).length;
525
- const includeState: RowSourceHeader["includeState"] =
526
- applicable.length === 0 || excludedInSource === 0
527
- ? "all"
528
- : excludedInSource === applicable.length
529
- ? "none"
530
- : "some";
531
- const counts = { added: 0, removed: 0, changed: 0 };
532
- for (const i of src.items) {
533
- if (excluded.has(cKey(src.id, i.key))) continue;
534
- if (i.verdict === "added") counts.added += 1;
535
- else if (i.verdict === "removed") counts.removed += 1;
536
- else if (i.verdict === "changed" || i.verdict === "too-large")
537
- counts.changed += 1;
538
- }
539
-
540
- const visible = src.items.filter((item) => {
541
- // Unchanged items never render — the dropdowns show only what a
542
- // restore would touch (changed) or can't touch (won't-apply).
543
- if (item.verdict === "unchanged") return false;
544
- if (q && !item.label.toLowerCase().includes(q)) return false;
545
- return true;
546
- });
547
- // Everything starts collapsed. The screen's job on open is "which
548
- // sources would this touch, and how much" — expanding a source with
549
- // 58 keys before you asked buries that under its own contents.
550
- const isCollapsed = expandable ? (collapsed[src.id] ?? true) : true;
551
- out.push({
552
- kind: "source",
553
- source: src,
554
- collapsed: isCollapsed,
555
- includeState,
556
- applicableCount: applicable.length,
557
- counts,
558
- expandable,
559
- summary,
560
- first: false,
561
- last: false,
562
- });
563
- if (!isCollapsed) {
564
- for (const note of src.notes) {
565
- out.push({
566
- kind: "note",
567
- id: `${src.id}:${note}`,
568
- text: note,
569
- first: false,
570
- last: false,
571
- });
572
- }
573
- if (src.error) {
574
- out.push({
575
- kind: "note",
576
- id: `${src.id}:err`,
577
- text: `⚠ ${src.error}`,
578
- first: false,
579
- last: false,
580
- });
581
- }
582
- for (const item of visible) {
583
- const key = cKey(src.id, item.key);
584
- out.push({
585
- kind: "item",
586
- sourceId: src.id,
587
- item,
588
- excluded: excluded.has(key),
589
- first: false,
590
- last: false,
591
- });
592
- if (openDiffs.has(key)) {
593
- out.push({
594
- kind: "diff",
595
- sourceId: src.id,
596
- item,
597
- first: false,
598
- last: false,
599
- });
600
- }
601
- }
602
- }
603
- }
604
- if (rightMeta?.route) {
605
- out.push({
606
- kind: "route",
607
- href: rightMeta.route.href,
608
- on: willRestoreRoute(rightMeta),
609
- first: false,
610
- last: false,
611
- });
612
- }
613
- // ONE card holds every source — the ends of the LIST round, and every
614
- // other boundary is just a hairline. Per-source cards would read as
615
- // separate groups, which they aren't: this is one list of what a restore
616
- // would touch.
617
- if (out.length > 0) {
618
- out[0].first = true;
619
- out[out.length - 1].last = true;
620
- }
621
- return { rows: out, blockedSources: blocked };
622
- }, [preview.sources, search, collapsed, excluded, openDiffs, rightMeta]);
623
-
624
- const renderRow: ListRenderItem<Row> = useCallback(
625
- ({ item: row }) => {
626
- if (row.kind === "source") {
627
- const src = row.source;
628
- const { counts } = row;
629
- return (
630
- <CardRow position={row}>
631
- <View style={styles.sourceCard}>
632
- {/* Always rendered, even when there is nothing to select: it is
633
- what every row lines up against now that the icons are gone,
634
- and an empty ring reads as "nothing selected here". */}
635
- <TouchableOpacity
636
- onPress={() => toggleSource(src, row.includeState)}
637
- disabled={row.applicableCount === 0}
638
- hitSlop={{ top: 10, bottom: 10, left: 8, right: 8 }}
639
- testID={`tm-preview-source-toggle-${src.id}`}
640
- >
641
- <Checkbox
642
- state={row.applicableCount === 0 ? "none" : row.includeState}
643
- />
644
- </TouchableOpacity>
645
- <TouchableOpacity
646
- style={styles.sourceCardTouch}
647
- onPress={() => row.expandable && toggleCollapse(src.id, row.collapsed)}
648
- disabled={!row.expandable}
649
- testID={`tm-preview-source-${src.id}`}
650
- >
651
- <View style={styles.sourceNameBlock}>
652
- <Text style={styles.sourceName} numberOfLines={1}>
653
- {src.label}
654
- </Text>
655
- <Text style={styles.sourceSummary} numberOfLines={1}>
656
- {row.includeState === "none" && row.applicableCount > 0
657
- ? `${row.summary} · excluded`
658
- : row.summary}
659
- </Text>
660
- </View>
661
- <View style={styles.sourceBadges}>
662
- {counts.removed > 0 ? (
663
- <CountPill glyph="−" count={counts.removed} color={tm.color.danger} />
664
- ) : null}
665
- {counts.added > 0 ? (
666
- <CountPill glyph="+" count={counts.added} color={tm.color.accent} />
667
- ) : null}
668
- {counts.changed > 0 ? (
669
- <CountPill glyph="≈" count={counts.changed} color={tm.color.info} />
670
- ) : null}
671
- </View>
672
- {row.expandable ? (
673
- row.collapsed ? (
674
- <DisclosureChevron />
675
- ) : (
676
- <ChevronUp size={16} color={tm.color.labelTertiary} />
677
- )
678
- ) : null}
679
- </TouchableOpacity>
680
- </View>
681
- </CardRow>
682
- );
683
- }
684
- if (row.kind === "note") {
685
- return (
686
- <CardRow position={row}>
687
- <Text style={styles.noteRow}>{row.text}</Text>
688
- </CardRow>
689
- );
690
- }
691
- if (row.kind === "route") {
692
- return (
693
- <CardRow position={row}>
694
- <TouchableOpacity
695
- style={styles.routeRow}
696
- onPress={toggleRoute}
697
- accessibilityRole="switch"
698
- accessibilityState={{ checked: row.on }}
699
- accessibilityLabel={`Also return to ${row.href}`}
700
- testID="tm-preview-route"
701
- >
702
- <Checkbox state={row.on ? "all" : "none"} />
703
- <View style={styles.routeText}>
704
- <Text style={styles.routeTitle}>Return to this screen</Text>
705
- <Text style={styles.routeHref} numberOfLines={1}>
706
- {row.href}
707
- </Text>
708
- </View>
709
- </TouchableOpacity>
710
- </CardRow>
711
- );
712
- }
713
- if (row.kind === "diff") {
714
- return (
715
- <CardRow position={row}>
716
- <ItemDiffPanel item={row.item} />
717
- </CardRow>
718
- );
719
- }
720
- return (
721
- <ItemRow
722
- row={row}
723
- expanded={openDiffs.has(cKey(row.sourceId, row.item.key))}
724
- onOpen={() => toggleDiff(cKey(row.sourceId, row.item.key))}
725
- onToggle={() => toggleItem(cKey(row.sourceId, row.item.key))}
726
- />
727
- );
728
- },
729
- [openDiffs, toggleDiff, toggleCollapse, toggleItem, toggleSource, toggleRoute]
730
- );
731
-
732
- const keyExtractor = useCallback((row: Row) => {
733
- if (row.kind === "source") return `s:${row.source.id}`;
734
- if (row.kind === "note") return `n:${row.id}`;
735
- if (row.kind === "route") return "route";
736
- if (row.kind === "diff") return `d:${row.sourceId}:${row.item.key}`;
737
- return `i:${row.sourceId}:${row.item.key}`;
738
- }, []);
739
-
740
- const header = (
741
- <View>
742
- {!hosted && (
743
- <View style={styles.fallbackHeader}>
744
- <TouchableOpacity onPress={onBack} hitSlop={HIT} testID="tm-preview-back">
745
- <Text style={styles.backText}>‹ Back</Text>
746
- </TouchableOpacity>
747
- <Text style={styles.screenTitle} numberOfLines={1}>
748
- Restore Preview
749
- </Text>
750
- </View>
751
- )}
752
-
753
- {rightMeta ? (
754
- <>
755
- <SectionLabel>Restore Point</SectionLabel>
756
- <Group>
757
- <RestorePointNameRow
758
- name={rightMeta.name}
759
- onRename={(next) =>
760
- void timeMachineStore.rename(rightMeta.id, next)
761
- }
762
- />
763
- </Group>
764
- </>
765
- ) : null}
766
-
767
- <SectionLabel>Changes to Restore</SectionLabel>
768
- </View>
769
- );
770
-
771
- const ctaDisabled = busy || preview.building || totals.applies === 0;
772
-
773
- return (
774
- <View style={styles.container}>
775
- <FlatList
776
- data={rows}
777
- renderItem={renderRow}
778
- keyExtractor={keyExtractor}
779
- ListHeaderComponent={header}
780
- ListEmptyComponent={
781
- preview.building ? (
782
- <ActivityIndicator
783
- style={styles.buildingSpinner}
784
- size="small"
785
- color={tm.color.accent}
786
- />
787
- ) : (
788
- <Text style={styles.emptyText}>
789
- {search
790
- ? "Nothing matches this filter."
791
- : "No changes — restoring would change nothing."}
792
- </Text>
793
- )
794
- }
795
- ListFooterComponent={
796
- <View>
797
- {totals.wontApply > 0 ? (
798
- <View style={styles.warnNote}>
799
- <AlertTriangle size={12} color={tm.color.warning} />
800
- <Text style={styles.warnNoteText}>
801
- {totals.wontApply} item{totals.wontApply === 1 ? "" : "s"}{" "}
802
- won't apply — expand{" "}
803
- {blockedSources.length > 0
804
- ? blockedSources.join(" and ")
805
- : "the source"}{" "}
806
- to see the reason.
807
- </Text>
808
- </View>
809
- ) : null}
810
- </View>
811
- }
812
- removeClippedSubviews
813
- initialNumToRender={20}
814
- windowSize={7}
815
- contentContainerStyle={styles.listContent}
816
- />
817
-
818
- {/* Sticky Restore CTA */}
819
- {liveLeft && rightMeta && (
820
- <View style={[styles.footer, { paddingBottom: insets.bottom }]}>
821
- <TouchableOpacity
822
- style={[
823
- styles.cta,
824
- isBaseline && styles.ctaDanger,
825
- ctaDisabled && styles.ctaDisabled,
826
- ]}
827
- onPress={() =>
828
- onRestore(isBaseline ? "reload" : "live", Array.from(excluded))
829
- }
830
- disabled={isBaseline ? busy || preview.building : ctaDisabled}
831
- testID="tm-preview-restore"
832
- >
833
- <RefreshCw size={16} color={isBaseline ? tm.color.onDanger : tm.color.onAccent} />
834
- <Text
835
- style={[styles.ctaText, isBaseline ? styles.ctaTextDanger : null]}
836
- >
837
- {isBaseline ? "Wipe & Reload" : "Restore State"}
838
- </Text>
839
- </TouchableOpacity>
840
- <Text style={styles.ctaCaption}>
841
- {isBaseline
842
- ? "This wipes all app storage and reloads the app."
843
- : totals.excludedCount > 0
844
- ? `Restores ${totals.applies} of ${totals.applies + totals.excludedCount} change${totals.applies + totals.excludedCount === 1 ? "" : "s"} — everything else stays as it is.`
845
- : "This will replace the current state with the snapshot."}
846
- </Text>
847
- </View>
848
- )}
849
- </View>
850
- );
851
- }
852
-
853
- const HIT = { top: 10, bottom: 10, left: 10, right: 10 };
854
-
855
- const styles = StyleSheet.create({
856
- // Transparent so JsModal's ToolBackground shows through (the modal paints opaque base beneath it).
857
- container: { flex: 1, backgroundColor: "transparent" },
858
- fallbackHeader: {
859
- flexDirection: "row",
860
- alignItems: "center",
861
- paddingHorizontal: tm.gutter,
862
- paddingVertical: 10,
863
- gap: 10,
864
- },
865
- backText: { color: tm.color.accent, fontSize: tm.font.control },
866
- screenTitle: {
867
- color: tm.color.label,
868
- fontSize: 20,
869
- fontWeight: "700",
870
- letterSpacing: tm.tracking.row,
871
- flex: 1,
872
- },
873
- dimmed: { opacity: 0.5 },
874
- listContent: { paddingTop: 14, paddingBottom: 12 },
875
-
876
- // ── The grouped card each list row paints its own share of ──────────────
877
- cardRow: {
878
- marginHorizontal: tm.gutter,
879
- backgroundColor: tm.color.group,
880
- },
881
- cardRowFirst: {
882
- borderTopLeftRadius: tm.radius.group,
883
- borderTopRightRadius: tm.radius.group,
884
- },
885
- cardRowLast: {
886
- borderBottomLeftRadius: tm.radius.group,
887
- borderBottomRightRadius: tm.radius.group,
888
- marginBottom: 10,
889
- },
890
- cardSeparator: {
891
- height: StyleSheet.hairlineWidth,
892
- marginLeft: 51,
893
- backgroundColor: tm.color.separator,
894
- },
895
-
896
- // ── Selection card ──────────────────────────────────────────────────────
897
-
898
- // ── The "won't apply" heads-up under the card ───────────────────────────
899
- warnNote: {
900
- flexDirection: "row",
901
- alignItems: "flex-start",
902
- gap: 6,
903
- paddingHorizontal: tm.gutter + tm.textInset,
904
- paddingTop: 8,
905
- },
906
- warnNoteText: {
907
- flex: 1,
908
- color: tm.color.labelSecondary,
909
- fontSize: tm.font.footnote,
910
- lineHeight: tm.font.footnote * 1.35,
911
- },
912
-
913
- // ── Count pills on a source row ─────────────────────────────────────────
914
- countPill: {
915
- borderRadius: tm.radius.pill,
916
- paddingHorizontal: 9,
917
- paddingVertical: 3,
918
- },
919
- countPillText: {
920
- fontFamily: TM_MONO,
921
- fontSize: tm.font.footnote,
922
- fontWeight: "600",
923
- },
924
-
925
- // ── Include checkbox ────────────────────────────────────────────────────
926
- checkbox: {
927
- width: 23,
928
- height: 23,
929
- borderRadius: tm.radius.pill,
930
- borderWidth: 1.7,
931
- borderColor: tm.color.labelTertiary,
932
- alignItems: "center",
933
- justifyContent: "center",
934
- },
935
- checkboxChecked: {
936
- borderColor: tm.color.accent,
937
- backgroundColor: tm.color.accent,
938
- },
939
- checkboxGlyph: {
940
- color: tm.color.onAccent,
941
- fontSize: 13,
942
- fontWeight: "700",
943
- lineHeight: 15,
944
- },
945
-
946
- // ── Route row ───────────────────────────────────────────────────────────
947
- routeRow: {
948
- flexDirection: "row",
949
- alignItems: "center",
950
- minHeight: 58,
951
- paddingHorizontal: tm.textInset,
952
- paddingVertical: 9,
953
- gap: 12,
954
- },
955
- routeText: { flex: 1, minWidth: 0, gap: 2 },
956
- routeTitle: {
957
- color: tm.color.label,
958
- fontSize: tm.font.row,
959
- fontWeight: "600",
960
- letterSpacing: tm.tracking.row,
961
- },
962
- routeHref: {
963
- color: tm.color.labelSecondary,
964
- fontFamily: TM_MONO,
965
- fontSize: tm.font.mono,
966
- },
967
-
968
- // ── Source header row (first row of its card) ───────────────────────────
969
- sourceCard: {
970
- flexDirection: "row",
971
- alignItems: "center",
972
- minHeight: 58,
973
- paddingHorizontal: tm.textInset,
974
- paddingVertical: 9,
975
- gap: 12,
976
- },
977
- sourceCardTouch: {
978
- flex: 1,
979
- flexDirection: "row",
980
- alignItems: "center",
981
- gap: 12,
982
- minWidth: 0,
983
- },
984
- sourceNameBlock: { flex: 1, minWidth: 0, gap: 2 },
985
- sourceName: {
986
- color: tm.color.label,
987
- fontSize: tm.font.row,
988
- fontWeight: "600",
989
- letterSpacing: tm.tracking.row,
990
- },
991
- sourceSummary: {
992
- color: tm.color.labelSecondary,
993
- fontSize: tm.font.footnote,
994
- fontVariant: ["tabular-nums"],
995
- },
996
- sourceBadges: { flexDirection: "row", gap: 6 },
997
-
998
- noteRow: {
999
- color: tm.color.labelTertiary,
1000
- fontSize: tm.font.footnote,
1001
- lineHeight: tm.font.footnote * 1.35,
1002
- paddingHorizontal: tm.textInset,
1003
- paddingVertical: 9,
1004
- },
1005
-
1006
- // ── Item rows (further rows of the same card) ───────────────────────────
1007
- itemRow: {
1008
- flexDirection: "row",
1009
- alignItems: "center",
1010
- paddingLeft: tm.textInset,
1011
- paddingRight: tm.textInset,
1012
- paddingVertical: 10,
1013
- gap: 12,
1014
- },
1015
- itemBodyTouch: {
1016
- flex: 1,
1017
- flexDirection: "row",
1018
- alignItems: "center",
1019
- gap: 10,
1020
- minWidth: 0,
1021
- },
1022
- itemGlyph: { fontSize: 14, fontWeight: "700", width: 14, textAlign: "center" },
1023
- itemBody: { flex: 1, minWidth: 0 },
1024
- itemLabel: {
1025
- color: tm.color.label,
1026
- fontSize: tm.font.control,
1027
- letterSpacing: tm.tracking.control,
1028
- },
1029
- itemPreview: {
1030
- color: tm.color.labelSecondary,
1031
- fontFamily: TM_MONO,
1032
- fontSize: tm.font.mono,
1033
- marginTop: 3,
1034
- },
1035
- itemPreviewRemoved: { textDecorationLine: "line-through" },
1036
- itemReason: {
1037
- color: tm.color.warning,
1038
- fontSize: tm.font.mono,
1039
- marginTop: 3,
1040
- },
1041
- itemExcluded: {
1042
- color: tm.color.labelTertiary,
1043
- fontSize: tm.font.mono,
1044
- marginTop: 3,
1045
- fontStyle: "italic",
1046
- },
1047
- buildingSpinner: {
1048
- marginTop: 28,
1049
- },
1050
- emptyText: {
1051
- color: tm.color.labelSecondary,
1052
- fontSize: tm.font.footnote,
1053
- textAlign: "center",
1054
- marginTop: 28,
1055
- },
1056
-
1057
- // ── Sticky restore CTA ──────────────────────────────────────────────────
1058
- footer: {
1059
- paddingHorizontal: tm.gutter,
1060
- paddingTop: 10,
1061
- gap: 8,
1062
- borderTopColor: tm.color.separator,
1063
- borderTopWidth: StyleSheet.hairlineWidth,
1064
- backgroundColor: tm.color.sheet,
1065
- },
1066
- cta: {
1067
- flexDirection: "row",
1068
- alignItems: "center",
1069
- justifyContent: "center",
1070
- gap: 8,
1071
- height: 50,
1072
- backgroundColor: tm.color.accent,
1073
- borderRadius: tm.radius.group,
1074
- },
1075
- ctaDanger: { backgroundColor: tm.color.danger },
1076
- ctaTextDanger: { color: tm.color.onDanger },
1077
- ctaDisabled: { opacity: 0.4 },
1078
- ctaText: {
1079
- color: tm.color.onAccent,
1080
- fontSize: tm.font.row,
1081
- fontWeight: "600",
1082
- letterSpacing: tm.tracking.row,
1083
- },
1084
- ctaCaption: {
1085
- color: tm.color.labelSecondary,
1086
- fontSize: tm.font.footnote,
1087
- lineHeight: tm.font.footnote * 1.35,
1088
- textAlign: "center",
1089
- },
1090
- });