-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support validate
options in node and mark attribute definitions.
#5991
base: next
Are you sure you want to change the base?
Support validate
options in node and mark attribute definitions.
#5991
Conversation
…initions. ProseMirror allows node and mark specs to define a `validate` function or type, which is used when deserializing JSON, parsing from the DOM, etc. See https://prosemirror.net/docs/ref/#model.AttributeSpec.validate Currently, `default` is the only attribute spec option passed through to ProseMirror when resolving the schema. This change updates `getAttributesFromExtensions` and `getSchemaByResolvedExtensions` (and relevant types) to also pass through any defined `validate` attribute option. To use this, add a `validate` type or function option in any extension's `addAttributes` or `addGlobalAttributes` definition, e.g.: ``` export const NodeId = Extension.create({ name: 'nodeId', addGlobalAttributes() { return [ { types: [...], attributes: { nodeId: { default: '__node_id__', validate: 'string', ... } } } ] } }); ``` A more complex validation could ensure that the ID is shaped like a UUID, or allow it to be `null` or `undefined`.
🦋 Changeset detectedLatest commit: f172ddb The changes in this PR will be included in the next version bump. This PR includes changesets to release 57 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fantastic PR, I'm going to merge this to be part of the next branch, as we are in a sort of feature freeze for Titpap v2
Changes Overview
ProseMirror allows node and mark specs to define a
validate
function or type, which is used when deserializing JSON, parsing from the DOM, etc.See https://prosemirror.net/docs/ref/#model.AttributeSpec.validate
Implementation Approach
Currently,
default
is the only attribute spec option passed through to ProseMirror when resolving the schema. This change updatesgetAttributesFromExtensions
andgetSchemaByResolvedExtensions
(and relevant types) to also pass through any definedvalidate
attribute option.Testing Done
Manual testing (plus using the patch in production!)
Verification Steps
To use this, add a
validate
type or function option in any extension'saddAttributes
oraddGlobalAttributes
definition, e.g.:A more complex validation could ensure that the ID is shaped like a UUID, or allow it to be
null
orundefined
.Additional Notes
Checklist
Related Issues