@fileverse-dev/ddoc 3.0.64-rtc-patch-1 → 3.0.65
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.es.js +26650 -24731
- package/dist/package/extensions/font-family-persistence.d.ts +11 -0
- package/dist/package/extensions/typography-persistence.d.ts +22 -0
- package/dist/package/hooks/use-rtc-websocket-disconnector.d.ts +1 -0
- package/dist/package/hooks/use-tab-editor.d.ts +2 -2
- package/dist/package/hooks/use-yjs-setup.d.ts +3 -3
- package/dist/package/sync-local/actions/index.d.ts +137 -0
- package/dist/package/sync-local/actions/syncMachineActions.d.ts +1 -0
- package/dist/package/sync-local/constants/config.d.ts +7 -0
- package/dist/package/sync-local/constants/index.d.ts +5 -0
- package/dist/package/sync-local/guards/syncMachineGuards.d.ts +10 -0
- package/dist/package/sync-local/index.d.ts +6 -3
- package/dist/package/sync-local/services/syncMachineServices.d.ts +19 -0
- package/dist/package/sync-local/socketClient.d.ts +26 -17
- package/dist/package/sync-local/syncMachine.d.ts +13 -0
- package/dist/package/sync-local/types/index.d.ts +120 -85
- package/dist/package/sync-local/useSyncMachine.d.ts +38 -0
- package/dist/package/sync-local/utils/createAwarenessUpdateHandler.d.ts +3 -3
- package/dist/package/use-ddoc-editor.d.ts +2 -2
- package/dist/style.css +1 -1
- package/package.json +7 -3
- package/dist/package/sync-local/SyncManager.d.ts +0 -52
- package/dist/package/sync-local/useSyncManager.d.ts +0 -13
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface Commands<ReturnType> {
|
|
5
|
+
fontFamilyPersistence: {
|
|
6
|
+
setFontFamily: (fontFamily: string) => ReturnType;
|
|
7
|
+
unsetFontFamily: () => ReturnType;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const FontFamilyPersistence: Extension<any, any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypographyPersistence consolidates fontFamily and fontSize persistence logic
|
|
5
|
+
* into a single extension with 3 plugins, replacing the 6 individual plugins
|
|
6
|
+
* that were split across FontFamilyPersistence and FontSize.
|
|
7
|
+
*
|
|
8
|
+
* Plugins:
|
|
9
|
+
* 1. typographyInheritance — when a new paragraph is inserted next to a styled
|
|
10
|
+
* one, inherit fontFamily and fontSize in a single setNodeMarkup pass.
|
|
11
|
+
* Skips trailing-node paragraphs (they inherit from the previous sibling
|
|
12
|
+
* at creation time, but should not be overridden when the user clears them).
|
|
13
|
+
* 2. typographyStoredMarks — when selection moves into an empty styled
|
|
14
|
+
* paragraph, restore storedMarks for both fontFamily and fontSize at once.
|
|
15
|
+
* 3. typographySyncNodeAttr — when storedMarks change on an empty paragraph,
|
|
16
|
+
* update both node attributes in one setNodeMarkup call.
|
|
17
|
+
* Clearing only happens when the textStyle mark itself explicitly has a null
|
|
18
|
+
* value for the property — NOT when non-textStyle marks (bold, italic, etc.)
|
|
19
|
+
* are stored, which was previously causing font attrs to be wiped on
|
|
20
|
+
* bold/italic toggle.
|
|
21
|
+
*/
|
|
22
|
+
export declare const TypographyPersistence: Extension<any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useRtcWebsocketDisconnector: (syncState: any, enableCollaboration: boolean | undefined) => void;
|
|
@@ -2,7 +2,7 @@ import { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|
|
2
2
|
import { DdocProps } from '../types';
|
|
3
3
|
import { AnyExtension, Editor } from '@tiptap/react';
|
|
4
4
|
import { ToCItemType } from '../components/toc/types';
|
|
5
|
-
import {
|
|
5
|
+
import { IConnectConf } from '../sync-local/useSyncMachine';
|
|
6
6
|
|
|
7
7
|
import * as Y from 'yjs';
|
|
8
8
|
interface UseTabEditorArgs {
|
|
@@ -38,7 +38,7 @@ interface UseTabEditorArgs {
|
|
|
38
38
|
onInvalidContentError?: DdocProps['onInvalidContentError'];
|
|
39
39
|
ignoreCorruptedData?: boolean;
|
|
40
40
|
onCollaboratorChange?: DdocProps['onCollaboratorChange'];
|
|
41
|
-
onConnect: (connectConfig:
|
|
41
|
+
onConnect: (connectConfig: IConnectConf) => void;
|
|
42
42
|
hasCollabContentInitialised?: boolean;
|
|
43
43
|
initialiseYjsIndexedDbProvider: () => Promise<void>;
|
|
44
44
|
externalExtensions?: Record<string, AnyExtension>;
|
|
@@ -14,12 +14,12 @@ interface UseYjsSetupArgs {
|
|
|
14
14
|
onCollabSessionTermination?: () => void;
|
|
15
15
|
onUnMergedUpdates?: (state: boolean) => void;
|
|
16
16
|
}
|
|
17
|
-
export declare const useYjsSetup: ({ onChange, enableIndexeddbSync, ddocId, onIndexedDbError, onCollabError, onCollaborationConnectCallback, onCollaborationCommit, onFetchCommitContent, onCollabSessionTermination, onUnMergedUpdates, }: UseYjsSetupArgs) => {
|
|
17
|
+
export declare const useYjsSetup: ({ onChange, enableIndexeddbSync, ddocId, enableCollaboration, onIndexedDbError, onCollabError, onCollaborationConnectCallback, onCollaborationCommit, onFetchCommitContent, onCollabSessionTermination, onUnMergedUpdates, }: UseYjsSetupArgs) => {
|
|
18
18
|
ydoc: Y.Doc;
|
|
19
|
-
onConnect: (connectConfig: import('../sync-local').
|
|
19
|
+
onConnect: (connectConfig: import('../sync-local/useSyncMachine').IConnectConf) => void;
|
|
20
20
|
isReady: boolean;
|
|
21
21
|
terminateSession: () => void;
|
|
22
|
-
awareness:
|
|
22
|
+
awareness: any;
|
|
23
23
|
hasCollabContentInitialised: boolean;
|
|
24
24
|
initialiseYjsIndexedDbProvider: () => Promise<void>;
|
|
25
25
|
refreshYjsIndexedDbProvider: () => Promise<void>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { SyncMachineContext, SyncMachinEvent } from '../types';
|
|
2
|
+
import { SocketClient } from '../socketClient';
|
|
3
|
+
|
|
4
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
5
|
+
export declare const initAwarenessHandler: (context: SyncMachineContext) => {
|
|
6
|
+
awareness: awarenessProtocol.Awareness;
|
|
7
|
+
_awarenessUpdateHandler: ({ added, updated, removed, }: {
|
|
8
|
+
added: number[];
|
|
9
|
+
updated: number[];
|
|
10
|
+
removed: number[];
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const updateConnectionStateHandler: (context: SyncMachineContext) => {
|
|
14
|
+
isConnected: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const websocketInitializer: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
17
|
+
socketClient: SocketClient;
|
|
18
|
+
initialUpdate: any;
|
|
19
|
+
roomKey: any;
|
|
20
|
+
roomId: any;
|
|
21
|
+
isOwner: any;
|
|
22
|
+
isEns: any;
|
|
23
|
+
wsUrl: any;
|
|
24
|
+
onCollaborationCommit: (file: File) => Promise<string>;
|
|
25
|
+
onFetchCommitContent: (cid: string) => Promise<any>;
|
|
26
|
+
onSessionTerminated: () => void;
|
|
27
|
+
onUnMergedUpdates: (state: boolean) => void;
|
|
28
|
+
onLocalUpdate: ((updatedDocContent: import('../../types').Data["editorJSONData"], updateChunk: string) => void) | undefined;
|
|
29
|
+
};
|
|
30
|
+
export declare const yjsUpdateHandler: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
31
|
+
uncommittedUpdatesIdList?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
uncommittedUpdatesIdList: any[];
|
|
34
|
+
};
|
|
35
|
+
export declare const roomMemberUpdateHandler: (context: SyncMachineContext) => {
|
|
36
|
+
roomMembers: import('../types').RoomMember[];
|
|
37
|
+
};
|
|
38
|
+
export declare const stateResetHandler: () => {
|
|
39
|
+
roomMembers: never[];
|
|
40
|
+
isConnected: boolean;
|
|
41
|
+
awareness: null;
|
|
42
|
+
_awarenessUpdateHandler: null;
|
|
43
|
+
socketClient: null;
|
|
44
|
+
};
|
|
45
|
+
export declare const registerUpdateHandler: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
46
|
+
uncommittedUpdatesIdList?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
uncommittedUpdatesIdList: any[];
|
|
49
|
+
};
|
|
50
|
+
export declare const removeLastProcessedUpdate: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
51
|
+
updateQueue: Uint8Array<ArrayBufferLike>[];
|
|
52
|
+
};
|
|
53
|
+
export declare const clearUncommitedUpdatesHandler: () => {
|
|
54
|
+
uncommittedUpdatesIdList: never[];
|
|
55
|
+
};
|
|
56
|
+
export declare const addUpdateToQueueHandler: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
57
|
+
updateQueue: any[];
|
|
58
|
+
};
|
|
59
|
+
export declare const updateConnectionReadyStateHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
60
|
+
isReady: any;
|
|
61
|
+
};
|
|
62
|
+
export declare const setNewDocFlagHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
63
|
+
isNewDoc: any;
|
|
64
|
+
};
|
|
65
|
+
export declare const commitUncommittedIdsHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
66
|
+
uncommittedUpdatesIdList: any;
|
|
67
|
+
};
|
|
68
|
+
export declare const setConnectionActiveStateHandler: (context: SyncMachineContext) => {
|
|
69
|
+
isConnected: boolean;
|
|
70
|
+
};
|
|
71
|
+
export declare const setMachineReadyStateHandler: () => {
|
|
72
|
+
isReady: boolean;
|
|
73
|
+
};
|
|
74
|
+
export declare const addRemoteContentToQueueHandler: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
75
|
+
contentTobeAppliedQueue: any[];
|
|
76
|
+
};
|
|
77
|
+
export declare const applyContentsFromRemote: (context: SyncMachineContext) => {
|
|
78
|
+
contentTobeAppliedQueue?: undefined;
|
|
79
|
+
} | {
|
|
80
|
+
contentTobeAppliedQueue: never[];
|
|
81
|
+
};
|
|
82
|
+
export declare const clearErrorCountHandler: () => {
|
|
83
|
+
errorCount: number;
|
|
84
|
+
errorMessage: string;
|
|
85
|
+
};
|
|
86
|
+
export declare const updateErrorCountHandler: (context: SyncMachineContext) => {
|
|
87
|
+
errorCount: number;
|
|
88
|
+
};
|
|
89
|
+
export declare const setCommitMessageErrorHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
90
|
+
errorMessage: string;
|
|
91
|
+
};
|
|
92
|
+
export declare const setUpdateErrorMessageHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
93
|
+
errorMessage: string;
|
|
94
|
+
};
|
|
95
|
+
export declare const setConnectionErrorMessageHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
96
|
+
errorMessage: string;
|
|
97
|
+
};
|
|
98
|
+
export declare const setIpfsQueryErrorMessageHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
99
|
+
errorMessage: string;
|
|
100
|
+
};
|
|
101
|
+
export declare const setInitialCommitErrorMessageHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
102
|
+
errorMessage: string;
|
|
103
|
+
};
|
|
104
|
+
export declare const setInitialUpdateErrorMessageHandler: (_context: SyncMachineContext, event: SyncMachinEvent) => {
|
|
105
|
+
errorMessage: string;
|
|
106
|
+
};
|
|
107
|
+
export declare const disconnectedStateHandler: () => {
|
|
108
|
+
socketClient: null;
|
|
109
|
+
roomMembers: never[];
|
|
110
|
+
isConnected: boolean;
|
|
111
|
+
awareness: null;
|
|
112
|
+
_awarenessUpdateHandler: null;
|
|
113
|
+
uncommittedUpdatesIdList: never[];
|
|
114
|
+
updateQueue: never[];
|
|
115
|
+
};
|
|
116
|
+
export declare const terminateSessionHandler: (context: SyncMachineContext) => {
|
|
117
|
+
socketClient: null;
|
|
118
|
+
roomId: string;
|
|
119
|
+
roomMembers: never[];
|
|
120
|
+
isConnected: boolean;
|
|
121
|
+
awareness: null;
|
|
122
|
+
_awarenessUpdateHandler: null;
|
|
123
|
+
roomKey: string;
|
|
124
|
+
wsUrl: string;
|
|
125
|
+
uncommittedUpdatesIdList: never[];
|
|
126
|
+
updateQueue: never[];
|
|
127
|
+
isOwner: boolean;
|
|
128
|
+
isReady: boolean;
|
|
129
|
+
isNewDoc: boolean;
|
|
130
|
+
contentTobeAppliedQueue: never[];
|
|
131
|
+
initialUpdate: null;
|
|
132
|
+
errorCount: number;
|
|
133
|
+
errorMessage: string;
|
|
134
|
+
};
|
|
135
|
+
export declare const setDocumentDecryptionStateHandler: (_: SyncMachineContext, event: SyncMachinEvent) => {
|
|
136
|
+
initalDocumentDecryptionState: any;
|
|
137
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const syncMachineActions: Record<any, any>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SyncMachineContext } from '../types';
|
|
2
|
+
|
|
3
|
+
export declare const syncMachineGuards: {
|
|
4
|
+
isUserConnected: (context: SyncMachineContext) => boolean;
|
|
5
|
+
hasMoreUpdates: (context: SyncMachineContext) => boolean;
|
|
6
|
+
isOwner: (context: SyncMachineContext) => boolean;
|
|
7
|
+
errorIsLessThanRetryCount: (context: SyncMachineContext) => boolean;
|
|
8
|
+
shouldRetryConnection: (context: SyncMachineContext) => boolean;
|
|
9
|
+
shouldRefetchCommit: (context: SyncMachineContext) => boolean;
|
|
10
|
+
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as syncMachine } from './syncMachine';
|
|
2
|
+
import { SyncMachineContext } from './types';
|
|
3
|
+
|
|
4
|
+
export { useSyncMachine } from './useSyncMachine';
|
|
5
|
+
export { syncMachine };
|
|
6
|
+
export type { SyncMachineContext };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Sender } from 'xstate';
|
|
2
|
+
import { SyncMachineContext, SyncMachinEvent } from '../types';
|
|
3
|
+
|
|
4
|
+
export declare const syncMachineServices: {
|
|
5
|
+
connectSocket: (context: SyncMachineContext) => (send: Sender<SyncMachinEvent>) => Promise<void>;
|
|
6
|
+
disconnectSocket: (context: SyncMachineContext) => () => Promise<void>;
|
|
7
|
+
processNextUpdate: (context: SyncMachineContext) => () => Promise<{
|
|
8
|
+
updateId: string | undefined;
|
|
9
|
+
queueOffset: number;
|
|
10
|
+
} | undefined>;
|
|
11
|
+
processCommit: (context: SyncMachineContext) => (send: Sender<SyncMachinEvent>) => Promise<void>;
|
|
12
|
+
syncLatestCommitFromIpfs: (context: SyncMachineContext) => (send: Sender<SyncMachinEvent>) => Promise<{
|
|
13
|
+
ids: string[];
|
|
14
|
+
unbroadcastedUpdate: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
broadcastLocalContents: (context: SyncMachineContext, event: SyncMachinEvent) => () => Promise<boolean>;
|
|
17
|
+
commitLocalContents: (context: SyncMachineContext, event: SyncMachinEvent) => (send: Sender<SyncMachinEvent>) => Promise<string | undefined>;
|
|
18
|
+
verifyConnectionState: (context: SyncMachineContext) => (send: Sender<SyncMachinEvent>) => Promise<void>;
|
|
19
|
+
};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlProvider } from 'partysocket/ws';
|
|
2
|
+
import { ISocketInitConfig, RoomMember, SocketStatusEnum, SendUpdateResponse, CommitResponse } from './types';
|
|
2
3
|
import { Awareness } from 'y-protocols/awareness.js';
|
|
3
4
|
|
|
4
5
|
interface ISocketClientConfig {
|
|
5
|
-
wsUrl:
|
|
6
|
+
wsUrl: UrlProvider;
|
|
6
7
|
roomKey: string;
|
|
7
|
-
roomId: string;
|
|
8
8
|
ownerEdSecret?: string;
|
|
9
9
|
contractAddress?: string;
|
|
10
10
|
ownerAddress?: string;
|
|
11
11
|
onCollaborationConnectCallback: (response: any) => void;
|
|
12
|
-
onError?: (e: Error) => void;
|
|
13
12
|
roomInfo?: {
|
|
14
13
|
documentTitle: string;
|
|
15
14
|
portalAddress: string;
|
|
@@ -17,12 +16,14 @@ interface ISocketClientConfig {
|
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
export declare class SocketClient {
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
private _websocketUrl;
|
|
20
|
+
private _machineEventHandler;
|
|
21
|
+
private _onConnect;
|
|
22
|
+
private _onDisconnection;
|
|
23
|
+
private _onHandShakeError;
|
|
24
|
+
private _sequenceCallbackMap;
|
|
25
|
+
_webSocketStatus: SocketStatusEnum;
|
|
26
|
+
private _webSocket;
|
|
26
27
|
private _websocketServiceDid;
|
|
27
28
|
private roomId;
|
|
28
29
|
roomMembers: RoomMember[];
|
|
@@ -38,8 +39,11 @@ export declare class SocketClient {
|
|
|
38
39
|
_onError: ISocketInitConfig['onError'] | null;
|
|
39
40
|
_onCollaborationConnectCallback: ISocketClientConfig['onCollaborationConnectCallback'] | null;
|
|
40
41
|
constructor(config: ISocketClientConfig);
|
|
42
|
+
private _getSequenceIdCallback;
|
|
43
|
+
private _removeSequenceIdFromMap;
|
|
41
44
|
registerAwareness(awareness: Awareness): void;
|
|
42
|
-
private
|
|
45
|
+
private _registerSequenceCallback;
|
|
46
|
+
private _sendNetworkRequest;
|
|
43
47
|
private _fetchRoomMembers;
|
|
44
48
|
sendUpdate({ update }: {
|
|
45
49
|
update: string;
|
|
@@ -48,19 +52,24 @@ export declare class SocketClient {
|
|
|
48
52
|
updates: string[];
|
|
49
53
|
cid: string;
|
|
50
54
|
}): Promise<CommitResponse>;
|
|
51
|
-
fetchLatestCommit(): Promise<
|
|
52
|
-
getUncommittedChanges(): Promise<
|
|
53
|
-
broadcastAwareness(awarenessUpdate: string): Promise<
|
|
54
|
-
disconnect: () => void;
|
|
55
|
+
fetchLatestCommit(): Promise<any>;
|
|
56
|
+
getUncommittedChanges(): Promise<any>;
|
|
57
|
+
broadcastAwareness(awarenessUpdate: string): Promise<any>;
|
|
58
|
+
disconnect: (reason: string, code: number) => void;
|
|
55
59
|
terminateSession: () => Promise<void>;
|
|
60
|
+
private _buildRequest;
|
|
56
61
|
private getCollaborationKeyPair;
|
|
57
62
|
private isUcanValid;
|
|
58
63
|
private getOwnerToken;
|
|
59
64
|
private buildSessionToken;
|
|
60
65
|
private _handleHandShake;
|
|
61
|
-
private
|
|
62
|
-
|
|
66
|
+
private _executeRequestCallback;
|
|
67
|
+
private _dispatchEventHandler;
|
|
63
68
|
private _onSessionTerminated;
|
|
69
|
+
private _processMessage;
|
|
70
|
+
private _clearSequenceCallbackMap;
|
|
71
|
+
connectSocket(): Promise<void> | undefined;
|
|
72
|
+
init(config: ISocketInitConfig): Promise<void>;
|
|
64
73
|
private resetSocketClient;
|
|
65
74
|
}
|
|
66
75
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SyncMachineContext } from './types';
|
|
2
|
+
|
|
3
|
+
declare const syncMachine: import('xstate').StateMachine<SyncMachineContext, any, {
|
|
4
|
+
type: string;
|
|
5
|
+
data: any;
|
|
6
|
+
}, {
|
|
7
|
+
value: any;
|
|
8
|
+
context: SyncMachineContext;
|
|
9
|
+
}, import('xstate').BaseActionObject, import('xstate').ServiceMap, import('xstate').ResolveTypegenMeta<import('xstate').TypegenDisabled, {
|
|
10
|
+
type: string;
|
|
11
|
+
data: any;
|
|
12
|
+
}, import('xstate').BaseActionObject, import('xstate').ServiceMap>>;
|
|
13
|
+
export default syncMachine;
|
|
@@ -1,108 +1,130 @@
|
|
|
1
1
|
import { Data } from '../../types';
|
|
2
|
-
import {
|
|
2
|
+
import { SocketClient } from '../socketClient';
|
|
3
3
|
|
|
4
4
|
import * as Y from 'yjs';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
CONNECTED = "connected",
|
|
10
|
-
PROCESSING = "processing",
|
|
11
|
-
DISCONNECTING = "disconnecting"
|
|
5
|
+
export interface IRoomMember {
|
|
6
|
+
userId: string;
|
|
7
|
+
username: string;
|
|
8
|
+
role: 'owner' | 'editor';
|
|
12
9
|
}
|
|
13
|
-
export interface
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
export interface SendUpdateResponse {
|
|
11
|
+
data: {
|
|
12
|
+
agent_id: string;
|
|
13
|
+
commitCid: string | null;
|
|
14
|
+
created_at: number;
|
|
15
|
+
data: string;
|
|
16
|
+
documentId: string;
|
|
17
|
+
id: string;
|
|
18
|
+
update_snapshot_ref: string | null;
|
|
19
|
+
updateType: string;
|
|
20
|
+
};
|
|
21
|
+
is_handshake_response: boolean;
|
|
22
|
+
status: boolean;
|
|
23
|
+
statusCode: number;
|
|
22
24
|
}
|
|
23
|
-
export interface
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
isEns?: boolean;
|
|
32
|
-
wsUrl: string;
|
|
33
|
-
roomInfo?: {
|
|
34
|
-
documentTitle: string;
|
|
35
|
-
portalAddress: string;
|
|
36
|
-
commentKey: string;
|
|
25
|
+
export interface CommitResponse {
|
|
26
|
+
data: {
|
|
27
|
+
agent_id: string;
|
|
28
|
+
cid: string;
|
|
29
|
+
created_at: number;
|
|
30
|
+
data: any | null;
|
|
31
|
+
documentId: string;
|
|
32
|
+
updates: string[];
|
|
37
33
|
};
|
|
34
|
+
is_handshake_response: boolean;
|
|
35
|
+
status: boolean;
|
|
36
|
+
statusCode: number;
|
|
38
37
|
}
|
|
39
|
-
export interface
|
|
40
|
-
|
|
38
|
+
export interface SyncMachineContext {
|
|
39
|
+
ydoc: Y.Doc;
|
|
40
|
+
socketClient: SocketClient | null;
|
|
41
|
+
roomId: string;
|
|
42
|
+
username: string;
|
|
43
|
+
roomMembers: IRoomMember[];
|
|
41
44
|
isConnected: boolean;
|
|
45
|
+
awareness: any;
|
|
46
|
+
_awarenessUpdateHandler: (({ added, updated, removed, }: {
|
|
47
|
+
added: number[];
|
|
48
|
+
updated: number[];
|
|
49
|
+
removed: number[];
|
|
50
|
+
}) => void) | null;
|
|
51
|
+
onError: ((e: Error) => void) | null;
|
|
52
|
+
roomKey: string;
|
|
53
|
+
wsUrl: string;
|
|
54
|
+
uncommittedUpdatesIdList: string[];
|
|
55
|
+
isOwner: boolean;
|
|
56
|
+
updateQueue: Uint8Array[];
|
|
42
57
|
isReady: boolean;
|
|
58
|
+
isNewDoc: boolean;
|
|
59
|
+
contentTobeAppliedQueue: string[];
|
|
60
|
+
initialUpdate: string | null;
|
|
61
|
+
errorCount: number;
|
|
62
|
+
errorMaxRetryCount: number;
|
|
43
63
|
errorMessage: string;
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
initalDocumentDecryptionState: 'done' | 'pending';
|
|
65
|
+
onCollaborationConnectCallback: (response: any) => void;
|
|
66
|
+
onCollaborationCommit: (file: File) => Promise<string>;
|
|
67
|
+
onFetchCommitContent: (cid: string) => Promise<any>;
|
|
68
|
+
onSessionTerminated: () => void;
|
|
69
|
+
onUnMergedUpdates: (state: boolean) => void;
|
|
70
|
+
onLocalUpdate?: (updatedDocContent: Data['editorJSONData'], updateChunk: string) => void;
|
|
46
71
|
}
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
COMMIT_MISSING_DATA = "COMMIT_MISSING_DATA",
|
|
57
|
-
INVALID_ADDRESS = "INVALID_ADDRESS",
|
|
58
|
-
NOT_AUTHENTICATED = "NOT_AUTHENTICATED",
|
|
59
|
-
DB_ERROR = "DB_ERROR",
|
|
60
|
-
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
72
|
+
export interface ErrorResponseMessage {
|
|
73
|
+
status: boolean;
|
|
74
|
+
statusCode: number;
|
|
75
|
+
seqId: string | null;
|
|
76
|
+
is_handshake_response: boolean;
|
|
77
|
+
err: string;
|
|
78
|
+
err_detail: {
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
} | null;
|
|
61
81
|
}
|
|
62
|
-
export interface
|
|
82
|
+
export interface SuccessResponseMessage {
|
|
63
83
|
status: boolean;
|
|
64
84
|
statusCode: number;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
seqId: string | null;
|
|
86
|
+
is_handshake_response: boolean;
|
|
87
|
+
data: {
|
|
88
|
+
[key: string]: any;
|
|
89
|
+
};
|
|
68
90
|
}
|
|
69
|
-
export interface
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}> {
|
|
91
|
+
export interface EventMessage {
|
|
92
|
+
type: string;
|
|
93
|
+
event_type: string;
|
|
94
|
+
event: {
|
|
95
|
+
data: any;
|
|
96
|
+
roomId: string;
|
|
97
|
+
};
|
|
77
98
|
}
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
export type RequestResponse = ErrorResponseMessage | SuccessResponseMessage;
|
|
100
|
+
export type OnMessagePayloadType = RequestResponse | EventMessage;
|
|
101
|
+
export type EventHandler = (message: EventMessage) => void;
|
|
102
|
+
export type DisconnectHandler = (e: CloseEvent | ErrorEvent) => void;
|
|
103
|
+
export type ConnectHandler = () => void;
|
|
104
|
+
export interface PartialRequest {
|
|
105
|
+
cmd: string;
|
|
106
|
+
args: {
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export interface RequestPayload extends PartialRequest {
|
|
111
|
+
seqId: string;
|
|
112
|
+
}
|
|
113
|
+
export type SequenceResponseCB = (data: RequestResponse) => void;
|
|
114
|
+
export interface SequenceToRequestMapValue {
|
|
115
|
+
callback: SequenceResponseCB;
|
|
84
116
|
}
|
|
117
|
+
export type SequenceToRequestMap = {
|
|
118
|
+
[key: string]: SequenceToRequestMapValue;
|
|
119
|
+
};
|
|
120
|
+
export type Update = Uint8Array;
|
|
85
121
|
export interface ISocketInitConfig {
|
|
86
|
-
onConnect:
|
|
87
|
-
onDisconnect:
|
|
122
|
+
onConnect: ConnectHandler;
|
|
123
|
+
onDisconnect: DisconnectHandler;
|
|
88
124
|
onError: (err: Error) => void;
|
|
125
|
+
onWsEvent: EventHandler;
|
|
89
126
|
onHandShakeError: (err: Error) => void;
|
|
90
|
-
|
|
91
|
-
id: string;
|
|
92
|
-
data: string;
|
|
93
|
-
createdAt: number;
|
|
94
|
-
roomId: string;
|
|
95
|
-
}) => void;
|
|
96
|
-
onMembershipChange: (data: {
|
|
97
|
-
action: string;
|
|
98
|
-
user: {
|
|
99
|
-
role: string;
|
|
100
|
-
};
|
|
101
|
-
roomId: string;
|
|
102
|
-
}) => void;
|
|
103
|
-
onSessionTerminated: (data: {
|
|
104
|
-
roomId: string;
|
|
105
|
-
}) => void;
|
|
127
|
+
roomId: string;
|
|
106
128
|
}
|
|
107
129
|
export declare enum SocketStatusEnum {
|
|
108
130
|
CLOSED = "CLOSED",
|
|
@@ -116,6 +138,19 @@ export interface RoomMember {
|
|
|
116
138
|
userId: string;
|
|
117
139
|
role: 'owner' | 'editor';
|
|
118
140
|
}
|
|
141
|
+
export type IAesKey = string;
|
|
142
|
+
export type SyncMachinEvent = {
|
|
143
|
+
type: string;
|
|
144
|
+
data: any;
|
|
145
|
+
};
|
|
146
|
+
export interface IpfsUploadResponse {
|
|
147
|
+
ipfsUrl: string;
|
|
148
|
+
ipfsHash: string;
|
|
149
|
+
ipfsStorage: string;
|
|
150
|
+
cachedUrl: string;
|
|
151
|
+
fileSize: number;
|
|
152
|
+
mimetype: string;
|
|
153
|
+
}
|
|
119
154
|
export interface IAuthArgs {
|
|
120
155
|
collaborationToken: string;
|
|
121
156
|
documentId: string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SyncMachineContext } from '.';
|
|
2
|
+
|
|
3
|
+
export interface IConnectConf {
|
|
4
|
+
username?: string;
|
|
5
|
+
roomKey: string;
|
|
6
|
+
roomId: string;
|
|
7
|
+
isOwner: boolean;
|
|
8
|
+
ownerEdSecret?: string;
|
|
9
|
+
contractAddress?: string;
|
|
10
|
+
ownerAddress?: string;
|
|
11
|
+
isEns?: boolean;
|
|
12
|
+
wsUrl: string;
|
|
13
|
+
roomInfo?: {
|
|
14
|
+
documentTitle: string;
|
|
15
|
+
portalAddress: string;
|
|
16
|
+
commentKey: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare const useSyncMachine: (config: Partial<SyncMachineContext>) => {
|
|
20
|
+
connect: (connectConfig: IConnectConf) => void;
|
|
21
|
+
disconnect: () => void;
|
|
22
|
+
isConnected: any;
|
|
23
|
+
isReady: boolean;
|
|
24
|
+
error: any;
|
|
25
|
+
terminateSession: () => void;
|
|
26
|
+
awareness: any;
|
|
27
|
+
hasCollabContentInitialised: boolean;
|
|
28
|
+
state: import('xstate').State<SyncMachineContext, {
|
|
29
|
+
type: string;
|
|
30
|
+
data: any;
|
|
31
|
+
}, any, {
|
|
32
|
+
value: any;
|
|
33
|
+
context: SyncMachineContext;
|
|
34
|
+
}, import('xstate').ResolveTypegenMeta<import('xstate').TypegenDisabled, {
|
|
35
|
+
type: string;
|
|
36
|
+
data: any;
|
|
37
|
+
}, import('xstate').BaseActionObject, import('xstate').ServiceMap>>;
|
|
38
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
-
import {
|
|
2
|
+
import { SyncMachineContext } from '../types';
|
|
3
3
|
|
|
4
|
-
export declare const createAwarenessUpdateHandler: (awareness: Awareness,
|
|
4
|
+
export declare const createAwarenessUpdateHandler: (awareness: Awareness, context: SyncMachineContext) => ({ added, updated, removed, }: {
|
|
5
5
|
added: number[];
|
|
6
6
|
updated: number[];
|
|
7
7
|
removed: number[];
|
|
8
|
-
}
|
|
8
|
+
}) => void;
|