@liveblocks/react-flow 0.0.0 → 3.16.0-flow2
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 +57 -0
- package/dist/constants.cjs +33 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.js +29 -0
- package/dist/constants.js.map +1 -0
- package/dist/cursors.cjs +157 -0
- package/dist/cursors.cjs.map +1 -0
- package/dist/cursors.js +155 -0
- package/dist/cursors.js.map +1 -0
- package/dist/flow.cjs +269 -0
- package/dist/flow.cjs.map +1 -0
- package/dist/flow.js +267 -0
- package/dist/flow.js.map +1 -0
- package/dist/helpers.cjs +35 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.js +30 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +217 -0
- package/dist/index.d.ts +217 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/version.cjs +10 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +104 -2
- package/src/styles/index.css +12 -0
- package/styles.css +1 -0
- package/styles.css.d.cts +1 -0
- package/styles.css.d.ts +1 -0
- package/styles.css.map +1 -0
- package/index.js +0 -1
package/dist/flow.cjs
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@liveblocks/core');
|
|
4
|
+
var react = require('@liveblocks/react');
|
|
5
|
+
var _private = require('@liveblocks/react/_private');
|
|
6
|
+
var react$2 = require('@xyflow/react');
|
|
7
|
+
var react$1 = require('react');
|
|
8
|
+
var constants = require('./constants.cjs');
|
|
9
|
+
var helpers = require('./helpers.cjs');
|
|
10
|
+
|
|
11
|
+
const EMPTY_ARRAY = [];
|
|
12
|
+
function mergeAndBuildDataConfigCache(base, data) {
|
|
13
|
+
if (!data)
|
|
14
|
+
return () => base;
|
|
15
|
+
const dataFallback = data["*"];
|
|
16
|
+
const fallback = dataFallback ? { ...base, data: dataFallback } : base;
|
|
17
|
+
const cache = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const type in data) {
|
|
19
|
+
if (type === "*")
|
|
20
|
+
continue;
|
|
21
|
+
const specific = data[type];
|
|
22
|
+
if (!specific)
|
|
23
|
+
continue;
|
|
24
|
+
const dataConfig = { ...dataFallback, ...specific };
|
|
25
|
+
cache.set(type, { ...base, data: dataConfig });
|
|
26
|
+
}
|
|
27
|
+
return (type) => cache.get(type) || fallback;
|
|
28
|
+
}
|
|
29
|
+
function buildNodeConfigCache(nodeDataConfig) {
|
|
30
|
+
return mergeAndBuildDataConfigCache(constants.NODE_BASE_CONFIG, nodeDataConfig);
|
|
31
|
+
}
|
|
32
|
+
function buildEdgeConfigCache(edgeDataConfig) {
|
|
33
|
+
return mergeAndBuildDataConfigCache(constants.EDGE_BASE_CONFIG, edgeDataConfig);
|
|
34
|
+
}
|
|
35
|
+
function applyNodeChanges(changes, nodes, history, getNodeSyncConfig) {
|
|
36
|
+
for (const change of changes) {
|
|
37
|
+
switch (change.type) {
|
|
38
|
+
case "add":
|
|
39
|
+
case "replace": {
|
|
40
|
+
const config = getNodeSyncConfig(change.item.type);
|
|
41
|
+
const existing = nodes.get(change.item.id);
|
|
42
|
+
if (existing) {
|
|
43
|
+
existing.reconcile(change.item, config);
|
|
44
|
+
} else {
|
|
45
|
+
nodes.set(
|
|
46
|
+
change.item.id,
|
|
47
|
+
helpers.toLiveblocksInternalNode(change.item, config)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "position": {
|
|
53
|
+
const node = nodes.get(change.id);
|
|
54
|
+
if (!node || !change.position)
|
|
55
|
+
break;
|
|
56
|
+
if (change.position !== void 0) {
|
|
57
|
+
node.set("position", change.position);
|
|
58
|
+
}
|
|
59
|
+
if (change.dragging !== void 0) {
|
|
60
|
+
if (change.dragging) {
|
|
61
|
+
history.pause();
|
|
62
|
+
} else {
|
|
63
|
+
history.resume();
|
|
64
|
+
}
|
|
65
|
+
node.setLocal("dragging", change.dragging);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "dimensions": {
|
|
70
|
+
const node = nodes.get(change.id);
|
|
71
|
+
if (!node)
|
|
72
|
+
break;
|
|
73
|
+
if (change.dimensions !== void 0 && change.setAttributes !== void 0) {
|
|
74
|
+
if (change.setAttributes === true || change.setAttributes === "width") {
|
|
75
|
+
node.set("width", change.dimensions.width);
|
|
76
|
+
}
|
|
77
|
+
if (change.setAttributes === true || change.setAttributes === "height") {
|
|
78
|
+
node.set("height", change.dimensions.height);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (change.dimensions !== void 0) {
|
|
82
|
+
node.setLocal("measured", change.dimensions);
|
|
83
|
+
}
|
|
84
|
+
if (change.resizing !== void 0) {
|
|
85
|
+
if (change.resizing) {
|
|
86
|
+
history.pause();
|
|
87
|
+
} else {
|
|
88
|
+
history.resume();
|
|
89
|
+
}
|
|
90
|
+
node.setLocal("resizing", change.resizing);
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "select": {
|
|
95
|
+
const node = nodes.get(change.id);
|
|
96
|
+
if (!node)
|
|
97
|
+
break;
|
|
98
|
+
node.setLocal("selected", change.selected);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case "remove":
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function applyEdgeChanges(changes, edges, getEdgeSyncConfig) {
|
|
107
|
+
for (const change of changes) {
|
|
108
|
+
switch (change.type) {
|
|
109
|
+
case "add": {
|
|
110
|
+
const config = getEdgeSyncConfig(change.item.type);
|
|
111
|
+
edges.set(
|
|
112
|
+
change.item.id,
|
|
113
|
+
helpers.toLiveblocksInternalEdge(change.item, config)
|
|
114
|
+
);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case "replace": {
|
|
118
|
+
const config = getEdgeSyncConfig(change.item.type);
|
|
119
|
+
const existing = edges.get(change.item.id);
|
|
120
|
+
if (existing) {
|
|
121
|
+
existing.reconcile(change.item, config);
|
|
122
|
+
} else {
|
|
123
|
+
edges.set(
|
|
124
|
+
change.item.id,
|
|
125
|
+
helpers.toLiveblocksInternalEdge(change.item, config)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "select":
|
|
131
|
+
{
|
|
132
|
+
const edge = edges.get(change.id);
|
|
133
|
+
if (!edge)
|
|
134
|
+
break;
|
|
135
|
+
edge.setLocal("selected", change.selected);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case "remove":
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function useLiveblocksFlow(options = {}) {
|
|
144
|
+
const history = react.useHistory();
|
|
145
|
+
const isStorageLoaded = react.useStorage(() => true) ?? false;
|
|
146
|
+
const frozenOptions = _private.useInitial({
|
|
147
|
+
nodes: options.nodes,
|
|
148
|
+
edges: options.edges,
|
|
149
|
+
storageKey: options.storageKey ?? constants.DEFAULT_STORAGE_KEY,
|
|
150
|
+
suspense: options.suspense ?? false
|
|
151
|
+
});
|
|
152
|
+
const [getNodeSyncConfig, getEdgeSyncConfig] = react$1.useMemo(
|
|
153
|
+
() => [
|
|
154
|
+
buildNodeConfigCache(frozenOptions.nodes?.sync),
|
|
155
|
+
buildEdgeConfigCache(frozenOptions.edges?.sync)
|
|
156
|
+
],
|
|
157
|
+
[frozenOptions]
|
|
158
|
+
);
|
|
159
|
+
const nodes = react.useStorage((storage) => {
|
|
160
|
+
const flow = storage[frozenOptions.storageKey];
|
|
161
|
+
return flow?.nodes ? [...flow.nodes.values()] : null;
|
|
162
|
+
});
|
|
163
|
+
const edges = react.useStorage((storage) => {
|
|
164
|
+
const flow = storage[frozenOptions.storageKey];
|
|
165
|
+
return flow?.edges ? [...flow.edges.values()] : null;
|
|
166
|
+
});
|
|
167
|
+
const onNodesChange = react.useMutation(
|
|
168
|
+
({ storage }, changes) => {
|
|
169
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
170
|
+
if (!flow) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
applyNodeChanges(changes, flow.get("nodes"), history, getNodeSyncConfig);
|
|
174
|
+
},
|
|
175
|
+
[history, frozenOptions, getNodeSyncConfig]
|
|
176
|
+
);
|
|
177
|
+
const onEdgesChange = react.useMutation(
|
|
178
|
+
({ storage }, changes) => {
|
|
179
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
180
|
+
if (!flow) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
applyEdgeChanges(changes, flow.get("edges"), getEdgeSyncConfig);
|
|
184
|
+
},
|
|
185
|
+
[frozenOptions, getEdgeSyncConfig]
|
|
186
|
+
);
|
|
187
|
+
const onConnect = react.useMutation(
|
|
188
|
+
({ storage }, connection) => {
|
|
189
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
190
|
+
if (!flow) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const [newEdge] = react$2.addEdge(connection, []);
|
|
194
|
+
if (!newEdge) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const edges2 = flow.get("edges");
|
|
198
|
+
const config = getEdgeSyncConfig(newEdge.type);
|
|
199
|
+
edges2.set(newEdge.id, helpers.toLiveblocksInternalEdge(newEdge, config));
|
|
200
|
+
},
|
|
201
|
+
[frozenOptions.storageKey, getEdgeSyncConfig]
|
|
202
|
+
);
|
|
203
|
+
const onDelete = react.useMutation(
|
|
204
|
+
({ storage }, params) => {
|
|
205
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
206
|
+
if (!flow) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const nodesMap = flow.get("nodes");
|
|
210
|
+
const edgesMap = flow.get("edges");
|
|
211
|
+
for (const edge of params.edges) {
|
|
212
|
+
edgesMap.delete(edge.id);
|
|
213
|
+
}
|
|
214
|
+
for (const node of params.nodes) {
|
|
215
|
+
nodesMap.delete(node.id);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
[frozenOptions.storageKey]
|
|
219
|
+
);
|
|
220
|
+
const setInitialStorage = react.useMutation(
|
|
221
|
+
({ storage }) => {
|
|
222
|
+
if (storage.get(frozenOptions.storageKey) !== void 0) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const initialNodes = frozenOptions.nodes?.initial ?? [];
|
|
226
|
+
const initialEdges = frozenOptions.edges?.initial ?? [];
|
|
227
|
+
storage.set(
|
|
228
|
+
frozenOptions.storageKey,
|
|
229
|
+
new core.LiveObject({
|
|
230
|
+
nodes: new core.LiveMap(
|
|
231
|
+
initialNodes.map((node) => [
|
|
232
|
+
node.id,
|
|
233
|
+
helpers.toLiveblocksInternalNode(node, getNodeSyncConfig(node.type))
|
|
234
|
+
])
|
|
235
|
+
),
|
|
236
|
+
edges: new core.LiveMap(
|
|
237
|
+
initialEdges.map((edge) => [
|
|
238
|
+
edge.id,
|
|
239
|
+
helpers.toLiveblocksInternalEdge(edge, getEdgeSyncConfig(edge.type))
|
|
240
|
+
])
|
|
241
|
+
)
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
[frozenOptions, getNodeSyncConfig, getEdgeSyncConfig]
|
|
246
|
+
);
|
|
247
|
+
react$1.useEffect(() => {
|
|
248
|
+
if (isStorageLoaded) {
|
|
249
|
+
history[core.kInternal].withoutHistory(() => {
|
|
250
|
+
setInitialStorage();
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}, [isStorageLoaded, setInitialStorage, history]);
|
|
254
|
+
if (frozenOptions.suspense) {
|
|
255
|
+
_private.useSuspendUntilStorageReady();
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
nodes: frozenOptions.suspense ? nodes ?? EMPTY_ARRAY : nodes,
|
|
259
|
+
edges: frozenOptions.suspense ? edges ?? EMPTY_ARRAY : edges,
|
|
260
|
+
isLoading: frozenOptions.suspense ? false : !isStorageLoaded,
|
|
261
|
+
onNodesChange,
|
|
262
|
+
onEdgesChange,
|
|
263
|
+
onConnect,
|
|
264
|
+
onDelete
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
exports.useLiveblocksFlow = useLiveblocksFlow;
|
|
269
|
+
//# sourceMappingURL=flow.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.cjs","sources":["../src/flow.ts"],"sourcesContent":["import type {\n History,\n JsonObject,\n Resolve,\n ToImmutable,\n} from \"@liveblocks/core\";\nimport { kInternal, LiveMap, LiveObject } from \"@liveblocks/core\";\nimport { useHistory, useMutation, useStorage } from \"@liveblocks/react\";\nimport {\n useInitial,\n useSuspendUntilStorageReady,\n} from \"@liveblocks/react/_private\";\nimport type {\n BuiltInEdge,\n BuiltInNode,\n Connection,\n Edge,\n EdgeChange,\n Node,\n NodeChange,\n OnConnect,\n OnDelete,\n OnEdgesChange,\n OnNodesChange,\n} from \"@xyflow/react\";\nimport { addEdge as defaultAddEdge } from \"@xyflow/react\";\nimport { useEffect, useMemo } from \"react\";\n\nimport {\n DEFAULT_STORAGE_KEY,\n EDGE_BASE_CONFIG,\n NODE_BASE_CONFIG,\n} from \"./constants\";\nimport { toLiveblocksInternalEdge, toLiveblocksInternalNode } from \"./helpers\";\nimport type {\n EdgeSyncConfig,\n InternalLiveblocksEdge,\n InternalLiveblocksFlow,\n InternalLiveblocksNode,\n NodeSyncConfig,\n SyncConfig,\n} from \"./types\";\n\nconst EMPTY_ARRAY = [] as unknown[];\n\ntype UseLiveblocksFlowResult<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n> = Resolve<\n (\n | {\n nodes: null;\n edges: null;\n isLoading: true;\n }\n | {\n nodes: N[];\n edges: E[];\n isLoading: false;\n }\n ) & {\n onNodesChange: OnNodesChange<N>;\n onEdgesChange: OnEdgesChange<E>;\n onConnect: OnConnect;\n onDelete: OnDelete<N, E>;\n }\n>;\n\ntype LiveblocksFlowSuspenseResult<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n> = Extract<UseLiveblocksFlowResult<N, E>, { isLoading: false }>;\n\nfunction mergeAndBuildDataConfigCache(\n base: SyncConfig,\n data?: Record<string, SyncConfig | undefined>\n): (type: string | undefined) => SyncConfig {\n if (!data) return () => base;\n\n const dataFallback = data[\"*\"];\n const fallback = dataFallback ? { ...base, data: dataFallback } : base;\n\n // Pre-compute full node/edge sync configs for all explicitly declared types\n const cache = new Map<string | undefined, SyncConfig>();\n for (const type in data) {\n if (type === \"*\") continue;\n const specific = data[type];\n if (!specific) continue;\n const dataConfig: SyncConfig = { ...dataFallback, ...specific };\n cache.set(type, { ...base, data: dataConfig });\n }\n\n return (type) => cache.get(type) || fallback;\n}\n\nfunction buildNodeConfigCache<N extends Node>(\n /** The user-provided node data sync configuration, if any. */\n nodeDataConfig?: NodeSyncConfig<N>\n): (type: string | undefined) => SyncConfig {\n return mergeAndBuildDataConfigCache(NODE_BASE_CONFIG, nodeDataConfig);\n}\n\nfunction buildEdgeConfigCache<E extends Edge>(\n /** The user-provided edge data sync configuration, if any. */\n edgeDataConfig?: EdgeSyncConfig<E>\n): (type: string | undefined) => SyncConfig {\n return mergeAndBuildDataConfigCache(EDGE_BASE_CONFIG, edgeDataConfig);\n}\n\ntype UseLiveblocksFlowOptions<N extends Node, E extends Edge> = {\n nodes?: {\n /**\n * The initial React Flow nodes.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * nodes: {\n * initial: [\n * { id: \"1\", position: { x: 0, y: 0 }, data: { label: \"Node 1\" } },\n * { id: \"2\", position: { x: 0, y: 100 }, data: { label: \"Node 2\" } },\n * ],\n * },\n * });\n * ```\n */\n initial?: N[];\n /**\n * Per-type sync configuration for node data keys.\n *\n * Use `\"*\"` as a fallback for all node types. Type-specific entries are\n * deep-merged on top of `\"*\"`, with explicitly named keys taking\n * precedence.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * nodes: {\n * sync: {\n * // Fallback for all node types\n * \"*\": { label: false },\n *\n * // Override for \"custom\" nodes\n * \"custom\": { color: false },\n * },\n * },\n * });\n * ```\n */\n // XXX Improve the example + match public documentation\n sync?: NodeSyncConfig<N>;\n };\n\n edges?: {\n initial?: E[];\n /**\n * Per-type sync configuration for edge data keys.\n *\n * Use `\"*\"` as a fallback for all edge types. Type-specific entries are\n * deep-merged on top of `\"*\"`, with explicitly named keys taking\n * precedence.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * edges: {\n * sync: {\n * // Fallback for all node types\n * \"*\": { floating: false },\n * },\n * },\n * });\n * ```\n */\n // XXX Improve the example + match public documentation\n sync?: EdgeSyncConfig<E>;\n };\n\n /**\n * The key used to store the React Flow diagram in Liveblocks Storage.\n * Defaults to `\"flow\"`.\n */\n storageKey?: string;\n\n /**\n * When true, suspends until Storage is ready (use a React `Suspense`\n * boundary). Then `nodes` and `edges` are always arrays and `isLoading` is\n * always false.\n */\n suspense?: boolean;\n};\n\n// Similar to React Flow's `applyNodeChanges()`, but writes local-only\n// properties via `setLocal()` / `delete()` on the LiveObject directly.\n// https://reactflow.dev/api-reference/utils/apply-node-changes\nfunction applyNodeChanges<N extends Node>(\n changes: NodeChange<N>[],\n nodes: LiveMap<string, InternalLiveblocksNode>,\n history: History,\n getNodeSyncConfig: (nodeType: string | undefined) => SyncConfig\n): void {\n for (const change of changes) {\n switch (change.type) {\n case \"add\":\n case \"replace\": {\n const config = getNodeSyncConfig(change.item.type);\n const existing = nodes.get(change.item.id);\n if (existing) {\n existing.reconcile(change.item as unknown as JsonObject, config);\n } else {\n nodes.set(\n change.item.id,\n toLiveblocksInternalNode(change.item, config)\n );\n }\n break;\n }\n\n case \"position\": {\n const node = nodes.get(change.id);\n if (!node || !change.position) break;\n\n if (change.position !== undefined) {\n node.set(\"position\", change.position);\n }\n\n if (change.dragging !== undefined) {\n if (change.dragging) {\n history.pause();\n } else {\n history.resume();\n }\n node.setLocal(\"dragging\", change.dragging);\n }\n break;\n }\n\n case \"dimensions\": {\n const node = nodes.get(change.id);\n if (!node) break;\n\n if (\n change.dimensions !== undefined &&\n change.setAttributes !== undefined\n ) {\n if (\n change.setAttributes === true ||\n change.setAttributes === \"width\"\n ) {\n node.set(\"width\", change.dimensions.width);\n }\n\n if (\n change.setAttributes === true ||\n change.setAttributes === \"height\"\n ) {\n node.set(\"height\", change.dimensions.height);\n }\n }\n\n if (change.dimensions !== undefined) {\n node.setLocal(\"measured\", change.dimensions);\n }\n\n if (change.resizing !== undefined) {\n if (change.resizing) {\n history.pause();\n } else {\n history.resume();\n }\n node.setLocal(\"resizing\", change.resizing);\n }\n\n break;\n }\n\n case \"select\": {\n const node = nodes.get(change.id);\n if (!node) break;\n\n node.setLocal(\"selected\", change.selected);\n break;\n }\n\n case \"remove\":\n // Removals are handled by onDelete for atomic undo\n break;\n }\n }\n}\n\n// Similar to React Flow's `applyEdgeChanges()`, but writes local-only\n// properties via `setLocal()` / `delete()` on the LiveObject directly.\n// https://reactflow.dev/api-reference/utils/apply-edge-changes\nfunction applyEdgeChanges<E extends Edge>(\n changes: EdgeChange<E>[],\n edges: LiveMap<string, InternalLiveblocksEdge>,\n getEdgeSyncConfig: (type: string | undefined) => SyncConfig\n): void {\n for (const change of changes) {\n switch (change.type) {\n case \"add\": {\n const config = getEdgeSyncConfig(change.item.type);\n edges.set(\n change.item.id,\n toLiveblocksInternalEdge(change.item, config)\n );\n break;\n }\n\n case \"replace\": {\n const config = getEdgeSyncConfig(change.item.type);\n const existing = edges.get(change.item.id);\n if (existing) {\n existing.reconcile(change.item as unknown as JsonObject, config);\n } else {\n edges.set(\n change.item.id,\n toLiveblocksInternalEdge(change.item, config)\n );\n }\n break;\n }\n\n case \"select\":\n {\n const edge = edges.get(change.id);\n if (!edge) break;\n edge.setLocal(\"selected\", change.selected);\n }\n break;\n\n case \"remove\":\n // Removals are handled by onDelete for atomic undo\n break;\n }\n }\n}\n\n/**\n * Returns a controlled React Flow state backed by Liveblocks Storage.\n *\n * @example\n * ```tsx\n * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete, isLoading } = useLiveblocksFlow();\n *\n * if (isLoading) {\n * return <div>Loading…</div>\n * }\n *\n * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;\n * ```\n * Pass `{ suspense: true }` to suspend until Storage is ready, `nodes` and `edges` will never be `null`.\n *\n * @example\n * ```tsx\n * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete } =\n * useLiveblocksFlow({ suspense: true });\n *\n * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;\n * ```\n */\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options?: UseLiveblocksFlowOptions<N, E> & { suspense?: false }\n): Resolve<UseLiveblocksFlowResult<N, E>>;\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options: UseLiveblocksFlowOptions<N, E> & { suspense: true }\n): Resolve<LiveblocksFlowSuspenseResult<N, E>>;\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options: UseLiveblocksFlowOptions<N, E> = {}\n): Resolve<UseLiveblocksFlowResult<N, E> | LiveblocksFlowSuspenseResult<N, E>> {\n const history = useHistory();\n const isStorageLoaded = useStorage(() => true) ?? false;\n\n // These options are not reactive, only their initial values are used.\n const frozenOptions = useInitial({\n nodes: options.nodes,\n edges: options.edges,\n storageKey: options.storageKey ?? DEFAULT_STORAGE_KEY,\n suspense: options.suspense ?? false,\n });\n\n // Pre-compute sync config caches once (not on every render)\n const [getNodeSyncConfig, getEdgeSyncConfig] = useMemo(\n () =>\n [\n buildNodeConfigCache(frozenOptions.nodes?.sync),\n buildEdgeConfigCache(frozenOptions.edges?.sync),\n ] as const,\n [frozenOptions]\n );\n\n // Storage already includes local overlays via toImmutable(), so no\n // separate local layer is needed. Individual node/edge immutable references\n // are already stable (only change when the underlying LiveObject changes).\n const nodes = useStorage((storage) => {\n const flow = storage[frozenOptions.storageKey] as\n | ToImmutable<InternalLiveblocksFlow>\n | undefined;\n return flow?.nodes ? ([...flow.nodes.values()] as unknown as N[]) : null;\n });\n const edges = useStorage((storage) => {\n const flow = storage[frozenOptions.storageKey] as\n | ToImmutable<InternalLiveblocksFlow>\n | undefined;\n return flow?.edges ? ([...flow.edges.values()] as unknown as E[]) : null;\n });\n\n const onNodesChange = useMutation(\n ({ storage }, changes: NodeChange<N>[]) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n applyNodeChanges(changes, flow.get(\"nodes\"), history, getNodeSyncConfig);\n },\n [history, frozenOptions, getNodeSyncConfig]\n );\n\n const onEdgesChange = useMutation(\n ({ storage }, changes: EdgeChange<E>[]) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n applyEdgeChanges(changes, flow.get(\"edges\"), getEdgeSyncConfig);\n },\n [frozenOptions, getEdgeSyncConfig]\n );\n\n const onConnect = useMutation(\n ({ storage }, connection: Connection) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n // Delegate to React Flow's own `addEdge` helper for consistent default\n // edge ID generation, passing an empty array since de-duplication is\n // already handled above.\n const [newEdge] = defaultAddEdge(connection, [] as E[]);\n if (!newEdge) {\n return;\n }\n\n const edges = flow.get(\"edges\");\n const config = getEdgeSyncConfig(newEdge.type);\n edges.set(newEdge.id, toLiveblocksInternalEdge(newEdge, config));\n },\n [frozenOptions.storageKey, getEdgeSyncConfig]\n );\n\n const onDelete = useMutation(\n ({ storage }, params: { nodes: N[]; edges: E[] }) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n const nodesMap = flow.get(\"nodes\");\n const edgesMap = flow.get(\"edges\");\n\n for (const edge of params.edges) {\n edgesMap.delete(edge.id);\n }\n\n for (const node of params.nodes) {\n nodesMap.delete(node.id);\n }\n },\n [frozenOptions.storageKey]\n );\n\n const setInitialStorage = useMutation(\n ({ storage }) => {\n // Similarly to `initialStorage` on `Client.enterRoom` and `RoomProvider`, we only\n // initialize Storage if it doesn't already exist.\n if (storage.get(frozenOptions.storageKey) !== undefined) {\n return;\n }\n\n const initialNodes = frozenOptions.nodes?.initial ?? [];\n const initialEdges = frozenOptions.edges?.initial ?? [];\n\n storage.set(\n frozenOptions.storageKey,\n new LiveObject({\n nodes: new LiveMap(\n initialNodes.map((node) => [\n node.id,\n toLiveblocksInternalNode(node, getNodeSyncConfig(node.type)),\n ])\n ),\n edges: new LiveMap(\n initialEdges.map((edge) => [\n edge.id,\n toLiveblocksInternalEdge(edge, getEdgeSyncConfig(edge.type)),\n ])\n ),\n })\n );\n },\n [frozenOptions, getNodeSyncConfig, getEdgeSyncConfig]\n );\n\n useEffect(() => {\n if (isStorageLoaded) {\n history[kInternal].withoutHistory(() => {\n setInitialStorage();\n });\n }\n }, [isStorageLoaded, setInitialStorage, history]);\n\n if (frozenOptions.suspense) {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- `suspense` is frozen so this branch is stable\n useSuspendUntilStorageReady();\n }\n\n return {\n nodes: frozenOptions.suspense ? (nodes ?? (EMPTY_ARRAY as N[])) : nodes,\n edges: frozenOptions.suspense ? (edges ?? (EMPTY_ARRAY as E[])) : edges,\n isLoading: frozenOptions.suspense ? false : !isStorageLoaded,\n onNodesChange,\n onEdgesChange,\n onConnect,\n onDelete,\n } as UseLiveblocksFlowResult<N, E> | LiveblocksFlowSuspenseResult<N, E>;\n}\n"],"names":["NODE_BASE_CONFIG","EDGE_BASE_CONFIG","toLiveblocksInternalNode","toLiveblocksInternalEdge","useHistory","useStorage","useInitial","DEFAULT_STORAGE_KEY","useMemo","useMutation","defaultAddEdge","edges","LiveObject","LiveMap","useEffect","kInternal","useSuspendUntilStorageReady"],"mappings":";;;;;;;;;;AA2CA,MAAM,cAAc,EAAC,CAAA;AA8BrB,SAAS,4BAAA,CACP,MACA,IAC0C,EAAA;AAC1C,EAAA,IAAI,CAAC,IAAA;AAAM,IAAA,OAAO,MAAM,IAAA,CAAA;AAExB,EAAM,MAAA,YAAA,GAAe,KAAK,GAAG,CAAA,CAAA;AAC7B,EAAA,MAAM,WAAW,YAAe,GAAA,EAAE,GAAG,IAAM,EAAA,IAAA,EAAM,cAAiB,GAAA,IAAA,CAAA;AAGlE,EAAM,MAAA,KAAA,uBAAY,GAAoC,EAAA,CAAA;AACtD,EAAA,KAAA,MAAW,QAAQ,IAAM,EAAA;AACvB,IAAA,IAAI,IAAS,KAAA,GAAA;AAAK,MAAA,SAAA;AAClB,IAAM,MAAA,QAAA,GAAW,KAAK,IAAI,CAAA,CAAA;AAC1B,IAAA,IAAI,CAAC,QAAA;AAAU,MAAA,SAAA;AACf,IAAA,MAAM,UAAyB,GAAA,EAAE,GAAG,YAAA,EAAc,GAAG,QAAS,EAAA,CAAA;AAC9D,IAAA,KAAA,CAAM,IAAI,IAAM,EAAA,EAAE,GAAG,IAAM,EAAA,IAAA,EAAM,YAAY,CAAA,CAAA;AAAA,GAC/C;AAEA,EAAA,OAAO,CAAC,IAAA,KAAS,KAAM,CAAA,GAAA,CAAI,IAAI,CAAK,IAAA,QAAA,CAAA;AACtC,CAAA;AAEA,SAAS,qBAEP,cAC0C,EAAA;AAC1C,EAAO,OAAA,4BAAA,CAA6BA,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,CAAC,CAAA;AAAA,aAC5D,CAAA;AAAA,WACH;AAAA,SACD,CAAA;AAAA,OACH,CAAA;AAAA,KACF;AAAA,IACA,CAAC,aAAe,EAAA,iBAAA,EAAmB,iBAAiB,CAAA;AAAA,GACtD,CAAA;AAEA,EAAAW,iBAAA,CAAU,MAAM;AACd,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAQ,OAAA,CAAAC,cAAS,CAAE,CAAA,cAAA,CAAe,MAAM;AACtC,QAAkB,iBAAA,EAAA,CAAA;AAAA,OACnB,CAAA,CAAA;AAAA,KACH;AAAA,GACC,EAAA,CAAC,eAAiB,EAAA,iBAAA,EAAmB,OAAO,CAAC,CAAA,CAAA;AAEhD,EAAA,IAAI,cAAc,QAAU,EAAA;AAE1B,IAA4BC,oCAAA,EAAA,CAAA;AAAA,GAC9B;AAEA,EAAO,OAAA;AAAA,IACL,KAAO,EAAA,aAAA,CAAc,QAAY,GAAA,KAAA,IAAU,WAAuB,GAAA,KAAA;AAAA,IAClE,KAAO,EAAA,aAAA,CAAc,QAAY,GAAA,KAAA,IAAU,WAAuB,GAAA,KAAA;AAAA,IAClE,SAAW,EAAA,aAAA,CAAc,QAAW,GAAA,KAAA,GAAQ,CAAC,eAAA;AAAA,IAC7C,aAAA;AAAA,IACA,aAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
package/dist/flow.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { LiveObject, LiveMap, kInternal } from '@liveblocks/core';
|
|
2
|
+
import { useHistory, useStorage, useMutation } from '@liveblocks/react';
|
|
3
|
+
import { useInitial, useSuspendUntilStorageReady } from '@liveblocks/react/_private';
|
|
4
|
+
import { addEdge } from '@xyflow/react';
|
|
5
|
+
import { useMemo, useEffect } from 'react';
|
|
6
|
+
import { NODE_BASE_CONFIG, EDGE_BASE_CONFIG, DEFAULT_STORAGE_KEY } from './constants.js';
|
|
7
|
+
import { toLiveblocksInternalNode, toLiveblocksInternalEdge } from './helpers.js';
|
|
8
|
+
|
|
9
|
+
const EMPTY_ARRAY = [];
|
|
10
|
+
function mergeAndBuildDataConfigCache(base, data) {
|
|
11
|
+
if (!data)
|
|
12
|
+
return () => base;
|
|
13
|
+
const dataFallback = data["*"];
|
|
14
|
+
const fallback = dataFallback ? { ...base, data: dataFallback } : base;
|
|
15
|
+
const cache = /* @__PURE__ */ new Map();
|
|
16
|
+
for (const type in data) {
|
|
17
|
+
if (type === "*")
|
|
18
|
+
continue;
|
|
19
|
+
const specific = data[type];
|
|
20
|
+
if (!specific)
|
|
21
|
+
continue;
|
|
22
|
+
const dataConfig = { ...dataFallback, ...specific };
|
|
23
|
+
cache.set(type, { ...base, data: dataConfig });
|
|
24
|
+
}
|
|
25
|
+
return (type) => cache.get(type) || fallback;
|
|
26
|
+
}
|
|
27
|
+
function buildNodeConfigCache(nodeDataConfig) {
|
|
28
|
+
return mergeAndBuildDataConfigCache(NODE_BASE_CONFIG, nodeDataConfig);
|
|
29
|
+
}
|
|
30
|
+
function buildEdgeConfigCache(edgeDataConfig) {
|
|
31
|
+
return mergeAndBuildDataConfigCache(EDGE_BASE_CONFIG, edgeDataConfig);
|
|
32
|
+
}
|
|
33
|
+
function applyNodeChanges(changes, nodes, history, getNodeSyncConfig) {
|
|
34
|
+
for (const change of changes) {
|
|
35
|
+
switch (change.type) {
|
|
36
|
+
case "add":
|
|
37
|
+
case "replace": {
|
|
38
|
+
const config = getNodeSyncConfig(change.item.type);
|
|
39
|
+
const existing = nodes.get(change.item.id);
|
|
40
|
+
if (existing) {
|
|
41
|
+
existing.reconcile(change.item, config);
|
|
42
|
+
} else {
|
|
43
|
+
nodes.set(
|
|
44
|
+
change.item.id,
|
|
45
|
+
toLiveblocksInternalNode(change.item, config)
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case "position": {
|
|
51
|
+
const node = nodes.get(change.id);
|
|
52
|
+
if (!node || !change.position)
|
|
53
|
+
break;
|
|
54
|
+
if (change.position !== void 0) {
|
|
55
|
+
node.set("position", change.position);
|
|
56
|
+
}
|
|
57
|
+
if (change.dragging !== void 0) {
|
|
58
|
+
if (change.dragging) {
|
|
59
|
+
history.pause();
|
|
60
|
+
} else {
|
|
61
|
+
history.resume();
|
|
62
|
+
}
|
|
63
|
+
node.setLocal("dragging", change.dragging);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case "dimensions": {
|
|
68
|
+
const node = nodes.get(change.id);
|
|
69
|
+
if (!node)
|
|
70
|
+
break;
|
|
71
|
+
if (change.dimensions !== void 0 && change.setAttributes !== void 0) {
|
|
72
|
+
if (change.setAttributes === true || change.setAttributes === "width") {
|
|
73
|
+
node.set("width", change.dimensions.width);
|
|
74
|
+
}
|
|
75
|
+
if (change.setAttributes === true || change.setAttributes === "height") {
|
|
76
|
+
node.set("height", change.dimensions.height);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (change.dimensions !== void 0) {
|
|
80
|
+
node.setLocal("measured", change.dimensions);
|
|
81
|
+
}
|
|
82
|
+
if (change.resizing !== void 0) {
|
|
83
|
+
if (change.resizing) {
|
|
84
|
+
history.pause();
|
|
85
|
+
} else {
|
|
86
|
+
history.resume();
|
|
87
|
+
}
|
|
88
|
+
node.setLocal("resizing", change.resizing);
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "select": {
|
|
93
|
+
const node = nodes.get(change.id);
|
|
94
|
+
if (!node)
|
|
95
|
+
break;
|
|
96
|
+
node.setLocal("selected", change.selected);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "remove":
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function applyEdgeChanges(changes, edges, getEdgeSyncConfig) {
|
|
105
|
+
for (const change of changes) {
|
|
106
|
+
switch (change.type) {
|
|
107
|
+
case "add": {
|
|
108
|
+
const config = getEdgeSyncConfig(change.item.type);
|
|
109
|
+
edges.set(
|
|
110
|
+
change.item.id,
|
|
111
|
+
toLiveblocksInternalEdge(change.item, config)
|
|
112
|
+
);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "replace": {
|
|
116
|
+
const config = getEdgeSyncConfig(change.item.type);
|
|
117
|
+
const existing = edges.get(change.item.id);
|
|
118
|
+
if (existing) {
|
|
119
|
+
existing.reconcile(change.item, config);
|
|
120
|
+
} else {
|
|
121
|
+
edges.set(
|
|
122
|
+
change.item.id,
|
|
123
|
+
toLiveblocksInternalEdge(change.item, config)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "select":
|
|
129
|
+
{
|
|
130
|
+
const edge = edges.get(change.id);
|
|
131
|
+
if (!edge)
|
|
132
|
+
break;
|
|
133
|
+
edge.setLocal("selected", change.selected);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "remove":
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function useLiveblocksFlow(options = {}) {
|
|
142
|
+
const history = useHistory();
|
|
143
|
+
const isStorageLoaded = useStorage(() => true) ?? false;
|
|
144
|
+
const frozenOptions = useInitial({
|
|
145
|
+
nodes: options.nodes,
|
|
146
|
+
edges: options.edges,
|
|
147
|
+
storageKey: options.storageKey ?? DEFAULT_STORAGE_KEY,
|
|
148
|
+
suspense: options.suspense ?? false
|
|
149
|
+
});
|
|
150
|
+
const [getNodeSyncConfig, getEdgeSyncConfig] = useMemo(
|
|
151
|
+
() => [
|
|
152
|
+
buildNodeConfigCache(frozenOptions.nodes?.sync),
|
|
153
|
+
buildEdgeConfigCache(frozenOptions.edges?.sync)
|
|
154
|
+
],
|
|
155
|
+
[frozenOptions]
|
|
156
|
+
);
|
|
157
|
+
const nodes = useStorage((storage) => {
|
|
158
|
+
const flow = storage[frozenOptions.storageKey];
|
|
159
|
+
return flow?.nodes ? [...flow.nodes.values()] : null;
|
|
160
|
+
});
|
|
161
|
+
const edges = useStorage((storage) => {
|
|
162
|
+
const flow = storage[frozenOptions.storageKey];
|
|
163
|
+
return flow?.edges ? [...flow.edges.values()] : null;
|
|
164
|
+
});
|
|
165
|
+
const onNodesChange = useMutation(
|
|
166
|
+
({ storage }, changes) => {
|
|
167
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
168
|
+
if (!flow) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
applyNodeChanges(changes, flow.get("nodes"), history, getNodeSyncConfig);
|
|
172
|
+
},
|
|
173
|
+
[history, frozenOptions, getNodeSyncConfig]
|
|
174
|
+
);
|
|
175
|
+
const onEdgesChange = useMutation(
|
|
176
|
+
({ storage }, changes) => {
|
|
177
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
178
|
+
if (!flow) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
applyEdgeChanges(changes, flow.get("edges"), getEdgeSyncConfig);
|
|
182
|
+
},
|
|
183
|
+
[frozenOptions, getEdgeSyncConfig]
|
|
184
|
+
);
|
|
185
|
+
const onConnect = useMutation(
|
|
186
|
+
({ storage }, connection) => {
|
|
187
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
188
|
+
if (!flow) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const [newEdge] = addEdge(connection, []);
|
|
192
|
+
if (!newEdge) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const edges2 = flow.get("edges");
|
|
196
|
+
const config = getEdgeSyncConfig(newEdge.type);
|
|
197
|
+
edges2.set(newEdge.id, toLiveblocksInternalEdge(newEdge, config));
|
|
198
|
+
},
|
|
199
|
+
[frozenOptions.storageKey, getEdgeSyncConfig]
|
|
200
|
+
);
|
|
201
|
+
const onDelete = useMutation(
|
|
202
|
+
({ storage }, params) => {
|
|
203
|
+
const flow = storage.get(frozenOptions.storageKey);
|
|
204
|
+
if (!flow) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const nodesMap = flow.get("nodes");
|
|
208
|
+
const edgesMap = flow.get("edges");
|
|
209
|
+
for (const edge of params.edges) {
|
|
210
|
+
edgesMap.delete(edge.id);
|
|
211
|
+
}
|
|
212
|
+
for (const node of params.nodes) {
|
|
213
|
+
nodesMap.delete(node.id);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
[frozenOptions.storageKey]
|
|
217
|
+
);
|
|
218
|
+
const setInitialStorage = useMutation(
|
|
219
|
+
({ storage }) => {
|
|
220
|
+
if (storage.get(frozenOptions.storageKey) !== void 0) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const initialNodes = frozenOptions.nodes?.initial ?? [];
|
|
224
|
+
const initialEdges = frozenOptions.edges?.initial ?? [];
|
|
225
|
+
storage.set(
|
|
226
|
+
frozenOptions.storageKey,
|
|
227
|
+
new LiveObject({
|
|
228
|
+
nodes: new LiveMap(
|
|
229
|
+
initialNodes.map((node) => [
|
|
230
|
+
node.id,
|
|
231
|
+
toLiveblocksInternalNode(node, getNodeSyncConfig(node.type))
|
|
232
|
+
])
|
|
233
|
+
),
|
|
234
|
+
edges: new LiveMap(
|
|
235
|
+
initialEdges.map((edge) => [
|
|
236
|
+
edge.id,
|
|
237
|
+
toLiveblocksInternalEdge(edge, getEdgeSyncConfig(edge.type))
|
|
238
|
+
])
|
|
239
|
+
)
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
},
|
|
243
|
+
[frozenOptions, getNodeSyncConfig, getEdgeSyncConfig]
|
|
244
|
+
);
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
if (isStorageLoaded) {
|
|
247
|
+
history[kInternal].withoutHistory(() => {
|
|
248
|
+
setInitialStorage();
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}, [isStorageLoaded, setInitialStorage, history]);
|
|
252
|
+
if (frozenOptions.suspense) {
|
|
253
|
+
useSuspendUntilStorageReady();
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
nodes: frozenOptions.suspense ? nodes ?? EMPTY_ARRAY : nodes,
|
|
257
|
+
edges: frozenOptions.suspense ? edges ?? EMPTY_ARRAY : edges,
|
|
258
|
+
isLoading: frozenOptions.suspense ? false : !isStorageLoaded,
|
|
259
|
+
onNodesChange,
|
|
260
|
+
onEdgesChange,
|
|
261
|
+
onConnect,
|
|
262
|
+
onDelete
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export { useLiveblocksFlow };
|
|
267
|
+
//# sourceMappingURL=flow.js.map
|
package/dist/flow.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.js","sources":["../src/flow.ts"],"sourcesContent":["import type {\n History,\n JsonObject,\n Resolve,\n ToImmutable,\n} from \"@liveblocks/core\";\nimport { kInternal, LiveMap, LiveObject } from \"@liveblocks/core\";\nimport { useHistory, useMutation, useStorage } from \"@liveblocks/react\";\nimport {\n useInitial,\n useSuspendUntilStorageReady,\n} from \"@liveblocks/react/_private\";\nimport type {\n BuiltInEdge,\n BuiltInNode,\n Connection,\n Edge,\n EdgeChange,\n Node,\n NodeChange,\n OnConnect,\n OnDelete,\n OnEdgesChange,\n OnNodesChange,\n} from \"@xyflow/react\";\nimport { addEdge as defaultAddEdge } from \"@xyflow/react\";\nimport { useEffect, useMemo } from \"react\";\n\nimport {\n DEFAULT_STORAGE_KEY,\n EDGE_BASE_CONFIG,\n NODE_BASE_CONFIG,\n} from \"./constants\";\nimport { toLiveblocksInternalEdge, toLiveblocksInternalNode } from \"./helpers\";\nimport type {\n EdgeSyncConfig,\n InternalLiveblocksEdge,\n InternalLiveblocksFlow,\n InternalLiveblocksNode,\n NodeSyncConfig,\n SyncConfig,\n} from \"./types\";\n\nconst EMPTY_ARRAY = [] as unknown[];\n\ntype UseLiveblocksFlowResult<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n> = Resolve<\n (\n | {\n nodes: null;\n edges: null;\n isLoading: true;\n }\n | {\n nodes: N[];\n edges: E[];\n isLoading: false;\n }\n ) & {\n onNodesChange: OnNodesChange<N>;\n onEdgesChange: OnEdgesChange<E>;\n onConnect: OnConnect;\n onDelete: OnDelete<N, E>;\n }\n>;\n\ntype LiveblocksFlowSuspenseResult<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n> = Extract<UseLiveblocksFlowResult<N, E>, { isLoading: false }>;\n\nfunction mergeAndBuildDataConfigCache(\n base: SyncConfig,\n data?: Record<string, SyncConfig | undefined>\n): (type: string | undefined) => SyncConfig {\n if (!data) return () => base;\n\n const dataFallback = data[\"*\"];\n const fallback = dataFallback ? { ...base, data: dataFallback } : base;\n\n // Pre-compute full node/edge sync configs for all explicitly declared types\n const cache = new Map<string | undefined, SyncConfig>();\n for (const type in data) {\n if (type === \"*\") continue;\n const specific = data[type];\n if (!specific) continue;\n const dataConfig: SyncConfig = { ...dataFallback, ...specific };\n cache.set(type, { ...base, data: dataConfig });\n }\n\n return (type) => cache.get(type) || fallback;\n}\n\nfunction buildNodeConfigCache<N extends Node>(\n /** The user-provided node data sync configuration, if any. */\n nodeDataConfig?: NodeSyncConfig<N>\n): (type: string | undefined) => SyncConfig {\n return mergeAndBuildDataConfigCache(NODE_BASE_CONFIG, nodeDataConfig);\n}\n\nfunction buildEdgeConfigCache<E extends Edge>(\n /** The user-provided edge data sync configuration, if any. */\n edgeDataConfig?: EdgeSyncConfig<E>\n): (type: string | undefined) => SyncConfig {\n return mergeAndBuildDataConfigCache(EDGE_BASE_CONFIG, edgeDataConfig);\n}\n\ntype UseLiveblocksFlowOptions<N extends Node, E extends Edge> = {\n nodes?: {\n /**\n * The initial React Flow nodes.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * nodes: {\n * initial: [\n * { id: \"1\", position: { x: 0, y: 0 }, data: { label: \"Node 1\" } },\n * { id: \"2\", position: { x: 0, y: 100 }, data: { label: \"Node 2\" } },\n * ],\n * },\n * });\n * ```\n */\n initial?: N[];\n /**\n * Per-type sync configuration for node data keys.\n *\n * Use `\"*\"` as a fallback for all node types. Type-specific entries are\n * deep-merged on top of `\"*\"`, with explicitly named keys taking\n * precedence.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * nodes: {\n * sync: {\n * // Fallback for all node types\n * \"*\": { label: false },\n *\n * // Override for \"custom\" nodes\n * \"custom\": { color: false },\n * },\n * },\n * });\n * ```\n */\n // XXX Improve the example + match public documentation\n sync?: NodeSyncConfig<N>;\n };\n\n edges?: {\n initial?: E[];\n /**\n * Per-type sync configuration for edge data keys.\n *\n * Use `\"*\"` as a fallback for all edge types. Type-specific entries are\n * deep-merged on top of `\"*\"`, with explicitly named keys taking\n * precedence.\n *\n * @example\n * ```tsx\n * const { ... } = useLiveblocksFlow({\n * edges: {\n * sync: {\n * // Fallback for all node types\n * \"*\": { floating: false },\n * },\n * },\n * });\n * ```\n */\n // XXX Improve the example + match public documentation\n sync?: EdgeSyncConfig<E>;\n };\n\n /**\n * The key used to store the React Flow diagram in Liveblocks Storage.\n * Defaults to `\"flow\"`.\n */\n storageKey?: string;\n\n /**\n * When true, suspends until Storage is ready (use a React `Suspense`\n * boundary). Then `nodes` and `edges` are always arrays and `isLoading` is\n * always false.\n */\n suspense?: boolean;\n};\n\n// Similar to React Flow's `applyNodeChanges()`, but writes local-only\n// properties via `setLocal()` / `delete()` on the LiveObject directly.\n// https://reactflow.dev/api-reference/utils/apply-node-changes\nfunction applyNodeChanges<N extends Node>(\n changes: NodeChange<N>[],\n nodes: LiveMap<string, InternalLiveblocksNode>,\n history: History,\n getNodeSyncConfig: (nodeType: string | undefined) => SyncConfig\n): void {\n for (const change of changes) {\n switch (change.type) {\n case \"add\":\n case \"replace\": {\n const config = getNodeSyncConfig(change.item.type);\n const existing = nodes.get(change.item.id);\n if (existing) {\n existing.reconcile(change.item as unknown as JsonObject, config);\n } else {\n nodes.set(\n change.item.id,\n toLiveblocksInternalNode(change.item, config)\n );\n }\n break;\n }\n\n case \"position\": {\n const node = nodes.get(change.id);\n if (!node || !change.position) break;\n\n if (change.position !== undefined) {\n node.set(\"position\", change.position);\n }\n\n if (change.dragging !== undefined) {\n if (change.dragging) {\n history.pause();\n } else {\n history.resume();\n }\n node.setLocal(\"dragging\", change.dragging);\n }\n break;\n }\n\n case \"dimensions\": {\n const node = nodes.get(change.id);\n if (!node) break;\n\n if (\n change.dimensions !== undefined &&\n change.setAttributes !== undefined\n ) {\n if (\n change.setAttributes === true ||\n change.setAttributes === \"width\"\n ) {\n node.set(\"width\", change.dimensions.width);\n }\n\n if (\n change.setAttributes === true ||\n change.setAttributes === \"height\"\n ) {\n node.set(\"height\", change.dimensions.height);\n }\n }\n\n if (change.dimensions !== undefined) {\n node.setLocal(\"measured\", change.dimensions);\n }\n\n if (change.resizing !== undefined) {\n if (change.resizing) {\n history.pause();\n } else {\n history.resume();\n }\n node.setLocal(\"resizing\", change.resizing);\n }\n\n break;\n }\n\n case \"select\": {\n const node = nodes.get(change.id);\n if (!node) break;\n\n node.setLocal(\"selected\", change.selected);\n break;\n }\n\n case \"remove\":\n // Removals are handled by onDelete for atomic undo\n break;\n }\n }\n}\n\n// Similar to React Flow's `applyEdgeChanges()`, but writes local-only\n// properties via `setLocal()` / `delete()` on the LiveObject directly.\n// https://reactflow.dev/api-reference/utils/apply-edge-changes\nfunction applyEdgeChanges<E extends Edge>(\n changes: EdgeChange<E>[],\n edges: LiveMap<string, InternalLiveblocksEdge>,\n getEdgeSyncConfig: (type: string | undefined) => SyncConfig\n): void {\n for (const change of changes) {\n switch (change.type) {\n case \"add\": {\n const config = getEdgeSyncConfig(change.item.type);\n edges.set(\n change.item.id,\n toLiveblocksInternalEdge(change.item, config)\n );\n break;\n }\n\n case \"replace\": {\n const config = getEdgeSyncConfig(change.item.type);\n const existing = edges.get(change.item.id);\n if (existing) {\n existing.reconcile(change.item as unknown as JsonObject, config);\n } else {\n edges.set(\n change.item.id,\n toLiveblocksInternalEdge(change.item, config)\n );\n }\n break;\n }\n\n case \"select\":\n {\n const edge = edges.get(change.id);\n if (!edge) break;\n edge.setLocal(\"selected\", change.selected);\n }\n break;\n\n case \"remove\":\n // Removals are handled by onDelete for atomic undo\n break;\n }\n }\n}\n\n/**\n * Returns a controlled React Flow state backed by Liveblocks Storage.\n *\n * @example\n * ```tsx\n * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete, isLoading } = useLiveblocksFlow();\n *\n * if (isLoading) {\n * return <div>Loading…</div>\n * }\n *\n * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;\n * ```\n * Pass `{ suspense: true }` to suspend until Storage is ready, `nodes` and `edges` will never be `null`.\n *\n * @example\n * ```tsx\n * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete } =\n * useLiveblocksFlow({ suspense: true });\n *\n * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;\n * ```\n */\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options?: UseLiveblocksFlowOptions<N, E> & { suspense?: false }\n): Resolve<UseLiveblocksFlowResult<N, E>>;\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options: UseLiveblocksFlowOptions<N, E> & { suspense: true }\n): Resolve<LiveblocksFlowSuspenseResult<N, E>>;\nexport function useLiveblocksFlow<\n N extends Node = BuiltInNode,\n E extends Edge = BuiltInEdge,\n>(\n options: UseLiveblocksFlowOptions<N, E> = {}\n): Resolve<UseLiveblocksFlowResult<N, E> | LiveblocksFlowSuspenseResult<N, E>> {\n const history = useHistory();\n const isStorageLoaded = useStorage(() => true) ?? false;\n\n // These options are not reactive, only their initial values are used.\n const frozenOptions = useInitial({\n nodes: options.nodes,\n edges: options.edges,\n storageKey: options.storageKey ?? DEFAULT_STORAGE_KEY,\n suspense: options.suspense ?? false,\n });\n\n // Pre-compute sync config caches once (not on every render)\n const [getNodeSyncConfig, getEdgeSyncConfig] = useMemo(\n () =>\n [\n buildNodeConfigCache(frozenOptions.nodes?.sync),\n buildEdgeConfigCache(frozenOptions.edges?.sync),\n ] as const,\n [frozenOptions]\n );\n\n // Storage already includes local overlays via toImmutable(), so no\n // separate local layer is needed. Individual node/edge immutable references\n // are already stable (only change when the underlying LiveObject changes).\n const nodes = useStorage((storage) => {\n const flow = storage[frozenOptions.storageKey] as\n | ToImmutable<InternalLiveblocksFlow>\n | undefined;\n return flow?.nodes ? ([...flow.nodes.values()] as unknown as N[]) : null;\n });\n const edges = useStorage((storage) => {\n const flow = storage[frozenOptions.storageKey] as\n | ToImmutable<InternalLiveblocksFlow>\n | undefined;\n return flow?.edges ? ([...flow.edges.values()] as unknown as E[]) : null;\n });\n\n const onNodesChange = useMutation(\n ({ storage }, changes: NodeChange<N>[]) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n applyNodeChanges(changes, flow.get(\"nodes\"), history, getNodeSyncConfig);\n },\n [history, frozenOptions, getNodeSyncConfig]\n );\n\n const onEdgesChange = useMutation(\n ({ storage }, changes: EdgeChange<E>[]) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n applyEdgeChanges(changes, flow.get(\"edges\"), getEdgeSyncConfig);\n },\n [frozenOptions, getEdgeSyncConfig]\n );\n\n const onConnect = useMutation(\n ({ storage }, connection: Connection) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n // Delegate to React Flow's own `addEdge` helper for consistent default\n // edge ID generation, passing an empty array since de-duplication is\n // already handled above.\n const [newEdge] = defaultAddEdge(connection, [] as E[]);\n if (!newEdge) {\n return;\n }\n\n const edges = flow.get(\"edges\");\n const config = getEdgeSyncConfig(newEdge.type);\n edges.set(newEdge.id, toLiveblocksInternalEdge(newEdge, config));\n },\n [frozenOptions.storageKey, getEdgeSyncConfig]\n );\n\n const onDelete = useMutation(\n ({ storage }, params: { nodes: N[]; edges: E[] }) => {\n const flow = storage.get(frozenOptions.storageKey) as\n | InternalLiveblocksFlow\n | undefined;\n if (!flow) {\n return;\n }\n\n const nodesMap = flow.get(\"nodes\");\n const edgesMap = flow.get(\"edges\");\n\n for (const edge of params.edges) {\n edgesMap.delete(edge.id);\n }\n\n for (const node of params.nodes) {\n nodesMap.delete(node.id);\n }\n },\n [frozenOptions.storageKey]\n );\n\n const setInitialStorage = useMutation(\n ({ storage }) => {\n // Similarly to `initialStorage` on `Client.enterRoom` and `RoomProvider`, we only\n // initialize Storage if it doesn't already exist.\n if (storage.get(frozenOptions.storageKey) !== undefined) {\n return;\n }\n\n const initialNodes = frozenOptions.nodes?.initial ?? [];\n const initialEdges = frozenOptions.edges?.initial ?? [];\n\n storage.set(\n frozenOptions.storageKey,\n new LiveObject({\n nodes: new LiveMap(\n initialNodes.map((node) => [\n node.id,\n toLiveblocksInternalNode(node, getNodeSyncConfig(node.type)),\n ])\n ),\n edges: new LiveMap(\n initialEdges.map((edge) => [\n edge.id,\n toLiveblocksInternalEdge(edge, getEdgeSyncConfig(edge.type)),\n ])\n ),\n })\n );\n },\n [frozenOptions, getNodeSyncConfig, getEdgeSyncConfig]\n );\n\n useEffect(() => {\n if (isStorageLoaded) {\n history[kInternal].withoutHistory(() => {\n setInitialStorage();\n });\n }\n }, [isStorageLoaded, setInitialStorage, history]);\n\n if (frozenOptions.suspense) {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- `suspense` is frozen so this branch is stable\n useSuspendUntilStorageReady();\n }\n\n return {\n nodes: frozenOptions.suspense ? (nodes ?? (EMPTY_ARRAY as N[])) : nodes,\n edges: frozenOptions.suspense ? (edges ?? (EMPTY_ARRAY as E[])) : edges,\n isLoading: frozenOptions.suspense ? false : !isStorageLoaded,\n onNodesChange,\n onEdgesChange,\n onConnect,\n onDelete,\n } as UseLiveblocksFlowResult<N, E> | LiveblocksFlowSuspenseResult<N, E>;\n}\n"],"names":["defaultAddEdge","edges"],"mappings":";;;;;;;;AA2CA,MAAM,cAAc,EAAC,CAAA;AA8BrB,SAAS,4BAAA,CACP,MACA,IAC0C,EAAA;AAC1C,EAAA,IAAI,CAAC,IAAA;AAAM,IAAA,OAAO,MAAM,IAAA,CAAA;AAExB,EAAM,MAAA,YAAA,GAAe,KAAK,GAAG,CAAA,CAAA;AAC7B,EAAA,MAAM,WAAW,YAAe,GAAA,EAAE,GAAG,IAAM,EAAA,IAAA,EAAM,cAAiB,GAAA,IAAA,CAAA;AAGlE,EAAM,MAAA,KAAA,uBAAY,GAAoC,EAAA,CAAA;AACtD,EAAA,KAAA,MAAW,QAAQ,IAAM,EAAA;AACvB,IAAA,IAAI,IAAS,KAAA,GAAA;AAAK,MAAA,SAAA;AAClB,IAAM,MAAA,QAAA,GAAW,KAAK,IAAI,CAAA,CAAA;AAC1B,IAAA,IAAI,CAAC,QAAA;AAAU,MAAA,SAAA;AACf,IAAA,MAAM,UAAyB,GAAA,EAAE,GAAG,YAAA,EAAc,GAAG,QAAS,EAAA,CAAA;AAC9D,IAAA,KAAA,CAAM,IAAI,IAAM,EAAA,EAAE,GAAG,IAAM,EAAA,IAAA,EAAM,YAAY,CAAA,CAAA;AAAA,GAC/C;AAEA,EAAA,OAAO,CAAC,IAAA,KAAS,KAAM,CAAA,GAAA,CAAI,IAAI,CAAK,IAAA,QAAA,CAAA;AACtC,CAAA;AAEA,SAAS,qBAEP,cAC0C,EAAA;AAC1C,EAAO,OAAA,4BAAA,CAA6B,kBAAkB,cAAc,CAAA,CAAA;AACtE,CAAA;AAEA,SAAS,qBAEP,cAC0C,EAAA;AAC1C,EAAO,OAAA,4BAAA,CAA6B,k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