Skip to content

Commit

Permalink
fix: recursively checks for invisible nodes (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb authored Oct 19, 2023
1 parent a5c245d commit 64ada61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/lib/nodes/Element.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import type { ComponentProps } from 'svelte';
export let tagName: string;
export let hasChildren: boolean;
export let empty: boolean;
export let expanded: boolean;
export let attributes: ComponentProps<ElementAttributes>['attributes'];
Expand Down Expand Up @@ -48,7 +48,16 @@
});
</script>

{#if hasChildren}
{#if empty}
<div>
<span>&lt;</span>
<span class="tag-name">
<Indexer text={tagName} />
</span>
<ElementAttributes attributes={cached} {listeners} />
<span>&nbsp;/&gt;</span>
</div>
{:else}
<div role="group" class:expanded class="expandable" on:dblclick={() => (expanded = !expanded)}>
<span>&lt;</span>
<span class="tag-name">
Expand Down Expand Up @@ -76,15 +85,6 @@
<span>&gt;</span>
</div>
{/if}
{:else}
<div>
<span>&lt;</span>
<span class="tag-name">
<Indexer text={tagName} />
</span>
<ElementAttributes attributes={cached} {listeners} />
<span>&nbsp;/&gt;</span>
</div>
{/if}

<style>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/nodes/Node.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import Slot from './Slot.svelte';
import { background } from '$lib/runtime';
import { visibility, hovered, selected } from '$lib/store';
import { hovered, selected, visibility } from '$lib/store';
export let node: NonNullable<typeof $selected>;
export let depth = 1;
node.invalidate = () => (node = node);
function invisible(n: typeof node): boolean {
return !$visibility[n.type] && n.children.every(invisible);
}
let lastLength = node.children.length;
let flash = false;
$: {
Expand Down Expand Up @@ -42,7 +46,7 @@
tagName={node.tagName}
attributes={node.detail?.attributes || []}
listeners={node.detail?.listeners || []}
hasChildren={!!node.children.length}
empty={!node.children.length || node.children.every(invisible)}
bind:expanded={node.expanded}
>
<ul>
Expand Down

0 comments on commit 64ada61

Please sign in to comment.