Skip to content

Commit 0c3f3ae

Browse files
committed
fix: #518 convert all Svelte examples to Svelte 5
1 parent 7cf7d2f commit 0c3f3ae

File tree

13 files changed

+35
-35
lines changed

13 files changed

+35
-35
lines changed

src/routes/examples/basic_usage_one_way_binding/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { JSONEditor } from 'svelte-jsoneditor'
33
4-
let content = {
4+
let content = $state({
55
text: undefined, // can be used to pass a stringified JSON document instead
66
json: {
77
array: [1, 2, 3],
@@ -12,7 +12,7 @@
1212
object: { a: 'b', c: 'd' },
1313
string: 'Hello World'
1414
}
15-
}
15+
})
1616
1717
function handleChange(updatedContent) {
1818
console.log('contents changed:', updatedContent)

src/routes/examples/basic_usage_two_way_binding/+page.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { JSONEditor } from 'svelte-jsoneditor'
33

4-
let content = {
4+
let content = $state({
55
text: undefined, // can be used to pass a stringified JSON document instead
66
json: {
77
array: [1, 2, 3],
@@ -12,9 +12,9 @@
1212
object: { a: 'b', c: 'd' },
1313
string: 'Hello World'
1414
}
15-
}
15+
})
1616

17-
$: console.log('contents changed:', content)
17+
$inspect('content', content)
1818
</script>
1919

2020
<svelte:head>

src/routes/examples/custom_context_menu_buttons/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
} from 'svelte-jsoneditor'
88
import { faCalculator } from '@fortawesome/free-solid-svg-icons'
99

10-
let content = {
10+
let content = $state({
1111
text: undefined, // can be used to pass a stringified JSON document instead
1212
json: {
1313
array: [1, 2, 3],
@@ -18,7 +18,7 @@
1818
object: { a: 'b', c: 'd' },
1919
string: 'Hello World'
2020
}
21-
}
21+
})
2222

2323
function handleCalculateSize() {
2424
const size = toTextContent(content).text.length

src/routes/examples/custom_dynamic_styling/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { JSONEditor } from 'svelte-jsoneditor'
33

4-
let content = {
4+
let content = $state({
55
text: undefined, // can be used to pass a stringified JSON document instead
66
json: {
77
array: [1, 2, 3],
@@ -12,7 +12,7 @@
1212
object: { a: 'b', c: 'd' },
1313
string: 'Hello World'
1414
}
15-
}
15+
})
1616

1717
function handleClassName(path, value) {
1818
if (JSON.stringify(path) === '["object","c"]' || JSON.stringify(path) === '["string"]') {

src/routes/examples/custom_json_parser/+page.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const LosslessJSONParser = { parse, stringify }
66

7-
let content = {
7+
let content = $state({
88
text: `{
99
"using": "Lossless JSON Parser",
1010
"formatted number": 4.0,
@@ -13,9 +13,9 @@
1313
"small": 1e-500
1414
}`,
1515
json: undefined
16-
}
16+
})
1717

18-
$: console.log('contents changed:', content)
18+
$inspect('content', content)
1919
</script>
2020

2121
<svelte:head>

src/routes/examples/custom_menu_buttons/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { faCopy } from '@fortawesome/free-regular-svg-icons'
1010
import copyToClipboard from '$lib/utils/copyToClipboard.js'
1111

12-
let content = {
12+
let content = $state({
1313
text: undefined, // can be used to pass a stringified JSON document instead
1414
json: {
1515
array: [1, 2, 3],
@@ -20,7 +20,7 @@
2020
object: { a: 'b', c: 'd' },
2121
string: 'Hello World'
2222
}
23-
}
23+
})
2424

2525
async function handleCopy() {
2626
console.log('Custom copy button clicked')

src/routes/examples/custom_theme_color/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script>
22
import { JSONEditor } from 'svelte-jsoneditor'
33

4-
let content = {
4+
let content = $state({
55
text: undefined, // can be used to pass a stringified JSON document instead
66
json: {
77
string: 'Hello custom theme color :)'
88
}
9-
}
9+
})
1010
</script>
1111

1212
<svelte:head>

src/routes/examples/custom_validation/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
return errors
8282
}
8383

84-
let content = {
84+
let content = $state({
8585
text: undefined, // can be used to pass a stringified JSON document instead
8686
json: {
8787
team: [
@@ -98,7 +98,7 @@
9898
}
9999
]
100100
}
101-
}
101+
})
102102
</script>
103103

104104
<svelte:head>

src/routes/examples/custom_value_renderer/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import ReadonlyPassword from '../../components/ReadonlyPassword.svelte'
1010
import { EvaluatorAction } from '../../components/EvaluatorAction'
1111

12-
let content = {
12+
let content = $state({
1313
text: undefined, // can be used to pass a stringified JSON document instead
1414
json: {
1515
username: 'John',
1616
password: 'secret...',
1717
gender: 'male',
1818
evaluate: '2 + 3'
1919
}
20-
}
20+
})
2121

2222
const genderOptions = [
2323
{ value: null, text: '-' },

src/routes/examples/custom_value_renderer2/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
} from 'svelte-jsoneditor'
88
import EditableValueInput from '../../components/EditableValueInput.svelte'
99

10-
let content = {
10+
let content = $state({
1111
text: undefined, // can be used to pass a stringified JSON document instead
1212
json: {
1313
array: [1, 2, 3],
@@ -18,7 +18,7 @@
1818
object: { a: 'b', c: 'd' },
1919
string: 'Hello World'
2020
}
21-
}
21+
})
2222

2323
function onRenderValue(props: RenderValueProps): RenderValueComponentDescription[] {
2424
if (props.isEditing && !props.readOnly) {

src/routes/examples/json_schema_validation/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
return renderJSONSchemaEnum(props, schema, schemaDefinitions) || renderValue(props)
8181
}
8282

83-
let content = {
83+
let content = $state({
8484
text: undefined, // can be used to pass a stringified JSON document instead
8585
json: {
8686
firstName: 'John',
@@ -94,7 +94,7 @@
9494
salary: 100
9595
}
9696
}
97-
}
97+
})
9898
</script>
9999

100100
<svelte:head>

src/routes/examples/switch_themes/+page.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
{ value: 'jse-font-large', label: 'large' }
1414
]
1515

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)
1818

