mindcache 3.3.1 → 3.3.2

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.mjs CHANGED
@@ -183,6 +183,7 @@ var init_CloudAdapter = __esm({
183
183
  if (!config.baseUrl) {
184
184
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
185
185
  }
186
+ this.setupNetworkDetection();
186
187
  }
187
188
  ws = null;
188
189
  mindcache = null;
@@ -190,8 +191,52 @@ var init_CloudAdapter = __esm({
190
191
  reconnectAttempts = 0;
191
192
  reconnectTimeout = null;
192
193
  _state = "disconnected";
194
+ _isOnline = true;
195
+ // Browser network status
193
196
  listeners = {};
194
197
  token = null;
198
+ handleOnline = null;
199
+ handleOffline = null;
200
+ /** Browser network status - instantly updated via navigator.onLine */
201
+ get isOnline() {
202
+ return this._isOnline;
203
+ }
204
+ setupNetworkDetection() {
205
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
206
+ return;
207
+ }
208
+ this._isOnline = navigator.onLine;
209
+ this.handleOnline = () => {
210
+ console.log("\u2601\uFE0F CloudAdapter: Network is back online");
211
+ this._isOnline = true;
212
+ this.emit("network_online");
213
+ if (this._state === "disconnected" || this._state === "error") {
214
+ this.connect();
215
+ }
216
+ };
217
+ this.handleOffline = () => {
218
+ console.log("\u2601\uFE0F CloudAdapter: Network went offline");
219
+ this._isOnline = false;
220
+ this.emit("network_offline");
221
+ if (this._state === "connected" || this._state === "connecting") {
222
+ this._state = "disconnected";
223
+ this.emit("disconnected");
224
+ }
225
+ };
226
+ window.addEventListener("online", this.handleOnline);
227
+ window.addEventListener("offline", this.handleOffline);
228
+ }
229
+ cleanupNetworkDetection() {
230
+ if (typeof window === "undefined") {
231
+ return;
232
+ }
233
+ if (this.handleOnline) {
234
+ window.removeEventListener("online", this.handleOnline);
235
+ }
236
+ if (this.handleOffline) {
237
+ window.removeEventListener("offline", this.handleOffline);
238
+ }
239
+ }
195
240
  setToken(token) {
196
241
  this.token = token;
197
242
  }
@@ -285,6 +330,7 @@ var init_CloudAdapter = __esm({
285
330
  this.ws.close();
286
331
  this.ws = null;
287
332
  }
333
+ this.cleanupNetworkDetection();
288
334
  this._state = "disconnected";
289
335
  this.emit("disconnected");
290
336
  }
@@ -401,7 +447,7 @@ var MindCache = class {
401
447
  listeners = {};
402
448
  globalListeners = [];
403
449
  // Metadata
404
- version = "3.3.1";
450
+ version = "3.3.2";
405
451
  // Internal flag to prevent sync loops when receiving remote updates
406
452
  // (Less critical with Yjs but kept for API compat)
407
453
  _isRemoteUpdate = false;
@@ -756,6 +802,19 @@ var MindCache = class {
756
802
  get isCloud() {
757
803
  return this._cloudConfig !== null;
758
804
  }
805
+ /**
806
+ * Browser network status. Returns true if online or in local-only mode.
807
+ * In cloud mode, this updates instantly when network status changes.
808
+ */
809
+ get isOnline() {
810
+ if (!this._cloudAdapter) {
811
+ if (typeof navigator !== "undefined") {
812
+ return navigator.onLine;
813
+ }
814
+ return true;
815
+ }
816
+ return this._cloudAdapter.isOnline;
817
+ }
759
818
  async waitForSync() {
760
819
  if (this._isLoaded) {
761
820
  return;