@fieldnotes/core 0.52.2 → 0.53.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
@@ -8184,6 +8184,7 @@ var Viewport = class {
8184
8184
  noteEditor;
8185
8185
  arrowLabelEditor;
8186
8186
  historyRecorder;
8187
+ transactionDepth = 0;
8187
8188
  selectionOps;
8188
8189
  toolContext;
8189
8190
  marginViewport;
@@ -8297,6 +8298,35 @@ var Viewport = class {
8297
8298
  get shortcuts() {
8298
8299
  return this.inputHandler.shortcuts;
8299
8300
  }
8301
+ /**
8302
+ * Groups synchronous local store and layer mutations into one undo step.
8303
+ * Nested calls join the outer transaction. If the callback throws, mutations
8304
+ * already applied remain undoable and the original error is rethrown.
8305
+ */
8306
+ transaction(operation) {
8307
+ const isOuterTransaction = this.transactionDepth === 0;
8308
+ if (isOuterTransaction) {
8309
+ this.inputHandler.flushPendingHistory();
8310
+ this.historyRecorder.begin();
8311
+ }
8312
+ this.transactionDepth += 1;
8313
+ try {
8314
+ return operation();
8315
+ } finally {
8316
+ this.transactionDepth -= 1;
8317
+ if (isOuterTransaction) this.historyRecorder.commit();
8318
+ }
8319
+ }
8320
+ /** Removes existing elements as one undoable operation and returns the number removed. */
8321
+ removeElements(ids) {
8322
+ const existingIds = [...new Set(ids)].filter((id) => this.store.getById(id) !== void 0);
8323
+ if (existingIds.length === 0) return 0;
8324
+ this.transaction(() => {
8325
+ for (const id of existingIds) this.store.remove(id);
8326
+ });
8327
+ this.requestRender();
8328
+ return existingIds.length;
8329
+ }
8300
8330
  undo() {
8301
8331
  this.inputHandler.flushPendingHistory();
8302
8332
  this.historyRecorder.pause();
@@ -11212,7 +11242,7 @@ var LaserTool = class {
11212
11242
  };
11213
11243
 
11214
11244
  // src/index.ts
11215
- var VERSION = "0.52.2";
11245
+ var VERSION = "0.53.0";
11216
11246
  // Annotate the CommonJS export names for ESM import in node:
11217
11247
  0 && (module.exports = {
11218
11248
  ArrowTool,