Skip to content

Commit 1f8a2d8

Browse files
authored
Merge pull request #28 from Rich-Harris/primitives
2 parents a19b90d + 217d1f1 commit 1f8a2d8

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/lib/svelte-json-tree/SvelteJsonTree/JSONNested.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<Expandable key={expandKey(key)} expanded={child_expanded[index]}>
6464
<!-- svelte-ignore a11y-no-static-element-interactions -->
6565
<span class="label" on:click={() => child_expanded[index].update((value) => !value)}>
66-
<JSONArrow /><slot name="item_key" {key} {index} />{#if !shouldShowColon || shouldShowColon(key)}<span class="operator">:</span>{/if}
66+
<JSONArrow /><slot name="item_key" {key} {index} />{#if !shouldShowColon || shouldShowColon(key)}<span class="operator">{': '}</span>{/if}
6767
</span><slot name="item_value" {key} {index} />
6868
</Expandable>
6969
</li>

src/lib/svelte-json-tree/SvelteJsonTree/Root.svelte

+24-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
export let defaultExpandedPaths: string[] = [];
1212
export let defaultExpandedLevel: number = 0;
1313
14+
$: expandable = value && typeof value === 'object'
1415
$: shouldExpandNode = getShouldExpandNode({ defaultExpandedPaths, defaultExpandedLevel });
1516
1617
const expanded = writable(true);
@@ -26,14 +27,20 @@
2627
});
2728
</script>
2829

29-
<ul>
30-
<Expandable key="$" {expanded}>
30+
<div class:expandable>
31+
{#if expandable}
32+
<Expandable key="$" {expanded}>
33+
<JSONNode {value} />
34+
</Expandable>
35+
{:else if typeof value === 'string'}
36+
<span>{value}</span>
37+
{:else}
3138
<JSONNode {value} />
32-
</Expandable>
33-
</ul>
39+
{/if}
40+
</div>
3441

3542
<style>
36-
ul {
43+
div {
3744
--string-color: var(--json-tree-string-color, #cb3f41);
3845
--symbol-color: var(--json-tree-symbol-color, #cb3f41);
3946
--boolean-color: var(--json-tree-boolean-color, #112aa7);
@@ -53,33 +60,36 @@
5360
font-size: var(--json-tree-font-size, 12px);
5461
font-family: var(--json-tree-font-family, 'Courier New', Courier, monospace);
5562
}
56-
ul :global(li) {
63+
div :global(li) {
5764
line-height: var(--li-line-height);
5865
display: var(--li-display, list-item);
5966
list-style: none;
6067
}
61-
ul,
62-
ul :global(ul) {
68+
div,
69+
div :global(ul) {
6370
padding: 0;
6471
margin: 0;
6572
}
6673
67-
ul {
74+
.expandable {
6875
margin-left: var(--li-identation);
6976
}
70-
ul {
77+
div {
7178
cursor: default;
7279
}
73-
ul :global(.label) {
80+
div :global(.label) {
7481
color: var(--label-color);
7582
}
76-
ul :global(.property) {
83+
div :global(.property) {
7784
color: var(--property-color);
7885
}
79-
ul :global(.internal) {
86+
div :global(.internal) {
8087
color: var(--internal-color);
8188
}
82-
ul :global(.operator) {
89+
div :global(.operator) {
8390
color: var(--operator-color);
8491
}
92+
span {
93+
white-space: pre-wrap;
94+
}
8595
</style>

0 commit comments

Comments
 (0)