Skip to content

Add shared docs toolbar and read-only mode#84

Merged
hackerwins merged 1 commit into
mainfrom
fix/shared-docs-toolbar-and-readonly
Mar 26, 2026
Merged

Add shared docs toolbar and read-only mode#84
hackerwins merged 1 commit into
mainfrom
fix/shared-docs-toolbar-and-readonly

Conversation

@hackerwins

@hackerwins hackerwins commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add formatting toolbar to shared docs for editor-role users (was completely missing)
  • Implement read-only mode for viewer-role users in the docs editor:
    • No cursor focus or text input (TextEditor not created)
    • No ruler drag interactions (mouse handlers skipped)
    • Canvas cursor shows default instead of text

Test plan

  • Open a shared doc link with editor role → toolbar should appear and be functional
  • Open a shared doc link with viewer role → no toolbar, no cursor, no ruler dragging
  • Verify authenticated docs editor (/d/:id) still works normally

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added read-only editor mode support. Editors now adapt their behavior based on user permissions, disabling editing interactions and the formatting toolbar for viewers while maintaining full functionality for authorized users.

Shared docs were missing the formatting toolbar entirely. This adds
the toolbar for editor-role users and implements read-only mode for
viewer-role users:

- Skip TextEditor creation in read-only mode (no cursor, no input)
- Skip Ruler mouse handlers in read-only mode (no margin/indent drag)
- Show formatting toolbar in shared docs for non-read-only users
- Change canvas cursor from text to default in read-only mode

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request adds read-only mode support to the document editor. The initialize() function now accepts a readOnly parameter that disables text editing, adjusts cursor styles, skips TextEditor instantiation, and prevents mouse event registration in the ruler. The SharedDocsLayout component wires this capability by managing editor state and conditionally rendering the formatting toolbar based on share role.

Changes

Cohort / File(s) Summary
Editor Read-Only Implementation
packages/docs/src/view/editor.ts, packages/docs/src/view/ruler.ts
Added optional readOnly?: boolean parameter to initialize() and Ruler constructor. When read-only mode is active: cursor style changes from 'text' to 'default', TextEditor is set to null, mouse event handlers in Ruler are not registered, and cursor blink is skipped. All TextEditor interactions use optional chaining for safe access.
Frontend Integration
packages/frontend/src/app/docs/docs-view.tsx, packages/frontend/src/app/shared/shared-document.tsx
Added optional readOnly?: boolean prop to DocsViewProps and updated DocsView to forward it to editor initialization. SharedDocsLayout now manages editor state and conditionally renders DocsFormattingToolbar based on share role (hidden for viewers), resolving a previous TODO regarding editor readiness plumbing.

Sequence Diagram

sequenceDiagram
    participant User
    participant SharedDocsLayout
    participant DocsView
    participant Editor as Editor.initialize()
    participant Ruler

    User->>SharedDocsLayout: Render with share role
    activate SharedDocsLayout
    Note over SharedDocsLayout: Determine readOnly<br/>based on share role
    
    SharedDocsLayout->>DocsView: Pass readOnly prop
    activate DocsView
    
    DocsView->>Editor: initialize(container, store, theme, readOnly)
    activate Editor
    
    alt readOnly = true
        Editor->>Editor: Set cursor to 'default'<br/>Set textEditor = null<br/>Set focused = false
        Editor->>Ruler: new Ruler(container, canvas, true)
        activate Ruler
        Note over Ruler: Skip mouse event<br/>handler registration
        deactivate Ruler
        Note over Editor: Skip TextEditor<br/>creation & wiring
    else readOnly = false
        Editor->>Editor: Set cursor to 'text'<br/>Create TextEditor
        Editor->>Ruler: new Ruler(container, canvas, false)
        activate Ruler
        Note over Ruler: Register mouse<br/>event handlers
        deactivate Ruler
        Note over Editor: Wire focus/blur<br/>Start cursor blink
    end
    
    Editor-->>DocsView: Return EditorAPI
    deactivate Editor
    
    DocsView-->>SharedDocsLayout: Emit onEditorReady
    deactivate DocsView
    
    SharedDocsLayout->>SharedDocsLayout: Store editor instance
    
    alt Share role ≠ viewer
        SharedDocsLayout->>DocsFormattingToolbar: Render with editor
        activate DocsFormattingToolbar
        deactivate DocsFormattingToolbar
    else Share role = viewer
        Note over SharedDocsLayout: DocsFormattingToolbar<br/>not rendered
    end
    
    deactivate SharedDocsLayout
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A canvas transformed with a read-only grace,
Where viewers gaze but cannot retrace,
The toolbar hides when roles demand to view,
As cursors shift from pencil's dance to still—
Read-only rabbits hop through safer halls! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding a shared docs toolbar and implementing read-only mode support across the editor components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/shared-docs-toolbar-and-readonly

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 105.8s

Lane Status Duration
sheets:build ✅ pass 13.7s
docs:build ✅ pass 5.6s
verify:fast ✅ pass 48.9s
frontend:build ✅ pass 14.8s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.3s
cli:build ✅ pass 1.8s
verify:entropy ✅ pass 16.3s

Verification: verify:integration

Result: ✅ PASS

@hackerwins
hackerwins merged commit a9356f8 into main Mar 26, 2026
3 checks passed
@hackerwins
hackerwins deleted the fix/shared-docs-toolbar-and-readonly branch March 26, 2026 13:07
hackerwins added a commit that referenced this pull request Mar 27, 2026
Remove unused lineX parameter from renderListMarker, remove unused
imports, and add missing textIndent/marginLeft fields to BlockStyle
test fixtures.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
hackerwins pushed a commit that referenced this pull request Mar 27, 2026
Replace pattern-tiling with Google Sheets-style OLS (Ordinary Least
Squares) regression for numeric cell autofill. When 2+ numeric cells
exist along the fill axis, compute y = mx + b and extrapolate the
trend. Mixed content (formulas, text, empty) falls back to existing
tiling behavior.

Use single-fraction computation with toPrecision(15) to minimize
IEEE 754 floating-point drift, matching Excel/Google Sheets precision.

Also fix docs package build and frontend test failures introduced by
PR #83/#84: refactor TypeScript parameter properties and const enum
unsupported by Node's --experimental-strip-types, remove unused
parameters/imports, and add missing BlockStyle fields in test fixtures.

Co-authored-by: Claude Opus 4.6 <[email protected]>
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.

1 participant