@bavuchoko/edge-node 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +437 -2
- package/dist/components/ConnectionLine.d.ts +9 -0
- package/dist/components/EdgeEditor.d.ts +16 -0
- package/dist/components/GraphCanvas.d.ts +42 -0
- package/dist/components/GraphEdge.d.ts +22 -0
- package/dist/components/GraphNode.d.ts +59 -0
- package/dist/dependencies.d.ts +32 -0
- package/dist/geometry.d.ts +26 -0
- package/dist/hooks/useColorMode.d.ts +21 -0
- package/dist/hooks/useConnectionDrag.d.ts +12 -0
- package/dist/hooks/useGraphPersistence.d.ts +42 -0
- package/dist/hooks/useViewport.d.ts +15 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1639 -0
- package/dist/layout.d.ts +20 -0
- package/dist/store.d.ts +46 -0
- package/dist/style.css +628 -0
- package/dist/theme.d.ts +108 -0
- package/dist/types.d.ts +86 -0
- package/package.json +68 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GraphNode, Point } from './types';
|
|
2
|
+
export declare const DEFAULT_NODE_WIDTH = 300;
|
|
3
|
+
export declare const DEFAULT_NODE_HEIGHT = 150;
|
|
4
|
+
/** Screen (client) → world coordinates given viewport transform. */
|
|
5
|
+
export declare function screenToWorld(screen: Point, viewportOrigin: Point, viewport: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
zoom: number;
|
|
9
|
+
}): Point;
|
|
10
|
+
export declare function getHandlePosition(node: Pick<GraphNode<unknown>, 'position' | 'width' | 'height'>, side: 'left' | 'right'): Point;
|
|
11
|
+
/** Cubic bezier path from source (right) to target (left). */
|
|
12
|
+
export declare function getBezierPath(source: Point, target: Point): string;
|
|
13
|
+
/** Point halfway along the curve drawn by `getBezierPath`. */
|
|
14
|
+
export declare function getBezierMidpoint(source: Point, target: Point): Point;
|
|
15
|
+
/** Gap between an arrow tip and the target handle center, in world units. */
|
|
16
|
+
export declare const ARROW_TIP_GAP = 7;
|
|
17
|
+
/**
|
|
18
|
+
* Edge geometry ending in an arrowhead at `target`. The curve stops at the
|
|
19
|
+
* arrow's notch so the stroke doesn't poke through the tip. Bezier tangents
|
|
20
|
+
* at the target are always horizontal, so the arrow points in +x.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getArrowEdge(source: Point, target: Point, arrowLength: number): {
|
|
23
|
+
path: string;
|
|
24
|
+
arrow: string | null;
|
|
25
|
+
};
|
|
26
|
+
export declare function distance(a: Point, b: Point): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { GraphColorMode } from '../theme';
|
|
2
|
+
export type ColorModePreference = GraphColorMode | 'system';
|
|
3
|
+
/** Current OS color scheme, updated live. Returns `'dark'` during SSR. */
|
|
4
|
+
export declare function useSystemColorMode(): GraphColorMode;
|
|
5
|
+
type UseColorModeOptions = {
|
|
6
|
+
/** Used when nothing is stored yet. Defaults to `'system'`. */
|
|
7
|
+
defaultMode?: ColorModePreference;
|
|
8
|
+
/** localStorage key to persist the choice under. Omit to skip persistence. */
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Color mode state for a `GraphCanvas` host: tracks the user's preference,
|
|
13
|
+
* resolves `'system'` against the OS setting and optionally persists it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useColorMode({ defaultMode, storageKey }?: UseColorModeOptions): {
|
|
16
|
+
mode: ColorModePreference;
|
|
17
|
+
resolvedMode: GraphColorMode;
|
|
18
|
+
setMode: (next: ColorModePreference) => void;
|
|
19
|
+
toggle: () => void;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NodeId, Point } from '../types';
|
|
2
|
+
type UseConnectionDragArgs = {
|
|
3
|
+
clientToWorld: (clientX: number, clientY: number) => Point;
|
|
4
|
+
onStart: (sourceId: NodeId, pointer: Point) => void;
|
|
5
|
+
onMove: (pointer: Point) => void;
|
|
6
|
+
onComplete: (targetId: NodeId) => void;
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function useConnectionDrag({ clientToWorld, onStart, onMove, onComplete, onCancel, }: UseConnectionDragArgs): {
|
|
10
|
+
startFromHandle: (sourceId: NodeId, event: React.PointerEvent) => void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Dispatch } from 'react';
|
|
2
|
+
import type { GraphAction } from '../store';
|
|
3
|
+
import type { GraphEdge, GraphNode, GraphState, NodeData, NodeId, Point } from '../types';
|
|
4
|
+
/** Return `false` or reject to roll the change back. */
|
|
5
|
+
export type GraphCallbackResult = void | boolean | Promise<void | boolean>;
|
|
6
|
+
export type GraphPersistenceCallbacks<TData = NodeData> = {
|
|
7
|
+
/**
|
|
8
|
+
* A new connection was confirmed: called once when its editor closes
|
|
9
|
+
* (Enter, Esc or clicking elsewhere) with the final `kind`, `label` and relations.
|
|
10
|
+
* Not called if the connection is deleted before that.
|
|
11
|
+
*/
|
|
12
|
+
onConnect?: (edge: GraphEdge) => GraphCallbackResult;
|
|
13
|
+
/**
|
|
14
|
+
* An existing connection's `kind` / `label` / relations changed: called once when its
|
|
15
|
+
* editor closes, only if something actually changed.
|
|
16
|
+
*/
|
|
17
|
+
onEdgeUpdate?: (edge: GraphEdge, previous: GraphEdge) => GraphCallbackResult;
|
|
18
|
+
/**
|
|
19
|
+
* A confirmed connection was removed — directly, or because one of its
|
|
20
|
+
* nodes was deleted (called once per edge).
|
|
21
|
+
*/
|
|
22
|
+
onEdgeDelete?: (edge: GraphEdge) => GraphCallbackResult;
|
|
23
|
+
/**
|
|
24
|
+
* A node was dragged to a new place: called once on drop (not while
|
|
25
|
+
* dragging), only if it actually moved. `node.position` is the new spot.
|
|
26
|
+
*/
|
|
27
|
+
onNodeMove?: (node: GraphNode<TData>, previous: Point) => GraphCallbackResult;
|
|
28
|
+
};
|
|
29
|
+
type UseGraphPersistenceArgs<TData> = GraphPersistenceCallbacks<TData> & {
|
|
30
|
+
state: GraphState<TData>;
|
|
31
|
+
dispatch: Dispatch<GraphAction>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Reports graph changes to the host (e.g. to save them through an API) and
|
|
35
|
+
* rolls the local change back when the host rejects it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useGraphPersistence<TData>({ state, dispatch, onConnect, onEdgeUpdate, onEdgeDelete, onNodeMove, }: UseGraphPersistenceArgs<TData>): {
|
|
38
|
+
savingEdgeIds: ReadonlySet<string>;
|
|
39
|
+
deleteSelection: () => void;
|
|
40
|
+
reportNodeMove: (id: NodeId, from: Point) => void;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Point, Viewport } from '../types';
|
|
2
|
+
type UseViewportArgs = {
|
|
3
|
+
viewport: Viewport;
|
|
4
|
+
onViewportChange: (viewport: Viewport) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function useViewport({ viewport, onViewportChange }: UseViewportArgs): {
|
|
7
|
+
containerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
8
|
+
isPanning: boolean;
|
|
9
|
+
clientToWorld: (clientX: number, clientY: number) => Point;
|
|
10
|
+
getOrigin: () => Point;
|
|
11
|
+
startPan: (event: React.PointerEvent) => void;
|
|
12
|
+
movePan: (event: React.PointerEvent) => void;
|
|
13
|
+
endPan: (event: React.PointerEvent) => void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { GraphCanvas, type GraphCanvasProps } from './components/GraphCanvas';
|
|
2
|
+
export type { NodeRenderContext, RenderNode } from './components/GraphNode';
|
|
3
|
+
export { getDependencyHighlight, getDownstream, getUpstream, wouldCreateCycle, type ChainRelation, type DependencyHighlight, type DependencyRole, } from './dependencies';
|
|
4
|
+
export { useColorMode, useSystemColorMode, type ColorModePreference, } from './hooks/useColorMode';
|
|
5
|
+
export type { GraphCallbackResult, GraphPersistenceCallbacks, } from './hooks/useGraphPersistence';
|
|
6
|
+
export { layoutColumns, type LayoutNodeInput } from './layout';
|
|
7
|
+
export { createInitialState } from './store';
|
|
8
|
+
export { darkGraphTheme, defaultGraphTheme, graphThemes, lightGraphTheme, resolveGraphTheme, type GraphColorMode, type GraphTheme, type ResolvedGraphTheme, } from './theme';
|
|
9
|
+
export type { EdgeId, EdgeKind, GraphEdge, GraphEdgeInput, GraphNode, GraphState, NodeData, NodeDetail, NodeId, NodeStatus, Point, Viewport, } from './types';
|