diff --git a/public/index.html b/public/index.html index a9b105c..23dd340 100644 --- a/public/index.html +++ b/public/index.html @@ -47,6 +47,7 @@

+

@@ -159,11 +160,15 @@ } document.getElementById('expandAll').onclick = function expandAll () { - testEditor.expandAll() + testEditor.expand(() => true) + } + + document.getElementById('expand2').onclick = function expandAll () { + testEditor.expand(path => path.length < 2) } document.getElementById('collapseAll').onclick = function collapseAll () { - testEditor.collapseAll() + testEditor.collapse(() => false) } diff --git a/src/JSONEditor.svelte b/src/JSONEditor.svelte index 97e3af5..730bd30 100644 --- a/src/JSONEditor.svelte +++ b/src/JSONEditor.svelte @@ -39,13 +39,9 @@ export let onChangeJson = () => {} - function expand (path) { - return path.length < 1 - } - $: { console.time('syncState') - state = syncState(doc, state, [], expand) + state = syncState(doc, state, [], (path) => path.length < 1) console.timeEnd('syncState') } @@ -59,12 +55,12 @@ }) let historyState = history.getState() - export function expandAll () { - state = syncState(doc, state, [], () => true, true) + export function expand (callback = () => true) { + state = syncState(doc, state, [], callback, true) } - export function collapseAll () { - state = syncState(doc, state, [], () => false, true) + export function collapse (doCollapse = () => false) { + state = syncState(doc, state, [], callback, true) } export function get() {