Skip to content

feat: Read-only example#2612

Open
matthewlipski wants to merge 1 commit intomainfrom
read-only-example
Open

feat: Read-only example#2612
matthewlipski wants to merge 1 commit intomainfrom
read-only-example

Conversation

@matthewlipski
Copy link
Copy Markdown
Collaborator

@matthewlipski matthewlipski commented Mar 31, 2026

Summary

This PR adds a basic read-only editor example to make testing easier.

Rationale

See above.

Changes

See above.

Impact

N/A

Testing

N/A

Screenshots/Video

N/A

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

Additional Notes

Summary by CodeRabbit

  • New Features

    • Added a new "Read-only Editor" example demonstrating how to configure a BlockNote editor in read-only mode while displaying all content types.
  • Documentation

    • Added documentation for the read-only editor example with links to editor setup and schema reference guides.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Mar 31, 2026 4:29pm
blocknote-website Ready Ready Preview Mar 31, 2026 4:29pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

A new read-only editor example has been added to the examples directory with complete project setup including configuration files, React component, and documentation. The playground registry was updated to include this new example and adjusted a path reference for the shadowdom example.

Changes

Cohort / File(s) Summary
Example Configuration & Build Setup
examples/01-basic/16-read-only-editor/.bnexample.json, examples/01-basic/16-read-only-editor/tsconfig.json, examples/01-basic/16-read-only-editor/vite.config.ts, examples/01-basic/16-read-only-editor/package.json
Added TypeScript and Vite configuration, package metadata, and build tool setup for the new read-only editor example with appropriate dependencies and build scripts.
Project Entry & Structure
examples/01-basic/16-read-only-editor/index.html, examples/01-basic/16-read-only-editor/main.tsx
Added HTML entry point and React root initialization that mounts the App component into the DOM.
Application Logic
examples/01-basic/16-read-only-editor/src/App.tsx
Implemented read-only editor component using BlockNote's useCreateBlockNote hook with comprehensive initial content demonstrating various block types (headings, quotes, lists, code blocks, tables, media) and editable={false} to enforce read-only mode.
Documentation
examples/01-basic/16-read-only-editor/README.md
Added documentation describing the read-only editor example purpose and included references to relevant BlockNote documentation.
Playground Registry
playground/src/examples.gen.tsx
Updated example registry to include the new read-only editor example and corrected the path reference for the shadowdom example from 15-shadowdom to 15-shadowdom.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A cozy editor, locked up tight and fair,
Read-only magic floating in the air,
No typing here, just viewing with delight,
BlockNote shines when content takes flight!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description uses the required template structure but many sections contain minimal or placeholder content ('See above', 'N/A'), and critical change details are deferred rather than properly documented. Provide detailed information in the Changes section listing the new files created, explain specific testing performed, and justify the checklist claims with concrete evidence.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a read-only editor example to the codebase.

