-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathOutputTypesDemoPage.tsx
More file actions
345 lines (325 loc) · 9.47 KB
/
OutputTypesDemoPage.tsx
File metadata and controls
345 lines (325 loc) · 9.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import React from "react";
import type { OutputData, OutputType } from "@runtimed/schema";
import { IframeOutput } from "./outputs/IframeOutput.js";
import { SingleOutput } from "./outputs/SingleOutput.js";
import { OutputsContainer } from "./outputs/OutputsContainer.js";
import { SuspenseSpinner } from "./outputs/SuspenseSpinner.js";
const createOutput = (
id: string,
outputType: OutputType,
data: Partial<OutputData>
): OutputData => {
return {
id,
cellId: "demo-cell",
outputType,
position: 0,
streamName: null,
executionCount: null,
displayId: null,
artifactId: null,
mimeType: null,
metadata: null,
representations: null,
data: null,
...data,
} as OutputData;
};
export const OutputTypesDemoPage: React.FC<{ iframeUri?: string }> = ({
iframeUri,
}) => {
const finalIframeUriPrefix = iframeUri ?? ".";
// Terminal outputs
const stdoutOutput: OutputData = createOutput("terminal-stdout", "terminal", {
streamName: "stdout",
data: "Hello, World!\nThis is stdout output with ANSI colors:\n\x1b[32mGreen text\x1b[0m\n\x1b[31mRed text\x1b[0m\n\x1b[1mBold text\x1b[0m",
position: 1,
});
const stderrOutput: OutputData = createOutput("terminal-stderr", "terminal", {
streamName: "stderr",
data: "Warning: This is stderr output\n\x1b[33mYellow warning\x1b[0m",
position: 2,
});
// Markdown output
const markdownOutput: OutputData = createOutput("markdown-1", "markdown", {
data: `# Markdown Output Demo
This is a **markdown** output with:
- Lists
- \`code\` blocks
- [Links](https://example.com)
\`\`\`python
def hello():
print("Hello from markdown!")
\`\`\`
> Blockquote example`,
position: 3,
});
// Error output
const errorOutput: OutputData = createOutput("error-1", "error", {
data: JSON.stringify({
ename: "ValueError",
evalue: "Invalid value provided",
traceback: [
"Traceback (most recent call last):",
' File "<stdin>", line 1, in <module>',
"ValueError: Invalid value provided",
],
}),
position: 4,
});
// HTML output (using IframeOutput)
const htmlOutput: OutputData = createOutput("html-1", "multimedia_display", {
data: "<div>HTML Content</div>",
mimeType: "text/html",
representations: {
"text/html": {
type: "inline",
data: `<div style="padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 8px;">
<h2>HTML Output Demo</h2>
<p>This is rendered HTML content with styling.</p>
<ul>
<li>Styled list item 1</li>
<li>Styled list item 2</li>
</ul>
</div>`,
},
},
position: 5,
});
// SVG output (using IframeOutput)
const svgOutput: OutputData = createOutput("svg-1", "multimedia_display", {
data: "<svg>SVG Content</svg>",
mimeType: "image/svg+xml",
representations: {
"image/svg+xml": {
type: "inline",
data: `<svg width="400" height="200" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<rect width="400" height="200" fill="url(#grad1)" />
<circle cx="200" cy="100" r="50" fill="white" opacity="0.8" />
<text x="200" y="110" font-family="Arial" font-size="24" fill="black" text-anchor="middle">SVG Output</text>
</svg>`,
},
},
position: 6,
});
// JSON output
const jsonOutput: OutputData = createOutput("json-1", "multimedia_result", {
data: '{"key": "value"}',
mimeType: "application/json",
representations: {
"application/json": {
type: "inline",
data: {
name: "Demo Data",
items: [1, 2, 3, 4, 5],
nested: {
key: "value",
number: 42,
},
},
},
},
executionCount: 1,
position: 7,
});
// GeoJSON output
const geojsonOutput: OutputData = createOutput(
"geojson-1",
"multimedia_result",
{
data: '{"type":"FeatureCollection"}',
mimeType: "application/geo+json",
representations: {
"application/geo+json": {
type: "inline",
data: {
type: "FeatureCollection",
features: [
{
type: "Feature",
geometry: {
type: "Point",
coordinates: [-122.4194, 37.7749],
},
properties: {
name: "San Francisco",
population: 873965,
},
},
{
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [
[
[-122.5, 37.7],
[-122.4, 37.7],
[-122.4, 37.8],
[-122.5, 37.8],
[-122.5, 37.7],
],
],
},
properties: {
name: "Sample Area",
area: "~77 km²",
},
},
],
},
},
},
executionCount: 2,
position: 8,
}
);
// Plain text output
const plainTextOutput: OutputData = createOutput(
"text-1",
"multimedia_result",
{
data: "Plain text content",
mimeType: "text/plain",
representations: {
"text/plain": {
type: "inline",
data: "This is plain text output.\nIt can span multiple lines.\n\nWith paragraphs too!",
},
},
executionCount: 3,
position: 9,
}
);
// Image output (PNG - base64 data URL example)
const imageOutput: OutputData = createOutput(
"image-1",
"multimedia_display",
{
data: "Image data",
mimeType: "image/png",
representations: {
"image/png": {
type: "inline",
data: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAnElEQVR42u3RAQ0AAAgDIE1u9FvDOahAVzLFGS1ECEKEIEQIQoQgRIgQIQgRghAhCBGCECEIQYgQhAhBiBCECEEIQoQgRAhChCBECEIQIgQhQhAiBCFCEIIQIQgRghAhCBGCEIQIQYgQhAhBiBCEIEQIQoQgRAhChCAEIUIQIgQhQhAiBCEIEYIQIQgRghAhCBEiRAhChCBECEK+W3uw+TnWoJc/AAAAAElFTkSuQmCC",
},
"text/plain": {
type: "inline",
data: "[Image: 1x1 pixel PNG]",
},
},
position: 10,
}
);
const allOutputs: Array<{
name: string;
type: string;
outputs: OutputData[];
}> = [
{
name: "Plain Text Output",
type: "text",
outputs: [plainTextOutput],
},
{
name: "Terminal Output (stdout)",
type: "terminal-stdout",
outputs: [stdoutOutput],
},
{
name: "Terminal Output (stderr)",
type: "terminal-stderr",
outputs: [stderrOutput],
},
{
name: "Error Output",
type: "error",
outputs: [errorOutput],
},
{
name: "Markdown Output",
type: "markdown",
outputs: [markdownOutput],
},
{
name: "JSON Output",
type: "json",
outputs: [jsonOutput],
},
{
name: "Image Output (PNG)",
type: "image",
outputs: [imageOutput],
},
{
name: "SVG Output (Iframe)",
type: "svg",
outputs: [svgOutput],
},
{
name: "HTML Output (Iframe)",
type: "html",
outputs: [htmlOutput],
},
{
name: "GeoJSON Output",
type: "geojson",
outputs: [geojsonOutput],
},
];
return (
<div className="container mx-auto max-w-6xl p-6">
<h1 className="mb-6 text-3xl font-bold">Cell Output Types Demo</h1>
<p className="text-muted-foreground mb-8">
This page demonstrates all the different cell output types supported by
the system. HTML and SVG outputs are rendered using IframeOutput for
sandboxed rendering.
</p>
<div className="space-y-4">
{allOutputs.map((section) => {
return (
<div
key={section.type}
className="grid gap-4 border-t border-black last:border-b sm:grid-cols-2"
>
<div className="flex items-start">
<h2 className="font-semibold">{section.name}</h2>
</div>
{/* Render HTML and SVG using IframeOutput */}
<div className="py-3">
{section.type === "html" || section.type === "svg" ? (
<div className="border border-dotted border-gray-300">
<pre className="bg-gray-100 p-1 text-xs">
{finalIframeUriPrefix}/react.html
</pre>
<IframeOutput
iframeUri={finalIframeUriPrefix}
outputs={section.outputs}
className="min-h-[200px] w-full"
isReact={true}
/>
</div>
) : (
<div className="border border-dotted border-gray-300">
<SuspenseSpinner>
<OutputsContainer>
{section.outputs.map((output) => (
<SingleOutput key={output.id} output={output} />
))}
</OutputsContainer>
</SuspenseSpinner>
</div>
)}
</div>
</div>
);
})}
</div>
</div>
);
};