truecanvas 0.3.0 → 0.4.0

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.
@@ -984,21 +984,30 @@ var Comments = class {
984
984
  file(canvas) {
985
985
  return path2.join(this.config.root, this.config.canvasDir, `${assertCanvasName(canvas)}.comments.json`);
986
986
  }
987
- list(canvas) {
987
+ read(canvas) {
988
988
  try {
989
- return JSON.parse(fs2.readFileSync(this.file(canvas), "utf8")).threads ?? [];
989
+ const f = JSON.parse(fs2.readFileSync(this.file(canvas), "utf8"));
990
+ return { version: 1, threads: f.threads ?? [], dismissed: f.dismissed };
990
991
  } catch {
991
- return [];
992
+ return { version: 1, threads: [] };
992
993
  }
993
994
  }
994
- save(canvas, threads) {
995
+ list(canvas) {
996
+ return this.read(canvas).threads;
997
+ }
998
+ /** Ids of client threads deleted here. */
999
+ dismissed(canvas) {
1000
+ return new Set(this.read(canvas).dismissed ?? []);
1001
+ }
1002
+ save(canvas, threads, dismissed = this.read(canvas).dismissed) {
995
1003
  const file = this.file(canvas);
996
- if (!threads.length) {
1004
+ if (!threads.length && !dismissed?.length) {
997
1005
  if (fs2.existsSync(file)) fs2.rmSync(file);
998
1006
  return;
999
1007
  }
1000
1008
  fs2.mkdirSync(path2.dirname(file), { recursive: true });
1001
- fs2.writeFileSync(file, `${JSON.stringify({ version: 1, threads }, null, 2)}
1009
+ const data = { version: 1, threads, ...dismissed?.length ? { dismissed } : {} };
1010
+ fs2.writeFileSync(file, `${JSON.stringify(data, null, 2)}
1002
1011
  `);
1003
1012
  }
1004
1013
  update(canvas, id, fn) {
@@ -1036,12 +1045,23 @@ var Comments = class {
1036
1045
  return this.update(canvas, id, (t) => {
1037
1046
  t.resolved = resolved;
1038
1047
  t.resolvedBy = resolved ? author : void 0;
1048
+ t.resolvedAt = Date.now();
1039
1049
  });
1040
1050
  }
1051
+ /** Applies synced threads (from a share link) in one write; returns whether anything changed. */
1052
+ merge(canvas, fn) {
1053
+ const threads = this.list(canvas);
1054
+ if (!fn(threads)) return false;
1055
+ this.save(canvas, threads);
1056
+ return true;
1057
+ }
1041
1058
  remove(canvas, id) {
1059
+ const { threads, dismissed = [] } = this.read(canvas);
1060
+ const gone = threads.find((t) => t.id === id);
1042
1061
  this.save(
1043
1062
  canvas,
1044
- this.list(canvas).filter((t) => t.id !== id)
1063
+ threads.filter((t) => t.id !== id),
1064
+ gone?.share ? [.../* @__PURE__ */ new Set([...dismissed, id])] : dismissed
1045
1065
  );
1046
1066
  }
1047
1067
  /** Frames keep their comments when renamed. */