@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,155 +0,0 @@
1
- /**
2
- * One restore point in the list: what it is, when it was taken, how big it
3
- * is, where it was captured — and the single action worth having at arm's
4
- * reach. Tapping the row opens the restore preview; the pill restores now.
5
- *
6
- * The route is shown as context — where this state was true. Whether a
7
- * restore also navigates there is decided in the restore preview, beside the
8
- * other changes it is about to make.
9
- *
10
- * Duplicate and delete live behind a swipe. A destructive target beside
11
- * "Restore" is a mis-tap that costs a snapshot, and the two-step gesture is
12
- * deliberate enough — recovery is the undo the list offers after, not a
13
- * dialog before. Renaming is NOT here: it belongs with the restore point's
14
- * other settings, on the preview screen.
15
- */
16
- import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
17
- import { PillLabel } from "../../ui/primitives";
18
- import { SwipeActionsRow } from "../../ui/SwipeActionsRow";
19
- import { TM_MONO, tm } from "../../ui/tmTheme";
20
- import type { SnapshotMeta } from "../../store/snapshotVault";
21
- import { formatBytes, timeAgo } from "../format";
22
-
23
- /** "15h ago · 9.5 KB · 5 sources · skips 2" */
24
- function describe(meta: SnapshotMeta): string {
25
- if (meta.baseline) return "Wipes to fresh install";
26
- const parts = [
27
- timeAgo(meta.createdAt),
28
- formatBytes(meta.sizeBytes),
29
- `${Object.keys(meta.sources).length} sources`,
30
- ];
31
- // A saved selection is worth stating on the row — this restore point no
32
- // longer does the obvious thing, and one tap on RESTORE honors it.
33
- if (meta.excludedKeys?.length) parts.push(`skips ${meta.excludedKeys.length}`);
34
- else if (meta.scope?.length) parts.push(`scoped (${meta.scope.length})`);
35
- return parts.join(" · ");
36
- }
37
-
38
- export function SnapshotRow({
39
- meta,
40
- busy,
41
- onOpen,
42
- onRestore,
43
- onDelete,
44
- onDuplicate,
45
- }: {
46
- meta: SnapshotMeta;
47
- busy: boolean;
48
- /** Zero-arg: a data-taking `onPress` prop is invoked with the event by
49
- * Buoy MCP's tap_element, which crashes the row. */
50
- onOpen: () => void;
51
- onRestore: () => void;
52
- onDelete: () => void;
53
- onDuplicate: () => void;
54
- }) {
55
- const testID = `time-machine-snap-${meta.id}`;
56
-
57
- return (
58
- <SwipeActionsRow
59
- testID={testID}
60
- actions={[
61
- // "Dup" over "Copy": on a row full of text, "Copy" reads as
62
- // copy-to-clipboard.
63
- { label: "Dup", onPress: onDuplicate },
64
- {
65
- label: "Delete",
66
- onPress: onDelete,
67
- background: tm.color.danger,
68
- color: tm.color.onDanger,
69
- },
70
- ]}
71
- >
72
- <TouchableOpacity
73
- style={styles.row}
74
- onPress={onOpen}
75
- activeOpacity={0.7}
76
- accessibilityRole="button"
77
- accessibilityLabel={`${meta.name}. ${describe(meta)}. Open restore preview`}
78
- testID={testID}
79
- >
80
- <View style={styles.text}>
81
- <Text style={styles.name} numberOfLines={1}>
82
- {meta.name}
83
- </Text>
84
- <Text style={styles.meta} numberOfLines={1}>
85
- {describe(meta)}
86
- </Text>
87
- {meta.lastRestoredAt ? (
88
- <Text style={styles.restored} numberOfLines={1}>
89
- Restored {timeAgo(meta.lastRestoredAt)}
90
- </Text>
91
- ) : null}
92
- {meta.route ? (
93
- <Text style={styles.route} numberOfLines={1}>
94
- {meta.route.href}
95
- </Text>
96
- ) : null}
97
- </View>
98
- <TouchableOpacity
99
- onPress={onRestore}
100
- disabled={busy}
101
- style={busy ? styles.actionDisabled : null}
102
- accessibilityRole="button"
103
- accessibilityLabel={meta.baseline ? "Wipe and reload" : "Restore"}
104
- testID={`${testID}-restore`}
105
- >
106
- <PillLabel
107
- label={meta.baseline ? "Wipe" : "Restore"}
108
- color={meta.baseline ? tm.color.danger : tm.color.accent}
109
- background={meta.baseline ? tm.color.dangerSoft : tm.color.accentSoft}
110
- />
111
- </TouchableOpacity>
112
- </TouchableOpacity>
113
- </SwipeActionsRow>
114
- );
115
- }
116
-
117
- const styles = StyleSheet.create({
118
- row: {
119
- flexDirection: "row",
120
- alignItems: "center",
121
- gap: 10,
122
- paddingHorizontal: tm.textInset,
123
- paddingVertical: 11,
124
- },
125
- text: {
126
- flex: 1,
127
- minWidth: 0,
128
- },
129
- name: {
130
- color: tm.color.label,
131
- fontSize: tm.font.row,
132
- fontWeight: "600",
133
- letterSpacing: tm.tracking.row,
134
- },
135
- meta: {
136
- color: tm.color.labelSecondary,
137
- fontSize: tm.font.footnote,
138
- marginTop: 2,
139
- fontVariant: ["tabular-nums"],
140
- },
141
- restored: {
142
- color: tm.color.accent,
143
- fontSize: tm.font.footnote,
144
- marginTop: 2,
145
- },
146
- route: {
147
- color: tm.color.labelTertiary,
148
- fontFamily: TM_MONO,
149
- fontSize: tm.font.mono,
150
- marginTop: 4,
151
- },
152
- actionDisabled: {
153
- opacity: 0.4,
154
- },
155
- });
@@ -1,124 +0,0 @@
1
- /**
2
- * Sources — one horizontally scrollable line of what a capture will pick up.
3
- *
4
- * Each source is its own tile (icon over name) rather than a count behind a
5
- * disclosure: "is Redux wired?" is a glance question, and the answer should
6
- * not cost a screen. A source that can't fully participate dims and carries a
7
- * status dot, with the reason spelled out underneath the strip.
8
- */
9
- import { ScrollView, StyleSheet, Text, View } from "react-native";
10
- import { tm } from "../../ui/tmTheme";
11
- import { sourceIcon, type SourceStatus } from "../sources";
12
-
13
- function statusDotColor(source: SourceStatus): string | null {
14
- if (!source.canCapture) return tm.color.labelTertiary; // not detected
15
- if (!source.canRestore) return tm.color.warning; // capture only
16
- return null; // ready — nothing to flag
17
- }
18
-
19
- function SourceTile({ source }: { source: SourceStatus }) {
20
- const Icon = sourceIcon(source.id);
21
- const dot = statusDotColor(source);
22
- return (
23
- <View
24
- style={styles.tile}
25
- testID={`time-machine-source-${source.id}`}
26
- accessibilityLabel={`${source.label}: ${
27
- source.canCapture
28
- ? source.canRestore
29
- ? "capture and restore"
30
- : "capture only"
31
- : "not detected"
32
- }`}
33
- >
34
- <View style={[styles.disc, !source.canCapture ? styles.discOff : null]}>
35
- {/* Disc color in, so the icon's cut-outs blend with it. */}
36
- <Icon size={26} bgColor={tm.color.fill} />
37
- {dot ? <View style={[styles.dot, { backgroundColor: dot }]} /> : null}
38
- </View>
39
- <Text
40
- style={[styles.label, !source.canCapture ? styles.labelOff : null]}
41
- numberOfLines={1}
42
- >
43
- {source.label}
44
- </Text>
45
- </View>
46
- );
47
- }
48
-
49
- export function SourcesStrip({ sources }: { sources: SourceStatus[] }) {
50
- return (
51
- <View style={styles.card}>
52
- <ScrollView
53
- horizontal
54
- showsHorizontalScrollIndicator={false}
55
- contentContainerStyle={styles.strip}
56
- testID="time-machine-sources"
57
- >
58
- {sources.map((source) => (
59
- <SourceTile key={source.id} source={source} />
60
- ))}
61
- {sources.length === 0 ? (
62
- <Text style={styles.empty}>No state tools installed.</Text>
63
- ) : null}
64
- </ScrollView>
65
- </View>
66
- );
67
- }
68
-
69
- const styles = StyleSheet.create({
70
- card: {
71
- marginHorizontal: tm.gutter,
72
- backgroundColor: tm.color.group,
73
- borderRadius: tm.radius.group,
74
- paddingVertical: 12,
75
- },
76
- strip: {
77
- flexDirection: "row",
78
- alignItems: "flex-start",
79
- paddingHorizontal: tm.textInset,
80
- gap: 18,
81
- },
82
- tile: {
83
- alignItems: "center",
84
- gap: 7,
85
- // Fixed width so the row reads as a grid, and wide enough for the
86
- // longest source name on ONE line: a second line would be blank for
87
- // every other tile while still setting the card's height.
88
- width: 78,
89
- },
90
- disc: {
91
- width: 50,
92
- height: 50,
93
- borderRadius: tm.radius.pill,
94
- backgroundColor: tm.color.fill,
95
- alignItems: "center",
96
- justifyContent: "center",
97
- },
98
- discOff: {
99
- opacity: 0.35,
100
- },
101
- dot: {
102
- position: "absolute",
103
- top: 2,
104
- right: 2,
105
- width: 10,
106
- height: 10,
107
- borderRadius: 5,
108
- // Ring it in the card color so it reads as a badge, not a smudge.
109
- borderWidth: 2,
110
- borderColor: tm.color.group,
111
- },
112
- label: {
113
- color: tm.color.labelSecondary,
114
- fontSize: tm.font.mono,
115
- textAlign: "center",
116
- },
117
- labelOff: {
118
- color: tm.color.labelTertiary,
119
- },
120
- empty: {
121
- color: tm.color.labelSecondary,
122
- fontSize: tm.font.footnote,
123
- },
124
- });
@@ -1,76 +0,0 @@
1
- /**
2
- * The way back from a swipe-delete.
3
- *
4
- * Swipe-then-tap is deliberate, which is why there's no confirmation dialog —
5
- * but deliberate and recoverable are different properties, and a restore
6
- * point can stand for state that took ten minutes and a cooperative backend
7
- * to build. The record is held in memory until this bar expires.
8
- */
9
- import { useEffect } from "react";
10
- import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
11
- import { tm } from "../../ui/tmTheme";
12
-
13
- /** Long enough to notice and react, short enough not to linger. */
14
- const WINDOW_MS = 8000;
15
-
16
- export function UndoDeleteBar({
17
- name,
18
- at,
19
- onUndo,
20
- onExpire,
21
- }: {
22
- name: string;
23
- /** Restarts the countdown when a second delete replaces the first. */
24
- at: number;
25
- onUndo: () => void;
26
- onExpire: () => void;
27
- }) {
28
- useEffect(() => {
29
- const timer = setTimeout(onExpire, WINDOW_MS);
30
- return () => clearTimeout(timer);
31
- // `at` keyed rather than `onExpire`: a new delete must restart the clock.
32
- // eslint-disable-next-line react-hooks/exhaustive-deps
33
- }, [at]);
34
-
35
- return (
36
- <View style={styles.bar}>
37
- <Text style={styles.text} numberOfLines={1}>
38
- Deleted “{name}”
39
- </Text>
40
- <TouchableOpacity
41
- onPress={onUndo}
42
- hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
43
- accessibilityRole="button"
44
- testID="time-machine-undo-delete"
45
- >
46
- <Text style={styles.undo}>Undo</Text>
47
- </TouchableOpacity>
48
- </View>
49
- );
50
- }
51
-
52
- const styles = StyleSheet.create({
53
- bar: {
54
- flexDirection: "row",
55
- alignItems: "center",
56
- gap: 12,
57
- marginHorizontal: tm.gutter,
58
- marginTop: 12,
59
- minHeight: 46,
60
- paddingHorizontal: tm.textInset,
61
- backgroundColor: tm.color.group,
62
- borderRadius: tm.radius.group,
63
- },
64
- text: {
65
- flex: 1,
66
- color: tm.color.labelSecondary,
67
- fontSize: tm.font.control,
68
- letterSpacing: tm.tracking.control,
69
- },
70
- undo: {
71
- color: tm.color.accent,
72
- fontSize: tm.font.control,
73
- fontWeight: "600",
74
- letterSpacing: tm.tracking.control,
75
- },
76
- });
@@ -1,42 +0,0 @@
1
- /**
2
- * "Wipe All App State…" — the destructive utility, deliberately last, alone
3
- * in its own card and with no icon competing for attention.
4
- */
5
- import { StyleSheet, Text, TouchableOpacity } from "react-native";
6
- import { tm } from "../../ui/tmTheme";
7
-
8
- export function WipeAllRow({
9
- disabled,
10
- onWipe,
11
- }: {
12
- disabled: boolean;
13
- onWipe: () => void;
14
- }) {
15
- return (
16
- <TouchableOpacity
17
- style={[styles.row, disabled ? styles.disabled : null]}
18
- onPress={onWipe}
19
- disabled={disabled}
20
- accessibilityRole="button"
21
- testID="time-machine-wipe-all"
22
- >
23
- <Text style={styles.label}>Wipe All App State…</Text>
24
- </TouchableOpacity>
25
- );
26
- }
27
-
28
- const styles = StyleSheet.create({
29
- row: {
30
- minHeight: tm.rowMinHeight,
31
- alignItems: "center",
32
- justifyContent: "center",
33
- },
34
- disabled: {
35
- opacity: 0.4,
36
- },
37
- label: {
38
- color: tm.color.danger,
39
- fontSize: tm.font.row,
40
- letterSpacing: tm.tracking.row,
41
- },
42
- });
@@ -1,77 +0,0 @@
1
- /**
2
- * One preview item's before/after, rendered INLINE under its row rather than
3
- * on a screen of its own — "what changed in this key" is a glance question,
4
- * and losing the list to answer it costs you the place you were reading.
5
- *
6
- * Split view only, with no view switcher. Side-by-side is the shape that
7
- * answers the question here ("what is it now, what will it become"), and
8
- * inside a list row the segmented control cost more vertical space than the
9
- * diff it was switching.
10
- *
11
- * The render-layer viewer only handles plain JSON faithfully, so both sides
12
- * pass through toDiffable (Dates→ISO, Maps→objects, BigInt→"1n", cycles→
13
- * "[Circular]") and the pair is memoized ONCE per item — the storage tool's
14
- * fix for the fresh-identity-every-render trap that redux/zustand still have.
15
- *
16
- * No scroller of its own: this sits inside the preview's FlatList, so the
17
- * viewer renders at natural height with `scrollEnabled={false}` (the storage
18
- * matched-pair contract).
19
- */
20
- import { useMemo } from "react";
21
- import { StyleSheet, Text, View } from "react-native";
22
- import type { StateSnapshotPreviewItem } from "@buoy-gg/shared-ui";
23
- import {
24
- ABSENT_VALUE,
25
- ThemedSplitView,
26
- devToolsDefaultTheme,
27
- toDiffable,
28
- } from "@buoy-gg/shared-ui/dataViewer";
29
- import { tm } from "../../ui/tmTheme";
30
-
31
- const EMPTY: unknown[] = [];
32
-
33
- export function ItemDiffPanel({ item }: { item: StateSnapshotPreviewItem }) {
34
- // ABSENT_VALUE keeps added/removed reading as pure additions/removals
35
- // instead of diffs against the literal "null".
36
- const { oldValue, newValue } = useMemo(
37
- () => ({
38
- oldValue:
39
- item.verdict === "added" ? ABSENT_VALUE : toDiffable(item.oldValue),
40
- newValue:
41
- item.verdict === "removed" ? ABSENT_VALUE : toDiffable(item.newValue),
42
- }),
43
- [item]
44
- );
45
-
46
- return (
47
- <View style={styles.panel}>
48
- {item.reason ? <Text style={styles.reason}>⚠ {item.reason}</Text> : null}
49
- <ThemedSplitView
50
- oldValue={oldValue}
51
- newValue={newValue}
52
- differences={EMPTY}
53
- theme={devToolsDefaultTheme}
54
- scrollEnabled={false}
55
- />
56
- </View>
57
- );
58
- }
59
-
60
- const styles = StyleSheet.create({
61
- // Same fill as the rows above it: this is part of the card, not a thing
62
- // floating under it.
63
- panel: {
64
- // Only a token indent: the viewer lays values out at their natural width
65
- // and a 51pt inset (matching the checkbox column) clipped long numbers.
66
- paddingLeft: 16,
67
- paddingRight: 12,
68
- paddingTop: 10,
69
- paddingBottom: 14,
70
- gap: 10,
71
- backgroundColor: tm.color.group,
72
- },
73
- reason: {
74
- color: tm.color.warning,
75
- fontSize: tm.font.footnote,
76
- },
77
- });
@@ -1,70 +0,0 @@
1
- /**
2
- * The preview screen, wired to the store — the restore leg (baseline
3
- * confirmation, the route prompt, landing back on the list) lives here so
4
- * RestorePreviewScreen stays presentation.
5
- *
6
- * Kept apart from the restore-point list so each screen mounts and unmounts
7
- * as a whole tree — the router in ../TimeMachineBody picks one, never swaps
8
- * branches inside a live tree. (Item diffs are NOT a screen: they expand
9
- * inline inside the preview's list.)
10
- */
11
- import { timeMachineStore } from "../../store/timeMachineStore";
12
- import type {
13
- PreviewSideRef,
14
- PreviewState,
15
- } from "../../store/timeMachineStore";
16
- import type { SnapshotMeta } from "../../store/snapshotVault";
17
- import { confirmDestructive } from "../confirm";
18
- import { RestorePreviewScreen } from "./RestorePreviewScreen";
19
-
20
- function snapshotFor(
21
- ref: PreviewSideRef,
22
- snapshots: SnapshotMeta[]
23
- ): SnapshotMeta | undefined {
24
- return ref === "current"
25
- ? undefined
26
- : snapshots.find((s) => s.id === ref.snapshotId);
27
- }
28
-
29
- export function PreviewScreen({
30
- preview,
31
- snapshots,
32
- busy,
33
- onClose,
34
- }: {
35
- preview: PreviewState;
36
- snapshots: SnapshotMeta[];
37
- busy: boolean;
38
- onClose: () => void;
39
- }) {
40
- const rightMeta = snapshotFor(preview.right, snapshots);
41
-
42
- const restore = (mode: "live" | "reload", excludeKeys?: string[]) => {
43
- if (!rightMeta || busy) return;
44
- if (rightMeta.baseline) {
45
- confirmDestructive(
46
- "Restore fresh install?",
47
- "This wipes all app storage and reloads the app.",
48
- "Wipe & reload",
49
- () => void timeMachineStore.restore(rightMeta.id, "reload")
50
- );
51
- return;
52
- }
53
- // Land back on the list, where the outcome card reports the results —
54
- // the preview's diff is stale the moment restore runs. Whether the route
55
- // comes back is the restore point's own setting, toggled on its row.
56
- void timeMachineStore
57
- .restore(rightMeta.id, mode, excludeKeys)
58
- .then(onClose);
59
- };
60
-
61
- return (
62
- <RestorePreviewScreen
63
- preview={preview}
64
- snapshots={snapshots}
65
- busy={busy}
66
- onBack={onClose}
67
- onRestore={restore}
68
- />
69
- );
70
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * The restore point's name, editable in place.
3
- *
4
- * Renaming lives on the preview rather than behind a swipe on the list: the
5
- * list is for picking one, and you rarely know a name is wrong until you're
6
- * looking at what the point actually contains.
7
- *
8
- * Commits on blur as well as on return — tapping away from a field you have
9
- * just typed into should keep the typing. Finder and iOS both treat leaving
10
- * as accepting, and silently discarding an edit is the one outcome nobody
11
- * wants.
12
- */
13
- import { useEffect, useState } from "react";
14
- import { StyleSheet, Text, TextInput, View } from "react-native";
15
- import { tm } from "../../ui/tmTheme";
16
-
17
- export function RestorePointNameRow({
18
- name,
19
- onRename,
20
- }: {
21
- name: string;
22
- onRename: (name: string) => void;
23
- }) {
24
- const [draft, setDraft] = useState(name);
25
-
26
- // A rename from anywhere else (MCP, the desktop) should show up here.
27
- useEffect(() => setDraft(name), [name]);
28
-
29
- const commit = () => {
30
- const trimmed = draft.trim();
31
- if (!trimmed) {
32
- setDraft(name); // an empty name would make the row unidentifiable
33
- return;
34
- }
35
- if (trimmed !== name) onRename(trimmed);
36
- };
37
-
38
- return (
39
- <View style={styles.row}>
40
- <Text style={styles.label}>Name</Text>
41
- <TextInput
42
- style={styles.input}
43
- value={draft}
44
- onChangeText={setDraft}
45
- onSubmitEditing={commit}
46
- onBlur={commit}
47
- returnKeyType="done"
48
- selectTextOnFocus
49
- accessibilityLabel="Restore point name"
50
- testID="tm-preview-name"
51
- />
52
- </View>
53
- );
54
- }
55
-
56
- const styles = StyleSheet.create({
57
- row: {
58
- flexDirection: "row",
59
- alignItems: "center",
60
- gap: 14,
61
- minHeight: tm.rowMinHeight,
62
- paddingHorizontal: tm.textInset,
63
- },
64
- label: {
65
- color: tm.color.labelSecondary,
66
- fontSize: tm.font.row,
67
- letterSpacing: tm.tracking.row,
68
- },
69
- input: {
70
- flex: 1,
71
- minWidth: 0,
72
- color: tm.color.label,
73
- fontSize: tm.font.row,
74
- fontWeight: "600",
75
- letterSpacing: tm.tracking.row,
76
- textAlign: "right",
77
- padding: 0,
78
- backgroundColor: "transparent",
79
- },
80
- });