@cueloop/client 0.1.0-alpha.43 → 0.1.0-alpha.45
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/package.json +5 -5
- package/src/App.plan-review.test.tsx +9 -9
- package/src/App.readonly.test.tsx +3 -3
- package/src/App.submit-confirm.test.tsx +6 -8
- package/src/App.tsx +26 -21
- package/src/App.walk.test.tsx +2 -1
- package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
- package/src/components/AnnotationCard.stories.tsx +9 -9
- package/src/components/AnnotationCard.tsx +16 -10
- package/src/components/ConfirmCard.stories.tsx +3 -24
- package/src/components/ConfirmCard.tsx +8 -16
- package/src/components/MarkerPopover.tsx +7 -1
- package/src/components/PlanSheet.tsx +115 -48
- package/src/components/ReviewRail.stories.tsx +0 -2
- package/src/components/ReviewRail.tsx +2 -7
- package/src/components/__snapshots__/stories.test.tsx.snap +9 -9
- package/src/components/agent-launcher.tsx +1 -1
- package/src/theme.ts +2 -2
- package/src/view-plan.regression.test.ts +60 -0
- package/src/view-plan.test.ts +105 -0
- package/src/view-plan.ts +96 -9
|
@@ -16,7 +16,9 @@ import {
|
|
|
16
16
|
blockRuns,
|
|
17
17
|
displayText,
|
|
18
18
|
overlayMarks,
|
|
19
|
-
|
|
19
|
+
renderedOffsetAtOrAfter,
|
|
20
|
+
renderedOffsetAtOrBefore,
|
|
21
|
+
safeLinkHref,
|
|
20
22
|
workRangeForRendered,
|
|
21
23
|
type DisplayBlock,
|
|
22
24
|
type Mark,
|
|
@@ -33,6 +35,20 @@ import { FRAME_BORDER_STYLE } from "./primitives/frame";
|
|
|
33
35
|
/** A cut block reads as removed: struck through and grayed, never red. */
|
|
34
36
|
const CUT_ATTRIBUTES = createTextAttributes({ strikethrough: true, dim: true });
|
|
35
37
|
|
|
38
|
+
/** Inline-emphasis attributes, reused per run so the render loop allocates none. */
|
|
39
|
+
const STRONG_ATTRIBUTES = createTextAttributes({ bold: true });
|
|
40
|
+
const EM_ATTRIBUTES = createTextAttributes({ italic: true });
|
|
41
|
+
const STRIKE_ATTRIBUTES = createTextAttributes({ strikethrough: true });
|
|
42
|
+
const LINK_ATTRIBUTES = createTextAttributes({ underline: true });
|
|
43
|
+
/** Block-level base attributes: headings read bold, blockquotes read italic. */
|
|
44
|
+
const HEADING_ATTRIBUTES = createTextAttributes({ bold: true });
|
|
45
|
+
const QUOTE_ATTRIBUTES = createTextAttributes({ italic: true });
|
|
46
|
+
|
|
47
|
+
/** The popover toolbar card is 3 rows tall and sits flush above the marked words. */
|
|
48
|
+
const POPOVER_ROWS_ABOVE = 3;
|
|
49
|
+
/** Widest toolbar row ("comment · cut · actions · [x]") plus border and padding. */
|
|
50
|
+
const POPOVER_TOOLBAR_COLUMNS = 33;
|
|
51
|
+
|
|
36
52
|
export interface PlanSelection {
|
|
37
53
|
displayIndex: number;
|
|
38
54
|
start: number;
|
|
@@ -73,6 +89,13 @@ export interface PlanSheetProps {
|
|
|
73
89
|
popover: PlanPopoverState | null;
|
|
74
90
|
editOrphanCount: number;
|
|
75
91
|
onLineActivate: (displayIndex: number) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Fires on any mouse release inside the sheet. A drag released outside a
|
|
94
|
+
* block's text (the gutter, past a line end, a gap between blocks) never
|
|
95
|
+
* reaches a block's own handler, so this fallback lets the app still turn
|
|
96
|
+
* the finished drag's native selection into a span.
|
|
97
|
+
*/
|
|
98
|
+
onSelectionRelease?: () => void;
|
|
76
99
|
theme?: Theme;
|
|
77
100
|
}
|
|
78
101
|
|
|
@@ -108,6 +131,7 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
108
131
|
popover,
|
|
109
132
|
editOrphanCount,
|
|
110
133
|
onLineActivate,
|
|
134
|
+
onSelectionRelease,
|
|
111
135
|
theme,
|
|
112
136
|
}: PlanSheetProps,
|
|
113
137
|
handleRef,
|
|
@@ -146,9 +170,11 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
146
170
|
if (!renderer) return;
|
|
147
171
|
const blockRef = blockRefs.current.get(span.displayIndex);
|
|
148
172
|
if (!blockRef) return;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
173
|
+
// a span over an emphasized word starts/ends on concealed markers with
|
|
174
|
+
// no rendered cell; snap to the visible characters inside them
|
|
175
|
+
const renderedStart = renderedOffsetAtOrAfter(blockRef.runs, span.start);
|
|
176
|
+
const renderedEnd = renderedOffsetAtOrBefore(blockRef.runs, span.end - 1);
|
|
177
|
+
if (renderedStart === null || renderedEnd === null || renderedEnd < renderedStart) return;
|
|
152
178
|
const startPosition = positionOfRenderedOffset(blockRef.renderable, renderedStart);
|
|
153
179
|
const endPosition = positionOfRenderedOffset(blockRef.renderable, renderedEnd);
|
|
154
180
|
renderer.startSelection(blockRef.renderable, startPosition.x, startPosition.y);
|
|
@@ -166,24 +192,43 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
166
192
|
},
|
|
167
193
|
}));
|
|
168
194
|
|
|
169
|
-
// the popover
|
|
170
|
-
//
|
|
171
|
-
|
|
195
|
+
// the popover sits flush above the marked words, anchored to the
|
|
196
|
+
// selection start mapped through the wrap geometry (line + column, not the
|
|
197
|
+
// block's linear offset). It renders as the LAST child of the scrollbox in
|
|
198
|
+
// content coordinates: content coordinates are scroll-invariant so the card
|
|
199
|
+
// tracks its block, and the last sibling paints over every block it floats
|
|
200
|
+
// across. Flips below when the line sits too near the viewport top.
|
|
201
|
+
const [popoverTop, setPopoverTop] = useState(0);
|
|
172
202
|
const [popoverLeft, setPopoverLeft] = useState(2);
|
|
203
|
+
// a terminal resize rewraps every block; re-run the anchor math against the
|
|
204
|
+
// new geometry instead of leaving the card at its pre-resize cell
|
|
205
|
+
const [resizeEpoch, setResizeEpoch] = useState(0);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
if (!renderer) return;
|
|
208
|
+
const onResize = (): void => setResizeEpoch((epoch) => epoch + 1);
|
|
209
|
+
renderer.on("resize", onResize);
|
|
210
|
+
return () => void renderer.off("resize", onResize);
|
|
211
|
+
}, [renderer]);
|
|
173
212
|
useEffect(() => {
|
|
174
213
|
if (!popover) return;
|
|
175
214
|
const blockRef = blockRefs.current.get(popover.displayIndex);
|
|
176
215
|
const scrollbox = scrollRef.current;
|
|
177
216
|
if (!blockRef || !scrollbox) return;
|
|
178
|
-
|
|
179
|
-
setPopoverFlipBelow(blockRef.renderable.y - scrollbox.y < 4);
|
|
180
|
-
// left-anchor to the start of the selection: gutter width + its column
|
|
181
|
-
const startColumn =
|
|
217
|
+
const renderedStart =
|
|
182
218
|
activeSpan && activeSpan.displayIndex === popover.displayIndex
|
|
183
|
-
? (
|
|
219
|
+
? (renderedOffsetAtOrAfter(blockRef.runs, activeSpan.start) ?? 0)
|
|
184
220
|
: 0;
|
|
185
|
-
|
|
186
|
-
|
|
221
|
+
const startPosition = positionOfRenderedOffset(blockRef.renderable, renderedStart);
|
|
222
|
+
const content = scrollbox.content;
|
|
223
|
+
const anchorLeft = startPosition.x - content.x;
|
|
224
|
+
const anchorTop = startPosition.y - content.y;
|
|
225
|
+
// clamp so the toolbar card never runs past the content's right edge
|
|
226
|
+
const maxLeft = Math.max(0, content.width - POPOVER_TOOLBAR_COLUMNS);
|
|
227
|
+
setPopoverLeft(Math.min(anchorLeft, maxLeft));
|
|
228
|
+
// only the toolbar (3 rows) + gap must fit above; the dropdown flows down
|
|
229
|
+
const lineViewportRow = startPosition.y - scrollbox.y;
|
|
230
|
+
setPopoverTop(anchorTop + (lineViewportRow < POPOVER_ROWS_ABOVE ? 1 : -POPOVER_ROWS_ABOVE));
|
|
231
|
+
}, [popover, activeSpan, display, cursor, resizeEpoch]);
|
|
187
232
|
|
|
188
233
|
const registerBlock = (
|
|
189
234
|
displayIndex: number,
|
|
@@ -235,13 +280,7 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
235
280
|
<box
|
|
236
281
|
key={displayIndex}
|
|
237
282
|
id={`plan-block-${displayIndex}`}
|
|
238
|
-
|
|
239
|
-
// later blocks it floats across (siblings paint in z-index order)
|
|
240
|
-
style={{
|
|
241
|
-
flexDirection: "row",
|
|
242
|
-
marginTop: gap,
|
|
243
|
-
zIndex: popover?.displayIndex === displayIndex ? 10 : undefined,
|
|
244
|
-
}}
|
|
283
|
+
style={{ flexDirection: "row", marginTop: gap }}
|
|
245
284
|
>
|
|
246
285
|
<text selectable={false}>
|
|
247
286
|
<span fg={isCursor ? tokens.accent : tokens.textDim}>{isCursor ? "▎ " : " "}</span>
|
|
@@ -258,31 +297,22 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
258
297
|
}
|
|
259
298
|
onMouseUp={() => onLineActivate(displayIndex)}
|
|
260
299
|
>
|
|
261
|
-
{runs.map((run, runIndex) =>
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
300
|
+
{runs.map((run, runIndex) => {
|
|
301
|
+
const url = run.role === "link" ? safeLinkHref(run.href) : undefined;
|
|
302
|
+
return (
|
|
303
|
+
<span
|
|
304
|
+
key={runIndex}
|
|
305
|
+
{...runStyle(run, block, tokens)}
|
|
306
|
+
{...(url ? { link: { url } } : {})}
|
|
307
|
+
>
|
|
308
|
+
{run.text}
|
|
309
|
+
</span>
|
|
310
|
+
);
|
|
311
|
+
})}
|
|
266
312
|
{showsChangeTag(block) ? (
|
|
267
313
|
<span fg={tagColor(block, tokens)}> [{tagLabel(block)}]</span>
|
|
268
314
|
) : null}
|
|
269
315
|
</text>
|
|
270
|
-
{popover && popover.displayIndex === displayIndex ? (
|
|
271
|
-
// float the card over the block, centered, with a one-row gap; flip
|
|
272
|
-
// below only when there is no room above (near the viewport top)
|
|
273
|
-
<box
|
|
274
|
-
style={{
|
|
275
|
-
position: "absolute",
|
|
276
|
-
left: popoverLeft,
|
|
277
|
-
// fixed offset: the toolbar sits one row above the selection and
|
|
278
|
-
// stays put; the dropdown flows down from it, over the selection
|
|
279
|
-
top: popoverFlipBelow ? 1 : -4,
|
|
280
|
-
flexDirection: "column",
|
|
281
|
-
}}
|
|
282
|
-
>
|
|
283
|
-
<MarkerPopover {...popover} theme={theme} />
|
|
284
|
-
</box>
|
|
285
|
-
) : null}
|
|
286
316
|
</box>,
|
|
287
317
|
);
|
|
288
318
|
}
|
|
@@ -298,9 +328,26 @@ export const PlanSheet = forwardRef<PlanSheetHandle, PlanSheetProps>(function Pl
|
|
|
298
328
|
);
|
|
299
329
|
}
|
|
300
330
|
}
|
|
331
|
+
if (popover) {
|
|
332
|
+
// last child on purpose: later siblings paint on top, so the floating card
|
|
333
|
+
// covers every block it overlaps regardless of scroll position
|
|
334
|
+
children.push(
|
|
335
|
+
<box
|
|
336
|
+
key="marker-popover"
|
|
337
|
+
style={{
|
|
338
|
+
position: "absolute",
|
|
339
|
+
left: popoverLeft,
|
|
340
|
+
top: popoverTop,
|
|
341
|
+
flexDirection: "column",
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
<MarkerPopover {...popover} theme={theme} />
|
|
345
|
+
</box>,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
301
348
|
|
|
302
349
|
return (
|
|
303
|
-
<box style={{ flexGrow: 1, flexDirection: "column" }}>
|
|
350
|
+
<box style={{ flexGrow: 1, flexDirection: "column" }} onMouseUp={onSelectionRelease}>
|
|
304
351
|
<box
|
|
305
352
|
style={{
|
|
306
353
|
flexGrow: 1,
|
|
@@ -366,15 +413,25 @@ function runStyle(
|
|
|
366
413
|
): { fg?: string; bg?: string; attributes?: number } {
|
|
367
414
|
// a cut block reads as removed: every run struck through and grayed, never red
|
|
368
415
|
if (block.type === "del") return { fg: tokens.textDim, attributes: CUT_ATTRIBUTES };
|
|
416
|
+
const isHeading = block.kind === "h1" || block.kind === "h2" || block.kind === "h3";
|
|
417
|
+
const isQuote = block.kind === "quote";
|
|
418
|
+
// headings are all bold; level reads from descending brightness alone (a
|
|
419
|
+
// terminal cannot scale font size), leaving the salmon accent to annotations
|
|
369
420
|
const headingFg =
|
|
370
421
|
block.kind === "h1"
|
|
371
422
|
? tokens.text
|
|
372
|
-
: block.kind === "h2"
|
|
373
|
-
? tokens.
|
|
374
|
-
:
|
|
423
|
+
: block.kind === "h2"
|
|
424
|
+
? tokens.textMuted
|
|
425
|
+
: block.kind === "h3"
|
|
426
|
+
? tokens.textDim
|
|
427
|
+
: undefined;
|
|
428
|
+
// block-level base: headings bold, quotes muted italic; inline roles compose on top
|
|
429
|
+
const baseFg = headingFg ?? (isQuote ? tokens.textMuted : tokens.text);
|
|
430
|
+
const baseAttributes = (isHeading ? HEADING_ATTRIBUTES : 0) | (isQuote ? QUOTE_ATTRIBUTES : 0);
|
|
431
|
+
const withBase = (roleAttributes: number): number => baseAttributes | roleAttributes;
|
|
375
432
|
switch (run.role) {
|
|
376
433
|
case "ins":
|
|
377
|
-
return { fg: tokens.insertedForeground };
|
|
434
|
+
return { fg: tokens.insertedForeground, attributes: baseAttributes || undefined };
|
|
378
435
|
case "del":
|
|
379
436
|
return { fg: tokens.deletedForeground };
|
|
380
437
|
case "mark-comment":
|
|
@@ -383,7 +440,17 @@ function runStyle(
|
|
|
383
440
|
return { fg: tokens.accentInk, bg: tokens.accent };
|
|
384
441
|
case "kspan":
|
|
385
442
|
return { fg: tokens.accentInk, bg: tokens.accent };
|
|
443
|
+
case "strong":
|
|
444
|
+
return { fg: baseFg, attributes: withBase(STRONG_ATTRIBUTES) };
|
|
445
|
+
case "em":
|
|
446
|
+
return { fg: baseFg, attributes: withBase(EM_ATTRIBUTES) };
|
|
447
|
+
case "code":
|
|
448
|
+
return { fg: tokens.text, bg: tokens.elevated };
|
|
449
|
+
case "strike":
|
|
450
|
+
return { fg: tokens.textMuted, attributes: withBase(STRIKE_ATTRIBUTES) };
|
|
451
|
+
case "link":
|
|
452
|
+
return { fg: tokens.blue, attributes: withBase(LINK_ATTRIBUTES) };
|
|
386
453
|
default:
|
|
387
|
-
return { fg:
|
|
454
|
+
return { fg: baseFg, attributes: baseAttributes || undefined };
|
|
388
455
|
}
|
|
389
456
|
}
|
|
@@ -75,11 +75,6 @@ export interface ReviewRailProps {
|
|
|
75
75
|
theme?: Theme;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
/** Forward-compatible: open annotation kinds may carry a blocking flag. */
|
|
79
|
-
export function annotationBlocking(annotation: Annotation): boolean {
|
|
80
|
-
return (annotation as Annotation & { blocking?: boolean }).blocking === true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
78
|
export const ReviewRail = forwardRef<ReviewRailHandle, ReviewRailProps>(function ReviewRail(
|
|
84
79
|
{
|
|
85
80
|
session,
|
|
@@ -133,13 +128,13 @@ export const ReviewRail = forwardRef<ReviewRailHandle, ReviewRailProps>(function
|
|
|
133
128
|
body: annotation.body,
|
|
134
129
|
isSelected: annotation.id === selectedId,
|
|
135
130
|
isOrphan: resolvedIds !== null && !resolvedIds.has(annotation.id),
|
|
136
|
-
isBlocking: annotationBlocking(annotation),
|
|
137
131
|
// border-title author: a collaborator's name, "agent" for agent notes, else "me"
|
|
138
132
|
author: annotation.author
|
|
139
133
|
? resolveDisplayName(annotation.author, session.participants, authorNames)
|
|
140
134
|
: isAgentNote(annotation)
|
|
141
135
|
? "agent"
|
|
142
136
|
: "me",
|
|
137
|
+
tone: tokens.blue,
|
|
143
138
|
editing:
|
|
144
139
|
cardEdit && cardEdit.id === annotation.id
|
|
145
140
|
? {
|
|
@@ -293,7 +288,7 @@ function RemovalCard({
|
|
|
293
288
|
<Card
|
|
294
289
|
title={title}
|
|
295
290
|
contentRows={contentRows}
|
|
296
|
-
borderColor={
|
|
291
|
+
borderColor={tokens.red}
|
|
297
292
|
backgroundColor="transparent"
|
|
298
293
|
theme={theme}
|
|
299
294
|
>
|
|
@@ -84,8 +84,8 @@ exports[`stories catalog AnnotationCard/SavedEditing renders, snapshots, and car
|
|
|
84
84
|
"
|
|
85
85
|
`;
|
|
86
86
|
|
|
87
|
-
exports[`stories catalog AnnotationCard/
|
|
88
|
-
"╭─ COMMENT · me ·
|
|
87
|
+
exports[`stories catalog AnnotationCard/SavedOrphan renders, snapshots, and carries its colors: AnnotationCard/SavedOrphan 1`] = `
|
|
88
|
+
"╭─ COMMENT · me · ORPHANED ────────────────────────────────────────────────────╮
|
|
89
89
|
│ "a removed passage" │
|
|
90
90
|
│ The passage is gone. │
|
|
91
91
|
╰──────────────────────────────────────────────────────────────────────────────╯
|
|
@@ -338,8 +338,6 @@ exports[`stories catalog CompletionOverlay/FeedbackCounting renders, snapshots,
|
|
|
338
338
|
|
|
339
339
|
exports[`stories catalog ConfirmCard/ApproveDefault renders, snapshots, and carries its colors: ConfirmCard/ApproveDefault 1`] = `
|
|
340
340
|
"╭─ submit review ─────────────────────╮
|
|
341
|
-
│ 0 annotations · 0 blocking │
|
|
342
|
-
│ │
|
|
343
341
|
│ Comment [Approve] Changes │
|
|
344
342
|
│ │
|
|
345
343
|
│ summary for the agent (optional) │
|
|
@@ -351,13 +349,13 @@ exports[`stories catalog ConfirmCard/ApproveDefault renders, snapshots, and carr
|
|
|
351
349
|
|
|
352
350
|
|
|
353
351
|
|
|
352
|
+
|
|
353
|
+
|
|
354
354
|
"
|
|
355
355
|
`;
|
|
356
356
|
|
|
357
357
|
exports[`stories catalog ConfirmCard/RequestChanges renders, snapshots, and carries its colors: ConfirmCard/RequestChanges 1`] = `
|
|
358
358
|
"╭─ submit review ─────────────────────╮
|
|
359
|
-
│ 3 annotations · 1 blocking │
|
|
360
|
-
│ │
|
|
361
359
|
│ Comment Approve [Changes] │
|
|
362
360
|
│ │
|
|
363
361
|
│ Tighten the steps. │
|
|
@@ -369,12 +367,13 @@ exports[`stories catalog ConfirmCard/RequestChanges renders, snapshots, and carr
|
|
|
369
367
|
|
|
370
368
|
|
|
371
369
|
|
|
370
|
+
|
|
371
|
+
|
|
372
372
|
"
|
|
373
373
|
`;
|
|
374
374
|
|
|
375
375
|
exports[`stories catalog ConfirmCard/WithViewedSummary renders, snapshots, and carries its colors: ConfirmCard/WithViewedSummary 1`] = `
|
|
376
376
|
"╭─ submit review ─────────────────────╮
|
|
377
|
-
│ 1 annotations · 0 blocking │
|
|
378
377
|
│ 2/3 files viewed │
|
|
379
378
|
│ │
|
|
380
379
|
│ Comment [Approve] Changes │
|
|
@@ -387,6 +386,7 @@ exports[`stories catalog ConfirmCard/WithViewedSummary renders, snapshots, and c
|
|
|
387
386
|
|
|
388
387
|
|
|
389
388
|
|
|
389
|
+
|
|
390
390
|
"
|
|
391
391
|
`;
|
|
392
392
|
|
|
@@ -1121,9 +1121,9 @@ exports[`stories catalog ReviewRail/SubmitConfirmOpen renders, snapshots, and ca
|
|
|
1121
1121
|
|
|
1122
1122
|
|
|
1123
1123
|
|
|
1124
|
+
|
|
1125
|
+
|
|
1124
1126
|
╭─ submit review ───────────────╮
|
|
1125
|
-
│ 2 annotations · 0 blocking │
|
|
1126
|
-
│ │
|
|
1127
1127
|
│ Comment Approve [Changes] │
|
|
1128
1128
|
│ │
|
|
1129
1129
|
│ summary for the agent (optiona│
|
package/src/theme.ts
CHANGED
|
@@ -57,8 +57,8 @@ export const DARK: Theme = {
|
|
|
57
57
|
accent: "#f5a3a3",
|
|
58
58
|
accentInk: "#2a1416",
|
|
59
59
|
green: "#62d96b",
|
|
60
|
-
red: "#
|
|
61
|
-
blue: "#
|
|
60
|
+
red: "#f08080",
|
|
61
|
+
blue: "#a9c8f5",
|
|
62
62
|
cursorBackground: "#33262a",
|
|
63
63
|
markCommentBackground: "#3d2a2e",
|
|
64
64
|
insertedForeground: "#62d96b",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
blockRuns,
|
|
4
|
+
buildDisplay,
|
|
5
|
+
displayText,
|
|
6
|
+
renderedOffsetFor,
|
|
7
|
+
workRangeForRendered,
|
|
8
|
+
} from "./view-plan";
|
|
9
|
+
|
|
10
|
+
// M0 (#232): lock the renderer's current StyleRun output and offset round-trips
|
|
11
|
+
// before the inline-tokenizer milestones (M1-M5) change blockRuns. The snapshots
|
|
12
|
+
// capture today's runs, so a later milestone's diff is explicit and reviewable.
|
|
13
|
+
// The round-trip assertions are the durable invariant: a visible word's rendered
|
|
14
|
+
// selection must always recover that word's *source* (block.text) offsets, even
|
|
15
|
+
// once inline markers are concealed - this is what keeps quote anchors exact.
|
|
16
|
+
|
|
17
|
+
const DOC = `# Heading with **bold**
|
|
18
|
+
|
|
19
|
+
A paragraph with **strong**, *em*, \`code\`, ~~strike~~ and a [label](https://example.com).
|
|
20
|
+
|
|
21
|
+
- a list item with *emphasis*
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const blocks = buildDisplay(DOC);
|
|
25
|
+
|
|
26
|
+
describe("view-plan regression harness (M0)", () => {
|
|
27
|
+
test("blockRuns output is stable across the representative blocks", () => {
|
|
28
|
+
// Arrange / Act
|
|
29
|
+
const runsByBlock = blocks.map((block) => ({
|
|
30
|
+
type: block.type,
|
|
31
|
+
text: displayText(block),
|
|
32
|
+
runs: blockRuns(block, true),
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
// Assert
|
|
36
|
+
expect(runsByBlock).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// A visible word's source offsets survive the rendered round-trip. Holds at M0
|
|
40
|
+
// (1:1 today) and must keep holding once M2 conceals markers and the rendered
|
|
41
|
+
// offset shifts - the recovered work range stays the word's block.text span.
|
|
42
|
+
const paragraph = blocks.find((block) => displayText(block).includes("strong"))!;
|
|
43
|
+
const paragraphRuns = blockRuns(paragraph, true);
|
|
44
|
+
const paragraphText = displayText(paragraph);
|
|
45
|
+
|
|
46
|
+
for (const word of ["paragraph", "strong", "strike", "label"]) {
|
|
47
|
+
test(`rendered selection of "${word}" recovers its block.text offsets`, () => {
|
|
48
|
+
// Arrange
|
|
49
|
+
const start = paragraphText.indexOf(word);
|
|
50
|
+
const rendered = renderedOffsetFor(paragraphRuns, start);
|
|
51
|
+
|
|
52
|
+
// Assert
|
|
53
|
+
expect(rendered).not.toBeNull();
|
|
54
|
+
expect(workRangeForRendered(paragraphRuns, rendered!, rendered! + word.length)).toEqual({
|
|
55
|
+
start,
|
|
56
|
+
end: start + word.length,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
package/src/view-plan.test.ts
CHANGED
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
marksByDisplay,
|
|
7
7
|
nextWorkBlock,
|
|
8
8
|
overlayMarks,
|
|
9
|
+
renderedOffsetAtOrAfter,
|
|
10
|
+
renderedOffsetAtOrBefore,
|
|
9
11
|
renderedOffsetFor,
|
|
12
|
+
safeLinkHref,
|
|
10
13
|
spanFromRange,
|
|
11
14
|
spanKey,
|
|
12
15
|
startSpan,
|
|
@@ -125,6 +128,86 @@ describe("blockRuns + overlayMarks", () => {
|
|
|
125
128
|
});
|
|
126
129
|
});
|
|
127
130
|
|
|
131
|
+
describe("M4: link hrefs are scheme-validated for OSC 8 (#236)", () => {
|
|
132
|
+
test("trusts http(s) and mailto, drops everything else", () => {
|
|
133
|
+
// Assert
|
|
134
|
+
expect(safeLinkHref("https://example.com")).toBe("https://example.com");
|
|
135
|
+
expect(safeLinkHref("http://x")).toBe("http://x");
|
|
136
|
+
expect(safeLinkHref("mailto:a@b.c")).toBe("mailto:a@b.c");
|
|
137
|
+
expect(safeLinkHref("javascript:alert(1)")).toBeUndefined();
|
|
138
|
+
expect(safeLinkHref("./relative/path")).toBeUndefined();
|
|
139
|
+
expect(safeLinkHref(undefined)).toBeUndefined();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("a control byte or space in the target drops the link", () => {
|
|
143
|
+
// Assert - ESC and BEL could splice into the OSC 8 escape stream
|
|
144
|
+
expect(safeLinkHref("https://x\x1b]8;;evil\x07")).toBeUndefined();
|
|
145
|
+
expect(safeLinkHref("https://x\x07")).toBeUndefined();
|
|
146
|
+
expect(safeLinkHref("https://x y")).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("blockRuns carries the link href through to the link run", () => {
|
|
150
|
+
// Act
|
|
151
|
+
const block = buildDisplay("see [docs](https://example.com) now\n")[0]!;
|
|
152
|
+
const link = blockRuns(block, true).find((run) => run.role === "link")!;
|
|
153
|
+
|
|
154
|
+
// Assert
|
|
155
|
+
expect(link.text).toBe("docs");
|
|
156
|
+
expect(link.href).toBe("https://example.com");
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("M3: inline emphasis composes with word-diff (#235)", () => {
|
|
161
|
+
test("context emphasis survives; added text keeps the green diff role; markers concealed", () => {
|
|
162
|
+
// Arrange - "**this**" is unchanged (context, stays emphasized); "safe"->"sound" is the edit
|
|
163
|
+
const block = buildDisplay("keep **this** safe\n", "keep **this** sound\n")[0]!;
|
|
164
|
+
|
|
165
|
+
// Act
|
|
166
|
+
const runs = blockRuns(block, true);
|
|
167
|
+
|
|
168
|
+
// Assert - no marker text renders anywhere
|
|
169
|
+
expect(runs.every((run) => !run.text.includes("*"))).toBe(true);
|
|
170
|
+
// the unchanged emphasized word keeps its strong role (context, not diffed)
|
|
171
|
+
expect(runs.find((run) => run.text === "this")!.role).toBe("strong");
|
|
172
|
+
// the added word is green (ins wins over any emphasis), the removed one opaque
|
|
173
|
+
expect(runs.find((run) => run.text.includes("sound"))!.role).toBe("ins");
|
|
174
|
+
expect(runs.some((run) => run.role === "del" && run.start === null)).toBe(true);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("markers inside added text conceal while the run stays a positioned ins", () => {
|
|
178
|
+
// Arrange - an emphasized word is added into an otherwise unchanged line
|
|
179
|
+
const block = buildDisplay("keep it safe\n", "keep it **very** safe\n")[0]!;
|
|
180
|
+
|
|
181
|
+
// Act
|
|
182
|
+
const runs = blockRuns(block, true);
|
|
183
|
+
const added = runs.find((run) => run.text === "very")!;
|
|
184
|
+
|
|
185
|
+
// Assert - concealed markers, green role, and an exact work offset back into work text
|
|
186
|
+
expect(added.role).toBe("ins");
|
|
187
|
+
expect(added.start).not.toBeNull();
|
|
188
|
+
expect(block.work!.text.slice(added.start!, added.start! + "very".length)).toBe("very");
|
|
189
|
+
expect(runs.every((run) => !run.text.includes("*"))).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("an anchor over an emphasized context word round-trips to its work offsets", () => {
|
|
193
|
+
// Arrange
|
|
194
|
+
const block = buildDisplay("hold **steady** now\n", "hold **steady** later\n")[0]!;
|
|
195
|
+
const runs = blockRuns(block, true);
|
|
196
|
+
const work = block.work!.text;
|
|
197
|
+
const start = work.indexOf("steady");
|
|
198
|
+
|
|
199
|
+
// Act
|
|
200
|
+
const rendered = renderedOffsetFor(runs, start);
|
|
201
|
+
|
|
202
|
+
// Assert
|
|
203
|
+
expect(rendered).not.toBeNull();
|
|
204
|
+
expect(workRangeForRendered(runs, rendered!, rendered! + "steady".length)).toEqual({
|
|
205
|
+
start,
|
|
206
|
+
end: start + "steady".length,
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
128
211
|
describe("marksByDisplay", () => {
|
|
129
212
|
test("annotations resolve into display coordinates", () => {
|
|
130
213
|
// Arrange
|
|
@@ -217,6 +300,28 @@ describe("rendered/work offset mapping", () => {
|
|
|
217
300
|
expect(renderedOffsetFor(runs, 99)).toBeNull();
|
|
218
301
|
expect(workRangeForRendered(runs, 90, 99)).toBeNull();
|
|
219
302
|
});
|
|
303
|
+
|
|
304
|
+
test("a span starting/ending on concealed markers snaps to the visible word", () => {
|
|
305
|
+
// Arrange - the word span over "**very**" covers the markers, which have
|
|
306
|
+
// no rendered cells; the clamped lookups land on "very" itself
|
|
307
|
+
const text = "keep it **very** safe\n";
|
|
308
|
+
const runs = blockRuns(buildDisplay(text)[0]!, true);
|
|
309
|
+
const spanStart = text.indexOf("**very**");
|
|
310
|
+
const spanEnd = spanStart + "**very**".length;
|
|
311
|
+
|
|
312
|
+
// Act
|
|
313
|
+
const renderedStart = renderedOffsetAtOrAfter(runs, spanStart)!;
|
|
314
|
+
const renderedEnd = renderedOffsetAtOrBefore(runs, spanEnd - 1)!;
|
|
315
|
+
|
|
316
|
+
// Assert
|
|
317
|
+
const renderedText = runs.map((run) => run.text).join("");
|
|
318
|
+
expect(renderedText.slice(renderedStart, renderedEnd + 1)).toBe("very");
|
|
319
|
+
// exact hits behave like renderedOffsetFor
|
|
320
|
+
expect(renderedOffsetAtOrAfter(runs, 0)).toBe(0);
|
|
321
|
+
expect(renderedOffsetAtOrBefore(runs, 0)).toBe(0);
|
|
322
|
+
// nothing positioned beyond the text end
|
|
323
|
+
expect(renderedOffsetAtOrAfter(runs, 99)).toBeNull();
|
|
324
|
+
});
|
|
220
325
|
});
|
|
221
326
|
|
|
222
327
|
describe("span mode", () => {
|