-
Notifications
You must be signed in to change notification settings - Fork 430
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
refactor(portable-text-editor): automatically resolve some validation errors #6705
Conversation
This was too damn messy and contained a bug where sometimes an annotation would not be added. Fixed the bug.
…efs to editor value We will normalize this automatically and update the value when needed. For this to work, the value must reflect the original value
…n the the schema Note: you need to actively edit the node before it's normalized
…n of marks and markdefs
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated May 21, 2024 12:36 PM (UTC)
|
… error Resolve errors for missing .markDefs, orphapned marks, empty children, missing child keys
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
packages/@sanity/portable-text-editor/src/editor/__tests__/pteWarningsSelfSolving.test.tsx
Show resolved
Hide resolved
...@sanity/portable-text-editor/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx
Show resolved
Hide resolved
Don't insert a empty array for missing span node .marks. It will be inserted through normalization inside withPortableTextMarkModel instead.
As .markDefs is optional, return true when missing
It should be allowed and is a optional property according to the schema
I have removed the validation for missing .markDefs as this propery is optional as defined by the schema. Updated some code to reflect this. |
@@ -23,7 +23,7 @@ export function isPortableTextTextBlock<T = PortableTextSpan | PortableTextObjec | |||
value.children.every((child) => isRecord(child)) && | |||
('markDefs' in value // optional property | |||
? Array.isArray(value.markDefs) && value.markDefs.every((def) => isRecord(def)) | |||
: false) && | |||
: true) && |
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 was incorrectly set to false. Should be true.
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.
Thanks @skogsmaskin looks good to me
Description
This will introduce a new prop to validation errors resolutions:
autoResolve
When a validation error occurs with such a resolution, the error will be automatically fixed for the user.
Currently the following validation errors will be automatically fixed:
Missing or- EDIT: should support missing markDefs prop.markDef
prop on a text block._key
on span nodsThese errors will be fixed through patches directly, meaning that they can be resolved without doing it through transformations in the editor. This allows for resolving the errors progressively so that the editor finally can be rendered when all the errors are resolved.
Besides this, I have also added editor normalization for the following inside the editor:
These will be normalized whenever an edit occurs to that node.
I have also refactored the
addAnnotation
static function because everything there now has to be called within thewithouthNormalizing
scope in order not to trigger the above mentioned normalization (in flight as we build the new annotation).What to review
That the changes are not causing edits when a user is only opening the editor.
Nothing should be patched automatically unless the user actually edits in the editor.
Testing
Should be covered by automatic tests.
However it would be nice with some manual testing as well. You can do so by for instance using the Vision plugin to set a block to certain value, for example without markDefs or with some mark that doesn't exist.
Notes for release