@unhingged/vizu-core 0.1.8 → 0.1.10

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/auto.cjs CHANGED
@@ -462,6 +462,11 @@ var CloudStorageAdapter = class {
462
462
  }
463
463
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
464
464
  async load(_namespace) {
465
+ if (!this.cachedToken || this.isExpired(this.cachedToken)) {
466
+ const fresh = this.readStoredToken();
467
+ if (!fresh || this.isExpired(fresh)) return [];
468
+ this.cachedToken = fresh;
469
+ }
465
470
  const out = [];
466
471
  let cursor = null;
467
472
  do {
@@ -3179,6 +3184,14 @@ var Vizu = class {
3179
3184
  this.selfHealedThisSession = /* @__PURE__ */ new Set();
3180
3185
  this.actions = [];
3181
3186
  this.user = null;
3187
+ /**
3188
+ * Flipped true once the initial loadComments() at construction has
3189
+ * settled (success or failure). The cloud onAuthChanged callback uses
3190
+ * this to decide whether a subsequent auth change should trigger a
3191
+ * re-load: skipped for the initial fire (the explicit loadComments
3192
+ * below handles it), fired for every later token acquisition.
3193
+ */
3194
+ this.hasLoadedComments = false;
3182
3195
  this.enabled = false;
3183
3196
  this.rafScheduled = false;
3184
3197
  this.bus = new EventBus();
@@ -3254,6 +3267,9 @@ var Vizu = class {
3254
3267
  _defaultStorage,
3255
3268
  (info) => {
3256
3269
  if (info.user) this.setUser(info.user);
3270
+ if (this.hasLoadedComments) {
3271
+ void this.loadComments();
3272
+ }
3257
3273
  }
3258
3274
  );
3259
3275
  if (options.actions) this.actions = [...options.actions];
@@ -3261,7 +3277,11 @@ var Vizu = class {
3261
3277
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
3262
3278
  if (typeof window !== "undefined") {
3263
3279
  window.addEventListener("keydown", this.onKeyDown);
3264
- void this.loadComments().then(() => this.subscribeStorage());
3280
+ void this.loadComments().catch(() => {
3281
+ }).finally(() => {
3282
+ this.hasLoadedComments = true;
3283
+ this.subscribeStorage();
3284
+ });
3265
3285
  if (options.startEnabled) this.deferred(() => this.enable());
3266
3286
  }
3267
3287
  }
@@ -3277,11 +3297,25 @@ var Vizu = class {
3277
3297
  this.user = user;
3278
3298
  this.popover?.setUser(user);
3279
3299
  this.pill?.setUser(user);
3300
+ if (this.pill) {
3301
+ if (this.shouldShowPill()) this.pill.show();
3302
+ else this.pill.hide();
3303
+ }
3280
3304
  this.bus.emit("user:changed", { user });
3281
3305
  }
3282
3306
  getUser() {
3283
3307
  return this.user;
3284
3308
  }
3309
+ /**
3310
+ * Whether the pill belongs on-screen right now. Cloud-mode workspaces
3311
+ * keep it hidden until the user is signed in; non-cloud usage (local /
3312
+ * memory storage) has no auth and always shows it. Recomputed on every
3313
+ * setUser and on mount.
3314
+ */
3315
+ shouldShowPill() {
3316
+ if (!(this.storage instanceof CloudStorageAdapter)) return true;
3317
+ return this.user !== null;
3318
+ }
3285
3319
  /**
3286
3320
  * Cloud-mode write gate. Every entry point that creates or modifies a
3287
3321
  * comment first checks that we have a known user. Without one, the
@@ -3645,7 +3679,7 @@ var Vizu = class {
3645
3679
  this.pill.setUser(this.user);
3646
3680
  this.pill.setComments(this.comments);
3647
3681
  this.pill.setMultiSelectState(this.multiSelectMode, this.pendingFingerprints.length);
3648
- this.pill.show();
3682
+ if (this.shouldShowPill()) this.pill.show();
3649
3683
  this.highlighter = new Highlighter(
3650
3684
  this.root,
3651
3685
  this.opts.ignoreSelectors ?? [],