-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathwebview.tsx
More file actions
39 lines (30 loc) · 1.11 KB
/
webview.tsx
File metadata and controls
39 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { render as ReactDOM_render } from "react-dom";
import { vscode } from "./vscode-api";
import { WebviewDefinition } from "./webview-definition";
// Allow all views to use Codicons
import "@vscode/codicons/dist/codicon.css";
import { registerUnhandledErrorListener } from "./common/errors";
const render = () => {
registerUnhandledErrorListener();
const element = document.getElementById("root");
if (!element) {
console.error('Could not find element with id "root"');
return;
}
const viewName = element.dataset.view;
if (!viewName) {
console.error("Could not find view name in data-view attribute");
return;
}
// It's a lot harder to use dynamic imports since those don't import the CSS
// and require a less strict CSP policy
// eslint-disable-next-line @typescript-eslint/no-var-requires
const view: WebviewDefinition = require(`./${viewName}/index.tsx`).default;
ReactDOM_render(
view.component,
document.getElementById("root"),
// Post a message to the extension when fully loaded.
() => vscode.postMessage({ t: "viewLoaded", viewName }),
);
};
render();