@cueloop/client 0.1.0-alpha.6 → 0.1.0-alpha.61

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 (161) hide show
  1. package/native/build-pty.sh +51 -0
  2. package/native/build.sh +82 -0
  3. package/native/darwin-arm64/libcuelooppty.dylib +0 -0
  4. package/native/darwin-arm64/libcueloopvt.dylib +0 -0
  5. package/native/src/pty.zig +193 -0
  6. package/native/src/shim.zig +114 -0
  7. package/package.json +37 -33
  8. package/src/App.appearance.test.tsx +51 -0
  9. package/src/App.autoclose.test.tsx +73 -47
  10. package/src/App.diff.test.tsx +169 -22
  11. package/src/App.export.test.tsx +49 -37
  12. package/src/App.plan-review.test.tsx +714 -0
  13. package/src/App.prototype.test.tsx +194 -0
  14. package/src/App.readonly.test.tsx +69 -35
  15. package/src/App.rendering.test.tsx +59 -31
  16. package/src/App.review-panel.test.tsx +143 -0
  17. package/src/App.submit-confirm.test.tsx +229 -0
  18. package/src/App.test.tsx +139 -68
  19. package/src/App.toast.test.tsx +77 -0
  20. package/src/App.tsx +0 -0
  21. package/src/App.walk.test.tsx +299 -0
  22. package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  23. package/src/app-key-state.ts +61 -0
  24. package/src/app-screens.tsx +270 -0
  25. package/src/app-view-model.ts +307 -0
  26. package/src/attribution.test.ts +31 -0
  27. package/src/attribution.ts +42 -0
  28. package/src/clipboard.test.ts +23 -0
  29. package/src/clipboard.ts +33 -0
  30. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  31. package/src/components/AnnotationCard.stories.tsx +94 -0
  32. package/src/components/AnnotationCard.tsx +250 -0
  33. package/src/components/Breadcrumb.stories.tsx +19 -0
  34. package/src/components/Breadcrumb.tsx +45 -0
  35. package/src/components/CodeBlock.stories.tsx +42 -0
  36. package/src/components/CodeBlock.tsx +84 -0
  37. package/src/components/CompletionOverlay.stories.tsx +23 -0
  38. package/src/components/CompletionOverlay.tsx +60 -0
  39. package/src/components/ConfirmCard.stories.tsx +35 -0
  40. package/src/components/ConfirmCard.tsx +129 -0
  41. package/src/components/ConfirmDialog.stories.tsx +21 -0
  42. package/src/components/ConfirmDialog.tsx +66 -0
  43. package/src/components/DiffSheet.scroll.test.tsx +135 -0
  44. package/src/components/DiffSheet.stories.tsx +78 -0
  45. package/src/components/DiffSheet.syntax.test.tsx +65 -0
  46. package/src/components/DiffSheet.tsx +374 -0
  47. package/src/components/InboxList.stories.tsx +31 -0
  48. package/src/components/InboxList.tsx +64 -0
  49. package/src/components/KeybindsDialog.stories.tsx +31 -0
  50. package/src/components/KeybindsDialog.tsx +59 -0
  51. package/src/components/MarkerPopover.stories.tsx +58 -0
  52. package/src/components/MarkerPopover.tsx +109 -0
  53. package/src/components/MenuBar.stories.tsx +37 -0
  54. package/src/components/MenuBar.tsx +75 -0
  55. package/src/components/PlanSheet.stories.tsx +113 -0
  56. package/src/components/PlanSheet.tsx +422 -0
  57. package/src/components/PromptDialog.stories.tsx +36 -0
  58. package/src/components/PromptDialog.tsx +80 -0
  59. package/src/components/PrototypeSheet.stories.tsx +20 -0
  60. package/src/components/PrototypeSheet.tsx +450 -0
  61. package/src/components/ReviewPanel.stories.tsx +86 -0
  62. package/src/components/ReviewPanel.tsx +103 -0
  63. package/src/components/ReviewRail.stories.tsx +218 -0
  64. package/src/components/ReviewRail.tsx +318 -0
  65. package/src/components/SettingsDialog.stories.tsx +111 -0
  66. package/src/components/SettingsDialog.tsx +147 -0
  67. package/src/components/SettingsRows.stories.tsx +18 -0
  68. package/src/components/SettingsRows.tsx +112 -0
  69. package/src/components/Toast.stories.tsx +12 -0
  70. package/src/components/Toast.tsx +45 -0
  71. package/src/components/WalkWizard.stories.tsx +100 -0
  72. package/src/components/WalkWizard.tsx +152 -0
  73. package/src/components/__snapshots__/stories.test.tsx.snap +1857 -0
  74. package/src/components/agent-launcher.stories.tsx +26 -0
  75. package/src/components/agent-launcher.test.tsx +50 -0
  76. package/src/components/agent-launcher.tsx +149 -0
  77. package/src/components/diff-sheet-layout.test.ts +128 -0
  78. package/src/components/diff-sheet-layout.ts +184 -0
  79. package/src/components/plan-sheet-run-style.ts +90 -0
  80. package/src/components/primitives/Button.stories.tsx +32 -0
  81. package/src/components/primitives/Button.tsx +52 -0
  82. package/src/components/primitives/Card.stories.tsx +25 -0
  83. package/src/components/primitives/Card.tsx +60 -0
  84. package/src/components/primitives/Dialog.stories.tsx +24 -0
  85. package/src/components/primitives/Dialog.tsx +66 -0
  86. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  87. package/src/components/primitives/StatusBar.tsx +23 -0
  88. package/src/components/primitives/Tabs.stories.tsx +29 -0
  89. package/src/components/primitives/Tabs.tsx +102 -0
  90. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  91. package/src/components/primitives/Toolbar.tsx +14 -0
  92. package/src/components/primitives/frame.test.ts +12 -0
  93. package/src/components/primitives/frame.ts +14 -0
  94. package/src/components/quick-actions-editor.stories.tsx +54 -0
  95. package/src/components/quick-actions-editor.tsx +138 -0
  96. package/src/components/stories-app.tsx +124 -0
  97. package/src/components/stories.test.tsx +66 -0
  98. package/src/components/story-fixtures.ts +98 -0
  99. package/src/components/story.ts +75 -0
  100. package/src/components/syntax-highlight.ts +102 -0
  101. package/src/components/terminal-pane.test.tsx +40 -0
  102. package/src/components/terminal-pane.ts +193 -0
  103. package/src/components/theme-context.stories.tsx +46 -0
  104. package/src/components/theme-context.tsx +37 -0
  105. package/src/components/truncate-text.ts +7 -0
  106. package/src/config.test.ts +448 -31
  107. package/src/config.ts +339 -57
  108. package/src/diff-hunk-curate.test.ts +315 -0
  109. package/src/diff-hunk-curate.ts +253 -0
  110. package/src/diff-intraline.test.ts +165 -0
  111. package/src/diff-intraline.ts +146 -0
  112. package/src/diff-syntax.test.ts +96 -0
  113. package/src/diff-syntax.ts +176 -0
  114. package/src/editor.test.ts +149 -0
  115. package/src/editor.ts +135 -9
  116. package/src/ghostty-terminal.test.ts +84 -0
  117. package/src/ghostty-terminal.ts +176 -0
  118. package/src/herdr.test.ts +9 -34
  119. package/src/herdr.ts +17 -21
  120. package/src/index.ts +10 -0
  121. package/src/integrations.test.ts +41 -0
  122. package/src/integrations.ts +32 -0
  123. package/src/intent-dispatch.test.ts +499 -0
  124. package/src/intent-dispatch.ts +585 -0
  125. package/src/key-bindings.test.ts +156 -0
  126. package/src/key-bindings.ts +452 -0
  127. package/src/keymap.test.ts +635 -0
  128. package/src/keymap.ts +404 -0
  129. package/src/kitty-image.test.ts +66 -0
  130. package/src/kitty-image.ts +138 -0
  131. package/src/prototype-browser.test.ts +56 -0
  132. package/src/prototype-browser.ts +289 -0
  133. package/src/pty.test.ts +81 -0
  134. package/src/pty.ts +237 -0
  135. package/src/review-panel.test.ts +113 -0
  136. package/src/review-panel.ts +83 -0
  137. package/src/run.ts +16 -5
  138. package/src/serve.test.ts +25 -9
  139. package/src/serve.ts +19 -8
  140. package/src/session-controller.curate.test.ts +260 -0
  141. package/src/session-controller.share.test.ts +320 -0
  142. package/src/session-controller.ts +993 -0
  143. package/src/share.ts +120 -0
  144. package/src/test-support.test.ts +60 -0
  145. package/src/test-support.ts +197 -0
  146. package/src/theme-presets.test.ts +51 -0
  147. package/src/theme-presets.ts +187 -0
  148. package/src/theme.ts +64 -17
  149. package/src/use-settings-dialog.tsx +275 -0
  150. package/src/version.ts +5 -0
  151. package/src/view-diff.test.ts +22 -8
  152. package/src/view-diff.ts +39 -23
  153. package/src/view-plan.regression.test.ts +60 -0
  154. package/src/view-plan.test.ts +406 -0
  155. package/src/view-plan.ts +554 -0
  156. package/src/walk.test.ts +121 -0
  157. package/src/walk.ts +74 -0
  158. package/src/syntax.test.ts +0 -41
  159. package/src/syntax.ts +0 -88
  160. package/src/view.test.ts +0 -157
  161. package/src/view.ts +0 -0
