diff --git a/sites/svelte-5-preview/src/lib/CodeMirror.svelte b/sites/svelte-5-preview/src/lib/CodeMirror.svelte index 651463499f..207e690341 100644 --- a/sites/svelte-5-preview/src/lib/CodeMirror.svelte +++ b/sites/svelte-5-preview/src/lib/CodeMirror.svelte @@ -102,7 +102,8 @@ } /** @type {StateEffectType[]>} */ - const addMarksDecoration = StateEffect.define(); + const setMarksDecoration = StateEffect.define(); + const clearMarksDecoration = StateEffect.define(); // This value must be added to the set of extensions to enable this const markField = StateField.define({ @@ -116,7 +117,11 @@ value = value.map(tr.changes); // If this transaction adds or removes decorations, apply those changes for (let effect of tr.effects) { - if (effect.is(addMarksDecoration)) value = value.update({ add: effect.value, sort: true }); + if (effect.is(setMarksDecoration)) { + value = value.update({ filter: () => false, add: effect.value }); + } else if (effect.is(clearMarksDecoration)) { + value = value.update({ filter: () => false }); + } } return value; }, @@ -136,16 +141,13 @@ }); $cmInstance.view?.dispatch({ - effects: [ - StateEffect.appendConfig.of(markField), - addMarksDecoration.of([executedMark.range(from, to)]) - ] + effects: [setMarksDecoration.of([executedMark.range(from, to)])] }); } export function unmarkText() { $cmInstance.view?.dispatch({ - effects: StateEffect.reconfigure.of($cmInstance.extensions ?? []) + effects: [clearMarksDecoration.of(null)] }); } @@ -220,7 +222,7 @@ lint: diagnostics, lintOptions: { delay: 200 }, autocomplete: true, - extensions: [svelte_rune_completions, js_rune_completions, watcher], + extensions: [svelte_rune_completions, js_rune_completions, watcher, markField], instanceStore: cmInstance }} oncodemirror:textChange={(/** @type {{ detail: string; }} */ event) => { diff --git a/sites/svelte-5-preview/src/lib/Output/AstNode.svelte b/sites/svelte-5-preview/src/lib/Output/AstNode.svelte index f99f21494c..6574e6acd3 100644 --- a/sites/svelte-5-preview/src/lib/Output/AstNode.svelte +++ b/sites/svelte-5-preview/src/lib/Output/AstNode.svelte @@ -1,98 +1,103 @@
  • - {#if !is_root && is_collapsable} - {:else if key_text} {key_text} {/if} - {#if is_collapsable} + {#if is_collapsable(value)} {#if collapsed && !is_root} - {:else} diff --git a/sites/svelte-5-preview/src/lib/Output/AstView.svelte b/sites/svelte-5-preview/src/lib/Output/AstView.svelte index e252e8c0b6..05b49b6ba7 100644 --- a/sites/svelte-5-preview/src/lib/Output/AstView.svelte +++ b/sites/svelte-5-preview/src/lib/Output/AstView.svelte @@ -3,20 +3,20 @@ import AstNode from './AstNode.svelte'; import { cursorIndex } from '../CodeMirror.svelte'; - /** @type {import('svelte/types/compiler/interfaces').Ast} */ - export let ast; - export let autoscroll = true; + /** @type {{ ast: unknown; autoscroll?: boolean }} */ + const { ast, autoscroll = true } = $props(); // $cursor_index may go over the max since ast computation is usually slower. // clamping this helps prevent the collapse view flashing - $: max_cursor_index = !ast ? $cursorIndex : Math.min($cursorIndex, get_ast_max_end(ast)); - - $: path_nodes = find_deepest_path(max_cursor_index, [ast]) || []; + const max_cursor_index = $derived( + !ast ? $cursorIndex : Math.min($cursorIndex, get_ast_max_end(ast)) + ); + const path_nodes = $derived(find_deepest_path(max_cursor_index, [ast]) || []); /** * @param {number} cursor - * @param {import('svelte/types/compiler/interfaces').Ast[]} paths - * @returns {import('svelte/types/compiler/interfaces').Ast[] | undefined} + * @param {unknown[]} paths + * @returns {unknown[] | undefined} */ function find_deepest_path(cursor, paths) { const value = paths[paths.length - 1]; @@ -31,6 +31,8 @@ } if ( + value !== null && + typeof value === 'object' && 'start' in value && 'end' in value && typeof value.start === 'number' && @@ -42,10 +44,12 @@ } } - /** @param {import('svelte/types/compiler/interfaces').Ast} ast */ + /** @param {unknown} ast */ function get_ast_max_end(ast) { let max_end = 0; + if (ast === null || typeof ast !== 'object') return max_end; + for (const node of Object.values(ast)) { if (node && typeof node.end === 'number' && node.end > max_end) { max_end = node.end; diff --git a/sites/svelte-5-preview/src/lib/Output/CompilerOptions.svelte b/sites/svelte-5-preview/src/lib/Output/CompilerOptions.svelte index 426e5044a7..d680c9327b 100644 --- a/sites/svelte-5-preview/src/lib/Output/CompilerOptions.svelte +++ b/sites/svelte-5-preview/src/lib/Output/CompilerOptions.svelte @@ -1,4 +1,3 @@ -