✏️ 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 read-only-example

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@examples/01-basic/16-read-only-editor/index.html`:
- Line 1: Add the HTML5 DOCTYPE declaration before the existing <html> tag in
the document by inserting <!DOCTYPE html> at the very top of the file so the
page validates with HTMLHint and browsers render in standards mode; ensure the
DOCTYPE appears immediately above the existing <html lang="en"> element.
- Around line 6-8: Replace the invalid HTML comment inside the <script> block in
the file by removing the <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> or
converting it to a valid JavaScript comment; locate the <script> tag in
examples/01-basic/16-read-only-editor/index.html and either delete the commented
line entirely or change it to a JS comment using // or /* */ so the script
contains only valid JavaScript.

In `@examples/01-basic/16-read-only-editor/vite.config.ts`:
- Around line 22-29: The alias mappings for "@blocknote/core" and
"@blocknote/react" in vite.config.ts point to "../../packages/..." but are one
level too shallow; update the path.resolve calls used in the alias object (the
entries for "@blocknote/core" and "@blocknote/react") to use
"../../../packages/..." so they correctly resolve from
examples/01-basic/16-read-only-editor to the repository root.
- Line 17: The path check using fs.existsSync(path.resolve(__dirname,
"../../packages/core/src")) is using the wrong relative depth; update the string
"../../packages/core/src" to "../../../packages/core/src" so it correctly
resolves from examples/01-basic/16-read-only-editor to the repo root packages
directory (i.e., change the path literal used in the fs.existsSync/path.resolve
call in vite.config.ts).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a9791640-7ad8-494c-9557-ee50b161520a

📥 Commits

Reviewing files that changed from the base of the PR and between a850078 and a9e8db6.

📒 Files selected for processing (18)
  • examples/01-basic/15-shadowdom/.bnexample.json
  • examples/01-basic/15-shadowdom/README.md
  • examples/01-basic/15-shadowdom/index.html
  • examples/01-basic/15-shadowdom/main.tsx
  • examples/01-basic/15-shadowdom/package.json
  • examples/01-basic/15-shadowdom/src/App.tsx
  • examples/01-basic/15-shadowdom/src/vite-env.d.ts
  • examples/01-basic/15-shadowdom/tsconfig.json
  • examples/01-basic/15-shadowdom/vite.config.ts
  • examples/01-basic/16-read-only-editor/.bnexample.json
  • examples/01-basic/16-read-only-editor/README.md
  • examples/01-basic/16-read-only-editor/index.html
  • examples/01-basic/16-read-only-editor/main.tsx
  • examples/01-basic/16-read-only-editor/package.json
  • examples/01-basic/16-read-only-editor/src/App.tsx
  • examples/01-basic/16-read-only-editor/tsconfig.json
  • examples/01-basic/16-read-only-editor/vite.config.ts
  • playground/src/examples.gen.tsx

@@ -0,0 +1,14 @@
<html lang="en">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing DOCTYPE declaration.

The HTML5 DOCTYPE declaration should be present before the <html> tag. This is flagged by HTMLHint.

Proposed fix
+<!DOCTYPE html>
 <html lang="en">
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<html lang="en">
<!DOCTYPE html>
<html lang="en">
🧰 Tools
🪛 HTMLHint (1.9.2)

[error] 1-1: Doctype must be declared before any non-comment content.

(doctype-first)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/01-basic/16-read-only-editor/index.html` at line 1, Add the HTML5
DOCTYPE declaration before the existing <html> tag in the document by inserting
<!DOCTYPE html> at the very top of the file so the page validates with HTMLHint
and browsers render in standards mode; ensure the DOCTYPE appears immediately
above the existing <html lang="en"> element.

Comment on lines +6 to +8
<script>
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
</script>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Invalid HTML comment syntax inside script tag.

HTML comments (<!-- -->) are not valid inside <script> tags. Use JavaScript comments instead, or remove this entirely since it's informational.

Proposed fix
     <script>
