@buoy-gg/time-machine 7.0.41 → 7.0.42

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