feat(svelte): add selectionMode prop
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { createEventDispatcher, onMount, setContext, SvelteComponentTyped } from 'svelte';
|
import { createEventDispatcher, onMount, setContext, SvelteComponentTyped } from 'svelte';
|
||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
import { errorMessages } from '@reactflow/system';
|
import { errorMessages, type NodeProps } from '@reactflow/system';
|
||||||
|
|
||||||
import drag from '$lib/actions/drag';
|
import drag from '$lib/actions/drag';
|
||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import DefaultNode from '$lib/components/nodes/DefaultNode.svelte';
|
import DefaultNode from '$lib/components/nodes/DefaultNode.svelte';
|
||||||
import type { NodeProps } from '$lib/types';
|
|
||||||
import type { NodeWrapperProps } from './types';
|
import type { NodeWrapperProps } from './types';
|
||||||
|
|
||||||
interface $$Props extends NodeWrapperProps {}
|
interface $$Props extends NodeWrapperProps {}
|
||||||
@@ -72,6 +72,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div
|
<div
|
||||||
use:drag={{ nodeId: id, nodes, transform, updateNodePositions }}
|
use:drag={{ nodeId: id, nodes, transform, updateNodePositions }}
|
||||||
bind:this={nodeRef}
|
bind:this={nodeRef}
|
||||||
|
|||||||
@@ -46,12 +46,12 @@
|
|||||||
selectionRect,
|
selectionRect,
|
||||||
selectionRectMode,
|
selectionRectMode,
|
||||||
selectionKeyPressed,
|
selectionKeyPressed,
|
||||||
resetSelectedElements
|
resetSelectedElements,
|
||||||
|
selectionMode
|
||||||
} = useStore();
|
} = useStore();
|
||||||
|
|
||||||
// @todo take from props
|
// @todo take from props
|
||||||
const elementsSelectable = true;
|
const elementsSelectable = true;
|
||||||
const selectionMode = SelectionMode.Partial;
|
|
||||||
|
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
let containerBounds: DOMRect | null = null;
|
let containerBounds: DOMRect | null = null;
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
$nodes,
|
$nodes,
|
||||||
nextUserSelectRect,
|
nextUserSelectRect,
|
||||||
$transform,
|
$transform,
|
||||||
selectionMode === SelectionMode.Partial,
|
$selectionMode === SelectionMode.Partial,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const selectedEdgeIds = getConnectedEdges(selectedNodes, $edges).map((e) => e.id);
|
const selectedEdgeIds = getConnectedEdges(selectedNodes, $edges).map((e) => e.id);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
export let nodeTypes: $$Props['nodeTypes'] = undefined;
|
export let nodeTypes: $$Props['nodeTypes'] = undefined;
|
||||||
export let edgeTypes: $$Props['edgeTypes'] = undefined;
|
export let edgeTypes: $$Props['edgeTypes'] = undefined;
|
||||||
export let selectionKey: $$Props['selectionKey'] = undefined;
|
export let selectionKey: $$Props['selectionKey'] = undefined;
|
||||||
|
export let selectionMode: $$Props['selectionMode'] = undefined;
|
||||||
export let deleteKey: $$Props['deleteKey'] = undefined;
|
export let deleteKey: $$Props['deleteKey'] = undefined;
|
||||||
export let connectionRadius: $$Props['connectionRadius'] = undefined;
|
export let connectionRadius: $$Props['connectionRadius'] = undefined;
|
||||||
export let connectionLineType: $$Props['connectionLineType'] = undefined;
|
export let connectionLineType: $$Props['connectionLineType'] = undefined;
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
id,
|
id,
|
||||||
connectionLineType,
|
connectionLineType,
|
||||||
connectionRadius,
|
connectionRadius,
|
||||||
|
selectionMode,
|
||||||
isValidConnection
|
isValidConnection
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import type {
|
|||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
NodeOrigin,
|
NodeOrigin,
|
||||||
OnConnectStartParams,
|
OnConnectStartParams,
|
||||||
Viewport
|
Viewport,
|
||||||
|
SelectionMode
|
||||||
} from '@reactflow/system';
|
} from '@reactflow/system';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@@ -27,6 +28,7 @@ export type SvelteFlowProps = {
|
|||||||
maxZoom?: number;
|
maxZoom?: number;
|
||||||
initialViewport?: Viewport;
|
initialViewport?: Viewport;
|
||||||
connectionRadius?: number;
|
connectionRadius?: number;
|
||||||
|
selectionMode?: SelectionMode;
|
||||||
|
|
||||||
class?: string;
|
class?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
|
|||||||
@@ -14,4 +14,8 @@ export * from '$lib/utils';
|
|||||||
|
|
||||||
export * from '$lib/hooks/useSvelteFlow';
|
export * from '$lib/hooks/useSvelteFlow';
|
||||||
|
|
||||||
|
export * from '@reactflow/utils';
|
||||||
|
export * from '@reactflow/system';
|
||||||
|
export * from '@reactflow/edge-utils';
|
||||||
|
|
||||||
export default SvelteFlow;
|
export default SvelteFlow;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import type { SvelteComponentTyped } from 'svelte';
|
import type { SvelteComponentTyped } from 'svelte';
|
||||||
import type { BaseNode } from '@reactflow/system';
|
import type { BaseNode, NodeProps } from '@reactflow/system';
|
||||||
|
|
||||||
// @todo: currently the helper function only like Node from '@reactflow/core'
|
// @todo: currently the helper function only like Node from '@reactflow/core'
|
||||||
// we need a base node type or helpes that accept Node like types
|
// we need a base node type or helpes that accept Node like types
|
||||||
@@ -14,16 +14,6 @@ export type Node<
|
|||||||
style?: string;
|
style?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
export type NodeProps<NodeData = any> = Pick<
|
|
||||||
Node<NodeData>,
|
|
||||||
'id' | 'data' | 'selected' | 'sourcePosition' | 'targetPosition'
|
|
||||||
> & {
|
|
||||||
xPos: number;
|
|
||||||
yPos: number;
|
|
||||||
isConnectable?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NodeTypes = Record<string, typeof SvelteComponentTyped<Partial<NodeProps>>>;
|
export type NodeTypes = Record<string, typeof SvelteComponentTyped<Partial<NodeProps>>>;
|
||||||
|
|
||||||
export type DefaultNodeOptions = Partial<Omit<Node, 'id'>>;
|
export type DefaultNodeOptions = Partial<Omit<Node, 'id'>>;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
Panel,
|
Panel,
|
||||||
createNodes,
|
createNodes,
|
||||||
createEdges,
|
createEdges,
|
||||||
type NodeTypes
|
type NodeTypes,
|
||||||
|
SelectionMode
|
||||||
} from '../../lib/index';
|
} from '../../lib/index';
|
||||||
import { CustomNode } from '../../example-components/CustomNode';
|
import { CustomNode } from '../../example-components/CustomNode';
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@
|
|||||||
fitView
|
fitView
|
||||||
minZoom={0.1}
|
minZoom={0.1}
|
||||||
maxZoom={2.5}
|
maxZoom={2.5}
|
||||||
|
selectionMode={SelectionMode.Full}
|
||||||
initialViewport={{ x: 100, y: 100, zoom: 2 }}
|
initialViewport={{ x: 100, y: 100, zoom: 2 }}
|
||||||
on:node:click={(event) => console.log('on node click', event)}
|
on:node:click={(event) => console.log('on node click', event)}
|
||||||
on:node:mouseenter={(event) => console.log('on node enter', event)}
|
on:node:mouseenter={(event) => console.log('on node enter', event)}
|
||||||
|
|||||||
Reference in New Issue
Block a user