Skip to content

Commit d4e301f

Browse files
committedSep 19, 2023
feat: improve welcome screen with action buttons to create an array or object
1 parent ac31282 commit d4e301f

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed
 

‎src/lib/components/modes/tablemode/TableModeWelcome.svelte

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
.filter((path) => path.length > 0)
2727
: []
2828
$: hasNestedArrays = !isEmpty(nestedArrayPaths)
29+
$: isEmptyDocument = json === undefined && (text === '' || text === undefined)
2930
3031
$: documentType = hasNestedArrays
3132
? 'Object with nested arrays'
32-
: json === undefined && (text === '' || text === undefined)
33+
: isEmptyDocument
3334
? 'An empty document'
3435
: isJSONObject(json)
3536
? 'An object'
@@ -48,7 +49,12 @@
4849
An object cannot be opened in table mode. You can open a nested array instead, or open the
4950
document in tree mode.
5051
{:else}
51-
{documentType} cannot be opened in table mode. You can open the document in tree mode instead.
52+
{documentType} cannot be opened in table mode.
53+
{/if}
54+
{#if isEmptyDocument && !readOnly}
55+
You can open the document in tree mode instead, or paste a JSON Array using <b>Ctrl+V</b>.
56+
{:else}
57+
You can open the document in tree mode instead.
5258
{/if}
5359
</div>
5460
{#each nestedArrayPaths as nestedArrayPath}

‎src/lib/components/modes/treemode/TreeMode.svelte

+15-1
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@
10271027
updateSelection(createValueSelection(documentState.selection.path, false))
10281028
}
10291029
1030+
if (!documentState.selection) {
1031+
updateSelection(getInitialSelection(json, documentState))
1032+
}
1033+
10301034
handleInsert(type)
10311035
}
10321036
@@ -2145,7 +2149,17 @@
21452149
</label>
21462150
{#if json === undefined}
21472151
{#if text === '' || text === undefined}
2148-
<Welcome {readOnly} />
2152+
<Welcome
2153+
{readOnly}
2154+
onCreateObject={() => {
2155+
focus()
2156+
handleInsertCharacter('{')
2157+
}}
2158+
onCreateArray={() => {
2159+
focus()
2160+
handleInsertCharacter('[')
2161+
}}
2162+
/>
21492163
{:else}
21502164
<Message
21512165
type="error"

‎src/lib/components/modes/treemode/Welcome.scss

+12-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.jse-welcome {
44
flex: 1;
5-
overflow: auto; // FIXME: overflow doesn't work (try giving editor 100px height)
5+
overflow: auto;
66
font-family: var(--jse-font-family);
77
font-size: var(--jse-font-size);
88

@@ -26,24 +26,21 @@
2626
}
2727

2828
.jse-contents {
29+
display: flex;
30+
flex-direction: column;
31+
max-width: 300px;
2932
margin: 2em $padding 0;
30-
color: var(--jse-panel-color-readonly);
33+
gap: $padding;
3134

32-
ul {
33-
$list-padding: 10px;
34-
35-
list-style: '';
36-
list-style-position: outside;
37-
padding-left: 2 * $list-padding;
35+
.jse-welcome-title {
36+
}
3837

39-
li {
40-
padding-left: $list-padding;
38+
.jse-welcome-info {
39+
color: var(--jse-panel-color-readonly);
40+
}
4141

42-
span.jse-bold {
43-
font-family: var(--jse-font-family-mono);
44-
font-weight: bold;
45-
}
46-
}
42+
button {
43+
@include jsoneditor-button-primary;
4744
}
4845
}
4946
}

‎src/lib/components/modes/treemode/Welcome.svelte

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
<script lang="ts">
44
export let readOnly: boolean
5+
export let onCreateArray: () => void
6+
export let onCreateObject: () => void
57
</script>
68

79
<div class="jse-welcome">
810
<div class="jse-space jse-before" />
911
<div class="jse-contents">
10-
Empty document
12+
<div class="jse-welcome-title">Empty document</div>
1113
{#if !readOnly}
12-
<ul>
13-
<li>Click inside the editor</li>
14-
<li>Paste clipboard data using <span class="jse-bold">Ctrl+V</span></li>
15-
<li>Create a new object by typing <span class="jse-bold">&lbrace;</span></li>
16-
<li>Create a new array by typing <span class="jse-bold">[</span></li>
17-
</ul>
14+
<div class="jse-welcome-info">
15+
You can paste clipboard data using <b>Ctrl+V</b>, or use the following options:
16+
</div>
17+
<button title={"Create an empty JSON object (press '{')"} on:click={() => onCreateObject()}>Create object</button>
18+
<button title={"Create an empty JSON array (press '[')"} on:click={() => onCreateArray()}>Create array</button>
1819
{/if}
1920
</div>
2021
<div class="jse-space jse-after" />

0 commit comments

Comments
 (0)
Please sign in to comment.