mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +02:00
* added onFocus, and docs. fixes #650 * sorted prop types declarations alphabetically
This commit is contained in:
@@ -23,6 +23,7 @@ The top-level React component that renders the Slate editor itself.
|
|||||||
- [Plugin-like Properties](#plugin-like-properties)
|
- [Plugin-like Properties](#plugin-like-properties)
|
||||||
- [`onBeforeInput`](#onbeforeinput)
|
- [`onBeforeInput`](#onbeforeinput)
|
||||||
- [`onBlur`](#onblur)
|
- [`onBlur`](#onblur)
|
||||||
|
- [`onFocus`](#onfocus)
|
||||||
- [`onCopy`](#oncopy)
|
- [`onCopy`](#oncopy)
|
||||||
- [`onCut`](#oncut)
|
- [`onCut`](#oncut)
|
||||||
- [`onDrop`](#ondrop)
|
- [`onDrop`](#ondrop)
|
||||||
@@ -163,6 +164,7 @@ const plugins = [
|
|||||||
|
|
||||||
### `onBeforeInput`
|
### `onBeforeInput`
|
||||||
### `onBlur`
|
### `onBlur`
|
||||||
|
### `onFocus`
|
||||||
### `onCopy`
|
### `onCopy`
|
||||||
### `onCut`
|
### `onCut`
|
||||||
### `onDrop`
|
### `onDrop`
|
||||||
|
@@ -19,6 +19,10 @@ When text is entered, the core plugin inserts the text from `event.data` into th
|
|||||||
|
|
||||||
When the editor is blurred, the core plugin updates the selection in Slate's internal data model without re-rendering.
|
When the editor is blurred, the core plugin updates the selection in Slate's internal data model without re-rendering.
|
||||||
|
|
||||||
|
### `onFocus`
|
||||||
|
|
||||||
|
When the editor is focused, the core plugin updates the selection in Slate's internal data model without re-rendering.
|
||||||
|
|
||||||
### `onCopy`
|
### `onCopy`
|
||||||
|
|
||||||
When the user copies part of the document, the core plugin adds the copied text to the clipboard with a serialized version of the document intact, so that it can be deserialized and inserted on paste, preserving formatting.
|
When the user copies part of the document, the core plugin adds the copied text to the clipboard with a serialized version of the document intact, so that it can be deserialized and inserted on paste, preserving formatting.
|
||||||
|
@@ -11,6 +11,7 @@ When the editor needs to resolve a plugin-related handler, it will loop through
|
|||||||
- [Event Handler Properties](#event-handle-properties)
|
- [Event Handler Properties](#event-handle-properties)
|
||||||
- [`onBeforeInput`](#onbeforeinput)
|
- [`onBeforeInput`](#onbeforeinput)
|
||||||
- [`onBlur`](#onblur)
|
- [`onBlur`](#onblur)
|
||||||
|
- [`onFocus`](#onfocus)
|
||||||
- [`onCopy`](#oncopy)
|
- [`onCopy`](#oncopy)
|
||||||
- [`onCut`](#oncut)
|
- [`onCut`](#oncut)
|
||||||
- [`onDrop`](#ondrop)
|
- [`onDrop`](#ondrop)
|
||||||
@@ -43,6 +44,7 @@ export default MySlatePlugin(options) {
|
|||||||
{
|
{
|
||||||
onBeforeInput: Function,
|
onBeforeInput: Function,
|
||||||
onBlur: Function,
|
onBlur: Function,
|
||||||
|
onFocus: Function,
|
||||||
onCopy: Function,
|
onCopy: Function,
|
||||||
onCut: Function,
|
onCut: Function,
|
||||||
onDrop: Function,
|
onDrop: Function,
|
||||||
@@ -70,6 +72,13 @@ This handler is called when the editor's `contenteditable` element is blurred.
|
|||||||
|
|
||||||
If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
||||||
|
|
||||||
|
### `onFocus`
|
||||||
|
`Function onFocus(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
||||||
|
|
||||||
|
This handler is called when the editor's `contenteditable` element is focused.
|
||||||
|
|
||||||
|
If no other plugin handles this event, it will be handled by the [Core plugin](./core.md).
|
||||||
|
|
||||||
### `onCopy`
|
### `onCopy`
|
||||||
`Function onCopy(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
`Function onCopy(event: Event, data: Object, state: State, editor: Editor) => State || Void`
|
||||||
|
|
||||||
|
@@ -46,6 +46,7 @@ class Content extends React.Component {
|
|||||||
onCopy: React.PropTypes.func.isRequired,
|
onCopy: React.PropTypes.func.isRequired,
|
||||||
onCut: React.PropTypes.func.isRequired,
|
onCut: React.PropTypes.func.isRequired,
|
||||||
onDrop: React.PropTypes.func.isRequired,
|
onDrop: React.PropTypes.func.isRequired,
|
||||||
|
onFocus: React.PropTypes.func.isRequired,
|
||||||
onKeyDown: React.PropTypes.func.isRequired,
|
onKeyDown: React.PropTypes.func.isRequired,
|
||||||
onPaste: React.PropTypes.func.isRequired,
|
onPaste: React.PropTypes.func.isRequired,
|
||||||
onSelect: React.PropTypes.func.isRequired,
|
onSelect: React.PropTypes.func.isRequired,
|
||||||
@@ -229,6 +230,23 @@ class Content extends React.Component {
|
|||||||
this.props.onBlur(event, data)
|
this.props.onBlur(event, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On focus, update the selection to be focused.
|
||||||
|
*
|
||||||
|
* @param {Event} event
|
||||||
|
*/
|
||||||
|
|
||||||
|
onFocus = (event) => {
|
||||||
|
if (this.props.readOnly) return
|
||||||
|
if (this.tmp.isCopying) return
|
||||||
|
if (!this.isInContentEditable(event)) return
|
||||||
|
|
||||||
|
const data = {}
|
||||||
|
|
||||||
|
debug('onFocus', { event, data })
|
||||||
|
this.props.onFocus(event, data)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On change, bubble up.
|
* On change, bubble up.
|
||||||
*
|
*
|
||||||
@@ -755,6 +773,7 @@ class Content extends React.Component {
|
|||||||
className={className}
|
className={className}
|
||||||
onBeforeInput={this.onBeforeInput}
|
onBeforeInput={this.onBeforeInput}
|
||||||
onBlur={this.onBlur}
|
onBlur={this.onBlur}
|
||||||
|
onFocus={this.onFocus}
|
||||||
onCompositionEnd={this.onCompositionEnd}
|
onCompositionEnd={this.onCompositionEnd}
|
||||||
onCompositionStart={this.onCompositionStart}
|
onCompositionStart={this.onCompositionStart}
|
||||||
onCopy={this.onCopy}
|
onCopy={this.onCopy}
|
||||||
|
@@ -23,6 +23,7 @@ const debug = Debug('slate:editor')
|
|||||||
const EVENT_HANDLERS = [
|
const EVENT_HANDLERS = [
|
||||||
'onBeforeInput',
|
'onBeforeInput',
|
||||||
'onBlur',
|
'onBlur',
|
||||||
|
'onFocus',
|
||||||
'onCopy',
|
'onCopy',
|
||||||
'onCut',
|
'onCut',
|
||||||
'onDrop',
|
'onDrop',
|
||||||
|
@@ -22,6 +22,7 @@ const debug = Debug('slate:stack')
|
|||||||
const EVENT_HANDLER_METHODS = [
|
const EVENT_HANDLER_METHODS = [
|
||||||
'onBeforeInput',
|
'onBeforeInput',
|
||||||
'onBlur',
|
'onBlur',
|
||||||
|
'onFocus',
|
||||||
'onCopy',
|
'onCopy',
|
||||||
'onCut',
|
'onCut',
|
||||||
'onDrop',
|
'onDrop',
|
||||||
|
@@ -167,6 +167,26 @@ function Plugin(options = {}) {
|
|||||||
.apply({ isNative })
|
.apply({ isNative })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On focus.
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {State} state
|
||||||
|
* @return {State}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onFocus(e, data, state) {
|
||||||
|
const isNative = true
|
||||||
|
|
||||||
|
debug('onFocus', { data, isNative })
|
||||||
|
|
||||||
|
return state
|
||||||
|
.transform()
|
||||||
|
.focus()
|
||||||
|
.apply({ isNative })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On copy.
|
* On copy.
|
||||||
*
|
*
|
||||||
@@ -834,6 +854,7 @@ function Plugin(options = {}) {
|
|||||||
editor={editor}
|
editor={editor}
|
||||||
onBeforeInput={editor.onBeforeInput}
|
onBeforeInput={editor.onBeforeInput}
|
||||||
onBlur={editor.onBlur}
|
onBlur={editor.onBlur}
|
||||||
|
onFocus={editor.onFocus}
|
||||||
onChange={editor.onChange}
|
onChange={editor.onChange}
|
||||||
onCopy={editor.onCopy}
|
onCopy={editor.onCopy}
|
||||||
onCut={editor.onCut}
|
onCut={editor.onCut}
|
||||||
@@ -924,6 +945,7 @@ function Plugin(options = {}) {
|
|||||||
onBeforeChange,
|
onBeforeChange,
|
||||||
onBeforeInput,
|
onBeforeInput,
|
||||||
onBlur,
|
onBlur,
|
||||||
|
onFocus,
|
||||||
onCopy,
|
onCopy,
|
||||||
onCut,
|
onCut,
|
||||||
onDrop,
|
onDrop,
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
const EVENT_HANDLERS = [
|
const EVENT_HANDLERS = [
|
||||||
'onBeforeInput',
|
'onBeforeInput',
|
||||||
'onBlur',
|
'onBlur',
|
||||||
|
'onFocus',
|
||||||
'onCopy',
|
'onCopy',
|
||||||
'onCut',
|
'onCut',
|
||||||
'onDrop',
|
'onDrop',
|
||||||
|
Reference in New Issue
Block a user