mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-20 13:22:04 +02:00
fix rich-text example lists
This commit is contained in:
parent
9c020d9a04
commit
c0c1133236
@ -4,6 +4,12 @@ import React from 'react'
|
||||
import initialState from './state.json'
|
||||
import keycode from 'keycode'
|
||||
|
||||
/**
|
||||
* Define the default node type.
|
||||
*/
|
||||
|
||||
const DEFAULT_NODE = 'paragraph'
|
||||
|
||||
/**
|
||||
* Define a set of node renderers.
|
||||
*
|
||||
@ -166,11 +172,29 @@ class RichText extends React.Component {
|
||||
const isActive = this.hasBlock(type)
|
||||
let { state } = this.state
|
||||
|
||||
state = state
|
||||
let transform = state
|
||||
.transform()
|
||||
.setBlock(isActive ? 'paragraph' : type)
|
||||
.apply()
|
||||
|
||||
// Handle the extra wrapping required for list buttons.
|
||||
if (type == 'bulleted-list' || type == 'numbered-list') {
|
||||
if (this.hasBlock('list-item')) {
|
||||
transform = transform
|
||||
.setBlock(DEFAULT_NODE)
|
||||
.unwrapBlock(type)
|
||||
} else {
|
||||
transform = transform
|
||||
.setBlock('list-item')
|
||||
.wrapBlock(type)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle everything but list buttons.
|
||||
else {
|
||||
transform = transform.setBlock(isActive ? DEFAULT_NODE : type)
|
||||
}
|
||||
|
||||
state = transform.apply()
|
||||
this.setState({ state })
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user