Skip to content

Offline ​

Edits made without a connection stay in the browser and reach the server once the connection is back.

Anna TurnerConnecting
Maria KimConnecting

Turn the connection off, edit the text in both panes and turn it back on.

While a client is offline, its edits wait in a queue. Once it reconnects, the client catches up with the log, rebases the queue and sends it. Without a saved copy, the queue lives only in the memory of the tab.

Keep edits in the browser ​

Create a copy with offlinePersistence and pass it to useCollabEditor as persistence:

ts
import { useCollabEditor } from '@numior/kit/collaboration/vue';import { contentSchema } from '@numior/kit/content';import { offlinePersistence } from '@numior/kit/offline';const persistence = offlinePersistence('oslo-chair', { schema: contentSchema });const { ready, document, plugins, ids, readOnly, report } = useCollabEditor({ doc: 'oslo-chair', user: { id: 'anna', name: 'Anna Turner' }, schema: contentSchema, transport, editor: () => api.value, persistence,});

The copy lives in IndexedDB: the document, the log of steps, the queue of unsent steps and the overwritten values. After a reload, the editor opens the saved document at once, with the same client id, and sends the queue when the connection is back.

The log is compacted into the document after 500 steps. A write the browser refuses is tried again after 1, 2 and 4 seconds and so on, up to 30. Meanwhile the edits stay in the memory of the tab.

Open again after a failure drops the saved queue as well. Offline copies are for editor documents: a spreadsheet book has none.

offlinePersistence: (doc: string, options: OfflinePersistenceOptions) => CollabPersistence
interface OfflinePersistenceOptions extends OfflineStoreOptions { readonly locks?: OfflineLocks | undefined; readonly channel?: OfflineChannelFactory | undefined; readonly migrations?: readonly OfflineMigration[] | undefined; readonly onError?: ((error: unknown) => void) | undefined; readonly onState?: ((state: OfflineCopy) => void) | undefined;}
interface OfflineStoreOptions { readonly schema: Schema; readonly plugins?: OfflinePlugins | undefined; readonly factory?: IDBFactory | undefined; readonly compactAfter?: number | undefined;}

One tab writes ​

Only one tab keeps the copy of a document. Other tabs with the same document work as plain clients and save nothing.

onState reports what happens to the copy, and your app decides how to show it:

StateMeaning
keptThis tab keeps the copy
failingThe browser refuses to write, and the tab keeps trying
elsewhereAnother tab keeps the copy
unavailableThe browser cannot pick a tab, so nothing is saved
ts
import { ref } from 'vue';import type { OfflineCopy } from '@numior/kit/offline';const copy = ref<OfflineCopy>();const persistence = offlinePersistence('oslo-chair', { schema: contentSchema, onState: (state) => { copy.value = state; },});

New schema version ​

A copy saved by an older version of your app may not fit the new schema. Describe the change in migrations, and the copy is converted on the device before the client connects:

ts
const persistence = offlinePersistence('oslo-chair', { schema: contentSchema, migrations: [ { subject: 'schema', from: 4, to: 5, document: (document) => withTableKeys(document), step: (step) => step, }, ],});

subject is schema for the document schema, or the name of a plugin listed in plugins. document converts the saved document, and step converts each saved step or returns undefined when it cannot.

When no migration fits, the document opens read-only, and report of useCollabEditor says why. Show it with NuiCollabReport. The queue stays on the device and does not reach the server.

vue
<template> <NuiCollabReport v-if="report !== undefined" :report="report" /></template>

API ​

Props

Name
Type
Default
Description
reportrequired
CollabReport
—
Report from useCollabEditor: why the saved copy cannot be opened for editing.
labels
Partial<Omit<NuiCollabMessages, "present">>
—
Your own texts in place of the built-in ones from collabMessages, one key at a time.

Texts

Key
Russian
English
add
Добавить комментарий
Add comment
alternativeEmpty
Пусто
Empty
alternativeFalse
Нет
No
alternativeHide
Скрыть
Hide
alternativeRestore
Вернуть
Put back
alternativeShow
Показать в документе
Show in the document
alternativeTrue
Да
Yes
alternativeUnknown
Другой участник
Another participant
alternatives
Перезаписанные значения
Overwritten values
cancel
Отмена
Cancel
closeVersion
Закрыть
Close
comments
Комментарии
Comments
empty
Пока нет комментариев
No comments yet
failed
Не удалось сохранить комментарий
The comment could not be saved
failureDiverged
Ваша копия новее документа на сервере.
Your copy is ahead of the document kept on the server.
failureDocument
Правка другого участника не подошла к вашей копии.
A change made by someone else did not fit your copy.
failureInvalid
Сервер не принял одну из ваших правок.
The server did not accept one of your changes.
failureProtocol
Сервер прислал ответ, который страница не смогла прочитать.
The server sent a reply this page could not read.
failureReadOnly
Документ открыт только для чтения, пока вы не откроете его заново.
The document is read-only until you open it again.
failureRejoin
Открыть заново
Open again
failureSchema
Страница работает на версии приложения старее той, что нужна документу. Обновите страницу.
This page runs an older version of the application than the document needs. Reload the page.
failureTitle
Правки больше не отправляются
Your changes are no longer sent
failureUnsent
({ count }) => `Не отправлено правок: ${count}. Скопируйте нужное, прежде чем открыть документ заново.`
({ count }) => `${count} ${plural('en', count, { one: 'change of yours was', other: 'changes of yours were' })} not sent. Copy what you need before you open the document again.`
history
История версий
Version history
historyFailed
История версий недоступна
The version history is unavailable
lost
Текст удалён
The text was removed
noChanges
В этой версии нет изменений
Nothing changed in this version
noVersions
Сохранённых версий пока нет
No saved versions yet
placeholder
Напишите комментарий
Write a comment
present
Сейчас в документе
People in this document
remove
Удалить
Delete
reopen
Открыть снова
Reopen
reply
Ответить
Reply
replyPlaceholder
Напишите ответ
Write a reply
reportDamaged
Копию на этом устройстве не удалось прочитать
The copy saved on this device cannot be read
reportStep
({ subject }) => `${subject}: сохранённые правки нельзя перевести на новую версию`
({ subject }) => `${subject}: saved changes cannot be converted to the new version`
reportTitle
Документ открыт только для чтения
This document is read-only
reportUnsent
({ count }) => `Неотправленные правки сохранены на этом устройстве: ${count}`
({ count }) => `${count} unsent ${plural('en', count, { one: 'change is', other: 'changes are' })} kept on this device`
reportVersion
({ subject, stored, current }) => `${subject}: у сохранённой копии версия ${stored}, приложение ждёт ${current}`
({ subject, stored, current }) => `${subject}: the saved copy has version ${stored}, this application expects ${current}`
resolve
Решить
Resolve
resolved
Решён
Resolved
restore
Восстановить эту версию
Restore this version
saveVersion
Сохранить версию
Save version
send
Отправить
Send
show
Показать в тексте
Show in text
showChanges
Показать изменения
Show changes

Edit this page

Search

Esc