@fieldnotes/core 0.17.0 → 0.18.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.
package/dist/index.cjs CHANGED
@@ -124,7 +124,13 @@ var EventBus = class {
124
124
  this.listeners.get(event)?.delete(listener);
125
125
  }
126
126
  emit(event, data) {
127
- this.listeners.get(event)?.forEach((listener) => listener(data));
127
+ this.listeners.get(event)?.forEach((listener) => {
128
+ try {
129
+ listener(data);
130
+ } catch (err) {
131
+ console.error(`[fieldnotes] listener error for "${String(event)}"`, err);
132
+ }
133
+ });
128
134
  }
129
135
  clear() {
130
136
  this.listeners.clear();
@@ -928,6 +934,7 @@ var KeyboardActions = class {
928
934
  clipboard = [];
929
935
  pasteCount = 0;
930
936
  nudgeTimer = null;
937
+ nudgeTxId = null;
931
938
  dispose() {
932
939
  this.flushPendingNudge();
933
940
  }
@@ -946,7 +953,9 @@ var KeyboardActions = class {
946
953
  if (sel.tool.selectedIds.length === 0) return false;
947
954
  const step = byCell ? sel.ctx.gridSize ?? 10 : 1;
948
955
  if (this.nudgeTimer === null) {
949
- this.deps.getHistoryRecorder()?.begin();
956
+ const recorder = this.deps.getHistoryRecorder();
957
+ recorder?.begin();
958
+ this.nudgeTxId = recorder?.currentTransactionId ?? null;
950
959
  } else {
951
960
  clearTimeout(this.nudgeTimer);
952
961
  }
@@ -958,9 +967,14 @@ var KeyboardActions = class {
958
967
  if (this.nudgeTimer === null) return;
959
968
  clearTimeout(this.nudgeTimer);
960
969
  this.nudgeTimer = null;
961
- this.deps.getHistoryRecorder()?.commit();
970
+ const recorder = this.deps.getHistoryRecorder();
971
+ if (this.nudgeTxId === null || recorder?.currentTransactionId === this.nudgeTxId) {
972
+ recorder?.commit();
973
+ }
974
+ this.nudgeTxId = null;
962
975
  }
963
976
  deleteSelected() {
977
+ if (this.deps.isToolActive()) return;
964
978
  this.flushPendingNudge();
965
979
  const sel = this.selectTool();
966
980
  if (!sel) return;
@@ -975,6 +989,7 @@ var KeyboardActions = class {
975
989
  sel.ctx.requestRender();
976
990
  }
977
991
  undo() {
992
+ if (this.deps.isToolActive()) return;
978
993
  this.flushPendingNudge();
979
994
  const ctx = this.deps.getToolContext();
980
995
  const stack = this.deps.getHistoryStack();
@@ -986,6 +1001,7 @@ var KeyboardActions = class {
986
1001
  ctx.requestRender();
987
1002
  }
988
1003
  redo() {
1004
+ if (this.deps.isToolActive()) return;
989
1005
  this.flushPendingNudge();
990
1006
  const ctx = this.deps.getToolContext();
991
1007
  const stack = this.deps.getHistoryStack();
@@ -1059,6 +1075,7 @@ var KeyboardActions = class {
1059
1075
  this.deps.fitToContent?.();
1060
1076
  }
1061
1077
  zOrder(operation) {
1078
+ if (this.deps.isToolActive()) return;
1062
1079
  this.flushPendingNudge();
1063
1080
  const sel = this.selectTool();
1064
1081
  if (!sel) return;
@@ -3618,6 +3635,7 @@ var HistoryRecorder = class {
3618
3635
  }
3619
3636
  recording = true;
3620
3637
  transaction = null;
3638
+ generation = 0;
3621
3639
  updateSnapshots = /* @__PURE__ */ new Map();
3622
3640
  unsubscribers;
3623
3641
  pause() {
@@ -3632,6 +3650,10 @@ var HistoryRecorder = class {
3632
3650
  }
3633
3651
  this.transaction = [];
3634
3652
  this.updateSnapshots.clear();
3653
+ this.generation += 1;
3654
+ }
3655
+ get currentTransactionId() {
3656
+ return this.transaction !== null ? this.generation : null;
3635
3657
  }
3636
3658
  commit() {
3637
3659
  if (!this.transaction) return;
@@ -4990,6 +5012,9 @@ var Viewport = class {
4990
5012
  loadJSON(json) {
4991
5013
  this.loadState(parseState(json));
4992
5014
  }
5015
+ setTool(name) {
5016
+ this.toolManager.setTool(name, this.toolContext);
5017
+ }
4993
5018
  undo() {
4994
5019
  this.inputHandler.flushPendingHistory();
4995
5020
  this.historyRecorder.pause();
@@ -7028,7 +7053,7 @@ var TemplateTool = class {
7028
7053
  };
7029
7054
 
7030
7055
  // src/index.ts
7031
- var VERSION = "0.17.0";
7056
+ var VERSION = "0.18.0";
7032
7057
  // Annotate the CommonJS export names for ESM import in node:
7033
7058
  0 && (module.exports = {
7034
7059
  AddElementCommand,
@@ -7116,3 +7141,4 @@ var VERSION = "0.17.0";
7116
7141
  unbindArrow,
7117
7142
  updateBoundArrow
7118
7143
  });
7144
+ //# sourceMappingURL=index.cjs.map