@miadi/stateloom-canvas 0.1.3 → 0.1.5
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 +32 -1
- package/dist/EntityRelationshipCanvas.js +8 -2
- package/dist/SequenceCanvas.d.ts +73 -0
- package/dist/SequenceCanvas.js +394 -0
- package/dist/StateMachineCanvas.js +5 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/styles.css +109 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @miadi/stateloom-canvas
|
|
2
2
|
|
|
3
|
-
The
|
|
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
|
|
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
|
|
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);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sequence design surface (Spec 81) — the third sibling of
|
|
3
|
+
* `<StateMachineCanvas>` and `<EntityRelationshipCanvas>`.
|
|
4
|
+
*
|
|
5
|
+
* Same contract: props in, callbacks out, no store, no socket. The host owns
|
|
6
|
+
* the definition and the viewport; the geometry is `sequenceLayout(def)`, which
|
|
7
|
+
* the host may compute once and pass in so that its own "centre on message 9"
|
|
8
|
+
* and this drawing agree to the pixel. Same gestures: wheel pans, ⌃/⌘ wheel
|
|
9
|
+
* zooms at the pointer, a drag anywhere pans (nothing on a sequence is dragged
|
|
10
|
+
* into place — the order IS the drawing), two fingers pinch. Same `--slc-*`
|
|
11
|
+
* variables, so a themed host has themed this board too.
|
|
12
|
+
*
|
|
13
|
+
* What is drawn, from the layout:
|
|
14
|
+
*
|
|
15
|
+
* - a header box per participant. An actor (a participant that names a system
|
|
16
|
+
* actor) has rounded ends; an object participant (it IS a machine's object)
|
|
17
|
+
* has its name underlined, as UML writes an instance.
|
|
18
|
+
* - a lifeline under each header.
|
|
19
|
+
* - one arrow per message, headed by its ref and label. The event it fires is a
|
|
20
|
+
* small chip after the label, the state it leaves the machine in follows as
|
|
21
|
+
* `→ State`. A reply is dashed, an optional message is tagged `opt`, and a
|
|
22
|
+
* message to oneself is a loop to the right.
|
|
23
|
+
* - each fragment as a frame below the main messages, headed
|
|
24
|
+
* `alt · after 11 · <label>`.
|
|
25
|
+
*
|
|
26
|
+
* Selection is by focus kind: `{ kind: "message", id: "9" }` or
|
|
27
|
+
* `{ kind: "participant", id: "Chart" }` — the same names `focus=` uses.
|
|
28
|
+
*/
|
|
29
|
+
import { type CSSProperties, type ReactNode } from "react";
|
|
30
|
+
import { type SequenceDefinition, type SequenceLayout, type Viewport } from "@miadi/stateloom-protocol";
|
|
31
|
+
import { type CanvasTheme } from "./theme.js";
|
|
32
|
+
export type SequenceTargetKind = "message" | "participant";
|
|
33
|
+
export interface SequenceSelection {
|
|
34
|
+
kind: SequenceTargetKind;
|
|
35
|
+
/** A message ref (`"9"`, `"f1.2"`) or a participant name. */
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
export interface SequenceCanvasTarget {
|
|
39
|
+
kind: SequenceTargetKind | "canvas";
|
|
40
|
+
id?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface SequenceCanvasProps {
|
|
43
|
+
definition: SequenceDefinition;
|
|
44
|
+
/** `sequenceLayout(definition)`. Computed here when omitted. */
|
|
45
|
+
layout?: SequenceLayout;
|
|
46
|
+
viewport: Viewport;
|
|
47
|
+
onViewportChange: (viewport: Viewport) => void;
|
|
48
|
+
selection?: SequenceSelection | null;
|
|
49
|
+
/** Elements failing a check, as focus strings: `message:9`, `participant:Chart`. */
|
|
50
|
+
errorElements?: readonly string[];
|
|
51
|
+
/** Elements with a warning (the replay's stops), drawn quieter than errors. */
|
|
52
|
+
warningElements?: readonly string[];
|
|
53
|
+
/** Change this to re-fit the board to the whole drawing. */
|
|
54
|
+
fitKey?: string | number;
|
|
55
|
+
onSelect?: (kind: SequenceTargetKind, id: string) => void;
|
|
56
|
+
onClearSelection?: () => void;
|
|
57
|
+
onContextMenu?: (clientX: number, clientY: number, target: SequenceCanvasTarget) => void;
|
|
58
|
+
emptyHint?: ReactNode;
|
|
59
|
+
theme?: Partial<CanvasTheme>;
|
|
60
|
+
className?: string;
|
|
61
|
+
style?: CSSProperties;
|
|
62
|
+
svgId?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The sequence as this canvas draws it: every string a string, every list a
|
|
66
|
+
* list, nothing null — so a malformed document draws what it can instead of
|
|
67
|
+
* throwing. Positions are kept (a null message stays a row, an unnamed
|
|
68
|
+
* participant a column) so refs and the layout still line up. Read-only: the
|
|
69
|
+
* host's definition is never changed.
|
|
70
|
+
*/
|
|
71
|
+
export declare function drawableSequence(def: SequenceDefinition): SequenceDefinition;
|
|
72
|
+
export declare function SequenceCanvas({ definition: given, layout: givenLayout, viewport, onViewportChange, selection, errorElements, warningElements, fitKey, onSelect, onClearSelection, onContextMenu, emptyHint, theme, className, style, svgId, }: SequenceCanvasProps): import("react").JSX.Element;
|
|
73
|
+
export default SequenceCanvas;
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The sequence design surface (Spec 81) — the third sibling of
|
|
4
|
+
* `<StateMachineCanvas>` and `<EntityRelationshipCanvas>`.
|
|
5
|
+
*
|
|
6
|
+
* Same contract: props in, callbacks out, no store, no socket. The host owns
|
|
7
|
+
* the definition and the viewport; the geometry is `sequenceLayout(def)`, which
|
|
8
|
+
* the host may compute once and pass in so that its own "centre on message 9"
|
|
9
|
+
* and this drawing agree to the pixel. Same gestures: wheel pans, ⌃/⌘ wheel
|
|
10
|
+
* zooms at the pointer, a drag anywhere pans (nothing on a sequence is dragged
|
|
11
|
+
* into place — the order IS the drawing), two fingers pinch. Same `--slc-*`
|
|
12
|
+
* variables, so a themed host has themed this board too.
|
|
13
|
+
*
|
|
14
|
+
* What is drawn, from the layout:
|
|
15
|
+
*
|
|
16
|
+
* - a header box per participant. An actor (a participant that names a system
|
|
17
|
+
* actor) has rounded ends; an object participant (it IS a machine's object)
|
|
18
|
+
* has its name underlined, as UML writes an instance.
|
|
19
|
+
* - a lifeline under each header.
|
|
20
|
+
* - one arrow per message, headed by its ref and label. The event it fires is a
|
|
21
|
+
* small chip after the label, the state it leaves the machine in follows as
|
|
22
|
+
* `→ State`. A reply is dashed, an optional message is tagged `opt`, and a
|
|
23
|
+
* message to oneself is a loop to the right.
|
|
24
|
+
* - each fragment as a frame below the main messages, headed
|
|
25
|
+
* `alt · after 11 · <label>`.
|
|
26
|
+
*
|
|
27
|
+
* Selection is by focus kind: `{ kind: "message", id: "9" }` or
|
|
28
|
+
* `{ kind: "participant", id: "Chart" }` — the same names `focus=` uses.
|
|
29
|
+
*/
|
|
30
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
31
|
+
import { allMessages, fitToBoxes, panBy, sequenceLayout, textWidth, viewportTransform, zoomAt, } from "@miadi/stateloom-protocol";
|
|
32
|
+
import { themeStyle } from "./theme.js";
|
|
33
|
+
const WHEEL_LINE_HEIGHT = 16;
|
|
34
|
+
const WHEEL_PAGE_HEIGHT = 400;
|
|
35
|
+
/** Movement under this many screen pixels is a click, not a drag. */
|
|
36
|
+
const DRAG_THRESHOLD = 4;
|
|
37
|
+
const LABEL_SIZE = 11;
|
|
38
|
+
const CHIP_SIZE = 10;
|
|
39
|
+
const REF_SIZE = 10;
|
|
40
|
+
/** A self-message's loop: how far right it reaches and how tall it is. */
|
|
41
|
+
const LOOP_W = 30;
|
|
42
|
+
const LOOP_H = 14;
|
|
43
|
+
function wheelPixels(delta, mode) {
|
|
44
|
+
if (mode === 1)
|
|
45
|
+
return delta * WHEEL_LINE_HEIGHT;
|
|
46
|
+
if (mode === 2)
|
|
47
|
+
return delta * WHEEL_PAGE_HEIGHT;
|
|
48
|
+
return delta;
|
|
49
|
+
}
|
|
50
|
+
/** A filled arrowhead with its tip at (x, y), pointing along +dx. */
|
|
51
|
+
function arrowHead(x, y, dir, open) {
|
|
52
|
+
const back = x - dir * 9;
|
|
53
|
+
return open ? `M ${back} ${y - 4.5} L ${x} ${y} L ${back} ${y + 4.5}` : `M ${back} ${y - 4.5} L ${x} ${y} L ${back} ${y + 4.5} Z`;
|
|
54
|
+
}
|
|
55
|
+
function participantTitle(p) {
|
|
56
|
+
return [
|
|
57
|
+
p.actor ? `actor ${p.actor}` : p.object ? `object ${p.object}` : p.service ? `service ${p.service}` : "",
|
|
58
|
+
p.holds?.length ? `holds ${p.holds.join(", ")}` : "",
|
|
59
|
+
p.description ?? "",
|
|
60
|
+
p.notes?.trim() ? `Notes: ${p.notes}` : "",
|
|
61
|
+
]
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.join("\n");
|
|
64
|
+
}
|
|
65
|
+
function messageTitle(ref, m) {
|
|
66
|
+
return [
|
|
67
|
+
`${ref}. ${m.from} → ${m.to}: ${m.label}`,
|
|
68
|
+
m.event ? `fires ${m.event}${m.machine ? ` on ${m.machine}` : ""}` : "",
|
|
69
|
+
m.carries ? `carries ${m.carries}` : "",
|
|
70
|
+
m.state ? `then ${m.state}` : "",
|
|
71
|
+
m.optional ? "optional" : "",
|
|
72
|
+
m.reply ? "reply" : "",
|
|
73
|
+
m.description ?? "",
|
|
74
|
+
m.notes?.trim() ? `Notes: ${m.notes}` : "",
|
|
75
|
+
]
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join("\n");
|
|
78
|
+
}
|
|
79
|
+
const text = (v) => (typeof v === "string" ? v : v === null || v === undefined ? "" : String(v));
|
|
80
|
+
const optional = (v) => text(v) || undefined;
|
|
81
|
+
function drawableMessage(m) {
|
|
82
|
+
const o = (m && typeof m === "object" ? m : {});
|
|
83
|
+
return {
|
|
84
|
+
from: text(o.from),
|
|
85
|
+
to: text(o.to),
|
|
86
|
+
label: text(o.label),
|
|
87
|
+
event: optional(o.event),
|
|
88
|
+
machine: optional(o.machine),
|
|
89
|
+
carries: optional(o.carries),
|
|
90
|
+
state: optional(o.state),
|
|
91
|
+
description: optional(o.description),
|
|
92
|
+
notes: optional(o.notes),
|
|
93
|
+
optional: o.optional === true || undefined,
|
|
94
|
+
reply: o.reply === true || undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The sequence as this canvas draws it: every string a string, every list a
|
|
99
|
+
* list, nothing null — so a malformed document draws what it can instead of
|
|
100
|
+
* throwing. Positions are kept (a null message stays a row, an unnamed
|
|
101
|
+
* participant a column) so refs and the layout still line up. Read-only: the
|
|
102
|
+
* host's definition is never changed.
|
|
103
|
+
*/
|
|
104
|
+
export function drawableSequence(def) {
|
|
105
|
+
const d = (def && typeof def === "object" ? def : {});
|
|
106
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
107
|
+
const settings = (d.settings && typeof d.settings === "object" ? d.settings : {});
|
|
108
|
+
return {
|
|
109
|
+
settings: { namespace: text(settings.namespace), name: text(settings.name), notes: optional(settings.notes) },
|
|
110
|
+
participants: list(d.participants).map((p) => {
|
|
111
|
+
const o = (p && typeof p === "object" ? p : {});
|
|
112
|
+
return {
|
|
113
|
+
name: text(o.name),
|
|
114
|
+
description: optional(o.description),
|
|
115
|
+
notes: optional(o.notes),
|
|
116
|
+
actor: optional(o.actor),
|
|
117
|
+
service: optional(o.service),
|
|
118
|
+
object: optional(o.object),
|
|
119
|
+
holds: Array.isArray(o.holds) ? o.holds.map(text) : typeof o.holds === "string" ? [o.holds] : undefined,
|
|
120
|
+
};
|
|
121
|
+
}),
|
|
122
|
+
messages: list(d.messages).map(drawableMessage),
|
|
123
|
+
...(Array.isArray(d.fragments)
|
|
124
|
+
? {
|
|
125
|
+
fragments: d.fragments.map((f) => {
|
|
126
|
+
const o = (f && typeof f === "object" ? f : {});
|
|
127
|
+
return {
|
|
128
|
+
kind: text(o.kind),
|
|
129
|
+
label: text(o.label),
|
|
130
|
+
after: typeof o.after === "number" && Number.isFinite(o.after) ? o.after : 0,
|
|
131
|
+
notes: optional(o.notes),
|
|
132
|
+
messages: list(o.messages).map(drawableMessage),
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
135
|
+
}
|
|
136
|
+
: {}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export function SequenceCanvas({ definition: given, layout: givenLayout, viewport, onViewportChange, selection = null, errorElements, warningElements, fitKey, onSelect, onClearSelection, onContextMenu, emptyHint, theme, className, style, svgId, }) {
|
|
140
|
+
const svgRef = useRef(null);
|
|
141
|
+
const viewportRef = useRef(viewport);
|
|
142
|
+
viewportRef.current = viewport;
|
|
143
|
+
const gestureRef = useRef(null);
|
|
144
|
+
const pointersRef = useRef(new Map());
|
|
145
|
+
const pinchRef = useRef(null);
|
|
146
|
+
// What is drawn: the document with every field read defensively — a
|
|
147
|
+
// hand-written or agent-written file is not always the shape the types say.
|
|
148
|
+
const definition = useMemo(() => drawableSequence(given), [given]);
|
|
149
|
+
const layout = useMemo(() => givenLayout ?? sequenceLayout(definition), [givenLayout, definition]);
|
|
150
|
+
// The words on each row, measured once drawn: an estimate places the event
|
|
151
|
+
// chip after the label, the measure puts it right after it. Keyed `ref:part`.
|
|
152
|
+
const textRefs = useRef(new Map());
|
|
153
|
+
const [measured, setMeasured] = useState({});
|
|
154
|
+
const measureRef = (key) => (el) => {
|
|
155
|
+
if (el)
|
|
156
|
+
textRefs.current.set(key, el);
|
|
157
|
+
else
|
|
158
|
+
textRefs.current.delete(key);
|
|
159
|
+
};
|
|
160
|
+
useLayoutEffect(() => {
|
|
161
|
+
const next = {};
|
|
162
|
+
let changed = false;
|
|
163
|
+
for (const [key, el] of textRefs.current) {
|
|
164
|
+
const w = typeof el.getComputedTextLength === "function" ? el.getComputedTextLength() : 0;
|
|
165
|
+
if (!w)
|
|
166
|
+
continue;
|
|
167
|
+
next[key] = w;
|
|
168
|
+
if (Math.abs((measured[key] ?? -1) - w) > 0.5)
|
|
169
|
+
changed = true;
|
|
170
|
+
}
|
|
171
|
+
if (changed)
|
|
172
|
+
setMeasured(next);
|
|
173
|
+
// Measured again whenever what is drawn changes.
|
|
174
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
175
|
+
}, [layout, definition]);
|
|
176
|
+
const messages = useMemo(() => new Map(allMessages(definition).map((m) => [m.ref, m.message])), [definition]);
|
|
177
|
+
const participants = useMemo(() => new Map(definition.participants.filter((p) => p.name).map((p) => [p.name, p])), [definition.participants]);
|
|
178
|
+
const toCanvasPoint = useCallback((clientX, clientY) => {
|
|
179
|
+
const rect = svgRef.current?.getBoundingClientRect();
|
|
180
|
+
return { x: clientX - (rect?.left ?? 0), y: clientY - (rect?.top ?? 0) };
|
|
181
|
+
}, []);
|
|
182
|
+
// Fit on demand, as the other boards do.
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (fitKey === undefined)
|
|
185
|
+
return;
|
|
186
|
+
const rect = svgRef.current?.getBoundingClientRect();
|
|
187
|
+
if (!rect || layout.participants.length === 0)
|
|
188
|
+
return;
|
|
189
|
+
onViewportChange(fitToBoxes([{ x: 0, y: 0, width: layout.width, height: layout.height }], rect.width, rect.height, { padding: 16 }));
|
|
190
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
191
|
+
}, [fitKey]);
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
const svg = svgRef.current;
|
|
194
|
+
if (!svg)
|
|
195
|
+
return;
|
|
196
|
+
const onWheel = (e) => {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
const vp = viewportRef.current;
|
|
199
|
+
const dx = wheelPixels(e.deltaX, e.deltaMode);
|
|
200
|
+
const dy = wheelPixels(e.deltaY, e.deltaMode);
|
|
201
|
+
if (e.ctrlKey || e.metaKey) {
|
|
202
|
+
onViewportChange(zoomAt(vp, Math.exp(-dy * 0.0025), toCanvasPoint(e.clientX, e.clientY)));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const moveX = e.shiftKey ? -(dx || dy) : -dx;
|
|
206
|
+
const moveY = e.shiftKey ? 0 : -dy;
|
|
207
|
+
if (moveX !== 0 || moveY !== 0)
|
|
208
|
+
onViewportChange(panBy(vp, moveX, moveY));
|
|
209
|
+
};
|
|
210
|
+
svg.addEventListener("wheel", onWheel, { passive: false });
|
|
211
|
+
return () => svg.removeEventListener("wheel", onWheel);
|
|
212
|
+
}, [onViewportChange, toCanvasPoint]);
|
|
213
|
+
const pinchState = () => {
|
|
214
|
+
const pts = [...pointersRef.current.values()];
|
|
215
|
+
if (pts.length < 2)
|
|
216
|
+
return null;
|
|
217
|
+
const [a, b] = pts;
|
|
218
|
+
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 } };
|
|
219
|
+
};
|
|
220
|
+
const onPointerDown = (e, target) => {
|
|
221
|
+
if (e.button !== 0 && e.pointerType === "mouse")
|
|
222
|
+
return;
|
|
223
|
+
e.stopPropagation();
|
|
224
|
+
svgRef.current?.setPointerCapture(e.pointerId);
|
|
225
|
+
pointersRef.current.set(e.pointerId, toCanvasPoint(e.clientX, e.clientY));
|
|
226
|
+
if (pointersRef.current.size >= 2) {
|
|
227
|
+
gestureRef.current = null;
|
|
228
|
+
pinchRef.current = pinchState();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
gestureRef.current = {
|
|
232
|
+
pointerId: e.pointerId,
|
|
233
|
+
startX: e.clientX,
|
|
234
|
+
startY: e.clientY,
|
|
235
|
+
lastX: e.clientX,
|
|
236
|
+
lastY: e.clientY,
|
|
237
|
+
target,
|
|
238
|
+
moved: false,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
const onPointerMove = (e) => {
|
|
242
|
+
if (pointersRef.current.has(e.pointerId))
|
|
243
|
+
pointersRef.current.set(e.pointerId, toCanvasPoint(e.clientX, e.clientY));
|
|
244
|
+
if (pinchRef.current) {
|
|
245
|
+
const next = pinchState();
|
|
246
|
+
if (!next)
|
|
247
|
+
return;
|
|
248
|
+
const prev = pinchRef.current;
|
|
249
|
+
const panned = panBy(viewportRef.current, next.mid.x - prev.mid.x, next.mid.y - prev.mid.y);
|
|
250
|
+
onViewportChange(zoomAt(panned, next.distance / prev.distance, next.mid));
|
|
251
|
+
pinchRef.current = next;
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const g = gestureRef.current;
|
|
255
|
+
if (!g || g.pointerId !== e.pointerId)
|
|
256
|
+
return;
|
|
257
|
+
if (!g.moved && Math.hypot(e.clientX - g.startX, e.clientY - g.startY) < DRAG_THRESHOLD)
|
|
258
|
+
return;
|
|
259
|
+
g.moved = true;
|
|
260
|
+
onViewportChange(panBy(viewportRef.current, e.clientX - g.lastX, e.clientY - g.lastY));
|
|
261
|
+
g.lastX = e.clientX;
|
|
262
|
+
g.lastY = e.clientY;
|
|
263
|
+
};
|
|
264
|
+
const onPointerUp = (e) => {
|
|
265
|
+
pointersRef.current.delete(e.pointerId);
|
|
266
|
+
if (pinchRef.current) {
|
|
267
|
+
if (pointersRef.current.size < 2)
|
|
268
|
+
pinchRef.current = null;
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const g = gestureRef.current;
|
|
272
|
+
if (!g || g.pointerId !== e.pointerId)
|
|
273
|
+
return;
|
|
274
|
+
gestureRef.current = null;
|
|
275
|
+
if (g.moved)
|
|
276
|
+
return;
|
|
277
|
+
if (g.target)
|
|
278
|
+
onSelect?.(g.target.kind, g.target.id);
|
|
279
|
+
else
|
|
280
|
+
onClearSelection?.();
|
|
281
|
+
};
|
|
282
|
+
const menu = (target) => (e) => {
|
|
283
|
+
if (!onContextMenu)
|
|
284
|
+
return;
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
e.stopPropagation();
|
|
287
|
+
onContextMenu(e.clientX, e.clientY, target);
|
|
288
|
+
};
|
|
289
|
+
const errors = new Set(errorElements ?? []);
|
|
290
|
+
const warnings = new Set(warningElements ?? []);
|
|
291
|
+
const isSel = (kind, id) => selection?.kind === kind && selection.id === id;
|
|
292
|
+
const selectedMessage = selection?.kind === "message" ? messages.get(selection.id) : undefined;
|
|
293
|
+
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: menu({ kind: "canvas" }), children: _jsxs("g", { transform: viewportTransform(viewport), children: [layout.fragments.map((box) => {
|
|
294
|
+
const f = definition.fragments?.[box.index];
|
|
295
|
+
if (!f)
|
|
296
|
+
return null;
|
|
297
|
+
const heading = `${f.kind} · after ${f.after} · ${f.label}`;
|
|
298
|
+
const tabW = textWidth(heading, LABEL_SIZE) + 18;
|
|
299
|
+
const top = box.top;
|
|
300
|
+
return (_jsxs("g", { className: "slc-sqd-fragment", children: [f.notes?.trim() && _jsx("title", { children: `Notes: ${f.notes}` }), _jsx("rect", { x: box.left, y: top, width: box.width, height: box.height, rx: 3, className: "slc-sqd-frame" }), _jsx("path", { d: `M ${box.left} ${top + 22} L ${box.left} ${top} L ${box.left + tabW} ${top} L ${box.left + tabW} ${top + 15} L ${box.left + tabW - 7} ${top + 22} Z`, className: "slc-sqd-frame-tab" }), _jsxs("text", { x: box.left + 8, y: top + 15, className: "slc-sqd-frame-heading", children: [_jsx("tspan", { className: "slc-sqd-frame-kind", children: f.kind }), ` · after ${f.after} · ${f.label}`] }), f.notes?.trim() && (_jsx("rect", { x: box.left + tabW + 6, y: top + 7, width: 13, height: 5, rx: 1.5, className: "slc-note-mark" }))] }, `f${box.index}`));
|
|
301
|
+
}), layout.participants.map((box) => {
|
|
302
|
+
const selected = isSel("participant", box.name);
|
|
303
|
+
return (_jsxs("g", { onPointerDown: (e) => onPointerDown(e, { kind: "participant", id: box.name }), children: [_jsx("path", { d: `M ${box.x} ${layout.lifelineTop} V ${layout.lifelineBottom}`, className: "slc-sqd-hit" }), _jsx("path", { d: `M ${box.x} ${layout.lifelineTop} V ${layout.lifelineBottom}`, className: `slc-sqd-lifeline${selected ? " slc-sqd-lifeline--selected" : ""}` })] }, `l-${box.name}`));
|
|
304
|
+
}), layout.fragments.map((box) => {
|
|
305
|
+
const f = definition.fragments?.[box.index];
|
|
306
|
+
const anchor = f && f.after > 0 ? layout.rows.find((r) => r.fragment === null && r.index === f.after - 1) : undefined;
|
|
307
|
+
if (!anchor)
|
|
308
|
+
return null;
|
|
309
|
+
const x = box.left + 4;
|
|
310
|
+
return (_jsx("path", { d: `M ${Math.min(anchor.fromX, anchor.toX) - 14} ${anchor.y} H ${x} V ${box.top}`, className: "slc-sqd-branch" }, `fa${box.index}`));
|
|
311
|
+
}), layout.rows.map((row) => {
|
|
312
|
+
const m = messages.get(row.ref);
|
|
313
|
+
if (!m)
|
|
314
|
+
return null;
|
|
315
|
+
const focus = `message:${row.ref}`;
|
|
316
|
+
const selected = isSel("message", row.ref);
|
|
317
|
+
const error = errors.has(focus);
|
|
318
|
+
const warn = !error && warnings.has(focus);
|
|
319
|
+
const lineClass = [
|
|
320
|
+
"slc-sqd-line",
|
|
321
|
+
m.reply ? "slc-sqd-line--reply" : "",
|
|
322
|
+
m.optional ? "slc-sqd-line--optional" : "",
|
|
323
|
+
error ? "slc-sqd-line--error" : warn ? "slc-sqd-line--warn" : "",
|
|
324
|
+
selected ? "slc-sqd-line--selected" : "",
|
|
325
|
+
]
|
|
326
|
+
.filter(Boolean)
|
|
327
|
+
.join(" ");
|
|
328
|
+
const headClass = `slc-sqd-head${m.reply ? " slc-sqd-head--open" : ""}${selected ? " slc-sqd-head--selected" : error ? " slc-sqd-head--error" : ""}`;
|
|
329
|
+
// The words, measured: ref, label, then the chips that follow it.
|
|
330
|
+
const refText = row.ref;
|
|
331
|
+
const refW = textWidth(refText, REF_SIZE) + 8;
|
|
332
|
+
const labelW = measured[`${row.ref}:label`] ?? textWidth(m.label ?? "", LABEL_SIZE);
|
|
333
|
+
const optW = m.optional ? textWidth("opt", CHIP_SIZE) + 8 : 0;
|
|
334
|
+
const chipW = m.event ? (measured[`${row.ref}:event`] ?? m.event.length * 6.1) + 12 : 0;
|
|
335
|
+
const stateText = m.state ? `→ ${m.state}` : "";
|
|
336
|
+
const stateW = m.state ? (measured[`${row.ref}:state`] ?? textWidth(stateText, LABEL_SIZE)) : 0;
|
|
337
|
+
const gap = 5;
|
|
338
|
+
const total = refW + gap + labelW + (optW ? gap + optW : 0) + (chipW ? gap + chipW : 0) + (stateW ? gap + stateW : 0);
|
|
339
|
+
let startX;
|
|
340
|
+
let baseline;
|
|
341
|
+
let geometry;
|
|
342
|
+
let hit;
|
|
343
|
+
if (row.self) {
|
|
344
|
+
const x = row.fromX;
|
|
345
|
+
const top = row.y - LOOP_H / 2 - 2;
|
|
346
|
+
const bottom = top + LOOP_H;
|
|
347
|
+
geometry = (_jsxs(_Fragment, { children: [_jsx("path", { d: `M ${x} ${top} H ${x + LOOP_W} V ${bottom} H ${x + 2}`, className: lineClass }), _jsx("path", { d: arrowHead(x + 1, bottom, -1, !!m.reply), className: headClass })] }));
|
|
348
|
+
startX = x + LOOP_W + 8;
|
|
349
|
+
baseline = row.y + 2;
|
|
350
|
+
hit = { x: x - 6, y: top - 8, w: LOOP_W + 14 + total, h: LOOP_H + 16 };
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const dir = row.toX >= row.fromX ? 1 : -1;
|
|
354
|
+
const lineEnd = row.toX - dir * 1;
|
|
355
|
+
geometry = (_jsxs(_Fragment, { children: [_jsx("path", { d: `M ${row.fromX} ${row.y} H ${lineEnd}`, className: lineClass }), _jsx("path", { d: arrowHead(lineEnd, row.y, dir, !!m.reply), className: headClass })] }));
|
|
356
|
+
const mid = (row.fromX + row.toX) / 2;
|
|
357
|
+
startX = mid - total / 2;
|
|
358
|
+
baseline = row.y - 6;
|
|
359
|
+
const left = Math.min(row.fromX, row.toX, startX);
|
|
360
|
+
const right = Math.max(row.fromX, row.toX, startX + total);
|
|
361
|
+
hit = { x: left - 4, y: row.y - 22, w: right - left + 8, h: 30 };
|
|
362
|
+
}
|
|
363
|
+
let cursor = startX;
|
|
364
|
+
const place = (w) => {
|
|
365
|
+
const at = cursor;
|
|
366
|
+
cursor += w + gap;
|
|
367
|
+
return at;
|
|
368
|
+
};
|
|
369
|
+
const refX = place(refW);
|
|
370
|
+
const labelX = place(labelW);
|
|
371
|
+
const optX = optW ? place(optW) : 0;
|
|
372
|
+
const chipX = chipW ? place(chipW) : 0;
|
|
373
|
+
const stateX = stateW ? place(stateW) : 0;
|
|
374
|
+
return (_jsxs("g", { className: "slc-sqd-message", onPointerDown: (e) => onPointerDown(e, { kind: "message", id: row.ref }), onContextMenu: menu({ kind: "message", id: row.ref }), children: [_jsx("title", { children: messageTitle(row.ref, m) }), _jsx("rect", { x: hit.x, y: hit.y, width: hit.w, height: hit.h, className: "slc-sqd-hitbox" }), selected && _jsx("rect", { x: hit.x, y: hit.y, width: hit.w, height: hit.h, rx: 4, className: "slc-sqd-selected-plate" }), geometry, _jsx("rect", { x: refX, y: baseline - 10, width: refW - 2, height: 13, rx: 6.5, className: `slc-sqd-ref-plate${selected ? " slc-sqd-ref-plate--selected" : ""}` }), _jsx("text", { x: refX + (refW - 2) / 2, y: baseline, textAnchor: "middle", className: "slc-sqd-ref", children: refText }), _jsx("text", { ref: measureRef(`${row.ref}:label`), x: labelX, y: baseline, className: `slc-sqd-label${selected ? " slc-sqd-label--selected" : ""}${error ? " slc-sqd-label--error" : ""}`, children: m.label }), optW > 0 && (_jsxs(_Fragment, { children: [_jsx("rect", { x: optX, y: baseline - 10, width: optW, height: 13, rx: 3, className: "slc-sqd-opt" }), _jsx("text", { x: optX + optW / 2, y: baseline - 0.5, textAnchor: "middle", className: "slc-sqd-opt-text", children: "opt" })] })), chipW > 0 && (_jsxs(_Fragment, { children: [_jsx("rect", { x: chipX, y: baseline - 10.5, width: chipW, height: 14, rx: 7, className: "slc-sqd-event" }), _jsx("text", { ref: measureRef(`${row.ref}:event`), x: chipX + chipW / 2, y: baseline - 0.5, textAnchor: "middle", className: "slc-sqd-event-text", children: m.event })] })), stateW > 0 && (_jsx("text", { ref: measureRef(`${row.ref}:state`), x: stateX, y: baseline, className: "slc-sqd-state", children: stateText })), m.notes?.trim() && (_jsx("rect", { x: cursor - gap + 3, y: baseline - 9, width: 5, height: 11, rx: 1.5, className: "slc-note-mark" }))] }, `m-${row.ref}`));
|
|
375
|
+
}), layout.participants.map((box) => {
|
|
376
|
+
const p = participants.get(box.name);
|
|
377
|
+
if (!p)
|
|
378
|
+
return null;
|
|
379
|
+
const focus = `participant:${box.name}`;
|
|
380
|
+
const selected = isSel("participant", box.name) || (!!selectedMessage && (selectedMessage.from === box.name || selectedMessage.to === box.name));
|
|
381
|
+
const cls = [
|
|
382
|
+
"slc-node",
|
|
383
|
+
"slc-sqd-header",
|
|
384
|
+
isSel("participant", box.name) ? "slc-node--selected" : selected ? "slc-sqd-header--involved" : "",
|
|
385
|
+
errors.has(focus) ? "slc-node--error" : "",
|
|
386
|
+
]
|
|
387
|
+
.filter(Boolean)
|
|
388
|
+
.join(" ");
|
|
389
|
+
const kind = p.actor ? "actor" : p.object ? "object" : p.service ? "service" : "";
|
|
390
|
+
return (_jsxs("g", { className: "slc-node--static slc-sqd-participant", onPointerDown: (e) => onPointerDown(e, { kind: "participant", id: box.name }), onContextMenu: menu({ kind: "participant", id: box.name }), children: [participantTitle(p) && _jsx("title", { children: participantTitle(p) }), _jsx("rect", { x: box.left, y: box.top, width: box.width, height: box.height, rx: p.actor ? box.height / 2 : 4, className: cls }), p.notes?.trim() && (_jsx("rect", { x: box.left + box.width - 24, y: box.top - 5, width: 13, height: 5, rx: 1.5, className: "slc-note-mark" })), _jsx("text", { x: box.x, y: box.top + box.height / 2 + (kind ? 1 : 4), textAnchor: "middle", className: `slc-node-name slc-sqd-name${p.object ? " slc-sqd-name--object" : ""}`, children: box.name }), kind && (_jsxs("text", { x: box.x, y: box.top + box.height - 4, textAnchor: "middle", className: "slc-sqd-kind", children: [kind === "object" ? `:${p.object}` : kind === "service" ? "service" : "actor", p.holds?.length ? ` · holds ${p.holds.length}` : ""] }))] }, `p-${box.name}`));
|
|
391
|
+
})] }) }), layout.participants.length === 0 && emptyHint && _jsx("div", { className: "slc-erd-empty", children: emptyHint })] }));
|
|
392
|
+
}
|
|
393
|
+
export default SequenceCanvas;
|
|
394
|
+
//# sourceMappingURL=SequenceCanvas.js.map
|
|
@@ -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 && (
|
|
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/index.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
|
16
16
|
export type { CanvasSelection, CanvasTarget, DrawMode, StateMachineCanvasHandle, StateMachineCanvasProps, } from "./StateMachineCanvas.js";
|
|
17
17
|
export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
18
18
|
export type { EntityRelationshipCanvasProps, ErdCanvasTarget } from "./EntityRelationshipCanvas.js";
|
|
19
|
+
export { SequenceCanvas, drawableSequence } from "./SequenceCanvas.js";
|
|
20
|
+
export type { SequenceCanvasProps, SequenceCanvasTarget, SequenceSelection, SequenceTargetKind, } from "./SequenceCanvas.js";
|
|
19
21
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
20
22
|
export type { CanvasTheme } from "./theme.js";
|
|
21
23
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
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";
|
|
24
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, erdAutoLayout, erdEntitySize, sequenceLayout, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
25
|
+
export type { AutoLayoutOptions, Box, EntityRelationshipDefinition, FitOptions, LayoutBox, Point, ScaleLimits, SequenceDefinition, SequenceLayout, StateDef, StateMachineDefinition, TransitionDef, Viewport, } from "@miadi/stateloom-protocol";
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
16
|
export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
17
|
+
export { SequenceCanvas, drawableSequence } from "./SequenceCanvas.js";
|
|
17
18
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
18
19
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
19
20
|
// The geometry and the model, re-exported at the address a host reaching for a
|
|
20
21
|
// canvas is already looking at.
|
|
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";
|
|
22
|
+
export { autoLayout, AUTO_LAYOUT_DEFAULTS, IDENTITY_VIEWPORT, VIEWPORT_LIMITS, clampScale, fitToBoxes, normalizeViewport, panBy, sameViewport, screenDeltaToWorld, screenToWorld, viewportTransform, worldToScreen, zoomAt, zoomTo, routeEdges, erdAutoLayout, erdEntitySize, sequenceLayout, placeLabels, eventGlyph, guardText, } from "@miadi/stateloom-protocol";
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
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. */
|
|
@@ -516,3 +521,107 @@
|
|
|
516
521
|
font-size: 16px;
|
|
517
522
|
pointer-events: none;
|
|
518
523
|
}
|
|
524
|
+
|
|
525
|
+
/* ─── Sequence canvas (Spec 81) ───────────────────────────────────────────── */
|
|
526
|
+
/* The same variables again: one theme skins all three boards. */
|
|
527
|
+
|
|
528
|
+
.slc-sqd-name { font-size: 12px; }
|
|
529
|
+
.slc-sqd-name--object { text-decoration: underline; }
|
|
530
|
+
|
|
531
|
+
.slc-sqd-kind {
|
|
532
|
+
fill: var(--slc-faint);
|
|
533
|
+
font-size: 8.5px;
|
|
534
|
+
pointer-events: none;
|
|
535
|
+
user-select: none;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.slc-sqd-header--involved { stroke: var(--slc-accent-ink); stroke-width: 1.5; }
|
|
539
|
+
|
|
540
|
+
.slc-sqd-participant,
|
|
541
|
+
.slc-sqd-message { cursor: pointer; }
|
|
542
|
+
|
|
543
|
+
.slc-sqd-lifeline {
|
|
544
|
+
fill: none;
|
|
545
|
+
stroke: var(--slc-node-stroke);
|
|
546
|
+
stroke-width: 1;
|
|
547
|
+
stroke-dasharray: 4 4;
|
|
548
|
+
pointer-events: none;
|
|
549
|
+
}
|
|
550
|
+
.slc-sqd-lifeline--selected { stroke: var(--slc-accent); stroke-width: 1.5; }
|
|
551
|
+
|
|
552
|
+
/* Invisible, wide: what a finger actually hits. */
|
|
553
|
+
.slc-sqd-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
|
|
554
|
+
.slc-sqd-hitbox { fill: transparent; }
|
|
555
|
+
|
|
556
|
+
.slc-sqd-line {
|
|
557
|
+
fill: none;
|
|
558
|
+
stroke: var(--slc-edge);
|
|
559
|
+
stroke-width: 1.5;
|
|
560
|
+
pointer-events: none;
|
|
561
|
+
}
|
|
562
|
+
.slc-sqd-line--reply { stroke-dasharray: 6 4; }
|
|
563
|
+
.slc-sqd-line--optional { opacity: 0.8; }
|
|
564
|
+
.slc-sqd-line--warn { stroke: var(--slc-draw-source); }
|
|
565
|
+
.slc-sqd-line--error { stroke: var(--slc-danger); }
|
|
566
|
+
.slc-sqd-line--selected { stroke: var(--slc-accent); stroke-width: 2; }
|
|
567
|
+
|
|
568
|
+
.slc-sqd-head { fill: var(--slc-edge); stroke: var(--slc-edge); stroke-width: 1.2; stroke-linejoin: round; pointer-events: none; }
|
|
569
|
+
.slc-sqd-head--open { fill: none; stroke-width: 1.5; }
|
|
570
|
+
.slc-sqd-head--error { fill: var(--slc-danger); stroke: var(--slc-danger); }
|
|
571
|
+
.slc-sqd-head--selected { fill: var(--slc-accent); stroke: var(--slc-accent); }
|
|
572
|
+
.slc-sqd-head--open.slc-sqd-head--selected,
|
|
573
|
+
.slc-sqd-head--open.slc-sqd-head--error { fill: none; }
|
|
574
|
+
|
|
575
|
+
.slc-sqd-selected-plate { fill: var(--slc-accent-fill); opacity: 0.35; pointer-events: none; }
|
|
576
|
+
|
|
577
|
+
.slc-sqd-ref-plate { fill: var(--slc-chip-fill); stroke: var(--slc-chip-stroke); stroke-width: 1; pointer-events: none; }
|
|
578
|
+
.slc-sqd-ref-plate--selected { stroke: var(--slc-accent); }
|
|
579
|
+
.slc-sqd-ref {
|
|
580
|
+
fill: var(--slc-muted);
|
|
581
|
+
font-size: 10px;
|
|
582
|
+
font-weight: 600;
|
|
583
|
+
pointer-events: none;
|
|
584
|
+
user-select: none;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.slc-sqd-label {
|
|
588
|
+
fill: var(--slc-label);
|
|
589
|
+
font-size: 11px;
|
|
590
|
+
pointer-events: none;
|
|
591
|
+
user-select: none;
|
|
592
|
+
}
|
|
593
|
+
.slc-sqd-label--selected { fill: var(--slc-accent-ink); }
|
|
594
|
+
.slc-sqd-label--error { fill: var(--slc-danger); }
|
|
595
|
+
|
|
596
|
+
.slc-sqd-event { fill: var(--slc-accent-fill); stroke: var(--slc-accent); stroke-width: 0.8; pointer-events: none; }
|
|
597
|
+
.slc-sqd-event-text {
|
|
598
|
+
fill: var(--slc-accent-ink);
|
|
599
|
+
font-size: 10px;
|
|
600
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
601
|
+
pointer-events: none;
|
|
602
|
+
user-select: none;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.slc-sqd-opt { fill: none; stroke: var(--slc-faint); stroke-width: 1; stroke-dasharray: 2 2; pointer-events: none; }
|
|
606
|
+
.slc-sqd-opt-text { fill: var(--slc-muted); font-size: 9.5px; font-style: italic; pointer-events: none; user-select: none; }
|
|
607
|
+
|
|
608
|
+
.slc-sqd-state {
|
|
609
|
+
fill: var(--slc-entry);
|
|
610
|
+
font-size: 11px;
|
|
611
|
+
font-weight: 600;
|
|
612
|
+
pointer-events: none;
|
|
613
|
+
user-select: none;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
.slc-sqd-frame { fill: none; stroke: var(--slc-composite); stroke-width: 1.2; pointer-events: none; }
|
|
617
|
+
.slc-sqd-frame-tab { fill: var(--slc-composite-fill); stroke: var(--slc-composite); stroke-width: 1.2; pointer-events: none; }
|
|
618
|
+
.slc-sqd-frame-heading { fill: var(--slc-muted); font-size: 11px; pointer-events: none; user-select: none; }
|
|
619
|
+
.slc-sqd-frame-kind { fill: var(--slc-label); font-weight: 700; }
|
|
620
|
+
|
|
621
|
+
.slc-sqd-branch {
|
|
622
|
+
fill: none;
|
|
623
|
+
stroke: var(--slc-composite);
|
|
624
|
+
stroke-width: 1;
|
|
625
|
+
stroke-dasharray: 1 3;
|
|
626
|
+
pointer-events: none;
|
|
627
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/stateloom-canvas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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.
|
|
46
|
+
"@miadi/stateloom-protocol": "^0.1.9"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react": "^19"
|