mindcache 3.3.0 → 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.
@@ -182,6 +182,7 @@ var init_CloudAdapter = __esm({
182
182
  if (!config.baseUrl) {
183
183
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
184
184
  }
185
+ this.setupNetworkDetection();
185
186
  }
186
187
  ws = null;
187
188
  mindcache = null;
@@ -189,8 +190,52 @@ var init_CloudAdapter = __esm({
189
190
  reconnectAttempts = 0;
190
191
  reconnectTimeout = null;
191
192
  _state = "disconnected";
193
+ _isOnline = true;
194
+ // Browser network status
192
195
  listeners = {};
193
196
  token = null;
197
+ handleOnline = null;
198
+ handleOffline = null;
199
+ /** Browser network status - instantly updated via navigator.onLine */
200
+ get isOnline() {
201
+ return this._isOnline;
202
+ }
203
+ setupNetworkDetection() {
204
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
205
+ return;
206
+ }
207
+ this._isOnline = navigator.onLine;
208
+ this.handleOnline = () => {
209
+ console.log("\u2601\uFE0F CloudAdapter: Network is back online");
210
+ this._isOnline = true;
211
+ this.emit("network_online");
212
+ if (this._state === "disconnected" || this._state === "error") {
213
+ this.connect();
214
+ }
215
+ };
216
+ this.handleOffline = () => {
217
+ console.log("\u2601\uFE0F CloudAdapter: Network went offline");
218
+ this._isOnline = false;
219
+ this.emit("network_offline");
220
+ if (this._state === "connected" || this._state === "connecting") {
221
+ this._state = "disconnected";
222
+ this.emit("disconnected");
223
+ }
224
+ };
225
+ window.addEventListener("online", this.handleOnline);
226
+ window.addEventListener("offline", this.handleOffline);
227
+ }
228
+ cleanupNetworkDetection() {
229
+ if (typeof window === "undefined") {
230
+ return;
231
+ }
232
+ if (this.handleOnline) {
233
+ window.removeEventListener("online", this.handleOnline);
234
+ }
235
+ if (this.handleOffline) {
236
+ window.removeEventListener("offline", this.handleOffline);
237
+ }
238
+ }
194
239
  setToken(token) {
195
240
  this.token = token;
196
241
  }
@@ -284,6 +329,7 @@ var init_CloudAdapter = __esm({
284
329
  this.ws.close();
285
330
  this.ws = null;
286
331
  }
332
+ this.cleanupNetworkDetection();
287
333
  this._state = "disconnected";
288
334
  this.emit("disconnected");
289
335
  }
@@ -400,7 +446,7 @@ var MindCache = class {
400
446
  listeners = {};
401
447
  globalListeners = [];
402
448
  // Metadata
403
- version = "3.1.0";
449
+ version = "3.3.2";
404
450
  // Internal flag to prevent sync loops when receiving remote updates
405
451
  // (Less critical with Yjs but kept for API compat)
406
452
  _isRemoteUpdate = false;
@@ -460,8 +506,22 @@ var MindCache = class {
460
506
  constructor(options) {
461
507
  this.doc = new Y.Doc();
462
508
  this.rootMap = this.doc.getMap("mindcache");
463
- this.rootMap.observe((event) => {
464
- event.keysChanged.forEach((key) => {
509
+ this.rootMap.observeDeep((events) => {
510
+ const keysAffected = /* @__PURE__ */ new Set();
511
+ events.forEach((event) => {
512
+ if (event.target === this.rootMap) {
513
+ const mapEvent = event;
514
+ mapEvent.keysChanged.forEach((key) => keysAffected.add(key));
515
+ } else if (event.target.parent === this.rootMap) {
516
+ for (const [key, val] of this.rootMap) {
517
+ if (val === event.target) {
518
+ keysAffected.add(key);
519
+ break;
520
+ }
521
+ }
522
+ }
523
+ });
524
+ keysAffected.forEach((key) => {
465
525
  const entryMap = this.rootMap.get(key);
466
526
  if (entryMap) {
467
527
  const value = entryMap.get("value");
@@ -474,8 +534,6 @@ var MindCache = class {
474
534
  }
475
535
  }
476
536
  });
477
- });
478
- this.rootMap.observeDeep((_events) => {
479
537
  this.notifyGlobalListeners();
480
538
  });
481
539
  this.initGlobalUndoManager();
@@ -743,6 +801,19 @@ var MindCache = class {
743
801
  get isCloud() {
744
802
  return this._cloudConfig !== null;
745
803
  }
804
+ /**
805
+ * Browser network status. Returns true if online or in local-only mode.
806
+ * In cloud mode, this updates instantly when network status changes.
807
+ */
808
+ get isOnline() {
809
+ if (!this._cloudAdapter) {
810
+ if (typeof navigator !== "undefined") {
811
+ return navigator.onLine;
812
+ }
813
+ return true;
814
+ }
815
+ return this._cloudAdapter.isOnline;
816
+ }
746
817
  async waitForSync() {
747
818
  if (this._isLoaded) {
748
819
  return;