Skip to content

refactor: zod poc #1724

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

refactor: zod poc #1724

wants to merge 4 commits into from

Conversation

YousefED
Copy link
Collaborator

@YousefED YousefED commented May 29, 2025

This is a POC to use Zod instead of our custom schema language for block and inline content props. Let's discuss if this is a direction we want to take. If so, we should:

  • add tests for more complex schemas than we currently support
  • use the same pattern for styles?
  • fix the other packages / examples. Atm at least all tests in core and tests pass!
  • validate input / output types are still the same. E.g.: can a heading only take the configured levels. And does the output type of a document with a heading always have the level prop?
  • (optional) create a backwards compatible API for custom blocks (we could translate the old schema passed to createReactBlockSpec to a Zod schema
  • check compatibility with yjs

thanks @aeplay for mentioning this in your talk 😂

closes #444

Copy link

vercel bot commented May 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ❌ Failed (Inspect) Jun 9, 2025 8:52am
blocknote-website ❌ Failed (Inspect) Jun 9, 2025 8:52am

})
.extend({
// File name.
name: z.string().default(""),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we want to do meta descriptions: https://zod.dev/metadata#meta

@@ -10,15 +10,15 @@ export const BackgroundColorExtension = Extension.create({
types: ["blockContainer", "tableCell", "tableHeader"],
attributes: {
backgroundColor: {
default: defaultProps.backgroundColor.default,
default: defaultProps.shape.backgroundColor._zod.def.defaultValue,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like reaching into what feels like an internal value for this, is there another way of doing it that is part of the public API?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Props complexity for custom blocks
2 participants