@miadi/stateloom-canvas 0.1.0 → 0.1.2
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/EntityRelationshipCanvas.d.ts +53 -0
- package/dist/EntityRelationshipCanvas.js +250 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/styles.css +64 -0
- package/package.json +4 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ERD design surface (Spec 80) — the sibling of `<StateMachineCanvas>`.
|
|
3
|
+
*
|
|
4
|
+
* Same contract: props in, callbacks out, no store, no socket. The host owns
|
|
5
|
+
* the definition, the box positions and the viewport; this component draws
|
|
6
|
+
* them and reports what the hand did. Same gestures too — wheel pans, ⌃/⌘
|
|
7
|
+
* wheel zooms at the pointer, a drag on the board pans, a drag on a box moves
|
|
8
|
+
* it, two fingers pinch — and the same `--slc-*` variables, so a host that has
|
|
9
|
+
* themed the state canvas has themed this one.
|
|
10
|
+
*
|
|
11
|
+
* An entity box lists its attributes; keys show as PK / UK / FK badges. An
|
|
12
|
+
* attribute that stores a machine's state (`stateOf`) is drawn in the accent
|
|
13
|
+
* ink with a ◉, and activating it reports the machine through
|
|
14
|
+
* `onOpenMachine` — the join between the two diagrams.
|
|
15
|
+
*
|
|
16
|
+
* Relationship lines reuse the state canvas's edge router, so several lines on
|
|
17
|
+
* one box face each get a port of their own. Each end carries its cardinality
|
|
18
|
+
* mark: a bar for "one", a crow's foot for "many".
|
|
19
|
+
*/
|
|
20
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
21
|
+
import { type EntityRelationshipDefinition, type LayoutBox, type Viewport } from "@miadi/stateloom-protocol";
|
|
22
|
+
import { type CanvasTheme } from "./theme.js";
|
|
23
|
+
export interface ErdCanvasTarget {
|
|
24
|
+
kind: "entity" | "canvas";
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface EntityRelationshipCanvasProps {
|
|
28
|
+
definition: EntityRelationshipDefinition;
|
|
29
|
+
/** Entity name → box. The host owns these; `erdAutoLayout` seeds them. */
|
|
30
|
+
positions: Record<string, LayoutBox>;
|
|
31
|
+
viewport: Viewport;
|
|
32
|
+
onViewportChange: (viewport: Viewport) => void;
|
|
33
|
+
/** The selected entity's name. */
|
|
34
|
+
selection?: string | null;
|
|
35
|
+
/** Entities failing validation. */
|
|
36
|
+
errorElements?: readonly string[];
|
|
37
|
+
readOnly?: boolean;
|
|
38
|
+
/** Change this to re-fit the board to its boxes (a new document, a re-layout). */
|
|
39
|
+
fitKey?: string | number;
|
|
40
|
+
onSelect?: (entity: string) => void;
|
|
41
|
+
onClearSelection?: () => void;
|
|
42
|
+
onEntityMove?: (name: string, box: LayoutBox) => void;
|
|
43
|
+
/** An attribute that stores a machine's state was activated. */
|
|
44
|
+
onOpenMachine?: (machine: string) => void;
|
|
45
|
+
onContextMenu?: (clientX: number, clientY: number, target: ErdCanvasTarget) => void;
|
|
46
|
+
emptyHint?: ReactNode;
|
|
47
|
+
theme?: Partial<CanvasTheme>;
|
|
48
|
+
className?: string;
|
|
49
|
+
style?: CSSProperties;
|
|
50
|
+
svgId?: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function EntityRelationshipCanvas({ definition, positions, viewport, onViewportChange, selection, errorElements, readOnly, fitKey, onSelect, onClearSelection, onEntityMove, onOpenMachine, onContextMenu, emptyHint, theme, className, style, svgId, }: EntityRelationshipCanvasProps): import("react").JSX.Element;
|
|
53
|
+
export default EntityRelationshipCanvas;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The ERD design surface (Spec 80) — the sibling of `<StateMachineCanvas>`.
|
|
4
|
+
*
|
|
5
|
+
* Same contract: props in, callbacks out, no store, no socket. The host owns
|
|
6
|
+
* the definition, the box positions and the viewport; this component draws
|
|
7
|
+
* them and reports what the hand did. Same gestures too — wheel pans, ⌃/⌘
|
|
8
|
+
* wheel zooms at the pointer, a drag on the board pans, a drag on a box moves
|
|
9
|
+
* it, two fingers pinch — and the same `--slc-*` variables, so a host that has
|
|
10
|
+
* themed the state canvas has themed this one.
|
|
11
|
+
*
|
|
12
|
+
* An entity box lists its attributes; keys show as PK / UK / FK badges. An
|
|
13
|
+
* attribute that stores a machine's state (`stateOf`) is drawn in the accent
|
|
14
|
+
* ink with a ◉, and activating it reports the machine through
|
|
15
|
+
* `onOpenMachine` — the join between the two diagrams.
|
|
16
|
+
*
|
|
17
|
+
* Relationship lines reuse the state canvas's edge router, so several lines on
|
|
18
|
+
* one box face each get a port of their own. Each end carries its cardinality
|
|
19
|
+
* mark: a bar for "one", a crow's foot for "many".
|
|
20
|
+
*/
|
|
21
|
+
import { useCallback, useEffect, useMemo, useRef, } from "react";
|
|
22
|
+
import { ERD_BOX, erdRowText, fitToBoxes, panBy, placeLabels, routeEdges, screenDeltaToWorld, stateOfList, viewportTransform, zoomAt, } from "@miadi/stateloom-protocol";
|
|
23
|
+
import { themeStyle } from "./theme.js";
|
|
24
|
+
const WHEEL_LINE_HEIGHT = 16;
|
|
25
|
+
const WHEEL_PAGE_HEIGHT = 400;
|
|
26
|
+
/** Movement under this many screen pixels is a click, not a drag. */
|
|
27
|
+
const DRAG_THRESHOLD = 4;
|
|
28
|
+
function wheelPixels(delta, mode) {
|
|
29
|
+
if (mode === 1)
|
|
30
|
+
return delta * WHEEL_LINE_HEIGHT;
|
|
31
|
+
if (mode === 2)
|
|
32
|
+
return delta * WHEEL_PAGE_HEIGHT;
|
|
33
|
+
return delta;
|
|
34
|
+
}
|
|
35
|
+
/** Which mark each end of a relationship carries: [from end, to end]. */
|
|
36
|
+
const ENDS = {
|
|
37
|
+
"1:1": ["one", "one"],
|
|
38
|
+
"1:N": ["one", "many"],
|
|
39
|
+
"N:1": ["many", "one"],
|
|
40
|
+
"N:M": ["many", "many"],
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The cardinality mark at `tip` (the point on the box edge), for a line that
|
|
44
|
+
* leaves toward `toward`. A bar for "one"; a crow's foot for "many", opening
|
|
45
|
+
* onto the box.
|
|
46
|
+
*/
|
|
47
|
+
function endMark(tip, toward, kind) {
|
|
48
|
+
const dx = toward.x - tip.x;
|
|
49
|
+
const dy = toward.y - tip.y;
|
|
50
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
51
|
+
const ux = dx / len;
|
|
52
|
+
const uy = dy / len;
|
|
53
|
+
const nx = -uy;
|
|
54
|
+
const ny = ux;
|
|
55
|
+
const at = (along, across) => `${(tip.x + ux * along + nx * across).toFixed(1)} ${(tip.y + uy * along + ny * across).toFixed(1)}`;
|
|
56
|
+
if (kind === "one")
|
|
57
|
+
return `M ${at(9, 6)} L ${at(9, -6)}`;
|
|
58
|
+
return `M ${at(13, 0)} L ${at(0, 7)} M ${at(13, 0)} L ${at(0, -7)} M ${at(13, 0)} L ${at(0, 0)}`;
|
|
59
|
+
}
|
|
60
|
+
const keyBadges = (attr) => [attr.key === "pk" ? "PK" : attr.key === "uk" ? "UK" : "", attr.references ? "FK" : ""].filter(Boolean).join(" ");
|
|
61
|
+
export function EntityRelationshipCanvas({ definition, positions, viewport, onViewportChange, selection = null, errorElements, readOnly = false, fitKey, onSelect, onClearSelection, onEntityMove, onOpenMachine, onContextMenu, emptyHint, theme, className, style, svgId, }) {
|
|
62
|
+
const svgRef = useRef(null);
|
|
63
|
+
const viewportRef = useRef(viewport);
|
|
64
|
+
viewportRef.current = viewport;
|
|
65
|
+
const gestureRef = useRef(null);
|
|
66
|
+
const pointersRef = useRef(new Map());
|
|
67
|
+
const pinchRef = useRef(null);
|
|
68
|
+
const entities = useMemo(() => {
|
|
69
|
+
const seen = new Set();
|
|
70
|
+
return (definition.entities ?? []).filter((e) => {
|
|
71
|
+
if (!e?.name || seen.has(e.name) || !positions[e.name])
|
|
72
|
+
return false;
|
|
73
|
+
seen.add(e.name);
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
}, [definition.entities, positions]);
|
|
77
|
+
// Routed by index, not by name: the router keys its faces on a space-joined
|
|
78
|
+
// string, and an entity may be called "Order Line".
|
|
79
|
+
const edges = useMemo(() => {
|
|
80
|
+
const indexOf = new Map(entities.map((e, i) => [e.name, `e${i}`]));
|
|
81
|
+
const drawn = (definition.relationships ?? []).filter((r) => r && indexOf.has(r.from) && indexOf.has(r.to));
|
|
82
|
+
const curves = routeEdges(drawn.map((r) => ({ from: indexOf.get(r.from), to: indexOf.get(r.to) })), (id) => positions[entities[Number(id.slice(1))].name]);
|
|
83
|
+
return drawn.map((rel, i) => ({ rel, curve: curves[i] }));
|
|
84
|
+
}, [definition.relationships, entities, positions]);
|
|
85
|
+
// The state canvas's chip placer: each label tries spots along its own line
|
|
86
|
+
// until it is clear of every box and of the labels already down.
|
|
87
|
+
const labels = useMemo(() => {
|
|
88
|
+
const pending = edges
|
|
89
|
+
.filter(({ rel }) => rel.label)
|
|
90
|
+
.map(({ rel, curve }) => ({ event: rel.label, at: curve.at }));
|
|
91
|
+
return placeLabels(pending, entities.map((e) => positions[e.name]));
|
|
92
|
+
}, [edges, entities, positions]);
|
|
93
|
+
const toCanvasPoint = useCallback((clientX, clientY) => {
|
|
94
|
+
const rect = svgRef.current?.getBoundingClientRect();
|
|
95
|
+
return { x: clientX - (rect?.left ?? 0), y: clientY - (rect?.top ?? 0) };
|
|
96
|
+
}, []);
|
|
97
|
+
// Fit on demand. Keyed rather than automatic so a box being dragged toward
|
|
98
|
+
// the edge never makes the board jump under the hand.
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (fitKey === undefined)
|
|
101
|
+
return;
|
|
102
|
+
const rect = svgRef.current?.getBoundingClientRect();
|
|
103
|
+
const boxes = Object.values(positions);
|
|
104
|
+
if (!rect || boxes.length === 0)
|
|
105
|
+
return;
|
|
106
|
+
onViewportChange(fitToBoxes(boxes, rect.width, rect.height));
|
|
107
|
+
// Positions are read at the moment of the fit, not watched.
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
}, [fitKey]);
|
|
110
|
+
// Native, because React's wheel listener is passive and cannot stop the page
|
|
111
|
+
// from zooming out from under the board.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const svg = svgRef.current;
|
|
114
|
+
if (!svg)
|
|
115
|
+
return;
|
|
116
|
+
const onWheel = (e) => {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
const vp = viewportRef.current;
|
|
119
|
+
const dx = wheelPixels(e.deltaX, e.deltaMode);
|
|
120
|
+
const dy = wheelPixels(e.deltaY, e.deltaMode);
|
|
121
|
+
if (e.ctrlKey || e.metaKey) {
|
|
122
|
+
onViewportChange(zoomAt(vp, Math.exp(-dy * 0.0025), toCanvasPoint(e.clientX, e.clientY)));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const moveX = e.shiftKey ? -(dx || dy) : -dx;
|
|
126
|
+
const moveY = e.shiftKey ? 0 : -dy;
|
|
127
|
+
if (moveX !== 0 || moveY !== 0)
|
|
128
|
+
onViewportChange(panBy(vp, moveX, moveY));
|
|
129
|
+
};
|
|
130
|
+
svg.addEventListener("wheel", onWheel, { passive: false });
|
|
131
|
+
return () => svg.removeEventListener("wheel", onWheel);
|
|
132
|
+
}, [onViewportChange, toCanvasPoint]);
|
|
133
|
+
const pinchState = () => {
|
|
134
|
+
const pts = [...pointersRef.current.values()];
|
|
135
|
+
if (pts.length < 2)
|
|
136
|
+
return null;
|
|
137
|
+
const [a, b] = pts;
|
|
138
|
+
return { distance: Math.hypot(b.x - a.x, b.y - a.y) || 1, mid: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 } };
|
|
139
|
+
};
|
|
140
|
+
const onPointerDown = (e, name) => {
|
|
141
|
+
if (e.button !== 0 && e.pointerType === "mouse")
|
|
142
|
+
return;
|
|
143
|
+
e.stopPropagation();
|
|
144
|
+
svgRef.current?.setPointerCapture(e.pointerId);
|
|
145
|
+
pointersRef.current.set(e.pointerId, toCanvasPoint(e.clientX, e.clientY));
|
|
146
|
+
if (pointersRef.current.size >= 2) {
|
|
147
|
+
// A second finger turns whatever was happening into a pinch.
|
|
148
|
+
gestureRef.current = null;
|
|
149
|
+
pinchRef.current = pinchState();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const movable = name !== undefined && !readOnly;
|
|
153
|
+
gestureRef.current = {
|
|
154
|
+
kind: movable ? "move" : "pan",
|
|
155
|
+
pointerId: e.pointerId,
|
|
156
|
+
startX: e.clientX,
|
|
157
|
+
startY: e.clientY,
|
|
158
|
+
lastX: e.clientX,
|
|
159
|
+
lastY: e.clientY,
|
|
160
|
+
name,
|
|
161
|
+
origin: movable ? positions[name] : undefined,
|
|
162
|
+
moved: false,
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
const onPointerMove = (e) => {
|
|
166
|
+
if (pointersRef.current.has(e.pointerId)) {
|
|
167
|
+
pointersRef.current.set(e.pointerId, toCanvasPoint(e.clientX, e.clientY));
|
|
168
|
+
}
|
|
169
|
+
if (pinchRef.current) {
|
|
170
|
+
const next = pinchState();
|
|
171
|
+
if (!next)
|
|
172
|
+
return;
|
|
173
|
+
const prev = pinchRef.current;
|
|
174
|
+
const panned = panBy(viewportRef.current, next.mid.x - prev.mid.x, next.mid.y - prev.mid.y);
|
|
175
|
+
onViewportChange(zoomAt(panned, next.distance / prev.distance, next.mid));
|
|
176
|
+
pinchRef.current = next;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const g = gestureRef.current;
|
|
180
|
+
if (!g || g.pointerId !== e.pointerId)
|
|
181
|
+
return;
|
|
182
|
+
if (!g.moved && Math.hypot(e.clientX - g.startX, e.clientY - g.startY) < DRAG_THRESHOLD)
|
|
183
|
+
return;
|
|
184
|
+
g.moved = true;
|
|
185
|
+
if (g.kind === "pan") {
|
|
186
|
+
onViewportChange(panBy(viewportRef.current, e.clientX - g.lastX, e.clientY - g.lastY));
|
|
187
|
+
}
|
|
188
|
+
else if (g.name && g.origin) {
|
|
189
|
+
const d = screenDeltaToWorld(viewportRef.current, e.clientX - g.startX, e.clientY - g.startY);
|
|
190
|
+
onEntityMove?.(g.name, { ...g.origin, x: g.origin.x + d.x, y: g.origin.y + d.y });
|
|
191
|
+
}
|
|
192
|
+
g.lastX = e.clientX;
|
|
193
|
+
g.lastY = e.clientY;
|
|
194
|
+
};
|
|
195
|
+
const onPointerUp = (e) => {
|
|
196
|
+
pointersRef.current.delete(e.pointerId);
|
|
197
|
+
if (pinchRef.current) {
|
|
198
|
+
if (pointersRef.current.size < 2)
|
|
199
|
+
pinchRef.current = null;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const g = gestureRef.current;
|
|
203
|
+
if (!g || g.pointerId !== e.pointerId)
|
|
204
|
+
return;
|
|
205
|
+
gestureRef.current = null;
|
|
206
|
+
if (g.moved)
|
|
207
|
+
return;
|
|
208
|
+
if (g.name)
|
|
209
|
+
onSelect?.(g.name);
|
|
210
|
+
else
|
|
211
|
+
onClearSelection?.();
|
|
212
|
+
};
|
|
213
|
+
const errors = new Set(errorElements ?? []);
|
|
214
|
+
return (_jsxs("div", { className: `slc-pane${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: [_jsx("svg", { ref: svgRef, id: svgId, className: "slc-surface", onPointerDown: (e) => onPointerDown(e), onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: onPointerUp, onContextMenu: (e) => {
|
|
215
|
+
if (!onContextMenu)
|
|
216
|
+
return;
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
onContextMenu(e.clientX, e.clientY, { kind: "canvas" });
|
|
219
|
+
}, children: _jsxs("g", { transform: viewportTransform(viewport), children: [edges.map(({ rel, curve }, i) => {
|
|
220
|
+
const [fromEnd, toEnd] = ENDS[rel.cardinality] ?? ENDS["1:N"];
|
|
221
|
+
return (_jsxs("g", { className: "slc-erd-rel", children: [_jsx("path", { d: curve.path, className: "slc-erd-line" }), _jsx("path", { d: endMark(curve.p0, curve.p1, fromEnd), className: "slc-erd-mark" }), _jsx("path", { d: endMark(curve.p3, curve.p2, toEnd), className: "slc-erd-mark" })] }, `r${i}`));
|
|
222
|
+
}), entities.map((entity) => {
|
|
223
|
+
const box = positions[entity.name];
|
|
224
|
+
const rows = (entity.attributes ?? []).filter((a) => a?.name);
|
|
225
|
+
const isSelected = selection === entity.name;
|
|
226
|
+
const boxClass = [
|
|
227
|
+
"slc-node",
|
|
228
|
+
isSelected ? "slc-node--selected" : "",
|
|
229
|
+
errors.has(entity.name) ? "slc-node--error" : "",
|
|
230
|
+
]
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.join(" ");
|
|
233
|
+
return (_jsxs("g", { className: readOnly ? "slc-node--static" : "slc-node--draggable", onPointerDown: (e) => onPointerDown(e, entity.name), onContextMenu: (e) => {
|
|
234
|
+
if (!onContextMenu)
|
|
235
|
+
return;
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
onContextMenu(e.clientX, e.clientY, { kind: "entity", id: entity.name });
|
|
239
|
+
}, 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) => {
|
|
240
|
+
const y = box.y + ERD_BOX.headerHeight + r * ERD_BOX.rowHeight + 15;
|
|
241
|
+
const machines = stateOfList(attr);
|
|
242
|
+
const badges = keyBadges(attr);
|
|
243
|
+
return (_jsxs("g", { className: machines.length && onOpenMachine ? "slc-erd-state" : undefined, onPointerDown: machines.length && onOpenMachine ? (e) => e.stopPropagation() : undefined, onClick: machines.length && onOpenMachine ? () => onOpenMachine(machines[0]) : undefined, children: [(machines.length > 0 || attr.description) && (_jsx("title", { children: [machines.length ? `stores the state of ${machines.join(", ")}` : "", attr.description ?? ""]
|
|
244
|
+
.filter(Boolean)
|
|
245
|
+
.join(" — ") })), _jsxs("text", { x: box.x + ERD_BOX.padX, y: y, className: `slc-erd-row${machines.length ? " slc-erd-row--state" : ""}${attr.key === "pk" ? " slc-erd-row--pk" : ""}`, children: [machines.length ? "◉ " : "", erdRowText(attr), attr.nullable ? " ?" : ""] }), badges && (_jsx("text", { x: box.x + box.width - ERD_BOX.padX, y: y, textAnchor: "end", className: "slc-erd-badge", children: badges }))] }, attr.name));
|
|
246
|
+
})] }, entity.name));
|
|
247
|
+
}), labels.map((spot, i) => (_jsxs("g", { pointerEvents: "none", children: [_jsx("rect", { x: spot.x, y: spot.y, width: spot.width, height: spot.height, rx: 4, className: "slc-chip-plate" }), _jsx("text", { x: spot.cx, y: spot.cy - 5, textAnchor: "middle", className: "slc-erd-rel-label", children: spot.label.event })] }, `l${i}`)))] }) }), entities.length === 0 && emptyHint && _jsx("div", { className: "slc-erd-empty", children: emptyHint })] }));
|
|
248
|
+
}
|
|
249
|
+
export default EntityRelationshipCanvas;
|
|
250
|
+
//# sourceMappingURL=EntityRelationshipCanvas.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
16
|
export type { CanvasSelection, CanvasTarget, DrawMode, StateMachineCanvasHandle, StateMachineCanvasProps, } from "./StateMachineCanvas.js";
|
|
17
|
+
export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
18
|
+
export type { EntityRelationshipCanvasProps, ErdCanvasTarget } from "./EntityRelationshipCanvas.js";
|
|
17
19
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
18
20
|
export type { CanvasTheme } from "./theme.js";
|
|
19
21
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
20
|
-
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
21
|
-
export type { AutoLayoutOptions, Box, FitOptions, LayoutBox, Point, ScaleLimits, StateDef, StateMachineDefinition, TransitionDef, Viewport, } from "@miadi/stateloom-protocol";
|
|
22
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, erdAutoLayout, erdEntitySize, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
23
|
+
export type { AutoLayoutOptions, Box, EntityRelationshipDefinition, FitOptions, LayoutBox, Point, ScaleLimits, StateDef, StateMachineDefinition, TransitionDef, Viewport, } from "@miadi/stateloom-protocol";
|
package/dist/index.js
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* here, so a host needs one dependency to draw a board rather than two.
|
|
14
14
|
*/
|
|
15
15
|
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
|
+
export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
16
17
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
17
18
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
18
19
|
// The geometry and the model, re-exported at the address a host reaching for a
|
|
19
20
|
// canvas is already looking at.
|
|
20
|
-
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
21
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, erdAutoLayout, erdEntitySize, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/styles.css
CHANGED
|
@@ -402,3 +402,67 @@
|
|
|
402
402
|
filter: drop-shadow(0 0 4px rgb(34 197 94 / 0.85));
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
+
|
|
406
|
+
/* ─── Entity-relationship canvas (Spec 80) ────────────────────────────────── */
|
|
407
|
+
/* Drawn with the same variables as the state board, so one theme skins both. */
|
|
408
|
+
|
|
409
|
+
.slc-erd-line {
|
|
410
|
+
fill: none;
|
|
411
|
+
stroke: var(--slc-edge);
|
|
412
|
+
stroke-width: 1.5;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.slc-erd-mark {
|
|
416
|
+
fill: none;
|
|
417
|
+
stroke: var(--slc-edge);
|
|
418
|
+
stroke-width: 1.5;
|
|
419
|
+
stroke-linecap: round;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.slc-erd-rel-label {
|
|
423
|
+
fill: var(--slc-muted);
|
|
424
|
+
font-size: 11px;
|
|
425
|
+
font-weight: 500;
|
|
426
|
+
pointer-events: none;
|
|
427
|
+
user-select: none;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.slc-erd-rule {
|
|
431
|
+
stroke: var(--slc-node-stroke);
|
|
432
|
+
stroke-width: 1;
|
|
433
|
+
pointer-events: none;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.slc-erd-row {
|
|
437
|
+
fill: var(--slc-muted);
|
|
438
|
+
font-size: 11px;
|
|
439
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
440
|
+
user-select: none;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.slc-erd-row--pk { fill: var(--slc-label); font-weight: 600; }
|
|
444
|
+
.slc-erd-row--state { fill: var(--slc-accent-ink); }
|
|
445
|
+
.slc-erd-row--empty { fill: var(--slc-faint); font-style: italic; }
|
|
446
|
+
|
|
447
|
+
.slc-erd-state { cursor: pointer; }
|
|
448
|
+
.slc-erd-state:hover .slc-erd-row--state { text-decoration: underline; }
|
|
449
|
+
|
|
450
|
+
.slc-erd-badge {
|
|
451
|
+
fill: var(--slc-faint);
|
|
452
|
+
font-size: 9px;
|
|
453
|
+
font-weight: 600;
|
|
454
|
+
letter-spacing: 0.04em;
|
|
455
|
+
pointer-events: none;
|
|
456
|
+
user-select: none;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.slc-erd-empty {
|
|
460
|
+
position: absolute;
|
|
461
|
+
inset: 0;
|
|
462
|
+
display: flex;
|
|
463
|
+
align-items: center;
|
|
464
|
+
justify-content: center;
|
|
465
|
+
color: var(--slc-faint);
|
|
466
|
+
font-size: 16px;
|
|
467
|
+
pointer-events: none;
|
|
468
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/stateloom-canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"types": "dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
20
21
|
"import": "./dist/index.js",
|
|
21
|
-
"
|
|
22
|
+
"default": "./dist/index.js"
|
|
22
23
|
},
|
|
23
24
|
"./styles.css": "./dist/styles.css"
|
|
24
25
|
},
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"node": ">=20"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@miadi/stateloom-protocol": "^0.1.
|
|
46
|
+
"@miadi/stateloom-protocol": "^0.1.6"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"react": "^19"
|