import { CellId } from "@nteract/commutable"; import { CellType } from "@nteract/commutable/src"; import { actions, ContentRef } from "@nteract/core"; import { Cells, CodeCell, 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 * as React from "react"; import { DndProvider } from "react-dnd"; import { HTML5Backend } from "react-dnd-html5-backend"; import { connect } from "react-redux"; import { Dispatch } from "redux"; import { userContext } from "../../../UserContext"; import * as cdbActions from "../NotebookComponent/actions"; import loadTransform from "../NotebookComponent/loadTransform"; import { AzureTheme } from "./AzureTheme"; import "./base.css"; import CellCreator from "./decorators/CellCreator"; import CellLabeler from "./decorators/CellLabeler"; import HoverableCell from "./decorators/HoverableCell"; import KeyboardShortcuts from "./decorators/kbd-shortcuts"; import "./default.css"; import MarkdownCell from "./markdown-cell"; import "./NotebookRenderer.less"; import SandboxOutputs from "./outputs/SandboxOutputs"; import Prompt from "./Prompt"; import { promptContent } from "./PromptContent"; import StatusBar from "./StatusBar"; import CellToolbar from "./Toolbar"; export interface NotebookRendererBaseProps { contentRef: any; } interface NotebookRendererDispatchProps { updateNotebookParentDomElt: (contentRef: ContentRef, parentElt: HTMLElement) => void; } type NotebookRendererProps = NotebookRendererBaseProps & NotebookRendererDispatchProps; const decorate = (id: string, contentRef: ContentRef, cell_type: CellType, children: React.ReactNode) => { const Cell = () => ( // TODO Draggable and HijackScroll not working anymore. Fix or remove when reworking MarkdownCell. // // {children} // // ); Cell.defaultProps = { cell_type }; return ; }; class BaseNotebookRenderer extends React.Component { private notebookRendererRef = React.createRef(); constructor(props: NotebookRendererProps) { super(props); this.state = { hoveredCellId: undefined, }; } componentDidMount() { if (!userContext.features.sandboxNotebookOutputs) { loadTransform(this.props as any); } this.props.updateNotebookParentDomElt(this.props.contentRef, this.notebookRendererRef.current); } componentDidUpdate() { this.props.updateNotebookParentDomElt(this.props.contentRef, this.notebookRendererRef.current); } componentWillUnmount() { this.props.updateNotebookParentDomElt(this.props.contentRef, undefined); } render(): JSX.Element { return ( <>
{{ code: ({ id, contentRef }: { id: CellId; contentRef: ContentRef }) => decorate( id, contentRef, "code", {{ editor: { monaco: (props: PassedEditorProps) => , }, prompt: ({ id, contentRef }: { id: CellId; contentRef: ContentRef }) => ( {promptContent} ), toolbar: () => , outputs: userContext.features.sandboxNotebookOutputs ? () => : undefined, }} ), markdown: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => decorate( id, contentRef, "markdown", {{ editor: { monaco: (props: PassedEditorProps) => , }, toolbar: () => , }} ), raw: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => decorate( id, contentRef, "raw", {{ editor: { monaco: (props: PassedEditorProps) => , }, toolbar: () => , }} ), }}
); } } const makeMapDispatchToProps = (initialDispatch: Dispatch, initialProps: NotebookRendererBaseProps) => { const mapDispatchToProps = (dispatch: Dispatch) => { return { addTransform: (transform: React.ComponentType & { MIMETYPE: string }) => { return dispatch( actions.addTransform({ mediaType: transform.MIMETYPE, component: transform, }) ); }, updateNotebookParentDomElt: (contentRef: ContentRef, parentElt: HTMLElement) => { return dispatch( cdbActions.UpdateNotebookParentDomElt({ contentRef, parentElt, }) ); }, }; }; return mapDispatchToProps; }; export default connect(null, makeMapDispatchToProps)(BaseNotebookRenderer);