@buoy-gg/network 7.0.56 → 7.0.57
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/lib/commonjs/network/conditions/NetworkFloatingTool.js +1 -1
- package/lib/commonjs/network/utils/startNetworkCapture.js +1 -1
- package/lib/module/network/conditions/NetworkFloatingTool.js +1 -1
- package/lib/module/network/utils/startNetworkCapture.js +1 -1
- package/lib/typescript/network/conditions/NetworkFloatingTool.d.ts +1 -0
- package/lib/web/index.mjs +25 -25
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.NetworkFloatingTool=NetworkFloatingTool;exports.createRemoteConditionsSource=createRemoteConditionsSource;exports.openNetworkFloatingTool=openNetworkFloatingTool;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _store=require("./store");var _jsxRuntime=require("react/jsx-runtime");function createRemoteConditionsSource(){let i;const n=new Set;return{getSnapshot:()=>i,subscribe:r=>{n.add(r);return()=>{n.delete(r)}},update(r){i=r;n.forEach(t=>t())}}}const noSubscribe=()=>()=>{};const noRemote=()=>void 0;const options=[{id:"normal",label:"No throttling",detail:"No added delay"},{id:"slow",label:"Slow",detail:"+500 ms before sending"},{id:"verySlow",label:"Very slow",detail:"+2 seconds before sending"},{id:"offline",label:"Offline",detail:"New requests fail"}];const localRegistration={id:"network-throttling",render:i=>(0,_jsxRuntime.jsx)(NetworkFloatingTool,{...i})};if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.NetworkFloatingTool=NetworkFloatingTool;exports.createRemoteConditionsSource=createRemoteConditionsSource;exports.openNetworkFloatingTool=openNetworkFloatingTool;exports.registerLocalNetworkFloatingTool=registerLocalNetworkFloatingTool;var _react=require("react");var _reactNative=require("react-native");var _sharedUi=require("@buoy-gg/shared-ui");var _store=require("./store");var _jsxRuntime=require("react/jsx-runtime");function createRemoteConditionsSource(){let i;const n=new Set;return{getSnapshot:()=>i,subscribe:r=>{n.add(r);return()=>{n.delete(r)}},update(r){i=r;n.forEach(t=>t())}}}const noSubscribe=()=>()=>{};const noRemote=()=>void 0;const options=[{id:"normal",label:"No throttling",detail:"No added delay"},{id:"slow",label:"Slow",detail:"+500 ms before sending"},{id:"verySlow",label:"Very slow",detail:"+2 seconds before sending"},{id:"offline",label:"Offline",detail:"New requests fail"}];const localRegistration={id:"network-throttling",render:i=>(0,_jsxRuntime.jsx)(NetworkFloatingTool,{...i})};function registerLocalNetworkFloatingTool(){if(typeof __DEV__==="undefined"||!__DEV__)return()=>{};return(0,_sharedUi.registerPersistentFloatingTool)(localRegistration,_sharedUi.persistentStorage)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){registerLocalNetworkFloatingTool()}function openNetworkFloatingTool(i){(0,_sharedUi.openFloatingTool)({id:"network-throttling",render:n=>(0,_jsxRuntime.jsx)(NetworkFloatingTool,{...n,source:i})})}function NetworkFloatingTool({id:i,revealToken:n,dismiss:r,source:t}){const k=(0,_react.useSyncExternalStore)(_store.subscribeNetworkConditions,_store.getNetworkCondition,_store.getNetworkCondition);const _=(0,_react.useSyncExternalStore)(_store.subscribeNetworkConditions,_store.conditionsCanApply,_store.conditionsCanApply);const g=(0,_react.useSyncExternalStore)(t?.subscribe??noSubscribe,t?.getSnapshot??noRemote,noRemote);const c=t?g?.profile??null:k;const d=t?g?.available===true:_;const[l,f]=(0,_react.useState)(false);const[x,h]=(0,_react.useState)();const u=(0,_react.useRef)(false);const a=(0,_react.useRef)(0);const s=(0,_react.useRef)(true);const{width:j}=(0,_reactNative.useWindowDimensions)();(0,_react.useEffect)(()=>{s.current=true;return()=>{s.current=false}},[]);(0,_react.useEffect)(()=>{a.current+=1;u.current=false;f(false);h(void 0)},[t,g?.targetId]);const C=c!==null&&c!=="normal";const e=c??"normal";const b=options.find(o=>o.id===e);const m=options[(options.findIndex(o=>o.id===e)+1)%options.length];const R=!d||e==="offline"?0:e==="verySlow"?1:e==="slow"?2:4;const T=l?"Applying\u2026":!d?"Unavailable":e==="normal"?"0 ms":e==="slow"?"+500 ms":e==="verySlow"?"+2000 ms":"Blocked";async function S(o,p=false){if(u.current)return;const y=++a.current;u.current=true;f(true);h(void 0);const v=t?.getSnapshot();try{if(t){if(!v?.available)throw new Error("Device unavailable. Open Network again to reconnect these controls.");await v.onChange(o)}else(0,_store.setNetworkCondition)(o);if(s.current&&a.current===y){if(p)r()}}catch(w){if(s.current&&a.current===y)h(w instanceof Error?w.message:String(w))}finally{if(a.current===y){u.current=false;if(s.current)f(false)}}}const N=x?(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.menu,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{accessibilityRole:"alert",style:styles.error,children:x})}):void 0;return(0,_jsxRuntime.jsx)(_sharedUi.FloatingTool,{id:i,revealToken:n,variant:"strip",dragFromSurface:true,accessibilityLabel:`Move or hide network throttling. ${C?"Active":"Off"}`,accessory:N,children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[styles.row,{width:Math.max(220,Math.min(292,j-64))}],children:[(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"throttling-cycle",accessibilityRole:"button",accessibilityLabel:`Network: ${b.label}. Switch to ${m.label}`,accessibilityState:{disabled:l||!d},disabled:l||!d,onPress:()=>void S(m.id),style:styles.signalButton,children:l?(0,_jsxRuntime.jsx)(_reactNative.ActivityIndicator,{size:"small",color:_sharedUi.night.color.accent}):(0,_jsxRuntime.jsxs)(_reactNative.View,{testID:`throttling-signal-${e}`,style:styles.signal,children:[[7,12,18,24].map((o,p)=>(0,_jsxRuntime.jsx)(_reactNative.View,{style:{width:4,height:o,borderRadius:2,backgroundColor:p<R?e==="offline"?_sharedUi.night.color.danger:_sharedUi.night.color.accent:_sharedUi.night.color.fillTertiary}},o)),e==="offline"&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.slash})]})}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.profile,children:(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"throttling-profile",accessibilityLabel:`Connection profile: ${b.label}`,accessibilityLiveRegion:"polite",numberOfLines:1,style:styles.profileLabel,children:b.label})}),(0,_jsxRuntime.jsx)(_reactNative.Text,{testID:"throttling-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:styles.status,children:T}),(0,_jsxRuntime.jsx)(_reactNative.View,{style:styles.separator}),(0,_jsxRuntime.jsx)(_reactNative.TouchableOpacity,{testID:"throttling-close",accessibilityRole:"button",accessibilityLabel:"Close and turn off throttling",disabled:l,accessibilityState:{disabled:l},onPress:()=>{if(c==="normal")r();else void S("normal",true)},style:[styles.action,l&&styles.disabled],children:(0,_jsxRuntime.jsx)(_reactNative.Text,{style:styles.actionText,children:"Close"})})]})})}const styles=_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center",gap:6,paddingVertical:4,minHeight:48},signalButton:{width:36,minHeight:44,alignItems:"center",justifyContent:"center"},signal:{flexDirection:"row",alignItems:"flex-end",gap:3,height:24},slash:{position:"absolute",width:30,height:2,backgroundColor:_sharedUi.night.color.danger,top:11,left:-2,transform:[{rotate:"-45deg"}]},separator:{height:20,width:1,backgroundColor:_sharedUi.night.color.separator,marginHorizontal:2},status:{color:_sharedUi.night.color.textSecondary,fontSize:10,lineHeight:15,flexShrink:1},profile:{flex:1,flexDirection:"row",alignItems:"center",gap:6,minHeight:44},profileLabel:{color:_sharedUi.night.color.text,fontSize:13,fontWeight:"500",flexShrink:1},action:{minHeight:36,minWidth:52,borderRadius:_sharedUi.night.radius.input,borderWidth:1,borderColor:_sharedUi.night.color.accentBorderStrong,alignItems:"center",justifyContent:"center",paddingHorizontal:10},actionText:{color:_sharedUi.night.color.accent,fontSize:12,fontWeight:"600"},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:_sharedUi.night.radius.card,borderWidth:1,borderColor:_sharedUi.night.color.separator,backgroundColor:_sharedUi.night.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},error:{color:_sharedUi.night.color.danger,fontSize:12,lineHeight:18,padding:10}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.startNetworkCapture=startNetworkCapture;var _networkEventStore=require("./networkEventStore");var _overrideRulesStore=require("../overrides/overrideRulesStore");function startNetworkCapture(){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.startNetworkCapture=startNetworkCapture;var _networkEventStore=require("./networkEventStore");var _overrideRulesStore=require("../overrides/overrideRulesStore");var _NetworkFloatingTool=require("../conditions/NetworkFloatingTool");function startNetworkCapture(){const e=typeof navigator!=="undefined"&&navigator.product==="ReactNative";if(!e&&(typeof window==="undefined"||typeof document==="undefined"))return()=>{};void _overrideRulesStore.overrideRulesStore.ensureLoaded();const r=e?()=>{}:(0,_NetworkFloatingTool.registerLocalNetworkFloatingTool)();const o=_networkEventStore.networkEventStore.subscribeToEvents(()=>{});let t=false;return()=>{if(t)return;t=true;r();o()}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useEffect as
|
|
1
|
+
"use strict";import{useEffect as L,useRef as _,useState as E,useSyncExternalStore as R}from"react";import{ActivityIndicator as U,StyleSheet as G,Text as p,TouchableOpacity as O,View as d,useWindowDimensions as J}from"react-native";import{FloatingTool as K,night as e,openFloatingTool as Q,persistentStorage as X,registerPersistentFloatingTool as Y}from"@buoy-gg/shared-ui";import{conditionsCanApply as H,getNetworkCondition as V,setNetworkCondition as Z,subscribeNetworkConditions as z}from"./store";import{jsx as t,jsxs as F}from"react/jsx-runtime";export function createRemoteConditionsSource(){let l;const a=new Set;return{getSnapshot:()=>l,subscribe:s=>{a.add(s);return()=>{a.delete(s)}},update(s){l=s;a.forEach(r=>r())}}}const ee=()=>()=>{};const j=()=>void 0;const y=[{id:"normal",label:"No throttling",detail:"No added delay"},{id:"slow",label:"Slow",detail:"+500 ms before sending"},{id:"verySlow",label:"Very slow",detail:"+2 seconds before sending"},{id:"offline",label:"Offline",detail:"New requests fail"}];const te={id:"network-throttling",render:l=>t(NetworkFloatingTool,{...l})};export function registerLocalNetworkFloatingTool(){if(typeof __DEV__==="undefined"||!__DEV__)return()=>{};return Y(te,X)}if(typeof __DEV__!=="undefined"&&__DEV__&&typeof navigator!=="undefined"&&navigator.product==="ReactNative"){registerLocalNetworkFloatingTool()}export function openNetworkFloatingTool(l){Q({id:"network-throttling",render:a=>t(NetworkFloatingTool,{...a,source:l})})}export function NetworkFloatingTool({id:l,revealToken:a,dismiss:s,source:r}){const W=R(z,V,V);const A=R(z,H,H);const m=R(r?.subscribe??ee,r?.getSnapshot??j,j);const g=r?m?.profile??null:W;const h=r?m?.available===true:A;const[c,w]=E(false);const[D,S]=E();const b=_(false);const f=_(0);const u=_(true);const{width:$}=J();L(()=>{u.current=true;return()=>{u.current=false}},[]);L(()=>{f.current+=1;b.current=false;w(false);S(void 0)},[r,m?.targetId]);const B=g!==null&&g!=="normal";const i=g??"normal";const v=y.find(n=>n.id===i);const I=y[(y.findIndex(n=>n.id===i)+1)%y.length];const P=!h||i==="offline"?0:i==="verySlow"?1:i==="slow"?2:4;const M=c?"Applying\u2026":!h?"Unavailable":i==="normal"?"0 ms":i==="slow"?"+500 ms":i==="verySlow"?"+2000 ms":"Blocked";async function N(n,x=false){if(b.current)return;const k=++f.current;b.current=true;w(true);S(void 0);const T=r?.getSnapshot();try{if(r){if(!T?.available)throw new Error("Device unavailable. Open Network again to reconnect these controls.");await T.onChange(n)}else Z(n);if(u.current&&f.current===k){if(x)s()}}catch(C){if(u.current&&f.current===k)S(C instanceof Error?C.message:String(C))}finally{if(f.current===k){b.current=false;if(u.current)w(false)}}}const q=D?t(d,{style:o.menu,children:t(p,{accessibilityRole:"alert",style:o.error,children:D})}):void 0;return t(K,{id:l,revealToken:a,variant:"strip",dragFromSurface:true,accessibilityLabel:`Move or hide network throttling. ${B?"Active":"Off"}`,accessory:q,children:F(d,{style:[o.row,{width:Math.max(220,Math.min(292,$-64))}],children:[t(O,{testID:"throttling-cycle",accessibilityRole:"button",accessibilityLabel:`Network: ${v.label}. Switch to ${I.label}`,accessibilityState:{disabled:c||!h},disabled:c||!h,onPress:()=>void N(I.id),style:o.signalButton,children:c?t(U,{size:"small",color:e.color.accent}):F(d,{testID:`throttling-signal-${i}`,style:o.signal,children:[[7,12,18,24].map((n,x)=>t(d,{style:{width:4,height:n,borderRadius:2,backgroundColor:x<P?i==="offline"?e.color.danger:e.color.accent:e.color.fillTertiary}},n)),i==="offline"&&t(d,{style:o.slash})]})}),t(d,{style:o.profile,children:t(p,{testID:"throttling-profile",accessibilityLabel:`Connection profile: ${v.label}`,accessibilityLiveRegion:"polite",numberOfLines:1,style:o.profileLabel,children:v.label})}),t(p,{testID:"throttling-status",numberOfLines:1,accessibilityLiveRegion:"polite",style:o.status,children:M}),t(d,{style:o.separator}),t(O,{testID:"throttling-close",accessibilityRole:"button",accessibilityLabel:"Close and turn off throttling",disabled:c,accessibilityState:{disabled:c},onPress:()=>{if(g==="normal")s();else void N("normal",true)},style:[o.action,c&&o.disabled],children:t(p,{style:o.actionText,children:"Close"})})]})})}const o=G.create({row:{flexDirection:"row",alignItems:"center",gap:6,paddingVertical:4,minHeight:48},signalButton:{width:36,minHeight:44,alignItems:"center",justifyContent:"center"},signal:{flexDirection:"row",alignItems:"flex-end",gap:3,height:24},slash:{position:"absolute",width:30,height:2,backgroundColor:e.color.danger,top:11,left:-2,transform:[{rotate:"-45deg"}]},separator:{height:20,width:1,backgroundColor:e.color.separator,marginHorizontal:2},status:{color:e.color.textSecondary,fontSize:10,lineHeight:15,flexShrink:1},profile:{flex:1,flexDirection:"row",alignItems:"center",gap:6,minHeight:44},profileLabel:{color:e.color.text,fontSize:13,fontWeight:"500",flexShrink:1},action:{minHeight:36,minWidth:52,borderRadius:e.radius.input,borderWidth:1,borderColor:e.color.accentBorderStrong,alignItems:"center",justifyContent:"center",paddingHorizontal:10},actionText:{color:e.color.accent,fontSize:12,fontWeight:"600"},disabled:{opacity:.4},menu:{marginVertical:8,padding:6,borderRadius:e.radius.card,borderWidth:1,borderColor:e.color.separator,backgroundColor:e.color.surface,shadowColor:"#000",shadowOffset:{width:0,height:6},shadowOpacity:.25,shadowRadius:16,elevation:8},error:{color:e.color.danger,fontSize:12,lineHeight:18,padding:10}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{networkEventStore as
|
|
1
|
+
"use strict";import{networkEventStore as n}from"./networkEventStore";import{overrideRulesStore as i}from"../overrides/overrideRulesStore";import{registerLocalNetworkFloatingTool as s}from"../conditions/NetworkFloatingTool";export function startNetworkCapture(){const e=typeof navigator!=="undefined"&&navigator.product==="ReactNative";if(!e&&(typeof window==="undefined"||typeof document==="undefined"))return()=>{};void i.ensureLoaded();const o=e?()=>{}:s();const r=n.subscribeToEvents(()=>{});let t=false;return()=>{if(t)return;t=true;o();r()}}
|
|
@@ -7,6 +7,7 @@ export declare function createRemoteConditionsSource(): {
|
|
|
7
7
|
update(next: RemoteNetworkConditions | undefined): void;
|
|
8
8
|
};
|
|
9
9
|
type RemoteSource = ReturnType<typeof createRemoteConditionsSource>;
|
|
10
|
+
export declare function registerLocalNetworkFloatingTool(): () => void;
|
|
10
11
|
export declare function openNetworkFloatingTool(source?: RemoteSource): void;
|
|
11
12
|
export declare function NetworkFloatingTool({ id, revealToken, dismiss, source }: FloatingToolRenderContext & {
|
|
12
13
|
source?: RemoteSource;
|