Spaces:
Paused
Paused
Commit
·
a4257e7
1
Parent(s):
b84b82c
Update app/editor/index.tsx
Browse files- app/editor/index.tsx +19 -1
app/editor/index.tsx
CHANGED
|
@@ -30,6 +30,11 @@ export default function Editor({ defaultValue }: { defaultValue: string }) {
|
|
| 30 |
automaticLayout: true,
|
| 31 |
})
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
const dispose = MonacoEditorCopilot(editor, { testName: 'basic example'} as any);
|
| 34 |
if (config[0]?.testName === 'example with dispose') {
|
| 35 |
setTimeout(() => {
|
|
@@ -43,5 +48,18 @@ export default function Editor({ defaultValue }: { defaultValue: string }) {
|
|
| 43 |
}
|
| 44 |
}, [])
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
|
|
|
| 30 |
automaticLayout: true,
|
| 31 |
})
|
| 32 |
|
| 33 |
+
const initialValue = editor.getValue();
|
| 34 |
+
const encodedJs = encodeURIComponent(initialValue);
|
| 35 |
+
const dataUri = "data:text/javascript;charset=utf-8," + encodedJs;
|
| 36 |
+
import(dataUri);
|
| 37 |
+
|
| 38 |
const dispose = MonacoEditorCopilot(editor, { testName: 'basic example'} as any);
|
| 39 |
if (config[0]?.testName === 'example with dispose') {
|
| 40 |
setTimeout(() => {
|
|
|
|
| 48 |
}
|
| 49 |
}, [])
|
| 50 |
|
| 51 |
+
const handlePreview = () => {
|
| 52 |
+
const codeDiv = document.querySelector("#editor");
|
| 53 |
+
const codeText = codeDiv.textContent;
|
| 54 |
+
const encodedJs = encodeURIComponent(codeString);
|
| 55 |
+
const dataUri = "data:text/javascript;charset=utf-8," + encodedJs;
|
| 56 |
+
import(dataUri);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
return (
|
| 60 |
+
<>
|
| 61 |
+
<div id="editor" ref={ref} style={{ height: 50vh }} />
|
| 62 |
+
<button onPress={}>preview</button>
|
| 63 |
+
<div id="root" />
|
| 64 |
+
</>
|
| 65 |
}
|