@unhingged/vizu-core 0.1.16 → 0.1.18

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
@@ -122,6 +122,9 @@ function renderAttachmentsHtml(attachments) {
122
122
  function migrateComment(raw) {
123
123
  if (!raw || typeof raw !== "object") return raw;
124
124
  const next = { ...raw };
125
+ if (next.id == null && next._id != null) {
126
+ next.id = next._id;
127
+ }
125
128
  if (!Array.isArray(next.fingerprints) || next.fingerprints.length === 0) {
126
129
  if (next.fingerprint) {
127
130
  next.fingerprints = [next.fingerprint];
@@ -2334,11 +2337,22 @@ var Sidebar = class {
2334
2337
  const conf = this.lastConfidence;
2335
2338
  const orphans = comments.filter((c) => conf.get(c.id) === "orphaned");
2336
2339
  const anchored = comments.filter((c) => conf.get(c.id) !== "orphaned");
2337
- const visible = this.filter === "open" ? anchored.filter((c) => (c.status ?? "open") === "open") : anchored;
2338
- const visibleOrphans = this.filter === "open" ? [] : orphans;
2340
+ const statusOf = (c) => c.status ?? "open";
2341
+ const visible = this.filter === "open" ? anchored.filter((c) => statusOf(c) === "open") : this.filter === "resolved" ? anchored.filter((c) => statusOf(c) === "resolved") : anchored;
2342
+ const visibleOrphans = this.filter === "all" ? orphans : [];
2339
2343
  const counts = countByStatus(comments);
2340
2344
  if (visible.length === 0 && visibleOrphans.length === 0) {
2341
- const emptyCopy = this.filter === "open" && comments.length > 0 ? `<strong>Nothing open.</strong>${counts.resolved + counts.wontfix} closed comment${counts.resolved + counts.wontfix === 1 ? "" : "s"} hidden. Switch to <em>All</em> to see them.` : "<strong>No comments yet</strong>Click any element on the page to leave one.";
2345
+ let emptyCopy;
2346
+ if (comments.length === 0) {
2347
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2348
+ } else if (this.filter === "open") {
2349
+ const closed = counts.resolved + counts.wontfix;
2350
+ emptyCopy = `<strong>Nothing open.</strong>${closed} closed comment${closed === 1 ? "" : "s"} hidden. Switch to <em>All</em> to see them.`;
2351
+ } else if (this.filter === "resolved") {
2352
+ emptyCopy = `<strong>Nothing resolved.</strong>${counts.open} still open. Switch to <em>Open</em> or <em>All</em> to see more.`;
2353
+ } else {
2354
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2355
+ }
2342
2356
  this.el.innerHTML = `
2343
2357
  ${this.headerHtml(comments.length, counts)}
2344
2358
  <div class="vz-sidebar-body">
@@ -2434,6 +2448,9 @@ var Sidebar = class {
2434
2448
  <button class="vz-sidebar-filter ${this.filter === "open" ? "is-active" : ""}" data-vz="filter" data-filter="open" role="tab" aria-selected="${this.filter === "open"}">
2435
2449
  Open <span class="vz-sidebar-filter-count">${counts.open}</span>
2436
2450
  </button>
2451
+ <button class="vz-sidebar-filter ${this.filter === "resolved" ? "is-active" : ""}" data-vz="filter" data-filter="resolved" role="tab" aria-selected="${this.filter === "resolved"}">
2452
+ Resolved <span class="vz-sidebar-filter-count">${counts.resolved}</span>
2453
+ </button>
2437
2454
  <button class="vz-sidebar-filter ${this.filter === "all" ? "is-active" : ""}" data-vz="filter" data-filter="all" role="tab" aria-selected="${this.filter === "all"}">
2438
2455
  All <span class="vz-sidebar-filter-count">${total}</span>
2439
2456
  </button>
@@ -4317,10 +4334,26 @@ var Vizu = class {
4317
4334
  this.refreshUi();
4318
4335
  }
4319
4336
  async removeComment(id) {
4320
- const comment = this.comments.find((c) => c.id === id);
4321
- if (!comment) return;
4337
+ const idx = this.comments.findIndex((c) => c.id === id);
4338
+ if (idx === -1) return;
4339
+ const comment = this.comments[idx];
4322
4340
  this.comments = this.comments.filter((c) => c.id !== id);
4323
- await this.storage.removeComment(this.opts.namespace, id);
4341
+ try {
4342
+ await this.storage.removeComment(this.opts.namespace, id);
4343
+ } catch (err) {
4344
+ this.comments.splice(idx, 0, comment);
4345
+ const status = err?.status;
4346
+ const code = err?.code ?? "";
4347
+ const msg = status === 403 || code === "forbidden" ? "Delete failed \u2014 you don't have permission." : status === 401 || code === "auth_required" ? "Delete failed \u2014 please sign in again." : "Delete failed. Please try again.";
4348
+ this.pill?.toast(msg);
4349
+ if (this.popover?.isOpen()) {
4350
+ const anchors = this.popover.getAnchors();
4351
+ if (anchors[0]) this.popover.update(this.commentsForElement(anchors[0]));
4352
+ }
4353
+ this.refreshUi();
4354
+ if (typeof console !== "undefined") console.warn("[vizu] removeComment failed", err);
4355
+ return;
4356
+ }
4324
4357
  this.bus.emit("comment:removed", { id, comment });
4325
4358
  if (this.popover?.isOpen()) {
4326
4359
  const anchors = this.popover.getAnchors();