@liveblocks/react-flow 3.16.0-flow1 → 3.16.0-flow3

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/dist/index.d.ts CHANGED
@@ -1,8 +1,25 @@
1
1
  import * as react from 'react';
2
- import { ComponentPropsWithoutRef } from 'react';
3
- import { LiveObject, DistributiveOmit, LsonObject, LiveMap, Resolve, JsonObject } from '@liveblocks/core';
4
- import { Node, Edge, OnNodesChange, OnEdgesChange, OnConnect } from '@xyflow/react';
2
+ import { ComponentPropsWithoutRef, ComponentType, CSSProperties } from 'react';
3
+ import { SyncConfig, LiveObject, LiveMap, SyncMode, Json, JsonScalar, LiveList, Lson, LsonObject, Resolve } from '@liveblocks/core';
4
+ export { SyncConfig, SyncMode } from '@liveblocks/core';
5
+ import { Node, Edge, BuiltInNode, BuiltInEdge, OnNodesChange, OnEdgesChange, OnConnect, OnDelete } from '@xyflow/react';
5
6
 
7
+ interface CursorsCursorProps {
8
+ /**
9
+ * The user ID for this cursor.
10
+ */
11
+ userId: string;
12
+ /**
13
+ * The connection ID for this cursor.
14
+ */
15
+ connectionId: number;
16
+ }
17
+ interface CursorsComponents {
18
+ /**
19
+ * The component used to display each cursor.
20
+ */
21
+ Cursor: ComponentType<CursorsCursorProps>;
22
+ }
6
23
  interface CursorsProps extends ComponentPropsWithoutRef<"div"> {
7
24
  /**
8
25
  * The key used to store the cursors in users' Presence.
@@ -10,6 +27,10 @@ interface CursorsProps extends ComponentPropsWithoutRef<"div"> {
10
27
  * Defaults to `"cursor"`.
11
28
  */
12
29
  presenceKey?: string;
30
+ /**
31
+ * Override the component's components.
32
+ */
33
+ components?: Partial<CursorsComponents>;
13
34
  }
14
35
  /**
15
36
  * Displays other users' cursors inside a React Flow canvas and stores the
@@ -20,131 +41,214 @@ interface CursorsProps extends ComponentPropsWithoutRef<"div"> {
20
41
  */
21
42
  declare const Cursors: react.ForwardRefExoticComponent<CursorsProps & react.RefAttributes<HTMLDivElement>>;
22
43
 
23
- declare const NODE_LOCAL_KEYS: ["selected", "dragging", "measured", "resizing"];
24
- declare const EDGE_LOCAL_KEYS: ["selected"];
25
- type SerializableNode = Node<JsonObject>;
26
- type SerializableEdge = Edge<JsonObject>;
44
+ declare const NODE_BASE_CONFIG: {
45
+ readonly selected: false;
46
+ readonly dragging: false;
47
+ readonly measured: false;
48
+ readonly resizing: false;
49
+ readonly position: "atomic";
50
+ readonly sourcePosition: "atomic";
51
+ readonly targetPosition: "atomic";
52
+ readonly extent: "atomic";
53
+ readonly origin: "atomic";
54
+ readonly handles: "atomic";
55
+ };
56
+ declare const EDGE_BASE_CONFIG: {
57
+ readonly selected: false;
58
+ readonly markerStart: "atomic";
59
+ readonly markerEnd: "atomic";
60
+ readonly label: "atomic";
61
+ };
62
+
63
+ type InferNodeTypeLiterals<N> = N extends Node<any, infer T extends string> ? string extends T ? never : T : never;
64
+ type NodeTypeLiterals<N> = (string & {}) | "*" | InferNodeTypeLiterals<N>;
65
+ type InferEdgeTypeLiterals<E> = E extends Edge<any, infer T extends string> ? string extends T ? never : T : never;
66
+ type EdgeTypeLiterals<E> = (string & {}) | "*" | InferEdgeTypeLiterals<E>;
67
+ type NodeSyncConfig<N extends Node> = {
68
+ [key in NodeTypeLiterals<N>]?: SyncConfig;
69
+ };
70
+ type EdgeSyncConfig<E extends Edge> = {
71
+ [key in EdgeTypeLiterals<E>]?: SyncConfig;
72
+ };
73
+ type ToLsonProperty<V, S extends SyncMode> = undefined extends V ? ToLson<Exclude<V, undefined>, S> | undefined : ToLson<V, S>;
74
+ type SyncedKeysFor<K, S extends SyncMode> = S extends SyncConfig ? K extends keyof S ? S[K] extends false ? never : K : K : K;
75
+ type SyncModeFor<K, S extends SyncMode> = S extends SyncConfig ? K extends keyof S ? S[K] extends SyncMode ? S[K] : true : true : S;
76
+ type ToLson<T, S extends SyncMode = true> = [S] extends [false] ? T : [S] extends ["atomic"] ? Json : T extends JsonScalar ? T : T extends Date | RegExp | Function | Promise<any> | WeakMap<any, any> | WeakSet<any> | Map<any, any> | Set<any> ? never : T extends ReadonlyArray<infer E> ? LiveList<ToLson<E, S> & Lson> : T extends CSSProperties ? LiveObject<CSSProperties & LsonObject> : T extends object ? LiveObject<{
77
+ [K in keyof T as SyncedKeysFor<K, S>]: ToLsonProperty<T[K], SyncModeFor<K, S>>;
78
+ } & LsonObject> : never;
79
+ type ToLiveElement<Base, BaseConfig, Concrete, Data> = LiveObject<{
80
+ [K in keyof Base]: K extends keyof BaseConfig ? BaseConfig[K & keyof BaseConfig] extends "atomic" | false ? Json : Concrete[K & keyof Concrete] : K extends "data" ? Data : ToLson<Base[K]>;
81
+ } & LsonObject>;
27
82
  /**
28
83
  * The Liveblocks Storage representation of a React Flow `Node`.
29
- *
30
- * It doesn't include local-only properties.
31
- * The entire node and its `data` property are both stored as `LiveObject`s.
32
84
  */
