@allternit/ix 0.1.0 → 0.1.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/README.md +6 -6
- package/dist/adapters/json-render.d.ts +5 -5
- package/dist/adapters/json-render.js +12 -12
- package/dist/collab/visual-editor.d.ts +1 -1
- package/dist/collab/visual-editor.js +4 -4
- package/dist/collab/visual-editor.js.map +1 -1
- package/dist/collab/yjs-adapter.d.ts +1 -1
- package/dist/collab/yjs-adapter.js +2 -2
- package/dist/collab/yjs-adapter.js.map +1 -1
- package/dist/collab/yjs-client.js +1 -1
- package/dist/collab/yjs-client.js.map +1 -1
- package/dist/collab/yjs-types.js +1 -1
- package/dist/collab/yjs-types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pipeline/llm-to-ix.d.ts +5 -5
- package/dist/pipeline/llm-to-ix.d.ts.map +1 -1
- package/dist/pipeline/llm-to-ix.js +6 -6
- package/dist/react/renderer.d.ts +2 -2
- package/dist/react/renderer.js +3 -3
- package/dist/react/renderer.js.map +1 -1
- package/dist/renderer/renderer.d.ts +1 -1
- package/dist/renderer/renderer.js +1 -1
- package/dist/runtime/capsule-runtime.d.ts +1 -1
- package/dist/runtime/capsule-runtime.js +1 -1
- package/dist/sdk/api.d.ts +3 -3
- package/dist/sdk/api.js +3 -3
- package/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/react.d.ts +2 -2
- package/dist/sdk/react.js +2 -2
- package/dist/state/index.d.ts +1 -1
- package/dist/state/index.js +1 -1
- package/dist/state/store.d.ts +1 -1
- package/dist/state/store.js +3 -3
- package/dist/state/store.js.map +1 -1
- package/dist/svelte/index.d.ts +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/svelte/renderer.d.ts +3 -3
- package/dist/svelte/renderer.js +4 -4
- package/dist/svelte/renderer.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/vue/renderer.d.ts +3 -3
- package/dist/vue/renderer.js +5 -5
- package/dist/vue/renderer.js.map +1 -1
- package/package.json +8 -8
- package/dist/adapters/json-render.d.ts.bak +0 -211
- package/dist/adapters/json-render.js.bak +0 -576
- package/dist/catalog/registry.d.ts.bak +0 -65
- package/dist/catalog/registry.js.bak +0 -388
- package/dist/collab/capsule-registry.d.ts.bak +0 -114
- package/dist/collab/capsule-registry.js.bak +0 -271
- package/dist/collab/index.d.ts.bak +0 -21
- package/dist/collab/index.js.bak +0 -32
- package/dist/collab/visual-editor.d.ts.bak +0 -199
- package/dist/collab/visual-editor.js.bak +0 -259
- package/dist/collab/yjs-adapter.d.ts.bak +0 -95
- package/dist/collab/yjs-adapter.js.bak +0 -282
- package/dist/collab/yjs-client.d.ts.bak +0 -101
- package/dist/collab/yjs-client.js.bak +0 -193
- package/dist/collab/yjs-protocols.d.ts.bak +0 -128
- package/dist/collab/yjs-protocols.js.bak +0 -245
- package/dist/collab/yjs-types.d.ts.bak +0 -201
- package/dist/collab/yjs-types.js.bak +0 -45
- package/dist/index.d.ts.bak +0 -38
- package/dist/index.js.bak +0 -48
- package/dist/pipeline/llm-to-ix.d.ts.bak +0 -249
- package/dist/pipeline/llm-to-ix.js.bak +0 -992
- package/dist/react/index.d.ts.bak +0 -18
- package/dist/react/index.js.bak +0 -18
- package/dist/react/renderer.d.ts.bak +0 -47
- package/dist/react/renderer.js.bak +0 -420
- package/dist/renderer/renderer.d.ts.bak +0 -55
- package/dist/renderer/renderer.js.bak +0 -232
- package/dist/runtime/capsule-runtime.d.ts.bak +0 -227
- package/dist/runtime/capsule-runtime.js.bak +0 -563
- package/dist/runtime/policy-gates.d.ts.bak +0 -116
- package/dist/runtime/policy-gates.js.bak +0 -317
- package/dist/schema/ui-ir.d.ts.bak +0 -26
- package/dist/schema/ui-ir.js.bak +0 -51
- package/dist/sdk/api.d.ts.bak +0 -101
- package/dist/sdk/api.js.bak +0 -177
- package/dist/sdk/index.d.ts.bak +0 -9
- package/dist/sdk/index.js.bak +0 -10
- package/dist/sdk/react.d.ts.bak +0 -63
- package/dist/sdk/react.js.bak +0 -161
- package/dist/state/index.d.ts.bak +0 -8
- package/dist/state/index.js.bak +0 -8
- package/dist/state/patch.d.ts.bak +0 -73
- package/dist/state/patch.js.bak +0 -437
- package/dist/state/store.d.ts.bak +0 -50
- package/dist/state/store.js.bak +0 -246
- package/dist/svelte/index.d.ts.bak +0 -15
- package/dist/svelte/index.js.bak +0 -15
- package/dist/svelte/renderer.d.ts.bak +0 -35
- package/dist/svelte/renderer.js.bak +0 -317
- package/dist/types/index.d.ts.bak +0 -349
- package/dist/types/index.js.bak +0 -152
- package/dist/vue/index.d.ts.bak +0 -18
- package/dist/vue/index.js.bak +0 -18
- package/dist/vue/renderer.d.ts.bak +0 -46
- package/dist/vue/renderer.js.bak +0 -302
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* YJS Client Setup - GAP-65
|
|
3
|
-
*
|
|
4
|
-
* Collaborative editing client using YJS CRDTs
|
|
5
|
-
*/
|
|
6
|
-
import * as Y from 'yjs';
|
|
7
|
-
import { WebrtcProvider } from 'y-webrtc';
|
|
8
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
9
|
-
export interface YjsConfig {
|
|
10
|
-
signalingUrls: string[];
|
|
11
|
-
iceServers: RTCIceServer[];
|
|
12
|
-
roomPrefix: string;
|
|
13
|
-
maxPeers?: number;
|
|
14
|
-
}
|
|
15
|
-
export interface CollaborationSession {
|
|
16
|
-
roomId: string;
|
|
17
|
-
participants: Participant[];
|
|
18
|
-
doc: Y.Doc;
|
|
19
|
-
provider: WebrtcProvider;
|
|
20
|
-
awareness: Awareness;
|
|
21
|
-
}
|
|
22
|
-
export interface Participant {
|
|
23
|
-
id: string;
|
|
24
|
-
name: string;
|
|
25
|
-
color: string;
|
|
26
|
-
cursor?: CursorPosition;
|
|
27
|
-
selection?: Range;
|
|
28
|
-
}
|
|
29
|
-
export interface CursorPosition {
|
|
30
|
-
x: number;
|
|
31
|
-
y: number;
|
|
32
|
-
line?: number;
|
|
33
|
-
ch?: number;
|
|
34
|
-
}
|
|
35
|
-
export interface Range {
|
|
36
|
-
anchor: CursorPosition;
|
|
37
|
-
head: CursorPosition;
|
|
38
|
-
}
|
|
39
|
-
export declare class YjsClient {
|
|
40
|
-
private doc;
|
|
41
|
-
private provider;
|
|
42
|
-
private awareness;
|
|
43
|
-
private config;
|
|
44
|
-
private roomId;
|
|
45
|
-
private session;
|
|
46
|
-
constructor(roomId: string, config: YjsConfig);
|
|
47
|
-
private setupProvider;
|
|
48
|
-
private setupAwareness;
|
|
49
|
-
private handleAwarenessChange;
|
|
50
|
-
private generateUserId;
|
|
51
|
-
private generateColor;
|
|
52
|
-
/**
|
|
53
|
-
* Get shared text for collaborative editing
|
|
54
|
-
*/
|
|
55
|
-
getText(name?: string): Y.Text;
|
|
56
|
-
/**
|
|
57
|
-
* Get shared array
|
|
58
|
-
*/
|
|
59
|
-
getArray<T>(name: string): Y.Array<T>;
|
|
60
|
-
/**
|
|
61
|
-
* Get shared map
|
|
62
|
-
*/
|
|
63
|
-
getMap<T>(name: string): Y.Map<T>;
|
|
64
|
-
/**
|
|
65
|
-
* Get the underlying Y.Doc
|
|
66
|
-
*/
|
|
67
|
-
getDoc(): Y.Doc;
|
|
68
|
-
/**
|
|
69
|
-
* Get current session
|
|
70
|
-
*/
|
|
71
|
-
getSession(): CollaborationSession | null;
|
|
72
|
-
/**
|
|
73
|
-
* Get all participants
|
|
74
|
-
*/
|
|
75
|
-
getParticipants(): Participant[];
|
|
76
|
-
/**
|
|
77
|
-
* Update local user state
|
|
78
|
-
*/
|
|
79
|
-
updateLocalState(state: Partial<Participant>): void;
|
|
80
|
-
/**
|
|
81
|
-
* Update cursor position
|
|
82
|
-
*/
|
|
83
|
-
updateCursor(cursor: CursorPosition): void;
|
|
84
|
-
/**
|
|
85
|
-
* Update selection range
|
|
86
|
-
*/
|
|
87
|
-
updateSelection(selection: Range): void;
|
|
88
|
-
/**
|
|
89
|
-
* Disconnect from the room
|
|
90
|
-
*/
|
|
91
|
-
disconnect(): void;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Create a new YJS client
|
|
95
|
-
*/
|
|
96
|
-
export declare function createYjsClient(roomId: string, config: YjsConfig): YjsClient;
|
|
97
|
-
/**
|
|
98
|
-
* Default configuration for common use cases
|
|
99
|
-
*/
|
|
100
|
-
export declare const defaultConfig: YjsConfig;
|
|
101
|
-
//# sourceMappingURL=yjs-client.d.ts.map
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
// OWNER: T2-A4
|
|
2
|
-
/**
|
|
3
|
-
* YJS Client Setup - GAP-65
|
|
4
|
-
*
|
|
5
|
-
* Collaborative editing client using YJS CRDTs
|
|
6
|
-
*/
|
|
7
|
-
import * as Y from 'yjs';
|
|
8
|
-
import { WebrtcProvider } from 'y-webrtc';
|
|
9
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
10
|
-
export class YjsClient {
|
|
11
|
-
doc;
|
|
12
|
-
provider = null;
|
|
13
|
-
awareness = null;
|
|
14
|
-
config;
|
|
15
|
-
roomId;
|
|
16
|
-
session = null;
|
|
17
|
-
constructor(roomId, config) {
|
|
18
|
-
this.roomId = roomId;
|
|
19
|
-
this.config = config;
|
|
20
|
-
// 1. Create Y.Doc
|
|
21
|
-
this.doc = new Y.Doc();
|
|
22
|
-
// 2. Setup WebRTC provider with signaling
|
|
23
|
-
this.setupProvider();
|
|
24
|
-
// 3. Configure awareness for participant tracking
|
|
25
|
-
this.setupAwareness();
|
|
26
|
-
}
|
|
27
|
-
setupProvider() {
|
|
28
|
-
// 2. Setup WebRTC provider with signaling
|
|
29
|
-
// 3. Configure TURN/STUN servers
|
|
30
|
-
// 4. Connect to room
|
|
31
|
-
this.provider = new WebrtcProvider(`${this.config.roomPrefix}-${this.roomId}`, this.doc, {
|
|
32
|
-
signaling: this.config.signalingUrls,
|
|
33
|
-
iceServers: this.config.iceServers,
|
|
34
|
-
maxConns: this.config.maxPeers || 20,
|
|
35
|
-
});
|
|
36
|
-
this.session = {
|
|
37
|
-
roomId: this.roomId,
|
|
38
|
-
participants: [],
|
|
39
|
-
doc: this.doc,
|
|
40
|
-
provider: this.provider,
|
|
41
|
-
awareness: this.awareness,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
setupAwareness() {
|
|
45
|
-
if (this.provider) {
|
|
46
|
-
this.awareness = new Awareness(this.doc);
|
|
47
|
-
// Set local user state
|
|
48
|
-
this.awareness.setLocalStateField('user', {
|
|
49
|
-
id: this.generateUserId(),
|
|
50
|
-
name: 'Anonymous',
|
|
51
|
-
color: this.generateColor(),
|
|
52
|
-
});
|
|
53
|
-
// Listen for participant changes
|
|
54
|
-
this.awareness.on('change', ({ added, updated, removed }) => {
|
|
55
|
-
this.handleAwarenessChange(added, updated, removed);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
handleAwarenessChange(added, updated, removed) {
|
|
60
|
-
if (!this.awareness)
|
|
61
|
-
return;
|
|
62
|
-
const states = this.awareness.getStates();
|
|
63
|
-
// Update participants list
|
|
64
|
-
if (this.session) {
|
|
65
|
-
this.session.participants = Array.from(states.values()).map((state) => ({
|
|
66
|
-
id: state.user?.id || 'unknown',
|
|
67
|
-
name: state.user?.name || 'Unknown',
|
|
68
|
-
color: state.user?.color || '#000000',
|
|
69
|
-
cursor: state.cursor,
|
|
70
|
-
selection: state.selection,
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
generateUserId() {
|
|
75
|
-
return `user_${Math.random().toString(36).substr(2, 9)}`;
|
|
76
|
-
}
|
|
77
|
-
generateColor() {
|
|
78
|
-
const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7'];
|
|
79
|
-
return colors[Math.floor(Math.random() * colors.length)];
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get shared text for collaborative editing
|
|
83
|
-
*/
|
|
84
|
-
getText(name = 'default') {
|
|
85
|
-
return this.doc.getText(name);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Get shared array
|
|
89
|
-
*/
|
|
90
|
-
getArray(name) {
|
|
91
|
-
return this.doc.getArray(name);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get shared map
|
|
95
|
-
*/
|
|
96
|
-
getMap(name) {
|
|
97
|
-
return this.doc.getMap(name);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get the underlying Y.Doc
|
|
101
|
-
*/
|
|
102
|
-
getDoc() {
|
|
103
|
-
return this.doc;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get current session
|
|
107
|
-
*/
|
|
108
|
-
getSession() {
|
|
109
|
-
return this.session;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get all participants
|
|
113
|
-
*/
|
|
114
|
-
getParticipants() {
|
|
115
|
-
return this.session?.participants || [];
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Update local user state
|
|
119
|
-
*/
|
|
120
|
-
updateLocalState(state) {
|
|
121
|
-
if (this.awareness) {
|
|
122
|
-
const currentState = this.awareness.getLocalState() || {};
|
|
123
|
-
this.awareness.setLocalState({
|
|
124
|
-
...currentState,
|
|
125
|
-
user: {
|
|
126
|
-
...currentState.user,
|
|
127
|
-
...state,
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Update cursor position
|
|
134
|
-
*/
|
|
135
|
-
updateCursor(cursor) {
|
|
136
|
-
if (this.awareness) {
|
|
137
|
-
const currentState = this.awareness.getLocalState() || {};
|
|
138
|
-
this.awareness.setLocalState({
|
|
139
|
-
...currentState,
|
|
140
|
-
cursor,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Update selection range
|
|
146
|
-
*/
|
|
147
|
-
updateSelection(selection) {
|
|
148
|
-
if (this.awareness) {
|
|
149
|
-
const currentState = this.awareness.getLocalState() || {};
|
|
150
|
-
this.awareness.setLocalState({
|
|
151
|
-
...currentState,
|
|
152
|
-
selection,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Disconnect from the room
|
|
158
|
-
*/
|
|
159
|
-
disconnect() {
|
|
160
|
-
if (this.provider) {
|
|
161
|
-
this.provider.destroy();
|
|
162
|
-
this.provider = null;
|
|
163
|
-
}
|
|
164
|
-
if (this.awareness) {
|
|
165
|
-
this.awareness.destroy();
|
|
166
|
-
this.awareness = null;
|
|
167
|
-
}
|
|
168
|
-
this.session = null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Create a new YJS client
|
|
173
|
-
*/
|
|
174
|
-
export function createYjsClient(roomId, config) {
|
|
175
|
-
return new YjsClient(roomId, config);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Default configuration for common use cases
|
|
179
|
-
*/
|
|
180
|
-
export const defaultConfig = {
|
|
181
|
-
signalingUrls: [
|
|
182
|
-
'wss://signaling.yjs.dev',
|
|
183
|
-
'wss://y-webrtc-signaling-us.herokuapp.com',
|
|
184
|
-
'wss://y-webrtc-signaling-eu.herokuapp.com',
|
|
185
|
-
],
|
|
186
|
-
iceServers: [
|
|
187
|
-
{ urls: 'stun:stun.l.google.com:19302' },
|
|
188
|
-
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
189
|
-
],
|
|
190
|
-
roomPrefix: 'a2r-collab',
|
|
191
|
-
maxPeers: 20,
|
|
192
|
-
};
|
|
193
|
-
//# sourceMappingURL=yjs-client.js.map
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* YJS Protocols - GAP-67, 68
|
|
3
|
-
*
|
|
4
|
-
* Broadcast and Sync protocols for YJS
|
|
5
|
-
*/
|
|
6
|
-
import * as Y from 'yjs';
|
|
7
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
8
|
-
import { encoding, decoding } from 'lib0';
|
|
9
|
-
import { AwarenessChanges, UserState, SyncState } from './yjs-types';
|
|
10
|
-
/**
|
|
11
|
-
* Broadcast Protocol - GAP-67
|
|
12
|
-
*
|
|
13
|
-
* Broadcast changes to all peers via WebRTC
|
|
14
|
-
*/
|
|
15
|
-
export declare class BroadcastProtocol {
|
|
16
|
-
private doc;
|
|
17
|
-
private provider;
|
|
18
|
-
private isSyncing;
|
|
19
|
-
constructor(doc: Y.Doc, provider: any);
|
|
20
|
-
/**
|
|
21
|
-
* Broadcast update to all peers
|
|
22
|
-
*/
|
|
23
|
-
broadcastUpdate(update: Uint8Array): void;
|
|
24
|
-
/**
|
|
25
|
-
* Handle incoming message
|
|
26
|
-
*/
|
|
27
|
-
handleMessage(message: Uint8Array, from: number): void;
|
|
28
|
-
private handleSyncMessage;
|
|
29
|
-
private handleAwarenessMessage;
|
|
30
|
-
/**
|
|
31
|
-
* Get sync state
|
|
32
|
-
*/
|
|
33
|
-
getSyncState(): SyncState;
|
|
34
|
-
/**
|
|
35
|
-
* Force sync with all peers
|
|
36
|
-
*/
|
|
37
|
-
forceSync(): void;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Sync Protocol - GAP-67
|
|
41
|
-
*
|
|
42
|
-
* Handle document synchronization
|
|
43
|
-
*/
|
|
44
|
-
export declare class SyncProtocol {
|
|
45
|
-
private doc;
|
|
46
|
-
private syncState;
|
|
47
|
-
constructor(doc: Y.Doc);
|
|
48
|
-
/**
|
|
49
|
-
* Sync document with remote
|
|
50
|
-
*/
|
|
51
|
-
syncDocument(remoteDoc: Y.Doc): void;
|
|
52
|
-
/**
|
|
53
|
-
* Create sync message
|
|
54
|
-
*/
|
|
55
|
-
createSyncMessage(): Uint8Array;
|
|
56
|
-
/**
|
|
57
|
-
* Handle sync step 1
|
|
58
|
-
*/
|
|
59
|
-
handleSyncStep1(encoder: encoding.Encoder, decoder: decoding.Decoder): void;
|
|
60
|
-
/**
|
|
61
|
-
* Handle sync step 2
|
|
62
|
-
*/
|
|
63
|
-
handleSyncStep2(decoder: decoding.Decoder): void;
|
|
64
|
-
/**
|
|
65
|
-
* Handle update
|
|
66
|
-
*/
|
|
67
|
-
handleUpdate(decoder: decoding.Decoder): void;
|
|
68
|
-
/**
|
|
69
|
-
* Get sync status for a peer
|
|
70
|
-
*/
|
|
71
|
-
getPeerSyncStatus(peerId: number): any;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Awareness Manager - GAP-68
|
|
75
|
-
*
|
|
76
|
-
* Manage user awareness and presence
|
|
77
|
-
*/
|
|
78
|
-
export declare class AwarenessManager {
|
|
79
|
-
private awareness;
|
|
80
|
-
private onChangeCallbacks;
|
|
81
|
-
constructor(doc: Y.Doc);
|
|
82
|
-
private setupListeners;
|
|
83
|
-
/**
|
|
84
|
-
* Set local user state
|
|
85
|
-
*/
|
|
86
|
-
setLocalState(state: UserState): void;
|
|
87
|
-
/**
|
|
88
|
-
* Set local state field
|
|
89
|
-
*/
|
|
90
|
-
setLocalStateField<T>(key: string, value: T): void;
|
|
91
|
-
/**
|
|
92
|
-
* Get all participant states
|
|
93
|
-
*/
|
|
94
|
-
getStates(): Map<number, UserState>;
|
|
95
|
-
/**
|
|
96
|
-
* Get local state
|
|
97
|
-
*/
|
|
98
|
-
getLocalState(): UserState | null;
|
|
99
|
-
/**
|
|
100
|
-
* Get state for specific client
|
|
101
|
-
*/
|
|
102
|
-
getState(clientId: number): UserState | null;
|
|
103
|
-
/**
|
|
104
|
-
* Listen for changes
|
|
105
|
-
*/
|
|
106
|
-
onChange(callback: (changes: AwarenessChanges) => void): () => void;
|
|
107
|
-
/**
|
|
108
|
-
* Get all connected clients
|
|
109
|
-
*/
|
|
110
|
-
getConnectedClients(): number[];
|
|
111
|
-
/**
|
|
112
|
-
* Remove client state
|
|
113
|
-
*/
|
|
114
|
-
removeLocalState(): void;
|
|
115
|
-
/**
|
|
116
|
-
* Get awareness instance
|
|
117
|
-
*/
|
|
118
|
-
getAwareness(): Awareness;
|
|
119
|
-
/**
|
|
120
|
-
* Destroy awareness manager
|
|
121
|
-
*/
|
|
122
|
-
destroy(): void;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create awareness manager
|
|
126
|
-
*/
|
|
127
|
-
export declare function createAwarenessManager(doc: Y.Doc): AwarenessManager;
|
|
128
|
-
//# sourceMappingURL=yjs-protocols.d.ts.map
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
// OWNER: T2-A5
|
|
2
|
-
/**
|
|
3
|
-
* YJS Protocols - GAP-67, 68
|
|
4
|
-
*
|
|
5
|
-
* Broadcast and Sync protocols for YJS
|
|
6
|
-
*/
|
|
7
|
-
import * as Y from 'yjs';
|
|
8
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
9
|
-
import * as syncProtocol from 'y-protocols/sync';
|
|
10
|
-
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
11
|
-
import { encoding, decoding } from 'lib0';
|
|
12
|
-
/**
|
|
13
|
-
* Broadcast Protocol - GAP-67
|
|
14
|
-
*
|
|
15
|
-
* Broadcast changes to all peers via WebRTC
|
|
16
|
-
*/
|
|
17
|
-
export class BroadcastProtocol {
|
|
18
|
-
doc;
|
|
19
|
-
provider;
|
|
20
|
-
isSyncing = false;
|
|
21
|
-
constructor(doc, provider) {
|
|
22
|
-
this.doc = doc;
|
|
23
|
-
this.provider = provider;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Broadcast update to all peers
|
|
27
|
-
*/
|
|
28
|
-
broadcastUpdate(update) {
|
|
29
|
-
if (!this.provider)
|
|
30
|
-
return;
|
|
31
|
-
try {
|
|
32
|
-
// 1. Encode update
|
|
33
|
-
const message = syncProtocol.createUpdateMessage(update);
|
|
34
|
-
// 2. Send via WebRTC provider
|
|
35
|
-
this.provider.broadcastMessage(message);
|
|
36
|
-
// 3. Handle sync state
|
|
37
|
-
this.isSyncing = false;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error('Failed to broadcast update:', error);
|
|
41
|
-
this.isSyncing = false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Handle incoming message
|
|
46
|
-
*/
|
|
47
|
-
handleMessage(message, from) {
|
|
48
|
-
const decoder = decoding.createDecoder(message);
|
|
49
|
-
const messageType = decoding.readVarUint(decoder);
|
|
50
|
-
switch (messageType) {
|
|
51
|
-
case syncProtocol.messageYjsSyncStep1:
|
|
52
|
-
case syncProtocol.messageYjsSyncStep2:
|
|
53
|
-
case syncProtocol.messageYjsUpdate:
|
|
54
|
-
this.handleSyncMessage(decoder, from);
|
|
55
|
-
break;
|
|
56
|
-
case awarenessProtocol.messageAwareness:
|
|
57
|
-
this.handleAwarenessMessage(decoder, from);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
handleSyncMessage(decoder, from) {
|
|
62
|
-
this.isSyncing = true;
|
|
63
|
-
try {
|
|
64
|
-
syncProtocol.readSyncMessage(decoder, encoding.createEncoder(), this.doc, null, from);
|
|
65
|
-
}
|
|
66
|
-
finally {
|
|
67
|
-
this.isSyncing = false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
handleAwarenessMessage(decoder, from) {
|
|
71
|
-
if (this.provider.awareness) {
|
|
72
|
-
awarenessProtocol.applyAwarenessUpdate(this.provider.awareness, decoding.readVarUint8Array(decoder), from);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get sync state
|
|
77
|
-
*/
|
|
78
|
-
getSyncState() {
|
|
79
|
-
return {
|
|
80
|
-
isSyncing: this.isSyncing,
|
|
81
|
-
progress: this.isSyncing ? 50 : 100,
|
|
82
|
-
lastSync: new Date(),
|
|
83
|
-
errors: [],
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Force sync with all peers
|
|
88
|
-
*/
|
|
89
|
-
forceSync() {
|
|
90
|
-
if (!this.provider)
|
|
91
|
-
return;
|
|
92
|
-
// Request sync step 1 from all peers
|
|
93
|
-
const encoder = encoding.createEncoder();
|
|
94
|
-
syncProtocol.writeSyncStep1(encoder, this.doc);
|
|
95
|
-
this.provider.broadcastMessage(encoding.toUint8Array(encoder));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Sync Protocol - GAP-67
|
|
100
|
-
*
|
|
101
|
-
* Handle document synchronization
|
|
102
|
-
*/
|
|
103
|
-
export class SyncProtocol {
|
|
104
|
-
doc;
|
|
105
|
-
syncState = new Map();
|
|
106
|
-
constructor(doc) {
|
|
107
|
-
this.doc = doc;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Sync document with remote
|
|
111
|
-
*/
|
|
112
|
-
syncDocument(remoteDoc) {
|
|
113
|
-
// 1. Create sync state vector
|
|
114
|
-
const stateVector = Y.encodeStateVector(this.doc);
|
|
115
|
-
// 2. Exchange with remote
|
|
116
|
-
const remoteStateVector = Y.encodeStateVector(remoteDoc);
|
|
117
|
-
// 3. Apply missing updates
|
|
118
|
-
const missingUpdates = Y.encodeStateAsUpdate(this.doc, remoteStateVector);
|
|
119
|
-
const remoteUpdates = Y.encodeStateAsUpdate(remoteDoc, stateVector);
|
|
120
|
-
Y.applyUpdate(this.doc, remoteUpdates);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Create sync message
|
|
124
|
-
*/
|
|
125
|
-
createSyncMessage() {
|
|
126
|
-
const encoder = encoding.createEncoder();
|
|
127
|
-
syncProtocol.writeSyncStep1(encoder, this.doc);
|
|
128
|
-
return encoding.toUint8Array(encoder);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Handle sync step 1
|
|
132
|
-
*/
|
|
133
|
-
handleSyncStep1(encoder, decoder) {
|
|
134
|
-
syncProtocol.readSyncStep1(decoder, encoder, this.doc);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Handle sync step 2
|
|
138
|
-
*/
|
|
139
|
-
handleSyncStep2(decoder) {
|
|
140
|
-
syncProtocol.readSyncStep2(decoder, this.doc, null);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Handle update
|
|
144
|
-
*/
|
|
145
|
-
handleUpdate(decoder) {
|
|
146
|
-
syncProtocol.readUpdate(decoder, this.doc, null);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get sync status for a peer
|
|
150
|
-
*/
|
|
151
|
-
getPeerSyncStatus(peerId) {
|
|
152
|
-
return this.syncState.get(peerId) || { synced: false };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Awareness Manager - GAP-68
|
|
157
|
-
*
|
|
158
|
-
* Manage user awareness and presence
|
|
159
|
-
*/
|
|
160
|
-
export class AwarenessManager {
|
|
161
|
-
awareness;
|
|
162
|
-
onChangeCallbacks = new Set();
|
|
163
|
-
constructor(doc) {
|
|
164
|
-
this.awareness = new Awareness(doc);
|
|
165
|
-
this.setupListeners();
|
|
166
|
-
}
|
|
167
|
-
setupListeners() {
|
|
168
|
-
this.awareness.on('change', (changes) => {
|
|
169
|
-
this.onChangeCallbacks.forEach(cb => cb(changes));
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Set local user state
|
|
174
|
-
*/
|
|
175
|
-
setLocalState(state) {
|
|
176
|
-
this.awareness.setLocalStateField('user', state);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Set local state field
|
|
180
|
-
*/
|
|
181
|
-
setLocalStateField(key, value) {
|
|
182
|
-
const currentState = this.awareness.getLocalState() || {};
|
|
183
|
-
this.awareness.setLocalState({
|
|
184
|
-
...currentState,
|
|
185
|
-
[key]: value,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Get all participant states
|
|
190
|
-
*/
|
|
191
|
-
getStates() {
|
|
192
|
-
return this.awareness.getStates();
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Get local state
|
|
196
|
-
*/
|
|
197
|
-
getLocalState() {
|
|
198
|
-
return this.awareness.getLocalState()?.user || null;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Get state for specific client
|
|
202
|
-
*/
|
|
203
|
-
getState(clientId) {
|
|
204
|
-
return this.awareness.getStates().get(clientId) || null;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Listen for changes
|
|
208
|
-
*/
|
|
209
|
-
onChange(callback) {
|
|
210
|
-
this.onChangeCallbacks.add(callback);
|
|
211
|
-
return () => this.onChangeCallbacks.delete(callback);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Get all connected clients
|
|
215
|
-
*/
|
|
216
|
-
getConnectedClients() {
|
|
217
|
-
return Array.from(this.awareness.getStates().keys());
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Remove client state
|
|
221
|
-
*/
|
|
222
|
-
removeLocalState() {
|
|
223
|
-
this.awareness.setLocalState(null);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get awareness instance
|
|
227
|
-
*/
|
|
228
|
-
getAwareness() {
|
|
229
|
-
return this.awareness;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Destroy awareness manager
|
|
233
|
-
*/
|
|
234
|
-
destroy() {
|
|
235
|
-
this.awareness.destroy();
|
|
236
|
-
this.onChangeCallbacks.clear();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Create awareness manager
|
|
241
|
-
*/
|
|
242
|
-
export function createAwarenessManager(doc) {
|
|
243
|
-
return new AwarenessManager(doc);
|
|
244
|
-
}
|
|
245
|
-
//# sourceMappingURL=yjs-protocols.js.map
|