fix(svelte) hiding elements considers missing html elements
This commit is contained in:
@@ -83,6 +83,12 @@
|
|||||||
type: 'custom',
|
type: 'custom',
|
||||||
data: { label: 'Custom Node' },
|
data: { label: 'Custom Node' },
|
||||||
position: { x: 150, y: 300 }
|
position: { x: 150, y: 300 }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'hideunhide',
|
||||||
|
data: { label: 'HIDE ME' },
|
||||||
|
position: { x: 300, y: 75 },
|
||||||
|
hidden: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -179,6 +185,13 @@
|
|||||||
<Panel position="top-right">
|
<Panel position="top-right">
|
||||||
<button on:click={updateNode}>update node pos</button>
|
<button on:click={updateNode}>update node pos</button>
|
||||||
<button on:click={updateEdge}>update edge type</button>
|
<button on:click={updateEdge}>update edge type</button>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
console.log($nodes, $nodes.length);
|
||||||
|
$nodes[$nodes.length - 1].hidden = !$nodes[$nodes.length - 1].hidden;
|
||||||
|
$nodes = $nodes;
|
||||||
|
}}>hide/unhide</button
|
||||||
|
>
|
||||||
</Panel>
|
</Panel>
|
||||||
</SvelteFlow>
|
</SvelteFlow>
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
<svelte:options immutable />
|
<svelte:options immutable />
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { createEventDispatcher, setContext, SvelteComponent, type ComponentType } from 'svelte';
|
||||||
createEventDispatcher,
|
|
||||||
onMount,
|
|
||||||
setContext,
|
|
||||||
SvelteComponent,
|
|
||||||
type ComponentType
|
|
||||||
} from 'svelte';
|
|
||||||
import { get, writable } from 'svelte/store';
|
import { get, writable } from 'svelte/store';
|
||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
import { errorMessages, Position, type NodeProps } from '@xyflow/system';
|
import { errorMessages, Position, type NodeProps } from '@xyflow/system';
|
||||||
@@ -54,6 +48,8 @@
|
|||||||
const nodeType = type || 'default';
|
const nodeType = type || 'default';
|
||||||
|
|
||||||
let nodeRef: HTMLDivElement;
|
let nodeRef: HTMLDivElement;
|
||||||
|
let prevNodeRef: HTMLDivElement;
|
||||||
|
|
||||||
const nodeTypeValid = !!$nodeTypes[nodeType];
|
const nodeTypeValid = !!$nodeTypes[nodeType];
|
||||||
|
|
||||||
if (!nodeTypeValid) {
|
if (!nodeTypeValid) {
|
||||||
@@ -109,13 +105,15 @@
|
|||||||
setContext('svelteflow__node_id', id);
|
setContext('svelteflow__node_id', id);
|
||||||
setContext('svelteflow__node_connectable', connectableStore);
|
setContext('svelteflow__node_connectable', connectableStore);
|
||||||
|
|
||||||
onMount(() => {
|
$: {
|
||||||
resizeObserver?.observe(nodeRef);
|
// hiding the noder removes html element is removed from the dom
|
||||||
|
if (nodeRef) {
|
||||||
return () => {
|
resizeObserver?.observe(nodeRef);
|
||||||
resizeObserver?.unobserve(nodeRef);
|
prevNodeRef = nodeRef;
|
||||||
};
|
} else if (prevNodeRef) {
|
||||||
});
|
resizeObserver?.unobserve(prevNodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onSelectNodeHandler(event: MouseEvent | TouchEvent) {
|
function onSelectNodeHandler(event: MouseEvent | TouchEvent) {
|
||||||
if (selectable && (!get(selectNodesOnDrag) || !draggable || get(nodeDragThreshold) > 0)) {
|
if (selectable && (!get(selectNodesOnDrag) || !draggable || get(nodeDragThreshold) > 0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user