@unhingged/vizu-core 0.1.3 → 0.1.4

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.js CHANGED
@@ -3143,6 +3143,23 @@ var Vizu = class {
3143
3143
  getUser() {
3144
3144
  return this.user;
3145
3145
  }
3146
+ /**
3147
+ * Cloud-mode write gate. Every entry point that creates or modifies a
3148
+ * comment first checks that we have a known user. Without one, the
3149
+ * write would land as Anonymous (or 401 on the backend) — neither is
3150
+ * the right UX. So we re-trigger the sign-in popup and refuse the
3151
+ * action. The user signs in, this.user gets set via onAuthChanged,
3152
+ * then they can retry the click themselves.
3153
+ *
3154
+ * Returns true when the caller may proceed.
3155
+ */
3156
+ requireUserOrAuth() {
3157
+ if (!(this.storage instanceof CloudStorageAdapter)) return true;
3158
+ if (this.user) return true;
3159
+ void this.storage.preflightAuth().catch(() => {
3160
+ });
3161
+ return false;
3162
+ }
3146
3163
  /* ===== Lifecycle ===== */
3147
3164
  enable() {
3148
3165
  if (this.enabled) return;
@@ -3311,6 +3328,7 @@ var Vizu = class {
3311
3328
  * patch for adapters that don't implement reply ops.
3312
3329
  */
3313
3330
  async addReply(commentId, text, mentions) {
3331
+ if (!this.requireUserOrAuth()) return null;
3314
3332
  const idx = this.comments.findIndex((c) => c.id === commentId);
3315
3333
  if (idx === -1) return null;
3316
3334
  const reply = {
@@ -3377,6 +3395,7 @@ var Vizu = class {
3377
3395
  /* ===== Multi-select API ===== */
3378
3396
  /** Toggle multi-select mode. When on, plain clicks accumulate into the selection. */
3379
3397
  toggleMultiSelectMode() {
3398
+ if (!this.requireUserOrAuth()) return;
3380
3399
  this.multiSelectMode = !this.multiSelectMode;
3381
3400
  if (!this.multiSelectMode) this.clearSelection();
3382
3401
  this.pill?.setMultiSelectState(this.multiSelectMode, this.pendingFingerprints.length);
@@ -3538,6 +3557,7 @@ var Vizu = class {
3538
3557
  p.onSelect(fp2);
3539
3558
  return;
3540
3559
  }
3560
+ if (!this.requireUserOrAuth()) return;
3541
3561
  const fp = fingerprint(el);
3542
3562
  if (this.popover?.isOpen() && e.shiftKey) {
3543
3563
  this.popover.addAnchor(fp, el);
@@ -3585,6 +3605,7 @@ var Vizu = class {
3585
3605
  );
3586
3606
  }
3587
3607
  async addCommentFromPopover(text, fps, references, mentions, attachments) {
3608
+ if (!this.requireUserOrAuth()) return;
3588
3609
  if (fps.length === 0) return;
3589
3610
  const pageUrl = typeof location !== "undefined" ? location.href : void 0;
3590
3611
  const c = {