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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-BgpqZE00.mjs';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-BgpqZE00.mjs';
1
+ import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-CeGQhFk9.mjs';
2
+ export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-CeGQhFk9.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  interface IndexedDBConfig {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-BgpqZE00.js';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-BgpqZE00.js';
1
+ import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-CeGQhFk9.js';
2
+ export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-CeGQhFk9.js';
3
3
  import 'yjs';
4
4
 
5
5
  interface IndexedDBConfig {
package/dist/index.js CHANGED
@@ -211,6 +211,7 @@ var init_CloudAdapter = __esm({
211
211
  if (!config.baseUrl) {
212
212
  throw new Error("MindCache Cloud: baseUrl is required. Please provide the cloud API URL in your configuration.");
213
213
  }
214
+ this.setupNetworkDetection();
214
215
  }
215
216
  ws = null;
216
217
  mindcache = null;
@@ -218,8 +219,52 @@ var init_CloudAdapter = __esm({
218
219
  reconnectAttempts = 0;
219
220
  reconnectTimeout = null;
220
221
  _state = "disconnected";
222
+ _isOnline = true;
223
+ // Browser network status
221
224
  listeners = {};
222
225
  token = null;
226
+ handleOnline = null;
227
+ handleOffline = null;
228
+ /** Browser network status - instantly updated via navigator.onLine */
229
+ get isOnline() {
230
+ return this._isOnline;
231
+ }
232
+ setupNetworkDetection() {
233
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
234
+ return;
235
+ }
236
+ this._isOnline = navigator.onLine;
237
+ this.handleOnline = () => {
238
+ console.log("\u2601\uFE0F CloudAdapter: Network is back online");
239
+ this._isOnline = true;
240
+ this.emit("network_online");
241
+ if (this._state === "disconnected" || this._state === "error") {
242
+ this.connect();
243
+ }
244
+ };
245
+ this.handleOffline = () => {
246
+ console.log("\u2601\uFE0F CloudAdapter: Network went offline");
247
+ this._isOnline = false;
248
+ this.emit("network_offline");
249
+ if (this._state === "connected" || this._state === "connecting") {
250
+ this._state = "disconnected";
251
+ this.emit("disconnected");
252
+ }
253
+ };
254
+ window.addEventListener("online", this.handleOnline);
255
+ window.addEventListener("offline", this.handleOffline);
256
+ }
257
+ cleanupNetworkDetection() {
258
+ if (typeof window === "undefined") {
259
+ return;
260
+ }
261
+ if (this.handleOnline) {
262
+ window.removeEventListener("online", this.handleOnline);
263
+ }
264
+ if (this.handleOffline) {
265
+ window.removeEventListener("offline", this.handleOffline);
266
+ }
267
+ }
223
268
  setToken(token) {
224
269
  this.token = token;
225
270
  }
@@ -313,6 +358,7 @@ var init_CloudAdapter = __esm({
313
358
  this.ws.close();
314
359
  this.ws = null;
315
360
  }
361
+ this.cleanupNetworkDetection();
316
362
  this._state = "disconnected";
317
363
  this.emit("disconnected");
318
364
  }
@@ -429,7 +475,7 @@ var MindCache = class {
429
475
  listeners = {};
430
476
  globalListeners = [];
431
477
  // Metadata
432
- version = "3.3.1";
478
+ version = "3.3.2";
433
479
  // Internal flag to prevent sync loops when receiving remote updates
434
480
  // (Less critical with Yjs but kept for API compat)
435
481
  _isRemoteUpdate = false;
@@ -784,6 +830,19 @@ var MindCache = class {
784
830
  get isCloud() {
785
831
  return this._cloudConfig !== null;
786
832
  }
833
+ /**
834
+ * Browser network status. Returns true if online or in local-only mode.
835
+ * In cloud mode, this updates instantly when network status changes.
836
+ */
837
+ get isOnline() {
838
+ if (!this._cloudAdapter) {
839
+ if (typeof navigator !== "undefined") {
840
+ return navigator.onLine;
841
+ }
842
+ return true;
843
+ }
844
+ return this._cloudAdapter.isOnline;
845
+ }
787
846
  async waitForSync() {
788
847
  if (this._isLoaded) {
789
848
  return;