Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Read-only viewer + presentation-package rename (UI)

nyblnet83d21ee0bcec
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.ts
index b50b3b05..ee10480e 100644
--- a/slides/src/editor/canvas.ts
+++ b/slides/src/editor/canvas.ts
@@ -806,6 +806,7 @@ export class SlideCanvas {
// --- text editing -----------------------------------------------------------
startTextEdit(node: HTMLElement) {
+ if (this.store.readOnly) return // live viewer — no inline editing
if (this.editing === node) return
this.commitTextEdit()
const inner = node.querySelector<HTMLElement>('.bento-text-inner')
@@ -902,6 +903,7 @@ export class SlideCanvas {
/** Commit any current edit, then edit cell (r,c) of table `id`. */
private editCellAt(id: string, r: number, c: number) {
+ if (this.store.readOnly) return // live viewer — no inline editing
this.commitTextEdit()
const td = this.surface?.querySelector<HTMLElement>(
`[data-el-id="${CSS.escape(id)}"] td[data-r="${r}"][data-c="${c}"]`)
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 0dd60934..ca920676 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -187,7 +187,7 @@ export class Editor {
this.dirtyDot = div('ed-dirty')
this.dirtyDot.title = t('Unsaved changes')
- const insert = div('ed-group')
+ const insert = div('ed-group ed-insert')
insert.append(
btn(ICONS.text, t('Text'), () => this.canvas.insert(defaultText({ y: 120 + Math.random() * 200 }), true),
t('Add a text box — double-click it to edit; **bold**, *italic*, `code` and “- ” bullets format as you type')),
@@ -276,6 +276,18 @@ export class Editor {
this.canvas = new SlideCanvas(canvasWrap, this.store)
this.canvas.onCommentModeChange = (on) => commentB.classList.toggle('ed-btn-armed', on)
this.panel = new PropsPanel(this.props, this.store)
+
+ if (this.store.doc.collab?.role === 'reader') this.enterReaderMode()
+ }
+
+ /** Live viewer: block user edits (store.readOnly), hide editing chrome, and
+ * show a banner. Remote ops still apply — the deck updates as others edit. */
+ private enterReaderMode() {
+ this.store.readOnly = true
+ document.body.classList.add('ed-reader')
+ const banner = div('ed-reader-banner')
+ banner.innerHTML = `<span class="ed-reader-dot"></span>${t('Read-only — viewing this live session. You can watch and present, but not edit.')}`
+ document.body.appendChild(banner)
}
// --- resizable side panels ------------------------------------------------
@@ -408,9 +420,14 @@ export class Editor {
item(t('Save as template…'),
t('Saves a template copy: everyone who opens it gets a fresh, independent deck with its own identity and keys.'),
() => void this.saveAsTemplate())
- item(t('Save read-only copy…'),
- t('A locked hand-out: it opens straight into the show — viewing and presenting only, no editor, no live session.'),
- () => void this.saveReadonlyCopy())
+ item(t('Save as presentation package…'),
+ t('A sealed hand-out: it opens straight into the show — viewing and presenting only, no editor, no live session.'),
+ () => void this.savePresentationPackage())
+ if (sharingOn(this.store)) {
+ item(t('Save read-only copy…'),
+ t('A live viewer: it follows this shared session and shows edits as they happen, but can never change the deck (the relay enforces it — read-only is not just honour-system).'),
+ () => void this.saveReaderCopy())
+ }
if (isEncryptionActive()) {
item(t('Change password…'),
t('Pick a new password for this file — takes effect on the next save.'),
@@ -435,14 +452,34 @@ export class Editor {
return wrap
}
- /** Save a locked hand-out copy: player file, no editor, no live session. */
- private async saveReadonlyCopy() {
+ /** A sealed hand-out: present-only player file, no editor, no live session. */
+ private async savePresentationPackage() {
const clone = JSON.parse(JSON.stringify(this.store.doc)) as import('../model').BentoDoc
clone.readonly = true
- delete clone.collab // a hand-out must not join (or leak) the live room
+ delete clone.collab // a sealed package must not join (or leak) the live room
+ try {
+ const ok = await writeUpdatedFileAs(await serializeAuto(clone), clone)
+ if (ok) this.toast(t('Presentation package saved — it opens straight into the show'))
+ } catch {
+ this.toast(t('Saving failed'))
+ }
+ }
+
+ /** A live viewer: follows the shared session read-only. Keeps the room + read
+ * key + writer PUBKEY (so the relay knows the room's writer) but drops the
+ * writer PRIVATE key — the relay then rejects any op it tries to send. */
+ private async saveReaderCopy() {
+ const c = this.store.doc.collab
+ if (!c?.room || !c.key) {
+ this.toast(t('Turn on live sharing first — a read-only copy follows the session'))
+ return
+ }
+ const clone = JSON.parse(JSON.stringify(this.store.doc)) as import('../model').BentoDoc
+ clone.collab = { ...c, role: 'reader', on: true, sync: undefined }
+ delete clone.collab.writerPriv // the muzzle — no write capability travels
try {
const ok = await writeUpdatedFileAs(await serializeAuto(clone), clone)
- if (ok) this.toast(t('Read-only copy saved — it opens straight into the show'))
+ if (ok) this.toast(t('Read-only copy saved — it follows the live session, view only'))
} catch {
this.toast(t('Saving failed'))
}
diff --git a/slides/src/main.ts b/slides/src/main.ts
index c2a9a653..e8989f4b 100644
--- a/slides/src/main.ts
+++ b/slides/src/main.ts
@@ -89,7 +89,7 @@ function playerMode(doc: BentoDoc) {
card.className = 'ed-player'
card.innerHTML =
`<div class="ed-playercard"><h1>${doc.title.replace(/</g, '&lt;')}</h1>` +
- `<p>${t('This deck is read-only.')}</p>` +
+ `<p>${t('This is a presentation package — view and present only.')}</p>` +
`<button class="ed-playgo">▶&nbsp; ${t('Present')}</button>` +
`<button class="ed-playcopy">⤓&nbsp; ${t('Save a copy')}</button></div>`
document.body.appendChild(card)
diff --git a/slides/src/store.ts b/slides/src/store.ts
index b4063fc0..e0eb396d 100644
--- a/slides/src/store.ts
+++ b/slides/src/store.ts
@@ -24,6 +24,11 @@ export class Store {
private redoStack: string[] = []
private listeners = new Map<StoreEvent, Set<Listener>>()
+ /** read-only viewer: block user edits (commit) while remote ops — which
+ * apply via the session's direct state.apply + emit, NOT commit — still
+ * flow, so a live viewer sees updates but can never author them. */
+ readOnly = false
+
constructor(doc: BentoDoc) {
this.doc = doc
}
@@ -79,6 +84,7 @@ export class Store {
/** checkpoint() + mutate + notify, in one call. */
commit(mutate: () => void, event: StoreEvent = 'doc') {
+ if (this.readOnly) return // live viewer — user edits are inert
this.checkpoint()
mutate()
this.touch(event)
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 8d356407..619d9b95 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -635,6 +635,25 @@ html, body {
.ed-help-more a { color: var(--accent, #ED8266); font-weight: 600; font-size: 13px; text-decoration: none; }
.ed-help-more a:hover { text-decoration: underline; }
+/* --- live viewer (read-only collaborator) -------------------------------- */
+.ed-reader .ed-insert { display: none; } /* no add-content tools */
+.ed-reader .moveable-control-box { display: none !important; } /* no resize/move handles */
+.ed-reader-banner {
+ position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60;
+ background: rgba(13,27,46,0.92); color: #fff; padding: 9px 18px; border-radius: 999px;
+ font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 9px;
+ box-shadow: 0 8px 26px rgba(0,0,0,0.32); backdrop-filter: blur(6px);
+}
+.ed-reader-dot {
+ width: 8px; height: 8px; border-radius: 50%; background: #FF9E8A; flex: none;
+ animation: ed-reader-pulse 2s infinite;
+}
+@keyframes ed-reader-pulse {
+ 0% { box-shadow: 0 0 0 0 rgba(255,158,138,0.5); }
+ 70% { box-shadow: 0 0 0 7px rgba(255,158,138,0); }
+ 100% { box-shadow: 0 0 0 0 rgba(255,158,138,0); }
+}
+
/* --- auto-save: recovery banner, saved tag, version history --------------- */
.ed-recover {
position: fixed;