@fileverse-dev/ddoc 2.3.4 → 2.4.0
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/{ccip-Dxo0827_.mjs → ccip-6RfBwSKM.mjs} +1 -1
- package/dist/{index-BDeTWJWD.mjs → index-CT3AMJnE.mjs} +45142 -37037
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1 -1
- package/dist/package/components/editor-bubble-menu/props.d.ts +2 -0
- package/dist/package/components/editor-bubble-menu/types.d.ts +2 -0
- package/dist/package/extensions/slash-command/slash-comand.d.ts +1 -1
- package/dist/package/extensions/slash-command/slash-command-utils.d.ts +10 -1
- package/dist/package/extensions/sync-cursor.d.ts +28 -0
- package/dist/package/hooks/use-editing-context.d.ts +2 -0
- package/dist/package/sync-local/actions/index.d.ts +144 -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/crypto/index.d.ts +6 -0
- package/dist/package/sync-local/guards/syncMachineGuards.d.ts +10 -0
- package/dist/package/sync-local/index.d.ts +6 -0
- package/dist/package/sync-local/services/syncMachineServices.d.ts +19 -0
- package/dist/package/sync-local/socketClient.d.ts +72 -0
- package/dist/package/sync-local/syncMachine.d.ts +13 -0
- package/dist/package/sync-local/types/index.d.ts +159 -0
- package/dist/package/sync-local/useSyncMachine.d.ts +31 -0
- package/dist/package/sync-local/utils/createAwarenessUpdateHandler.d.ts +8 -0
- package/dist/package/sync-local/utils/objectToFile.d.ts +1 -0
- package/dist/package/types.d.ts +30 -0
- package/dist/package/use-ddoc-editor.d.ts +2 -2
- package/dist/package/utils/template-utils.d.ts +1 -1
- package/dist/style.css +1 -1
- package/package.json +16 -2
package/dist/index.d.ts
CHANGED
@@ -5,3 +5,4 @@ export { useHeadlessEditor } from './package/hooks/use-headless-editor';
|
|
5
5
|
export { ReminderBlock } from './package/extensions/reminder-block/reminder-block';
|
6
6
|
export { type Reminder, type ReminderBlockOptions, } from './package/extensions/reminder-block/types';
|
7
7
|
export { Editor } from '@tiptap/react';
|
8
|
+
export type { ICollaborationConfig } from './package/types';
|
package/dist/index.es.js
CHANGED
@@ -61,6 +61,8 @@ export declare const bubbleMenuProps: (props: EditorBubbleMenuProps) => {
|
|
61
61
|
}>;
|
62
62
|
onReminderCreate?: (reminder: import('../../..').Reminder, type: string) => void;
|
63
63
|
isConnected?: boolean;
|
64
|
+
isCollabDocOwner?: boolean;
|
65
|
+
enableCollaboration?: boolean;
|
64
66
|
};
|
65
67
|
export declare const shouldShow: ({ editor }: {
|
66
68
|
editor: Editor;
|
@@ -31,6 +31,8 @@ export type EditorBubbleMenuProps = Omit<BubbleMenuProps, 'children'> & {
|
|
31
31
|
}>;
|
32
32
|
onReminderCreate?: (reminder: Reminder, type: string) => void;
|
33
33
|
isConnected?: boolean;
|
34
|
+
isCollabDocOwner?: boolean;
|
35
|
+
enableCollaboration?: boolean;
|
34
36
|
};
|
35
37
|
export interface NodeSelectorProps {
|
36
38
|
editor: Editor;
|
@@ -2,5 +2,5 @@ import { Extension } from '@tiptap/core';
|
|
2
2
|
import { IpfsImageUploadResponse } from '../../types';
|
3
3
|
|
4
4
|
export declare const Command: Extension<any, any>;
|
5
|
-
declare const SlashCommand: (onError?: (errorString: string) => void, ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>, isConnected?: boolean) => Extension<any, any>;
|
5
|
+
declare const SlashCommand: (onError?: (errorString: string) => void, ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>, isConnected?: boolean, enableCollaboration?: boolean) => Extension<any, any>;
|
6
6
|
export default SlashCommand;
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { CommandProps } from './types';
|
2
2
|
import { IpfsImageUploadResponse } from '../../types';
|
3
3
|
|
4
|
-
export declare const getSuggestionItems: ({ query, onError, isConnected, ipfsImageUploadFn, editor, }: {
|
4
|
+
export declare const getSuggestionItems: ({ query, onError, isConnected, ipfsImageUploadFn, editor, enableCollaboration, }: {
|
5
5
|
query: string;
|
6
6
|
onError?: (errorString: string) => void;
|
7
7
|
ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
|
8
8
|
isConnected?: boolean;
|
9
9
|
editor?: any;
|
10
|
+
enableCollaboration?: boolean;
|
10
11
|
}) => ({
|
11
12
|
title: string;
|
12
13
|
description: string;
|
@@ -23,5 +24,13 @@ export declare const getSuggestionItems: ({ query, onError, isConnected, ipfsIma
|
|
23
24
|
image: string;
|
24
25
|
command: ({ editor, range }: CommandProps) => void;
|
25
26
|
isDisabled?: undefined;
|
27
|
+
} | {
|
28
|
+
title: string;
|
29
|
+
description: string;
|
30
|
+
searchTerms: string[];
|
31
|
+
icon: import("react/jsx-runtime").JSX.Element;
|
32
|
+
image: string;
|
33
|
+
isDisabled: boolean | undefined;
|
34
|
+
command: ({ editor, range }: CommandProps) => true | undefined;
|
26
35
|
})[];
|
27
36
|
export declare const updateScrollView: (container: HTMLElement, item: HTMLElement) => void;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
2
|
+
|
3
|
+
type CollaborationCursorStorage = {
|
4
|
+
users: {
|
5
|
+
clientId: number;
|
6
|
+
[key: string]: any;
|
7
|
+
}[];
|
8
|
+
};
|
9
|
+
export interface CollaborationCursorOptions {
|
10
|
+
provider: any;
|
11
|
+
user: Record<string, any>;
|
12
|
+
render(user: Record<string, any>): HTMLElement;
|
13
|
+
selectionRender(user: Record<string, any>): any;
|
14
|
+
onUpdate: (users: {
|
15
|
+
clientId: number;
|
16
|
+
[key: string]: any;
|
17
|
+
}[]) => null;
|
18
|
+
}
|
19
|
+
declare module '@tiptap/core' {
|
20
|
+
interface Commands<ReturnType> {
|
21
|
+
collaborationCursor: {
|
22
|
+
updateUser: (attributes: Record<string, any>) => ReturnType;
|
23
|
+
user: (attributes: Record<string, any>) => ReturnType;
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
27
|
+
export declare const SyncCursor: Extension<CollaborationCursorOptions, CollaborationCursorStorage>;
|
28
|
+
export {};
|
@@ -3,12 +3,14 @@ import { default as React, ReactNode } from 'react';
|
|
3
3
|
type EditingContextType = {
|
4
4
|
isPreviewMode: boolean;
|
5
5
|
isPresentationMode?: boolean;
|
6
|
+
isCollaboratorsDoc?: boolean;
|
6
7
|
};
|
7
8
|
export declare const useEditingContext: () => EditingContextType;
|
8
9
|
type EditingProviderProps = {
|
9
10
|
children: ReactNode;
|
10
11
|
isPreviewMode: boolean;
|
11
12
|
isPresentationMode?: boolean;
|
13
|
+
isCollaboratorsDoc?: boolean;
|
12
14
|
};
|
13
15
|
export declare const EditingProvider: React.FC<EditingProviderProps>;
|
14
16
|
export {};
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { SyncMachineContext, SyncMachinEvent } from '../types';
|
2
|
+
import { SocketClient } from '../socketClient';
|
3
|
+
|
4
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
5
|
+
export declare const awarenessUpdateHandler: (context: SyncMachineContext, event: SyncMachinEvent) => {};
|
6
|
+
export declare const initAwarenessHandler: (context: SyncMachineContext) => {
|
7
|
+
awareness: awarenessProtocol.Awareness;
|
8
|
+
_awarenessUpdateHandler: ({ added, updated, removed, }: {
|
9
|
+
added: number[];
|
10
|
+
updated: number[];
|
11
|
+
removed: number[];
|
12
|
+
}) => void;
|
13
|
+
};
|
14
|
+
export declare const updateConnectionStateHandler: (context: SyncMachineContext) => {
|
15
|
+
isConnected: boolean;
|
16
|
+
};
|
17
|
+
export declare const websocketInitializer: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
18
|
+
socketClient: SocketClient;
|
19
|
+
initialUpdate: any;
|
20
|
+
roomKey: any;
|
21
|
+
roomId: any;
|
22
|
+
isOwner: any;
|
23
|
+
isEns: any;
|
24
|
+
wsUrl: any;
|
25
|
+
onCollaborationCommit: (file: File) => Promise<string>;
|
26
|
+
onFetchCommitContent: (cid: string) => Promise<any>;
|
27
|
+
onSessionTerminated: () => void;
|
28
|
+
onUnMergedUpdates: (state: boolean) => void;
|
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 handleDisconnectionDueToError: (context: SyncMachineContext, event: SyncMachinEvent) => {
|
117
|
+
errorCount: number;
|
118
|
+
errorMessage: any;
|
119
|
+
} | {
|
120
|
+
errorCount?: undefined;
|
121
|
+
errorMessage?: undefined;
|
122
|
+
};
|
123
|
+
export declare const terminateSessionHandler: (context: SyncMachineContext) => {
|
124
|
+
socketClient: null;
|
125
|
+
roomId: string;
|
126
|
+
roomMembers: never[];
|
127
|
+
isConnected: boolean;
|
128
|
+
awareness: null;
|
129
|
+
_awarenessUpdateHandler: null;
|
130
|
+
roomKey: string;
|
131
|
+
wsUrl: string;
|
132
|
+
uncommittedUpdatesIdList: never[];
|
133
|
+
updateQueue: never[];
|
134
|
+
isOwner: boolean;
|
135
|
+
isReady: boolean;
|
136
|
+
isNewDoc: boolean;
|
137
|
+
contentTobeAppliedQueue: never[];
|
138
|
+
initialUpdate: null;
|
139
|
+
errorCount: number;
|
140
|
+
errorMessage: string;
|
141
|
+
};
|
142
|
+
export declare const setDocumentDecryptionStateHandler: (_: SyncMachineContext, event: SyncMachinEvent) => {
|
143
|
+
initalDocumentDecryptionState: any;
|
144
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const syncMachineActions: Record<any, any>;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare const crypto: {
|
2
|
+
generateKeyPair: () => import('@fileverse/crypto/ecies').EciesKeyPairBytes;
|
3
|
+
encryptData: (key: Uint8Array, message: Uint8Array) => string;
|
4
|
+
decryptData: (key: Uint8Array, message: string) => Uint8Array<ArrayBufferLike>;
|
5
|
+
generateRandomBytes: <E extends import('@fileverse/crypto/types').EncodingType = "bytes">(length?: number, encoding?: E) => import('@fileverse/crypto/types').EncodedReturnType<E>;
|
6
|
+
};
|
@@ -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
|
+
};
|
@@ -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
|
+
};
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { UrlProvider } from 'partysocket/ws';
|
2
|
+
import { ISocketInitConfig, RoomMember, SocketStatusEnum, SendUpdateResponse, CommitResponse } from './types';
|
3
|
+
import { Awareness } from 'y-protocols/awareness.js';
|
4
|
+
|
5
|
+
interface ISocketClientConfig {
|
6
|
+
wsUrl: UrlProvider;
|
7
|
+
roomKey: string;
|
8
|
+
ownerEdSecret?: string;
|
9
|
+
contractAddress?: string;
|
10
|
+
ownerAddress?: string;
|
11
|
+
onCollaborationConnectCallback: (response: any) => void;
|
12
|
+
roomInfo?: {
|
13
|
+
documentTitle: string;
|
14
|
+
portalAddress: string;
|
15
|
+
commentKey: string;
|
16
|
+
};
|
17
|
+
}
|
18
|
+
export declare class SocketClient {
|
19
|
+
private _websocketUrl;
|
20
|
+
private _machineEventHandler;
|
21
|
+
private _onConnect;
|
22
|
+
private _onDisconnection;
|
23
|
+
private _sequenceCallbackMap;
|
24
|
+
_webSocketStatus: SocketStatusEnum;
|
25
|
+
private _webSocket;
|
26
|
+
private _websocketServiceDid;
|
27
|
+
private roomId;
|
28
|
+
roomMembers: RoomMember[];
|
29
|
+
private collaborationKeyPair;
|
30
|
+
private ownerKeyPair?;
|
31
|
+
private contractAddress?;
|
32
|
+
private ownerUcan?;
|
33
|
+
private ownerAddress?;
|
34
|
+
private roomKey;
|
35
|
+
private roomInfo?;
|
36
|
+
private awareness;
|
37
|
+
_onError: ISocketInitConfig['onError'] | null;
|
38
|
+
_onCollaborationConnectCallback: ISocketClientConfig['onCollaborationConnectCallback'] | null;
|
39
|
+
constructor(config: ISocketClientConfig);
|
40
|
+
private _getSequenceIdCallback;
|
41
|
+
private _removeSequenceIdFromMap;
|
42
|
+
registerAwareness(awareness: Awareness): void;
|
43
|
+
private _registerSequenceCallback;
|
44
|
+
private _sendNetworkRequest;
|
45
|
+
private _fetchRoomMembers;
|
46
|
+
sendUpdate({ update }: {
|
47
|
+
update: string;
|
48
|
+
}): Promise<SendUpdateResponse>;
|
49
|
+
commitUpdates({ updates, cid }: {
|
50
|
+
updates: string[];
|
51
|
+
cid: string;
|
52
|
+
}): Promise<CommitResponse>;
|
53
|
+
fetchLatestCommit(): Promise<any>;
|
54
|
+
getUncommittedChanges(): Promise<any>;
|
55
|
+
broadcastAwareness(awarenessUpdate: string): Promise<any>;
|
56
|
+
disconnect: () => void;
|
57
|
+
terminateSession: () => Promise<void>;
|
58
|
+
private _buildRequest;
|
59
|
+
private getCollaborationKeyPair;
|
60
|
+
private getOwnerToken;
|
61
|
+
private buildToken;
|
62
|
+
private _handleHandShake;
|
63
|
+
private _executeRequestCallback;
|
64
|
+
private _dispatchEventHandler;
|
65
|
+
private _onSessionTerminated;
|
66
|
+
private _processMessage;
|
67
|
+
private _clearSequenceCallbackMap;
|
68
|
+
connectSocket(): Promise<void> | undefined;
|
69
|
+
init(config: ISocketInitConfig): Promise<void>;
|
70
|
+
private resetSocketClient;
|
71
|
+
}
|
72
|
+
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;
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import { SocketClient } from '../socketClient';
|
2
|
+
|
3
|
+
import * as Y from 'yjs';
|
4
|
+
export interface IRoomMember {
|
5
|
+
userId: string;
|
6
|
+
username: string;
|
7
|
+
role: 'owner' | 'editor';
|
8
|
+
}
|
9
|
+
export interface SendUpdateResponse {
|
10
|
+
data: {
|
11
|
+
agent_id: string;
|
12
|
+
commitCid: string | null;
|
13
|
+
created_at: number;
|
14
|
+
data: string;
|
15
|
+
documentId: string;
|
16
|
+
id: string;
|
17
|
+
update_snapshot_ref: string | null;
|
18
|
+
updateType: string;
|
19
|
+
};
|
20
|
+
is_handshake_response: boolean;
|
21
|
+
status: boolean;
|
22
|
+
statusCode: number;
|
23
|
+
}
|
24
|
+
export interface CommitResponse {
|
25
|
+
data: {
|
26
|
+
agent_id: string;
|
27
|
+
cid: string;
|
28
|
+
created_at: number;
|
29
|
+
data: any | null;
|
30
|
+
documentId: string;
|
31
|
+
updates: string[];
|
32
|
+
};
|
33
|
+
is_handshake_response: boolean;
|
34
|
+
status: boolean;
|
35
|
+
statusCode: number;
|
36
|
+
}
|
37
|
+
export interface SyncMachineContext {
|
38
|
+
ydoc: Y.Doc;
|
39
|
+
socketClient: SocketClient | null;
|
40
|
+
roomId: string;
|
41
|
+
username: string;
|
42
|
+
roomMembers: IRoomMember[];
|
43
|
+
isConnected: boolean;
|
44
|
+
awareness: any;
|
45
|
+
_awarenessUpdateHandler: (({ added, updated, removed, }: {
|
46
|
+
added: number[];
|
47
|
+
updated: number[];
|
48
|
+
removed: number[];
|
49
|
+
}) => void) | null;
|
50
|
+
onError: ((e: string) => void) | null;
|
51
|
+
roomKey: string;
|
52
|
+
wsUrl: string;
|
53
|
+
uncommittedUpdatesIdList: string[];
|
54
|
+
isOwner: boolean;
|
55
|
+
updateQueue: Uint8Array[];
|
56
|
+
isReady: boolean;
|
57
|
+
isNewDoc: boolean;
|
58
|
+
contentTobeAppliedQueue: string[];
|
59
|
+
initialUpdate: string | null;
|
60
|
+
errorCount: number;
|
61
|
+
errorMaxRetryCount: number;
|
62
|
+
errorMessage: string;
|
63
|
+
initalDocumentDecryptionState: 'done' | 'pending';
|
64
|
+
onCollaborationConnectCallback: (response: any) => void;
|
65
|
+
onCollaborationCommit: (file: File) => Promise<string>;
|
66
|
+
onFetchCommitContent: (cid: string) => Promise<any>;
|
67
|
+
onSessionTerminated: () => void;
|
68
|
+
onUnMergedUpdates: (state: boolean) => void;
|
69
|
+
}
|
70
|
+
export interface ErrorResponseMessage {
|
71
|
+
status: boolean;
|
72
|
+
statusCode: number;
|
73
|
+
seqId: string | null;
|
74
|
+
is_handshake_response: boolean;
|
75
|
+
err: string;
|
76
|
+
err_detail: {
|
77
|
+
[key: string]: any;
|
78
|
+
} | null;
|
79
|
+
}
|
80
|
+
export interface SuccessResponseMessage {
|
81
|
+
status: boolean;
|
82
|
+
statusCode: number;
|
83
|
+
seqId: string | null;
|
84
|
+
is_handshake_response: boolean;
|
85
|
+
data: {
|
86
|
+
[key: string]: any;
|
87
|
+
};
|
88
|
+
}
|
89
|
+
export interface EventMessage {
|
90
|
+
type: string;
|
91
|
+
event_type: string;
|
92
|
+
event: {
|
93
|
+
data: any;
|
94
|
+
roomId: string;
|
95
|
+
};
|
96
|
+
}
|
97
|
+
export type RequestResponse = ErrorResponseMessage | SuccessResponseMessage;
|
98
|
+
export type OnMessagePayloadType = RequestResponse | EventMessage;
|
99
|
+
export type EventHandler = (message: EventMessage) => void;
|
100
|
+
export type DisconnectHandler = (e: CloseEvent | ErrorEvent) => void;
|
101
|
+
export type ConnectHandler = () => void;
|
102
|
+
export interface PartialRequest {
|
103
|
+
cmd: string;
|
104
|
+
args: {
|
105
|
+
[key: string]: any;
|
106
|
+
};
|
107
|
+
}
|
108
|
+
export interface RequestPayload extends PartialRequest {
|
109
|
+
seqId: string;
|
110
|
+
}
|
111
|
+
export type SequenceResponseCB = (data: RequestResponse) => void;
|
112
|
+
export interface SequenceToRequestMapValue {
|
113
|
+
callback: SequenceResponseCB;
|
114
|
+
}
|
115
|
+
export type SequenceToRequestMap = {
|
116
|
+
[key: string]: SequenceToRequestMapValue;
|
117
|
+
};
|
118
|
+
export type Update = Uint8Array;
|
119
|
+
export interface ISocketInitConfig {
|
120
|
+
onConnect: ConnectHandler;
|
121
|
+
onDisconnect: DisconnectHandler;
|
122
|
+
onError: (err: string) => void;
|
123
|
+
onWsEvent: EventHandler;
|
124
|
+
roomId: string;
|
125
|
+
}
|
126
|
+
export declare enum SocketStatusEnum {
|
127
|
+
CLOSED = "CLOSED",
|
128
|
+
CONNECTED = "CONNECTED",
|
129
|
+
CONNECTING = "CONNECTING",
|
130
|
+
DISCONNECTING = "DISCONNECTING",
|
131
|
+
DISCONNECTED = "DISCONNECTED"
|
132
|
+
}
|
133
|
+
export interface RoomMember {
|
134
|
+
username: string;
|
135
|
+
userId: string;
|
136
|
+
role: 'owner' | 'editor';
|
137
|
+
}
|
138
|
+
export type IAesKey = string;
|
139
|
+
export type SyncMachinEvent = {
|
140
|
+
type: string;
|
141
|
+
data: any;
|
142
|
+
};
|
143
|
+
export interface IpfsUploadResponse {
|
144
|
+
ipfsUrl: string;
|
145
|
+
ipfsHash: string;
|
146
|
+
ipfsStorage: string;
|
147
|
+
cachedUrl: string;
|
148
|
+
fileSize: number;
|
149
|
+
mimetype: string;
|
150
|
+
}
|
151
|
+
export interface IAuthArgs {
|
152
|
+
collaborationToken: string;
|
153
|
+
documentId: string;
|
154
|
+
ownerToken?: string;
|
155
|
+
ownerAddress?: string;
|
156
|
+
contractAddress?: string;
|
157
|
+
sessionDid?: string;
|
158
|
+
roomInfo?: string;
|
159
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { SyncMachineContext } from '.';
|
2
|
+
|
3
|
+
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: any;
|
24
|
+
getYjsEncodedState: () => string;
|
25
|
+
applyYjsEncodedState: (update: string) => void;
|
26
|
+
error: any;
|
27
|
+
terminateSession: () => void;
|
28
|
+
awareness: any;
|
29
|
+
hasCollabContentInitialised: boolean;
|
30
|
+
};
|
31
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
2
|
+
import { SyncMachineContext } from '../types';
|
3
|
+
|
4
|
+
export declare const createAwarenessUpdateHandler: (awareness: Awareness, context: SyncMachineContext) => ({ added, updated, removed, }: {
|
5
|
+
added: number[];
|
6
|
+
updated: number[];
|
7
|
+
removed: number[];
|
8
|
+
}) => void;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const objectToFile: (data: Record<string, unknown>, fileName: string) => File;
|
package/dist/package/types.d.ts
CHANGED
@@ -7,6 +7,7 @@ import { IComment } from './extensions/comment';
|
|
7
7
|
|
8
8
|
export declare const DdocEditorProps: EditorProps;
|
9
9
|
export interface IDocCollabUsers {
|
10
|
+
clientId: number;
|
10
11
|
name: string;
|
11
12
|
isEns: string;
|
12
13
|
color: string;
|
@@ -142,11 +143,24 @@ export interface DdocProps extends CommentAccountProps {
|
|
142
143
|
activeModel?: CustomModel;
|
143
144
|
maxTokens?: number;
|
144
145
|
isAIAgentEnabled?: boolean;
|
146
|
+
collaborationKey?: CryptoKey | null;
|
147
|
+
collaborationKeyPair?: {
|
148
|
+
publicKey: string;
|
149
|
+
privateKey: string;
|
150
|
+
};
|
151
|
+
collabConfig?: ICollaborationConfig;
|
145
152
|
/**
|
146
153
|
* Document styling configuration
|
147
154
|
* @description Customize the appearance of the document editor
|
148
155
|
*/
|
149
156
|
documentStyling?: DocumentStyling;
|
157
|
+
onCollaborationConnectCallback?: (response: any) => void;
|
158
|
+
onCollaborationCommit?: (file: File) => Promise<string>;
|
159
|
+
onFetchCommitContent?: (cid: string) => Promise<any>;
|
160
|
+
onCollabSessionTermination?: () => void;
|
161
|
+
onUnMergedUpdates?: (state: boolean) => void;
|
162
|
+
onCollabError?: (error: any) => void;
|
163
|
+
isExistingCollabSession?: boolean;
|
150
164
|
}
|
151
165
|
export interface IEditorSelectionData {
|
152
166
|
from: number;
|
@@ -178,3 +192,19 @@ export interface IpfsImageFetchPayload {
|
|
178
192
|
mimeType: string;
|
179
193
|
authTag: string;
|
180
194
|
}
|
195
|
+
export interface ICollaborationConfig {
|
196
|
+
roomKey: string;
|
197
|
+
collaborationId: string;
|
198
|
+
username: string;
|
199
|
+
isOwner: boolean;
|
200
|
+
ownerEdSecret?: string;
|
201
|
+
contractAddress?: string;
|
202
|
+
ownerAddress?: string;
|
203
|
+
wsUrl: string;
|
204
|
+
isEns?: boolean;
|
205
|
+
roomInfo?: {
|
206
|
+
documentTitle: string;
|
207
|
+
portalAddress: string;
|
208
|
+
commentKey: string;
|
209
|
+
};
|
210
|
+
}
|