@unhingged/vizu-core 0.1.14 → 0.1.16

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
@@ -319,6 +319,16 @@ interface VizuOptions {
319
319
  */
320
320
  onCommentAdded?: (c: VizuComment) => void;
321
321
  onCommentRemoved?: (id: string) => void;
322
+ /**
323
+ * Optional override for the @ mention picker's member list. When set,
324
+ * the popover dropdown calls this instead of going to the cloud
325
+ * `/api/workspaces/[slug]/mentionable` route. Useful for non-cloud
326
+ * hosts (local / memory storage) that still want @-mentions, and for
327
+ * tests / playgrounds that need a static teammate list.
328
+ *
329
+ * Return an empty array to suppress the dropdown.
330
+ */
331
+ mentionable?: () => MentionableUser[] | Promise<MentionableUser[]>;
322
332
  }
323
333
  /**
324
334
  * Typed event map. Every event payload is an object (never bare values) so the
@@ -680,8 +690,13 @@ declare class Vizu {
680
690
  /**
681
691
  * Fetch the list of users who can be @-mentioned on the current
682
692
  * workspace. Used by the popover's mention dropdown; hosts can also
683
- * call this directly to build their own picker. Returns [] for
684
- * non-cloud adapters (no workspace, no member list to fetch from).
693
+ * call this directly to build their own picker.
694
+ *
695
+ * Resolution order:
696
+ * 1. `options.mentionable` if provided — host-supplied static or
697
+ * custom resolver. Wins over everything else.
698
+ * 2. Cloud adapter's API call if running cloud mode.
699
+ * 3. Empty array (non-cloud, no override).
685
700
  */
686
701
  searchMentionable(): Promise<MentionableUser[]>;
687
702
  /**
package/dist/index.d.ts CHANGED
@@ -319,6 +319,16 @@ interface VizuOptions {
319
319
  */
320
320
  onCommentAdded?: (c: VizuComment) => void;
321
321
  onCommentRemoved?: (id: string) => void;
322
+ /**
323
+ * Optional override for the @ mention picker's member list. When set,
324
+ * the popover dropdown calls this instead of going to the cloud
325
+ * `/api/workspaces/[slug]/mentionable` route. Useful for non-cloud
326
+ * hosts (local / memory storage) that still want @-mentions, and for
327
+ * tests / playgrounds that need a static teammate list.
328
+ *
329
+ * Return an empty array to suppress the dropdown.
330
+ */
331
+ mentionable?: () => MentionableUser[] | Promise<MentionableUser[]>;
322
332
  }
323
333
  /**
324
334
  * Typed event map. Every event payload is an object (never bare values) so the
@@ -680,8 +690,13 @@ declare class Vizu {
680
690
  /**
681
691
  * Fetch the list of users who can be @-mentioned on the current
682
692
  * workspace. Used by the popover's mention dropdown; hosts can also
683
- * call this directly to build their own picker. Returns [] for
684
- * non-cloud adapters (no workspace, no member list to fetch from).
693
+ * call this directly to build their own picker.
694
+ *
695
+ * Resolution order:
696
+ * 1. `options.mentionable` if provided — host-supplied static or
697
+ * custom resolver. Wins over everything else.
698
+ * 2. Cloud adapter's API call if running cloud mode.
699
+ * 3. Empty array (non-cloud, no override).
685
700
  */
686
701
  searchMentionable(): Promise<MentionableUser[]>;
687
702
  /**
package/dist/index.js CHANGED
@@ -3236,7 +3236,9 @@ var STYLES = `
3236
3236
  .vz-ref:hover { background: color-mix(in srgb, var(--vz-accent) 30%, var(--vz-bg-hover)); transform: translateY(-1px); }
3237
3237
  .vz-ref::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--vz-accent); flex-shrink: 0; }
3238
3238
 
3239
- /* Inline @mention chip (rendered inside displayed comments) */
3239
+ /* Inline @mention chip (rendered inside displayed comments). user-select
3240
+ * prevents the user from selecting the chip's text and editing it; the
3241
+ * displayed comment is intentionally read-only after save. */
3240
3242
  .vz-mention {
3241
3243
  display: inline-flex; align-items: center;
3242
3244
  padding: 1px 8px 1px 8px;
@@ -3246,13 +3248,21 @@ var STYLES = `
3246
3248
  font-size: 12px; font-weight: 600;
3247
3249
  vertical-align: baseline;
3248
3250
  margin: 0 1px;
3251
+ user-select: none;
3252
+ -webkit-user-select: none;
3253
+ cursor: default;
3249
3254
  }
3250
3255
 
3251
- /* Mention chip inside the editor (contenteditable=false token) */
3256
+ /* Mention chip inside the editor (contenteditable=false token). Same
3257
+ * non-selection rules as .vz-mention so the chip stays atomic even
3258
+ * inside the editable surface \u2014 caret can land before/after but not
3259
+ * inside, no partial-text edit. */
3252
3260
  .vz-chip-mention {
3253
3261
  background: color-mix(in srgb, var(--vz-accent) 16%, var(--vz-bg-hover));
3254
3262
  color: var(--vz-accent);
3255
3263
  font-weight: 600;
3264
+ user-select: none;
3265
+ -webkit-user-select: none;
3256
3266
  }
3257
3267
  .vz-chip-mention::before { display: none; }
3258
3268
 
@@ -3332,6 +3342,10 @@ var STYLES = `
3332
3342
  pointer-events: none;
3333
3343
  z-index: 1;
3334
3344
  }
