@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/index.d.cts CHANGED
@@ -635,6 +635,14 @@ declare class Vizu {
635
635
  private selfHealedThisSession;
636
636
  private actions;
637
637
  private user;
638
+ /**
639
+ * Flipped true once the initial loadComments() at construction has
640
+ * settled (success or failure). The cloud onAuthChanged callback uses
641
+ * this to decide whether a subsequent auth change should trigger a
642
+ * re-load: skipped for the initial fire (the explicit loadComments
643
+ * below handles it), fired for every later token acquisition.
644
+ */
645
+ private hasLoadedComments;
638
646
  private enabled;
639
647
  private rafScheduled;
640
648
  private bus;
@@ -650,6 +658,13 @@ declare class Vizu {
650
658
  off<E extends VizuEventName>(event: E, handler: VizuEventHandler<E>): void;
651
659
  setUser(user: VizuUser | null): void;
652
660
  getUser(): VizuUser | null;
661
+ /**
662
+ * Whether the pill belongs on-screen right now. Cloud-mode workspaces
663
+ * keep it hidden until the user is signed in; non-cloud usage (local /
664
+ * memory storage) has no auth and always shows it. Recomputed on every
665
+ * setUser and on mount.
666
+ */
667
+ private shouldShowPill;
653
668
  /**
654
669
  * Cloud-mode write gate. Every entry point that creates or modifies a
655
670
  * comment first checks that we have a known user. Without one, the
package/dist/index.d.ts CHANGED
@@ -635,6 +635,14 @@ declare class Vizu {
635
635
  private selfHealedThisSession;
636
636
  private actions;
637
637
  private user;
638
+ /**
639
+ * Flipped true once the initial loadComments() at construction has
640
+ * settled (success or failure). The cloud onAuthChanged callback uses
641
+ * this to decide whether a subsequent auth change should trigger a
642
+ * re-load: skipped for the initial fire (the explicit loadComments
643
+ * below handles it), fired for every later token acquisition.
644
+ */
645
+ private hasLoadedComments;
638
646
  private enabled;
639
647
  private rafScheduled;
640
648
  private bus;
@@ -650,6 +658,13 @@ declare class Vizu {
650
658
  off<E extends VizuEventName>(event: E, handler: VizuEventHandler<E>): void;
651
659
  setUser(user: VizuUser | null): void;
652
660
  getUser(): VizuUser | null;
661
+ /**
662
+ * Whether the pill belongs on-screen right now. Cloud-mode workspaces
663
+ * keep it hidden until the user is signed in; non-cloud usage (local /
664
+ * memory storage) has no auth and always shows it. Recomputed on every
665
+ * setUser and on mount.
666
+ */
667
+ private shouldShowPill;
653
668
  /**
654
669
  * Cloud-mode write gate. Every entry point that creates or modifies a
655
670
  * comment first checks that we have a known user. Without one, the
package/dist/index.js CHANGED
@@ -436,6 +436,11 @@ var CloudStorageAdapter = class {
436
436
  }
437
437
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
438
438
  async load(_namespace) {
439
+ if (!this.cachedToken || this.isExpired(this.cachedToken)) {
440
+ const fresh = this.readStoredToken();
441
+ if (!fresh || this.isExpired(fresh)) return [];
442
+ this.cachedToken = fresh;
443
+ }
439
444
  const out = [];
440
445
  let cursor = null;
441
446
  do {
@@ -3153,6 +3158,14 @@ var Vizu = class {
3153
3158
  this.selfHealedThisSession = /* @__PURE__ */ new Set();
3154
3159
  this.actions = [];
3155
3160
  this.user = null;
3161
+ /**
3162
+ * Flipped true once the initial loadComments() at construction has
3163
+ * settled (success or failure). The cloud onAuthChanged callback uses
3164
+ * this to decide whether a subsequent auth change should trigger a
3165
+ * re-load: skipped for the initial fire (the explicit loadComments
3166
+ * below handles it), fired for every later token acquisition.
3167
+ */
3168
+ this.hasLoadedComments = false;
3156
3169
  this.enabled = false;
3157
3170
  this.rafScheduled = false;
3158
3171
  this.bus = new EventBus();
@@ -3228,6 +3241,9 @@ var Vizu = class {
3228
3241
  _defaultStorage,
3229
3242
  (info) => {
3230
3243
  if (info.user) this.setUser(info.user);
3244
+ if (this.hasLoadedComments) {
3245
+ void this.loadComments();
3246
+ }
3231
3247
  }
3232
3248
  );
3233
3249
  if (options.actions) this.actions = [...options.actions];
@@ -3235,7 +3251,11 @@ var Vizu = class {
3235
3251
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
3236
3252
  if (typeof window !== "undefined") {
3237
3253
  window.addEventListener("keydown", this.onKeyDown);
3238
- void this.loadComments().then(() => this.subscribeStorage());
3254
+ void this.loadComments().catch(() => {
3255
+ }).finally(() => {
3256
+ this.hasLoadedComments = true;
3257
+ this.subscribeStorage();
3258
+ });
3239
3259
  if (options.startEnabled) this.deferred(() => this.enable());
3240
3260
  }
3241
3261
  }
@@ -3251,11 +3271,25 @@ var Vizu = class {
3251
3271
  this.user = user;
3252
3272
  this.popover?.setUser(user);
3253
3273
  this.pill?.setUser(user);
3274
+ if (this.pill) {
3275
+ if (this.shouldShowPill()) this.pill.show();
3276
+ else this.pill.hide();
3277
+ }
3254
3278
  this.bus.emit("user:changed", { user });
3255
3279
  }
3256
3280
  getUser() {
3257
3281
  return this.user;
3258
3282
  }
3283
+ /**
3284
+ * Whether the pill belongs on-screen right now. Cloud-mode workspaces
3285
+ * keep it hidden until the user is signed in; non-cloud usage (local /
3286
+ * memory storage) has no auth and always shows it. Recomputed on every
3287
+ * setUser and on mount.
3288
+ */
3289
+ shouldShowPill() {
3290
+ if (!(this.storage instanceof CloudStorageAdapter)) return true;
3291
+ return this.user !== null;
3292
+ }
3259
3293
  /**
3260
3294
  * Cloud-mode write gate. Every entry point that creates or modifies a
3261
3295
  * comment first checks that we have a known user. Without one, the
@@ -3619,7 +3653,7 @@ var Vizu = class {
3619
3653
  this.pill.setUser(this.user);
3620
3654
  this.pill.setComments(this.comments);
3621
3655
  this.pill.setMultiSelectState(this.multiSelectMode, this.pendingFingerprints.length);
3622
- this.pill.show();
3656
+ if (this.shouldShowPill()) this.pill.show();
3623
3657
  this.highlighter = new Highlighter(
3624
3658
  this.root,
3625
3659
  this.opts.ignoreSelectors ?? [],