1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 10:51:44 +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,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)
})
}
/**