-
Notifications
You must be signed in to change notification settings - Fork 39
/
Debug.svelte
113 lines (106 loc) · 2.51 KB
/
Debug.svelte
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script>
import Modal from "../Modal.svelte";
import Container from "../Container.svelte";
import * as modals from "../modals.js";
import * as stores from "../stores.js";
let parsedStores = {};
let editingStore, editingStoreVal, saveStoreError;
$: {
Object.entries(stores).forEach(([key, value]) => {
value.subscribe(
v => (parsedStores[key] = [typeof v, JSON.stringify(v)])
);
});
}
</script>
<Modal showClose={true} on:close={modals.closeLastModal}>
<h2 slot="header">Debug</h2>
<div slot="default">
<h2>Stores</h2>
{#each Object.entries(parsedStores) as [storeName, [storeType, storeVal]]}
<Container>
<b>{storeName}</b><br />
{#if editingStore === storeName}
{#if storeType === "object"}
<textarea
class="white"
style="width: 100%;"
name="input"
autocomplete="off"
bind:value={editingStoreVal}
on:keydown={e => {
if (e.key == "Enter") e.preventDefault();
}}
/>
{:else if storeType === "boolean"}
<input type="checkbox" bind:checked={editingStoreVal} />
{:else if storeType === "number"}
<input
type="number"
class="white"
style="width: 100%;"
name="input"
autocomplete="off"
bind:value={editingStoreVal}
/>
{:else}
<input
type="text"
class="white"
style="width: 100%;"
name="input"
autocomplete="off"
bind:value={editingStoreVal}
/>
{/if}
{:else}
<code>{storeVal}</code>
{/if}
{#if editingStore === storeName && saveStoreError}
<p style="color: crimson;">{saveStoreError}</p>
{/if}
<div class="settings-controls">
{#if editingStore === storeName}
<button
class="circle close"
on:click={() => (editingStore = "")}
/>
<button
class="circle check"
on:click={() => {
try {
stores[storeName].set(
storeType === "object"
? JSON.parse(editingStoreVal)
: editingStoreVal
);
editingStore = "";
} catch (e) {
saveStoreError = e;
}
}}
/>
{:else}
<button
class="circle settings"
on:click={() => {
saveStoreError = "";
editingStoreVal =
storeType === "object"
? storeVal
: JSON.parse(storeVal);
editingStore = storeName;
}}
/>
{/if}
</div>
</Container>
{/each}
</div>
</Modal>
<style>
textarea,
input {
margin-top: 0.5em;
}
</style>