-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy pathdisplay.tsx
More file actions
78 lines (76 loc) · 1.74 KB
/
display.tsx
File metadata and controls
78 lines (76 loc) · 1.74 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
import React from "react";
import { toJS } from "mobx";
import { observer } from "mobx-react";
import {
DisplayData,
ExecuteResult,
StreamText,
KernelOutputError,
Output,
Media,
RichMedia,
} from "@nteract/outputs";
import Plotly from "./plotly";
import {
VegaLite1,
VegaLite2,
VegaLite3,
VegaLite4,
Vega2,
Vega3,
Vega4,
Vega5,
} from "@nteract/transform-vega";
import { Markdown } from "./markdown";
// All supported media types for output go here
export const supportedMediaTypes = (
<RichMedia>
<Vega5 />
<Vega4 />
<Vega3 />
<Vega2 />
<Plotly />
<VegaLite4 />
<VegaLite3 />
<VegaLite2 />
<VegaLite1 />
<Media.Json />
<Media.JavaScript />
<Media.HTML />
<Markdown />
<Media.LaTeX />
<Media.SVG />
<Media.Image mediaType="image/gif" />
<Media.Image mediaType="image/jpeg" />
<Media.Image mediaType="image/png" />
<Media.Plain />
</RichMedia>
);
export function isTextOutputOnly(data: Record<string, any>) {
const supported = React.Children.map(
supportedMediaTypes.props.children,
(mediaComponent) => mediaComponent.props.mediaType
);
const bundleMediaTypes = [...Object.keys(data)].filter((mediaType) =>
supported.includes(mediaType)
);
return bundleMediaTypes.length === 1 && bundleMediaTypes[0] === "text/plain"
? true
: false;
}
@observer
class Display extends React.Component<{
output: any;
}> {
render() {
return (
<Output output={toJS(this.props.output)}>
<ExecuteResult expanded>{supportedMediaTypes}</ExecuteResult>
<DisplayData expanded>{supportedMediaTypes}</DisplayData>
<StreamText expanded />
<KernelOutputError expanded />
</Output>
);
}
}
export default Display;