@miadi/stateloom-canvas 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @miadi/stateloom-canvas
2
2
 
3
- The SMDF design surface, as a component anyone can mount.
3
+ The stateloom design surfaces, as components anyone can mount: `<StateMachineCanvas>` for
4
+ a `.smdf.json` state machine and `<EntityRelationshipCanvas>` for a `.erdf.json`
5
+ entity-relationship diagram.
4
6
 
5
7
  This is the stateloom designer's board with its store taken out: pan, zoom,
6
8
  drill into composites, drag boxes, routed edges, settled event labels, touch
@@ -37,6 +39,35 @@ export function Board({ definition }) {
37
39
  }
38
40
  ```
39
41
 
42
+ ## `<EntityRelationshipCanvas>`
43
+
44
+ The ERD sibling, with the same contract — props in, callbacks out, the host owns the
45
+ definition, the positions and the viewport — the same gestures, and the same `--slc-*` theme.
46
+
47
+ ```tsx
48
+ import { EntityRelationshipCanvas, erdAutoLayout, IDENTITY_VIEWPORT } from "@miadi/stateloom-canvas";
49
+
50
+ const [notation, setNotation] = useState<"crowsfoot" | "chen">("crowsfoot");
51
+ const positions = useMemo(() => erdAutoLayout(definition, { notation }), [definition, notation]);
52
+
53
+ <EntityRelationshipCanvas
54
+ definition={definition}
55
+ notation={notation}
56
+ positions={positions}
57
+ viewport={viewport}
58
+ onViewportChange={setViewport}
59
+ readOnly={locked} // a drag on a shape pans instead of moving it; a tap still selects
60
+ onEntityMove={(name, box) => …}
61
+ onOpenMachine={(machine) => …} // an attribute with `stateOf` was activated
62
+ />
63
+ ```
64
+
65
+ `notation` chooses the drawing, never the data: **crow's foot** lists attributes as rows in
66
+ the entity box with `PK` / `UK` / `FK` badges; **Chen** draws a rectangle (double when
67
+ `weak`), an oval per attribute with the primary key underlined, a diamond per relationship
68
+ and `1` / `N` / `M` beside the line. A shape that carries `notes` shows a small tab on its
69
+ top edge, in both canvases.
70
+
40
71
  ## Navigation
41
72
 
42
73
  | Gesture | What it does |
@@ -77,6 +77,10 @@ function attributeTitle(attr) {
77
77
  .filter(Boolean)
78
78
  .join(" — ");
79
79
  }
80
+ /** What hovering an entity says: what it is, then what was said about it. */
81
+ function entityTitle(entity) {
82
+ return [entity.description ?? "", entity.notes?.trim() ? `Notes: ${entity.notes}` : ""].filter(Boolean).join("\n\n");
83
+ }
80
84
  /**
81
85
  * Chen only: the short segment from where a routed line ends (on the corridor
82
86
  * above or below the rectangle) to the rectangle's own edge.
@@ -289,7 +293,7 @@ export function EntityRelationshipCanvas({ definition, notation = "crowsfoot", p
289
293
  const machines = stateOfList(o.attribute);
290
294
  const opens = machines.length > 0 && !!onOpenMachine;
291
295
  return (_jsxs("g", { className: opens ? "slc-erd-state" : undefined, onPointerDown: opens ? (e) => e.stopPropagation() : undefined, onClick: opens ? () => onOpenMachine(machines[0]) : undefined, children: [_jsx("title", { children: attributeTitle(o.attribute) }), _jsx("ellipse", { cx: o.cx, cy: o.cy, rx: o.rx, ry: o.ry, className: "slc-erd-oval" }), _jsxs("text", { x: o.cx, y: o.cy + 4, textAnchor: "middle", className: `slc-erd-oval-text${o.attribute.key === "pk" ? " slc-erd-oval-text--pk" : ""}${machines.length ? " slc-erd-row--state" : ""}`, children: [machines.length ? "◉ " : "", o.attribute.name] })] }, o.attribute.name));
292
- }), entity.description && _jsx("title", { children: entity.description }), _jsx("rect", { x: rect.x, y: rect.y, width: rect.width, height: rect.height, rx: 2, className: boxClass }), entity.weak && (_jsx("rect", { x: rect.x + 4, y: rect.y + 4, width: rect.width - 8, height: rect.height - 8, rx: 1, className: "slc-erd-weak" })), _jsx("text", { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 + 5, textAnchor: "middle", className: "slc-node-name", children: entity.name })] }, entity.name));
296
+ }), entityTitle(entity) && _jsx("title", { children: entityTitle(entity) }), _jsx("rect", { x: rect.x, y: rect.y, width: rect.width, height: rect.height, rx: 2, className: boxClass }), entity.notes?.trim() && (_jsx("rect", { x: rect.x + rect.width - 24, y: rect.y - 5, width: 13, height: 5, rx: 1.5, className: "slc-note-mark" })), entity.weak && (_jsx("rect", { x: rect.x + 4, y: rect.y + 4, width: rect.width - 8, height: rect.height - 8, rx: 1, className: "slc-erd-weak" })), _jsx("text", { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 + 5, textAnchor: "middle", className: "slc-node-name", children: entity.name })] }, entity.name));
293
297
  }
294
298
  return (_jsxs("g", { className: readOnly ? "slc-node--static" : "slc-node--draggable", onPointerDown: (e) => onPointerDown(e, entity.name), onContextMenu: (e) => {
295
299
  if (!onContextMenu)
@@ -297,7 +301,9 @@ export function EntityRelationshipCanvas({ definition, notation = "crowsfoot", p
297
301
  e.preventDefault();
298
302
  e.stopPropagation();
299
303
  onContextMenu(e.clientX, e.clientY, { kind: "entity", id: entity.name });
300
- }, children: [entity.description && _jsx("title", { children: entity.description }), _jsx("rect", { x: box.x, y: box.y, width: box.width, height: box.height, rx: 6, className: boxClass }), _jsx("path", { d: `M ${box.x} ${box.y + ERD_BOX.headerHeight} h ${box.width}`, className: "slc-erd-rule" }), _jsx("text", { x: box.x + box.width / 2, y: box.y + ERD_BOX.headerHeight / 2 + 5, textAnchor: "middle", className: "slc-node-name", children: entity.name }), rows.length === 0 && (_jsx("text", { x: box.x + ERD_BOX.padX, y: box.y + ERD_BOX.headerHeight + 15, className: "slc-erd-row slc-erd-row--empty", children: "no attributes" })), rows.map((attr, r) => {
304
+ }, children: [entityTitle(entity) && _jsx("title", { children: entityTitle(entity) }), _jsx("rect", { x: box.x, y: box.y, width: box.width, height: box.height, rx: 6, className: boxClass }), entity.notes?.trim() && (
305
+ // A small tab on the top edge: somebody left notes on this entity.
306
+ _jsx("rect", { x: box.x + box.width - 24, y: box.y - 5, width: 13, height: 5, rx: 1.5, className: "slc-note-mark" })), _jsx("path", { d: `M ${box.x} ${box.y + ERD_BOX.headerHeight} h ${box.width}`, className: "slc-erd-rule" }), _jsx("text", { x: box.x + box.width / 2, y: box.y + ERD_BOX.headerHeight / 2 + 5, textAnchor: "middle", className: "slc-node-name", children: entity.name }), rows.length === 0 && (_jsx("text", { x: box.x + ERD_BOX.padX, y: box.y + ERD_BOX.headerHeight + 15, className: "slc-erd-row slc-erd-row--empty", children: "no attributes" })), rows.map((attr, r) => {
301
307
  const y = box.y + ERD_BOX.headerHeight + r * ERD_BOX.rowHeight + 15;
302
308
  const machines = stateOfList(attr);
303
309
  const badges = keyBadges(attr);
@@ -898,7 +898,11 @@ export const StateMachineCanvas = forwardRef(function StateMachineCanvas(props,
898
898
  isActive ? "slc-node--active" : "",
899
899
  ]
900
900
  .filter(Boolean)
901
- .join(" ") }), _jsx("text", { x: pos.x + pos.width / 2, y: pos.y + (hasEntry || hasExit ? pos.height / 2 : pos.height / 2 + 5), textAnchor: "middle", className: "slc-node-name", children: state.name }), state.kind && state.kind !== "normal" && (_jsx("text", { x: pos.x + pos.width - 8, y: pos.y + 14, textAnchor: "end", className: "slc-node-kind", children: state.kind })), hasEntry && (_jsx("text", { x: pos.x + 6, y: pos.y + pos.height - 6, className: "slc-node-entry", children: "\u25B8entry" })), hasExit && (_jsx("text", { x: pos.x + pos.width - 6, y: pos.y + pos.height - 6, textAnchor: "end", className: "slc-node-exit", children: "exit\u25C2" })), errored && (_jsx("text", { x: pos.x + 6, y: pos.y + 14, className: "slc-node-warn", children: "\u26A0" })), composite && (_jsxs("text", { x: pos.x + pos.width / 2, y: pos.y + pos.height - 6, textAnchor: "middle", className: "slc-node-drill", children: ["\u25BC ", childCount(state), " children \u2014 ", coarsePointer ? "double-tap" : "double-click", " to enter"] }))] })] }, state.name));
901
+ .join(" ") }), _jsx("text", { x: pos.x + pos.width / 2, y: pos.y + (hasEntry || hasExit ? pos.height / 2 : pos.height / 2 + 5), textAnchor: "middle", className: "slc-node-name", children: state.name }), state.kind && state.kind !== "normal" && (_jsx("text", { x: pos.x + pos.width - 8, y: pos.y + 14, textAnchor: "end", className: "slc-node-kind", children: state.kind })), hasEntry && (_jsx("text", { x: pos.x + 6, y: pos.y + pos.height - 6, className: "slc-node-entry", children: "\u25B8entry" })), hasExit && (_jsx("text", { x: pos.x + pos.width - 6, y: pos.y + pos.height - 6, textAnchor: "end", className: "slc-node-exit", children: "exit\u25C2" })), errored && (
902
+ // Drawn, not typed: "⚠" is a full-colour emoji on iOS and ignores the danger ink.
903
+ _jsx("path", { d: `M ${pos.x + 6} ${pos.y + 15} l 5.5 -9.5 l 5.5 9.5 Z M ${pos.x + 11.5} ${pos.y + 9.5} v 2.6`, className: "slc-node-warn-mark" })), state.notes?.trim() && (
904
+ // A small tab on the top edge: somebody left notes on this state.
905
+ _jsxs("g", { children: [_jsx("title", { children: `Notes: ${state.notes}` }), _jsx("rect", { x: pos.x + pos.width - 24, y: pos.y - 5, width: 13, height: 5, rx: 1.5, className: "slc-note-mark" })] })), composite && (_jsxs("text", { x: pos.x + pos.width / 2, y: pos.y + pos.height - 6, textAnchor: "middle", className: "slc-node-drill", children: ["\u25BC ", childCount(state), " children \u2014 ", coarsePointer ? "double-tap" : "double-click", " to enter"] }))] })] }, state.name));
902
906
  }), Array.from(exitingNodes.entries()).map(([name, { state, pos }]) => {
903
907
  const exFinal = state.kind === "final";
904
908
  const exComposite = isComposite(state);
package/dist/styles.css CHANGED
@@ -107,6 +107,11 @@
107
107
  .slc-node-entry { fill: var(--slc-entry); font-size: 9px; pointer-events: none; user-select: none; }
108
108
  .slc-node-exit { fill: var(--slc-exit); font-size: 9px; pointer-events: none; user-select: none; }
109
109
  .slc-node-warn { fill: var(--slc-danger); font-size: 12px; pointer-events: none; user-select: none; }
110
+ /* Somebody left notes on this shape — a small tab on its top edge, in both canvases. */
111
+ .slc-note-mark { fill: var(--slc-accent-ink); opacity: 0.75; }
112
+
113
+ .slc-node-warn-mark { fill: none; stroke: var(--slc-danger); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
114
+
110
115
  .slc-node-drill { fill: var(--slc-composite); font-size: 9px; pointer-events: none; user-select: none; }
111
116
 
112
117
  /* What the pointer says a box will do. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/stateloom-canvas",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "The reusable SMDF design surface: a pannable, zoomable, drillable React SVG canvas with routed edges, settled labels and a navigation HUD",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,7 +43,7 @@
43
43
  "node": ">=20"
44
44
  },
45
45
  "dependencies": {
46
- "@miadi/stateloom-protocol": "^0.1.7"
46
+ "@miadi/stateloom-protocol": "^0.1.8"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react": "^19"