@buoy-gg/jotai 7.0.36 → 7.0.38

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 (51) hide show
  1. package/README.md +32 -5
  2. package/lib/commonjs/index.js +1 -112
  3. package/lib/commonjs/jotai/components/JotaiAtomBrowser.js +1 -199
  4. package/lib/commonjs/jotai/components/JotaiAtomChangeItem.js +1 -85
  5. package/lib/commonjs/jotai/components/JotaiAtomDetailContent.js +1 -715
  6. package/lib/commonjs/jotai/components/JotaiAtomValueDetailContent.js +1 -444
  7. package/lib/commonjs/jotai/components/JotaiEventFilterView.js +1 -43
  8. package/lib/commonjs/jotai/components/JotaiIcon.js +1 -18
  9. package/lib/commonjs/jotai/components/JotaiModal.js +1 -743
  10. package/lib/commonjs/jotai/hooks/useJotaiAtomChanges.js +1 -67
  11. package/lib/commonjs/jotai/sync/jotaiSyncAdapter.js +1 -306
  12. package/lib/commonjs/jotai/utils/jotaiStateStore.js +1 -321
  13. package/lib/commonjs/jotai/utils/snapshotProvider.js +1 -215
  14. package/lib/commonjs/jotai/utils/testIDs.js +1 -90
  15. package/lib/commonjs/jotai/utils/watchAtoms.js +1 -162
  16. package/lib/commonjs/jotai/utils/writeSemantics.js +1 -47
  17. package/lib/commonjs/preset.js +1 -90
  18. package/lib/module/index.js +1 -85
  19. package/lib/module/jotai/components/JotaiAtomBrowser.js +1 -195
  20. package/lib/module/jotai/components/JotaiAtomChangeItem.js +1 -81
  21. package/lib/module/jotai/components/JotaiAtomDetailContent.js +1 -710
  22. package/lib/module/jotai/components/JotaiAtomValueDetailContent.js +1 -442
  23. package/lib/module/jotai/components/JotaiEventFilterView.js +1 -39
  24. package/lib/module/jotai/components/JotaiIcon.js +1 -11
  25. package/lib/module/jotai/components/JotaiModal.js +1 -738
  26. package/lib/module/jotai/hooks/useJotaiAtomChanges.js +1 -63
  27. package/lib/module/jotai/sync/jotaiSyncAdapter.js +1 -303
  28. package/lib/module/jotai/utils/jotaiStateStore.js +1 -317
  29. package/lib/module/jotai/utils/snapshotProvider.js +1 -214
  30. package/lib/module/jotai/utils/testIDs.js +1 -82
  31. package/lib/module/jotai/utils/watchAtoms.js +1 -157
  32. package/lib/module/jotai/utils/writeSemantics.js +1 -43
  33. package/lib/module/preset.js +1 -87
  34. package/package.json +4 -4
  35. package/lib/typescript/index.d.ts.map +0 -1
  36. package/lib/typescript/jotai/components/JotaiAtomBrowser.d.ts.map +0 -1
  37. package/lib/typescript/jotai/components/JotaiAtomChangeItem.d.ts.map +0 -1
  38. package/lib/typescript/jotai/components/JotaiAtomDetailContent.d.ts.map +0 -1
  39. package/lib/typescript/jotai/components/JotaiAtomValueDetailContent.d.ts.map +0 -1
  40. package/lib/typescript/jotai/components/JotaiEventFilterView.d.ts.map +0 -1
  41. package/lib/typescript/jotai/components/JotaiIcon.d.ts.map +0 -1
  42. package/lib/typescript/jotai/components/JotaiModal.d.ts.map +0 -1
  43. package/lib/typescript/jotai/hooks/useJotaiAtomChanges.d.ts.map +0 -1
  44. package/lib/typescript/jotai/sync/jotaiSyncAdapter.d.ts.map +0 -1
  45. package/lib/typescript/jotai/types/index.d.ts.map +0 -1
  46. package/lib/typescript/jotai/utils/jotaiStateStore.d.ts.map +0 -1
  47. package/lib/typescript/jotai/utils/snapshotProvider.d.ts.map +0 -1
  48. package/lib/typescript/jotai/utils/testIDs.d.ts.map +0 -1
  49. package/lib/typescript/jotai/utils/watchAtoms.d.ts.map +0 -1
  50. package/lib/typescript/jotai/utils/writeSemantics.d.ts.map +0 -1
  51. package/lib/typescript/preset.d.ts.map +0 -1
