@opengeni/react 3.7.0-canary.7 → 3.8.0-canary.1

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.
Files changed (72) hide show
  1. package/README.md +6 -0
  2. package/dist/chat.js +1 -1
  3. package/dist/chunk-5M6VTFJ5.js +171 -0
  4. package/dist/chunk-5M6VTFJ5.js.map +1 -0
  5. package/dist/{chunk-IOLVN74D.js → chunk-6J56T3MG.js} +15 -1
  6. package/dist/chunk-6J56T3MG.js.map +1 -0
  7. package/dist/{chunk-BQGIXRKV.js → chunk-7BWFU6H4.js} +22 -4
  8. package/dist/chunk-7BWFU6H4.js.map +1 -0
  9. package/dist/{chunk-3HIF5IFC.js → chunk-7W6PVVTK.js} +63 -18
  10. package/dist/chunk-7W6PVVTK.js.map +1 -0
  11. package/dist/{chunk-ZFOFY5ST.js → chunk-NLTS7JHI.js} +16 -31
  12. package/dist/chunk-NLTS7JHI.js.map +1 -0
  13. package/dist/chunk-NOSYBS2D.js +208 -0
  14. package/dist/chunk-NOSYBS2D.js.map +1 -0
  15. package/dist/{chunk-F2CFHN3Y.js → chunk-YAIPFO5D.js} +2 -1
  16. package/dist/chunk-YAIPFO5D.js.map +1 -0
  17. package/dist/chunk-YBM6CQRU.js +292 -0
  18. package/dist/chunk-YBM6CQRU.js.map +1 -0
  19. package/dist/chunk-ZYRGEKWS.js +216 -0
  20. package/dist/chunk-ZYRGEKWS.js.map +1 -0
  21. package/dist/components/composer.d.ts +4 -2
  22. package/dist/components/message-timeline.d.ts +9 -2
  23. package/dist/components/timeline-annotation-chrome.d.ts +25 -0
  24. package/dist/components/timeline-annotation-layout.d.ts +42 -0
  25. package/dist/components/timeline-annotation-markers.d.ts +8 -0
  26. package/dist/components/timeline-annotation-reveal-context.d.ts +4 -0
  27. package/dist/components/timeline-annotation-shared.d.ts +31 -0
  28. package/dist/components/timeline-annotations-dialog.d.ts +1 -1
  29. package/dist/components/timeline-annotations.d.ts +8 -2
  30. package/dist/composer.js +2 -2
  31. package/dist/hooks/use-composer.d.ts +2 -0
  32. package/dist/index.js +9 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/interaction.js +6 -6
  35. package/dist/machines.js +1 -1
  36. package/dist/{queue-surface-implementation-XL2A6PBM.js → queue-surface-implementation-LK3S4BIW.js} +5 -2
  37. package/dist/{queue-surface-implementation-XL2A6PBM.js.map → queue-surface-implementation-LK3S4BIW.js.map} +1 -1
  38. package/dist/session-ui.js +8 -5
  39. package/dist/session.js +1 -1
  40. package/dist/timeline-annotation-markers-DRSTLEM6.js +165 -0
  41. package/dist/timeline-annotation-markers-DRSTLEM6.js.map +1 -0
  42. package/dist/timeline-annotation-selection-IHLUGVND.js +236 -0
  43. package/dist/timeline-annotation-selection-IHLUGVND.js.map +1 -0
  44. package/dist/timeline-annotations-dialog-6Q53N5FG.js +262 -0
  45. package/dist/timeline-annotations-dialog-6Q53N5FG.js.map +1 -0
  46. package/package.json +2 -2
  47. package/src/components/chat-composer.tsx +5 -2
  48. package/src/components/composer.tsx +40 -5
  49. package/src/components/copy-button.tsx +1 -0
  50. package/src/components/machines-dashboard.tsx +1 -16
  51. package/src/components/message-timeline.tsx +357 -297
  52. package/src/components/timeline-annotation-chrome.tsx +183 -0
  53. package/src/components/timeline-annotation-layout.ts +268 -0
  54. package/src/components/timeline-annotation-markers.tsx +185 -0
  55. package/src/components/timeline-annotation-reveal-context.ts +9 -0
  56. package/src/components/timeline-annotation-selection.tsx +99 -54
  57. package/src/components/timeline-annotation-shared.ts +245 -0
  58. package/src/components/timeline-annotations-dialog.tsx +172 -128
  59. package/src/components/timeline-annotations.tsx +178 -45
  60. package/src/hooks/use-composer.ts +17 -0
  61. package/styles/compiled.css +86 -22
  62. package/dist/chunk-3HIF5IFC.js.map +0 -1
  63. package/dist/chunk-BQGIXRKV.js.map +0 -1
  64. package/dist/chunk-F2CFHN3Y.js.map +0 -1
  65. package/dist/chunk-IOLVN74D.js.map +0 -1
  66. package/dist/chunk-W3OUAH6M.js +0 -170
  67. package/dist/chunk-W3OUAH6M.js.map +0 -1
  68. package/dist/chunk-ZFOFY5ST.js.map +0 -1
  69. package/dist/timeline-annotation-selection-3L7LHGG2.js +0 -187
  70. package/dist/timeline-annotation-selection-3L7LHGG2.js.map +0 -1
  71. package/dist/timeline-annotations-dialog-U7EVLR75.js +0 -196
  72. package/dist/timeline-annotations-dialog-U7EVLR75.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/timeline-annotation-markers.tsx"],"sourcesContent":["import type { DraftTimelineAnnotation } from \"@opengeni/sdk\";\nimport { useLayoutEffect, useState, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { cn } from \"../lib/cn\";\nimport {\n annotationBoxIntersects,\n annotationViewportBox,\n layoutAnnotationBadges,\n type AnnotationBadgeAnchor,\n type AnnotationBox,\n} from \"./timeline-annotation-layout\";\nimport {\n annotationDisplayOrdinal,\n annotationHasNote,\n annotatableText,\n buildQuoteRange,\n cssEscapeAttribute,\n matchingQuoteInSource,\n occurrenceOffsets,\n} from \"./timeline-annotation-shared\";\n\nfunction lastVisibleRect(range: Range): DOMRect | null {\n try {\n const rects = range.getClientRects();\n for (let index = rects.length - 1; index >= 0; index--) {\n const rect = rects.item(index);\n if (rect && (rect.width > 0 || rect.height > 0)) return rect;\n }\n } catch {\n // jsdom ranges may omit client rects.\n }\n try {\n const bounding = range.getBoundingClientRect();\n if (bounding.width > 0 || bounding.height > 0) return bounding;\n } catch {\n // jsdom ranges may omit layout geometry.\n }\n return null;\n}\n\nfunction occurrenceForAnnotation(\n sourceEl: HTMLElement,\n annotation: DraftTimelineAnnotation,\n): number {\n const { text } = annotatableText(sourceEl);\n const quote = matchingQuoteInSource(text, annotation.quote) ?? annotation.quote;\n const offsets = occurrenceOffsets(text, quote);\n if (offsets.length <= 1) return 0;\n let best = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n offsets.forEach((offset, index) => {\n const distance = Math.abs(offset - annotation.source.startOffset);\n if (distance < bestDistance) {\n best = index;\n bestDistance = distance;\n }\n });\n return best;\n}\n\nfunction timelineScroller(root: HTMLElement): HTMLElement {\n if (root.matches(\"[data-og-timeline-scroller]\")) return root;\n const nested = root.querySelector(\"[data-og-timeline-scroller]\");\n return nested instanceof HTMLElement ? nested : root;\n}\n\nfunction currentAnnotationViewport(root: HTMLElement): AnnotationBox {\n const scroller = timelineScroller(root);\n const rect = scroller.getBoundingClientRect();\n const scrollerBox = {\n left: rect.left,\n right: rect.right,\n top: rect.top,\n bottom: rect.bottom,\n } satisfies AnnotationBox;\n return annotationViewportBox(window.innerWidth || 1024, window.innerHeight || 768, scrollerBox);\n}\n\nfunction sourceInTimeline(root: HTMLElement, eventId: string): HTMLElement | null {\n const source = root.querySelector(\n `[data-og-annotation-source-key=\"${cssEscapeAttribute(eventId)}\"]`,\n );\n return source instanceof HTMLElement ? source : null;\n}\n\nfunction collectMarkers(\n root: HTMLElement | null,\n annotations: readonly DraftTimelineAnnotation[],\n): AnnotationBadgeAnchor[] {\n if (!root) return [];\n const viewport = currentAnnotationViewport(root);\n const next: AnnotationBadgeAnchor[] = [];\n for (const [index, annotation] of annotations.entries()) {\n const source = sourceInTimeline(root, annotation.source.eventId);\n if (!source) continue;\n const quote =\n matchingQuoteInSource(annotatableText(source).text, annotation.quote) ?? annotation.quote;\n const range = buildQuoteRange(source, quote, occurrenceForAnnotation(source, annotation));\n if (!range) continue;\n const rect = lastVisibleRect(range);\n if (!rect) continue;\n if (\n !annotationBoxIntersects(\n { left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom },\n viewport,\n )\n ) {\n continue;\n }\n next.push({\n id: annotation.id,\n ordinal: annotationDisplayOrdinal(annotation, index),\n left: rect.right,\n top: rect.top,\n incomplete: !annotationHasNote(annotation.note),\n });\n }\n return layoutAnnotationBadges(next, viewport);\n}\n\nexport function TimelineAnnotationMarkers({\n annotations,\n onSelect,\n rootRef,\n}: {\n annotations: readonly DraftTimelineAnnotation[];\n onSelect?: ((id: string) => void) | undefined;\n rootRef: RefObject<HTMLElement | null>;\n}) {\n const [markers, setMarkers] = useState<AnnotationBadgeAnchor[]>([]);\n\n useLayoutEffect(() => {\n const root = rootRef.current;\n if (!root || annotations.length === 0) {\n setMarkers([]);\n return;\n }\n const update = () => setMarkers(collectMarkers(root, annotations));\n update();\n window.addEventListener(\"resize\", update);\n window.addEventListener(\"scroll\", update, true);\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(update) : null;\n observer?.observe(root);\n for (const annotation of annotations) {\n const source = sourceInTimeline(root, annotation.source.eventId);\n if (source) observer?.observe(source);\n }\n return () => {\n window.removeEventListener(\"resize\", update);\n window.removeEventListener(\"scroll\", update, true);\n observer?.disconnect();\n };\n }, [annotations, rootRef]);\n\n if (markers.length === 0 || typeof document === \"undefined\") return null;\n return createPortal(\n <div className=\"og-root pointer-events-none fixed inset-0 z-[35]\">\n {markers.map((marker) => (\n <button\n key={marker.id}\n type=\"button\"\n data-og-annotation-badge=\"\"\n data-og-annotation-badge-ordinal={marker.ordinal}\n style={{ left: marker.left, top: marker.top, zIndex: marker.ordinal }}\n className={cn(\n \"pointer-events-auto absolute flex h-4 min-w-4 -translate-x-1/2 -translate-y-[110%] items-center justify-center rounded-full bg-og-accent px-0.5 text-[10px] font-semibold tabular-nums text-white shadow-sm outline-hidden select-none after:absolute after:-inset-2 after:content-[''] focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:after:-inset-2.5\",\n marker.incomplete && \"ring-1 ring-og-accent-fg/35\",\n )}\n aria-label={`Annotation ${marker.ordinal}`}\n onMouseDown={(event) => event.preventDefault()}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n onSelect?.(marker.id);\n }}\n >\n {marker.ordinal}\n </button>\n ))}\n </div>,\n document.body,\n );\n}\n\nexport default TimelineAnnotationMarkers;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA,SAAS,iBAAiB,gBAAgC;AAC1D,SAAS,oBAAoB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SAAS;AAAA,EACX;AACF;AAEA,IAAO,sCAAQ;","names":[]}
