@docx-editor.dev/pro/collaboration
@docx-editor.dev/pro/collaboration — Yjs replica factories and the module factory.
The default entry imports no network provider. Import @docx-editor.dev/pro/collaboration/webrtc for the WebRTC wrapper.
Functions (4)
collaborationModulefunctionSource ↗
Build the collaboration module. Construction never validates the key and never touches the network.
declare function collaborationModule(options: CollaborationModuleOptions): EditorModule;createDocumentCollaborationfunctionSource ↗
Create or join one full-document collaboration replica.
The caller owns ydoc.
declare function createDocumentCollaboration(options: CreateDocumentCollaborationOptions): Promise<DocumentCollaborationHandle>;createTextCollaborationfunctionbetaSource ↗
Create or join one experimental paragraph-text collaboration replica.
This replica shares only the body paragraph text of an unchanging paragraph set: no formatting, no structure, no images. Use [createDocumentCollaboration](createDocumentCollaboration) for full-document collaboration; this factory remains for hosts that want to replicate plain paragraph text and nothing else. The caller owns ydoc.
declare function createTextCollaboration(options: CreateTextCollaborationOptions): Promise<TextCollaborationHandle>;readCollaborationDocumentfunctionSource ↗
Read the document a synchronized Y.Doc holds, as .docx bytes.
This is the server side of a room: export, autosave to your own storage, search indexing, a nightly PDF, a webhook. It JOINS NOTHING. There is no identity, no Awareness and no session, so the job that calls it never appears in anyone's avatar stack, and it creates no editing gate, so it cannot write back.
ydoc must already hold the room's state: connect your provider and wait for its initial sync first, exactly as a { kind: \'join\' } bootstrap does. A document that was never seeded refuses with not-initialized rather than returning a truncated file.
ts
// Hocuspocus hands onStoreDocument the synced Y.Doc already:
async onStoreDocument({ documentName, document }) {
await writeFile(${documentName}.docx, readCollaborationDocument(document));
}
Synchronous, and it materializes the whole package per call — this is a job, not a render.
declare function readCollaborationDocument(ydoc: Y.Doc): Uint8Array;Classes (1)
CollaborationSchemaErrorclassSource ↗
Typed collaboration schema or trust-boundary failure.
declare class CollaborationSchemaError extends Error| Member | Type | Summary |
|---|---|---|
| (constructor) | | Constructs a new instance of the `CollaborationSchemaError` class |
| code | CollaborationFailureCode | |
| detail? | string | undefined |
Interfaces (8)
CollaborationHandleinterfaceSource ↗
Owned collaboration replica: document bytes, session, and teardown.
Text and document factories share this shape. A host reads [CollaborationSession](CollaborationSession); the engine session remains assignable.
interface CollaborationHandle<TSession extends CollaborationSession>| Member | Type | Summary |
|---|---|---|
| destroy | | |
| document | Uint8Array | |
| session | TSession |
CollaborationIdentityUpdateinterfaceSource ↗
Display-identity fields a live session can update.
actorId and role are attribution and stay immutable for the session lifetime, so this type cannot name them.
interface CollaborationIdentityUpdate| Member | Type | Summary |
|---|---|---|
| color? | string | |
| name? | string |
CollaborationModuleOptionsinterfaceSource ↗
How [collaborationModule](collaborationModule) is configured. The session is required; the licence key is optional and never validated.
interface CollaborationModuleOptions extends ProLicenseOptions| Member | Type | Summary |
|---|---|---|
| session | EditorCollaborationSession |
CollaborationSessioninterfaceSource ↗
Host-facing collaboration session.
A host reads identity, status, presence, and undo. The editor attaches [EditorCollaborationSession](EditorCollaborationSession) internally and never through this type.
interface CollaborationSession| Member | Type | Summary |
|---|---|---|
| canRedo | | |
| canUndo | | |
| documentId | string | |
| identity | CollaborationIdentity | |
| participants | | |
| redo | | |
| remoteSelections | | |
| sessionId | string | Unique identity for this attachment lifetime. |
| setIdentity | | Update the display name and color mid-session, when the replica supports it. |
| status | | |
| statusSnapshot | | Cached status, current reason, and last failure. |
| subscribeParticipants | | |
| subscribeRemoteSelections | | |
| subscribeStatus | | |
| undo | |
CreateDocumentCollaborationOptionsinterfaceSource ↗
Options for one full-document collaboration replica.
The caller owns ydoc.
interface CreateDocumentCollaborationOptions| Member | Type | Summary |
|---|---|---|
| awareness | Awareness | |
| bootstrap | CollaborationBootstrap | |
| documentId | string | |
| identity | CollaborationIdentity | |
| offlineEditing? | boolean | Admit local edits while the transport is `disconnected`. |
| sessionId? | string | Unique attachment identity. Omit it to generate a new identity for this session. |
| ydoc | Y.Doc |
CreateTextCollaborationOptionsinterfacebetaSource ↗
Options for the experimental paragraph-text replica of [createTextCollaboration](createTextCollaboration).
The caller owns ydoc.
interface CreateTextCollaborationOptions| Member | Type | Summary |
|---|---|---|
| awareness | Awareness | |
| bootstrap | CollaborationBootstrap | |
| documentId | string | |
| identity | CollaborationIdentity | |
| sessionId? | string | Unique attachment identity. Omit it to generate a new identity for this session. |
| ydoc | Y.Doc |
DocumentCollaborationSessioninterfaceSource ↗
Full-document collaboration session.
The seam matches [TextCollaborationSession](TextCollaborationSession), plus a live display-identity update.
interface DocumentCollaborationSession extends TextCollaborationSession| Member | Type | Summary |
|---|---|---|
| setIdentity | | Update the display identity for the rest of this session and republish presence. |
TextCollaborationSessioninterfaceSource ↗
Engine-facing paragraph-text session, including attach and operation gating.
Hosts consume [CollaborationSession](CollaborationSession). Providers call setTransportStatus.
interface TextCollaborationSession extends EditorCollaborationSession| Member | Type | Summary |
|---|---|---|
| setTransportStatus | | Provider convenience seam. Low-level consumers normally leave the session ready. |
Type aliases (3)
CollaborationBootstraptypeSource ↗
Create or join bootstrap for one collaboration replica.
Text, document, and WebRTC factories share this union.
create-or-join removes the out-of-band decision about which peer creates a room. The replica probes for an initialized room and joins it when one appears. Otherwise it runs a short awareness election and only the winning candidate seeds from document. A room that two peers seeded concurrently reports the terminal failure code concurrent-seed on every replica. The document and WebRTC factories accept this kind; the experimental text factory refuses it.
type CollaborationBootstrap = {
readonly kind: 'create';
readonly document: Uint8Array;
} | {
readonly kind: 'join';
readonly timeoutMs?: number;
readonly signal?: AbortSignal;
} | {
readonly kind: 'create-or-join';
readonly document: Uint8Array;
readonly probeTimeoutMs?: number;
readonly electionWindowMs?: number;
readonly timeoutMs?: number;
readonly signal?: AbortSignal;
};DocumentCollaborationHandletypeSource ↗
Owned full-document collaboration replica.
type DocumentCollaborationHandle = CollaborationHandle<DocumentCollaborationSession>;TextCollaborationHandletypebetaSource ↗
Owned replica of the experimental [createTextCollaboration](createTextCollaboration) factory.
type TextCollaborationHandle = CollaborationHandle<TextCollaborationSession>;Variables (3)
MAX_BASELINE_BYTESconstSource ↗
Maximum accepted creator baseline size in bytes.
MAX_BASELINE_BYTES: numberPROTOCOL_VERSIONconstSource ↗
Wire protocol version a replica writes into shared metadata and refuses to mismatch.
PROTOCOL_VERSION = 1SCHEMA_VERSIONconstSource ↗
Shared Yjs schema version a replica writes into shared metadata and refuses to mismatch.
SCHEMA_VERSION = 1