Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/lib/CustomProperty.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
<script lang="ts">
import { serialize_path } from './utils.js';
import type { CustomPropertyProps } from './types.js';
import { getContext } from 'svelte';
import { paths_equal, serialize_path } from './utils.js';
import { create_anchor_gate } from './node_visibility.svelte.js';
import type { CustomPropertyProps, SveditRenderContext } from './types.js';

let { path, tag = 'div', class: css_class, children, style, ...rest }: CustomPropertyProps = $props();
const svedit = getContext<SveditRenderContext>('svedit');

let {
path,
tag = 'div',
class: css_class,
children,
style,
...rest
}: CustomPropertyProps = $props();
let path_str = $derived(serialize_path(path));

let is_selected = $derived(
svedit.session.selection?.type === 'property' &&
paths_equal(path, svedit.session.selection.path)
);
// The selected property keeps its anchor: the selection overlay targets it.
const anchor = create_anchor_gate(
svedit,
() => path_str,
'property',
() => is_selected
);
</script>

<svelte:element
this={tag}
class={css_class}
data-type="property"
data-path={path_str}
style="anchor-name: --{path_str};{style ? ` ${style}` : ''}"
style="{anchor.style}{style ? ` ${style}` : ''}"
{...rest}
>
<div class="property-selectable">
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Node.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { getContext } from 'svelte';
import { serialize_path } from './utils.js';
import { create_anchor_gate } from './node_visibility.svelte.js';
import type {
NodeArrayAttachmentContext,
NodeArrayRenderContext,
Expand All @@ -15,6 +16,8 @@
let node = $derived(svedit.session.get(path));
let path_str = $derived(serialize_path(path));

const anchor = create_anchor_gate(svedit, () => path_str, 'node');

const node_array_meta = getContext<NodeArrayRenderContext | undefined>('node_array_meta');
let child_index = $derived(node_array_meta ? (path.at(-1) as number) : -1);
let is_first = $derived(node_array_meta && child_index === 0);
Expand Down Expand Up @@ -55,7 +58,7 @@
data-node-id={node.id}
data-path={path_str}
data-type="node"
style="anchor-name: --{path_str};{style}"
style="{anchor.style}{style}"
{...rest}
{@attach svedit.visibility_registry.track_node(path_str)}
>
Expand Down
Loading