3345
+ /* Opt-in only during an active dragover. The explicit display:flex
3346
+ * above out-specifics the browser default for [hidden], so we restate
3347
+ * the hide rule here to make the attribute toggle effective. */
3348
+ .vz-attachment-drop-hint[hidden] { display: none; }
3335
3349
 
3336
3350
  /* Pending attachments (uploaded but not yet saved) */
3337
3351
  .vz-attachment-list {
@@ -3728,10 +3742,25 @@ var Vizu = class {
3728
3742
  /**
3729
3743
  * Fetch the list of users who can be @-mentioned on the current
3730
3744
  * workspace. Used by the popover's mention dropdown; hosts can also
3731
- * call this directly to build their own picker. Returns [] for
3732
- * non-cloud adapters (no workspace, no member list to fetch from).
3745
+ * call this directly to build their own picker.
3746
+ *
3747
+ * Resolution order:
3748
+ * 1. `options.mentionable` if provided — host-supplied static or
3749
+ * custom resolver. Wins over everything else.
3750
+ * 2. Cloud adapter's API call if running cloud mode.
3751
+ * 3. Empty array (non-cloud, no override).
3733
3752
  */
3734
3753
  async searchMentionable() {
3754
+ if (this.opts.mentionable) {
3755
+ try {
3756
+ return await this.opts.mentionable();
3757
+ } catch (err) {
3758
+ if (typeof console !== "undefined") {
3759
+ console.warn("[vizu] options.mentionable threw", err);
3760
+ }
3761
+ return [];
3762
+ }
3763
+ }
3735
3764
  if (this.storage instanceof CloudStorageAdapter) {
3736
3765
  return this.storage.searchMentionable();
3737
3766
  }
@@ -3946,10 +3975,29 @@ var Vizu = class {
3946
3975
  replies: [...this.comments[idx].replies ?? [], reply]
3947
3976
  };
3948
3977
  this.comments[idx] = updated;
3949
- if (this.storage.addReply) {
3950
- await this.storage.addReply(this.opts.namespace, commentId, reply);
3951
- } else {
3952
- await this.storage.updateComment(this.opts.namespace, commentId, { replies: updated.replies });
3978
+ try {
3979
+ if (this.storage.addReply) {
3980
+ await this.storage.addReply(this.opts.namespace, commentId, reply);
3981
+ } else {
3982
+ await this.storage.updateComment(this.opts.namespace, commentId, { replies: updated.replies });
3983
+ }
3984
+ } catch (err) {
3985
+ const cur = this.comments[idx];
3986
+ this.comments[idx] = {
3987
+ ...cur,
3988
+ replies: (cur.replies ?? []).filter((r) => r.id !== reply.id)
3989
+ };
3990
+ const code = err?.code ?? "";
3991
+ const status = err?.status;
3992
+ const msg = status === 403 || code === "forbidden" ? "Reply failed \u2014 you don't have permission." : status === 401 || code === "auth_required" ? "Reply failed \u2014 please sign in again." : "Reply failed. Please try again.";
3993
+ this.pill?.toast(msg);
3994
+ this.refreshUi();
3995
+ if (this.popover?.isOpen()) {
3996
+ const anchors = this.popover.getAnchors();
3997
+ if (anchors[0]) this.popover.update(this.commentsForElement(anchors[0]));
3998
+ }
3999
+ if (typeof console !== "undefined") console.warn("[vizu] addReply failed", err);
4000
+ return null;
3953
4001
  }
3954
4002
  this.bus.emit("comment:updated", { comment: updated });
3955
4003
  this.refreshUi();