@buoy-gg/jotai 7.0.32 → 7.0.34

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 (35) hide show
  1. package/lib/commonjs/jotai/components/JotaiAtomBrowser.js +20 -41
  2. package/lib/commonjs/jotai/components/JotaiAtomChangeItem.js +7 -52
  3. package/lib/commonjs/jotai/components/JotaiAtomDetailContent.js +8 -87
  4. package/lib/commonjs/jotai/components/JotaiEventFilterView.js +21 -299
  5. package/lib/commonjs/jotai/components/JotaiModal.js +82 -124
  6. package/lib/commonjs/jotai/hooks/useJotaiAtomChanges.js +33 -49
  7. package/lib/commonjs/jotai/sync/jotaiSyncAdapter.js +19 -66
  8. package/lib/commonjs/jotai/utils/jotaiStateStore.js +23 -188
  9. package/lib/commonjs/jotai/utils/snapshotProvider.js +7 -25
  10. package/lib/commonjs/preset.js +14 -22
  11. package/lib/module/jotai/components/JotaiAtomBrowser.js +21 -42
  12. package/lib/module/jotai/components/JotaiAtomChangeItem.js +9 -54
  13. package/lib/module/jotai/components/JotaiAtomDetailContent.js +9 -88
  14. package/lib/module/jotai/components/JotaiEventFilterView.js +24 -302
  15. package/lib/module/jotai/components/JotaiModal.js +84 -126
  16. package/lib/module/jotai/hooks/useJotaiAtomChanges.js +34 -50
  17. package/lib/module/jotai/sync/jotaiSyncAdapter.js +20 -67
  18. package/lib/module/jotai/utils/jotaiStateStore.js +23 -188
  19. package/lib/module/jotai/utils/snapshotProvider.js +8 -26
  20. package/lib/module/preset.js +13 -20
  21. package/lib/typescript/jotai/components/JotaiAtomBrowser.d.ts.map +1 -1
  22. package/lib/typescript/jotai/components/JotaiAtomChangeItem.d.ts.map +1 -1
  23. package/lib/typescript/jotai/components/JotaiAtomDetailContent.d.ts.map +1 -1
  24. package/lib/typescript/jotai/components/JotaiEventFilterView.d.ts +2 -2
  25. package/lib/typescript/jotai/components/JotaiEventFilterView.d.ts.map +1 -1
  26. package/lib/typescript/jotai/components/JotaiModal.d.ts.map +1 -1
  27. package/lib/typescript/jotai/hooks/useJotaiAtomChanges.d.ts +2 -1
  28. package/lib/typescript/jotai/hooks/useJotaiAtomChanges.d.ts.map +1 -1
  29. package/lib/typescript/jotai/sync/jotaiSyncAdapter.d.ts +54 -68
  30. package/lib/typescript/jotai/sync/jotaiSyncAdapter.d.ts.map +1 -1
  31. package/lib/typescript/jotai/utils/jotaiStateStore.d.ts +2 -25
  32. package/lib/typescript/jotai/utils/jotaiStateStore.d.ts.map +1 -1
  33. package/lib/typescript/preset.d.ts +2 -8
  34. package/lib/typescript/preset.d.ts.map +1 -1
  35. package/package.json +3 -3
@@ -26,33 +26,32 @@ var _jsxRuntime = require("react/jsx-runtime");
26
26
  */
27
27
 
28
28
  /**
29
- * Cell clipping, off in e2e bundles only.
30
- *
31
- * `removeClippedSubviews` unmounts the views of rows scrolled out of the
32
- * window, which is what makes a long change list cheap — and which makes
33
- * Detox report a perfectly rendered row as un-hittable. The env var is
34
- * inlined at bundle time, so a bundler that does NOT inline it leaves the
35
- * production behaviour exactly as it was.
29
+ * The change log's "nothing here". Everything but the nouns is the shared
30
+ * precedence — see `ToolEmptyState` in shared-ui for why it lives there.
36
31
  */