@@ -0,0 +1,236 @@
1
+ import {
2
+ clipRangeToSource,
3
+ matchingQuoteInSource,
4
+ occurrenceOffsets,
5
+ quoteOccurrenceIndex,
6
+ truncateAnnotationQuote,
7
+ visibleClientRect
8
+ } from "./chunk-NOSYBS2D.js";
9
+ import {
10
+ usePortalTokenStyle
11
+ } from "./chunk-VZTQ73XT.js";
12
+
13
+ // src/components/timeline-annotation-selection.tsx
14
+ import { QuoteIcon } from "lucide-react";
15
+ import { useEffect, useRef, useState } from "react";
16
+ import { createPortal } from "react-dom";
17
+ import { jsx, jsxs } from "react/jsx-runtime";
18
+ var CONTROL_SELECTOR = "button,input,textarea,select,summary,[contenteditable='true']";
19
+ var SOURCE_CONTEXT_BYTES = 160;
20
+ var MAX_QUOTE_BYTES = 16 * 1024;
21
+ var POPOVER_WIDTH = 280;
22
+ var POPOVER_HEIGHT = 64;
23
+ function utf8Prefix(value, maxBytes) {
24
+ let output = "";
25
+ let bytes = 0;
26
+ for (const character of value) {
27
+ const next = new TextEncoder().encode(character).byteLength;
28
+ if (bytes + next > maxBytes) break;
29
+ output += character;
30
+ bytes += next;
31
+ }
32
+ return output;
33
+ }
34
+ function utf8Suffix(value, maxBytes) {
35
+ let output = "";
36
+ let bytes = 0;
37
+ for (const character of [...value].reverse()) {
38
+ const next = new TextEncoder().encode(character).byteLength;
39
+ if (bytes + next > maxBytes) break;
40
+ output = character + output;
41
+ bytes += next;
42
+ }
43
+ return output;
44
+ }
45
+ function selectionElement(node) {
46
+ return node instanceof Element ? node : node?.parentElement ?? null;
47
+ }
48
+ function containingSource(node) {
49
+ const element = selectionElement(node);
50
+ const source = element?.closest("[data-og-annotation-source-key]");
51
+ return source instanceof HTMLElement ? source : null;
52
+ }
53
+ function resolveSourceBoundary(range, root) {
54
+ const start = containingSource(range.startContainer);
55
+ const end = containingSource(range.endContainer);
56
+ if (start && end && start !== end) return null;
57
+ const boundary = start ?? end;
58
+ if (!boundary || !root.contains(boundary)) return null;
59
+ return boundary;
60
+ }
61
+ function isWhollyInsideControl(range, boundary) {
62
+ const start = selectionElement(range.startContainer)?.closest(CONTROL_SELECTOR);
63
+ const end = selectionElement(range.endContainer)?.closest(CONTROL_SELECTOR);
64
+ return start instanceof Element && start === end && boundary.contains(start) && start !== boundary;
65
+ }
66
+ function annotationId() {
67
+ if (typeof globalThis.crypto?.randomUUID === "function") {
68
+ return globalThis.crypto.randomUUID();
69
+ }
70
+ return `annotation-${Date.now()}-${Math.random().toString(16).slice(2)}`;
71
+ }
72
+ function clamp(value, min, max) {
73
+ return Math.min(Math.max(value, min), max);
74
+ }
75
+ function popoverPosition(rect) {
76
+ const half = POPOVER_WIDTH / 2;
77
+ const left = clamp(rect.left + rect.width / 2, 12 + half, window.innerWidth - 12 - half);
78
+ const preferBelow = rect.bottom + 8 + POPOVER_HEIGHT <= window.innerHeight - 12;
79
+ const top = preferBelow ? rect.bottom + 8 : Math.max(12, rect.top - POPOVER_HEIGHT - 8);
80
+ return { left, top };
81
+ }
82
+ function buildCandidate(root, sources, keyboard) {
83
+ const selection = document.getSelection();
84
+ if (!selection || selection.rangeCount !== 1 || selection.isCollapsed) return null;
85
+ const range = selection.getRangeAt(0);
86
+ const startBoundary = resolveSourceBoundary(range, root);
87
+ if (!startBoundary) return null;
88
+ if (isWhollyInsideControl(range, startBoundary)) return null;
89
+ const clipped = clipRangeToSource(range, startBoundary);
90
+ if (!clipped) return null;
91
+ const sourceKey = startBoundary.dataset.ogAnnotationSourceKey;
92
+ const source = sourceKey ? sources.get(sourceKey) : void 0;
93
+ const rawQuote = clipped.toString();
94
+ const quote = (source ? matchingQuoteInSource(source.text, rawQuote) : null) ?? rawQuote;
95
+ if (!source || quote.trim().length === 0 || new TextEncoder().encode(quote).byteLength > MAX_QUOTE_BYTES) {
96
+ return null;
97
+ }
98
+ const sourceOffsets = occurrenceOffsets(source.text, quote);
99
+ if (sourceOffsets.length === 0) return null;
100
+ const occurrence = quoteOccurrenceIndex(startBoundary, clipped, quote);
101
+ const startOffset = sourceOffsets[Math.min(occurrence, sourceOffsets.length - 1)];
102
+ const endOffset = startOffset + quote.length;
103
+ const rect = visibleClientRect(range) ?? visibleClientRect(clipped);
104
+ if (!rect) return null;
105
+ const position = popoverPosition(rect);
106
+ return {
107
+ annotation: {
108
+ id: annotationId(),
109
+ quote,
110
+ note: "",
111
+ source: {
112
+ kind: source.kind,
113
+ eventId: source.eventId,
114
+ eventType: source.eventType,
115
+ sequence: source.sequence,
116
+ turnId: source.turnId,
117
+ startOffset,
118
+ endOffset,
119
+ contextBefore: utf8Suffix(source.text.slice(0, startOffset), SOURCE_CONTEXT_BYTES),
120
+ contextAfter: utf8Prefix(source.text.slice(endOffset), SOURCE_CONTEXT_BYTES),
121
+ ...source.label ? { label: source.label } : {}
122
+ }
123
+ },
124
+ left: position.left,
125
+ top: position.top,
126
+ keyboard
127
+ };
128
+ }
129
+ function TimelineAnnotationSelection({
130
+ rootRef,
131
+ sources,
132
+ onAnnotate
133
+ }) {
134
+ const [candidate, setCandidate] = useState(null);
135
+ const buttonRef = useRef(null);
136
+ const pointerOriginRef = useRef("unset");
137
+ const portalStyle = usePortalTokenStyle(rootRef.current);
138
+ useEffect(() => {
139
+ const root = rootRef.current;
140
+ if (!root || !onAnnotate) {
141
+ setCandidate(null);
142
+ return;
143
+ }
144
+ const update = (keyboard) => {
145
+ setCandidate(buildCandidate(root, sources, keyboard));
146
+ };
147
+ const onRootPointerUp = (event) => {
148
+ if (event.target instanceof Node && buttonRef.current?.contains(event.target)) return;
149
+ if (pointerOriginRef.current === "outside") return;
150
+ window.setTimeout(() => update(false), 0);
151
+ };
152
+ const onDocumentPointerUp = (event) => {
153
+ if (event.target instanceof Node && buttonRef.current?.contains(event.target)) return;
154
+ const startedInRoot = pointerOriginRef.current === "inside";
155
+ pointerOriginRef.current = "unset";
156
+ if (!startedInRoot) return;
157
+ window.setTimeout(() => update(false), 0);
158
+ };
159
+ const onKeyUp = (event) => {
160
+ if (event.key === "Escape") {
161
+ setCandidate(null);
162
+ return;
163
+ }
164
+ window.setTimeout(() => update(true), 0);
165
+ };
166
+ const onPointerDown = (event) => {
167
+ if (event.target instanceof Node && buttonRef.current?.contains(event.target)) {
168
+ event.preventDefault();
169
+ return;
170
+ }
171
+ pointerOriginRef.current = event.target instanceof Node && root.contains(event.target) ? "inside" : "outside";
172
+ setCandidate(null);
173
+ };
174
+ const onDocumentKeyDown = (event) => {
175
+ if (event.key === "Escape") setCandidate(null);
176
+ };
177
+ const onSelectionChange = () => {
178
+ if (buttonRef.current && document.activeElement === buttonRef.current) return;
179
+ const selection = document.getSelection();
180
+ if (!selection || selection.isCollapsed) setCandidate(null);
181
+ };
182
+ root.addEventListener("pointerup", onRootPointerUp);
183
+ root.addEventListener("keyup", onKeyUp);
184
+ document.addEventListener("pointerup", onDocumentPointerUp);
185
+ document.addEventListener("pointerdown", onPointerDown);
186
+ document.addEventListener("keydown", onDocumentKeyDown);
187
+ document.addEventListener("selectionchange", onSelectionChange);
188
+ return () => {
189
+ root.removeEventListener("pointerup", onRootPointerUp);
190
+ root.removeEventListener("keyup", onKeyUp);
191
+ document.removeEventListener("pointerup", onDocumentPointerUp);
192
+ document.removeEventListener("pointerdown", onPointerDown);
193
+ document.removeEventListener("keydown", onDocumentKeyDown);
194
+ document.removeEventListener("selectionchange", onSelectionChange);
195
+ };
196
+ }, [onAnnotate, rootRef, sources]);
197
+ useEffect(() => {
198
+ if (candidate?.keyboard) buttonRef.current?.focus();
199
+ }, [candidate]);
200
+ if (!candidate || !onAnnotate || typeof document === "undefined") return null;
201
+ const preview = truncateAnnotationQuote(candidate.annotation.quote, 72);
202
+ return createPortal(
203
+ /* @__PURE__ */ jsxs(
204
+ "button",
205
+ {
206
+ ref: buttonRef,
207
+ type: "button",
208
+ "data-og-annotation-popover": "",
209
+ style: { left: candidate.left, top: candidate.top, ...portalStyle },
210
+ className: "og-root fixed z-[80] flex max-w-[min(18rem,calc(100vw-1.5rem))] -translate-x-1/2 items-start gap-2 rounded-2xl border border-og-border bg-og-surface-1 px-3 py-2 text-og-sm font-medium text-og-fg shadow-xl outline-hidden transition hover:border-og-accent/40 hover:bg-og-surface-2 focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:min-h-[44px]",
211
+ "aria-label": `Add a note about \u201C${preview}\u201D`,
212
+ title: candidate.annotation.quote,
213
+ onPointerDown: (event) => event.preventDefault(),
214
+ onClick: () => {
215
+ onAnnotate(candidate.annotation);
216
+ document.getSelection()?.removeAllRanges();
217
+ setCandidate(null);
218
+ },
219
+ children: [
220
+ /* @__PURE__ */ jsx(QuoteIcon, { className: "mt-0.5 size-3.5 shrink-0 text-og-accent", "aria-hidden": "true" }),
221
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 text-left", children: [
222
+ /* @__PURE__ */ jsx("span", { className: "block leading-5", children: "Add note" }),
223
+ /* @__PURE__ */ jsx("span", { className: "mt-0.5 block truncate text-og-xs font-normal text-og-fg-muted", children: preview })
224
+ ] })
225
+ ]
226
+ }
227
+ ),
228
+ document.body
229
+ );
230
+ }
231
+ var timeline_annotation_selection_default = TimelineAnnotationSelection;
232
+ export {
233
+ TimelineAnnotationSelection,
234
+ timeline_annotation_selection_default as default
235
+ };
236
+ //# sourceMappingURL=timeline-annotation-selection-IHLUGVND.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/timeline-annotation-selection.tsx"],"sourcesContent":["import type { DraftTimelineAnnotation } from \"@opengeni/sdk\";\nimport { QuoteIcon } from \"lucide-react\";\nimport { useEffect, useRef, useState, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { usePortalTokenStyle } from \"../lib/use-portal-token-style\";\nimport type { TimelineAnnotationSourceDescriptor } from \"../timeline\";\nimport {\n clipRangeToSource,\n matchingQuoteInSource,\n occurrenceOffsets,\n quoteOccurrenceIndex,\n truncateAnnotationQuote,\n visibleClientRect,\n} from \"./timeline-annotation-shared\";\n\ntype SelectionCandidate = {\n annotation: DraftTimelineAnnotation;\n left: number;\n top: number;\n keyboard: boolean;\n};\n\nconst CONTROL_SELECTOR = \"button,input,textarea,select,summary,[contenteditable='true']\";\nconst SOURCE_CONTEXT_BYTES = 160;\nconst MAX_QUOTE_BYTES = 16 * 1024;\nconst POPOVER_WIDTH = 280;\nconst POPOVER_HEIGHT = 64;\n\nfunction utf8Prefix(value: string, maxBytes: number): string {\n let output = \"\";\n let bytes = 0;\n for (const character of value) {\n const next = new TextEncoder().encode(character).byteLength;\n if (bytes + next > maxBytes) break;\n output += character;\n bytes += next;\n }\n return output;\n}\n\nfunction utf8Suffix(value: string, maxBytes: number): string {\n let output = \"\";\n let bytes = 0;\n for (const character of [...value].reverse()) {\n const next = new TextEncoder().encode(character).byteLength;\n if (bytes + next > maxBytes) break;\n output = character + output;\n bytes += next;\n }\n return output;\n}\n\nfunction selectionElement(node: Node | null): Element | null {\n return node instanceof Element ? node : (node?.parentElement ?? null);\n}\n\nfunction containingSource(node: Node | null): HTMLElement | null {\n const element = selectionElement(node);\n const source = element?.closest(\"[data-og-annotation-source-key]\");\n return source instanceof HTMLElement ? source : null;\n}\n\nfunction resolveSourceBoundary(range: Range, root: HTMLElement): HTMLElement | null {\n const start = containingSource(range.startContainer);\n const end = containingSource(range.endContainer);\n if (start && end && start !== end) return null;\n const boundary = start ?? end;\n if (!boundary || !root.contains(boundary)) return null;\n return boundary;\n}\n\nfunction isWhollyInsideControl(range: Range, boundary: HTMLElement): boolean {\n const start = selectionElement(range.startContainer)?.closest(CONTROL_SELECTOR);\n const end = selectionElement(range.endContainer)?.closest(CONTROL_SELECTOR);\n return (\n start instanceof Element && start === end && boundary.contains(start) && start !== boundary\n );\n}\n\nfunction annotationId(): string {\n if (typeof globalThis.crypto?.randomUUID === \"function\") {\n return globalThis.crypto.randomUUID();\n }\n return `annotation-${Date.now()}-${Math.random().toString(16).slice(2)}`;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction popoverPosition(rect: DOMRect): { left: number; top: number } {\n const half = POPOVER_WIDTH / 2;\n const left = clamp(rect.left + rect.width / 2, 12 + half, window.innerWidth - 12 - half);\n const preferBelow = rect.bottom + 8 + POPOVER_HEIGHT <= window.innerHeight - 12;\n const top = preferBelow ? rect.bottom + 8 : Math.max(12, rect.top - POPOVER_HEIGHT - 8);\n return { left, top };\n}\n\nfunction buildCandidate(\n root: HTMLElement,\n sources: ReadonlyMap<string, TimelineAnnotationSourceDescriptor>,\n keyboard: boolean,\n): SelectionCandidate | null {\n const selection = document.getSelection();\n if (!selection || selection.rangeCount !== 1 || selection.isCollapsed) return null;\n const range = selection.getRangeAt(0);\n const startBoundary = resolveSourceBoundary(range, root);\n if (!startBoundary) return null;\n if (isWhollyInsideControl(range, startBoundary)) return null;\n const clipped = clipRangeToSource(range, startBoundary);\n if (!clipped) return null;\n const sourceKey = startBoundary.dataset.ogAnnotationSourceKey;\n const source = sourceKey ? sources.get(sourceKey) : undefined;\n const rawQuote = clipped.toString();\n const quote = (source ? matchingQuoteInSource(source.text, rawQuote) : null) ?? rawQuote;\n if (\n !source ||\n quote.trim().length === 0 ||\n new TextEncoder().encode(quote).byteLength > MAX_QUOTE_BYTES\n ) {\n return null;\n }\n const sourceOffsets = occurrenceOffsets(source.text, quote);\n if (sourceOffsets.length === 0) return null;\n const occurrence = quoteOccurrenceIndex(startBoundary, clipped, quote);\n const startOffset = sourceOffsets[Math.min(occurrence, sourceOffsets.length - 1)]!;\n const endOffset = startOffset + quote.length;\n const rect = visibleClientRect(range) ?? visibleClientRect(clipped);\n if (!rect) return null;\n const position = popoverPosition(rect);\n return {\n annotation: {\n id: annotationId(),\n quote,\n note: \"\",\n source: {\n kind: source.kind,\n eventId: source.eventId,\n eventType: source.eventType,\n sequence: source.sequence,\n turnId: source.turnId,\n startOffset,\n endOffset,\n contextBefore: utf8Suffix(source.text.slice(0, startOffset), SOURCE_CONTEXT_BYTES),\n contextAfter: utf8Prefix(source.text.slice(endOffset), SOURCE_CONTEXT_BYTES),\n ...(source.label ? { label: source.label } : {}),\n },\n },\n left: position.left,\n top: position.top,\n keyboard,\n };\n}\n\nexport function TimelineAnnotationSelection({\n rootRef,\n sources,\n onAnnotate,\n}: {\n rootRef: RefObject<HTMLElement | null>;\n sources: ReadonlyMap<string, TimelineAnnotationSourceDescriptor>;\n onAnnotate?: ((annotation: DraftTimelineAnnotation) => void) | undefined;\n}) {\n const [candidate, setCandidate] = useState<SelectionCandidate | null>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n const pointerOriginRef = useRef<\"unset\" | \"inside\" | \"outside\">(\"unset\");\n const portalStyle = usePortalTokenStyle(rootRef.current);\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root || !onAnnotate) {\n setCandidate(null);\n return;\n }\n const update = (keyboard: boolean) => {\n setCandidate(buildCandidate(root, sources, keyboard));\n };\n const onRootPointerUp = (event: PointerEvent) => {\n if (event.target instanceof Node && buttonRef.current?.contains(event.target)) return;\n // Tests may fire only pointerup on the source. A real click that started\n // outside the timeline must not resurrect leftover selection.\n if (pointerOriginRef.current === \"outside\") return;\n window.setTimeout(() => update(false), 0);\n };\n const onDocumentPointerUp = (event: PointerEvent) => {\n if (event.target instanceof Node && buttonRef.current?.contains(event.target)) return;\n const startedInRoot = pointerOriginRef.current === \"inside\";\n pointerOriginRef.current = \"unset\";\n if (!startedInRoot) return;\n window.setTimeout(() => update(false), 0);\n };\n const onKeyUp = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n setCandidate(null);\n return;\n }\n window.setTimeout(() => update(true), 0);\n };\n const onPointerDown = (event: PointerEvent) => {\n if (event.target instanceof Node && buttonRef.current?.contains(event.target)) {\n event.preventDefault();\n return;\n }\n pointerOriginRef.current =\n event.target instanceof Node && root.contains(event.target) ? \"inside\" : \"outside\";\n setCandidate(null);\n };\n const onDocumentKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") setCandidate(null);\n };\n const onSelectionChange = () => {\n if (buttonRef.current && document.activeElement === buttonRef.current) return;\n const selection = document.getSelection();\n if (!selection || selection.isCollapsed) setCandidate(null);\n };\n root.addEventListener(\"pointerup\", onRootPointerUp);\n root.addEventListener(\"keyup\", onKeyUp);\n document.addEventListener(\"pointerup\", onDocumentPointerUp);\n document.addEventListener(\"pointerdown\", onPointerDown);\n document.addEventListener(\"keydown\", onDocumentKeyDown);\n document.addEventListener(\"selectionchange\", onSelectionChange);\n return () => {\n root.removeEventListener(\"pointerup\", onRootPointerUp);\n root.removeEventListener(\"keyup\", onKeyUp);\n document.removeEventListener(\"pointerup\", onDocumentPointerUp);\n document.removeEventListener(\"pointerdown\", onPointerDown);\n document.removeEventListener(\"keydown\", onDocumentKeyDown);\n document.removeEventListener(\"selectionchange\", onSelectionChange);\n };\n }, [onAnnotate, rootRef, sources]);\n\n useEffect(() => {\n if (candidate?.keyboard) buttonRef.current?.focus();\n }, [candidate]);\n\n if (!candidate || !onAnnotate || typeof document === \"undefined\") return null;\n const preview = truncateAnnotationQuote(candidate.annotation.quote, 72);\n return createPortal(\n <button\n ref={buttonRef}\n type=\"button\"\n data-og-annotation-popover=\"\"\n style={{ left: candidate.left, top: candidate.top, ...portalStyle }}\n className=\"og-root fixed z-[80] flex max-w-[min(18rem,calc(100vw-1.5rem))] -translate-x-1/2 items-start gap-2 rounded-2xl border border-og-border bg-og-surface-1 px-3 py-2 text-og-sm font-medium text-og-fg shadow-xl outline-hidden transition hover:border-og-accent/40 hover:bg-og-surface-2 focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:min-h-[44px]\"\n aria-label={`Add a note about “${preview}”`}\n title={candidate.annotation.quote}\n onPointerDown={(event) => event.preventDefault()}\n onClick={() => {\n onAnnotate(candidate.annotation);\n document.getSelection()?.removeAllRanges();\n setCandidate(null);\n }}\n >\n <QuoteIcon className=\"mt-0.5 size-3.5 shrink-0 text-og-accent\" aria-hidden=\"true\" />\n <span className=\"min-w-0 text-left\">\n <span className=\"block leading-5\">Add note</span>\n <span className=\"mt-0.5 block truncate text-og-xs font-normal text-og-fg-muted\">\n {preview}\n </span>\n </span>\n </button>,\n document.body,\n );\n}\n\nexport default TimelineAnnotationSelection;\n"],"mappings":";;;;;;;;;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,WAAW,QAAQ,gBAAgC;AAC5D,SAAS,oBAAoB;AA0PvB,cACA,YADA;AAvON,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB,KAAK;AAC7B,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AAEvB,SAAS,WAAW,OAAe,UAA0B;AAC3D,MAAI,SAAS;AACb,MAAI,QAAQ;AACZ,aAAW,aAAa,OAAO;AAC7B,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,SAAS,EAAE;AACjD,QAAI,QAAQ,OAAO,SAAU;AAC7B,cAAU;AACV,aAAS;AAAA,EACX;AACA,SAAO;AACT;AAEA,SAAS,WAAW,OAAe,UAA0B;AAC3D,MAAI,SAAS;AACb,MAAI,QAAQ;AACZ,aAAW,aAAa,CAAC,GAAG,KAAK,EAAE,QAAQ,GAAG;AAC5C,UAAM,OAAO,IAAI,YAAY,EAAE,OAAO,SAAS,EAAE;AACjD,QAAI,QAAQ,OAAO,SAAU;AAC7B,aAAS,YAAY;AACrB,aAAS;AAAA,EACX;AACA,SAAO;AACT;AAEA,SAAS,iBAAiB,MAAmC;AAC3D,SAAO,gBAAgB,UAAU,OAAQ,MAAM,iBAAiB;AAClE;AAEA,SAAS,iBAAiB,MAAuC;AAC/D,QAAM,UAAU,iBAAiB,IAAI;AACrC,QAAM,SAAS,SAAS,QAAQ,iCAAiC;AACjE,SAAO,kBAAkB,cAAc,SAAS;AAClD;AAEA,SAAS,sBAAsB,OAAc,MAAuC;AAClF,QAAM,QAAQ,iBAAiB,MAAM,cAAc;AACnD,QAAM,MAAM,iBAAiB,MAAM,YAAY;AAC/C,MAAI,SAAS,OAAO,UAAU,IAAK,QA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Y,0BAAqB,OAAO;AAAA,QACxC,OAAO,UAAU,WAAW;AAAA,QAC5B,eAAe,CAAC,UAAU,MAAM,eAAe;AAAA,QAC/C,SAAS,MAAM;AACb,qBAAW,UAAU,UAAU;AAC/B,mBAAS,aAAa,GAAG,gBAAgB;AACzC,uBAAa,IAAI;AAAA,QACnB;AAAA,QAEA;AAAA,8BAAC,aAAU,WAAU,2CAA0C,eAAY,QAAO;AAAA,UAClF,qBAAC,UAAK,WAAU,qBACd;AAAA,gCAAC,UAAK,WAAU,mBAAkB,sBAAQ;AAAA,YAC1C,oBAAC,UAAK,WAAU,iEACb,mBACH;AAAA,aACF;AAAA;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAEA,IAAO,wCAAQ;","names":[]}
@@ -0,0 +1,262 @@
1
+ import {
2
+ AnnotationAccentRow,
3
+ AnnotationNoteField,
4
+ AnnotationNotePreview,
5
+ AnnotationQuoteSourceButton
6
+ } from "./chunk-5M6VTFJ5.js";
7
+ import {
8
+ ANNOTATION_REVIEW_DIALOG_WIDTH_PX,
9
+ clampAnnotationDialogPlacement,
10
+ scrollAnnotationRowIntoList
11
+ } from "./chunk-ZYRGEKWS.js";
12
+ import {
13
+ annotationDisplayOrdinal,
14
+ cssEscapeAttribute
15
+ } from "./chunk-NOSYBS2D.js";
16
+ import {
17
+ usePortalTokenStyle
18
+ } from "./chunk-VZTQ73XT.js";
19
+ import "./chunk-22KP6LR5.js";
20
+
21
+ // src/components/timeline-annotations-dialog.tsx
22
+ import { XIcon } from "lucide-react";
23
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
24
+ import { createPortal } from "react-dom";
25
+ import { jsx, jsxs } from "react/jsx-runtime";
26
+ function focusableElements(root) {
27
+ return [
28
+ ...root.querySelectorAll(
29
+ 'button:not([disabled]),textarea:not([disabled]),input:not([disabled]),[href],[tabindex]:not([tabindex="-1"])'
30
+ )
31
+ ].filter((element) => element.tabIndex >= 0 && !element.closest("[inert]"));
32
+ }
33
+ function TimelineAnnotationsDialog({
34
+ annotations,
35
+ editable,
36
+ focusAnnotationId,
37
+ onFocusConsumed,
38
+ onUpdate,
39
+ onRemove,
40
+ onRevealSource,
41
+ triggerRef,
42
+ countLabel,
43
+ onDismiss
44
+ }) {
45
+ const [unavailableId, setUnavailableId] = useState(null);
46
+ const [position, setPosition] = useState({ left: 12, top: 12, maxHeight: 0 });
47
+ const panelRef = useRef(null);
48
+ const headerRef = useRef(null);
49
+ const listRef = useRef(null);
50
+ const noteRefs = useRef(/* @__PURE__ */ new Map());
51
+ const portalStyle = usePortalTokenStyle(triggerRef.current);
52
+ const revealNote = (id) => {
53
+ const row = listRef.current?.querySelector(
54
+ `[data-og-annotation-id="${cssEscapeAttribute(id)}"]`
55
+ );
56
+ scrollAnnotationRowIntoList(listRef.current, row);
57
+ noteRefs.current.get(id)?.focus();
58
+ };
59
+ const commitNotes = (fromId) => {
60
+ const incomplete = annotations.filter((annotation) => {
61
+ const live = noteRefs.current.get(annotation.id);
62
+ return (live?.value ?? annotation.note).trim().length === 0;
63
+ });
64
+ if (incomplete.length === 0) {
65
+ onDismiss(true);
66
+ return;
67
+ }
68
+ const fromIndex = annotations.findIndex((annotation) => annotation.id === fromId);
69
+ const next = incomplete.find(
70
+ (item) => annotations.findIndex((annotation) => annotation.id === item.id) > fromIndex
71
+ ) ?? incomplete[0];
72
+ revealNote(next.id);
73
+ };
74
+ useLayoutEffect(() => {
75
+ const updatePosition = () => {
76
+ const rect = triggerRef.current?.getBoundingClientRect();
77
+ if (!rect) return;
78
+ const contentHeight = (headerRef.current?.offsetHeight ?? 44) + (listRef.current?.scrollHeight ?? 200);
79
+ setPosition(
80
+ clampAnnotationDialogPlacement({
81
+ triggerLeft: rect.left,
82
+ triggerTop: rect.top,
83
+ triggerBottom: rect.bottom,
84
+ contentHeight,
85
+ viewportWidth: window.innerWidth,
86
+ viewportHeight: window.innerHeight,
87
+ panelWidth: ANNOTATION_REVIEW_DIALOG_WIDTH_PX
88
+ })
89
+ );
90
+ };
91
+ updatePosition();
92
+ window.addEventListener("resize", updatePosition);
93
+ window.addEventListener("scroll", updatePosition, true);
94
+ return () => {
95
+ window.removeEventListener("resize", updatePosition);
96
+ window.removeEventListener("scroll", updatePosition, true);
97
+ };
98
+ }, [annotations, triggerRef]);
99
+ useLayoutEffect(() => {
100
+ if (!focusAnnotationId || position.maxHeight <= 0) return;
101
+ revealNote(focusAnnotationId);
102
+ const note = noteRefs.current.get(focusAnnotationId);
103
+ if (note && document.activeElement === note) onFocusConsumed?.();
104
+ }, [focusAnnotationId, onFocusConsumed, annotations.length, position.maxHeight]);
105
+ useEffect(() => {
106
+ const onKeyDown = (event) => {
107
+ if (event.key === "Escape") {
108
+ event.stopPropagation();
109
+ onDismiss(true);
110
+ return;
111
+ }
112
+ if (event.key !== "Tab" || !panelRef.current) return;
113
+ const focusable = focusableElements(panelRef.current);
114
+ if (focusable.length === 0) return;
115
+ const first = focusable[0];
116
+ const last = focusable[focusable.length - 1];
117
+ if (event.shiftKey && document.activeElement === first) {
118
+ event.preventDefault();
119
+ last.focus();
120
+ } else if (!event.shiftKey && document.activeElement === last) {
121
+ event.preventDefault();
122
+ first.focus();
123
+ }
124
+ };
125
+ const onPointerDown = (event) => {
126
+ if (!(event.target instanceof Node)) return;
127
+ if (panelRef.current?.contains(event.target) || triggerRef.current?.contains(event.target)) {
128
+ return;
129
+ }
130
+ onDismiss(false);
131
+ };
132
+ document.addEventListener("keydown", onKeyDown);
133
+ document.addEventListener("pointerdown", onPointerDown);
134
+ if (!focusAnnotationId) {
135
+ window.setTimeout(() => {
136
+ if (document.activeElement === triggerRef.current) panelRef.current?.focus();
137
+ }, 0);
138
+ }
139
+ return () => {
140
+ document.removeEventListener("keydown", onKeyDown);
141
+ document.removeEventListener("pointerdown", onPointerDown);
142
+ };
143
+ }, [focusAnnotationId, onDismiss, triggerRef]);
144
+ if (typeof document === "undefined") return null;
145
+ return createPortal(
146
+ /* @__PURE__ */ jsxs(
147
+ "div",
148
+ {
149
+ ref: panelRef,
150
+ role: "dialog",
151
+ tabIndex: -1,
152
+ "data-og-annotation-review": "",
153
+ style: {
154
+ left: position.left,
155
+ top: position.top,
156
+ maxHeight: position.maxHeight,
157
+ ...portalStyle
158
+ },
159
+ className: "og-root fixed z-[75] box-border flex w-[min(25rem,calc(100vw-1.5rem))] flex-col overflow-hidden rounded-og-lg border border-og-border bg-og-surface-1 text-og-fg shadow-xl outline-hidden",
160
+ "aria-label": editable ? "Edit quoted notes" : "Quoted notes",
161
+ children: [
162
+ /* @__PURE__ */ jsxs(
163
+ "div",
164
+ {
165
+ ref: headerRef,
166
+ "data-og-annotation-review-header": "",
167
+ className: "flex shrink-0 items-start justify-between gap-3 px-3 pt-3 pb-2",
168
+ children: [
169
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 pt-0.5 text-og-sm font-medium text-og-fg-muted", children: countLabel }),
170
+ /* @__PURE__ */ jsx(
171
+ "button",
172
+ {
173
+ type: "button",
174
+ className: "inline-flex size-8 shrink-0 items-center justify-center rounded-md border-0 bg-transparent text-og-fg-muted outline-hidden hover:bg-og-surface-2 hover:text-og-fg focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:size-11",
175
+ "aria-label": "Close",
176
+ onClick: () => onDismiss(true),
177
+ children: /* @__PURE__ */ jsx(XIcon, { className: "size-3.5", "aria-hidden": "true" })
178
+ }
179
+ )
180
+ ]
181
+ }
182
+ ),
183
+ /* @__PURE__ */ jsx(
184
+ "div",
185
+ {
186
+ ref: listRef,
187
+ "data-og-annotation-review-list": "",
188
+ className: "grid min-h-0 flex-1 gap-2.5 overflow-x-hidden overflow-y-auto overscroll-contain px-3 pb-3",
189
+ children: annotations.map((annotation, index) => {
190
+ const ordinal = annotationDisplayOrdinal(annotation, index);
191
+ return /* @__PURE__ */ jsx(
192
+ "section",
193
+ {
194
+ "data-og-annotation-id": annotation.id,
195
+ "aria-label": `Annotation ${ordinal}`,
196
+ children: /* @__PURE__ */ jsxs(AnnotationAccentRow, { children: [
197
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-1", children: [
198
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
199
+ /* @__PURE__ */ jsxs("p", { className: "mb-0.5 text-og-xs font-medium tabular-nums text-og-fg-subtle", children: [
200
+ "Annotation ",
201
+ ordinal
202
+ ] }),
203
+ /* @__PURE__ */ jsx(
204
+ AnnotationQuoteSourceButton,
205
+ {
206
+ annotation,
207
+ lines: 2,
208
+ onRevealSource,
209
+ onUnavailable: setUnavailableId
210
+ }
211
+ )
212
+ ] }),
213
+ editable && onRemove ? /* @__PURE__ */ jsx(
214
+ "button",
215
+ {
216
+ type: "button",
217
+ className: "inline-flex size-7 shrink-0 items-center justify-center rounded-md border-0 bg-transparent text-og-fg-subtle outline-hidden hover:bg-og-surface-1 hover:text-og-status-failed focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:size-11",
218
+ "aria-label": `Remove annotation ${ordinal}`,
219
+ onClick: () => onRemove(annotation.id),
220
+ children: /* @__PURE__ */ jsx(XIcon, { className: "size-3.5", "aria-hidden": "true" })
221
+ }
222
+ ) : null
223
+ ] }),
224
+ unavailableId === annotation.id ? /* @__PURE__ */ jsx("p", { role: "status", className: "text-og-xs text-og-status-waiting", children: "Source is outside the loaded timeline window." }) : null,
225
+ editable && onUpdate ? /* @__PURE__ */ jsx(
226
+ AnnotationNoteField,
227
+ {
228
+ annotation,
229
+ inputRef: (node) => {
230
+ if (node) noteRefs.current.set(annotation.id, node);
231
+ else noteRefs.current.delete(annotation.id);
232
+ },
233
+ onUpdate,
234
+ onCommit: () => commitNotes(annotation.id)
235
+ }
236
+ ) : /* @__PURE__ */ jsx(
237
+ AnnotationNotePreview,
238
+ {
239
+ note: annotation.note,
240
+ annotationId: annotation.id,
241
+ ordinal
242
+ }
243
+ )
244
+ ] })
245
+ },
246
+ annotation.id
247
+ );
248
+ })
249
+ }
250
+ )
251
+ ]
252
+ }
253
+ ),
254
+ document.body
255
+ );
256
+ }
257
+ var timeline_annotations_dialog_default = TimelineAnnotationsDialog;
258
+ export {
259
+ TimelineAnnotationsDialog,
260
+ timeline_annotations_dialog_default as default
261
+ };
262
+ //# sourceMappingURL=timeline-annotations-dialog-6Q53N5FG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/timeline-annotations-dialog.tsx"],"sourcesContent":["import type { TimelineAnnotationSource } from \"@opengeni/sdk\";\nimport { XIcon } from \"lucide-react\";\nimport { useEffect, useLayoutEffect, useRef, useState, type RefObject } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { usePortalTokenStyle } from \"../lib/use-portal-token-style\";\nimport {\n AnnotationAccentRow,\n AnnotationNoteField,\n AnnotationNotePreview,\n AnnotationQuoteSourceButton,\n type TimelineAnnotationLike,\n} from \"./timeline-annotation-chrome\";\nimport {\n ANNOTATION_REVIEW_DIALOG_WIDTH_PX,\n clampAnnotationDialogPlacement,\n scrollAnnotationRowIntoList,\n} from \"./timeline-annotation-layout\";\nimport { annotationDisplayOrdinal, cssEscapeAttribute } from \"./timeline-annotation-shared\";\n\nfunction focusableElements(root: HTMLElement): HTMLElement[] {\n return [\n ...root.querySelectorAll<HTMLElement>(\n 'button:not([disabled]),textarea:not([disabled]),input:not([disabled]),[href],[tabindex]:not([tabindex=\"-1\"])',\n ),\n ].filter((element) => element.tabIndex >= 0 && !element.closest(\"[inert]\"));\n}\n\nexport function TimelineAnnotationsDialog({\n annotations,\n editable,\n focusAnnotationId,\n onFocusConsumed,\n onUpdate,\n onRemove,\n onRevealSource,\n triggerRef,\n countLabel,\n onDismiss,\n}: {\n annotations: readonly TimelineAnnotationLike[];\n editable: boolean;\n focusAnnotationId?: string | null | undefined;\n onFocusConsumed?: (() => void) | undefined;\n onUpdate?: ((id: string, note: string) => void) | undefined;\n onRemove?: ((id: string) => void) | undefined;\n onRevealSource?: ((source: TimelineAnnotationSource) => boolean) | undefined;\n triggerRef: RefObject<HTMLButtonElement | null>;\n countLabel: string;\n onDismiss: (restoreFocus: boolean) => void;\n}) {\n const [unavailableId, setUnavailableId] = useState<string | null>(null);\n const [position, setPosition] = useState({ left: 12, top: 12, maxHeight: 0 });\n const panelRef = useRef<HTMLDivElement | null>(null);\n const headerRef = useRef<HTMLDivElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const noteRefs = useRef(new Map<string, HTMLTextAreaElement>());\n const portalStyle = usePortalTokenStyle(triggerRef.current);\n const revealNote = (id: string) => {\n const row = listRef.current?.querySelector<HTMLElement>(\n `[data-og-annotation-id=\"${cssEscapeAttribute(id)}\"]`,\n );\n scrollAnnotationRowIntoList(listRef.current, row);\n noteRefs.current.get(id)?.focus();\n };\n\n const commitNotes = (fromId: string) => {\n const incomplete = annotations.filter((annotation) => {\n const live = noteRefs.current.get(annotation.id);\n return (live?.value ?? annotation.note).trim().length === 0;\n });\n if (incomplete.length === 0) {\n onDismiss(true);\n return;\n }\n const fromIndex = annotations.findIndex((annotation) => annotation.id === fromId);\n const next =\n incomplete.find(\n (item) => annotations.findIndex((annotation) => annotation.id === item.id) > fromIndex,\n ) ?? incomplete[0]!;\n revealNote(next.id);\n };\n\n useLayoutEffect(() => {\n const updatePosition = () => {\n const rect = triggerRef.current?.getBoundingClientRect();\n if (!rect) return;\n const contentHeight =\n (headerRef.current?.offsetHeight ?? 44) + (listRef.current?.scrollHeight ?? 200);\n setPosition(\n clampAnnotationDialogPlacement({\n triggerLeft: rect.left,\n triggerTop: rect.top,\n triggerBottom: rect.bottom,\n contentHeight,\n viewportWidth: window.innerWidth,\n viewportHeight: window.innerHeight,\n panelWidth: ANNOTATION_REVIEW_DIALOG_WIDTH_PX,\n }),\n );\n };\n updatePosition();\n window.addEventListener(\"resize\", updatePosition);\n window.addEventListener(\"scroll\", updatePosition, true);\n return () => {\n window.removeEventListener(\"resize\", updatePosition);\n window.removeEventListener(\"scroll\", updatePosition, true);\n };\n }, [annotations, triggerRef]);\n\n useLayoutEffect(() => {\n if (!focusAnnotationId || position.maxHeight <= 0) return;\n revealNote(focusAnnotationId);\n const note = noteRefs.current.get(focusAnnotationId);\n if (note && document.activeElement === note) onFocusConsumed?.();\n }, [focusAnnotationId, onFocusConsumed, annotations.length, position.maxHeight]);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.stopPropagation();\n onDismiss(true);\n return;\n }\n if (event.key !== \"Tab\" || !panelRef.current) return;\n const focusable = focusableElements(panelRef.current);\n if (focusable.length === 0) return;\n const first = focusable[0]!;\n const last = focusable[focusable.length - 1]!;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n const onPointerDown = (event: PointerEvent) => {\n if (!(event.target instanceof Node)) return;\n if (panelRef.current?.contains(event.target) || triggerRef.current?.contains(event.target)) {\n return;\n }\n onDismiss(false);\n };\n document.addEventListener(\"keydown\", onKeyDown);\n document.addEventListener(\"pointerdown\", onPointerDown);\n if (!focusAnnotationId) {\n window.setTimeout(() => {\n if (document.activeElement === triggerRef.current) panelRef.current?.focus();\n }, 0);\n }\n return () => {\n document.removeEventListener(\"keydown\", onKeyDown);\n document.removeEventListener(\"pointerdown\", onPointerDown);\n };\n }, [focusAnnotationId, onDismiss, triggerRef]);\n\n if (typeof document === \"undefined\") return null;\n return createPortal(\n <div\n ref={panelRef}\n role=\"dialog\"\n tabIndex={-1}\n data-og-annotation-review=\"\"\n style={{\n left: position.left,\n top: position.top,\n maxHeight: position.maxHeight,\n ...portalStyle,\n }}\n className=\"og-root fixed z-[75] box-border flex w-[min(25rem,calc(100vw-1.5rem))] flex-col overflow-hidden rounded-og-lg border border-og-border bg-og-surface-1 text-og-fg shadow-xl outline-hidden\"\n aria-label={editable ? \"Edit quoted notes\" : \"Quoted notes\"}\n >\n <div\n ref={headerRef}\n data-og-annotation-review-header=\"\"\n className=\"flex shrink-0 items-start justify-between gap-3 px-3 pt-3 pb-2\"\n >\n <p className=\"min-w-0 pt-0.5 text-og-sm font-medium text-og-fg-muted\">{countLabel}</p>\n <button\n type=\"button\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-md border-0 bg-transparent text-og-fg-muted outline-hidden hover:bg-og-surface-2 hover:text-og-fg focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:size-11\"\n aria-label=\"Close\"\n onClick={() => onDismiss(true)}\n >\n <XIcon className=\"size-3.5\" aria-hidden=\"true\" />\n </button>\n </div>\n <div\n ref={listRef}\n data-og-annotation-review-list=\"\"\n className=\"grid min-h-0 flex-1 gap-2.5 overflow-x-hidden overflow-y-auto overscroll-contain px-3 pb-3\"\n >\n {annotations.map((annotation, index) => {\n const ordinal = annotationDisplayOrdinal(annotation, index);\n return (\n <section\n key={annotation.id}\n data-og-annotation-id={annotation.id}\n aria-label={`Annotation ${ordinal}`}\n >\n <AnnotationAccentRow>\n <div className=\"flex items-start gap-1\">\n <div className=\"min-w-0 flex-1\">\n <p className=\"mb-0.5 text-og-xs font-medium tabular-nums text-og-fg-subtle\">\n Annotation {ordinal}\n </p>\n <AnnotationQuoteSourceButton\n annotation={annotation}\n lines={2}\n onRevealSource={onRevealSource}\n onUnavailable={setUnavailableId}\n />\n </div>\n {editable && onRemove ? (\n <button\n type=\"button\"\n className=\"inline-flex size-7 shrink-0 items-center justify-center rounded-md border-0 bg-transparent text-og-fg-subtle outline-hidden hover:bg-og-surface-1 hover:text-og-status-failed focus-visible:ring-2 focus-visible:ring-og-accent pointer-coarse:size-11\"\n aria-label={`Remove annotation ${ordinal}`}\n onClick={() => onRemove(annotation.id)}\n >\n <XIcon className=\"size-3.5\" aria-hidden=\"true\" />\n </button>\n ) : null}\n </div>\n {unavailableId === annotation.id ? (\n <p role=\"status\" className=\"text-og-xs text-og-status-waiting\">\n Source is outside the loaded timeline window.\n </p>\n ) : null}\n {editable && onUpdate ? (\n <AnnotationNoteField\n annotation={annotation}\n inputRef={(node) => {\n if (node) noteRefs.current.set(annotation.id, node);\n else noteRefs.current.delete(annotation.id);\n }}\n onUpdate={onUpdate}\n onCommit={() => commitNotes(annotation.id)}\n />\n ) : (\n <AnnotationNotePreview\n note={annotation.note}\n annotationId={annotation.id}\n ordinal={ordinal}\n />\n )}\n </AnnotationAccentRow>\n </section>\n );\n })}\n </div>\n </div>,\n document.body,\n );\n}\n\nexport default TimelineAnnotationsDialog;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,SAAS,aAAa;AACtB,SAAS,WAAW,iBAAiB,QAAQ,gBAAgC;AAC7E,SAAS,oBAAoB;AAyKvB,SAKE,KALF;AAzJN,SAAS,kBAAkB,MAAkC;AAC3D,SAAO;AAAA,IACL,GAAG,KAAK;AAAA,MACN;AAAA,IACF;AAAA,EACF,EAAE,OAAO,CAAC,YAAY,QAAQ,YAAY,KAAK,CAAC,QAAQ,QAAQ,SAAS,CAAC;AAC5E;AAEO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAWG;AACD,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AACtE,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,EAAE,MAAM,IAAI,KAAK,IAAI,WAAW,EAAE,CAAC;AAC5E,QAAM,WAAW,OAA8B,IAAI;AACnD,QAAM,YAAY,OAA8B,IAAI;AACpD,QAAM,UAAU,OAA8B,IAAI;AAClD,QAAM,WAAW,OAAO,oBAAI,IAAiC,CAAC;AAC9D,QAAM,cAAc,oBAAoB,WAAW,OAAO;AAC1D,QAAM,aAAa,CAAC,OAAe;AACjC,UAAM,MAAM,QAAQ,SAAS;AAAA,MAC3B,2BAA2B,mBAAmB,EAAE,CAAC;AAAA,IACnD;AACA,gCAA4B,QAAQ,SAAS,GAAG;AAChD,aAAS,QAAQ,IAAI,EAAE,GAAG,MAAM;AAAA,EAClC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C;AAAA;AAAA,4BACC,MAAK;AAAA,4BACL,WAAU;AAAA,4BACV,cAAY,qBAAqB,OAAO;AAAA,4BACxC,SAAS,MAAM,SAAS,WAAW,EAAE;AAAA,4BAErC,8BAAC,SAAM,WAAU,YAAW,eAAY,QAAO;AAAA;AAAA,wBACjD,IACE;AAAA,yBACN;AAAA,sBACC,kBAAkB,WAAW,KAC5B,oBAAC,OAAE,MAAK,UAAS,WAAU,qCAAoC,2DAE/D,IACE;AAAA,sBACH,YAAY,WACX;AAAA,wBAAC;AAAA;AAAA,0BACC;AAAA,0BACA,UAAU,CAAC,SAAS;AAClB,gCAAI,KAAM,UAAS,QAAQ,IAAI,WAAW,IAAI,IAAI;AAAA,gCAC7C,UAAS,QAAQ,OAAO,WAAW,EAAE;AAAA,0BAC5C;AAAA,0BACA;AAAA,0BACA,UAAU,MAAM,YAAY,WAAW,EAAE;AAAA;AAAA,sBAC3C,IAEA;AAAA,wBAAC;AAAA;AAAA,0BACC,MAAM,WAAW;AAAA,0BACjB,cAAc,WAAW;AAAA,0BACzB;AAAA;AAAA,sBACF;AAAA,uBAEJ;AAAA;AAAA,kBAlDK,WAAW;AAAA,gBAmDlB;AAAA,cAEJ,CAAC;AAAA;AAAA,UACH;AAAA;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;AAEA,IAAO,sCAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/react",
3
- "version": "3.7.0-canary.7",
3
+ "version": "3.8.0-canary.1",
4
4
  "description": "React hooks and styled components for OpenGeni: live session streaming, chat composer, message timeline, session status, and fleet views — token-themed (CSS variables), dark-first, built on Tailwind v4 + Radix + Motion.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -124,7 +124,7 @@
124
124
  "@dnd-kit/utilities": "3.2.2",
125
125
  "@fontsource-variable/noto-sans-arabic": "5.2.10",
126
126
  "@fontsource-variable/noto-sans-jp": "5.2.10",
127
- "@opengeni/sdk": "^3.7.0-canary.7",
127
+ "@opengeni/sdk": "^3.8.0-canary.1",
128
128
  "clsx": "^2.1.1",
129
129
  "dequal": "2.0.3",
130
130
  "lucide-react": "^1.8.0",
@@ -157,8 +157,11 @@ export function ChatComposer({
157
157
  <RestoredResources />
158
158
  <Attachments />
159
159
  {header}
160
- {composer.annotations && composer.annotations.length > 0 ? (
161
- <div className="px-3 pt-2 sm:px-4">
160
+ {composer.annotations &&
161
+ composer.annotations.length > 0 &&
162
+ composer.updateAnnotation &&
163
+ composer.removeAnnotation ? (
164
+ <div className="px-3.5 pt-2 md:px-4">
162
165
  <TimelineAnnotationsChip
163
166
  annotations={composer.annotations}
164
167
  editable