19-
let content = {
19+
let content = $state({
2020
text: undefined, // can be used to pass a stringified JSON document instead
2121
json: {
2222
array: [1, 2, 3],
@@ -27,7 +27,7 @@
2727
object: { a: 'b', c: 'd' },
2828
string: 'Hello World'
2929
}
30-
}
30+
})
3131

3232
let editorRef
3333
function refresh() {
@@ -36,7 +36,7 @@
3636
editorRef?.refresh()
3737
}
3838

39-
$: console.log('contents changed:', content)
39+
$inspect('content', content)
4040
</script>
4141

4242
<svelte:head>
@@ -49,15 +49,15 @@
4949
<p>You can customize the styling of the editor using CSS variables</p>
5050

5151
<p>
52-
Theme: <select bind:value={selectedTheme} on:change={refresh}>
52+
Theme: <select bind:value={selectedTheme} onchange={refresh}>
5353
{#each themes as theme}
5454
<option value={theme.value}>{theme.label}</option>
5555
{/each}
5656
</select>
5757
</p>
5858
<p>
5959
Font size:
60-
<select bind:value={selectedFontSize} on:change={refresh}>
60+
<select bind:value={selectedFontSize} onchange={refresh}>
6161
{#each fontSizes as fontSize}
6262
<option value={fontSize.value}>{fontSize.label}</option>
6363
{/each}

src/routes/examples/use_methods/+page.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
let refJsonEditor
55

6-
let content = {
6+
let content = $state({
77
text: undefined, // can be used to pass a stringified JSON document instead
88
json: {
99
array: [1, 2, 3],
@@ -14,7 +14,7 @@
1414
object: { a: 'b', c: 'd' },
1515
string: 'Hello World'
1616
}
17-
}
17+
})
1818

1919
function expandAll() {
2020
refJsonEditor.expand([], () => true)
@@ -33,8 +33,8 @@
3333
<p>You can call methods on the editor by creating a reference to the editor instance.</p>
3434

3535
<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>
3838
</p>
3939

4040
<div class="editor">

0 commit comments

Comments
 (0)