37
- const CLIP_OFFSCREEN_CELLS = !(typeof process !== "undefined" && process.env?.EXPO_PUBLIC_E2E);
38
32
  function EventsEmptyState({
39
- isEnabled
33
+ isEnabled,
34
+ searchText,
35
+ totalChanges
40
36
  }) {
41
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
42
- style: styles.emptyState,
43
- testID: `${_testIDs.JOTAI_TEST_ID}-empty`,
44
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.Box, {
45
- size: 32,
46
- color: _sharedUi.night.color.textTertiary
47
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
48
- style: styles.emptyTitle,
49
- testID: `${_testIDs.JOTAI_TEST_ID}-empty-title`,
50
- children: "No atom changes"
51
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
52
- style: styles.emptyText,
53
- testID: `${_testIDs.JOTAI_TEST_ID}-empty-text`,
54
- children: isEnabled ? "Atom changes will appear here as values update." : "Enable capture to start recording atom changes"
55
- })]
37
+ const content = (0, _sharedUi.resolveListEmptyState)({
38
+ subject: "changes",
39
+ search: searchText,
40
+ total: totalChanges,
41
+ capturing: isEnabled,
42
+ waiting: {
43
+ otto: "waiting",
44
+ title: "No atom changes",
45
+ message: "Atom changes will appear here as values update."
46
+ },
47
+ paused: {
48
+ title: "No atom changes",
49
+ message: "Enable capture to start recording atom changes"
50
+ }
51
+ });
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.ToolEmptyState, {
53
+ ...content,
54
+ testID: `${_testIDs.JOTAI_TEST_ID}-empty`
56
55
  });
57
56
  }
