@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.js CHANGED
@@ -86,6 +86,9 @@ function renderAttachmentsHtml(attachments) {
86
86
  function migrateComment(raw) {
87
87
  if (!raw || typeof raw !== "object") return raw;
88
88
  const next = { ...raw };
89
+ if (next.id == null && next._id != null) {
90
+ next.id = next._id;
91
+ }
89
92
  if (!Array.isArray(next.fingerprints) || next.fingerprints.length === 0) {
90
93
  if (next.fingerprint) {
91
94
  next.fingerprints = [next.fingerprint];
@@ -2298,11 +2301,22 @@ var Sidebar = class {
2298
2301
  const conf = this.lastConfidence;
2299
2302
  const orphans = comments.filter((c) => conf.get(c.id) === "orphaned");
2300
2303
  const anchored = comments.filter((c) => conf.get(c.id) !== "orphaned");
2301
- const visible = this.filter === "open" ? anchored.filter((c) => (c.status ?? "open") === "open") : anchored;
2302
- const visibleOrphans = this.filter === "open" ? [] : orphans;
2304
+ const statusOf = (c) => c.status ?? "open";
2305
+ const visible = this.filter === "open" ? anchored.filter((c) => statusOf(c) === "open") : this.filter === "resolved" ? anchored.filter((c) => statusOf(c) === "resolved") : anchored;
2306
+ const visibleOrphans = this.filter === "all" ? orphans : [];
2303
2307
  const counts = countByStatus(comments);
2304
2308
  if (visible.length === 0 && visibleOrphans.length === 0) {
2305
- 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.";
2309
+ let emptyCopy;
2310
+ if (comments.length === 0) {
2311
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2312
+ } else if (this.filter === "open") {
2313
+ const closed = counts.resolved + counts.wontfix;
2314
+ emptyCopy = `<strong>Nothing open.</strong>${closed} closed comment${closed === 1 ? "" : "s"} hidden. Switch to <em>All</em> to see them.`;
2315
+ } else if (this.filter === "resolved") {
2316
+ emptyCopy = `<strong>Nothing resolved.</strong>${counts.open} still open. Switch to <em>Open</em> or <em>All</em> to see more.`;
2317
+ } else {
2318
+ emptyCopy = "<strong>No comments yet</strong>Click any element on the page to leave one.";
2319
+ }
2306
2320
  this.el.innerHTML = `
2307
2321
  ${this.headerHtml(comments.length, counts)}
2308
2322
  <div class="vz-sidebar-body">
@@ -2398,6 +2412,9 @@ var Sidebar = class {
2398
2412
  <button class="vz-sidebar-filter ${this.filter === "open" ? "is-active" : ""}" data-vz="filter" data-filter="open" role="tab" aria-selected="${this.filter === "open"}">
2399
2413
  Open <span class="vz-sidebar-filter-count">${counts.open}</span>
2400
2414
  </button>
2415
+ <button class="vz-sidebar-filter ${this.filter === "resolved" ? "is-active" : ""}" data-vz="filter" data-filter="resolved" role="tab" aria-selected="${this.filter === "resolved"}">
2416
+ Resolved <span class="vz-sidebar-filter-count">${counts.resolved}</span>
2417
+ </button>
2401
2418
  <button class="vz-sidebar-filter ${this.filter === "all" ? "is-active" : ""}" data-vz="filter" data-filter="all" role="tab" aria-selected="${this.filter === "all"}">
2402
2419
  All <span class="vz-sidebar-filter-count">${total}</span>
2403
2420
  </button>
@@ -4281,10 +4298,26 @@ var Vizu = class {
4281
4298
  this.refreshUi();
4282
4299
  }
4283
4300
  async removeComment(id) {
4284
- const comment = this.comments.find((c) => c.id === id);
4285
- if (!comment) return;
4301
+ const idx = this.comments.findIndex((c) => c.id === id);
4302
+ if (idx === -1) return;
4303
+ const comment = this.comments[idx];
4286
4304
  this.comments = this.comments.filter((c) => c.id !== id);
4287
- await this.storage.removeComment(this.opts.namespace, id);
4305
+ try {
4306
+ await this.storage.removeComment(this.opts.namespace, id);
4307
+ } catch (err) {
4308
+ this.comments.splice(idx, 0, comment);
4309
+ const status = err?.status;
4310
+ const code = err?.code ?? "";
4311
+ 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.";
4312
+ this.pill?.toast(msg);
4313
+ if (this.popover?.isOpen()) {
4314
+ const anchors = this.popover.getAnchors();
4315
+ if (anchors[0]) this.popover.update(this.commentsForElement(anchors[0]));
4316
+ }
4317
+ this.refreshUi();
4318
+ if (typeof console !== "undefined") console.warn("[vizu] removeComment failed", err);
4319
+ return;
4320
+ }
4288
4321
  this.bus.emit("comment:removed", { id, comment });
4289
4322
  if (this.popover?.isOpen()) {
4290
4323
  const anchors = this.popover.getAnchors();