mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 01:50:06 +02:00
Allow void elements to receive marks (#5135)
Some void elements are effectively stand-ins for text, such as with the mentions example, where the mention element renders the character's name. Users might want to format Void elements like this with bold, or set their font and size, so `editor.markableVoid` tells Slate whether or not to apply Marks to the text children of void elements. - Adds `markableVoid()` as a schema-specific overrideable test. - Changes `addMark` and `removeMark` so marks can apply to voids. Also changes behavior of collapsed selection so that if a markable Void is selected, the mark will be applied / removed. - Shows how `markableVoid()` can work in the mentions example
This commit is contained in:
@@ -12,6 +12,7 @@ interface Editor {
|
||||
// Schema-specific node behaviors.
|
||||
isInline: (element: Element) => boolean
|
||||
isVoid: (element: Element) => boolean
|
||||
markableVoid: (element: Element) => boolean
|
||||
normalizeNode: (entry: NodeEntry) => void
|
||||
onChange: () => void
|
||||
// Overrideable core actions.
|
||||
@@ -70,6 +71,20 @@ editor.insertText = text => {
|
||||
}
|
||||
```
|
||||
|
||||
If you have void "mention" elements that can accept marks like bold or italic:
|
||||
|
||||
```javascript
|
||||
const { isVoid, markableVoid } = editor
|
||||
|
||||
editor.isVoid = element => {
|
||||
return element.type === 'mention' ? true : isInline(element)
|
||||
}
|
||||
|
||||
editor.markableVoid = element => {
|
||||
return element.type === 'mention' || markableVoid(element)
|
||||
}
|
||||
```
|
||||
|
||||
Or you can even define custom "normalizations" that take place to ensure that links obey certain constraints:
|
||||
|
||||
```javascript
|
||||
|
Reference in New Issue
Block a user