@dschz/solid-flow 0.3.0-next.5 → 1.0.0-next.7
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/README.md +41 -12
- package/dist/index/index.d.ts +151 -106
- package/dist/index/index.js +471 -254
- package/dist/index/index.jsx +470 -245
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -15,12 +15,12 @@ A SolidJS port of [React Flow](https://reactflow.dev/) and [Svelte Flow](https:/
|
|
|
15
15
|
|
|
16
16
|
## Version pairing
|
|
17
17
|
|
|
18
|
-
| Solid Flow | SolidJS | Status
|
|
19
|
-
| ---------- | --------------- |
|
|
20
|
-
| `
|
|
21
|
-
| `0.2.x` | `solid-js` 1.9+ | Maintenance (fixes)
|
|
18
|
+
| Solid Flow | SolidJS | Status |
|
|
19
|
+
| ---------- | --------------- | ------------------------------- |
|
|
20
|
+
| `1.x` | `solid-js` 2.x | Active development (`next` tag) |
|
|
21
|
+
| `0.2.x` | `solid-js` 1.9+ | Maintenance (fixes) |
|
|
22
22
|
|
|
23
|
-
The
|
|
23
|
+
The 1.x line is built for SolidJS 2.0 and its deferred, fine-grained reactive graph; the stable 1.0.0 ships alongside SolidJS 2.0 stable (until then, install with the `next` tag). Keep `solid-js` and `@solidjs/web` on matching 2.0 versions — mixing them breaks at import time. Upgrading from 0.2.x? See [Migrating from 0.2.x](#migrating-from-02x).
|
|
24
24
|
|
|
25
25
|
## Key Features
|
|
26
26
|
|
|
@@ -135,11 +135,11 @@ const [nodes] = createNodeStore<typeof nodeTypes>([
|
|
|
135
135
|
The same guided unions are exported as standalone types, so plain arrays, props, and vanilla stores get identical narrowing:
|
|
136
136
|
|
|
137
137
|
```tsx
|
|
138
|
-
import type {
|
|
138
|
+
import type { SolidFlowEdge, SolidFlowNode } from "@dschz/solid-flow";
|
|
139
139
|
|
|
140
140
|
const initialNodes = [
|
|
141
141
|
{ id: "a", type: "counter", data: { count: 1 }, position: { x: 0, y: 0 } },
|
|
142
|
-
] satisfies
|
|
142
|
+
] satisfies SolidFlowNode<typeof nodeTypes>[];
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
## Who owns the data
|
|
@@ -150,6 +150,34 @@ The stores you pass as `nodes` / `edges` props are **controlled** — a delibera
|
|
|
150
150
|
- **The flow writes runtime fields onto your rows.** Dragging updates `position`, selection updates `selected`, measurement fills `measured` — on the same objects you provided, so reading your store is always live.
|
|
151
151
|
- **Imperative commands don't write membership back.** `commands.addNodes(...)` and friends update the flow, not your store. To keep an element across a store replacement, adopt it — like the `onConnect` handler in the Quick Start pushing the new connection into the edge store.
|
|
152
152
|
|
|
153
|
+
**Prefer letting the flow own the data?** Pass `defaultNodes` / `defaultEdges` instead of `nodes` / `edges` for an **uncontrolled** flow (React Flow parity): the arrays seed the flow once (later values are ignored), and membership belongs to the flow — commands like `addNodes` and completed connections persist with no adoption step. Read live state through `useSolidFlow()`'s `flow.nodes` / `flow.edges`. The two axes are independent, so you can control edges while leaving nodes uncontrolled (or vice versa); supplying both props on one axis is a mistake (`nodes` wins, with a dev warning).
|
|
154
|
+
|
|
155
|
+
## Loading your graph from an API
|
|
156
|
+
|
|
157
|
+
Both stores accept an async seed — pass `async () => data` instead of an array. No memo, no lifecycle juggling: reads are not-ready until the data lands (SolidJS 2.0's async model), so a `<Loading>` boundary holds the flow and swaps in the graph when it arrives. Afterwards the stores behave exactly like their array-seeded counterparts — drafts, adoption, wholesale replacement.
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import { Loading } from "@solidjs/web";
|
|
161
|
+
|
|
162
|
+
const fetchNodes = async () => (await fetch("/api/graph/nodes")).json();
|
|
163
|
+
const fetchEdges = async () => (await fetch("/api/graph/edges")).json();
|
|
164
|
+
|
|
165
|
+
export const Flow = () => {
|
|
166
|
+
const [nodes] = createNodeStore(fetchNodes);
|
|
167
|
+
const [edges, setEdges] = createEdgeStore(fetchEdges);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Loading fallback={<div>Loading graph…</div>}>
|
|
171
|
+
<SolidFlow nodes={nodes} edges={edges} fitView>
|
|
172
|
+
<Background variant="dots" />
|
|
173
|
+
</SolidFlow>
|
|
174
|
+
</Loading>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Where the boundary goes is your design decision (SolidJS 2.0: "fetch high, block low") — one `<Loading>` can cover the flow together with its toolbar and sidebar, or sit tight around the flow alone. Without any boundary the flow renders immediately (canvas, controls, background) and the graph pops in when the data arrives — there is deliberately no `fallback` prop. See the AsyncData playground example for the full version (including connection adoption after the async seed).
|
|
180
|
+
|
|
153
181
|
## The flow API
|
|
154
182
|
|
|
155
183
|
`useSolidFlow()` returns `{ flow, commands }` (with `commands` also spread at the top level for React/Svelte Flow familiarity). Both are stable identities — destructuring is safe.
|
|
@@ -263,6 +291,7 @@ Reconnection lifecycle callbacks (`onReconnectStart`, `onReconnect`, `onReconnec
|
|
|
263
291
|
Two complementary culling tiers keep large graphs fast:
|
|
264
292
|
|
|
265
293
|
- **CSS culling (always on):** Elements outside the (overscanned) viewport are hidden with `visibility: hidden` + `pointer-events: none`. Everything stays mounted, so component state, measurement, and accessibility semantics are untouched — this tier has no userland contract at all.
|
|
294
|
+
- **Gesture-time spatial queries:** Dragging a connection runs upstream's closest-handle search on every pointer move — a full node scan in stock React/Svelte Flow. Solid Flow snapshots node geometry into a spatial grid at gesture start (geometry is frozen mid-gesture) and answers from the pointer's neighborhood: at 10,000 nodes a connection drag went from ~422ms per move (unusable) to ~5ms median. Box selection and `getIntersectingNodes` use the same machinery.
|
|
266
295
|
- **`onlyRenderVisibleElements` (opt-in):** Off-screen elements are **unmounted entirely** and remount as the viewport reaches them. At 10,000 nodes this cuts the DOM ~16x, roughly halves memory, and makes node drags several times faster. Positions, selection, and cached measurements live in the flow's data graph — outside your components — so elements come back exactly as they left. Component-_local_ state does not survive unmounting: keep state you care about in `node.data`. Selected elements, unmeasured nodes, and the node holding focus are never unmounted — and an element whose content must keep running off-screen (media, timers, embeds) can opt out of culling entirely with `cullable: false` on the node or edge.
|
|
267
296
|
|
|
268
297
|
The MiniMap always renders the full graph in either mode — it reads the data graph, not the DOM.
|
|
@@ -280,7 +309,7 @@ The MiniMap always renders the full graph in either mode — it reads the data g
|
|
|
280
309
|
|
|
281
310
|
## Migrating from 0.2.x
|
|
282
311
|
|
|
283
|
-
The
|
|
312
|
+
The 1.x line targets SolidJS 2.0, which changes how you write to stores, and reworks the read API. The gestures, components, plugins, and commands are otherwise the same.
|
|
284
313
|
|
|
285
314
|
**1. Upgrade the peer dependencies.** `solid-js` and `@solidjs/web` move to matching 2.0 versions.
|
|
286
315
|
|
|
@@ -291,7 +320,7 @@ The 0.3 line targets SolidJS 2.0, which changes how you write to stores, and rew
|
|
|
291
320
|
setNodes(0, "position", "x", (x) => x + 20);
|
|
292
321
|
setEdges((edge) => edge.id === "e1", "animated", true);
|
|
293
322
|
|
|
294
|
-
//
|
|
323
|
+
// 1.x (SolidJS 2.0) — draft callback
|
|
295
324
|
setNodes((nodes) => {
|
|
296
325
|
nodes[0]!.position.x += 20;
|
|
297
326
|
});
|
|
@@ -307,7 +336,7 @@ setNodes(() => nextNodes);
|
|
|
307
336
|
**3. `useSolidFlow` reads moved to the reactive `flow` struct.** The flat getters (`getNodes()`, `getEdges()`, `getNode(id)`, `getEdge(id)`, `getInternalNode(id)`, `getViewport()`, `getZoom()`) are removed:
|
|
308
337
|
|
|
309
338
|
```tsx
|
|
310
|
-
// 0.2.x //
|
|
339
|
+
// 0.2.x // 1.x
|
|
311
340
|
solidFlow.getNodes();
|
|
312
341
|
flow.nodes;
|
|
313
342
|
solidFlow.getViewport();
|
|
@@ -322,9 +351,9 @@ useInternalNode(() => "a");
|
|
|
322
351
|
|
|
323
352
|
`flow.*` reads are reactive — using them in JSX or a tracked scope subscribes. Commands (`fitView`, `setViewport`, `updateNode`, `deleteElements`, ...) are unchanged and now also available namespaced under `commands`.
|
|
324
353
|
|
|
325
|
-
**4. New connections are no longer written into your edge store.** In 0.2.x the flow inserted the connected edge into your store before `onConnect` fired. Under
|
|
354
|
+
**4. New connections are no longer written into your edge store.** In 0.2.x the flow inserted the connected edge into your store before `onConnect` fired. Under the 1.x ownership contract your store owns membership: adopt the connection yourself (see the Quick Start's `onConnect`). Unadopted connections still render, but won't survive a wholesale store replacement.
|
|
326
355
|
|
|
327
|
-
**5. `onlyRenderVisibleElements` now does what it says.** In 0.2.x the prop was accepted but inert. In
|
|
356
|
+
**5. `onlyRenderVisibleElements` now does what it says.** In 0.2.x the prop was accepted but inert. In 1.x it opts into unmount culling (off-screen elements are not mounted at all — see [Performance](#performance)), while the CSS culling tier is always on and needs no prop.
|
|
328
357
|
|
|
329
358
|
**6. Smaller signature changes.** `useNodes()` / `useEdges()` return `readonly` arrays; `useHandleEdgeSelect` is removed (it was internal plumbing — select edges through `commands`).
|
|
330
359
|
|
package/dist/index/index.d.ts
CHANGED
|
@@ -368,10 +368,7 @@ type ConnectionLineProps<NodeType extends Node = Node> = {
|
|
|
368
368
|
declare const ConnectionLine: <NodeType extends Node = Node>(props: ParentProps<Partial<ConnectionLineProps<NodeType>>>) => JSX.Element;
|
|
369
369
|
//#endregion
|
|
370
370
|
//#region src/components/container/EdgeRenderer.d.ts
|
|
371
|
-
type EdgeRendererProps<EdgeType extends Edge = Edge> = EdgeEvents<EdgeType
|
|
372
|
-
readonly defaultEdgeOptions?: DefaultEdgeOptions;
|
|
373
|
-
readonly reconnectRadius: number;
|
|
374
|
-
};
|
|
371
|
+
type EdgeRendererProps<EdgeType extends Edge = Edge> = EdgeEvents<EdgeType>;
|
|
375
372
|
/** Internal renderer iterating the edge id list into `EdgeWrapper`s. */
|
|
376
373
|
declare const EdgeRenderer: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(props: EdgeRendererProps<EdgeType>) => JSX.Element;
|
|
377
374
|
//#endregion
|
|
@@ -627,6 +624,22 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
|
|
|
627
624
|
* ]);
|
|
628
625
|
*/
|
|
629
626
|
readonly edges?: Store<EdgeType[]>;
|
|
627
|
+
/**
|
|
628
|
+
* Initial nodes for an UNCONTROLLED flow. When `nodes` is not supplied,
|
|
629
|
+
* the flow owns element state: this array seeds it once (later values
|
|
630
|
+
* are ignored), and membership belongs to the flow — commands like
|
|
631
|
+
* `addNodes`/`deleteElements` and completed connections write through
|
|
632
|
+
* and persist, with no adoption step. Mutually exclusive with `nodes`
|
|
633
|
+
* (which wins, with a dev warning). Mode is fixed at mount, per axis:
|
|
634
|
+
* nodes and edges can each be controlled or uncontrolled independently.
|
|
635
|
+
*/
|
|
636
|
+
readonly defaultNodes?: readonly NodeType[];
|
|
637
|
+
/**
|
|
638
|
+
* Initial edges for an UNCONTROLLED flow — the edge-axis counterpart of
|
|
639
|
+
* `defaultNodes`: seeds once, flow owns membership, completed
|
|
640
|
+
* connections are kept automatically. Mutually exclusive with `edges`.
|
|
641
|
+
*/
|
|
642
|
+
readonly defaultEdges?: readonly EdgeType[];
|
|
630
643
|
/**
|
|
631
644
|
* Custom node types to be available in a flow.
|
|
632
645
|
* Solid Flow matches a node's type to a component in the nodeTypes object.
|
|
@@ -848,6 +861,12 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
|
|
|
848
861
|
* @default false
|
|
849
862
|
*/
|
|
850
863
|
readonly panOnScroll?: boolean;
|
|
864
|
+
/**
|
|
865
|
+
* Controls how fast the viewport pans while scrolling.
|
|
866
|
+
* Only applies when `panOnScroll` is enabled.
|
|
867
|
+
* @default 0.5
|
|
868
|
+
*/
|
|
869
|
+
readonly panOnScrollSpeed?: number;
|
|
851
870
|
/**
|
|
852
871
|
* This prop is used to limit the direction of panning when panOnScroll is enabled.
|
|
853
872
|
* The "free" option allows panning in any direction.
|
|
@@ -903,6 +922,12 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
|
|
|
903
922
|
* @default true
|
|
904
923
|
*/
|
|
905
924
|
readonly autoPanOnNodeDrag?: boolean;
|
|
925
|
+
/**
|
|
926
|
+
* The speed at which the viewport auto-pans while dragging a node or a
|
|
927
|
+
* connection toward the edge of the viewport.
|
|
928
|
+
* @default 15
|
|
929
|
+
*/
|
|
930
|
+
readonly autoPanSpeed?: number;
|
|
906
931
|
/**
|
|
907
932
|
* Defaults to be applied to all new edges that are added to the flow.
|
|
908
933
|
* Properties on a new edge will override these defaults if they exist.
|
|
@@ -919,6 +944,11 @@ type SolidFlowProps<NodeType extends Node = Node, EdgeType extends Edge = Edge>
|
|
|
919
944
|
* @example 'system' | 'light' | 'dark'
|
|
920
945
|
*/
|
|
921
946
|
readonly colorMode?: ColorMode$1;
|
|
947
|
+
/**
|
|
948
|
+
* Static message announced to screen readers via the flow's aria-live
|
|
949
|
+
* region (in addition to the built-in keyboard-interaction messages).
|
|
950
|
+
*/
|
|
951
|
+
readonly ariaLiveMessage?: string;
|
|
922
952
|
/** Fallback color mode for SSR if colorMode is set to 'system' */
|
|
923
953
|
readonly colorModeSSR?: Omit<ColorMode$1, "system">;
|
|
924
954
|
/** Class to be applied to the flow container */
|
|
@@ -1070,102 +1100,6 @@ declare const SolidFlow: <NodeType extends Node = Node, EdgeType extends Edge =
|
|
|
1070
1100
|
/** Hoists flow state above `SolidFlow` so hooks work outside the component (multi-panel UIs). */
|
|
1071
1101
|
declare const SolidFlowProvider: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(props: ParentProps<SolidFlowProps<NodeType, EdgeType>>) => JSX.Element;
|
|
1072
1102
|
//#endregion
|
|
1073
|
-
//#region src/core/createEdgeStore.d.ts
|
|
1074
|
-
type EdgeDataOf<T> = T extends ((props: EdgeProps<infer TData, infer _TType>) => unknown) ? TData : UnknownStruct;
|
|
1075
|
-
type AllEdgeTypes<TUserEdgeTypes extends EdgeTypes> = TUserEdgeTypes extends Record<string, never> ? BuiltInEdgeTypes : BuiltInEdgeTypes & TUserEdgeTypes;
|
|
1076
|
-
/**
|
|
1077
|
-
* The discriminated union of edge configurations for a renderer map: one
|
|
1078
|
-
* member per built-in and custom edge type, with `data` narrowed by the
|
|
1079
|
-
* `type` discriminant (the MAP KEY — what the renderer actually matches).
|
|
1080
|
-
* Use it to carry `createEdgeStore`'s guided typing anywhere a plain array
|
|
1081
|
-
* or vanilla store is typed:
|
|
1082
|
-
*
|
|
1083
|
-
* ```typescript
|
|
1084
|
-
* const initialEdges = [
|
|
1085
|
-
* { id: "e1", source: "1", target: "2", type: "labeled", data: { label: "hi" } },
|
|
1086
|
-
* ] satisfies EdgesFor<typeof edgeTypes>[];
|
|
1087
|
-
* ```
|
|
1088
|
-
*/
|
|
1089
|
-
type EdgesFor<TUserEdgeTypes extends EdgeTypes = Record<string, never>> = { [K in keyof AllEdgeTypes<TUserEdgeTypes>]: Edge<EdgeDataOf<AllEdgeTypes<TUserEdgeTypes>[K]>, K & string>; }[keyof AllEdgeTypes<TUserEdgeTypes>];
|
|
1090
|
-
type EdgesInput<TUserEdgeTypes extends EdgeTypes> = EdgesFor<TUserEdgeTypes>;
|
|
1091
|
-
/**
|
|
1092
|
-
* Creates a type-safe reactive store of edges for use in Solid Flow.
|
|
1093
|
-
*
|
|
1094
|
-
* This utility function provides full type safety and autocomplete for creating edges,
|
|
1095
|
-
* combining both built-in edge types (default, straight, step, smoothstep) and custom user-defined
|
|
1096
|
-
* edge types. When a specific edge type is selected, TypeScript automatically infers the
|
|
1097
|
-
* required data structure and validates the edge configuration.
|
|
1098
|
-
*
|
|
1099
|
-
* @template TUserEdgeTypes - The user's custom edge types map (optional)
|
|
1100
|
-
* @param edges - Array of edge configurations to create
|
|
1101
|
-
* @returns A SolidJS store tuple [store, setStore] with properly typed Edge objects
|
|
1102
|
-
*
|
|
1103
|
-
* @example
|
|
1104
|
-
* ```typescript
|
|
1105
|
-
* // Using only built-in edge types (no generic parameter needed)
|
|
1106
|
-
* const [builtInEdges, setBuiltInEdges] = createEdgeStore([
|
|
1107
|
-
* {
|
|
1108
|
-
* id: "1",
|
|
1109
|
-
* source: "1",
|
|
1110
|
-
* target: "2",
|
|
1111
|
-
* type: "default",
|
|
1112
|
-
* data: { label: "Start" }
|
|
1113
|
-
* },
|
|
1114
|
-
* {
|
|
1115
|
-
* id: "2",
|
|
1116
|
-
* source: "2",
|
|
1117
|
-
* target: "3",
|
|
1118
|
-
* type: "default",
|
|
1119
|
-
* data: { label: "Process" }
|
|
1120
|
-
* }
|
|
1121
|
-
* ]);
|
|
1122
|
-
* ```
|
|
1123
|
-
*
|
|
1124
|
-
* @example
|
|
1125
|
-
* ```typescript
|
|
1126
|
-
* // Using custom edge types (requires generic parameter)
|
|
1127
|
-
* const customEdgeTypes = {
|
|
1128
|
-
* textEdge: (props: EdgeProps<{ content: string }, "textEdge">) =>
|
|
1129
|
-
* <div>{props.data.content}</div>,
|
|
1130
|
-
* numberEdge: (props: EdgeProps<{ value: number }, "numberEdge">) =>
|
|
1131
|
-
* <div>{props.data.value}</div>
|
|
1132
|
-
* } satisfies EdgeTypes;
|
|
1133
|
-
*
|
|
1134
|
-
* const [mixedEdges, setMixedEdges] = createEdgeStore<typeof customEdgeTypes>([
|
|
1135
|
-
* {
|
|
1136
|
-
* id: "1",
|
|
1137
|
-
* source: "1",
|
|
1138
|
-
* target: "2",
|
|
1139
|
-
* type: "default", // Built-in type
|
|
1140
|
-
* data: { label: "Input" }
|
|
1141
|
-
* },
|
|
1142
|
-
* {
|
|
1143
|
-
* id: "2",
|
|
1144
|
-
* source: "2",
|
|
1145
|
-
* target: "3",
|
|
1146
|
-
* type: "textEdge", // Custom type - gets autocomplete
|
|
1147
|
-
* data: { content: "Custom text edge" } // Type-safe data
|
|
1148
|
-
* },
|
|
1149
|
-
* {
|
|
1150
|
-
* id: "3",
|
|
1151
|
-
* source: "3",
|
|
1152
|
-
* target: "4",
|
|
1153
|
-
* type: "numberEdge", // Another custom type
|
|
1154
|
-
* data: { value: 42 }, // Type-safe data
|
|
1155
|
-
* style: { "background-color": "lightblue" } // All Edge properties available
|
|
1156
|
-
* }
|
|
1157
|
-
* ]);
|
|
1158
|
-
* ```
|
|
1159
|
-
*
|
|
1160
|
-
* @remarks
|
|
1161
|
-
* - Provides autocomplete for the `type` field with all available node types
|
|
1162
|
-
* - Validates `data` structure based on the selected node type
|
|
1163
|
-
* - Supports all Node properties (style, draggable, hidden, etc.)
|
|
1164
|
-
* - Works seamlessly with both built-in and custom node types
|
|
1165
|
-
* - Type errors prevent invalid type names or incorrect data structures
|
|
1166
|
-
*/
|
|
1167
|
-
declare const createEdgeStore: <TUserEdgeTypes extends EdgeTypes = Record<string, never>>(edges: NoInfer<EdgesInput<TUserEdgeTypes>>[]) => readonly [Store<EdgesInput<TUserEdgeTypes>[]>, StoreSetter<EdgesInput<TUserEdgeTypes>[]>];
|
|
1168
|
-
//#endregion
|
|
1169
1103
|
//#region src/core/projections/connections.d.ts
|
|
1170
1104
|
/**
|
|
1171
1105
|
* Lookup keys for the connection index. Each edge is registered under six
|
|
@@ -1319,7 +1253,109 @@ type FlowCommands<NodeType extends Node = Node, EdgeType extends Edge = Edge> =
|
|
|
1319
1253
|
};
|
|
1320
1254
|
};
|
|
1321
1255
|
//#endregion
|
|
1322
|
-
//#region src/core/
|
|
1256
|
+
//#region src/core/stores/createEdgeStore.d.ts
|
|
1257
|
+
type EdgeDataOf<T> = T extends ((props: EdgeProps<infer TData, infer _TType>) => unknown) ? TData : UnknownStruct;
|
|
1258
|
+
type AllEdgeTypes<TUserEdgeTypes extends EdgeTypes> = TUserEdgeTypes extends Record<string, never> ? BuiltInEdgeTypes : BuiltInEdgeTypes & TUserEdgeTypes;
|
|
1259
|
+
/**
|
|
1260
|
+
* The discriminated union of edge configurations for a renderer map: one
|
|
1261
|
+
* member per built-in and custom edge type, with `data` narrowed by the
|
|
1262
|
+
* `type` discriminant (the MAP KEY — what the renderer actually matches).
|
|
1263
|
+
* Use it to carry `createEdgeStore`'s guided typing anywhere a plain array
|
|
1264
|
+
* or vanilla store is typed:
|
|
1265
|
+
*
|
|
1266
|
+
* ```typescript
|
|
1267
|
+
* const initialEdges = [
|
|
1268
|
+
* { id: "e1", source: "1", target: "2", type: "labeled", data: { label: "hi" } },
|
|
1269
|
+
* ] satisfies SolidFlowEdge<typeof edgeTypes>[];
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
type SolidFlowEdge<TUserEdgeTypes extends EdgeTypes = Record<string, never>> = { [K in keyof AllEdgeTypes<TUserEdgeTypes>]: Edge<EdgeDataOf<AllEdgeTypes<TUserEdgeTypes>[K]>, K & string>; }[keyof AllEdgeTypes<TUserEdgeTypes>];
|
|
1273
|
+
type EdgesInput<TUserEdgeTypes extends EdgeTypes> = SolidFlowEdge<TUserEdgeTypes>;
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates a type-safe reactive store of edges for use in Solid Flow.
|
|
1276
|
+
*
|
|
1277
|
+
* This utility function provides full type safety and autocomplete for creating edges,
|
|
1278
|
+
* combining both built-in edge types (default, straight, step, smoothstep) and custom user-defined
|
|
1279
|
+
* edge types. When a specific edge type is selected, TypeScript automatically infers the
|
|
1280
|
+
* required data structure and validates the edge configuration.
|
|
1281
|
+
*
|
|
1282
|
+
* @template TUserEdgeTypes - The user's custom edge types map (optional)
|
|
1283
|
+
* @param edges - Array of edge configurations to create
|
|
1284
|
+
* @returns A SolidJS store tuple [store, setStore] with properly typed Edge objects
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* ```typescript
|
|
1288
|
+
* // Using only built-in edge types (no generic parameter needed)
|
|
1289
|
+
* const [builtInEdges, setBuiltInEdges] = createEdgeStore([
|
|
1290
|
+
* {
|
|
1291
|
+
* id: "1",
|
|
1292
|
+
* source: "1",
|
|
1293
|
+
* target: "2",
|
|
1294
|
+
* type: "default",
|
|
1295
|
+
* data: { label: "Start" }
|
|
1296
|
+
* },
|
|
1297
|
+
* {
|
|
1298
|
+
* id: "2",
|
|
1299
|
+
* source: "2",
|
|
1300
|
+
* target: "3",
|
|
1301
|
+
* type: "default",
|
|
1302
|
+
* data: { label: "Process" }
|
|
1303
|
+
* }
|
|
1304
|
+
* ]);
|
|
1305
|
+
* ```
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* ```typescript
|
|
1309
|
+
* // Using custom edge types (requires generic parameter)
|
|
1310
|
+
* const customEdgeTypes = {
|
|
1311
|
+
* textEdge: (props: EdgeProps<{ content: string }, "textEdge">) =>
|
|
1312
|
+
* <div>{props.data.content}</div>,
|
|
1313
|
+
* numberEdge: (props: EdgeProps<{ value: number }, "numberEdge">) =>
|
|
1314
|
+
* <div>{props.data.value}</div>
|
|
1315
|
+
* } satisfies EdgeTypes;
|
|
1316
|
+
*
|
|
1317
|
+
* const [mixedEdges, setMixedEdges] = createEdgeStore<typeof customEdgeTypes>([
|
|
1318
|
+
* {
|
|
1319
|
+
* id: "1",
|
|
1320
|
+
* source: "1",
|
|
1321
|
+
* target: "2",
|
|
1322
|
+
* type: "default", // Built-in type
|
|
1323
|
+
* data: { label: "Input" }
|
|
1324
|
+
* },
|
|
1325
|
+
* {
|
|
1326
|
+
* id: "2",
|
|
1327
|
+
* source: "2",
|
|
1328
|
+
* target: "3",
|
|
1329
|
+
* type: "textEdge", // Custom type - gets autocomplete
|
|
1330
|
+
* data: { content: "Custom text edge" } // Type-safe data
|
|
1331
|
+
* },
|
|
1332
|
+
* {
|
|
1333
|
+
* id: "3",
|
|
1334
|
+
* source: "3",
|
|
1335
|
+
* target: "4",
|
|
1336
|
+
* type: "numberEdge", // Another custom type
|
|
1337
|
+
* data: { value: 42 }, // Type-safe data
|
|
1338
|
+
* style: { "background-color": "lightblue" } // All Edge properties available
|
|
1339
|
+
* }
|
|
1340
|
+
* ]);
|
|
1341
|
+
* ```
|
|
1342
|
+
*
|
|
1343
|
+
* @remarks
|
|
1344
|
+
* - Provides autocomplete for the `type` field with all available node types
|
|
1345
|
+
* - Validates `data` structure based on the selected node type
|
|
1346
|
+
* - Supports all Node properties (style, draggable, hidden, etc.)
|
|
1347
|
+
* - Works seamlessly with both built-in and custom node types
|
|
1348
|
+
* - Type errors prevent invalid type names or incorrect data structures
|
|
1349
|
+
*/
|
|
1350
|
+
/**
|
|
1351
|
+
* Also accepts an async seed ("Fetch High"): pass `async () => edges`
|
|
1352
|
+
* instead of an array. Reads throw `NotReadyError` until the first value
|
|
1353
|
+
* (cover the flow with `<Loading fallback>`); afterwards the store is an
|
|
1354
|
+
* ordinary writable store. See {@link createNodeStore} for details.
|
|
1355
|
+
*/
|
|
1356
|
+
declare const createEdgeStore: <TUserEdgeTypes extends EdgeTypes = Record<string, never>>(edges: NoInfer<EdgesInput<TUserEdgeTypes>>[] | (() => Promise<NoInfer<EdgesInput<TUserEdgeTypes>>[]>)) => readonly [Store<EdgesInput<TUserEdgeTypes>[]>, StoreSetter<EdgesInput<TUserEdgeTypes>[]>];
|
|
1357
|
+
//#endregion
|
|
1358
|
+
//#region src/core/stores/createNodeStore.d.ts
|
|
1323
1359
|
type NodeDataOf<T> = T extends ((props: NodeProps<infer TData, infer _TType>) => unknown) ? TData : UnknownStruct;
|
|
1324
1360
|
type AllNodeTypes<TUserNodeTypes extends NodeTypes> = TUserNodeTypes extends Record<string, never> ? BuiltInNodeTypes : BuiltInNodeTypes & TUserNodeTypes;
|
|
1325
1361
|
/**
|
|
@@ -1332,11 +1368,11 @@ type AllNodeTypes<TUserNodeTypes extends NodeTypes> = TUserNodeTypes extends Rec
|
|
|
1332
1368
|
* ```typescript
|
|
1333
1369
|
* const initialNodes = [
|
|
1334
1370
|
* { id: "1", type: "custom", position: { x: 0, y: 0 }, data: { value: 1 } },
|
|
1335
|
-
* ] satisfies
|
|
1371
|
+
* ] satisfies SolidFlowNode<typeof nodeTypes>[];
|
|
1336
1372
|
* ```
|
|
1337
1373
|
*/
|
|
1338
|
-
type
|
|
1339
|
-
type NodesInput<TUserNodeTypes extends NodeTypes> =
|
|
1374
|
+
type SolidFlowNode<TUserNodeTypes extends NodeTypes = Record<string, never>> = { [K in keyof AllNodeTypes<TUserNodeTypes>]: Node<NodeDataOf<AllNodeTypes<TUserNodeTypes>[K]>, K & string>; }[keyof AllNodeTypes<TUserNodeTypes>];
|
|
1375
|
+
type NodesInput<TUserNodeTypes extends NodeTypes> = SolidFlowNode<TUserNodeTypes>;
|
|
1340
1376
|
/**
|
|
1341
1377
|
* Creates a type-safe reactive store of nodes for use in Solid Flow.
|
|
1342
1378
|
*
|
|
@@ -1408,7 +1444,16 @@ type NodesInput<TUserNodeTypes extends NodeTypes> = NodesFor<TUserNodeTypes>;
|
|
|
1408
1444
|
* - Works seamlessly with both built-in and custom node types
|
|
1409
1445
|
* - Type errors prevent invalid type names or incorrect data structures
|
|
1410
1446
|
*/
|
|
1411
|
-
|
|
1447
|
+
/**
|
|
1448
|
+
* Also accepts an async seed ("Fetch High"): pass `async () => nodes` —
|
|
1449
|
+
* typically an API call — instead of an array. No memo required: the
|
|
1450
|
+
* function goes straight to `createStore`'s projection derive, so reads
|
|
1451
|
+
* throw `NotReadyError` until the first value (cover the flow with
|
|
1452
|
+
* `<Loading fallback>`), and the graph retries them when the data lands.
|
|
1453
|
+
* Afterwards the store is an ordinary writable store — draft writes and
|
|
1454
|
+
* wholesale replacement work exactly like the array form.
|
|
1455
|
+
*/
|
|
1456
|
+
declare const createNodeStore: <TUserNodeTypes extends NodeTypes = Record<string, never>>(nodes: NoInfer<NodesInput<TUserNodeTypes>>[] | (() => Promise<NoInfer<NodesInput<TUserNodeTypes>>[]>)) => readonly [Store<NodesInput<TUserNodeTypes>[]>, StoreSetter<NodesInput<TUserNodeTypes>[]>];
|
|
1412
1457
|
//#endregion
|
|
1413
1458
|
//#region src/hooks/useColorMode.d.ts
|
|
1414
1459
|
/**
|
|
@@ -1929,4 +1974,4 @@ declare const getEdgeCenter: typeof getEdgeCenter$1;
|
|
|
1929
1974
|
/** Returns the label center and offsets for a bezier edge. */
|
|
1930
1975
|
declare const getBezierEdgeCenter: typeof getBezierEdgeCenter$1;
|
|
1931
1976
|
//#endregion
|
|
1932
|
-
export { Align, AriaLabelConfig, Background, type BackgroundProps, type BackgroundVariant, BaseEdge, BezierEdge, BezierEdgeInternal, type BezierEdgeProps, BezierPathOptions, Box, type BuiltInEdge, type BuiltInNode, type BuiltInNodeTypes, ColorMode, ColorModeClass, type Connection, ConnectionData, ConnectionLine, ConnectionLineComponentProps, ConnectionLineType, ConnectionMode, type ConnectionsRecord, ControlButton, type ControlLinePosition, type ControlPosition, Controls, type CoordinateExtent, type DefaultEdgeOptions, DefaultNode, DeleteEvents, Dimensions, type Edge, EdgeConnection, EdgeEvents, EdgeLabel, EdgeLabelRenderer, type EdgeMarker, EdgeMarkerType, type EdgeProps, EdgeReconnectAnchor, EdgeReconnectEvents, EdgeRenderer, EdgeToolbar, EdgeToolbarProps, type EdgeTypes, EdgeWrapper, type
|
|
1977
|
+
export { Align, AriaLabelConfig, Background, type BackgroundProps, type BackgroundVariant, BaseEdge, BezierEdge, BezierEdgeInternal, type BezierEdgeProps, BezierPathOptions, Box, type BuiltInEdge, type BuiltInNode, type BuiltInNodeTypes, ColorMode, ColorModeClass, type Connection, ConnectionData, ConnectionLine, ConnectionLineComponentProps, ConnectionLineType, ConnectionMode, type ConnectionsRecord, ControlButton, type ControlLinePosition, type ControlPosition, Controls, type CoordinateExtent, type DefaultEdgeOptions, DefaultNode, DeleteEvents, Dimensions, type Edge, EdgeConnection, EdgeEvents, EdgeLabel, EdgeLabelRenderer, type EdgeMarker, EdgeMarkerType, type EdgeProps, EdgeReconnectAnchor, EdgeReconnectEvents, EdgeRenderer, EdgeToolbar, EdgeToolbarProps, type EdgeTypes, EdgeWrapper, type FitBounds, FitBoundsOptions, FitViewOptions, type FlowCommands, type FlowSelection, type FlowState, GetBezierPathParams, type GetMiniMapNodeAttribute, GetSmoothStepPathParams, GetStraightPathParams, GroupNode, Handle, type HandleConnection, InputNode, type InternalNode, IsValidConnection, KeyDefinition, KeyDefinitionObject, KeyModifier, Marker, MarkerDefinition, MarkerType, MiniMap, MiniMapNode, type MiniMapNodeProps, type MiniMapProps, type Node, type NodeConnection, NodeEvents, NodeGraph, type NodeOrigin, type NodeProps, NodeRenderer, NodeResizer, NodeSelection, NodeSelectionEvents, NodeToolbar, NodeToolbarProps, type NodeTypes, NodeWrapper, OnBeforeDelete, OnBeforeEdgeConnect, OnBeforeReconnect, OnConnect, OnConnectEnd, OnConnectStart, OnConnectStartParams, OnDelete, OnEdgeConnect, OnEdgeCreate, OnError, type OnMove, OnMoveEnd, OnMoveStart, OnReconnect, OnReconnectEnd, OnReconnectStart, OnResize, OnResizeEnd, OnResizeStart, OnSelectionChange, OnSelectionDrag, OutputNode, PanOnScrollMode, Pane, PaneEvents, Panel, type PanelPosition, Position, ProOptions, Rect, ResizeControl, ResizeControlVariant, ResizeDragEvent, ResizeParams, ResizeParamsWithDirection, Selection, SelectionMode, SelectionRect, type SetCenter, SetCenterOptions, type SetViewport, ShortcutModifier, ShortcutModifierDefinition, type ShouldResize, SmoothStepEdge, SmoothStepEdgeInternal, type SmoothStepEdgeProps, SmoothStepPathOptions, SnapGrid, SolidFlow, type SolidFlowEdge, type SolidFlowInitialProps, type SolidFlowNode, type SolidFlowProps, SolidFlowProvider, StepEdge, StepEdgeInternal, type StepEdgeProps, StraightEdge, StraightEdgeInternal, type StraightEdgeProps, Transform, UseSolidFlowReturn, Viewport, ViewportHelperFunctionOptions, ViewportPortal, type XYPosition, XYZPosition, Zoom, addEdge, connectionKey, createEdgeStore, createNodeStore, getBezierEdgeCenter, getBezierPath, getConnectedEdges, getEdgeCenter, getIncomers, getNodesBounds, getOutgoers, getSmoothStepPath, getStraightPath, getViewportForBounds, useColorMode, useConnection, useEdgeId, useEdges, useInternalNode, useNodeConnections, useNodeId, useNodes, useNodesData, useNodesInitialized, useSolidFlow, useUpdateNodeInternals, useViewport, useViewportInitialized };
|