@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/README.md +51 -0
- package/dist/constants.cjs +34 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.js +30 -0
- package/dist/constants.js.map +1 -0
- package/dist/cursors.cjs +27 -18
- package/dist/cursors.cjs.map +1 -1
- package/dist/cursors.js +29 -20
- package/dist/cursors.js.map +1 -1
- package/dist/flow.cjs +166 -237
- package/dist/flow.cjs.map +1 -1
- package/dist/flow.js +171 -240
- package/dist/flow.js.map +1 -1
- 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 +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +197 -93
- package/dist/index.d.ts +197 -93
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -18
- package/dist/suspense.cjs +0 -13
- package/dist/suspense.cjs.map +0 -1
- package/dist/suspense.d.cts +0 -149
- package/dist/suspense.d.ts +0 -149
- package/dist/suspense.js +0 -7
- package/dist/suspense.js.map +0 -1
- package/suspense/README.md +0 -5
- package/suspense/package.json +0 -4
package/dist/helpers.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@liveblocks/core');
|
|
4
|
+
var constants = require('./constants.cjs');
|
|
5
|
+
|
|
6
|
+
function toLiveblocksInternalNode(node, config) {
|
|
7
|
+
return core.LiveObject.from(
|
|
8
|
+
node,
|
|
9
|
+
config
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function toLiveblocksInternalEdge(edge, config) {
|
|
13
|
+
return core.LiveObject.from(
|
|
14
|
+
edge,
|
|
15
|
+
config
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function toLiveblocksNode(node, config) {
|
|
19
|
+
return toLiveblocksInternalNode(node, {
|
|
20
|
+
...constants.NODE_BASE_CONFIG,
|
|
21
|
+
data: config
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function toLiveblocksEdge(edge, config) {
|
|
25
|
+
return toLiveblocksInternalEdge(edge, {
|
|
26
|
+
...constants.EDGE_BASE_CONFIG,
|
|
27
|
+
data: config
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.toLiveblocksEdge = toLiveblocksEdge;
|
|
32
|
+
exports.toLiveblocksInternalEdge = toLiveblocksInternalEdge;
|
|
33
|
+
exports.toLiveblocksInternalNode = toLiveblocksInternalNode;
|
|
34
|
+
exports.toLiveblocksNode = toLiveblocksNode;
|
|
35
|
+
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sources":["../src/helpers.ts"],"sourcesContent":["import type { JsonObject, SyncConfig } from \"@liveblocks/core\";\nimport { LiveObject } from \"@liveblocks/core\";\nimport type { Edge, Node } from \"@xyflow/react\";\n\nimport { EDGE_BASE_CONFIG, NODE_BASE_CONFIG } from \"./constants\";\nimport type {\n InternalLiveblocksEdge,\n InternalLiveblocksNode,\n LiveblocksEdge,\n LiveblocksNode,\n} from \"./types\";\n\nexport function toLiveblocksInternalNode<N extends Node>(\n node: N,\n config: SyncConfig\n): InternalLiveblocksNode {\n return LiveObject.from(\n node as unknown as JsonObject,\n config\n ) as InternalLiveblocksNode;\n}\n\nexport function toLiveblocksInternalEdge<E extends Edge>(\n edge: E,\n config: SyncConfig\n): InternalLiveblocksEdge {\n return LiveObject.from(\n edge as unknown as JsonObject,\n config\n ) as InternalLiveblocksEdge;\n}\n\n/**\n * @experimental\n *\n * Converts a React Flow `Node` into a Liveblocks Storage version.\n * Keys marked `false` in config are set as local-only (not synced).\n * Keys marked `\"atomic\"` are stored as plain Json (no deep wrapping).\n * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).\n */\nexport function toLiveblocksNode<N extends Node>(\n node: N,\n config?: SyncConfig\n): LiveblocksNode<N> {\n return toLiveblocksInternalNode(node, {\n ...NODE_BASE_CONFIG,\n data: config,\n }) as unknown as LiveblocksNode<N>;\n}\n\n/**\n * @experimental\n *\n * Converts a React Flow `Edge` into a Liveblocks Storage version.\n * Keys marked `false` in config are set as local-only (not synced).\n * Keys marked `\"atomic\"` are stored as plain Json (no deep wrapping).\n * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).\n */\nexport function toLiveblocksEdge<E extends Edge>(\n edge: E,\n config?: SyncConfig\n): LiveblocksEdge<E> {\n return toLiveblocksInternalEdge(edge, {\n ...EDGE_BASE_CONFIG,\n data: config,\n }) as unknown as LiveblocksEdge<E>;\n}\n"],"names":["LiveObject","NODE_BASE_CONFIG","EDGE_BASE_CONFIG"],"mappings":";;;;;AAYgB,SAAA,wBAAA,CACd,MACA,MACwB,EAAA;AACxB,EAAA,OAAOA,eAAW,CAAA,IAAA;AAAA,IAChB,IAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEgB,SAAA,wBAAA,CACd,MACA,MACwB,EAAA;AACxB,EAAA,OAAOA,eAAW,CAAA,IAAA;AAAA,IAChB,IAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF,CAAA;AAUgB,SAAA,gBAAA,CACd,MACA,MACmB,EAAA;AACnB,EAAA,OAAO,yBAAyB,IAAM,EAAA;AAAA,IACpC,GAAGC,0BAAA;AAAA,IACH,IAAM,EAAA,MAAA;AAAA,GACP,CAAA,CAAA;AACH,CAAA;AAUgB,SAAA,gBAAA,CACd,MACA,MACmB,EAAA;AACnB,EAAA,OAAO,yBAAyB,IAAM,EAAA;AAAA,IACpC,GAAGC,0BAAA;AAAA,IACH,IAAM,EAAA,MAAA;AAAA,GACP,CAAA,CAAA;AACH;;;;;;;"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LiveObject } from '@liveblocks/core';
|
|
2
|
+
import { NODE_BASE_CONFIG, EDGE_BASE_CONFIG } from './constants.js';
|
|
3
|
+
|
|
4
|
+
function toLiveblocksInternalNode(node, config) {
|
|
5
|
+
return LiveObject.from(
|
|
6
|
+
node,
|
|
7
|
+
config
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
function toLiveblocksInternalEdge(edge, config) {
|
|
11
|
+
return LiveObject.from(
|
|
12
|
+
edge,
|
|
13
|
+
config
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function toLiveblocksNode(node, config) {
|
|
17
|
+
return toLiveblocksInternalNode(node, {
|
|
18
|
+
...NODE_BASE_CONFIG,
|
|
19
|
+
data: config
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function toLiveblocksEdge(edge, config) {
|
|
23
|
+
return toLiveblocksInternalEdge(edge, {
|
|
24
|
+
...EDGE_BASE_CONFIG,
|
|
25
|
+
data: config
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { toLiveblocksEdge, toLiveblocksInternalEdge, toLiveblocksInternalNode, toLiveblocksNode };
|
|
30
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import type { JsonObject, SyncConfig } from \"@liveblocks/core\";\nimport { LiveObject } from \"@liveblocks/core\";\nimport type { Edge, Node } from \"@xyflow/react\";\n\nimport { EDGE_BASE_CONFIG, NODE_BASE_CONFIG } from \"./constants\";\nimport type {\n InternalLiveblocksEdge,\n InternalLiveblocksNode,\n LiveblocksEdge,\n LiveblocksNode,\n} from \"./types\";\n\nexport function toLiveblocksInternalNode<N extends Node>(\n node: N,\n config: SyncConfig\n): InternalLiveblocksNode {\n return LiveObject.from(\n node as unknown as JsonObject,\n config\n ) as InternalLiveblocksNode;\n}\n\nexport function toLiveblocksInternalEdge<E extends Edge>(\n edge: E,\n config: SyncConfig\n): InternalLiveblocksEdge {\n return LiveObject.from(\n edge as unknown as JsonObject,\n config\n ) as InternalLiveblocksEdge;\n}\n\n/**\n * @experimental\n *\n * Converts a React Flow `Node` into a Liveblocks Storage version.\n * Keys marked `false` in config are set as local-only (not synced).\n * Keys marked `\"atomic\"` are stored as plain Json (no deep wrapping).\n * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).\n */\nexport function toLiveblocksNode<N extends Node>(\n node: N,\n config?: SyncConfig\n): LiveblocksNode<N> {\n return toLiveblocksInternalNode(node, {\n ...NODE_BASE_CONFIG,\n data: config,\n }) as unknown as LiveblocksNode<N>;\n}\n\n/**\n * @experimental\n *\n * Converts a React Flow `Edge` into a Liveblocks Storage version.\n * Keys marked `false` in config are set as local-only (not synced).\n * Keys marked `\"atomic\"` are stored as plain Json (no deep wrapping).\n * All other keys are deep-liveified (objects→LiveObject, arrays→LiveList).\n */\nexport function toLiveblocksEdge<E extends Edge>(\n edge: E,\n config?: SyncConfig\n): LiveblocksEdge<E> {\n return toLiveblocksInternalEdge(edge, {\n ...EDGE_BASE_CONFIG,\n data: config,\n }) as unknown as LiveblocksEdge<E>;\n}\n"],"names":[],"mappings":";;;AAYgB,SAAA,wBAAA,CACd,MACA,MACwB,EAAA;AACxB,EAAA,OAAO,UAAW,CAAA,IAAA;AAAA,IAChB,IAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEgB,SAAA,wBAAA,CACd,MACA,MACwB,EAAA;AACxB,EAAA,OAAO,UAAW,CAAA,IAAA;AAAA,IAChB,IAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF,CAAA;AAUgB,SAAA,gBAAA,CACd,MACA,MACmB,EAAA;AACnB,EAAA,OAAO,yBAAyB,IAAM,EAAA;AAAA,IACpC,GAAG,gBAAA;AAAA,IACH,IAAM,EAAA,MAAA;AAAA,GACP,CAAA,CAAA;AACH,CAAA;AAUgB,SAAA,gBAAA,CACd,MACA,MACmB,EAAA;AACnB,EAAA,OAAO,yBAAyB,IAAM,EAAA;AAAA,IACpC,GAAG,gBAAA;AAAA,IACH,IAAM,EAAA,MAAA;AAAA,GACP,CAAA,CAAA;AACH;;;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -4,10 +4,12 @@ var core = require('@liveblocks/core');
|
|
|
4
4
|
var version = require('./version.cjs');
|
|
5
5
|
var cursors = require('./cursors.cjs');
|
|
6
6
|
var flow = require('./flow.cjs');
|
|
7
|
+
var helpers = require('./helpers.cjs');
|
|
7
8
|
|
|
8
9
|
core.detectDupes(version.PKG_NAME, version.PKG_VERSION, version.PKG_FORMAT);
|
|
9
10
|
|
|
10
11
|
exports.Cursors = cursors.Cursors;
|
|
11
|
-
exports.createLiveblocksFlow = flow.createLiveblocksFlow;
|
|
12
12
|
exports.useLiveblocksFlow = flow.useLiveblocksFlow;
|
|
13
|
+
exports.toLiveblocksEdge = helpers.toLiveblocksEdge;
|
|
14
|
+
exports.toLiveblocksNode = helpers.toLiveblocksNode;
|
|
13
15
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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 {
|
|
1
|
+
{"version":3,"file":"index.cjs","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":["detectDupes","PKG_NAME","PKG_VERSION","PKG_FORMAT"],"mappings":";;;;;;;;AAIAA,gBAAY,CAAAC,gBAAA,EAAUC,qBAAaC,kBAAU,CAAA;;;;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
-
import { LiveObject,
|
|
4
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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<
|
|
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<
|
|
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<
|
|
52
|
-
nodes: LiveMap<string, LiveblocksNode<
|
|
53
|
-
edges: LiveMap<string, LiveblocksEdge<
|
|
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
|
-
|
|
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:
|
|
61
|
-
edges:
|
|
103
|
+
nodes: N[];
|
|
104
|
+
edges: E[];
|
|
62
105
|
isLoading: false;
|
|
63
106
|
}) & {
|
|
64
|
-
onNodesChange: OnNodesChange<
|
|
65
|
-
onEdgesChange: OnEdgesChange<
|
|
107
|
+
onNodesChange: OnNodesChange<N>;
|
|
108
|
+
onEdgesChange: OnEdgesChange<E>;
|
|
66
109
|
onConnect: OnConnect;
|
|
110
|
+
onDelete: OnDelete<N, E>;
|
|
67
111
|
}>;
|
|
68
|
-
type
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
|
252
|
+
declare function toLiveblocksEdge<E extends Edge>(edge: E, config?: SyncConfig): LiveblocksEdge<E>;
|
|
149
253
|
|
|
150
|
-
export { Cursors, LiveblocksEdge, LiveblocksFlow, LiveblocksNode,
|
|
254
|
+
export { Cursors, CursorsCursorProps, CursorsProps, EdgeSyncConfig, LiveblocksEdge, LiveblocksFlow, LiveblocksNode, NodeSyncConfig, toLiveblocksEdge, toLiveblocksNode, useLiveblocksFlow };
|