@buoy-gg/jotai 7.0.56 → 7.0.58
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.
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Inspect registered Jotai atoms and their captured changes, with live values and per-atom history.
|
|
6
6
|
|
|
7
|
+
The Free row cap is used after the filter.
|
|
8
|
+
|
|
7
9
|
<a href="https://buoy.gg/buoy/latest/docs/tools/jotai"><b>Jotai guide</b></a> · <a href="https://buoy.gg">buoy.gg</a> · <a href="https://github.com/Buoy-gg/buoy">All tools</a>
|
|
8
10
|
|
|
9
11
|
[](https://www.npmjs.com/package/@buoy-gg/jotai) [](https://www.npmjs.com/package/@buoy-gg/jotai)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.JotaiModal=JotaiModal;exports.JotaiToolView=JotaiToolView;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _license=require("@buoy-gg/license");var _useJotaiAtomChanges=require("../hooks/useJotaiAtomChanges");var _JotaiAtomChangeItem=require("./JotaiAtomChangeItem");var _JotaiAtomDetailContent=require("./JotaiAtomDetailContent");var _JotaiAtomBrowser=require("./JotaiAtomBrowser");var _JotaiAtomValueDetailContent=require("./JotaiAtomValueDetailContent");var _JotaiEventFilterView=require("./JotaiEventFilterView");var _testIDs=require("../utils/testIDs");var _jsxRuntime=require("react/jsx-runtime");function EventsEmptyState({isEnabled:u,searchText:S,totalChanges:y}){const A=(0,_sharedUi.resolveListEmptyState)({subject:"changes",search:S,total:y,capturing:u,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{...A,testID:`${_testIDs.JOTAI_TEST_ID}-empty`})}function JotaiModal({visible:u,onClose:S,onBack:y,onMinimize:A,enableSharedModalDimensions:Q=false,inline:X=false,initialTab:Y,initialSelectedChangeId:h,initialDetailView:Z,onChangeSelect:j,onAtomExpand:B}){const ve=(0,_license.useIsPro)();const I=(0,_sharedUi.useLimit)("jotai.changes");const[ee,M]=(0,_react.useState)(false);const[s,te]=(0,_react.useState)(Y??"atoms");const[a,_]=(0,_react.useState)(null);const[T,H]=(0,_react.useState)(null);const[D,v]=(0,_react.useState)(false);const[l,V]=(0,_react.useState)(new Set);const{atomChanges:P,filteredChanges:E,stats:oe,filter:Ee,setFilter:b,atoms:x,clearChanges:ae,isEnabled:C,toggleCapture:ne}=(0,_useJotaiAtomChanges.useJotaiAtomChanges)();const r=(0,_react.useMemo)(()=>{if(l.size===0)return E;return E.filter(e=>!Array.from(l).some(t=>e.atomLabel.toLowerCase().includes(t.toLowerCase())))},[E,l]);const g=(0,_react.useMemo)(()=>{if(l.size===0)return x;return x.filter(e=>!Array.from(l).some(t=>e.label.toLowerCase().includes(t.toLowerCase())))},[x,l]);const re=(0,_react.useMemo)(()=>{if(!a)return 0;return P.filter(e=>e.atomLabel===a).length},[P,a]);const f=(0,_react.useMemo)(()=>r.slice(0,I),[r,I]);const w=(0,_react.useMemo)(()=>Math.max(0,r.length-I),[r.length,I]);const se=w>0;const o=(0,_react.useMemo)(()=>{if(a){return f.filter(e=>e.atomLabel===a)}return f},[f,a]);const[k,c]=(0,_react.useState)(null);const d=(0,_react.useMemo)(()=>{if(k===null)return null;const e=o.findIndex(t=>t.id===k);return e>=0?e:null},[k,o]);const n=d!==null?o[d]:null;const $=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!j)return;const e=n?.id??null;if(e===null||e===$.current)return;$.current=e;j(n)},[n,j]);const O=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!h)return;if(O.current===h)return;const e=o.some(t=>t.id===h);if(!e)return;O.current=h;c(h)},[h,o]);const[i,J]=(0,_react.useState)("");const[le,p]=(0,_react.useState)(false);const we=(0,_react.useRef)(null);const ie=(0,_react.useRef)(null);const ce=(0,_react.useCallback)(e=>{},[]);const de=e=>{J(e);if(s==="events"){b(t=>({...t,searchText:e}))}};const ue=(0,_react.useCallback)(()=>{J("");b(e=>({...e,searchText:""}));p(false)},[b]);const L=(0,_react.useCallback)(e=>{c(e.id)},[]);const he=(0,_react.useCallback)(()=>{M(true)},[]);const ge=(0,_react.useCallback)(()=>{c(null)},[]);const R=(0,_react.useCallback)(e=>{const t=o[e];if(t)c(t.id)},[o]);const me=(0,_react.useCallback)(e=>{_(e);c(null)},[]);const Te=(0,_react.useCallback)(()=>{_(null);c(null)},[]);const be=(0,_react.useCallback)(e=>{H(e);B?.(e)},[B]);const xe=(0,_react.useCallback)(()=>{H(null)},[]);const fe=(0,_react.useCallback)(()=>{return g.reduce((e,t)=>{try{const m=t.getValue();e[t.label]=(0,_sharedUi.truncatePayload)(m)}catch{e[t.label]=null}return e},{})},[g]);const ye=(0,_react.useCallback)(()=>{return r.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:(0,_sharedUi.truncatePayload)(e.prevValue),nextValue:(0,_sharedUi.truncatePayload)(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[r]);const Ie=(0,_react.useCallback)(()=>{return o.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:(0,_sharedUi.truncatePayload)(e.prevValue),nextValue:(0,_sharedUi.truncatePayload)(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[o]);const Ce=(0,_react.useCallback)(e=>{V(t=>{const m=new Set(t);if(m.has(e))m.delete(e);else m.add(e);return m})},[]);const pe=(0,_react.useCallback)(e=>{V(t=>new Set([...t,e]))},[]);const Se=(0,_react.useCallback)(e=>{te(e);_(null);c(null);v(false);if(i){J("");b(t=>({...t,searchText:""}))}p(false)},[i,b]);const F=(0,_react.useCallback)(e=>e.id,[]);const z=(0,_react.useMemo)(()=>(0,_testIDs.buildChangeRowTestIDs)(o),[o]);const N=(0,_react.useCallback)(({item:e})=>(0,_jsxRuntime.jsx)(_JotaiAtomChangeItem.JotaiAtomChangeItem,{change:e,onPress:L,testID:z.get(e.id)}),[L,z]);const q=l.size>0;const W=()=>{if(D){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:()=>v(false)}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:"Filters",centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-filters-title`})]})}if(n){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:ge}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:`${n.atomLabel}/${n.category}`,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-detail-title`})]})}if(a){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:Te}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:`${a} History`,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-history-title`}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Actions,{children:(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:Ie,disabled:o.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`})})]})}if(T){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:xe}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:T,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-atom-detail-title`})]})}return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[y&&(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:y}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:"",children:le?(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Search,{value:i,onChangeText:de,onCancel:ue,placeholder:s==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${_testIDs.JOTAI_TEST_ID}-search-field`,containerTestID:`${_testIDs.JOTAI_TEST_ID}-search`,clearTestID:`${_testIDs.JOTAI_TEST_ID}-search-clear`,onBlur:()=>{if(i.length===0)p(false)}}):(0,_jsxRuntime.jsx)(_sharedUi.TabSelector,{tabs:[{key:"atoms",label:`Atoms${g.length>0?` (${g.length})`:""}`},{key:"events",label:`Events${r.length>0?` (${r.length})`:""}`}],activeTab:s,onTabChange:Se,testIDPrefix:`${_testIDs.JOTAI_TEST_ID}-tab`})}),(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader.Actions,{children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{onPress:()=>p(true),style:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:(0,_jsxRuntime.jsx)(_sharedUi.Search,{size:14,color:_sharedUi.night.color.textSecondary})}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{onPress:()=>v(true),style:[styles.headerActionButton,q&&styles.headerActionButtonActive],testID:`${_testIDs.JOTAI_TEST_ID}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:(0,_jsxRuntime.jsx)(_sharedUi.Filter,{size:14,color:q?_sharedUi.night.color.accent:_sharedUi.night.color.textSecondary})}),s==="atoms"&&(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:fe,disabled:g.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`}),s==="events"&&(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:ye,disabled:r.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`}),(0,_jsxRuntime.jsx)(_sharedUi.PowerToggleButton,{isEnabled:C,onToggle:ne,accessibilityLabel:"Toggle Jotai atom capture",testID:`${_testIDs.JOTAI_TEST_ID}-power`}),(0,_jsxRuntime.jsx)(_sharedUi.ToolbarClearButton,{onPress:ae,disabled:r.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-clear`})]})]})]})};const Ae=()=>{if(D){return(0,_jsxRuntime.jsx)(_JotaiEventFilterView.JotaiEventFilterView,{ignoredPatterns:l,onTogglePattern:Ce,onAddPattern:pe,atoms:x})}if(n&&d!==null){return(0,_jsxRuntime.jsx)(_JotaiAtomDetailContent.JotaiAtomDetailContent,{change:n,changes:o,selectedIndex:d,onIndexChange:R,disableInternalFooter:true,initialView:Z})}if(a){return o.length>0?(0,_jsxRuntime.jsx)(_reactNative.FlatList,{testID:`${_testIDs.JOTAI_TEST_ID}-history-list`,data:o,renderItem:N,keyExtractor:F,contentContainerStyle:styles.listContent,showsVerticalScrollIndicator:true,..._sharedUi.EVENT_LIST_PRESET}):(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{testID:`${_testIDs.JOTAI_TEST_ID}-history-empty`,...(0,_sharedUi.resolveListEmptyState)({subject:"changes",search:i,total:i.trim()?re:0,capturing:C,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${a} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${a}.`}})})}if(T){const e=x.find(t=>t.label===T)??null;return e?(0,_jsxRuntime.jsx)(_JotaiAtomValueDetailContent.JotaiAtomValueDetailContent,{atom:e,onViewHistory:me}):(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{testID:`${_testIDs.JOTAI_TEST_ID}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${T} is not in the registry any more.`})}if(s==="atoms"){return(0,_jsxRuntime.jsx)(_JotaiAtomBrowser.JotaiAtomBrowser,{atoms:g,searchQuery:i,onOpenAtom:be})}return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[!C&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.disabledBanner,testID:`${_testIDs.JOTAI_TEST_ID}-banner-disabled`,children:[(0,_jsxRuntime.jsx)(_sharedUi.Power,{size:14,color:_sharedUi.night.color.warning}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.disabledText,children:"Atom capture is disabled"})]}),se&&(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{style:styles.lockedBanner,onPress:he,activeOpacity:.8,testID:`${_testIDs.JOTAI_TEST_ID}-locked`,accessibilityRole:"button",children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.lockedText,testID:`${_testIDs.JOTAI_TEST_ID}-locked-text`,children:[w," older"," ",w===1?"change":"changes"," locked"]}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.upgradeBadge,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.upgradeBadgeText,children:"UPGRADE"})})]}),f.length>0?(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:ie,testID:`${_testIDs.JOTAI_TEST_ID}-list`,data:f,renderItem:N,keyExtractor:F,contentContainerStyle:styles.listContent,showsVerticalScrollIndicator:true,..._sharedUi.EVENT_LIST_PRESET}):(0,_jsxRuntime.jsx)(EventsEmptyState,{isEnabled:C,searchText:i,totalChanges:oe.totalChanges})]})};const je=Q?_sharedUi.devToolsStorageKeys.modal.root():"buoy-jotai-modal";if(!u)return null;const K=n&&d!==null?(0,_jsxRuntime.jsx)(_JotaiAtomDetailContent.JotaiAtomDetailFooter,{change:n,changes:o,selectedIndex:d,onIndexChange:R}):null;const _e=n&&o.length>1?68:0;const De=!D&&!(n&&d!==null)&&(a!=null||s==="events"||s==="atoms");const U=(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.container,children:Ae()});const G=(0,_jsxRuntime.jsx)(_sharedUi.ProUpgradeModal,{visible:ee,onClose:()=>M(false),featureName:"Full Atom History"});if(X){return(0,_jsxRuntime.jsxs)(_sharedUi.TickProvider,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.inlineRoot,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.inlineHeader,..._sharedUi.windowDragProps,children:W()}),U,K]}),G]})}return(0,_jsxRuntime.jsxs)(_sharedUi.TickProvider,{children:[(0,_jsxRuntime.jsx)(_sharedUi.JsModal,{visible:u,onClose:S,onMinimize:A,persistenceKey:je,header:{showToggleButton:true,customContent:W()},onModeChange:ce,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:De,styles:{},footer:K,footerHeight:_e,children:U}),G]})}function JotaiToolView(u={}){return(0,_jsxRuntime.jsx)(JotaiModal,{...u,inline:true,visible:true,onClose:()=>{}})}const styles=_reactNative.StyleSheet.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:_sharedUi.macOSColors.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:_sharedUi.night.color.buttonSurface,borderWidth:1,borderColor:_sharedUi.night.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:_sharedUi.night.color.accentSoft,borderColor:_sharedUi.night.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:_sharedUi.night.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.warning+"20"},disabledText:{color:_sharedUi.night.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:_sharedUi.night.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:_sharedUi.night.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:_sharedUi.night.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.accentBorder},lockedText:{color:_sharedUi.night.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:_sharedUi.night.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:_sharedUi.night.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.JotaiModal=JotaiModal;exports.JotaiToolView=JotaiToolView;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _license=require("@buoy-gg/license");var _useJotaiAtomChanges=require("../hooks/useJotaiAtomChanges");var _JotaiAtomChangeItem=require("./JotaiAtomChangeItem");var _JotaiAtomDetailContent=require("./JotaiAtomDetailContent");var _JotaiAtomBrowser=require("./JotaiAtomBrowser");var _JotaiAtomValueDetailContent=require("./JotaiAtomValueDetailContent");var _JotaiEventFilterView=require("./JotaiEventFilterView");var _testIDs=require("../utils/testIDs");var _jsxRuntime=require("react/jsx-runtime");function EventsEmptyState({isEnabled:u,searchText:S,totalChanges:f}){const A=(0,_sharedUi.resolveListEmptyState)({subject:"changes",search:S,total:f,capturing:u,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{...A,testID:`${_testIDs.JOTAI_TEST_ID}-empty`})}function JotaiModal({visible:u,onClose:S,onBack:f,onMinimize:A,enableSharedModalDimensions:X=false,inline:Y=false,initialTab:Z,initialSelectedChangeId:h,initialDetailView:ee,onChangeSelect:j,onAtomExpand:M}){const Ee=(0,_license.useIsPro)();const y=(0,_sharedUi.useLimit)("jotai.changes");const[te,H]=(0,_react.useState)(false);const[s,oe]=(0,_react.useState)(Z??"atoms");const[a,_]=(0,_react.useState)(null);const[T,V]=(0,_react.useState)(null);const[D,v]=(0,_react.useState)(false);const[l,P]=(0,_react.useState)(new Set);const{atomChanges:$,filteredChanges:E,stats:ae,filter:we,setFilter:b,atoms:x,clearChanges:ne,isEnabled:I,toggleCapture:re}=(0,_useJotaiAtomChanges.useJotaiAtomChanges)();const r=(0,_react.useMemo)(()=>{if(l.size===0)return E;return E.filter(e=>!Array.from(l).some(t=>e.atomLabel.toLowerCase().includes(t.toLowerCase())))},[E,l]);const g=(0,_react.useMemo)(()=>{if(l.size===0)return x;return x.filter(e=>!Array.from(l).some(t=>e.label.toLowerCase().includes(t.toLowerCase())))},[x,l]);const se=(0,_react.useMemo)(()=>{if(!a)return 0;return $.filter(e=>e.atomLabel===a).length},[$,a]);const C=(0,_react.useMemo)(()=>a?r.filter(e=>e.atomLabel===a):r,[r,a]);const w=(0,_react.useMemo)(()=>C.slice(0,y),[C,y]);const k=(0,_react.useMemo)(()=>Math.max(0,C.length-y),[C.length,y]);const le=k>0;const o=w;const[J,c]=(0,_react.useState)(null);const d=(0,_react.useMemo)(()=>{if(J===null)return null;const e=o.findIndex(t=>t.id===J);return e>=0?e:null},[J,o]);const n=d!==null?o[d]:null;const O=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!j)return;const e=n?.id??null;if(e===null||e===O.current)return;O.current=e;j(n)},[n,j]);const L=(0,_react.useRef)(null);(0,_react.useEffect)(()=>{if(!h)return;if(L.current===h)return;const e=o.some(t=>t.id===h);if(!e)return;L.current=h;c(h)},[h,o]);const[i,B]=(0,_react.useState)("");const[ie,p]=(0,_react.useState)(false);const ke=(0,_react.useRef)(null);const ce=(0,_react.useRef)(null);const de=(0,_react.useCallback)(e=>{},[]);const ue=e=>{B(e);if(s==="events"){b(t=>({...t,searchText:e}))}};const he=(0,_react.useCallback)(()=>{B("");b(e=>({...e,searchText:""}));p(false)},[b]);const R=(0,_react.useCallback)(e=>{c(e.id)},[]);const ge=(0,_react.useCallback)(()=>{H(true)},[]);const me=(0,_react.useCallback)(()=>{c(null)},[]);const F=(0,_react.useCallback)(e=>{const t=o[e];if(t)c(t.id)},[o]);const Te=(0,_react.useCallback)(e=>{_(e);c(null)},[]);const be=(0,_react.useCallback)(()=>{_(null);c(null)},[]);const xe=(0,_react.useCallback)(e=>{V(e);M?.(e)},[M]);const fe=(0,_react.useCallback)(()=>{V(null)},[]);const ye=(0,_react.useCallback)(()=>{return g.reduce((e,t)=>{try{const m=t.getValue();e[t.label]=(0,_sharedUi.truncatePayload)(m)}catch{e[t.label]=null}return e},{})},[g]);const Ie=(0,_react.useCallback)(()=>{return r.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:(0,_sharedUi.truncatePayload)(e.prevValue),nextValue:(0,_sharedUi.truncatePayload)(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[r]);const Ce=(0,_react.useCallback)(()=>{return o.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:(0,_sharedUi.truncatePayload)(e.prevValue),nextValue:(0,_sharedUi.truncatePayload)(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[o]);const pe=(0,_react.useCallback)(e=>{P(t=>{const m=new Set(t);if(m.has(e))m.delete(e);else m.add(e);return m})},[]);const Se=(0,_react.useCallback)(e=>{P(t=>new Set([...t,e]))},[]);const Ae=(0,_react.useCallback)(e=>{oe(e);_(null);c(null);v(false);if(i){B("");b(t=>({...t,searchText:""}))}p(false)},[i,b]);const z=(0,_react.useCallback)(e=>e.id,[]);const N=(0,_react.useMemo)(()=>(0,_testIDs.buildChangeRowTestIDs)(o),[o]);const q=(0,_react.useCallback)(({item:e})=>(0,_jsxRuntime.jsx)(_JotaiAtomChangeItem.JotaiAtomChangeItem,{change:e,onPress:R,testID:N.get(e.id)}),[R,N]);const W=l.size>0;const K=()=>{if(D){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:()=>v(false)}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:"Filters",centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-filters-title`})]})}if(n){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:me}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:`${n.atomLabel}/${n.category}`,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-detail-title`})]})}if(a){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:be}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:`${a} History`,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-history-title`}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Actions,{children:(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:Ce,disabled:o.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`})})]})}if(T){return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:fe}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:T,centered:true,testID:`${_testIDs.JOTAI_TEST_ID}-atom-detail-title`})]})}return(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader,{children:[f&&(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Navigation,{onBack:f}),(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Content,{title:"",children:ie?(0,_jsxRuntime.jsx)(_sharedUi.ModalHeader.Search,{value:i,onChangeText:ue,onCancel:he,placeholder:s==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${_testIDs.JOTAI_TEST_ID}-search-field`,containerTestID:`${_testIDs.JOTAI_TEST_ID}-search`,clearTestID:`${_testIDs.JOTAI_TEST_ID}-search-clear`,onBlur:()=>{if(i.length===0)p(false)}}):(0,_jsxRuntime.jsx)(_sharedUi.TabSelector,{tabs:[{key:"atoms",label:`Atoms${g.length>0?` (${g.length})`:""}`},{key:"events",label:`Events${r.length>0?` (${r.length})`:""}`}],activeTab:s,onTabChange:Ae,testIDPrefix:`${_testIDs.JOTAI_TEST_ID}-tab`})}),(0,_jsxRuntime.jsxs)(_sharedUi.ModalHeader.Actions,{children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{onPress:()=>p(true),style:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:(0,_jsxRuntime.jsx)(_sharedUi.Search,{size:14,color:_sharedUi.night.color.textSecondary})}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{onPress:()=>v(true),style:[styles.headerActionButton,W&&styles.headerActionButtonActive],testID:`${_testIDs.JOTAI_TEST_ID}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:(0,_jsxRuntime.jsx)(_sharedUi.Filter,{size:14,color:W?_sharedUi.night.color.accent:_sharedUi.night.color.textSecondary})}),s==="atoms"&&(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:ye,disabled:g.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`}),s==="events"&&(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[(0,_jsxRuntime.jsx)(_sharedUi.ToolbarCopyButton,{value:Ie,disabled:r.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-copy`}),(0,_jsxRuntime.jsx)(_sharedUi.PowerToggleButton,{isEnabled:I,onToggle:re,accessibilityLabel:"Toggle Jotai atom capture",testID:`${_testIDs.JOTAI_TEST_ID}-power`}),(0,_jsxRuntime.jsx)(_sharedUi.ToolbarClearButton,{onPress:ne,disabled:r.length===0,buttonStyle:styles.headerActionButton,testID:`${_testIDs.JOTAI_TEST_ID}-clear`})]})]})]})};const je=()=>{if(D){return(0,_jsxRuntime.jsx)(_JotaiEventFilterView.JotaiEventFilterView,{ignoredPatterns:l,onTogglePattern:pe,onAddPattern:Se,atoms:x})}if(n&&d!==null){return(0,_jsxRuntime.jsx)(_JotaiAtomDetailContent.JotaiAtomDetailContent,{change:n,changes:o,selectedIndex:d,onIndexChange:F,disableInternalFooter:true,initialView:ee})}if(a){return o.length>0?(0,_jsxRuntime.jsx)(_reactNative.FlatList,{testID:`${_testIDs.JOTAI_TEST_ID}-history-list`,data:o,renderItem:q,keyExtractor:z,contentContainerStyle:styles.listContent,showsVerticalScrollIndicator:true,..._sharedUi.EVENT_LIST_PRESET}):(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{testID:`${_testIDs.JOTAI_TEST_ID}-history-empty`,...(0,_sharedUi.resolveListEmptyState)({subject:"changes",search:i,total:i.trim()?se:0,capturing:I,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${a} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${a}.`}})})}if(T){const e=x.find(t=>t.label===T)??null;return e?(0,_jsxRuntime.jsx)(_JotaiAtomValueDetailContent.JotaiAtomValueDetailContent,{atom:e,onViewHistory:Te}):(0,_jsxRuntime.jsx)(_sharedUi.ToolEmptyState,{testID:`${_testIDs.JOTAI_TEST_ID}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${T} is not in the registry any more.`})}if(s==="atoms"){return(0,_jsxRuntime.jsx)(_JotaiAtomBrowser.JotaiAtomBrowser,{atoms:g,searchQuery:i,onOpenAtom:xe})}return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[!I&&(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.disabledBanner,testID:`${_testIDs.JOTAI_TEST_ID}-banner-disabled`,children:[(0,_jsxRuntime.jsx)(_sharedUi.Power,{size:14,color:_sharedUi.night.color.warning}),(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.disabledText,children:"Atom capture is disabled"})]}),le&&(0,_jsxRuntime.jsxs)(_reactNative.TouchableOpacity,{style:styles.lockedBanner,onPress:ge,activeOpacity:.8,testID:`${_testIDs.JOTAI_TEST_ID}-locked`,accessibilityRole:"button",children:[(0,_jsxRuntime.jsxs)(_reactNative.Text,{style:styles.lockedText,testID:`${_testIDs.JOTAI_TEST_ID}-locked-text`,children:[k," older"," ",k===1?"change":"changes"," locked"]}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.upgradeBadge,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.upgradeBadgeText,children:"UPGRADE"})})]}),w.length>0?(0,_jsxRuntime.jsx)(_reactNative.FlatList,{ref:ce,testID:`${_testIDs.JOTAI_TEST_ID}-list`,data:w,renderItem:q,keyExtractor:z,contentContainerStyle:styles.listContent,showsVerticalScrollIndicator:true,..._sharedUi.EVENT_LIST_PRESET}):(0,_jsxRuntime.jsx)(EventsEmptyState,{isEnabled:I,searchText:i,totalChanges:ae.totalChanges})]})};const _e=X?_sharedUi.devToolsStorageKeys.modal.root():"buoy-jotai-modal";if(!u)return null;const U=n&&d!==null?(0,_jsxRuntime.jsx)(_JotaiAtomDetailContent.JotaiAtomDetailFooter,{change:n,changes:o,selectedIndex:d,onIndexChange:F}):null;const De=n&&o.length>1?68:0;const ve=!D&&!(n&&d!==null)&&(a!=null||s==="events"||s==="atoms");const G=(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.container,children:je()});const Q=(0,_jsxRuntime.jsx)(_sharedUi.ProUpgradeModal,{visible:te,onClose:()=>H(false),featureName:"Full Atom History"});if(Y){return(0,_jsxRuntime.jsxs)(_sharedUi.TickProvider,{children:[(0,_jsxRuntime.jsxs)(_reactNative.View,{style:styles.inlineRoot,children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.inlineHeader,..._sharedUi.windowDragProps,children:K()}),G,U]}),Q]})}return(0,_jsxRuntime.jsxs)(_sharedUi.TickProvider,{children:[(0,_jsxRuntime.jsx)(_sharedUi.JsModal,{visible:u,onClose:S,onMinimize:A,persistenceKey:_e,header:{showToggleButton:true,customContent:K()},onModeChange:de,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:ve,styles:{},footer:U,footerHeight:De,children:G}),Q]})}function JotaiToolView(u={}){return(0,_jsxRuntime.jsx)(JotaiModal,{...u,inline:true,visible:true,onClose:()=>{}})}const styles=_reactNative.StyleSheet.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:_sharedUi.macOSColors.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:_sharedUi.night.color.buttonSurface,borderWidth:1,borderColor:_sharedUi.night.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:_sharedUi.night.color.accentSoft,borderColor:_sharedUi.night.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:_sharedUi.night.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.warning+"20"},disabledText:{color:_sharedUi.night.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:_sharedUi.night.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:_sharedUi.night.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:_sharedUi.night.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:_sharedUi.night.color.accentBorder},lockedText:{color:_sharedUi.night.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:_sharedUi.night.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:_sharedUi.night.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useState as g,useMemo as p,useRef as E,useCallback as r,useEffect as he}from"react";import{View as D,Text as K,StyleSheet as qe,FlatList as ge,TouchableOpacity as O}from"react-native";import{JsModal as Xe,ModalHeader as a,TabSelector as Ye,macOSColors as Ze,night as l,Search as et,Filter as tt,Power as ot,ToolEmptyState as U,resolveListEmptyState as me,devToolsStorageKeys as nt,ProUpgradeModal as rt,PowerToggleButton as at,ToolbarCopyButton as G,ToolbarClearButton as lt,truncatePayload as $,TickProvider as fe,useLimit as st,windowDragProps as it,EVENT_LIST_PRESET as be}from"@buoy-gg/shared-ui";import{useIsPro as ct}from"@buoy-gg/license";import{useJotaiAtomChanges as dt}from"../hooks/useJotaiAtomChanges";import{JotaiAtomChangeItem as ut}from"./JotaiAtomChangeItem";import{JotaiAtomDetailContent as ht,JotaiAtomDetailFooter as gt}from"./JotaiAtomDetailContent";import{JotaiAtomBrowser as mt}from"./JotaiAtomBrowser";import{JotaiAtomValueDetailContent as ft}from"./JotaiAtomValueDetailContent";import{JotaiEventFilterView as bt}from"./JotaiEventFilterView";import{JOTAI_TEST_ID as n,buildChangeRowTestIDs as pt}from"../utils/testIDs";import{jsx as t,jsxs as c,Fragment as pe}from"react/jsx-runtime";function yt({isEnabled:S,searchText:H,totalChanges:k}){const z=me({subject:"changes",search:H,total:k,capturing:S,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return t(U,{...z,testID:`${n}-empty`})}export function JotaiModal({visible:S,onClose:H,onBack:k,onMinimize:z,enableSharedModalDimensions:ye=false,inline:Ce=false,initialTab:Se,initialSelectedChangeId:T,initialDetailView:Te,onChangeSelect:F,onAtomExpand:Q}){const Ct=ct();const P=st("jotai.changes");const[xe,q]=g(false);const[m,Ie]=g(Se??"atoms");const[d,R]=g(null);const[A,X]=g(null);const[J,M]=g(false);const[f,Y]=g(new Set);const{atomChanges:Z,filteredChanges:N,stats:Ae,filter:St,setFilter:w,atoms:v,clearChanges:we,isEnabled:V,toggleCapture:ve}=dt();const h=p(()=>{if(f.size===0)return N;return N.filter(e=>!Array.from(f).some(o=>e.atomLabel.toLowerCase().includes(o.toLowerCase())))},[N,f]);const x=p(()=>{if(f.size===0)return v;return v.filter(e=>!Array.from(f).some(o=>e.label.toLowerCase().includes(o.toLowerCase())))},[v,f]);const Be=p(()=>{if(!d)return 0;return Z.filter(e=>e.atomLabel===d).length},[Z,d]);const B=p(()=>h.slice(0,P),[h,P]);const j=p(()=>Math.max(0,h.length-P),[h.length,P]);const De=j>0;const i=p(()=>{if(d){return B.filter(e=>e.atomLabel===d)}return B},[B,d]);const[W,y]=g(null);const C=p(()=>{if(W===null)return null;const e=i.findIndex(o=>o.id===W);return e>=0?e:null},[W,i]);const u=C!==null?i[C]:null;const ee=E(null);he(()=>{if(!F)return;const e=u?.id??null;if(e===null||e===ee.current)return;ee.current=e;F(u)},[u,F]);const te=E(null);he(()=>{if(!T)return;if(te.current===T)return;const e=i.some(o=>o.id===T);if(!e)return;te.current=T;y(T)},[T,i]);const[b,_]=g("");const[$e,L]=g(false);const Tt=E(null);const ke=E(null);const Pe=r(e=>{},[]);const Ve=e=>{_(e);if(m==="events"){w(o=>({...o,searchText:e}))}};const Le=r(()=>{_("");w(e=>({...e,searchText:""}));L(false)},[w]);const oe=r(e=>{y(e.id)},[]);const Ee=r(()=>{q(true)},[]);const He=r(()=>{y(null)},[]);const ne=r(e=>{const o=i[e];if(o)y(o.id)},[i]);const ze=r(e=>{R(e);y(null)},[]);const Fe=r(()=>{R(null);y(null)},[]);const Re=r(e=>{X(e);Q?.(e)},[Q]);const Je=r(()=>{X(null)},[]);const Me=r(()=>{return x.reduce((e,o)=>{try{const I=o.getValue();e[o.label]=$(I)}catch{e[o.label]=null}return e},{})},[x]);const Ne=r(()=>{return h.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:$(e.prevValue),nextValue:$(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[h]);const je=r(()=>{return i.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:$(e.prevValue),nextValue:$(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[i]);const We=r(e=>{Y(o=>{const I=new Set(o);if(I.has(e))I.delete(e);else I.add(e);return I})},[]);const _e=r(e=>{Y(o=>new Set([...o,e]))},[]);const Ke=r(e=>{Ie(e);R(null);y(null);M(false);if(b){_("");w(o=>({...o,searchText:""}))}L(false)},[b,w]);const re=r(e=>e.id,[]);const ae=p(()=>pt(i),[i]);const le=r(({item:e})=>t(ut,{change:e,onPress:oe,testID:ae.get(e.id)}),[oe,ae]);const se=f.size>0;const ie=()=>{if(J){return c(a,{children:[t(a.Navigation,{onBack:()=>M(false)}),t(a.Content,{title:"Filters",centered:true,testID:`${n}-filters-title`})]})}if(u){return c(a,{children:[t(a.Navigation,{onBack:He}),t(a.Content,{title:`${u.atomLabel}/${u.category}`,centered:true,testID:`${n}-detail-title`})]})}if(d){return c(a,{children:[t(a.Navigation,{onBack:Fe}),t(a.Content,{title:`${d} History`,centered:true,testID:`${n}-history-title`}),t(a.Actions,{children:t(G,{value:je,disabled:i.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`})})]})}if(A){return c(a,{children:[t(a.Navigation,{onBack:Je}),t(a.Content,{title:A,centered:true,testID:`${n}-atom-detail-title`})]})}return c(a,{children:[k&&t(a.Navigation,{onBack:k}),t(a.Content,{title:"",children:$e?t(a.Search,{value:b,onChangeText:Ve,onCancel:Le,placeholder:m==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${n}-search-field`,containerTestID:`${n}-search`,clearTestID:`${n}-search-clear`,onBlur:()=>{if(b.length===0)L(false)}}):t(Ye,{tabs:[{key:"atoms",label:`Atoms${x.length>0?` (${x.length})`:""}`},{key:"events",label:`Events${h.length>0?` (${h.length})`:""}`}],activeTab:m,onTabChange:Ke,testIDPrefix:`${n}-tab`})}),c(a.Actions,{children:[t(O,{onPress:()=>L(true),style:s.headerActionButton,testID:`${n}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:t(et,{size:14,color:l.color.textSecondary})}),t(O,{onPress:()=>M(true),style:[s.headerActionButton,se&&s.headerActionButtonActive],testID:`${n}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:t(tt,{size:14,color:se?l.color.accent:l.color.textSecondary})}),m==="atoms"&&t(G,{value:Me,disabled:x.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`}),m==="events"&&c(pe,{children:[t(G,{value:Ne,disabled:h.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`}),t(at,{isEnabled:V,onToggle:ve,accessibilityLabel:"Toggle Jotai atom capture",testID:`${n}-power`}),t(lt,{onPress:we,disabled:h.length===0,buttonStyle:s.headerActionButton,testID:`${n}-clear`})]})]})]})};const Oe=()=>{if(J){return t(bt,{ignoredPatterns:f,onTogglePattern:We,onAddPattern:_e,atoms:v})}if(u&&C!==null){return t(ht,{change:u,changes:i,selectedIndex:C,onIndexChange:ne,disableInternalFooter:true,initialView:Te})}if(d){return i.length>0?t(ge,{testID:`${n}-history-list`,data:i,renderItem:le,keyExtractor:re,contentContainerStyle:s.listContent,showsVerticalScrollIndicator:true,...be}):t(U,{testID:`${n}-history-empty`,...me({subject:"changes",search:b,total:b.trim()?Be:0,capturing:V,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${d} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${d}.`}})})}if(A){const e=v.find(o=>o.label===A)??null;return e?t(ft,{atom:e,onViewHistory:ze}):t(U,{testID:`${n}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${A} is not in the registry any more.`})}if(m==="atoms"){return t(mt,{atoms:x,searchQuery:b,onOpenAtom:Re})}return c(pe,{children:[!V&&c(D,{style:s.disabledBanner,testID:`${n}-banner-disabled`,children:[t(ot,{size:14,color:l.color.warning}),t(K,{style:s.disabledText,children:"Atom capture is disabled"})]}),De&&c(O,{style:s.lockedBanner,onPress:Ee,activeOpacity:.8,testID:`${n}-locked`,accessibilityRole:"button",children:[c(K,{style:s.lockedText,testID:`${n}-locked-text`,children:[j," older"," ",j===1?"change":"changes"," locked"]}),t(D,{style:s.upgradeBadge,children:t(K,{style:s.upgradeBadgeText,children:"UPGRADE"})})]}),B.length>0?t(ge,{ref:ke,testID:`${n}-list`,data:B,renderItem:le,keyExtractor:re,contentContainerStyle:s.listContent,showsVerticalScrollIndicator:true,...be}):t(yt,{isEnabled:V,searchText:b,totalChanges:Ae.totalChanges})]})};const Ue=ye?nt.modal.root():"buoy-jotai-modal";if(!S)return null;const ce=u&&C!==null?t(gt,{change:u,changes:i,selectedIndex:C,onIndexChange:ne}):null;const Ge=u&&i.length>1?68:0;const Qe=!J&&!(u&&C!==null)&&(d!=null||m==="events"||m==="atoms");const de=t(D,{style:s.container,children:Oe()});const ue=t(rt,{visible:xe,onClose:()=>q(false),featureName:"Full Atom History"});if(Ce){return c(fe,{children:[c(D,{style:s.inlineRoot,children:[t(D,{style:s.inlineHeader,...it,children:ie()}),de,ce]}),ue]})}return c(fe,{children:[t(Xe,{visible:S,onClose:H,onMinimize:z,persistenceKey:Ue,header:{showToggleButton:true,customContent:ie()},onModeChange:Pe,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:Qe,styles:{},footer:ce,footerHeight:Ge,children:de}),ue]})}export function JotaiToolView(S={}){return t(JotaiModal,{...S,inline:true,visible:true,onClose:()=>{}})}const s=qe.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:Ze.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:l.color.buttonSurface,borderWidth:1,borderColor:l.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:l.color.accentSoft,borderColor:l.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:l.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:l.color.warning+"20"},disabledText:{color:l.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:l.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:l.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:l.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:l.color.accentBorder},lockedText:{color:l.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:l.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:l.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});
|
|
1
|
+
"use strict";import{useState as g,useMemo as p,useRef as E,useCallback as r,useEffect as ge}from"react";import{View as B,Text as O,StyleSheet as Xe,FlatList as me,TouchableOpacity as U}from"react-native";import{JsModal as Ye,ModalHeader as a,TabSelector as Ze,macOSColors as et,night as l,Search as tt,Filter as ot,Power as nt,ToolEmptyState as G,resolveListEmptyState as fe,devToolsStorageKeys as rt,ProUpgradeModal as at,PowerToggleButton as lt,ToolbarCopyButton as Q,ToolbarClearButton as st,truncatePayload as D,TickProvider as be,useLimit as it,windowDragProps as ct,EVENT_LIST_PRESET as pe}from"@buoy-gg/shared-ui";import{useIsPro as dt}from"@buoy-gg/license";import{useJotaiAtomChanges as ut}from"../hooks/useJotaiAtomChanges";import{JotaiAtomChangeItem as ht}from"./JotaiAtomChangeItem";import{JotaiAtomDetailContent as gt,JotaiAtomDetailFooter as mt}from"./JotaiAtomDetailContent";import{JotaiAtomBrowser as ft}from"./JotaiAtomBrowser";import{JotaiAtomValueDetailContent as bt}from"./JotaiAtomValueDetailContent";import{JotaiEventFilterView as pt}from"./JotaiEventFilterView";import{JOTAI_TEST_ID as n,buildChangeRowTestIDs as yt}from"../utils/testIDs";import{jsx as t,jsxs as c,Fragment as ye}from"react/jsx-runtime";function Ct({isEnabled:S,searchText:H,totalChanges:$}){const z=fe({subject:"changes",search:H,total:$,capturing:S,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return t(G,{...z,testID:`${n}-empty`})}export function JotaiModal({visible:S,onClose:H,onBack:$,onMinimize:z,enableSharedModalDimensions:Ce=false,inline:Se=false,initialTab:Te,initialSelectedChangeId:T,initialDetailView:xe,onChangeSelect:F,onAtomExpand:q}){const St=dt();const k=it("jotai.changes");const[Ie,X]=g(false);const[m,Ae]=g(Te??"atoms");const[d,R]=g(null);const[A,Y]=g(null);const[J,M]=g(false);const[f,Z]=g(new Set);const{atomChanges:ee,filteredChanges:N,stats:we,filter:Tt,setFilter:w,atoms:v,clearChanges:ve,isEnabled:P,toggleCapture:Be}=ut();const h=p(()=>{if(f.size===0)return N;return N.filter(e=>!Array.from(f).some(o=>e.atomLabel.toLowerCase().includes(o.toLowerCase())))},[N,f]);const x=p(()=>{if(f.size===0)return v;return v.filter(e=>!Array.from(f).some(o=>e.label.toLowerCase().includes(o.toLowerCase())))},[v,f]);const De=p(()=>{if(!d)return 0;return ee.filter(e=>e.atomLabel===d).length},[ee,d]);const V=p(()=>d?h.filter(e=>e.atomLabel===d):h,[h,d]);const j=p(()=>V.slice(0,k),[V,k]);const W=p(()=>Math.max(0,V.length-k),[V.length,k]);const $e=W>0;const i=j;const[_,y]=g(null);const C=p(()=>{if(_===null)return null;const e=i.findIndex(o=>o.id===_);return e>=0?e:null},[_,i]);const u=C!==null?i[C]:null;const te=E(null);ge(()=>{if(!F)return;const e=u?.id??null;if(e===null||e===te.current)return;te.current=e;F(u)},[u,F]);const oe=E(null);ge(()=>{if(!T)return;if(oe.current===T)return;const e=i.some(o=>o.id===T);if(!e)return;oe.current=T;y(T)},[T,i]);const[b,K]=g("");const[ke,L]=g(false);const xt=E(null);const Pe=E(null);const Ve=r(e=>{},[]);const Le=e=>{K(e);if(m==="events"){w(o=>({...o,searchText:e}))}};const Ee=r(()=>{K("");w(e=>({...e,searchText:""}));L(false)},[w]);const ne=r(e=>{y(e.id)},[]);const He=r(()=>{X(true)},[]);const ze=r(()=>{y(null)},[]);const re=r(e=>{const o=i[e];if(o)y(o.id)},[i]);const Fe=r(e=>{R(e);y(null)},[]);const Re=r(()=>{R(null);y(null)},[]);const Je=r(e=>{Y(e);q?.(e)},[q]);const Me=r(()=>{Y(null)},[]);const Ne=r(()=>{return x.reduce((e,o)=>{try{const I=o.getValue();e[o.label]=D(I)}catch{e[o.label]=null}return e},{})},[x]);const je=r(()=>{return h.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:D(e.prevValue),nextValue:D(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[h]);const We=r(()=>{return i.map(e=>({id:e.id,atomLabel:e.atomLabel,timestamp:e.timestamp,prevValue:D(e.prevValue),nextValue:D(e.nextValue),hasValueChange:e.hasValueChange,changedKeys:e.changedKeys}))},[i]);const _e=r(e=>{Z(o=>{const I=new Set(o);if(I.has(e))I.delete(e);else I.add(e);return I})},[]);const Ke=r(e=>{Z(o=>new Set([...o,e]))},[]);const Oe=r(e=>{Ae(e);R(null);y(null);M(false);if(b){K("");w(o=>({...o,searchText:""}))}L(false)},[b,w]);const ae=r(e=>e.id,[]);const le=p(()=>yt(i),[i]);const se=r(({item:e})=>t(ht,{change:e,onPress:ne,testID:le.get(e.id)}),[ne,le]);const ie=f.size>0;const ce=()=>{if(J){return c(a,{children:[t(a.Navigation,{onBack:()=>M(false)}),t(a.Content,{title:"Filters",centered:true,testID:`${n}-filters-title`})]})}if(u){return c(a,{children:[t(a.Navigation,{onBack:ze}),t(a.Content,{title:`${u.atomLabel}/${u.category}`,centered:true,testID:`${n}-detail-title`})]})}if(d){return c(a,{children:[t(a.Navigation,{onBack:Re}),t(a.Content,{title:`${d} History`,centered:true,testID:`${n}-history-title`}),t(a.Actions,{children:t(Q,{value:We,disabled:i.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`})})]})}if(A){return c(a,{children:[t(a.Navigation,{onBack:Me}),t(a.Content,{title:A,centered:true,testID:`${n}-atom-detail-title`})]})}return c(a,{children:[$&&t(a.Navigation,{onBack:$}),t(a.Content,{title:"",children:ke?t(a.Search,{value:b,onChangeText:Le,onCancel:Ee,placeholder:m==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${n}-search-field`,containerTestID:`${n}-search`,clearTestID:`${n}-search-clear`,onBlur:()=>{if(b.length===0)L(false)}}):t(Ze,{tabs:[{key:"atoms",label:`Atoms${x.length>0?` (${x.length})`:""}`},{key:"events",label:`Events${h.length>0?` (${h.length})`:""}`}],activeTab:m,onTabChange:Oe,testIDPrefix:`${n}-tab`})}),c(a.Actions,{children:[t(U,{onPress:()=>L(true),style:s.headerActionButton,testID:`${n}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:t(tt,{size:14,color:l.color.textSecondary})}),t(U,{onPress:()=>M(true),style:[s.headerActionButton,ie&&s.headerActionButtonActive],testID:`${n}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:t(ot,{size:14,color:ie?l.color.accent:l.color.textSecondary})}),m==="atoms"&&t(Q,{value:Ne,disabled:x.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`}),m==="events"&&c(ye,{children:[t(Q,{value:je,disabled:h.length===0,buttonStyle:s.headerActionButton,testID:`${n}-copy`}),t(lt,{isEnabled:P,onToggle:Be,accessibilityLabel:"Toggle Jotai atom capture",testID:`${n}-power`}),t(st,{onPress:ve,disabled:h.length===0,buttonStyle:s.headerActionButton,testID:`${n}-clear`})]})]})]})};const Ue=()=>{if(J){return t(pt,{ignoredPatterns:f,onTogglePattern:_e,onAddPattern:Ke,atoms:v})}if(u&&C!==null){return t(gt,{change:u,changes:i,selectedIndex:C,onIndexChange:re,disableInternalFooter:true,initialView:xe})}if(d){return i.length>0?t(me,{testID:`${n}-history-list`,data:i,renderItem:se,keyExtractor:ae,contentContainerStyle:s.listContent,showsVerticalScrollIndicator:true,...pe}):t(G,{testID:`${n}-history-empty`,...fe({subject:"changes",search:b,total:b.trim()?De:0,capturing:P,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${d} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${d}.`}})})}if(A){const e=v.find(o=>o.label===A)??null;return e?t(bt,{atom:e,onViewHistory:Fe}):t(G,{testID:`${n}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${A} is not in the registry any more.`})}if(m==="atoms"){return t(ft,{atoms:x,searchQuery:b,onOpenAtom:Je})}return c(ye,{children:[!P&&c(B,{style:s.disabledBanner,testID:`${n}-banner-disabled`,children:[t(nt,{size:14,color:l.color.warning}),t(O,{style:s.disabledText,children:"Atom capture is disabled"})]}),$e&&c(U,{style:s.lockedBanner,onPress:He,activeOpacity:.8,testID:`${n}-locked`,accessibilityRole:"button",children:[c(O,{style:s.lockedText,testID:`${n}-locked-text`,children:[W," older"," ",W===1?"change":"changes"," locked"]}),t(B,{style:s.upgradeBadge,children:t(O,{style:s.upgradeBadgeText,children:"UPGRADE"})})]}),j.length>0?t(me,{ref:Pe,testID:`${n}-list`,data:j,renderItem:se,keyExtractor:ae,contentContainerStyle:s.listContent,showsVerticalScrollIndicator:true,...pe}):t(Ct,{isEnabled:P,searchText:b,totalChanges:we.totalChanges})]})};const Ge=Ce?rt.modal.root():"buoy-jotai-modal";if(!S)return null;const de=u&&C!==null?t(mt,{change:u,changes:i,selectedIndex:C,onIndexChange:re}):null;const Qe=u&&i.length>1?68:0;const qe=!J&&!(u&&C!==null)&&(d!=null||m==="events"||m==="atoms");const ue=t(B,{style:s.container,children:Ue()});const he=t(at,{visible:Ie,onClose:()=>X(false),featureName:"Full Atom History"});if(Se){return c(be,{children:[c(B,{style:s.inlineRoot,children:[t(B,{style:s.inlineHeader,...ct,children:ce()}),ue,de]}),he]})}return c(be,{children:[t(Ye,{visible:S,onClose:H,onMinimize:z,persistenceKey:Ge,header:{showToggleButton:true,customContent:ce()},onModeChange:Ve,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:qe,styles:{},footer:de,footerHeight:Qe,children:ue}),he]})}export function JotaiToolView(S={}){return t(JotaiModal,{...S,inline:true,visible:true,onClose:()=>{}})}const s=Xe.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:et.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:l.color.buttonSurface,borderWidth:1,borderColor:l.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:l.color.accentSoft,borderColor:l.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:l.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:l.color.warning+"20"},disabledText:{color:l.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:l.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:l.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:l.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:l.color.accentBorder},lockedText:{color:l.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:l.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:l.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});
|
package/lib/web/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";var it=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var sa=Object.getOwnPropertyNames;var ca=Object.prototype.hasOwnProperty;var da=(e,t)=>{for(var a in t)it(e,a,{get:t[a],enumerable:true})},lt=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of sa(t))!ca.call(e,o)&&o!==a&&it(e,o,{get:()=>t[o],enumerable:!(r=la(t,o))||r.enumerable});return e},ua=(e,t,a)=>(lt(e,t,"default"),a&<(a,t,"default"));typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{createRestoreScope as ha,emptyRestoreResult as ga,failedRestore as ma,registerStateSnapshotProvider as fa,unionKeys as pa}from"@buoy-gg/shared-ui/web";import{boundedDeepEqual as ya}from"@buoy-gg/shared-ui/web/dataViewer";import{ChangeLog as ba,entityColor as Ca,formatValuePreview as va,shallowDiffSummary as wa}from"@buoy-gg/shared-ui/web";var xa={count:"#10B981",auth:"#8B5CF6",user:"#3B82F6",cart:"#EC4899",app:"#6366F1",ui:"#F59E0B",settings:"#14B8A6",theme:"#06B6D4",nav:"#F97316",form:"#EF4444",modal:"#A855F7",filter:"#84CC16"};function st(e){return Ca(e,xa)}function Va(e,t=40){return va(e,{maxLength:t,functionLabel:"(fn)"})}var Ta=wa,Sa=class extends ba{constructor(){super(...arguments);this.atoms=new Map;this.atomListeners=new Set}addAtomChange(e){if(!this.canRecord())return;let{atomLabel:t,prevValue:a,nextValue:r,category:o="write"}=e,n=a!==r,{summary:s,changedKeys:i,changedCount:d}=Ta(a,r),m=Va(r),y={id:this.nextId(),atomLabel:t,timestamp:Date.now(),prevValue:a,nextValue:r,hasValueChange:n,category:o,changedKeys:i,changedKeysCount:d,diffSummary:s,valuePreview:m,isSlowUpdate:false};this.push(y);let E=this.atoms.get(t);E&&E.changeCount++,this.notifyListeners(),this.notifyAtomListeners()}getAtomChanges(){return this.getAll()}getAtomChangeById(e){return this.getById(e)}clearAtomChanges(){for(let e of this.atoms.values())e.changeCount=0;this.clear(),this.notifyAtomListeners()}getAtomSnapshots(){return Array.from(this.atoms.values()).map(e=>{let t;try{t=e.getValue()}catch{t=void 0}return{label:e.label,changeCount:e.changeCount,color:e.color,currentValue:t,writeKind:e.writeKind}})}replaceFromSnapshot(e,t){if(!this.getEnabled())return;let a=new Map;for(let n of this.items){let s=n.prevValue;(!s||s.__buoyValueOnDevice!==true)&&a.set(n.id,n)}let r=e.slice(0,this.max).map(n=>{let s=a.get(n.id),i=n.prevValue;return s&&i?.__buoyValueOnDevice===true?{...n,prevValue:s.prevValue,nextValue:s.nextValue}:n}),o=new Map;for(let[n,s]of this.atoms)try{let i=s.getValue(),d=i;(!d||d.__buoyValueOnDevice!==true)&&o.set(n,i)}catch{}this.atoms=new Map(t.map(n=>{let s=n.currentValue,i=o.get(n.label),d=i!==void 0&&s?.__buoyValueOnDevice===true?i:n.currentValue;return[n.label,{label:n.label,changeCount:n.changeCount,color:n.color,getValue:()=>d,writeKind:n.writeKind}]})),this.setItems(r),this.notifyAtomListeners()}hydrateChange(e,t){this.hydrateById(e,t)}hydrateAtomValue(e,t){let a=this.atoms.get(e);a&&(this.atoms.set(e,{...a,getValue:()=>t}),this.notifyAtomListeners())}registerAtom(e,t,a,r){if(this.atoms.has(e))return;let o={label:e,changeCount:0,color:st(e),getValue:t,setValue:a,writeKind:r};this.atoms.set(e,o),this.notifyAtomListeners()}setAtomValue(e,t){let a=this.atoms.get(e);if(!a)throw new Error(`Atom "${e}" is not registered`);if(!a.setValue)throw new Error(`Atom "${e}" is read-only (derived) \u2014 cannot set`);a.setValue(t)}unregisterAtom(e){this.atoms.delete(e),this.notifyAtomListeners()}getAtoms(){return Array.from(this.atoms.values())}getAtom(e){return this.atoms.get(e)}getAtomColor(e){return this.atoms.get(e)?.color??st(e)}filterAtomChanges(e){let t=this.getAll();if(e.searchText){let a=e.searchText.toLowerCase();t=t.filter(r=>r.atomLabel.toLowerCase().includes(a)||r.valuePreview.toLowerCase().includes(a)||r.changedKeys.some(o=>o.toLowerCase().includes(a)))}return e.atomLabels&&e.atomLabels.length>0&&(t=t.filter(a=>e.atomLabels.includes(a.atomLabel))),e.onlyWithChanges&&(t=t.filter(a=>a.hasValueChange)),t}getStats(){let e=this.items.length,t=this.items.filter(a=>a.hasValueChange).length;return{totalChanges:e,changesWithValueChange:t,changesWithoutValueChange:e-t,atomCount:this.atoms.size}}getUniqueAtomLabels(){return Array.from(this.atoms.keys()).sort()}setMaxChanges(e){this.setMax(e)}subscribeToAtoms(e){return this.atomListeners.add(e),()=>this.atomListeners.delete(e)}notifyAtomListeners(){let e=this.getAtoms();this.atomListeners.forEach(t=>t(e))}},p=new Sa;function Aa(){let e=p.getAtoms();if(e.length===0)return{canCapture:false,canRestore:false,detail:"No Jotai atoms registered \u2014 pass your atoms to watchAtoms() / watchDefaultStoreAtoms()"};let t=e.filter(a=>a.setValue).length;return{canCapture:true,canRestore:t>0,detail:t<e.length?`${e.length-t} derived atom(s) recompute automatically and are not restored`:void 0}}async function Ia(){let e=[],t={},a=0;for(let r of p.getAtoms())try{let o=r.getValue();if(typeof o=="function"){e.push(`atom "${r.label}": function value not capturable`);continue}r.setValue||(a+=1),t[r.label]={value:o,writable:!!r.setValue}}catch(o){e.push(`atom "${r.label}": capture failed (${String(o)})`)}return a>0&&e.push(`${a} derived atom(s) captured for inspection only (recompute on restore)`),{data:{atoms:t},warnings:e}}async function Da(e,t){let a=e,r=ha(t),o=ga();if(!a?.atoms)return ma("empty jotai snapshot");let n=0;for(let[i,d]of Object.entries(a.atoms)){if(!r.allows(i))continue;if(!d.writable){n+=1;continue}let m=p.getAtom(i);if(!m){o.skipped.push({id:i,reason:"atom not registered (renamed, or unwatched since snapshot?)"});continue}if(!m.setValue){o.skipped.push({id:i,reason:"atom is now read-only (derived)"});continue}try{m.setValue(d.value),o.applied+=1}catch(y){o.skipped.push({id:i,reason:String(y)}),o.ok=false}}n>0&&o.warnings.push(`${n} derived atom(s) left to recompute`);let s=r.excludedWarning("atom(s)");return s&&o.warnings.push(s),o}async function Ba(e,t){let a=e?.atoms??{},r=t===void 0,o={};if(r)for(let i of p.getAtoms())try{o[i.label]={value:i.getValue(),writable:!!i.setValue}}catch{}else Object.assign(o,t?.atoms??{});let n=[],s=[];for(let i of pa(o,a)){if(!(i in a)){r?s.push(`atom "${i}" not in snapshot \u2014 untouched`):n.push({key:i,label:i,verdict:"removed",oldValue:o[i]?.value});continue}let d=a[i],m=i in o&&ya(o[i].value,d.value);if(!d.writable){n.push({key:i,label:i,verdict:m?"unchanged":"recomputes",reason:m?void 0:"derived atom \u2014 recomputes from its sources",oldValue:o[i]?.value,newValue:d.value});continue}if(r){let y=p.getAtom(i);if(!y){n.push({key:i,label:i,verdict:"wont-apply",reason:"atom not registered (renamed, or unwatched since snapshot?)"});continue}if(!y.setValue){n.push({key:i,label:i,verdict:"wont-apply",reason:"atom is now read-only (derived)"});continue}}i in o?m?n.push({key:i,label:i,verdict:"unchanged"}):n.push({key:i,label:i,verdict:"changed",oldValue:o[i].value,newValue:d.value}):n.push({key:i,label:i,verdict:"added",newValue:d.value})}return{items:n,notes:s}}fa({id:"jotai",label:"Jotai",status:Aa,capture:Ia,restore:Da,previewItems:Ba});import{useState as _,useMemo as Q,useRef as Ve,useCallback as D,useEffect as ct}from"react";var dt={};da(dt,{AccessibilityInfo:()=>Ea,ActivityIndicator:()=>Do,Alert:()=>Lo,Animated:()=>Pa,AppRegistry:()=>za,AppState:()=>Ha,Appearance:()=>Ra,BackHandler:()=>Wa,Button:()=>Bo,CheckBox:()=>eo,Clipboard:()=>ja,DeviceEventEmitter:()=>po,Dimensions:()=>Ma,Easing:()=>Fa,FlatList:()=>$e,I18nManager:()=>Oa,Image:()=>to,ImageBackground:()=>ao,InteractionManager:()=>Ka,Keyboard:()=>Na,KeyboardAvoidingView:()=>oo,LayoutAnimation:()=>Ja,Linking:()=>_a,LogBox:()=>fo,Modal:()=>Ao,NativeEventEmitter:()=>Ua,NativeModules:()=>$a,PanResponder:()=>Ga,Picker:()=>no,PixelRatio:()=>Ya,Platform:()=>qa,Pressable:()=>So,ProgressBar:()=>ro,RefreshControl:()=>io,SafeAreaView:()=>lo,ScrollView:()=>ge,SectionList:()=>so,Share:()=>Qa,StatusBar:()=>co,StyleSheet:()=>ne,Switch:()=>Io,Text:()=>b,TextInput:()=>xo,Touchable:()=>uo,TouchableHighlight:()=>Vo,TouchableNativeFeedback:()=>ho,TouchableOpacity:()=>re,TouchableWithoutFeedback:()=>To,UIManager:()=>Za,Vibration:()=>Xa,View:()=>c,VirtualizedList:()=>go,YellowBox:()=>mo,findNodeHandle:()=>ko,unstable_createElement:()=>La,useColorScheme:()=>yo,useLocaleContext:()=>bo,useWindowDimensions:()=>Co});ua(dt,ka);import*as ka from"react-native-web";import{unstable_createElement as La,NativeModules as $a,AccessibilityInfo as Ea,Animated as Pa,Appearance as Ra,AppRegistry as za,AppState as Ha,BackHandler as Wa,Clipboard as ja,Dimensions as Ma,Easing as Fa,I18nManager as Oa,Keyboard as Na,InteractionManager as Ka,LayoutAnimation as Ja,Linking as _a,NativeEventEmitter as Ua,PanResponder as Ga,PixelRatio as Ya,Platform as qa,Share as Qa,StyleSheet as ne,UIManager as Za,Vibration as Xa,CheckBox as eo,FlatList as $e,Image as to,ImageBackground as ao,KeyboardAvoidingView as oo,Picker as no,ProgressBar as ro,RefreshControl as io,SafeAreaView as lo,SectionList as so,StatusBar as co,Touchable as uo,TouchableNativeFeedback as ho,VirtualizedList as go,YellowBox as mo,LogBox as fo,DeviceEventEmitter as po,useColorScheme as yo,useLocaleContext as bo,useWindowDimensions as Co}from"react-native-web";import*as j from"react-native-web";import{createElement as vo,forwardRef as wo}from"react";function F(e){let t=wo((r,o)=>{let{accessibilityState:n,accessibilityValue:s,...i}=r;for(let d of["busy","checked","disabled","expanded","selected"])n?.[d]!==void 0&&i[`aria-${d}`]===void 0&&(i[`aria-${d}`]=n[d]);for(let[d,m]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))s?.[d]!==void 0&&i[`aria-${m}`]===void 0&&(i[`aria-${m}`]=s[d]);return vo(e,{...i,ref:o})}),a=e.State;return a&&Object.assign(t,{State:a}),t.displayName=e.displayName??e.name??"NativeWebView",t}var c=F(j.View),b=F(j.Text),xo=F(j.TextInput),re=F(j.TouchableOpacity),Vo=F(j.TouchableHighlight),To=F(j.TouchableWithoutFeedback),So=F(j.Pressable),ge=F(j.ScrollView),Ao=F(j.Modal),Io=F(j.Switch),Do=F(j.ActivityIndicator),Bo=F(j.Button),ko=j.findNodeHandle,Lo={alert(e,t,a,r){if(typeof document>"u")return;let o=document.createElement("dialog");o.dataset.buoyRoot="",o.setAttribute("aria-label",e),o.style.cssText="position:fixed;inset:0;margin:auto;width:min(440px,90vw);padding:24px;border:1px solid #475569;border-radius:14px;background:#17212e;color:#f1f5f9;font:14px system-ui;box-shadow:0 20px 80px #0008;z-index:2147483647";let n=document.createElement("h2");if(n.textContent=e,n.style.cssText="font-size:18px;margin:0 0 12px",o.appendChild(n),t){let m=document.createElement("p");m.textContent=t,m.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",o.appendChild(m)}let s=document.createElement("div");s.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let i=a?.length?a:[{text:"OK"}],d=()=>{o.close?.(),o.remove()};for(let m of i){let y=document.createElement("button");y.type="button",y.textContent=m.text??"OK",y.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${m.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,y.onclick=()=>{d(),m.onPress?.()},s.appendChild(y)}o.addEventListener("cancel",m=>{m.preventDefault(),r?.cancelable!==false&&(d(),r?.onDismiss?.())}),o.appendChild(s),document.body.appendChild(o),o.showModal?o.showModal():o.setAttribute("open","")}};import{JsModal as $o,ModalHeader as B,TabSelector as Eo,macOSColors as Po,night as k,Search as Ro,Filter as zo,Power as Ho,ToolEmptyState as Ee,resolveListEmptyState as ut,devToolsStorageKeys as Wo,ProUpgradeModal as jo,PowerToggleButton as Mo,ToolbarCopyButton as Pe,ToolbarClearButton as Fo,truncatePayload as me,TickProvider as ht,useLimit as Oo,windowDragProps as No,EVENT_LIST_PRESET as gt}from"@buoy-gg/shared-ui/web";import{useIsPro as Ko}from"@buoy-gg/license/web";import{useCallback as Jo,useMemo as mt}from"react";import{useChangeLog as _o,useSubscribedValue as Uo}from"@buoy-gg/shared-ui/web";function Go(e,t){let a=e;if(t.searchText){let r=t.searchText.toLowerCase();a=a.filter(o=>o.atomLabel.toLowerCase().includes(r)||o.valuePreview.toLowerCase().includes(r)||o.changedKeys.some(n=>n.toLowerCase().includes(r)))}return t.atomLabels&&t.atomLabels.length>0&&(a=a.filter(r=>t.atomLabels.includes(r.atomLabel))),t.onlyWithChanges&&(a=a.filter(r=>r.hasValueChange)),a}var Yo=()=>p.getAtoms(),qo=e=>p.subscribeToAtoms(e);function ft(){let e=_o(p,{filterItems:Go}),t=Uo(Yo,qo),a=mt(()=>{let n=e.items.length,s=e.items.filter(i=>i.hasValueChange).length;return{totalChanges:n,changesWithValueChange:s,changesWithoutValueChange:n-s,atomCount:t.length}},[e.items,t]),r=mt(()=>p.getUniqueAtomLabels(),[t]),o=Jo(n=>p.getAtomChangeById(n),[]);return{atomChanges:e.items,filteredChanges:e.filteredItems,filter:e.filter,setFilter:e.setFilter,stats:a,atoms:t,clearChanges:p.clearAtomChanges.bind(p),isEnabled:e.isEnabled,toggleCapture:e.toggleCapture,atomLabels:r,getChangeById:o}}import{memo as Qo}from"react";import{ChangeRow as Zo,night as Xo}from"@buoy-gg/shared-ui/web";import{jsx as en}from"react/jsx-runtime";function tn(e,t){return t}function an(e,t){return e==="initial"?Xo.color.textTertiary:p.getAtomColor(t)}function Re(e,t=20){if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e=="boolean"||typeof e=="number")return String(e);if(typeof e=="string")return`"${e.length>t?e.slice(0,t-1)+"\u2026":e}"`;if(Array.isArray(e))return e.length===0?"[]":`[${e.length} item${e.length===1?"":"s"}]`;if(typeof e=="object"){let a=Object.keys(e);return a.length===0?"{}":`{${a.slice(0,2).join(", ")}${a.length>2?"\u2026":""}}`}return String(e).slice(0,t)}function on(e){return e.hasValueChange?`${Re(e.prevValue)} \u2192 ${Re(e.nextValue)}`:"no change"}function nn(e){return e.category==="initial"?"INIT":"WRITE"}function rn(e){let t=e.nextValue;return typeof t=="object"&&t!==null&&!Array.isArray(t)?e.changedKeys.length>0&&e.changedKeys.length<=3?e.changedKeys.join(", "):e.changedKeys.length>3?`${e.changedKeys.slice(0,2).join(", ")} +${e.changedKeys.length-2}`:e.valuePreview||"atom()":Re(t)}var pt=Qo(function({change:e,onPress:t,testID:a}){let r=an(e.category,e.atomLabel),o=tn(e.category,e.atomLabel),n=on(e),s=rn(e),i=nn(e);return en(Zo,{statusColor:r,statusLabel:o,sublabel:n,primaryText:s,timestamp:e.timestamp,badgeText:i,changed:e.hasValueChange,onPress:()=>t(e),testID:a})});import{memo as ln,useState as ze,useCallback as fe,useMemo as yt}from"react";import{buoyColors as pe,night as v,EventStepperFooter as bt,formatRelativeTime as Te,parseValue as Se,Info as sn,Zap as Ct,FileText as cn,Database as dn,GitBranch as un,copyToClipboard as hn,ProUpgradeModal as gn,DiffModeTabs as mn,CompareBar as fn,DetailViewToggle as pn,monoFont as J}from"@buoy-gg/shared-ui/web";import{DataViewer as yn,SplitDiffViewer as bn,TreeDiffViewer as Cn,diffThemes as vn}from"@buoy-gg/shared-ui/web/dataViewer";import{useIsPro as wn}from"@buoy-gg/license/web";var u="buoy-jotai";function Ae(e){return String(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"unknown"}function xn(e,t){return`${u}-row-${Ae(e)}-${t}`}function vt(e){return`${u}-atom-${Ae(e)}`}function Vn(e){let t=new Map,a=new Map;for(let r of e){let o=(t.get(r.atomLabel)??0)+1;t.set(r.atomLabel,o),a.set(r.id,xn(r.atomLabel,o))}return a}import{jsx as h,jsxs as R}from"react/jsx-runtime";var Tn=[{key:"change",label:"CHANGE",icon:cn},{key:"value",label:"VALUE",icon:dn},{key:"diff",label:"DIFF",icon:un}],Sn=["diff"];function An(e){switch(e){case"initial":return{label:"INITIAL",color:v.color.textTertiary,bgColor:v.color.textTertiary+"26"};default:return{label:"WRITE",color:pe.success,bgColor:pe.success+"26"}}}function In(e){let t=new Date(e),a=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0"),o=t.getSeconds().toString().padStart(2,"0"),n=t.getMilliseconds().toString().padStart(3,"0");return`${a}:${r}:${o}.${n}`}function wt(e){return new Date(e).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Dn(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"array":typeof e}function xt(e){return e==="initial"?"INIT":"WRITE"}var Bn=[{key:"tree",label:"TREE VIEW"},{key:"split",label:"SPLIT VIEW"}],kn=ln(function({change:e}){let t=wn(),[a,r]=ze(false),o=An(e.category),n=p.getAtomColor(e.atomLabel),s=fe(async()=>{if(!t){r(true);return}await hn(e.nextValue)},[e.nextValue,t]);return R(ge,{style:f.container,contentContainerStyle:f.content,showsVerticalScrollIndicator:false,testID:`${u}-detail-scroll`,children:[R(c,{style:f.card,testID:`${u}-info-card`,children:[h(c,{style:f.sectionHeader,children:R(c,{style:f.sectionHeaderLeft,children:[h(sn,{size:14,color:v.color.accent}),h(b,{style:f.sectionTitle,children:"CHANGE INFO"})]})}),R(c,{style:f.cardContent,children:[R(c,{style:f.infoRow,children:[h(b,{style:f.infoLabel,children:"Atom"}),h(b,{style:[f.infoValue,f.infoValueMono,{color:n}],numberOfLines:1,ellipsizeMode:"middle",testID:`${u}-info-atom`,children:e.atomLabel})]}),R(c,{style:f.infoRow,children:[h(b,{style:f.infoLabel,children:"Time"}),h(b,{style:[f.infoValue,f.infoValueMono],testID:`${u}-info-time`,children:In(e.timestamp)})]}),R(c,{style:f.badgeRow,children:[h(c,{style:[f.categoryBadge,{backgroundColor:o.bgColor}],children:h(b,{style:[f.categoryText,{color:o.color}],testID:`${u}-info-category`,children:o.label})}),e.hasValueChange?R(c,{style:f.changesBadge,children:[h(Ct,{size:10,color:pe.success}),h(b,{style:f.changesText,testID:`${u}-info-changes`,children:e.diffSummary||"changed"})]}):h(c,{style:f.noChangesBadge,children:h(b,{style:f.noChangesText,testID:`${u}-info-no-changes`,children:"no change"})})]})]})]}),e.changedKeys.length>0&&R(c,{style:f.card,testID:`${u}-keys-card`,children:[R(c,{style:f.sectionHeader,children:[R(c,{style:f.sectionHeaderLeft,children:[h(Ct,{size:14,color:v.color.accent}),h(b,{style:f.sectionTitle,children:"CHANGED KEYS"})]}),h(c,{style:f.countBadge,children:h(b,{style:f.countText,testID:`${u}-keys-count`,children:e.changedKeys.length})})]}),h(c,{style:f.cardContent,children:h(c,{style:f.keysContainer,children:e.changedKeys.map(i=>h(c,{style:f.keyBadge,children:h(b,{style:f.keyText,testID:`${u}-key-${Ae(i)}`,children:i})},i))})})]}),h(c,{style:f.actionsRow,children:h(c,{style:[f.actionButton,f.actionButtonCopy],onTouchEnd:s,testID:`${u}-copy-value`,accessibilityRole:"button",accessibilityLabel:"Copy value",children:h(b,{style:[f.actionButtonText,{color:v.color.accent}],children:"COPY VALUE"})})}),h(gn,{visible:a,onClose:()=>r(false),featureName:"Copy"})]})});function Vt({change:e,changes:t,selectedIndex:a,onIndexChange:r,disableInternalFooter:o=false,initialView:n="change"}){let[s,i]=ze(n),[d,m]=ze("tree"),y=t.length,E=p.getAtomColor(e.atomLabel),w=xt(e.category),C=Dn(Se(e.nextValue)),T=y-a,A=a<y-1?a+1:null,W=A!==null?t[A]:null,z=T-1,ie=yt(()=>({index:A??0,label:z>0?`#${z}`:"Initial",timestamp:W?wt(W.timestamp):"",relativeTime:W?Te(new Date(W.timestamp)):"value",badge:W?h(c,{style:[L.changeBadgeSmall,{backgroundColor:`${p.getAtomColor(W.atomLabel)}20`}],children:h(b,{style:[L.changeTextSmall,{color:p.getAtomColor(W.atomLabel)}],children:xt(W.category)})}):void 0}),[A,W,z]),Z=yt(()=>({index:a,label:`#${T}`,timestamp:wt(e.timestamp),relativeTime:Te(new Date(e.timestamp)),badge:h(c,{style:[L.changeBadgeSmall,{backgroundColor:`${E}20`}],children:h(b,{style:[L.changeTextSmall,{color:E}],children:w})})}),[a,e.timestamp,E,w,T]),be=fe(()=>{let Y=Se(e.nextValue);return R(c,{style:L.contentCard,testID:`${u}-value-card`,children:[R(c,{style:L.valueHeader,children:[h(b,{style:L.valueLabel,children:"VALUE AFTER CHANGE"}),R(c,{style:L.valueHeaderBadges,children:[h(c,{style:[L.changeBadge,{backgroundColor:`${E}20`}],children:h(b,{style:[L.changeText,{color:E}],children:w})}),h(c,{style:L.typeBadge,children:h(b,{style:L.typeText,testID:`${u}-value-type`,children:C.toUpperCase()})})]})]}),h(c,{style:f.dataViewerContainer,children:h(yn,{title:"",data:Y,showTypeFilter:true,rawMode:true,initialExpanded:true})})]})},[e.nextValue,E,w,C]),le=fe(()=>{let Y=Se(e.prevValue),ve=Se(e.nextValue);return d==="split"?h(ge,{style:{flex:1},showsVerticalScrollIndicator:true,children:h(bn,{oldValue:Y,newValue:ve,theme:vn.devToolsDefault,options:{hideLineNumbers:false,disableWordDiff:false,showDiffOnly:false,compareMethod:"words",contextLines:3},showThemeName:false})}):h(Cn,{oldValue:Y,newValue:ve})},[e.prevValue,e.nextValue,d]),se=fe(()=>{r(Math.min(y-1,a+1))},[a,y,r]),N=fe(()=>{r(Math.max(0,a-1))},[a,r]),Ce=e.prevValue===void 0,ce=!o&&y>1;return R(c,{style:L.container,children:[h(pn,{views:Tn,activeView:s,onViewChange:i,disabledKeys:Ce?Sn:void 0,testIDPrefix:u}),R(c,{style:[L.contentArea,ce&&L.contentAreaFooterPad],children:[s==="change"&&h(kn,{change:e}),s==="value"&&h(c,{style:L.stateContainer,children:be()}),s==="diff"&&R(c,{style:L.diffContainer,testID:`${u}-diff`,children:[h(mn,{tabs:Bn,activeTab:d,onTabChange:m,testIDPrefix:`${u}-diff-tab`}),h(fn,{leftEvent:ie,rightEvent:Z}),h(c,{style:L.diffContent,testID:`${u}-diff-content`,children:le()})]})]}),ce&&h(bt,{currentIndex:T-1,totalItems:y,onPrevious:se,onNext:N,itemLabel:"Change",subtitle:Te(new Date(e.timestamp)),absolute:true})]})}function Tt({change:e,changes:t,selectedIndex:a,onIndexChange:r}){let o=t.length;if(o<=1)return null;let n=o-a;return h(bt,{currentIndex:n-1,totalItems:o,onPrevious:()=>r(Math.min(o-1,a+1)),onNext:()=>r(Math.max(0,a-1)),itemLabel:"Change",subtitle:Te(new Date(e.timestamp))})}var L=ne.create({container:{flex:1,backgroundColor:"transparent"},contentArea:{flex:1},contentAreaFooterPad:{paddingBottom:96},stateContainer:{flex:1,padding:14},contentCard:{backgroundColor:v.color.surface,borderRadius:14,padding:14,borderWidth:1,borderColor:v.color.border},valueHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:8},valueLabel:{fontSize:10,color:v.color.textSecondary,fontFamily:J,letterSpacing:.5,fontWeight:"600"},valueHeaderBadges:{flexDirection:"row",alignItems:"center",gap:6},changeBadge:{paddingHorizontal:8,paddingVertical:2,borderRadius:4},changeText:{fontSize:9,fontWeight:"700",fontFamily:J,letterSpacing:.3},typeBadge:{paddingHorizontal:8,paddingVertical:2,borderRadius:4,backgroundColor:v.color.surfaceElevated},typeText:{fontSize:9,fontWeight:"600",color:v.color.textTertiary,fontFamily:J},valueBox:{backgroundColor:v.color.bg,borderRadius:6,borderWidth:1,borderColor:v.color.border,padding:8},valueText:{fontSize:12,color:v.color.text,fontFamily:J,lineHeight:18},diffContainer:{flex:1},diffContent:{flex:1,paddingHorizontal:14},changeBadgeSmall:{paddingHorizontal:6,paddingVertical:1,borderRadius:3},changeTextSmall:{fontSize:8,fontWeight:"700",fontFamily:J}}),f=ne.create({container:{flex:1},content:{padding:8,paddingBottom:100,gap:16},card:{backgroundColor:v.color.surface,borderRadius:6,borderWidth:1,borderColor:v.color.accentBorderStrong,overflow:"hidden",shadowColor:v.color.accent,shadowOffset:{width:0,height:0},shadowOpacity:.1,shadowRadius:6},sectionHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingHorizontal:12,paddingVertical:10,borderBottomWidth:1,borderBottomColor:v.color.accentBorder,backgroundColor:v.color.accentSoft},sectionHeaderLeft:{flexDirection:"row",alignItems:"center",gap:6},sectionTitle:{fontSize:12,fontWeight:"600",letterSpacing:.5,color:v.color.accent,fontFamily:J},cardContent:{padding:14,gap:10},infoRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},infoLabel:{fontSize:11,color:v.color.textTertiary,fontWeight:"500"},infoValue:{fontSize:11,color:v.color.text,fontWeight:"500",flex:1,textAlign:"right",marginLeft:12},infoValueMono:{fontFamily:J},badgeRow:{flexDirection:"row",flexWrap:"wrap",gap:8,marginTop:6},categoryBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4},categoryText:{fontSize:9,fontWeight:"700",letterSpacing:.3},changesBadge:{flexDirection:"row",alignItems:"center",gap:4,paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:pe.success+"26"},changesText:{fontSize:9,fontWeight:"600",color:pe.success},noChangesBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:v.color.surfaceElevated},noChangesText:{fontSize:9,fontWeight:"600",color:v.color.textTertiary},keysContainer:{flexDirection:"row",flexWrap:"wrap",gap:6},keyBadge:{paddingHorizontal:8,paddingVertical:4,borderRadius:4,backgroundColor:v.color.accentSoft,borderWidth:1,borderColor:v.color.accentBorder},keyText:{fontSize:11,fontWeight:"600",color:v.color.accent,fontFamily:J},countBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:v.color.accentFill},countText:{fontSize:9,fontWeight:"700",color:v.color.accent,fontFamily:J},actionsRow:{flexDirection:"row",gap:12},actionButton:{paddingHorizontal:14,paddingVertical:8,borderRadius:8,borderWidth:1},actionButtonCopy:{borderColor:v.color.accentBorder,backgroundColor:v.color.accentSoft},actionButtonText:{fontSize:10,fontWeight:"700",fontFamily:J,letterSpacing:.3},dataViewerContainer:{marginTop:-12,marginHorizontal:-12,marginBottom:-12}});import{useMemo as Ln}from"react";import{CompactRow as $n,night as He,ToolEmptyState as St,resolveListEmptyState as En,monoFont as At}from"@buoy-gg/shared-ui/web";import{jsx as U,jsxs as We}from"react/jsx-runtime";function Pn(e){try{let t=e.getValue();if(t&&typeof t=="object"&&t.__buoyValueOnDevice===true)return"on device";if(t===void 0)return"undefined";if(t===null)return"null";if(Array.isArray(t))return t.length===0?"[]":`[${t.length} item${t.length===1?"":"s"}]`;if(typeof t=="object"){let a=Object.keys(t);return a.length===0?"{}":a.length<=3?a.join(", "):`${a.slice(0,2).join(", ")} +${a.length-2}`}return String(t).slice(0,40)}catch{return""}}function Rn(e){return e.writeKind==="value"?"primitive":e.writeKind==="action"?"custom write":e.setValue?"writable":"derived"}function zn(){return U(St,{testID:`${u}-atoms-empty`,otto:"scanning",title:"No atoms registered",message:`Use watchAtoms(store, { atomName }) to register your Jotai atoms.
|
|
2
|
-
They will appear here with their current value.`})}function Hn({atoms:e,searchQuery:t,onOpenAtom:a}){let r=Ln(()=>{if(!t)return e;let o=t.toLowerCase();return e.filter(n=>n.label.toLowerCase().includes(o))},[e,t]);return r.length===0&&!t?U(zn,{}):r.length===0&&t?U(St,{testID:`${u}-atoms-no-match`,...En({subject:"atoms",verb:"registered",search:t,total:e.length,waiting:{otto:"scanning",title:"No atoms registered",message:"Use watchAtoms() to register your Jotai atoms."}})}):We(ge,{style:G.container,contentContainerStyle:G.scrollContent,showsVerticalScrollIndicator:true,testID:`${u}-atoms-scroll`,children:[We(c,{style:G.sectionHeader,children:[U(b,{style:G.sectionTitle,children:"ATOMS"}),U(c,{style:G.sectionCountBadge,children:U(b,{style:G.sectionCountText,testID:`${u}-atoms-count`,children:r.length})})]}),r.map(o=>{let n=Pn(o),s=p.getAtomColor(o.label),i=vt(o.label);return We(c,{style:G.atomRowWrapper,children:[U($n,{statusDotColor:s,statusLabel:Rn(o),primaryText:o.label,secondaryText:n||void 0,showChevron:true,onPress:()=>a(o.label),testID:i,statusTestID:`${i}-kind`,primaryTestID:`${i}-name`,secondaryTestID:`${i}-preview`}),o.changeCount>0&&U(c,{style:[G.absCountBadge,{backgroundColor:s+"22",borderColor:s+"55"}],pointerEvents:"none",children:U(b,{style:[G.absCountText,{color:s}],testID:`${i}-count`,children:String(o.changeCount)})})]},o.label)})]})}var G=ne.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:At},scrollContent:{paddingTop:8,paddingBottom:20},sectionHeader:{flexDirection:"row",alignItems:"center",paddingHorizontal:16,paddingVertical:8,gap:8},sectionTitle:{fontSize:11,fontWeight:"700",letterSpacing:.5,color:He.color.textTertiary},sectionCountBadge:{backgroundColor:He.color.accentFill,paddingHorizontal:8,paddingVertical:2,borderRadius:4},sectionCountText:{fontSize:10,fontWeight:"700",color:He.color.accent,fontFamily:At}});import{useCallback as Wn,useEffect as jn,useMemo as je,useState as It}from"react";import{buoyColors as Me,ExpandedInfoRow as Fe,FileJson as Mn,night as I,PillBadge as Oe,parseValue as Dt,monoFont as ye}from"@buoy-gg/shared-ui/web";import{DataViewer as Fn,LiveExplorer as On,ValueEditModal as Nn,updateNestedDataByPath as Kn,deleteNestedDataByPath as Jn}from"@buoy-gg/shared-ui/web/dataViewer";import{Fragment as _n,jsx as V,jsxs as O}from"react/jsx-runtime";var Un=300,te=`${u}-atom-detail`;function Gn(e){let t=a=>a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return e.length===0?`${te}-explorer-root`:`${te}-explorer-${e.map(t).filter(Boolean).join("-")}`}function Yn(e,t){if(!e.setValue)return"Derived atom \u2014 its value recomputes from other atoms and has no setter. Edit the atoms it reads from instead.";if(typeof t=="function")return"This atom holds a function \u2014 nothing here to edit as data.";if(t&&typeof t=="object"&&t.__buoyValueOnDevice===true)return"The value stayed on the device (too large for the wire) \u2014 open the tool on-device to edit it.";if(t&&typeof t=="object"){let a=Object.getPrototypeOf(t);if(!(a===Object.prototype||a===null||Array.isArray(t)||t instanceof Map||t instanceof Set))return`This atom holds a ${t.constructor?.name??"class"} instance \u2014 rebuilding it from edited fields would drop its prototype. Edit via app code.`}return null}function qn(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`array \xB7 ${e.length}`:typeof e}function Bt({atom:e,onViewHistory:t}){let a=vt(e.label),[r,o]=It(0);jn(()=>{let C=()=>o(W=>W+1),T=p.subscribe(C),A=p.subscribeToAtoms(C);return()=>{T(),A()}},[]);let n=je(()=>{try{return e.getValue()}catch{return}},[e,r]),s=Yn(e,n),[i,d]=It(false),m=je(()=>{if(s===null)return{update:(C,T)=>{let A=e.getValue();e.setValue?.(C.length===0?T:Kn(A,C,T))},remove:C=>{if(C.length===0)return;let T=e.getValue();e.setValue?.(Jn(T,C))},canRemove:C=>C.length>0}},[e,s]),y=je(()=>{if(n&&typeof n=="object"){let C={};for(let[T,A]of Object.entries(n))typeof A!="function"&&(C[T]=A);return Dt(C)}return Dt(n)},[n,r]),E=Wn(C=>{e.setValue?.(C),d(false)},[e]),w=e.setValue===void 0?{color:I.color.textTertiary,label:"READ-ONLY (DERIVED)"}:e.writeKind==="action"?{color:Me.warning,label:"CUSTOM WRITE"}:{color:Me.success,label:"PRIMITIVE"};return O(c,{style:x.root,children:[O(ge,{testID:`${te}-scroll`,style:x.scroll,contentContainerStyle:x.scrollContent,keyboardShouldPersistTaps:"handled",children:[V(c,{style:x.section,children:O(c,{style:x.editorContainer,children:[O(c,{style:x.sectionHeaderRow,children:[V(b,{testID:`${te}-editor-header`,style:x.sectionHeaderText,children:"Value Editor"}),s===null?O(re,{onPress:()=>d(true),testID:`${te}-raw`,accessibilityRole:"button",accessibilityLabel:"Edit raw JSON",style:x.rawButton,hitSlop:{top:6,bottom:6,left:6,right:6},children:[V(Mn,{size:13,color:I.color.accent}),V(b,{style:x.rawButtonText,children:"Raw"})]}):null]}),V(c,{style:x.sectionBody,children:s===null?O(_n,{children:[V(On,{editable:true,label:e.label,value:n,defaultExpanded:[e.label],writer:m,dataVersion:r,testIDForPath:Gn,debounceMs:Un}),V(b,{style:x.editorHint,children:e.writeKind==="action"?"This atom has a custom write \u2014 the edited value is handed to it as its argument (a set for atomWithStorage, an ACTION for a reducer atom).":"Edits write into the live atom as you make them \u2014 the whole value is replaced, jotai's own semantics."})]}):V(b,{style:x.blockedText,testID:`${te}-edit-blocked`,children:s})})]})}),V(c,{style:x.section,children:O(c,{style:x.infoContainer,children:[V(b,{style:x.sectionHeaderTextPlain,children:"Atom Details"}),O(c,{style:x.infoBody,children:[O(Fe,{label:"Type",children:[V(Oe,{color:e.color,testID:`${a}-type`,children:"JOTAI"}),V(b,{style:x.valueTypeText,testID:`${a}-valuetype`,children:qn(n)})]}),V(Fe,{label:"Write",children:V(Oe,{color:w.color,testID:`${te}-write`,children:w.label})}),e.changeCount>0&&O(Fe,{label:"Changes",children:[V(Oe,{color:Me.warning,testID:`${a}-changes`,children:String(e.changeCount)}),V(re,{onPress:()=>t(e.label),style:x.inlineLinkButton,hitSlop:{top:6,bottom:6,left:6,right:6},testID:`${a}-history`,accessibilityRole:"button",accessibilityLabel:`View ${e.label} history`,children:V(b,{style:[x.inlineLinkText,{color:e.color}],children:"view history \u2192"})})]})]})]})}),V(c,{style:x.section,children:O(c,{style:x.infoContainer,children:[V(b,{style:x.sectionHeaderTextPlain,children:"Value Explorer"}),V(c,{style:x.viewerBody,testID:`${a}-value`,children:y&&typeof y=="object"?V(Fn,{title:"",data:y,showTypeFilter:true,rawMode:true,initialExpanded:false}):V(b,{style:x.primitiveText,testID:`${a}-primitive`,children:String(n??"undefined")})})]})})]}),i&&s===null?V(Nn,{path:[],value:n,onSave:E,onCancel:()=>d(false),saveLabel:"Apply",testIDPrefix:`${u}-value`}):null]})}var x=ne.create({root:{flex:1,minHeight:0},scroll:{flex:1},scrollContent:{paddingHorizontal:8,paddingTop:8,paddingBottom:24},section:{marginBottom:16},editorContainer:{minWidth:200,backgroundColor:I.color.surface,borderRadius:6,borderWidth:1,borderColor:I.color.accent+"4D",overflow:"hidden",shadowColor:I.color.accent,shadowOffset:{width:0,height:0},shadowOpacity:.1,shadowRadius:6},sectionHeaderRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",backgroundColor:I.color.accent+"1A",paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:I.color.accent+"33"},sectionHeaderText:{fontWeight:"600",fontSize:12,color:I.color.accent,letterSpacing:.5,textTransform:"uppercase",fontFamily:ye},rawButton:{flexDirection:"row",alignItems:"center",gap:4},rawButtonText:{color:I.color.accent,fontSize:11,fontWeight:"700"},sectionBody:{padding:8},editorHint:{color:I.color.textTertiary,fontSize:10,paddingTop:8,paddingHorizontal:4,lineHeight:14},blockedText:{color:I.color.textSecondary,fontSize:12,padding:12,lineHeight:18},infoContainer:{minWidth:200,backgroundColor:I.color.surface,borderRadius:6,borderWidth:1,borderColor:I.color.border,overflow:"hidden"},sectionHeaderTextPlain:{backgroundColor:I.color.surfaceElevated,paddingHorizontal:12,paddingVertical:8,fontWeight:"600",fontSize:12,color:I.color.textSecondary,borderBottomWidth:1,borderBottomColor:I.color.border,letterSpacing:.5,textTransform:"uppercase",fontFamily:ye},infoBody:{padding:12,gap:10},viewerBody:{backgroundColor:I.color.bg,minHeight:60},primitiveText:{color:I.color.text,fontSize:12,fontFamily:ye,padding:14},valueTypeText:{color:I.color.textTertiary,fontSize:10,fontFamily:ye,marginLeft:6},inlineLinkButton:{marginLeft:4},inlineLinkText:{fontSize:10,fontWeight:"600",fontFamily:ye}});import{useMemo as Qn}from"react";import{EntityFilterView as Zn}from"@buoy-gg/shared-ui/web";import{jsx as Xn}from"react/jsx-runtime";var er=["\u2022 count -> hides countAtom from atoms & events","\u2022 auth -> hides authAtom, authStatusAtom","\u2022 user -> hides userAtom from both tabs"];function tr({ignoredPatterns:e,onTogglePattern:t,onAddPattern:a,atoms:r}){let o=Qn(()=>r.map(n=>({name:n.label,color:n.color})),[r]);return Xn(Zn,{entities:o,ignoredPatterns:e,onTogglePattern:t,onAddPattern:a,entityNoun:"ATOMS",entitySingular:"atom",entityKey:"atom",testIDPrefix:u,slug:Ae,howItWorks:"Patterns hide matching atoms from both the Atoms tab and the Events tab. Tap an atom above to quickly add it as a filter.",examples:er,emptyMessage:"No atoms are being watched yet."})}import{Fragment as kt,jsx as g,jsxs as H}from"react/jsx-runtime";function ar({isEnabled:e,searchText:t,totalChanges:a}){let r=ut({subject:"changes",search:t,total:a,capturing:e,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return g(Ee,{...r,testID:`${u}-empty`})}function Ne({visible:e,onClose:t,onBack:a,onMinimize:r,enableSharedModalDimensions:o=false,inline:n=false,initialTab:s,initialSelectedChangeId:i,initialDetailView:d,onChangeSelect:m,onAtomExpand:y}){let E=Ko(),w=Oo("jotai.changes"),[C,T]=_(false),[A,W]=_(s??"atoms"),[z,ie]=_(null),[Z,be]=_(null),[le,se]=_(false),[N,Ce]=_(new Set),{atomChanges:ce,filteredChanges:Y,stats:ve,filter:$r,setFilter:de,atoms:ue,clearChanges:zt,isEnabled:we,toggleCapture:Ht}=ft(),K=Q(()=>N.size===0?Y:Y.filter(l=>!Array.from(N).some(S=>l.atomLabel.toLowerCase().includes(S.toLowerCase()))),[Y,N]),ae=Q(()=>N.size===0?ue:ue.filter(l=>!Array.from(N).some(S=>l.label.toLowerCase().includes(S.toLowerCase()))),[ue,N]),Wt=Q(()=>z?ce.filter(l=>l.atomLabel===z).length:0,[ce,z]),he=Q(()=>K.slice(0,w),[K,w]),Be=Q(()=>Math.max(0,K.length-w),[K.length,w]),jt=Be>0,P=Q(()=>z?he.filter(l=>l.atomLabel===z):he,[he,z]),[ke,X]=_(null),ee=Q(()=>{if(ke===null)return null;let l=P.findIndex(S=>S.id===ke);return l>=0?l:null},[ke,P]),M=ee!==null?P[ee]:null,Ge=Ve(null);ct(()=>{if(!m)return;let l=M?.id??null;l===null||l===Ge.current||(Ge.current=l,m(M))},[M,m]);let Ye=Ve(null);ct(()=>{!i||Ye.current===i||!P.some(l=>l.id===i)||(Ye.current=i,X(i))},[i,P]);let[q,Le]=_(""),[Mt,xe]=_(false),Er=Ve(null),Ft=Ve(null),Ot=D(l=>{},[]),Nt=l=>{Le(l),A==="events"&&de(S=>({...S,searchText:l}))},Kt=D(()=>{Le(""),de(l=>({...l,searchText:""})),xe(false)},[de]),qe=D(l=>{X(l.id)},[]),Jt=D(()=>{T(true)},[]),_t=D(()=>{X(null)},[]),Qe=D(l=>{let S=P[l];S&&X(S.id)},[P]),Ut=D(l=>{ie(l),X(null)},[]),Gt=D(()=>{ie(null),X(null)},[]),Yt=D(l=>{be(l),y?.(l)},[y]),qt=D(()=>{be(null)},[]),Qt=D(()=>ae.reduce((l,S)=>{try{let oe=S.getValue();l[S.label]=me(oe)}catch{l[S.label]=null}return l},{}),[ae]),Zt=D(()=>K.map(l=>({id:l.id,atomLabel:l.atomLabel,timestamp:l.timestamp,prevValue:me(l.prevValue),nextValue:me(l.nextValue),hasValueChange:l.hasValueChange,changedKeys:l.changedKeys})),[K]),Xt=D(()=>P.map(l=>({id:l.id,atomLabel:l.atomLabel,timestamp:l.timestamp,prevValue:me(l.prevValue),nextValue:me(l.nextValue),hasValueChange:l.hasValueChange,changedKeys:l.changedKeys})),[P]),ea=D(l=>{Ce(S=>{let oe=new Set(S);return oe.has(l)?oe.delete(l):oe.add(l),oe})},[]),ta=D(l=>{Ce(S=>new Set([...S,l]))},[]),aa=D(l=>{W(l),ie(null),X(null),se(false),q&&(Le(""),de(S=>({...S,searchText:""}))),xe(false)},[q,de]),Ze=D(l=>l.id,[]),Xe=Q(()=>Vn(P),[P]),et=D(({item:l})=>g(pt,{change:l,onPress:qe,testID:Xe.get(l.id)}),[qe,Xe]),tt=N.size>0,at=()=>le?H(B,{children:[g(B.Navigation,{onBack:()=>se(false)}),g(B.Content,{title:"Filters",centered:true,testID:`${u}-filters-title`})]}):M?H(B,{children:[g(B.Navigation,{onBack:_t}),g(B.Content,{title:`${M.atomLabel}/${M.category}`,centered:true,testID:`${u}-detail-title`})]}):z?H(B,{children:[g(B.Navigation,{onBack:Gt}),g(B.Content,{title:`${z} History`,centered:true,testID:`${u}-history-title`}),g(B.Actions,{children:g(Pe,{value:Xt,disabled:P.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`})})]}):Z?H(B,{children:[g(B.Navigation,{onBack:qt}),g(B.Content,{title:Z,centered:true,testID:`${u}-atom-detail-title`})]}):H(B,{children:[a&&g(B.Navigation,{onBack:a}),g(B.Content,{title:"",children:Mt?g(B.Search,{value:q,onChangeText:Nt,onCancel:Kt,placeholder:A==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${u}-search-field`,containerTestID:`${u}-search`,clearTestID:`${u}-search-clear`,onBlur:()=>{q.length===0&&xe(false)}}):g(Eo,{tabs:[{key:"atoms",label:`Atoms${ae.length>0?` (${ae.length})`:""}`},{key:"events",label:`Events${K.length>0?` (${K.length})`:""}`}],activeTab:A,onTabChange:aa,testIDPrefix:`${u}-tab`})}),H(B.Actions,{children:[g(re,{onPress:()=>xe(true),style:$.headerActionButton,testID:`${u}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:g(Ro,{size:14,color:k.color.textSecondary})}),g(re,{onPress:()=>se(true),style:[$.headerActionButton,tt&&$.headerActionButtonActive],testID:`${u}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:g(zo,{size:14,color:tt?k.color.accent:k.color.textSecondary})}),A==="atoms"&&g(Pe,{value:Qt,disabled:ae.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`}),A==="events"&&H(kt,{children:[g(Pe,{value:Zt,disabled:K.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`}),g(Mo,{isEnabled:we,onToggle:Ht,accessibilityLabel:"Toggle Jotai atom capture",testID:`${u}-power`}),g(Fo,{onPress:zt,disabled:K.length===0,buttonStyle:$.headerActionButton,testID:`${u}-clear`})]})]})]}),oa=()=>{if(le)return g(tr,{ignoredPatterns:N,onTogglePattern:ea,onAddPattern:ta,atoms:ue});if(M&&ee!==null)return g(Vt,{change:M,changes:P,selectedIndex:ee,onIndexChange:Qe,disableInternalFooter:true,initialView:d});if(z)return P.length>0?g($e,{testID:`${u}-history-list`,data:P,renderItem:et,keyExtractor:Ze,contentContainerStyle:$.listContent,showsVerticalScrollIndicator:true,...gt}):g(Ee,{testID:`${u}-history-empty`,...ut({subject:"changes",search:q,total:q.trim()?Wt:0,capturing:we,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${z} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${z}.`}})});if(Z){let l=ue.find(S=>S.label===Z)??null;return l?g(Bt,{atom:l,onViewHistory:Ut}):g(Ee,{testID:`${u}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${Z} is not in the registry any more.`})}return A==="atoms"?g(Hn,{atoms:ae,searchQuery:q,onOpenAtom:Yt}):H(kt,{children:[!we&&H(c,{style:$.disabledBanner,testID:`${u}-banner-disabled`,children:[g(Ho,{size:14,color:k.color.warning}),g(b,{style:$.disabledText,children:"Atom capture is disabled"})]}),jt&&H(re,{style:$.lockedBanner,onPress:Jt,activeOpacity:.8,testID:`${u}-locked`,accessibilityRole:"button",children:[H(b,{style:$.lockedText,testID:`${u}-locked-text`,children:[Be," older"," ",Be===1?"change":"changes"," locked"]}),g(c,{style:$.upgradeBadge,children:g(b,{style:$.upgradeBadgeText,children:"UPGRADE"})})]}),he.length>0?g($e,{ref:Ft,testID:`${u}-list`,data:he,renderItem:et,keyExtractor:Ze,contentContainerStyle:$.listContent,showsVerticalScrollIndicator:true,...gt}):g(ar,{isEnabled:we,searchText:q,totalChanges:ve.totalChanges})]})},na=o?Wo.modal.root():"buoy-jotai-modal";if(!e)return null;let ot=M&&ee!==null?g(Tt,{change:M,changes:P,selectedIndex:ee,onIndexChange:Qe}):null,ra=M&&P.length>1?68:0,ia=!le&&!(M&&ee!==null)&&(z!=null||A==="events"||A==="atoms"),nt=g(c,{style:$.container,children:oa()}),rt=g(jo,{visible:C,onClose:()=>T(false),featureName:"Full Atom History"});return n?H(ht,{children:[H(c,{style:$.inlineRoot,children:[g(c,{style:$.inlineHeader,...No,children:at()}),nt,ot]}),rt]}):H(ht,{children:[g($o,{visible:e,onClose:t,onMinimize:r,persistenceKey:na,header:{showToggleButton:true,customContent:at()},onModeChange:Ot,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:ia,styles:{},footer:ot,footerHeight:ra,children:nt}),rt]})}function or(e={}){return g(Ne,{...e,inline:true,visible:true,onClose:()=>{}})}var $=ne.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:Po.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:k.color.buttonSurface,borderWidth:1,borderColor:k.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:k.color.accentSoft,borderColor:k.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:k.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:k.color.warning+"20"},disabledText:{color:k.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:k.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:k.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:k.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:k.color.accentBorder},lockedText:{color:k.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:k.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:k.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});import{JotaiIcon as Ke,JOTAI_ICON_COLOR as nr}from"@buoy-gg/shared-ui/web";import{createToolFactory as rr,defineToolPreset as ir}from"@buoy-gg/shared-ui/web";import{jsx as Lt}from"react/jsx-runtime";var $t=ir({id:"jotai",name:"JOTAI",description:"Jotai atom & state inspector",slot:"both",icon:({size:e})=>Lt(Ke,{size:e}),component:Ne,props:{enableSharedModalDimensions:false}}),lr=rr($t,e=>({enableSharedModalDimensions:e.enableSharedModalDimensions??false}),e=>({icon:({size:t})=>Lt(Ke,{size:t,color:e.iconColor})}));import{getDefaultStore as sr}from"jotai/vanilla";import{atom as cr}from"jotai/vanilla";var dr=cr(null),Je=dr.write,Et=typeof Je=="function"?String(Je):null;function ur(e){let t=e,a=t?.write;return typeof a!="function"?"action":a===Je||t!==null&&"init"in t&&Et!==null&&String(a)===Et?"value":"action"}function Pt(e,t,a){let r=a?.enabled!==false,o=[];for(let[n,s]of Object.entries(t)){let i=s,d=Symbol.for(`@@buoy-jotai/watched/${n}`);if(i[d])continue;i[d]=true;let m;try{m=e.get(s)}catch{m=void 0}let y=typeof s.write=="function",E=e.set&&y?C=>{e.set(s,C)}:void 0;p.registerAtom(n,()=>{try{return e.get(s)}catch{return}},E,y?ur(s):void 0),r&&p.addAtomChange({atomLabel:n,prevValue:void 0,nextValue:m,category:"initial"});let w=e.sub(s,()=>{try{let C=e.get(s);p.addAtomChange({atomLabel:n,prevValue:m,nextValue:C,category:"write"}),m=C}catch{}});o.push(()=>{w(),delete i[d],p.unregisterAtom(n)})}return()=>o.forEach(n=>n())}function hr(e,t){let a=sr();return Pt(a,e,t)}function gr(e){return p.getAtom(e)!==void 0}import{WIRE_DETAIL_LIMIT_BYTES as mr,createSyncAdapter as fr,capDetail as pr,detailByIdAction as yr,expandKeyedArrays as br,memoByIdentity as Cr,onDeviceMarker as vr,patchFromPath as wr,readParams as _e,readPath as xr,refusalText as Vr,shapeSummary as Ie,suggestedPatch as Tr,toWire as Sr,typedEditViolations as Ar,unshapedLists as Ir}from"@buoy-gg/shared-ui/web";var De=vr("Value","Atom values stay on the device \u2014 fetched on demand via getChangeDetail / getAtomValue."),Ue=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Rt(e,t){if(!Ue(e)||!Ue(t))return t;let a={...e};for(let[r,o]of Object.entries(t))a[r]=r in e?Rt(e[r],o):o;return a}function Dr(e,t){let a=e;for(let r of t.split(".")){if(!Ue(a)||!(r in a))return false;a=a[r]}return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"}var Br=Cr(e=>({...e,prevValue:De,nextValue:De})),kr=e=>Sr(e,De),Lr=fr({version:2,getSnapshot:()=>({changes:p.getAtomChanges().map(Br),atoms:p.getAtomSnapshots().map(e=>({...e,currentValue:kr(e.currentValue)}))}),subscribe:[e=>p.subscribe(e),e=>p.subscribeToAtoms(e)],actions:{clearEvents:()=>{p.clearAtomChanges()},getChangeDetail:yr(e=>p.getAtomChangeById(e),(e,t)=>({prevValue:t(e.prevValue),nextValue:t(e.nextValue)})),getAtomValue:e=>{let{label:t,path:a}=_e(e);if(!t)return{found:false,reason:"missing label"};let r=p.getAtom(t);if(!r)return{found:false,reason:"unknown label"};let o;try{o=r.getValue()}catch{o=void 0}try{JSON.stringify(o)}catch{return{found:true,label:t,currentValue:De}}if(a){let n=xr(o,a);return n.ok?{found:true,label:t,path:a,shape:Ie(n.value),currentValue:n.value}:{found:false,reason:n.error}}return{found:true,label:t,...Ie(o)?{shape:Ie(o)}:{},currentValue:pr(o,mr)}},listAtoms:e=>{let{includeValues:t=false,limit:a}=_e(e),r=p.getAtoms(),o=(typeof a=="number"&&a>0?r.slice(0,a):r).map(n=>{let s;if(t)try{s=n.getValue()}catch{s=void 0}let i;try{i=Ie(n.getValue())}catch{i=void 0}return{label:n.label,changes:n.changeCount,writable:typeof n.setValue=="function",...i?{shape:i}:{},...t?{currentValue:s}:{}}});return{atoms:o,total:r.length,returned:o.length,includedValues:t}},setAtom:e=>{let{label:t,value:a,merge:r,path:o,force:n}=_e(e);if(!t)throw new Error("setAtom requires a `label`");let s=p.getAtom(t),i;try{i=s?.getValue()}catch{i=void 0}let d=a,m=[],y=[],E=r===true||o!==void 0;if(o!==void 0){if(a===void 0)return{ok:false,error:`Refused: sent \`path\` without \`value\`. Say what to set "${o}" to.`};let w=wr(i,o,a);if(!w.ok)return{ok:false,error:`Refused: ${w.error}`};d=w.patch}if(!n&&E&&i!==void 0){let w=br(i,d);if(w.error)return{ok:false,error:`Refused: ${w.error}`};d=w.patch,m=w.notes,y=Ir(i).filter(T=>Dr(d,T));let C=Ar(i,d,{noun:"atom"});if(C.length){let T=Tr(d,C);return{ok:false,error:Vr(C,"atom",T),violations:C,...T?{suggestedValue:T}:{}}}}return p.setAtomValue(t,E?Rt(i,d):d),{ok:true,...o!==void 0?{path:o}:{},...m.length?{keyed:m}:{},...y.length?{unchecked:y.map(w=>`\`${w}\` was empty, so nothing knows what its items look like and the shape of what you added was NOT checked.`)}:{}}}}});export{nr as JOTAI_ICON_COLOR,pt as JotaiAtomChangeItem,Vt as JotaiAtomDetailContent,Tt as JotaiAtomDetailFooter,Bt as JotaiAtomValueDetailContent,Ke as JotaiIcon,Ne as JotaiModal,or as JotaiToolView,lr as createJotaiTool,gr as isAtomWatched,p as jotaiStateStore,Lr as jotaiSyncAdapter,$t as jotaiToolPreset,ft as useJotaiAtomChanges,Pt as watchAtoms,hr as watchDefaultStoreAtoms};
|
|
1
|
+
"use client";var lt=Object.defineProperty;var sa=Object.getOwnPropertyDescriptor;var ca=Object.getOwnPropertyNames;var da=Object.prototype.hasOwnProperty;var ua=(e,t)=>{for(var a in t)lt(e,a,{get:t[a],enumerable:true})},st=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ca(t))!da.call(e,o)&&o!==a&<(e,o,{get:()=>t[o],enumerable:!(r=sa(t,o))||r.enumerable});return e},ha=(e,t,a)=>(st(e,t,"default"),a&&st(a,t,"default"));var Rr=(()=>{try{let e=globalThis.Capacitor;if(e&&typeof e.isNativePlatform=="function"&&e.isNativePlatform())return e.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{createRestoreScope as ga,emptyRestoreResult as ma,failedRestore as fa,registerStateSnapshotProvider as pa,unionKeys as ya}from"@buoy-gg/shared-ui/web";import{boundedDeepEqual as ba}from"@buoy-gg/shared-ui/web/dataViewer";import{ChangeLog as Ca,entityColor as va,formatValuePreview as wa,shallowDiffSummary as xa}from"@buoy-gg/shared-ui/web";var Va={count:"#10B981",auth:"#8B5CF6",user:"#3B82F6",cart:"#EC4899",app:"#6366F1",ui:"#F59E0B",settings:"#14B8A6",theme:"#06B6D4",nav:"#F97316",form:"#EF4444",modal:"#A855F7",filter:"#84CC16"};function ct(e){return va(e,Va)}function Ta(e,t=40){return wa(e,{maxLength:t,functionLabel:"(fn)"})}var Sa=xa,Aa=class extends Ca{constructor(){super(...arguments);this.atoms=new Map;this.atomListeners=new Set}addAtomChange(e){if(!this.canRecord())return;let{atomLabel:t,prevValue:a,nextValue:r,category:o="write"}=e,n=a!==r,{summary:s,changedKeys:i,changedCount:d}=Sa(a,r),m=Ta(r),y={id:this.nextId(),atomLabel:t,timestamp:Date.now(),prevValue:a,nextValue:r,hasValueChange:n,category:o,changedKeys:i,changedKeysCount:d,diffSummary:s,valuePreview:m,isSlowUpdate:false};this.push(y);let E=this.atoms.get(t);E&&E.changeCount++,this.notifyListeners(),this.notifyAtomListeners()}getAtomChanges(){return this.getAll()}getAtomChangeById(e){return this.getById(e)}clearAtomChanges(){for(let e of this.atoms.values())e.changeCount=0;this.clear(),this.notifyAtomListeners()}getAtomSnapshots(){return Array.from(this.atoms.values()).map(e=>{let t;try{t=e.getValue()}catch{t=void 0}return{label:e.label,changeCount:e.changeCount,color:e.color,currentValue:t,writeKind:e.writeKind}})}replaceFromSnapshot(e,t){if(!this.getEnabled())return;let a=new Map;for(let n of this.items){let s=n.prevValue;(!s||s.__buoyValueOnDevice!==true)&&a.set(n.id,n)}let r=e.slice(0,this.max).map(n=>{let s=a.get(n.id),i=n.prevValue;return s&&i?.__buoyValueOnDevice===true?{...n,prevValue:s.prevValue,nextValue:s.nextValue}:n}),o=new Map;for(let[n,s]of this.atoms)try{let i=s.getValue(),d=i;(!d||d.__buoyValueOnDevice!==true)&&o.set(n,i)}catch{}this.atoms=new Map(t.map(n=>{let s=n.currentValue,i=o.get(n.label),d=i!==void 0&&s?.__buoyValueOnDevice===true?i:n.currentValue;return[n.label,{label:n.label,changeCount:n.changeCount,color:n.color,getValue:()=>d,writeKind:n.writeKind}]})),this.setItems(r),this.notifyAtomListeners()}hydrateChange(e,t){this.hydrateById(e,t)}hydrateAtomValue(e,t){let a=this.atoms.get(e);a&&(this.atoms.set(e,{...a,getValue:()=>t}),this.notifyAtomListeners())}registerAtom(e,t,a,r){if(this.atoms.has(e))return;let o={label:e,changeCount:0,color:ct(e),getValue:t,setValue:a,writeKind:r};this.atoms.set(e,o),this.notifyAtomListeners()}setAtomValue(e,t){let a=this.atoms.get(e);if(!a)throw new Error(`Atom "${e}" is not registered`);if(!a.setValue)throw new Error(`Atom "${e}" is read-only (derived) \u2014 cannot set`);a.setValue(t)}unregisterAtom(e){this.atoms.delete(e),this.notifyAtomListeners()}getAtoms(){return Array.from(this.atoms.values())}getAtom(e){return this.atoms.get(e)}getAtomColor(e){return this.atoms.get(e)?.color??ct(e)}filterAtomChanges(e){let t=this.getAll();if(e.searchText){let a=e.searchText.toLowerCase();t=t.filter(r=>r.atomLabel.toLowerCase().includes(a)||r.valuePreview.toLowerCase().includes(a)||r.changedKeys.some(o=>o.toLowerCase().includes(a)))}return e.atomLabels&&e.atomLabels.length>0&&(t=t.filter(a=>e.atomLabels.includes(a.atomLabel))),e.onlyWithChanges&&(t=t.filter(a=>a.hasValueChange)),t}getStats(){let e=this.items.length,t=this.items.filter(a=>a.hasValueChange).length;return{totalChanges:e,changesWithValueChange:t,changesWithoutValueChange:e-t,atomCount:this.atoms.size}}getUniqueAtomLabels(){return Array.from(this.atoms.keys()).sort()}setMaxChanges(e){this.setMax(e)}subscribeToAtoms(e){return this.atomListeners.add(e),()=>this.atomListeners.delete(e)}notifyAtomListeners(){let e=this.getAtoms();this.atomListeners.forEach(t=>t(e))}},p=new Aa;function Ia(){let e=p.getAtoms();if(e.length===0)return{canCapture:false,canRestore:false,detail:"No Jotai atoms registered \u2014 pass your atoms to watchAtoms() / watchDefaultStoreAtoms()"};let t=e.filter(a=>a.setValue).length;return{canCapture:true,canRestore:t>0,detail:t<e.length?`${e.length-t} derived atom(s) recompute automatically and are not restored`:void 0}}async function Da(){let e=[],t={},a=0;for(let r of p.getAtoms())try{let o=r.getValue();if(typeof o=="function"){e.push(`atom "${r.label}": function value not capturable`);continue}r.setValue||(a+=1),t[r.label]={value:o,writable:!!r.setValue}}catch(o){e.push(`atom "${r.label}": capture failed (${String(o)})`)}return a>0&&e.push(`${a} derived atom(s) captured for inspection only (recompute on restore)`),{data:{atoms:t},warnings:e}}async function Ba(e,t){let a=e,r=ga(t),o=ma();if(!a?.atoms)return fa("empty jotai snapshot");let n=0;for(let[i,d]of Object.entries(a.atoms)){if(!r.allows(i))continue;if(!d.writable){n+=1;continue}let m=p.getAtom(i);if(!m){o.skipped.push({id:i,reason:"atom not registered (renamed, or unwatched since snapshot?)"});continue}if(!m.setValue){o.skipped.push({id:i,reason:"atom is now read-only (derived)"});continue}try{m.setValue(d.value),o.applied+=1}catch(y){o.skipped.push({id:i,reason:String(y)}),o.ok=false}}n>0&&o.warnings.push(`${n} derived atom(s) left to recompute`);let s=r.excludedWarning("atom(s)");return s&&o.warnings.push(s),o}async function ka(e,t){let a=e?.atoms??{},r=t===void 0,o={};if(r)for(let i of p.getAtoms())try{o[i.label]={value:i.getValue(),writable:!!i.setValue}}catch{}else Object.assign(o,t?.atoms??{});let n=[],s=[];for(let i of ya(o,a)){if(!(i in a)){r?s.push(`atom "${i}" not in snapshot \u2014 untouched`):n.push({key:i,label:i,verdict:"removed",oldValue:o[i]?.value});continue}let d=a[i],m=i in o&&ba(o[i].value,d.value);if(!d.writable){n.push({key:i,label:i,verdict:m?"unchanged":"recomputes",reason:m?void 0:"derived atom \u2014 recomputes from its sources",oldValue:o[i]?.value,newValue:d.value});continue}if(r){let y=p.getAtom(i);if(!y){n.push({key:i,label:i,verdict:"wont-apply",reason:"atom not registered (renamed, or unwatched since snapshot?)"});continue}if(!y.setValue){n.push({key:i,label:i,verdict:"wont-apply",reason:"atom is now read-only (derived)"});continue}}i in o?m?n.push({key:i,label:i,verdict:"unchanged"}):n.push({key:i,label:i,verdict:"changed",oldValue:o[i].value,newValue:d.value}):n.push({key:i,label:i,verdict:"added",newValue:d.value})}return{items:n,notes:s}}pa({id:"jotai",label:"Jotai",status:Ia,capture:Da,restore:Ba,previewItems:ka});import{useState as _,useMemo as Q,useRef as Ve,useCallback as D,useEffect as dt}from"react";var ut={};ua(ut,{AccessibilityInfo:()=>Pa,ActivityIndicator:()=>Bo,Alert:()=>$o,Animated:()=>Ra,AppRegistry:()=>Ha,AppState:()=>Wa,Appearance:()=>za,BackHandler:()=>Fa,Button:()=>ko,CheckBox:()=>to,Clipboard:()=>Ma,DeviceEventEmitter:()=>yo,Dimensions:()=>ja,Easing:()=>Oa,FlatList:()=>Ee,I18nManager:()=>Na,Image:()=>ao,ImageBackground:()=>oo,InteractionManager:()=>Ja,Keyboard:()=>Ka,KeyboardAvoidingView:()=>no,LayoutAnimation:()=>_a,Linking:()=>Ua,LogBox:()=>po,Modal:()=>Io,NativeEventEmitter:()=>Ga,NativeModules:()=>Ea,PanResponder:()=>Ya,Picker:()=>ro,PixelRatio:()=>qa,Platform:()=>Qa,Pressable:()=>Ao,ProgressBar:()=>io,RefreshControl:()=>lo,SafeAreaView:()=>so,ScrollView:()=>he,SectionList:()=>co,Share:()=>Za,StatusBar:()=>uo,StyleSheet:()=>ne,Switch:()=>Do,Text:()=>b,TextInput:()=>Vo,Touchable:()=>ho,TouchableHighlight:()=>To,TouchableNativeFeedback:()=>go,TouchableOpacity:()=>re,TouchableWithoutFeedback:()=>So,UIManager:()=>Xa,Vibration:()=>eo,View:()=>c,VirtualizedList:()=>mo,YellowBox:()=>fo,findNodeHandle:()=>Lo,unstable_createElement:()=>$a,useColorScheme:()=>bo,useLocaleContext:()=>Co,useWindowDimensions:()=>vo});ha(ut,La);import*as La from"react-native-web";import{unstable_createElement as $a,NativeModules as Ea,AccessibilityInfo as Pa,Animated as Ra,Appearance as za,AppRegistry as Ha,AppState as Wa,BackHandler as Fa,Clipboard as Ma,Dimensions as ja,Easing as Oa,I18nManager as Na,Keyboard as Ka,InteractionManager as Ja,LayoutAnimation as _a,Linking as Ua,NativeEventEmitter as Ga,PanResponder as Ya,PixelRatio as qa,Platform as Qa,Share as Za,StyleSheet as ne,UIManager as Xa,Vibration as eo,CheckBox as to,FlatList as Ee,Image as ao,ImageBackground as oo,KeyboardAvoidingView as no,Picker as ro,ProgressBar as io,RefreshControl as lo,SafeAreaView as so,SectionList as co,StatusBar as uo,Touchable as ho,TouchableNativeFeedback as go,VirtualizedList as mo,YellowBox as fo,LogBox as po,DeviceEventEmitter as yo,useColorScheme as bo,useLocaleContext as Co,useWindowDimensions as vo}from"react-native-web";import*as F from"react-native-web";import{createElement as wo,forwardRef as xo}from"react";function j(e){let t=xo((r,o)=>{let{accessibilityState:n,accessibilityValue:s,...i}=r;for(let d of["busy","checked","disabled","expanded","selected"])n?.[d]!==void 0&&i[`aria-${d}`]===void 0&&(i[`aria-${d}`]=n[d]);for(let[d,m]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))s?.[d]!==void 0&&i[`aria-${m}`]===void 0&&(i[`aria-${m}`]=s[d]);return wo(e,{...i,ref:o})}),a=e.State;return a&&Object.assign(t,{State:a}),t.displayName=e.displayName??e.name??"NativeWebView",t}var c=j(F.View),b=j(F.Text),Vo=j(F.TextInput),re=j(F.TouchableOpacity),To=j(F.TouchableHighlight),So=j(F.TouchableWithoutFeedback),Ao=j(F.Pressable),he=j(F.ScrollView),Io=j(F.Modal),Do=j(F.Switch),Bo=j(F.ActivityIndicator),ko=j(F.Button),Lo=F.findNodeHandle,$o={alert(e,t,a,r){if(typeof document>"u")return;let o=document.createElement("dialog");o.dataset.buoyRoot="",o.setAttribute("aria-label",e),o.style.cssText="position:fixed;inset:0;margin:auto;width:min(440px,90vw);padding:24px;border:1px solid #475569;border-radius:14px;background:#17212e;color:#f1f5f9;font:14px system-ui;box-shadow:0 20px 80px #0008;z-index:2147483647";let n=document.createElement("h2");if(n.textContent=e,n.style.cssText="font-size:18px;margin:0 0 12px",o.appendChild(n),t){let m=document.createElement("p");m.textContent=t,m.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",o.appendChild(m)}let s=document.createElement("div");s.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let i=a?.length?a:[{text:"OK"}],d=()=>{o.close?.(),o.remove()};for(let m of i){let y=document.createElement("button");y.type="button",y.textContent=m.text??"OK",y.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${m.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,y.onclick=()=>{d(),m.onPress?.()},s.appendChild(y)}o.addEventListener("cancel",m=>{m.preventDefault(),r?.cancelable!==false&&(d(),r?.onDismiss?.())}),o.appendChild(s),document.body.appendChild(o),o.showModal?o.showModal():o.setAttribute("open","")}};import{JsModal as Eo,ModalHeader as B,TabSelector as Po,macOSColors as Ro,night as k,Search as zo,Filter as Ho,Power as Wo,ToolEmptyState as Pe,resolveListEmptyState as ht,devToolsStorageKeys as Fo,ProUpgradeModal as Mo,PowerToggleButton as jo,ToolbarCopyButton as Re,ToolbarClearButton as Oo,truncatePayload as ge,TickProvider as gt,useLimit as No,windowDragProps as Ko,EVENT_LIST_PRESET as mt}from"@buoy-gg/shared-ui/web";import{useIsPro as Jo}from"@buoy-gg/license/web";import{useCallback as _o,useMemo as ft}from"react";import{useChangeLog as Uo,useSubscribedValue as Go}from"@buoy-gg/shared-ui/web";function Yo(e,t){let a=e;if(t.searchText){let r=t.searchText.toLowerCase();a=a.filter(o=>o.atomLabel.toLowerCase().includes(r)||o.valuePreview.toLowerCase().includes(r)||o.changedKeys.some(n=>n.toLowerCase().includes(r)))}return t.atomLabels&&t.atomLabels.length>0&&(a=a.filter(r=>t.atomLabels.includes(r.atomLabel))),t.onlyWithChanges&&(a=a.filter(r=>r.hasValueChange)),a}var qo=()=>p.getAtoms(),Qo=e=>p.subscribeToAtoms(e);function pt(){let e=Uo(p,{filterItems:Yo}),t=Go(qo,Qo),a=ft(()=>{let n=e.items.length,s=e.items.filter(i=>i.hasValueChange).length;return{totalChanges:n,changesWithValueChange:s,changesWithoutValueChange:n-s,atomCount:t.length}},[e.items,t]),r=ft(()=>p.getUniqueAtomLabels(),[t]),o=_o(n=>p.getAtomChangeById(n),[]);return{atomChanges:e.items,filteredChanges:e.filteredItems,filter:e.filter,setFilter:e.setFilter,stats:a,atoms:t,clearChanges:p.clearAtomChanges.bind(p),isEnabled:e.isEnabled,toggleCapture:e.toggleCapture,atomLabels:r,getChangeById:o}}import{memo as Zo}from"react";import{ChangeRow as Xo,night as en}from"@buoy-gg/shared-ui/web";import{jsx as tn}from"react/jsx-runtime";function an(e,t){return t}function on(e,t){return e==="initial"?en.color.textTertiary:p.getAtomColor(t)}function ze(e,t=20){if(e===void 0)return"undefined";if(e===null)return"null";if(typeof e=="boolean"||typeof e=="number")return String(e);if(typeof e=="string")return`"${e.length>t?e.slice(0,t-1)+"\u2026":e}"`;if(Array.isArray(e))return e.length===0?"[]":`[${e.length} item${e.length===1?"":"s"}]`;if(typeof e=="object"){let a=Object.keys(e);return a.length===0?"{}":`{${a.slice(0,2).join(", ")}${a.length>2?"\u2026":""}}`}return String(e).slice(0,t)}function nn(e){return e.hasValueChange?`${ze(e.prevValue)} \u2192 ${ze(e.nextValue)}`:"no change"}function rn(e){return e.category==="initial"?"INIT":"WRITE"}function ln(e){let t=e.nextValue;return typeof t=="object"&&t!==null&&!Array.isArray(t)?e.changedKeys.length>0&&e.changedKeys.length<=3?e.changedKeys.join(", "):e.changedKeys.length>3?`${e.changedKeys.slice(0,2).join(", ")} +${e.changedKeys.length-2}`:e.valuePreview||"atom()":ze(t)}var yt=Zo(function({change:e,onPress:t,testID:a}){let r=on(e.category,e.atomLabel),o=an(e.category,e.atomLabel),n=nn(e),s=ln(e),i=rn(e);return tn(Xo,{statusColor:r,statusLabel:o,sublabel:n,primaryText:s,timestamp:e.timestamp,badgeText:i,changed:e.hasValueChange,onPress:()=>t(e),testID:a})});import{memo as sn,useState as He,useCallback as me,useMemo as bt}from"react";import{buoyColors as fe,night as v,EventStepperFooter as Ct,formatRelativeTime as Te,parseValue as Se,Info as cn,Zap as vt,FileText as dn,Database as un,GitBranch as hn,copyToClipboard as gn,ProUpgradeModal as mn,DiffModeTabs as fn,CompareBar as pn,DetailViewToggle as yn,monoFont as K}from"@buoy-gg/shared-ui/web";import{DataViewer as bn,SplitDiffViewer as Cn,TreeDiffViewer as vn,diffThemes as wn}from"@buoy-gg/shared-ui/web/dataViewer";import{useIsPro as xn}from"@buoy-gg/license/web";var u="buoy-jotai";function Ae(e){return String(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"unknown"}function Vn(e,t){return`${u}-row-${Ae(e)}-${t}`}function wt(e){return`${u}-atom-${Ae(e)}`}function Tn(e){let t=new Map,a=new Map;for(let r of e){let o=(t.get(r.atomLabel)??0)+1;t.set(r.atomLabel,o),a.set(r.id,Vn(r.atomLabel,o))}return a}import{jsx as h,jsxs as R}from"react/jsx-runtime";var Sn=[{key:"change",label:"CHANGE",icon:dn},{key:"value",label:"VALUE",icon:un},{key:"diff",label:"DIFF",icon:hn}],An=["diff"];function In(e){switch(e){case"initial":return{label:"INITIAL",color:v.color.textTertiary,bgColor:v.color.textTertiary+"26"};default:return{label:"WRITE",color:fe.success,bgColor:fe.success+"26"}}}function Dn(e){let t=new Date(e),a=t.getHours().toString().padStart(2,"0"),r=t.getMinutes().toString().padStart(2,"0"),o=t.getSeconds().toString().padStart(2,"0"),n=t.getMilliseconds().toString().padStart(3,"0");return`${a}:${r}:${o}.${n}`}function xt(e){return new Date(e).toLocaleTimeString("en-US",{hour12:false,hour:"2-digit",minute:"2-digit",second:"2-digit"})}function Bn(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"array":typeof e}function Vt(e){return e==="initial"?"INIT":"WRITE"}var kn=[{key:"tree",label:"TREE VIEW"},{key:"split",label:"SPLIT VIEW"}],Ln=sn(function({change:e}){let t=xn(),[a,r]=He(false),o=In(e.category),n=p.getAtomColor(e.atomLabel),s=me(async()=>{if(!t){r(true);return}await gn(e.nextValue)},[e.nextValue,t]);return R(he,{style:f.container,contentContainerStyle:f.content,showsVerticalScrollIndicator:false,testID:`${u}-detail-scroll`,children:[R(c,{style:f.card,testID:`${u}-info-card`,children:[h(c,{style:f.sectionHeader,children:R(c,{style:f.sectionHeaderLeft,children:[h(cn,{size:14,color:v.color.accent}),h(b,{style:f.sectionTitle,children:"CHANGE INFO"})]})}),R(c,{style:f.cardContent,children:[R(c,{style:f.infoRow,children:[h(b,{style:f.infoLabel,children:"Atom"}),h(b,{style:[f.infoValue,f.infoValueMono,{color:n}],numberOfLines:1,ellipsizeMode:"middle",testID:`${u}-info-atom`,children:e.atomLabel})]}),R(c,{style:f.infoRow,children:[h(b,{style:f.infoLabel,children:"Time"}),h(b,{style:[f.infoValue,f.infoValueMono],testID:`${u}-info-time`,children:Dn(e.timestamp)})]}),R(c,{style:f.badgeRow,children:[h(c,{style:[f.categoryBadge,{backgroundColor:o.bgColor}],children:h(b,{style:[f.categoryText,{color:o.color}],testID:`${u}-info-category`,children:o.label})}),e.hasValueChange?R(c,{style:f.changesBadge,children:[h(vt,{size:10,color:fe.success}),h(b,{style:f.changesText,testID:`${u}-info-changes`,children:e.diffSummary||"changed"})]}):h(c,{style:f.noChangesBadge,children:h(b,{style:f.noChangesText,testID:`${u}-info-no-changes`,children:"no change"})})]})]})]}),e.changedKeys.length>0&&R(c,{style:f.card,testID:`${u}-keys-card`,children:[R(c,{style:f.sectionHeader,children:[R(c,{style:f.sectionHeaderLeft,children:[h(vt,{size:14,color:v.color.accent}),h(b,{style:f.sectionTitle,children:"CHANGED KEYS"})]}),h(c,{style:f.countBadge,children:h(b,{style:f.countText,testID:`${u}-keys-count`,children:e.changedKeys.length})})]}),h(c,{style:f.cardContent,children:h(c,{style:f.keysContainer,children:e.changedKeys.map(i=>h(c,{style:f.keyBadge,children:h(b,{style:f.keyText,testID:`${u}-key-${Ae(i)}`,children:i})},i))})})]}),h(c,{style:f.actionsRow,children:h(c,{style:[f.actionButton,f.actionButtonCopy],onTouchEnd:s,testID:`${u}-copy-value`,accessibilityRole:"button",accessibilityLabel:"Copy value",children:h(b,{style:[f.actionButtonText,{color:v.color.accent}],children:"COPY VALUE"})})}),h(mn,{visible:a,onClose:()=>r(false),featureName:"Copy"})]})});function Tt({change:e,changes:t,selectedIndex:a,onIndexChange:r,disableInternalFooter:o=false,initialView:n="change"}){let[s,i]=He(n),[d,m]=He("tree"),y=t.length,E=p.getAtomColor(e.atomLabel),w=Vt(e.category),C=Bn(Se(e.nextValue)),T=y-a,A=a<y-1?a+1:null,W=A!==null?t[A]:null,z=T-1,ie=bt(()=>({index:A??0,label:z>0?`#${z}`:"Initial",timestamp:W?xt(W.timestamp):"",relativeTime:W?Te(new Date(W.timestamp)):"value",badge:W?h(c,{style:[L.changeBadgeSmall,{backgroundColor:`${p.getAtomColor(W.atomLabel)}20`}],children:h(b,{style:[L.changeTextSmall,{color:p.getAtomColor(W.atomLabel)}],children:Vt(W.category)})}):void 0}),[A,W,z]),Z=bt(()=>({index:a,label:`#${T}`,timestamp:xt(e.timestamp),relativeTime:Te(new Date(e.timestamp)),badge:h(c,{style:[L.changeBadgeSmall,{backgroundColor:`${E}20`}],children:h(b,{style:[L.changeTextSmall,{color:E}],children:w})})}),[a,e.timestamp,E,w,T]),ye=me(()=>{let Y=Se(e.nextValue);return R(c,{style:L.contentCard,testID:`${u}-value-card`,children:[R(c,{style:L.valueHeader,children:[h(b,{style:L.valueLabel,children:"VALUE AFTER CHANGE"}),R(c,{style:L.valueHeaderBadges,children:[h(c,{style:[L.changeBadge,{backgroundColor:`${E}20`}],children:h(b,{style:[L.changeText,{color:E}],children:w})}),h(c,{style:L.typeBadge,children:h(b,{style:L.typeText,testID:`${u}-value-type`,children:C.toUpperCase()})})]})]}),h(c,{style:f.dataViewerContainer,children:h(bn,{title:"",data:Y,showTypeFilter:true,rawMode:true,initialExpanded:true})})]})},[e.nextValue,E,w,C]),le=me(()=>{let Y=Se(e.prevValue),Ce=Se(e.nextValue);return d==="split"?h(he,{style:{flex:1},showsVerticalScrollIndicator:true,children:h(Cn,{oldValue:Y,newValue:Ce,theme:wn.devToolsDefault,options:{hideLineNumbers:false,disableWordDiff:false,showDiffOnly:false,compareMethod:"words",contextLines:3},showThemeName:false})}):h(vn,{oldValue:Y,newValue:Ce})},[e.prevValue,e.nextValue,d]),se=me(()=>{r(Math.min(y-1,a+1))},[a,y,r]),N=me(()=>{r(Math.max(0,a-1))},[a,r]),be=e.prevValue===void 0,ce=!o&&y>1;return R(c,{style:L.container,children:[h(yn,{views:Sn,activeView:s,onViewChange:i,disabledKeys:be?An:void 0,testIDPrefix:u}),R(c,{style:[L.contentArea,ce&&L.contentAreaFooterPad],children:[s==="change"&&h(Ln,{change:e}),s==="value"&&h(c,{style:L.stateContainer,children:ye()}),s==="diff"&&R(c,{style:L.diffContainer,testID:`${u}-diff`,children:[h(fn,{tabs:kn,activeTab:d,onTabChange:m,testIDPrefix:`${u}-diff-tab`}),h(pn,{leftEvent:ie,rightEvent:Z}),h(c,{style:L.diffContent,testID:`${u}-diff-content`,children:le()})]})]}),ce&&h(Ct,{currentIndex:T-1,totalItems:y,onPrevious:se,onNext:N,itemLabel:"Change",subtitle:Te(new Date(e.timestamp)),absolute:true})]})}function St({change:e,changes:t,selectedIndex:a,onIndexChange:r}){let o=t.length;if(o<=1)return null;let n=o-a;return h(Ct,{currentIndex:n-1,totalItems:o,onPrevious:()=>r(Math.min(o-1,a+1)),onNext:()=>r(Math.max(0,a-1)),itemLabel:"Change",subtitle:Te(new Date(e.timestamp))})}var L=ne.create({container:{flex:1,backgroundColor:"transparent"},contentArea:{flex:1},contentAreaFooterPad:{paddingBottom:96},stateContainer:{flex:1,padding:14},contentCard:{backgroundColor:v.color.surface,borderRadius:14,padding:14,borderWidth:1,borderColor:v.color.border},valueHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginBottom:8},valueLabel:{fontSize:10,color:v.color.textSecondary,fontFamily:K,letterSpacing:.5,fontWeight:"600"},valueHeaderBadges:{flexDirection:"row",alignItems:"center",gap:6},changeBadge:{paddingHorizontal:8,paddingVertical:2,borderRadius:4},changeText:{fontSize:9,fontWeight:"700",fontFamily:K,letterSpacing:.3},typeBadge:{paddingHorizontal:8,paddingVertical:2,borderRadius:4,backgroundColor:v.color.surfaceElevated},typeText:{fontSize:9,fontWeight:"600",color:v.color.textTertiary,fontFamily:K},valueBox:{backgroundColor:v.color.bg,borderRadius:6,borderWidth:1,borderColor:v.color.border,padding:8},valueText:{fontSize:12,color:v.color.text,fontFamily:K,lineHeight:18},diffContainer:{flex:1},diffContent:{flex:1,paddingHorizontal:14},changeBadgeSmall:{paddingHorizontal:6,paddingVertical:1,borderRadius:3},changeTextSmall:{fontSize:8,fontWeight:"700",fontFamily:K}}),f=ne.create({container:{flex:1},content:{padding:8,paddingBottom:100,gap:16},card:{backgroundColor:v.color.surface,borderRadius:6,borderWidth:1,borderColor:v.color.accentBorderStrong,overflow:"hidden",shadowColor:v.color.accent,shadowOffset:{width:0,height:0},shadowOpacity:.1,shadowRadius:6},sectionHeader:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingHorizontal:12,paddingVertical:10,borderBottomWidth:1,borderBottomColor:v.color.accentBorder,backgroundColor:v.color.accentSoft},sectionHeaderLeft:{flexDirection:"row",alignItems:"center",gap:6},sectionTitle:{fontSize:12,fontWeight:"600",letterSpacing:.5,color:v.color.accent,fontFamily:K},cardContent:{padding:14,gap:10},infoRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},infoLabel:{fontSize:11,color:v.color.textTertiary,fontWeight:"500"},infoValue:{fontSize:11,color:v.color.text,fontWeight:"500",flex:1,textAlign:"right",marginLeft:12},infoValueMono:{fontFamily:K},badgeRow:{flexDirection:"row",flexWrap:"wrap",gap:8,marginTop:6},categoryBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4},categoryText:{fontSize:9,fontWeight:"700",letterSpacing:.3},changesBadge:{flexDirection:"row",alignItems:"center",gap:4,paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:fe.success+"26"},changesText:{fontSize:9,fontWeight:"600",color:fe.success},noChangesBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:v.color.surfaceElevated},noChangesText:{fontSize:9,fontWeight:"600",color:v.color.textTertiary},keysContainer:{flexDirection:"row",flexWrap:"wrap",gap:6},keyBadge:{paddingHorizontal:8,paddingVertical:4,borderRadius:4,backgroundColor:v.color.accentSoft,borderWidth:1,borderColor:v.color.accentBorder},keyText:{fontSize:11,fontWeight:"600",color:v.color.accent,fontFamily:K},countBadge:{paddingHorizontal:8,paddingVertical:3,borderRadius:4,backgroundColor:v.color.accentFill},countText:{fontSize:9,fontWeight:"700",color:v.color.accent,fontFamily:K},actionsRow:{flexDirection:"row",gap:12},actionButton:{paddingHorizontal:14,paddingVertical:8,borderRadius:8,borderWidth:1},actionButtonCopy:{borderColor:v.color.accentBorder,backgroundColor:v.color.accentSoft},actionButtonText:{fontSize:10,fontWeight:"700",fontFamily:K,letterSpacing:.3},dataViewerContainer:{marginTop:-12,marginHorizontal:-12,marginBottom:-12}});import{useMemo as $n}from"react";import{CompactRow as En,night as We,ToolEmptyState as At,resolveListEmptyState as Pn,monoFont as It}from"@buoy-gg/shared-ui/web";import{jsx as U,jsxs as Fe}from"react/jsx-runtime";function Rn(e){try{let t=e.getValue();if(t&&typeof t=="object"&&t.__buoyValueOnDevice===true)return"on device";if(t===void 0)return"undefined";if(t===null)return"null";if(Array.isArray(t))return t.length===0?"[]":`[${t.length} item${t.length===1?"":"s"}]`;if(typeof t=="object"){let a=Object.keys(t);return a.length===0?"{}":a.length<=3?a.join(", "):`${a.slice(0,2).join(", ")} +${a.length-2}`}return String(t).slice(0,40)}catch{return""}}function zn(e){return e.writeKind==="value"?"primitive":e.writeKind==="action"?"custom write":e.setValue?"writable":"derived"}function Hn(){return U(At,{testID:`${u}-atoms-empty`,otto:"scanning",title:"No atoms registered",message:`Use watchAtoms(store, { atomName }) to register your Jotai atoms.
|
|
2
|
+
They will appear here with their current value.`})}function Wn({atoms:e,searchQuery:t,onOpenAtom:a}){let r=$n(()=>{if(!t)return e;let o=t.toLowerCase();return e.filter(n=>n.label.toLowerCase().includes(o))},[e,t]);return r.length===0&&!t?U(Hn,{}):r.length===0&&t?U(At,{testID:`${u}-atoms-no-match`,...Pn({subject:"atoms",verb:"registered",search:t,total:e.length,waiting:{otto:"scanning",title:"No atoms registered",message:"Use watchAtoms() to register your Jotai atoms."}})}):Fe(he,{style:G.container,contentContainerStyle:G.scrollContent,showsVerticalScrollIndicator:true,testID:`${u}-atoms-scroll`,children:[Fe(c,{style:G.sectionHeader,children:[U(b,{style:G.sectionTitle,children:"ATOMS"}),U(c,{style:G.sectionCountBadge,children:U(b,{style:G.sectionCountText,testID:`${u}-atoms-count`,children:r.length})})]}),r.map(o=>{let n=Rn(o),s=p.getAtomColor(o.label),i=wt(o.label);return Fe(c,{style:G.atomRowWrapper,children:[U(En,{statusDotColor:s,statusLabel:zn(o),primaryText:o.label,secondaryText:n||void 0,showChevron:true,onPress:()=>a(o.label),testID:i,statusTestID:`${i}-kind`,primaryTestID:`${i}-name`,secondaryTestID:`${i}-preview`}),o.changeCount>0&&U(c,{style:[G.absCountBadge,{backgroundColor:s+"22",borderColor:s+"55"}],pointerEvents:"none",children:U(b,{style:[G.absCountText,{color:s}],testID:`${i}-count`,children:String(o.changeCount)})})]},o.label)})]})}var G=ne.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:It},scrollContent:{paddingTop:8,paddingBottom:20},sectionHeader:{flexDirection:"row",alignItems:"center",paddingHorizontal:16,paddingVertical:8,gap:8},sectionTitle:{fontSize:11,fontWeight:"700",letterSpacing:.5,color:We.color.textTertiary},sectionCountBadge:{backgroundColor:We.color.accentFill,paddingHorizontal:8,paddingVertical:2,borderRadius:4},sectionCountText:{fontSize:10,fontWeight:"700",color:We.color.accent,fontFamily:It}});import{useCallback as Fn,useEffect as Mn,useMemo as Me,useState as Dt}from"react";import{buoyColors as je,ExpandedInfoRow as Oe,FileJson as jn,night as I,PillBadge as Ne,parseValue as Bt,monoFont as pe}from"@buoy-gg/shared-ui/web";import{DataViewer as On,LiveExplorer as Nn,ValueEditModal as Kn,updateNestedDataByPath as Jn,deleteNestedDataByPath as _n}from"@buoy-gg/shared-ui/web/dataViewer";import{Fragment as Un,jsx as V,jsxs as O}from"react/jsx-runtime";var Gn=300,te=`${u}-atom-detail`;function Yn(e){let t=a=>a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return e.length===0?`${te}-explorer-root`:`${te}-explorer-${e.map(t).filter(Boolean).join("-")}`}function qn(e,t){if(!e.setValue)return"Derived atom \u2014 its value recomputes from other atoms and has no setter. Edit the atoms it reads from instead.";if(typeof t=="function")return"This atom holds a function \u2014 nothing here to edit as data.";if(t&&typeof t=="object"&&t.__buoyValueOnDevice===true)return"The value stayed on the device (too large for the wire) \u2014 open the tool on-device to edit it.";if(t&&typeof t=="object"){let a=Object.getPrototypeOf(t);if(!(a===Object.prototype||a===null||Array.isArray(t)||t instanceof Map||t instanceof Set))return`This atom holds a ${t.constructor?.name??"class"} instance \u2014 rebuilding it from edited fields would drop its prototype. Edit via app code.`}return null}function Qn(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`array \xB7 ${e.length}`:typeof e}function kt({atom:e,onViewHistory:t}){let a=wt(e.label),[r,o]=Dt(0);Mn(()=>{let C=()=>o(W=>W+1),T=p.subscribe(C),A=p.subscribeToAtoms(C);return()=>{T(),A()}},[]);let n=Me(()=>{try{return e.getValue()}catch{return}},[e,r]),s=qn(e,n),[i,d]=Dt(false),m=Me(()=>{if(s===null)return{update:(C,T)=>{let A=e.getValue();e.setValue?.(C.length===0?T:Jn(A,C,T))},remove:C=>{if(C.length===0)return;let T=e.getValue();e.setValue?.(_n(T,C))},canRemove:C=>C.length>0}},[e,s]),y=Me(()=>{if(n&&typeof n=="object"){let C={};for(let[T,A]of Object.entries(n))typeof A!="function"&&(C[T]=A);return Bt(C)}return Bt(n)},[n,r]),E=Fn(C=>{e.setValue?.(C),d(false)},[e]),w=e.setValue===void 0?{color:I.color.textTertiary,label:"READ-ONLY (DERIVED)"}:e.writeKind==="action"?{color:je.warning,label:"CUSTOM WRITE"}:{color:je.success,label:"PRIMITIVE"};return O(c,{style:x.root,children:[O(he,{testID:`${te}-scroll`,style:x.scroll,contentContainerStyle:x.scrollContent,keyboardShouldPersistTaps:"handled",children:[V(c,{style:x.section,children:O(c,{style:x.editorContainer,children:[O(c,{style:x.sectionHeaderRow,children:[V(b,{testID:`${te}-editor-header`,style:x.sectionHeaderText,children:"Value Editor"}),s===null?O(re,{onPress:()=>d(true),testID:`${te}-raw`,accessibilityRole:"button",accessibilityLabel:"Edit raw JSON",style:x.rawButton,hitSlop:{top:6,bottom:6,left:6,right:6},children:[V(jn,{size:13,color:I.color.accent}),V(b,{style:x.rawButtonText,children:"Raw"})]}):null]}),V(c,{style:x.sectionBody,children:s===null?O(Un,{children:[V(Nn,{editable:true,label:e.label,value:n,defaultExpanded:[e.label],writer:m,dataVersion:r,testIDForPath:Yn,debounceMs:Gn}),V(b,{style:x.editorHint,children:e.writeKind==="action"?"This atom has a custom write \u2014 the edited value is handed to it as its argument (a set for atomWithStorage, an ACTION for a reducer atom).":"Edits write into the live atom as you make them \u2014 the whole value is replaced, jotai's own semantics."})]}):V(b,{style:x.blockedText,testID:`${te}-edit-blocked`,children:s})})]})}),V(c,{style:x.section,children:O(c,{style:x.infoContainer,children:[V(b,{style:x.sectionHeaderTextPlain,children:"Atom Details"}),O(c,{style:x.infoBody,children:[O(Oe,{label:"Type",children:[V(Ne,{color:e.color,testID:`${a}-type`,children:"JOTAI"}),V(b,{style:x.valueTypeText,testID:`${a}-valuetype`,children:Qn(n)})]}),V(Oe,{label:"Write",children:V(Ne,{color:w.color,testID:`${te}-write`,children:w.label})}),e.changeCount>0&&O(Oe,{label:"Changes",children:[V(Ne,{color:je.warning,testID:`${a}-changes`,children:String(e.changeCount)}),V(re,{onPress:()=>t(e.label),style:x.inlineLinkButton,hitSlop:{top:6,bottom:6,left:6,right:6},testID:`${a}-history`,accessibilityRole:"button",accessibilityLabel:`View ${e.label} history`,children:V(b,{style:[x.inlineLinkText,{color:e.color}],children:"view history \u2192"})})]})]})]})}),V(c,{style:x.section,children:O(c,{style:x.infoContainer,children:[V(b,{style:x.sectionHeaderTextPlain,children:"Value Explorer"}),V(c,{style:x.viewerBody,testID:`${a}-value`,children:y&&typeof y=="object"?V(On,{title:"",data:y,showTypeFilter:true,rawMode:true,initialExpanded:false}):V(b,{style:x.primitiveText,testID:`${a}-primitive`,children:String(n??"undefined")})})]})})]}),i&&s===null?V(Kn,{path:[],value:n,onSave:E,onCancel:()=>d(false),saveLabel:"Apply",testIDPrefix:`${u}-value`}):null]})}var x=ne.create({root:{flex:1,minHeight:0},scroll:{flex:1},scrollContent:{paddingHorizontal:8,paddingTop:8,paddingBottom:24},section:{marginBottom:16},editorContainer:{minWidth:200,backgroundColor:I.color.surface,borderRadius:6,borderWidth:1,borderColor:I.color.accent+"4D",overflow:"hidden",shadowColor:I.color.accent,shadowOffset:{width:0,height:0},shadowOpacity:.1,shadowRadius:6},sectionHeaderRow:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",backgroundColor:I.color.accent+"1A",paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:I.color.accent+"33"},sectionHeaderText:{fontWeight:"600",fontSize:12,color:I.color.accent,letterSpacing:.5,textTransform:"uppercase",fontFamily:pe},rawButton:{flexDirection:"row",alignItems:"center",gap:4},rawButtonText:{color:I.color.accent,fontSize:11,fontWeight:"700"},sectionBody:{padding:8},editorHint:{color:I.color.textTertiary,fontSize:10,paddingTop:8,paddingHorizontal:4,lineHeight:14},blockedText:{color:I.color.textSecondary,fontSize:12,padding:12,lineHeight:18},infoContainer:{minWidth:200,backgroundColor:I.color.surface,borderRadius:6,borderWidth:1,borderColor:I.color.border,overflow:"hidden"},sectionHeaderTextPlain:{backgroundColor:I.color.surfaceElevated,paddingHorizontal:12,paddingVertical:8,fontWeight:"600",fontSize:12,color:I.color.textSecondary,borderBottomWidth:1,borderBottomColor:I.color.border,letterSpacing:.5,textTransform:"uppercase",fontFamily:pe},infoBody:{padding:12,gap:10},viewerBody:{backgroundColor:I.color.bg,minHeight:60},primitiveText:{color:I.color.text,fontSize:12,fontFamily:pe,padding:14},valueTypeText:{color:I.color.textTertiary,fontSize:10,fontFamily:pe,marginLeft:6},inlineLinkButton:{marginLeft:4},inlineLinkText:{fontSize:10,fontWeight:"600",fontFamily:pe}});import{useMemo as Zn}from"react";import{EntityFilterView as Xn}from"@buoy-gg/shared-ui/web";import{jsx as er}from"react/jsx-runtime";var tr=["\u2022 count -> hides countAtom from atoms & events","\u2022 auth -> hides authAtom, authStatusAtom","\u2022 user -> hides userAtom from both tabs"];function ar({ignoredPatterns:e,onTogglePattern:t,onAddPattern:a,atoms:r}){let o=Zn(()=>r.map(n=>({name:n.label,color:n.color})),[r]);return er(Xn,{entities:o,ignoredPatterns:e,onTogglePattern:t,onAddPattern:a,entityNoun:"ATOMS",entitySingular:"atom",entityKey:"atom",testIDPrefix:u,slug:Ae,howItWorks:"Patterns hide matching atoms from both the Atoms tab and the Events tab. Tap an atom above to quickly add it as a filter.",examples:tr,emptyMessage:"No atoms are being watched yet."})}import{Fragment as Lt,jsx as g,jsxs as H}from"react/jsx-runtime";function or({isEnabled:e,searchText:t,totalChanges:a}){let r=ht({subject:"changes",search:t,total:a,capturing:e,waiting:{otto:"waiting",title:"No atom changes",message:"Atom changes will appear here as values update."},paused:{title:"No atom changes",message:"Enable capture to start recording atom changes"}});return g(Pe,{...r,testID:`${u}-empty`})}function Ke({visible:e,onClose:t,onBack:a,onMinimize:r,enableSharedModalDimensions:o=false,inline:n=false,initialTab:s,initialSelectedChangeId:i,initialDetailView:d,onChangeSelect:m,onAtomExpand:y}){let E=Jo(),w=No("jotai.changes"),[C,T]=_(false),[A,W]=_(s??"atoms"),[z,ie]=_(null),[Z,ye]=_(null),[le,se]=_(false),[N,be]=_(new Set),{atomChanges:ce,filteredChanges:Y,stats:Ce,filter:Er,setFilter:de,atoms:ue,clearChanges:Ht,isEnabled:ve,toggleCapture:Wt}=pt(),J=Q(()=>N.size===0?Y:Y.filter(l=>!Array.from(N).some(S=>l.atomLabel.toLowerCase().includes(S.toLowerCase()))),[Y,N]),ae=Q(()=>N.size===0?ue:ue.filter(l=>!Array.from(N).some(S=>l.label.toLowerCase().includes(S.toLowerCase()))),[ue,N]),Ft=Q(()=>z?ce.filter(l=>l.atomLabel===z).length:0,[ce,z]),we=Q(()=>z?J.filter(l=>l.atomLabel===z):J,[J,z]),Be=Q(()=>we.slice(0,w),[we,w]),ke=Q(()=>Math.max(0,we.length-w),[we.length,w]),Mt=ke>0,P=Be,[Le,X]=_(null),ee=Q(()=>{if(Le===null)return null;let l=P.findIndex(S=>S.id===Le);return l>=0?l:null},[Le,P]),M=ee!==null?P[ee]:null,Ye=Ve(null);dt(()=>{if(!m)return;let l=M?.id??null;l===null||l===Ye.current||(Ye.current=l,m(M))},[M,m]);let qe=Ve(null);dt(()=>{!i||qe.current===i||!P.some(l=>l.id===i)||(qe.current=i,X(i))},[i,P]);let[q,$e]=_(""),[jt,xe]=_(false),Pr=Ve(null),Ot=Ve(null),Nt=D(l=>{},[]),Kt=l=>{$e(l),A==="events"&&de(S=>({...S,searchText:l}))},Jt=D(()=>{$e(""),de(l=>({...l,searchText:""})),xe(false)},[de]),Qe=D(l=>{X(l.id)},[]),_t=D(()=>{T(true)},[]),Ut=D(()=>{X(null)},[]),Ze=D(l=>{let S=P[l];S&&X(S.id)},[P]),Gt=D(l=>{ie(l),X(null)},[]),Yt=D(()=>{ie(null),X(null)},[]),qt=D(l=>{ye(l),y?.(l)},[y]),Qt=D(()=>{ye(null)},[]),Zt=D(()=>ae.reduce((l,S)=>{try{let oe=S.getValue();l[S.label]=ge(oe)}catch{l[S.label]=null}return l},{}),[ae]),Xt=D(()=>J.map(l=>({id:l.id,atomLabel:l.atomLabel,timestamp:l.timestamp,prevValue:ge(l.prevValue),nextValue:ge(l.nextValue),hasValueChange:l.hasValueChange,changedKeys:l.changedKeys})),[J]),ea=D(()=>P.map(l=>({id:l.id,atomLabel:l.atomLabel,timestamp:l.timestamp,prevValue:ge(l.prevValue),nextValue:ge(l.nextValue),hasValueChange:l.hasValueChange,changedKeys:l.changedKeys})),[P]),ta=D(l=>{be(S=>{let oe=new Set(S);return oe.has(l)?oe.delete(l):oe.add(l),oe})},[]),aa=D(l=>{be(S=>new Set([...S,l]))},[]),oa=D(l=>{W(l),ie(null),X(null),se(false),q&&($e(""),de(S=>({...S,searchText:""}))),xe(false)},[q,de]),Xe=D(l=>l.id,[]),et=Q(()=>Tn(P),[P]),tt=D(({item:l})=>g(yt,{change:l,onPress:Qe,testID:et.get(l.id)}),[Qe,et]),at=N.size>0,ot=()=>le?H(B,{children:[g(B.Navigation,{onBack:()=>se(false)}),g(B.Content,{title:"Filters",centered:true,testID:`${u}-filters-title`})]}):M?H(B,{children:[g(B.Navigation,{onBack:Ut}),g(B.Content,{title:`${M.atomLabel}/${M.category}`,centered:true,testID:`${u}-detail-title`})]}):z?H(B,{children:[g(B.Navigation,{onBack:Yt}),g(B.Content,{title:`${z} History`,centered:true,testID:`${u}-history-title`}),g(B.Actions,{children:g(Re,{value:ea,disabled:P.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`})})]}):Z?H(B,{children:[g(B.Navigation,{onBack:Qt}),g(B.Content,{title:Z,centered:true,testID:`${u}-atom-detail-title`})]}):H(B,{children:[a&&g(B.Navigation,{onBack:a}),g(B.Content,{title:"",children:jt?g(B.Search,{value:q,onChangeText:Kt,onCancel:Jt,placeholder:A==="atoms"?"Search atoms...":"Search events...",accessibilityLabel:"Search Jotai atoms and events",iconSize:14,testID:`${u}-search-field`,containerTestID:`${u}-search`,clearTestID:`${u}-search-clear`,onBlur:()=>{q.length===0&&xe(false)}}):g(Po,{tabs:[{key:"atoms",label:`Atoms${ae.length>0?` (${ae.length})`:""}`},{key:"events",label:`Events${J.length>0?` (${J.length})`:""}`}],activeTab:A,onTabChange:oa,testIDPrefix:`${u}-tab`})}),H(B.Actions,{children:[g(re,{onPress:()=>xe(true),style:$.headerActionButton,testID:`${u}-search-open`,accessibilityRole:"button",accessibilityLabel:"Search",children:g(zo,{size:14,color:k.color.textSecondary})}),g(re,{onPress:()=>se(true),style:[$.headerActionButton,at&&$.headerActionButtonActive],testID:`${u}-filters-open`,accessibilityRole:"button",accessibilityLabel:"Filters",children:g(Ho,{size:14,color:at?k.color.accent:k.color.textSecondary})}),A==="atoms"&&g(Re,{value:Zt,disabled:ae.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`}),A==="events"&&H(Lt,{children:[g(Re,{value:Xt,disabled:J.length===0,buttonStyle:$.headerActionButton,testID:`${u}-copy`}),g(jo,{isEnabled:ve,onToggle:Wt,accessibilityLabel:"Toggle Jotai atom capture",testID:`${u}-power`}),g(Oo,{onPress:Ht,disabled:J.length===0,buttonStyle:$.headerActionButton,testID:`${u}-clear`})]})]})]}),na=()=>{if(le)return g(ar,{ignoredPatterns:N,onTogglePattern:ta,onAddPattern:aa,atoms:ue});if(M&&ee!==null)return g(Tt,{change:M,changes:P,selectedIndex:ee,onIndexChange:Ze,disableInternalFooter:true,initialView:d});if(z)return P.length>0?g(Ee,{testID:`${u}-history-list`,data:P,renderItem:tt,keyExtractor:Xe,contentContainerStyle:$.listContent,showsVerticalScrollIndicator:true,...mt}):g(Pe,{testID:`${u}-history-empty`,...ht({subject:"changes",search:q,total:q.trim()?Ft:0,capturing:ve,waiting:{otto:"waiting",title:"No history yet",message:`Changes for ${z} will appear here.`},paused:{title:"No history yet",message:`Capture is off, so nothing is being recorded for ${z}.`}})});if(Z){let l=ue.find(S=>S.label===Z)??null;return l?g(kt,{atom:l,onViewHistory:Gt}):g(Pe,{testID:`${u}-atom-detail-gone`,otto:"ghost",title:"Atom no longer registered",message:`${Z} is not in the registry any more.`})}return A==="atoms"?g(Wn,{atoms:ae,searchQuery:q,onOpenAtom:qt}):H(Lt,{children:[!ve&&H(c,{style:$.disabledBanner,testID:`${u}-banner-disabled`,children:[g(Wo,{size:14,color:k.color.warning}),g(b,{style:$.disabledText,children:"Atom capture is disabled"})]}),Mt&&H(re,{style:$.lockedBanner,onPress:_t,activeOpacity:.8,testID:`${u}-locked`,accessibilityRole:"button",children:[H(b,{style:$.lockedText,testID:`${u}-locked-text`,children:[ke," older"," ",ke===1?"change":"changes"," locked"]}),g(c,{style:$.upgradeBadge,children:g(b,{style:$.upgradeBadgeText,children:"UPGRADE"})})]}),Be.length>0?g(Ee,{ref:Ot,testID:`${u}-list`,data:Be,renderItem:tt,keyExtractor:Xe,contentContainerStyle:$.listContent,showsVerticalScrollIndicator:true,...mt}):g(or,{isEnabled:ve,searchText:q,totalChanges:Ce.totalChanges})]})},ra=o?Fo.modal.root():"buoy-jotai-modal";if(!e)return null;let nt=M&&ee!==null?g(St,{change:M,changes:P,selectedIndex:ee,onIndexChange:Ze}):null,ia=M&&P.length>1?68:0,la=!le&&!(M&&ee!==null)&&(z!=null||A==="events"||A==="atoms"),rt=g(c,{style:$.container,children:na()}),it=g(Mo,{visible:C,onClose:()=>T(false),featureName:"Full Atom History"});return n?H(gt,{children:[H(c,{style:$.inlineRoot,children:[g(c,{style:$.inlineHeader,...Ko,children:ot()}),rt,nt]}),it]}):H(gt,{children:[g(Eo,{visible:e,onClose:t,onMinimize:r,persistenceKey:ra,header:{showToggleButton:true,customContent:ot()},onModeChange:Nt,enablePersistence:true,initialMode:"bottomSheet",enableGlitchEffects:true,disableScrollWrapper:la,styles:{},footer:nt,footerHeight:ia,children:rt}),it]})}function nr(e={}){return g(Ke,{...e,inline:true,visible:true,onClose:()=>{}})}var $=ne.create({inlineRoot:{flex:1,minHeight:0,backgroundColor:"transparent"},inlineHeader:{paddingHorizontal:12,paddingVertical:8,borderBottomWidth:1,borderBottomColor:Ro.border.default,backgroundColor:"transparent"},container:{flex:1,backgroundColor:"transparent"},headerActionButton:{width:32,height:32,borderRadius:8,backgroundColor:k.color.buttonSurface,borderWidth:1,borderColor:k.color.border,alignItems:"center",justifyContent:"center"},headerActionButtonActive:{backgroundColor:k.color.accentSoft,borderColor:k.color.accentBorderStrong},disabledBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:k.color.warningSoft,borderRadius:8,borderWidth:1,borderColor:k.color.warning+"20"},disabledText:{color:k.color.warning,fontSize:11,flex:1},listContent:{paddingTop:8,paddingBottom:20},emptyState:{alignItems:"center",paddingVertical:40},emptyTitle:{color:k.color.text,fontSize:14,fontWeight:"600",marginTop:12,marginBottom:6},emptyText:{color:k.color.textTertiary,fontSize:12,textAlign:"center",lineHeight:18},lockedBanner:{flexDirection:"row",alignItems:"center",gap:8,padding:10,marginHorizontal:12,marginTop:8,backgroundColor:k.color.accentSoft,borderRadius:8,borderWidth:1,borderColor:k.color.accentBorder},lockedText:{color:k.color.accent,fontSize:11,fontWeight:"500",flex:1},upgradeBadge:{backgroundColor:k.color.accent,paddingHorizontal:8,paddingVertical:3,borderRadius:4},upgradeBadgeText:{color:k.color.onAccent,fontSize:9,fontWeight:"700",letterSpacing:.5}});import{JotaiIcon as Je,JOTAI_ICON_COLOR as rr}from"@buoy-gg/shared-ui/web";import{createToolFactory as ir,defineToolPreset as lr}from"@buoy-gg/shared-ui/web";import{jsx as $t}from"react/jsx-runtime";var Et=lr({id:"jotai",name:"JOTAI",description:"Jotai atom & state inspector",slot:"both",icon:({size:e})=>$t(Je,{size:e}),component:Ke,props:{enableSharedModalDimensions:false}}),sr=ir(Et,e=>({enableSharedModalDimensions:e.enableSharedModalDimensions??false}),e=>({icon:({size:t})=>$t(Je,{size:t,color:e.iconColor})}));import{getDefaultStore as cr}from"jotai/vanilla";import{atom as dr}from"jotai/vanilla";var ur=dr(null),_e=ur.write,Pt=typeof _e=="function"?String(_e):null;function hr(e){let t=e,a=t?.write;return typeof a!="function"?"action":a===_e||t!==null&&"init"in t&&Pt!==null&&String(a)===Pt?"value":"action"}function Rt(e,t,a){let r=a?.enabled!==false,o=[];for(let[n,s]of Object.entries(t)){let i=s,d=Symbol.for(`@@buoy-jotai/watched/${n}`);if(i[d])continue;i[d]=true;let m;try{m=e.get(s)}catch{m=void 0}let y=typeof s.write=="function",E=e.set&&y?C=>{e.set(s,C)}:void 0;p.registerAtom(n,()=>{try{return e.get(s)}catch{return}},E,y?hr(s):void 0),r&&p.addAtomChange({atomLabel:n,prevValue:void 0,nextValue:m,category:"initial"});let w=e.sub(s,()=>{try{let C=e.get(s);p.addAtomChange({atomLabel:n,prevValue:m,nextValue:C,category:"write"}),m=C}catch{}});o.push(()=>{w(),delete i[d],p.unregisterAtom(n)})}return()=>o.forEach(n=>n())}function gr(e,t){let a=cr();return Rt(a,e,t)}function mr(e){return p.getAtom(e)!==void 0}import{WIRE_DETAIL_LIMIT_BYTES as fr,createSyncAdapter as pr,capDetail as yr,detailByIdAction as br,expandKeyedArrays as Cr,memoByIdentity as vr,onDeviceMarker as wr,patchFromPath as xr,readParams as Ue,readPath as Vr,refusalText as Tr,shapeSummary as Ie,suggestedPatch as Sr,toWire as Ar,typedEditViolations as Ir,unshapedLists as Dr}from"@buoy-gg/shared-ui/web";var De=wr("Value","Atom values stay on the device \u2014 fetched on demand via getChangeDetail / getAtomValue."),Ge=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function zt(e,t){if(!Ge(e)||!Ge(t))return t;let a={...e};for(let[r,o]of Object.entries(t))a[r]=r in e?zt(e[r],o):o;return a}function Br(e,t){let a=e;for(let r of t.split(".")){if(!Ge(a)||!(r in a))return false;a=a[r]}return Array.isArray(a)?a.length>0:!!a&&typeof a=="object"}var kr=vr(e=>({...e,prevValue:De,nextValue:De})),Lr=e=>Ar(e,De),$r=pr({version:2,getSnapshot:()=>({changes:p.getAtomChanges().map(kr),atoms:p.getAtomSnapshots().map(e=>({...e,currentValue:Lr(e.currentValue)}))}),subscribe:[e=>p.subscribe(e),e=>p.subscribeToAtoms(e)],actions:{clearEvents:()=>{p.clearAtomChanges()},getChangeDetail:br(e=>p.getAtomChangeById(e),(e,t)=>({prevValue:t(e.prevValue),nextValue:t(e.nextValue)})),getAtomValue:e=>{let{label:t,path:a}=Ue(e);if(!t)return{found:false,reason:"missing label"};let r=p.getAtom(t);if(!r)return{found:false,reason:"unknown label"};let o;try{o=r.getValue()}catch{o=void 0}try{JSON.stringify(o)}catch{return{found:true,label:t,currentValue:De}}if(a){let n=Vr(o,a);return n.ok?{found:true,label:t,path:a,shape:Ie(n.value),currentValue:n.value}:{found:false,reason:n.error}}return{found:true,label:t,...Ie(o)?{shape:Ie(o)}:{},currentValue:yr(o,fr)}},listAtoms:e=>{let{includeValues:t=false,limit:a}=Ue(e),r=p.getAtoms(),o=(typeof a=="number"&&a>0?r.slice(0,a):r).map(n=>{let s;if(t)try{s=n.getValue()}catch{s=void 0}let i;try{i=Ie(n.getValue())}catch{i=void 0}return{label:n.label,changes:n.changeCount,writable:typeof n.setValue=="function",...i?{shape:i}:{},...t?{currentValue:s}:{}}});return{atoms:o,total:r.length,returned:o.length,includedValues:t}},setAtom:e=>{let{label:t,value:a,merge:r,path:o,force:n}=Ue(e);if(!t)throw new Error("setAtom requires a `label`");let s=p.getAtom(t),i;try{i=s?.getValue()}catch{i=void 0}let d=a,m=[],y=[],E=r===true||o!==void 0;if(o!==void 0){if(a===void 0)return{ok:false,error:`Refused: sent \`path\` without \`value\`. Say what to set "${o}" to.`};let w=xr(i,o,a);if(!w.ok)return{ok:false,error:`Refused: ${w.error}`};d=w.patch}if(!n&&E&&i!==void 0){let w=Cr(i,d);if(w.error)return{ok:false,error:`Refused: ${w.error}`};d=w.patch,m=w.notes,y=Dr(i).filter(T=>Br(d,T));let C=Ir(i,d,{noun:"atom"});if(C.length){let T=Sr(d,C);return{ok:false,error:Tr(C,"atom",T),violations:C,...T?{suggestedValue:T}:{}}}}return p.setAtomValue(t,E?zt(i,d):d),{ok:true,...o!==void 0?{path:o}:{},...m.length?{keyed:m}:{},...y.length?{unchecked:y.map(w=>`\`${w}\` was empty, so nothing knows what its items look like and the shape of what you added was NOT checked.`)}:{}}}}});export{rr as JOTAI_ICON_COLOR,yt as JotaiAtomChangeItem,Tt as JotaiAtomDetailContent,St as JotaiAtomDetailFooter,kt as JotaiAtomValueDetailContent,Je as JotaiIcon,Ke as JotaiModal,nr as JotaiToolView,sr as createJotaiTool,mr as isAtomWatched,p as jotaiStateStore,$r as jotaiSyncAdapter,Et as jotaiToolPreset,pt as useJotaiAtomChanges,Rt as watchAtoms,gr as watchDefaultStoreAtoms};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/jotai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.58",
|
|
4
4
|
"description": "Inspect registered Jotai atoms, observed writes, retained history and current values in a React Native app.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"./lib/web/**/*.mjs"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@buoy-gg/
|
|
42
|
-
"@buoy-gg/
|
|
41
|
+
"@buoy-gg/shared-ui": "^7.0.58",
|
|
42
|
+
"@buoy-gg/license": "^7.0.58"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"jotai": ">=2.0.0",
|