@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/index.cjs CHANGED
@@ -3179,6 +3179,23 @@ var Vizu = class {
3179
3179
  getUser() {
3180
3180
  return this.user;
3181
3181
  }
3182
+ /**
3183
+ * Cloud-mode write gate. Every entry point that creates or modifies a
3184
+ * comment first checks that we have a known user. Without one, the
3185
+ * write would land as Anonymous (or 401 on the backend) — neither is
3186
+ * the right UX. So we re-trigger the sign-in popup and refuse the
3187
+ * action. The user signs in, this.user gets set via onAuthChanged,
3188
+ * then they can retry the click themselves.
3189
+ *
3190
+ * Returns true when the caller may proceed.
3191
+ */
3192
+ requireUserOrAuth() {
3193
+ if (!(this.storage instanceof CloudStorageAdapter)) return true;
3194
+ if (this.user) return true;
3195
+ void this.storage.preflightAuth().catch(() => {
3196
+ });
3197
+ return false;
3198
+ }
3182
3199
  /* ===== Lifecycle ===== */
3183
3200
  enable() {
3184
3201
  if (this.enabled) return;
@@ -3347,6 +3364,7 @@ var Vizu = class {
3347
3364
  * patch for adapters that don't implement reply ops.
3348
3365
  */
3349
3366
  async addReply(commentId, text, mentions) {
3367
+ if (!this.requireUserOrAuth()) return null;
3350
3368
  const idx = this.comments.findIndex((c) => c.id === commentId);
3351
3369
  if (idx === -1) return null;
3352
3370
  const reply = {
@@ -3413,6 +3431,7 @@ var Vizu = class {
3413
3431
  /* ===== Multi-select API ===== */
3414
3432
  /** Toggle multi-select mode. When on, plain clicks accumulate into the selection. */
3415
3433
  toggleMultiSelectMode() {
3434
+ if (!this.requireUserOrAuth()) return;
3416
3435
  this.multiSelectMode = !this.multiSelectMode;
3417
3436
  if (!this.multiSelectMode) this.clearSelection();
3418
3437
  this.pill?.setMultiSelectState(this.multiSelectMode, this.pendingFingerprints.length);
@@ -3574,6 +3593,7 @@ var Vizu = class {
3574
3593
  p.onSelect(fp2);
3575
3594
  return;
3576
3595
  }
3596
+ if (!this.requireUserOrAuth()) return;
3577
3597
  const fp = fingerprint(el);
3578
3598
  if (this.popover?.isOpen() && e.shiftKey) {
3579
3599
  this.popover.addAnchor(fp, el);
@@ -3621,6 +3641,7 @@ var Vizu = class {
3621
3641
  );
3622
3642
  }
3623
3643
  async addCommentFromPopover(text, fps, references, mentions, attachments) {
3644
+ if (!this.requireUserOrAuth()) return;
3624
3645
  if (fps.length === 0) return;
3625
3646
  const pageUrl = typeof location !== "undefined" ? location.href : void 0;
3626
3647
  const c = {