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.
@@ -142,7 +142,7 @@ declare class MindCache {
142
142
  private rootMap;
143
143
  private listeners;
144
144
  private globalListeners;
145
- readonly version = "3.1.0";
145
+ readonly version = "3.3.2";
146
146
  private _isRemoteUpdate;
147
147
  private normalizeSystemTags;
148
148
  private _cloudAdapter;
@@ -212,6 +212,11 @@ declare class MindCache {
212
212
  get isLoaded(): boolean;
213
213
  protected _getCloudAdapterClass(): Promise<any>;
214
214
  get isCloud(): boolean;
215
+ /**
216
+ * Browser network status. Returns true if online or in local-only mode.
217
+ * In cloud mode, this updates instantly when network status changes.
218
+ */
219
+ get isOnline(): boolean;
215
220
  waitForSync(): Promise<void>;
216
221
  disconnect(): void;
217
222
  isRemoteUpdate(): boolean;
@@ -498,6 +503,8 @@ interface CloudAdapterEvents {
498
503
  disconnected: () => void;
499
504
  error: (error: Error) => void;
500
505
  synced: () => void;
506
+ network_online: () => void;
507
+ network_offline: () => void;
501
508
  }
502
509
 
503
510
  declare class CloudAdapter {
@@ -508,9 +515,16 @@ declare class CloudAdapter {
508
515
  private reconnectAttempts;
509
516
  private reconnectTimeout;
510
517
  private _state;
518
+ private _isOnline;
511
519
  private listeners;
512
520
  private token;
521
+ private handleOnline;
522
+ private handleOffline;
513
523
  constructor(config: CloudConfig);
524
+ /** Browser network status - instantly updated via navigator.onLine */
525
+ get isOnline(): boolean;
526
+ private setupNetworkDetection;
527
+ private cleanupNetworkDetection;
514
528
  setToken(token: string): void;
515
529
  setTokenProvider(provider: () => Promise<string>): void;
516
530
  get state(): ConnectionState;
@@ -142,7 +142,7 @@ declare class MindCache {
142
142
  private rootMap;
143
143
  private listeners;
144
144
  private globalListeners;
145
- readonly version = "3.1.0";
145
+ readonly version = "3.3.2";
146
146
  private _isRemoteUpdate;
147
147
  private normalizeSystemTags;
148
148
  private _cloudAdapter;
@@ -212,6 +212,11 @@ declare class MindCache {
212
212
  get isLoaded(): boolean;
213
213
  protected _getCloudAdapterClass(): Promise<any>;
214
214
  get isCloud(): boolean;
215
+ /**
216
+ * Browser network status. Returns true if online or in local-only mode.
217
+ * In cloud mode, this updates instantly when network status changes.
218
+ */
219
+ get isOnline(): boolean;
215
220
  waitForSync(): Promise<void>;
216
221
  disconnect(): void;
217
222
  isRemoteUpdate(): boolean;
@@ -498,6 +503,8 @@ interface CloudAdapterEvents {
498
503
  disconnected: () => void;
499
504
  error: (error: Error) => void;
500
505
  synced: () => void;
506
+ network_online: () => void;
507
+ network_offline: () => void;
501
508
  }
502
509
 
503
510
  declare class CloudAdapter {
@@ -508,9 +515,16 @@ declare class CloudAdapter {
508
515
  private reconnectAttempts;
509
516
  private reconnectTimeout;
510
517
  private _state;
518
+ private _isOnline;
511
519
  private listeners;
512
520
  private token;
521
+ private handleOnline;
522
+ private handleOffline;
513
523
  constructor(config: CloudConfig);
524
+ /** Browser network status - instantly updated via navigator.onLine */
525
+ get isOnline(): boolean;
526
+ private setupNetworkDetection;
527
+ private cleanupNetworkDetection;
514
528
  setToken(token: string): void;
515
529
  setTokenProvider(provider: () => Promise<string>): void;
516
530
  get state(): ConnectionState;
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CSncOr3V.mjs';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CSncOr3V.mjs';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CeGQhFk9.mjs';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CeGQhFk9.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CSncOr3V.js';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CSncOr3V.js';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CeGQhFk9.js';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CeGQhFk9.js';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -210,6 +210,7 @@ var init_CloudAdapter = __esm({
210
210
  if (!config.baseUrl) {
211
211
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
212
212
  }
213
+ this.setupNetworkDetection();
213
214
  }
214
215
  ws = null;
215
216
  mindcache = null;
@@ -217,8 +218,52 @@ var init_CloudAdapter = __esm({
217
218
  reconnectAttempts = 0;
218
219
  reconnectTimeout = null;
219
220
  _state = "disconnected";
221
+ _isOnline = true;
222
+ // Browser network status
220
223
  listeners = {};
221
224
  token = null;
225
+ handleOnline = null;
226
+ handleOffline = null;
227
+ /** Browser network status - instantly updated via navigator.onLine */
228
+ get isOnline() {
229
+ return this._isOnline;
230
+ }
231
+ setupNetworkDetection() {
232
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
233
+ return;
234
+ }
235
+ this._isOnline = navigator.onLine;
236
+ this.handleOnline = () => {
237
+ console.log("\u2601\uFE0F CloudAdapter: Network is back online");
238
+ this._isOnline = true;
239
+ this.emit("network_online");
240
+ if (this._state === "disconnected" || this._state === "error") {
241
+ this.connect();
242
+ }
243
+ };
244
+ this.handleOffline = () => {
245
+ console.log("\u2601\uFE0F CloudAdapter: Network went offline");
246
+ this._isOnline = false;
247
+ this.emit("network_offline");
248
+ if (this._state === "connected" || this._state === "connecting") {
249
+ this._state = "disconnected";
250
+ this.emit("disconnected");
251
+ }
252
+ };
253
+ window.addEventListener("online", this.handleOnline);
254
+ window.addEventListener("offline", this.handleOffline);
255
+ }
256
+ cleanupNetworkDetection() {
257
+ if (typeof window === "undefined") {
258
+ return;
259
+ }
260
+ if (this.handleOnline) {
261
+ window.removeEventListener("online", this.handleOnline);
262
+ }
263
+ if (this.handleOffline) {
264
+ window.removeEventListener("offline", this.handleOffline);
265
+ }
266
+ }
222
267
  setToken(token) {
223
268
  this.token = token;
224
269
  }
@@ -312,6 +357,7 @@ var init_CloudAdapter = __esm({
312
357
  this.ws.close();
313
358
  this.ws = null;
314
359
  }
360
+ this.cleanupNetworkDetection();
315
361
  this._state = "disconnected";
316
362
  this.emit("disconnected");
317
363
  }
@@ -428,7 +474,7 @@ var MindCache = class {
428
474
  listeners = {};
429
475
  globalListeners = [];
430
476
  // Metadata
431
- version = "3.1.0";
477
+ version = "3.3.2";
432
478
  // Internal flag to prevent sync loops when receiving remote updates
433
479
  // (Less critical with Yjs but kept for API compat)
434
480
  _isRemoteUpdate = false;
@@ -488,8 +534,22 @@ var MindCache = class {
488
534
  constructor(options) {
489
535
  this.doc = new Y__namespace.Doc();
490
536
  this.rootMap = this.doc.getMap("mindcache");
491
- this.rootMap.observe((event) => {
492
- event.keysChanged.forEach((key) => {
537
+ this.rootMap.observeDeep((events) => {
538
+ const keysAffected = /* @__PURE__ */ new Set();
539
+ events.forEach((event) => {
540
+ if (event.target === this.rootMap) {
541
+ const mapEvent = event;
542
+ mapEvent.keysChanged.forEach((key) => keysAffected.add(key));
543
+ } else if (event.target.parent === this.rootMap) {
544
+ for (const [key, val] of this.rootMap) {
545
+ if (val === event.target) {
546
+ keysAffected.add(key);
547
+ break;
548
+ }
549
+ }
550
+ }
551
+ });
552
+ keysAffected.forEach((key) => {
493
553
  const entryMap = this.rootMap.get(key);
494
554
  if (entryMap) {
495
555
  const value = entryMap.get("value");
@@ -502,8 +562,6 @@ var MindCache = class {
502
562
  }
503
563
  }
504
564
  });
505
- });
506
- this.rootMap.observeDeep((_events) => {
507
565
  this.notifyGlobalListeners();
508
566
  });
509
567
  this.initGlobalUndoManager();
@@ -771,6 +829,19 @@ var MindCache = class {
771
829
  get isCloud() {
772
830
  return this._cloudConfig !== null;
773
831
  }
832
+ /**
833
+ * Browser network status. Returns true if online or in local-only mode.
834
+ * In cloud mode, this updates instantly when network status changes.
835
+ */
836
+ get isOnline() {
837
+ if (!this._cloudAdapter) {
838
+ if (typeof navigator !== "undefined") {
839
+ return navigator.onLine;
840
+ }
841
+ return true;
842
+ }
843
+ return this._cloudAdapter.isOnline;
844
+ }
774
845
  async waitForSync() {
775
846
  if (this._isLoaded) {
776
847
  return;