33
- type LiveblocksNode<TNode extends SerializableNode = SerializableNode> = LiveObject<DistributiveOmit<TNode, (typeof NODE_LOCAL_KEYS)[number] | "data"> & {
34
- data: LiveObject<TNode["data"]>;
35
- } & LsonObject>;
85
+ type LiveblocksNode<N extends Node = BuiltInNode, S extends SyncConfig = SyncConfig> = ToLiveElement<Node, typeof NODE_BASE_CONFIG, N, ToLson<N["data"], S>>;
36
86
  /**
37
87
  * The Liveblocks Storage representation of a React Flow `Edge`.
38
- *
39
- * It doesn't include local-only properties.
40
- * The entire edge and its `data` property are both stored as `LiveObject`s.
41
88
  */
42
- type LiveblocksEdge<TEdge extends SerializableEdge = SerializableEdge> = LiveObject<DistributiveOmit<TEdge, (typeof EDGE_LOCAL_KEYS)[number] | "data"> & {
43
- data?: LiveObject<NonNullable<TEdge["data"]>>;
44
- } & LsonObject>;
89
+ type LiveblocksEdge<E extends Edge = BuiltInEdge, S extends SyncConfig = SyncConfig> = ToLiveElement<Edge, typeof EDGE_BASE_CONFIG, E, ToLson<E["data"], S>>;
45
90
  /**
46
91
  * The Liveblocks Storage representation of a React Flow diagram made of nodes and edges.
47
- *
48
- * Nodes and edges are stored as `LiveMap`s keyed by their IDs, enabling
49
- * fine-grained conflict-free updates from multiple clients simultaneously.
50
92
  */
