@bpmnkit/editor 0.0.35 → 0.2.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/ops.js ADDED
@@ -0,0 +1,82 @@
1
+ import { applyAutoLayout } from "@bpmnkit/core";
2
+ import { createIdFactory } from "./id.js";
3
+ import { changeElementType, createAnnotation, createAnnotationWithLink, createBoundaryEvent, createConnection, createShape, deleteElements, insertEdgeWaypoint, insertShapeOnEdge, moveEdgeSegment, moveEdgeWaypoint, moveShapes, pasteElements, removeCollinearWaypoints, resizeShape, updateEdgeEndpoint, updateLabel, updateLabelPosition, updateShapeColor, } from "./modeling.js";
4
+ /** Performs an op. The same op, on the same document, anywhere. */
5
+ export function applyOp(defs, op) {
6
+ switch (op.kind) {
7
+ case "createShape": {
8
+ const r = createShape(defs, op.type, op.bounds, op.name, createIdFactory(op.seed));
9
+ // Dropping a shape onto a flow splices it into that flow.
10
+ const next = op.onEdge ? insertShapeOnEdge(r.defs, op.onEdge, r.id) : r.defs;
11
+ return { defs: next, created: [r.id] };
12
+ }
13
+ case "createBoundaryEvent": {
14
+ const r = createBoundaryEvent(defs, op.hostId, op.eventDefType, op.bounds, true, createIdFactory(op.seed));
15
+ return { defs: r.defs, created: [r.id] };
16
+ }
17
+ case "createAnnotation": {
18
+ const r = createAnnotation(defs, op.bounds, op.text, createIdFactory(op.seed));
19
+ return { defs: r.defs, created: [r.id] };
20
+ }
21
+ case "createAnnotationFor": {
22
+ const r = createAnnotationWithLink(defs, op.bounds, op.sourceId, op.sourceBounds, undefined, createIdFactory(op.seed));
23
+ return { defs: r.defs, created: [r.annotationId, r.associationId] };
24
+ }
25
+ case "createConnection": {
26
+ const r = createConnection(defs, op.sourceId, op.targetId, op.waypoints, createIdFactory(op.seed));
27
+ return { defs: r.defs, created: [r.id] };
28
+ }
29
+ case "createConnected": {
30
+ // One factory for both halves, so the pair of ids is one sequence.
31
+ const ids = createIdFactory(op.seed);
32
+ const shape = createShape(defs, op.type, op.bounds, op.name, ids);
33
+ const flow = createConnection(shape.defs, op.sourceId, shape.id, op.waypoints, ids);
34
+ return { defs: flow.defs, created: [shape.id, flow.id] };
35
+ }
36
+ case "paste": {
37
+ const r = pasteElements(defs, op.clipboard, op.offsetX, op.offsetY, createIdFactory(op.seed));
38
+ return { defs: r.defs, created: r.topLevelIds };
39
+ }
40
+ case "move": {
41
+ const moved = moveShapes(defs, op.moves);
42
+ const next = op.onEdge ? insertShapeOnEdge(moved, op.onEdge.edgeId, op.onEdge.shapeId) : moved;
43
+ return { defs: next, created: [] };
44
+ }
45
+ case "resize":
46
+ return { defs: resizeShape(defs, op.id, op.bounds), created: [] };
47
+ case "delete":
48
+ return { defs: deleteElements(defs, op.ids), created: [] };
49
+ case "rename":
50
+ return { defs: updateLabel(defs, op.id, op.name), created: [] };
51
+ case "labelPosition":
52
+ return { defs: updateLabelPosition(defs, op.id, op.bounds), created: [] };
53
+ case "color":
54
+ return { defs: updateShapeColor(defs, op.id, op.color), created: [] };
55
+ case "changeType":
56
+ return { defs: changeElementType(defs, op.id, op.type), created: [] };
57
+ case "reconnect":
58
+ return { defs: updateEdgeEndpoint(defs, op.edgeId, op.isStart, op.port), created: [] };
59
+ // Every waypoint edit tidies the route afterwards, so a drag that leaves
60
+ // three points in a line does not leave the middle one behind.
61
+ case "insertWaypoint":
62
+ return {
63
+ defs: removeCollinearWaypoints(insertEdgeWaypoint(defs, op.edgeId, op.segIdx, op.point), op.edgeId),
64
+ created: [],
65
+ };
66
+ case "moveWaypoint":
67
+ return {
68
+ defs: removeCollinearWaypoints(moveEdgeWaypoint(defs, op.edgeId, op.wpIdx, op.point), op.edgeId),
69
+ created: [],
70
+ };
71
+ case "moveSegment":
72
+ return {
73
+ defs: removeCollinearWaypoints(moveEdgeSegment(defs, op.edgeId, op.segIdx, op.isHoriz, op.delta), op.edgeId),
74
+ created: [],
75
+ };
76
+ case "autoLayout":
77
+ return { defs: applyAutoLayout(defs), created: [] };
78
+ case "snapshot":
79
+ return { defs: op.defs, created: [] };
80
+ }
81
+ }
82
+ //# sourceMappingURL=ops.js.map
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { CanvasEvents, CanvasOptions } from "@bpmnkit/canvas";
2
2
  import type { BpmnDefinitions } from "@bpmnkit/core";
