Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import(
/* webpackChunkName: "NpmSearchDialog" */ "./components/NpmSearchDialog"
)
);
const DependencyList = lazy(() =>
import(/* webpackChunkName: "DependencyList" */ "./components/DependencyList")
);
const TSConfigEditor = lazy(() =>
import(/* webpackChunkName: "TSConfigEditor" */ "./components/TSConfigEditor")
);
const CodeEditor = lazy(() =>
import(/* webpackChunkName: "CodeEditor" */ "./components/CodeEditor")
);
const resolver = new Resolver();
const installer = new Installer(languages.typescript.typescriptDefaults);
export function Playground() {
const [
primaryEditor,
setPrimaryEditor
] = useState(null);
const [code, setCode] = useState("");
const [compilerOptionsStr, setCompilerOptionsStr] = useState("");
const [compilerOptions, setCompilerOptions] = useState({});
const [sharableConfig, setSharableConfig] = useState("");
const [showDialog, setShowDialog] = useState(false);
const { loading, error, objects, setQuery } = useNpmSearch();
const { dependencies, append, remove } = useNpmInstall();
const handleChangeTSConfig = useCallback((tsconfig: string) => {
setCompilerOptionsStr(tsconfig);
const handleChangeTSConfig = useCallback((tsconfig: string) => {
setCompilerOptionsStr(tsconfig);
const { config, error } = parseConfigFileTextToJson(
"tsconfig.json",
tsconfig
);
if (error) {
console.error(error);
return;
}
setCompilerOptions(config.compilerOptions);
languages.typescript.typescriptDefaults.setCompilerOptions(
config.compilerOptions
);
}, []);
const handleUninstall = useCallback(
render() {
const { code, compilerConfig, onError } = this.props
const compiledCode = compileCode(
transpile(code, {
target: languages.typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
jsx: languages.typescript.JsxEmit.React,
noEmit: true,
}),
compilerConfig,
onError,
)
if (!compiledCode) {
return null
}
const { head, example } = splitExampleCode(compiledCode)
const initialState = this.getExampleInitialState(head)
const exampleComponent = this.getExampleComponent(example)
const wrappedComponent = (
import { languages } from "monaco-editor"
export default {
target: languages.typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
allowSyntheticDefaultImports: true,
esModuleInterop: true,
jsx: languages.typescript.JsxEmit.React,
moduleResolution: languages.typescript.ModuleResolutionKind.NodeJs,
module: languages.typescript.ModuleKind.CommonJS,
noEmit: true,
}
import { languages } from "monaco-editor"
export default {
target: languages.typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
allowSyntheticDefaultImports: true,
esModuleInterop: true,
jsx: languages.typescript.JsxEmit.React,
moduleResolution: languages.typescript.ModuleResolutionKind.NodeJs,
module: languages.typescript.ModuleKind.CommonJS,
noEmit: true,
}
render() {
const { code, compilerConfig, onError } = this.props
const compiledCode = compileCode(
transpile(code, {
target: languages.typescript.ScriptTarget.ESNext,
allowNonTsExtensions: true,
jsx: languages.typescript.JsxEmit.React,
noEmit: true,
}),
compilerConfig,
onError,
)
if (!compiledCode) {
return null
}
const { head, example } = splitExampleCode(compiledCode)
const initialState = this.getExampleInitialState(head)
const exampleComponent = this.getExampleComponent(example)
const wrappedComponent = (