eventmodeler 0.6.12 → 0.6.13

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.
Files changed (2) hide show
  1. package/dist/index.js +84 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3166,6 +3166,11 @@ function removeSticky(doc, chapterId, stickyId) {
3166
3166
  cells.get(loc.key).delete(loc.index, 1);
3167
3167
  });
3168
3168
  }
3169
+ function removeSheet(doc, chapterId) {
3170
+ doc.transact(() => {
3171
+ getGridMap(doc).delete(chapterId);
3172
+ });
3173
+ }
3169
3174
  function getCellNotesMap(doc, chapterId, create) {
3170
3175
  const sheet = getGridMap(doc).get(chapterId);
3171
3176
  if (!sheet)
@@ -3192,6 +3197,54 @@ function setCellNote(doc, chapterId, sliceId, swimLaneId, text) {
3192
3197
  getCellNotesMap(doc, chapterId, true).set(key, trimmed);
3193
3198
  });
3194
3199
  }
3200
+ // ../packages/canvas-model/src/sheet-delete.ts
3201
+ var CHAPTERS_SCOPE = "chapters";
3202
+ var SLICES_SCOPE2 = "slices";
3203
+ var SWIM_LANES_SCOPE = "swimLanes";
3204
+ var SCENARIOS_SCOPE2 = "scenarios";
3205
+ var SHEET_FLOWS_SCOPE = "sheetFlows";
3206
+ function deleteSheet(doc, chapterId) {
3207
+ doc.transact(() => {
3208
+ const sheet = getGridMap(doc).get(chapterId);
3209
+ const removedStickies = new Set;
3210
+ const sliceIds = new Set;
3211
+ const laneIds = new Set;
3212
+ if (sheet) {
3213
+ for (const id of sheet.get("columns").toArray())
3214
+ sliceIds.add(id);
3215
+ for (const id of sheet.get("rows").toArray())
3216
+ laneIds.add(id);
3217
+ const cells = sheet.get("cells");
3218
+ for (const key of cells.keys()) {
3219
+ for (const ref of cells.get(key).toArray()) {
3220
+ const stickyId = ref.get("stickyId");
3221
+ getScopeMap(doc, ref.get("scope")).delete(stickyId);
3222
+ removedStickies.add(stickyId);
3223
+ }
3224
+ }
3225
+ }
3226
+ for (const id of sliceIds)
3227
+ getScopeMap(doc, SLICES_SCOPE2).delete(id);
3228
+ for (const id of laneIds)
3229
+ getScopeMap(doc, SWIM_LANES_SCOPE).delete(id);
3230
+ const scenarios = getScopeMap(doc, SCENARIOS_SCOPE2);
3231
+ for (const [id, sc] of scenarios.entries()) {
3232
+ if (sliceIds.has(sc.get("sliceId"))) {
3233
+ scenarios.delete(id);
3234
+ removedStickies.add(id);
3235
+ }
3236
+ }
3237
+ cascadeStickyRemoval(doc, removedStickies);
3238
+ const sheetFlows = getScopeMap(doc, SHEET_FLOWS_SCOPE);
3239
+ for (const [id, f] of sheetFlows.entries()) {
3240
+ if (f.get("sourceChapterId") === chapterId || f.get("targetChapterId") === chapterId) {
3241
+ sheetFlows.delete(id);
3242
+ }
3243
+ }
3244
+ removeSheet(doc, chapterId);
3245
+ getScopeMap(doc, CHAPTERS_SCOPE).delete(chapterId);
3246
+ });
3247
+ }
3195
3248
  // ../packages/canvas-model/src/sheet-layout.ts