3
3
  import type { Translate } from "./i18n.js";
4
+ import type { EditorOp } from "./ops.js";
4
5
  export type CreateShapeType = "startEvent" | "messageStartEvent" | "timerStartEvent" | "conditionalStartEvent" | "signalStartEvent" | "endEvent" | "messageEndEvent" | "escalationEndEvent" | "errorEndEvent" | "compensationEndEvent" | "signalEndEvent" | "terminateEndEvent" | "intermediateThrowEvent" | "intermediateCatchEvent" | "messageCatchEvent" | "messageThrowEvent" | "timerCatchEvent" | "escalationThrowEvent" | "conditionalCatchEvent" | "linkCatchEvent" | "linkThrowEvent" | "compensationThrowEvent" | "signalCatchEvent" | "signalThrowEvent" | "task" | "serviceTask" | "userTask" | "scriptTask" | "sendTask" | "receiveTask" | "businessRuleTask" | "manualTask" | "callActivity" | "subProcess" | "adHocSubProcess" | "transaction" | "exclusiveGateway" | "parallelGateway" | "inclusiveGateway" | "eventBasedGateway" | "complexGateway" | "textAnnotation";
5
6
  /** Element types that support resize handles. */
6
7
  export declare const RESIZABLE_TYPES: ReadonlySet<string>;
@@ -25,6 +26,21 @@ export type EditorOptions = CanvasOptions & {
25
26
  };
26
27
  export interface EditorEvents extends CanvasEvents {
27
28
  "diagram:change": (defs: BpmnDefinitions) => void;
29
+ /**
30
+ * The same change, described rather than materialised.
31
+ *
32
+ * Fires immediately after `diagram:change` for every change to the document,
33
+ * undo and redo included — those arrive as a whole-document `snapshot` op,
34
+ * because the stack records states rather than inverses and a relay that
35
+ * never heard about an undo would be silently wrong from then on.
36
+ *
37
+ * The exception is `loadDefinitions`, which is the host replacing the
38
+ * document rather than the user changing it, and says nothing.
39
+ *
40
+ * A listener relaying edits to other people wants this event; a listener that
41
+ * just needs the current document wants `diagram:change`.
42
+ */
43
+ "diagram:op": (op: EditorOp, defs: BpmnDefinitions) => void;
28
44
  "editor:select": (ids: string[]) => void;
29
45
  "editor:tool": (tool: Tool) => void;
30
46
  "editor:drag": (dragging: boolean) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmnkit/editor",
3
- "version": "0.0.35",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
+ },
12
+ "./headless": {
13
+ "types": "./dist/headless.d.ts",
14
+ "import": "./dist/headless.js"
11
15
  }
12
16
  },
13
17
  "files": [
@@ -17,8 +21,8 @@
17
21
  "dist/**/*.d.ts"
18
22
  ],
19
23
  "dependencies": {
20
- "@bpmnkit/canvas": "0.1.0",
21
- "@bpmnkit/core": "0.3.0"
24
+ "@bpmnkit/canvas": "0.2.0",
25
+ "@bpmnkit/core": "0.4.0"
22
26
  },
23
27
  "description": "Full-featured interactive BPMN editor with undo/redo, HUD, and side-dock UI",
24
28
  "keywords": [