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