paseo-plugin-mermaid 0.4.3 → 0.5.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/OVERVIEW.md +8 -2
- package/README.md +72 -30
- package/client/diagram.tsx +263 -2
- package/client/file-panel.tsx +2 -1
- package/index.client.tsx +17 -6
- package/package.json +5 -5
- package/shared/classic-shapes.ts +126 -0
- package/shared/drawable.ts +30 -10
- package/shared/fence.ts +10 -0
- package/shared/file-view.ts +6 -8
- package/shared/flowchart.ts +298 -41
- package/shared/layout.ts +47 -7
- package/shared/segment.ts +104 -42
- package/shared/transform.ts +64 -12
package/OVERVIEW.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
Mermaid draws `mermaid` code blocks in agent and user messages as diagrams in the chat timeline, at the width of the message and from the first streamed line. It draws flowcharts and sequence diagrams.
|
|
1
|
+
Mermaid draws `mermaid` code blocks in agent and user messages as diagrams in the chat timeline, at the width of the message and from the first streamed line. It draws flowcharts and sequence diagrams. Flowchart shapes include cylinders, hexagons, parallelograms, trapezoids and double circles, written in brackets or in the Mermaid 11 `@{ shape }` syntax.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Other diagrams go to Mermaid. On Paseo 0.13 and newer, a diagram the plugin does not draw in full (other diagram types, subgraphs, `style` and `classDef` lines, sequence blocks like `loop`, `%%{init}%%` directives) is rendered by Mermaid through Paseo's Markdown, inside the plugin's message, and the message's other diagrams stay inline. A message that defines reference-style links or footnotes is rendered whole by Paseo's Markdown. On Paseo 0.11 and 0.12, such messages are left to Paseo's own renderer. On Android, parallelograms and trapezoids go to Mermaid too, because React Native cannot skew a View there.
|
|
4
|
+
|
|
5
|
+
Paseo's renderer refuses `@{`, so the plugin first writes the shape objects it reads in bracket syntax. An object it does not read, such as another shape name or a key like `img`, shows as code.
|
|
6
|
+
|
|
7
|
+
On Paseo 0.13 and newer, the text around a diagram uses Paseo's own Markdown, so it looks like the rest of the chat. On Paseo 0.11 and 0.12 it uses a limited renderer (headings, lists, emphasis and code). Messages without a diagram are left to Paseo.
|
|
8
|
+
|
|
9
|
+
With Better Paseo installed, turn off its "Plugin markdown for replies" setting, which is on by default. Paseo gives a reply to the first plugin that takes it, `better-paseo` comes first, and with that setting on it shows mermaid blocks as code before this plugin sees them.
|
|
4
10
|
|
|
5
11
|
Each diagram has a toolbar to zoom, fit to view, pop out to a larger view, and show the code. Zoom matches Paseo's own diagram viewer: 100% is the drawing fitted to the row.
|
|
6
12
|
|
package/README.md
CHANGED
|
@@ -29,14 +29,15 @@ Listed in the [Paseo plugin directory](https://paseo.sh/plugins/dutchakdev/merma
|
|
|
29
29
|
- **A toolbar on every diagram:** zoom, fit to view, pop out, and the source on demand.
|
|
30
30
|
- **`.mmd` files in the file tab** on Paseo 0.13 and newer, redrawn when the file changes.
|
|
31
31
|
- **Nothing leaves the app.** The plugin has no server half, no settings and no network
|
|
32
|
-
access; it reads the message text it is given and draws it with React Native views
|
|
32
|
+
access; it reads the message text it is given and draws it with React Native views
|
|
33
|
+
or passes it to Paseo's Markdown.
|
|
33
34
|
|
|
34
35
|
Paseo draws Mermaid itself too, in an iframe inside a zoomable box with a
|
|
35
36
|
fullscreen viewer, and it draws every diagram type. This plugin draws flowcharts
|
|
36
37
|
and sequence diagrams inline instead: readable at the width of the message, from
|
|
37
38
|
the first streamed line, with the same controls above it for the times the fitted
|
|
38
39
|
drawing is not enough: zoom, fit to view, pop out, and the source on demand. A
|
|
39
|
-
diagram it cannot draw in full
|
|
40
|
+
diagram it cannot draw in full goes to Mermaid; see [What it draws](#what-it-draws).
|
|
40
41
|
|
|
41
42
|
## Install
|
|
42
43
|
|
|
@@ -83,23 +84,40 @@ paseo plugin install "$PWD"
|
|
|
83
84
|
| Diagram | Supported |
|
|
84
85
|
| ------- | --------- |
|
|
85
86
|
| `flowchart` / `graph` | `TD`, `TB`, `BT`, `LR`, `RL` |
|
|
86
|
-
| Node shapes | `[rect]`, `(round)`, `([stadium])`, `[[subroutine]]`, `{diamond}`, `((circle))`, `>asymmetric]` |
|
|
87
|
+
| Node shapes | `[rect]`, `(round)`, `([stadium])`, `[[subroutine]]`, `[(cylinder)]`, `{diamond}`, `{{hexagon}}`, `((circle))`, `(((double circle)))`, `>asymmetric]`, `[/parallelogram/]`, `[\alt parallelogram\]`, `[/trapezoid\]`, `[\alt trapezoid/]` |
|
|
88
|
+
| Shape objects | `id@{ shape: db, label: "Orders" }` for the names Mermaid 11 gives these shapes (`cyl`, `db`, `hex`, `lean-r`, `trap-t`, `dbl-circ`, ...) |
|
|
87
89
|
| Edges | `-->`, `---`, `-.->`, `-.-`, `==>`, `===` |
|
|
88
90
|
| Edge labels | `-->|both|` and `-- forms -->` |
|
|
89
91
|
| `sequenceDiagram` | participants, actors, notes, messages to oneself |
|
|
90
92
|
| Message arrows | `->`, `->>`, `-->`, `-->>`, `-x`, `--x`, `-)`, `--)` |
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`alt`, `%%{init}%%` directives,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
94
|
+
A node given twice takes the last label and shape, as in Mermaid.
|
|
95
|
+
|
|
96
|
+
Everything else goes to Mermaid: other diagram types, subgraphs, Markdown string
|
|
97
|
+
labels, `style` and `classDef` lines, `&` and `;` joining nodes or statements on
|
|
98
|
+
one line, sequence blocks such as `loop` and `alt`, `%%{init}%%` directives, front
|
|
99
|
+
matter, and shape objects with another shape name or key. On Android,
|
|
100
|
+
React Native cannot skew a View, so a diagram with a parallelogram or a trapezoid
|
|
101
|
+
goes to Mermaid there too. Where Mermaid runs depends on your Paseo:
|
|
102
|
+
|
|
103
|
+
| Paseo | A diagram the plugin does not draw in full |
|
|
104
|
+
| ----- | ------------------------------------------ |
|
|
105
|
+
| 0.13 and newer | Stays in the plugin's message and renders through Paseo's Markdown, which uses Mermaid. Other diagrams in the message stay inline. |
|
|
106
|
+
| 0.11 and 0.12 | Paseo has no such Markdown, so the whole message is left to Paseo's own renderer. |
|
|
107
|
+
|
|
108
|
+
A message that defines reference-style links or footnotes is kept whole on 0.13
|
|
109
|
+
and newer and rendered by Paseo's Markdown, which also draws its diagrams. On
|
|
110
|
+
0.11 and 0.12 it is left to Paseo: split around the diagram, a definition in one
|
|
111
|
+
piece would not reach the link in another.
|
|
112
|
+
|
|
113
|
+
Paseo's renderer refuses any source holding `@{`. So before a diagram reaches it,
|
|
114
|
+
in a message, a kept-whole message or the `.mmd` tab, the plugin writes each shape
|
|
115
|
+
object it reads in bracket syntax: `A@{ shape: db, label: "Orders" }` becomes
|
|
116
|
+
`A[("Orders")]`. An object it does not read stays as written, and Paseo shows that
|
|
117
|
+
diagram as code: another shape name such as `cloud`, another key such as `img` or
|
|
118
|
+
`icon`, an object over several lines, a label containing `"`.
|
|
119
|
+
|
|
120
|
+
When the plugin renders a message, the text around the diagram goes through Paseo's
|
|
103
121
|
own Markdown on Paseo 0.13 and newer, so it looks like the rest of the chat. On
|
|
104
122
|
0.11 and 0.12 it goes through the plugin's renderer, which covers headings, lists,
|
|
105
123
|
emphasis and code.
|
|
@@ -132,19 +150,36 @@ has the same toolbar as in the chat and redraws when the file changes on disk, s
|
|
|
132
150
|
a diagram an agent is editing updates in place. A diagram the plugin does not draw
|
|
133
151
|
in full is rendered in the same tab by Paseo's Markdown, which uses Mermaid.
|
|
134
152
|
|
|
153
|
+
## With Better Paseo
|
|
154
|
+
|
|
155
|
+
Paseo gives a reply to the first plugin, by plugin id, whose transformer takes it.
|
|
156
|
+
`better-paseo` sorts before `mermaid`, and with its setting **Plugin markdown for
|
|
157
|
+
replies** on, the default, it takes every assistant reply and shows mermaid fences
|
|
158
|
+
as code. This plugin never sees those replies. Turn the setting off to get
|
|
159
|
+
diagrams. Paseo declined to chain transformers
|
|
160
|
+
([getpaseo/paseo#8785](https://github.com/getpaseo/paseo/issues/8785)).
|
|
161
|
+
|
|
135
162
|
## How it works
|
|
136
163
|
|
|
137
164
|
```mermaid
|
|
138
165
|
flowchart TD
|
|
139
166
|
Msg([Message arrives]) --> Check{Has mermaid?}
|
|
140
167
|
Check -->|no| Paseo[Paseo renders it]
|
|
141
|
-
Check -->|yes|
|
|
168
|
+
Check -->|yes| Host{Paseo 0.13 or newer?}
|
|
169
|
+
Host -->|yes| Defs{Link definitions or footnotes?}
|
|
170
|
+
Defs -->|no| Split[[Split into segments]]
|
|
171
|
+
Defs -->|yes| Whole[Message kept whole]
|
|
172
|
+
Whole --> Fix
|
|
173
|
+
Host -->|no| Full{All drawn in full, no definitions?}
|
|
142
174
|
Full -->|no| Paseo
|
|
143
|
-
Full -->|yes| Split
|
|
175
|
+
Full -->|yes| Split
|
|
144
176
|
Split --> Text(Prose)
|
|
145
177
|
Split --> Src(Diagram source)
|
|
146
178
|
Text --> Md[Paseo Markdown from 0.13]
|
|
147
|
-
Src -->
|
|
179
|
+
Src --> Own{Drawn in full?}
|
|
180
|
+
Own -->|no| Fix[Shape objects to brackets]
|
|
181
|
+
Fix --> Mer[Mermaid through Paseo's Markdown]
|
|
182
|
+
Own -->|yes| Parse{Which parser?}
|
|
148
183
|
Parse -->|flowchart| Layout[Layered layout]
|
|
149
184
|
Parse -->|sequence| Columns[Column layout]
|
|
150
185
|
Layout --> Draw((Views))
|
|
@@ -166,16 +201,19 @@ diagram, the plugin owns the message. It is split into prose and diagram
|
|
|
166
201
|
segments, and each becomes its own item, so the text around the diagram keeps its
|
|
167
202
|
place. From Paseo 0.13 that prose goes through Paseo's own Markdown component;
|
|
168
203
|
before it, through a small renderer covering headings, lists, emphasis and code.
|
|
204
|
+
On 0.13 and newer, a diagram the plugin cannot draw becomes a text item holding
|
|
205
|
+
its source as a mermaid fence, which Paseo's Markdown renders with Mermaid
|
|
206
|
+
(`shared/fence.ts`).
|
|
169
207
|
Messages without a diagram are left alone entirely.
|
|
170
208
|
|
|
171
|
-
**A diagram is drawn in full or not at all.**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
209
|
+
**A diagram is drawn in full or not at all.** A drawing with lines missing would
|
|
210
|
+
be worse than Mermaid's. The parsers report every line they skip, and one skipped
|
|
211
|
+
line sends that diagram to Mermaid (`shared/drawable.ts`). That is decided from
|
|
212
|
+
what the parsers read, not from the first word of the source, so the parsers
|
|
213
|
+
refuse what they would draw wrong rather than accept it loosely: a label with a
|
|
214
|
+
stray square bracket, a label wrapped whole in brackets that names another shape,
|
|
215
|
+
a directive. Each diagram in a message is judged alone on 0.13 and newer. Before
|
|
216
|
+
that, one such diagram leaves the whole message to Paseo.
|
|
179
217
|
|
|
180
218
|
**Items store the source, not a parsed graph.** Parsing happens at render time.
|
|
181
219
|
The stored data stays small, and a later fix to the parser improves diagrams that
|
|
@@ -188,8 +226,10 @@ diagram for the whole stream and then swap renderers at the last line. An
|
|
|
188
226
|
unfinished block is therefore taken over at once and drawn from whatever has
|
|
189
227
|
parsed so far. While the message streams and the fence is open, the last line
|
|
190
228
|
counts only once its newline has arrived: until then it may be half typed.
|
|
191
|
-
|
|
192
|
-
|
|
229
|
+
A diagram going to Mermaid gets only its finished lines too, since Paseo's
|
|
230
|
+
Markdown draws every update as final and a half-typed line would show as code.
|
|
231
|
+
Finished lines never change, so a diagram that does need Mermaid, say one that
|
|
232
|
+
opens a subgraph, moves to it once, at the first line that shows it. A finished
|
|
193
233
|
message is judged on every line, even when its fence never closed.
|
|
194
234
|
|
|
195
235
|
**The drawing is fitted to the row.** A diagram's natural size is whatever its
|
|
@@ -212,9 +252,9 @@ The parsers, the layout, the zoom model and the transform are pure functions
|
|
|
212
252
|
with no runtime dependencies, and that is where the tests are: bracket shapes,
|
|
213
253
|
operator precedence (`-.->` must never read as `-.-` plus a stray `>`), cycles in
|
|
214
254
|
a flowchart, node overlap, arrow direction, zoom steps that land back on 100%,
|
|
215
|
-
which toolbar controls are live, which diagrams go to
|
|
255
|
+
which toolbar controls are live, which diagrams go to Mermaid (checked on diagrams
|
|
216
256
|
from this owner's own docs, in `tests/fixtures/`), that a message streamed one
|
|
217
|
-
character at a time changes renderer at most once and only towards
|
|
257
|
+
character at a time changes renderer at most once and only towards Mermaid, and the
|
|
218
258
|
JSON round trip Paseo performs on item data before rendering. The Views themselves are checked by
|
|
219
259
|
`npm run typecheck` and by reloading the plugin. `npm run check:bundle` compiles
|
|
220
260
|
the client entry with the installed daemon's compiler and loads it into a stand-in
|
|
@@ -224,11 +264,13 @@ the client entry with the installed daemon's compiler and loads it into a stand-
|
|
|
224
264
|
| ---- | ---- |
|
|
225
265
|
| `shared/segment.ts` | splits a message into prose and diagram blocks |
|
|
226
266
|
| `shared/flowchart.ts` | flowchart parser |
|
|
267
|
+
| `shared/classic-shapes.ts` | writes shape objects in bracket syntax for Paseo's renderer |
|
|
227
268
|
| `shared/sequence.ts` | sequence diagram parser |
|
|
228
269
|
| `shared/layout.ts` | layered layout, orthogonal edge routing, column layout |
|
|
229
270
|
| `shared/markdown.ts` | the Markdown subset used for prose |
|
|
230
271
|
| `shared/zoom.ts` | zoom steps, fit to view, and which controls are live |
|
|
231
|
-
| `shared/drawable.ts` | whether the plugin draws a diagram in full, or
|
|
272
|
+
| `shared/drawable.ts` | whether the plugin draws a diagram in full, or hands it to Mermaid |
|
|
273
|
+
| `shared/fence.ts` | wraps diagram source in a mermaid fence for Paseo's Markdown |
|
|
232
274
|
| `shared/transform.ts` | the timeline transform itself |
|
|
233
275
|
| `shared/file-view.ts` | what the file panel shows for a `.mmd` file |
|
|
234
276
|
| `client/diagram.tsx` | drawing, in Views, at natural size |
|
package/client/diagram.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import { Platform, StyleSheet, Text, View, type StyleProp, type ViewStyle } from "react-native";
|
|
4
4
|
import { parseFlowchart, type Flowchart, type NodeShape } from "../shared/flowchart";
|
|
5
5
|
import {
|
|
6
|
+
CYLINDER_CAP,
|
|
7
|
+
DOUBLE_RING_GAP,
|
|
6
8
|
layoutFlowchart,
|
|
7
9
|
layoutSequence,
|
|
8
10
|
SELF_LABEL_GAP,
|
|
9
11
|
SELF_LOOP_WIDTH,
|
|
12
|
+
slantFor,
|
|
10
13
|
type FlowLayout,
|
|
11
14
|
type LaidOutEdge,
|
|
12
15
|
type LaidOutNode,
|
|
@@ -29,6 +32,14 @@ import type { Size } from "../shared/zoom";
|
|
|
29
32
|
|
|
30
33
|
const ARROW = 5;
|
|
31
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Whether this app can shear a View, which the parallelograms and trapezoids need.
|
|
37
|
+
* React Native on Android drops `skewX`, so there a diagram with one of them goes to
|
|
38
|
+
* Mermaid as soon as the line that gives the shape has finished (`drawable`'s
|
|
39
|
+
* `skew` option).
|
|
40
|
+
*/
|
|
41
|
+
export const canSkew = Platform.OS !== "android";
|
|
42
|
+
|
|
32
43
|
export type ParsedDiagram =
|
|
33
44
|
| { kind: "flow"; layout: FlowLayout; skipped: Flowchart["skipped"] }
|
|
34
45
|
| { kind: "sequence"; diagram: SequenceDiagram; size: Size }
|
|
@@ -64,7 +75,7 @@ export function Drawing({ parsed, theme }: { parsed: DrawableDiagram; theme: Plu
|
|
|
64
75
|
|
|
65
76
|
/**
|
|
66
77
|
* Source that names no diagram yet. The transform hands every diagram this plugin
|
|
67
|
-
* cannot draw to
|
|
78
|
+
* cannot draw to Mermaid, so what reaches here is a diagram still arriving, shown as
|
|
68
79
|
* it is typed until its header settles.
|
|
69
80
|
*/
|
|
70
81
|
export function Arriving({ source, theme }: { source: string; theme: PluginTheme }) {
|
|
@@ -143,6 +154,17 @@ function NodeView({ node, theme }: { node: LaidOutNode; theme: PluginTheme }) {
|
|
|
143
154
|
);
|
|
144
155
|
}
|
|
145
156
|
|
|
157
|
+
if (BUILT.has(node.shape)) {
|
|
158
|
+
return (
|
|
159
|
+
<View style={common}>
|
|
160
|
+
<Outline node={node} theme={theme} />
|
|
161
|
+
<View style={[{ position: "absolute", alignItems: "center", justifyContent: "center", paddingHorizontal: 8 }, labelArea(node)]}>
|
|
162
|
+
<Text style={{ color: theme.colors.foreground, fontSize: 12, textAlign: "center" }}>{node.label}</Text>
|
|
163
|
+
</View>
|
|
164
|
+
</View>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
146
168
|
return (
|
|
147
169
|
<View
|
|
148
170
|
style={[
|
|
@@ -177,6 +199,245 @@ function NodeView({ node, theme }: { node: LaidOutNode; theme: PluginTheme }) {
|
|
|
177
199
|
);
|
|
178
200
|
}
|
|
179
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Shapes no single box can draw. Each is built from a few Views behind an upright
|
|
204
|
+
* label, so no text is ever rotated or sheared. Their outlines reach the box
|
|
205
|
+
* where the layout routes edges to it: the top and bottom middle, and at
|
|
206
|
+
* mid-height either the box side or, for slanted sides, `sideInset` in from it.
|
|
207
|
+
*/
|
|
208
|
+
const BUILT: ReadonlySet<NodeShape> = new Set([
|
|
209
|
+
"cylinder",
|
|
210
|
+
"hexagon",
|
|
211
|
+
"lean-right",
|
|
212
|
+
"lean-left",
|
|
213
|
+
"trapezoid",
|
|
214
|
+
"trapezoid-top",
|
|
215
|
+
"double-circle",
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
interface Box {
|
|
219
|
+
left: number;
|
|
220
|
+
top: number;
|
|
221
|
+
width: number;
|
|
222
|
+
height: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The part of a built shape's box that its outline leaves clear for the label. */
|
|
226
|
+
function labelArea(node: LaidOutNode): Box {
|
|
227
|
+
const { width, height } = node;
|
|
228
|
+
switch (node.shape) {
|
|
229
|
+
case "cylinder":
|
|
230
|
+
// Below the lid's two arcs, above the base's one.
|
|
231
|
+
return { left: 0, top: 2 * CYLINDER_CAP, width, height: height - 3 * CYLINDER_CAP };
|
|
232
|
+
case "hexagon":
|
|
233
|
+
return { left: height / 2, top: 0, width: width - height, height };
|
|
234
|
+
case "lean-right":
|
|
235
|
+
case "lean-left": {
|
|
236
|
+
const slant = slantFor(height);
|
|
237
|
+
return { left: slant / 2, top: 0, width: width - slant, height };
|
|
238
|
+
}
|
|
239
|
+
case "trapezoid":
|
|
240
|
+
case "trapezoid-top": {
|
|
241
|
+
// The narrow side bounds the label.
|
|
242
|
+
const slant = slantFor(height);
|
|
243
|
+
return { left: slant, top: 0, width: width - 2 * slant, height };
|
|
244
|
+
}
|
|
245
|
+
case "double-circle":
|
|
246
|
+
return {
|
|
247
|
+
left: DOUBLE_RING_GAP,
|
|
248
|
+
top: DOUBLE_RING_GAP,
|
|
249
|
+
width: width - 2 * DOUBLE_RING_GAP,
|
|
250
|
+
height: height - 2 * DOUBLE_RING_GAP,
|
|
251
|
+
};
|
|
252
|
+
default:
|
|
253
|
+
return { left: 0, top: 0, width, height };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function Outline({ node, theme }: { node: LaidOutNode; theme: PluginTheme }) {
|
|
258
|
+
const { width, height } = node;
|
|
259
|
+
const accent = theme.colors.accent;
|
|
260
|
+
const fill = theme.colors.surface0;
|
|
261
|
+
const outline: ViewStyle = { borderWidth: 1, borderColor: accent, backgroundColor: fill };
|
|
262
|
+
// A plain filled View: a line, or an area of fill with no border of its own.
|
|
263
|
+
const solid = (left: number, top: number, w: number, h: number, color: string) => (
|
|
264
|
+
<View style={{ position: "absolute", left, top, width: w, height: h, backgroundColor: color }} />
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
// Where a View's edge falls across a line of the outline, that View must not
|
|
268
|
+
// paint fill under the line: at a fractional pixel, as under the viewer's
|
|
269
|
+
// scale, the browser blends the fill into the line along that edge and the
|
|
270
|
+
// outline shows a light notch. So at every join lines meet lines and fill
|
|
271
|
+
// meets fill.
|
|
272
|
+
switch (node.shape) {
|
|
273
|
+
case "cylinder": {
|
|
274
|
+
// The base ellipse first, the body over its upper half so only the lower arc
|
|
275
|
+
// shows, the whole lid last. The body's sides start and end on the ellipses'
|
|
276
|
+
// centre lines, where the ellipses are widest and run straight down; its
|
|
277
|
+
// fill stops at the sides instead of running under them.
|
|
278
|
+
const ellipse = (top: number) => (
|
|
279
|
+
<View
|
|
280
|
+
style={[outline, { position: "absolute", left: 0, top, width, height: 2 * CYLINDER_CAP, borderRadius: "50%" }]}
|
|
281
|
+
/>
|
|
282
|
+
);
|
|
283
|
+
const body = height - 2 * CYLINDER_CAP;
|
|
284
|
+
return (
|
|
285
|
+
<>
|
|
286
|
+
{ellipse(height - 2 * CYLINDER_CAP)}
|
|
287
|
+
{solid(1, CYLINDER_CAP, width - 2, body, fill)}
|
|
288
|
+
{solid(0, CYLINDER_CAP, 1, body, accent)}
|
|
289
|
+
{solid(width - 1, CYLINDER_CAP, 1, body, accent)}
|
|
290
|
+
{ellipse(0)}
|
|
291
|
+
</>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
case "hexagon": {
|
|
295
|
+
// Two diamonds give the points, as in the diamond shape: a square of side
|
|
296
|
+
// height / root two, turned 45 degrees, spans the height and reaches the box
|
|
297
|
+
// side with its corner. A band between their centres covers their inner
|
|
298
|
+
// halves and draws the flat top and bottom.
|
|
299
|
+
const side = height / Math.SQRT2;
|
|
300
|
+
const point = (centre: number) => (
|
|
301
|
+
<View
|
|
302
|
+
style={[
|
|
303
|
+
outline,
|
|
304
|
+
{
|
|
305
|
+
position: "absolute",
|
|
306
|
+
left: centre - side / 2,
|
|
307
|
+
top: (height - side) / 2,
|
|
308
|
+
width: side,
|
|
309
|
+
height: side,
|
|
310
|
+
transform: [{ rotate: "45deg" }],
|
|
311
|
+
},
|
|
312
|
+
]}
|
|
313
|
+
/>
|
|
314
|
+
);
|
|
315
|
+
return (
|
|
316
|
+
<>
|
|
317
|
+
{point(height / 2)}
|
|
318
|
+
{point(width - height / 2)}
|
|
319
|
+
<View
|
|
320
|
+
style={{
|
|
321
|
+
position: "absolute",
|
|
322
|
+
left: height / 2,
|
|
323
|
+
top: 0,
|
|
324
|
+
width: width - height,
|
|
325
|
+
height,
|
|
326
|
+
borderTopWidth: 1,
|
|
327
|
+
borderBottomWidth: 1,
|
|
328
|
+
borderColor: accent,
|
|
329
|
+
backgroundColor: fill,
|
|
330
|
+
}}
|
|
331
|
+
/>
|
|
332
|
+
</>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
case "lean-right":
|
|
336
|
+
case "lean-left":
|
|
337
|
+
return <Parallelogram node={node} sides={node.shape === "lean-right" ? "/" : "\\"} left={0} outline={outline} />;
|
|
338
|
+
case "trapezoid":
|
|
339
|
+
case "trapezoid-top": {
|
|
340
|
+
// The left half of one parallelogram and the right half of the other, each
|
|
341
|
+
// clipped to its half of the box and overlapping a pixel each way around
|
|
342
|
+
// the middle, where both hold the same top and bottom lines and the same
|
|
343
|
+
// fill. The clip edges cut through those lines, so the fill sits in a child
|
|
344
|
+
// inside the borders rather than under them. `[/ \]` is wide at the bottom.
|
|
345
|
+
const wideAtBottom = node.shape === "trapezoid";
|
|
346
|
+
const half = width / 2;
|
|
347
|
+
const clip: ViewStyle = { position: "absolute", top: 0, width: half + 1, height, overflow: "hidden" };
|
|
348
|
+
const lines: ViewStyle = { borderColor: accent, borderTopWidth: 1, borderBottomWidth: 1 };
|
|
349
|
+
const inside = <View style={{ position: "absolute", left: 0, right: 0, top: 0, bottom: 0, backgroundColor: fill }} />;
|
|
350
|
+
return (
|
|
351
|
+
<>
|
|
352
|
+
<View style={[clip, { left: 0 }]}>
|
|
353
|
+
<Parallelogram node={node} sides={wideAtBottom ? "/" : "\\"} left={0} outline={[lines, { borderLeftWidth: 1 }]}>
|
|
354
|
+
{inside}
|
|
355
|
+
</Parallelogram>
|
|
356
|
+
</View>
|
|
357
|
+
<View style={[clip, { left: half - 1 }]}>
|
|
358
|
+
<Parallelogram
|
|
359
|
+
node={node}
|
|
360
|
+
sides={wideAtBottom ? "\\" : "/"}
|
|
361
|
+
left={half - 1}
|
|
362
|
+
outline={[lines, { borderRightWidth: 1 }]}
|
|
363
|
+
>
|
|
364
|
+
{inside}
|
|
365
|
+
</Parallelogram>
|
|
366
|
+
</View>
|
|
367
|
+
</>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
case "double-circle": {
|
|
371
|
+
const inner = width - 2 * DOUBLE_RING_GAP;
|
|
372
|
+
return (
|
|
373
|
+
<>
|
|
374
|
+
<View style={[outline, { position: "absolute", left: 0, top: 0, width, height, borderRadius: width / 2 }]} />
|
|
375
|
+
<View
|
|
376
|
+
style={{
|
|
377
|
+
position: "absolute",
|
|
378
|
+
left: DOUBLE_RING_GAP,
|
|
379
|
+
top: DOUBLE_RING_GAP,
|
|
380
|
+
width: inner,
|
|
381
|
+
height: inner,
|
|
382
|
+
borderRadius: inner / 2,
|
|
383
|
+
borderWidth: 1,
|
|
384
|
+
borderColor: accent,
|
|
385
|
+
}}
|
|
386
|
+
/>
|
|
387
|
+
</>
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
default:
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* A View one slant narrower than the box, centred in it and sheared about its
|
|
397
|
+
* middle: the top and bottom edges move half the slant in opposite directions,
|
|
398
|
+
* so the far corners reach both sides of the box and the sides run `/` or `\`.
|
|
399
|
+
* The slant is the layout's own, which is what puts the side where a horizontal
|
|
400
|
+
* edge stops. `left` is where the box starts inside a clipping parent.
|
|
401
|
+
*
|
|
402
|
+
* React Native on Android applies no skew and leaves the upright View between the
|
|
403
|
+
* two mid-height points. There a diagram with these shapes goes to Mermaid
|
|
404
|
+
* (`canSkew`), so that box shows only while the line giving the shape is typed.
|
|
405
|
+
*/
|
|
406
|
+
function Parallelogram({
|
|
407
|
+
node,
|
|
408
|
+
sides,
|
|
409
|
+
left,
|
|
410
|
+
outline,
|
|
411
|
+
children,
|
|
412
|
+
}: {
|
|
413
|
+
node: LaidOutNode;
|
|
414
|
+
sides: "/" | "\\";
|
|
415
|
+
left: number;
|
|
416
|
+
outline: StyleProp<ViewStyle>;
|
|
417
|
+
children?: React.ReactNode;
|
|
418
|
+
}) {
|
|
419
|
+
const slant = slantFor(node.height);
|
|
420
|
+
const angle = (Math.atan(slant / node.height) * 180) / Math.PI;
|
|
421
|
+
return (
|
|
422
|
+
<View
|
|
423
|
+
style={[
|
|
424
|
+
outline,
|
|
425
|
+
{
|
|
426
|
+
position: "absolute",
|
|
427
|
+
left: slant / 2 - left,
|
|
428
|
+
top: 0,
|
|
429
|
+
width: node.width - slant,
|
|
430
|
+
height: node.height,
|
|
431
|
+
// A positive skew moves the bottom edge right, which runs the sides `\`.
|
|
432
|
+
transform: [{ skewX: `${sides === "/" ? -angle : angle}deg` }],
|
|
433
|
+
},
|
|
434
|
+
]}
|
|
435
|
+
>
|
|
436
|
+
{children}
|
|
437
|
+
</View>
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
180
441
|
function EdgeView({ edge, theme }: { edge: LaidOutEdge; theme: PluginTheme }) {
|
|
181
442
|
const color = theme.colors.foregroundMuted;
|
|
182
443
|
return (
|
package/client/file-panel.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Loading, Markdown } from "@getpaseo/plugin/client/ui";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { ScrollView, Text } from "react-native";
|
|
5
5
|
import { fileView } from "../shared/file-view";
|
|
6
|
+
import { canSkew } from "./diagram";
|
|
6
7
|
import { DiagramViewer } from "./viewer";
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -21,7 +22,7 @@ export function MermaidFilePanel({ file, theme, layout }: PluginFilePanelProps)
|
|
|
21
22
|
return <Text style={{ color: theme.colors.statusDanger, padding }}>{text.error.message}</Text>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const view = fileView(text.text);
|
|
25
|
+
const view = fileView(text.text, { skew: canSkew });
|
|
25
26
|
return (
|
|
26
27
|
<ScrollView style={{ flex: 1, backgroundColor: theme.colors.surface0 }} contentContainerStyle={{ padding }}>
|
|
27
28
|
{view.kind === "diagram" ? (
|
package/index.client.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import * as ui from "@getpaseo/plugin/client/ui";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
import { addFilePanel } from "./client/compat";
|
|
4
|
+
import { addFilePanel, hostMarkdown } from "./client/compat";
|
|
5
|
+
import { canSkew } from "./client/diagram";
|
|
4
6
|
import { MermaidFilePanel } from "./client/file-panel";
|
|
5
7
|
import { DiagramItem, TextItem } from "./client/item";
|
|
6
8
|
import { DIAGRAM_KIND, split, TEXT_KIND } from "./shared/transform";
|
|
@@ -8,6 +10,9 @@ import { DIAGRAM_KIND, split, TEXT_KIND } from "./shared/transform";
|
|
|
8
10
|
const textSchema = z.object({ text: z.string() });
|
|
9
11
|
const diagramSchema = z.object({ source: z.string() });
|
|
10
12
|
|
|
13
|
+
/** Apps from 0.13 have Paseo's Markdown, which draws the diagrams this plugin cannot. */
|
|
14
|
+
const hostMarkdownAvailable = hostMarkdown(ui) !== null;
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* Renders Mermaid diagrams inside the transcript.
|
|
13
18
|
*
|
|
@@ -18,14 +23,20 @@ const diagramSchema = z.object({ source: z.string() });
|
|
|
18
23
|
* Paseo runs transformers while building the render model, on every streaming
|
|
19
24
|
* update as well as on the finished message, and memoizes by source item. The
|
|
20
25
|
* transform is therefore pure and synchronous, and it claims a mermaid fence
|
|
21
|
-
* the moment the fence opens
|
|
26
|
+
* the moment the fence opens, before Paseo draws it. While a diagram streams it
|
|
27
|
+
* changes renderer at most once, from this plugin's drawing to Mermaid, at the
|
|
28
|
+
* first finished line the plugin cannot draw.
|
|
22
29
|
*
|
|
23
30
|
* The item stores the Mermaid source rather than a parsed graph. Parsing happens
|
|
24
31
|
* at render time, which keeps the stored data small and lets a later fix to the
|
|
25
32
|
* parser improve diagrams that were sent months ago.
|
|
26
33
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
34
|
+
* What this plugin cannot draw in full (see `shared/drawable.ts`) goes to Paseo's
|
|
35
|
+
* Markdown, which runs Mermaid, as a mermaid fence inside the plugin's own text item,
|
|
36
|
+
* so a message with a diagram is never left to Paseo on 0.13 and later. Apps before
|
|
37
|
+
* 0.13 have no such Markdown; there such a message is left to Paseo whole. On
|
|
38
|
+
* Android, where React Native cannot shear a View, a diagram with a parallelogram
|
|
39
|
+
* or trapezoid counts as one this plugin does not draw (`canSkew`).
|
|
29
40
|
*
|
|
30
41
|
* Everything here runs in the app. The plugin has no server entry and starts no
|
|
31
42
|
* daemon process.
|
|
@@ -36,12 +47,12 @@ export default function contribute(client: PluginClientContext) {
|
|
|
36
47
|
client.addTimelineTransformer({
|
|
37
48
|
id: "mermaid-assistant",
|
|
38
49
|
query: { itemType: "assistant_message" },
|
|
39
|
-
transform: ({ item, phase }) => split(item.text, phase),
|
|
50
|
+
transform: ({ item, phase }) => split(item.text, phase, { hostMarkdown: hostMarkdownAvailable, skew: canSkew, deferToGenerativeUi: true }),
|
|
40
51
|
});
|
|
41
52
|
client.addTimelineTransformer({
|
|
42
53
|
id: "mermaid-user",
|
|
43
54
|
query: { itemType: "user_message" },
|
|
44
|
-
transform: ({ item, phase }) => split(item.text, phase),
|
|
55
|
+
transform: ({ item, phase }) => split(item.text, phase, { hostMarkdown: hostMarkdownAvailable, skew: canSkew }),
|
|
45
56
|
});
|
|
46
57
|
|
|
47
58
|
client.addTimelineRenderer({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-plugin-mermaid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Render Mermaid diagrams inside the Paseo chat timeline",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dutchakdev",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"@getpaseo/client": "0.13.2",
|
|
29
29
|
"@getpaseo/plugin": "0.13.2",
|
|
30
30
|
"@getpaseo/protocol": "0.13.2",
|
|
31
|
-
"@tanstack/react-query": "^5.
|
|
31
|
+
"@tanstack/react-query": "^5.107.1",
|
|
32
32
|
"@types/node": "22.20.5",
|
|
33
33
|
"@types/react": "~19.2.0",
|
|
34
34
|
"react": "19.1.0",
|
|
35
35
|
"react-native": "0.81.5",
|
|
36
|
-
"semver": "7.8.
|
|
36
|
+
"semver": "7.8.6",
|
|
37
37
|
"tsx": "^4.23.13",
|
|
38
38
|
"typescript": "^7.0.2",
|
|
39
|
-
"vite": "^8.3.
|
|
40
|
-
"vitest": "^5.0
|
|
39
|
+
"vite": "^8.3.8",
|
|
40
|
+
"vitest": "^5.1.0",
|
|
41
41
|
"zod": "^4.4.3"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|