import React from "react"; import { ImmutableCell } from "@nteract/commutable"; import { ContentRef } from "@nteract/core"; import { KernelOutputError, Media, StreamText } from "@nteract/outputs"; import { Source } from "@nteract/presentational-components"; import Editor, { EditorSlots } from "../inputs/editor"; import Input from "../inputs/input"; import Prompt, { PassedPromptProps } from "../inputs/prompt"; import Outputs from "../outputs"; import InputPrompts from "../outputs/input-prompts"; import Pagers from "../outputs/pagers"; import TransformMedia from "../outputs/transform-media"; interface NamedCodeCellSlots { editor?: EditorSlots; prompt?: (props: { id: string; contentRef: string }) => JSX.Element; pagers?: (props: { id: string; contentRef: string }) => JSX.Element; inputPrompts?: (props: { id: string; contentRef: string }) => JSX.Element; outputs?: (props: { id: string; contentRef: string }) => JSX.Element; toolbar?: () => JSX.Element; } interface ComponentProps { id: string; contentRef: ContentRef; cell?: ImmutableCell; cell_type?: "code"; children?: NamedCodeCellSlots; } export default class CodeCell extends React.Component { static defaultProps = { cell_type: "code", }; render() { const { id, contentRef, children } = this.props; const defaults = { prompt: (props: { id: string; contentRef: string }) => ( {(props: PassedPromptProps) => { if (props.status === "busy") { return {"[*]"}; } if (props.status === "queued") { return {"[…]"}; } if (typeof props.executionCount === "number") { return ( {`[${props.executionCount}]`} ); } return {"[ ]"}; }} ), pagers: (props: any) => ( ), inputPrompts: (props: any) => ( ), outputs: (props: any) => ( ), }; const prompt = children?.prompt || defaults.prompt; /** * We don't set the editor slots as defaults to support dynamic imports * Users can continue to add the editorSlots as children */ const editor = children?.editor; const pagers = children?.pagers ?? defaults.pagers; const inputPrompts = children?.inputPrompts ?? defaults.inputPrompts; const outputs = children?.outputs ?? defaults.outputs; const toolbar = children?.toolbar; return (
{toolbar && toolbar()}
{prompt({ id, contentRef })} {editor} {pagers({ id, contentRef })} {inputPrompts({ id, contentRef })} {outputs({ id, contentRef })}
); } }