Debian Codegraph @

html_renderer/demo-src/DemoApp.svelte

raw
1 <script lang="ts">
2 import pyinstrumentHTMLRenderer from "../src/main";
3
4 const fileURLs = import.meta.glob("../demo-data/*.json", {import: "default"})
5
6 const files = Object.entries(fileURLs).map(([srcURL, promiseFn]) => {
7 const filename = srcURL.split("/").pop()!;
8 const stem = filename.split(".").slice(0, -1).join(".");
9 return { name: stem, promiseFn };
10 });
11
12 let file = files[0];
13
14 let data: any = null;
15 let error: Error | null = null;
16 let loading = false;
17 $: {
18 loading = true;
19 error = null;
20 data = null;
21 file.promiseFn()
22 .then((json) => {
23 data = json;
24 error = null;
25 })
26 .catch((e) => {
27 error = e;
28 })
29 .finally(() => {
30 loading = false;
31 });
32 }
33
34 let appComponent: ReturnType<
35 (typeof pyinstrumentHTMLRenderer)["render"]
36 > | null = null;
37 let resultElement: HTMLElement | undefined;
38
39 $: if (resultElement && data) {
40 if (appComponent) {
41 appComponent.$destroy();
42 }
43 appComponent = pyinstrumentHTMLRenderer.render(resultElement, data);
44 }
45 </script>
46
47 <div class="demo-app">
48 <div class="header">
49 <div class="left"></div>
50 <div class="right">
51 Choose a demo profile:
52 <select bind:value={file}>
53 {#each files as optionFile}
54 <option value={optionFile}>{optionFile.name}</option>
55 {/each}
56 </select>
57 </div>
58 </div>
59 <div class="body">
60 {#if loading}
61 <div>Loading...</div>
62 {:else if error}
63 <div>Error loading file: {error.message}</div>
64 {/if}
65
66 <div class="result-element" style={!data ? 'display: none' : ''} bind:this={resultElement}></div>
67 </div>
68 </div>
69
70 <style lang="scss">
71 .demo-app {
72 background-color: #111;
73 color: white;
74 font-size: 11px;
75 font-family:
76 system-ui,
77 -apple-system,
78 BlinkMacSystemFont,
79 "Segoe UI",
80 Roboto,
81 Oxygen,
82 Ubuntu,
83 Cantarell,
84 "Open Sans",
85 "Helvetica Neue",
86 sans-serif;
87
88 display: flex;
89 flex-direction: column;
90 position: absolute;
91 top: 0;
92 bottom: 0;
93 left: 0;
94 right: 0;
95 }
96 .header {
97 // background: #292f32;
98 // font-size: 14px;
99 padding: 5px 10px;
100 display: flex;
101 justify-content: space-between;
102 align-items: center;
103 }
104 .body {
105 position: relative;
106 flex: 1;
107 }
108 select {
109 font: inherit;
110 }
111 </style>