import { actions, ContentRef } from "@nteract/core"; import { KernelOutputError, StreamText } from "@nteract/outputs"; import { Cells, CodeCell, MarkdownCell, RawCell } from "@nteract/stateful-components"; import MonacoEditor from "@nteract/stateful-components/lib/inputs/connected-editors/monacoEditor"; import { PassedEditorProps } from "@nteract/stateful-components/lib/inputs/editor"; import Prompt, { PassedPromptProps } from "@nteract/stateful-components/lib/inputs/prompt"; import TransformMedia from "@nteract/stateful-components/lib/outputs/transform-media"; import * as React from "react"; import { connect } from "react-redux"; import { Dispatch } from "redux"; import { userContext } from "../../../UserContext"; import loadTransform from "../NotebookComponent/loadTransform"; import { AzureTheme } from "./AzureTheme"; import "./base.css"; import "./default.css"; import "./NotebookReadOnlyRenderer.less"; import IFrameOutputs from "./outputs/IFrameOutputs"; export interface NotebookRendererProps { contentRef: any; hideInputs?: boolean; hidePrompts?: boolean; } /** * This is the class that uses nteract to render a read-only notebook. */ class NotebookReadOnlyRenderer extends React.Component { componentDidMount() { loadTransform(this.props as any); } private renderPrompt(id: string, contentRef: string): JSX.Element { if (this.props.hidePrompts) { return <>; } return ( {(props: PassedPromptProps) => { if (props.status === "busy") { return {"[*]"}; } if (props.status === "queued") { return {"[…]"}; } if (typeof props.executionCount === "number") { return {`[${props.executionCount}]`}; } return {"[ ]"}; }} ); } render(): JSX.Element { return (
{{ code: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => ( {{ prompt: (props: { id: string; contentRef: string }) => this.renderPrompt(props.id, props.contentRef), outputs: userContext.features.sandboxNotebookOutputs ? (props: any) => ( ) : undefined, editor: { monaco: (props: PassedEditorProps) => this.props.hideInputs ? <> : , }, }} ), markdown: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => ( {{ editor: {}, }} ), raw: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => ( {{ editor: { monaco: (props: PassedEditorProps) => this.props.hideInputs ? <> : , }, }} ), }}
); } } const makeMapDispatchToProps = (initialDispatch: Dispatch, initialProps: NotebookRendererProps) => { const mapDispatchToProps = (dispatch: Dispatch) => { return { addTransform: (transform: React.ComponentType & { MIMETYPE: string }) => { return dispatch( actions.addTransform({ mediaType: transform.MIMETYPE, component: transform, }) ); }, }; }; return mapDispatchToProps; }; export default connect(null, makeMapDispatchToProps)(NotebookReadOnlyRenderer);