@docx-editor.dev/pro 2.10.0 → 2.12.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/README.md +1 -7
- package/dist/chunk-6DEUT2RQ.js +1 -0
- package/dist/chunk-C4RVARMI.cjs +3 -0
- package/dist/chunk-DHIPX767.js +3 -0
- package/dist/chunk-EMO6YTKO.cjs +1 -0
- package/dist/chunk-GDTCNTK7.cjs +1 -0
- package/dist/chunk-HJB77VBO.js +1 -0
- package/dist/chunk-KOGVHJ7U.js +3 -0
- package/dist/chunk-LUUFBXJ5.cjs +1 -0
- package/dist/chunk-NQW54J56.js +1 -0
- package/dist/chunk-Q2VBO66F.js +1 -0
- package/dist/chunk-Q4YPX2DT.cjs +1 -0
- package/dist/chunk-QA3F5EUJ.cjs +3 -0
- package/dist/chunk-QLZH2Q2C.cjs +1 -0
- package/dist/chunk-W3V54DWZ.js +1 -0
- package/dist/collaboration/hocuspocus.cjs +1 -0
- package/dist/collaboration/hocuspocus.d.cts +58 -0
- package/dist/collaboration/hocuspocus.d.ts +58 -0
- package/dist/collaboration/hocuspocus.js +1 -0
- package/dist/collaboration/index.cjs +2 -0
- package/dist/collaboration/index.d.cts +54 -0
- package/dist/collaboration/index.d.ts +54 -0
- package/dist/collaboration/index.js +2 -0
- package/dist/collaboration/webrtc.cjs +2 -0
- package/dist/collaboration/webrtc.d.cts +86 -0
- package/dist/collaboration/webrtc.d.ts +86 -0
- package/dist/collaboration/webrtc.js +2 -0
- package/dist/collaboration-module-BgRxhW5b.d.cts +45 -0
- package/dist/collaboration-module-BgRxhW5b.d.ts +45 -0
- package/dist/{define-custom-node-Bk8kFO27.d.cts → define-custom-node-B_p2nr9T.d.cts} +2 -20
- package/dist/{define-custom-node-Bk8kFO27.d.ts → define-custom-node-BehI3jWX.d.ts} +2 -20
- package/dist/document-session-1VSzWYaC.d.ts +123 -0
- package/dist/document-session-I77CU7RQ.cjs +1 -0
- package/dist/document-session-KYavjw8A.d.cts +123 -0
- package/dist/document-session-MTK2LEYT.cjs +1 -0
- package/dist/document-session-NFUE7UBO.js +1 -0
- package/dist/document-session-WEZH77T3.js +1 -0
- package/dist/hocuspocus-3FLNEX7M.cjs +1 -0
- package/dist/hocuspocus-FC5NXRLW.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/react/hocuspocus.cjs +1 -0
- package/dist/react/hocuspocus.d.cts +104 -0
- package/dist/react/hocuspocus.d.ts +104 -0
- package/dist/react/hocuspocus.js +1 -0
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +320 -5
- package/dist/react/index.d.ts +320 -5
- package/dist/react/index.js +2 -2
- package/dist/react/webrtc.cjs +1 -0
- package/dist/react/webrtc.d.cts +98 -0
- package/dist/react/webrtc.d.ts +98 -0
- package/dist/react/webrtc.js +1 -0
- package/dist/room-id-BfudXOZz.d.cts +13 -0
- package/dist/room-id-BfudXOZz.d.ts +13 -0
- package/dist/session-BH7Qgyp6.d.cts +140 -0
- package/dist/session-BH7Qgyp6.d.ts +140 -0
- package/dist/session-okdqygLg.d.cts +82 -0
- package/dist/session-okdqygLg.d.ts +82 -0
- package/dist/vue/hocuspocus.cjs +1 -0
- package/dist/vue/hocuspocus.d.cts +105 -0
- package/dist/vue/hocuspocus.d.ts +105 -0
- package/dist/vue/hocuspocus.js +1 -0
- package/dist/vue/index.cjs +2 -2
- package/dist/vue/index.d.cts +439 -3
- package/dist/vue/index.d.ts +439 -3
- package/dist/vue/index.js +2 -2
- package/dist/vue/webrtc.cjs +1 -0
- package/dist/vue/webrtc.d.cts +99 -0
- package/dist/vue/webrtc.d.ts +99 -0
- package/dist/vue/webrtc.js +1 -0
- package/dist/webrtc-UAS5I63G.cjs +2 -0
- package/dist/webrtc-V2JQ2NO7.js +2 -0
- package/package.json +62 -7
- package/dist/chunk-4LFF2FXG.cjs +0 -1
- package/dist/chunk-TH5PXU6L.js +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { WebrtcProvider } from 'y-webrtc';
|
|
3
|
+
import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
|
|
4
|
+
import { EditorModule } from '@docx-editor.dev/core/editor';
|
|
5
|
+
import { a as CollaborationBootstrap, C as CollaborationSession } from '../session-BH7Qgyp6.cjs';
|
|
6
|
+
export { b as CollaborationIdentityUpdate } from '../session-BH7Qgyp6.cjs';
|
|
7
|
+
import 'y-protocols/awareness';
|
|
8
|
+
|
|
9
|
+
/** Bootstrap for one WebRTC room. @public */
|
|
10
|
+
type UseWebrtcCollaborationBootstrap = CollaborationBootstrap;
|
|
11
|
+
/** Arguments for {@link UseWebrtcCollaborationReturn.connect}. @public */
|
|
12
|
+
interface UseWebrtcCollaborationConnectOptions {
|
|
13
|
+
readonly roomId: string;
|
|
14
|
+
readonly identity: CollaborationIdentity;
|
|
15
|
+
readonly bootstrap: UseWebrtcCollaborationBootstrap;
|
|
16
|
+
/**
|
|
17
|
+
* Admit local edits while the transport is `disconnected`. Buffered updates merge on
|
|
18
|
+
* reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
|
|
19
|
+
*/
|
|
20
|
+
readonly offlineEditing?: boolean;
|
|
21
|
+
readonly signaling?: readonly string[];
|
|
22
|
+
readonly iceServers?: readonly RTCIceServer[];
|
|
23
|
+
readonly password?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Input for {@link useWebrtcCollaboration}. @public */
|
|
26
|
+
interface UseWebrtcCollaborationOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Host modules. The hook adds `collaborationModule` when a room is ready.
|
|
29
|
+
* A host collaboration contribution is a configuration error and throws.
|
|
30
|
+
*/
|
|
31
|
+
readonly modules?: readonly EditorModule[];
|
|
32
|
+
/**
|
|
33
|
+
* Connect this room on mount. Omit it and call
|
|
34
|
+
* {@link UseWebrtcCollaborationReturn.connect} after the user chooses a room.
|
|
35
|
+
*/
|
|
36
|
+
readonly room?: UseWebrtcCollaborationConnectOptions | null;
|
|
37
|
+
}
|
|
38
|
+
/** Values {@link useWebrtcCollaboration} returns. @public */
|
|
39
|
+
interface UseWebrtcCollaborationReturn {
|
|
40
|
+
readonly document: Uint8Array | null;
|
|
41
|
+
readonly modules: readonly EditorModule[];
|
|
42
|
+
readonly session: CollaborationSession | null;
|
|
43
|
+
/**
|
|
44
|
+
* The room's shared Yjs document, owned by the hook. Null while no room is connected.
|
|
45
|
+
*
|
|
46
|
+
* Read-only escape hatch: observe it or wire additional providers, but leave teardown to
|
|
47
|
+
* the hook.
|
|
48
|
+
*/
|
|
49
|
+
readonly ydoc: Y.Doc | null;
|
|
50
|
+
/**
|
|
51
|
+
* The owned `y-webrtc` provider. Null while no room is connected.
|
|
52
|
+
*
|
|
53
|
+
* Read-only escape hatch for transport-level access (`disconnect()`/`connect()`, peer
|
|
54
|
+
* introspection). The hook destroys it on leave and unmount.
|
|
55
|
+
*/
|
|
56
|
+
readonly provider: WebrtcProvider | null;
|
|
57
|
+
readonly pending: boolean;
|
|
58
|
+
readonly error: CollaborationFailure | null;
|
|
59
|
+
/**
|
|
60
|
+
* Connect a room. RESOLVES with the failure, or null on success — it does not reject.
|
|
61
|
+
*
|
|
62
|
+
* A rejection carried nothing the resolved value does not, and it made the ordinary call
|
|
63
|
+
* site wrong by default: `onClick={() => connect(options)}` produced an unhandled rejection
|
|
64
|
+
* on every failed connect. `error` reports the same failure for renderers.
|
|
65
|
+
*/
|
|
66
|
+
readonly connect: (options: UseWebrtcCollaborationConnectOptions) => Promise<CollaborationFailure | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Destroy the room and carry on editing locally.
|
|
69
|
+
*
|
|
70
|
+
* The current bytes live in the editor, not in this hook, so the argument is required:
|
|
71
|
+
* pass `await editor.save()` to keep what the room typed. The hook remounts the editor
|
|
72
|
+
* from exactly these bytes.
|
|
73
|
+
*/
|
|
74
|
+
readonly leave: (nextDocument: Uint8Array) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Recover a session that reached status `error`: leave with `nextDocument`, then connect
|
|
77
|
+
* again to the same room with the same identity, signaling, and password.
|
|
78
|
+
*
|
|
79
|
+
* The reconnect always uses bootstrap `{ kind: 'join' }`, because an active room still
|
|
80
|
+
* exists on the other peers. When no peer holds the room any more, the join rejects with
|
|
81
|
+
* `initialization-timeout` — nothing is lost, because `nextDocument` (your saved bytes)
|
|
82
|
+
* stays mounted locally. A connect that failed also counts as the prior attempt, so
|
|
83
|
+
* rejoin retries it as a joiner.
|
|
84
|
+
*/
|
|
85
|
+
readonly rejoin: (nextDocument: Uint8Array) => Promise<CollaborationFailure | null>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Own a WebRTC collaboration room for a React host.
|
|
89
|
+
*
|
|
90
|
+
* The default Pro React entry does not import this hook. Import it from
|
|
91
|
+
* `@docx-editor.dev/pro/react/webrtc` so a review-only bundle does not load
|
|
92
|
+
* a network provider.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
declare function useWebrtcCollaboration(options?: UseWebrtcCollaborationOptions): UseWebrtcCollaborationReturn;
|
|
97
|
+
|
|
98
|
+
export { CollaborationSession, type UseWebrtcCollaborationBootstrap, type UseWebrtcCollaborationConnectOptions, type UseWebrtcCollaborationOptions, type UseWebrtcCollaborationReturn, useWebrtcCollaboration };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { WebrtcProvider } from 'y-webrtc';
|
|
3
|
+
import { CollaborationIdentity, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
|
|
4
|
+
import { EditorModule } from '@docx-editor.dev/core/editor';
|
|
5
|
+
import { a as CollaborationBootstrap, C as CollaborationSession } from '../session-BH7Qgyp6.js';
|
|
6
|
+
export { b as CollaborationIdentityUpdate } from '../session-BH7Qgyp6.js';
|
|
7
|
+
import 'y-protocols/awareness';
|
|
8
|
+
|
|
9
|
+
/** Bootstrap for one WebRTC room. @public */
|
|
10
|
+
type UseWebrtcCollaborationBootstrap = CollaborationBootstrap;
|
|
11
|
+
/** Arguments for {@link UseWebrtcCollaborationReturn.connect}. @public */
|
|
12
|
+
interface UseWebrtcCollaborationConnectOptions {
|
|
13
|
+
readonly roomId: string;
|
|
14
|
+
readonly identity: CollaborationIdentity;
|
|
15
|
+
readonly bootstrap: UseWebrtcCollaborationBootstrap;
|
|
16
|
+
/**
|
|
17
|
+
* Admit local edits while the transport is `disconnected`. Buffered updates merge on
|
|
18
|
+
* reconnect. See {@link CreateDocumentCollaborationOptions.offlineEditing}.
|
|
19
|
+
*/
|
|
20
|
+
readonly offlineEditing?: boolean;
|
|
21
|
+
readonly signaling?: readonly string[];
|
|
22
|
+
readonly iceServers?: readonly RTCIceServer[];
|
|
23
|
+
readonly password?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Input for {@link useWebrtcCollaboration}. @public */
|
|
26
|
+
interface UseWebrtcCollaborationOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Host modules. The hook adds `collaborationModule` when a room is ready.
|
|
29
|
+
* A host collaboration contribution is a configuration error and throws.
|
|
30
|
+
*/
|
|
31
|
+
readonly modules?: readonly EditorModule[];
|
|
32
|
+
/**
|
|
33
|
+
* Connect this room on mount. Omit it and call
|
|
34
|
+
* {@link UseWebrtcCollaborationReturn.connect} after the user chooses a room.
|
|
35
|
+
*/
|
|
36
|
+
readonly room?: UseWebrtcCollaborationConnectOptions | null;
|
|
37
|
+
}
|
|
38
|
+
/** Values {@link useWebrtcCollaboration} returns. @public */
|
|
39
|
+
interface UseWebrtcCollaborationReturn {
|
|
40
|
+
readonly document: Uint8Array | null;
|
|
41
|
+
readonly modules: readonly EditorModule[];
|
|
42
|
+
readonly session: CollaborationSession | null;
|
|
43
|
+
/**
|
|
44
|
+
* The room's shared Yjs document, owned by the hook. Null while no room is connected.
|
|
45
|
+
*
|
|
46
|
+
* Read-only escape hatch: observe it or wire additional providers, but leave teardown to
|
|
47
|
+
* the hook.
|
|
48
|
+
*/
|
|
49
|
+
readonly ydoc: Y.Doc | null;
|
|
50
|
+
/**
|
|
51
|
+
* The owned `y-webrtc` provider. Null while no room is connected.
|
|
52
|
+
*
|
|
53
|
+
* Read-only escape hatch for transport-level access (`disconnect()`/`connect()`, peer
|
|
54
|
+
* introspection). The hook destroys it on leave and unmount.
|
|
55
|
+
*/
|
|
56
|
+
readonly provider: WebrtcProvider | null;
|
|
57
|
+
readonly pending: boolean;
|
|
58
|
+
readonly error: CollaborationFailure | null;
|
|
59
|
+
/**
|
|
60
|
+
* Connect a room. RESOLVES with the failure, or null on success — it does not reject.
|
|
61
|
+
*
|
|
62
|
+
* A rejection carried nothing the resolved value does not, and it made the ordinary call
|
|
63
|
+
* site wrong by default: `onClick={() => connect(options)}` produced an unhandled rejection
|
|
64
|
+
* on every failed connect. `error` reports the same failure for renderers.
|
|
65
|
+
*/
|
|
66
|
+
readonly connect: (options: UseWebrtcCollaborationConnectOptions) => Promise<CollaborationFailure | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Destroy the room and carry on editing locally.
|
|
69
|
+
*
|
|
70
|
+
* The current bytes live in the editor, not in this hook, so the argument is required:
|
|
71
|
+
* pass `await editor.save()` to keep what the room typed. The hook remounts the editor
|
|
72
|
+
* from exactly these bytes.
|
|
73
|
+
*/
|
|
74
|
+
readonly leave: (nextDocument: Uint8Array) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Recover a session that reached status `error`: leave with `nextDocument`, then connect
|
|
77
|
+
* again to the same room with the same identity, signaling, and password.
|
|
78
|
+
*
|
|
79
|
+
* The reconnect always uses bootstrap `{ kind: 'join' }`, because an active room still
|
|
80
|
+
* exists on the other peers. When no peer holds the room any more, the join rejects with
|
|
81
|
+
* `initialization-timeout` — nothing is lost, because `nextDocument` (your saved bytes)
|
|
82
|
+
* stays mounted locally. A connect that failed also counts as the prior attempt, so
|
|
83
|
+
* rejoin retries it as a joiner.
|
|
84
|
+
*/
|
|
85
|
+
readonly rejoin: (nextDocument: Uint8Array) => Promise<CollaborationFailure | null>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Own a WebRTC collaboration room for a React host.
|
|
89
|
+
*
|
|
90
|
+
* The default Pro React entry does not import this hook. Import it from
|
|
91
|
+
* `@docx-editor.dev/pro/react/webrtc` so a review-only bundle does not load
|
|
92
|
+
* a network provider.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
declare function useWebrtcCollaboration(options?: UseWebrtcCollaborationOptions): UseWebrtcCollaborationReturn;
|
|
97
|
+
|
|
98
|
+
export { CollaborationSession, type UseWebrtcCollaborationBootstrap, type UseWebrtcCollaborationConnectOptions, type UseWebrtcCollaborationOptions, type UseWebrtcCollaborationReturn, useWebrtcCollaboration };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b as b$1,a}from'../chunk-HJB77VBO.js';import'../chunk-Q2VBO66F.js';import {useId,useMemo}from'react';var s=Symbol("useWebrtcCollaboration.createRoom");function c(o){return o?`${o.signaling?o.signaling.join(","):""}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function d(o){let{createWebrtcCollaboration:t}=await import('../collaboration/webrtc.js');return t(o)}function b(o){return o[s]??d}function p(o={}){let t=useId(),e=b$1({ownerKey:`react-webrtc:${t}`,hookName:"useWebrtcCollaboration",createRoom:b(o),hostModules:o.modules??a,autoRoom:o.room??null,autoKey:c(o.room??null),rejoinOptionsOf:r=>({...r,bootstrap:{kind:"join"}}),identityOf:r=>r.identity});return useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e])}export{p as useWebrtcCollaboration};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room identifier helpers shared by the provider convenience wrappers.
|
|
3
|
+
*
|
|
4
|
+
* The WebRTC and Hocuspocus factories validate the same room-id shape. This module holds
|
|
5
|
+
* the rule once, with no provider import, so each provider subpath re-exports it without
|
|
6
|
+
* dragging in the other provider's package.
|
|
7
|
+
*/
|
|
8
|
+
/** Create a cryptographically strong room identifier. It is not an authorization token. @public */
|
|
9
|
+
declare function createCollaborationRoomId(): string;
|
|
10
|
+
/** Validate and normalize a room identifier from a host interface. @public */
|
|
11
|
+
declare function validateRoomId(value: string): string;
|
|
12
|
+
|
|
13
|
+
export { createCollaborationRoomId as c, validateRoomId as v };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room identifier helpers shared by the provider convenience wrappers.
|
|
3
|
+
*
|
|
4
|
+
* The WebRTC and Hocuspocus factories validate the same room-id shape. This module holds
|
|
5
|
+
* the rule once, with no provider import, so each provider subpath re-exports it without
|
|
6
|
+
* dragging in the other provider's package.
|
|
7
|
+
*/
|
|
8
|
+
/** Create a cryptographically strong room identifier. It is not an authorization token. @public */
|
|
9
|
+
declare function createCollaborationRoomId(): string;
|
|
10
|
+
/** Validate and normalize a room identifier from a host interface. @public */
|
|
11
|
+
declare function validateRoomId(value: string): string;
|
|
12
|
+
|
|
13
|
+
export { createCollaborationRoomId as c, validateRoomId as v };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import { CollaborationIdentity, CollaborationStatus, CollaborationStatusSnapshot, CollaborationFailureCode, CollaborationParticipant, CollaborationRemoteSelection, EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create or join bootstrap for one collaboration replica.
|
|
7
|
+
*
|
|
8
|
+
* Text, document, and WebRTC factories share this union.
|
|
9
|
+
*
|
|
10
|
+
* `create-or-join` removes the out-of-band decision about which peer creates a room.
|
|
11
|
+
* The replica probes for an initialized room and joins it when one appears. Otherwise it
|
|
12
|
+
* runs a short awareness election and only the winning candidate seeds from `document`.
|
|
13
|
+
* A room that two peers seeded concurrently reports the terminal failure code
|
|
14
|
+
* `concurrent-seed` on every replica. The document and WebRTC factories accept this kind;
|
|
15
|
+
* the experimental text factory refuses it.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
type CollaborationBootstrap = {
|
|
19
|
+
readonly kind: 'create';
|
|
20
|
+
readonly document: Uint8Array;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'join';
|
|
23
|
+
readonly timeoutMs?: number;
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'create-or-join';
|
|
27
|
+
readonly document: Uint8Array;
|
|
28
|
+
/** Wait for an existing initialized room before the seed election. Default 4000 ms. */
|
|
29
|
+
readonly probeTimeoutMs?: number;
|
|
30
|
+
/** Seed election window after an empty probe. Default 1500 ms. */
|
|
31
|
+
readonly electionWindowMs?: number;
|
|
32
|
+
/** Join wait after this replica loses the seed election. Default 30000 ms. */
|
|
33
|
+
readonly timeoutMs?: number;
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Display-identity fields a live session can update.
|
|
38
|
+
*
|
|
39
|
+
* `actorId` and `role` are attribution and stay immutable for the session lifetime, so this
|
|
40
|
+
* type cannot name them.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
interface CollaborationIdentityUpdate {
|
|
44
|
+
readonly name?: string;
|
|
45
|
+
readonly color?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Host-facing collaboration session.
|
|
49
|
+
*
|
|
50
|
+
* A host reads identity, status, presence, and undo. The editor attaches
|
|
51
|
+
* {@link EditorCollaborationSession} internally and never through this type.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface CollaborationSession {
|
|
55
|
+
readonly documentId: string;
|
|
56
|
+
/** Unique identity for this attachment lifetime. */
|
|
57
|
+
readonly sessionId: string;
|
|
58
|
+
readonly identity: CollaborationIdentity;
|
|
59
|
+
/**
|
|
60
|
+
* Update the display name and color mid-session, when the replica supports it.
|
|
61
|
+
*
|
|
62
|
+
* Full-document sessions implement this and republish presence at once. A replica that
|
|
63
|
+
* freezes identity for its lifetime omits it.
|
|
64
|
+
*/
|
|
65
|
+
setIdentity?(update: CollaborationIdentityUpdate): void;
|
|
66
|
+
status(): CollaborationStatus;
|
|
67
|
+
/**
|
|
68
|
+
* Cached status, current reason, and last failure.
|
|
69
|
+
*
|
|
70
|
+
* Same reference until any of those values change.
|
|
71
|
+
*/
|
|
72
|
+
statusSnapshot(): CollaborationStatusSnapshot;
|
|
73
|
+
subscribeStatus(listener: (status: CollaborationStatus, reason?: CollaborationFailureCode, detail?: string) => void): () => void;
|
|
74
|
+
canUndo(): boolean;
|
|
75
|
+
canRedo(): boolean;
|
|
76
|
+
undo(): boolean;
|
|
77
|
+
redo(): boolean;
|
|
78
|
+
participants(): readonly CollaborationParticipant[];
|
|
79
|
+
subscribeParticipants(listener: (participants: readonly CollaborationParticipant[]) => void): () => void;
|
|
80
|
+
remoteSelections(): readonly CollaborationRemoteSelection[];
|
|
81
|
+
subscribeRemoteSelections(listener: (selections: readonly CollaborationRemoteSelection[]) => void): () => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for the experimental paragraph-text replica of {@link createTextCollaboration}.
|
|
85
|
+
*
|
|
86
|
+
* The caller owns `ydoc`.
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
interface CreateTextCollaborationOptions {
|
|
90
|
+
readonly ydoc: Y.Doc;
|
|
91
|
+
readonly awareness: Awareness;
|
|
92
|
+
readonly documentId: string;
|
|
93
|
+
/** Unique attachment identity. Omit it to generate a new identity for this session. */
|
|
94
|
+
readonly sessionId?: string;
|
|
95
|
+
readonly identity: CollaborationIdentity;
|
|
96
|
+
readonly bootstrap: CollaborationBootstrap;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Engine-facing paragraph-text session, including attach and operation gating.
|
|
100
|
+
*
|
|
101
|
+
* Hosts consume {@link CollaborationSession}. Providers call `setTransportStatus`.
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
interface TextCollaborationSession extends EditorCollaborationSession {
|
|
105
|
+
/**
|
|
106
|
+
* Provider convenience seam. Low-level consumers normally leave the session ready.
|
|
107
|
+
*
|
|
108
|
+
* `reason` is a typed code so a host can branch on it: pass `'transport-disconnected'` for
|
|
109
|
+
* a socket that will retry itself and `'authentication-failed'` for a credential the server
|
|
110
|
+
* rejected, because those need opposite responses. The provider's own phrasing goes in
|
|
111
|
+
* `detail`.
|
|
112
|
+
*/
|
|
113
|
+
setTransportStatus(status: 'ready' | 'disconnected' | 'error', reason?: CollaborationFailureCode, detail?: string): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Owned collaboration replica: document bytes, session, and teardown.
|
|
117
|
+
*
|
|
118
|
+
* Text and document factories share this shape. A host reads
|
|
119
|
+
* {@link CollaborationSession}; the engine session remains assignable.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
interface CollaborationHandle<TSession extends CollaborationSession> {
|
|
123
|
+
readonly document: Uint8Array;
|
|
124
|
+
readonly session: TSession;
|
|
125
|
+
destroy(): void;
|
|
126
|
+
}
|
|
127
|
+
/** Owned replica of the experimental {@link createTextCollaboration} factory. @beta */
|
|
128
|
+
type TextCollaborationHandle = CollaborationHandle<TextCollaborationSession>;
|
|
129
|
+
/**
|
|
130
|
+
* Create or join one experimental paragraph-text collaboration replica.
|
|
131
|
+
*
|
|
132
|
+
* This replica shares only the body paragraph text of an unchanging paragraph set: no
|
|
133
|
+
* formatting, no structure, no images. Use {@link createDocumentCollaboration} for
|
|
134
|
+
* full-document collaboration; this factory remains for hosts that want to replicate plain
|
|
135
|
+
* paragraph text and nothing else. The caller owns `ydoc`.
|
|
136
|
+
* @beta
|
|
137
|
+
*/
|
|
138
|
+
declare function createTextCollaboration(options: CreateTextCollaborationOptions): Promise<TextCollaborationHandle>;
|
|
139
|
+
|
|
140
|
+
export { type CollaborationSession as C, type TextCollaborationHandle as T, type CollaborationBootstrap as a, type CollaborationIdentityUpdate as b, type CollaborationHandle as c, type CreateTextCollaborationOptions as d, type TextCollaborationSession as e, createTextCollaboration as f };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import { CollaborationIdentity, CollaborationStatus, CollaborationStatusSnapshot, CollaborationFailureCode, CollaborationParticipant, CollaborationRemoteSelection, EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create or join bootstrap for one collaboration replica.
|
|
7
|
+
*
|
|
8
|
+
* Text, document, and WebRTC factories share this union.
|
|
9
|
+
*
|
|
10
|
+
* `create-or-join` removes the out-of-band decision about which peer creates a room.
|
|
11
|
+
* The replica probes for an initialized room and joins it when one appears. Otherwise it
|
|
12
|
+
* runs a short awareness election and only the winning candidate seeds from `document`.
|
|
13
|
+
* A room that two peers seeded concurrently reports the terminal failure code
|
|
14
|
+
* `concurrent-seed` on every replica. The document and WebRTC factories accept this kind;
|
|
15
|
+
* the experimental text factory refuses it.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
type CollaborationBootstrap = {
|
|
19
|
+
readonly kind: 'create';
|
|
20
|
+
readonly document: Uint8Array;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'join';
|
|
23
|
+
readonly timeoutMs?: number;
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: 'create-or-join';
|
|
27
|
+
readonly document: Uint8Array;
|
|
28
|
+
/** Wait for an existing initialized room before the seed election. Default 4000 ms. */
|
|
29
|
+
readonly probeTimeoutMs?: number;
|
|
30
|
+
/** Seed election window after an empty probe. Default 1500 ms. */
|
|
31
|
+
readonly electionWindowMs?: number;
|
|
32
|
+
/** Join wait after this replica loses the seed election. Default 30000 ms. */
|
|
33
|
+
readonly timeoutMs?: number;
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Display-identity fields a live session can update.
|
|
38
|
+
*
|
|
39
|
+
* `actorId` and `role` are attribution and stay immutable for the session lifetime, so this
|
|
40
|
+
* type cannot name them.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
interface CollaborationIdentityUpdate {
|
|
44
|
+
readonly name?: string;
|
|
45
|
+
readonly color?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Host-facing collaboration session.
|
|
49
|
+
*
|
|
50
|
+
* A host reads identity, status, presence, and undo. The editor attaches
|
|
51
|
+
* {@link EditorCollaborationSession} internally and never through this type.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
interface CollaborationSession {
|
|
55
|
+
readonly documentId: string;
|
|
56
|
+
/** Unique identity for this attachment lifetime. */
|
|
57
|
+
readonly sessionId: string;
|
|
58
|
+
readonly identity: CollaborationIdentity;
|
|
59
|
+
/**
|
|
60
|
+
* Update the display name and color mid-session, when the replica supports it.
|
|
61
|
+
*
|
|
62
|
+
* Full-document sessions implement this and republish presence at once. A replica that
|
|
63
|
+
* freezes identity for its lifetime omits it.
|
|
64
|
+
*/
|
|
65
|
+
setIdentity?(update: CollaborationIdentityUpdate): void;
|
|
66
|
+
status(): CollaborationStatus;
|
|
67
|
+
/**
|
|
68
|
+
* Cached status, current reason, and last failure.
|
|
69
|
+
*
|
|
70
|
+
* Same reference until any of those values change.
|
|
71
|
+
*/
|
|
72
|
+
statusSnapshot(): CollaborationStatusSnapshot;
|
|
73
|
+
subscribeStatus(listener: (status: CollaborationStatus, reason?: CollaborationFailureCode, detail?: string) => void): () => void;
|
|
74
|
+
canUndo(): boolean;
|
|
75
|
+
canRedo(): boolean;
|
|
76
|
+
undo(): boolean;
|
|
77
|
+
redo(): boolean;
|
|
78
|
+
participants(): readonly CollaborationParticipant[];
|
|
79
|
+
subscribeParticipants(listener: (participants: readonly CollaborationParticipant[]) => void): () => void;
|
|
80
|
+
remoteSelections(): readonly CollaborationRemoteSelection[];
|
|
81
|
+
subscribeRemoteSelections(listener: (selections: readonly CollaborationRemoteSelection[]) => void): () => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for the experimental paragraph-text replica of {@link createTextCollaboration}.
|
|
85
|
+
*
|
|
86
|
+
* The caller owns `ydoc`.
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
interface CreateTextCollaborationOptions {
|
|
90
|
+
readonly ydoc: Y.Doc;
|
|
91
|
+
readonly awareness: Awareness;
|
|
92
|
+
readonly documentId: string;
|
|
93
|
+
/** Unique attachment identity. Omit it to generate a new identity for this session. */
|
|
94
|
+
readonly sessionId?: string;
|
|
95
|
+
readonly identity: CollaborationIdentity;
|
|
96
|
+
readonly bootstrap: CollaborationBootstrap;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Engine-facing paragraph-text session, including attach and operation gating.
|
|
100
|
+
*
|
|
101
|
+
* Hosts consume {@link CollaborationSession}. Providers call `setTransportStatus`.
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
interface TextCollaborationSession extends EditorCollaborationSession {
|
|
105
|
+
/**
|
|
106
|
+
* Provider convenience seam. Low-level consumers normally leave the session ready.
|
|
107
|
+
*
|
|
108
|
+
* `reason` is a typed code so a host can branch on it: pass `'transport-disconnected'` for
|
|
109
|
+
* a socket that will retry itself and `'authentication-failed'` for a credential the server
|
|
110
|
+
* rejected, because those need opposite responses. The provider's own phrasing goes in
|
|
111
|
+
* `detail`.
|
|
112
|
+
*/
|
|
113
|
+
setTransportStatus(status: 'ready' | 'disconnected' | 'error', reason?: CollaborationFailureCode, detail?: string): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Owned collaboration replica: document bytes, session, and teardown.
|
|
117
|
+
*
|
|
118
|
+
* Text and document factories share this shape. A host reads
|
|
119
|
+
* {@link CollaborationSession}; the engine session remains assignable.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
interface CollaborationHandle<TSession extends CollaborationSession> {
|
|
123
|
+
readonly document: Uint8Array;
|
|
124
|
+
readonly session: TSession;
|
|
125
|
+
destroy(): void;
|
|
126
|
+
}
|
|
127
|
+
/** Owned replica of the experimental {@link createTextCollaboration} factory. @beta */
|
|
128
|
+
type TextCollaborationHandle = CollaborationHandle<TextCollaborationSession>;
|
|
129
|
+
/**
|
|
130
|
+
* Create or join one experimental paragraph-text collaboration replica.
|
|
131
|
+
*
|
|
132
|
+
* This replica shares only the body paragraph text of an unchanging paragraph set: no
|
|
133
|
+
* formatting, no structure, no images. Use {@link createDocumentCollaboration} for
|
|
134
|
+
* full-document collaboration; this factory remains for hosts that want to replicate plain
|
|
135
|
+
* paragraph text and nothing else. The caller owns `ydoc`.
|
|
136
|
+
* @beta
|
|
137
|
+
*/
|
|
138
|
+
declare function createTextCollaboration(options: CreateTextCollaborationOptions): Promise<TextCollaborationHandle>;
|
|
139
|
+
|
|
140
|
+
export { type CollaborationSession as C, type TextCollaborationHandle as T, type CollaborationBootstrap as a, type CollaborationIdentityUpdate as b, type CollaborationHandle as c, type CreateTextCollaborationOptions as d, type TextCollaborationSession as e, createTextCollaboration as f };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CollaborationIdentity, CollaborationStatus, CollaborationStatusSnapshot, CollaborationFailureCode, CollaborationParticipant, CollaborationRemoteSelection } from '@docx-editor.dev/core/collaboration';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create or join bootstrap for one collaboration replica.
|
|
5
|
+
*
|
|
6
|
+
* Text, document, and WebRTC factories share this union.
|
|
7
|
+
*
|
|
8
|
+
* `create-or-join` removes the out-of-band decision about which peer creates a room.
|
|
9
|
+
* The replica probes for an initialized room and joins it when one appears. Otherwise it
|
|
10
|
+
* runs a short awareness election and only the winning candidate seeds from `document`.
|
|
11
|
+
* A room that two peers seeded concurrently reports the terminal failure code
|
|
12
|
+
* `concurrent-seed` on every replica. The document and WebRTC factories accept this kind;
|
|
13
|
+
* the experimental text factory refuses it.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
type CollaborationBootstrap = {
|
|
17
|
+
readonly kind: 'create';
|
|
18
|
+
readonly document: Uint8Array;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'join';
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'create-or-join';
|
|
25
|
+
readonly document: Uint8Array;
|
|
26
|
+
/** Wait for an existing initialized room before the seed election. Default 4000 ms. */
|
|
27
|
+
readonly probeTimeoutMs?: number;
|
|
28
|
+
/** Seed election window after an empty probe. Default 1500 ms. */
|
|
29
|
+
readonly electionWindowMs?: number;
|
|
30
|
+
/** Join wait after this replica loses the seed election. Default 30000 ms. */
|
|
31
|
+
readonly timeoutMs?: number;
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Display-identity fields a live session can update.
|
|
36
|
+
*
|
|
37
|
+
* `actorId` and `role` are attribution and stay immutable for the session lifetime, so this
|
|
38
|
+
* type cannot name them.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface CollaborationIdentityUpdate {
|
|
42
|
+
readonly name?: string;
|
|
43
|
+
readonly color?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Host-facing collaboration session.
|
|
47
|
+
*
|
|
48
|
+
* A host reads identity, status, presence, and undo. The editor attaches
|
|
49
|
+
* {@link EditorCollaborationSession} internally and never through this type.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
interface CollaborationSession {
|
|
53
|
+
readonly documentId: string;
|
|
54
|
+
/** Unique identity for this attachment lifetime. */
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
readonly identity: CollaborationIdentity;
|
|
57
|
+
/**
|
|
58
|
+
* Update the display name and color mid-session, when the replica supports it.
|
|
59
|
+
*
|
|
60
|
+
* Full-document sessions implement this and republish presence at once. A replica that
|
|
61
|
+
* freezes identity for its lifetime omits it.
|
|
62
|
+
*/
|
|
63
|
+
setIdentity?(update: CollaborationIdentityUpdate): void;
|
|
64
|
+
status(): CollaborationStatus;
|
|
65
|
+
/**
|
|
66
|
+
* Cached status, current reason, and last failure.
|
|
67
|
+
*
|
|
68
|
+
* Same reference until any of those values change.
|
|
69
|
+
*/
|
|
70
|
+
statusSnapshot(): CollaborationStatusSnapshot;
|
|
71
|
+
subscribeStatus(listener: (status: CollaborationStatus, reason?: CollaborationFailureCode, detail?: string) => void): () => void;
|
|
72
|
+
canUndo(): boolean;
|
|
73
|
+
canRedo(): boolean;
|
|
74
|
+
undo(): boolean;
|
|
75
|
+
redo(): boolean;
|
|
76
|
+
participants(): readonly CollaborationParticipant[];
|
|
77
|
+
subscribeParticipants(listener: (participants: readonly CollaborationParticipant[]) => void): () => void;
|
|
78
|
+
remoteSelections(): readonly CollaborationRemoteSelection[];
|
|
79
|
+
subscribeRemoteSelections(listener: (selections: readonly CollaborationRemoteSelection[]) => void): () => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type { CollaborationSession as C, CollaborationBootstrap as a, CollaborationIdentityUpdate as b };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CollaborationIdentity, CollaborationStatus, CollaborationStatusSnapshot, CollaborationFailureCode, CollaborationParticipant, CollaborationRemoteSelection } from '@docx-editor.dev/core/collaboration';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create or join bootstrap for one collaboration replica.
|
|
5
|
+
*
|
|
6
|
+
* Text, document, and WebRTC factories share this union.
|
|
7
|
+
*
|
|
8
|
+
* `create-or-join` removes the out-of-band decision about which peer creates a room.
|
|
9
|
+
* The replica probes for an initialized room and joins it when one appears. Otherwise it
|
|
10
|
+
* runs a short awareness election and only the winning candidate seeds from `document`.
|
|
11
|
+
* A room that two peers seeded concurrently reports the terminal failure code
|
|
12
|
+
* `concurrent-seed` on every replica. The document and WebRTC factories accept this kind;
|
|
13
|
+
* the experimental text factory refuses it.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
type CollaborationBootstrap = {
|
|
17
|
+
readonly kind: 'create';
|
|
18
|
+
readonly document: Uint8Array;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'join';
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'create-or-join';
|
|
25
|
+
readonly document: Uint8Array;
|
|
26
|
+
/** Wait for an existing initialized room before the seed election. Default 4000 ms. */
|
|
27
|
+
readonly probeTimeoutMs?: number;
|
|
28
|
+
/** Seed election window after an empty probe. Default 1500 ms. */
|
|
29
|
+
readonly electionWindowMs?: number;
|
|
30
|
+
/** Join wait after this replica loses the seed election. Default 30000 ms. */
|
|
31
|
+
readonly timeoutMs?: number;
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Display-identity fields a live session can update.
|
|
36
|
+
*
|
|
37
|
+
* `actorId` and `role` are attribution and stay immutable for the session lifetime, so this
|
|
38
|
+
* type cannot name them.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
interface CollaborationIdentityUpdate {
|
|
42
|
+
readonly name?: string;
|
|
43
|
+
readonly color?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Host-facing collaboration session.
|
|
47
|
+
*
|
|
48
|
+
* A host reads identity, status, presence, and undo. The editor attaches
|
|
49
|
+
* {@link EditorCollaborationSession} internally and never through this type.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
interface CollaborationSession {
|
|
53
|
+
readonly documentId: string;
|
|
54
|
+
/** Unique identity for this attachment lifetime. */
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
readonly identity: CollaborationIdentity;
|
|
57
|
+
/**
|
|
58
|
+
* Update the display name and color mid-session, when the replica supports it.
|
|
59
|
+
*
|
|
60
|
+
* Full-document sessions implement this and republish presence at once. A replica that
|
|
61
|
+
* freezes identity for its lifetime omits it.
|
|
62
|
+
*/
|
|
63
|
+
setIdentity?(update: CollaborationIdentityUpdate): void;
|
|
64
|
+
status(): CollaborationStatus;
|
|
65
|
+
/**
|
|
66
|
+
* Cached status, current reason, and last failure.
|
|
67
|
+
*
|
|
68
|
+
* Same reference until any of those values change.
|
|
69
|
+
*/
|
|
70
|
+
statusSnapshot(): CollaborationStatusSnapshot;
|
|
71
|
+
subscribeStatus(listener: (status: CollaborationStatus, reason?: CollaborationFailureCode, detail?: string) => void): () => void;
|
|
72
|
+
canUndo(): boolean;
|
|
73
|
+
canRedo(): boolean;
|
|
74
|
+
undo(): boolean;
|
|
75
|
+
redo(): boolean;
|
|
76
|
+
participants(): readonly CollaborationParticipant[];
|
|
77
|
+
subscribeParticipants(listener: (participants: readonly CollaborationParticipant[]) => void): () => void;
|
|
78
|
+
remoteSelections(): readonly CollaborationRemoteSelection[];
|
|
79
|
+
subscribeRemoteSelections(listener: (selections: readonly CollaborationRemoteSelection[]) => void): () => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type { CollaborationSession as C, CollaborationBootstrap as a, CollaborationIdentityUpdate as b };
|