Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xyflow/svelte

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xyflow/svelte - npm Package Compare versions

Comparing version 0.0.27 to 0.0.28

dist/lib/hooks/useColorModeClass.d.ts

1

dist/lib/actions/drag/index.js

@@ -16,2 +16,3 @@ import { get } from 'svelte/store';

nodes: get(store.nodes),
nodeLookup: get(store.nodeLookup),
edges: get(store.edges),

@@ -18,0 +19,0 @@ nodeExtent: get(store.nodeExtent),

@@ -1,3 +0,9 @@

export default function (node: Element, target?: string): {
type PortalOptions = {
target?: string;
domNode: Element | null;
};
export default function (node: Element, { target, domNode }: PortalOptions): {
update({ target, domNode }: PortalOptions): Promise<void>;
destroy(): void;
};
export {};

@@ -1,7 +0,16 @@

export default function (node, target = 'body') {
const targetEl = document.querySelector(target);
function tryToMount(node, domNode, target) {
if (!domNode) {
return;
}
const targetEl = target ? domNode.querySelector(target) : domNode;
if (targetEl) {
targetEl.appendChild(node);
}
}
export default function (node, { target, domNode }) {
tryToMount(node, domNode, target);
return {
async update({ target, domNode }) {
tryToMount(node, domNode, target);
},
destroy() {

@@ -8,0 +17,0 @@ if (node.parentNode) {

9

dist/lib/components/KeyHandler/types.d.ts
import type { KeyDefinition } from '../../types';
export type KeyHandlerProps = {
selectionKey?: KeyDefinition;
multiSelectionKey?: KeyDefinition;
deleteKey?: KeyDefinition;
panActivationKey?: KeyDefinition;
selectionKey?: KeyDefinition | null;
multiSelectionKey?: KeyDefinition | null;
deleteKey?: KeyDefinition | null;
panActivationKey?: KeyDefinition | null;
zoomActivationKey?: KeyDefinition | null;
};
import { SvelteComponentTyped } from "svelte";
import type { Node } from '../../types';
declare const __propDef: {
props: Record<string, never>;
events: {
selectioncontextmenu: CustomEvent<{
nodes: Node[];
event: MouseEvent | TouchEvent;
}>;
selectionclick: CustomEvent<{
nodes: Node[];
event: MouseEvent | TouchEvent;
}>;
} & {
[evt: string]: CustomEvent<any>;

@@ -6,0 +16,0 @@ };

@@ -5,4 +5,10 @@ import { SvelteComponentTyped } from "svelte";

declare const __propDef: {
props: Pick<Node, "id" | "data" | "type" | "sourcePosition" | "targetPosition" | "hidden" | "selected" | "dragging" | "draggable" | "selectable" | "connectable" | "dragHandle" | "width" | "height" | "positionAbsolute" | "class" | "style"> & {
positionOrigin?: import("@xyflow/system").XYPosition | undefined;
props: Pick<Node, "id" | "data" | "type" | "sourcePosition" | "targetPosition" | "hidden" | "selected" | "dragging" | "draggable" | "selectable" | "connectable" | "dragHandle" | "class" | "style"> & {
width?: number | undefined;
height?: number | undefined;
type: string;
positionX: number;
positionY: number;
positionOriginX: number;
positionOriginY: number;
'on:nodeclick'?: ((event: MouseEvent) => void) | undefined;

@@ -9,0 +15,0 @@ resizeObserver?: ResizeObserver | null | undefined;

@@ -1,5 +0,10 @@

import type { XYPosition } from '@xyflow/system';
import type { Node } from '../../types';
export type NodeWrapperProps = Pick<Node, 'id' | 'class' | 'connectable' | 'data' | 'draggable' | 'dragging' | 'positionAbsolute' | 'selected' | 'selectable' | 'style' | 'type' | 'width' | 'height' | 'sourcePosition' | 'targetPosition' | 'dragHandle' | 'hidden'> & {
positionOrigin?: XYPosition;
export type NodeWrapperProps = Pick<Node, 'id' | 'class' | 'connectable' | 'data' | 'draggable' | 'dragging' | 'selected' | 'selectable' | 'style' | 'type' | 'sourcePosition' | 'targetPosition' | 'dragHandle' | 'hidden'> & {
width?: number;
height?: number;
type: string;
positionX: number;
positionY: number;
positionOriginX: number;
positionOriginY: number;
'on:nodeclick'?: (event: MouseEvent) => void;

@@ -6,0 +11,0 @@ resizeObserver?: ResizeObserver | null;

@@ -57,2 +57,10 @@ import { SvelteComponentTyped } from "svelte";

}>;
selectionclick: CustomEvent<{
nodes: import("../..").Node[];
event: MouseEvent | TouchEvent;
}>;
selectioncontextmenu: CustomEvent<{
nodes: import("../..").Node[];
event: MouseEvent | TouchEvent;
}>;
} & {

@@ -59,0 +67,0 @@ [evt: string]: CustomEvent<any>;

import type { DOMAttributes } from 'svelte/elements';
import type { ConnectionLineType, NodeOrigin, Viewport, SelectionMode, SnapGrid, OnMoveStart, OnMove, OnMoveEnd, CoordinateExtent, PanOnScrollMode, IsValidConnection, OnError, ConnectionMode, PanelPosition, ProOptions } from '@xyflow/system';
import type { Edge, Node, NodeTypes, KeyDefinition, EdgeTypes, DefaultEdgeOptions, FitViewOptions } from '../../types';
import type { ConnectionLineType, NodeOrigin, Viewport, SelectionMode, SnapGrid, OnMoveStart, OnMove, OnMoveEnd, CoordinateExtent, PanOnScrollMode, IsValidConnection, OnError, ConnectionMode, PanelPosition, ProOptions, ColorMode } from '@xyflow/system';
import type { Edge, Node, NodeTypes, KeyDefinition, EdgeTypes, DefaultEdgeOptions, FitViewOptions, OnDelete } from '../../types';
import type { Writable } from 'svelte/store';

@@ -11,5 +11,7 @@ export type SvelteFlowProps = DOMAttributes<HTMLDivElement> & {

edgeTypes?: EdgeTypes;
selectionKey?: KeyDefinition;
panActivationKey?: KeyDefinition;
deleteKey?: KeyDefinition;
selectionKey?: KeyDefinition | null;
panActivationKey?: KeyDefinition | null;
deleteKey?: KeyDefinition | null;
multiSelectionKey?: KeyDefinition | null;
zoomActivationKey?: KeyDefinition | null;
fitView?: boolean;

@@ -50,2 +52,3 @@ fitViewOptions?: FitViewOptions;

height?: number;
colorMode?: ColorMode;
class?: string;

@@ -58,3 +61,4 @@ style?: string;

onMoveEnd?: OnMoveEnd;
onError?: OnError;
onerror?: OnError;
ondelete?: OnDelete;
};
import type { SvelteFlowStore } from '../../store/types';
import type { EdgeTypes, NodeTypes } from '../../types';
import type { CoordinateExtent } from '@xyflow/system';
import type { ColorMode, CoordinateExtent } from '@xyflow/system';
import type { Writable } from 'svelte/store';

@@ -28,6 +28,8 @@ export declare function updateStore(store: SvelteFlowStore, { nodeTypes, edgeTypes, minZoom, maxZoom, translateExtent }: {

connectionMode?: UnwrapWritable<SvelteFlowStore['connectionMode']>;
onError?: UnwrapWritable<SvelteFlowStore['onError']>;
onerror?: UnwrapWritable<SvelteFlowStore['onerror']>;
ondelete?: UnwrapWritable<SvelteFlowStore['ondelete']>;
nodeDragThreshold?: UnwrapWritable<SvelteFlowStore['nodeDragThreshold']>;
};
export declare function updateStoreByKeys(store: SvelteFlowStore, keys: UpdatableStoreProps): void;
export declare function getColorModeClass(colorMode?: ColorMode): "light" | "dark" | undefined;
export {};

@@ -31,1 +31,10 @@ // this is helper function for updating the store

}
export function getColorModeClass(colorMode) {
if (colorMode !== 'system') {
return colorMode;
}
if (!colorMode || typeof window === 'undefined' || !window.matchMedia) {
return 'light';
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}

@@ -50,3 +50,3 @@ import { get } from 'svelte/store';

return (nodesToIntersect || get(nodes)).filter((n) => {
if (!isRect && (n.id === node.id || !n.positionAbsolute)) {
if (!isRect && (n.id === node.id || !n.computed?.positionAbsolute)) {
return false;

@@ -53,0 +53,0 @@ }

@@ -8,9 +8,9 @@ import { get } from 'svelte/store';

const updateIds = Array.isArray(id) ? id : [id];
const updates = updateIds.reduce((res, updateId) => {
const updates = new Map();
updateIds.forEach((updateId) => {
const nodeElement = get(domNode)?.querySelector(`.svelte-flow__node[data-id="${updateId}"]`);
if (nodeElement) {
res.push({ id: updateId, nodeElement, forceUpdate: true });
updates.set(updateId, { id: updateId, nodeElement, forceUpdate: true });
}
return res;
}, []);
});
requestAnimationFrame(() => updateNodeDimensions(updates));

@@ -17,0 +17,0 @@ };

@@ -12,2 +12,3 @@ export { SvelteFlow } from './container/SvelteFlow';

export * from './plugins/Minimap';
export * from './plugins/NodeToolbar';
export { useStore } from './store';

@@ -23,3 +24,3 @@ export * from './utils';

export type { SvelteFlowStore } from './store/types';
export { type SmoothStepPathOptions, type BezierPathOptions, ConnectionLineType, type EdgeMarker, type EdgeMarkerType, MarkerType, type OnMove, type OnMoveStart, type OnMoveEnd, type Connection, type ConnectionStatus, ConnectionMode, type OnConnectStartParams, type OnConnectStart, type OnConnect, type OnConnectEnd, type IsValidConnection, type Viewport, type SnapGrid, PanOnScrollMode, type ViewportHelperFunctionOptions, type SetCenterOptions, type FitBoundsOptions, type PanelPosition, type ProOptions, SelectionMode, type SelectionRect, type OnError, type NodeProps, type NodeOrigin, type OnNodeDrag, type OnSelectionDrag, Position, type XYPosition, type XYZPosition, type Dimensions, type Rect, type Box, type Transform, type CoordinateExtent } from '@xyflow/system';
export { type SmoothStepPathOptions, type BezierPathOptions, ConnectionLineType, type EdgeMarker, type EdgeMarkerType, MarkerType, type OnMove, type OnMoveStart, type OnMoveEnd, type Connection, type ConnectionStatus, ConnectionMode, type OnConnectStartParams, type OnConnectStart, type OnConnect, type OnConnectEnd, type IsValidConnection, type Viewport, type SnapGrid, PanOnScrollMode, type ViewportHelperFunctionOptions, type SetCenterOptions, type FitBoundsOptions, type PanelPosition, type ProOptions, SelectionMode, type SelectionRect, type OnError, type NodeProps, type NodeOrigin, type OnNodeDrag, type OnSelectionDrag, Position, type XYPosition, type XYZPosition, type Dimensions, type Rect, type Box, type Transform, type CoordinateExtent, type ColorMode, type ColorModeClass } from '@xyflow/system';
export { type GetBezierPathParams, getBezierEdgeCenter, getBezierPath, getEdgeCenter, type GetSmoothStepPathParams, getSmoothStepPath, type GetStraightPathParams, getStraightPath, getViewportForBounds, getNodesBounds } from '@xyflow/system';

@@ -15,2 +15,3 @@ // main component

export * from './plugins/Minimap';
export * from './plugins/NodeToolbar';
// store

@@ -17,0 +18,0 @@ export { useStore } from './store';

@@ -9,5 +9,5 @@ import { SvelteComponentTyped } from "svelte";

borderRadius?: number | undefined;
color: string;
color?: string | undefined;
shapeRendering: string;
strokeColor: string;
strokeColor?: string | undefined;
strokeWidth?: number | undefined;

@@ -14,0 +14,0 @@ selected?: boolean | undefined;

@@ -27,9 +27,9 @@ import { derived } from 'svelte/store';

store.connectionMode,
store.nodes,
store.nodeLookup,
store.viewport
], ([connection, connectionLineType, connectionMode, nodes, viewport]) => {
], ([connection, connectionLineType, connectionMode, nodeLookup, viewport]) => {
if (!connection.connectionStartHandle?.nodeId) {
return initConnectionProps;
}
const fromNode = nodes.find((n) => n.id === connection.connectionStartHandle?.nodeId);
const fromNode = nodeLookup.get(connection.connectionStartHandle?.nodeId);
const fromHandleBounds = fromNode?.[internalsSymbol]?.handleBounds;

@@ -46,6 +46,8 @@ const handleBoundsStrict = fromHandleBounds?.[connection.connectionStartHandle.type || 'source'] || [];

? fromHandle.x + fromHandle.width / 2
: (fromNode?.width ?? 0) / 2;
const fromHandleY = fromHandle ? fromHandle.y + fromHandle.height / 2 : fromNode?.height ?? 0;
const fromX = (fromNode?.positionAbsolute?.x ?? 0) + fromHandleX;
const fromY = (fromNode?.positionAbsolute?.y ?? 0) + fromHandleY;
: (fromNode?.computed?.width ?? 0) / 2;
const fromHandleY = fromHandle
? fromHandle.y + fromHandle.height / 2
: fromNode?.computed?.height ?? 0;
const fromX = (fromNode?.computed?.positionAbsolute?.x ?? 0) + fromHandleX;
const fromY = (fromNode?.computed?.positionAbsolute?.y ?? 0) + fromHandleY;
const fromPosition = fromHandle?.position;

@@ -52,0 +54,0 @@ const toPosition = fromPosition ? oppositePosition[fromPosition] : undefined;

@@ -7,2 +7,3 @@ import { derived } from 'svelte/store';

store.nodes,
store.nodeLookup,
store.onlyRenderVisibleElements,

@@ -12,7 +13,7 @@ store.viewport,

store.height
], ([edges, nodes, onlyRenderVisibleElements, viewport, width, height]) => {
], ([edges, , nodeLookup, onlyRenderVisibleElements, viewport, width, height]) => {
const visibleEdges = onlyRenderVisibleElements && width && height
? edges.filter((edge) => {
const sourceNode = nodes.find((node) => node.id === edge.source);
const targetNode = nodes.find((node) => node.id === edge.target);
const sourceNode = nodeLookup.get(edge.source);
const targetNode = nodeLookup.get(edge.target);
return (sourceNode &&

@@ -31,6 +32,6 @@ targetNode &&

});
return derived([visibleEdges, store.nodes, store.connectionMode, store.onError], ([visibleEdges, nodes, connectionMode, onError]) => {
return derived([visibleEdges, store.nodes, store.nodeLookup, store.connectionMode, store.onerror], ([visibleEdges, , nodeLookup, connectionMode, onerror]) => {
const layoutedEdges = visibleEdges.reduce((res, edge) => {
const sourceNode = nodes.find((node) => node.id === edge.source);
const targetNode = nodes.find((node) => node.id === edge.target);
const sourceNode = nodeLookup.get(edge.source);
const targetNode = nodeLookup.get(edge.target);
if (!sourceNode || !targetNode) {

@@ -46,3 +47,3 @@ return res;

connectionMode,
onError
onError: onerror
});

@@ -57,5 +58,5 @@ if (edgePosition) {

}, []);
const groupedEdges = groupEdgesByZLevel(layoutedEdges, nodes, false);
const groupedEdges = groupEdgesByZLevel(layoutedEdges, nodeLookup, false);
return groupedEdges;
});
}

@@ -31,14 +31,17 @@ import { getContext, setContext } from 'svelte';

store.nodes.update((nds) => {
return nds.map((n) => {
const nodeDragItem = nodeDragItems.find((ndi) => ndi.id === n.id);
return nds.map((node) => {
const nodeDragItem = nodeDragItems.find((ndi) => ndi.id === node.id);
if (nodeDragItem) {
return {
...n,
[internalsSymbol]: n[internalsSymbol],
...node,
dragging,
positionAbsolute: nodeDragItem.positionAbsolute,
position: nodeDragItem.position
position: nodeDragItem.position,
computed: {
...node.computed,
positionAbsolute: nodeDragItem.computed?.positionAbsolute
},
[internalsSymbol]: node[internalsSymbol]
};
}
return n;
return node;
});

@@ -48,3 +51,3 @@ });

function updateNodeDimensions(updates) {
const nextNodes = updateNodeDimensionsSystem(updates, get(store.nodes), get(store.domNode), get(store.nodeOrigin));
const nextNodes = updateNodeDimensionsSystem(updates, get(store.nodes), get(store.nodeLookup), get(store.domNode), get(store.nodeOrigin));
if (!nextNodes) {

@@ -143,2 +146,6 @@ return;

store.edges.update((eds) => eds.filter((edge) => !matchingEdges.some((mE) => mE.id === edge.id)));
get(store.ondelete)?.({
nodes: matchingNodes,
edges: matchingEdges
});
}

@@ -145,0 +152,0 @@ }

@@ -11,3 +11,3 @@ /// <reference types="svelte" />

import StepEdge from '../components/edges/StepEdge.svelte';
import type { NodeTypes, EdgeTypes, EdgeLayouted, Node, Edge, FitViewOptions } from '../types';
import type { NodeTypes, EdgeTypes, EdgeLayouted, Node, Edge, FitViewOptions, OnDelete } from '../types';
import { type ConnectionProps } from './derived-connection-props';

@@ -41,2 +41,3 @@ export declare const initialNodeTypes: {

};
nodeLookup: import("svelte/store").Readable<Map<string, Node>>;
visibleNodes: import("svelte/store").Readable<Node[]>;

@@ -68,2 +69,3 @@ edges: import("svelte/store").Writable<Edge[]> & {

panActivationKeyPressed: import("svelte/store").Writable<boolean>;
zoomActivationKeyPressed: import("svelte/store").Writable<boolean>;
selectionRectMode: import("svelte/store").Writable<string | null>;

@@ -88,3 +90,4 @@ selectionMode: import("svelte/store").Writable<SelectionMode>;

onlyRenderVisibleElements: import("svelte/store").Writable<boolean>;
onError: import("svelte/store").Writable<OnError>;
onerror: import("svelte/store").Writable<OnError>;
ondelete: import("svelte/store").Writable<OnDelete>;
};

@@ -26,10 +26,10 @@ import { readable, writable } from 'svelte/store';

export const getInitialStore = ({ nodes = [], edges = [], width, height, fitView }) => {
const nextNodes = updateNodes(nodes, [], { nodeOrigin: [0, 0], elevateNodesOnSelect: false });
const nodeLookup = new Map();
const nextNodes = updateNodes(nodes, nodeLookup, {
nodeOrigin: [0, 0],
elevateNodesOnSelect: false
});
let viewport = { x: 0, y: 0, zoom: 1 };
if (fitView && width && height) {
const nodesWithDimensions = nextNodes.map((node) => ({
...node,
width: node.size?.width,
height: node.size?.height
}));
const nodesWithDimensions = nextNodes.filter((node) => node.width && node.height);
const bounds = getNodesBounds(nodesWithDimensions, [0, 0]);

@@ -40,3 +40,4 @@ viewport = getViewportForBounds(bounds, width, height, 0.5, 2, 0.1);

flowId: writable(null),
nodes: createNodesStore(nextNodes),
nodes: createNodesStore(nextNodes, nodeLookup),
nodeLookup: readable(nodeLookup),
visibleNodes: readable([]),

@@ -66,2 +67,3 @@ edges: createEdgesStore(edges),

panActivationKeyPressed: writable(false),
zoomActivationKeyPressed: writable(false),
selectionRectMode: writable(null),

@@ -86,4 +88,5 @@ selectionMode: writable(SelectionMode.Partial),

onlyRenderVisibleElements: writable(false),
onError: writable(devWarn)
onerror: writable(devWarn),
ondelete: writable(undefined)
};
};

@@ -19,3 +19,3 @@ import type { Writable } from 'svelte/store';

updateNodePositions: UpdateNodePositions;
updateNodeDimensions: (updates: NodeDimensionUpdate[]) => void;
updateNodeDimensions: (updates: Map<string, NodeDimensionUpdate>) => void;
unselectNodesAndEdges: (params?: {

@@ -22,0 +22,0 @@ nodes?: Node[];

@@ -10,3 +10,3 @@ import { type Unsubscriber, type Subscriber, type Updater, type Writable } from 'svelte/store';

};
export declare const createNodesStore: (nodes: Node[]) => {
export declare const createNodesStore: (nodes: Node[], nodeLookup: Map<string, Node>) => {
subscribe: (this: void, run: Subscriber<Node[]>) => Unsubscriber;

@@ -13,0 +13,0 @@ update: (this: void, updater: Updater<Node[]>) => void;

@@ -8,3 +8,10 @@ import { writable, get } from 'svelte/store';

const userNodesStoreSetter = userNodesStore.set;
let val = get(userNodesStore);
const currentNodesStore = get(nodesStore);
const currentUserNodesStore = get(userNodesStore);
// depending how the user initializes the nodes, we need to decide if we want to use
// the user nodes or the internal nodes for initialization. A user can use a SvelteFlowProvider
// without providing any nodes, in that case we want to use the nodes passed by the user.
// By default we are using the store nodes, because they already have the absolute positions.
const initWithUserNodes = currentNodesStore.length === 0 && currentUserNodesStore.length > 0;
let val = initWithUserNodes ? currentUserNodesStore : currentNodesStore;
nodesStore.set(val);

@@ -67,3 +74,3 @@ const _set = (nds) => {

// The user only passes in relative positions, so we need to calculate the absolute positions based on the parent nodes.
export const createNodesStore = (nodes) => {
export const createNodesStore = (nodes, nodeLookup) => {
const { subscribe, set, update } = writable([]);

@@ -74,3 +81,3 @@ let value = nodes;

const _set = (nds) => {
const nextNodes = updateNodes(nds, value, {
const nextNodes = updateNodes(nds, nodeLookup, {
elevateNodesOnSelect,

@@ -77,0 +84,0 @@ defaults

import type { ShortcutModifierDefinition } from '@svelte-put/shortcut';
import type { FitViewOptionsBase, HandleType, Position, XYPosition, ConnectingHandle } from '@xyflow/system';
import type { Node } from './nodes';
import type { Edge } from './edges';
export type KeyModifier = ShortcutModifierDefinition;

@@ -27,1 +28,5 @@ export type KeyDefinitionObject = {

export type FitViewOptions = FitViewOptionsBase<Node>;
export type OnDelete = (params: {
nodes: Node[];
edges: Edge[];
}) => void;
{
"name": "@xyflow/svelte",
"version": "0.0.27",
"version": "0.0.28",
"description": "Svelte Flow - A highly customizable Svelte library for building node-based editors, workflow systems, diagrams and more.",

@@ -35,3 +35,3 @@ "keywords": [

"classcat": "^5.0.4",
"@xyflow/system": "0.0.10"
"@xyflow/system": "0.0.11"
},

@@ -38,0 +38,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc