@digilogiclabs/saas-factory-ui 0.26.1 → 0.27.0

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/dist/index.js CHANGED
@@ -23418,75 +23418,115 @@ function useMounted() {
23418
23418
 
23419
23419
  // src/hooks/network/use-network-info.ts
23420
23420
  var import_react44 = require("react");
23421
+ var isReactNative = typeof navigator === "undefined";
23421
23422
  function useNetworkInfo() {
23422
23423
  const [networkInfo, setNetworkInfo] = (0, import_react44.useState)(() => ({
23423
- isOnline: typeof navigator !== "undefined" ? navigator.onLine : true,
23424
+ isOnline: isReactNative ? true : typeof navigator !== "undefined" ? navigator.onLine : true,
23424
23425
  isSlowConnection: false,
23425
23426
  connectionType: "unknown",
23426
23427
  effectiveType: "unknown"
23427
23428
  }));
23428
23429
  (0, import_react44.useEffect)(() => {
23429
- if (typeof navigator === "undefined") return;
23430
- const updateNetworkInfo = () => {
23431
- const connection2 = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
23432
- setNetworkInfo({
23433
- isOnline: navigator.onLine,
23434
- isSlowConnection: connection2 ? connection2.effectiveType === "slow-2g" || connection2.effectiveType === "2g" : false,
23435
- connectionType: connection2 ? connection2.type || "unknown" : "unknown",
23436
- effectiveType: connection2 ? connection2.effectiveType || "unknown" : "unknown"
23430
+ if (isReactNative) {
23431
+ let NetInfo;
23432
+ try {
23433
+ NetInfo = require("@react-native-netinfo/netinfo");
23434
+ } catch (error) {
23435
+ console.warn("NetInfo not available, install @react-native-netinfo/netinfo for network detection in React Native");
23436
+ return;
23437
+ }
23438
+ const unsubscribe = NetInfo.addEventListener((state) => {
23439
+ setNetworkInfo({
23440
+ isOnline: state.isConnected ?? false,
23441
+ isSlowConnection: state.details?.effectiveType === "slow-2g" || state.details?.effectiveType === "2g",
23442
+ connectionType: state.type === "wifi" ? "wifi" : state.type === "cellular" ? "cellular" : "unknown",
23443
+ effectiveType: state.details?.effectiveType || "unknown"
23444
+ });
23437
23445
  });
23438
- };
23439
- updateNetworkInfo();
23440
- const handleOnline = () => updateNetworkInfo();
23441
- const handleOffline = () => updateNetworkInfo();
23442
- const handleConnectionChange = () => updateNetworkInfo();
23443
- window.addEventListener("online", handleOnline);
23444
- window.addEventListener("offline", handleOffline);
23445
- const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
23446
- if (connection) {
23447
- connection.addEventListener("change", handleConnectionChange);
23448
- }
23449
- return () => {
23450
- window.removeEventListener("online", handleOnline);
23451
- window.removeEventListener("offline", handleOffline);
23446
+ return unsubscribe;
23447
+ } else {
23448
+ if (typeof navigator === "undefined") return;
23449
+ const updateNetworkInfo = () => {
23450
+ const connection2 = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
23451
+ setNetworkInfo({
23452
+ isOnline: navigator.onLine,
23453
+ isSlowConnection: connection2 ? connection2.effectiveType === "slow-2g" || connection2.effectiveType === "2g" : false,
23454
+ connectionType: connection2 ? connection2.type || "unknown" : "unknown",
23455
+ effectiveType: connection2 ? connection2.effectiveType || "unknown" : "unknown"
23456
+ });
23457
+ };
23458
+ updateNetworkInfo();
23459
+ const handleOnline = () => updateNetworkInfo();
23460
+ const handleOffline = () => updateNetworkInfo();
23461
+ const handleConnectionChange = () => updateNetworkInfo();
23462
+ window.addEventListener("online", handleOnline);
23463
+ window.addEventListener("offline", handleOffline);
23464
+ const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
23452
23465
  if (connection) {
23453
- connection.removeEventListener("change", handleConnectionChange);
23466
+ connection.addEventListener("change", handleConnectionChange);
23454
23467
  }
23455
- };
23468
+ return () => {
23469
+ window.removeEventListener("online", handleOnline);
23470
+ window.removeEventListener("offline", handleOffline);
23471
+ if (connection) {
23472
+ connection.removeEventListener("change", handleConnectionChange);
23473
+ }
23474
+ };
23475
+ }
23456
23476
  }, []);
23457
23477
  return networkInfo;
23458
23478
  }
23459
23479
 
23460
23480
  // src/hooks/network/use-offline-state.ts
23461
23481
  var import_react45 = require("react");
23482
+ var isReactNative2 = typeof navigator === "undefined";
23462
23483
  function useOfflineState() {
23463
23484
  const [state, setState] = (0, import_react45.useState)(() => ({
23464
- isOffline: typeof navigator !== "undefined" ? !navigator.onLine : false,
23465
- isOnline: typeof navigator !== "undefined" ? navigator.onLine : true,
23485
+ isOffline: isReactNative2 ? false : typeof navigator !== "undefined" ? !navigator.onLine : false,
23486
+ isOnline: isReactNative2 ? true : typeof navigator !== "undefined" ? navigator.onLine : true,
23466
23487
  wasOffline: false
23467
23488
  }));
23468
23489
  (0, import_react45.useEffect)(() => {
23469
- if (typeof navigator === "undefined") return;
23470
- const handleOnline = () => {
23471
- setState((prev) => ({
23472
- isOffline: false,
23473
- isOnline: true,
23474
- wasOffline: prev.isOffline
23475
- }));
23476
- };
23477
- const handleOffline = () => {
23478
- setState((prev) => ({
23479
- isOffline: true,
23480
- isOnline: false,
23481
- wasOffline: prev.wasOffline
23482
- }));
23483
- };
23484
- window.addEventListener("online", handleOnline);
23485
- window.addEventListener("offline", handleOffline);
23486
- return () => {
23487
- window.removeEventListener("online", handleOnline);
23488
- window.removeEventListener("offline", handleOffline);
23489
- };
23490
+ if (isReactNative2) {
23491
+ let NetInfo;
23492
+ try {
23493
+ NetInfo = require("@react-native-netinfo/netinfo");
23494
+ } catch (error) {
23495
+ console.warn("NetInfo not available, install @react-native-netinfo/netinfo for offline detection in React Native");
23496
+ return;
23497
+ }
23498
+ const unsubscribe = NetInfo.addEventListener((netState) => {
23499
+ const isConnected = netState.isConnected ?? false;
23500
+ setState((prev) => ({
23501
+ isOffline: !isConnected,
23502
+ isOnline: isConnected,
23503
+ wasOffline: prev.isOffline || !isConnected
23504
+ }));
23505
+ });
23506
+ return unsubscribe;
23507
+ } else {
23508
+ if (typeof navigator === "undefined") return;
23509
+ const handleOnline = () => {
23510
+ setState((prev) => ({
23511
+ isOffline: false,
23512
+ isOnline: true,
23513
+ wasOffline: prev.isOffline
23514
+ }));
23515
+ };
23516
+ const handleOffline = () => {
23517
+ setState((prev) => ({
23518
+ isOffline: true,
23519
+ isOnline: false,
23520
+ wasOffline: prev.wasOffline
23521
+ }));
23522
+ };
23523
+ window.addEventListener("online", handleOnline);
23524
+ window.addEventListener("offline", handleOffline);
23525
+ return () => {
23526
+ window.removeEventListener("online", handleOnline);
23527
+ window.removeEventListener("offline", handleOffline);
23528
+ };
23529
+ }
23490
23530
  }, []);
23491
23531
  return state;
23492
23532
  }