-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed regression in #4208 where normalization on empty block nodes co…
…uld not be overridden (#4431)
- Loading branch information
Showing
3 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate': minor | ||
--- | ||
|
||
Fixed regression in #4208 where normalization on empty block nodes could not be overridden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/slate/test/normalization/block/insert-custom-block.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from '../..' | ||
import { Editor, Element, Transforms } from 'slate' | ||
|
||
export const input = ( | ||
<editor> | ||
<element type="body" /> | ||
</editor> | ||
) | ||
|
||
// patch in a custom normalizer that inserts empty paragraphs in the body instead of text nodes | ||
// this test also verifies the new node itself is also normalized, because it's inserting a non-normalized node | ||
const editor = (input as unknown) as Editor | ||
const defaultNormalize = editor.normalizeNode | ||
editor.normalizeNode = entry => { | ||
const [node, path] = entry | ||
if ( | ||
Element.isElement(node) && | ||
node.children.length === 0 && | ||
(node as any).type === 'body' | ||
) { | ||
const child = { type: 'paragraph', children: [] } | ||
Transforms.insertNodes(editor, child, { | ||
at: path.concat(0), | ||
voids: true, | ||
}) | ||
} else { | ||
defaultNormalize(entry) | ||
} | ||
} | ||
|
||
export const output = ( | ||
<editor> | ||
<element type="body"> | ||
<element type="paragraph"> | ||
<text /> | ||
</element> | ||
</element> | ||
</editor> | ||
) |