Skip to content

fix(readonly): show read-only state in the editor toolbar - #299

Merged
chaxus merged 3 commits into
mainfrom
fix/readonly-toolbar-state
Nov 2, 2026
Merged

chaxus merged 3 commits into
mainfrom
fix/readonly-toolbar-state

Conversation

@chaxus

@chaxus chaxus commented Nov 2, 2026

Copy link
Copy Markdown
Member

Fixes #298.

Problem

Read-only (?readonly=1, embed readonly: true, document:set-readonly) blocked edits through asc_setRestriction(128), but no vendor web-app listens for asc_onChangeRestrictions. The toolbar, right panel and context menu stayed visually enabled while doing nothing.

The processRightsChange fallback in lib/onlyoffice/readonly.ts never reached the editor (serviceCommand wraps it in internalCommand). Had it arrived, the vendor would have handled it with asc_coAuthoringDisconnect(), which cannot be undone.

Change

  • Keep the edit-mode mount and the reversible restriction. In addition, trigger the vendor's own stacked editing:disable event under a readonly type: push it on lock, pop it on unlock. This is the same mechanism the vendor uses for signature, forms and disconnect, and it re-applies whatever is left on the stack.
  • Locked: toolbar, right panel, context menu, review, and the header edit-mode switch. Comments and the cell editor switch to preview mode.
  • Left usable: left-menu search and navigation, header search, status bar (zoom, sheet tabs), keyboard shortcuts.
  • viewMode follows the flag. DisableToolbar stores it as editMode, so an unlock that kept it true would leave the mask on.
  • onDocumentReady now calls setReadonlyMode(true), so the restriction and the UI lock are applied together.
  • Removed the dead fallback and editorSendCommand (scoped rg: zero references), plus the two unit tests that pinned it.

Trade-off: the vendor masks the whole toolbar, so the PDF editor's toolbar paging and zoom are covered too. The status bar keeps zoom, fit and paging.

Verification

  • New test/e2e/readonly-chrome.spec.ts covers docx, xlsx, pptx and pdf: open read-only → mask present, search and zoom-in usable → unlock → mask gone → relock → mask back.
  • Reverse validation: with syncReadonlyChrome(readonly) commented out, all 4 fail (masked: false). With it restored, all 4 pass.
  • The existing readonly cases (format-parity, embed-regression, pdf-roundtrip) plus the new spec pass: 13/13 against local vite dev.
  • vendor-contract.test.ts now pins editing:disable, stackDisableActions, and DisableToolbar storing viewMode as editMode in all four apps.
  • Unit tests, tsc, oxlint and prettier pass on the changed files.

Record: docs/explorations/2026-11-02-readonly-toolbar-state.md

🤖 Generated with Claude Code

chaxus and others added 3 commits November 2, 2026 10:24
asc_setRestriction blocks edits in the SDK only; no web-app listens for
asc_onChangeRestrictions, so readonly documents kept a toolbar that looked
live and did nothing (#298). Push the vendor's own stacked editing:disable
request under a 'readonly' type when locking and pop it when unlocking,
leaving search, navigation, zoom and the status bar usable.

Drop the processRightsChange fallback: serviceCommand wrapped it in
internalCommand so it never reached the editor, and the vendor handles it by
disconnecting, which cannot be undone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…disable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying document with  Cloudflare Pages  Cloudflare Pages

Latest commit: cfc70ff
Status: ✅  Deploy successful!
Preview URL: https://ddbd529b.document-7hm.pages.dev
Branch Preview URL: https://fix-readonly-toolbar-state.document-7hm.pages.dev

View logs

@chaxus
chaxus enabled auto-merge (rebase) November 2, 2026 02:30
@chaxus
chaxus merged commit 6104b91 into main Nov 2, 2026
19 checks passed
@chaxus
chaxus deleted the fix/readonly-toolbar-state branch November 2, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read-only mode leaves editing controls visually enabled

1 participant