3196
3249
  function applyLayoutOverride(cells, ov) {
3197
3250
  const out = {};
@@ -3377,9 +3430,9 @@ function computeSheetLayout(doc, chapterId, override) {
3377
3430
  }
3378
3431
  // ../packages/canvas-model/src/reflow.ts
3379
3432
  var REFLOW_ORIGIN = Symbol("sheet-reflow");
3380
- var CHAPTERS_SCOPE = "chapters";
3381
- var SLICES_SCOPE2 = "slices";
3382
- var SWIM_LANES_SCOPE = "swimLanes";
3433
+ var CHAPTERS_SCOPE2 = "chapters";
3434
+ var SLICES_SCOPE3 = "slices";
3435
+ var SWIM_LANES_SCOPE2 = "swimLanes";
3383
3436
  var STICKY_SCOPES = [
3384
3437
  "commands",
3385
3438
  "events",
@@ -3404,14 +3457,14 @@ function applyBox(m, box, size = true) {
3404
3457
  }
3405
3458
  }
3406
3459
  function reflowAllSheets(doc, origin = REFLOW_ORIGIN) {
3407
- const chapters = getScopeMap(doc, CHAPTERS_SCOPE);
3460
+ const chapters = getScopeMap(doc, CHAPTERS_SCOPE2);
3408
3461
  if (chapters.size === 0)
3409
3462
  return;
3410
3463
  doc.transact(() => {
3411
3464
  for (const chapterId of chapters.keys())
3412
3465
  ensureSheet(doc, chapterId);
3413
- const slices = getScopeMap(doc, SLICES_SCOPE2);
3414
- const lanes = getScopeMap(doc, SWIM_LANES_SCOPE);
3466
+ const slices = getScopeMap(doc, SLICES_SCOPE3);
3467
+ const lanes = getScopeMap(doc, SWIM_LANES_SCOPE2);
3415
3468
  const stickyMaps = STICKY_SCOPES.map((s) => getScopeMap(doc, s));
3416
3469
  for (const chapterId of getGridMap(doc).keys()) {
3417
3470
  pruneOrphanCellRefs(doc, chapterId);
@@ -5863,6 +5916,31 @@ function registerSheetCommands(program) {
5863
5916
  throw err;
5864
5917
  }
5865
5918
  });
5919
+ sheet.command("delete [sheet]").description("Delete a whole sheet and everything in it — slices, lanes, elements, scenarios, flows. Destructive; pass --yes to confirm.").option("--yes", "Confirm the deletion (required — this cannot be undone)").option("--model <id>", "Target model id").action(async (sheetRef, opts) => {
5920
+ const modelId = resolveModelId(opts.model);
5921
+ try {
5922
+ const out = await withDoc(modelId, (doc) => {
5923
+ const s = resolveSheet2(doc, sheetRef);
5924
+ const name2 = getEntry(doc, "chapters", s.chapterId)?.name ?? s.chapterId;
5925
+ const elements = Object.values(s.structure.cells).reduce((n, refs) => n + refs.length, 0);
5926
+ const summary = `sheet "${name2}" — ${s.structure.columns.length} slice(s), ${s.structure.rows.length} lane(s), ${elements} element(s)`;
5927
+ if (!opts.yes) {
5928
+ return `Would delete ${summary}.
5929
+ This cannot be undone. Re-run with --yes to confirm.`;
5930
+ }
5931
+ deleteSheet(doc, s.chapterId);
5932
+ reflowAllSheets(doc);
5933
+ return `Deleted ${summary}.`;
5934
+ });
5935
+ console.log(out);
5936
+ } catch (err) {
5937
+ if (err instanceof SheetAddressError) {
5938
+ console.error(err.message);
5939
+ process.exit(2);
5940
+ }
5941
+ throw err;
5942
+ }
5943
+ });
5866
5944
  const insert = sheet.command("insert").description("Insert a slice (column), a lane (row), or an element into a cell");
5867
5945
  insert.command("slice <name>").description("Insert a new slice (column)").option("--at <n>", "Position (1-based); appends if omitted").option("--sheet <ref>", "Which sheet (name or chapterId) when the model has several").option("--model <id>", "Target model id").action((name2, opts) => runWrite(opts, (doc, s, modelId) => insertColumn(doc, s, modelId, name2, atIndex(opts.at))));
5868
5946
  for (const kind of LANE_KINDS) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eventmodeler",
3
- "version": "0.6.12",
3
+ "version": "0.6.13",
4
4
  "description": "CLI tool for event modeling - explore, design, and generate code from your event models",
5
5
  "type": "module",
6
6
  "repository": {