1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

fix to always normalize ancestors of a node (#1310)

* fix to always normalize ancestors of a node

* fix plugins example

* update changelog
This commit is contained in:
Ian Storm Taylor
2017-10-27 09:36:06 -07:00
committed by GitHub
parent d4eec124d8
commit 8f307b8260
4 changed files with 14 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ import SoftBreak from 'slate-soft-break'
function WordCount(options) {
return {
render(props) {
renderEditor(props) {
return (
<div>
<div>
@@ -56,11 +56,8 @@ class Plugins extends React.Component {
state = {
state: Plain.deserialize(`This example shows how you can extend Slate with plugins! It uses four fairly simple plugins, but you can use any plugins you want, or write your own!
The first is a simple plugin to collapse the selection whenever the escape key is pressed. Try selecting some text and pressing escape.
The second is another simple plugin that inserts a "soft" break when enter is pressed instead of creating a new block. Try pressing enter!
The third is an example of using the plugin.render property to create a higher-order-component.`)
}

View File

@@ -15,6 +15,8 @@ This document maintains a list of changes to the `slate-react` package with each
- **The `plugin.onBeforeChange` function was removed.** Previously there was both an `onBeforeChange` handler and an `onChange` handler. Now there is just an `onChange` handler, and the core plugin adds it's own logic before others.
- **The `plugin.render` function was renamed to `plugin.renderEditor`.** It performs the same function, but has been renamed to disambiguate between all of the other new rendering functions available to plugins.
###### NEW
- **`State` objects now have an embedded `state.schema` property.** This new schema property is used to automatically normalize the state as it changes, according to the editor's current schema. This makes normalization much easier.

View File

@@ -38,7 +38,7 @@ class Content extends React.Component {
static propTypes = {
autoCorrect: Types.bool.isRequired,
autoFocus: Types.bool.isRequired,
children: Types.array.isRequired,
children: Types.any.isRequired,
className: Types.string,
editor: Types.object.isRequired,
readOnly: Types.bool.isRequired,

View File

@@ -40,9 +40,18 @@ Changes.normalizeDocument = (change) => {
Changes.normalizeNodeByKey = (change, key) => {
const { state } = change
const { document, schema } = state
let { document, schema } = state
const node = document.assertNode(key)
normalizeNodeAndChildren(change, node, schema)
document = change.state.document
const ancestors = document.getAncestors(key)
if (!ancestors) return
ancestors.forEach((ancestor) => {
normalizeNode(change, ancestor, schema)
})
}
/**