@vuer-ai/vuer-rtc 0.0.1
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/client/EditBuffer.d.ts +43 -0
- package/dist/client/EditBuffer.d.ts.map +1 -0
- package/dist/client/EditBuffer.js +96 -0
- package/dist/client/EditBuffer.js.map +1 -0
- package/dist/client/actions.d.ts +66 -0
- package/dist/client/actions.d.ts.map +1 -0
- package/dist/client/actions.js +345 -0
- package/dist/client/actions.js.map +1 -0
- package/dist/client/createGraph.d.ts +30 -0
- package/dist/client/createGraph.d.ts.map +1 -0
- package/dist/client/createGraph.js +91 -0
- package/dist/client/createGraph.js.map +1 -0
- package/dist/client/hooks.d.ts +81 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +161 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +74 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +11 -0
- package/dist/client/types.js.map +1 -0
- package/dist/hooks.d.ts +8 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +7 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/operations/OperationTypes.d.ts +239 -0
- package/dist/operations/OperationTypes.d.ts.map +1 -0
- package/dist/operations/OperationTypes.js +10 -0
- package/dist/operations/OperationTypes.js.map +1 -0
- package/dist/operations/OperationValidator.d.ts +32 -0
- package/dist/operations/OperationValidator.d.ts.map +1 -0
- package/dist/operations/OperationValidator.js +208 -0
- package/dist/operations/OperationValidator.js.map +1 -0
- package/dist/operations/apply/array.d.ts +22 -0
- package/dist/operations/apply/array.d.ts.map +1 -0
- package/dist/operations/apply/array.js +64 -0
- package/dist/operations/apply/array.js.map +1 -0
- package/dist/operations/apply/boolean.d.ts +18 -0
- package/dist/operations/apply/boolean.d.ts.map +1 -0
- package/dist/operations/apply/boolean.js +34 -0
- package/dist/operations/apply/boolean.js.map +1 -0
- package/dist/operations/apply/color.d.ts +14 -0
- package/dist/operations/apply/color.d.ts.map +1 -0
- package/dist/operations/apply/color.js +46 -0
- package/dist/operations/apply/color.js.map +1 -0
- package/dist/operations/apply/index.d.ts +18 -0
- package/dist/operations/apply/index.d.ts.map +1 -0
- package/dist/operations/apply/index.js +26 -0
- package/dist/operations/apply/index.js.map +1 -0
- package/dist/operations/apply/node.d.ts +24 -0
- package/dist/operations/apply/node.d.ts.map +1 -0
- package/dist/operations/apply/node.js +77 -0
- package/dist/operations/apply/node.js.map +1 -0
- package/dist/operations/apply/number.d.ts +26 -0
- package/dist/operations/apply/number.d.ts.map +1 -0
- package/dist/operations/apply/number.js +54 -0
- package/dist/operations/apply/number.js.map +1 -0
- package/dist/operations/apply/object.d.ts +14 -0
- package/dist/operations/apply/object.d.ts.map +1 -0
- package/dist/operations/apply/object.js +47 -0
- package/dist/operations/apply/object.js.map +1 -0
- package/dist/operations/apply/quaternion.d.ts +15 -0
- package/dist/operations/apply/quaternion.d.ts.map +1 -0
- package/dist/operations/apply/quaternion.js +33 -0
- package/dist/operations/apply/quaternion.js.map +1 -0
- package/dist/operations/apply/string.d.ts +14 -0
- package/dist/operations/apply/string.d.ts.map +1 -0
- package/dist/operations/apply/string.js +26 -0
- package/dist/operations/apply/string.js.map +1 -0
- package/dist/operations/apply/types.d.ts +34 -0
- package/dist/operations/apply/types.d.ts.map +1 -0
- package/dist/operations/apply/types.js +32 -0
- package/dist/operations/apply/types.js.map +1 -0
- package/dist/operations/apply/vector3.d.ts +18 -0
- package/dist/operations/apply/vector3.d.ts.map +1 -0
- package/dist/operations/apply/vector3.js +44 -0
- package/dist/operations/apply/vector3.js.map +1 -0
- package/dist/operations/dispatcher.d.ts +35 -0
- package/dist/operations/dispatcher.d.ts.map +1 -0
- package/dist/operations/dispatcher.js +107 -0
- package/dist/operations/dispatcher.js.map +1 -0
- package/dist/operations/index.d.ts +10 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/state/ConflictResolver.d.ts +36 -0
- package/dist/state/ConflictResolver.d.ts.map +1 -0
- package/dist/state/ConflictResolver.js +167 -0
- package/dist/state/ConflictResolver.js.map +1 -0
- package/dist/state/DType.d.ts +160 -0
- package/dist/state/DType.d.ts.map +1 -0
- package/dist/state/DType.js +282 -0
- package/dist/state/DType.js.map +1 -0
- package/dist/state/Schema.d.ts +32 -0
- package/dist/state/Schema.d.ts.map +1 -0
- package/dist/state/Schema.js +175 -0
- package/dist/state/Schema.js.map +1 -0
- package/dist/state/VectorClock.d.ts +42 -0
- package/dist/state/VectorClock.d.ts.map +1 -0
- package/dist/state/VectorClock.js +84 -0
- package/dist/state/VectorClock.js.map +1 -0
- package/dist/state/index.d.ts +11 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +13 -0
- package/dist/state/index.js.map +1 -0
- package/docs/OPERATION_HINTS.md +222 -0
- package/docs/SCENE_GRAPH.md +373 -0
- package/docs/TYPE_BEHAVIORS.md +348 -0
- package/examples/01-basic-usage.ts +139 -0
- package/examples/02-concurrent-edits.ts +208 -0
- package/examples/03-scene-building.ts +258 -0
- package/examples/04-conflict-resolution.ts +339 -0
- package/examples/README.md +86 -0
- package/jest.config.js +19 -0
- package/package.json +57 -0
- package/src/client/EditBuffer.ts +105 -0
- package/src/client/actions.ts +397 -0
- package/src/client/createGraph.ts +132 -0
- package/src/client/hooks.tsx +249 -0
- package/src/client/index.ts +35 -0
- package/src/client/types.ts +94 -0
- package/src/hooks.ts +20 -0
- package/src/index.ts +14 -0
- package/src/operations/OperationTypes.ts +340 -0
- package/src/operations/OperationValidator.ts +260 -0
- package/src/operations/apply/array.ts +84 -0
- package/src/operations/apply/boolean.ts +48 -0
- package/src/operations/apply/color.ts +65 -0
- package/src/operations/apply/index.ts +37 -0
- package/src/operations/apply/node.ts +98 -0
- package/src/operations/apply/number.ts +76 -0
- package/src/operations/apply/object.ts +63 -0
- package/src/operations/apply/quaternion.ts +47 -0
- package/src/operations/apply/string.ts +36 -0
- package/src/operations/apply/types.ts +66 -0
- package/src/operations/apply/vector3.ts +60 -0
- package/src/operations/dispatcher.ts +127 -0
- package/src/operations/index.ts +80 -0
- package/src/state/ConflictResolver.ts +205 -0
- package/src/state/DType.ts +333 -0
- package/src/state/Schema.ts +236 -0
- package/src/state/VectorClock.ts +98 -0
- package/src/state/index.ts +14 -0
- package/tests/client/actions.test.ts +371 -0
- package/tests/client/edit-buffer.test.ts +117 -0
- package/tests/fixtures/array-ops.jsonl +6 -0
- package/tests/fixtures/boolean-ops.jsonl +6 -0
- package/tests/fixtures/color-ops.jsonl +4 -0
- package/tests/fixtures/edit-buffer.jsonl +3 -0
- package/tests/fixtures/node-ops.jsonl +6 -0
- package/tests/fixtures/number-ops.jsonl +7 -0
- package/tests/fixtures/object-ops.jsonl +4 -0
- package/tests/fixtures/operations.jsonl +7 -0
- package/tests/fixtures/string-ops.jsonl +4 -0
- package/tests/fixtures/undo-redo.jsonl +3 -0
- package/tests/fixtures/vector-ops.jsonl +9 -0
- package/tests/operations/collections.test.ts +193 -0
- package/tests/operations/nodes.test.ts +228 -0
- package/tests/operations/primitives.test.ts +222 -0
- package/tests/operations/vectors.test.ts +150 -0
- package/tsconfig.json +21 -0
- package/tsconfig.test.json +9 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createGraph - Factory function for creating a graph store
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const store = createGraph({
|
|
7
|
+
* sessionId: 'my-session',
|
|
8
|
+
* onSend: (msg) => websocket.send(msg),
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* store.edit({ otype: 'vector3.add', key: 'cube', path: 'position', value: [1, 0, 0] });
|
|
12
|
+
* store.commit('Move cube');
|
|
13
|
+
* store.undo();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { enableMapSet } from 'immer';
|
|
17
|
+
import { createInitialState, onEdit, commitEdits, onServerAck, onRemoteMessage, undo, redo, compact, initFromServer, } from './actions.js';
|
|
18
|
+
// Enable immer support for Map and Set
|
|
19
|
+
enableMapSet();
|
|
20
|
+
/**
|
|
21
|
+
* Create a graph store
|
|
22
|
+
*/
|
|
23
|
+
export function createGraph(options) {
|
|
24
|
+
let state = createInitialState(options.sessionId, options.initialSnapshot);
|
|
25
|
+
const listeners = new Set();
|
|
26
|
+
function dispatch(fn) {
|
|
27
|
+
state = fn(state);
|
|
28
|
+
options.onStateChange?.(state);
|
|
29
|
+
listeners.forEach(l => l());
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
// State access
|
|
33
|
+
getState: () => state,
|
|
34
|
+
subscribe: (listener) => {
|
|
35
|
+
listeners.add(listener);
|
|
36
|
+
return () => listeners.delete(listener);
|
|
37
|
+
},
|
|
38
|
+
// Edit operations
|
|
39
|
+
edit: (op) => {
|
|
40
|
+
dispatch(s => onEdit(s, op));
|
|
41
|
+
},
|
|
42
|
+
commit: (_description) => {
|
|
43
|
+
const result = commitEdits(state, _description);
|
|
44
|
+
dispatch(() => result.state);
|
|
45
|
+
if (result.msg) {
|
|
46
|
+
options.onSend?.(result.msg);
|
|
47
|
+
}
|
|
48
|
+
return result.msg;
|
|
49
|
+
},
|
|
50
|
+
// Server communication
|
|
51
|
+
receive: (msg) => {
|
|
52
|
+
dispatch(s => onRemoteMessage(s, msg));
|
|
53
|
+
},
|
|
54
|
+
ack: (msgId) => {
|
|
55
|
+
dispatch(s => onServerAck(s, msgId));
|
|
56
|
+
},
|
|
57
|
+
// Undo/redo
|
|
58
|
+
undo: () => {
|
|
59
|
+
const result = undo(state);
|
|
60
|
+
dispatch(() => result.state);
|
|
61
|
+
if (result.msg) {
|
|
62
|
+
options.onSend?.(result.msg);
|
|
63
|
+
}
|
|
64
|
+
return { msg: result.msg };
|
|
65
|
+
},
|
|
66
|
+
redo: () => {
|
|
67
|
+
const result = redo(state);
|
|
68
|
+
dispatch(() => result.state);
|
|
69
|
+
if (result.msg) {
|
|
70
|
+
options.onSend?.(result.msg);
|
|
71
|
+
}
|
|
72
|
+
return { msg: result.msg };
|
|
73
|
+
},
|
|
74
|
+
// Maintenance
|
|
75
|
+
compact: () => {
|
|
76
|
+
dispatch(s => compact(s));
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a graph store initialized from server state
|
|
82
|
+
*/
|
|
83
|
+
export function createGraphFromServer(options) {
|
|
84
|
+
const store = createGraph(options);
|
|
85
|
+
// Replace state with server-initialized state
|
|
86
|
+
const serverState = initFromServer(options.sessionId, options.snapshot, options.journal);
|
|
87
|
+
// Hack: directly set state (since we don't expose setState)
|
|
88
|
+
store._state = serverState;
|
|
89
|
+
return store;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=createGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGraph.js","sourceRoot":"","sources":["../../src/client/createGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,WAAW,EAEX,WAAW,EACX,eAAe,EACf,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,uCAAuC;AACvC,YAAY,EAAE,CAAC;AAEf;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,IAAI,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3E,MAAM,S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C;IAEpC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Hooks for vuer-rtc
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* ```tsx
|
|
6
|
+
* function App() {
|
|
7
|
+
* return (
|
|
8
|
+
* <GraphProvider sessionId="my-session" onSend={sendToServer}>
|
|
9
|
+
* <Scene />
|
|
10
|
+
* </GraphProvider>
|
|
11
|
+
* );
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* function Scene() {
|
|
15
|
+
* const graph = useGraph();
|
|
16
|
+
* const { edit, commit, undo, redo } = useGraphActions();
|
|
17
|
+
* // ...
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import React, { type ReactNode } from 'react';
|
|
22
|
+
import type { CRDTMessage, Operation, SceneGraph, SceneNode } from '../operations/OperationTypes.js';
|
|
23
|
+
import { type GraphStore, type Snapshot } from './createGraph.js';
|
|
24
|
+
export interface GraphProviderProps {
|
|
25
|
+
sessionId: string;
|
|
26
|
+
initialSnapshot?: Snapshot;
|
|
27
|
+
onSend?: (msg: CRDTMessage) => void;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export declare function GraphProvider({ sessionId, initialSnapshot, onSend, children, }: GraphProviderProps): React.ReactElement;
|
|
31
|
+
/**
|
|
32
|
+
* Get the graph store
|
|
33
|
+
*/
|
|
34
|
+
export declare function useGraphStore(): GraphStore;
|
|
35
|
+
/**
|
|
36
|
+
* Get the current graph (reactive)
|
|
37
|
+
*/
|
|
38
|
+
export declare function useGraph(): SceneGraph;
|
|
39
|
+
/**
|
|
40
|
+
* Get a specific node (reactive)
|
|
41
|
+
*/
|
|
42
|
+
export declare function useNode(key: string): SceneNode | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Get node property (reactive)
|
|
45
|
+
*/
|
|
46
|
+
export declare function useNodeProperty<T>(key: string, path: string): T | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Get graph actions
|
|
49
|
+
*/
|
|
50
|
+
export declare function useGraphActions(): {
|
|
51
|
+
edit: (op: Operation) => void;
|
|
52
|
+
commit: (description?: string) => CRDTMessage | null;
|
|
53
|
+
undo: () => {
|
|
54
|
+
msg: CRDTMessage | null;
|
|
55
|
+
};
|
|
56
|
+
redo: () => {
|
|
57
|
+
msg: CRDTMessage | null;
|
|
58
|
+
};
|
|
59
|
+
receive: (msg: CRDTMessage) => void;
|
|
60
|
+
ack: (msgId: string) => void;
|
|
61
|
+
compact: () => void;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Hook for drag operations
|
|
65
|
+
*
|
|
66
|
+
* Usage:
|
|
67
|
+
* ```tsx
|
|
68
|
+
* const { onDragStart, onDrag, onDragEnd, isDragging } = useDrag('cube', 'position');
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function useDrag(nodeKey: string, path: string): {
|
|
72
|
+
isDragging: boolean;
|
|
73
|
+
onDragStart: () => void;
|
|
74
|
+
onDrag: (delta: [number, number, number]) => void;
|
|
75
|
+
onDragEnd: () => void;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Hook for undo/redo keyboard shortcuts
|
|
79
|
+
*/
|
|
80
|
+
export declare function useUndoRedoShortcuts(): void;
|
|
81
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/client/hooks.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAY/E,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;IACpC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,GACT,EAAE,kBAAkB,GAAG,KAAK,CAAC,YAAY,CAczC;AAMD;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAM1C;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,UAAU,CAOrC;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAO1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAa3E;AAED;;GAEG;AACH,wBAAgB,eAAe;eAItB,SAAS;2BAOC,MAAM;;;;;;;mBAef,WAAW;iBAOT,MAAM;;EAsBjB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;oBASzC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;;EAoBnC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,SAkBnC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* React Hooks for vuer-rtc
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function App() {
|
|
8
|
+
* return (
|
|
9
|
+
* <GraphProvider sessionId="my-session" onSend={sendToServer}>
|
|
10
|
+
* <Scene />
|
|
11
|
+
* </GraphProvider>
|
|
12
|
+
* );
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* function Scene() {
|
|
16
|
+
* const graph = useGraph();
|
|
17
|
+
* const { edit, commit, undo, redo } = useGraphActions();
|
|
18
|
+
* // ...
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import React, { createContext, useContext, useState, useCallback, useSyncExternalStore, useMemo, } from 'react';
|
|
23
|
+
import { createGraph } from './createGraph.js';
|
|
24
|
+
// ===========================================
|
|
25
|
+
// Context
|
|
26
|
+
// ===========================================
|
|
27
|
+
const GraphContext = createContext(null);
|
|
28
|
+
export function GraphProvider({ sessionId, initialSnapshot, onSend, children, }) {
|
|
29
|
+
const [store] = useState(() => createGraph({
|
|
30
|
+
sessionId,
|
|
31
|
+
initialSnapshot,
|
|
32
|
+
onSend,
|
|
33
|
+
}));
|
|
34
|
+
return (_jsx(GraphContext.Provider, { value: store, children: children }));
|
|
35
|
+
}
|
|
36
|
+
// ===========================================
|
|
37
|
+
// Hooks
|
|
38
|
+
// ===========================================
|
|
39
|
+
/**
|
|
40
|
+
* Get the graph store
|
|
41
|
+
*/
|
|
42
|
+
export function useGraphStore() {
|
|
43
|
+
const store = useContext(GraphContext);
|
|
44
|
+
if (!store) {
|
|
45
|
+
throw new Error('useGraphStore must be used within a GraphProvider');
|
|
46
|
+
}
|
|
47
|
+
return store;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the current graph (reactive)
|
|
51
|
+
*/
|
|
52
|
+
export function useGraph() {
|
|
53
|
+
const store = useGraphStore();
|
|
54
|
+
return useSyncExternalStore(store.subscribe, () => store.getState().graph, () => store.getState().graph);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get a specific node (reactive)
|
|
58
|
+
*/
|
|
59
|
+
export function useNode(key) {
|
|
60
|
+
const store = useGraphStore();
|
|
61
|
+
return useSyncExternalStore(store.subscribe, () => store.getState().graph.nodes[key], () => store.getState().graph.nodes[key]);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get node property (reactive)
|
|
65
|
+
*/
|
|
66
|
+
export function useNodeProperty(key, path) {
|
|
67
|
+
const store = useGraphStore();
|
|
68
|
+
return useSyncExternalStore(store.subscribe, () => {
|
|
69
|
+
const node = store.getState().graph.nodes[key];
|
|
70
|
+
return node ? node[path] : undefined;
|
|
71
|
+
}, () => {
|
|
72
|
+
const node = store.getState().graph.nodes[key];
|
|
73
|
+
return node ? node[path] : undefined;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get graph actions
|
|
78
|
+
*/
|
|
79
|
+
export function useGraphActions() {
|
|
80
|
+
const store = useGraphStore();
|
|
81
|
+
const edit = useCallback((op) => {
|
|
82
|
+
store.edit(op);
|
|
83
|
+
}, [store]);
|
|
84
|
+
const commit = useCallback((description) => {
|
|
85
|
+
return store.commit(description);
|
|
86
|
+
}, [store]);
|
|
87
|
+
const undoAction = useCallback(() => {
|
|
88
|
+
return store.undo();
|
|
89
|
+
}, [store]);
|
|
90
|
+
const redoAction = useCallback(() => {
|
|
91
|
+
return store.redo();
|
|
92
|
+
}, [store]);
|
|
93
|
+
const receive = useCallback((msg) => {
|
|
94
|
+
store.receive(msg);
|
|
95
|
+
}, [store]);
|
|
96
|
+
const ack = useCallback((msgId) => {
|
|
97
|
+
store.ack(msgId);
|
|
98
|
+
}, [store]);
|
|
99
|
+
const compact = useCallback(() => {
|
|
100
|
+
store.compact();
|
|
101
|
+
}, [store]);
|
|
102
|
+
return useMemo(() => ({
|
|
103
|
+
edit,
|
|
104
|
+
commit,
|
|
105
|
+
undo: undoAction,
|
|
106
|
+
redo: redoAction,
|
|
107
|
+
receive,
|
|
108
|
+
ack,
|
|
109
|
+
compact,
|
|
110
|
+
}), [edit, commit, undoAction, redoAction, receive, ack, compact]);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Hook for drag operations
|
|
114
|
+
*
|
|
115
|
+
* Usage:
|
|
116
|
+
* ```tsx
|
|
117
|
+
* const { onDragStart, onDrag, onDragEnd, isDragging } = useDrag('cube', 'position');
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function useDrag(nodeKey, path) {
|
|
121
|
+
const { edit, commit } = useGraphActions();
|
|
122
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
123
|
+
const onDragStart = useCallback(() => {
|
|
124
|
+
setIsDragging(true);
|
|
125
|
+
}, []);
|
|
126
|
+
const onDrag = useCallback((delta) => {
|
|
127
|
+
edit({
|
|
128
|
+
otype: 'vector3.add',
|
|
129
|
+
key: nodeKey,
|
|
130
|
+
path,
|
|
131
|
+
value: delta,
|
|
132
|
+
});
|
|
133
|
+
}, [edit, nodeKey, path]);
|
|
134
|
+
const onDragEnd = useCallback(() => {
|
|
135
|
+
setIsDragging(false);
|
|
136
|
+
commit(`Move ${nodeKey}`);
|
|
137
|
+
}, [commit, nodeKey]);
|
|
138
|
+
return useMemo(() => ({ isDragging, onDragStart, onDrag, onDragEnd }), [isDragging, onDragStart, onDrag, onDragEnd]);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Hook for undo/redo keyboard shortcuts
|
|
142
|
+
*/
|
|
143
|
+
export function useUndoRedoShortcuts() {
|
|
144
|
+
const { undo, redo } = useGraphActions();
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
const handleKeyDown = (e) => {
|
|
147
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'z') {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
if (e.shiftKey) {
|
|
150
|
+
redo();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
undo();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
158
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
159
|
+
}, [undo, redo]);
|
|
160
|
+
}
|
|
161
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AC9C,CAAC,CAAC,cAAc,EAAE,CAAC;gBACnB,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;oBACf,IAAI,EAAE,CAAC;gBACT,CAAC;qBAAM,CAAC;oBACN,IAAI,EAAE,CAAC;gBACT,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client module exports
|
|
3
|
+
*/
|
|
4
|
+
export type { ClientState, JournalEntry, EditBuffer, Snapshot, CreateGraphOptions, GraphStore, } from './types.js';
|
|
5
|
+
export { createGraph, createGraphFromServer } from './createGraph.js';
|
|
6
|
+
export { createInitialState, rebuildGraph, onEdit, commitEdits, cancelEdits, onServerAck, onRemoteMessage, undo, redo, compact, initFromServer, generateUUID, } from './actions.js';
|
|
7
|
+
export { isAdditiveOp, mergeValues, EditBufferImpl } from './EditBuffer.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGtE,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,EACf,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,cAAc,EACd,YAAY,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client module exports
|
|
3
|
+
*/
|
|
4
|
+
// Factory
|
|
5
|
+
export { createGraph, createGraphFromServer } from './createGraph.js';
|
|
6
|
+
// Actions (for advanced usage)
|
|
7
|
+
export { createInitialState, rebuildGraph, onEdit, commitEdits, cancelEdits, onServerAck, onRemoteMessage, undo, redo, compact, initFromServer, generateUUID, } from './actions.js';
|
|
8
|
+
// Edit buffer utilities
|
|
9
|
+
export { isAdditiveOp, mergeValues, EditBufferImpl } from './EditBuffer.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,+BAA+B;AAC/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,EACf,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,cAAc,EACd,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,wBAAwB;AACxB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client State Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the state model for CRDT clients with:
|
|
5
|
+
* - graph: current computed state
|
|
6
|
+
* - journal: committed messages with ack and deletedAt
|
|
7
|
+
* - edits: uncommitted operations (edit buffer)
|
|
8
|
+
* - snapshot: checkpoint for fast replay
|
|
9
|
+
*/
|
|
10
|
+
import type { CRDTMessage, Operation, SceneGraph } from '../operations/OperationTypes.js';
|
|
11
|
+
import type { VectorClock } from '../state/VectorClock.js';
|
|
12
|
+
/**
|
|
13
|
+
* Journal entry - a committed message with metadata
|
|
14
|
+
*/
|
|
15
|
+
export interface JournalEntry {
|
|
16
|
+
msg: CRDTMessage;
|
|
17
|
+
ack: boolean;
|
|
18
|
+
deletedAt?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Edit buffer - uncommitted operations
|
|
22
|
+
*/
|
|
23
|
+
export interface EditBuffer {
|
|
24
|
+
ops: Operation[];
|
|
25
|
+
startGraph: SceneGraph | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Snapshot - checkpoint for fast replay
|
|
29
|
+
*/
|
|
30
|
+
export interface Snapshot {
|
|
31
|
+
graph: SceneGraph;
|
|
32
|
+
vectorClock: VectorClock;
|
|
33
|
+
journalIndex: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Client state - complete client-side state
|
|
37
|
+
*/
|
|
38
|
+
export interface ClientState {
|
|
39
|
+
graph: SceneGraph;
|
|
40
|
+
journal: JournalEntry[];
|
|
41
|
+
edits: EditBuffer;
|
|
42
|
+
snapshot: Snapshot;
|
|
43
|
+
lamportTime: number;
|
|
44
|
+
vectorClock: VectorClock;
|
|
45
|
+
sessionId: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for creating a graph store
|
|
49
|
+
*/
|
|
50
|
+
export interface CreateGraphOptions {
|
|
51
|
+
sessionId: string;
|
|
52
|
+
initialSnapshot?: Snapshot;
|
|
53
|
+
onSend?: (msg: CRDTMessage) => void;
|
|
54
|
+
onStateChange?: (state: ClientState) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Graph store - the public API
|
|
58
|
+
*/
|
|
59
|
+
export interface GraphStore {
|
|
60
|
+
getState: () => ClientState;
|
|
61
|
+
subscribe: (listener: () => void) => () => void;
|
|
62
|
+
edit: (op: Operation) => void;
|
|
63
|
+
commit: (description?: string) => CRDTMessage | null;
|
|
64
|
+
receive: (msg: CRDTMessage) => void;
|
|
65
|
+
ack: (msgId: string) => void;
|
|
66
|
+
undo: () => {
|
|
67
|
+
msg: CRDTMessage | null;
|
|
68
|
+
};
|
|
69
|
+
redo: () => {
|
|
70
|
+
msg: CRDTMessage | null;
|
|
71
|
+
};
|
|
72
|
+
compact: () => void;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,WAAW,CAAC;IACjB,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,SAAS,EAAE,CAAC;IACjB,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAE1B,KAAK,EAAE,UAAU,CAAC;IAGlB,OAAO,EAAE,YAAY,EAAE,CAAC;IAGxB,KAAK,EAAE,UAAU,CAAC;IAGlB,QAAQ,EAAE,QAAQ,CAAC;IAGnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;IACpC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAEzB,QAAQ,EAAE,MAAM,WAAW,CAAC;IAC5B,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAGhD,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,IAAI,CAAC;IAC9B,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,CAAC;IAGrD,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;IACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAG7B,IAAI,EAAE,MAAM;QAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAA;KAAE,CAAC;IACxC,IAAI,EAAE,MAAM;QAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAA;KAAE,CAAC;IAGxC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client State Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the state model for CRDT clients with:
|
|
5
|
+
* - graph: current computed state
|
|
6
|
+
* - journal: committed messages with ack and deletedAt
|
|
7
|
+
* - edits: uncommitted operations (edit buffer)
|
|
8
|
+
* - snapshot: checkpoint for fast replay
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for @vuer-ai/vuer-rtc
|
|
3
|
+
*
|
|
4
|
+
* Import from '@vuer-ai/vuer-rtc/hooks'
|
|
5
|
+
*/
|
|
6
|
+
export { GraphProvider, useGraphStore, useGraph, useNode, useNodeProperty, useGraphActions, useDrag, useUndoRedoShortcuts, type GraphProviderProps, } from './client/hooks.js';
|
|
7
|
+
export type { GraphStore, ClientState, Snapshot } from './client/types.js';
|
|
8
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,OAAO,EACP,eAAe,EACf,eAAe,EACf,OAAO,EACP,oBAAoB,EACpB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hooks for @vuer-ai/vuer-rtc
|
|
3
|
+
*
|
|
4
|
+
* Import from '@vuer-ai/vuer-rtc/hooks'
|
|
5
|
+
*/
|
|
6
|
+
export { GraphProvider, useGraphStore, useGraph, useNode, useNodeProperty, useGraphActions, useDrag, useUndoRedoShortcuts, } from './client/hooks.js';
|
|
7
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,OAAO,EACP,eAAe,EACf,eAAe,EACf,OAAO,EACP,oBAAoB,GAErB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,uBAAuB,CAAC;AAGtC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vuer-ai/vuer-rtc
|
|
3
|
+
*
|
|
4
|
+
* CRDT-based real-time collaborative data structures
|
|
5
|
+
*/
|
|
6
|
+
// Operations
|
|
7
|
+
export * from './operations/index.js';
|
|
8
|
+
// State utilities
|
|
9
|
+
export * from './state/index.js';
|
|
10
|
+
// Client (state management, createGraph, etc.)
|
|
11
|
+
export * from './client/index.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,aAAa;AACb,cAAc,uBAAuB,CAAC;AAEtC,kBAAkB;AAClB,cAAc,kBAAkB,CAAC;AAEjC,+CAA+C;AAC/C,cAAc,mBAAmB,CAAC"}
|