@miadi/stateloom-canvas 0.1.5 → 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.
- package/dist/CompanionDock.d.ts +101 -0
- package/dist/CompanionDock.js +62 -0
- package/dist/MarkCards.d.ts +76 -0
- package/dist/MarkCards.js +104 -0
- package/dist/StageCaption.d.ts +39 -0
- package/dist/StageCaption.js +15 -0
- package/dist/StageOverlay.d.ts +54 -0
- package/dist/StageOverlay.js +121 -0
- package/dist/icons.d.ts +28 -0
- package/dist/icons.js +46 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +10 -1
- package/dist/styles.css +617 -0
- package/package.json +2 -2
|
@@ -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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words of the step on stage, and the buttons that move a tour (Spec 83).
|
|
3
|
+
*
|
|
4
|
+
* A card over the bottom of the board: who is presenting, the tour and the
|
|
5
|
+
* step's title, what the agent says, where the tour stands. The controls are
|
|
6
|
+
* the person's: back, play or pause, forward, the voice on or off, answer
|
|
7
|
+
* (the host opens a mark on what is lit), close. Nothing here plays anything;
|
|
8
|
+
* the buttons call the host, which holds the stage session.
|
|
9
|
+
*/
|
|
10
|
+
import type { CSSProperties } from "react";
|
|
11
|
+
import type { TourStep } from "@miadi/stateloom-protocol";
|
|
12
|
+
import { type CanvasTheme } from "./theme.js";
|
|
13
|
+
export interface StageCaptionProps {
|
|
14
|
+
shown: {
|
|
15
|
+
step: TourStep;
|
|
16
|
+
index: number | null;
|
|
17
|
+
count: number | null;
|
|
18
|
+
title?: string;
|
|
19
|
+
origin?: string;
|
|
20
|
+
} | null;
|
|
21
|
+
playing?: boolean;
|
|
22
|
+
speaking?: boolean;
|
|
23
|
+
/** The canvas's voice is on. Absent: no voice button. */
|
|
24
|
+
voice?: boolean;
|
|
25
|
+
onToggleVoice?: () => void;
|
|
26
|
+
onPlay?: () => void;
|
|
27
|
+
onPause?: () => void;
|
|
28
|
+
onNext?: () => void;
|
|
29
|
+
onPrev?: () => void;
|
|
30
|
+
onGoto?: (index: number) => void;
|
|
31
|
+
onClose?: () => void;
|
|
32
|
+
/** Answer what is lit: the host opens a mark on it. Absent: no answer button. */
|
|
33
|
+
onAnswer?: () => void;
|
|
34
|
+
theme?: Partial<CanvasTheme>;
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: CSSProperties;
|
|
37
|
+
}
|
|
38
|
+
export declare function StageCaption({ shown, playing, speaking, voice, onToggleVoice, onPlay, onPause, onNext, onPrev, onGoto, onClose, onAnswer, theme, className, style, }: StageCaptionProps): import("react").JSX.Element | null;
|
|
39
|
+
export default StageCaption;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { themeStyle } from "./theme.js";
|
|
3
|
+
import { CloseIcon, NextIcon, PauseIcon, PlayIcon, PrevIcon, SpeakerIcon, SpeakerOffIcon } from "./icons.js";
|
|
4
|
+
/** Past this many steps the dots give way to the count alone. */
|
|
5
|
+
const MAX_DOTS = 24;
|
|
6
|
+
export function StageCaption({ shown, playing = false, speaking = false, voice, onToggleVoice, onPlay, onPause, onNext, onPrev, onGoto, onClose, onAnswer, theme, className, style, }) {
|
|
7
|
+
if (!shown)
|
|
8
|
+
return null;
|
|
9
|
+
const { step, index, count, title, origin } = shown;
|
|
10
|
+
const inTour = index !== null && count !== null;
|
|
11
|
+
const heading = [title, step.title].filter(Boolean).join(" · ");
|
|
12
|
+
return (_jsxs("section", { className: `slc-stage-caption${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, role: "region", "aria-label": "What the agent is showing", "aria-live": "polite", children: [_jsxs("header", { className: "slc-stage-caption-head", children: [origin && _jsx("span", { className: "slc-stage-caption-origin", children: origin }), heading && _jsx("span", { className: "slc-stage-caption-title", children: heading }), inTour && (_jsxs("span", { className: "slc-stage-caption-count", children: [index + 1, " / ", count] })), speaking && _jsx("span", { className: "slc-stage-caption-speaking", "aria-label": "speaking" }), onClose && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--quiet", onClick: onClose, "aria-label": "Close", title: "Close", children: _jsx(CloseIcon, {}) }))] }), _jsx("p", { className: "slc-stage-caption-say", children: step.say }), inTour && count <= MAX_DOTS && count > 1 && (_jsx("nav", { className: "slc-stage-dots", "aria-label": "Steps", children: Array.from({ length: count }, (_, i) => (_jsx("button", { type: "button", className: `slc-stage-dot${i === index ? " slc-stage-dot--current" : i < index ? " slc-stage-dot--seen" : ""}`, onClick: () => onGoto?.(i), "aria-label": `Step ${i + 1}`, "aria-current": i === index ? "step" : undefined }, i))) })), _jsxs("footer", { className: "slc-stage-caption-controls", children: [inTour && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "slc-stage-btn", onClick: onPrev, disabled: index === 0, "aria-label": "Previous step", title: "Previous step", children: _jsx(PrevIcon, {}) }), playing ? (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--main", onClick: onPause, "aria-label": "Pause", title: "Pause", children: _jsx(PauseIcon, {}) })) : (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--main", onClick: onPlay, "aria-label": "Play", title: "Play", children: _jsx(PlayIcon, {}) })), _jsx("button", { type: "button", className: "slc-stage-btn", onClick: onNext, disabled: index === count - 1, "aria-label": "Next step", title: "Next step", children: _jsx(NextIcon, {}) })] })), _jsx("span", { className: "slc-stage-spacer" }), voice !== undefined && (_jsx("button", { type: "button", className: `slc-stage-btn${voice ? " slc-stage-btn--on" : ""}`, onClick: onToggleVoice, "aria-pressed": voice, title: voice ? "Voice on — the steps are read aloud" : "Voice off — the steps are read on screen", children: voice ? _jsx(SpeakerIcon, {}) : _jsx(SpeakerOffIcon, {}) })), onAnswer && (_jsx("button", { type: "button", className: "slc-stage-btn slc-stage-btn--answer", onClick: onAnswer, title: "Answer \u2014 mark what is lit and say something about it", children: "Answer" }))] })] }));
|
|
13
|
+
}
|
|
14
|
+
export default StageCaption;
|
|
15
|
+
//# sourceMappingURL=StageCaption.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stage's layer over a canvas (Spec 83) — any of the three boards, or any
|
|
3
|
+
* host's board that shares a viewport.
|
|
4
|
+
*
|
|
5
|
+
* It never reaches into the canvas under it. It is told the viewport and where
|
|
6
|
+
* the elements are (`machineElementBoxes`, `erdElementBoxes`,
|
|
7
|
+
* `sequenceElementBoxes` from the protocol), and from those alone it:
|
|
8
|
+
*
|
|
9
|
+
* - **lights** what an agent points at: the rest of the drawing dims behind a
|
|
10
|
+
* scrim with a hole around each spotlighted element, and each hole is ringed;
|
|
11
|
+
* - **frames** an area the agent names;
|
|
12
|
+
* - **pins** each mark at what it points at, numbered, coloured by whether it
|
|
13
|
+
* waits (open), was answered, or is done — a tap opens its thread;
|
|
14
|
+
* - **takes a mark** when the host turns marking on: a tap names the element
|
|
15
|
+
* under it, a drag names the elements inside the area drawn (and the area).
|
|
16
|
+
*
|
|
17
|
+
* Positioned over the canvas by the host (both in one `position: relative`
|
|
18
|
+
* box); it lets every pointer through to the canvas except on its pins and
|
|
19
|
+
* while marking.
|
|
20
|
+
*/
|
|
21
|
+
import { type CSSProperties } from "react";
|
|
22
|
+
import { type Box, type ElementBox, type Mark, type Viewport } from "@miadi/stateloom-protocol";
|
|
23
|
+
import { type CanvasTheme } from "./theme.js";
|
|
24
|
+
/** What a person pointed at while marking, before they say anything about it. */
|
|
25
|
+
export interface MarkDraft {
|
|
26
|
+
elements: string[];
|
|
27
|
+
region?: Box;
|
|
28
|
+
}
|
|
29
|
+
export interface StageOverlayProps {
|
|
30
|
+
viewport: Viewport;
|
|
31
|
+
/** Where the drawn elements are, in the drawing's coordinates. */
|
|
32
|
+
boxes: readonly ElementBox[];
|
|
33
|
+
/** Elements to light; the rest dims. */
|
|
34
|
+
spotlight?: readonly string[];
|
|
35
|
+
/** An area to frame. */
|
|
36
|
+
region?: Box | null;
|
|
37
|
+
marks?: readonly Mark[];
|
|
38
|
+
selectedMark?: string | null;
|
|
39
|
+
onSelectMark?: (id: string) => void;
|
|
40
|
+
/** Resolved marks keep no pin. Default true. */
|
|
41
|
+
hideResolved?: boolean;
|
|
42
|
+
/** Take the next tap or drag as a mark. */
|
|
43
|
+
marking?: boolean;
|
|
44
|
+
onDraft?: (draft: MarkDraft) => void;
|
|
45
|
+
/** A mark being written: its elements ringed, its area framed. */
|
|
46
|
+
draft?: MarkDraft | null;
|
|
47
|
+
theme?: Partial<CanvasTheme>;
|
|
48
|
+
className?: string;
|
|
49
|
+
style?: CSSProperties;
|
|
50
|
+
}
|
|
51
|
+
/** Where a mark sits: its elements that are drawn here, else its area. */
|
|
52
|
+
export declare function markAnchor(mark: Pick<Mark, "elements" | "region">, boxes: readonly ElementBox[]): Box | null;
|
|
53
|
+
export declare function StageOverlay({ viewport, boxes, spotlight, region, marks, selectedMark, onSelectMark, hideResolved, marking, onDraft, draft, theme, className, style, }: StageOverlayProps): import("react").JSX.Element;
|
|
54
|
+
export default StageOverlay;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The stage's layer over a canvas (Spec 83) — any of the three boards, or any
|
|
4
|
+
* host's board that shares a viewport.
|
|
5
|
+
*
|
|
6
|
+
* It never reaches into the canvas under it. It is told the viewport and where
|
|
7
|
+
* the elements are (`machineElementBoxes`, `erdElementBoxes`,
|
|
8
|
+
* `sequenceElementBoxes` from the protocol), and from those alone it:
|
|
9
|
+
*
|
|
10
|
+
* - **lights** what an agent points at: the rest of the drawing dims behind a
|
|
11
|
+
* scrim with a hole around each spotlighted element, and each hole is ringed;
|
|
12
|
+
* - **frames** an area the agent names;
|
|
13
|
+
* - **pins** each mark at what it points at, numbered, coloured by whether it
|
|
14
|
+
* waits (open), was answered, or is done — a tap opens its thread;
|
|
15
|
+
* - **takes a mark** when the host turns marking on: a tap names the element
|
|
16
|
+
* under it, a drag names the elements inside the area drawn (and the area).
|
|
17
|
+
*
|
|
18
|
+
* Positioned over the canvas by the host (both in one `position: relative`
|
|
19
|
+
* box); it lets every pointer through to the canvas except on its pins and
|
|
20
|
+
* while marking.
|
|
21
|
+
*/
|
|
22
|
+
import { useId, useMemo, useRef, useState } from "react";
|
|
23
|
+
import { boxesOf, elementAt, elementsInRegion, padBox, screenToWorld, unionBox, viewportTransform, worldToScreen, } from "@miadi/stateloom-protocol";
|
|
24
|
+
import { themeStyle } from "./theme.js";
|
|
25
|
+
/** Below this many screen pixels a press is a tap, not an area. */
|
|
26
|
+
const DRAG_THRESHOLD = 6;
|
|
27
|
+
/** A tap on empty board marks a square this many screen pixels wide around it. */
|
|
28
|
+
const TAP_AREA = 56;
|
|
29
|
+
const HOLE_PAD = 8;
|
|
30
|
+
/** Where a mark sits: its elements that are drawn here, else its area. */
|
|
31
|
+
export function markAnchor(mark, boxes) {
|
|
32
|
+
const drawn = mark.elements?.length ? boxesOf(boxes, mark.elements) : [];
|
|
33
|
+
return unionBox(drawn) ?? mark.region ?? null;
|
|
34
|
+
}
|
|
35
|
+
function pinTone(mark) {
|
|
36
|
+
if (mark.status === "resolved")
|
|
37
|
+
return "resolved";
|
|
38
|
+
if (mark.author.role === "agent")
|
|
39
|
+
return mark.status === "answered" ? "answered" : "question";
|
|
40
|
+
return mark.status === "answered" ? "answered" : "open";
|
|
41
|
+
}
|
|
42
|
+
export function StageOverlay({ viewport, boxes, spotlight, region, marks, selectedMark = null, onSelectMark, hideResolved = true, marking = false, onDraft, draft = null, theme, className, style, }) {
|
|
43
|
+
const maskId = `slc-stage-mask-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
44
|
+
const rootRef = useRef(null);
|
|
45
|
+
const press = useRef(null);
|
|
46
|
+
const [drag, setDrag] = useState(null);
|
|
47
|
+
const holes = useMemo(() => (spotlight?.length ? boxesOf(boxes, spotlight).map((b) => padBox(b, HOLE_PAD)) : []), [boxes, spotlight]);
|
|
48
|
+
const vt = viewportTransform(viewport);
|
|
49
|
+
const selected = marks?.find((m) => m.id === selectedMark) ?? null;
|
|
50
|
+
const ringed = useMemo(() => {
|
|
51
|
+
const out = [];
|
|
52
|
+
if (selected?.elements?.length)
|
|
53
|
+
out.push(...boxesOf(boxes, selected.elements));
|
|
54
|
+
if (draft?.elements.length)
|
|
55
|
+
out.push(...boxesOf(boxes, draft.elements));
|
|
56
|
+
return out.map((b) => padBox(b, 4));
|
|
57
|
+
}, [boxes, selected, draft]);
|
|
58
|
+
const framed = [selected?.region, draft?.region].filter((b) => !!b);
|
|
59
|
+
const pins = (marks ?? [])
|
|
60
|
+
.map((m, i) => ({ mark: m, n: i + 1 }))
|
|
61
|
+
.filter(({ mark }) => !(hideResolved && mark.status === "resolved" && mark.id !== selectedMark))
|
|
62
|
+
.map(({ mark, n }) => {
|
|
63
|
+
const at = markAnchor(mark, boxes);
|
|
64
|
+
if (!at)
|
|
65
|
+
return null;
|
|
66
|
+
const p = worldToScreen(viewport, { x: at.x + at.width, y: at.y });
|
|
67
|
+
return { mark, n, x: p.x, y: p.y };
|
|
68
|
+
})
|
|
69
|
+
.filter((p) => p !== null);
|
|
70
|
+
const local = (e) => {
|
|
71
|
+
const r = rootRef.current?.getBoundingClientRect();
|
|
72
|
+
return { x: e.clientX - (r?.left ?? 0), y: e.clientY - (r?.top ?? 0) };
|
|
73
|
+
};
|
|
74
|
+
const onDown = (e) => {
|
|
75
|
+
if (e.button !== 0 && e.pointerType === "mouse")
|
|
76
|
+
return;
|
|
77
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
78
|
+
const p = local(e);
|
|
79
|
+
press.current = { id: e.pointerId, x: p.x, y: p.y, moved: false };
|
|
80
|
+
};
|
|
81
|
+
const onMove = (e) => {
|
|
82
|
+
const s = press.current;
|
|
83
|
+
if (!s || s.id !== e.pointerId)
|
|
84
|
+
return;
|
|
85
|
+
const p = local(e);
|
|
86
|
+
if (!s.moved && Math.hypot(p.x - s.x, p.y - s.y) < DRAG_THRESHOLD)
|
|
87
|
+
return;
|
|
88
|
+
s.moved = true;
|
|
89
|
+
setDrag({ x: Math.min(s.x, p.x), y: Math.min(s.y, p.y), w: Math.abs(p.x - s.x), h: Math.abs(p.y - s.y) });
|
|
90
|
+
};
|
|
91
|
+
const onUp = (e) => {
|
|
92
|
+
const s = press.current;
|
|
93
|
+
if (!s || s.id !== e.pointerId)
|
|
94
|
+
return;
|
|
95
|
+
press.current = null;
|
|
96
|
+
setDrag(null);
|
|
97
|
+
const p = local(e);
|
|
98
|
+
if (s.moved) {
|
|
99
|
+
const a = screenToWorld(viewport, { x: Math.min(s.x, p.x), y: Math.min(s.y, p.y) });
|
|
100
|
+
const b = screenToWorld(viewport, { x: Math.max(s.x, p.x), y: Math.max(s.y, p.y) });
|
|
101
|
+
const area = { x: a.x, y: a.y, width: Math.max(1, b.x - a.x), height: Math.max(1, b.y - a.y) };
|
|
102
|
+
onDraft?.({ elements: elementsInRegion(boxes, area), region: area });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const w = screenToWorld(viewport, p);
|
|
106
|
+
const hit = elementAt(boxes, w.x, w.y);
|
|
107
|
+
if (hit)
|
|
108
|
+
return onDraft?.({ elements: [hit] });
|
|
109
|
+
const half = TAP_AREA / 2 / (viewport.scale || 1);
|
|
110
|
+
onDraft?.({ elements: [], region: { x: w.x - half, y: w.y - half, width: half * 2, height: half * 2 } });
|
|
111
|
+
};
|
|
112
|
+
return (_jsxs("div", { ref: rootRef, className: `slc-stage${marking ? " slc-stage--marking" : ""}${className ? ` ${className}` : ""}`, style: { ...themeStyle(theme), ...style }, children: [_jsxs("svg", { className: "slc-stage-svg", "aria-hidden": "true", children: [holes.length > 0 && (_jsxs(_Fragment, { children: [_jsx("defs", { children: _jsxs("mask", { id: maskId, maskUnits: "userSpaceOnUse", x: "0", y: "0", width: "100%", height: "100%", children: [_jsx("rect", { x: "0", y: "0", width: "100%", height: "100%", fill: "white" }), _jsx("g", { transform: vt, children: holes.map((b, i) => (_jsx("rect", { x: b.x, y: b.y, width: b.width, height: b.height, rx: 10, fill: "black" }, i))) })] }) }), _jsx("rect", { x: "0", y: "0", width: "100%", height: "100%", className: "slc-stage-scrim", mask: `url(#${maskId})` }), _jsx("g", { transform: vt, children: holes.map((b, i) => (_jsx("rect", { x: b.x, y: b.y, width: b.width, height: b.height, rx: 10, className: "slc-stage-ring", vectorEffect: "non-scaling-stroke" }, i))) })] })), _jsxs("g", { transform: vt, children: [region && (_jsx("rect", { x: region.x, y: region.y, width: region.width, height: region.height, rx: 6, className: "slc-stage-region", vectorEffect: "non-scaling-stroke" })), ringed.map((b, i) => (_jsx("rect", { x: b.x, y: b.y, width: b.width, height: b.height, rx: 8, className: "slc-stage-mark-ring", vectorEffect: "non-scaling-stroke" }, `r${i}`))), framed.map((b, i) => (_jsx("rect", { x: b.x, y: b.y, width: b.width, height: b.height, rx: 4, className: "slc-stage-mark-area", vectorEffect: "non-scaling-stroke" }, `f${i}`)))] }), drag && _jsx("rect", { x: drag.x, y: drag.y, width: drag.w, height: drag.h, rx: 4, className: "slc-stage-drag" })] }), pins.map(({ mark, n, x, y }) => (_jsxs("button", { type: "button", className: `slc-stage-pin slc-stage-pin--${pinTone(mark)}${mark.id === selectedMark ? " slc-stage-pin--selected" : ""}`, style: { left: x, top: y }, title: `${mark.author.name}: ${mark.text}${mark.replies?.length ? ` (${mark.replies.length} repl${mark.replies.length === 1 ? "y" : "ies"})` : ""}`, "aria-label": `Mark ${n}, ${mark.status}: ${mark.text}`, onPointerDown: (e) => e.stopPropagation(), onClick: (e) => {
|
|
113
|
+
e.stopPropagation();
|
|
114
|
+
onSelectMark?.(mark.id);
|
|
115
|
+
}, children: [n, (mark.replies?.length ?? 0) > 0 && _jsx("span", { className: "slc-stage-pin-count", children: mark.replies.length })] }, mark.id))), marking && (_jsx("div", { className: "slc-stage-catch", onPointerDown: onDown, onPointerMove: onMove, onPointerUp: onUp, onPointerCancel: () => {
|
|
116
|
+
press.current = null;
|
|
117
|
+
setDrag(null);
|
|
118
|
+
} }))] }));
|
|
119
|
+
}
|
|
120
|
+
export default StageOverlay;
|
|
121
|
+
//# sourceMappingURL=StageOverlay.js.map
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stage's icons, drawn: outlines in the current colour.
|
|
3
|
+
*
|
|
4
|
+
* Typed symbols such as 🎙, 🔊, 💬, 👍 and even ▶ render as colour emoji on iOS,
|
|
5
|
+
* saturated and larger than the text around them. The person these designers are
|
|
6
|
+
* built with works on an iPhone and is visually sensitive, so every icon in the
|
|
7
|
+
* stage's chrome is a line drawing that takes the button's own colour and size.
|
|
8
|
+
*/
|
|
9
|
+
import type { SVGProps } from "react";
|
|
10
|
+
type IconProps = Omit<SVGProps<SVGSVGElement>, "children"> & {
|
|
11
|
+
size?: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function MicIcon(p: IconProps): import("react").JSX.Element;
|
|
14
|
+
export declare function SpeakerIcon(p: IconProps): import("react").JSX.Element;
|
|
15
|
+
export declare function SpeakerOffIcon(p: IconProps): import("react").JSX.Element;
|
|
16
|
+
/** A speech bubble: the marks on a drawing, what people said about it. */
|
|
17
|
+
export declare function MarksIcon(p: IconProps): import("react").JSX.Element;
|
|
18
|
+
export declare function PlayIcon(p: IconProps): import("react").JSX.Element;
|
|
19
|
+
export declare function PauseIcon(p: IconProps): import("react").JSX.Element;
|
|
20
|
+
export declare function StopIcon(p: IconProps): import("react").JSX.Element;
|
|
21
|
+
export declare function PrevIcon(p: IconProps): import("react").JSX.Element;
|
|
22
|
+
export declare function NextIcon(p: IconProps): import("react").JSX.Element;
|
|
23
|
+
export declare function ThumbUpIcon(p: IconProps): import("react").JSX.Element;
|
|
24
|
+
export declare function ThumbDownIcon(p: IconProps): import("react").JSX.Element;
|
|
25
|
+
export declare function CloseIcon(p: IconProps): import("react").JSX.Element;
|
|
26
|
+
/** A pencil: marking is on, a tap or a drag marks the drawing. */
|
|
27
|
+
export declare function MarkIcon(p: IconProps): import("react").JSX.Element;
|
|
28
|
+
export {};
|