Enables single editor mode, allowing only one user to edit the document at a time while others remain in read-only mode.
Params
config: (object, optional). Configuration object for controlling single editor mode behavior
customMode: (boolean, optional). When true, SDK won’t automatically make HTML elements read-only for viewers. You need to handle this manually with the help of other APIs listed here. (default: false)
singleTabEditor: (boolean, optional). When enabled, restricts the editor to edit in only one browser tab at a time, preventing them from making changes across multiple tabs simultaneously (default: true)
Restrict Single Editor Mode to specific containers.
By default Single Editor Mode is enabled at the entire DOM level. You can restrict this feature to only certain HTML containers & their children by using this.
Control which elements are controlled by Single Editor Mode.
You must add the data-velt-sync-access-* attributes to native HTML elements (e.g. button, input). It will not work directly on React components.
Copy
Ask AI
// Enable sync access on custom elementsreturn ( <div data-velt-sync-access="true"> Controlled by Single Editor Mode </div>);// Exclude elements from sync accessreturn ( <button data-velt-sync-access-disabled="true"> Not controlled by Single Editor Mode </button>);
Copy
Ask AI
// Enable sync access on custom elementsreturn ( <div data-velt-sync-access="true"> Controlled by Single Editor Mode </div>);// Exclude elements from sync accessreturn ( <button data-velt-sync-access-disabled="true"> Not controlled by Single Editor Mode </button>);
Copy
Ask AI
<!-- Enable sync access on custom elements --><div data-velt-sync-access="true"> Controlled by Single Editor Mode</div><!-- Exclude elements from sync access --><button data-velt-sync-access-disabled="true"> Not controlled by Single Editor Mode</button>
Enable automatic syncing of text element contents across all users.
Supported elements:
<input>
<textarea>
ContentEditable <div>
First enable the feature and then define which elements should sync realtime.
Copy
Ask AI
const liveStateSyncElement = useLiveStateSyncUtils();// Enable auto-sync stateliveStateSyncElement.enableAutoSyncState();// In your JSXreturn ( <textarea id="uniqueId" data-velt-sync-state="true"></textarea>);
Copy
Ask AI
const liveStateSyncElement = useLiveStateSyncUtils();// Enable auto-sync stateliveStateSyncElement.enableAutoSyncState();// In your JSXreturn ( <textarea id="uniqueId" data-velt-sync-state="true"></textarea>);
Copy
Ask AI
<script>const liveStateSyncElement = Velt.getLiveStateSyncElement();liveStateSyncElement.enableAutoSyncState();</script><body> <!-- Enable auto-sync on text elements --> <textarea id="uniqueId" data-velt-sync-state="true"></textarea></body>
undefined: When there are no current editors available in single editor mode.
UserEditorAccess: When there is at least one editor available in single editor mode.
isEditor (boolean) - Whether the user is the editor
isEditorOnCurrentTab (boolean) - Whether the user is editor on current tab
Copy
Ask AI
// Using Hooksconst { isEditor, isEditorOnCurrentTab } = useUserEditorState();// Using APIconst liveStateSyncElement = useLiveStateSyncUtils();let subscription = liveStateSyncElement.isUserEditor().subscribe((userEditorAccess) => { console.log('Is Editor:', userEditorAccess.isEditor); console.log('Is Editor on Current Tab:', userEditorAccess.isEditorOnCurrentTab);});
To unsubscribe from the subscription:
Copy
Ask AI
subscription?.unsubscribe()
Copy
Ask AI
// Using Hooksconst { isEditor, isEditorOnCurrentTab } = useUserEditorState();// Using APIconst liveStateSyncElement = useLiveStateSyncUtils();let subscription = liveStateSyncElement.isUserEditor().subscribe((userEditorAccess) => { console.log('Is Editor:', userEditorAccess.isEditor); console.log('Is Editor on Current Tab:', userEditorAccess.isEditorOnCurrentTab);});
To unsubscribe from the subscription:
Copy
Ask AI
subscription?.unsubscribe()
Copy
Ask AI
const liveStateSyncElement = Velt.getLiveStateSyncElement();let subscription = liveStateSyncElement.isUserEditor().subscribe((userEditorAccess) => { console.log('Is Editor:', userEditorAccess.isEditor); console.log('Is Editor on Current Tab:', userEditorAccess.isEditorOnCurrentTab);});// To unsubscribe from the subscription:subscription?.unsubscribe()
requestStatus (string) - ‘requested’ for active requests
requestedBy (User) - User object of the requester
Copy
Ask AI
// Using Hooksconst editorAccessRequested = useEditorAccessRequestHandler();// Using APIconst liveStateSyncElement = useLiveStateSyncUtils();let subscription = liveStateSyncElement.isEditorAccessRequested().subscribe((data) => { if (data === null) { console.log('No active requests or user is not editor'); } else { console.log('Request from:', data.requestedBy.name); }});
To unsubscribe from the subscription:
Copy
Ask AI
subscription?.unsubscribe()
Copy
Ask AI
// Using Hooksconst editorAccessRequested = useEditorAccessRequestHandler();// Using APIconst liveStateSyncElement = useLiveStateSyncUtils();let subscription = liveStateSyncElement.isEditorAccessRequested().subscribe((data) => { if (data === null) { console.log('No active requests or user is not editor'); } else { console.log('Request from:', data.requestedBy.name); }});
To unsubscribe from the subscription:
Copy
Ask AI
subscription?.unsubscribe()
Copy
Ask AI
const liveStateSyncElement = Velt.getLiveStateSyncElement();let subscription = liveStateSyncElement.isEditorAccessRequested().subscribe((data) => { if (data === null) { console.log('No active requests or user is not editor'); } else { console.log('Request from:', data.requestedBy.name); }});// To unsubscribe from the subscription:subscription?.unsubscribe()