-      <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
+      // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
     </script>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<script>
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
</script>
<script>
// AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY
</script>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/01-basic/16-read-only-editor/index.html` around lines 6 - 8, Replace
the invalid HTML comment inside the <script> block in the file by removing the
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> or converting it to a valid
JavaScript comment; locate the <script> tag in
examples/01-basic/16-read-only-editor/index.html and either delete the commented
line entirely or change it to a JS comment using // or /* */ so the script
contains only valid JavaScript.

resolve: {
alias:
conf.command === "build" ||
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the correct relative path from the example directory to packages/core/src

# Check current structure
echo "=== Directory structure ==="
tree -L 3 -d examples/01-basic/16-read-only-editor 2>/dev/null || find examples/01-basic/16-read-only-editor -type d 2>/dev/null

# Verify packages/core/src exists at root level
echo ""
echo "=== Checking packages/core/src from root ==="
ls -la packages/core/src 2>/dev/null && echo "packages/core/src exists at root" || echo "packages/core/src NOT found at root"

# Check what other examples use for the same path
echo ""
echo "=== Checking path patterns in other example vite configs ==="
rg -n "packages/core/src" examples/01-basic/*/vite.config.ts 2>/dev/null | head -10

Repository: TypeCellOS/BlockNote

Length of output: 2504


🏁 Script executed:

cat -n examples/01-basic/16-read-only-editor/vite.config.ts

Repository: TypeCellOS/BlockNote

Length of output: 1270


🏁 Script executed:

# Check if there are examples at different nesting levels
find examples -name "vite.config.ts" -type f | head -20

# Check if there's a template file
find . -name "*template*" -o -name "*vite.config*" | grep -v node_modules | grep -v dist | head -20

# Verify directory depth of each example
for dir in examples/*/; do
  echo "=== $dir ===" 
  echo "  Levels up to root: $(echo "$dir" | tr -cd '/' | wc -c)"
done

Repository: TypeCellOS/BlockNote

Length of output: 2638


🏁 Script executed:

# Check the path used in a 02-backend example
cat examples/02-backend/01-file-uploading/vite.config.ts | grep -A 2 "existsSync"

# Get the full path structure to understand __dirname resolution
echo "=== Directory nesting levels ==="
echo "01-basic example: examples/01-basic/01-minimal"
echo "  Levels: examples (1) -> 01-basic (2) -> 01-minimal (3)"
echo ""
echo "02-backend example: examples/02-backend/01-file-uploading"  
echo "  Levels: examples (1) -> 02-backend (2) -> 01-file-uploading (3)"
echo ""
echo "From examples/01-basic/16-read-only-editor/ with ../../packages/core/src:"
echo "  -> up 2 levels -> examples/ -> packages/core/src does NOT exist"
echo ""
echo "From examples/02-backend/01-file-uploading/ with ../../packages/core/src:"
echo "  -> up 2 levels -> examples/ -> packages/core/src does NOT exist"
echo ""
echo "BOTH should use ../../ equally, which means BOTH are wrong if packages/core/src is at ROOT"

Repository: TypeCellOS/BlockNote

Length of output: 798


Fix relative path in package existence check.

The path ../../packages/core/src from examples/01-basic/16-read-only-editor/ resolves to examples/packages/core/src, which doesn't exist. It must go up 3 levels to reach the repository root where packages/core/src is located.

Proposed fix
-      !fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
+      !fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
!fs.existsSync(path.resolve(__dirname, "../../packages/core/src"))
!fs.existsSync(path.resolve(__dirname, "../../../packages/core/src"))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/01-basic/16-read-only-editor/vite.config.ts` at line 17, The path
check using fs.existsSync(path.resolve(__dirname, "../../packages/core/src")) is
using the wrong relative depth; update the string "../../packages/core/src" to
"../../../packages/core/src" so it correctly resolves from
examples/01-basic/16-read-only-editor to the repo root packages directory (i.e.,
change the path literal used in the fs.existsSync/path.resolve call in
vite.config.ts).

Comment on lines +22 to +29
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Alias paths are also incorrect - need 3 levels up, not 2.

The alias paths use ../../packages/ but should use ../../../packages/ to correctly resolve from examples/01-basic/16-read-only-editor/ to the repository root.

Proposed fix
             "@blocknote/core": path.resolve(
               __dirname,
-              "../../packages/core/src/"
+              "../../../packages/core/src/"
             ),
             "@blocknote/react": path.resolve(
               __dirname,
-              "../../packages/react/src/"
+              "../../../packages/react/src/"
             ),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
),
"@blocknote/core": path.resolve(
__dirname,
"../../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../../packages/react/src/"
),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/01-basic/16-read-only-editor/vite.config.ts` around lines 22 - 29,
The alias mappings for "@blocknote/core" and "@blocknote/react" in
vite.config.ts point to "../../packages/..." but are one level too shallow;
update the path.resolve calls used in the alias object (the entries for
"@blocknote/core" and "@blocknote/react") to use "../../../packages/..." so they
correctly resolve from examples/01-basic/16-read-only-editor to the repository
root.

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.

2 participants