removed defaultNodeOptions again

This commit is contained in:
peterkogo
2025-01-07 10:41:21 +01:00
parent 56ef230428
commit e62c496a77
7 changed files with 9 additions and 54 deletions

View File

@@ -52,7 +52,7 @@
z: zIndex = 0,
positionAbsolute: { x: positionX, y: positionY }
}
} = $derived(store.defaultNodeOptions ? { ...store.defaultNodeOptions, ...node } : node);
} = $derived(node);
let { id } = node;

View File

@@ -122,12 +122,12 @@
if (!isSelecting || !containerBounds || !store.selectionRect) {
return;
}
const start = performance.now();
selectionInProgress = true;
const mousePos = getEventPosition(event, containerBounds);
const startX = store.selectionRect.startX ?? 0;
const startY = store.selectionRect.startY ?? 0;
const { startX = 0, startY = 0 } = store.selectionRect;
const nextUserSelectRect = {
...store.selectionRect,
x: mousePos.x < startX ? mousePos.x : startX,
@@ -145,8 +145,7 @@
nextUserSelectRect,
[store.viewport.x, store.viewport.y, store.viewport.zoom],
store.selectionMode === SelectionMode.Partial,
true,
store.defaultNodeOptions.selectable
true
).map((n) => n.id)
);
@@ -174,9 +173,6 @@
store.selectionRectMode = 'user';
store.selectionRect = nextUserSelectRect;
const end = performance.now();
// console.log('onPointerMove', end - start);
}
function onPointerUp(event: PointerEvent) {

View File

@@ -32,8 +32,7 @@ import type {
OnDelete,
OnEdgeCreate,
OnBeforeDelete,
IsValidConnection,
DefaultNodeOptions
IsValidConnection
} from '$lib/types';
import type { Snippet } from 'svelte';
@@ -303,22 +302,6 @@ export type SvelteFlowProps = NodeEvents &
* }
*/
defaultEdgeOptions?: DefaultEdgeOptions;
/** Defaults to be applied to all new nodes that are added to the flow.
*
* Properties on a new nodes will override these defaults if they exist.
* @example
* const defaultNodeOptions = {
* type: 'customNodeType',
* position: {x: 0, y: 0}
* data: { label: 'custom label' },
* hidden: false,
* deletable: true,
* selected: false,
* focusable: true,
* zIndex: 12,
* }
*/
defaultNodeOptions?: DefaultNodeOptions;
/** Sets a fixed width for the flow */
width?: number;
/** Sets a fixed height for the flow */

View File

@@ -52,14 +52,7 @@ export type {
DefaultEdgeOptions
} from '$lib/types/edges';
export type { HandleProps, FitViewOptions } from '$lib/types/general';
export type {
Node,
NodeTypes,
DefaultNodeOptions,
BuiltInNode,
NodeProps,
InternalNode
} from '$lib/types/nodes';
export type { Node, NodeTypes, BuiltInNode, NodeProps, InternalNode } from '$lib/types/nodes';
export type { SvelteFlowStore } from '$lib/store/types';
// system types

View File

@@ -169,7 +169,6 @@ export const getInitialStore = (signals: StoreSignals) => {
translateExtent: CoordinateExtent = $derived(signals.props.translateExtent ?? infiniteExtent);
defaultEdgeOptions: Partial<Edge> = $derived(signals.props.defaultEdgeOptions ?? {});
defaultNodeOptions: Partial<Node> = $derived(signals.props.defaultNodeOptions ?? {});
nodeDragThreshold: number = $derived(signals.props.nodeDragThreshold ?? 1);
autoPanOnNodeDrag: boolean = $derived(signals.props.autoPanOnNodeDrag ?? true);

View File

@@ -40,21 +40,6 @@ export type NodeTypes = Record<
>
>;
// TODO: we should be more selective about this but otherwise good to go
export type DefaultNodeOptions = Partial<Omit<Node, 'id'>>;
export type BuiltInNode =
| Node<{ label: string }, 'input' | 'output' | 'default'>
| Node<Record<string, never>, 'group'>;
// TODO SVELTE5 remove this
export type NodeEventMap = {
nodeclick: { node: Node; event: MouseEvent | TouchEvent };
nodecontextmenu: { node: Node; event: MouseEvent | TouchEvent };
nodedrag: { targetNode: Node | null; nodes: Node[]; event: MouseEvent | TouchEvent };
nodedragstart: { targetNode: Node | null; nodes: Node[]; event: MouseEvent | TouchEvent };
nodedragstop: { targetNode: Node | null; nodes: Node[]; event: MouseEvent | TouchEvent };
nodemouseenter: { node: Node; event: MouseEvent | TouchEvent };
nodemouseleave: { node: Node; event: MouseEvent | TouchEvent };
nodemousemove: { node: Node; event: MouseEvent | TouchEvent };
};

View File

@@ -202,8 +202,7 @@ export const getNodesInside = <NodeType extends NodeBase = NodeBase>(
[tx, ty, tScale]: Transform = [0, 0, 1],
partially = false,
// set excludeNonSelectableNodes if you want to pay attention to the nodes "selectable" attribute
excludeNonSelectableNodes = false,
defaultNodeSelectable: boolean = true
excludeNonSelectableNodes = false
): InternalNodeBase<NodeType>[] => {
const paneRect = {
...pointToRendererPoint(rect, [tx, ty, tScale]),
@@ -214,7 +213,7 @@ export const getNodesInside = <NodeType extends NodeBase = NodeBase>(
const visibleNodes: InternalNodeBase<NodeType>[] = [];
for (const node of nodes.values()) {
const { measured, selectable = defaultNodeSelectable, hidden = false } = node;
const { measured, selectable = true, hidden = false } = node;
if ((excludeNonSelectableNodes && !selectable) || hidden) {
continue;