@unhingged/vizu-core 0.1.16 → 0.1.17

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];
@@ -4317,10 +4320,26 @@ var Vizu = class {
4317
4320
  this.refreshUi();
4318
4321
  }
4319
4322
  async removeComment(id) {
4320
- const comment = this.comments.find((c) => c.id === id);
4321
- if (!comment) return;
4323
+ const idx = this.comments.findIndex((c) => c.id === id);
4324
+ if (idx === -1) return;
4325
+ const comment = this.comments[idx];
4322
4326
  this.comments = this.comments.filter((c) => c.id !== id);
4323
- await this.storage.removeComment(this.opts.namespace, id);
4327
+ try {
4328
+ await this.storage.removeComment(this.opts.namespace, id);
4329
+ } catch (err) {
4330
+ this.comments.splice(idx, 0, comment);
4331
+ const status = err?.status;
4332
+ const code = err?.code ?? "";
4333
+ 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.";
4334
+ this.pill?.toast(msg);
4335
+ if (this.popover?.isOpen()) {
4336
+ const anchors = this.popover.getAnchors();
4337
+ if (anchors[0]) this.popover.update(this.commentsForElement(anchors[0]));
4338
+ }
4339
+ this.refreshUi();
4340
+ if (typeof console !== "undefined") console.warn("[vizu] removeComment failed", err);
4341
+ return;
4342
+ }
4324
4343
  this.bus.emit("comment:removed", { id, comment });
4325
4344
  if (this.popover?.isOpen()) {
4326
4345
  const anchors = this.popover.getAnchors();