51
- type LiveblocksFlow<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge> = LiveObject<{
52
- nodes: LiveMap<string, LiveblocksNode<TNode>>;
53
- edges: LiveMap<string, LiveblocksEdge<TEdge>>;
93
+ type LiveblocksFlow<N extends Node = BuiltInNode, E extends Edge = BuiltInEdge, NS extends SyncConfig = SyncConfig, ES extends SyncConfig = SyncConfig> = LiveObject<{
94
+ nodes: LiveMap<string, LiveblocksNode<N, NS>>;
95
+ edges: LiveMap<string, LiveblocksEdge<E, ES>>;
54
96
  }>;
55
- type UseLiveblocksFlowResult<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge> = Resolve<({
97
+
98
+ type UseLiveblocksFlowResult<N extends Node = BuiltInNode, E extends Edge = BuiltInEdge> = Resolve<({
56
99
  nodes: null;
57
100
  edges: null;
58
101
  isLoading: true;
59
102
  } | {
60
- nodes: TNode[];
61
- edges: TEdge[];
103
+ nodes: N[];
104
+ edges: E[];
62
105
  isLoading: false;
63
106
  }) & {
64
- onNodesChange: OnNodesChange<TNode>;
65
- onEdgesChange: OnEdgesChange<TEdge>;
107
+ onNodesChange: OnNodesChange<N>;
108
+ onEdgesChange: OnEdgesChange<E>;
66
109
  onConnect: OnConnect;
110
+ onDelete: OnDelete<N, E>;
67
111
  }>;
68
- type UseLiveblocksFlowOptions<TNode extends SerializableNode, TEdge extends SerializableEdge> = {
69
- /**
70
- * The initial React Flow nodes and edges.
71
- *
72
- * @example
73
- * ```tsx
74
- * const { ... } = useLiveblocksFlow({
75
- * initial: {
76
- * nodes: [
77
- * { id: "1", position: { x: 0, y: 0 }, data: { label: "Node 1" } },
78
- * { id: "2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
79
- * ],
80
- * edges: [
81
- * { id: "1-2", source: "1", target: "2" },
82
- * ],
83
- * },
84
- * });
85
- * ```
86
- *
87
- * This is equivalent to setting `initialStorage` on `RoomProvider`.
88
- *
89
- * @example
90
- * ```tsx
91
- * <RoomProvider
92
- * initialStorage={{
93
- * flow: createLiveblocksFlow([
94
- * { id: "1", position: { x: 0, y: 0 }, data: { label: "Node 1" } },
95
- * { id: "2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
96
- * ], [
97
- * { id: "1-2", source: "1", target: "2" },
98
- * ]),
99
- * }}
100
- * />
101
- * ```
102
- */
103
- initial?: {
104
- nodes?: TNode[];
105
- edges?: TEdge[];
112
+ type LiveblocksFlowSuspenseResult<N extends Node = BuiltInNode, E extends Edge = BuiltInEdge> = Extract<UseLiveblocksFlowResult<N, E>, {
113
+ isLoading: false;
114
+ }>;
115
+ type UseLiveblocksFlowOptions<N extends Node, E extends Edge> = {
116
+ nodes?: {
117
+ /**
118
+ * The initial React Flow nodes.
119
+ *
120
+ * @example
121
+ * ```tsx
122
+ * const { ... } = useLiveblocksFlow({
123
+ * nodes: {
124
+ * initial: [
125
+ * { id: "1", position: { x: 0, y: 0 }, data: { label: "Node 1" } },
126
+ * { id: "2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
127
+ * ],
128
+ * },
129
+ * });
130
+ * ```
131
+ */
132
+ initial?: N[];
133
+ /**
134
+ * Per-type sync configuration for node data keys.
135
+ *
136
+ * Use `"*"` as a fallback for all node types. Type-specific entries are
137
+ * deep-merged on top of `"*"`, with explicitly named keys taking
138
+ * precedence.
139
+ *
140
+ * @example
141
+ * ```tsx
142
+ * const { ... } = useLiveblocksFlow({
143
+ * nodes: {
144
+ * sync: {
145
+ * // Fallback for all node types
146
+ * "*": {
147
+ * label: false, // Don't sync node.data.label
148
+ * },
149
+ *
150
+ * // Override for node.type === 'myCustomNode'
151
+ * // This will also not sync `myCustomNode.data.label` (because of the fallback above)
152
+ * myCustomNode: {
153
+ * showPreview: false, // Don't sync myCustomNode.data.showPreview
154
+ * },
155
+ * },
156
+ * },
157
+ * });
158
+ * ```
159
+ */
160
+ sync?: NodeSyncConfig<N>;
161
+ };
162
+ edges?: {
163
+ initial?: E[];
164
+ /**
165
+ * Per-type sync configuration for edge data keys.
166
+ *
167
+ * Use `"*"` as a fallback for all edge types. Type-specific entries are
168
+ * deep-merged on top of `"*"`, with explicitly named keys taking
169
+ * precedence.
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * const { ... } = useLiveblocksFlow({
174
+ * edges: {
175
+ * sync: {
176
+ * // Fallback for all edge types
177
+ * "*": {
178
+ * hovered: false, // Don't sync edge.data.hovered
179
+ * },
180
+ *
181
+ * // Override for edge.type === 'myCustomEdge'
182
+ * // This will also not sync `myCustomEdge.data.hovered` (because of the fallback above)
183
+ * myCustomEdge: {
184
+ * isHighlighted: false, // Don't sync myCustomEdge.data.isHighlighted
185
+ * },
186
+ * },
187
+ * },
188
+ * });
189
+ * ```
190
+ */
191
+ sync?: EdgeSyncConfig<E>;
106
192
  };
107
193
  /**
108
194
  * The key used to store the React Flow diagram in Liveblocks Storage.
109
- *
110
195
  * Defaults to `"flow"`.
111
- *
112
- * @example
113
- * ```tsx
114
- * const { ... } = useLiveblocksFlow({
115
- * storageKey: "myDiagram",
116
- * });
117
- * ```
118
196
  */
119
197
  storageKey?: string;
198
+ /**
199
+ * When true, suspends until Storage is ready (use a React `Suspense`
200
+ * boundary). Then `nodes` and `edges` are always arrays and `isLoading` is
201
+ * always false.
202
+ */
203
+ suspense?: boolean;
120
204
  };
121
- /**
122
- * Creates a Liveblocks Storage representation of a React Flow diagram from nodes and edges.
123
- *
124
- * @example
125
- * ```tsx
126
- * <RoomProvider
127
- * initialStorage={{
128
- * flow: createLiveblocksFlow(initialNodes, initialEdges),
129
- * }}
130
- * />
131
- * ```
132
- */
133
- declare function createLiveblocksFlow<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge>(nodes?: TNode[], edges?: TEdge[]): LiveblocksFlow<TNode, TEdge>;
134
205
  /**
135
206
  * Returns a controlled React Flow state backed by Liveblocks Storage.
136
207
  *
137
208
  * @example
138
209
  * ```tsx
139
- * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, isLoading } = useLiveblocksFlow();
210
+ * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete, isLoading } = useLiveblocksFlow();
140
211
  *
141
212
  * if (isLoading) {
142
213
  * return <div>Loading…</div>
143
214
  * }
144
215
  *
145
- * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} />;
216
+ * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;
146
217
  * ```
218
+ * Pass `{ suspense: true }` to suspend until Storage is ready, `nodes` and `edges` will never be `null`.
219
+ *
220
+ * @example
221
+ * ```tsx
222
+ * const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onDelete } =
223
+ * useLiveblocksFlow({ suspense: true });
224
+ *
225
+ * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} onDelete={onDelete} />;
226
+ * ```
227
+ */
228
+ declare function useLiveblocksFlow<N extends Node = BuiltInNode, E extends Edge = BuiltInEdge>(options?: UseLiveblocksFlowOptions<N, E> & {
229
+ suspense?: false;
230
+ }): Resolve<UseLiveblocksFlowResult<N, E>>;
231
+ declare function useLiveblocksFlow<N extends Node = BuiltInNode, E extends Edge = BuiltInEdge>(options: UseLiveblocksFlowOptions<N, E> & {
232
+ suspense: true;
233
+ }): Resolve<LiveblocksFlowSuspenseResult<N, E>>;
234
+
235
+ /**
236
+ * @experimental
237
+ *
238
+ * Converts a React Flow `Node` into a Liveblocks Storage version.
239
+ * Keys marked `false` in config are set as local-only (not synced).
240
+ * Keys marked `"atomic"` are stored as plain Json (no deep wrapping).
241
+ * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).
242
+ */
243
+ declare function toLiveblocksNode<N extends Node>(node: N, config?: SyncConfig): LiveblocksNode<N>;
244
+ /**
245
+ * @experimental
246
+ *
247
+ * Converts a React Flow `Edge` into a Liveblocks Storage version.
248
+ * Keys marked `false` in config are set as local-only (not synced).
249
+ * Keys marked `"atomic"` are stored as plain Json (no deep wrapping).
250
+ * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).
147
251
  */
148
- declare function useLiveblocksFlow<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge>(options?: UseLiveblocksFlowOptions<TNode, TEdge>): Resolve<UseLiveblocksFlowResult<TNode, TEdge>>;
252
+ declare function toLiveblocksEdge<E extends Edge>(edge: E, config?: SyncConfig): LiveblocksEdge<E>;
149
253
 
150
- export { Cursors, LiveblocksEdge, LiveblocksFlow, LiveblocksNode, createLiveblocksFlow, useLiveblocksFlow };
254
+ export { Cursors, CursorsCursorProps, CursorsProps, EdgeSyncConfig, LiveblocksEdge, LiveblocksFlow, LiveblocksNode, NodeSyncConfig, toLiveblocksEdge, toLiveblocksNode, useLiveblocksFlow };
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { detectDupes } from '@liveblocks/core';
2
2
  import { PKG_NAME, PKG_VERSION, PKG_FORMAT } from './version.js';
3
3
  export { Cursors } from './cursors.js';
4
- export { createLiveblocksFlow, useLiveblocksFlow } from './flow.js';
4
+ export { useLiveblocksFlow } from './flow.js';
5
+ export { toLiveblocksEdge, toLiveblocksNode } from './helpers.js';
5
6
 
6
7
  detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport { Cursors } from \"./cursors\";\nexport type { LiveblocksEdge, LiveblocksFlow, LiveblocksNode } from \"./flow\";\nexport { createLiveblocksFlow, useLiveblocksFlow } from \"./flow\";\n"],"names":[],"mappings":";;;;;AAIA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport type { CursorsCursorProps, CursorsProps } from \"./cursors\";\nexport { Cursors } from \"./cursors\";\nexport { useLiveblocksFlow } from \"./flow\";\nexport { toLiveblocksEdge, toLiveblocksNode } from \"./helpers\";\nexport type {\n EdgeSyncConfig,\n LiveblocksEdge,\n LiveblocksFlow,\n LiveblocksNode,\n NodeSyncConfig,\n SyncConfig,\n SyncMode,\n} from \"./types\";\n"],"names":[],"mappings":";;;;;;AAIA,WAAY,CAAA,QAAA,EAAU,aAAa,UAAU,CAAA"}
package/dist/version.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const PKG_NAME = "@liveblocks/react-flow";
4
- const PKG_VERSION = typeof "3.16.0-flow1" === "string" && "3.16.0-flow1";
4
+ const PKG_VERSION = typeof "3.16.0-flow3" === "string" && "3.16.0-flow3";
5
5
  const PKG_FORMAT = typeof TSUP_FORMAT === "string" && TSUP_FORMAT;
6
6
 
7
7
  exports.PKG_FORMAT = PKG_FORMAT;
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const PKG_NAME = "@liveblocks/react-flow";
2
- const PKG_VERSION = typeof "3.16.0-flow1" === "string" && "3.16.0-flow1";
2
+ const PKG_VERSION = typeof "3.16.0-flow3" === "string" && "3.16.0-flow3";
3
3
  const PKG_FORMAT = typeof TSUP_FORMAT === "string" && TSUP_FORMAT;
4
4
 
5
5
  export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liveblocks/react-flow",
3
- "version": "3.16.0-flow1",
4
- "description": "An integration of React Flow to enable collaboration, comments, live cursors, and more with Liveblocks.",
3
+ "version": "3.16.0-flow3",
4
+ "description": "An integration of React Flow to enable collaboration and realtime cursors with Liveblocks.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Liveblocks Inc.",
7
7
  "type": "module",
@@ -22,17 +22,6 @@
22
22
  "./styles.css": {
23
23
  "types": "./styles.css.d.cts",
24
24
  "default": "./styles.css"
25
- },
26
- "./suspense": {
27
- "import": {
28
- "types": "./dist/suspense.d.ts",
29
- "default": "./dist/suspense.js"
30
- },
31
- "require": {
32
- "types": "./dist/suspense.d.cts",
33
- "module": "./dist/suspense.js",
34
- "default": "./dist/suspense.cjs"
35
- }
36
25
  }
37
26
  },
38
27
  "files": [
@@ -41,7 +30,6 @@
41
30
  "**/*.css.d.cts",
42
31
  "**/*.css.d.ts",
43
32
  "**/*.css.map",
44
- "suspense/**",
45
33
  "README.md"
46
34
  ],
47
35
  "scripts": {
@@ -55,10 +43,10 @@
55
43
  "test:watch": "vitest"
56
44
  },
57
45
  "dependencies": {
58
- "@liveblocks/client": "3.16.0-flow1",
59
- "@liveblocks/core": "3.16.0-flow1",
60
- "@liveblocks/react": "3.16.0-flow1",
61
- "@liveblocks/react-ui": "3.16.0-flow1"
46
+ "@liveblocks/client": "3.16.0-flow3",
47
+ "@liveblocks/core": "3.16.0-flow3",
48
+ "@liveblocks/react": "3.16.0-flow3",
49
+ "@liveblocks/react-ui": "3.16.0-flow3"
62
50
  },
63
51
  "peerDependencies": {
64
52
  "@xyflow/react": "^12",
package/dist/suspense.cjs DELETED
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@liveblocks/core');
4
- var version = require('./version.cjs');
5
- var cursors = require('./cursors.cjs');
6
- var flow = require('./flow.cjs');
7
-
8
- core.detectDupes(version.PKG_NAME, version.PKG_VERSION, version.PKG_FORMAT);
9
-
10
- exports.Cursors = cursors.Cursors;
11
- exports.createLiveblocksFlow = flow.createLiveblocksFlow;
12
- exports.useLiveblocksFlow = flow.useLiveblocksFlowSuspense;
13
- //# sourceMappingURL=suspense.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"suspense.cjs","sources":["../src/suspense.ts"],"sourcesContent":["import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n\nexport { Cursors } from \"./cursors\";\nexport type { LiveblocksEdge, LiveblocksFlow, LiveblocksNode } from \"./flow\";\nexport {\n createLiveblocksFlow,\n useLiveblocksFlowSuspense as useLiveblocksFlow,\n} from \"./flow\";\n"],"names":["detectDupes","PKG_NAME","PKG_VERSION","PKG_FORMAT"],"mappings":";;;;;;;AAIAA,gBAAY,CAAAC,gBAAA,EAAUC,qBAAaC,kBAAU,CAAA;;;;;;"}
@@ -1,149 +0,0 @@
1
- import * as react from 'react';
2
- import { ComponentPropsWithoutRef } from 'react';
3
- import { LiveObject, DistributiveOmit, LsonObject, LiveMap, Resolve, JsonObject } from '@liveblocks/core';
4
- import { Node, Edge, OnNodesChange, OnEdgesChange, OnConnect } from '@xyflow/react';
5
-
6
- interface CursorsProps extends ComponentPropsWithoutRef<"div"> {
7
- /**
8
- * The key used to store the cursors in users' Presence.
9
- *
10
- * Defaults to `"cursor"`.
11
- */
12
- presenceKey?: string;
13
- }
14
- /**
15
- * Displays other users' cursors inside a React Flow canvas and stores the
16
- * current user's cursor in Presence as `{ cursor: { x, y } }`.
17
- *
18
- * Cursor coordinates are kept in React Flow canvas space, so panning moves
19
- * them correctly while zooming only affects their position, not their size.
20
- */
21
- declare const Cursors: react.ForwardRefExoticComponent<CursorsProps & react.RefAttributes<HTMLDivElement>>;
22
-
23
- declare const NODE_LOCAL_KEYS: ["selected", "dragging", "measured", "resizing"];
24
- declare const EDGE_LOCAL_KEYS: ["selected"];
25
- type SerializableNode = Node<JsonObject>;
26
- type SerializableEdge = Edge<JsonObject>;
27
- /**
28
- * The Liveblocks Storage representation of a React Flow `Node`.
29
- *
30
- * It doesn't include local-only properties.
31
- * The entire node and its `data` property are both stored as `LiveObject`s.
32
- */
33
- type LiveblocksNode<TNode extends SerializableNode = SerializableNode> = LiveObject<DistributiveOmit<TNode, (typeof NODE_LOCAL_KEYS)[number] | "data"> & {
34
- data: LiveObject<TNode["data"]>;
35
- } & LsonObject>;
36
- /**
37
- * The Liveblocks Storage representation of a React Flow `Edge`.
38
- *
39
- * It doesn't include local-only properties.
40
- * The entire edge and its `data` property are both stored as `LiveObject`s.
41
- */
42
- type LiveblocksEdge<TEdge extends SerializableEdge = SerializableEdge> = LiveObject<DistributiveOmit<TEdge, (typeof EDGE_LOCAL_KEYS)[number] | "data"> & {
43
- data?: LiveObject<NonNullable<TEdge["data"]>>;
44
- } & LsonObject>;
45
- /**
46
- * The Liveblocks Storage representation of a React Flow diagram made of nodes and edges.
47
- *
48
- * Nodes and edges are stored as `LiveMap`s keyed by their IDs, enabling
49
- * fine-grained conflict-free updates from multiple clients simultaneously.
50
- */
51
- type LiveblocksFlow<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge> = LiveObject<{
52
- nodes: LiveMap<string, LiveblocksNode<TNode>>;
53
- edges: LiveMap<string, LiveblocksEdge<TEdge>>;
54
- }>;
55
- type UseLiveblocksFlowResult<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge> = Resolve<({
56
- nodes: null;
57
- edges: null;
58
- isLoading: true;
59
- } | {
60
- nodes: TNode[];
61
- edges: TEdge[];
62
- isLoading: false;
63
- }) & {
64
- onNodesChange: OnNodesChange<TNode>;
65
- onEdgesChange: OnEdgesChange<TEdge>;
66
- onConnect: OnConnect;
67
- }>;
68
- type LiveblocksFlowSuspenseResult<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge> = Extract<UseLiveblocksFlowResult<TNode, TEdge>, {
69
- isLoading: false;
70
- }>;
71
- type UseLiveblocksFlowOptions<TNode extends SerializableNode, TEdge extends SerializableEdge> = {
72
- /**
73
- * The initial React Flow nodes and edges.
74
- *
75
- * @example
76
- * ```tsx
77
- * const { ... } = useLiveblocksFlow({
78
- * initial: {
79
- * nodes: [
80
- * { id: "1", position: { x: 0, y: 0 }, data: { label: "Node 1" } },
81
- * { id: "2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
82
- * ],
83
- * edges: [
84
- * { id: "1-2", source: "1", target: "2" },
85
- * ],
86
- * },
87
- * });
88
- * ```
89
- *
90
- * This is equivalent to setting `initialStorage` on `RoomProvider`.
91
- *
92
- * @example
93
- * ```tsx
94
- * <RoomProvider
95
- * initialStorage={{
96
- * flow: createLiveblocksFlow([
97
- * { id: "1", position: { x: 0, y: 0 }, data: { label: "Node 1" } },
98
- * { id: "2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
99
- * ], [
100
- * { id: "1-2", source: "1", target: "2" },
101
- * ]),
102
- * }}
103
- * />
104
- * ```
105
- */
106
- initial?: {
107
- nodes?: TNode[];
108
- edges?: TEdge[];
109
- };
110
- /**
111
- * The key used to store the React Flow diagram in Liveblocks Storage.
112
- *
113
- * Defaults to `"flow"`.
114
- *
115
- * @example
116
- * ```tsx
117
- * const { ... } = useLiveblocksFlow({
118
- * storageKey: "myDiagram",
119
- * });
120
- * ```
121
- */
122
- storageKey?: string;
123
- };
124
- /**
125
- * Creates a Liveblocks Storage representation of a React Flow diagram from nodes and edges.
126
- *
127
- * @example
128
- * ```tsx
129
- * <RoomProvider
130
- * initialStorage={{
131
- * flow: createLiveblocksFlow(initialNodes, initialEdges),
132
- * }}
133
- * />
134
- * ```
135
- */
136
- declare function createLiveblocksFlow<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge>(nodes?: TNode[], edges?: TEdge[]): LiveblocksFlow<TNode, TEdge>;
137
- /**
138
- * Returns a controlled React Flow state backed by Liveblocks Storage.
139
- *
140
- * @example
141
- * ```tsx
142
- * const { nodes, edges, onNodesChange, onEdgesChange, onConnect } = useLiveblocksFlow();
143
- *
144
- * return <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} />;
145
- * ```
146
- */
147
- declare function useLiveblocksFlowSuspense<TNode extends SerializableNode = SerializableNode, TEdge extends SerializableEdge = SerializableEdge>(options?: UseLiveblocksFlowOptions<TNode, TEdge>): Resolve<LiveblocksFlowSuspenseResult<TNode, TEdge>>;
148
-
149
- export { Cursors, LiveblocksEdge, LiveblocksFlow, LiveblocksNode, createLiveblocksFlow, useLiveblocksFlowSuspense as useLiveblocksFlow };