/* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ import * as React from "react"; import SimpleEditor from "react-simple-code-editor"; import Highlight, { Prism } from "prism-react-renderer"; import { useStyletron } from "baseui"; import type { TTransformToken, TEditorProps } from "react-view"; import { lightTheme, useValueDebounce } from "react-view"; import darkTheme from "./dark-theme"; const highlightCode = ( code: string, theme: typeof lightTheme, transformToken?: TTransformToken, ) => ( {({ tokens, getLineProps, getTokenProps }) => ( {tokens.map((line, i) => ( // eslint-disable-next-line react/jsx-key
{line.map((token, key) => { const tokenProps = getTokenProps({ token, key }); if (transformToken) { return transformToken(tokenProps); } // eslint-disable-next-line react/jsx-key return ; })}
))}
)}
); const Editor: React.FC = ({ code: globalCode, transformToken, onChange, placeholder, small, }) => { const [css, theme] = useStyletron(); const [focused, setFocused] = React.useState(false); const plainStyles = theme.name.startsWith("light-theme") ? lightTheme : darkTheme; const editorTheme = { ...plainStyles, plain: { ...plainStyles.plain, fontSize: small ? "13px" : "14px", whiteSpace: "break-spaces", backgroundColor: focused ? theme.colors.inputFillActive : theme.colors.inputFill, }, }; const [code, setCode] = useValueDebounce(globalCode, onChange); return (