@@ -0,0 +1,422 @@
1
+ /**
2
+ * The plan document sheet: header chrome, the reconciliation banner, and the
3
+ * scrollable block flow. Each prose block renders as one natively wrapped
4
+ * text (wrapMode "word") beside a marker gutter, so wrapping is the
5
+ * renderer's job; the sheet keeps the rendered/work offset mapping per block
6
+ * and exposes an imperative selection surface - the keyboard span drives the
7
+ * native selection, and a mouse drag reads back as an exact work-text range,
8
+ * which keeps quote anchors char-precise.
9
+ */
10
+
11
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
12
+ import { useRenderer } from "@opentui/react";
13
+ import { type ScrollBoxRenderable, type TextRenderable } from "@opentui/core";
14
+ import type { ReviewSession } from "@cueloop/schema";
15
+ import {
16
+ blockRuns,
17
+ displayText,
18
+ overlayMarks,
19
+ renderedOffsetAtOrAfter,
20
+ renderedOffsetAtOrBefore,
21
+ safeLinkHref,
22
+ workRangeForRendered,
23
+ type DisplayBlock,
24
+ type Mark,
25
+ type SpanState,
26
+ type StyleRun,
27
+ } from "../view-plan";
28
+ import type { Theme } from "../theme";
29
+ import { useComponentTheme } from "./theme-context";
30
+ import { CodeBlock } from "./CodeBlock";
31
+ import { AnnotationCard, type AnnotationDraft } from "./AnnotationCard";
32
+ import { MarkerPopover, type MarkerPopoverProps } from "./MarkerPopover";
33
+ import { FRAME_BORDER_STYLE } from "./primitives/frame";
34
+ import { runStyle } from "./plan-sheet-run-style";
35
+
36
+ /** The popover toolbar card is 3 rows tall and sits flush above the marked words. */
37
+ const POPOVER_ROWS_ABOVE = 3;
38
+ /** Widest toolbar row ("comment · cut · actions · [x]") plus border and padding. */
39
+ const POPOVER_TOOLBAR_COLUMNS = 33;
40
+
41
+ export interface PlanSelection {
42
+ displayIndex: number;
43
+ start: number;
44
+ end: number;
45
+ }
46
+
47
+ export interface PlanSheetHandle {
48
+ /** Work-text range of the current native (mouse) selection, if any. */
49
+ /** The current native selection; `preferredIndex` (the mouse-up block) re-anchors a fresh drag. */
50
+ readSelection(preferredIndex?: number): PlanSelection | null;
51
+ /** Anchor/extend the renderer's native selection from keyboard span offsets. */
52
+ driveSpanSelection(span: SpanState): void;
53
+ clearSelection(): void;
54
+ revealBlock(displayIndex: number): void;
55
+ }
56
+
57
+ export interface PlanComposeState {
58
+ kind: "comment";
59
+ displayIndex: number;
60
+ quote: string;
61
+ draft: AnnotationDraft;
62
+ }
63
+
64
+ /** The marker-actions popover, rendered inline at its block while span mode is live. */
65
+ export interface PlanPopoverState extends MarkerPopoverProps {
66
+ displayIndex: number;
67
+ }
68
+
69
+ export interface PlanSheetProps {
70
+ session: ReviewSession;
71
+ display: DisplayBlock[];
72
+ marks: Map<number, Mark[]>;
73
+ cursor: number;
74
+ /** Extra selection-style paint on one block (keyboard span or compose anchor). */
75
+ activeSpan: { displayIndex: number; start: number; end: number } | null;
76
+ compose: PlanComposeState | null;
77
+ /** The marker-actions popover for the span's block; null when not in span mode. */
78
+ popover: PlanPopoverState | null;
79
+ editOrphanCount: number;
80
+ onLineActivate: (displayIndex: number) => void;
81
+ /**
82
+ * Fires on any mouse release inside the sheet. A drag released outside a
83
+ * block's text (the gutter, past a line end, a gap between blocks) never
84
+ * reaches a block's own handler, so this fallback lets the app still turn
85
+ * the finished drag's native selection into a span.
86
+ */
87
+ onSelectionRelease?: () => void;
88
+ theme?: Theme;
89
+ }
90
+
91
+ interface BlockRef {
92
+ renderable: TextRenderable;
93
+ runs: StyleRun[];
94
+ }
95
+
96
+ /** Screen position of a rendered-text offset inside a wrapped text. */
97
+ function positionOfRenderedOffset(
98
+ renderable: TextRenderable,
99
+ renderedOffset: number,
100
+ ): { x: number; y: number } {
101
+ const info = renderable.lineInfo;
102
+ let lineIndex = 0;
103
+
104
+ for (let index = 0; index < info.lineStartCols.length; index++) {
105
+ if (info.lineStartCols[index]! <= renderedOffset) lineIndex = index;
106
+ else break;
107
+ }
108
+
109
+ return {
110
+ x: renderable.x + renderedOffset - (info.lineStartCols[lineIndex] ?? 0),
111
+ y: renderable.y + lineIndex,
112
+ };
113
+ }
114
+
115
+ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function PlanSheet(
116
+ {
117
+ display,
118
+ marks,
119
+ cursor,
120
+ activeSpan,
121
+ compose,
122
+ popover,
123
+ editOrphanCount,
124
+ onLineActivate,
125
+ onSelectionRelease,
126
+ theme,
127
+ }: PlanSheetProps,
128
+ handleRef,
129
+ ): React.ReactNode {
130
+ const tokens = useComponentTheme(theme);
131
+ const renderer = useRenderer();
132
+ const blockRefs = useRef(new Map<number, BlockRef>());
133
+ const scrollRef = useRef<ScrollBoxRenderable | null>(null);
134
+
135
+ useImperativeHandle(handleRef, () => ({
136
+ readSelection: (preferredIndex?: number): PlanSelection | null => {
137
+ if (!renderer?.hasSelection) return null;
138
+ const readBlock = (displayIndex: number): PlanSelection | null => {
139
+ const blockRef = blockRefs.current.get(displayIndex);
140
+
141
+ if (!blockRef) return null;
142
+ const selection = blockRef.renderable.getSelection();
143
+
144
+ if (!selection || selection.end <= selection.start) return null;
145
+ const range = workRangeForRendered(blockRef.runs, selection.start, selection.end);
146
+
147
+ return range ? { displayIndex, ...range } : null;
148
+ };
149
+
150
+ // the block the mouse released on wins, so a fresh drag re-anchors the span
151
+ // (one marker at a time) instead of sticking to the topmost prior selection
152
+ if (preferredIndex !== undefined) {
153
+ const preferred = readBlock(preferredIndex);
154
+
155
+ if (preferred) return preferred;
156
+ }
157
+ for (const displayIndex of [...blockRefs.current.keys()].sort(
158
+ (left, right) => left - right,
159
+ )) {
160
+ const found = readBlock(displayIndex);
161
+
162
+ if (found) return found;
163
+ }
164
+
165
+ return null;
166
+ },
167
+ driveSpanSelection: (span: SpanState): void => {
168
+ if (!renderer) return;
169
+ const blockRef = blockRefs.current.get(span.displayIndex);
170
+
171
+ if (!blockRef) return;
172
+ // a span over an emphasized word starts/ends on concealed markers with
173
+ // no rendered cell; snap to the visible characters inside them
174
+ const renderedStart = renderedOffsetAtOrAfter(blockRef.runs, span.start);
175
+ const renderedEnd = renderedOffsetAtOrBefore(blockRef.runs, span.end - 1);
176
+
177
+ if (renderedStart === null || renderedEnd === null || renderedEnd < renderedStart) return;
178
+ const startPosition = positionOfRenderedOffset(blockRef.renderable, renderedStart);
179
+ const endPosition = positionOfRenderedOffset(blockRef.renderable, renderedEnd);
180
+
181
+ renderer.startSelection(blockRef.renderable, startPosition.x, startPosition.y);
182
+ renderer.updateSelection(blockRef.renderable, endPosition.x + 1, endPosition.y);
183
+ },
184
+ clearSelection: (): void => {
185
+ renderer?.clearSelection();
186
+ },
187
+ revealBlock: (displayIndex: number): void => {
188
+ try {
189
+ scrollRef.current?.scrollChildIntoView(`plan-block-${displayIndex}`);
190
+ } catch {
191
+ // reveal is best-effort; selection state is already correct
192
+ }
193
+ },
194
+ }));
195
+
196
+ // the popover sits flush above the marked words, anchored to the
197
+ // selection start mapped through the wrap geometry (line + column, not the
198
+ // block's linear offset). It renders as the LAST child of the scrollbox in
199
+ // content coordinates: content coordinates are scroll-invariant so the card
200
+ // tracks its block, and the last sibling paints over every block it floats
201
+ // across. Flips below when the line sits too near the viewport top.
202
+ const [popoverTop, setPopoverTop] = useState(0);
203
+ const [popoverLeft, setPopoverLeft] = useState(2);
204
+ // a terminal resize rewraps every block; re-run the anchor math against the
205
+ // new geometry instead of leaving the card at its pre-resize cell
206
+ const [resizeEpoch, setResizeEpoch] = useState(0);
207
+
208
+ useEffect(() => {
209
+ if (!renderer) return;
210
+ const onResize = (): void => setResizeEpoch((epoch) => epoch + 1);
211
+
212
+ renderer.on("resize", onResize);
213
+
214
+ return () => void renderer.off("resize", onResize);
215
+ }, [renderer]);
216
+ useEffect(() => {
217
+ if (!popover) return;
218
+ const blockRef = blockRefs.current.get(popover.displayIndex);
219
+ const scrollbox = scrollRef.current;
220
+
221
+ if (!blockRef || !scrollbox) return;
222
+ const renderedStart =
223
+ activeSpan && activeSpan.displayIndex === popover.displayIndex
224
+ ? (renderedOffsetAtOrAfter(blockRef.runs, activeSpan.start) ?? 0)
225
+ : 0;
226
+ const startPosition = positionOfRenderedOffset(blockRef.renderable, renderedStart);
227
+ const content = scrollbox.content;
228
+ const anchorLeft = startPosition.x - content.x;
229
+ const anchorTop = startPosition.y - content.y;
230
+ // clamp so the toolbar card never runs past the content's right edge
231
+ const maxLeft = Math.max(0, content.width - POPOVER_TOOLBAR_COLUMNS);
232
+
233
+ setPopoverLeft(Math.min(anchorLeft, maxLeft));
234
+ // only the toolbar (3 rows) + gap must fit above; the dropdown flows down
235
+ const lineViewportRow = startPosition.y - scrollbox.y;
236
+
237
+ setPopoverTop(anchorTop + (lineViewportRow < POPOVER_ROWS_ABOVE ? 1 : -POPOVER_ROWS_ABOVE));
238
+ }, [popover, activeSpan, display, cursor, resizeEpoch]);
239
+
240
+ const registerBlock = (
241
+ displayIndex: number,
242
+ renderable: TextRenderable | null,
243
+ runs: StyleRun[],
244
+ ): void => {
245
+ if (renderable) blockRefs.current.set(displayIndex, { renderable, runs });
246
+ else blockRefs.current.delete(displayIndex);
247
+ };
248
+
249
+ // stale refs must not survive a shrinking display list
250
+ useEffect(() => {
251
+ for (const displayIndex of blockRefs.current.keys()) {
252
+ if (displayIndex >= display.length) blockRefs.current.delete(displayIndex);
253
+ }
254
+ }, [display]);
255
+
256
+ const children: React.ReactNode[] = [];
257
+
258
+ for (let displayIndex = 0; displayIndex < display.length; displayIndex++) {
259
+ const block = display[displayIndex]!;
260
+ const isCursor = displayIndex === cursor;
261
+ const gap = topGap(display[displayIndex - 1], block);
262
+
263
+ if (block.kind === "code") {
264
+ children.push(
265
+ <CodeBlock
266
+ key={displayIndex}
267
+ id={`plan-block-${displayIndex}`}
268
+ language={(block.work ?? block.base)?.lang}
269
+ content={displayText(block)}
270
+ isCursor={isCursor}
271
+ marginTop={gap}
272
+ isAnnotated={(marks.get(displayIndex) ?? []).length > 0}
273
+ changeTag={showsChangeTag(block) ? tagLabel(block) : undefined}
274
+ cut={block.type === "del"}
275
+ theme={theme}
276
+ />,
277
+ );
278
+ } else {
279
+ const blockMarks = [...(marks.get(displayIndex) ?? [])];
280
+
281
+ if (activeSpan && activeSpan.displayIndex === displayIndex) {
282
+ blockMarks.push({ start: activeSpan.start, end: activeSpan.end, role: "kspan" });
283
+ }
284
+ const runs = overlayMarks(blockRuns(block, true), blockMarks);
285
+ // the change tag participates in the rendered text but carries no offsets;
286
+ // a cut block shows no tag (its strikethrough already reads as removed)
287
+ const mappedRuns: StyleRun[] = showsChangeTag(block)
288
+ ? [...runs, { text: ` [${tagLabel(block)}]`, role: "plain", start: null }]
289
+ : runs;
290
+
291
+ children.push(
292
+ <box
293
+ key={displayIndex}
294
+ id={`plan-block-${displayIndex}`}
295
+ style={{ flexDirection: "row", marginTop: gap }}
296
+ >
297
+ <text selectable={false}>
298
+ <span fg={isCursor ? tokens.accent : tokens.textDim}>{isCursor ? "▎ " : " "}</span>
299
+ <span fg={tokens.textDim}>{marker(block)}</span>
300
+ </text>
301
+ <text
302
+ bg={isCursor ? tokens.cursorBackground : undefined}
303
+ selectable
304
+ selectionBg={tokens.accent}
305
+ selectionFg={tokens.accentInk}
306
+ style={{ wrapMode: "word", flexGrow: 1, flexShrink: 1 }}
307
+ ref={(renderable: TextRenderable | null) =>
308
+ registerBlock(displayIndex, renderable, mappedRuns)
309
+ }
310
+ onMouseUp={() => onLineActivate(displayIndex)}
311
+ >
312
+ {runs.map((run, runIndex) => {
313
+ const url = run.role === "link" ? safeLinkHref(run.href) : undefined;
314
+
315
+ return (
316
+ <span
317
+ key={runIndex}
318
+ {...runStyle(run, block, tokens)}
319
+ {...(url ? { link: { url } } : {})}
320
+ >
321
+ {run.text}
322
+ </span>
323
+ );
324
+ })}
325
+ {showsChangeTag(block) ? (
326
+ <span fg={tagColor(block, tokens)}> [{tagLabel(block)}]</span>
327
+ ) : null}
328
+ </text>
329
+ </box>,
330
+ );
331
+ }
332
+ if (compose && compose.displayIndex === displayIndex) {
333
+ children.push(
334
+ <AnnotationCard
335
+ key={`compose-${displayIndex}`}
336
+ kind={compose.kind}
337
+ quote={compose.quote}
338
+ draft={compose.draft}
339
+ theme={theme}
340
+ />,
341
+ );
342
+ }
343
+ }
344
+ if (popover) {
345
+ // last child on purpose: later siblings paint on top, so the floating card
346
+ // covers every block it overlaps regardless of scroll position
347
+ children.push(
348
+ <box
349
+ key="marker-popover"
350
+ style={{
351
+ position: "absolute",
352
+ left: popoverLeft,
353
+ top: popoverTop,
354
+ flexDirection: "column",
355
+ }}
356
+ >
357
+ <MarkerPopover {...popover} theme={theme} />
358
+ </box>,
359
+ );
360
+ }
361
+
362
+ return (
363
+ <box style={{ flexGrow: 1, flexDirection: "column" }} onMouseUp={onSelectionRelease}>
364
+ <box
365
+ style={{
366
+ flexGrow: 1,
367
+ flexDirection: "column",
368
+ border: true,
369
+ borderStyle: FRAME_BORDER_STYLE,
370
+ borderColor: tokens.text,
371
+ }}
372
+ >
373
+ {editOrphanCount > 0 ? (
374
+ <box style={{ height: 1, backgroundColor: tokens.markCommentBackground, paddingLeft: 1 }}>
375
+ <text fg={tokens.red}>
376
+ {editOrphanCount} annotation{editOrphanCount === 1 ? "" : "s"} no longer match - the
377
+ passage was removed.
378
+ </text>
379
+ </box>
380
+ ) : null}
381
+ <scrollbox
382
+ ref={scrollRef}
383
+ style={{ flexGrow: 1, paddingLeft: 1, paddingTop: 0 }}
384
+ focused={false}
385
+ >
386
+ {children}
387
+ </scrollbox>
388
+ </box>
389
+ </box>
390
+ );
391
+ });
392
+
393
+ /** Vertical rhythm: gaps live ABOVE blocks so boundaries never collapse. */
394
+ function topGap(previous: DisplayBlock | undefined, current: DisplayBlock): number {
395
+ if (!previous) return 0;
396
+ const tightPair =
397
+ (current.kind === "li" && previous.kind === "li") ||
398
+ (current.kind === "oli" && previous.kind === "oli");
399
+
400
+ return tightPair ? 0 : 1;
401
+ }
402
+
403
+ function marker(block: DisplayBlock): string {
404
+ if (block.kind === "li") return "- ";
405
+ if (block.kind === "oli") return `${block.orderedItemNumber ?? 1}. `;
406
+ if (block.kind === "quote") return "▏ ";
407
+
408
+ return "";
409
+ }
410
+
411
+ /** An added or edited block earns a tag; a cut block relies on its strikethrough. */
412
+ function showsChangeTag(block: DisplayBlock): boolean {
413
+ return block.type === "add" || block.type === "mod";
414
+ }
415
+
416
+ function tagLabel(block: DisplayBlock): "new" | "edited" {
417
+ return block.type === "add" ? "new" : "edited";
418
+ }
419
+
420
+ function tagColor(block: DisplayBlock, tokens: Theme): string {
421
+ return block.type === "add" ? tokens.green : tokens.accent;
422
+ }
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { PromptDialog } from "./PromptDialog";
5
+
6
+ export const meta: StoryMeta = { title: "PromptDialog" };
7
+
8
+ export const RenameAuthor: Story = {
9
+ render: () => (
10
+ <PromptDialog
11
+ isOpen
12
+ title=" Rename author "
13
+ label="Display name for this collaborator:"
14
+ value="Robin"
15
+ placeholder="their name"
16
+ onInput={() => {}}
17
+ />
18
+ ),
19
+ expectedColors: [DARK.elevated, DARK.accent],
20
+ size: { width: 64, height: 16 },
21
+ };
22
+
23
+ export const NameYourself: Story = {
24
+ render: () => (
25
+ <PromptDialog
26
+ isOpen
27
+ title=" Welcome "
28
+ label="Your name (optional) - it attributes the notes you leave:"
29
+ value=""
30
+ placeholder="your name"
31
+ onInput={() => {}}
32
+ />
33
+ ),
34
+ expectedColors: [DARK.elevated],
35
+ size: { width: 64, height: 16 },
36
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * A centered single-field text prompt on the shared Dialog overlay. The focused
3
+ * input owns typing/cursor natively; the reducer's `prompt` overlay drives ⏎
4
+ * save / esc cancel (like the composer). Used to rename an author and to ask a
5
+ * collaborator for their name.
6
+ */
7
+
8
+ import React, { useEffect, useRef } from "react";
9
+ import { useTerminalDimensions } from "@opentui/react";
10
+ import type { KeyBinding, TextareaRenderable } from "@opentui/core";
11
+ import type { Theme } from "../theme";
12
+ import { useComponentTheme } from "./theme-context";
13
+ import { Dialog } from "./primitives/Dialog";
14
+
15
+ // ⏎ submits (suppresses the textarea's default newline); the grammar owns save.
16
+ const PROMPT_KEY_BINDINGS: KeyBinding[] = [{ name: "return", action: "submit" }];
17
+
18
+ export interface PromptDialogProps {
19
+ isOpen: boolean;
20
+ title?: string;
21
+ label: string;
22
+ value: string;
23
+ placeholder?: string;
24
+ onInput: (text: string) => void;
25
+ theme?: Theme;
26
+ }
27
+
28
+ export function PromptDialog({
29
+ isOpen,
30
+ title,
31
+ label,
32
+ value,
33
+ placeholder,
34
+ onInput,
35
+ theme,
36
+ }: PromptDialogProps): React.ReactNode {
37
+ const tokens = useComponentTheme(theme);
38
+ const { width: terminalWidth } = useTerminalDimensions();
39
+ const inputRef = useRef<TextareaRenderable | null>(null);
40
+
41
+ useEffect(() => {
42
+ // open with the caret after the seeded value, like a text field
43
+ if (inputRef.current) inputRef.current.cursorOffset = value.length;
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ }, []);
46
+ if (!isOpen) return null;
47
+
48
+ return (
49
+ <Dialog isOpen title={title} width={Math.min(54, terminalWidth - 6)} height={7} theme={theme}>
50
+ <box
51
+ style={{
52
+ flexDirection: "column",
53
+ flexGrow: 1,
54
+ paddingLeft: 1,
55
+ paddingRight: 1,
56
+ paddingTop: 1,
57
+ }}
58
+ >
59
+ <text fg={tokens.textDim}>{label}</text>
60
+ <textarea
61
+ ref={inputRef}
62
+ focused
63
+ initialValue={value}
64
+ placeholder={placeholder}
65
+ keyBindings={PROMPT_KEY_BINDINGS}
66
+ onContentChange={() => onInput(inputRef.current?.plainText ?? "")}
67
+ style={{
68
+ height: 1,
69
+ backgroundColor: tokens.elevated,
70
+ focusedBackgroundColor: tokens.elevated,
71
+ textColor: tokens.text,
72
+ focusedTextColor: tokens.text,
73
+ }}
74
+ />
75
+ <box style={{ flexGrow: 1 }} />
76
+ <text fg={tokens.textDim}>enter save · esc cancel</text>
77
+ </box>
78
+ </Dialog>
79
+ );
80
+ }
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { PrototypeSheet } from "./PrototypeSheet";
5
+
6
+ export const meta: StoryMeta = { title: "PrototypeSheet" };
7
+
8
+ // The story renderer reports no kitty graphics, so the sheet shows its fallback.
9
+ export const Unsupported: Story = {
10
+ render: () => (
11
+ <PrototypeSheet
12
+ prototypePath="/tmp/example.html"
13
+ quickActions={[]}
14
+ canComment={true}
15
+ onCommentElement={() => {}}
16
+ />
17
+ ),
18
+ expectedColors: [DARK.textDim],
19
+ size: { width: 80, height: 24 },
20
+ };