@fileverse-dev/ddoc 3.0.67 → 3.0.69-rtc-patch-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +28650 -30320
- package/dist/package/hooks/use-tab-editor.d.ts +4 -5
- package/dist/package/hooks/use-tab-manager.d.ts +1 -1
- package/dist/package/hooks/use-yjs-setup.d.ts +6 -11
- package/dist/package/sync-local/SyncManager.d.ts +55 -0
- package/dist/package/sync-local/collabStateMachine.d.ts +23 -0
- package/dist/package/sync-local/index.d.ts +3 -6
- package/dist/package/sync-local/socketClient.d.ts +22 -29
- package/dist/package/sync-local/types/index.d.ts +156 -123
- package/dist/package/sync-local/useSyncManager.d.ts +11 -0
- package/dist/package/sync-local/utils/createAwarenessUpdateHandler.d.ts +3 -3
- package/dist/package/types.d.ts +3 -31
- package/dist/package/use-ddoc-editor.d.ts +4 -3
- package/package.json +3 -7
- package/dist/package/hooks/use-rtc-websocket-disconnector.d.ts +0 -1
- package/dist/package/sync-local/actions/index.d.ts +0 -137
- package/dist/package/sync-local/actions/syncMachineActions.d.ts +0 -1
- package/dist/package/sync-local/constants/config.d.ts +0 -7
- package/dist/package/sync-local/constants/index.d.ts +0 -5
- package/dist/package/sync-local/guards/syncMachineGuards.d.ts +0 -10
- package/dist/package/sync-local/services/syncMachineServices.d.ts +0 -19
- package/dist/package/sync-local/syncMachine.d.ts +0 -13
- package/dist/package/sync-local/useSyncMachine.d.ts +0 -38
|
@@ -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 { CollabConnectionConfig, CollaborationProps } from '../sync-local/types';
|
|
6
6
|
|
|
7
7
|
import * as Y from 'yjs';
|
|
8
8
|
interface UseTabEditorArgs {
|
|
@@ -12,8 +12,7 @@ interface UseTabEditorArgs {
|
|
|
12
12
|
versionId?: string;
|
|
13
13
|
isPreviewMode?: boolean;
|
|
14
14
|
initialContent: DdocProps['initialContent'];
|
|
15
|
-
|
|
16
|
-
collabConfig?: DdocProps['collabConfig'];
|
|
15
|
+
collaboration?: CollaborationProps;
|
|
17
16
|
isReady?: boolean;
|
|
18
17
|
awareness?: any;
|
|
19
18
|
disableInlineComment?: boolean;
|
|
@@ -38,7 +37,7 @@ interface UseTabEditorArgs {
|
|
|
38
37
|
onInvalidContentError?: DdocProps['onInvalidContentError'];
|
|
39
38
|
ignoreCorruptedData?: boolean;
|
|
40
39
|
onCollaboratorChange?: DdocProps['onCollaboratorChange'];
|
|
41
|
-
onConnect: (connectConfig:
|
|
40
|
+
onConnect: (connectConfig: CollabConnectionConfig) => void;
|
|
42
41
|
hasCollabContentInitialised?: boolean;
|
|
43
42
|
initialiseYjsIndexedDbProvider: () => Promise<void>;
|
|
44
43
|
externalExtensions?: Record<string, AnyExtension>;
|
|
@@ -47,7 +46,7 @@ interface UseTabEditorArgs {
|
|
|
47
46
|
theme?: 'dark' | 'light';
|
|
48
47
|
editorRef?: MutableRefObject<Editor | null>;
|
|
49
48
|
}
|
|
50
|
-
export declare const useTabEditor: ({ ydoc, isVersionMode, hasTabState, versionId, isPreviewMode, initialContent,
|
|
49
|
+
export declare const useTabEditor: ({ ydoc, isVersionMode, hasTabState, versionId, isPreviewMode, initialContent, collaboration, isReady, awareness, disableInlineComment, onCommentInteraction, onError, ipfsImageUploadFn, metadataProxyUrl, onCopyHeadingLink, ipfsImageFetchFn, fetchV1ImageFn, isConnected, activeModel, maxTokens, isAIAgentEnabled, setCharacterCount, setWordCount, setIsContentLoading, setIsCollabContentLoading, unFocused, zoomLevel, isPresentationMode, onInvalidContentError, ignoreCorruptedData, onCollaboratorChange, onConnect, hasCollabContentInitialised, initialiseYjsIndexedDbProvider, externalExtensions, isContentLoading, activeTabId, theme, editorRef, }: UseTabEditorArgs) => {
|
|
51
50
|
editor: Editor | null;
|
|
52
51
|
ref: import('react').RefObject<HTMLDivElement>;
|
|
53
52
|
slides: string[];
|
|
@@ -5,7 +5,7 @@ import * as Y from 'yjs';
|
|
|
5
5
|
interface UseTabManagerArgs {
|
|
6
6
|
ydoc: Y.Doc;
|
|
7
7
|
initialContent: DdocProps['initialContent'];
|
|
8
|
-
enableCollaboration
|
|
8
|
+
enableCollaboration?: boolean;
|
|
9
9
|
isDDocOwner: boolean;
|
|
10
10
|
createDefaultTabIfMissing: boolean;
|
|
11
11
|
shouldSyncActiveTab: boolean;
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
import { JSONContent } from '@tiptap/react';
|
|
2
|
-
import {
|
|
2
|
+
import { CollaborationProps } from '../sync-local/types';
|
|
3
3
|
import * as Y from 'yjs';
|
|
4
4
|
interface UseYjsSetupArgs {
|
|
5
5
|
onChange?: (updatedDocContent: string | JSONContent, updateChunk: string) => void;
|
|
6
6
|
enableIndexeddbSync?: boolean;
|
|
7
7
|
ddocId?: string;
|
|
8
|
-
|
|
8
|
+
collaboration?: CollaborationProps;
|
|
9
9
|
onIndexedDbError?: (error: Error) => void;
|
|
10
|
-
onCollabError?: DdocProps['onCollabError'];
|
|
11
|
-
onCollaborationConnectCallback?: DdocProps['onCollaborationConnectCallback'];
|
|
12
|
-
onCollaborationCommit?: DdocProps['onCollaborationCommit'];
|
|
13
|
-
onFetchCommitContent?: DdocProps['onFetchCommitContent'];
|
|
14
|
-
onCollabSessionTermination?: () => void;
|
|
15
|
-
onUnMergedUpdates?: (state: boolean) => void;
|
|
16
10
|
}
|
|
17
|
-
export declare const useYjsSetup: ({ onChange, enableIndexeddbSync, ddocId,
|
|
11
|
+
export declare const useYjsSetup: ({ onChange, enableIndexeddbSync, ddocId, collaboration, onIndexedDbError, }: UseYjsSetupArgs) => {
|
|
18
12
|
ydoc: Y.Doc;
|
|
19
|
-
onConnect: (connectConfig: import('../
|
|
13
|
+
onConnect: (connectConfig: import('../types').CollabConnectionConfig) => void;
|
|
20
14
|
isReady: boolean;
|
|
21
15
|
terminateSession: () => void;
|
|
22
|
-
awareness:
|
|
16
|
+
awareness: import('y-protocols/awareness.js').Awareness | null;
|
|
23
17
|
hasCollabContentInitialised: boolean;
|
|
24
18
|
initialiseYjsIndexedDbProvider: () => Promise<void>;
|
|
25
19
|
refreshYjsIndexedDbProvider: () => Promise<void>;
|
|
20
|
+
collabState: import('../types').CollabState;
|
|
26
21
|
};
|
|
27
22
|
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness.js';
|
|
2
|
+
import { SyncManagerConfig, CollabConnectionConfig, CollabServices, CollabCallbacks, CollabStatus, CollabState } from './types';
|
|
3
|
+
|
|
4
|
+
export declare class SyncManager {
|
|
5
|
+
private onCollabStateChange;
|
|
6
|
+
private _status;
|
|
7
|
+
private _context;
|
|
8
|
+
private _awareness;
|
|
9
|
+
private socketClient;
|
|
10
|
+
private roomKey;
|
|
11
|
+
private roomKeyBytes;
|
|
12
|
+
private isOwner;
|
|
13
|
+
private updateQueue;
|
|
14
|
+
private uncommittedUpdatesIdList;
|
|
15
|
+
private contentTobeAppliedQueue;
|
|
16
|
+
private isProcessing;
|
|
17
|
+
private _awarenessUpdateHandler;
|
|
18
|
+
private ydoc;
|
|
19
|
+
private servicesRef;
|
|
20
|
+
private callbacksRef;
|
|
21
|
+
private onLocalUpdate?;
|
|
22
|
+
constructor(config: SyncManagerConfig, onCollabStateChange: (state: CollabState) => void);
|
|
23
|
+
/** Called by useSyncManager on every render to keep refs fresh */
|
|
24
|
+
updateRefs(services: CollabServices | undefined, callbacks: CollabCallbacks | undefined, onLocalUpdate?: (updatedDocContent: string, updateChunk: string) => void): void;
|
|
25
|
+
get isConnected(): boolean;
|
|
26
|
+
get isReady(): boolean;
|
|
27
|
+
get awareness(): Awareness | null;
|
|
28
|
+
get status(): CollabStatus;
|
|
29
|
+
get collabState(): CollabState;
|
|
30
|
+
private send;
|
|
31
|
+
private runExitActions;
|
|
32
|
+
private runEntryActions;
|
|
33
|
+
connect(config: CollabConnectionConfig): Promise<void>;
|
|
34
|
+
disconnect(): Promise<void>;
|
|
35
|
+
terminateSession(): Promise<void>;
|
|
36
|
+
enqueueLocalUpdate(update: Uint8Array): void;
|
|
37
|
+
forceCleanup(): void;
|
|
38
|
+
private handleConnectionError;
|
|
39
|
+
private handleReconnection;
|
|
40
|
+
private connectSocket;
|
|
41
|
+
private syncLatestCommit;
|
|
42
|
+
private initializeAwareness;
|
|
43
|
+
private cleanupAwareness;
|
|
44
|
+
private commitLocalContents;
|
|
45
|
+
private broadcastLocalContents;
|
|
46
|
+
private processUpdateQueue;
|
|
47
|
+
private processNextUpdate;
|
|
48
|
+
private processCommit;
|
|
49
|
+
private handleRemoteContentUpdate;
|
|
50
|
+
private applyRemoteYjsUpdate;
|
|
51
|
+
private applyQueuedRemoteContents;
|
|
52
|
+
private withRetry;
|
|
53
|
+
private disconnectInternal;
|
|
54
|
+
private resetInternalState;
|
|
55
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CollabStatus, CollabEvent, CollabContext, CollabState, CollabErrorCode } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const INITIAL_CONTEXT: CollabContext;
|
|
4
|
+
type TransitionResult = {
|
|
5
|
+
status: CollabStatus;
|
|
6
|
+
context: Partial<CollabContext>;
|
|
7
|
+
} | null;
|
|
8
|
+
/**
|
|
9
|
+
* Transition map: (currentStatus, eventType) → nextStatus + context mutations.
|
|
10
|
+
* Returns null if the transition is invalid.
|
|
11
|
+
*/
|
|
12
|
+
export declare function transition(currentStatus: CollabStatus, event: CollabEvent, context: CollabContext): TransitionResult;
|
|
13
|
+
/**
|
|
14
|
+
* Derives the consumer-facing CollabState from internal status + context.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deriveCollabState(status: CollabStatus, context: CollabContext): CollabState;
|
|
17
|
+
/** Helper to create a CollabError */
|
|
18
|
+
export declare function createCollabError(code: CollabErrorCode, message: string, recoverable?: boolean): {
|
|
19
|
+
code: CollabErrorCode;
|
|
20
|
+
message: string;
|
|
21
|
+
recoverable: boolean;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { useSyncMachine } from './useSyncMachine';
|
|
5
|
-
export { syncMachine };
|
|
6
|
-
export type { SyncMachineContext };
|
|
1
|
+
export { useSyncManager } from './useSyncManager';
|
|
2
|
+
export { SyncManager } from './SyncManager';
|
|
3
|
+
export type { SyncManagerConfig, CollabConnectionConfig, CollabServices, CollabCallbacks, CollaborationProps, CollabSessionMeta, CollabStatus, CollabState, CollabError, CollabErrorCode, CollabEvent, CollabContext, } from './types';
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ISocketInitConfig, RoomMember, SocketStatusEnum, SendUpdateResponse, CommitResponse } from './types';
|
|
1
|
+
import { ISocketInitConfig, RoomMember, SocketStatusEnum, SendUpdateResponse, CommitResponse, AckResponse } from './types';
|
|
3
2
|
import { Awareness } from 'y-protocols/awareness.js';
|
|
4
3
|
|
|
5
4
|
interface ISocketClientConfig {
|
|
6
|
-
wsUrl:
|
|
5
|
+
wsUrl: string;
|
|
7
6
|
roomKey: string;
|
|
7
|
+
roomId: string;
|
|
8
8
|
ownerEdSecret?: string;
|
|
9
9
|
contractAddress?: string;
|
|
10
10
|
ownerAddress?: string;
|
|
11
|
-
|
|
11
|
+
onHandshakeData?: (response: {
|
|
12
|
+
data: AckResponse;
|
|
13
|
+
roomKey: string;
|
|
14
|
+
}) => void;
|
|
12
15
|
roomInfo?: {
|
|
13
16
|
documentTitle: string;
|
|
14
17
|
portalAddress: string;
|
|
@@ -16,14 +19,12 @@ interface ISocketClientConfig {
|
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
export declare class SocketClient {
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_webSocketStatus: SocketStatusEnum;
|
|
26
|
-
private _webSocket;
|
|
22
|
+
private _socketUrl;
|
|
23
|
+
private _socket;
|
|
24
|
+
private _webSocketStatus;
|
|
25
|
+
private _isIntentionalDisconnect;
|
|
26
|
+
get isConnected(): boolean;
|
|
27
|
+
get status(): SocketStatusEnum;
|
|
27
28
|
private _websocketServiceDid;
|
|
28
29
|
private roomId;
|
|
29
30
|
roomMembers: RoomMember[];
|
|
@@ -36,14 +37,11 @@ export declare class SocketClient {
|
|
|
36
37
|
private roomKey;
|
|
37
38
|
private roomInfo?;
|
|
38
39
|
private awareness;
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
private connectionAttemptErrorCount;
|
|
41
|
+
private _onHandshakeData;
|
|
41
42
|
constructor(config: ISocketClientConfig);
|
|
42
|
-
private _getSequenceIdCallback;
|
|
43
|
-
private _removeSequenceIdFromMap;
|
|
44
43
|
registerAwareness(awareness: Awareness): void;
|
|
45
|
-
private
|
|
46
|
-
private _sendNetworkRequest;
|
|
44
|
+
private _emitWithAck;
|
|
47
45
|
private _fetchRoomMembers;
|
|
48
46
|
sendUpdate({ update }: {
|
|
49
47
|
update: string;
|
|
@@ -52,24 +50,19 @@ export declare class SocketClient {
|
|
|
52
50
|
updates: string[];
|
|
53
51
|
cid: string;
|
|
54
52
|
}): Promise<CommitResponse>;
|
|
55
|
-
fetchLatestCommit(): Promise<any
|
|
56
|
-
getUncommittedChanges(): Promise<any
|
|
57
|
-
broadcastAwareness(awarenessUpdate: string): Promise<
|
|
58
|
-
disconnect: (
|
|
53
|
+
fetchLatestCommit(): Promise<AckResponse<any>>;
|
|
54
|
+
getUncommittedChanges(): Promise<AckResponse<any>>;
|
|
55
|
+
broadcastAwareness(awarenessUpdate: string): Promise<void>;
|
|
56
|
+
disconnect: () => void;
|
|
59
57
|
terminateSession: () => Promise<void>;
|
|
60
|
-
private _buildRequest;
|
|
61
58
|
private getCollaborationKeyPair;
|
|
62
59
|
private isUcanValid;
|
|
63
60
|
private getOwnerToken;
|
|
64
61
|
private buildSessionToken;
|
|
65
62
|
private _handleHandShake;
|
|
66
|
-
private
|
|
67
|
-
|
|
63
|
+
private _handleAwarenessUpdate;
|
|
64
|
+
connectSocket(config: ISocketInitConfig): Promise<void>;
|
|
68
65
|
private _onSessionTerminated;
|
|
69
|
-
private _processMessage;
|
|
70
|
-
private _clearSequenceCallbackMap;
|
|
71
|
-
connectSocket(): Promise<void> | undefined;
|
|
72
|
-
init(config: ISocketInitConfig): Promise<void>;
|
|
73
66
|
private resetSocketClient;
|
|
74
67
|
}
|
|
75
68
|
export {};
|
|
@@ -1,130 +1,176 @@
|
|
|
1
|
-
import { Data } from '../../types';
|
|
2
|
-
import { SocketClient } from '../socketClient';
|
|
1
|
+
import { Data, IDocCollabUsers } from '../../types';
|
|
3
2
|
|
|
4
3
|
import * as Y from 'yjs';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/** Connection identity — changes to these trigger reconnect */
|
|
5
|
+
export interface CollabConnectionConfig {
|
|
6
|
+
roomKey: string;
|
|
7
|
+
roomId: string;
|
|
8
|
+
wsUrl: string;
|
|
9
|
+
isOwner: boolean;
|
|
10
|
+
ownerEdSecret?: string;
|
|
11
|
+
contractAddress?: string;
|
|
12
|
+
ownerAddress?: string;
|
|
13
|
+
roomInfo?: {
|
|
14
|
+
documentTitle: string;
|
|
15
|
+
portalAddress: string;
|
|
16
|
+
commentKey: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Session metadata — changes to these update awareness, NOT reconnect */
|
|
20
|
+
export interface CollabSessionMeta {
|
|
7
21
|
username: string;
|
|
8
|
-
|
|
22
|
+
isEns?: boolean;
|
|
9
23
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
24
|
+
/** Storage integrations the sync engine depends on */
|
|
25
|
+
export interface CollabServices {
|
|
26
|
+
commitToStorage?: (file: File) => Promise<string>;
|
|
27
|
+
fetchFromStorage?: (cid: string) => Promise<any>;
|
|
24
28
|
}
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
status:
|
|
36
|
-
|
|
29
|
+
export type CollabErrorCode = 'CONNECTION_FAILED' | 'AUTH_FAILED' | 'SYNC_FAILED' | 'TIMEOUT' | 'UNKNOWN';
|
|
30
|
+
export type CollabError = {
|
|
31
|
+
code: CollabErrorCode;
|
|
32
|
+
message: string;
|
|
33
|
+
recoverable: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type CollabStatus = 'idle' | 'connecting' | 'syncing' | 'ready' | 'reconnecting' | 'error' | 'terminated';
|
|
36
|
+
export type CollabState = {
|
|
37
|
+
status: 'idle';
|
|
38
|
+
} | {
|
|
39
|
+
status: 'connecting';
|
|
40
|
+
} | {
|
|
41
|
+
status: 'syncing';
|
|
42
|
+
hasUnmergedPeerUpdates: boolean;
|
|
43
|
+
} | {
|
|
44
|
+
status: 'ready';
|
|
45
|
+
} | {
|
|
46
|
+
status: 'reconnecting';
|
|
47
|
+
attempt: number;
|
|
48
|
+
maxAttempts: number;
|
|
49
|
+
} | {
|
|
50
|
+
status: 'error';
|
|
51
|
+
error: CollabError;
|
|
52
|
+
} | {
|
|
53
|
+
status: 'terminated';
|
|
54
|
+
reason?: string;
|
|
55
|
+
};
|
|
56
|
+
export type CollabEvent = {
|
|
57
|
+
type: 'CONNECT';
|
|
58
|
+
} | {
|
|
59
|
+
type: 'AUTH_SUCCESS';
|
|
60
|
+
} | {
|
|
61
|
+
type: 'SYNC_COMPLETE';
|
|
62
|
+
} | {
|
|
63
|
+
type: 'SET_UNMERGED_UPDATES';
|
|
64
|
+
hasUpdates: boolean;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'SOCKET_DROPPED';
|
|
67
|
+
} | {
|
|
68
|
+
type: 'RECONNECTED';
|
|
69
|
+
} | {
|
|
70
|
+
type: 'RETRY_EXHAUSTED';
|
|
71
|
+
} | {
|
|
72
|
+
type: 'ERROR';
|
|
73
|
+
error: CollabError;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'SESSION_TERMINATED';
|
|
76
|
+
reason?: string;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'RESET';
|
|
79
|
+
};
|
|
80
|
+
export interface CollabContext {
|
|
81
|
+
hasUnmergedPeerUpdates: boolean;
|
|
82
|
+
reconnectAttempt: number;
|
|
83
|
+
maxReconnectAttempts: number;
|
|
84
|
+
error: CollabError | null;
|
|
85
|
+
terminationReason?: string;
|
|
37
86
|
}
|
|
38
|
-
|
|
87
|
+
/** Event callbacks the consumer reacts to */
|
|
88
|
+
export interface CollabCallbacks {
|
|
89
|
+
onStateChange?: (state: CollabState) => void;
|
|
90
|
+
onError?: (error: CollabError) => void;
|
|
91
|
+
onCollaboratorsChange?: (collaborators: IDocCollabUsers[]) => void;
|
|
92
|
+
onHandshakeData?: (data: {
|
|
93
|
+
data: AckResponse;
|
|
94
|
+
roomKey: string;
|
|
95
|
+
}) => void;
|
|
96
|
+
}
|
|
97
|
+
/** Discriminated union — TypeScript enforces config+services only when enabled */
|
|
98
|
+
export type CollaborationProps = {
|
|
99
|
+
enabled: false;
|
|
100
|
+
} | {
|
|
101
|
+
enabled: true;
|
|
102
|
+
connection: CollabConnectionConfig;
|
|
103
|
+
session: CollabSessionMeta;
|
|
104
|
+
services: CollabServices;
|
|
105
|
+
on?: CollabCallbacks;
|
|
106
|
+
};
|
|
107
|
+
export interface SyncManagerConfig {
|
|
39
108
|
ydoc: Y.Doc;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
username: string;
|
|
43
|
-
roomMembers: IRoomMember[];
|
|
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[];
|
|
57
|
-
isReady: boolean;
|
|
58
|
-
isNewDoc: boolean;
|
|
59
|
-
contentTobeAppliedQueue: string[];
|
|
60
|
-
initialUpdate: string | null;
|
|
61
|
-
errorCount: number;
|
|
62
|
-
errorMaxRetryCount: number;
|
|
63
|
-
errorMessage: string;
|
|
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;
|
|
109
|
+
services?: CollabServices;
|
|
110
|
+
callbacks?: CollabCallbacks;
|
|
70
111
|
onLocalUpdate?: (updatedDocContent: Data['editorJSONData'], updateChunk: string) => void;
|
|
71
112
|
}
|
|
72
|
-
export
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
export declare enum ServerErrorCode {
|
|
114
|
+
AUTH_TOKEN_MISSING = "AUTH_TOKEN_MISSING",
|
|
115
|
+
AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID",
|
|
116
|
+
SESSION_NOT_FOUND = "SESSION_NOT_FOUND",
|
|
117
|
+
SESSION_TERMINATED = "SESSION_TERMINATED",
|
|
118
|
+
SESSION_DID_MISSING = "SESSION_DID_MISSING",
|
|
119
|
+
DOCUMENT_ID_MISSING = "DOCUMENT_ID_MISSING",
|
|
120
|
+
UPDATE_DATA_MISSING = "UPDATE_DATA_MISSING",
|
|
121
|
+
COMMIT_UNAUTHORIZED = "COMMIT_UNAUTHORIZED",
|
|
122
|
+
COMMIT_MISSING_DATA = "COMMIT_MISSING_DATA",
|
|
123
|
+
INVALID_ADDRESS = "INVALID_ADDRESS",
|
|
124
|
+
NOT_AUTHENTICATED = "NOT_AUTHENTICATED",
|
|
125
|
+
DB_ERROR = "DB_ERROR",
|
|
126
|
+
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
81
127
|
}
|
|
82
|
-
export interface
|
|
128
|
+
export interface AckResponse<T = Record<string, any>> {
|
|
83
129
|
status: boolean;
|
|
84
130
|
statusCode: number;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[key: string]: any;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export interface EventMessage {
|
|
92
|
-
type: string;
|
|
93
|
-
event_type: string;
|
|
94
|
-
event: {
|
|
95
|
-
data: any;
|
|
96
|
-
roomId: string;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
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
|
-
};
|
|
131
|
+
data?: T;
|
|
132
|
+
error?: string;
|
|
133
|
+
errorCode?: ServerErrorCode;
|
|
109
134
|
}
|
|
110
|
-
export interface
|
|
111
|
-
|
|
135
|
+
export interface SendUpdateResponse extends AckResponse<{
|
|
136
|
+
id: string;
|
|
137
|
+
documentId: string;
|
|
138
|
+
data: string;
|
|
139
|
+
updateType: string;
|
|
140
|
+
commitCid: string | null;
|
|
141
|
+
createdAt: number;
|
|
142
|
+
}> {
|
|
112
143
|
}
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
export interface CommitResponse extends AckResponse<{
|
|
145
|
+
cid: string;
|
|
146
|
+
createdAt: number;
|
|
147
|
+
documentId: string;
|
|
148
|
+
updates: string[];
|
|
149
|
+
}> {
|
|
116
150
|
}
|
|
117
|
-
export type SequenceToRequestMap = {
|
|
118
|
-
[key: string]: SequenceToRequestMapValue;
|
|
119
|
-
};
|
|
120
|
-
export type Update = Uint8Array;
|
|
121
151
|
export interface ISocketInitConfig {
|
|
122
|
-
|
|
123
|
-
onDisconnect:
|
|
152
|
+
onHandshakeSuccess: () => void;
|
|
153
|
+
onDisconnect: () => void;
|
|
154
|
+
onSocketDropped: () => void;
|
|
124
155
|
onError: (err: Error) => void;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
156
|
+
onHandShakeError: (err: Error, statusCode?: number) => void;
|
|
157
|
+
onContentUpdate: (data: {
|
|
158
|
+
id: string;
|
|
159
|
+
data: string;
|
|
160
|
+
createdAt: number;
|
|
161
|
+
roomId: string;
|
|
162
|
+
}) => void;
|
|
163
|
+
onMembershipChange: (data: {
|
|
164
|
+
action: string;
|
|
165
|
+
user: {
|
|
166
|
+
role: string;
|
|
167
|
+
};
|
|
168
|
+
roomId: string;
|
|
169
|
+
}) => void;
|
|
170
|
+
onSessionTerminated: (data: {
|
|
171
|
+
roomId: string;
|
|
172
|
+
}) => void;
|
|
173
|
+
onReconnectFailed: () => void;
|
|
128
174
|
}
|
|
129
175
|
export declare enum SocketStatusEnum {
|
|
130
176
|
CLOSED = "CLOSED",
|
|
@@ -138,19 +184,6 @@ export interface RoomMember {
|
|
|
138
184
|
userId: string;
|
|
139
185
|
role: 'owner' | 'editor';
|
|
140
186
|
}
|
|
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
|
-
}
|
|
154
187
|
export interface IAuthArgs {
|
|
155
188
|
collaborationToken: string;
|
|
156
189
|
documentId: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SyncManagerConfig, CollabConnectionConfig, CollabState } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const useSyncManager: (config: SyncManagerConfig) => {
|
|
4
|
+
state: CollabState;
|
|
5
|
+
connect: (connectConfig: CollabConnectionConfig) => void;
|
|
6
|
+
disconnect: () => void;
|
|
7
|
+
terminateSession: () => void;
|
|
8
|
+
isReady: boolean;
|
|
9
|
+
awareness: import('y-protocols/awareness.js').Awareness | null;
|
|
10
|
+
hasCollabContentInitialised: boolean;
|
|
11
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
-
import {
|
|
2
|
+
import { SocketClient } from '../socketClient';
|
|
3
3
|
|
|
4
|
-
export declare const createAwarenessUpdateHandler: (awareness: Awareness,
|
|
4
|
+
export declare const createAwarenessUpdateHandler: (awareness: Awareness, socketClient: SocketClient, roomKey: string) => ({ added, updated, removed, }: {
|
|
5
5
|
added: number[];
|
|
6
6
|
updated: number[];
|
|
7
7
|
removed: number[];
|
|
8
|
-
}) => void;
|
|
8
|
+
}, origin: any) => void;
|
package/dist/package/types.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { EditorProps } from '@tiptap/pm/view';
|
|
|
4
4
|
import { Editor } from '@tiptap/react';
|
|
5
5
|
import { default as React, SetStateAction } from 'react';
|
|
6
6
|
import { IComment } from './extensions/comment';
|
|
7
|
+
import { CollaborationProps } from './sync-local/types';
|
|
7
8
|
|
|
9
|
+
export type { CollaborationProps, CollabConnectionConfig, CollabSessionMeta, CollabServices, CollabCallbacks, CollabState, CollabError, CollabErrorCode, CollabStatus, } from './sync-local/types';
|
|
8
10
|
export declare const DdocEditorProps: EditorProps;
|
|
9
11
|
export interface IDocCollabUsers {
|
|
10
12
|
clientId: number;
|
|
@@ -113,7 +115,7 @@ export interface DdocProps extends CommentAccountProps {
|
|
|
113
115
|
extensions?: Record<string, Extension | any>;
|
|
114
116
|
selectedTags?: TagType[];
|
|
115
117
|
setSelectedTags?: React.Dispatch<SetStateAction<TagType[]>>;
|
|
116
|
-
|
|
118
|
+
collaboration?: CollaborationProps;
|
|
117
119
|
setIsCommentSectionOpen?: React.Dispatch<SetStateAction<boolean>>;
|
|
118
120
|
inlineCommentData?: InlineCommentData;
|
|
119
121
|
setInlineCommentData?: React.Dispatch<React.SetStateAction<InlineCommentData>>;
|
|
@@ -124,7 +126,6 @@ export interface DdocProps extends CommentAccountProps {
|
|
|
124
126
|
setIsNavbarVisible: React.Dispatch<SetStateAction<boolean>>;
|
|
125
127
|
editorCanvasClassNames?: string;
|
|
126
128
|
isCommentSectionOpen?: boolean;
|
|
127
|
-
collaborationId?: string;
|
|
128
129
|
isPreviewMode: boolean;
|
|
129
130
|
ensResolutionUrl?: string;
|
|
130
131
|
ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
|
|
@@ -175,24 +176,11 @@ export interface DdocProps extends CommentAccountProps {
|
|
|
175
176
|
activeModel?: CustomModel;
|
|
176
177
|
maxTokens?: number;
|
|
177
178
|
isAIAgentEnabled?: boolean;
|
|
178
|
-
collaborationKey?: CryptoKey | null;
|
|
179
|
-
collaborationKeyPair?: {
|
|
180
|
-
publicKey: string;
|
|
181
|
-
privateKey: string;
|
|
182
|
-
};
|
|
183
|
-
collabConfig?: ICollaborationConfig;
|
|
184
179
|
/**
|
|
185
180
|
* Document styling configuration
|
|
186
181
|
* @description Customize the appearance of the document editor
|
|
187
182
|
*/
|
|
188
183
|
documentStyling?: DocumentStyling;
|
|
189
|
-
onCollaborationConnectCallback?: (response: any) => void;
|
|
190
|
-
onCollaborationCommit?: (file: File) => Promise<string>;
|
|
191
|
-
onFetchCommitContent?: (cid: string) => Promise<any>;
|
|
192
|
-
onCollabSessionTermination?: () => void;
|
|
193
|
-
onUnMergedUpdates?: (state: boolean) => void;
|
|
194
|
-
onCollabError?: (error: any) => void;
|
|
195
|
-
isExistingCollabSession?: boolean;
|
|
196
184
|
/**
|
|
197
185
|
* Callback when IndexedDB initialization fails
|
|
198
186
|
* @description Called when the IndexedDB persistence provider fails to initialize (e.g., private browsing, quota exceeded, corrupted DB). The editor will continue to function without local persistence.
|
|
@@ -229,19 +217,3 @@ export interface IpfsImageFetchPayload {
|
|
|
229
217
|
mimeType: string;
|
|
230
218
|
authTag: string;
|
|
231
219
|
}
|
|
232
|
-
export interface ICollaborationConfig {
|
|
233
|
-
roomKey: string;
|
|
234
|
-
collaborationId: string;
|
|
235
|
-
username: string;
|
|
236
|
-
isOwner: boolean;
|
|
237
|
-
ownerEdSecret?: string;
|
|
238
|
-
contractAddress?: string;
|
|
239
|
-
ownerAddress?: string;
|
|
240
|
-
wsUrl: string;
|
|
241
|
-
isEns?: boolean;
|
|
242
|
-
roomInfo?: {
|
|
243
|
-
documentTitle: string;
|
|
244
|
-
portalAddress: string;
|
|
245
|
-
commentKey: string;
|
|
246
|
-
};
|
|
247
|
-
}
|