1
0
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:
Ian Storm Taylor 2016-07-15 16:08:13 -07:00
parent 9c020d9a04
commit c0c1133236

View File

@ -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 })
}