Emit error on invalid content
Please describe your changes
Adds an optional onError callback event and aborts rendering if the throwOnError Editor option is set to true.
How did you accomplish your changes
By adding an additional boolean to the EditorOptions and an error handler callback, we can toggle on emitting errors instead of silently handling them and not rendering any content.
This let's you set a an onError callback that gets called when invalid content is passed into the constructor or the setContent rawCommand.
How have you tested your changes
I've added emitError.spec.ts test file which checks that the onError event handler is not called when the throwOnError flag is false (the default behavior) and does get called only when invalid content is passed in.
How can we verify your changes
By creating an invalid json as the content and leaving the flag off, it will silently render nothing.
Then set throwOnError: true and set the onError callback and it will be triggered with the error.
Remarks
CC: @janthurau
Checklist
- [x] The changes are not breaking the editor
- [x] Added tests where possible
- [x] Followed the guidelines
- [x] Fixed linting issues
Related issues
Deploy Preview for tiptap-embed ready!
| Name | Link |
|---|---|
| Latest commit | 67bf2ac1db52179d8c7920c0d5775f37b3a7b3d2 |
| Latest deploy log | https://app.netlify.com/sites/tiptap-embed/deploys/663cdbc03496dc000874b2f3 |
| Deploy Preview | https://deploy-preview-4641--tiptap-embed.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Hi @Krakaw, really appreciate your contribution here, we've gone ahead and merged some thing that achieves the same sort of thing. Thank you for your PR, it was a good basis to start the conversation
See the merge here: https://github.com/ueberdosis/tiptap/pull/5178