diff --git a/examples/auto-markdown/index.js b/examples/auto-markdown/index.js
index 2ddef17de..848cb4a99 100644
--- a/examples/auto-markdown/index.js
+++ b/examples/auto-markdown/index.js
@@ -4,10 +4,29 @@ import React from 'react'
import keycode from 'keycode'
import state from './state.json'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ 'block-quote': props =>
{props.children}
,
+ 'bulleted-list': props => ,
+ 'heading-one': props => {props.children}
,
+ 'heading-two': props => {props.children}
,
+ 'heading-three': props => {props.children}
,
+ 'heading-four': props => {props.children}
,
+ 'heading-five': props => {props.children}
,
+ 'heading-six': props => {props.children}
,
+ 'list-item': props => {props.children},
+ 'paragraph': props => {props.children}
+}
+
/**
* The auto-markdown example.
*
- * @type {Component} AutoMarkdown
+ * @type {Component}
*/
class AutoMarkdown extends React.Component {
@@ -57,8 +76,7 @@ class AutoMarkdown extends React.Component {
this.renderNode(node)}
- renderMark={mark => this.renderMark(mark)}
+ renderNode={node => NODES[node.type]}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onChange={(state) => {
console.groupCollapsed('Change!')
@@ -73,48 +91,6 @@ class AutoMarkdown extends React.Component {
)
}
- /**
- * Render each of our custom `node` types.
- *
- * @param {Node} node
- * @return {Component} component
- */
-
- renderNode(node) {
- switch (node.type) {
- case 'block-quote': {
- return (props) => {props.children}
- }
- case 'bulleted-list': {
- return (props) =>
- }
- case 'heading-one': {
- return (props) => {props.children}
- }
- case 'heading-two': {
- return (props) => {props.children}
- }
- case 'heading-three': {
- return (props) => {props.children}
- }
- case 'heading-four': {
- return (props) => {props.children}
- }
- case 'heading-five': {
- return (props) => {props.children}
- }
- case 'heading-six': {
- return (props) => {props.children}
- }
- case 'list-item': {
- return (props) => {props.children}
- }
- case 'paragraph': {
- return (props) => {props.children}
- }
- }
- }
-
/**
* On key down, check for our specific key shortcuts.
*
diff --git a/examples/code-highlighting/index.js b/examples/code-highlighting/index.js
index f16d6d559..9c932fc77 100644
--- a/examples/code-highlighting/index.js
+++ b/examples/code-highlighting/index.js
@@ -6,7 +6,9 @@ import keycode from 'keycode'
import state from './state.json'
/**
- * Node and mark renderers.
+ * Node renderers.
+ *
+ * @type {Object}
*/
const NODES = {
@@ -14,6 +16,12 @@ const NODES = {
paragraph: props => {props.children}
}
+/**
+ * Mark renderers.
+ *
+ * @type {Object}
+ */
+
const MARKS = {
'highlight-comment': {
opacity: '0.33'
@@ -29,7 +37,7 @@ const MARKS = {
/**
* Example.
*
- * @type {Component} CodeHighlighting
+ * @type {Component}
*/
class CodeHighlighting extends React.Component {
@@ -56,8 +64,8 @@ class CodeHighlighting extends React.Component {
this.renderNode(...args)}
- renderMark={(...args) => this.renderMark(...args)}
+ renderNode={node => NODES[node.type]}
+ renderMark={mark => MARKS[mark.type] || {}}
renderDecorations={(...args) => this.renderDecorations(...args)}
onKeyDown={(...args) => this.onKeyDown(...args)}
onChange={(state) => {
@@ -73,14 +81,6 @@ class CodeHighlighting extends React.Component {
)
}
- renderNode(node) {
- return NODES[node.type]
- }
-
- renderMark(mark) {
- return MARKS[mark.type] || {}
- }
-
renderDecorations(text, state, editor) {
let characters = text.characters
const { document } = state
@@ -88,7 +88,6 @@ class CodeHighlighting extends React.Component {
if (block.type != 'code') return characters
const string = text.text
- console.log('render decorations:', string)
const grammar = Prism.languages.javascript
const tokens = Prism.tokenize(string, grammar)
let offset = 0
@@ -116,28 +115,6 @@ class CodeHighlighting extends React.Component {
return characters
}
- // renderDecorations(text) {
- // const { state } = this.state
- // const { document } = state
- // const block = document.getClosestBlock(text)
- // if (block.type != 'code') return
-
- // const string = text.text
- // if (cache[string]) return cache[string]
-
- // const grammar = Prism.languages.javascript
- // const tokens = Prism.tokenize(string, grammar)
- // const ranges = tokens.map((token) => {
- // return typeof token == 'string'
- // ? { text: token }
- // : {
- // text: token.content,
- // marks: [{ type: token.type }]
- // }
- // })
-
- // return cached[string] = ranges
- // }
}
/**
diff --git a/examples/hovering-menu/index.js b/examples/hovering-menu/index.js
index adbe555ad..f83ea00fe 100644
--- a/examples/hovering-menu/index.js
+++ b/examples/hovering-menu/index.js
@@ -5,10 +5,44 @@ import React from 'react'
import position from 'selection-position'
import state from './state.json'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ paragraph: props => {props.children}
+}
+
+/**
+ * Mark renderers.
+ *
+ * @type {Object}
+ */
+
+const MARKS = {
+ bold: {
+ fontWeight: 'bold'
+ },
+ code: {
+ fontFamily: 'monospace',
+ backgroundColor: '#eee',
+ padding: '3px',
+ borderRadius: '4px'
+ },
+ italic: {
+ fontStyle: 'italic'
+ },
+ underlined: {
+ textDecoration: 'underline'
+ }
+}
+
/**
* The rich text example.
*
- * @type {Component} HoveringMenu
+ * @type {Component}
*/
class HoveringMenu extends React.Component {
@@ -101,8 +135,8 @@ class HoveringMenu extends React.Component {
this.renderNode(node)}
- renderMark={mark => this.renderMark(mark)}
+ renderNode={node => NODES[node.type]}
+ renderMark={mark => MARKS[mark.type]}
onChange={(state) => {
console.groupCollapsed('Change!')
console.log('Document:', state.document.toJS())
@@ -116,42 +150,6 @@ class HoveringMenu extends React.Component {
)
}
- renderNode(node) {
- switch (node.type) {
- case 'paragraph': {
- return (props) => {props.children}
- }
- }
- }
-
- renderMark(mark) {
- switch (mark.type) {
- case 'bold': {
- return {
- fontWeight: 'bold'
- }
- }
- case 'code': {
- return {
- fontFamily: 'monospace',
- backgroundColor: '#eee',
- padding: '3px',
- borderRadius: '4px'
- }
- }
- case 'italic': {
- return {
- fontStyle: 'italic'
- }
- }
- case 'underlined': {
- return {
- textDecoration: 'underline'
- }
- }
- }
- }
-
}
/**
diff --git a/examples/images/index.js b/examples/images/index.js
index 843307073..f9cfa5714 100644
--- a/examples/images/index.js
+++ b/examples/images/index.js
@@ -5,10 +5,27 @@ import ReactDOM from 'react-dom'
import state from './state.json'
import { Map } from 'immutable'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ paragraph: props => {props.children}
,
+ image: (props) => {
+ const { node, state } = props
+ const { data } = node
+ const isActive = state.isFocused && state.blocks.includes(node)
+ const src = data.get('src')
+ return
+ }
+}
+
/**
* The images example.
*
- * @type {Component} Images
+ * @type {Component}
*/
class Images extends React.Component {
@@ -112,7 +129,7 @@ class Images extends React.Component {
this.renderNode(node)}
+ renderNode={node => NODES[node.type]}
onChange={(state) => {
console.groupCollapsed('Change!')
console.log('Document:', state.document.toJS())
@@ -126,30 +143,6 @@ class Images extends React.Component {
)
}
- /**
- * Render our custom `node`.
- *
- * @param {Node} node
- * @return {Element} element
- */
-
- renderNode(node) {
- switch (node.type) {
- case 'image': {
- return (props) => {
- const { node, state } = props
- const { data } = node
- const isActive = state.selection.isFocused && state.blocks.includes(node)
- const src = data.get('src')
- return
- }
- }
- case 'paragraph': {
- return (props) => {props.children}
- }
- }
- }
-
}
/**
diff --git a/examples/links/index.js b/examples/links/index.js
index e64051ce9..2416fd3c4 100644
--- a/examples/links/index.js
+++ b/examples/links/index.js
@@ -5,10 +5,25 @@ import ReactDOM from 'react-dom'
import state from './state.json'
import { Map } from 'immutable'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ paragraph: props => {props.children}
,
+ link: (props) => {
+ const { data } = props.node
+ const href = data.get('href')
+ return {props.children}
+ }
+}
+
/**
* The links example.
*
- * @type {Component} Links
+ * @type {Component}
*/
class Links extends React.Component {
@@ -114,7 +129,7 @@ class Links extends React.Component {
this.renderNode(node)}
+ renderNode={node => NODES[node.type]}
onChange={(state) => {
console.groupCollapsed('Change!')
console.log('Document:', state.document.toJS())
@@ -128,28 +143,6 @@ class Links extends React.Component {
)
}
- /**
- * Render our custom `node`.
- *
- * @param {Node} node
- * @return {Element} element
- */
-
- renderNode(node) {
- switch (node.type) {
- case 'link': {
- return (props) => {
- const { data } = props.node
- const href = data.get('href')
- return {props.children}
- }
- }
- case 'paragraph': {
- return (props) => {props.children}
- }
- }
- }
-
}
/**
diff --git a/examples/paste-html/index.js b/examples/paste-html/index.js
index bd52f63b6..9e4e99447 100644
--- a/examples/paste-html/index.js
+++ b/examples/paste-html/index.js
@@ -3,13 +3,63 @@ import { Editor, Html, Raw } from '../..'
import React from 'react'
import state from './state.json'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ 'bulleted-list': props => ,
+ 'code': props => {props.children}
,
+ 'heading-one': props => {props.children}
,
+ 'heading-two': props => {props.children}
,
+ 'heading-three': props => {props.children}
,
+ 'heading-four': props => {props.children}
,
+ 'heading-five': props => {props.children}
,
+ 'heading-six': props => {props.children}
,
+ 'list-item': props => {props.children},
+ 'numbered-list': props => {props.children}
,
+ 'paragraph': props => {props.children}
,
+ 'quote': props => {props.children}
,
+ 'link': (props) => {
+ const { data } = props.node
+ const href = data.get('href')
+ return {props.children}
+ }
+}
+
+/**
+ * Mark renderers.
+ *
+ * @type {Object}
+ */
+
+const MARKS = {
+ bold: {
+ fontWeight: 'bold'
+ },
+ code: {
+ fontFamily: 'monospace',
+ backgroundColor: '#eee',
+ padding: '3px',
+ borderRadius: '4px'
+ },
+ italic: {
+ fontStyle: 'italic'
+ },
+ underlined: {
+ textDecoration: 'underline'
+ }
+}
+
/**
* Tags to blocks.
*
* @type {Object}
*/
-const BLOCKS = {
+const BLOCK_TAGS = {
p: 'paragraph',
li: 'list-item',
ul: 'bulleted-list',
@@ -30,7 +80,7 @@ const BLOCKS = {
* @type {Object}
*/
-const MARKS = {
+const MARK_TAGS = {
strong: 'bold',
em: 'italic',
u: 'underline',
@@ -47,7 +97,7 @@ const MARKS = {
const RULES = [
{
deserialize(el, next) {
- const block = BLOCKS[el.tagName]
+ const block = BLOCK_TAGS[el.tagName]
if (!block) return
return {
kind: 'block',
@@ -58,7 +108,7 @@ const RULES = [
},
{
deserialize(el, next) {
- const mark = MARKS[el.tagName]
+ const mark = MARK_TAGS[el.tagName]
if (!mark) return
return {
kind: 'mark',
@@ -101,6 +151,8 @@ const RULES = [
/**
* Create a new HTML serializer with `RULES`.
+ *
+ * @type {Html}
*/
const serializer = new Html(RULES)
@@ -108,7 +160,7 @@ const serializer = new Html(RULES)
/**
* The rich text example.
*
- * @type {Component} PasteHtml
+ * @type {Component}
*/
class PasteHtml extends React.Component {
@@ -133,8 +185,8 @@ class PasteHtml extends React.Component {
this.renderNode(node)}
- renderMark={mark => this.renderMark(mark)}
+ renderNode={node => NODES[node.type]}
+ renderMark={mark => MARKS[mark.type]}
onPaste={(...args) => this.onPaste(...args)}
onChange={(state) => {
console.groupCollapsed('Change!')
@@ -149,56 +201,6 @@ class PasteHtml extends React.Component {
)
}
- renderNode(node) {
- switch (node.type) {
- case 'bulleted-list': return (props) =>
- case 'code': return (props) => {props.children}
- case 'heading-one': return (props) => {props.children}
- case 'heading-two': return (props) => {props.children}
- case 'heading-three': return (props) => {props.children}
- case 'heading-four': return (props) => {props.children}
- case 'heading-five': return (props) => {props.children}
- case 'heading-six': return (props) => {props.children}
- case 'list-item': return (props) => {props.children}
- case 'numbered-list': return (props) => {props.children}
- case 'paragraph': return (props) => {props.children}
- case 'quote': return (props) => {props.children}
- case 'link': return (props) => {
- const { data } = props.node
- const href = data.get('href')
- return {props.children}
- }
- }
- }
-
- renderMark(mark) {
- switch (mark.type) {
- case 'bold': {
- return {
- fontWeight: 'bold'
- }
- }
- case 'code': {
- return {
- fontFamily: 'monospace',
- backgroundColor: '#eee',
- padding: '3px',
- borderRadius: '4px'
- }
- }
- case 'italic': {
- return {
- fontStyle: 'italic'
- }
- }
- case 'underlined': {
- return {
- textDecoration: 'underline'
- }
- }
- }
- }
-
}
/**
diff --git a/examples/plain-text/index.js b/examples/plain-text/index.js
index 872b5f70e..982a5b449 100644
--- a/examples/plain-text/index.js
+++ b/examples/plain-text/index.js
@@ -34,15 +34,15 @@ function deserialize(string) {
*/
function serialize(state) {
- return state.document.nodes
- .map(node => node.text)
+ return state.blocks
+ .map(block => block.text)
.join('\n')
}
/**
* The plain text example.
*
- * @type {Component} PlainText
+ * @type {Component}
*/
class PlainText extends React.Component {
diff --git a/examples/rich-text/index.js b/examples/rich-text/index.js
index 53c14bd5c..62b36a4c8 100644
--- a/examples/rich-text/index.js
+++ b/examples/rich-text/index.js
@@ -3,10 +3,50 @@ import { Editor, Mark, Raw } from '../..'
import React from 'react'
import state from './state.json'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ 'block-quote': props => {props.children}
,
+ 'bulleted-list': props => ,
+ 'heading-one': props => {props.children}
,
+ 'heading-two': props => {props.children}
,
+ 'list-item': props => {props.chidlren},
+ 'numbered-list': props => {props.children}
,
+ 'paragraph': props => {props.children}
+}
+
+/**
+ * Mark renderers.
+ *
+ * @type {Object}
+ */
+
+const MARKS = {
+ bold: {
+ fontWeight: 'bold'
+ },
+ code: {
+ fontFamily: 'monospace',
+ backgroundColor: '#eee',
+ padding: '3px',
+ borderRadius: '4px'
+ },
+ italic: {
+ fontStyle: 'italic'
+ },
+ underlined: {
+ textDecoration: 'underline'
+ }
+}
+
/**
* The rich text example.
*
- * @type {Component} RichText
+ * @type {Component}
*/
class RichText extends React.Component {
@@ -101,8 +141,8 @@ class RichText extends React.Component {
this.renderNode(node)}
- renderMark={mark => this.renderMark(mark)}
+ renderNode={node => NODES[node.type]}
+ renderMark={mark => MARKS[mark.type]}
onChange={(state) => {
console.groupCollapsed('Change!')
console.log('Document:', state.document.toJS())
@@ -115,61 +155,6 @@ class RichText extends React.Component {
)
}
-
- renderNode(node) {
- switch (node.type) {
- case 'block-quote': {
- return (props) => {props.children}
- }
- case 'bulleted-list': {
- return (props) =>
- }
- case 'heading-one': {
- return (props) => {props.children}
- }
- case 'heading-two': {
- return (props) => {props.children}
- }
- case 'list-item': {
- return (props) => {props.chidlren}
- }
- case 'numbered-list': {
- return (props) => {props.children}
- }
- case 'paragraph': {
- return (props) => {props.children}
- }
- }
- }
-
- renderMark(mark) {
- switch (mark.type) {
- case 'bold': {
- return {
- fontWeight: 'bold'
- }
- }
- case 'code': {
- return {
- fontFamily: 'monospace',
- backgroundColor: '#eee',
- padding: '3px',
- borderRadius: '4px'
- }
- }
- case 'italic': {
- return {
- fontStyle: 'italic'
- }
- }
- case 'underlined': {
- return {
- textDecoration: 'underline'
- }
- }
- }
- }
-
}
/**
diff --git a/examples/tables/index.js b/examples/tables/index.js
index 925958a5f..501662724 100644
--- a/examples/tables/index.js
+++ b/examples/tables/index.js
@@ -4,10 +4,35 @@ import React from 'react'
import keycode from 'keycode'
import state from './state.json'
+/**
+ * Node renderers.
+ *
+ * @type {Object}
+ */
+
+const NODES = {
+ 'paragraph': props => {props.children}
,
+ 'table': props => ,
+ 'table-row': props => {props.children}
,
+ 'table-cell': props => {props.children} |
+}
+
+/**
+ * Mark renderers.
+ *
+ * @type {Object}
+ */
+
+const MARKS = {
+ bold: {
+ fontWeight: 'bold'
+ }
+}
+
/**
* The tables example.
*
- * @type {Component} Tables
+ * @type {Component}
*/
class Tables extends React.Component {
@@ -33,8 +58,8 @@ class Tables extends React.Component {
this.renderNode(node)}
- renderMark={mark => this.renderMark(mark)}
+ renderNode={node => NODES[node.type]}
+ renderMark={mark => MARKS[mark.type]}
onKeyDown={(e, state) => this.onKeyDown(e, state)}
onChange={(state) => {
console.groupCollapsed('Change!')
@@ -49,47 +74,6 @@ class Tables extends React.Component {
)
}
- /**
- * Render each of our custom `mark` types.
- *
- * @param {Mark} mark
- * @return {Component} component
- */
-
- renderMark(mark) {
- switch (mark.type) {
- case 'bold': {
- return {
- fontWeight: 'bold'
- }
- }
- }
- }
-
- /**
- * Render each of our custom `node` types.
- *
- * @param {Node} node
- * @return {Component} component
- */
-
- renderNode(node) {
- switch (node.type) {
- case 'paragraph': {
- return (props) => {props.children}
- }
- case 'table': {
- return (props) =>
- }
- case 'table-row': {
- return (props) => {props.children}
- }
- case 'table-cell': {
- return (props) => {props.children} |
- }
- }
- }
-
/**
* On key down, check for our specific key shortcuts.
*
diff --git a/lib/components/content.js b/lib/components/content.js
index 3888fa483..cc0b09091 100644
--- a/lib/components/content.js
+++ b/lib/components/content.js
@@ -64,25 +64,21 @@ class Content extends React.Component {
*/
componentWillMount() {
- console.log('is rendering')
this.tmp.isRendering = true
}
componentWillUpdate(props, state) {
- console.log('is rendering')
this.tmp.isRendering = true
}
componentDidMount() {
setTimeout(() => {
- console.log('not rendering')
this.tmp.isRendering = false
})
}
componentDidUpdate(props, state) {
setTimeout(() => {
- console.log('not rendering')
this.tmp.isRendering = false
})
}
@@ -331,7 +327,6 @@ class Content extends React.Component {
*/
render() {
- console.log('render contents')
const { state } = this.props
const { document } = state
const children = document.nodes
diff --git a/lib/components/text.js b/lib/components/text.js
index 040e5b89d..c84f50013 100644
--- a/lib/components/text.js
+++ b/lib/components/text.js
@@ -44,7 +44,6 @@ class Text extends React.Component {
*/
render() {
- console.log('render text:', this.props.node.key)
return (
{this.renderLeaves()}
diff --git a/lib/components/void.js b/lib/components/void.js
index 8cd4ed657..07be30a78 100644
--- a/lib/components/void.js
+++ b/lib/components/void.js
@@ -29,7 +29,7 @@ class Void extends React.Component {
return (
{this.renderSpacer()}
- {children}
+ {children}
)
}