mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-01-19 06:18:16 +01:00
ded82812b0
#### Is this adding or improving a _feature_ or fixing a _bug_? Improvement. #### What's the new behavior? - Tweaking the declarative schema definition syntax to make it easier to represent more complex states, as well as enable it to validate previously impossible things. - Rename `validateNode` to `normalizeNode` for clarity. - Introduce `validateNode`, `checkNode`, `assertNode` helpers for more advanced use cases, like front-end API validation of "invalid" fields that need to be fixed before they are sent to the server. #### How does this change work? The `schema.blocks/inlines/document` entries are now a shorthand for a more powerful `schema.rules` syntax. For example, this now allows for declaratively validating by a node's data, regardless of type: ```js { rules: [ { match: { data: { id: '2kd293lry' }, }, nodes: [ { match: { type: 'paragraph' }}, { match: { type: 'image' }}, ] } ] } ``` Previously you'd have to use `validateNode` for this, since the syntax wasn't flexible enough to validate nodes without hard-coding their `type`. This also simplifies the "concatenation" of schema rules, because under the covers all of them are implemented using the `schema.rules` array, so they simply take effect in order, just like everything else in plugins. #### Have you checked that...? <!-- Please run through this checklist for your pull request: --> * [x] The new code matches the existing patterns and styles. * [x] The tests pass with `yarn test`. * [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.) * [x] The relevant examples still work. (Run examples with `yarn watch`.) #### Does this fix any issues or need any specific reviewers? Fixes: #1842 Fixes: #1923
2 lines
5 B
Plaintext
2 lines
5 B
Plaintext
*.md
|