@miadi/stateloom-canvas 0.1.5 → 0.1.8
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 +110 -0
- package/dist/MarkCards.js +137 -0
- package/dist/StageCaption.d.ts +39 -0
- package/dist/StageCaption.js +15 -0
- package/dist/StageOverlay.d.ts +65 -0
- package/dist/StageOverlay.js +130 -0
- package/dist/icons.d.ts +28 -0
- package/dist/icons.js +46 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +18 -1
- package/dist/marksRead.d.ts +12 -0
- package/dist/marksRead.js +64 -0
- package/dist/styles.css +699 -0
- package/package.json +2 -2
|
@@ -0,0 +1,130 @@
|
|
|
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; a mark
|
|
15
|
+
* the host lists in `unread` (an agent's word not yet opened) wears a quiet
|
|
16
|
+
* "new" ring and dot;
|
|
17
|
+
* - **takes a mark** when the host turns marking on: a tap names the element
|
|
18
|
+
* under it, a drag names the elements inside the area drawn (and the area).
|
|
19
|
+
* A mouse or pen tap on empty board marks a small area there; a finger's tap
|
|
20
|
+
* on empty board does nothing, so a phone's stray touch never makes a mark
|
|
21
|
+
* (a finger's drag still frames an area).
|
|
22
|
+
*
|
|
23
|
+
* Positioned over the canvas by the host (both in one `position: relative`
|
|
24
|
+
* box); it lets every pointer through to the canvas except on its pins and
|
|
25
|
+
* while marking.
|
|
26
|
+
*/
|
|
27
|
+
import { useId, useMemo, useRef, useState } from "react";
|
|
28
|
+
import { boxesOf, elementAt, elementsInRegion, padBox, screenToWorld, unionBox, viewportTransform, worldToScreen, } from "@miadi/stateloom-protocol";
|
|
29
|
+
import { themeStyle } from "./theme.js";
|
|
30
|
+
/** Below this many screen pixels a press is a tap, not an area. */
|
|
31
|
+
const DRAG_THRESHOLD = 6;
|
|
32
|
+
/** A tap on empty board marks a square this many screen pixels wide around it. */
|
|
33
|
+
const TAP_AREA = 56;
|
|
34
|
+
const HOLE_PAD = 8;
|
|
35
|
+
/** Where a mark sits: its elements that are drawn here, else its area. */
|
|
36
|
+
export function markAnchor(mark, boxes) {
|
|
37
|
+
const drawn = mark.elements?.length ? boxesOf(boxes, mark.elements) : [];
|
|
38
|
+
return unionBox(drawn) ?? mark.region ?? null;
|
|
39
|
+
}
|
|
40
|
+
function pinTone(mark) {
|
|
41
|
+
if (mark.status === "resolved")
|
|
42
|
+
return "resolved";
|
|
43
|
+
if (mark.author.role === "agent")
|
|
44
|
+
return mark.status === "answered" ? "answered" : "question";
|
|
45
|
+
return mark.status === "answered" ? "answered" : "open";
|
|
46
|
+
}
|
|
47
|
+
export function StageOverlay({ viewport, boxes, spotlight, region, marks, selectedMark = null, onSelectMark, unread, hideResolved = true, marking = false, onDraft, draft = null, theme, className, style, }) {
|
|
48
|
+
const maskId = `slc-stage-mask-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
49
|
+
const rootRef = useRef(null);
|
|
50
|
+
const press = useRef(null);
|
|
51
|
+
const [drag, setDrag] = useState(null);
|
|
52
|
+
const holes = useMemo(() => (spotlight?.length ? boxesOf(boxes, spotlight).map((b) => padBox(b, HOLE_PAD)) : []), [boxes, spotlight]);
|
|
53
|
+
const vt = viewportTransform(viewport);
|
|
54
|
+
const selected = marks?.find((m) => m.id === selectedMark) ?? null;
|
|
55
|
+
const unreadIds = useMemo(() => new Set(unread ?? []), [unread]);
|
|
56
|
+
const ringed = useMemo(() => {
|
|
57
|
+
const out = [];
|
|
58
|
+
if (selected?.elements?.length)
|
|
59
|
+
out.push(...boxesOf(boxes, selected.elements));
|
|
60
|
+
if (draft?.elements.length)
|
|
61
|
+
out.push(...boxesOf(boxes, draft.elements));
|
|
62
|
+
return out.map((b) => padBox(b, 4));
|
|
63
|
+
}, [boxes, selected, draft]);
|
|
64
|
+
const framed = [selected?.region, draft?.region].filter((b) => !!b);
|
|
65
|
+
const pins = (marks ?? [])
|
|
66
|
+
.map((m, i) => ({ mark: m, n: i + 1 }))
|
|
67
|
+
.filter(({ mark }) => !(hideResolved && mark.status === "resolved" && mark.id !== selectedMark))
|
|
68
|
+
.map(({ mark, n }) => {
|
|
69
|
+
const at = markAnchor(mark, boxes);
|
|
70
|
+
if (!at)
|
|
71
|
+
return null;
|
|
72
|
+
const p = worldToScreen(viewport, { x: at.x + at.width, y: at.y });
|
|
73
|
+
return { mark, n, x: p.x, y: p.y };
|
|
74
|
+
})
|
|
75
|
+
.filter((p) => p !== null);
|
|
76
|
+
const local = (e) => {
|
|
77
|
+
const r = rootRef.current?.getBoundingClientRect();
|
|
78
|
+
return { x: e.clientX - (r?.left ?? 0), y: e.clientY - (r?.top ?? 0) };
|
|
79
|
+
};
|
|
80
|
+
const onDown = (e) => {
|
|
81
|
+
if (e.button !== 0 && e.pointerType === "mouse")
|
|
82
|
+
return;
|
|
83
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
84
|
+
const p = local(e);
|
|
85
|
+
press.current = { id: e.pointerId, x: p.x, y: p.y, moved: false };
|
|
86
|
+
};
|
|
87
|
+
const onMove = (e) => {
|
|
88
|
+
const s = press.current;
|
|
89
|
+
if (!s || s.id !== e.pointerId)
|
|
90
|
+
return;
|
|
91
|
+
const p = local(e);
|
|
92
|
+
if (!s.moved && Math.hypot(p.x - s.x, p.y - s.y) < DRAG_THRESHOLD)
|
|
93
|
+
return;
|
|
94
|
+
s.moved = true;
|
|
95
|
+
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) });
|
|
96
|
+
};
|
|
97
|
+
const onUp = (e) => {
|
|
98
|
+
const s = press.current;
|
|
99
|
+
if (!s || s.id !== e.pointerId)
|
|
100
|
+
return;
|
|
101
|
+
press.current = null;
|
|
102
|
+
setDrag(null);
|
|
103
|
+
const p = local(e);
|
|
104
|
+
if (s.moved) {
|
|
105
|
+
const a = screenToWorld(viewport, { x: Math.min(s.x, p.x), y: Math.min(s.y, p.y) });
|
|
106
|
+
const b = screenToWorld(viewport, { x: Math.max(s.x, p.x), y: Math.max(s.y, p.y) });
|
|
107
|
+
const area = { x: a.x, y: a.y, width: Math.max(1, b.x - a.x), height: Math.max(1, b.y - a.y) };
|
|
108
|
+
onDraft?.({ elements: elementsInRegion(boxes, area), region: area });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const w = screenToWorld(viewport, p);
|
|
112
|
+
const hit = elementAt(boxes, w.x, w.y);
|
|
113
|
+
if (hit)
|
|
114
|
+
return onDraft?.({ elements: [hit] });
|
|
115
|
+
// A finger's tap on empty board is a pan or a dismiss gone astray, not a mark.
|
|
116
|
+
if (e.pointerType === "touch")
|
|
117
|
+
return;
|
|
118
|
+
const half = TAP_AREA / 2 / (viewport.scale || 1);
|
|
119
|
+
onDraft?.({ elements: [], region: { x: w.x - half, y: w.y - half, width: half * 2, height: half * 2 } });
|
|
120
|
+
};
|
|
121
|
+
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)}${unreadIds.has(mark.id) ? " slc-stage-pin--new" : ""}${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"})` : ""}${unreadIds.has(mark.id) ? " · new" : ""}`, "aria-label": `Mark ${n}, ${mark.status}${unreadIds.has(mark.id) ? ", new" : ""}: ${mark.text}`, onPointerDown: (e) => e.stopPropagation(), onClick: (e) => {
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
onSelectMark?.(mark.id);
|
|
124
|
+
}, 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: () => {
|
|
125
|
+
press.current = null;
|
|
126
|
+
setDrag(null);
|
|
127
|
+
} }))] }));
|
|
128
|
+
}
|
|
129
|
+
export default StageOverlay;
|
|
130
|
+
//# 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 {};
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
function Icon({ size = 16, children, ...rest }) {
|
|
3
|
+
return (_jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", className: "slc-icon", ...rest, children: children }));
|
|
4
|
+
}
|
|
5
|
+
export function MicIcon(p) {
|
|
6
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }), _jsx("path", { d: "M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21M8.5 21h7" })] }));
|
|
7
|
+
}
|
|
8
|
+
export function SpeakerIcon(p) {
|
|
9
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("path", { d: "M4 9.5h3.5L12 5.5v13l-4.5-4H4z" }), _jsx("path", { d: "M15.5 9a4 4 0 0 1 0 6M18 6.5a7.5 7.5 0 0 1 0 11" })] }));
|
|
10
|
+
}
|
|
11
|
+
export function SpeakerOffIcon(p) {
|
|
12
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("path", { d: "M4 9.5h3.5L12 5.5v13l-4.5-4H4z" }), _jsx("path", { d: "M16 10l4 4M20 10l-4 4" })] }));
|
|
13
|
+
}
|
|
14
|
+
/** A speech bubble: the marks on a drawing, what people said about it. */
|
|
15
|
+
export function MarksIcon(p) {
|
|
16
|
+
return (_jsx(Icon, { ...p, children: _jsx("path", { d: "M5 5h14a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 16h-7l-4.5 3.5V16H5a1.5 1.5 0 0 1-1.5-1.5v-8A1.5 1.5 0 0 1 5 5z" }) }));
|
|
17
|
+
}
|
|
18
|
+
export function PlayIcon(p) {
|
|
19
|
+
return (_jsx(Icon, { ...p, children: _jsx("path", { d: "M8 5.5v13l10-6.5z", fill: "currentColor" }) }));
|
|
20
|
+
}
|
|
21
|
+
export function PauseIcon(p) {
|
|
22
|
+
return (_jsx(Icon, { ...p, children: _jsx("path", { d: "M8.5 5.5v13M15.5 5.5v13", strokeWidth: 2.6 }) }));
|
|
23
|
+
}
|
|
24
|
+
export function StopIcon(p) {
|
|
25
|
+
return (_jsx(Icon, { ...p, children: _jsx("rect", { x: "7", y: "7", width: "10", height: "10", rx: "1.5", fill: "currentColor" }) }));
|
|
26
|
+
}
|
|
27
|
+
export function PrevIcon(p) {
|
|
28
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("path", { d: "M17 5.5v13L8 12z" }), _jsx("path", { d: "M6.5 5.5v13" })] }));
|
|
29
|
+
}
|
|
30
|
+
export function NextIcon(p) {
|
|
31
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("path", { d: "M7 5.5v13l9-6.5z" }), _jsx("path", { d: "M17.5 5.5v13" })] }));
|
|
32
|
+
}
|
|
33
|
+
export function ThumbUpIcon(p) {
|
|
34
|
+
return (_jsx(Icon, { ...p, children: _jsx("path", { d: "M7.5 10.5v9H4.5v-9zM7.5 10.5l3.5-6.5a2 2 0 0 1 2.5 2.2l-.6 3.3h5.4a2 2 0 0 1 2 2.4l-1.3 6.2a2 2 0 0 1-2 1.4H7.5" }) }));
|
|
35
|
+
}
|
|
36
|
+
export function ThumbDownIcon(p) {
|
|
37
|
+
return (_jsx(Icon, { ...p, style: { transform: "scaleY(-1)", ...p.style }, children: _jsx("path", { d: "M7.5 10.5v9H4.5v-9zM7.5 10.5l3.5-6.5a2 2 0 0 1 2.5 2.2l-.6 3.3h5.4a2 2 0 0 1 2 2.4l-1.3 6.2a2 2 0 0 1-2 1.4H7.5" }) }));
|
|
38
|
+
}
|
|
39
|
+
export function CloseIcon(p) {
|
|
40
|
+
return (_jsx(Icon, { ...p, children: _jsx("path", { d: "M6.5 6.5l11 11M17.5 6.5l-11 11" }) }));
|
|
41
|
+
}
|
|
42
|
+
/** A pencil: marking is on, a tap or a drag marks the drawing. */
|
|
43
|
+
export function MarkIcon(p) {
|
|
44
|
+
return (_jsxs(Icon, { ...p, children: [_jsx("path", { d: "M4.5 19.5l1-4.2L15.8 5a1.8 1.8 0 0 1 2.5 0l.7.7a1.8 1.8 0 0 1 0 2.5L8.7 18.5z" }), _jsx("path", { d: "M13.8 7l3.2 3.2" })] }));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=icons.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -18,8 +18,18 @@ export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
|
18
18
|
export type { EntityRelationshipCanvasProps, ErdCanvasTarget } from "./EntityRelationshipCanvas.js";
|
|
19
19
|
export { SequenceCanvas, drawableSequence } from "./SequenceCanvas.js";
|
|
20
20
|
export type { SequenceCanvasProps, SequenceCanvasTarget, SequenceSelection, SequenceTargetKind, } from "./SequenceCanvas.js";
|
|
21
|
+
export { StageOverlay, markAnchor } from "./StageOverlay.js";
|
|
22
|
+
export type { StageOverlayProps, MarkDraft } from "./StageOverlay.js";
|
|
23
|
+
export { StageCaption } from "./StageCaption.js";
|
|
24
|
+
export type { StageCaptionProps } from "./StageCaption.js";
|
|
25
|
+
export { MarkComposer, MarkThread, MarksPanel, MarkNotice } from "./MarkCards.js";
|
|
26
|
+
export { useMarksRead, loadMarksRead, saveMarksRead, marksReadKey } from "./marksRead.js";
|
|
27
|
+
export { CompanionDock } from "./CompanionDock.js";
|
|
28
|
+
export type { CompanionDockProps, DockItem, DockReply, DockStep, DockTake } from "./CompanionDock.js";
|
|
29
|
+
export { MicIcon, SpeakerIcon, SpeakerOffIcon, MarksIcon, MarkIcon, PlayIcon, PauseIcon, StopIcon, PrevIcon, NextIcon, ThumbUpIcon, ThumbDownIcon, CloseIcon, } from "./icons.js";
|
|
30
|
+
export type { MarkComposerProps, MarkThreadProps, MarksPanelProps, MarkNoticeProps, ListenerLike } from "./MarkCards.js";
|
|
21
31
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
22
32
|
export type { CanvasTheme } from "./theme.js";
|
|
23
33
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
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";
|
|
34
|
+
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, machineElementBoxes, erdElementBoxes, sequenceElementBoxes, elementsInRegion, elementAt, boxesOf, unionBox, marksWaitingOn, markCounts, unreadMarks, isMarkUnread, withMarkRead, lastWordOf, agentWordIn, agentWordText, } from "@miadi/stateloom-protocol";
|
|
35
|
+
export type { AutoLayoutOptions, Box, EntityRelationshipDefinition, FitOptions, LayoutBox, Point, ScaleLimits, SequenceDefinition, SequenceLayout, StateDef, StateMachineDefinition, TransitionDef, Viewport, ElementBox, Mark, MarkKind, MarksRead, MarksEnvelope, AgentWord, TourStep, TourDefinition, } from "@miadi/stateloom-protocol";
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,26 @@
|
|
|
15
15
|
export { StateMachineCanvas, default } from "./StateMachineCanvas.js";
|
|
16
16
|
export { EntityRelationshipCanvas } from "./EntityRelationshipCanvas.js";
|
|
17
17
|
export { SequenceCanvas, drawableSequence } from "./SequenceCanvas.js";
|
|
18
|
+
// The stage (Spec 83): a layer over any of the boards that lights what an
|
|
19
|
+
// agent points at and takes a person's marks, the caption that plays a tour,
|
|
20
|
+
// and the cards marks are written and read in.
|
|
21
|
+
export { StageOverlay, markAnchor } from "./StageOverlay.js";
|
|
22
|
+
export { StageCaption } from "./StageCaption.js";
|
|
23
|
+
export { MarkComposer, MarkThread, MarksPanel, MarkNotice } from "./MarkCards.js";
|
|
24
|
+
// Whether an agent's word has been read, per drawing in this browser, and
|
|
25
|
+
// what a marks button counts — for any host that shows marks (Miadi's room
|
|
26
|
+
// as the loom): `useMarksRead(doc)` + `unreadMarks(marks, read)` give the
|
|
27
|
+
// pins' and the list's `unread`; `markCounts(marks, read)` gives `forYou`
|
|
28
|
+
// (what waits on the person: the main number) and `forAgent` (the quiet one);
|
|
29
|
+
// `agentWordIn(envelope)` + `agentWordText(word)` turn a `marks:changed` that
|
|
30
|
+
// carries an agent's answer into the line for `<MarkNotice>`.
|
|
31
|
+
export { useMarksRead, loadMarksRead, saveMarksRead, marksReadKey } from "./marksRead.js";
|
|
32
|
+
// Talking with a companion from the canvas (Spec 84).
|
|
33
|
+
export { CompanionDock } from "./CompanionDock.js";
|
|
34
|
+
export { MicIcon, SpeakerIcon, SpeakerOffIcon, MarksIcon, MarkIcon, PlayIcon, PauseIcon, StopIcon, PrevIcon, NextIcon, ThumbUpIcon, ThumbDownIcon, CloseIcon, } from "./icons.js";
|
|
18
35
|
export { themeStyle, CANVAS_THEME_VARS } from "./theme.js";
|
|
19
36
|
export { childByName, childStatesAt, childrenOf, definedEvents, findState, livePath, parentAt, } from "./drill.js";
|
|
20
37
|
// The geometry and the model, re-exported at the address a host reaching for a
|
|
21
38
|
// canvas is already looking at.
|
|
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";
|
|
39
|
+
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, machineElementBoxes, erdElementBoxes, sequenceElementBoxes, elementsInRegion, elementAt, boxesOf, unionBox, marksWaitingOn, markCounts, unreadMarks, isMarkUnread, withMarkRead, lastWordOf, agentWordIn, agentWordText, } from "@miadi/stateloom-protocol";
|
|
23
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Mark, type MarksRead } from "@miadi/stateloom-protocol";
|
|
2
|
+
export declare function marksReadKey(doc: string): string;
|
|
3
|
+
export declare function loadMarksRead(doc: string): MarksRead;
|
|
4
|
+
export declare function saveMarksRead(doc: string, read: MarksRead): void;
|
|
5
|
+
/**
|
|
6
|
+
* The read record of one drawing, and `markRead(mark)` to call when the person
|
|
7
|
+
* opens a thread (and again while it stays open as replies arrive).
|
|
8
|
+
*/
|
|
9
|
+
export declare function useMarksRead(doc: string | null): {
|
|
10
|
+
read: MarksRead;
|
|
11
|
+
markRead: (mark: Pick<Mark, "id" | "replies">) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a person has read of a drawing's marks, kept in this browser (Spec 83).
|
|
3
|
+
*
|
|
4
|
+
* Per drawing, `stateloom.marks.read.v1:<doc>` holds mark id → the number of
|
|
5
|
+
* replies the thread had when the person last opened it. With the protocol's
|
|
6
|
+
* `unreadMarks(marks, read)` it says which threads carry an agent's word they
|
|
7
|
+
* have not seen. Every access is guarded: a private window, blocked storage or
|
|
8
|
+
* a server render reads as nothing read, and a write that fails is dropped.
|
|
9
|
+
*/
|
|
10
|
+
import { useCallback, useEffect, useState } from "react";
|
|
11
|
+
import { withMarkRead } from "@miadi/stateloom-protocol";
|
|
12
|
+
const PREFIX = "stateloom.marks.read.v1:";
|
|
13
|
+
export function marksReadKey(doc) {
|
|
14
|
+
return `${PREFIX}${doc}`;
|
|
15
|
+
}
|
|
16
|
+
export function loadMarksRead(doc) {
|
|
17
|
+
try {
|
|
18
|
+
const raw = window.localStorage.getItem(marksReadKey(doc));
|
|
19
|
+
const parsed = raw ? JSON.parse(raw) : null;
|
|
20
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
21
|
+
return {};
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const [id, n] of Object.entries(parsed)) {
|
|
24
|
+
if (typeof n === "number" && Number.isFinite(n) && n >= 0)
|
|
25
|
+
out[id] = n;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function saveMarksRead(doc, read) {
|
|
34
|
+
try {
|
|
35
|
+
window.localStorage.setItem(marksReadKey(doc), JSON.stringify(read));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Storage refused (private mode, quota): the marks read again as new next time.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The read record of one drawing, and `markRead(mark)` to call when the person
|
|
43
|
+
* opens a thread (and again while it stays open as replies arrive).
|
|
44
|
+
*/
|
|
45
|
+
export function useMarksRead(doc) {
|
|
46
|
+
const [state, setState] = useState(() => ({ doc, read: doc ? loadMarksRead(doc) : {} }));
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
setState((s) => (s.doc === doc ? s : { doc, read: doc ? loadMarksRead(doc) : {} }));
|
|
49
|
+
}, [doc]);
|
|
50
|
+
const markRead = useCallback((mark) => {
|
|
51
|
+
if (!doc)
|
|
52
|
+
return;
|
|
53
|
+
setState((s) => {
|
|
54
|
+
const base = s.doc === doc ? s.read : loadMarksRead(doc);
|
|
55
|
+
if (base[mark.id] === (mark.replies?.length ?? 0) && s.doc === doc)
|
|
56
|
+
return s;
|
|
57
|
+
const read = withMarkRead(base, mark);
|
|
58
|
+
saveMarksRead(doc, read);
|
|
59
|
+
return { doc, read };
|
|
60
|
+
});
|
|
61
|
+
}, [doc]);
|
|
62
|
+
return { read: state.doc === doc ? state.read : {}, markRead };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=marksRead.js.map
|