refactor(react/svelte): simplify ssr usage

This commit is contained in:
moklick
2023-10-23 16:37:28 +02:00
parent f42f6314e2
commit 6de9bbc916
6 changed files with 70 additions and 28 deletions
+4 -1
View File
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { internalsSymbol } from '../constants';
import type { XYPosition, Position, CoordinateExtent, HandleElement } from '.';
import { Optional } from '../utils/types';
// this is stuff that all nodes share independent of the framework
export type NodeBase<T = any, U extends string | undefined = string | undefined> = {
@@ -28,7 +29,7 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
ariaLabel?: string;
focusable?: boolean;
origin?: NodeOrigin;
handles?: HandleElement[];
handles?: NodeHandle[];
size?: {
width?: number;
height?: number;
@@ -94,3 +95,5 @@ export type NodeOrigin = [number, number];
export type OnNodeDrag = (event: MouseEvent, node: NodeBase, nodes: NodeBase[]) => void;
export type OnSelectionDrag = (event: MouseEvent, nodes: NodeBase[]) => void;
export type NodeHandle = Optional<HandleElement, 'width' | 'height'>;
+7 -4
View File
@@ -1,6 +1,6 @@
import { EdgePosition } from '../../types/edges';
import { ConnectionMode, OnError } from '../../types/general';
import { NodeBase, NodeHandleBounds } from '../../types/nodes';
import { NodeBase, NodeHandle, NodeHandleBounds } from '../../types/nodes';
import { Position, Rect, XYPosition } from '../../types/utils';
import { errorMessages, internalsSymbol } from '../../constants';
import { HandleElement } from '../../types';
@@ -59,19 +59,22 @@ export function getEdgePosition(params: GetEdgePositionParams): EdgePosition | n
};
}
function toHandleBounds(handles?: HandleElement[]) {
function toHandleBounds(handles?: NodeHandle[]) {
if (!handles) {
return null;
}
return handles.reduce<NodeHandleBounds>(
(res, item) => {
item.width = item.width || 1;
item.height = item.height || 1;
if (item.type === 'source') {
res.source?.push(item);
res.source?.push(item as HandleElement);
}
if (item.type === 'target') {
res.target?.push(item);
res.target?.push(item as HandleElement);
}
return res;
+1
View File
@@ -0,0 +1 @@
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;