58
57
  function JotaiModal({
@@ -79,7 +78,9 @@ function JotaiModal({
79
78
  const [showFilters, setShowFilters] = (0, _react.useState)(false);
80
79
  const [ignoredPatterns, setIgnoredPatterns] = (0, _react.useState)(new Set());
81
80
  const {
81
+ atomChanges,
82
82
  filteredChanges,
83
+ stats,
83
84
  filter,
84
85
  setFilter,
85
86
  atoms,
@@ -102,6 +103,15 @@ function JotaiModal({
102
103
 
103
104
  // Pro is Infinity here, so slice() returns everything and the locked count
104
105
  // floors at 0 — no tier branching needed at the call site.
106
+ /**
107
+ * How many changes this atom has captured, before the search — the
108
+ * denominator the scoped empty state needs so "clear the search" is only
109
+ * offered when clearing it would actually show something.
110
+ */
111
+ const scopedTotalForAtom = (0, _react.useMemo)(() => {
112
+ if (!selectedHistoryAtom) return 0;
113
+ return atomChanges.filter(c => c.atomLabel === selectedHistoryAtom).length;
114
+ }, [atomChanges, selectedHistoryAtom]);
105
115
  const visibleChanges = (0, _react.useMemo)(() => displayedChanges.slice(0, changeLimit), [displayedChanges, changeLimit]);
106
116
  const lockedChangeCount = (0, _react.useMemo)(() => Math.max(0, displayedChanges.length - changeLimit), [displayedChanges.length, changeLimit]);
107
117
  const hasLockedChanges = lockedChangeCount > 0;
@@ -337,49 +347,24 @@ function JotaiModal({
337
347
  onBack: onBack
338
348
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.ModalHeader.Content, {
339
349
  title: "",
340
- children: isSearchActive ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
341
- style: styles.headerSearchContainer,
342
- testID: `${_testIDs.JOTAI_TEST_ID}-search`,
343
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.Search, {
344
- size: 14,
345
- color: _sharedUi.night.color.textSecondary
346
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
347
- ref: searchInputRef,
348
- testID: `${_testIDs.JOTAI_TEST_ID}-search-field`,
349
- style: styles.headerSearchInput,
350
- placeholder: activeTab === "atoms" ? "Search atoms..." : "Search events...",
351
- placeholderTextColor: _sharedUi.night.color.placeholder,
352
- value: searchText,
353
- onChangeText: handleSearch,
354
- onSubmitEditing: () => searchInputRef.current?.blur()
355
- // Stay open while the query is still narrowing the list.
356
- //
357
- // Collapsing on blur hid the reason rows were missing: the
358
- // header went back to its TABS — whose counts are of the
359
- // WHOLE capture — while the list stayed filtered, so the tool
360
- // showed "Atoms (8)" above a single row and offered nothing to
361
- // explain the gap. The only way back was to reopen a field the
362
- // user had no reason to think was still armed. Same shape, and
363
- // the same fix, as the Redux, Events and Zustand tools.
364
- ,
365
- onBlur: () => {
366
- if (searchText.length === 0) setIsSearchActive(false);
367
- },
368
- accessibilityLabel: "Search Jotai atoms and events",
369
- autoCapitalize: "none",
370
- autoCorrect: false,
371
- returnKeyType: "search"
372
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
373
- onPress: closeSearch,
374
- style: styles.headerSearchClear,
375
- testID: `${_testIDs.JOTAI_TEST_ID}-search-clear`,
376
- accessibilityRole: "button",
377
- accessibilityLabel: "Close search",
378
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.X, {
379
- size: 14,
380
- color: _sharedUi.night.color.textSecondary
381
- })
382
- })]
350
+ children: isSearchActive ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.ModalHeader.Search, {
351
+ value: searchText,
352
+ onChangeText: handleSearch,
353
+ onCancel: closeSearch,
354
+ placeholder: activeTab === "atoms" ? "Search atoms..." : "Search events...",
355
+ accessibilityLabel: "Search Jotai atoms and events",
356
+ iconSize: 14,
357
+ testID: `${_testIDs.JOTAI_TEST_ID}-search-field`,
358
+ containerTestID: `${_testIDs.JOTAI_TEST_ID}-search`,
359
+ clearTestID: `${_testIDs.JOTAI_TEST_ID}-search-clear`
360
+ // Stay open while the query is still narrowing the list: the
361
+ // header would otherwise go back to its TABS — whose counts are
362
+ // of the WHOLE capture — above a filtered list, with nothing to
363
+ // explain the gap.
364
+ ,
365
+ onBlur: () => {
366
+ if (searchText.length === 0) setIsSearchActive(false);
367
+ }
383
368
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.TabSelector, {
384
369
  tabs: [{
385
370
  key: "atoms",
@@ -469,24 +454,25 @@ function JotaiModal({
469
454
  keyExtractor: keyExtractor,
470
455
  contentContainerStyle: styles.listContent,
471
456
  showsVerticalScrollIndicator: true,
472
- removeClippedSubviews: CLIP_OFFSCREEN_CELLS,
473
- initialNumToRender: 12,
474
- maxToRenderPerBatch: 8,
475
- windowSize: 5,
476
- updateCellsBatchingPeriod: 50
477
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
478
- style: styles.emptyState,
457
+ ..._sharedUi.EVENT_LIST_PRESET
458
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.ToolEmptyState, {
479
459
  testID: `${_testIDs.JOTAI_TEST_ID}-history-empty`,
480
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.Box, {
481
- size: 32,
482
- color: _sharedUi.night.color.textTertiary
483
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
484
- style: styles.emptyTitle,
485
- children: "No history yet"
486
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
487
- style: styles.emptyText,
488
- children: ["Changes for ", selectedHistoryAtom, " will appear here."]
489
- })]
460
+ ...(0, _sharedUi.resolveListEmptyState)({
461
+ subject: "changes",
462
+ search: searchText,
463
+ // Scoped to one atom, so the count is this atom's, not the log's.
464
+ total: searchText.trim() ? scopedTotalForAtom : 0,
465
+ capturing: isEnabled,
466
+ waiting: {
467
+ otto: "waiting",
468
+ title: "No history yet",
469
+ message: `Changes for ${selectedHistoryAtom} will appear here.`
470
+ },
471
+ paused: {
472
+ title: "No history yet",
473
+ message: `Capture is off, so nothing is being recorded for ${selectedHistoryAtom}.`
474
+ }
475
+ })
490
476
  });
491
477
  }
492
478
 
@@ -502,19 +488,14 @@ function JotaiModal({
502
488
  /*#__PURE__*/
503
489
  // The atom fell out of the registry mid-look (a remote mirror
504
490
  // rebuilding, a dev reload). Say so rather than rendering nothing.
505
- (0, _jsxRuntime.jsxs)(_reactNative.View, {
506
- style: styles.emptyState,
507
- testID: `${_testIDs.JOTAI_TEST_ID}-atom-detail-gone`,
508
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sharedUi.Box, {
509
- size: 32,
510
- color: _sharedUi.night.color.textTertiary
511
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
512
- style: styles.emptyTitle,
513
- children: "Atom no longer registered"
514
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Text, {
515
- style: styles.emptyText,
516
- children: [selectedAtomLabel, " is not in the registry any more."]
517
- })]
491
+ (0, _jsxRuntime.jsx)(_sharedUi.ToolEmptyState, {
492
+ testID: `${_testIDs.JOTAI_TEST_ID}-atom-detail-gone`
493
+ // ghost = "stale or detached: an unmounted component, an old
494
+ // snapshot" — exactly what the atom you are looking at has become.
495
+ ,
496
+ otto: "ghost",
497
+ title: "Atom no longer registered",
498
+ message: `${selectedAtomLabel} is not in the registry any more.`
518
499
  });
519
500
  }
520
501
  if (activeTab === "atoms") {
@@ -562,13 +543,11 @@ function JotaiModal({
562
543
  keyExtractor: keyExtractor,
563
544
  contentContainerStyle: styles.listContent,
564
545
  showsVerticalScrollIndicator: true,
565
- removeClippedSubviews: CLIP_OFFSCREEN_CELLS,
566
- initialNumToRender: 12,
567
- maxToRenderPerBatch: 8,
568
- windowSize: 5,
569
- updateCellsBatchingPeriod: 50
546
+ ..._sharedUi.EVENT_LIST_PRESET
570
547
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(EventsEmptyState, {
571
- isEnabled: isEnabled
548
+ isEnabled: isEnabled,
549
+ searchText: searchText,
550
+ totalChanges: stats.totalChanges
572
551
  })]
573
552
  });
574
553
  };
@@ -678,27 +657,6 @@ const styles = _reactNative.StyleSheet.create({
678
657
  // Transparent so JsModal's ToolBackground shows through (the modal paints opaque base beneath it).
679
658
  backgroundColor: "transparent"
680
659
  },
681
- headerSearchContainer: {
682
- flexDirection: "row",
683
- alignItems: "center",
684
- backgroundColor: _sharedUi.night.color.surfaceElevated,
685
- borderRadius: _sharedUi.night.radius.row,
686
- borderWidth: 1,
687
- borderColor: _sharedUi.night.color.border,
688
- paddingHorizontal: 12,
689
- paddingVertical: 5
690
- },
691
- headerSearchInput: {
692
- flex: 1,
693
- color: _sharedUi.night.color.text,
694
- fontSize: 13,
695
- marginLeft: 6,
696
- paddingVertical: 2
697
- },
698
- headerSearchClear: {
699
- marginLeft: 6,
700
- padding: 4
701
- },
702
660
  headerActionButton: {
703
661
  width: 32,
704
662
  height: 32,
@@ -5,78 +5,62 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useJotaiAtomChanges = useJotaiAtomChanges;
7
7
  var _react = require("react");
8
+ var _sharedUi = require("@buoy-gg/shared-ui");
8
9
  var _jotaiStateStore = require("../utils/jotaiStateStore");
9
10
  /**
10
11
  * Hook for consuming Jotai atom changes from the store
11
12
  *
12
- * Mirrors useZustandStateChanges.ts from @buoy-gg/zustand
13
+ * The subscribe / filter / pause / clear plumbing is shared `useChangeLog`;
14
+ * this file owns the jotai-specific filter, stats and atom registry.
13
15
  */
14
16
 
17
+ function filterChanges(changes, filter) {
18
+ let filtered = changes;
19
+ if (filter.searchText) {
20
+ const search = filter.searchText.toLowerCase();
21
+ filtered = filtered.filter(c => c.atomLabel.toLowerCase().includes(search) || c.valuePreview.toLowerCase().includes(search) || c.changedKeys.some(k => k.toLowerCase().includes(search)));
22
+ }
23
+ if (filter.atomLabels && filter.atomLabels.length > 0) {
24
+ filtered = filtered.filter(c => filter.atomLabels.includes(c.atomLabel));
25
+ }
26
+ if (filter.onlyWithChanges) {
27
+ filtered = filtered.filter(c => c.hasValueChange);
28
+ }
29
+ return filtered;
30
+ }
31
+ const readAtoms = () => _jotaiStateStore.jotaiStateStore.getAtoms();
32
+ const subscribeToAtoms = listener => _jotaiStateStore.jotaiStateStore.subscribeToAtoms(listener);
15
33
  function useJotaiAtomChanges() {
16
- const [atomChanges, setAtomChanges] = (0, _react.useState)(() => _jotaiStateStore.jotaiStateStore.getAtomChanges());
17
- const [atoms, setAtoms] = (0, _react.useState)(() => _jotaiStateStore.jotaiStateStore.getAtoms());
18
- const [filter, setFilter] = (0, _react.useState)({});
19
- const [isEnabled, setIsEnabled] = (0, _react.useState)(() => _jotaiStateStore.jotaiStateStore.getEnabled());
20
- (0, _react.useEffect)(() => {
21
- const unsubChanges = _jotaiStateStore.jotaiStateStore.subscribe(newChanges => {
22
- setAtomChanges(newChanges);
23
- });
24
- const unsubAtoms = _jotaiStateStore.jotaiStateStore.subscribeToAtoms(newAtoms => {
25
- setAtoms(newAtoms);
26
- });
27
- return () => {
28
- unsubChanges();
29
- unsubAtoms();
30
- };
31
- }, []);
32
- const filteredChanges = (0, _react.useMemo)(() => {
33
- let filtered = atomChanges;
34
- if (filter.searchText) {
35
- const search = filter.searchText.toLowerCase();
36
- filtered = filtered.filter(c => c.atomLabel.toLowerCase().includes(search) || c.valuePreview.toLowerCase().includes(search) || c.changedKeys.some(k => k.toLowerCase().includes(search)));
37
- }
38
- if (filter.atomLabels && filter.atomLabels.length > 0) {
39
- filtered = filtered.filter(c => filter.atomLabels.includes(c.atomLabel));
40
- }
41
- if (filter.onlyWithChanges) {
42
- filtered = filtered.filter(c => c.hasValueChange);
43
- }
44
- return filtered;
45
- }, [atomChanges, filter]);
34
+ const log = (0, _sharedUi.useChangeLog)(_jotaiStateStore.jotaiStateStore, {
35
+ filterItems: filterChanges
36
+ });
37
+ const atoms = (0, _sharedUi.useSubscribedValue)(readAtoms, subscribeToAtoms);
46
38
  const stats = (0, _react.useMemo)(() => {
47
- const total = atomChanges.length;
48
- const withChanges = atomChanges.filter(c => c.hasValueChange).length;
39
+ const total = log.items.length;
40
+ const withChanges = log.items.filter(c => c.hasValueChange).length;
49
41
  return {
50
42
  totalChanges: total,
51
43
  changesWithValueChange: withChanges,
52
44
  changesWithoutValueChange: total - withChanges,
53
45
  atomCount: atoms.length
54
46
  };
55
- }, [atomChanges, atoms]);
47
+ }, [log.items, atoms]);
56
48
  const atomLabels = (0, _react.useMemo)(() => {
57
49
  return _jotaiStateStore.jotaiStateStore.getUniqueAtomLabels();
58
50
  }, [atoms]);
59
- const clearChanges = (0, _react.useCallback)(() => {
60
- _jotaiStateStore.jotaiStateStore.clearAtomChanges();
61
- }, []);
62
- const toggleCapture = (0, _react.useCallback)(() => {
63
- const newEnabled = !isEnabled;
64
- _jotaiStateStore.jotaiStateStore.setEnabled(newEnabled);
65
- setIsEnabled(newEnabled);
66
- }, [isEnabled]);
67
51
  const getChangeById = (0, _react.useCallback)(id => {
68
52
  return _jotaiStateStore.jotaiStateStore.getAtomChangeById(id);
69
53
  }, []);
70
54
  return {
71
- atomChanges,
72
- filteredChanges,
73
- filter,
74
- setFilter,
55
+ atomChanges: log.items,
56
+ filteredChanges: log.filteredItems,
57
+ filter: log.filter,
58
+ setFilter: log.setFilter,
75
59
  stats,
76
60
  atoms,
77
- clearChanges,
78
- isEnabled,
79
- toggleCapture,
61
+ clearChanges: log.clear,
62
+ isEnabled: log.isEnabled,
63
+ toggleCapture: log.toggleCapture,
80
64
  atomLabels,
81
65
  getChangeById
82
66
  };
@@ -11,36 +11,21 @@ var _sharedUi = require("@buoy-gg/shared-ui");
11
11
  * Same hazard as redux/zustand: up to 200 changes × 2 values on every
12
12
  * snapshot. Dashboards fetch values via `getChangeDetail`.
13
13
  */
14
- const VALUE_ON_DEVICE = exports.VALUE_ON_DEVICE = Object.freeze({
15
- __buoyValueOnDevice: true,
16
- note: "Atom values stay on the device — fetched on demand via getChangeDetail / getAtomValue."
17
- });
18
- const MAX_CHANGE_DETAIL_BYTES = 8 * 1024 * 1024;
19
- const MAX_WIRE_PAYLOAD_BYTES = 16 * 1024;
14
+ const VALUE_ON_DEVICE = exports.VALUE_ON_DEVICE = (0, _sharedUi.onDeviceMarker)("Value", "Atom values stay on the device — fetched on demand via getChangeDetail / getAtomValue.");
20
15
  /**
21
16
  * Per-change wire cache — the store prepends and never mutates a recorded
22
17
  * change, so identity is a correct, self-invalidating key.
23
18
  */
24
- const changeCache = new WeakMap();
25
- function toWireChange(change) {
26
- const cached = changeCache.get(change);
27
- if (cached) return cached;
28
- const wire = {
29
- ...change,
30
- prevValue: VALUE_ON_DEVICE,
31
- nextValue: VALUE_ON_DEVICE
32
- };
33
- changeCache.set(change, wire);
34
- return wire;
35
- }
36
- function toWireValue(value) {
37
- return (0, _sharedUi.isOverWireBudget)(value, MAX_WIRE_PAYLOAD_BYTES) ? VALUE_ON_DEVICE : value;
38
- }
19
+ const toWireChange = (0, _sharedUi.memoByIdentity)(change => ({
20
+ ...change,
21
+ prevValue: VALUE_ON_DEVICE,
22
+ nextValue: VALUE_ON_DEVICE
23
+ }));
24
+ const toWireValue = value => (0, _sharedUi.toWire)(value, VALUE_ON_DEVICE);
39
25
 
40
26
  /**
41
27
  * Sync adapter for the jotai tool, consumed by @buoy-gg/external-sync's
42
- * `useExternalSync` (structurally matches its ToolSyncAdapter interface so
43
- * this package doesn't need a dependency on it).
28
+ * `useExternalSync`.
44
29
  *
45
30
  * Atom changes are captured by watchAtoms(), independent of whether a
46
31
  * dashboard is watching — subscribing here only streams what the store
@@ -52,7 +37,7 @@ function toWireValue(value) {
52
37
  * Dashboards fetch values via `getChangeDetail`. Oversized / unserializable
53
38
  * `atoms[].currentValue` uses the same marker and is fetched via `getAtomValue`.
54
39
  */
55
- const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
40
+ const jotaiSyncAdapter = exports.jotaiSyncAdapter = (0, _sharedUi.createSyncAdapter)({
56
41
  version: 2,
57
42
  getSnapshot: () => ({
58
43
  changes: _jotaiStateStore.jotaiStateStore.getAtomChanges().map(toWireChange),
@@ -61,14 +46,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
61
46
  currentValue: toWireValue(atom.currentValue)
62
47
  }))
63
48
  }),
64
- subscribe: onChange => {
65
- const unsubscribeChanges = _jotaiStateStore.jotaiStateStore.subscribe(onChange);
66
- const unsubscribeAtoms = _jotaiStateStore.jotaiStateStore.subscribeToAtoms(onChange);
67
- return () => {
68
- unsubscribeChanges();
69
- unsubscribeAtoms();
70
- };
71
- },
49
+ subscribe: [onChange => _jotaiStateStore.jotaiStateStore.subscribe(onChange), onChange => _jotaiStateStore.jotaiStateStore.subscribeToAtoms(onChange)],
72
50
  actions: {
73
51
  clearEvents: () => {
74
52
  _jotaiStateStore.jotaiStateStore.clearAtomChanges();
@@ -78,31 +56,10 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
78
56
  * The per-snapshot stream stays value-free; this is the explicit,
79
57
  * size-guarded channel for the detail pane.
80
58
  */
81
- getChangeDetail: params => {
82
- const {
83
- id
84
- } = params ?? {};
85
- if (!id) return {
86
- found: false,
87
- reason: "missing id"
88
- };
89
- const change = _jotaiStateStore.jotaiStateStore.getAtomChangeById(id);
90
- if (!change) return {
91
- found: false,
92
- reason: "unknown id"
93
- };
94
- const cappedNote = {
95
- __buoyTruncated: true,
96
- note: `Exceeds the ${MAX_CHANGE_DETAIL_BYTES / (1024 * 1024)}MB detail limit — inspect it on-device.`
97
- };
98
- const cap = value => (0, _sharedUi.isOverWireBudget)(value, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : value;
99
- return {
100
- found: true,
101
- id,
102
- prevValue: cap(change.prevValue),
103
- nextValue: cap(change.nextValue)
104
- };
105
- },
59
+ getChangeDetail: (0, _sharedUi.detailByIdAction)(id => _jotaiStateStore.jotaiStateStore.getAtomChangeById(id), (change, cap) => ({
60
+ prevValue: cap(change.prevValue),
61
+ nextValue: cap(change.nextValue)
62
+ })),
106
63
  /**
107
64
  * On-demand current value for one atom. Wire-form snapshots replace
108
65
  * oversized / unserializable `currentValue` with VALUE_ON_DEVICE.
@@ -110,7 +67,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
110
67
  getAtomValue: params => {
111
68
  const {
112
69
  label
113
- } = params ?? {};
70
+ } = (0, _sharedUi.readParams)(params);
114
71
  if (!label) return {
115
72
  found: false,
116
73
  reason: "missing label"
@@ -126,10 +83,6 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
126
83
  } catch {
127
84
  currentValue = undefined;
128
85
  }
129
- const cappedNote = {
130
- __buoyTruncated: true,
131
- note: `Exceeds the ${MAX_CHANGE_DETAIL_BYTES / (1024 * 1024)}MB detail limit — inspect it on-device.`
132
- };
133
86
  try {
134
87
  JSON.stringify(currentValue);
135
88
  } catch {
@@ -142,7 +95,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
142
95
  return {
143
96
  found: true,
144
97
  label,
145
- currentValue: (0, _sharedUi.isOverWireBudget)(currentValue, MAX_CHANGE_DETAIL_BYTES) ? cappedNote : currentValue
98
+ currentValue: (0, _sharedUi.capDetail)(currentValue, _sharedUi.WIRE_DETAIL_LIMIT_BYTES)
146
99
  };
147
100
  },
148
101
  /**
@@ -155,7 +108,7 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
155
108
  const {
156
109
  includeValues = false,
157
110
  limit
158
- } = params ?? {};
111
+ } = (0, _sharedUi.readParams)(params);
159
112
  const all = _jotaiStateStore.jotaiStateStore.getAtoms();
160
113
  const capped = typeof limit === "number" && limit > 0 ? all.slice(0, limit) : all;
161
114
  const atoms = capped.map(a => {
@@ -188,9 +141,9 @@ const jotaiSyncAdapter = exports.jotaiSyncAdapter = {
188
141
  const {
189
142
  label,
190
143
  value
191
- } = params ?? {};
144
+ } = (0, _sharedUi.readParams)(params);
192
145
  if (!label) throw new Error("setAtom requires a `label`");
193
146
  _jotaiStateStore.jotaiStateStore.setAtomValue(label, value);
194
147
  }
195
148
  }
196
- };
149
+ });