Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add access to editor in schema data validator #2542

Closed
klis87 opened this issue Jan 17, 2019 · 2 comments
Closed

Add access to editor in schema data validator #2542

klis87 opened this issue Jan 17, 2019 · 2 comments
Labels

Comments

@klis87
Copy link
Contributor

klis87 commented Jan 17, 2019

Do you want to request a feature or report a bug?

Feature

What's the current behavior?

Currently you can define many schema rules. I am interested in data specifically:

const schema = {
  blocks: {
    image: {
      isVoid: true,
      data: {
        src: v => v && isUrl(v),
      },
    },
  },
}

I have a use case that I need to validate a node data based on editor.value.document.data, which I use to keep some global editor state. Unfortunately in data callback in schema rules we dont have access to it.

What's the expected behavior?

If we could add editor passed as 2nd argument to data callback, I could read current editor.value.document.data and normalize this node with schema normalize. Now I guess I will need to resort to lower level normalizeNode with worse performance.

Apologies for potential duplicate #1960 , I guess the answer will be the same, but maybe we could think of a global editor/document data which wouldn't break memoization?

@klis87
Copy link
Contributor Author

klis87 commented Jan 17, 2019

EDIT: normalizeNode also won't work unfortunately, because normalizeNode for given nodes isn't called when document.data is updated.

I had a similar problem in renderNode, which I solved by using react context. For this issue though context won't help.

@ianstormtaylor
Copy link
Owner

Hey @klis87, I understand your need, but like you said I've already addressed this in #1960. In the current architecture for how normalizing works this isn't really possible.

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

No branches or pull requests

2 participants