Setup
Single Editor Mode
With Single Editor Mode, only one user will be able to edit the document at any given time. All other users live on the document will automatically be read-only.
Accessing the LiveStateSyncElement
The LiveStateSyncElement
contains all of the methods used to interact with the single editor mode
and live state sync
features.
There are two ways to access the LiveStateSyncElement
.
Accessing via the Velt client object
Accessing via a hook
Enable Single Editor Mode
Enables single editor mode.
Disabled by default
(Optional) Set your DOM to read-only yourself, or let our SDK do it for you.
Default: We handle it for you.
You can pass a configuration object to enable customMode
on Single Editor Mode.
If custom mode is enabled, we will not make the viewer’s DOM read-only. You will have to handle the logic yourself.
(Optional) Lock Edit access to Single-Tab.
Default: true
The configuration {singleTabEditor: boolean}
limits editing to one tab at a time. If an editor opens the same document
in multiple tabs and begins editing in one (e.g., Tab 1), edit access is automatically disabled in the others (e.g., Tab 2). To enable editing in a different tab, a button can be implemented to trigger the editCurrentTab()
method, granting edit access in that specific tab.
Disable Single Editor Mode
Disables single editor mode.
Enable default Single Editor UI
In Single Editor mode, by default there is a small toast at the bottom of the screen that shows:
- whether you are the editor or viewer
- whether any other viewer has requested editor access
- access request timeout coundown
- option to reject request
To enable this toast, you can use the enableDefaultSingleEditorUI()
method.
Default: enabled
Disable default single editor UI
In Single Editor mode, by default there is a small toast at the bottom of the screen that shows:
- whether you are the editor or viewer
- whether any other viewer has requested editor access
- access request timeout coundown
- option to reject request
You can choose to disable this toast in favor of using your own custom UI.
To disable this pop up, you can use the disableDefaultSingleEditorUI()
method.
Set current user as the Editor
Sets the current user as Editor. Note this will mark all the other users on the document as readonly users.
Check if current user is the Editor
isUserEditor()
returns a subscription that emits the following UserEditorAccess
object:
To unsubscribe from the subscription:
Using Hooks:
The useUserEditorState()
hook is used to call liveStateSyncElement.isUserEditor()
without having to handle the subscription.
The hook will automatically unsubscribe from the subscription when the component dismounts.
Get the current editor
getEditor()
returns a subscription that emits the User
object representing the current editor.
User
object schema:
To unsubscribe from the subscription:
Using Hooks:
The useEditor()
hook is used to call liveStateSyncElement.getEditor()
without having to handle the subscription.
The hook will automatically unsubscribe from the subscription when the component dismounts.
Reset access for all users
Resets access for all users.
Request editor access from the current editor
Call requestEditorAccess()
from a Viewer’s client to get editor access from the current editor.
It returns a subscription that emits:
null
if the request is pendingtrue
if the request went accepted by the editorfalse
if the request was rejected by the editor
To unsubscribe from the subscription:
Check whether editor access is being requested
The isEditorAccessRequested()
method is used to detect on the Editor's
client if a Viewer
has requested editor access or not.
If the user is not the editor or the request has been canceled, the subscription will emit a null
value.
It returns a subscription that emits:
null
if the user is not the editor or the request has been canceled- a
isUserEditor
object if the user is the editor and there is an ongoing request
isUserEditor
Object Schema:
To unsubscribe from the subscription:
Using Hooks:
The useEditorAccessRequestHandler()
hook is used to call liveStateSyncElement.isEditorAccessRequested()
without having to handle the subscription.
The hook will automatically unsubscribe from the subscription when the component dismounts.
Accept Editor access request
Once the Editor gets an Editor Access request, call ‘acceptEditorAccessRequest()’ method to accept
the request.
Use with isEditorAccessRequested()
:
Reject Editor access request
Once the Editor gets an Editor access request, call ‘rejectEditorAccessRequest()’ method to reject
the request.
Use with isEditorAccessRequested()
:
To cancel an edit access request by the Viewer
The cancelEditorAccessRequest()
method is used to cancel an existing edit access request by the Viewer.
To make the current tab editable when the editor has opened multiple tabs
The editCurrentTab()
method is used to make the current tab editable when the editor has opened multiple tabs on the same page.
Setting timeout value for automatic editor access transfer after request
The setEditorAccessTimeout()
method is used to set the editor access timeout value in seconds.
Default: 5 seconds
Enable automatic transfer of edit access after timeout
The enableEditorAccessTransferOnTimeOut()
method is used to enable automatic transferring of editor access after timeout.
Default: enabled
Disable automatic transfer of edit access after timeout
The disableEditorAccessTransferOnTimeOut()
method is used to disable automatic transferring of editor access after timeout.
Automatically sync contents of Text Elements
Auto syncs the content of the following Text HTML elements, such that when editor
types, the element’s content is synced across all active users currently live on the document.
- input
- textarea
- ContentEditable Divs
To enable syncing, follow these two steps:
- Enable Auto Sync State feature:
- Set the
data-velt-sync-state
attribute totrue
on the Text HTML element you want to sync:
id
to the HTML element to make the syncing more robust.data-velt-sync-state
attribute to a native HTML element (e.g. input, textarea). It will not work directly on React components.Automatically make HTML Elements readonly or editable
By default in Single Editor Mode, we control making these html elements editable or readonly on the entire DOM:
- input
- textarea
- select
- button
- contentEditable divs
For Viewers, the default elements listed above will be disabled, meaning click
, mouseup
and mousedown
events will be prevented.
If there are any other elements that you want us to control beyond the default elements we listed above, such as div
, span
elements etc, then you can add data-velt-sync-access="true"
to that element.
data-velt-sync-access
attribute to native HTML elements (e.g. div, span). It will not work directly on React components.Exclude default HTML elements from Auto Syncing Access
In Single Editor Mode, we control enabling and disabling of certain html elements on the entire DOM.
If you want to exclude any of those html elements from this behavior, you can add data-velt-sync-access-disabled="true"
to that element.
data-velt-sync-access-disabled
attribute to native HTML elements (e.g. button, input). It will not work directly on React components.Restrict Single Editor Mode to Specific Parent 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 the singleEditorModeContainerIds()
method. It takes in an array of element ID strings. These IDs represent the parent elements within which Single Editor Mode will be enabled.
Get Editor Access Timer State
With the useEditorAccessTimer
hook, you can get the Editor Access Timer state.
The editorAccessTimer
class has the following schema:
state
:'idle'
|'inProgress'
|'completed'
durationLeft
:number