@miadi/stateloom-canvas 0.1.4 → 0.1.6

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.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Talking with a companion from the canvas (Spec 84) — the dock.
3
+ *
4
+ * The phone page's conversation, folded into a corner of the board: one button records a
5
+ * take (Record → Stop & send → Sending…, Send again when a send failed), the line under
6
+ * it says what happened, and the conversation reads newest first — the person's takes
7
+ * (with the drawing they were looking at) and the companion's replies, each with ▶ to
8
+ * hear it walk the diagram again, and a thumb. Closed, it is one round button that shows
9
+ * the clock while recording and how many replies are new.
10
+ *
11
+ * Props in, callbacks out: the host holds the recorder, the conversation and the stage
12
+ * (`createTakeRecorder`, `createCompanionThread`, `present` in `@miadi/stateloom-react`).
13
+ */
14
+ import type { CSSProperties } from "react";
15
+ import { type CanvasTheme } from "./theme.js";
16
+ export interface DockTake {
17
+ kind: "take";
18
+ take: string;
19
+ at: string;
20
+ text: string;
21
+ canvas?: {
22
+ doc: string | null;
23
+ kind: string | null;
24
+ focus: string | null;
25
+ step?: {
26
+ title?: string;
27
+ index?: number;
28
+ count?: number;
29
+ } | null;
30
+ };
31
+ }
32
+ /** One step of a reply that walks the diagram: what is said, on which drawing, lighting what. */
33
+ export interface DockStep {
34
+ say: string;
35
+ title?: string;
36
+ doc?: string;
37
+ focus?: string;
38
+ spotlight?: string[];
39
+ }
40
+ export interface DockReply {
41
+ kind: "reply";
42
+ id: string;
43
+ take: string | null;
44
+ text: string;
45
+ at: string;
46
+ audio: string | null;
47
+ unvoiced?: string;
48
+ feedback?: "up" | "down";
49
+ steps?: DockStep[];
50
+ }
51
+ export type DockItem = DockTake | DockReply;
52
+ export interface CompanionDockProps {
53
+ open: boolean;
54
+ onOpenChange: (open: boolean) => void;
55
+ /** Who answers. Default "Mia". */
56
+ who?: string;
57
+ episode: string | null;
58
+ episodes?: readonly {
59
+ path: string;
60
+ number: number;
61
+ }[];
62
+ onEpisode?: (path: string) => void;
63
+ presence: {
64
+ state: string;
65
+ takes?: string[];
66
+ } | null;
67
+ recorder: {
68
+ state: "idle" | "starting" | "recording" | "sending" | "retry";
69
+ seconds: number;
70
+ held: number;
71
+ message: string;
72
+ error: boolean;
73
+ unavailable?: string;
74
+ };
75
+ onRecord: () => void;
76
+ items: readonly DockItem[];
77
+ /** Replies that arrived and were not heard yet. */
78
+ unheard?: readonly string[];
79
+ /** The reply being heard now. */
80
+ playing?: string | null;
81
+ /** The step of that reply on the board now, counted from 0. */
82
+ playingStep?: number | null;
83
+ /** Play a reply; `from` starts a reply with steps at that step (from 0). */
84
+ onPlay: (id: string, from?: number) => void;
85
+ onStop?: () => void;
86
+ onFeedback?: (id: string, value: "up" | "down" | "") => void;
87
+ autoplay: boolean;
88
+ onAutoplay: (on: boolean) => void;
89
+ /** A take waiting for its reply, and for how long. */
90
+ waiting?: {
91
+ take: string;
92
+ seconds: number;
93
+ } | null;
94
+ notice?: string | null;
95
+ error?: string | null;
96
+ theme?: Partial<CanvasTheme>;
97
+ className?: string;
98
+ style?: CSSProperties;
99
+ }
100
+ export declare function CompanionDock({ open, onOpenChange, who, episode, episodes, onEpisode, presence, recorder, onRecord, items, unheard, playing, playingStep, onPlay, onStop, onFeedback, autoplay, onAutoplay, waiting, notice, error, theme, className, style, }: CompanionDockProps): import("react").JSX.Element;
101
+ export default CompanionDock;
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { themeStyle } from "./theme.js";
3
+ import { CloseIcon, MicIcon, PlayIcon, SpeakerIcon, StopIcon, ThumbDownIcon, ThumbUpIcon } from "./icons.js";
4
+ const clock = (s) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
5
+ const when = (iso) => {
6
+ const d = new Date(iso);
7
+ return Number.isNaN(d.getTime()) ? "" : d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
8
+ };
9
+ const fileOf = (p) => (p ? p.split("/").pop() ?? p : "");
10
+ /** A drawing named for a person: its file name without the format's extensions. */
11
+ const drawingOf = (p) => fileOf(p).replace(/\.(smdf|erdf|sqdf|sysdf)\.json$/i, "").replace(/\.json$/i, "");
12
+ /** What a step lights, said briefly: the element's own name, or how many. */
13
+ function litOf(step) {
14
+ const names = step.spotlight?.length ? step.spotlight : step.focus ? [step.focus] : [];
15
+ // A message is known by its number on the drawing; everything else by its name.
16
+ const bare = names.map((n) => (n.startsWith("message:") ? `#${n.slice(8)}` : n.slice(n.indexOf(":") + 1)));
17
+ if (!bare.length)
18
+ return "";
19
+ return bare.length <= 2 ? bare.join(", ") : `${bare.slice(0, 2).join(", ")} +${bare.length - 2}`;
20
+ }
21
+ function presenceLine(who, presence, episode) {
22
+ if (!episode)
23
+ return { text: "Choose the episode you are speaking in.", away: true };
24
+ switch (presence?.state) {
25
+ case "listening":
26
+ return { text: `${who} is listening.`, away: false };
27
+ case "answering":
28
+ return { text: `${who} is answering${presence.takes?.length ? ` take ${presence.takes.join(", ")}` : ""}.`, away: false };
29
+ case "answered":
30
+ return { text: `${who} has answered and is getting ready to listen again.`, away: false };
31
+ default:
32
+ return { text: `Nobody is listening yet. A take waits in the episode until ${who} does.`, away: true };
33
+ }
34
+ }
35
+ const RECORD_LABEL = {
36
+ idle: "● Record",
37
+ starting: "Opening the mic…",
38
+ recording: "■ Stop & send",
39
+ sending: "Sending…",
40
+ retry: "Send again",
41
+ };
42
+ export function CompanionDock({ open, onOpenChange, who = "Mia", episode, episodes, onEpisode, presence, recorder, onRecord, items, unheard = [], playing = null, playingStep = null, onPlay, onStop, onFeedback, autoplay, onAutoplay, waiting, notice, error, theme, className, style, }) {
43
+ const live = recorder.state === "recording";
44
+ const busy = recorder.state === "starting" || recorder.state === "sending";
45
+ const fresh = unheard.length;
46
+ if (!open) {
47
+ return (_jsx("div", { className: `slc-talk${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: _jsxs("button", { type: "button", className: `slc-talk-fab${live ? " slc-talk-fab--live" : ""}${!live && playing ? " slc-talk-fab--speaking" : ""}`, onClick: () => (live ? onRecord() : onOpenChange(true)), "aria-label": live ? `Stop and send (${clock(recorder.seconds)})` : playing ? `${who} is speaking. Open the conversation` : `Talk with ${who}${fresh ? `, ${fresh} new` : ""}`, title: live ? "Stop and send your take" : playing ? `${who} is walking the diagram` : `Talk with ${who} about what is on the canvas`, children: [live ? _jsx("span", { className: "slc-talk-fab-clock", children: clock(recorder.seconds) }) : playing ? _jsx(SpeakerIcon, { size: 24 }) : _jsx(MicIcon, { size: 24 }), !live && fresh > 0 && _jsx("span", { className: "slc-talk-fab-badge", children: fresh })] }) }));
48
+ }
49
+ const line = presenceLine(who, presence, episode);
50
+ const newest = [...items].reverse();
51
+ return (_jsx("div", { className: `slc-talk slc-talk--open${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: _jsxs("section", { className: "slc-talk-panel", "aria-label": `Conversation with ${who}`, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("header", { className: "slc-talk-head", children: [_jsxs("span", { className: "slc-talk-title", children: [_jsx(MicIcon, {}), " Talk with ", who] }), _jsx("span", { className: `slc-talk-presence${line.away ? " slc-talk-presence--away" : ""}`, title: line.text }), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: () => onOpenChange(false), "aria-label": "Close the conversation", children: _jsx(CloseIcon, {}) })] }), episodes?.length && onEpisode ? (_jsxs("select", { className: "slc-stage-input slc-talk-episode", value: episode ?? "", onChange: (e) => onEpisode(e.target.value), disabled: live || busy, "aria-label": "The episode this conversation belongs to", children: [!episode && _jsx("option", { value: "", children: "Choose the episode\u2026" }), episodes.map((ep) => (_jsxs("option", { value: ep.path, children: [ep.number ? `${String(ep.number).padStart(3, "0")} · ` : "", ep.path.replace(/^\d{4}-\d{2}-\d{2}-episode-\d+-/, "")] }, ep.path)))] })) : (_jsx("div", { className: "slc-talk-meta", children: episode ?? "No episode chosen." })), _jsx("div", { className: `slc-talk-meta${line.away ? " slc-talk-meta--away" : ""}`, children: line.text }), _jsxs("button", { type: "button", className: `slc-talk-record${live ? " slc-talk-record--live" : ""}${recorder.state === "retry" ? " slc-talk-record--retry" : ""}`, onClick: onRecord, disabled: busy || !!recorder.unavailable || !episode, title: recorder.unavailable ? `Cannot record: ${recorder.unavailable}` : live ? "Stop and send your take" : "Speak to the episode, about what is on the canvas", children: [RECORD_LABEL[recorder.state], live && _jsx("span", { className: "slc-talk-clock", children: clock(recorder.seconds) })] }), recorder.unavailable && _jsxs("div", { className: "slc-talk-meta slc-talk-meta--error", children: ["Cannot record here: ", recorder.unavailable, "."] }), recorder.message && _jsx("div", { className: `slc-talk-meta${recorder.error ? " slc-talk-meta--error" : ""}`, children: recorder.message }), waiting && _jsxs("div", { className: "slc-talk-meta", children: ["Waiting for ", who, "\u2026 ", clock(waiting.seconds)] }), notice && _jsx("div", { className: "slc-talk-notice", children: notice }), error && _jsx("div", { className: "slc-talk-meta slc-talk-meta--error", children: error }), _jsxs("label", { className: "slc-talk-toggle", children: [_jsx("input", { type: "checkbox", checked: autoplay, onChange: (e) => onAutoplay(e.target.checked) }), "Play ", who, "'s replies on the diagram as they arrive"] }), _jsxs("ol", { className: "slc-talk-thread", children: [newest.length === 0 && _jsx("li", { className: "slc-stage-empty", children: "Nothing said in this episode yet. Look at a drawing, press Record, and speak." }), newest.map((item) => item.kind === "take" ? (_jsxs("li", { className: "slc-talk-entry slc-talk-entry--take", children: [_jsxs("div", { className: "slc-talk-who", children: [_jsx("strong", { children: "You" }), _jsxs("span", { children: ["take ", item.take, " \u00B7 ", when(item.at)] })] }), item.canvas?.doc && (_jsxs("div", { className: "slc-talk-canvas", children: ["on ", drawingOf(item.canvas.doc), item.canvas.focus ? ` · ${item.canvas.focus.slice(item.canvas.focus.indexOf(":") + 1)}` : "", item.canvas.step?.title ? ` · during “${item.canvas.step.title}”` : ""] })), _jsx("div", { className: "slc-talk-text", children: item.text || "(no transcript yet)" })] }, `t${item.take}`)) : (_jsxs("li", { className: `slc-talk-entry slc-talk-entry--reply${unheard.includes(item.id) ? " slc-talk-entry--new" : ""}`, children: [_jsxs("div", { className: "slc-talk-who", children: [_jsx("strong", { children: who }), _jsx("span", { children: when(item.at) }), (!item.unvoiced || (item.steps?.length ?? 0) > 0) &&
52
+ (playing === item.id ? (_jsx("button", { type: "button", className: "slc-stage-btn slc-talk-play slc-talk-play--on", onClick: onStop, "aria-label": "Stop", title: "Stop", children: _jsx(StopIcon, {}) })) : (_jsxs("button", { type: "button", className: "slc-stage-btn slc-talk-play", onClick: () => onPlay(item.id), disabled: live, title: item.unvoiced
53
+ ? `Walk the diagram with ${who}'s words (no voice)`
54
+ : item.steps?.length
55
+ ? `Hear ${who} walk the diagram (${item.steps.length} steps)`
56
+ : `Hear ${who}`, children: [_jsx(PlayIcon, {}), (item.steps?.length ?? 0) > 0 ? _jsxs("span", { children: ["Walk ", item.steps.length, " steps"] }) : null, unheard.includes(item.id) ? _jsx("span", { className: "slc-talk-new", children: "New" }) : null] }))), onFeedback && (_jsx("span", { className: "slc-talk-thumbs", children: ["up", "down"].map((v) => (_jsx("button", { type: "button", className: `slc-talk-thumb${item.feedback === v ? " slc-talk-thumb--on" : ""}`, onClick: () => onFeedback(item.id, item.feedback === v ? "" : v), "aria-label": v === "up" ? "This reply worked" : "This reply missed", children: v === "up" ? _jsx(ThumbUpIcon, { size: 15 }) : _jsx(ThumbDownIcon, { size: 15 }) }, v))) }))] }), (item.steps?.length ?? 0) > 0 ? (_jsx("ol", { className: "slc-talk-steps", "aria-label": `${who}'s walk through the diagram`, children: item.steps.map((step, i) => {
57
+ const here = playing === item.id && playingStep === i;
58
+ return (_jsx("li", { children: _jsxs("button", { type: "button", className: `slc-talk-step${here ? " slc-talk-step--here" : ""}`, onClick: () => onPlay(item.id, i), disabled: live, "aria-current": here ? "step" : undefined, title: `Walk from step ${i + 1}`, children: [_jsx("span", { className: "slc-talk-step-n", children: i + 1 }), _jsxs("span", { className: "slc-talk-step-body", children: [(step.title || step.doc) && (_jsxs("span", { className: "slc-talk-step-head", children: [step.title && _jsx("strong", { children: step.title }), (step.doc || litOf(step)) && (_jsx("span", { className: "slc-talk-step-where", children: [drawingOf(step.doc), litOf(step)].filter(Boolean).join(" · ") }))] })), _jsx("span", { className: "slc-talk-step-say", children: step.say })] })] }) }, i));
59
+ }) })) : (_jsx("div", { className: "slc-talk-text", children: item.text })), item.unvoiced && _jsx("div", { className: "slc-talk-meta", children: item.unvoiced })] }, `r${item.id}`)))] })] }) }));
60
+ }
61
+ export default CompanionDock;
62
+ //# sourceMappingURL=CompanionDock.js.map
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The cards a person writes and reads marks in (Spec 83).
3
+ *
4
+ * - `<MarkComposer>`: what was pointed at, and a box to say something about
5
+ * it — typed, or spoken when the host hands it something that listens.
6
+ * - `<MarkThread>`: one mark and its replies; reply, resolve, reopen, remove.
7
+ * - `<MarksPanel>`: every mark on the drawing, waiting ones first, and the
8
+ * button that copies them as a review for an agent.
9
+ *
10
+ * Props in, callbacks out, as the canvases: the host writes the sidecar and
11
+ * tells the hub. The listener is any object shaped like
12
+ * `@miadi/stateloom-react`'s `browserDictation()`, so this package needs no
13
+ * socket and no speech code of its own.
14
+ */
15
+ import { type CSSProperties } from "react";
16
+ import { type Box, type Mark, type MarkKind } from "@miadi/stateloom-protocol";
17
+ import { type CanvasTheme } from "./theme.js";
18
+ /** Something that turns speech into words (`browserDictation()`). */
19
+ export interface ListenerLike {
20
+ start(onText: (text: string, final: boolean) => void, onEnd?: (error?: string) => void): void;
21
+ stop(): void;
22
+ }
23
+ export interface MarkComposerProps {
24
+ elements: readonly string[];
25
+ region?: Box;
26
+ /** The name marks are signed with. Empty: the composer asks for one. */
27
+ author: string;
28
+ onAuthorChange?: (name: string) => void;
29
+ /** `author` is the name the mark is signed with: the one given, or the one typed here. */
30
+ onSubmit: (mark: {
31
+ text: string;
32
+ kind: MarkKind;
33
+ author: string;
34
+ }) => void;
35
+ onCancel: () => void;
36
+ listener?: ListenerLike | null;
37
+ /** Start listening as soon as it opens (the person pressed Answer by voice). */
38
+ listenAtOnce?: boolean;
39
+ busy?: boolean;
40
+ error?: string | null;
41
+ placeholder?: string;
42
+ theme?: Partial<CanvasTheme>;
43
+ className?: string;
44
+ style?: CSSProperties;
45
+ }
46
+ export declare function MarkComposer({ elements, region, author, onAuthorChange, onSubmit, onCancel, listener, listenAtOnce, busy, error, placeholder, theme, className, style, }: MarkComposerProps): import("react").JSX.Element;
47
+ export interface MarkThreadProps {
48
+ mark: Mark;
49
+ /** Its number on the board. */
50
+ number?: number;
51
+ onReply?: (text: string) => void;
52
+ onResolve?: () => void;
53
+ onReopen?: () => void;
54
+ onRemove?: () => void;
55
+ onClose: () => void;
56
+ listener?: ListenerLike | null;
57
+ busy?: boolean;
58
+ error?: string | null;
59
+ theme?: Partial<CanvasTheme>;
60
+ className?: string;
61
+ style?: CSSProperties;
62
+ }
63
+ export declare function MarkThread({ mark, number, onReply, onResolve, onReopen, onRemove, onClose, listener, busy, error, theme, className, style, }: MarkThreadProps): import("react").JSX.Element;
64
+ export interface MarksPanelProps {
65
+ marks: readonly Mark[];
66
+ selected?: string | null;
67
+ onSelect: (id: string) => void;
68
+ /** Copy the waiting marks as a review an agent reads. */
69
+ onCopy?: () => void;
70
+ copied?: boolean;
71
+ onClose?: () => void;
72
+ theme?: Partial<CanvasTheme>;
73
+ className?: string;
74
+ style?: CSSProperties;
75
+ }
76
+ export declare function MarksPanel({ marks, selected, onSelect, onCopy, copied, onClose, theme, className, style }: MarksPanelProps): import("react").JSX.Element;
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The cards a person writes and reads marks in (Spec 83).
4
+ *
5
+ * - `<MarkComposer>`: what was pointed at, and a box to say something about
6
+ * it — typed, or spoken when the host hands it something that listens.
7
+ * - `<MarkThread>`: one mark and its replies; reply, resolve, reopen, remove.
8
+ * - `<MarksPanel>`: every mark on the drawing, waiting ones first, and the
9
+ * button that copies them as a review for an agent.
10
+ *
11
+ * Props in, callbacks out, as the canvases: the host writes the sidecar and
12
+ * tells the hub. The listener is any object shaped like
13
+ * `@miadi/stateloom-react`'s `browserDictation()`, so this package needs no
14
+ * socket and no speech code of its own.
15
+ */
16
+ import { useEffect, useRef, useState } from "react";
17
+ import { MARK_KINDS, markAnchorText } from "@miadi/stateloom-protocol";
18
+ import { themeStyle } from "./theme.js";
19
+ import { CloseIcon, MicIcon } from "./icons.js";
20
+ const KIND_LABEL = {
21
+ comment: "Comment",
22
+ question: "Question",
23
+ looks_good: "Looks good",
24
+ delete: "Should go",
25
+ };
26
+ function useListening(listener, onText) {
27
+ const [listening, setListening] = useState(false);
28
+ const base = useRef("");
29
+ useEffect(() => () => listener?.stop(), [listener]);
30
+ const toggle = (current) => {
31
+ if (!listener)
32
+ return;
33
+ if (listening) {
34
+ listener.stop();
35
+ setListening(false);
36
+ return;
37
+ }
38
+ base.current = current ? `${current.trimEnd()} ` : "";
39
+ setListening(true);
40
+ listener.start((heard) => onText(base.current + heard), () => setListening(false));
41
+ };
42
+ return { listening, toggle };
43
+ }
44
+ function Anchor({ elements, region }) {
45
+ if (!elements?.length && !region)
46
+ return _jsx("span", { className: "slc-stage-chip slc-stage-chip--quiet", children: "the drawing" });
47
+ return (_jsxs(_Fragment, { children: [elements?.map((e) => (_jsx("span", { className: "slc-stage-chip", children: e }, e))), region && !elements?.length && _jsx("span", { className: "slc-stage-chip slc-stage-chip--quiet", children: "an area" })] }));
48
+ }
49
+ export function MarkComposer({ elements, region, author, onAuthorChange, onSubmit, onCancel, listener, listenAtOnce = false, busy = false, error, placeholder = "What should the agent know about this?", theme, className, style, }) {
50
+ const [text, setText] = useState("");
51
+ const [kind, setKind] = useState("comment");
52
+ const [name, setName] = useState(author);
53
+ const { listening, toggle } = useListening(listener, setText);
54
+ const area = useRef(null);
55
+ useEffect(() => {
56
+ if (listenAtOnce && listener)
57
+ toggle("");
58
+ else
59
+ area.current?.focus();
60
+ // Once, when the composer opens.
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ }, []);
63
+ const submit = (e) => {
64
+ e?.preventDefault();
65
+ if (!text.trim() || busy)
66
+ return;
67
+ if (listening)
68
+ listener?.stop();
69
+ const signed = author || name.trim();
70
+ if (!author && signed)
71
+ onAuthorChange?.(signed);
72
+ onSubmit({ text: text.trim(), kind, author: signed });
73
+ };
74
+ return (_jsxs("form", { className: `slc-stage-card slc-stage-composer${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onSubmit: submit, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-anchor", children: [_jsx("span", { className: "slc-stage-card-label", children: "On" }), _jsx(Anchor, { elements: elements, region: region })] }), _jsx("textarea", { ref: area, className: "slc-stage-input slc-stage-textarea", value: text, placeholder: listening ? "Listening…" : placeholder, onChange: (e) => setText(e.target.value), onKeyDown: (e) => {
75
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey))
76
+ submit();
77
+ if (e.key === "Escape")
78
+ onCancel();
79
+ }, rows: 3 }), !author && (_jsx("input", { className: "slc-stage-input", value: name, placeholder: "Your name (signs your marks)", onChange: (e) => setName(e.target.value) })), _jsxs("div", { className: "slc-stage-card-row", children: [_jsx("select", { className: "slc-stage-input slc-stage-select", value: kind, onChange: (e) => setKind(e.target.value), "aria-label": "Kind of mark", children: MARK_KINDS.map((k) => (_jsx("option", { value: k, children: KIND_LABEL[k] }, k))) }), listener && (_jsx("button", { type: "button", className: `slc-stage-btn${listening ? " slc-stage-btn--live" : ""}`, onClick: () => toggle(text), "aria-pressed": listening, title: listening ? "Stop listening" : "Speak instead of typing", children: _jsx(MicIcon, {}) })), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onCancel, children: "Cancel" }), _jsx("button", { type: "submit", className: "slc-stage-btn slc-stage-btn--main", disabled: !text.trim() || busy || (!author && !name.trim()), children: busy ? "Saving…" : "Mark" })] }), error && _jsx("div", { className: "slc-stage-card-error", children: error })] }));
80
+ }
81
+ export function MarkThread({ mark, number, onReply, onResolve, onReopen, onRemove, onClose, listener, busy = false, error, theme, className, style, }) {
82
+ const [reply, setReply] = useState("");
83
+ const { listening, toggle } = useListening(listener, setReply);
84
+ const send = (e) => {
85
+ e?.preventDefault();
86
+ if (!reply.trim() || busy)
87
+ return;
88
+ if (listening)
89
+ listener?.stop();
90
+ onReply?.(reply.trim());
91
+ setReply("");
92
+ };
93
+ return (_jsxs("div", { className: `slc-stage-card slc-stage-thread${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-row", children: [number !== undefined && _jsx("span", { className: `slc-stage-pin slc-stage-pin--inline slc-stage-pin--${mark.status === "resolved" ? "resolved" : mark.status}`, children: number }), _jsxs("span", { className: "slc-stage-card-label", children: [KIND_LABEL[mark.kind], " \u00B7 ", mark.status] }), _jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "slc-stage-card-anchor", children: _jsx(Anchor, { elements: mark.elements, region: mark.region }) }), _jsxs("ol", { className: "slc-stage-thread-list", children: [_jsxs("li", { className: `slc-stage-said slc-stage-said--${mark.author.role}`, children: [_jsx("span", { className: "slc-stage-said-who", children: mark.author.name }), _jsx("span", { className: "slc-stage-said-text", children: mark.text })] }), (mark.replies ?? []).map((r, i) => (_jsxs("li", { className: `slc-stage-said slc-stage-said--${r.author.role}`, children: [_jsx("span", { className: "slc-stage-said-who", children: r.author.name }), _jsx("span", { className: "slc-stage-said-text", children: r.text })] }, i)))] }), onReply && (_jsxs("form", { className: "slc-stage-card-row", onSubmit: send, children: [_jsx("input", { className: "slc-stage-input slc-stage-grow", value: reply, placeholder: listening ? "Listening…" : "Reply…", onChange: (e) => setReply(e.target.value) }), listener && (_jsx("button", { type: "button", className: `slc-stage-btn${listening ? " slc-stage-btn--live" : ""}`, onClick: () => toggle(reply), "aria-pressed": listening, title: "Speak the reply", children: _jsx(MicIcon, {}) })), _jsx("button", { type: "submit", className: "slc-stage-btn slc-stage-btn--main", disabled: !reply.trim() || busy, children: "Reply" })] })), _jsxs("div", { className: "slc-stage-card-row", children: [mark.status === "resolved"
94
+ ? onReopen && (_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onReopen, children: "Reopen" }))
95
+ : onResolve && (_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onResolve, children: "Resolve" })), _jsx("span", { className: "slc-stage-spacer" }), onRemove && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--danger", onClick: onRemove, children: "Remove" }))] }), error && _jsx("div", { className: "slc-stage-card-error", children: error })] }));
96
+ }
97
+ export function MarksPanel({ marks, selected, onSelect, onCopy, copied, onClose, theme, className, style }) {
98
+ const [all, setAll] = useState(false);
99
+ const numbered = marks.map((m, i) => ({ m, n: i + 1 }));
100
+ const shown = all ? numbered : numbered.filter(({ m }) => m.status !== "resolved");
101
+ const open = marks.filter((m) => m.status !== "resolved").length;
102
+ return (_jsxs("div", { className: `slc-stage-card slc-stage-panel${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, onPointerDown: (e) => e.stopPropagation(), children: [_jsxs("div", { className: "slc-stage-card-row", children: [_jsx("span", { className: "slc-stage-card-label", children: "Marks on this drawing" }), _jsx("span", { className: "slc-stage-spacer" }), _jsxs("span", { className: "slc-stage-segment", role: "group", "aria-label": "Which marks to list", children: [_jsxs("button", { type: "button", className: `slc-stage-segment-btn${all ? "" : " slc-stage-segment-btn--on"}`, "aria-pressed": !all, onClick: () => setAll(false), children: ["Open ", open] }), _jsxs("button", { type: "button", className: `slc-stage-segment-btn${all ? " slc-stage-segment-btn--on" : ""}`, "aria-pressed": all, onClick: () => setAll(true), children: ["All ", marks.length] })] }), onClose && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", children: _jsx(CloseIcon, {}) }))] }), shown.length === 0 && _jsx("div", { className: "slc-stage-empty", children: marks.length ? "Every mark is resolved." : "No marks yet. Turn on marking (✎) and tap or draw around what you mean." }), _jsx("ul", { className: "slc-stage-panel-list", children: shown.map(({ m, n }) => (_jsx("li", { children: _jsxs("button", { type: "button", className: `slc-stage-panel-item${m.id === selected ? " slc-stage-panel-item--selected" : ""}`, onClick: () => onSelect(m.id), children: [_jsx("span", { className: `slc-stage-pin slc-stage-pin--inline slc-stage-pin--${m.status === "resolved" ? "resolved" : m.author.role === "agent" && m.status === "open" ? "question" : m.status}`, children: n }), _jsxs("span", { className: "slc-stage-panel-text", children: [_jsx("span", { className: "slc-stage-panel-said", children: m.text }), _jsxs("span", { className: "slc-stage-panel-meta", children: [m.author.name, " \u00B7 ", markAnchorText(m), m.replies?.length ? ` · ${m.replies.length} repl${m.replies.length === 1 ? "y" : "ies"}` : ""] })] })] }) }, m.id))) }), onCopy && (_jsxs("div", { className: "slc-stage-card-row", children: [_jsx("span", { className: "slc-stage-spacer" }), _jsx("button", { type: "button", className: "slc-stage-btn", onClick: onCopy, title: "Copy what is on screen and the waiting marks, to paste into any agent", children: copied ? "Copied" : "Copy for the agent" })] }))] }));
103
+ }
104
+ //# sourceMappingURL=MarkCards.js.map
@@ -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;