paseo-plugin-genui 0.1.8 → 0.2.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.
- package/README.md +1 -1
- package/client/components/content.tsx +62 -3
- package/client/components/data.tsx +26 -17
- package/client/components/dev.tsx +2 -1
- package/client/components/image-lightbox.tsx +153 -33
- package/client/components/inputs.tsx +3 -2
- package/client/components/media.tsx +37 -24
- package/client/components/project.tsx +24 -1
- package/client/components/widgets.tsx +2 -2
- package/client/live-ui.tsx +7 -2
- package/client/markdown.tsx +20 -1
- package/client/render.tsx +2 -0
- package/gallery/Draft-long.ui +1 -0
- package/gallery/Draft.ui +1 -0
- package/package.json +2 -2
- package/paseo-plugin.json +1 -1
- package/server/data-source.ts +2 -1
- package/server/project.test.ts +81 -0
- package/server/project.ts +48 -11
- package/shared/core/catalog.ts +5 -0
- package/shared/core/markdown.ts +5 -0
- package/shared/core/validate.ts +75 -0
- package/shared/diagram/markdown.test.ts +28 -0
- package/shared/diagram/markdown.ts +12 -2
- package/shared/genui.test.ts +48 -0
- package/shared/instructions.ts +1 -0
- package/shared/logic/lightbox.test.ts +32 -0
- package/shared/logic/lightbox.ts +27 -0
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Paseo renders a card with a plan switch, a seat slider, and a live total. Moving
|
|
|
48
48
|
| Group | Components |
|
|
49
49
|
| --- | --- |
|
|
50
50
|
| **Layout** | `Card` · `Row` · `Stack` · `Grid` · `Tabs` · `Details` · `Divider` · `Carousel` |
|
|
51
|
-
| **Content** | `Text` · `Callout` · `Metric` · `Badge` · `Icon` · `KeyValue` · `Image` · `File` · `Entity` · `Sources` · `List` |
|
|
51
|
+
| **Content** | `Text` · `Callout` · `Draft` · `Metric` · `Badge` · `Icon` · `KeyValue` · `Image` · `File` · `Entity` · `Sources` · `List` |
|
|
52
52
|
| **Data** | `Table` · `Chart` (bar, line, area, pie, scatter, radar, funnel, heatmap) · `Sparkline` · `Progress` · `Gauge` · `SegmentedBar` · `Steps` · `Timeline` · `Calendar` · `CalendarHeatmap` · `Tree` · `Code` · `Snippet` · `Diff` · `Diagram` |
|
|
53
53
|
| **Media** | `ImageSearch` · `Gallery` · `Map` · `Hotspots` |
|
|
54
54
|
| **Inputs** | `Slider` · `Stepper` · `Toggle` · `Choice` · `Radio` · `Select` · `Checklist` · `ListEditor` · `Input` · `TextArea` · `DateInput` · `Rating` · `OptionCards` · `Swatches` · `EditableTable` · `Button` · `Form` · `FollowUps` |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Icon as PaseoIcon, Modal } from "@getpaseo/plugin/client/react-native";
|
|
1
|
+
import { Icon as PaseoIcon, Modal, copyText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
2
2
|
import { ImageLightbox } from "./image-lightbox";
|
|
3
3
|
import { ExternalLink } from "@getpaseo/plugin/client/ui";
|
|
4
4
|
import React, { useContext, useEffect, useState } from "react";
|
|
@@ -8,7 +8,7 @@ import { parseListRows } from "../../shared/logic/explain-logic";
|
|
|
8
8
|
import { resolveIconName } from "../../shared/logic/icons";
|
|
9
9
|
import { entityKind, imageRef, inlineFacts, sourceLinks } from "../../shared/logic/references-model";
|
|
10
10
|
import { finiteNumber, isNode, list, optionalText, text, tone, type Props } from "../../shared/logic/values";
|
|
11
|
-
import { MarkdownText } from "../markdown";
|
|
11
|
+
import { InlineMarkdown, MarkdownText } from "../markdown";
|
|
12
12
|
import { ErrorLine, RenderNode } from "../node-renderer";
|
|
13
13
|
import { InTableContext, toneColor, toneMutedColor, useUiRuntime, type ImageUrl } from "../runtime";
|
|
14
14
|
|
|
@@ -51,6 +51,65 @@ export function Callout({ props }: { props: Props }) {
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export function Draft({ props }: { props: Props }) {
|
|
55
|
+
const { theme, compact } = useUiRuntime();
|
|
56
|
+
const toast = useToast();
|
|
57
|
+
const [source, setSource] = useState(false);
|
|
58
|
+
const body = text(props.markdown);
|
|
59
|
+
const title = optionalText(props.title);
|
|
60
|
+
const action = (label: string, onPress: () => void, active = false) => (
|
|
61
|
+
<Pressable accessibilityRole="button" onPress={onPress} hitSlop={8}>
|
|
62
|
+
<RNText style={{ color: active ? theme.colors.foreground : theme.colors.foregroundMuted, fontSize: 11.5, fontWeight: "500" }}>
|
|
63
|
+
{label}
|
|
64
|
+
</RNText>
|
|
65
|
+
</Pressable>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<View
|
|
70
|
+
style={{
|
|
71
|
+
borderRadius: 8,
|
|
72
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
73
|
+
borderColor: theme.colors.border,
|
|
74
|
+
backgroundColor: theme.colors.surface2,
|
|
75
|
+
overflow: "hidden",
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<View
|
|
79
|
+
style={{
|
|
80
|
+
flexDirection: "row",
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
gap: 12,
|
|
83
|
+
paddingHorizontal: 10,
|
|
84
|
+
paddingVertical: 6,
|
|
85
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
86
|
+
borderBottomColor: theme.colors.border,
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<RNText numberOfLines={1} style={{ flex: 1, color: theme.colors.foregroundMuted, fontSize: 11.5 }}>
|
|
90
|
+
{title ?? "Draft"}
|
|
91
|
+
</RNText>
|
|
92
|
+
{action("Source", () => setSource((value) => !value), source)}
|
|
93
|
+
{action("Copy", () => {
|
|
94
|
+
void copyText(body).then(
|
|
95
|
+
() => toast.show("Copied", { variant: "success" }),
|
|
96
|
+
() => toast.error("Could not copy"),
|
|
97
|
+
);
|
|
98
|
+
})}
|
|
99
|
+
</View>
|
|
100
|
+
<View style={{ padding: 10 }}>
|
|
101
|
+
{source ? (
|
|
102
|
+
<RNText selectable style={{ color: theme.colors.foreground, fontFamily: "monospace", fontSize: 12, lineHeight: 18 }}>
|
|
103
|
+
{body}
|
|
104
|
+
</RNText>
|
|
105
|
+
) : (
|
|
106
|
+
<MarkdownText text={body} theme={theme} compact={compact} />
|
|
107
|
+
)}
|
|
108
|
+
</View>
|
|
109
|
+
</View>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
54
113
|
export function Metric({ props }: { props: Props }) {
|
|
55
114
|
const { theme } = useUiRuntime();
|
|
56
115
|
const label = text(props.label);
|
|
@@ -473,7 +532,7 @@ export function List({ props }: { props: Props }) {
|
|
|
473
532
|
</RNText>
|
|
474
533
|
{item.detail ? (
|
|
475
534
|
<RNText style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
476
|
-
{item.detail}
|
|
535
|
+
<InlineMarkdown text={item.detail} theme={theme} />
|
|
477
536
|
</RNText>
|
|
478
537
|
) : null}
|
|
479
538
|
</View>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Icon, copyText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { InlineMarkdown } from "../markdown";
|
|
2
3
|
import React, { useMemo, useState } from "react";
|
|
3
4
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
4
5
|
import { calendarLayout, calendarStats, dayLabel, readDays } from "../../shared/logic/calendarMath";
|
|
@@ -525,7 +526,7 @@ export function Steps({ props }: { props: Props }) {
|
|
|
525
526
|
</Text>
|
|
526
527
|
{detail ? (
|
|
527
528
|
<Text selectable style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
528
|
-
{detail}
|
|
529
|
+
<InlineMarkdown text={detail} theme={theme} />
|
|
529
530
|
</Text>
|
|
530
531
|
) : null}
|
|
531
532
|
</View>
|
|
@@ -564,7 +565,7 @@ export function Timeline({ props }: { props: Props }) {
|
|
|
564
565
|
</View>
|
|
565
566
|
{entry.detail ? (
|
|
566
567
|
<Text selectable style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
567
|
-
{entry.detail}
|
|
568
|
+
<InlineMarkdown text={entry.detail} theme={theme} />
|
|
568
569
|
</Text>
|
|
569
570
|
) : null}
|
|
570
571
|
</View>
|
|
@@ -782,11 +783,27 @@ export function Tree({ props }: { props: Props }) {
|
|
|
782
783
|
);
|
|
783
784
|
}
|
|
784
785
|
|
|
786
|
+
const PROSE_LANGUAGES = new Set(["markdown", "md", "text", "txt"]);
|
|
787
|
+
|
|
785
788
|
export function Code({ props }: { props: Props }) {
|
|
786
789
|
const { theme } = useUiRuntime();
|
|
787
790
|
const toast = useToast();
|
|
788
791
|
const code = text(props.code);
|
|
789
792
|
const language = optionalText(props.language);
|
|
793
|
+
const wrap = language !== null && PROSE_LANGUAGES.has(language.toLowerCase());
|
|
794
|
+
const codeText = (
|
|
795
|
+
<Text
|
|
796
|
+
selectable
|
|
797
|
+
style={{
|
|
798
|
+
color: theme.colors.foreground,
|
|
799
|
+
fontFamily: "monospace",
|
|
800
|
+
fontSize: 12,
|
|
801
|
+
lineHeight: 18,
|
|
802
|
+
}}
|
|
803
|
+
>
|
|
804
|
+
{code}
|
|
805
|
+
</Text>
|
|
806
|
+
);
|
|
790
807
|
|
|
791
808
|
return (
|
|
792
809
|
<View
|
|
@@ -823,21 +840,13 @@ export function Code({ props }: { props: Props }) {
|
|
|
823
840
|
<Icon name="Copy" size={13} color={theme.colors.foregroundMuted} />
|
|
824
841
|
</Pressable>
|
|
825
842
|
</View>
|
|
826
|
-
|
|
827
|
-
<View style={{ padding: 10 }}>
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
fontSize: 12,
|
|
834
|
-
lineHeight: 18,
|
|
835
|
-
}}
|
|
836
|
-
>
|
|
837
|
-
{code}
|
|
838
|
-
</Text>
|
|
839
|
-
</View>
|
|
840
|
-
</ScrollView>
|
|
843
|
+
{wrap ? (
|
|
844
|
+
<View style={{ padding: 10 }}>{codeText}</View>
|
|
845
|
+
) : (
|
|
846
|
+
<ScrollView horizontal>
|
|
847
|
+
<View style={{ padding: 10 }}>{codeText}</View>
|
|
848
|
+
</ScrollView>
|
|
849
|
+
)}
|
|
841
850
|
</View>
|
|
842
851
|
);
|
|
843
852
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Icon, TextInput, copyText as copyToClipboard, useToast } from "@getpaseo/plugin/client/react-native";
|
|
2
2
|
import { ExternalLink } from "@getpaseo/plugin/client/ui";
|
|
3
|
+
import { InlineMarkdown } from "../markdown";
|
|
3
4
|
import React, { useMemo, useState } from "react";
|
|
4
5
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
5
6
|
import { formatRatio, readBenchmark } from "../../shared/core/benchmark";
|
|
@@ -309,7 +310,7 @@ export function Findings({ props }: { props: Props }) {
|
|
|
309
310
|
</Pressable>
|
|
310
311
|
) : null}
|
|
311
312
|
{item.detail ? (
|
|
312
|
-
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}
|
|
313
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}><InlineMarkdown text={item.detail} theme={theme} /></Text>
|
|
313
314
|
) : null}
|
|
314
315
|
<Pressable
|
|
315
316
|
onPress={() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
1
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
import {
|
|
3
3
|
Image,
|
|
4
4
|
Modal,
|
|
@@ -10,11 +10,22 @@ import {
|
|
|
10
10
|
useWindowDimensions,
|
|
11
11
|
View,
|
|
12
12
|
} from "react-native";
|
|
13
|
+
import { clampZoom, wheelFactor, zoomAt, type LightboxView } from "../../shared/logic/lightbox";
|
|
14
|
+
|
|
15
|
+
type PointerLike = { clientX: number; clientY: number; button: number };
|
|
16
|
+
type WheelLike = { clientX: number; clientY: number; deltaY: number; deltaMode: number; ctrlKey: boolean; preventDefault(): void };
|
|
17
|
+
/** The DOM node react-native-web hands back as a View ref; the plugin has no DOM lib types. */
|
|
18
|
+
type StageNode = {
|
|
19
|
+
addEventListener(type: string, listener: (event: never) => void, options?: { passive: boolean }): void;
|
|
20
|
+
removeEventListener(type: string, listener: (event: never) => void): void;
|
|
21
|
+
getBoundingClientRect(): { left: number; top: number; width: number; height: number };
|
|
22
|
+
};
|
|
13
23
|
|
|
14
24
|
/**
|
|
15
25
|
* A fullscreen image viewer, like the one Paseo uses for chat images. The plugin
|
|
16
26
|
* SDK exposes no call to open the host's, so this is built on React Native's Modal,
|
|
17
|
-
* which covers the whole window.
|
|
27
|
+
* which covers the whole window. On web, scroll or pinch zooms at the cursor and
|
|
28
|
+
* dragging moves the image; click the image to switch between fit and actual size.
|
|
18
29
|
*/
|
|
19
30
|
export function ImageLightbox({
|
|
20
31
|
uri,
|
|
@@ -25,9 +36,14 @@ export function ImageLightbox({
|
|
|
25
36
|
title: string;
|
|
26
37
|
onClose(): void;
|
|
27
38
|
}) {
|
|
39
|
+
const web = Platform.OS === "web";
|
|
28
40
|
const viewport = useWindowDimensions();
|
|
29
41
|
const [natural, setNatural] = useState<{ width: number; height: number } | null>(null);
|
|
30
42
|
const [actual, setActual] = useState(false);
|
|
43
|
+
const [stage, setStage] = useState<{ width: number; height: number } | null>(null);
|
|
44
|
+
const [view, setView] = useState<LightboxView | null>(null);
|
|
45
|
+
const stageRef = useRef<View>(null);
|
|
46
|
+
const moved = useRef(false);
|
|
31
47
|
|
|
32
48
|
useEffect(() => {
|
|
33
49
|
let live = true;
|
|
@@ -43,12 +59,83 @@ export function ImageLightbox({
|
|
|
43
59
|
};
|
|
44
60
|
}, [uri]);
|
|
45
61
|
|
|
46
|
-
const stageWidth = viewport.width;
|
|
47
|
-
const stageHeight = Math.max(200, viewport.height - 96);
|
|
62
|
+
const stageWidth = stage?.width ?? viewport.width;
|
|
63
|
+
const stageHeight = stage?.height ?? Math.max(200, viewport.height - 96);
|
|
48
64
|
const fit = natural === null ? 1 : Math.min(stageWidth / natural.width, stageHeight / natural.height, 1);
|
|
49
|
-
const scale = actual ? 1 : fit;
|
|
50
|
-
const shown = natural === null ? null : { width: natural.width * scale, height: natural.height * scale };
|
|
51
65
|
const zoomable = natural !== null && fit < 1;
|
|
66
|
+
const current = view ?? { zoom: fit, x: 0, y: 0 };
|
|
67
|
+
const scale = web ? current.zoom : actual ? 1 : fit;
|
|
68
|
+
const shown = natural === null ? null : { width: natural.width * scale, height: natural.height * scale };
|
|
69
|
+
|
|
70
|
+
const latest = useRef({ current, fit });
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
latest.current = { current, fit };
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const node = stageRef.current as unknown as StageNode | null;
|
|
77
|
+
if (!web || natural === null || node === null) return;
|
|
78
|
+
const fromCentre = (e: { clientX: number; clientY: number }) => {
|
|
79
|
+
const r = node.getBoundingClientRect();
|
|
80
|
+
return { x: e.clientX - r.left - r.width / 2, y: e.clientY - r.top - r.height / 2 };
|
|
81
|
+
};
|
|
82
|
+
let drag: { px: number; py: number; x: number; y: number } | null = null;
|
|
83
|
+
const onWheel = (e: WheelLike) => {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
const { current: now, fit: f } = latest.current;
|
|
86
|
+
setView(zoomAt(now, wheelFactor(e.deltaY, e.ctrlKey, e.deltaMode), fromCentre(e), f));
|
|
87
|
+
};
|
|
88
|
+
const onDown = (e: PointerLike) => {
|
|
89
|
+
if (e.button !== 0) return;
|
|
90
|
+
moved.current = false;
|
|
91
|
+
const { x, y } = latest.current.current;
|
|
92
|
+
drag = { px: e.clientX, py: e.clientY, x, y };
|
|
93
|
+
};
|
|
94
|
+
const onMove = (e: PointerLike) => {
|
|
95
|
+
if (drag === null) return;
|
|
96
|
+
const dx = e.clientX - drag.px;
|
|
97
|
+
const dy = e.clientY - drag.py;
|
|
98
|
+
if (!moved.current && Math.hypot(dx, dy) < 4) return;
|
|
99
|
+
moved.current = true;
|
|
100
|
+
const { current: now, fit: f } = latest.current;
|
|
101
|
+
if (now.zoom > f) setView({ zoom: now.zoom, x: drag.x + dx, y: drag.y + dy });
|
|
102
|
+
};
|
|
103
|
+
const onUp = () => {
|
|
104
|
+
drag = null;
|
|
105
|
+
};
|
|
106
|
+
const noDrag = (e: { preventDefault(): void }) => e.preventDefault();
|
|
107
|
+
node.addEventListener("wheel", onWheel, { passive: false });
|
|
108
|
+
node.addEventListener("pointerdown", onDown);
|
|
109
|
+
node.addEventListener("pointermove", onMove);
|
|
110
|
+
node.addEventListener("pointerup", onUp);
|
|
111
|
+
node.addEventListener("pointerleave", onUp);
|
|
112
|
+
node.addEventListener("dragstart", noDrag);
|
|
113
|
+
return () => {
|
|
114
|
+
node.removeEventListener("wheel", onWheel);
|
|
115
|
+
node.removeEventListener("pointerdown", onDown);
|
|
116
|
+
node.removeEventListener("pointermove", onMove);
|
|
117
|
+
node.removeEventListener("pointerup", onUp);
|
|
118
|
+
node.removeEventListener("pointerleave", onUp);
|
|
119
|
+
node.removeEventListener("dragstart", noDrag);
|
|
120
|
+
};
|
|
121
|
+
}, [web, natural]);
|
|
122
|
+
|
|
123
|
+
// A press that ended a drag is not a click.
|
|
124
|
+
const closeFromStage = () => {
|
|
125
|
+
if (!moved.current) onClose();
|
|
126
|
+
};
|
|
127
|
+
const toggleWeb = () => {
|
|
128
|
+
if (moved.current || natural === null) return;
|
|
129
|
+
setView(current.zoom > fit + 1e-3 ? null : zoomable ? { zoom: clampZoom(1, fit), x: 0, y: 0 } : view);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const hint = web
|
|
133
|
+
? `Scroll to zoom${current.zoom > fit ? " · drag to move" : ""}${zoomable ? " · click for 100%" : ""} · Esc to close`
|
|
134
|
+
: zoomable
|
|
135
|
+
? actual
|
|
136
|
+
? "Tap to fit"
|
|
137
|
+
: "Tap to zoom"
|
|
138
|
+
: "";
|
|
52
139
|
|
|
53
140
|
return (
|
|
54
141
|
<Modal transparent animationType="fade" visible onRequestClose={onClose} statusBarTranslucent>
|
|
@@ -59,40 +146,71 @@ export function ImageLightbox({
|
|
|
59
146
|
{natural !== null ? ` ${natural.width} × ${natural.height}` : ""}
|
|
60
147
|
</Text>
|
|
61
148
|
{natural !== null ? <Text style={styles.percent}>{Math.round(scale * 100)}%</Text> : null}
|
|
62
|
-
<Pressable accessibilityRole="button" accessibilityLabel="Close" hitSlop={
|
|
149
|
+
<Pressable accessibilityRole="button" accessibilityLabel="Close" hitSlop={16} onPress={onClose} style={styles.close}>
|
|
63
150
|
<Text style={styles.closeText}>✕</Text>
|
|
64
151
|
</Pressable>
|
|
65
152
|
</View>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
153
|
+
{web ? (
|
|
154
|
+
<View
|
|
155
|
+
ref={stageRef}
|
|
156
|
+
style={styles.webStage}
|
|
157
|
+
onLayout={(e) => setStage({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height })}
|
|
158
|
+
>
|
|
159
|
+
<Pressable accessibilityRole="button" accessibilityLabel="Close" onPress={closeFromStage} style={StyleSheet.absoluteFill} />
|
|
160
|
+
{shown !== null ? (
|
|
161
|
+
<Pressable
|
|
162
|
+
accessibilityRole="imagebutton"
|
|
163
|
+
accessibilityLabel={title}
|
|
164
|
+
onPress={toggleWeb}
|
|
165
|
+
style={{
|
|
166
|
+
position: "absolute",
|
|
167
|
+
left: (stageWidth - shown.width) / 2 + current.x,
|
|
168
|
+
top: (stageHeight - shown.height) / 2 + current.y,
|
|
169
|
+
cursor: current.zoom > fit ? "grab" : zoomable ? "zoom-in" : "default",
|
|
170
|
+
} as never}
|
|
171
|
+
>
|
|
172
|
+
<Image source={{ uri }} resizeMode="contain" style={shown} />
|
|
173
|
+
</Pressable>
|
|
174
|
+
) : (
|
|
175
|
+
<Text style={[styles.percent, styles.loading]}>Loading…</Text>
|
|
176
|
+
)}
|
|
177
|
+
</View>
|
|
178
|
+
) : (
|
|
73
179
|
<ScrollView
|
|
74
|
-
|
|
75
|
-
|
|
180
|
+
style={styles.stage}
|
|
181
|
+
contentContainerStyle={{ minHeight: stageHeight, minWidth: stageWidth, alignItems: "center", justifyContent: "center" }}
|
|
182
|
+
horizontal={actual}
|
|
183
|
+
maximumZoomScale={4}
|
|
184
|
+
centerContent
|
|
76
185
|
>
|
|
77
186
|
<Pressable
|
|
78
|
-
accessibilityRole="
|
|
79
|
-
accessibilityLabel=
|
|
80
|
-
onPress={
|
|
81
|
-
|
|
82
|
-
}}
|
|
187
|
+
accessibilityRole="button"
|
|
188
|
+
accessibilityLabel="Close"
|
|
189
|
+
onPress={onClose}
|
|
190
|
+
style={{ minHeight: stageHeight, minWidth: stageWidth }}
|
|
83
191
|
>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
192
|
+
<ScrollView
|
|
193
|
+
contentContainerStyle={{ minHeight: stageHeight, justifyContent: "center", alignItems: "center" }}
|
|
194
|
+
scrollEnabled={actual}
|
|
195
|
+
>
|
|
196
|
+
<Pressable
|
|
197
|
+
accessibilityRole="imagebutton"
|
|
198
|
+
accessibilityLabel={zoomable ? (actual ? "Fit to window" : "Show actual size") : title}
|
|
199
|
+
onPress={() => {
|
|
200
|
+
if (zoomable) setActual((value) => !value);
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
{shown !== null ? (
|
|
204
|
+
<Image source={{ uri }} resizeMode="contain" style={shown} />
|
|
205
|
+
) : (
|
|
206
|
+
<Text style={styles.percent}>Loading…</Text>
|
|
207
|
+
)}
|
|
208
|
+
</Pressable>
|
|
209
|
+
</ScrollView>
|
|
89
210
|
</Pressable>
|
|
90
211
|
</ScrollView>
|
|
91
|
-
|
|
92
|
-
<Text style={styles.hint}>
|
|
93
|
-
{zoomable ? (actual ? "Click to fit" : "Click to zoom") : ""}
|
|
94
|
-
{Platform.OS === "web" ? `${zoomable ? " · " : ""}Esc to close` : ""}
|
|
95
|
-
</Text>
|
|
212
|
+
)}
|
|
213
|
+
<Text style={styles.hint}>{hint}</Text>
|
|
96
214
|
</View>
|
|
97
215
|
</Modal>
|
|
98
216
|
);
|
|
@@ -103,8 +221,10 @@ const styles = StyleSheet.create({
|
|
|
103
221
|
header: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingTop: 16, paddingBottom: 8 },
|
|
104
222
|
title: { flex: 1, color: "#f4f4f5", fontSize: 13, fontWeight: "600" },
|
|
105
223
|
percent: { color: "#a1a1aa", fontSize: 12 },
|
|
106
|
-
|
|
107
|
-
|
|
224
|
+
loading: { textAlign: "center", marginTop: 40 },
|
|
225
|
+
close: { paddingHorizontal: 14, paddingVertical: 8 },
|
|
226
|
+
closeText: { color: "#f4f4f5", fontSize: 24 },
|
|
108
227
|
stage: { flex: 1 },
|
|
228
|
+
webStage: { flex: 1, overflow: "hidden" },
|
|
109
229
|
hint: { color: "#a1a1aa", fontSize: 12, textAlign: "center", paddingVertical: 8 },
|
|
110
230
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Icon, TextInput } from "@getpaseo/plugin/client/react-native";
|
|
2
|
+
import { InlineMarkdown } from "../markdown";
|
|
2
3
|
import React, { useState } from "react";
|
|
3
4
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
4
5
|
import { formMessage } from "../../shared/core/form";
|
|
@@ -377,7 +378,7 @@ export function Radio({ props }: { props: Props }) {
|
|
|
377
378
|
</Text>
|
|
378
379
|
{opt.detail ? (
|
|
379
380
|
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
380
|
-
{opt.detail}
|
|
381
|
+
<InlineMarkdown text={opt.detail} theme={theme} />
|
|
381
382
|
</Text>
|
|
382
383
|
) : null}
|
|
383
384
|
</View>
|
|
@@ -686,7 +687,7 @@ export function OptionCards({ props }: { props: Props }) {
|
|
|
686
687
|
</Text>
|
|
687
688
|
</View>
|
|
688
689
|
{opt.detail ? (
|
|
689
|
-
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}
|
|
690
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}><InlineMarkdown text={opt.detail} theme={theme} /></Text>
|
|
690
691
|
) : null}
|
|
691
692
|
</Pressable>
|
|
692
693
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Icon
|
|
1
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
2
2
|
import { ExternalLink } from "@getpaseo/plugin/client/ui";
|
|
3
3
|
import React, { useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { Image as RNImage, Pressable, StyleSheet, Text, View } from "react-native";
|
|
@@ -7,8 +7,9 @@ import { hotspotPoints, imageRef } from "../../shared/logic/references-model";
|
|
|
7
7
|
import { asRecord, finiteNumber, list, optionalText, text, type Props } from "../../shared/logic/values";
|
|
8
8
|
import { useGeocodePlace, useImageSearch, useMapTileLoader } from "../loaders";
|
|
9
9
|
import { ErrorLine } from "../node-renderer";
|
|
10
|
-
import { useUiRuntime } from "../runtime";
|
|
10
|
+
import { useUiRuntime, type ImageUrl } from "../runtime";
|
|
11
11
|
import { LoadedImageView } from "./content";
|
|
12
|
+
import { ImageLightbox } from "./image-lightbox";
|
|
12
13
|
|
|
13
14
|
export function ImageSearch({ props }: { props: Props }) {
|
|
14
15
|
const { theme } = useUiRuntime();
|
|
@@ -71,6 +72,39 @@ export function ImageSearch({ props }: { props: Props }) {
|
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
function GalleryLightbox({
|
|
76
|
+
item,
|
|
77
|
+
onClose,
|
|
78
|
+
}: {
|
|
79
|
+
item: { src?: string; query?: string; caption: string | null };
|
|
80
|
+
onClose(): void;
|
|
81
|
+
}) {
|
|
82
|
+
const { loadImage } = useUiRuntime();
|
|
83
|
+
const found = useImageSearch(item.query ?? "");
|
|
84
|
+
const [loaded, setLoaded] = useState<ImageUrl | null>(null);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (item.query || !item.src || !loadImage) return;
|
|
88
|
+
let live = true;
|
|
89
|
+
void loadImage(item.src).then((res) => {
|
|
90
|
+
if (live) setLoaded(res);
|
|
91
|
+
});
|
|
92
|
+
return () => {
|
|
93
|
+
live = false;
|
|
94
|
+
};
|
|
95
|
+
}, [item.query, item.src, loadImage]);
|
|
96
|
+
|
|
97
|
+
const result = item.query ? (found === null ? null : found.ok ? { ok: true as const, url: found.image.url } : found) : loaded;
|
|
98
|
+
const failed = result !== null && !result.ok;
|
|
99
|
+
// The tile already shows why the image failed, so a failed lookup just closes.
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (failed) onClose();
|
|
102
|
+
}, [failed, onClose]);
|
|
103
|
+
|
|
104
|
+
if (result === null || !result.ok) return null;
|
|
105
|
+
return <ImageLightbox uri={result.url} title={item.caption ?? item.query ?? item.src ?? "Image"} onClose={onClose} />;
|
|
106
|
+
}
|
|
107
|
+
|
|
74
108
|
export function Gallery({ props }: { props: Props }) {
|
|
75
109
|
const { theme, compact } = useUiRuntime();
|
|
76
110
|
const rawItems = list(props.images);
|
|
@@ -118,32 +152,11 @@ export function Gallery({ props }: { props: Props }) {
|
|
|
118
152
|
) : item.src ? (
|
|
119
153
|
<LoadedImageView src={item.src} alt={item.caption} height={150} zoomable={false} />
|
|
120
154
|
) : null}
|
|
121
|
-
{item.caption ? (
|
|
122
|
-
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 11.5 }}>
|
|
123
|
-
{item.caption}
|
|
124
|
-
</Text>
|
|
125
|
-
) : null}
|
|
126
155
|
</Pressable>
|
|
127
156
|
))}
|
|
128
157
|
</View>
|
|
129
158
|
))}
|
|
130
|
-
{selected ? (
|
|
131
|
-
<Modal
|
|
132
|
-
title={selected.caption ?? "Image"}
|
|
133
|
-
open={true}
|
|
134
|
-
onOpenChange={(open) => {
|
|
135
|
-
if (!open) setSelected(null);
|
|
136
|
-
}}
|
|
137
|
-
>
|
|
138
|
-
<Modal.Content>
|
|
139
|
-
{selected.query ? (
|
|
140
|
-
<ImageSearch props={{ query: selected.query, alt: selected.caption ?? selected.query }} />
|
|
141
|
-
) : selected.src ? (
|
|
142
|
-
<LoadedImageView src={selected.src} alt={selected.caption} height={360} zoomable={false} />
|
|
143
|
-
) : null}
|
|
144
|
-
</Modal.Content>
|
|
145
|
-
</Modal>
|
|
146
|
-
) : null}
|
|
159
|
+
{selected ? <GalleryLightbox item={selected} onClose={() => setSelected(null)} /> : null}
|
|
147
160
|
</View>
|
|
148
161
|
);
|
|
149
162
|
}
|
|
@@ -27,6 +27,8 @@ import { useUiRuntime } from "../runtime";
|
|
|
27
27
|
import { LoadedImageView } from "./content";
|
|
28
28
|
import { Diff } from "./data";
|
|
29
29
|
|
|
30
|
+
const CHANGES_ROWS = 50;
|
|
31
|
+
|
|
30
32
|
export function Changes({ props }: { props: Props }) {
|
|
31
33
|
const { theme, agentId, blockKey } = useUiRuntime();
|
|
32
34
|
const projectRpc = useProjectRpc();
|
|
@@ -34,6 +36,10 @@ export function Changes({ props }: { props: Props }) {
|
|
|
34
36
|
const parsedPaths = parsePathFilter(props.paths);
|
|
35
37
|
const [state, setState] = useState<ChangesResult | null>(null);
|
|
36
38
|
const [expandedFile, setExpandedFile] = useState<string | null>(null);
|
|
39
|
+
// Keyed by the request so a new target or path filter starts collapsed again.
|
|
40
|
+
const requestKey = `${rawTarget ?? ""}|${JSON.stringify(parsedPaths.ok ? parsedPaths.value : null)}`;
|
|
41
|
+
const [expandedFor, setExpandedFor] = useState<string | null>(null);
|
|
42
|
+
const showAll = expandedFor === requestKey;
|
|
37
43
|
|
|
38
44
|
useEffect(() => {
|
|
39
45
|
const parsedTarget = parseChangesTarget(rawTarget);
|
|
@@ -67,6 +73,8 @@ export function Changes({ props }: { props: Props }) {
|
|
|
67
73
|
|
|
68
74
|
const totals = changeTotals(state.files);
|
|
69
75
|
const patchByPath = new Map(state.patches.map((p) => [p.path, p.patch]));
|
|
76
|
+
const shownFiles = showAll ? state.files : state.files.slice(0, CHANGES_ROWS);
|
|
77
|
+
const hiddenFiles = state.files.length - shownFiles.length;
|
|
70
78
|
|
|
71
79
|
return (
|
|
72
80
|
<View
|
|
@@ -97,7 +105,7 @@ export function Changes({ props }: { props: Props }) {
|
|
|
97
105
|
<Text style={{ color: theme.colors.statusDanger }}>−{totals.deletions}</Text>
|
|
98
106
|
</Text>
|
|
99
107
|
</View>
|
|
100
|
-
{
|
|
108
|
+
{shownFiles.map((file, idx) => {
|
|
101
109
|
const patch = patchByPath.get(file.path);
|
|
102
110
|
const isOpen = expandedFile === file.path;
|
|
103
111
|
return (
|
|
@@ -133,6 +141,21 @@ export function Changes({ props }: { props: Props }) {
|
|
|
133
141
|
</View>
|
|
134
142
|
);
|
|
135
143
|
})}
|
|
144
|
+
{hiddenFiles > 0 ? (
|
|
145
|
+
<Pressable
|
|
146
|
+
onPress={() => setExpandedFor(requestKey)}
|
|
147
|
+
style={{
|
|
148
|
+
paddingHorizontal: 10,
|
|
149
|
+
paddingVertical: 8,
|
|
150
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
151
|
+
borderTopColor: theme.colors.border,
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
|
|
155
|
+
Show {hiddenFiles} more file{hiddenFiles === 1 ? "" : "s"}
|
|
156
|
+
</Text>
|
|
157
|
+
</Pressable>
|
|
158
|
+
) : null}
|
|
136
159
|
</View>
|
|
137
160
|
);
|
|
138
161
|
}
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
STOPPED,
|
|
47
47
|
type Clock,
|
|
48
48
|
} from "../../shared/logic/widget-logic";
|
|
49
|
-
import { MarkdownText } from "../markdown";
|
|
49
|
+
import { InlineMarkdown, MarkdownText } from "../markdown";
|
|
50
50
|
import { ErrorLine } from "../node-renderer";
|
|
51
51
|
import { propsKey, usePersistedState, useUiRuntime } from "../runtime";
|
|
52
52
|
|
|
@@ -385,7 +385,7 @@ export function Plan({ props }: { props: Props }) {
|
|
|
385
385
|
) : null}
|
|
386
386
|
</View>
|
|
387
387
|
{step.detail ? (
|
|
388
|
-
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}
|
|
388
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}><InlineMarkdown text={step.detail} theme={theme} /></Text>
|
|
389
389
|
) : null}
|
|
390
390
|
{step.files.length > 0 ? (
|
|
391
391
|
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 6 }}>
|
package/client/live-ui.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
2
|
import { openExternalUrl, usePaseo, type PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
3
3
|
import { Icon, copyText, useRevealedText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
4
|
+
import { Markdown } from "@getpaseo/plugin/client/ui";
|
|
4
5
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
6
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
6
7
|
import {
|
|
@@ -15,7 +16,6 @@ import {
|
|
|
15
16
|
import type { Action, Diagnostic, Value } from "../shared/core/types";
|
|
16
17
|
import type { GenUiBlockData, GenUiTextData } from "../shared/rpc";
|
|
17
18
|
import { useAudioLoader, useImageLoader, useLoadedData, useTextLoader, type FileScope } from "./loaders";
|
|
18
|
-
import { MarkdownText } from "./markdown";
|
|
19
19
|
import { RenderNodes } from "./render";
|
|
20
20
|
import { UiRuntimeContext, type UiRuntime } from "./runtime";
|
|
21
21
|
import { canRenderWebIframe, mountSandboxedAppIframe, openWorkspaceFile, readStorage, writeStorage } from "./web";
|
|
@@ -521,5 +521,10 @@ export function TimelineTextItem({
|
|
|
521
521
|
layout,
|
|
522
522
|
}: PluginTimelineItemProps<GenUiTextData>) {
|
|
523
523
|
const revealed = useRevealedText(item.data.text, item.data.phase ?? "complete");
|
|
524
|
-
|
|
524
|
+
// Paseo's own renderer and testID give this text the host's links, selection and copy, and plugin styles such as Chat Polish.
|
|
525
|
+
return (
|
|
526
|
+
<View testID="assistant-message">
|
|
527
|
+
<Markdown>{revealed}</Markdown>
|
|
528
|
+
</View>
|
|
529
|
+
);
|
|
525
530
|
}
|
package/client/markdown.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
|
+
import { openExternalUrl } from "@getpaseo/plugin/client";
|
|
2
3
|
import React, { useMemo } from "react";
|
|
3
4
|
import { StyleSheet, Text, View } from "react-native";
|
|
4
|
-
import { parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown";
|
|
5
|
+
import { parseInline, parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown";
|
|
5
6
|
|
|
6
7
|
export function MarkdownText({
|
|
7
8
|
text,
|
|
@@ -24,6 +25,12 @@ export function MarkdownText({
|
|
|
24
25
|
);
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/** One line of inline Markdown (links, emphasis, code), nested inside a caller's styled Text. */
|
|
29
|
+
export function InlineMarkdown({ text, theme }: { text: string; theme: PluginTheme }) {
|
|
30
|
+
const content = useMemo(() => parseInline(text), [text]);
|
|
31
|
+
return <Spans content={content} theme={theme} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
function BlockView({
|
|
28
35
|
block,
|
|
29
36
|
theme,
|
|
@@ -165,6 +172,18 @@ function Spans({ content, theme }: { content: Inline[]; theme: PluginTheme }) {
|
|
|
165
172
|
</Text>
|
|
166
173
|
);
|
|
167
174
|
}
|
|
175
|
+
if (span.kind === "link") {
|
|
176
|
+
return (
|
|
177
|
+
<Text
|
|
178
|
+
key={index}
|
|
179
|
+
accessibilityRole="link"
|
|
180
|
+
onPress={() => void openExternalUrl(span.url)}
|
|
181
|
+
style={{ color: theme.colors.accent, textDecorationLine: "underline" }}
|
|
182
|
+
>
|
|
183
|
+
{span.text}
|
|
184
|
+
</Text>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
168
187
|
return <Text key={index}>{span.text}</Text>;
|
|
169
188
|
})}
|
|
170
189
|
</>
|
package/client/render.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import type { Props } from "../shared/logic/values";
|
|
|
4
4
|
import {
|
|
5
5
|
Badge,
|
|
6
6
|
Callout,
|
|
7
|
+
Draft,
|
|
7
8
|
Entity,
|
|
8
9
|
File,
|
|
9
10
|
Icon,
|
|
@@ -102,6 +103,7 @@ export const RENDERERS = {
|
|
|
102
103
|
Divider,
|
|
103
104
|
Text,
|
|
104
105
|
Callout,
|
|
106
|
+
Draft,
|
|
105
107
|
Metric,
|
|
106
108
|
Badge,
|
|
107
109
|
Icon,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Card("Draft PR comment", [Draft("**Suggestion:** `requeue()` passes only the job id, so a retried job loses its payload and the worker fails with `undefined is not iterable` on the second attempt. Passing the whole job object, or reading the payload back from the store before requeueing, would fix it.")])
|
package/gallery/Draft.ui
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Card("Draft reply to the review", [Draft("Thanks, fixed in `a1b2c3d`:\n\n- the retry now keeps the payload\n- added a regression test\n\nCan you take another look?", "PR #42 reply")])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-genui",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Paseo plugin: agents answer with charts, diagrams, maps, plans and forms rendered inline in the chat.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paseo",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"test": "vitest run"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@getpaseo/plugin": "0.
|
|
42
|
+
"@getpaseo/plugin": "0.13.0",
|
|
43
43
|
"@tanstack/react-query": "^5.90.11",
|
|
44
44
|
"@types/node": "^24.19.2",
|
|
45
45
|
"@types/react": "~19.2.0",
|
package/paseo-plugin.json
CHANGED
package/server/data-source.ts
CHANGED
|
@@ -50,7 +50,7 @@ type FileContent =
|
|
|
50
50
|
type FileReader = (requested: string, maxBytes: number) => Promise<FileContent>;
|
|
51
51
|
|
|
52
52
|
const AGENT_REFUSAL =
|
|
53
|
-
"only files in this agent's workspace, its thread storage, /tmp or a folder added in Generative UI settings can be loaded";
|
|
53
|
+
"only files in this agent's workspace, its thread storage, /tmp or a folder added in Generative UI settings can be loaded; copy the file to $BB_THREAD_STORAGE to show it";
|
|
54
54
|
|
|
55
55
|
let extraRoots: readonly string[] = [];
|
|
56
56
|
|
|
@@ -62,6 +62,7 @@ export function setExtraLoadFolders(folders: readonly string[]): void {
|
|
|
62
62
|
function expandHome(requested: string): string {
|
|
63
63
|
return requested === "~" || requested.startsWith("~/") ? path.join(os.homedir(), requested.slice(1)) : requested;
|
|
64
64
|
}
|
|
65
|
+
|
|
65
66
|
const GALLERY_REFUSAL = "gallery specs can only load files in gallery/";
|
|
66
67
|
|
|
67
68
|
function contains(root: string, target: string): boolean {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { detectGitBranches } from "./project";
|
|
7
|
+
|
|
8
|
+
const dirs: string[] = [];
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function repo(): { dir: string; git: (...args: string[]) => void; commit: (name: string) => void } {
|
|
14
|
+
const dir = mkdtempSync(join(tmpdir(), "genui-base-"));
|
|
15
|
+
dirs.push(dir);
|
|
16
|
+
const git = (...args: string[]) => {
|
|
17
|
+
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", ...args], { cwd: dir, stdio: "ignore" });
|
|
18
|
+
};
|
|
19
|
+
const commit = (name: string) => {
|
|
20
|
+
writeFileSync(join(dir, name), name);
|
|
21
|
+
git("add", name);
|
|
22
|
+
git("commit", "-m", name);
|
|
23
|
+
};
|
|
24
|
+
git("init", "-q", "-b", "main");
|
|
25
|
+
commit("root");
|
|
26
|
+
return { dir, git, commit };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("detectGitBranches", () => {
|
|
30
|
+
it("picks dev for a branch cut from dev, not the default branch", async () => {
|
|
31
|
+
const { dir, git, commit } = repo();
|
|
32
|
+
git("checkout", "-q", "-b", "dev");
|
|
33
|
+
for (const n of ["d1", "d2", "d3"]) commit(n);
|
|
34
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
35
|
+
commit("mine");
|
|
36
|
+
const info = await detectGitBranches(dir);
|
|
37
|
+
expect(info.ok && info.base).toBe("dev");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("keeps main for a branch cut from main", async () => {
|
|
41
|
+
const { dir, git, commit } = repo();
|
|
42
|
+
git("checkout", "-q", "-b", "dev");
|
|
43
|
+
commit("d1");
|
|
44
|
+
git("checkout", "-q", "main");
|
|
45
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
46
|
+
commit("mine");
|
|
47
|
+
const info = await detectGitBranches(dir);
|
|
48
|
+
expect(info.ok && info.base).toBe("main");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("treats dev itself as on its base", async () => {
|
|
52
|
+
const { dir, git, commit } = repo();
|
|
53
|
+
git("checkout", "-q", "-b", "dev");
|
|
54
|
+
commit("d1");
|
|
55
|
+
const info = await detectGitBranches(dir);
|
|
56
|
+
expect(info.ok && info.base).toBe("dev");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("uses local dev when it is ahead of a stale origin/dev", async () => {
|
|
60
|
+
const { dir, git, commit } = repo();
|
|
61
|
+
git("checkout", "-q", "-b", "dev");
|
|
62
|
+
git("update-ref", "refs/remotes/origin/dev", "HEAD");
|
|
63
|
+
for (const n of ["d1", "d2", "d3"]) commit(n);
|
|
64
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
65
|
+
commit("mine");
|
|
66
|
+
const info = await detectGitBranches(dir);
|
|
67
|
+
expect(info.ok && info.baseRef).toBe("dev");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("keeps main for a branch from main that is already merged into dev", async () => {
|
|
71
|
+
const { dir, git, commit } = repo();
|
|
72
|
+
git("checkout", "-q", "-b", "fix/thing");
|
|
73
|
+
commit("mine");
|
|
74
|
+
git("checkout", "-q", "-b", "dev", "main");
|
|
75
|
+
commit("d1");
|
|
76
|
+
git("merge", "-q", "--no-ff", "-m", "merge", "fix/thing");
|
|
77
|
+
git("checkout", "-q", "fix/thing");
|
|
78
|
+
const info = await detectGitBranches(dir);
|
|
79
|
+
expect(info.ok && info.base).toBe("main");
|
|
80
|
+
});
|
|
81
|
+
});
|
package/server/project.ts
CHANGED
|
@@ -58,12 +58,14 @@ async function runGit(
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
async function detectGitBranches(cwd: string): Promise<
|
|
61
|
+
export async function detectGitBranches(cwd: string): Promise<
|
|
62
62
|
| {
|
|
63
63
|
ok: true;
|
|
64
64
|
branch: string | null;
|
|
65
65
|
head: string | null;
|
|
66
66
|
base: string;
|
|
67
|
+
/** The ref to diff against: origin/<base> when it exists, so a stale local branch doesn't skew it. */
|
|
68
|
+
baseRef: string;
|
|
67
69
|
checkout: "branch" | "detached" | "unborn";
|
|
68
70
|
}
|
|
69
71
|
| ProjectFailure
|
|
@@ -79,12 +81,47 @@ async function detectGitBranches(cwd: string): Promise<
|
|
|
79
81
|
const checkout = head === null ? "unborn" : branch !== null ? "branch" : "detached";
|
|
80
82
|
|
|
81
83
|
const originHead = await runGit(cwd, ["symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"]);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const defaultBranch = originHead.ok ? originHead.stdout.trim().replace(/^origin\//, "") : "";
|
|
85
|
+
const { base, baseRef } = await closestBase(cwd, branch, head !== null, defaultBranch);
|
|
86
|
+
return { ok: true, branch, head, base, baseRef, checkout };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const BASE_CANDIDATES = ["main", "master", "dev", "develop"];
|
|
90
|
+
|
|
91
|
+
/** Feature branches often fork from dev rather than the default branch, so pick the candidate fewest commits behind HEAD. */
|
|
92
|
+
async function closestBase(
|
|
93
|
+
cwd: string,
|
|
94
|
+
branch: string | null,
|
|
95
|
+
hasHead: boolean,
|
|
96
|
+
defaultBranch: string,
|
|
97
|
+
): Promise<{ base: string; baseRef: string }> {
|
|
98
|
+
const names = [...new Set([defaultBranch, ...BASE_CANDIDATES].filter(Boolean))];
|
|
99
|
+
// Both the remote and local ref of each name compete, so neither a stale origin nor a stale local copy wins.
|
|
100
|
+
const refs = names.flatMap((name) => [`origin/${name}`, name].map((ref) => ({ name, ref })));
|
|
101
|
+
const resolved = await Promise.all(
|
|
102
|
+
refs.map(async (c) => ((await runGit(cwd, ["rev-parse", "--verify", "-q", `${c.ref}^{commit}`])).ok ? c : null)),
|
|
103
|
+
);
|
|
104
|
+
const existing = resolved.filter((c): c is { name: string; ref: string } => c !== null);
|
|
105
|
+
const fallback = existing[0] ?? { name: defaultBranch || "main", ref: defaultBranch || "main" };
|
|
106
|
+
const own = existing.find((c) => c.name === branch);
|
|
107
|
+
if (own) return { base: own.name, baseRef: own.ref };
|
|
108
|
+
if (!hasHead || existing.length < 2) return { base: fallback.name, baseRef: fallback.ref };
|
|
109
|
+
|
|
110
|
+
const scored = await Promise.all(
|
|
111
|
+
existing.map(async (c) => {
|
|
112
|
+
const [ahead, behind] = await Promise.all([
|
|
113
|
+
runGit(cwd, ["rev-list", "--count", `${c.ref}..HEAD`]),
|
|
114
|
+
runGit(cwd, ["rev-list", "--count", `HEAD..${c.ref}`]),
|
|
115
|
+
]);
|
|
116
|
+
const aheadCount = ahead.ok ? Number(ahead.stdout.trim()) : Number.POSITIVE_INFINITY;
|
|
117
|
+
// A ref that already holds every HEAD commit and more has merged this branch; it isn't where it forked from.
|
|
118
|
+
const mergedIn = aheadCount === 0 && behind.ok && Number(behind.stdout.trim()) > 0;
|
|
119
|
+
return { ...c, ahead: aheadCount, mergedIn };
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
const pool = scored.some((c) => !c.mergedIn) ? scored.filter((c) => !c.mergedIn) : scored;
|
|
123
|
+
const best = pool.reduce((a, b) => (b.ahead < a.ahead ? b : a));
|
|
124
|
+
return { base: best.name, baseRef: best.ref };
|
|
88
125
|
}
|
|
89
126
|
|
|
90
127
|
function mapStatusChar(code: string): ChangeKind {
|
|
@@ -452,8 +489,8 @@ export async function readProjectChanges(
|
|
|
452
489
|
base: gitInfo.base,
|
|
453
490
|
onBase: false,
|
|
454
491
|
};
|
|
455
|
-
diffArgs = ["diff", `${gitInfo.
|
|
456
|
-
numstatArgs = ["diff", `${gitInfo.
|
|
492
|
+
diffArgs = ["diff", `${gitInfo.baseRef}...HEAD`, "--unified=3"];
|
|
493
|
+
numstatArgs = ["diff", `${gitInfo.baseRef}...HEAD`, "--numstat", "--find-renames"];
|
|
457
494
|
}
|
|
458
495
|
|
|
459
496
|
const [numstatRes, nameStatusRes, patchRes] = await Promise.all([
|
|
@@ -560,7 +597,7 @@ export async function readProjectCommits(paseo: PaseoApi, agentId: string): Prom
|
|
|
560
597
|
if (!gitInfo.ok) return gitInfo;
|
|
561
598
|
|
|
562
599
|
const onBase = gitInfo.branch === gitInfo.base;
|
|
563
|
-
const range = onBase ? `-n ${MAX_COMMITS}` : `${gitInfo.
|
|
600
|
+
const range = onBase ? `-n ${MAX_COMMITS}` : `${gitInfo.baseRef}..HEAD`;
|
|
564
601
|
const logArgs = onBase
|
|
565
602
|
? ["log", `-n`, String(MAX_COMMITS), "--format=%H%x09%h%x09%s%x09%an%x09%at"]
|
|
566
603
|
: ["log", range, "--format=%H%x09%h%x09%s%x09%an%x09%at"];
|
|
@@ -581,7 +618,7 @@ export async function readProjectCommits(paseo: PaseoApi, agentId: string): Prom
|
|
|
581
618
|
let ahead: number | null = null;
|
|
582
619
|
let behind: number | null = null;
|
|
583
620
|
if (!onBase) {
|
|
584
|
-
const counts = await runGit(cwd, ["rev-list", "--left-right", "--count", `${gitInfo.
|
|
621
|
+
const counts = await runGit(cwd, ["rev-list", "--left-right", "--count", `${gitInfo.baseRef}...HEAD`]);
|
|
585
622
|
if (counts.ok) {
|
|
586
623
|
const [bStr, aStr] = counts.stdout.trim().split(/\s+/);
|
|
587
624
|
behind = Number(bStr) || 0;
|
package/shared/core/catalog.ts
CHANGED
|
@@ -101,6 +101,11 @@ export const COMPONENTS = {
|
|
|
101
101
|
group: "Content",
|
|
102
102
|
params: [{ name: "text", kind: "text" }, tone, { name: "title", kind: "string", optional: true }],
|
|
103
103
|
},
|
|
104
|
+
Draft: {
|
|
105
|
+
group: "Content",
|
|
106
|
+
params: [{ name: "markdown", kind: "text" }, { name: "title", kind: "string", optional: true }],
|
|
107
|
+
summary: "text the user approves before it is posted: rendered, with Source and Copy",
|
|
108
|
+
},
|
|
104
109
|
Metric: {
|
|
105
110
|
group: "Content",
|
|
106
111
|
params: [
|
package/shared/core/markdown.ts
CHANGED
|
@@ -434,6 +434,11 @@ function block(node: UiNode): string {
|
|
|
434
434
|
return "---";
|
|
435
435
|
case "Text":
|
|
436
436
|
return inline(props.text);
|
|
437
|
+
case "Draft": {
|
|
438
|
+
const title = inline(props.title);
|
|
439
|
+
const body = inline(props.markdown);
|
|
440
|
+
return paragraphs([title === "" ? "**Draft**" : `**Draft: ${title}**`, body]);
|
|
441
|
+
}
|
|
437
442
|
case "Callout": {
|
|
438
443
|
const title = inline(props.title);
|
|
439
444
|
const text = inline(props.text);
|
package/shared/core/validate.ts
CHANGED
|
@@ -130,6 +130,63 @@ export function coerceState(holds: StateKind | undefined, value: Value): Value |
|
|
|
130
130
|
return undefined;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
type StateExpr = Extract<Expr, { type: "state" }>;
|
|
134
|
+
|
|
135
|
+
/** The empty value an input starts with when its state was never declared. */
|
|
136
|
+
function emptyState(holds: StateKind | undefined): readonly [] | number | boolean | string {
|
|
137
|
+
return holds === "list" ? [] : holds === "number" ? 0 : holds === "boolean" ? false : "";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function children(expr: Expr): readonly Expr[] {
|
|
141
|
+
switch (expr.type) {
|
|
142
|
+
case "literal":
|
|
143
|
+
case "state":
|
|
144
|
+
case "ident":
|
|
145
|
+
return [];
|
|
146
|
+
case "template":
|
|
147
|
+
return expr.parts;
|
|
148
|
+
case "list":
|
|
149
|
+
return expr.items;
|
|
150
|
+
case "object":
|
|
151
|
+
return expr.entries.flatMap((entry) => (typeof entry.key === "object" && entry.key !== null ? [entry.key, entry.value] : [entry.value]));
|
|
152
|
+
case "spread":
|
|
153
|
+
return [expr.value];
|
|
154
|
+
case "unary":
|
|
155
|
+
return [expr.operand];
|
|
156
|
+
case "binary":
|
|
157
|
+
return [expr.left, expr.right];
|
|
158
|
+
case "conditional":
|
|
159
|
+
return [expr.test, expr.then, expr.else];
|
|
160
|
+
case "member":
|
|
161
|
+
return [expr.object];
|
|
162
|
+
case "index":
|
|
163
|
+
return [expr.object, expr.index];
|
|
164
|
+
case "call":
|
|
165
|
+
return [...expr.args, ...expr.named.map((arg) => arg.value)];
|
|
166
|
+
case "method":
|
|
167
|
+
return [expr.object, ...expr.args, ...expr.named.map((arg) => arg.value)];
|
|
168
|
+
case "arrow":
|
|
169
|
+
return [expr.body];
|
|
170
|
+
case "let":
|
|
171
|
+
return [expr.value, expr.body];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Every `$name` passed as an input's binding, in source order, with what that input holds. */
|
|
176
|
+
function inputBindings(expr: Expr): { state: StateExpr; holds: StateKind | undefined }[] {
|
|
177
|
+
const found: { state: StateExpr; holds: StateKind | undefined }[] = [];
|
|
178
|
+
const spec = expr.type === "call" ? COMPONENT_SPECS.get(expr.name) : undefined;
|
|
179
|
+
if (expr.type === "call" && spec !== undefined) {
|
|
180
|
+
spec.params.forEach((param, index) => {
|
|
181
|
+
if (param.kind !== "binding") return;
|
|
182
|
+
const slot = expr.named.find((arg) => arg.name === param.name)?.value ?? expr.args[index];
|
|
183
|
+
if (slot?.type === "state") found.push({ state: slot, holds: param.holds });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
for (const child of children(expr)) found.push(...inputBindings(child));
|
|
187
|
+
return found;
|
|
188
|
+
}
|
|
189
|
+
|
|
133
190
|
/** Params whose literal arguments can be type-checked before evaluation. */
|
|
134
191
|
const LITERAL_KINDS: Partial<Record<ParamKind, Kind>> = { list: "list", number: "number", boolean: "boolean" };
|
|
135
192
|
|
|
@@ -246,6 +303,24 @@ const Validator = defineClass(
|
|
|
246
303
|
}
|
|
247
304
|
}
|
|
248
305
|
|
|
306
|
+
// Agents often bind an input to `$name` without declaring it; declare it empty rather than fail the block.
|
|
307
|
+
const exprs = [...roots, ...[...this.named.values()].map((decl) => decl.value), ...stateDecls.map((decl) => decl.value)];
|
|
308
|
+
for (const slot of exprs.flatMap(inputBindings)) {
|
|
309
|
+
if (this.states.has(slot.state.name) || this.named.has(slot.state.name)) continue;
|
|
310
|
+
const empty = emptyState(slot.holds);
|
|
311
|
+
const { name, pos } = slot.state;
|
|
312
|
+
const value: Expr = typeof empty === "object" ? { type: "list", items: [], pos } : { type: "literal", value: empty, pos };
|
|
313
|
+
const decl: Decl = { name, value, pos };
|
|
314
|
+
this.states.set(decl.name, { index: stateDecls.length, decl });
|
|
315
|
+
stateDecls.push(decl);
|
|
316
|
+
const initial = JSON.stringify(empty);
|
|
317
|
+
this.diagnostics.report(
|
|
318
|
+
slot.state.pos,
|
|
319
|
+
`\`$${decl.name}\` was not declared, so it starts as ${initial}. Declare it first, as in \`$${decl.name} = ${initial}\`.`,
|
|
320
|
+
"warning",
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
249
324
|
const used = new Set<string>();
|
|
250
325
|
const namedRefs = new Map<string, Refs>();
|
|
251
326
|
for (const [name, decl] of this.named) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parseInline } from "./markdown";
|
|
3
|
+
|
|
4
|
+
describe("parseInline links", () => {
|
|
5
|
+
it("reads a Markdown link", () => {
|
|
6
|
+
expect(parseInline("see [the docs](https://paseo.sh/docs) now")).toEqual([
|
|
7
|
+
{ kind: "text", text: "see " },
|
|
8
|
+
{ kind: "link", text: "the docs", url: "https://paseo.sh/docs" },
|
|
9
|
+
{ kind: "text", text: " now" },
|
|
10
|
+
]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("links a bare URL without its trailing punctuation", () => {
|
|
14
|
+
expect(parseInline("go to https://paseo.sh/a_b_c.")).toEqual([
|
|
15
|
+
{ kind: "text", text: "go to " },
|
|
16
|
+
{ kind: "link", text: "https://paseo.sh/a_b_c", url: "https://paseo.sh/a_b_c" },
|
|
17
|
+
{ kind: "text", text: "." },
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("leaves a URL inside code alone", () => {
|
|
22
|
+
expect(parseInline("`https://paseo.sh`")).toEqual([{ kind: "code", text: "https://paseo.sh" }]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("shows a link with an unsafe scheme as its text", () => {
|
|
26
|
+
expect(parseInline("[x](javascript:void)")).toEqual([{ kind: "text", text: "x" }]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -11,7 +11,8 @@ export type Inline =
|
|
|
11
11
|
| { kind: "text"; text: string }
|
|
12
12
|
| { kind: "bold"; text: string }
|
|
13
13
|
| { kind: "italic"; text: string }
|
|
14
|
-
| { kind: "code"; text: string }
|
|
14
|
+
| { kind: "code"; text: string }
|
|
15
|
+
| { kind: "link"; text: string; url: string };
|
|
15
16
|
|
|
16
17
|
export type Block =
|
|
17
18
|
| { kind: "heading"; level: number; content: Inline[] }
|
|
@@ -22,14 +23,23 @@ export type Block =
|
|
|
22
23
|
| { kind: "quote"; content: Inline[] }
|
|
23
24
|
| { kind: "rule" };
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
// A bare URL drops trailing punctuation, so "see https://x.dev." links to https://x.dev.
|
|
27
|
+
const INLINE =
|
|
28
|
+
/(`[^`]+`|\[[^\]\n]+\]\([^)\s]+\)|https?:\/\/[^\s<>]*[^\s<>.,;:!?'")\]*_]|\*\*[^*]+\*\*|__[^_]+__|\*[^*\n]+\*|_[^_\n]+_)/;
|
|
29
|
+
const LINK = /^\[([^\]\n]+)\]\(([^)\s]+)\)$/;
|
|
26
30
|
|
|
27
31
|
export function parseInline(text: string): Inline[] {
|
|
28
32
|
const out: Inline[] = [];
|
|
29
33
|
for (const piece of text.split(INLINE)) {
|
|
30
34
|
if (piece.length === 0) continue;
|
|
35
|
+
const link = LINK.exec(piece);
|
|
31
36
|
if (piece.startsWith("`") && piece.endsWith("`") && piece.length > 1) {
|
|
32
37
|
out.push({ kind: "code", text: piece.slice(1, -1) });
|
|
38
|
+
} else if (link) {
|
|
39
|
+
// Only web and mail links open; any other scheme (javascript:, file:) shows as its text.
|
|
40
|
+
out.push(/^(https?:|mailto:)/i.test(link[2]) ? { kind: "link", text: link[1], url: link[2] } : { kind: "text", text: link[1] });
|
|
41
|
+
} else if (/^https?:\/\//.test(piece)) {
|
|
42
|
+
out.push({ kind: "link", text: piece, url: piece });
|
|
33
43
|
} else if ((piece.startsWith("**") && piece.endsWith("**")) || (piece.startsWith("__") && piece.endsWith("__"))) {
|
|
34
44
|
out.push({ kind: "bold", text: piece.slice(2, -2) });
|
|
35
45
|
} else if ((piece.startsWith("*") && piece.endsWith("*")) || (piece.startsWith("_") && piece.endsWith("_"))) {
|
package/shared/genui.test.ts
CHANGED
|
@@ -64,6 +64,28 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
|
|
|
64
64
|
expect(roots.map((root) => root.props.text)).toEqual(["x,z,y", "1,9,10", "x,y"]);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
it("declares state an input binds to but the block never declared", () => {
|
|
68
|
+
const compiled = compile(`Card("x", [
|
|
69
|
+
Text($org == "" ? "no org" : $org),
|
|
70
|
+
Form([
|
|
71
|
+
Radio($browser, [{value: "A", detail: "a"}], label: "Q1"),
|
|
72
|
+
Input($org, label: "Q2"),
|
|
73
|
+
Toggle($ok, "Q3"),
|
|
74
|
+
Checklist($picks, ["a", "b"]),
|
|
75
|
+
Slider($n, 0, 10)
|
|
76
|
+
], submit: "Send")
|
|
77
|
+
])`);
|
|
78
|
+
expect(compiled.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
|
|
79
|
+
expect(compiled.diagnostics.filter((d) => d.severity === "warning")).toHaveLength(5);
|
|
80
|
+
expect(initialState(compiled.program!)).toEqual({ browser: "", org: "", ok: false, picks: [], n: 0 });
|
|
81
|
+
expect(evaluate(compiled.program!, initialState(compiled.program!)).diagnostics).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("still reports state that no input binds to", () => {
|
|
85
|
+
const compiled = compile('Text($missing)');
|
|
86
|
+
expect(compiled.diagnostics.some((d) => d.severity === "error" && d.message.includes("unknown state `$missing`"))).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
|
|
67
89
|
it("renders a bare Send, OpenUrl or Copy among children as a Button", () => {
|
|
68
90
|
const compiled = compile('Card("x", [Text("a"), OpenUrl("https://docs.google.com/x"), Send("Go"), Copy("id")])');
|
|
69
91
|
expect(compiled.diagnostics.filter((d) => d.severity === "error")).toEqual([]);
|
|
@@ -261,3 +283,29 @@ describe("paseo-plugin-genui core, instructions, and gallery", () => {
|
|
|
261
283
|
}
|
|
262
284
|
});
|
|
263
285
|
});
|
|
286
|
+
|
|
287
|
+
describe("Draft", () => {
|
|
288
|
+
it("is in the catalog and compiles with and without a title", () => {
|
|
289
|
+
expect(COMPONENTS.Draft.group).toBe("Content");
|
|
290
|
+
for (const call of ['Draft("**hi**")', 'Draft("**hi**", "PR reply")']) {
|
|
291
|
+
const compiled = compile(`Card("x", [${call}])`);
|
|
292
|
+
expect(compiled.diagnostics, call).toEqual([]);
|
|
293
|
+
expect(compiled.program).not.toBeNull();
|
|
294
|
+
}
|
|
295
|
+
expect(compile('Card("x", [Draft()])').diagnostics.length).toBeGreaterThan(0);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("keeps the draft label in the markdown fallback", async () => {
|
|
299
|
+
const load = (req: { path: string }) => loadGalleryFile(req.path, req);
|
|
300
|
+
const untitled = await renderReplyMarkdown('```ui\nDraft("Looks good")\n```', load);
|
|
301
|
+
expect(untitled).toContain("**Draft**");
|
|
302
|
+
expect(untitled).toContain("Looks good");
|
|
303
|
+
const titled = await renderReplyMarkdown('```ui\nDraft("Looks good", "PR reply")\n```', load);
|
|
304
|
+
expect(titled).toContain("**Draft: PR reply**");
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("is listed in the agent reference with a rule against markdown Code", () => {
|
|
308
|
+
expect(UI_REFERENCE).toContain("Draft(markdown, title?)");
|
|
309
|
+
expect(CODE_WORK_INSTRUCTIONS).toContain("Draft(markdown, title)");
|
|
310
|
+
});
|
|
311
|
+
});
|
package/shared/instructions.ts
CHANGED
|
@@ -49,6 +49,7 @@ Replies here are read in Paseo, which draws these components; pasted output, a m
|
|
|
49
49
|
- outdated or vulnerable packages → Dependencies: \`npm outdated --json --long\`, \`npm audit --json\`, \`pip list --outdated --format=json\`
|
|
50
50
|
- a CI run → Pipeline: \`gh run view <id> --json name,displayTitle,status,conclusion,event,headBranch,headSha,url,createdAt,updatedAt,jobs\`
|
|
51
51
|
- timings you measured (before/after, A vs B) → Benchmark([{name, before, after, unit}]) or Load(\`hyperfine --export-json\`); a page load → Waterfall(Load(a HAR)); what takes space → Treemap(Load(\`du -k -d 2 <dir>\` or an esbuild metafile))
|
|
52
|
+
- text the user must approve before it is posted (PR comments, replies, messages) → Draft(markdown, title), never Code(…, "markdown")
|
|
52
53
|
- an API response → Json(Load(…)) from \`curl -s -o\`
|
|
53
54
|
- what you changed → Changes(); a commit → Changes(sha); this branch's commits → Commits(); the pull request → PullRequest(); subthreads → Threads()
|
|
54
55
|
- tasks or issues → Board(Load(…)) from \`gh issue list --json number,title,state,labels,assignees,url,updatedAt\`
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { clampZoom, MAX_ZOOM, wheelFactor, zoomAt } from "./lightbox";
|
|
3
|
+
|
|
4
|
+
describe("lightbox zoom", () => {
|
|
5
|
+
it("keeps the point under the cursor still", () => {
|
|
6
|
+
const next = zoomAt({ zoom: 1, x: 0, y: 0 }, 2, { x: 100, y: -50 }, 0.5);
|
|
7
|
+
// image point under the cursor was (100, -50) / 1; after zoom it must map back to the cursor
|
|
8
|
+
expect((100 - next!.x) / next!.zoom).toBeCloseTo(100);
|
|
9
|
+
expect((-50 - next!.y) / next!.zoom).toBeCloseTo(-50);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns to fit (null) rather than a fixed zoom, so a later resize refits", () => {
|
|
13
|
+
expect(zoomAt({ zoom: 1, x: 40, y: 40 }, 0.1, { x: 0, y: 0 }, 0.5)).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("clamps between fit (or 100% for small images) and the max", () => {
|
|
17
|
+
expect(clampZoom(0.1, 0.4)).toBe(0.4);
|
|
18
|
+
expect(clampZoom(0.1, 1)).toBe(1);
|
|
19
|
+
expect(clampZoom(50, 0.4)).toBe(MAX_ZOOM);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("wheel up zooms in, wheel down zooms out", () => {
|
|
23
|
+
expect(wheelFactor(-100, false)).toBeGreaterThan(1);
|
|
24
|
+
expect(wheelFactor(100, false)).toBeLessThan(1);
|
|
25
|
+
expect(wheelFactor(-10, true)).toBeGreaterThan(wheelFactor(-10, false));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("treats line and page wheel deltas like their pixel size", () => {
|
|
29
|
+
expect(wheelFactor(-3, false, 1)).toBeCloseTo(wheelFactor(-48, false, 0));
|
|
30
|
+
expect(wheelFactor(-1, false, 2)).toBeCloseTo(wheelFactor(-800, false, 0));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type LightboxView = { readonly zoom: number; readonly x: number; readonly y: number };
|
|
2
|
+
|
|
3
|
+
export const MAX_ZOOM = 8;
|
|
4
|
+
|
|
5
|
+
const LINE_PX = 16;
|
|
6
|
+
const PAGE_PX = 800;
|
|
7
|
+
|
|
8
|
+
export function clampZoom(zoom: number, fit: number): number {
|
|
9
|
+
return Math.min(MAX_ZOOM, Math.max(Math.min(fit, 1), zoom));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Zooms by `factor` keeping the image point under `at` still; `at` and x/y are offsets from the stage centre.
|
|
14
|
+
* Returns null at fit so the view follows the stage when it is resized.
|
|
15
|
+
*/
|
|
16
|
+
export function zoomAt(view: LightboxView, factor: number, at: { x: number; y: number }, fit: number): LightboxView | null {
|
|
17
|
+
const zoom = clampZoom(view.zoom * factor, fit);
|
|
18
|
+
if (zoom <= fit) return null;
|
|
19
|
+
const ratio = zoom / view.zoom;
|
|
20
|
+
return { zoom, x: at.x - (at.x - view.x) * ratio, y: at.y - (at.y - view.y) * ratio };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Wheel delta to zoom factor; trackpad pinch arrives as a ctrl+wheel with small deltas. `deltaMode` 1 = lines, 2 = pages. */
|
|
24
|
+
export function wheelFactor(deltaY: number, pinch: boolean, deltaMode = 0): number {
|
|
25
|
+
const px = deltaY * (deltaMode === 1 ? LINE_PX : deltaMode === 2 ? PAGE_PX : 1);
|
|
26
|
+
return Math.exp(-px * (pinch ? 0.01 : 0.0015));
|
|
27
|
+
}
|