@@ -1,162 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isAtomWatched = isAtomWatched;
7
- exports.watchAtoms = watchAtoms;
8
- exports.watchDefaultStoreAtoms = watchDefaultStoreAtoms;
9
- var _jotaiStateStore = require("./jotaiStateStore");
10
- var _writeSemantics = require("./writeSemantics");
11
- /**
12
- * Buoy Jotai DevTools — Atom instrumentation
13
- *
14
- * watchAtoms() — RECOMMENDED. Pass a Jotai store and a named atom map.
15
- * Uses store.sub() to observe each atom externally. Never touches atom internals.
16
- *
17
- * watchDefaultStoreAtoms() — Convenience wrapper that uses getDefaultStore().
18
- */
19
-
20
- /** Any Jotai atom — alias for Atom<unknown> for readability */
21
-
22
- /** Minimal store shape — what Jotai's createStore() / getDefaultStore() returns */
23
-
24
- /**
25
- * Watch a set of Jotai atoms for value changes.
26
- *
27
- * Pass a Jotai store and an object mapping display names to atoms.
28
- * Uses store.sub() to observe each atom — never modifies atom internals.
29
- *
30
- * @example
31
- * ```tsx
32
- * import { getDefaultStore } from 'jotai';
33
- * import { watchAtoms } from '@buoy-gg/jotai';
34
- * import { countAtom } from './atoms/count';
35
- * import { authAtom } from './atoms/auth';
36
- *
37
- * watchAtoms(getDefaultStore(), {
38
- * countAtom,
39
- * authAtom,
40
- * });
41
- * ```
42
- *
43
- * @param store - Jotai store (from createStore() or getDefaultStore())
44
- * @param atoms - Object mapping display labels to Jotai atoms
45
- * @param options - Optional configuration
46
- * @returns Cleanup function that removes all subscriptions
47
- */
48
- function watchAtoms(store, atoms, options) {
49
- const enabled = options?.enabled !== false;
50
- const cleanups = [];
51
- for (const [label, atom] of Object.entries(atoms)) {
52
- // Skip if already watched under this label
53
- const atomAny = atom;
54
- const watchedKey = Symbol.for(`@@buoy-jotai/watched/${label}`);
55
- if (atomAny[watchedKey]) continue;
56
- atomAny[watchedKey] = true;
57
- let prevValue;
58
- try {
59
- prevValue = store.get(atom);
60
- } catch {
61
- prevValue = undefined;
62
- }
63
-
64
- // Register the atom for the browser view. A setter is captured only when
65
- // the store supports `set` AND the atom itself is writable (has a `write`
66
- // function — primitive atoms get a default one, read-only derived atoms
67
- // have none). Deriveds used to get a setter that threw inside jotai at
68
- // set time; now they're correctly reported as read-only up front.
69
- const isWritable = typeof atom.write === "function";
70
- const setter = store.set && isWritable ? value => {
71
- store.set(atom, value);
72
- } : undefined;
73
- _jotaiStateStore.jotaiStateStore.registerAtom(label, () => {
74
- try {
75
- return store.get(atom);
76
- } catch {
77
- return undefined;
78
- }
79
- }, setter,
80
- // "value" = jotai's shared defaultWrite (a primitive atom: store.set
81
- // stores the value). "action" = a custom write receiving the value as
82
- // its argument — still writable, but the editor says so.
83
- isWritable ? (0, _writeSemantics.classifyAtomWrite)(atom) : undefined);
84
-
85
- // Record initial value
86
- if (enabled) {
87
- _jotaiStateStore.jotaiStateStore.addAtomChange({
88
- atomLabel: label,
89
- prevValue: undefined,
90
- nextValue: prevValue,
91
- category: "initial"
92
- });
93
- }
94
-
95
- // Subscribe to future changes
96
- const unsubscribe = store.sub(atom, () => {
97
- try {
98
- const nextValue = store.get(atom);
99
- _jotaiStateStore.jotaiStateStore.addAtomChange({
100
- atomLabel: label,
101
- prevValue,
102
- nextValue,
103
- category: "write"
104
- });
105
- prevValue = nextValue;
106
- } catch {
107
- // Silently catch — our bug must never propagate into the store
108
- }
109
- });
110
- cleanups.push(() => {
111
- unsubscribe();
112
- delete atomAny[watchedKey];
113
- _jotaiStateStore.jotaiStateStore.unregisterAtom(label);
114
- });
115
- }
116
- return () => cleanups.forEach(fn => fn());
117
- }
118
-
119
- /**
120
- * Watch atoms using Jotai's default store (no Provider setup required).
121
- *
122
- * Convenience wrapper around watchAtoms() — auto-imports getDefaultStore.
123
- *
124
- * @example
125
- * ```tsx
126
- * import { watchDefaultStoreAtoms } from '@buoy-gg/jotai';
127
- * import { countAtom, authAtom } from './atoms';
128
- *
129
- * watchDefaultStoreAtoms({ countAtom, authAtom });
130
- * ```
131
- */
132
- function watchDefaultStoreAtoms(atoms, options) {
133
- // Dynamic import to avoid bundling jotai internals when not needed
134
- let store;
135
- try {
136
- // eslint-disable-next-line @typescript-eslint/no-var-requires
137
- const {
138
- getDefaultStore
139
- } = require("jotai/vanilla");
140
- store = getDefaultStore();
141
- } catch {
142
- // Try the main jotai entry (React Native)
143
- try {
144
- // eslint-disable-next-line @typescript-eslint/no-var-requires
145
- const {
146
- getDefaultStore
147
- } = require("jotai");
148
- store = getDefaultStore();
149
- } catch {
150
- console.warn("[@buoy-gg/jotai] Could not find getDefaultStore from jotai. " + "Pass the store explicitly via watchAtoms(store, atoms) instead.");
151
- return () => {};
152
- }
153
- }
154
- return watchAtoms(store, atoms, options);
155
- }
156
-
157
- /**
158
- * Check if an atom label is currently being watched
159
- */
160
- function isAtomWatched(label) {
161
- return _jotaiStateStore.jotaiStateStore.getAtom(label) !== undefined;
162
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isAtomWatched=isAtomWatched,exports.watchAtoms=watchAtoms,exports.watchDefaultStoreAtoms=watchDefaultStoreAtoms;var _jotaiStateStore=require("./jotaiStateStore"),_writeSemantics=require("./writeSemantics");function watchAtoms(t,e,o){const a=!1!==o?.enabled,r=[];for(const[o,i]of Object.entries(e)){const e=i,c=Symbol.for(`@@buoy-jotai/watched/${o}`);if(e[c])continue;let s;e[c]=!0;try{s=t.get(i)}catch{s=void 0}const n="function"==typeof i.write,u=t.set&&n?e=>{t.set(i,e)}:void 0;_jotaiStateStore.jotaiStateStore.registerAtom(o,()=>{try{return t.get(i)}catch{return}},u,n?(0,_writeSemantics.classifyAtomWrite)(i):void 0),a&&_jotaiStateStore.jotaiStateStore.addAtomChange({atomLabel:o,prevValue:void 0,nextValue:s,category:"initial"});const S=t.sub(i,()=>{try{const e=t.get(i);_jotaiStateStore.jotaiStateStore.addAtomChange({atomLabel:o,prevValue:s,nextValue:e,category:"write"}),s=e}catch{}});r.push(()=>{S(),delete e[c],_jotaiStateStore.jotaiStateStore.unregisterAtom(o)})}return()=>r.forEach(t=>t())}function watchDefaultStoreAtoms(t,e){let o;try{const{getDefaultStore:t}=require("jotai/vanilla");o=t()}catch{try{const{getDefaultStore:t}=require("jotai");o=t()}catch{return console.warn("[@buoy-gg/jotai] Could not find getDefaultStore from jotai. Pass the store explicitly via watchAtoms(store, atoms) instead."),()=>{}}}return watchAtoms(o,t,e)}function isAtomWatched(t){return void 0!==_jotaiStateStore.jotaiStateStore.getAtom(t)}
@@ -1,47 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.classifyAtomWrite = classifyAtomWrite;
7
- var _vanilla = require("jotai/vanilla");
8
- /**
9
- * What does `store.set(atom, x)` DO with x?
10
- *
11
- * jotai's `atom(initialValue)` gives every primitive atom the SAME shared
12
- * `defaultWrite` function (see jotai/src/vanilla/atom.ts): it stores x as the
13
- * atom's new value (or calls it with the previous value when x is a
14
- * function). Any other `write` is app code — `atomWithReducer` receives
15
- * ACTIONS, `atomWithStorage` persists as a side effect, a custom write can do
16
- * anything — so a raw value handed to `store.set` may not mean "set to this".
17
- *
18
- * The tool's editor needs that distinction to be honest: a "value" atom edits
19
- * like plain data; an "action" atom is still writable (the MCP `setAtom` and
20
- * Time Machine restore already write to them) but the editor says what the
21
- * write actually does.
22
- *
23
- * Detection: a probe primitive atom exposes this jotai instance's
24
- * `defaultWrite`; identity match is exact. The `toString` fallback covers an
25
- * app that somehow bundles a second jotai copy (its atoms carry a different —
26
- * but textually identical — defaultWrite instance). An unrecognized write
27
- * classifies as "action", which only makes the editor more cautious.
28
- */
29
-
30
- const probe = (0, _vanilla.atom)(null);
31
- const DEFAULT_WRITE = probe.write;
32
- const DEFAULT_WRITE_SOURCE = typeof DEFAULT_WRITE === "function" ? String(DEFAULT_WRITE) : null;
33
-
34
- /** Classify a writable atom's write. Call only when `atom.write` exists. */
35
- function classifyAtomWrite(candidate) {
36
- const atomLike = candidate;
37
- const write = atomLike?.write;
38
- if (typeof write !== "function") return "action";
39
- if (write === DEFAULT_WRITE) return "value";
40
- // Dual-copy fallback: a primitive atom from another jotai instance holds
41
- // its own value (`init` present) and its write's source is the library's
42
- // defaultWrite verbatim.
43
- if (atomLike !== null && "init" in atomLike && DEFAULT_WRITE_SOURCE !== null && String(write) === DEFAULT_WRITE_SOURCE) {
44
- return "value";
45
- }
46
- return "action";
47
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.classifyAtomWrite=classifyAtomWrite;var _vanilla=require("jotai/vanilla");const probe=(0,_vanilla.atom)(null),DEFAULT_WRITE=probe.write,DEFAULT_WRITE_SOURCE="function"==typeof DEFAULT_WRITE?String(DEFAULT_WRITE):null;function classifyAtomWrite(t){const i=t,e=i?.write;return"function"!=typeof e?"action":e===DEFAULT_WRITE||null!==i&&"init"in i&&null!==DEFAULT_WRITE_SOURCE&&String(e)===DEFAULT_WRITE_SOURCE?"value":"action"}
@@ -1,90 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.jotaiToolPreset = exports.createJotaiTool = void 0;
7
- var _JotaiModal = require("./jotai/components/JotaiModal");
8
- var _JotaiIcon = require("./jotai/components/JotaiIcon");
9
- var _sharedUi = require("@buoy-gg/shared-ui");
10
- var _jsxRuntime = require("react/jsx-runtime");
11
- /**
12
- * Pre-configured Jotai DevTools preset for FloatingDevTools
13
- *
14
- * ZERO-CONFIG: This preset is auto-discovered by FloatingDevTools!
15
- * Just install @buoy-gg/jotai and call watchAtoms() with your atoms.
16
- *
17
- * @example Automatic (recommended)
18
- * ```tsx
19
- * import { getDefaultStore } from 'jotai';
20
- * import { watchAtoms } from '@buoy-gg/jotai';
21
- * import { countAtom, authAtom } from './atoms';
22
- *
23
- * watchAtoms(getDefaultStore(), { countAtom, authAtom });
24
- *
25
- * // The Jotai tool appears automatically in FloatingDevTools!
26
- * <FloatingDevTools />
27
- * ```
28
- *
29
- * @example Manual (only for custom configuration)
30
- * ```tsx
31
- * import { createJotaiTool } from '@buoy-gg/jotai';
32
- *
33
- * const customJotaiTool = createJotaiTool({
34
- * name: "ATOMS",
35
- * iconColor: "#6C47FF",
36
- * });
37
- *
38
- * <FloatingDevTools apps={[customJotaiTool]} />
39
- * ```
40
- */
41
-
42
- /**
43
- * Pre-configured Jotai DevTools preset for FloatingDevTools.
44
- * Includes:
45
- * - Live atom change monitoring
46
- * - Atom value inspection (JSON viewer)
47
- * - Value diff visualization (tree + split)
48
- * - Filter by atom label
49
- * - Changed keys tracking for object atoms
50
- */
51
- const jotaiToolPreset = exports.jotaiToolPreset = (0, _sharedUi.defineToolPreset)({
52
- id: "jotai",
53
- name: "JOTAI",
54
- description: "Jotai atom & state inspector",
55
- slot: "both",
56
- icon: ({
57
- size
58
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_JotaiIcon.JotaiIcon, {
59
- size: size
60
- }),
61
- component: _JotaiModal.JotaiModal,
62
- props: {
63
- enableSharedModalDimensions: false
64
- }
65
- });
66
-
67
- /**
68
- * Create a custom Jotai DevTools configuration.
69
- * Use this if you want to override default settings.
70
- *
71
- * @example
72
- * ```tsx
73
- * import { createJotaiTool } from '@buoy-gg/jotai';
74
- *
75
- * const myJotaiTool = createJotaiTool({
76
- * name: "ATOMS",
77
- * iconColor: "#6C47FF",
78
- * });
79
- * ```
80
- */
81
- const createJotaiTool = exports.createJotaiTool = (0, _sharedUi.createToolFactory)(jotaiToolPreset, options => ({
82
- enableSharedModalDimensions: options.enableSharedModalDimensions ?? false
83
- }), options => ({
84
- icon: ({
85
- size
86
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_JotaiIcon.JotaiIcon, {
87
- size: size,
88
- color: options.iconColor
89
- })
90
- }));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.jotaiToolPreset=exports.createJotaiTool=void 0;var _JotaiModal=require("./jotai/components/JotaiModal"),_JotaiIcon=require("./jotai/components/JotaiIcon"),_sharedUi=require("@buoy-gg/shared-ui"),_jsxRuntime=require("react/jsx-runtime");const jotaiToolPreset=exports.jotaiToolPreset=(0,_sharedUi.defineToolPreset)({id:"jotai",name:"JOTAI",description:"Jotai atom & state inspector",slot:"both",icon:({size:o})=>(0,_jsxRuntime.jsx)(_JotaiIcon.JotaiIcon,{size:o}),component:_JotaiModal.JotaiModal,props:{enableSharedModalDimensions:!1}}),createJotaiTool=exports.createJotaiTool=(0,_sharedUi.createToolFactory)(jotaiToolPreset,o=>({enableSharedModalDimensions:o.enableSharedModalDimensions??!1}),o=>({icon:({size:e})=>(0,_jsxRuntime.jsx)(_JotaiIcon.JotaiIcon,{size:e,color:o.iconColor})}));
@@ -1,85 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * @buoy-gg/jotai
5
- *
6
- * Jotai Atom DevTools for React Native
7
- *
8
- * PUBLIC API - Only these exports are supported for external use.
9
- *
10
- * @example Recommended setup (one line, pass your atoms)
11
- * ```tsx
12
- * import { getDefaultStore } from 'jotai';
13
- * import { watchAtoms } from '@buoy-gg/jotai';
14
- * import { countAtom } from './atoms/count';
15
- * import { authAtom } from './atoms/auth';
16
- *
17
- * // One call, anywhere at module scope or in your root layout:
18
- * watchAtoms(getDefaultStore(), {
19
- * countAtom,
20
- * authAtom,
21
- * });
22
- * ```
23
- *
24
- * @example With a custom store (Provider-based)
25
- * ```tsx
26
- * import { createStore } from 'jotai';
27
- * import { watchAtoms } from '@buoy-gg/jotai';
28
- *
29
- * const myStore = createStore();
30
- *
31
- * watchAtoms(myStore, { countAtom, authAtom });
32
- * ```
33
- */
34
-
35
- // Side-effect: registers the Time Machine snapshot provider
36
- import "./jotai/utils/snapshotProvider";
37
-
38
- // =============================================================================
39
- // PRESET (Primary entry point for FloatingDevTools)
40
- // =============================================================================
41
- export { jotaiToolPreset, createJotaiTool } from "./preset";
42
-
43
- // =============================================================================
44
- // WATCH ATOMS (Recommended — subscribe-only, non-intrusive)
45
- // =============================================================================
46
- export { watchAtoms } from "./jotai/utils/watchAtoms";
47
-
48
- // =============================================================================
49
- // CONVENIENCE (Default store shortcut)
50
- // =============================================================================
51
- export { watchDefaultStoreAtoms } from "./jotai/utils/watchAtoms";
52
-
53
- // =============================================================================
54
- // UTILITIES
55
- // =============================================================================
56
- export { isAtomWatched } from "./jotai/utils/watchAtoms";
57
- // =============================================================================
58
- // HOOKS (For consuming Jotai atom data)
59
- // =============================================================================
60
- export { useJotaiAtomChanges } from "./jotai/hooks/useJotaiAtomChanges";
61
- // =============================================================================
62
- // COMPONENTS (For custom UI implementations)
63
- // =============================================================================
64
- // `JotaiToolView` is the same tool rendered inline (header bar + body + footer)
65
- // instead of inside a JsModal — for hosts that show tools in a panel.
66
- export { JotaiModal, JotaiToolView } from "./jotai/components/JotaiModal";
67
- export { JotaiAtomChangeItem } from "./jotai/components/JotaiAtomChangeItem";
68
- export { JotaiAtomDetailContent, JotaiAtomDetailFooter } from "./jotai/components/JotaiAtomDetailContent";
69
- export { JotaiAtomValueDetailContent } from "./jotai/components/JotaiAtomValueDetailContent";
70
- export { JotaiIcon, JOTAI_ICON_COLOR } from "./jotai/components/JotaiIcon";
71
-
72
- // =============================================================================
73
- // EXTERNAL SYNC (Adapter for @buoy-gg/external-sync's useExternalSync)
74
- // =============================================================================
75
- export { jotaiSyncAdapter } from "./jotai/sync/jotaiSyncAdapter";
76
-
77
- // =============================================================================
78
- // TYPES
79
- // =============================================================================
80
-
81
- // =============================================================================
82
- // INTERNAL EXPORTS (For @buoy-gg/* packages only - not part of public API)
83
- // =============================================================================
84
- /** @internal */
85
- export { jotaiStateStore } from "./jotai/utils/jotaiStateStore";
1
+ "use strict";import"./jotai/utils/snapshotProvider";export{jotaiToolPreset,createJotaiTool}from"./preset";export{watchAtoms}from"./jotai/utils/watchAtoms";export{watchDefaultStoreAtoms}from"./jotai/utils/watchAtoms";export{isAtomWatched}from"./jotai/utils/watchAtoms";export{useJotaiAtomChanges}from"./jotai/hooks/useJotaiAtomChanges";export{JotaiModal,JotaiToolView}from"./jotai/components/JotaiModal";export{JotaiAtomChangeItem}from"./jotai/components/JotaiAtomChangeItem";export{JotaiAtomDetailContent,JotaiAtomDetailFooter}from"./jotai/components/JotaiAtomDetailContent";export{JotaiAtomValueDetailContent}from"./jotai/components/JotaiAtomValueDetailContent";export{JotaiIcon,JOTAI_ICON_COLOR}from"./jotai/components/JotaiIcon";export{jotaiSyncAdapter}from"./jotai/sync/jotaiSyncAdapter";export{jotaiStateStore}from"./jotai/utils/jotaiStateStore";
@@ -1,195 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * JotaiAtomBrowser
5
- *
6
- * Atoms tab — shows all registered Jotai atoms and their current value.
7
- * Mirrors ZustandStoreBrowser.tsx from @buoy-gg/zustand: tapping a card
8
- * NAVIGATES to the atom's detail screen (live editor + details + read-only
9
- * tree) rather than expanding in place — the modal owns that selection.
10
- */
11
-
12
- import { useMemo } from "react";
13
- import { View, Text, StyleSheet, ScrollView } from "react-native";
14
- import { CompactRow, night, ToolEmptyState, resolveListEmptyState, monoFont } from "@buoy-gg/shared-ui";
15
- import { jotaiStateStore } from "../utils/jotaiStateStore";
16
- import { JOTAI_TEST_ID, atomRowTestID } from "../utils/testIDs";
17
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
- function getValuePreview(atom) {
19
- try {
20
- const value = atom.getValue();
21
- if (value && typeof value === "object" && value.__buoyValueOnDevice === true) {
22
- return "on device";
23
- }
24
- if (value === undefined) return "undefined";
25
- if (value === null) return "null";
26
- if (Array.isArray(value)) {
27
- if (value.length === 0) return "[]";
28
- return `[${value.length} item${value.length === 1 ? "" : "s"}]`;
29
- }
30
- if (typeof value === "object") {
31
- const keys = Object.keys(value);
32
- if (keys.length === 0) return "{}";
33
- if (keys.length <= 3) return keys.join(", ");
34
- return `${keys.slice(0, 2).join(", ")} +${keys.length - 2}`;
35
- }
36
- return String(value).slice(0, 40);
37
- } catch {
38
- return "";
39
- }
40
- }
41
-
42
- /**
43
- * The card's categorical slot — the atom's write story, mirroring the
44
- * zustand card's "persisted"/"in-memory" backing label.
45
- */
46
- function getWriteKindLabel(atom) {
47
- if (atom.writeKind === "value") return "primitive";
48
- if (atom.writeKind === "action") return "custom write";
49
- return atom.setValue ? "writable" : "derived";
50
- }
51
- function EmptyBrowserState() {
52
- return /*#__PURE__*/_jsx(ToolEmptyState, {
53
- testID: `${JOTAI_TEST_ID}-atoms-empty`
54
- // scanning = "scanning for targets… and finding none". The registry is
55
- // discovered, not configured, so an empty one is a scan result.
56
- ,
57
- otto: "scanning",
58
- title: "No atoms registered",
59
- message: "Use watchAtoms(store, { atomName }) to register your Jotai atoms.\nThey will appear here with their current value."
60
- });
61
- }
62
- export function JotaiAtomBrowser({
63
- atoms,
64
- searchQuery,
65
- onOpenAtom
66
- }) {
67
- const filteredAtoms = useMemo(() => {
68
- if (!searchQuery) return atoms;
69
- const search = searchQuery.toLowerCase();
70
- return atoms.filter(a => a.label.toLowerCase().includes(search));
71
- }, [atoms, searchQuery]);
72
- if (filteredAtoms.length === 0 && !searchQuery) {
73
- return /*#__PURE__*/_jsx(EmptyBrowserState, {});
74
- }
75
- if (filteredAtoms.length === 0 && searchQuery) {
76
- return /*#__PURE__*/_jsx(ToolEmptyState, {
77
- testID: `${JOTAI_TEST_ID}-atoms-no-match`,
78
- ...resolveListEmptyState({
79
- subject: "atoms",
80
- verb: "registered",
81
- search: searchQuery,
82
- total: atoms.length,
83
- waiting: {
84
- otto: "scanning",
85
- title: "No atoms registered",
86
- message: "Use watchAtoms() to register your Jotai atoms."
87
- }
88
- })
89
- });
90
- }
91
- return /*#__PURE__*/_jsxs(ScrollView, {
92
- style: styles.container,
93
- contentContainerStyle: styles.scrollContent,
94
- showsVerticalScrollIndicator: true,
95
- testID: `${JOTAI_TEST_ID}-atoms-scroll`,
96
- children: [/*#__PURE__*/_jsxs(View, {
97
- style: styles.sectionHeader,
98
- children: [/*#__PURE__*/_jsx(Text, {
99
- style: styles.sectionTitle,
100
- children: "ATOMS"
101
- }), /*#__PURE__*/_jsx(View, {
102
- style: styles.sectionCountBadge,
103
- children: /*#__PURE__*/_jsx(Text, {
104
- style: styles.sectionCountText,
105
- testID: `${JOTAI_TEST_ID}-atoms-count`,
106
- children: filteredAtoms.length
107
- })
108
- })]
109
- }), filteredAtoms.map(atom => {
110
- const valuePreview = getValuePreview(atom);
111
- const atomColor = jotaiStateStore.getAtomColor(atom.label);
112
- const rowID = atomRowTestID(atom.label);
113
- return /*#__PURE__*/_jsxs(View, {
114
- style: styles.atomRowWrapper,
115
- children: [/*#__PURE__*/_jsx(CompactRow, {
116
- statusDotColor: atomColor,
117
- statusLabel: getWriteKindLabel(atom),
118
- primaryText: atom.label,
119
- secondaryText: valuePreview || undefined,
120
- showChevron: true,
121
- onPress: () => onOpenAtom(atom.label),
122
- testID: rowID,
123
- statusTestID: `${rowID}-kind`,
124
- primaryTestID: `${rowID}-name`,
125
- secondaryTestID: `${rowID}-preview`
126
- }), atom.changeCount > 0 && /*#__PURE__*/_jsx(View, {
127
- style: [styles.absCountBadge, {
128
- backgroundColor: atomColor + "22",
129
- borderColor: atomColor + "55"
130
- }],
131
- pointerEvents: "none",
132
- children: /*#__PURE__*/_jsx(Text, {
133
- style: [styles.absCountText, {
134
- color: atomColor
135
- }],
136
- testID: `${rowID}-count`,
137
- children: String(atom.changeCount)
138
- })
139
- })]
140
- }, atom.label);
141
- })]
142
- });
143
- }
144
- const styles = StyleSheet.create({
145
- container: {
146
- flex: 1
147
- },
148
- atomRowWrapper: {
149
- position: "relative"
150
- },
151
- absCountBadge: {
152
- position: "absolute",
153
- top: 4,
154
- right: 10,
155
- paddingHorizontal: 5,
156
- paddingVertical: 1,
157
- borderRadius: 4,
158
- borderWidth: 1,
159
- zIndex: 1
160
- },
161
- absCountText: {
162
- fontSize: 9,
163
- fontWeight: "700",
164
- fontFamily: monoFont
165
- },
166
- scrollContent: {
167
- paddingTop: 8,
168
- paddingBottom: 20
169
- },
170
- sectionHeader: {
171
- flexDirection: "row",
172
- alignItems: "center",
173
- paddingHorizontal: 16,
174
- paddingVertical: 8,
175
- gap: 8
176
- },
177
- sectionTitle: {
178
- fontSize: 11,
179
- fontWeight: "700",
180
- letterSpacing: 0.5,
181
- color: night.color.textTertiary
182
- },
183
- sectionCountBadge: {
184
- backgroundColor: night.color.accentFill,
185
- paddingHorizontal: 8,
186
- paddingVertical: 2,
187
- borderRadius: 4
188
- },
189
- sectionCountText: {
190
- fontSize: 10,
191
- fontWeight: "700",
192
- color: night.color.accent,
193
- fontFamily: monoFont
194
- }
195
- });
1
+ "use strict";import{useMemo}from"react";import{View,Text,StyleSheet,ScrollView}from"react-native";import{CompactRow,night,ToolEmptyState,resolveListEmptyState,monoFont}from"@buoy-gg/shared-ui";import{jotaiStateStore}from"../utils/jotaiStateStore";import{JOTAI_TEST_ID,atomRowTestID}from"../utils/testIDs";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function getValuePreview(t){try{const e=t.getValue();if(e&&"object"==typeof e&&!0===e.__buoyValueOnDevice)return"on device";if(void 0===e)return"undefined";if(null===e)return"null";if(Array.isArray(e))return 0===e.length?"[]":`[${e.length} item${1===e.length?"":"s"}]`;if("object"==typeof e){const t=Object.keys(e);return 0===t.length?"{}":t.length<=3?t.join(", "):`${t.slice(0,2).join(", ")} +${t.length-2}`}return String(e).slice(0,40)}catch{return""}}function getWriteKindLabel(t){return"value"===t.writeKind?"primitive":"action"===t.writeKind?"custom write":t.setValue?"writable":"derived"}function EmptyBrowserState(){return _jsx(ToolEmptyState,{testID:`${JOTAI_TEST_ID}-atoms-empty`,otto:"scanning",title:"No atoms registered",message:"Use watchAtoms(store, { atomName }) to register your Jotai atoms.\nThey will appear here with their current value."})}export function JotaiAtomBrowser({atoms:t,searchQuery:e,onOpenAtom:o}){const r=useMemo(()=>{if(!e)return t;const o=e.toLowerCase();return t.filter(t=>t.label.toLowerCase().includes(o))},[t,e]);return 0!==r.length||e?0===r.length&&e?_jsx(ToolEmptyState,{testID:`${JOTAI_TEST_ID}-atoms-no-match`,...resolveListEmptyState({subject:"atoms",verb:"registered",search:e,total:t.length,waiting:{otto:"scanning",title:"No atoms registered",message:"Use watchAtoms() to register your Jotai atoms."}})}):_jsxs(ScrollView,{style:styles.container,contentContainerStyle:styles.scrollContent,showsVerticalScrollIndicator:!0,testID:`${JOTAI_TEST_ID}-atoms-scroll`,children:[_jsxs(View,{style:styles.sectionHeader,children:[_jsx(Text,{style:styles.sectionTitle,children:"ATOMS"}),_jsx(View,{style:styles.sectionCountBadge,children:_jsx(Text,{style:styles.sectionCountText,testID:`${JOTAI_TEST_ID}-atoms-count`,children:r.length})})]}),r.map(t=>{const e=getValuePreview(t),r=jotaiStateStore.getAtomColor(t.label),n=atomRowTestID(t.label);return _jsxs(View,{style:styles.atomRowWrapper,children:[_jsx(CompactRow,{statusDotColor:r,statusLabel:getWriteKindLabel(t),primaryText:t.label,secondaryText:e||void 0,showChevron:!0,onPress:()=>o(t.label),testID:n,statusTestID:`${n}-kind`,primaryTestID:`${n}-name`,secondaryTestID:`${n}-preview`}),t.changeCount>0&&_jsx(View,{style:[styles.absCountBadge,{backgroundColor:r+"22",borderColor:r+"55"}],pointerEvents:"none",children:_jsx(Text,{style:[styles.absCountText,{color:r}],testID:`${n}-count`,children:String(t.changeCount)})})]},t.label)})]}):_jsx(EmptyBrowserState,{})}const styles=StyleSheet.create({container:{flex:1},atomRowWrapper:{position:"relative"},absCountBadge:{position:"absolute",top:4,right:10,paddingHorizontal:5,paddingVertical:1,borderRadius:4,borderWidth:1,zIndex:1},absCountText:{fontSize:9,fontWeight:"700",fontFamily:monoFont},scrollContent:{paddingTop:8,paddingBottom:20},sectionHeader:{flexDirection:"row",alignItems:"center",paddingHorizontal:16,paddingVertical:8,gap:8},sectionTitle:{fontSize:11,fontWeight:"700",letterSpacing:.5,color:night.color.textTertiary},sectionCountBadge:{backgroundColor:night.color.accentFill,paddingHorizontal:8,paddingVertical:2,borderRadius:4},sectionCountText:{fontSize:10,fontWeight:"700",color:night.color.accent,fontFamily:monoFont}});
@@ -1,81 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Compact list item for displaying a Jotai atom change
5
- *
6
- * Mirrors ZustandStateChangeItem.tsx — uses shared CompactRow for consistent styling
7
- */
8
-
9
- import { memo } from "react";
10
- import { ChangeRow, night } from "@buoy-gg/shared-ui";
11
- import { jotaiStateStore } from "../utils/jotaiStateStore";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- function getStatusLabel(category, atomLabel) {
14
- if (category === "initial") return "Initial";
15
- return atomLabel.charAt(0).toUpperCase() + atomLabel.slice(1);
16
- }
17
- function getCategoryColor(category, atomLabel) {
18
- if (category === "initial") return night.color.textTertiary;
19
- return jotaiStateStore.getAtomColor(atomLabel);
20
- }
21
- function formatCompact(value, maxLen = 20) {
22
- if (value === undefined) return "undefined";
23
- if (value === null) return "null";
24
- if (typeof value === "boolean") return String(value);
25
- if (typeof value === "number") return String(value);
26
- if (typeof value === "string") {
27
- const truncated = value.length > maxLen ? value.slice(0, maxLen - 1) + "…" : value;
28
- return `"${truncated}"`;
29
- }
30
- if (Array.isArray(value)) {
31
- return value.length === 0 ? "[]" : `[${value.length} item${value.length === 1 ? "" : "s"}]`;
32
- }
33
- if (typeof value === "object") {
34
- const keys = Object.keys(value);
35
- if (keys.length === 0) return "{}";
36
- return `{${keys.slice(0, 2).join(", ")}${keys.length > 2 ? "…" : ""}}`;
37
- }
38
- return String(value).slice(0, maxLen);
39
- }
40
- function getSublabel(change) {
41
- if (!change.hasValueChange) return "no change";
42
- return `${formatCompact(change.prevValue)} → ${formatCompact(change.nextValue)}`;
43
- }
44
- function getBadgeText(change) {
45
- if (change.category === "initial") return "INIT";
46
- return "WRITE";
47
- }
48
- function getPrimaryText(change) {
49
- if (change.changedKeys.length > 0 && change.changedKeys.length <= 3) {
50
- return change.changedKeys.join(", ");
51
- }
52
- if (change.changedKeys.length > 3) {
53
- return `${change.changedKeys.slice(0, 2).join(", ")} +${change.changedKeys.length - 2}`;
54
- }
55
- return change.valuePreview || "atom()";
56
- }
57
-
58
- // Memo justified by profiling (tool-bench 2026-07-06) — see
59
- // ZustandStateChangeItem (same pattern).
60
- export const JotaiAtomChangeItem = /*#__PURE__*/memo(function JotaiAtomChangeItem({
61
- change,
62
- onPress,
63
- testID
64
- }) {
65
- const statusColor = getCategoryColor(change.category, change.atomLabel);
66
- const statusLabel = getStatusLabel(change.category, change.atomLabel);
67
- const sublabel = getSublabel(change);
68
- const primaryText = getPrimaryText(change);
69
- const badgeText = getBadgeText(change);
70
- return /*#__PURE__*/_jsx(ChangeRow, {
71
- statusColor: statusColor,
72
- statusLabel: statusLabel,
73
- sublabel: sublabel,
74
- primaryText: primaryText,
75
- timestamp: change.timestamp,
76
- badgeText: badgeText,
77
- changed: change.hasValueChange,
78
- onPress: () => onPress(change),
79
- testID: testID
80
- });
81
- });
1
+ "use strict";import{memo}from"react";import{ChangeRow,night}from"@buoy-gg/shared-ui";import{jotaiStateStore}from"../utils/jotaiStateStore";import{jsx as _jsx}from"react/jsx-runtime";function getStatusLabel(t,e){return"initial"===t?"Initial":e.charAt(0).toUpperCase()+e.slice(1)}function getCategoryColor(t,e){return"initial"===t?night.color.textTertiary:jotaiStateStore.getAtomColor(e)}function formatCompact(t,e=20){if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return String(t);if("number"==typeof t)return String(t);if("string"==typeof t)return`"${t.length>e?t.slice(0,e-1)+"…":t}"`;if(Array.isArray(t))return 0===t.length?"[]":`[${t.length} item${1===t.length?"":"s"}]`;if("object"==typeof t){const e=Object.keys(t);return 0===e.length?"{}":`{${e.slice(0,2).join(", ")}${e.length>2?"…":""}}`}return String(t).slice(0,e)}function getSublabel(t){return t.hasValueChange?`${formatCompact(t.prevValue)} → ${formatCompact(t.nextValue)}`:"no change"}function getBadgeText(t){return"initial"===t.category?"INIT":"WRITE"}function getPrimaryText(t){return t.changedKeys.length>0&&t.changedKeys.length<=3?t.changedKeys.join(", "):t.changedKeys.length>3?`${t.changedKeys.slice(0,2).join(", ")} +${t.changedKeys.length-2}`:t.valuePreview||"atom()"}export const JotaiAtomChangeItem=memo(function({change:t,onPress:e,testID:r}){const n=getCategoryColor(t.category,t.atomLabel),a=getStatusLabel(t.category,t.atomLabel),o=getSublabel(t),i=getPrimaryText(t),g=getBadgeText(t);return _jsx(ChangeRow,{statusColor:n,statusLabel:a,sublabel:o,primaryText:i,timestamp:t.timestamp,badgeText:g,changed:t.hasValueChange,onPress:()=>e(t),testID:r})});