@octanejs/xyflow 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/xyflow",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "engines": {
@@ -43,22 +43,22 @@
43
43
  "./dist/style.css": "./src/styles/style.css"
44
44
  },
45
45
  "dependencies": {
46
- "@octanejs/zustand": "0.1.71",
46
+ "@octanejs/zustand": "0.1.72",
47
47
  "@xyflow/system": "0.0.79",
48
48
  "classcat": "5.0.5"
49
49
  },
50
50
  "peerDependencies": {
51
- "octane": "^0.18.0"
51
+ "octane": "^0.19.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@octanejs/zustand": "0.1.71",
54
+ "@octanejs/zustand": "0.1.72",
55
55
  "@tsrx/react": "^0.4.5",
56
56
  "@types/jsdom": "30.0.0",
57
57
  "@types/react": "^19.2.17",
58
58
  "@types/react-dom": "^19.2.3",
59
59
  "@xyflow/react": "12.11.2",
60
60
  "esbuild": "^0.28.1",
61
- "octane": "0.18.0",
61
+ "octane": "0.19.0",
62
62
  "react": "19.2.7",
63
63
  "react-dom": "19.2.7",
64
64
  "vitest": "^4.1.10"
@@ -6,7 +6,7 @@ type LinePatternProps = {
6
6
  dimensions: [number, number];
7
7
  variant: BackgroundVariant;
8
8
  lineWidth?: number;
9
- className?: string;
9
+ className?: string | undefined;
10
10
  };
11
11
 
12
12
  export function LinePattern({ dimensions, lineWidth, variant, className }: LinePatternProps) {
@@ -21,7 +21,7 @@ export function LinePattern({ dimensions, lineWidth, variant, className }: LineP
21
21
 
22
22
  type DotPatternProps = {
23
23
  radius: number;
24
- className?: string;
24
+ className?: string | undefined;
25
25
  };
26
26
 
27
27
  export function DotPattern({ radius, className }: DotPatternProps) {
@@ -8,6 +8,7 @@ import { shallow } from '@octanejs/zustand/shallow';
8
8
  import { useStore } from '../../hooks/useStore';
9
9
  import { MiniMapNode } from './MiniMapNode.tsrx';
10
10
  import type { ReactFlowState, Node } from '../../types';
11
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
11
12
  import type {
12
13
  MiniMapNodes as MiniMapNodesProps,
13
14
  GetMiniMapNodeAttribute,
@@ -32,7 +33,7 @@ function MiniMapNodes<NodeType extends Node>({
32
33
  */
33
34
  nodeComponent: NodeComponent = MiniMapNode,
34
35
  onClick,
35
- }: MiniMapNodesProps<NodeType>) {
36
+ }: AllowUndefined<MiniMapNodesProps<NodeType>, keyof MiniMapNodesProps<NodeType>>) {
36
37
  const nodeIds = useStore(selectorNodeIds, shallow);
37
38
  const nodeColorFunc = getAttrFunction<NodeType>(nodeColor);
38
39
  const nodeStrokeColorFunc = getAttrFunction<NodeType>(nodeStrokeColor);
@@ -84,7 +85,7 @@ function NodeComponentWrapperInner<NodeType extends Node>({
84
85
  nodeStrokeColorFunc: GetMiniMapNodeAttribute<NodeType>;
85
86
  nodeClassNameFunc: GetMiniMapNodeAttribute<NodeType>;
86
87
  nodeBorderRadius: number;
87
- nodeStrokeWidth?: number;
88
+ nodeStrokeWidth: number | undefined;
88
89
  NodeComponent: ComponentType<MiniMapNodeProps>;
89
90
  onClick: MiniMapNodesProps['onClick'];
90
91
  shapeRendering: string;
@@ -6,8 +6,8 @@ import { Panel } from '../Panel/index.tsrx';
6
6
  declare const process: { env: { NODE_ENV?: string } };
7
7
 
8
8
  type AttributionProps = {
9
- proOptions?: ProOptions;
10
- position?: PanelPosition;
9
+ proOptions?: ProOptions | undefined;
10
+ position?: PanelPosition | undefined;
11
11
  };
12
12
 
13
13
  const link = `https://reactflow.dev${
@@ -1,5 +1,5 @@
1
1
  import { createContext, type OctaneNode, useCallback, useContext, useMemo } from 'octane';
2
- import type { EdgeChange, NodeChange } from '@xyflow/system';
2
+ import type { EdgeChange } from '@xyflow/system';
3
3
 
4
4
  import { useStoreApi } from '../../hooks/useStore';
5
5
  import { getElementsDiffChanges } from '../../utils';
@@ -55,7 +55,7 @@ export function BatchProvider<NodeType extends Node = Node, EdgeType extends Edg
55
55
  let changes = getElementsDiffChanges({
56
56
  items: next,
57
57
  lookup: nodeLookup,
58
- }) as NodeChange<NodeType>[];
58
+ });
59
59
 
60
60
  for (const middleware of onNodesChangeMiddlewareMap.values()) {
61
61
  changes = middleware(changes);
@@ -16,9 +16,9 @@ import { useConnection } from '../../hooks/useConnection';
16
16
 
17
17
  type ConnectionLineWrapperProps<NodeType extends Node = Node> = {
18
18
  type: ConnectionLineType;
19
- component?: ConnectionLineComponent<NodeType>;
20
- containerStyle?: CSSProperties;
21
- style?: CSSProperties;
19
+ component?: ConnectionLineComponent<NodeType> | undefined;
20
+ containerStyle?: CSSProperties | undefined;
21
+ style?: CSSProperties | undefined;
22
22
  };
23
23
 
24
24
  const selector = (s: ReactFlowState) => ({
@@ -58,8 +58,8 @@ export function ConnectionLineWrapper<NodeType extends Node = Node>({
58
58
 
59
59
  type ConnectionLineProps<NodeType extends Node = Node> = {
60
60
  type: ConnectionLineType;
61
- style?: CSSProperties;
62
- CustomComponent?: ConnectionLineComponent<NodeType>;
61
+ style?: CSSProperties | undefined;
62
+ CustomComponent?: ConnectionLineComponent<NodeType> | undefined;
63
63
  isValid: boolean | null;
64
64
  };
65
65
 
@@ -1,3 +1,4 @@
1
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
1
2
  import { useState, useMemo, useRef, useCallback, memo } from 'octane';
2
3
  import type { KeyboardEvent, MouseEvent as ReactMouseEvent } from '../../react-shim.js';
3
4
  import type { Octane } from 'octane/jsx-runtime';
@@ -37,7 +38,21 @@ function EdgeWrapper<EdgeType extends Edge = Edge>({
37
38
  noPanClassName,
38
39
  onError,
39
40
  disableKeyboardA11y,
40
- }: EdgeWrapperProps<EdgeType>): Octane.JSX.Element | null {
41
+ }: AllowUndefined<
42
+ EdgeWrapperProps<EdgeType>,
43
+ | 'onClick'
44
+ | 'onDoubleClick'
45
+ | 'onContextMenu'
46
+ | 'onMouseEnter'
47
+ | 'onMouseMove'
48
+ | 'onMouseLeave'
49
+ | 'onReconnect'
50
+ | 'onReconnectStart'
51
+ | 'onReconnectEnd'
52
+ | 'reconnectRadius'
53
+ | 'edgeTypes'
54
+ | 'onError'
55
+ >): Octane.JSX.Element | null {
41
56
  let edge = useStore((s) => s.edgeLookup.get(id)!) as EdgeType;
42
57
  const defaultEdgeOptions = useStore((s) => s.defaultEdgeOptions);
43
58
  edge = defaultEdgeOptions ? { ...defaultEdgeOptions, ...edge } : edge;
@@ -7,7 +7,7 @@ import {
7
7
  SimpleBezierEdgeInternal,
8
8
  } from '../Edges';
9
9
 
10
- export const builtinEdgeTypes: EdgeTypes = {
10
+ export const builtinEdgeTypes: EdgeTypes & { default: EdgeTypes[string] } = {
11
11
  default: BezierEdgeInternal,
12
12
  straight: StraightEdgeInternal,
13
13
  step: StepEdgeInternal,
@@ -18,7 +18,7 @@ export interface EdgeAnchorProps extends SVGAttributes<SVGGElement> {
18
18
  position: Position;
19
19
  centerX: number;
20
20
  centerY: number;
21
- radius?: number;
21
+ radius?: number | undefined;
22
22
  onMouseDown: (event: ReactMouseEvent<SVGGElement, MouseEvent>) => void;
23
23
  onMouseEnter: (event: ReactMouseEvent<SVGGElement, MouseEvent>) => void;
24
24
  onMouseOut: (event: ReactMouseEvent<SVGGElement, MouseEvent>) => void;
@@ -1,3 +1,4 @@
1
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
1
2
  import { memo } from 'octane';
2
3
  import type { KeyboardEvent, MouseEvent } from '../../react-shim.js';
3
4
  import cc from 'classcat';
@@ -41,7 +42,18 @@ function NodeWrapper<NodeType extends Node>({
41
42
  nodeTypes,
42
43
  nodeClickDistance,
43
44
  onError,
44
- }: NodeWrapperProps<NodeType>) {
45
+ }: AllowUndefined<
46
+ NodeWrapperProps<NodeType>,
47
+ | 'onClick'
48
+ | 'onDoubleClick'
49
+ | 'onContextMenu'
50
+ | 'onMouseEnter'
51
+ | 'onMouseMove'
52
+ | 'onMouseLeave'
53
+ | 'nodeTypes'
54
+ | 'nodeExtent'
55
+ | 'onError'
56
+ >) {
45
57
  const { node, internals, isParent } = useStore((s) => {
46
58
  const node = s.nodeLookup.get(id)! as InternalNode<NodeType>;
47
59
  const isParent = s.parentLookup.has(id);
@@ -172,7 +184,7 @@ function NodeWrapper<NodeType extends Node>({
172
184
  });
173
185
 
174
186
  moveSelectedNodes({
175
- direction: arrowKeyDiffs[event.key],
187
+ direction: arrowKeyDiffs[event.key]!,
176
188
  factor: event.shiftKey ? 4 : 1,
177
189
  });
178
190
  }
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from 'octane';
2
2
 
3
- import type { InternalNode } from '../../types';
3
+ import type { InternalNode, Node } from '../../types';
4
4
  import { useStoreApi } from '../../hooks/useStore';
5
5
  import { resolveHookSlot, subSlot } from '../../hooks/slot';
6
6
 
@@ -10,14 +10,14 @@ import { resolveHookSlot, subSlot } from '../../hooks/slot';
10
10
  * @internal
11
11
  * @returns nodeRef - reference to the node element
12
12
  */
13
- export function useNodeObserver(
13
+ export function useNodeObserver<NodeType extends Node>(
14
14
  {
15
15
  node,
16
16
  nodeType,
17
17
  hasDimensions,
18
18
  resizeObserver,
19
19
  }: {
20
- node: InternalNode;
20
+ node: InternalNode<NodeType>;
21
21
  nodeType: string;
22
22
  hasDimensions: boolean;
23
23
  resizeObserver: ResizeObserver | null;
@@ -13,7 +13,7 @@ export const arrowKeyDiffs: Record<string, XYPosition> = {
13
13
  ArrowRight: { x: 1, y: 0 },
14
14
  };
15
15
 
16
- export const builtinNodeTypes: NodeTypes = {
16
+ export const builtinNodeTypes: NodeTypes & { default: NodeTypes[string] } = {
17
17
  input: InputNode,
18
18
  default: DefaultNode,
19
19
  output: OutputNode,
@@ -15,7 +15,7 @@ import { arrowKeyDiffs } from '../NodeWrapper/utils.tsrx';
15
15
  import type { Node, ReactFlowState } from '../../types';
16
16
 
17
17
  export type NodesSelectionProps<NodeType> = {
18
- onSelectionContextMenu?: (event: MouseEvent, nodes: NodeType[]) => void;
18
+ onSelectionContextMenu?: ((event: MouseEvent, nodes: NodeType[]) => void) | undefined;
19
19
  noPanClassName?: string;
20
20
  disableKeyboardA11y: boolean;
21
21
  };
@@ -75,7 +75,7 @@ export function NodesSelection<NodeType extends Node>({
75
75
  event.preventDefault();
76
76
 
77
77
  moveSelectedNodes({
78
- direction: arrowKeyDiffs[event.key],
78
+ direction: arrowKeyDiffs[event.key]!,
79
79
  factor: event.shiftKey ? 4 : 1,
80
80
  });
81
81
  }
@@ -11,7 +11,7 @@ import { useStore, useStoreApi } from '../../hooks/useStore';
11
11
  import type { ReactFlowState, OnSelectionChangeFunc, Node, Edge } from '../../types';
12
12
 
13
13
  type SelectionListenerProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
14
- onSelectionChange?: OnSelectionChangeFunc<NodeType, EdgeType>;
14
+ onSelectionChange?: OnSelectionChangeFunc<NodeType, EdgeType> | undefined;
15
15
  };
16
16
 
17
17
  const selector = (s: ReactFlowState) => {
@@ -3,6 +3,7 @@
3
3
  * We distinguish between values we can update directly with `useDirectStoreUpdater` (like `snapGrid`)
4
4
  * and values that have a dedicated setter function in the store (like `setNodes`).
5
5
  */
6
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
6
7
  import { useEffect, useRef } from 'octane';
7
8
  import { shallow } from '@octanejs/zustand/shallow';
8
9
  import {
@@ -79,8 +80,8 @@ const reactFlowFieldsToTrack = [
79
80
  ] as const;
80
81
 
81
82
  type ReactFlowFieldsToTrack = (typeof reactFlowFieldsToTrack)[number];
82
- type StoreUpdaterProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = Pick<
83
- ReactFlowProps<NodeType, EdgeType>,
83
+ type StoreUpdaterProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> = AllowUndefined<
84
+ Pick<ReactFlowProps<NodeType, EdgeType>, ReactFlowFieldsToTrack>,
84
85
  ReactFlowFieldsToTrack
85
86
  > & {
86
87
  rfId: string;
@@ -3,6 +3,7 @@ import { type MarkerProps, createMarkerIds } from '@xyflow/system';
3
3
 
4
4
  import { useStore } from '../../hooks/useStore';
5
5
  import { useMarkerSymbol } from './MarkerSymbols.tsrx';
6
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
6
7
 
7
8
  type MarkerDefinitionsProps = {
8
9
  defaultColor: string | null;
@@ -18,7 +19,10 @@ const Marker = ({
18
19
  markerUnits = 'strokeWidth',
19
20
  strokeWidth,
20
21
  orient = 'auto-start-reverse',
21
- }: MarkerProps) => {
22
+ }: AllowUndefined<
23
+ MarkerProps,
24
+ 'color' | 'width' | 'height' | 'markerUnits' | 'strokeWidth' | 'orient'
25
+ >) => {
22
26
  const Symbol = useMarkerSymbol(type);
23
27
 
24
28
  if (!Symbol) {
@@ -2,8 +2,9 @@ import { useMemo } from 'octane';
2
2
  import { errorMessages, MarkerType, type EdgeMarker } from '@xyflow/system';
3
3
 
4
4
  import { useStoreApi } from '../../hooks/useStore';
5
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
5
6
 
6
- type SymbolProps = Omit<EdgeMarker, 'type'>;
7
+ type SymbolProps = AllowUndefined<Omit<EdgeMarker, 'type'>, 'color' | 'strokeWidth'>;
7
8
 
8
9
  const ArrowSymbol = ({ color = 'none', strokeWidth = 1 }: SymbolProps) => {
9
10
  const style = {
@@ -29,7 +29,7 @@ export type FlowRendererProps<NodeType extends Node = Node> = Omit<
29
29
  children: OctaneNode;
30
30
  };
31
31
 
32
- const win = typeof window !== 'undefined' ? window : undefined;
32
+ const win = typeof window !== 'undefined' ? window : null;
33
33
 
34
34
  const selector = (s: ReactFlowState) => {
35
35
  return {
@@ -1,3 +1,4 @@
1
+ import type { AllowUndefined } from '../../types/allow-undefined-props';
1
2
  import { useEffect, useRef, type OctaneNode } from 'octane';
2
3
  import type {
3
4
  EventHandler,
@@ -25,28 +26,26 @@ import { useStore, useStoreApi } from '../../hooks/useStore';
25
26
  import { getSelectionChanges } from '../../utils';
26
27
  import type { ReactFlowProps, ReactFlowState } from '../../types';
27
28
 
29
+ type PaneForwardedProps =
30
+ | 'selectionMode'
31
+ | 'panOnDrag'
32
+ | 'autoPanOnSelection'
33
+ | 'onSelectionStart'
34
+ | 'onSelectionEnd'
35
+ | 'onPaneClick'
36
+ | 'onPaneContextMenu'
37
+ | 'onPaneScroll'
38
+ | 'onPaneMouseEnter'
39
+ | 'onPaneMouseMove'
40
+ | 'onPaneMouseLeave'
41
+ | 'selectionOnDrag';
42
+
28
43
  type PaneProps = {
29
44
  isSelecting: boolean;
30
45
  selectionKeyPressed: boolean;
31
46
  children: OctaneNode;
32
47
  paneClickDistance: number;
33
- } & Partial<
34
- Pick<
35
- ReactFlowProps,
36
- | 'selectionMode'
37
- | 'panOnDrag'
38
- | 'autoPanOnSelection'
39
- | 'onSelectionStart'
40
- | 'onSelectionEnd'
41
- | 'onPaneClick'
42
- | 'onPaneContextMenu'
43
- | 'onPaneScroll'
44
- | 'onPaneMouseEnter'
45
- | 'onPaneMouseMove'
46
- | 'onPaneMouseLeave'
47
- | 'selectionOnDrag'
48
- >
49
- >;
48
+ } & AllowUndefined<Partial<Pick<ReactFlowProps, PaneForwardedProps>>, PaneForwardedProps>;
50
49
 
51
50
  const wrapHandler = <EventType extends Event>(
52
51
  handler: EventHandler<EventType> | undefined,
@@ -276,7 +275,11 @@ export function Pane({
276
275
  if (!autoPanOnSelection || !containerBounds.current) {
277
276
  return;
278
277
  }
279
- const [x, y] = calcAutoPan(position.current, containerBounds.current, autoPanSpeed);
278
+ // @xyflow/system always returns the x/y pair but declares it as number[].
279
+ const [x, y] = calcAutoPan(position.current, containerBounds.current, autoPanSpeed) as [
280
+ number,
281
+ number,
282
+ ];
280
283
 
281
284
  panBy({ x, y }).then((panned) => {
282
285
  if (!selectionInProgress.current || !panned) {
@@ -22,18 +22,18 @@ export function Wrapper({
22
22
  zIndexMode,
23
23
  }: {
24
24
  children: OctaneNode;
25
- nodes?: Node[];
26
- edges?: Edge[];
25
+ nodes?: Node[] | undefined;
26
+ edges?: Edge[] | undefined;
27
27
  defaultNodes?: Node[];
28
28
  defaultEdges?: Edge[];
29
- width?: number;
30
- height?: number;
31
- fitView?: boolean;
32
- fitViewOptions?: FitViewOptions;
29
+ width?: number | undefined;
30
+ height?: number | undefined;
31
+ fitView?: boolean | undefined;
32
+ fitViewOptions?: FitViewOptions | undefined;
33
33
  minZoom?: number;
34
34
  maxZoom?: number;
35
35
  nodeOrigin?: NodeOrigin;
36
- nodeExtent?: CoordinateExtent;
36
+ nodeExtent?: CoordinateExtent | undefined;
37
37
  zIndexMode?: ZIndexMode;
38
38
  }) {
39
39
  const isWrapped = useContext(StoreContext);
@@ -354,4 +354,9 @@ function ReactFlow<NodeType extends Node = Node, EdgeType extends Edge = Edge>(
354
354
  *}
355
355
  *```
356
356
  */
357
- export default fixedForwardRef<HTMLDivElement, ReactFlowProps>(ReactFlow);
357
+ export default fixedForwardRef<HTMLDivElement, ReactFlowProps>(ReactFlow) as {
358
+ <NodeType extends Node = Node, EdgeType extends Edge = Edge>(
359
+ props: ReactFlowProps<NodeType, EdgeType> & { ref?: ForwardedRef<HTMLDivElement> },
360
+ ): ReturnType<typeof ReactFlow>;
361
+ displayName?: string;
362
+ };
@@ -1,9 +1,11 @@
1
1
  import { shallow } from '@octanejs/zustand/shallow';
2
2
  import { resolveHookSlot, withoutSlot } from './slot';
3
- import { ConnectionState, pointToRendererPoint } from '@xyflow/system';
3
+ import { pointToRendererPoint } from '@xyflow/system';
4
4
 
5
5
  import { useStore } from './useStore';
6
- import type { InternalNode, Node, ReactFlowStore } from '../types';
6
+ import type { Node, ReactFlowStore } from '../types';
7
+
8
+ type ConnectionFor<NodeType extends Node = Node> = ReactFlowStore<NodeType>['connection'];
7
9
 
8
10
  function storeSelector(s: ReactFlowStore) {
9
11
  return s.connection.inProgress
@@ -11,15 +13,12 @@ function storeSelector(s: ReactFlowStore) {
11
13
  : { ...s.connection };
12
14
  }
13
15
 
14
- function getSelector<
15
- NodeType extends Node = Node,
16
- SelectorReturn = ConnectionState<InternalNode<NodeType>>,
17
- >(
18
- connectionSelector?: (connection: ConnectionState<InternalNode<NodeType>>) => SelectorReturn,
19
- ): (s: ReactFlowStore) => SelectorReturn | ConnectionState<InternalNode> {
16
+ function getSelector<NodeType extends Node = Node, SelectorReturn = ConnectionFor<NodeType>>(
17
+ connectionSelector?: (connection: ConnectionFor<NodeType>) => SelectorReturn,
18
+ ): (s: ReactFlowStore) => SelectorReturn | ConnectionFor {
20
19
  if (connectionSelector) {
21
20
  const combinedSelector = (s: ReactFlowStore) => {
22
- const connection = storeSelector(s) as ConnectionState<InternalNode<NodeType>>;
21
+ const connection = storeSelector(s) as ConnectionFor<NodeType>;
23
22
  return connectionSelector(connection);
24
23
  };
25
24
  return combinedSelector;
@@ -58,17 +57,16 @@ function getSelector<
58
57
  */
59
58
  export function useConnection<
60
59
  NodeType extends Node = Node,
61
- SelectorReturn = ConnectionState<InternalNode<NodeType>>,
60
+ SelectorReturn = ConnectionFor<NodeType>,
62
61
  >(
63
- connectionSelector?: (connection: ConnectionState<InternalNode<NodeType>>) => SelectorReturn,
62
+ connectionSelector?: (connection: ConnectionFor<NodeType>) => SelectorReturn,
64
63
  ...rest: [slot?: symbol]
65
64
  ): SelectorReturn;
66
65
  export function useConnection<
67
66
  NodeType extends Node = Node,
68
- SelectorReturn = ConnectionState<InternalNode<NodeType>>,
67
+ SelectorReturn = ConnectionFor<NodeType>,
69
68
  >(
70
- connectionSelectorArg?:
71
- ((connection: ConnectionState<InternalNode<NodeType>>) => SelectorReturn) | symbol,
69
+ connectionSelectorArg?: ((connection: ConnectionFor<NodeType>) => SelectorReturn) | symbol,
72
70
  ...rest: [slot?: symbol]
73
71
  ): SelectorReturn {
74
72
  const slot =
@@ -10,10 +10,10 @@ type UseDragParams = {
10
10
  nodeRef: RefObject<HTMLDivElement>;
11
11
  disabled?: boolean;
12
12
  noDragClassName?: string;
13
- handleSelector?: string;
13
+ handleSelector?: string | undefined;
14
14
  nodeId?: string;
15
15
  isSelectable?: boolean;
16
- nodeClickDistance?: number;
16
+ nodeClickDistance?: number | undefined;
17
17
  };
18
18
 
19
19
  /**
@@ -9,7 +9,7 @@ import { Edge, Node } from '../types';
9
9
 
10
10
  const selected = (item: Node | Edge) => item.selected;
11
11
 
12
- const win = typeof window !== 'undefined' ? window : undefined;
12
+ const win = typeof window !== 'undefined' ? window : null;
13
13
 
14
14
  /**
15
15
  * Hook for handling global key events.
@@ -11,12 +11,9 @@ import {
11
11
  NodeSelectionChange,
12
12
  ParentExpandChild,
13
13
  initialConnection,
14
- NodeOrigin,
15
- CoordinateExtent,
16
14
  fitViewport,
17
15
  getHandlePosition,
18
16
  Position,
19
- ZIndexMode,
20
17
  } from '@xyflow/system';
21
18
 
22
19
  import {
@@ -25,14 +22,8 @@ import {
25
22
  createSelectionChange,
26
23
  getSelectionChanges,
27
24
  } from '../utils/changes';
28
- import getInitialState from './initialState';
29
- import type {
30
- ReactFlowState,
31
- Node,
32
- Edge,
33
- UnselectNodesAndEdgesParams,
34
- FitViewOptions,
35
- } from '../types';
25
+ import getInitialState, { type InitialStateOptions } from './initialState';
26
+ import type { ReactFlowState, Node, Edge, UnselectNodesAndEdgesParams } from '../types';
36
27
 
37
28
  const createStore = ({
38
29
  nodes,
@@ -48,21 +39,7 @@ const createStore = ({
48
39
  nodeOrigin,
49
40
  nodeExtent,
50
41
  zIndexMode,
51
- }: {
52
- nodes?: Node[];
53
- edges?: Edge[];
54
- defaultNodes?: Node[];
55
- defaultEdges?: Edge[];
56
- width?: number;
57
- height?: number;
58
- fitView?: boolean;
59
- fitViewOptions?: FitViewOptions;
60
- minZoom?: number;
61
- maxZoom?: number;
62
- nodeOrigin?: NodeOrigin;
63
- nodeExtent?: CoordinateExtent;
64
- zIndexMode?: ZIndexMode;
65
- }) =>
42
+ }: InitialStateOptions) =>
66
43
  createWithEqualityFn<ReactFlowState>((set, get) => {
67
44
  async function resolveFitView() {
68
45
  const {
@@ -18,6 +18,22 @@ const devWarn = createDevWarn('React Flow', 'https://reactflow.dev/');
18
18
 
19
19
  import type { Edge, FitViewOptions, InternalNode, Node, ReactFlowStore } from '../types';
20
20
 
21
+ export type InitialStateOptions = {
22
+ nodes?: Node[] | undefined;
23
+ edges?: Edge[] | undefined;
24
+ defaultNodes?: Node[] | undefined;
25
+ defaultEdges?: Edge[] | undefined;
26
+ width?: number | undefined;
27
+ height?: number | undefined;
28
+ fitView?: boolean | undefined;
29
+ fitViewOptions?: FitViewOptions | undefined;
30
+ minZoom?: number | undefined;
31
+ maxZoom?: number | undefined;
32
+ nodeOrigin?: NodeOrigin | undefined;
33
+ nodeExtent?: CoordinateExtent | undefined;
34
+ zIndexMode?: ZIndexMode | undefined;
35
+ };
36
+
21
37
  const getInitialState = ({
22
38
  nodes,
23
39
  edges,
@@ -32,21 +48,7 @@ const getInitialState = ({
32
48
  nodeOrigin,
33
49
  nodeExtent,
34
50
  zIndexMode = 'basic',
35
- }: {
36
- nodes?: Node[];
37
- edges?: Edge[];
38
- defaultNodes?: Node[];
39
- defaultEdges?: Edge[];
40
- width?: number;
41
- height?: number;
42
- fitView?: boolean;
43
- fitViewOptions?: FitViewOptions;
44
- minZoom?: number;
45
- maxZoom?: number;
46
- nodeOrigin?: NodeOrigin;
47
- nodeExtent?: CoordinateExtent;
48
- zIndexMode?: ZIndexMode;
49
- } = {}): ReactFlowStore => {
51
+ }: InitialStateOptions = {}): ReactFlowStore => {
50
52
  const nodeLookup = new Map<string, InternalNode>();
51
53
  const parentLookup = new Map();
52
54
  const connectionLookup = new Map();
@@ -0,0 +1,4 @@
1
+ /** Permit explicit undefined only on audited internal forwarding keys. */
2
+ export type AllowUndefined<Props, Keys extends keyof Props> = {
3
+ [Key in keyof Props]: Key extends Keys ? Props[Key] | undefined : Props[Key];
4
+ };
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  ConnectionMode,
3
3
  withResolvers,
4
- type ConnectionState,
4
+ type ConnectionInProgress,
5
+ type NoConnection,
5
6
  type CoordinateExtent,
6
7
  type InternalNodeUpdate,
7
8
  type UpdateNodePositions,
@@ -21,13 +22,10 @@ import {
21
22
  type OnMoveStart,
22
23
  type OnMove,
23
24
  type OnMoveEnd,
24
- type UpdateConnection,
25
25
  type EdgeLookup,
26
26
  type ConnectionLookup,
27
- type NodeLookup,
28
27
  type NodeChange,
29
28
  type EdgeChange,
30
- type ParentLookup,
31
29
  type AriaLabelConfig,
32
30
  type SetCenter,
33
31
  type ZIndexMode,
@@ -51,6 +49,15 @@ import type {
51
49
  InternalNode,
52
50
  } from '.';
53
51
 
52
+ // The pinned system generics cannot prove their default InternalNodeBase
53
+ // constraint for a generic InternalNode<NodeType> under exact optionals.
54
+ type FlowConnectionState<NodeType extends Node = Node> =
55
+ | NoConnection
56
+ | (Omit<ConnectionInProgress, 'fromNode' | 'toNode'> & {
57
+ fromNode: InternalNode<NodeType>;
58
+ toNode: InternalNode<NodeType> | null;
59
+ });
60
+
54
61
  export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge = Edge> = {
55
62
  rfId: string;
56
63
  width: number;
@@ -58,8 +65,8 @@ export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge =
58
65
  transform: Transform;
59
66
  nodes: NodeType[];
60
67
  nodesInitialized: boolean;
61
- nodeLookup: NodeLookup<InternalNode<NodeType>>;
62
- parentLookup: ParentLookup<InternalNode<NodeType>>;
68
+ nodeLookup: Map<string, InternalNode<NodeType>>;
69
+ parentLookup: Map<string, Map<string, InternalNode<NodeType>>>;
63
70
  edges: EdgeType[];
64
71
  edgeLookup: EdgeLookup<EdgeType>;
65
72
  connectionLookup: ConnectionLookup;
@@ -83,7 +90,7 @@ export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge =
83
90
  userSelectionActive: boolean;
84
91
  userSelectionRect: SelectionRect | null;
85
92
 
86
- connection: ConnectionState<InternalNode<NodeType>>;
93
+ connection: FlowConnectionState<NodeType>;
87
94
  connectionMode: ConnectionMode;
88
95
  connectionClickStartHandle:
89
96
  (Pick<Handle, 'nodeId' | 'id'> & Required<Pick<Handle, 'type'>>) | null;
@@ -136,9 +143,9 @@ export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge =
136
143
  onError?: OnError;
137
144
 
138
145
  // event handlers
139
- onViewportChangeStart?: OnViewportChange;
140
- onViewportChange?: OnViewportChange;
141
- onViewportChangeEnd?: OnViewportChange;
146
+ onViewportChangeStart?: OnViewportChange | undefined;
147
+ onViewportChange?: OnViewportChange | undefined;
148
+ onViewportChangeEnd?: OnViewportChange | undefined;
142
149
  onBeforeDelete?: OnBeforeDelete<NodeType, EdgeType>;
143
150
 
144
151
  onSelectionChangeHandlers: OnSelectionChangeFunc<NodeType, EdgeType>[];
@@ -149,7 +156,7 @@ export type ReactFlowStore<NodeType extends Node = Node, EdgeType extends Edge =
149
156
  autoPanSpeed: number;
150
157
  connectionRadius: number;
151
158
 
152
- isValidConnection?: IsValidConnection<EdgeType>;
159
+ isValidConnection?: IsValidConnection<EdgeType> | undefined;
153
160
 
154
161
  lib: string;
155
162
  debug: boolean;
@@ -184,7 +191,7 @@ export type ReactFlowActions<NodeType extends Node, EdgeType extends Edge> = {
184
191
  setTranslateExtent: (translateExtent: CoordinateExtent) => void;
185
192
  setNodeExtent: (nodeExtent: CoordinateExtent) => void;
186
193
  cancelConnection: () => void;
187
- updateConnection: UpdateConnection<InternalNode<NodeType>>;
194
+ updateConnection: (state: FlowConnectionState<NodeType>) => void;
188
195
  reset: () => void;
189
196
  triggerNodeChanges: (changes: NodeChange<NodeType>[]) => void;
190
197
  triggerEdgeChanges: (changes: EdgeChange<EdgeType>[]) => void;
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import {
3
3
  EdgeLookup,
4
- NodeLookup,
5
4
  EdgeChange,
6
5
  NodeChange,
7
6
  NodeSelectionChange,
@@ -9,7 +8,7 @@ import {
9
8
  NodeRemoveChange,
10
9
  EdgeRemoveChange,
11
10
  } from '@xyflow/system';
12
- import type { Node, Edge, InternalNode } from '../types';
11
+ import type { Node, Edge, ReactFlowStore } from '../types';
13
12
 
14
13
  /*
15
14
  * This function applies changes to nodes or edges that are triggered by React Flow internally.
@@ -271,13 +270,13 @@ export function getSelectionChanges(
271
270
  * @param params.lookup = a lookup map of the current store elements
272
271
  * @returns an array of changes
273
272
  */
274
- export function getElementsDiffChanges({
273
+ export function getElementsDiffChanges<NodeType extends Node>({
275
274
  items,
276
275
  lookup,
277
276
  }: {
278
- items: Node[] | undefined;
279
- lookup: NodeLookup<InternalNode<Node>>;
280
- }): NodeChange[];
277
+ items: NodeType[] | undefined;
278
+ lookup: ReactFlowStore<NodeType>['nodeLookup'];
279
+ }): NodeChange<NodeType>[];
281
280
  export function getElementsDiffChanges({
282
281
  items,
283
282
  lookup,