@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,40 +0,0 @@
1
- /**
2
- * One place for the verdict → glyph/color/label mapping. Color is ALWAYS
3
- * paired with a distinct glyph (true minus U+2212, approx U+2248) — the
4
- * repo-wide accessibility convention for diff surfaces.
5
- */
6
- import type { StateSnapshotPreviewVerdict } from "@buoy-gg/shared-ui";
7
- import { tm } from "../../ui/tmTheme";
8
-
9
- export interface VerdictMeta {
10
- glyph: string;
11
- color: string;
12
- label: string;
13
- /** Counts toward "will change" totals. */
14
- applies: boolean;
15
- }
16
-
17
- export const VERDICT_META: Record<StateSnapshotPreviewVerdict, VerdictMeta> = {
18
- added: { glyph: "+", color: tm.color.accent, label: "added", applies: true },
19
- removed: { glyph: "−", color: tm.color.danger, label: "removed", applies: true },
20
- changed: { glyph: "≈", color: tm.color.info, label: "changed", applies: true },
21
- "too-large": {
22
- glyph: "≈",
23
- color: tm.color.warning,
24
- label: "changed (large)",
25
- applies: true,
26
- },
27
- unchanged: { glyph: "=", color: tm.color.labelTertiary, label: "unchanged", applies: false },
28
- "wont-apply": {
29
- glyph: "⊘",
30
- color: tm.color.warning,
31
- label: "won't apply",
32
- applies: false,
33
- },
34
- recomputes: {
35
- glyph: "↻",
36
- color: tm.color.labelTertiary,
37
- label: "recomputes",
38
- applies: false,
39
- },
40
- };
@@ -1,92 +0,0 @@
1
- /**
2
- * What Time Machine can capture from, and how healthy each source is.
3
- *
4
- * On device these are live registry probes; on Buoy Desktop the same shapes
5
- * arrive mirrored in the sync payload. Route is folded in as a source even
6
- * though it is a device capability rather than a registered provider — from
7
- * the user's side "can this snapshot take me back to that screen?" is the
8
- * same question as "will my Redux store come back".
9
- */
10
- import type { ComponentType } from "react";
11
- import {
12
- JotaiIcon,
13
- QueryIcon,
14
- ReduxIcon,
15
- RoutesIcon,
16
- StorageIcon,
17
- TimeMachineIcon,
18
- ZustandIcon,
19
- } from "@buoy-gg/floating-tools-core";
20
- import { useSnapshotProviders, useTimeMachineState } from "../hooks/useTimeMachine";
21
- import { canNavigate } from "../store/routeRestore";
22
-
23
- export interface SourceStatus {
24
- id: string;
25
- label: string;
26
- canCapture: boolean;
27
- canRestore: boolean;
28
- /** Why it is in this state — shown on the Sources screen. */
29
- detail?: string;
30
- }
31
-
32
- /**
33
- * Buoy icons paint their knock-out parts with `fill: "bg"`, defaulting to a
34
- * near-black — so whatever surface an icon sits on has to be handed in as
35
- * `bgColor` or those cut-outs read as black holes (storage's floppy slot and
36
- * the route glyph are the two that use it).
37
- */
38
- export type SourceIcon = ComponentType<{
39
- size?: number;
40
- color?: string;
41
- bgColor?: string;
42
- }>;
43
-
44
- const ICONS: Record<string, SourceIcon> = {
45
- storage: StorageIcon,
46
- redux: ReduxIcon,
47
- zustand: ZustandIcon,
48
- jotai: JotaiIcon,
49
- query: QueryIcon,
50
- route: RoutesIcon,
51
- };
52
-
53
- export function sourceIcon(id: string): SourceIcon {
54
- return ICONS[id] ?? TimeMachineIcon;
55
- }
56
-
57
- /** Id of the route tile — a device capability, not a snapshot provider. */
58
- export const ROUTE_SOURCE_ID = "route";
59
-
60
- export function useSourceStatuses(): SourceStatus[] {
61
- const { remoteProviders, remoteRoute } = useTimeMachineState();
62
- const localProviders = useSnapshotProviders();
63
-
64
- const providers: SourceStatus[] =
65
- remoteProviders ??
66
- localProviders.map((p) => ({ id: p.id, label: p.label, ...p.status() }));
67
-
68
- const routeAvailable = remoteProviders
69
- ? remoteRoute?.available === true
70
- : canNavigate();
71
-
72
- return [
73
- ...providers,
74
- {
75
- id: ROUTE_SOURCE_ID,
76
- label: "Route",
77
- canCapture: routeAvailable,
78
- canRestore: routeAvailable,
79
- // No live pathname here: these screens only re-render on store changes,
80
- // so a route printed as status goes stale the moment you navigate with
81
- // the tool still open. Each restore point shows the route it holds.
82
- detail: routeAvailable
83
- ? "Recorded with every snapshot — a restore can take you back"
84
- : "No Expo Router detected — snapshots record no route",
85
- },
86
- ];
87
- }
88
-
89
- /** A source is "attached" when a snapshot would actually pick it up. */
90
- export function isAttached(source: SourceStatus): boolean {
91
- return source.canCapture;
92
- }
@@ -1,26 +0,0 @@
1
- import { useEffect, useState, useSyncExternalStore } from "react";
2
- import {
3
- getStateSnapshotProviders,
4
- subscribeToStateSnapshotProviders,
5
- type StateSnapshotProvider,
6
- } from "@buoy-gg/shared-ui";
7
- import { timeMachineStore } from "../store/timeMachineStore";
8
- import type { TimeMachineState } from "../store/timeMachineStore";
9
-
10
- export function useTimeMachineState(): TimeMachineState {
11
- return useSyncExternalStore(timeMachineStore.subscribe, () =>
12
- timeMachineStore.getState()
13
- );
14
- }
15
-
16
- /** Registered snapshot providers (query registers late, hence the subscribe). */
17
- export function useSnapshotProviders(): StateSnapshotProvider[] {
18
- const [providers, setProviders] = useState(getStateSnapshotProviders);
19
- useEffect(() => {
20
- setProviders(getStateSnapshotProviders());
21
- return subscribeToStateSnapshotProviders(() =>
22
- setProviders(getStateSnapshotProviders())
23
- );
24
- }, []);
25
- return providers;
26
- }
package/src/index.tsx DELETED
@@ -1,68 +0,0 @@
1
- /**
2
- * @buoy-gg/time-machine
3
- *
4
- * Time Machine — snapshot & restore app state for React Native DevTools.
5
- *
6
- * Capture the complete client-side state of the app (storage, Redux,
7
- * Zustand, Jotai, React Query) as a named snapshot; restore any snapshot in
8
- * one tap to iterate on multi-step test flows without rebuilding state.
9
- *
10
- * PUBLIC API - Only these exports are supported for external use.
11
- */
12
-
13
- import { armPendingRouteRestore as armPendingRouteRestoreOnLoad } from "./store/routeRestore";
14
-
15
- // Tool preset for FloatingDevTools
16
- export { timeMachineToolPreset, createTimeMachineTool } from "./preset";
17
-
18
- // Components
19
- export {
20
- TimeMachineModal,
21
- TimeMachineToolView,
22
- type TimeMachineModalProps,
23
- } from "./components/TimeMachineModal";
24
-
25
- // External-sync adapter (auto-registered by @buoy-gg/core)
26
- export { timeMachineSyncAdapter } from "./sync/timeMachineSyncAdapter";
27
-
28
- // Programmatic snapshot control (also used by tests / power users)
29
- export {
30
- timeMachineStore,
31
- RESTORE_ORDER,
32
- type RestoreMode,
33
- type RestoreOptions,
34
- type RestoreOutcome,
35
- type TimeMachineState,
36
- type RemoteProviderStatus,
37
- type PreviewSource,
38
- } from "./store/timeMachineStore";
39
-
40
- // Route capture / restore ("also take me back to the screen I was on")
41
- export {
42
- armPendingRouteRestore,
43
- captureCurrentRoute,
44
- navigateToRoute,
45
- canNavigate as canRestoreRoute,
46
- type SnapshotRoute,
47
- type RouteRestoreResult,
48
- type RouteRestoreStatus,
49
- } from "./store/routeRestore";
50
-
51
- // Buoy Desktop remote-mirror seam
52
- export {
53
- setRemoteTimeMachineHandler,
54
- replaceTimeMachineFromSnapshot,
55
- } from "./store/timeMachineStore";
56
- export type {
57
- SnapshotMeta,
58
- SnapshotSourceMeta,
59
- StoredSnapshot,
60
- } from "./store/snapshotVault";
61
-
62
- // A reload-mode restore that also restores the route can't navigate itself —
63
- // the JS realm dies with the reload. It parks the route in storage; this picks
64
- // it up on the next boot. Core requires this module while mounting the
65
- // floating menu, which is the earliest point we're guaranteed to run.
66
- // Idempotent: repeated imports (or a host calling it explicitly) arm once.
67
- armPendingRouteRestoreOnLoad();
68
-
package/src/preset.tsx DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * Pre-configured Time Machine tool for FloatingDevTools.
3
- *
4
- * @example
5
- * ```tsx
6
- * import { timeMachineToolPreset } from '@buoy-gg/time-machine';
7
- *
8
- * <FloatingDevTools apps={[timeMachineToolPreset]} />
9
- * ```
10
- */
11
-
12
- import {
13
- TimeMachineIcon,
14
- TIME_MACHINE_ICON_COLOR,
15
- } from "@buoy-gg/shared-ui";
16
- import { TimeMachineBody } from "./components/TimeMachineBody";
17
- import { HeaderReloadButton } from "./components/HeaderReloadButton";
18
-
19
- export const timeMachineToolPreset = {
20
- id: "time-machine",
21
- name: "TIME MACHINE",
22
- description: "Snapshot & restore app state (storage, stores, query cache)",
23
- slot: "both" as const,
24
- icon: ({ size, color }: { size: number; color?: string }) => (
25
- <TimeMachineIcon size={size} color={color || TIME_MACHINE_ICON_COLOR} />
26
- ),
27
- component: TimeMachineBody,
28
- // Declarative chrome: core's ToolModalShell provides the JsModal, the
29
- // managed header (screens override it via useToolHeader) and header search.
30
- modal: {
31
- subtitle: "snapshot & restore app state",
32
- searchable: true,
33
- searchPlaceholder: "Filter…",
34
- headerActions: <HeaderReloadButton />,
35
- },
36
- };
37
-
38
- /** Create a custom Time Machine tool configuration. */
39
- export function createTimeMachineTool(
40
- options: { name?: string; description?: string } = {}
41
- ) {
42
- return {
43
- ...timeMachineToolPreset,
44
- name: options.name ?? timeMachineToolPreset.name,
45
- description: options.description ?? timeMachineToolPreset.description,
46
- };
47
- }
@@ -1,194 +0,0 @@
1
- /**
2
- * Route capture & restore for Time Machine.
3
- *
4
- * A restore point is only half the story: state without the screen you were
5
- * on drops you into the right data on the wrong page. Every snapshot records
6
- * the route it was captured on, and a restore can navigate back to it.
7
- *
8
- * Two navigation paths, because a "reload" restore kills the JS realm:
9
- * - LIVE restore: navigate immediately once the sources are applied.
10
- * - RELOAD restore: persist the route BEFORE the reload is scheduled, then
11
- * {@link armPendingRouteRestore} picks it up on the next boot, waits for the
12
- * router to come online, and navigates.
13
- *
14
- * Everything here is best-effort: apps without expo-router capture no route,
15
- * so the UI simply never offers the option.
16
- */
17
- import {
18
- getSafeCurrentRoute,
19
- getSafeRouter,
20
- persistentStorage,
21
- type SafeRouteLocation,
22
- } from "@buoy-gg/shared-ui";
23
-
24
- /**
25
- * The route a snapshot was captured on. Only the URL is stored — imperative
26
- * params passed as objects (`navigate(path, { user })`) are not part of a
27
- * route and are not restored.
28
- */
29
- export interface SnapshotRoute {
30
- /** Pathname with dynamic segments resolved, e.g. `/pokemon/25`. */
31
- pathname: string;
32
- /** What we navigate to — pathname plus search params. */
33
- href: string;
34
- }
35
-
36
- /** How a restore's route leg ended, reported back in the RestoreOutcome. */
37
- export type RouteRestoreStatus =
38
- | "navigated"
39
- | "deferred"
40
- | "failed"
41
- | "unavailable";
42
-
43
- export interface RouteRestoreResult {
44
- pathname: string;
45
- href: string;
46
- status: RouteRestoreStatus;
47
- /** Present when status is "failed" / "unavailable". */
48
- error?: string;
49
- }
50
-
51
- /**
52
- * Same `@react_buoy` family as the snapshot vault, so every tool's
53
- * isDevToolsStorageKey filter (and therefore every wipe/restore) leaves it
54
- * alone — a pending route must survive the storage restore that precedes the
55
- * reload it's waiting on.
56
- */
57
- const PENDING_KEY = "@react_buoy_time_machine:pending-route";
58
-
59
- /**
60
- * A pending route older than this belongs to a reload that never happened
61
- * (the app was killed, the user moved on). Boot-time navigation into a screen
62
- * someone left minutes ago is worse than doing nothing.
63
- */
64
- export const PENDING_ROUTE_TTL_MS = 60_000;
65
-
66
- /** How long to wait at boot for the router to come online. */
67
- const ROUTER_READY_TIMEOUT_MS = 8_000;
68
-
69
- /** Settle window after the router appears, so the initial route mounts first. */
70
- const ROUTER_SETTLE_MS = 250;
71
-
72
- interface PendingRoute extends SnapshotRoute {
73
- savedAt: number;
74
- snapshotName?: string;
75
- }
76
-
77
- function toSnapshotRoute(location: SafeRouteLocation): SnapshotRoute {
78
- return { pathname: location.pathname, href: location.href };
79
- }
80
-
81
- /** The route to stamp on a snapshot being captured, or null when unavailable. */
82
- export function captureCurrentRoute(): SnapshotRoute | null {
83
- const current = getSafeCurrentRoute();
84
- return current ? toSnapshotRoute(current) : null;
85
- }
86
-
87
- /** The live route, for "you're already here" checks in the UI. */
88
- export function currentRoute(): SnapshotRoute | null {
89
- return captureCurrentRoute();
90
- }
91
-
92
- /** True when imperative navigation is possible on this device. */
93
- export function canNavigate(): boolean {
94
- return getSafeRouter() != null;
95
- }
96
-
97
- /**
98
- * Navigate to a captured route now. Uses `navigate` (not `push`) so restoring
99
- * the same route twice doesn't stack duplicate screens.
100
- */
101
- export function navigateToRoute(route: SnapshotRoute): RouteRestoreResult {
102
- const base = { pathname: route.pathname, href: route.href };
103
- const router = getSafeRouter();
104
- if (!router?.navigate) {
105
- return {
106
- ...base,
107
- status: "unavailable",
108
- error: "expo-router is not available on this device",
109
- };
110
- }
111
- try {
112
- router.navigate(route.href);
113
- return { ...base, status: "navigated" };
114
- } catch (e) {
115
- return { ...base, status: "failed", error: String(e) };
116
- }
117
- }
118
-
119
- // ── Pending route (survives the reload) ──────────────────────────────────────
120
-
121
- export async function savePendingRoute(
122
- route: SnapshotRoute,
123
- snapshotName?: string
124
- ): Promise<void> {
125
- const pending: PendingRoute = {
126
- ...route,
127
- savedAt: Date.now(),
128
- ...(snapshotName ? { snapshotName } : {}),
129
- };
130
- await persistentStorage.setItem(PENDING_KEY, JSON.stringify(pending));
131
- }
132
-
133
- export async function clearPendingRoute(): Promise<void> {
134
- try {
135
- await persistentStorage.removeItem(PENDING_KEY);
136
- } catch {
137
- // best-effort — a stale key is dropped by the TTL check anyway
138
- }
139
- }
140
-
141
- async function loadPendingRoute(): Promise<PendingRoute | null> {
142
- try {
143
- const raw = await persistentStorage.getItem(PENDING_KEY);
144
- if (!raw) return null;
145
- const parsed = JSON.parse(raw) as Partial<PendingRoute>;
146
- if (typeof parsed?.href !== "string" || !parsed.href) return null;
147
- if (typeof parsed.savedAt !== "number") return null;
148
- return {
149
- pathname:
150
- typeof parsed.pathname === "string" ? parsed.pathname : parsed.href,
151
- href: parsed.href,
152
- savedAt: parsed.savedAt,
153
- snapshotName:
154
- typeof parsed.snapshotName === "string" ? parsed.snapshotName : undefined,
155
- };
156
- } catch {
157
- return null;
158
- }
159
- }
160
-
161
- let armed = false;
162
-
163
- /**
164
- * Boot-time consumer of a pending route: called once when the package loads
165
- * (core requires it while mounting the floating menu), it navigates to the
166
- * route a reload-mode restore asked for and clears the slot.
167
- *
168
- * Idempotent and self-limiting — the slot is cleared before navigating, so a
169
- * route that crashes the app on arrival can't put it in a boot loop.
170
- */
171
- export function armPendingRouteRestore(): void {
172
- if (armed) return;
173
- armed = true;
174
- void (async () => {
175
- const pending = await loadPendingRoute();
176
- if (!pending) return;
177
- // Clear FIRST: whatever happens next, this route is spent.
178
- await clearPendingRoute();
179
- if (Date.now() - pending.savedAt > PENDING_ROUTE_TTL_MS) return;
180
-
181
- const deadline = Date.now() + ROUTER_READY_TIMEOUT_MS;
182
- while (!canNavigate() && Date.now() < deadline) {
183
- await new Promise((r) => setTimeout(r, 100));
184
- }
185
- if (!canNavigate()) return;
186
- await new Promise((r) => setTimeout(r, ROUTER_SETTLE_MS));
187
- navigateToRoute({ pathname: pending.pathname, href: pending.href });
188
- })();
189
- }
190
-
191
- /** @internal test seam — re-arms the boot-time consumer. */
192
- export function resetPendingRouteArm(): void {
193
- armed = false;
194
- }