-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathindex.tsx
More file actions
63 lines (48 loc) · 1.87 KB
/
index.tsx
File metadata and controls
63 lines (48 loc) · 1.87 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* index.ts
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
import React from "react";
import { createRoot } from 'react-dom/client';
import * as uuid from "uuid";
import 'vscode-webview';
import { addEditor, initEditorTranslations, initializeStore, setEditorTheme } from 'editor-ui';
import { App } from "./App";
import { visualEditorHostClient, visualEditorJsonRpcRequestTransport } from './sync';
import { editorThemeFromStore } from "./theme";
import "editor-ui/src/styles";
import "./styles.scss"
async function runEditor() {
try {
// init localization
await initEditorTranslations();
// connection to host
const vscode = acquireVsCodeApi<unknown>();
const request = visualEditorJsonRpcRequestTransport(vscode)
const host = visualEditorHostClient(vscode, request);
// get host context
const context = await host.getHostContext();
// initialize store and read initial prefs
const store = await initializeStore(request);
// create editor id
const editorId = uuid.v4();
store.dispatch(addEditor(editorId));
// render
const root = createRoot(document.getElementById('root')!);
setEditorTheme(editorThemeFromStore(store));
root.render(<App store={store} editorId={editorId} host={host} context={context} request={request}/>);
} catch (error) {
console.error('error',error);
}
}
runEditor();