2016-07-29 12:05:01 -07:00
|
|
|
|
start removing raw serializer (#1098)
* start removing raw serializer
* convert first tests to use jsx
* simplify jsx tests for raw serializer
* allow for options in raw serializer tests
* add more preserve option tests
* convert plain serializer tests
* convert html serialize
* start converting html deserialize
* add hyperscript util
* remove slate-sugar copy-pasted
* finish converting html deserialize
* convert plugins tests
* update rendering tests
* convert schemas tests
* convert core plugin tests
* update hyperscript utl
* refactor changes test directory structure
* fix changes before migration
* add migrated changes test files
* remove <x- prefixes from migration
* get addMark at-current-range tests passing
* get delete at-current-range tests passing
* remove old tests
* convert deleteForward and deleteBackward
* convert insertBlock, insertInline, insertFragment, insertText
* convert removeMark, setBlock, setInline, splitBlock, splitInline
* add unstaged tests
* convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText
* convert call, setData
* convert on-selection tests
* remove old on-selection tests
* convert history tests
* convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey
* convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey
* convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey
* fix tests
* port missing at-range tests to at-current-range
* remove at-range tests
* fix raw serializer tests
* fix linter
* fix to prefer toJSON as the canonical method name
* fix todos
* remove internal references to Raw
* add deprecation helper to Text.fromJSON
* convert examples to not use Raw, and not rely on terse
* remove focus-blur example, rename large document example
* refactor Raw serialize to deprecate, not remove, terse
* deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
|
|
|
import { Editor, State } from '../..'
|
2016-07-29 12:05:01 -07:00
|
|
|
import React from 'react'
|
|
|
|
import initialState from './state.json'
|
|
|
|
|
|
|
|
/**
|
2016-08-14 13:21:46 -07:00
|
|
|
* Define a schema.
|
2016-07-29 12:05:01 -07:00
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
|
2016-08-14 13:21:46 -07:00
|
|
|
const schema = {
|
|
|
|
nodes: {
|
2017-02-25 10:13:21 -08:00
|
|
|
'block-quote': props => <blockquote {...props.attributes}>{props.children}</blockquote>,
|
2016-08-14 13:21:46 -07:00
|
|
|
}
|
2016-07-29 12:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The plain text example.
|
|
|
|
*
|
|
|
|
* @type {Component}
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PlainText extends React.Component {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deserialize the initial editor state.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
|
|
|
|
state = {
|
start removing raw serializer (#1098)
* start removing raw serializer
* convert first tests to use jsx
* simplify jsx tests for raw serializer
* allow for options in raw serializer tests
* add more preserve option tests
* convert plain serializer tests
* convert html serialize
* start converting html deserialize
* add hyperscript util
* remove slate-sugar copy-pasted
* finish converting html deserialize
* convert plugins tests
* update rendering tests
* convert schemas tests
* convert core plugin tests
* update hyperscript utl
* refactor changes test directory structure
* fix changes before migration
* add migrated changes test files
* remove <x- prefixes from migration
* get addMark at-current-range tests passing
* get delete at-current-range tests passing
* remove old tests
* convert deleteForward and deleteBackward
* convert insertBlock, insertInline, insertFragment, insertText
* convert removeMark, setBlock, setInline, splitBlock, splitInline
* add unstaged tests
* convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText
* convert call, setData
* convert on-selection tests
* remove old on-selection tests
* convert history tests
* convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey
* convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey
* convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey
* fix tests
* port missing at-range tests to at-current-range
* remove at-range tests
* fix raw serializer tests
* fix linter
* fix to prefer toJSON as the canonical method name
* fix todos
* remove internal references to Raw
* add deprecation helper to Text.fromJSON
* convert examples to not use Raw, and not rely on terse
* remove focus-blur example, rename large document example
* refactor Raw serialize to deprecate, not remove, terse
* deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
|
|
|
state: State.fromJSON(initialState)
|
|
|
|
}
|
2016-07-29 12:05:01 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On change.
|
|
|
|
*
|
2017-09-05 18:03:41 -07:00
|
|
|
* @param {Change} change
|
2016-07-29 12:05:01 -07:00
|
|
|
*/
|
|
|
|
|
2017-09-05 18:03:41 -07:00
|
|
|
onChange = ({ state }) => {
|
2016-07-29 12:05:01 -07:00
|
|
|
this.setState({ state })
|
|
|
|
}
|
|
|
|
|
2016-08-01 15:18:37 -07:00
|
|
|
/**
|
|
|
|
* On key down, if it's <shift-enter> add a soft break.
|
|
|
|
*
|
|
|
|
* @param {Event} e
|
|
|
|
* @param {Object} data
|
2017-09-05 18:03:41 -07:00
|
|
|
* @param {Change} change
|
2016-08-01 15:18:37 -07:00
|
|
|
*/
|
|
|
|
|
2017-09-05 18:03:41 -07:00
|
|
|
onKeyDown = (e, data, change) => {
|
2016-08-01 15:18:37 -07:00
|
|
|
if (data.key == 'enter' && data.isShift) {
|
2017-09-05 18:03:41 -07:00
|
|
|
e.preventDefault()
|
|
|
|
change.insertText('\n')
|
|
|
|
return true
|
2016-08-01 15:18:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:05:01 -07:00
|
|
|
/**
|
|
|
|
* Render the editor.
|
|
|
|
*
|
|
|
|
* @return {Component} component
|
|
|
|
*/
|
|
|
|
|
2017-08-02 18:36:33 +02:00
|
|
|
render() {
|
2016-07-29 12:05:01 -07:00
|
|
|
return (
|
|
|
|
<Editor
|
|
|
|
placeholder={'Enter some plain text...'}
|
2016-08-14 13:21:46 -07:00
|
|
|
schema={schema}
|
|
|
|
state={this.state.state}
|
2016-07-29 12:05:01 -07:00
|
|
|
onChange={this.onChange}
|
2016-08-01 15:18:37 -07:00
|
|
|
onKeyDown={this.onKeyDown}
|
2016-07-29 12:05:01 -07:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default PlainText
|