mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 06:53:25 +02:00
fix findNativePoint in empty blocks, add error reporting to examples
This commit is contained in:
@@ -145,13 +145,27 @@ input:focus {
|
|||||||
* Example.
|
* Example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.example {
|
.example, .error {
|
||||||
max-width: 42em;
|
max-width: 42em;
|
||||||
margin: 0 auto;
|
margin: 0 auto 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.example {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background: #fffae0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error .info {
|
||||||
|
background: #fbf1bd;
|
||||||
|
white-space: pre;
|
||||||
|
overflow-x: scroll;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.editor > * > * + * {
|
.editor > * > * + * {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,15 @@ const EXAMPLES = [
|
|||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
|
|
||||||
|
state = {
|
||||||
|
error: null,
|
||||||
|
info: null,
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error, info) {
|
||||||
|
this.setState({ error, info })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="app">
|
<div className="app">
|
||||||
@@ -78,14 +87,39 @@ class App extends React.Component {
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="example">
|
{this.state.error
|
||||||
<Switch>
|
? this.renderError()
|
||||||
{EXAMPLES.map(([ name, Component, path ]) => (
|
: this.renderExample()}
|
||||||
<Route key={path} path={path} component={Component} />
|
</div>
|
||||||
))}
|
)
|
||||||
<Redirect from="/" to="/rich-text" />
|
}
|
||||||
</Switch>
|
|
||||||
</div>
|
renderExample() {
|
||||||
|
return (
|
||||||
|
<div className="example">
|
||||||
|
<Switch>
|
||||||
|
{EXAMPLES.map(([ name, Component, path ]) => (
|
||||||
|
<Route key={path} path={path} component={Component} />
|
||||||
|
))}
|
||||||
|
<Redirect from="/" to="/rich-text" />
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
renderError() {
|
||||||
|
return (
|
||||||
|
<div className="error">
|
||||||
|
<p>
|
||||||
|
An error was thrown by one of the example's React components!
|
||||||
|
</p>
|
||||||
|
<pre className="info">
|
||||||
|
<code>
|
||||||
|
{this.state.error.stack}
|
||||||
|
{'\n'}
|
||||||
|
{this.state.info.componentStack}
|
||||||
|
</code>
|
||||||
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,16 @@ function findNativePoint(key, offset) {
|
|||||||
start = end
|
start = end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// COMPAT: For empty blocks with only a single empty text node, we will have
|
||||||
|
// rendered a `<br/>` instead of a text node.
|
||||||
|
if (
|
||||||
|
el.childNodes.length == 1 &&
|
||||||
|
el.childNodes[0].childNodes.length == 1 &&
|
||||||
|
el.childNodes[0].childNodes[0].tagName == 'BR'
|
||||||
|
) {
|
||||||
|
return { node: el.childNodes[0], offset: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user