mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
pass in context properties to mark components, fixes #617
This commit is contained in:
@@ -29,10 +29,11 @@ class Leaf extends React.Component {
|
||||
*/
|
||||
|
||||
static propTypes = {
|
||||
editor: React.PropTypes.object.isRequired,
|
||||
index: React.PropTypes.number.isRequired,
|
||||
isVoid: React.PropTypes.bool,
|
||||
marks: React.PropTypes.object.isRequired,
|
||||
node: React.PropTypes.object.isRequired,
|
||||
offset: React.PropTypes.number.isRequired,
|
||||
parent: React.PropTypes.object.isRequired,
|
||||
ranges: React.PropTypes.object.isRequired,
|
||||
schema: React.PropTypes.object.isRequired,
|
||||
@@ -40,16 +41,6 @@ class Leaf extends React.Component {
|
||||
text: React.PropTypes.string.isRequired
|
||||
};
|
||||
|
||||
/**
|
||||
* Default properties.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
|
||||
static defaultProps = {
|
||||
isVoid: false
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -292,14 +283,27 @@ class Leaf extends React.Component {
|
||||
*/
|
||||
|
||||
renderMarks(props) {
|
||||
const { marks, schema } = props
|
||||
const text = this.renderText(props)
|
||||
const { marks, schema, node, offset, text, state, editor } = props
|
||||
const children = this.renderText(props)
|
||||
|
||||
return marks.reduce((children, mark) => {
|
||||
return marks.reduce((memo, mark) => {
|
||||
const Component = mark.getComponent(schema)
|
||||
if (!Component) return children
|
||||
return <Component mark={mark} marks={marks}>{children}</Component>
|
||||
}, text)
|
||||
if (!Component) return memo
|
||||
return (
|
||||
<Component
|
||||
editor={editor}
|
||||
mark={mark}
|
||||
marks={marks}
|
||||
node={node}
|
||||
offset={offset}
|
||||
schema={schema}
|
||||
state={state}
|
||||
text={text}
|
||||
>
|
||||
{memo}
|
||||
</Component>
|
||||
)
|
||||
}, children)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -348,16 +348,18 @@ class Node extends React.Component {
|
||||
*/
|
||||
|
||||
renderLeaf = (ranges, range, index, offset) => {
|
||||
const { node, parent, schema, state } = this.props
|
||||
const { node, parent, schema, state, editor } = this.props
|
||||
const text = range.text
|
||||
const marks = range.marks
|
||||
|
||||
return (
|
||||
<Leaf
|
||||
key={`${node.key}-${index}`}
|
||||
editor={editor}
|
||||
index={index}
|
||||
marks={marks}
|
||||
node={node}
|
||||
offset={offset}
|
||||
parent={parent}
|
||||
ranges={ranges}
|
||||
schema={schema}
|
||||
|
@@ -4,7 +4,6 @@ import Leaf from './leaf'
|
||||
import Mark from '../models/mark'
|
||||
import OffsetKey from '../utils/offset-key'
|
||||
import React from 'react'
|
||||
import noop from '../utils/noop'
|
||||
import { IS_FIREFOX } from '../constants/environment'
|
||||
|
||||
/**
|
||||
@@ -153,10 +152,11 @@ class Void extends React.Component {
|
||||
*/
|
||||
|
||||
renderLeaf = () => {
|
||||
const { node, schema, state } = this.props
|
||||
const { node, schema, state, editor } = this.props
|
||||
const child = node.getFirstText()
|
||||
const ranges = child.getRanges()
|
||||
const text = ''
|
||||
const offset = 0
|
||||
const marks = Mark.createSet()
|
||||
const index = 0
|
||||
const offsetKey = OffsetKey.stringify({
|
||||
@@ -166,17 +166,17 @@ class Void extends React.Component {
|
||||
|
||||
return (
|
||||
<Leaf
|
||||
isVoid
|
||||
renderMark={noop}
|
||||
key={offsetKey}
|
||||
schema={schema}
|
||||
state={state}
|
||||
editor={editor}
|
||||
index={index}
|
||||
marks={marks}
|
||||
node={child}
|
||||
offset={offset}
|
||||
parent={node}
|
||||
ranges={ranges}
|
||||
index={index}
|
||||
schema={schema}
|
||||
state={state}
|
||||
text={text}
|
||||
marks={marks}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user