@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/auto.cjs CHANGED
@@ -112,6 +112,9 @@ function renderAttachmentsHtml(attachments) {
112
112
  function migrateComment(raw) {
113
113
  if (!raw || typeof raw !== "object") return raw;
114
114
  const next = { ...raw };
115
+ if (next.id == null && next._id != null) {
116
+ next.id = next._id;
117
+ }
115
118
  if (!Array.isArray(next.fingerprints) || next.fingerprints.length === 0) {
116
119
  if (next.fingerprint) {
117
120
  next.fingerprints = [next.fingerprint];
@@ -2324,11 +2327,22 @@ var Sidebar = class {
2324
2327
  const conf = this.lastConfidence;
2325
2328
  const orphans = comments.filter((c) => conf.get(c.id) === "orphaned");
2326
2329
  const anchored = comments.filter((c) => conf.get(c.id) !== "orphaned");
2327
- const visible = this.filter === "open" ? anchored.filter((c) => (c.status ?? "open") === "open") : anchored;
2328
- const visibleOrphans = this.filter === "open" ? [] : orphans;
2330
+ const statusOf = (c) => c.status ?? "open";
2331
+ const visible = this.filter === "open" ? anchored.filter((c) => statusOf(c) === "open") : this.filter === "resolved" ? anchored.filter((c) => statusOf(c) === "resolved") : anchored;
2332
+ const visibleOrphans = this.filter === "all" ? orphans : [];
2329
2333
  const counts = countByStatus(comments);
2330
2334
  if (visible.length === 0 && visibleOrphans.length === 0) {
2331
- 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.";
2335
+ let emptyCopy;
2336
+ if (comments.length === 0) {
2337
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2338
+ } else if (this.filter === "open") {
2339
+ const closed = counts.resolved + counts.wontfix;
2340
+ emptyCopy = `<strong>Nothing open.</strong>${closed} closed comment${closed === 1 ? "" : "s"} hidden. Switch to <em>All</em> to see them.`;
2341
+ } else if (this.filter === "resolved") {
2342
+ emptyCopy = `<strong>Nothing resolved.</strong>${counts.open} still open. Switch to <em>Open</em> or <em>All</em> to see more.`;
2343
+ } else {
2344
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2345
+ }
2332
2346
  this.el.innerHTML = `
2333
2347
  ${this.headerHtml(comments.length, counts)}
2334
2348
  <div class="vz-sidebar-body">
@@ -2424,6 +2438,9 @@ var Sidebar = class {
2424
2438
  <button class="vz-sidebar-filter ${this.filter === "open" ? "is-active" : ""}" data-vz="filter" data-filter="open" role="tab" aria-selected="${this.filter === "open"}">
2425
2439
  Open <span class="vz-sidebar-filter-count">${counts.open}</span>
2426
2440
  </button>
2441
+ <button class="vz-sidebar-filter ${this.filter === "resolved" ? "is-active" : ""}" data-vz="filter" data-filter="resolved" role="tab" aria-selected="${this.filter === "resolved"}">
2442
+ Resolved <span class="vz-sidebar-filter-count">${counts.resolved}</span>
2443
+ </button>
2427
2444
  <button class="vz-sidebar-filter ${this.filter === "all" ? "is-active" : ""}" data-vz="filter" data-filter="all" role="tab" aria-selected="${this.filter === "all"}">
2428
2445
  All <span class="vz-sidebar-filter-count">${total}</span>
2429
2446
  </button>
@@ -4307,10 +4324,26 @@ var Vizu = class {
4307
4324
  this.refreshUi();
4308
4325
  }
4309
4326
  async removeComment(id) {
4310
- const comment = this.comments.find((c) => c.id === id);
4311
- if (!comment) return;
4327
+ const idx = this.comments.findIndex((c) => c.id === id);
4328
+ if (idx === -1) return;
4329
+ const comment = this.comments[idx];
4312
4330
  this.comments = this.comments.filter((c) => c.id !== id);
4313
- await this.storage.removeComment(this.opts.namespace, id);
4331
+ try {
4332
+ await this.storage.removeComment(this.opts.namespace, id);
4333
+ } catch (err) {
4334
+ this.comments.splice(idx, 0, comment);
4335
+ const status = err?.status;
4336
+ const code = err?.code ?? "";
4337
+ 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.";
4338
+ this.pill?.toast(msg);
4339
+ if (this.popover?.isOpen()) {
4340
+ const anchors = this.popover.getAnchors();
4341
+ if (anchors[0]) this.popover.update(this.commentsForElement(anchors[0]));
4342
+ }
4343
+ this.refreshUi();
4344
+ if (typeof console !== "undefined") console.warn("[vizu] removeComment failed", err);
4345
+ return;
4346
+ }
4314
4347
  this.bus.emit("comment:removed", { id, comment });
4315
4348
  if (this.popover?.isOpen()) {
4316
4349
  const anchors = this.popover.getAnchors();