Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

v0.8.2: offline mode, templates, Collaborate rename, identity field, dialog fix

nyblnet451da419edf9
diff --git a/docs/collab-design.md b/docs/collab-design.md
index 9267fb96..0d598af6 100644
--- a/docs/collab-design.md
+++ b/docs/collab-design.md
@@ -232,6 +232,29 @@ One Worker + Durable Object class, ~300 lines:
M0+M1 are pure client work, shippable through the existing release channel.
M2 is the first Bento server code ever — small, blind, and replaceable.
+## Identity (v0.8.2 posture and the enterprise path)
+
+Identity is deliberately **self-managed and local**: a display name in the
+Collaborate popover (localStorage `bento-author`, shared with comments),
+shown to peers via presence — zero friction, zero accounts, consistent with
+E2EE (the relay couldn't verify identities anyway; it never sees them).
+Presence names are therefore *claims, not proofs* — fine for teams that
+share room keys deliberately. The future enterprise path, when demand
+appears: an optional identity layer where ops/presence are SIGNED by
+per-user keypairs and an org roster (SSO-provisioned) maps public keys to
+verified names — layered ON TOP of the existing protocol (a signature field
+in frames), relay still blind, local-first files unchanged. Nothing shipped
+today constrains that design.
+
+## Offline mode
+
+A viewer-side hard switch (localStorage `bento-offline`, toggle in About)
+that blocks every network touch: update checks and the relay transport.
+Same-machine tab sync (BroadcastChannel) is not networking and stays on.
+Documents keep their (dormant) credentials — offline mode is a property of
+the VIEWER, not the file — so nothing breaks when the switch flips either
+way. This is the "no cloud, provably" story for local-first purists.
+
## What we are explicitly protecting
The five invariants that already define the format survive untouched:
diff --git a/slides/package.json b/slides/package.json
index 75cfa88f..11f89cb1 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "bento-slides",
"private": true,
- "version": "0.8.1",
+ "version": "0.8.2",
"type": "module",
"scripts": {
"dev": "vite",
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index b1658e6b..51462e20 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -8,16 +8,16 @@ import {
instantiateLayout, layoutElementIds, newDocId, uid,
type ShapeKind, type Slide, type SlideElement,
} from '../model'
-import { APP_VERSION, applyUpdate, applyUpdateInPlace, autoCheckEnabled, canUpdateInPlace, checkForUpdates, setAutoCheck } from '../update'
+import { APP_VERSION, applyUpdate, applyUpdateInPlace, autoCheckEnabled, canUpdateInPlace, checkForUpdates, offlineEnabled, setAutoCheck, setOffline } from '../update'
import { CHART_PRESETS } from '../charts'
import { renderSlide, renderThumbnail } from '../render'
import { SlideCanvas } from './canvas'
import { PropsPanel } from './panels'
import { startPresentation } from '../present'
-import { saveFile } from '../save'
+import { saveFile, serializeFile, writeUpdatedFileAs } from '../save'
import { ICONS } from '../icons'
import { t, setLocale, locale, LOCALE_CHOICES } from '../i18n'
-import { joinFromDoc, mintCollab, onlineTransport, rotateKeys, sharingOn, startSharing, stopSharing } from '../sync/online'
+import { disconnectOnline, joinFromDoc, mintCollab, onlineTransport, rotateKeys, sharingOn, startSharing, stopSharing } from '../sync/online'
const i18nT = t
@@ -176,7 +176,7 @@ export class Editor {
// launch-time check (opt-out lives in the About dialog); a found update
// turns the button into a visible peach chip
setTimeout(async () => {
- if (!autoCheckEnabled()) return
+ if (!autoCheckEnabled() || offlineEnabled()) return
const r = await checkForUpdates()
this.lastAutoCheck = r
if (r.status === 'update') {
@@ -294,7 +294,7 @@ export class Editor {
private shareDropdown(): HTMLElement {
const wrap = div('ed-dropdown')
this.shareWrap = wrap
- this.shareB = btn(ICONS.share, t('Share'), () => {
+ this.shareB = btn(ICONS.share, t('Collaborate'), () => {
wrap.classList.toggle('open')
if (wrap.classList.contains('open')) this.renderSharePanel()
}, t('Live collaboration — work on this deck together'))
@@ -323,6 +323,36 @@ export class Editor {
panel.appendChild(b)
return b
}
+ // your display name — self-managed, stored in this browser only, shown
+ // to collaborators via presence (shared with the comments feature)
+ const nameRow = div('ed-share-name')
+ const nameLabel = document.createElement('label')
+ nameLabel.textContent = t('Your name')
+ const nameInput = document.createElement('input')
+ nameInput.type = 'text'
+ nameInput.placeholder = t('Guest')
+ try {
+ nameInput.value = localStorage.getItem('bento-author') ?? ''
+ } catch {
+ /* storage unavailable */
+ }
+ nameInput.addEventListener('change', () => {
+ try {
+ localStorage.setItem('bento-author', nameInput.value.trim())
+ } catch {
+ /* storage unavailable */
+ }
+ this.session?.hello() // push the new name to peers right away
+ })
+ nameRow.append(nameLabel, nameInput)
+ panel.appendChild(nameRow)
+
+ if (offlineEnabled()) {
+ note(t('Offline mode is on — nothing leaves this computer.'))
+ note(t('Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.'))
+ return
+ }
+
const tr = onlineTransport()
if (!sharingOn(this.store) || !tr) {
note(t('Work on this deck together, live.'))
@@ -988,6 +1018,31 @@ export class Editor {
autoRow.append(autoCb, document.createTextNode(' ' + t('Check for updates automatically at launch')))
box.appendChild(autoRow)
+ // the hard no-network switch: blocks update checks AND online
+ // collaboration for this browser. Same-machine tab sync is not
+ // networking and stays on.
+ const offRow = document.createElement('label')
+ offRow.className = 'ed-about-auto'
+ const offCb = document.createElement('input')
+ offCb.type = 'checkbox'
+ offCb.checked = offlineEnabled()
+ offCb.addEventListener('change', () => {
+ setOffline(offCb.checked)
+ if (offCb.checked) {
+ if (this.session) disconnectOnline(this.session)
+ } else if (this.session && sharingOn(this.store)) {
+ joinFromDoc(this.session, this.store)
+ }
+ this.wireOnlineStatus()
+ this.toast(
+ offCb.checked
+ ? t('Offline mode on — nothing leaves this computer')
+ : t('Offline mode off — online features re-enabled'),
+ )
+ })
+ offRow.append(offCb, document.createTextNode(' ' + t('Offline mode — block all network features (updates, online collaboration)')))
+ box.appendChild(offRow)
+
const langRow = document.createElement('label')
langRow.className = 'ed-about-auto'
const langSel = document.createElement('select')
@@ -1070,7 +1125,24 @@ export class Editor {
this.toast(t('This is now a new deck — save it under a new name'))
void this.save(true)
})
- dupRow.append(dupB)
+ const tplB = document.createElement('button')
+ tplB.className = 'ed-btn'
+ tplB.textContent = t('Save as template…')
+ tplB.title = t('Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.')
+ tplB.addEventListener('click', async () => {
+ const clone = JSON.parse(JSON.stringify(this.store.doc)) as import('../model').BentoDoc
+ clone.template = true
+ delete clone.collab // instances mint their own credentials
+ delete (clone as { docId?: string }).docId
+ try {
+ const ok = await writeUpdatedFileAs(serializeFile(clone), clone)
+ if (ok) this.toast(t('Template saved — every open of it starts a fresh deck'))
+ } catch (err) {
+ console.error(err)
+ this.toast(t('Save failed — see console'))
+ }
+ })
+ dupRow.append(dupB, tplB)
box.appendChild(dupRow)
const fine = div('ed-about-fine')
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index b46a2afb..5ce4a4a5 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -259,4 +259,15 @@ export const de: Catalog = {
"Duplicate as new deck…": "Als neues Deck duplizieren…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "Kopiert alles in ein unabhängiges Dokument mit eigener Identität — es synchronisiert sich nie mit diesem.",
"This is now a new deck — save it under a new name": "Dies ist jetzt ein neues Deck — unter neuem Namen speichern",
+ "Collaborate": "Zusammenarbeiten",
+ "Your name": "Dein Name",
+ "Guest": "Gast",
+ "Offline mode is on — nothing leaves this computer.": "Der Offline-Modus ist aktiv — nichts verlässt diesen Computer.",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "Tabs auf diesem Rechner synchronisieren sich weiterhin; deaktiviere den Offline-Modus im „Über“-Dialog, um online zusammenzuarbeiten.",
+ "Offline mode — block all network features (updates, online collaboration)": "Offline-Modus — blockiert alle Netzwerkfunktionen (Updates, Online-Zusammenarbeit)",
+ "Offline mode on — nothing leaves this computer": "Offline-Modus an — nichts verlässt diesen Computer",
+ "Offline mode off — online features re-enabled": "Offline-Modus aus — Online-Funktionen wieder aktiviert",
+ "Save as template…": "Als Vorlage speichern…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "Speichert eine Vorlagenkopie: Wer sie öffnet, erhält ein frisches, unabhängiges Deck mit eigener Identität und eigenen Schlüsseln.",
+ "Template saved — every open of it starts a fresh deck": "Vorlage gespeichert — jedes Öffnen startet ein frisches Deck",
}
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index 6ff487b2..535f546c 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -259,4 +259,15 @@ export const es: Catalog = {
"Duplicate as new deck…": "Duplicar como presentación nueva…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "Copia todo en un documento independiente con identidad propia: nunca se sincronizará con este.",
"This is now a new deck — save it under a new name": "Esta ya es una presentación nueva: guárdala con otro nombre",
+ "Collaborate": "Colaborar",
+ "Your name": "Tu nombre",
+ "Guest": "Invitado",
+ "Offline mode is on — nothing leaves this computer.": "El modo sin conexión está activo: nada sale de este equipo.",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "Las pestañas de este equipo siguen sincronizándose; desactiva el modo sin conexión en «Acerca de» para colaborar en línea.",
+ "Offline mode — block all network features (updates, online collaboration)": "Modo sin conexión: bloquea todas las funciones de red (actualizaciones, colaboración en línea)",
+ "Offline mode on — nothing leaves this computer": "Modo sin conexión activado: nada sale de este equipo",
+ "Offline mode off — online features re-enabled": "Modo sin conexión desactivado: funciones en línea reactivadas",
+ "Save as template…": "Guardar como plantilla…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "Guarda una copia como plantilla: cada persona que la abra obtiene una presentación nueva e independiente, con identidad y claves propias.",
+ "Template saved — every open of it starts a fresh deck": "Plantilla guardada: cada apertura inicia una presentación nueva",
}
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index e2762572..bb6cba27 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -259,4 +259,15 @@ export const fr: Catalog = {
"Duplicate as new deck…": "Dupliquer comme nouveau diaporama…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "Copie tout dans un document indépendant avec sa propre identité — il ne se synchronisera jamais avec celui-ci.",
"This is now a new deck — save it under a new name": "C'est maintenant un nouveau diaporama — enregistrez-le sous un nouveau nom",
+ "Collaborate": "Collaborer",
+ "Your name": "Votre nom",
+ "Guest": "Invité",
+ "Offline mode is on — nothing leaves this computer.": "Le mode hors ligne est activé — rien ne quitte cet ordinateur.",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "Les onglets de cette machine restent synchronisés ; désactivez le mode hors ligne dans « À propos » pour collaborer en ligne.",
+ "Offline mode — block all network features (updates, online collaboration)": "Mode hors ligne — bloque toutes les fonctions réseau (mises à jour, collaboration en ligne)",
+ "Offline mode on — nothing leaves this computer": "Mode hors ligne activé — rien ne quitte cet ordinateur",
+ "Offline mode off — online features re-enabled": "Mode hors ligne désactivé — fonctions en ligne réactivées",
+ "Save as template…": "Enregistrer comme modèle…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "Enregistre une copie modèle : chaque personne qui l'ouvre obtient un diaporama neuf et indépendant, avec sa propre identité et ses propres clés.",
+ "Template saved — every open of it starts a fresh deck": "Modèle enregistré — chaque ouverture démarre un nouveau diaporama",
}
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 86ab3680..1bed105f 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -259,4 +259,15 @@ export const it: Catalog = {
"Duplicate as new deck…": "Duplica come nuova presentazione…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "Copia tutto in un documento indipendente con identità propria: non si sincronizzerà mai con questo.",
"This is now a new deck — save it under a new name": "Ora è una nuova presentazione: salvala con un altro nome",
+ "Collaborate": "Collabora",
+ "Your name": "Il tuo nome",
+ "Guest": "Ospite",
+ "Offline mode is on — nothing leaves this computer.": "La modalità offline è attiva: nulla lascia questo computer.",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "Le schede su questa macchina restano sincronizzate; disattiva la modalità offline in «Informazioni» per collaborare online.",
+ "Offline mode — block all network features (updates, online collaboration)": "Modalità offline: blocca tutte le funzioni di rete (aggiornamenti, collaborazione online)",
+ "Offline mode on — nothing leaves this computer": "Modalità offline attiva: nulla lascia questo computer",
+ "Offline mode off — online features re-enabled": "Modalità offline disattivata: funzioni online riattivate",
+ "Save as template…": "Salva come modello…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "Salva una copia modello: chiunque la apra ottiene una presentazione nuova e indipendente, con identità e chiavi proprie.",
+ "Template saved — every open of it starts a fresh deck": "Modello salvato: ogni apertura avvia una nuova presentazione",
}
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index ae765f51..a3009755 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -259,4 +259,15 @@ export const ja: Catalog = {
"Duplicate as new deck…": "新しいデッキとして複製…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "すべてを独立した新しいドキュメントに複製します — 元のファイルと同期することはありません。",
"This is now a new deck — save it under a new name": "新しいデッキになりました — 新しい名前で保存してください",
+ "Collaborate": "共同編集",
+ "Your name": "あなたの名前",
+ "Guest": "ゲスト",
+ "Offline mode is on — nothing leaves this computer.": "オフラインモードがオンです — このコンピュータから何も送信されません。",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "同じマシンのタブ同士は引き続き同期します。オンラインで共同編集するには「About」でオフラインモードを解除してください。",
+ "Offline mode — block all network features (updates, online collaboration)": "オフラインモード — すべてのネットワーク機能を遮断(更新確認・オンライン共同編集)",
+ "Offline mode on — nothing leaves this computer": "オフラインモード オン — このコンピュータから何も送信されません",
+ "Offline mode off — online features re-enabled": "オフラインモード オフ — オンライン機能を再有効化しました",
+ "Save as template…": "テンプレートとして保存…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "テンプレートを保存します。開いた人はそれぞれ、独自の ID とキーを持つ独立した新しいデッキを取得します。",
+ "Template saved — every open of it starts a fresh deck": "テンプレートを保存しました — 開くたびに新しいデッキが始まります",
}
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index 6c64d0ad..5adf3aa3 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -259,4 +259,15 @@ export const zhHans: Catalog = {
"Duplicate as new deck…": "复制为新演示文稿…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "将全部内容复制到具有独立身份的新文档 — 它永远不会与当前文档同步。",
"This is now a new deck — save it under a new name": "这已是新演示文稿 — 请用新名称保存",
+ "Collaborate": "协作",
+ "Your name": "你的名字",
+ "Guest": "访客",
+ "Offline mode is on — nothing leaves this computer.": "离线模式已开启 — 任何数据都不会离开这台电脑。",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "本机的标签页仍会同步;要在线协作,请在“关于”对话框中关闭离线模式。",
+ "Offline mode — block all network features (updates, online collaboration)": "离线模式 — 屏蔽所有网络功能(更新检查、在线协作)",
+ "Offline mode on — nothing leaves this computer": "离线模式已开启 — 任何数据都不会离开这台电脑",
+ "Offline mode off — online features re-enabled": "离线模式已关闭 — 在线功能已恢复",
+ "Save as template…": "另存为模板…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "保存为模板副本:每个打开它的人都会得到一份全新的独立演示文稿,拥有自己的标识和密钥。",
+ "Template saved — every open of it starts a fresh deck": "模板已保存 — 每次打开都会生成新的演示文稿",
}
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index 5587ba3e..a100089c 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -259,4 +259,15 @@ export const zhHant: Catalog = {
"Duplicate as new deck…": "複製為新簡報…",
"Copies everything into an independent document with its own identity — it will never sync with this one.": "將全部內容複製到具有獨立身分的新文件 — 它永遠不會與目前文件同步。",
"This is now a new deck — save it under a new name": "這已是新簡報 — 請用新名稱儲存",
+ "Collaborate": "協作",
+ "Your name": "你的名字",
+ "Guest": "訪客",
+ "Offline mode is on — nothing leaves this computer.": "離線模式已開啟 — 任何資料都不會離開這台電腦。",
+ "Tabs on this machine still sync; turn offline mode off in the About dialog to collaborate online.": "本機的分頁仍會同步;要線上協作,請在「關於」對話方塊中關閉離線模式。",
+ "Offline mode — block all network features (updates, online collaboration)": "離線模式 — 封鎖所有網路功能(更新檢查、線上協作)",
+ "Offline mode on — nothing leaves this computer": "離線模式已開啟 — 任何資料都不會離開這台電腦",
+ "Offline mode off — online features re-enabled": "離線模式已關閉 — 線上功能已恢復",
+ "Save as template…": "另存為範本…",
+ "Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.": "儲存為範本副本:每個開啟它的人都會得到一份全新的獨立簡報,擁有自己的識別碼與金鑰。",
+ "Template saved — every open of it starts a fresh deck": "範本已儲存 — 每次開啟都會產生新的簡報",
}
diff --git a/slides/src/model.ts b/slides/src/model.ts
index 2b44113a..a5cda9b4 100644
--- a/slides/src/model.ts
+++ b/slides/src/model.ts
@@ -274,6 +274,14 @@ export interface BentoDoc {
on?: boolean
sync?: import('./sync/crdt').SyncStateJSON
}
+ /**
+ * Template file (.dotx-style): every OPEN instantiates a fresh document —
+ * parseDoc strips this flag, mints a new docId and drops collab, so each
+ * person who opens the template gets an independent deck with its own
+ * identity and credentials. The template file itself never changes (there
+ * is no file handle until the user's first save-as).
+ */
+ template?: boolean
slides: Slide[]
modified: string
}
@@ -525,6 +533,12 @@ export function parseDoc(json: string): BentoDoc | null {
// Documents from before docId existed get one minted here; it persists
// on the next save and stays stable from then on.
if (typeof doc.docId !== 'string' || !doc.docId) doc.docId = newDocId()
+ if (doc.template) {
+ // template instantiation: this open IS a new document
+ delete doc.template
+ doc.docId = newDocId()
+ delete doc.collab
+ }
return doc as BentoDoc
}
} catch {
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 4019a161..e65f51e3 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -1086,3 +1086,31 @@ body.ed-col-resizing { cursor: col-resize; user-select: none; }
background: #34a866;
}
.ed-btn-connecting::after { background: #d9a13b; }
+
+/* about rows wrap instead of overflowing the dialog */
+.ed-about-row {
+ flex-wrap: wrap;
+}
+.ed-about-row .ed-btn {
+ max-width: 100%;
+ white-space: normal;
+ text-align: left;
+}
+
+/* collaborate popover: your-name field */
+.ed-share-name {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: var(--muted, #5d6b80);
+}
+.ed-share-name input {
+ flex: 1;
+ min-width: 0;
+ padding: 5px 8px;
+ border: 1px solid var(--line, #d5dbe4);
+ border-radius: 6px;
+ font: inherit;
+ font-size: 12.5px;
+}
diff --git a/slides/src/sync/online.ts b/slides/src/sync/online.ts
index b6934f20..cf496b98 100644
--- a/slides/src/sync/online.ts
+++ b/slides/src/sync/online.ts
@@ -12,6 +12,7 @@ import type { Store } from '../store'
import type { BentoDoc } from '../model'
import type { SyncStateJSON } from './crdt'
import type { Frame, SyncSession, Transport } from './session'
+import { offlineEnabled } from '../update'
export const DEFAULT_SYNC_HOST = 'wss://sync.bento.page'
const SNAP_EVERY = 200 // ops between encrypted snapshot uploads
@@ -290,6 +291,7 @@ export function sharingOn(store: Store): boolean {
/** connect the session to the relay in doc.collab (no-op unless sharing is on) */
export function joinFromDoc(session: SyncSession, store: Store): OnlineTransport | null {
+ if (offlineEnabled()) return null // the hard no-network switch wins over everything
if (active) return active
if (!sharingOn(store)) return null
session.addTransport((docId, onFrame) => {
@@ -314,13 +316,26 @@ export function joinFromDoc(session: SyncSession, store: Store): OnlineTransport
/** flip sharing on and connect — the "Start live session" action.
* Credentials already exist (minted at creation); this only arms them. */
-export function startSharing(session: SyncSession, store: Store): OnlineTransport {
+export function startSharing(session: SyncSession, store: Store): OnlineTransport | null {
+ if (offlineEnabled()) return null
if (active) return active
store.commit(() => {
if (!store.doc.collab) store.doc.collab = mintCollab()
store.doc.collab.on = true
})
- return joinFromDoc(session, store)!
+ return joinFromDoc(session, store)
+}
+
+/**
+ * Offline-mode disconnect: drop the relay WITHOUT touching doc.collab.on —
+ * the document's sharing intent is unchanged; this viewer just won't
+ * network. Turning offline mode off re-joins via the normal path.
+ */
+export function disconnectOnline(session: SyncSession) {
+ if (active) {
+ session.removeTransport(active)
+ active = null
+ }
}
/** flip sharing off and disconnect. Credentials stay — copies saved during
diff --git a/slides/src/update.ts b/slides/src/update.ts
index b574804e..24642c29 100644
--- a/slides/src/update.ts
+++ b/slides/src/update.ts
@@ -29,6 +29,28 @@ declare const __APP_VERSION__: string
export const APP_VERSION: string = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0'
/** Per-browser preference: check for updates automatically at launch. */
+/**
+ * Offline mode: a hard, viewer-side switch that blocks EVERY network touch —
+ * update checks and online collaboration alike. Same-machine tab sync
+ * (BroadcastChannel) is not networking and stays on. The guarantee this
+ * buys: with the switch on, nothing about you or a document ever leaves
+ * this computer.
+ */
+export const offlineEnabled = (): boolean => {
+ try {
+ return localStorage.getItem('bento-offline') === 'on'
+ } catch {
+ return false
+ }
+}
+export const setOffline = (on: boolean): void => {
+ try {
+ localStorage.setItem('bento-offline', on ? 'on' : 'off')
+ } catch {
+ /* storage unavailable */
+ }
+}
+
export const autoCheckEnabled = (): boolean => localStorage.getItem('bento-auto-check') !== 'off'
export const setAutoCheck = (on: boolean): void => {
if (on) localStorage.removeItem('bento-auto-check')