File tree 13 files changed +35
-35
lines changed
basic_usage_one_way_binding
basic_usage_two_way_binding 13 files changed +35
-35
lines changed Original file line number Diff line number Diff line change 1
1
<script >
2
2
import { JSONEditor } from ' svelte-jsoneditor'
3
3
4
- let content = {
4
+ let content = $state ( {
5
5
text: undefined , // can be used to pass a stringified JSON document instead
6
6
json: {
7
7
array: [1 , 2 , 3 ],
12
12
object: { a: ' b' , c: ' d' },
13
13
string: ' Hello World'
14
14
}
15
- }
15
+ })
16
16
17
17
function handleChange (updatedContent ) {
18
18
console .log (' contents changed:' , updatedContent)
Original file line number Diff line number Diff line change 1
1
<script>
2
2
import { JSONEditor } from 'svelte-jsoneditor'
3
3
4
- let content = {
4
+ let content = $state( {
5
5
text: undefined, // can be used to pass a stringified JSON document instead
6
6
json: {
7
7
array: [1, 2, 3],
12
12
object: { a: 'b', c: 'd' },
13
13
string: 'Hello World'
14
14
}
15
- }
15
+ })
16
16
17
- $: console . log ( ' contents changed: ' , content)
17
+ $inspect('content ', content)
18
18
</script>
19
19
20
20
<svelte:head>
Original file line number Diff line number Diff line change 7
7
} from 'svelte-jsoneditor'
8
8
import { faCalculator } from '@fortawesome/free-solid-svg-icons'
9
9
10
- let content = {
10
+ let content = $state( {
11
11
text: undefined, // can be used to pass a stringified JSON document instead
12
12
json: {
13
13
array: [1, 2, 3],
18
18
object: { a: 'b', c: 'd' },
19
19
string: 'Hello World'
20
20
}
21
- }
21
+ })
22
22
23
23
function handleCalculateSize() {
24
24
const size = toTextContent(content).text.length
Original file line number Diff line number Diff line change 1
1
<script>
2
2
import { JSONEditor } from 'svelte-jsoneditor'
3
3
4
- let content = {
4
+ let content = $state( {
5
5
text: undefined, // can be used to pass a stringified JSON document instead
6
6
json: {
7
7
array: [1, 2, 3],
12
12
object: { a: 'b', c: 'd' },
13
13
string: 'Hello World'
14
14
}
15
- }
15
+ })
16
16
17
17
function handleClassName(path, value) {
18
18
if (JSON.stringify(path) === '["object","c"]' || JSON.stringify(path) === '["string"]') {
Original file line number Diff line number Diff line change 4
4
5
5
const LosslessJSONParser = { parse, stringify }
6
6
7
- let content = {
7
+ let content = $state( {
8
8
text: `{
9
9
"using": "Lossless JSON Parser",
10
10
"formatted number": 4.0,
13
13
"small": 1e-500
14
14
}`,
15
15
json: undefined
16
- }
16
+ })
17
17
18
- $: console.log('contents changed: ', content)
18
+ $inspect('content ', content)
19
19
</script>
20
20
21
21
<svelte:head>
Original file line number Diff line number Diff line change 9
9
import { faCopy } from '@fortawesome/free-regular-svg-icons'
10
10
import copyToClipboard from '$lib/utils/copyToClipboard.js'
11
11
12
- let content = {
12
+ let content = $state( {
13
13
text: undefined, // can be used to pass a stringified JSON document instead
14
14
json: {
15
15
array: [1, 2, 3],
20
20
object: { a: 'b', c: 'd' },
21
21
string: 'Hello World'
22
22
}
23
- }
23
+ })
24
24
25
25
async function handleCopy() {
26
26
console.log('Custom copy button clicked')
Original file line number Diff line number Diff line change 1
1
<script>
2
2
import { JSONEditor } from 'svelte-jsoneditor'
3
3
4
- let content = {
4
+ let content = $state( {
5
5
text: undefined, // can be used to pass a stringified JSON document instead
6
6
json: {
7
7
string: 'Hello custom theme color :)'
8
8
}
9
- }
9
+ })
10
10
</script>
11
11
12
12
<svelte:head>
Original file line number Diff line number Diff line change 81
81
return errors
82
82
}
83
83
84
- let content = {
84
+ let content = $state( {
85
85
text: undefined, // can be used to pass a stringified JSON document instead
86
86
json: {
87
87
team: [
98
98
}
99
99
]
100
100
}
101
- }
101
+ })
102
102
</script>
103
103
104
104
<svelte:head>
Original file line number Diff line number Diff line change 9
9
import ReadonlyPassword from '../../components/ReadonlyPassword.svelte'
10
10
import { EvaluatorAction } from '../../components/EvaluatorAction'
11
11
12
- let content = {
12
+ let content = $state( {
13
13
text: undefined, // can be used to pass a stringified JSON document instead
14
14
json: {
15
15
username: 'John',
16
16
password: 'secret...',
17
17
gender: 'male',
18
18
evaluate: '2 + 3'
19
19
}
20
- }
20
+ })
21
21
22
22
const genderOptions = [
23
23
{ value: null, text: '-' },
Original file line number Diff line number Diff line change 7
7
} from 'svelte-jsoneditor'
8
8
import EditableValueInput from '../../components/EditableValueInput.svelte'
9
9
10
- let content = {
10
+ let content = $state( {
11
11
text: undefined, // can be used to pass a stringified JSON document instead
12
12
json: {
13
13
array: [1, 2, 3],
18
18
object: { a: 'b', c: 'd' },
19
19
string: 'Hello World'
20
20
}
21
- }
21
+ })
22
22
23
23
function onRenderValue(props: RenderValueProps): RenderValueComponentDescription[] {
24
24
if (props.isEditing && !props.readOnly) {
Original file line number Diff line number Diff line change 80
80
return renderJSONSchemaEnum(props, schema, schemaDefinitions) || renderValue(props)
81
81
}
82
82
83
- let content = {
83
+ let content = $state( {
84
84
text: undefined, // can be used to pass a stringified JSON document instead
85
85
json: {
86
86
firstName: 'John',
94
94
salary: 100
95
95
}
96
96
}
97
- }
97
+ })
98
98
</script>
99
99
100
100
<svelte:head>
Original file line number Diff line number Diff line change 13
13
{ value: 'jse-font-large', label: 'large' }
14
14
]
15
15
16
- let selectedTheme = themes[1].value
17
- let selectedFontSize = fontSizes[1].value
16
+ let selectedTheme = $state( themes[1].value)
17
+ let selectedFontSize = $state( fontSizes[1].value)
18
18
19
- let content = {
19
+ let content = $state( {
20
20
text: undefined, // can be used to pass a stringified JSON document instead
21
21
json: {
22
22
array: [1, 2, 3],
27
27
object: { a: 'b', c: 'd' },
28
28
string: 'Hello World'
29
29
}
30
- }
30
+ })
31
31
32
32
let editorRef
33
33
function refresh() {
36
36
editorRef?.refresh()
37
37
}
38
38
39
- $: console.log('contents changed: ', content)
39
+ $inspect('content ', content)
40
40
</script>
41
41
42
42
<svelte:head>
49
49
<p>You can customize the styling of the editor using CSS variables</p>
50
50
51
51
<p>
52
- Theme: <select bind:value={selectedTheme} on:change ={refresh}>
52
+ Theme: <select bind:value={selectedTheme} onchange ={refresh}>
53
53
{#each themes as theme}
54
54
<option value={theme.value}>{theme.label}</option>
55
55
{/each}
56
56
</select>
57
57
</p>
58
58
<p>
59
59
Font size:
60
- <select bind:value={selectedFontSize} on:change ={refresh}>
60
+ <select bind:value={selectedFontSize} onchange ={refresh}>
61
61
{#each fontSizes as fontSize}
62
62
<option value={fontSize.value}>{fontSize.label}</option>
63
63
{/each}
Original file line number Diff line number Diff line change 3
3
4
4
let refJsonEditor
5
5
6
- let content = {
6
+ let content = $state( {
7
7
text: undefined, // can be used to pass a stringified JSON document instead
8
8
json: {
9
9
array: [1, 2, 3],
14
14
object: { a: 'b', c: 'd' },
15
15
string: 'Hello World'
16
16
}
17
- }
17
+ })
18
18
19
19
function expandAll() {
20
20
refJsonEditor.expand([], () => true)
33
33
<p>You can call methods on the editor by creating a reference to the editor instance.</p>
34
34
35
35
<p>
36
- <button type="button" on:click ={expandAll}>Expand All</button>
37
- <button type="button" on:click ={collapseAll}>Collapse All</button>
36
+ <button type="button" onclick ={expandAll}>Expand All</button>
37
+ <button type="button" onclick ={collapseAll}>Collapse All</button>
38
38
</p>
39
39
40
40
<div class="editor">
You can’t perform that action at this time.
0 commit comments