refactor(svelte): cleanup node options and props

This commit is contained in:
moklick
2023-03-02 15:31:37 +01:00
parent df6c3381b1
commit 33b9a801fe
15 changed files with 141 additions and 59 deletions
@@ -84,7 +84,7 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
};
const onKeyDown = (event: KeyboardEvent) => {
if (isInputDOMNode(event)) {
if (isInputDOMNode(event.nativeEvent)) {
return;
}
@@ -1,13 +1,12 @@
import { memo, useMemo, useEffect, useRef, type ComponentType } from 'react';
import { shallow } from 'zustand/shallow';
import { internalsSymbol, errorMessages, Position } from '@reactflow/system';
import { clampPosition } from '@reactflow/utils';
import { clampPosition, getPositionWithOrigin } from '@reactflow/utils';
import useVisibleNodes from '../../hooks/useVisibleNodes';
import { useStore } from '../../hooks/useStore';
import { containerStyle } from '../../styles';
import { GraphViewProps } from '../GraphView';
import { getPositionWithOrigin } from './utils';
import type { ReactFlowState, WrapNodeProps } from '../../types';
type NodeRendererProps = Pick<
@@ -1,5 +1,5 @@
import type { ComponentType } from 'react';
import type { NodeProps, NodeOrigin, XYPosition } from '@reactflow/system';
import type { NodeProps } from '@reactflow/system';
import DefaultNode from '../../components/Nodes/DefaultNode';
import InputNode from '../../components/Nodes/InputNode';
@@ -32,30 +32,3 @@ export function createNodeTypes(nodeTypes: NodeTypes): NodeTypesWrapped {
...specialTypes,
};
}
export const getPositionWithOrigin = ({
x,
y,
width,
height,
origin,
}: {
x: number;
y: number;
width: number;
height: number;
origin: NodeOrigin;
}): XYPosition => {
if (!width || !height) {
return { x, y };
}
if (origin[0] < 0 || origin[1] < 0 || origin[0] > 1 || origin[1] > 1) {
return { x, y };
}
return {
x: x - width * origin[0],
y: y - height * origin[1],
};
};