mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11:17 +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:
@@ -15,7 +15,7 @@ import SoftBreak from 'slate-soft-break'
|
|||||||
|
|
||||||
function WordCount(options) {
|
function WordCount(options) {
|
||||||
return {
|
return {
|
||||||
render(props) {
|
renderEditor(props) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
@@ -56,11 +56,8 @@ class Plugins extends React.Component {
|
|||||||
|
|
||||||
state = {
|
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!
|
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 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 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.`)
|
The third is an example of using the plugin.render property to create a higher-order-component.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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.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
|
###### 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.
|
- **`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.
|
||||||
|
@@ -38,7 +38,7 @@ class Content extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
autoCorrect: Types.bool.isRequired,
|
autoCorrect: Types.bool.isRequired,
|
||||||
autoFocus: Types.bool.isRequired,
|
autoFocus: Types.bool.isRequired,
|
||||||
children: Types.array.isRequired,
|
children: Types.any.isRequired,
|
||||||
className: Types.string,
|
className: Types.string,
|
||||||
editor: Types.object.isRequired,
|
editor: Types.object.isRequired,
|
||||||
readOnly: Types.bool.isRequired,
|
readOnly: Types.bool.isRequired,
|
||||||
|
@@ -40,9 +40,18 @@ Changes.normalizeDocument = (change) => {
|
|||||||
|
|
||||||
Changes.normalizeNodeByKey = (change, key) => {
|
Changes.normalizeNodeByKey = (change, key) => {
|
||||||
const { state } = change
|
const { state } = change
|
||||||
const { document, schema } = state
|
let { document, schema } = state
|
||||||
const node = document.assertNode(key)
|
const node = document.assertNode(key)
|
||||||
|
|
||||||
normalizeNodeAndChildren(change, node, schema)
|
normalizeNodeAndChildren(change, node, schema)
|
||||||
|
|
||||||
|
document = change.state.document
|
||||||
|
const ancestors = document.getAncestors(key)
|
||||||
|
if (!ancestors) return
|
||||||
|
|
||||||
|
ancestors.forEach((ancestor) => {
|
||||||
|
normalizeNode(change, ancestor, schema)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user