• Go back
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
<script lang="ts">
    import {
        TextEditor,
        createModel,
        setupMonaco,
        cleanupMonaco,
        type ContentChangeEvent
    } from '@svuick/monaco';
    import { onMount } from 'svelte';
    let path = '/main.ts';
    const files: Record<string, string> = {
        '/test.ts': 'export function test() {\n\tconsole.log("test");\n}',
        '/main.ts': 'import { test } from "./test";\n\ntest();',
        '/file.yaml': 'this:\n\tis: yaml!',
        '/file.json': '{\n\t"json": "file"\n}'
    };
    function loadModels() {
        for (const file in files) {
            createModel(file, files[file]);
        }
    }
    function handleContentChange(e: ContentChangeEvent) {
        const { path, content } = e.detail;
        files[path] = content;
    }
    onMount(() => {
        setupMonaco({
            onReady: loadModels
        });
        return () => {
            cleanupMonaco();
        };
Enter to Rename, Shift+Enter to Preview