Skip to content

Commit 2fa5cae

Browse files
authored
fix: individual expanded state (#211)
1 parent 4041a4b commit 2fa5cae

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

workspace/extension/src/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144

145145
{#if app.selected?.type === 'component'}
146146
<h2>Props</h2>
147-
<PropertyList entries={app.selected?.detail.attributes} />
147+
<PropertyList entries={app.selected.detail.attributes} />
148148

149149
<Divider type="horizontal" />
150150

@@ -154,7 +154,7 @@
154154
<Divider type="horizontal" />
155155

156156
<h2>State</h2>
157-
<PropertyList entries={app.selected?.detail.ctx} />
157+
<PropertyList entries={app.selected.detail.ctx} />
158158
{:else if app.selected?.type === 'block' || app.selected?.type === 'iteration'}
159159
<h2>State</h2>
160160
<PropertyList entries={app.selected.detail.ctx} />

workspace/extension/src/lib/panel/PropertyList.svelte

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414
keys?: string[];
1515
}
1616
17-
const { entries = [], keys = [] }: Props = $props();
17+
const { entries = [], keys: parents = [] }: Props = $props();
1818
19-
let expanded = $state(false);
19+
const expanded = $state<{ [k: string]: boolean }>({});
2020
</script>
2121

2222
{#if entries.length}
2323
<ul>
2424
{#each entries as { key, value, readonly = false } (key)}
25-
{@const id = `${app.selected?.id}+${keys.join('.')}.${key}`}
25+
{@const keys = [...parents, key]}
2626
{@const type = typeof value}
2727

2828
<!-- svelte-ignore a11y-click-events-have-key-events -->
2929
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
3030
<li
31-
data-tooltip={errors[id] || null}
31+
data-tooltip={errors[`${app.selected?.id}+${keys.join('.')}`] || null}
3232
style:--indent="-3px"
3333
style:--y-pad="0.125rem"
34-
class:expanded
34+
class:expanded={expanded[key]}
3535
class:expandable={value != null &&
3636
value === value &&
3737
type === 'object' &&
@@ -41,7 +41,7 @@
4141
Object.keys(value).length)}
4242
onclick={(event) => {
4343
event.stopPropagation();
44-
expanded = !expanded;
44+
expanded[key] = !expanded[key];
4545
}}
4646
>
4747
<span>{key}:</span>
@@ -52,45 +52,45 @@
5252
{readonly}
5353
type="string"
5454
{value}
55-
onchange={(updated) => inject([...keys, key], updated)}
55+
onchange={(updated) => inject(keys, updated)}
5656
/>
5757
{:else if value == null || value !== value}
5858
<Editable
5959
{readonly}
6060
type="null"
6161
value={value === null ? 'null' : 'undefined'}
62-
onchange={(updated) => inject([...keys, key], updated)}
62+
onchange={(updated) => inject(keys, updated)}
6363
/>
6464
{:else if type === 'number' || type === 'boolean'}
6565
<Editable
6666
{readonly}
6767
type="number"
6868
{value}
69-
onchange={(updated) => inject([...keys, key], updated)}
69+
onchange={(updated) => inject(keys, updated)}
7070
/>
7171
{:else if Array.isArray(value)}
7272
<span class="object">Array [{value.length || ''}]</span>
7373

74-
{#if value.length && expanded}
74+
{#if value.length && expanded[key]}
7575
{@const entries = value.map((v, i) => ({ key: `${i}`, value: v, readonly }))}
7676

77-
<PropertyList {entries} keys={[...keys, key]} />
77+
<PropertyList {entries} {keys} />
7878
{/if}
7979
{:else if type === 'object'}
8080
{#if value.__is === 'function'}
8181
<span class="function">function {value.name || ''}()</span>
82-
{#if expanded}<pre style:width="100%">{value.source}</pre>{/if}
82+
{#if expanded[key]}<pre style:width="100%">{value.source}</pre>{/if}
8383
{:else if value.__is === 'symbol'}
8484
<span class="symbol">{value.name || 'Symbol()'}</span>
8585
{:else if Object.keys(value).length}
8686
<span class="object">Object &lbrace;&hellip;&rbrace;</span>
8787

88-
{#if expanded}
88+
{#if expanded[key]}
8989
{@const entries = Object.entries(value).map(([key, v]) => {
9090
return { key, value: v, readonly };
9191
})}
9292

93-
<PropertyList {entries} keys={[...keys, key]} />
93+
<PropertyList {entries} {keys} />
9494
{/if}
9595
{:else}
9696
<span class="object">Object &lbrace; &rbrace;</span>

0 commit comments

Comments
 (0)