mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-07-31 04:20:26 +02:00
fix rich-text example lists
This commit is contained in:
@@ -4,6 +4,12 @@ import React from 'react'
|
|||||||
import initialState from './state.json'
|
import initialState from './state.json'
|
||||||
import keycode from 'keycode'
|
import keycode from 'keycode'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the default node type.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const DEFAULT_NODE = 'paragraph'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a set of node renderers.
|
* Define a set of node renderers.
|
||||||
*
|
*
|
||||||
@@ -166,11 +172,29 @@ class RichText extends React.Component {
|
|||||||
const isActive = this.hasBlock(type)
|
const isActive = this.hasBlock(type)
|
||||||
let { state } = this.state
|
let { state } = this.state
|
||||||
|
|
||||||
state = state
|
let transform = state
|
||||||
.transform()
|
.transform()
|
||||||
.setBlock(isActive ? 'paragraph' : type)
|
.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 })
|
this.setState({ state })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user